zink: always compile shaders in pipeline order
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 30 Jun 2020 13:59:57 +0000 (09:59 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 7 Aug 2020 12:36:59 +0000 (12:36 +0000)
in order to accurately perform slot/location mapping that's consistent across
stages, we need to go through the stages in order so that we can pass each successive
slot map allocation along to the next compiled stage

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5970>

src/gallium/drivers/zink/zink_program.c

index f6b3acdc84d20cab17b5a68e6bb64f5c69d929c8..550c0506f423407606060fb67e5193755429f707 100644 (file)
@@ -138,20 +138,24 @@ update_shader_modules(struct zink_context *ctx, struct zink_shader *stages[ZINK_
 {
    struct zink_shader *dirty[ZINK_SHADER_COUNT] = {NULL};
 
+   /* we need to map pipe_shader_type -> gl_shader_stage so we can ensure that we're compiling
+    * the shaders in pipeline order and have builtin input/output locations match up after being compacted
+    */
    unsigned dirty_shader_stages = ctx->dirty_shader_stages;
    while (dirty_shader_stages) {
       unsigned type = u_bit_scan(&dirty_shader_stages);
-      dirty[type] = stages[type];
+      dirty[tgsi_processor_to_shader_stage(type)] = stages[type];
    }
    for (int i = 0; i < ZINK_SHADER_COUNT; ++i) {
+      enum pipe_shader_type type = pipe_shader_type_from_mesa(i);
       if (dirty[i]) {
-         prog->stages[i] = CALLOC_STRUCT(zink_shader_module);
-         assert(prog->stages[i]);
-         pipe_reference_init(&prog->stages[i]->reference, 1);
-         prog->stages[i]->shader = zink_shader_compile(zink_screen(ctx->base.screen), stages[i]);
-      } else if (stages[i]) /* reuse existing shader module */
-         zink_shader_module_reference(zink_screen(ctx->base.screen), &prog->stages[i], ctx->curr_program->stages[i]);
-      prog->shaders[i] = stages[i];
+         prog->stages[type] = CALLOC_STRUCT(zink_shader_module);
+         assert(prog->stages[type]);
+         pipe_reference_init(&prog->stages[type]->reference, 1);
+         prog->stages[type]->shader = zink_shader_compile(zink_screen(ctx->base.screen), dirty[i]);
+      } else if (stages[type]) /* reuse existing shader module */
+         zink_shader_module_reference(zink_screen(ctx->base.screen), &prog->stages[type], ctx->curr_program->stages[type]);
+      prog->shaders[type] = stages[type];
    }
    ctx->dirty_shader_stages = 0;
 }