Skip to content

Commit 41d4600

Browse files
committed
Metal: dedup per-frame uniforms bind and clean up OSD locals
Follow-up cleanup to 5298e70 ("Metal: inline single-call helpers in render path"), which made two small issues visible: 1. The core-draw, menu-draw, and overlay blocks in -renderFrame: each bound _context.uniforms at BufferIndexUniforms on the main render command encoder, always with the same buffer. Issue one bind per frame instead. The bind is placed AFTER [_frameView drawWithContext:_context] returns rather than at the top of the frame. FrameView's shader-pass loop may, on its back-buffer pass, rebind vertex slots at indices determined by .slang shader reflection data, which in principle could collide with BufferIndexUniforms. Binding after drawWithContext: guarantees the uniforms slot holds what the subsequent menu/overlay draws expect. 2. Rename width_n/height_n (awkward names introduced by the inlining of -_renderMessage:data:, which previously had its own scope free of width/height parameter shadowing) to bg_w/bg_h, matching the semantics of the OSD message background quad. No functional change intended.
1 parent 5298e70 commit 41d4600

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

gfx/drivers/metal.m

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,9 +2487,17 @@ - (bool)renderFrame:(const void *)frame
24872487

24882488
/* Draw core: back buffer + optional encoder pass. */
24892489
[_frameView drawWithContext:_context];
2490+
2491+
/* Bind uniforms once for all subsequent encoder work on the main
2492+
* command encoder. FrameView's shader passes can rebind vertex
2493+
* slots at shader-reflection-driven indices on the back-buffer
2494+
* pass, so bind AFTER drawWithContext: returns, not before.
2495+
* All subsequent blocks (core encoder pass, menu, overlay) reuse
2496+
* this binding instead of each rebinding the same uniforms. */
2497+
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
2498+
24902499
if ((_frameView.drawState & ViewDrawStateEncoder) != 0)
24912500
{
2492-
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
24932501
[rce setRenderPipelineState:_t_pipelineStateNoAlpha];
24942502
if (_frameView.filter == RTextureFilterNearest)
24952503
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
@@ -2505,7 +2513,6 @@ - (bool)renderFrame:(const void *)frame
25052513
if (_menu.hasFrame)
25062514
{
25072515
[_menu.view drawWithContext:_context];
2508-
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
25092516
[rce setRenderPipelineState:_t_pipelineState];
25102517
if (_menu.view.filter == RTextureFilterNearest)
25112518
[rce setFragmentSamplerState:_samplerStateNearest atIndex:SamplerIndexDraw];
@@ -2527,7 +2534,6 @@ - (bool)renderFrame:(const void *)frame
25272534
{
25282535
[_context resetRenderViewport:_overlay.fullscreen ? kFullscreenViewport : kVideoViewport];
25292536
[rce setRenderPipelineState:[_context getStockShader:VIDEO_SHADER_STOCK_BLEND blend:YES]];
2530-
[rce setVertexBytes:_context.uniforms length:sizeof(*_context.uniforms) atIndex:BufferIndexUniforms];
25312537
[rce setFragmentSamplerState:_samplerStateLinear atIndex:SamplerIndexDraw];
25322538
[_overlay drawWithEncoder:rce];
25332539
}
@@ -2563,23 +2569,23 @@ - (bool)renderFrame:(const void *)frame
25632569
float bgcolor_opacity = settings->floats.video_msg_bgcolor_opacity;
25642570
float x = settings->floats.video_msg_pos_x;
25652571
float y = 1.0f - settings->floats.video_msg_pos_y;
2566-
float width_n = msg_width / (float)_viewport->full_width;
2567-
float height_n = font_size / (float)_viewport->full_height;
2572+
float bg_w = msg_width / (float)_viewport->full_width;
2573+
float bg_h = font_size / (float)_viewport->full_height;
25682574
float x2 = 0.005f; /* extend background around text */
25692575
float y2 = 0.005f;
25702576
float r = bgcolor_red / 255.0f;
25712577
float g = bgcolor_green / 255.0f;
25722578
float b = bgcolor_blue / 255.0f;
25732579
float a = bgcolor_opacity;
25742580

2575-
y -= height_n;
2581+
y -= bg_h;
25762582
x -= x2;
25772583
y -= y2;
2578-
width_n += x2;
2579-
height_n += y2;
2584+
bg_w += x2;
2585+
bg_h += y2;
25802586

25812587
[_context resetRenderViewport:kFullscreenViewport];
2582-
[_context drawQuadX:x y:y w:width_n h:height_n r:r g:g b:b a:a];
2588+
[_context drawQuadX:x y:y w:bg_w h:bg_h r:r g:g b:b a:a];
25832589
}
25842590

25852591
font_driver_render_msg(data, msg, NULL, NULL);

0 commit comments

Comments
 (0)