[Mesa-dev] [RFC PATCH 33/65] st/glsl_to_tgsi: add support for bindless images

Samuel Pitoiset samuel.pitoiset at gmail.com
Thu May 25 12:08:26 UTC 2017



On 05/24/2017 01:34 PM, Nicolai Hähnle wrote:
> On 19.05.2017 18:52, Samuel Pitoiset wrote:
>> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
>> ---
>>   src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 78 
>> ++++++++++++++++++++++++------
>>   1 file changed, 63 insertions(+), 15 deletions(-)
>>
>> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
>> b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> index 5734d0e456..264b43c10b 100644
>> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> @@ -288,7 +288,7 @@ public:
>>      st_dst_reg dst[2];
>>      st_src_reg src[4];
>> -   st_src_reg resource; /**< sampler or buffer register */
>> +   st_src_reg resource; /**< sampler, image or buffer register */
>>      st_src_reg *tex_offsets;
>>      /** Pointer to the ir source this tree came from for debugging */
>> @@ -3765,15 +3765,46 @@ 
>> glsl_to_tgsi_visitor::visit_image_intrinsic(ir_call *ir)
>>      exec_node *param = ir->actual_parameters.get_head();
>>      ir_dereference *img = (ir_dereference *)param;
>> -   const ir_variable *imgvar = img->variable_referenced();
>> -   const glsl_type *type = imgvar->type->without_array();
>> +   const struct glsl_struct_field *struct_field = NULL;
>>      unsigned sampler_array_size = 1, sampler_base = 0;
>> +   unsigned memory_coherent, memory_volatile, memory_restrict, 
>> image_format;
>> +   const ir_variable *imgvar;
>> +   const glsl_type *type;
>> +
>> +   if (img->ir_type == ir_type_dereference_record) {
>> +      ir_dereference_record *r = img->as_dereference_record();
>> +      const glsl_type *struct_type = r->record->type;
>> +
>> +      for (unsigned i = 0; i < struct_type->length; i++) {
>> +         if (!strcmp(struct_type->fields.structure[i].name, r->field)) {
>> +            struct_field = &struct_type->fields.structure[i];
>> +            break;
>> +         }
>> +      }
>> +      assert(struct_field);
>> +   }
>> +
>> +   imgvar = img->variable_referenced();
>> +
>> +   if (struct_field) {
>> +      type = struct_field->type;
>> +      memory_coherent = struct_field->memory_coherent;
>> +      memory_volatile = struct_field->memory_volatile;
>> +      memory_restrict = struct_field->memory_restrict;
>> +      image_format = struct_field->image_format;
>> +   } else {
>> +      type = imgvar->type->without_array();
>> +      memory_coherent = imgvar->data.memory_coherent;
>> +      memory_volatile = imgvar->data.memory_volatile;
>> +      memory_restrict = imgvar->data.memory_restrict;
>> +      image_format = imgvar->data.image_format;
>> +   }
> 
> What about
> 
>     struct {
>        coherent image2D imgs[6];
>     } s;
> 
>     imageStore(s.imgs[i], ...);
> 
> and obviously nested arrays. I think you need to follow the dereferences 
> until you hit the first ir_dereference_record or ir_dereference_variable.

This is right. I'm going to fix it up.

