glsl_to_nir: handle bindless textures
authorKarol Herbst <kherbst@redhat.com>
Sun, 24 Mar 2019 16:11:34 +0000 (17:11 +0100)
committerKarol Herbst <kherbst@redhat.com>
Fri, 12 Apr 2019 07:02:59 +0000 (09:02 +0200)
v2: add support for AMD

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> (v1)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_nir_to_llvm.c
src/compiler/glsl/glsl_to_nir.cpp

index 3d2f738..f5440d1 100644 (file)
@@ -3498,9 +3498,17 @@ static LLVMValueRef get_sampler_desc(struct ac_nir_context *ctx,
        bool bindless = false;
 
        if (!deref_instr) {
-               assert(tex_instr && !image);
+               int sampSrcIdx = nir_tex_instr_src_index(tex_instr,
+                                                        nir_tex_src_sampler_handle);
                descriptor_set = 0;
-               base_index = tex_instr->sampler_index;
+               if (sampSrcIdx != -1) {
+                       base_index = 0;
+                       bindless = true;
+                       index = get_src(ctx, tex_instr->src[sampSrcIdx].src);
+               } else {
+                       assert(tex_instr && !image);
+                       base_index = tex_instr->sampler_index;
+               }
        } else {
                while(deref_instr->deref_type != nir_deref_type_var) {
                        if (deref_instr->deref_type == nir_deref_type_array) {
index 6a1a0b5..89edaa4 100644 (file)
@@ -2410,10 +2410,21 @@ nir_visitor::visit(ir_texture *ir)
    }
 
    nir_deref_instr *sampler_deref = evaluate_deref(ir->sampler);
-   instr->src[0].src = nir_src_for_ssa(&sampler_deref->dest.ssa);
-   instr->src[0].src_type = nir_tex_src_texture_deref;
-   instr->src[1].src = nir_src_for_ssa(&sampler_deref->dest.ssa);
-   instr->src[1].src_type = nir_tex_src_sampler_deref;
+
+   /* check for bindless handles */
+   if (sampler_deref->mode != nir_var_uniform ||
+       nir_deref_instr_get_variable(sampler_deref)->data.bindless) {
+      nir_ssa_def *load = nir_load_deref(&b, sampler_deref);
+      instr->src[0].src = nir_src_for_ssa(load);
+      instr->src[0].src_type = nir_tex_src_texture_handle;
+      instr->src[1].src = nir_src_for_ssa(load);
+      instr->src[1].src_type = nir_tex_src_sampler_handle;
+   } else {
+      instr->src[0].src = nir_src_for_ssa(&sampler_deref->dest.ssa);
+      instr->src[0].src_type = nir_tex_src_texture_deref;
+      instr->src[1].src = nir_src_for_ssa(&sampler_deref->dest.ssa);
+      instr->src[1].src_type = nir_tex_src_sampler_deref;
+   }
 
    unsigned src_number = 2;