Procházet zdrojové kódy

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

(cherry picked from commit 73c9f25867e60c8a7c18ff9b427c1c5e7ffdc8be)
Jakub Wasilewski před 2 měsíci
rodič
revize
e8fbb7e820
1 změnil soubory, kde provedl 12 přidání a 0 odebrání
  1. 12 0
      src/gpu/metal/SDL_gpu_metal.m

+ 12 - 0
src/gpu/metal/SDL_gpu_metal.m

@@ -2373,6 +2373,7 @@ static void METAL_BindGraphicsPipeline(
 {
 {
     @autoreleasepool {
     @autoreleasepool {
         MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
         MetalCommandBuffer *metalCommandBuffer = (MetalCommandBuffer *)commandBuffer;
+        MetalGraphicsPipeline *previousPipeline = metalCommandBuffer->graphics_pipeline;
         MetalGraphicsPipeline *pipeline = (MetalGraphicsPipeline *)graphicsPipeline;
         MetalGraphicsPipeline *pipeline = (MetalGraphicsPipeline *)graphicsPipeline;
         SDL_GPURasterizerState *rast = &pipeline->rasterizerState;
         SDL_GPURasterizerState *rast = &pipeline->rasterizerState;
         Uint32 i;
         Uint32 i;
@@ -2415,6 +2416,17 @@ static void METAL_BindGraphicsPipeline(
                     metalCommandBuffer);
                     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;
+            }
+        }
     }
     }
 }
 }