ac: add load_resource() to the ABI
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 9 Feb 2018 12:54:23 +0000 (13:54 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 12 Feb 2018 10:54:13 +0000 (11:54 +0100)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_nir_to_llvm.c
src/amd/common/ac_shader_abi.h

index 406f55d8c4013b8acacf94e2a76a98e8adb1f25e..f99c9d3d6928b946b1622e7fa5e281c8c03065e5 100644 (file)
@@ -2351,12 +2351,11 @@ static LLVMValueRef build_tex_intrinsic(struct ac_nir_context *ctx,
        return ac_build_image_opcode(&ctx->ac, args);
 }
 
-static LLVMValueRef visit_vulkan_resource_index(struct nir_to_llvm_context *ctx,
-                                                nir_intrinsic_instr *instr)
+static LLVMValueRef
+radv_load_resource(struct ac_shader_abi *abi, LLVMValueRef index,
+                  unsigned desc_set, unsigned binding)
 {
-       LLVMValueRef index = get_src(ctx->nir, instr->src[0]);
-       unsigned desc_set = nir_intrinsic_desc_set(instr);
-       unsigned binding = nir_intrinsic_binding(instr);
+       struct nir_to_llvm_context *ctx = nir_to_llvm_context_from_abi(abi);
        LLVMValueRef desc_ptr = ctx->descriptor_sets[desc_set];
        struct radv_pipeline_layout *pipeline_layout = ctx->options->layout;
        struct radv_descriptor_set_layout *layout = pipeline_layout->set[desc_set].layout;
@@ -4386,9 +4385,15 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
        case nir_intrinsic_load_push_constant:
                result = visit_load_push_constant(ctx->nctx, instr);
                break;
-       case nir_intrinsic_vulkan_resource_index:
-               result = visit_vulkan_resource_index(ctx->nctx, instr);
+       case nir_intrinsic_vulkan_resource_index: {
+               LLVMValueRef index = get_src(ctx, instr->src[0]);
+               unsigned desc_set = nir_intrinsic_desc_set(instr);
+               unsigned binding = nir_intrinsic_binding(instr);
+
+               result = ctx->abi->load_resource(ctx->abi, index, desc_set,
+                                                binding);
                break;
+       }
        case nir_intrinsic_vulkan_resource_reindex:
                result = visit_vulkan_resource_reindex(ctx->nctx, instr);
                break;
@@ -6781,6 +6786,7 @@ LLVMModuleRef ac_translate_nir_to_llvm(LLVMTargetMachineRef tm,
        ctx.abi.load_ubo = radv_load_ubo;
        ctx.abi.load_ssbo = radv_load_ssbo;
        ctx.abi.load_sampler_desc = radv_get_sampler_desc;
+       ctx.abi.load_resource = radv_load_resource;
        ctx.abi.clamp_shadow_reference = false;
 
        if (shader_count >= 2)
index c5f7fcd2f8766b44c962caf0ca212896559ea658..c89987c35f8b41fd4c3ecc5d48f906d05f76c149 100644 (file)
@@ -156,6 +156,18 @@ struct ac_shader_abi {
                                          enum ac_descriptor_type desc_type,
                                          bool image, bool write);
 
+       /**
+        * Load a Vulkan-specific resource.
+        *
+        * \param index resource index
+        * \param desc_set descriptor set
+        * \param binding descriptor set binding
+        */
+       LLVMValueRef (*load_resource)(struct ac_shader_abi *abi,
+                                     LLVMValueRef index,
+                                     unsigned desc_set,
+                                     unsigned binding);
+
        LLVMValueRef (*lookup_interp_param)(struct ac_shader_abi *abi,
                                            enum glsl_interp_mode interp,
                                            unsigned location);