nir: allow nir_lower_uniforms_to_ubo to be run repeatedly
authorMarek Olšák <marek.olsak@amd.com>
Fri, 18 Oct 2019 23:49:44 +0000 (19:49 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 22 Oct 2019 18:41:23 +0000 (14:41 -0400)
for st/mesa

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir_lower_uniforms_to_ubo.c
src/compiler/shader_info.h

index 2f6b23a248f147bdf57297327cad3d8cb765ffcb..7def01aad7eb331862b64a4695586f0a612f9a62 100644 (file)
@@ -43,7 +43,9 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b, int multiplier)
 {
    b->cursor = nir_before_instr(&instr->instr);
 
-   if (instr->intrinsic == nir_intrinsic_load_ubo) {
+   /* Increase all UBO binding points by 1. */
+   if (instr->intrinsic == nir_intrinsic_load_ubo &&
+       !b->shader->info.first_ubo_is_default_ubo) {
       nir_ssa_def *old_idx = nir_ssa_for_src(b, instr->src[0], 1);
       nir_ssa_def *new_idx = nir_iadd(b, old_idx, nir_imm_int(b, 1));
       nir_instr_rewrite_src(&instr->instr, &instr->src[0],
@@ -99,6 +101,7 @@ nir_lower_uniforms_to_ubo(nir_shader *shader, int multiplier)
       }
    }
 
+   shader->info.first_ubo_is_default_ubo = true;
    return progress;
 }
 
index 1de583e60107ff879c8ea605b8d49cb847dfe09c..e8c875f333f665a8ed47f40f590d1d0b19314f86 100644 (file)
@@ -151,6 +151,9 @@ typedef struct shader_info {
    /* The size of the gl_CullDistance[] array, if declared. */
    unsigned cull_distance_array_size;
 
+   /* Whether the first UBO is the default uniform buffer, i.e. uniforms. */
+   bool first_ubo_is_default_ubo;
+
    /* Whether or not separate shader objects were used */
    bool separate_shader;