GPU: Metal: Rebind storage buffers when changing the pipeline moves them.

(cherry picked from commit 73c9f25867)
This commit is contained in:
Jakub Wasilewski
2025-12-14 11:16:02 +01:00
committed by Sam Lantinga
parent 7f84afa68b
commit e8fbb7e820

View File

@@ -2373,6 +2373,7 @@ static void METAL_BindGraphicsPipeline(
{
@autoreleasepool {
MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
MetalGraphicsPipeline *previousPipeline = metalCommandBuffer->graphics_pipeline;
MetalGraphicsPipeline *pipeline = (MetalGraphicsPipeline *)graphicsPipeline;
SDL_GPURasterizerState *rast = &pipeline->rasterizerState;
Uint32 i;
@@ -2415,6 +2416,17 @@ static void METAL_BindGraphicsPipeline(
metalCommandBuffer);
}
}
if (previousPipeline && previousPipeline != pipeline) {
// if the number of uniform buffers has changed, the storage buffers will move as well
// and need a rebind at their new locations
if (previousPipeline->header.num_vertex_uniform_buffers != pipeline->header.num_vertex_uniform_buffers) {
metalCommandBuffer->needVertexStorageBufferBind = true;
}
if (previousPipeline->header.num_fragment_uniform_buffers != pipeline->header.num_fragment_uniform_buffers) {
metalCommandBuffer->needFragmentStorageBufferBind = true;
}
}
}
}