From: Nicolai Hähnle <nicolai.haeh...@amd.com>

---
 src/gallium/drivers/radeonsi/si_shader.h        |  1 +
 src/gallium/drivers/radeonsi/si_shader_nir.c    | 26 +++++++++++++++++++++++++
 src/gallium/drivers/radeonsi/si_state_shaders.c |  2 ++
 3 files changed, 29 insertions(+)

diff --git a/src/gallium/drivers/radeonsi/si_shader.h 
b/src/gallium/drivers/radeonsi/si_shader.h
index 4881bae..f1a1af3 100644
--- a/src/gallium/drivers/radeonsi/si_shader.h
+++ b/src/gallium/drivers/radeonsi/si_shader.h
@@ -615,20 +615,21 @@ void si_shader_apply_scratch_relocs(struct si_shader 
*shader,
 void si_shader_binary_read_config(struct ac_shader_binary *binary,
                                  struct si_shader_config *conf,
                                  unsigned symbol_offset);
 unsigned si_get_spi_shader_z_format(bool writes_z, bool writes_stencil,
                                    bool writes_samplemask);
 const char *si_get_shader_name(const struct si_shader *shader, unsigned 
processor);
 
 /* 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. */
 
 /* Return the pointer to the main shader part's pointer. */
 static inline struct si_shader **
 si_get_main_shader_part(struct si_shader_selector *sel,
                        struct si_shader_key *key)
 {
        if (key->as_ls)
                return &sel->main_shader_part_ls;
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c 
b/src/gallium/drivers/radeonsi/si_shader_nir.c
index f02abab..dc2ef8b 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -306,20 +306,46 @@ void si_nir_scan_shader(const struct nir_shader *nir,
        info->const_buffers_declared = u_bit_consecutive(0, 
SI_NUM_CONST_BUFFERS);
        info->shader_buffers_declared = u_bit_consecutive(0, 
SI_NUM_SHADER_BUFFERS);
 
        func = (struct nir_function *)exec_list_get_head_const(&nir->functions);
        nir_foreach_block(block, func->impl) {
                nir_foreach_instr(instr, block)
                        scan_instruction(info, instr);
        }
 }
 
+/**
+ * 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])
 {
        si_llvm_load_input_vs(ctx, variable->data.driver_location / 4 + rel, 
out);
 }
 
 static void declare_nir_input_fs(struct si_shader_context *ctx,
                                 struct nir_variable *variable, unsigned rel,
                                 unsigned *fs_attr_idx,
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c 
b/src/gallium/drivers/radeonsi/si_state_shaders.c
index e1a31ad..afa78eb 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -1979,20 +1979,22 @@ static void *si_create_shader_selector(struct 
pipe_context *ctx,
                        return NULL;
                }
 
                tgsi_scan_shader(state->tokens, &sel->info);
        } else {
                assert(state->type == PIPE_SHADER_IR_NIR);
 
                sel->nir = state->ir.nir;
 
                si_nir_scan_shader(sel->nir, &sel->info);
+
+               si_lower_nir(sel);
        }
 
        sel->type = sel->info.processor;
        p_atomic_inc(&sscreen->b.num_shaders_created);
        si_get_active_slot_masks(&sel->info,
                                 &sel->active_const_and_shader_buffers,
                                 &sel->active_samplers_and_images);
 
        /* Record which streamout buffers are enabled. */
        for (i = 0; i < sel->so.num_outputs; i++) {
-- 
2.9.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to