radeonsi/nir: implement ac_shader_abi::load_sampler_desc
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 8 Jun 2017 23:52:06 +0000 (01:52 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Mon, 31 Jul 2017 12:55:38 +0000 (14:55 +0200)
v2: remove enum desc_type from radeonsi (Marek)

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_nir.c
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c

index 81cc018af22d24d54a02ccc750de9a9aa29eb701..1483ebc5db42cb09a366528271c6c4ff5d52a0d0 100644 (file)
@@ -314,6 +314,10 @@ 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);
 
+LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
+                                 LLVMValueRef list, LLVMValueRef index,
+                                 enum ac_descriptor_type type);
+
 void si_llvm_load_input_vs(
        struct si_shader_context *ctx,
        unsigned input_index,
index eec5ac15d1b15d68f65c808dd3940b6ecd81545c..22c7e238456d4b4d52d495e06ad534ba5b3ee06e 100644 (file)
@@ -342,6 +342,37 @@ static void declare_nir_input_fs(struct si_shader_context *ctx,
        (*fs_attr_idx)++;
 }
 
+static LLVMValueRef
+si_nir_load_sampler_desc(struct ac_shader_abi *abi,
+                        unsigned descriptor_set, unsigned base_index,
+                        unsigned constant_index, LLVMValueRef dynamic_index,
+                        enum ac_descriptor_type desc_type)
+{
+       struct si_shader_context *ctx = si_shader_context_from_abi(abi);
+       LLVMBuilderRef builder = ctx->ac.builder;
+       LLVMValueRef list = LLVMGetParam(ctx->main_fn, ctx->param_samplers_and_images);
+       LLVMValueRef index = dynamic_index;
+
+       assert(!descriptor_set);
+
+       if (!index)
+               index = ctx->ac.i32_0;
+
+       index = LLVMBuildAdd(builder, index,
+                            LLVMConstInt(ctx->ac.i32, base_index + constant_index, false),
+                            "");
+
+       assert(base_index + constant_index < ctx->num_samplers);
+
+       if (dynamic_index)
+               index = si_llvm_bound_index(ctx, index, ctx->num_samplers);
+
+       index = LLVMBuildAdd(ctx->gallivm.builder, index,
+                            LLVMConstInt(ctx->i32, SI_NUM_IMAGES / 2, 0), "");
+
+       return si_load_sampler_desc(ctx, list, index, desc_type);
+}
+
 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir)
 {
        unsigned fs_attr_idx = 0;
@@ -366,6 +397,7 @@ bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir)
        }
 
        ctx->abi.inputs = &ctx->inputs[0];
+       ctx->abi.load_sampler_desc = si_nir_load_sampler_desc;
 
        ac_nir_translate(&ctx->ac, &ctx->abi, nir, NULL);
 
index 3b50ca5341469865bc90d9741cb20cfd9c2eee55..e5afeb0644546dd972de2fed70f37c48ae52210d 100644 (file)
@@ -37,13 +37,6 @@ static void build_tex_intrinsic(const struct lp_build_tgsi_action *action,
 
 static const struct lp_build_tgsi_action tex_action;
 
-enum desc_type {
-       DESC_IMAGE,
-       DESC_BUFFER,
-       DESC_FMASK,
-       DESC_SAMPLER,
-};
-
 /**
  * Given a v8i32 resource descriptor for a buffer, extract the size of the
  * buffer in number of elements and return it as an i32.
@@ -1127,31 +1120,31 @@ static void resq_emit(
 /**
  * Load an image view, fmask view. or sampler state descriptor.
  */
-static LLVMValueRef load_sampler_desc(struct si_shader_context *ctx,
-                                     LLVMValueRef list, LLVMValueRef index,
-                                     enum desc_type type)
+LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
+                                 LLVMValueRef list, LLVMValueRef index,
+                                 enum ac_descriptor_type type)
 {
        struct gallivm_state *gallivm = &ctx->gallivm;
        LLVMBuilderRef builder = gallivm->builder;
 
        switch (type) {
-       case DESC_IMAGE:
+       case AC_DESC_IMAGE:
                /* The image is at [0:7]. */
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 2, 0), "");
                break;
-       case DESC_BUFFER:
+       case AC_DESC_BUFFER:
                /* The buffer is in [4:7]. */
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), "");
                index = LLVMBuildAdd(builder, index, ctx->i32_1, "");
                list = LLVMBuildPointerCast(builder, list,
                                            si_const_array(ctx->v4i32, 0), "");
                break;
-       case DESC_FMASK:
+       case AC_DESC_FMASK:
                /* The FMASK is at [8:15]. */
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 2, 0), "");
                index = LLVMBuildAdd(builder, index, ctx->i32_1, "");
                break;
-       case DESC_SAMPLER:
+       case AC_DESC_SAMPLER:
                /* The sampler state is at [12:15]. */
                index = LLVMBuildMul(builder, index, LLVMConstInt(ctx->i32, 4, 0), "");
                index = LLVMBuildAdd(builder, index, LLVMConstInt(ctx->i32, 3, 0), "");
@@ -1233,9 +1226,9 @@ static void tex_fetch_ptrs(
        }
 
        if (target == TGSI_TEXTURE_BUFFER)
-               *res_ptr = load_sampler_desc(ctx, list, index, DESC_BUFFER);
+               *res_ptr = si_load_sampler_desc(ctx, list, index, AC_DESC_BUFFER);
        else
-               *res_ptr = load_sampler_desc(ctx, list, index, DESC_IMAGE);
+               *res_ptr = si_load_sampler_desc(ctx, list, index, AC_DESC_IMAGE);
 
        if (samp_ptr)
                *samp_ptr = NULL;
@@ -1245,12 +1238,12 @@ static void tex_fetch_ptrs(
        if (target == TGSI_TEXTURE_2D_MSAA ||
            target == TGSI_TEXTURE_2D_ARRAY_MSAA) {
                if (fmask_ptr)
-                       *fmask_ptr = load_sampler_desc(ctx, list, index,
-                                                      DESC_FMASK);
+                       *fmask_ptr = si_load_sampler_desc(ctx, list, index,
+                                                         AC_DESC_FMASK);
        } else if (target != TGSI_TEXTURE_BUFFER) {
                if (samp_ptr) {
-                       *samp_ptr = load_sampler_desc(ctx, list, index,
-                                                     DESC_SAMPLER);
+                       *samp_ptr = si_load_sampler_desc(ctx, list, index,
+                                                        AC_DESC_SAMPLER);
                        *samp_ptr = sici_fix_sampler_aniso(ctx, *res_ptr, *samp_ptr);
                }
        }