From: Karol Herbst Date: Sun, 24 Mar 2019 16:11:34 +0000 (+0100) Subject: glsl_to_nir: handle bindless textures X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d7bbb3caf19e6e0f2dd47855babb8f5e91596e77;p=mesa.git glsl_to_nir: handle bindless textures v2: add support for AMD Signed-off-by: Karol Herbst Reviewed-by: Jason Ekstrand (v1) Reviewed-by: Timothy Arceri Reviewed-by: Marek Olšák --- diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c index 3d2f738edec..f5440d19e83 100644 --- a/src/amd/common/ac_nir_to_llvm.c +++ b/src/amd/common/ac_nir_to_llvm.c @@ -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) { diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index 6a1a0b5f113..89edaa41d27 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -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;