> 
> Cheers,
> Nicolai
> 
> 
>>      st_src_reg reladdr;
>>      st_src_reg image(PROGRAM_IMAGE, 0, GLSL_TYPE_UINT);
>>      get_deref_offsets(img, &sampler_array_size, &sampler_base,
>> -                     (uint16_t*)&image.index, &reladdr, true);
>> +                     (uint16_t*)&image.index, &reladdr, 
>> !imgvar->is_bindless());
>>      if (reladdr.file != PROGRAM_UNDEFINED) {
>>         image.reladdr = ralloc(mem_ctx, st_src_reg);
>> @@ -3886,19 +3917,27 @@ 
>> glsl_to_tgsi_visitor::visit_image_intrinsic(ir_call *ir)
>>            inst->dst[0].writemask = WRITEMASK_XYZW;
>>      }
>> -   inst->resource = image;
>> -   inst->sampler_array_size = sampler_array_size;
>> -   inst->sampler_base = sampler_base;
>> +   if (imgvar->is_bindless()) {
>> +      img->accept(this);
>> +      inst->resource = this->result;
>> +      inst->resource.swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y,
>> +                                             SWIZZLE_X, SWIZZLE_Y);
>> +      inst->bindless = 1;
>> +   } else {
>> +      inst->resource = image;
>> +      inst->sampler_array_size = sampler_array_size;
>> +      inst->sampler_base = sampler_base;
>> +   }
>>      inst->tex_target = type->sampler_index();
>>      inst->image_format = st_mesa_format_to_pipe_format(st_context(ctx),
>> -         _mesa_get_shader_image_format(imgvar->data.image_format));
>> +         _mesa_get_shader_image_format(image_format));
>> -   if (imgvar->data.memory_coherent)
>> +   if (memory_coherent)
>>         inst->buffer_access |= TGSI_MEMORY_COHERENT;
>> -   if (imgvar->data.memory_restrict)
>> +   if (memory_restrict)
>>         inst->buffer_access |= TGSI_MEMORY_RESTRICT;
>> -   if (imgvar->data.memory_volatile)
>> +   if (memory_volatile)
>>         inst->buffer_access |= TGSI_MEMORY_VOLATILE;
>>   }
>> @@ -5911,7 +5950,12 @@ compile_tgsi_instruction(struct st_translate *t,
>>         } else if (inst->resource.file == PROGRAM_BUFFER) {
>>            src[0] = t->buffers[inst->resource.index];
>>         } else {
>> -         src[0] = t->images[inst->resource.index];
>> +         if (inst->resource.file == PROGRAM_IMAGE) {
>> +            src[0] = t->images[inst->resource.index];
>> +         } else {
>> +            /* Bindless images. */
>> +            src[0] = translate_src(t, &inst->resource);
>> +         }
>>            tex_target = st_translate_texture_target(inst->tex_target, 
>> inst->tex_shadow);
>>         }
>>         if (inst->resource.reladdr)
>> @@ -5919,7 +5963,7 @@ compile_tgsi_instruction(struct st_translate *t,
>>         assert(src[0].File != TGSI_FILE_NULL);
>>         ureg_memory_insn(ureg, inst->op, dst, num_dst, src, num_src,
>>                          inst->buffer_access,
>> -                       tex_target, inst->image_format, 0);
>> +                       tex_target, inst->image_format, inst->bindless);
>>         break;
>>      case TGSI_OPCODE_STORE:
>> @@ -5928,7 +5972,11 @@ compile_tgsi_instruction(struct st_translate *t,
>>         } else if (inst->resource.file == PROGRAM_BUFFER) {
>>            dst[0] = ureg_dst(t->buffers[inst->resource.index]);
>>         } else {
>> -         dst[0] = ureg_dst(t->images[inst->resource.index]);
>> +         if (inst->resource.file == PROGRAM_IMAGE) {
>> +            dst[0] = ureg_dst(t->images[inst->resource.index]);
>> +         } else {
>> +            dst[0] = ureg_dst(translate_src(t, &inst->resource));
>> +         }
>>            tex_target = st_translate_texture_target(inst->tex_target, 
>> inst->tex_shadow);
>>         }
>>         dst[0] = ureg_writemask(dst[0], inst->dst[0].writemask);
>> @@ -5937,7 +5985,7 @@ compile_tgsi_instruction(struct st_translate *t,
>>         assert(dst[0].File != TGSI_FILE_NULL);
>>         ureg_memory_insn(ureg, inst->op, dst, num_dst, src, num_src,
>>                          inst->buffer_access,
>> -                       tex_target, inst->image_format, 0);
>> +                       tex_target, inst->image_format, inst->bindless);
>>         break;
>>      case TGSI_OPCODE_SCS:
>>
> 
> 


More information about the mesa-dev mailing list