radeonsi/nir: perform lowering of input/output driver locations
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Sat, 24 Jun 2017 15:30:16 +0000 (17:30 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 31 Jul 2017 12:55:40 +0000 (14:55 +0200)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_shader_nir.c
src/gallium/drivers/radeonsi/si_state_shaders.c

index 339e156b1685fc6f86f7c4369ea2f7d0c9435b1a..e44d71c2614aa83294e7cabfcac081e650a8c5ce 100644 (file)
@@ -635,6 +635,7 @@ const char *si_get_shader_name(const struct si_shader *shader, unsigned processo
 /* si_shader_nir.c */
 void si_nir_scan_shader(const struct nir_shader *nir,
                        struct tgsi_shader_info *info);
+void si_lower_nir(struct si_shader_selector *sel);
 
 /* Inline helpers. */
 
index 076fce818a4edaafd0a19dca627ce7da7da8c82d..2c311d3865d9fd0b419e36cded71df6a35232c95 100644 (file)
@@ -313,6 +313,32 @@ void si_nir_scan_shader(const struct nir_shader *nir,
        }
 }
 
+/**
+ * Perform "lowering" operations on the NIR that are run once when the shader
+ * selector is created.
+ */
+void
+si_lower_nir(struct si_shader_selector* sel)
+{
+       /* Adjust the driver location of inputs and outputs. The state tracker
+        * interprets them as slots, while the ac/nir backend interprets them
+        * as individual components.
+        */
+       nir_foreach_variable(variable, &sel->nir->inputs)
+               variable->data.driver_location *= 4;
+
+       nir_foreach_variable(variable, &sel->nir->outputs) {
+               variable->data.driver_location *= 4;
+
+               if (sel->nir->stage == MESA_SHADER_FRAGMENT) {
+                       if (variable->data.location == FRAG_RESULT_DEPTH)
+                               variable->data.driver_location += 2;
+                       else if (variable->data.location == FRAG_RESULT_STENCIL)
+                               variable->data.driver_location += 1;
+               }
+       }
+}
+
 static void declare_nir_input_vs(struct si_shader_context *ctx,
                                 struct nir_variable *variable, unsigned rel,
                                 LLVMValueRef out[4])
index 5a0ead1313a55614c6b69d1fc04920283929b344..8a795c0faefe17f9f5e50ba7912647642314ee70 100644 (file)
@@ -1989,6 +1989,8 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
                sel->nir = state->ir.nir;
 
                si_nir_scan_shader(sel->nir, &sel->info);
+
+               si_lower_nir(sel);
        }
 
        sel->type = sel->info.processor;