[Mesa-dev] [PATCH v2 2/3] nir: add support for bindless_texture samplers

Karol Herbst kherbst at redhat.com
Thu Apr 12 14:36:22 UTC 2018


On Tue, Apr 10, 2018 at 5:10 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> On Tue, Apr 10, 2018 at 8:05 AM, Karol Herbst <kherbst at redhat.com> wrote:
>>
>> v2: add both texture and sampler handles
>>
>> Signed-off-by: Karol Herbst <kherbst at redhat.com>
>> ---
>>  src/compiler/glsl/glsl_to_nir.cpp | 17 +++++++++++++++--
>>  src/compiler/nir/nir.h            |  2 ++
>>  src/compiler/nir/nir_print.c      |  6 ++++++
>>  3 files changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/compiler/glsl/glsl_to_nir.cpp
>> b/src/compiler/glsl/glsl_to_nir.cpp
>> index dbb58d82e8f..9f233637306 100644
>> --- a/src/compiler/glsl/glsl_to_nir.cpp
>> +++ b/src/compiler/glsl/glsl_to_nir.cpp
>> @@ -1971,6 +1971,8 @@ nir_visitor::visit(ir_texture *ir)
>>  {
>>     unsigned num_srcs;
>>     nir_texop op;
>> +   bool bindless =
>> ir->sampler->variable_referenced()->contains_bindless();
>
>
> What happens if I have a uniform struct containing both a regular sampler
> and a bindless sampler?  I think this should be possible.
>

well currently mesa just fails to compile, but even if it would I
don't see a way how we know with a ir_dereference if we reference a
bindless or bound sampler.

The glsl_type doesn't tell us either and maybe it makes sense to add a
is_bindless method to glsl_type so that we can use it in places like
here? ir->sampler->type gives me the sampler type, but lacks the
information if it is bindless or not. Any thoughts?

>>
>> +
>>     switch (ir->op) {
>>     case ir_tex:
>>        op = nir_texop_tex;
>> @@ -2044,6 +2046,8 @@ nir_visitor::visit(ir_texture *ir)
>>        num_srcs++;
>>     if (ir->offset != NULL)
>>        num_srcs++;
>> +   if (bindless)
>> +      num_srcs++;
>>
>>     nir_tex_instr *instr = nir_tex_instr_create(this->shader, num_srcs);
>>
>> @@ -2069,10 +2073,19 @@ nir_visitor::visit(ir_texture *ir)
>>        unreachable("not reached");
>>     }
>>
>> -   instr->texture = evaluate_deref(&instr->instr, ir->sampler);
>> -
>>     unsigned src_number = 0;
>>
>> +   /* for bindless we use the texture handle src */
>> +   if (bindless) {
>> +      instr->texture = NULL;
>> +      instr->src[src_number].src =
>> +         nir_src_for_ssa(evaluate_rvalue(ir->sampler));
>> +      instr->src[src_number].src_type = nir_tex_src_texture_handle;
>> +      src_number++;
>> +   } else {
>> +      instr->texture = evaluate_deref(&instr->instr, ir->sampler);
>> +   }
>> +
>>     if (ir->coordinate != NULL) {
>>        instr->coord_components = ir->coordinate->type->vector_elements;
>>        instr->src[src_number].src =
>> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
>> index f33049d7134..e395352f89c 100644
>> --- a/src/compiler/nir/nir.h
>> +++ b/src/compiler/nir/nir.h
>> @@ -1218,6 +1218,8 @@ typedef enum {
>>     nir_tex_src_texture_offset, /* < dynamically uniform indirect offset
>> */
>>     nir_tex_src_sampler_offset, /* < dynamically uniform indirect offset
>> */
>>     nir_tex_src_plane,          /* < selects plane for planar textures */
>> +   nir_tex_src_texture_handle, /* < handle for bindless texture */
>> +   nir_tex_src_sampler_handle, /* < handle for bindless sampler */
>>     nir_num_tex_src_types
>>  } nir_tex_src_type;
>>
>> diff --git a/src/compiler/nir/nir_print.c b/src/compiler/nir/nir_print.c
>> index 21f13097651..52f20b1eb10 100644
>> --- a/src/compiler/nir/nir_print.c
>> +++ b/src/compiler/nir/nir_print.c
>> @@ -778,6 +778,12 @@ print_tex_instr(nir_tex_instr *instr, print_state
>> *state)
>>        case nir_tex_src_plane:
>>           fprintf(fp, "(plane)");
>>           break;
>> +      case nir_tex_src_texture_handle:
>> +         fprintf(fp, "(texture_handle)");
>> +         break;
>> +      case nir_tex_src_sampler_handle:
>> +         fprintf(fp, "(sampler_handle)");
>> +         break;
>>
>>        default:
>>           unreachable("Invalid texture source type");
>> --
>> 2.14.3
>>
>


More information about the mesa-dev mailing list