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

---
 src/gallium/drivers/radeonsi/si_shader.c          | 11 ++++++++--
 src/gallium/drivers/radeonsi/si_shader_internal.h |  5 +++++
 src/gallium/drivers/radeonsi/si_shader_nir.c      | 26 +++++++++++++++++++++++
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index e97e0ee..b7ea131 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -337,24 +337,23 @@ static LLVMValueRef extract_double_to_float(struct 
si_shader_context *ctx,
 {
        LLVMBuilderRef builder = ctx->gallivm.builder;
        LLVMTypeRef f64 = LLVMDoubleTypeInContext(ctx->gallivm.context);
        LLVMValueRef dvec2 = LLVMBuildBitCast(builder, vec4,
                                              LLVMVectorType(f64, 2), "");
        LLVMValueRef index = LLVMConstInt(ctx->i32, double_index, 0);
        LLVMValueRef value = LLVMBuildExtractElement(builder, dvec2, index, "");
        return LLVMBuildFPTrunc(builder, value, ctx->f32, "");
 }
 
-static void declare_input_vs(
+void si_llvm_load_input_vs(
        struct si_shader_context *ctx,
        unsigned input_index,
-       const struct tgsi_full_declaration *decl,
        LLVMValueRef out[4])
 {
        struct gallivm_state *gallivm = &ctx->gallivm;
 
        unsigned chan;
        unsigned fix_fetch;
        unsigned num_fetches;
        unsigned fetch_stride;
 
        LLVMValueRef t_list_ptr;
@@ -543,20 +542,28 @@ static void declare_input_vs(
                    fix_fetch == SI_FIX_FETCH_RGB_16) {
                        out[3] = LLVMConstReal(ctx->f32, 1);
                } else {
                        out[3] = LLVMBuildBitCast(gallivm->builder, ctx->i32_1,
                                                  ctx->f32, "");
                }
                break;
        }
 }
 
+static void declare_input_vs(
+       struct si_shader_context *ctx,
+       unsigned input_index,
+       const struct tgsi_full_declaration *decl,
+       LLVMValueRef out[4])
+{
+       si_llvm_load_input_vs(ctx, input_index, out);
+}
 
 static LLVMValueRef get_primitive_id(struct si_shader_context *ctx,
                                     unsigned swizzle)
 {
        if (swizzle > 0)
                return ctx->i32_0;
 
        switch (ctx->type) {
        case PIPE_SHADER_VERTEX:
                return LLVMGetParam(ctx->main_fn,
diff --git a/src/gallium/drivers/radeonsi/si_shader_internal.h 
b/src/gallium/drivers/radeonsi/si_shader_internal.h
index c8dcd5c..99d17c2 100644
--- a/src/gallium/drivers/radeonsi/si_shader_internal.h
+++ b/src/gallium/drivers/radeonsi/si_shader_internal.h
@@ -306,13 +306,18 @@ void si_emit_waitcnt(struct si_shader_context *ctx, 
unsigned simm16);
 
 LLVMValueRef si_get_bounded_indirect_index(struct si_shader_context *ctx,
                                           const struct tgsi_ind_register *ind,
                                           int rel_index, unsigned num);
 
 LLVMTypeRef si_const_array(LLVMTypeRef elem_type, int num_elements);
 
 void si_shader_context_init_alu(struct lp_build_tgsi_context *bld_base);
 void si_shader_context_init_mem(struct si_shader_context *ctx);
 
+void si_llvm_load_input_vs(
+       struct si_shader_context *ctx,
+       unsigned input_index,
+       LLVMValueRef out[4]);
+
 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir);
 
 #endif
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c 
b/src/gallium/drivers/radeonsi/si_shader_nir.c
index cc7517b..8b8baac 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -306,16 +306,42 @@ 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);
        }
 }
 
+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);
+}
+
 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir)
 {
+       nir_foreach_variable(variable, &nir->inputs) {
+               unsigned attrib_count = 
glsl_count_attribute_slots(variable->type,
+                                                                  nir->stage 
== MESA_SHADER_VERTEX);
+               unsigned input_idx = variable->data.driver_location;
+
+               for (unsigned i = 0; i < attrib_count; ++i) {
+                       LLVMValueRef data[4];
+
+                       declare_nir_input_vs(ctx, variable, i, data);
+
+                       for (unsigned chan = 0; chan < 4; chan++) {
+                               ctx->inputs[input_idx + chan] =
+                                       LLVMBuildBitCast(ctx->ac.builder, 
data[chan], ctx->ac.i32, "");
+                       }
+               }
+       }
+
+       ctx->abi.inputs = &ctx->inputs[0];
+
        ac_nir_translate(&ctx->ac, &ctx->abi, nir, NULL);
 
        return true;
 }
-- 
2.9.3

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

Reply via email to