v2: - rebased (is_bindless() -> contains_bindless()) - remove dead inst->bindless assignment - add missing comment
Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com> Reviewed-by: Marek Olšák <marek.ol...@amd.com> (v1) --- src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 75 ++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index d637dd803a..24ac177786 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 */ @@ -3764,15 +3764,47 @@ 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; + } 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->contains_bindless()); if (reladdr.file != PROGRAM_UNDEFINED) { image.reladdr = ralloc(mem_ctx, st_src_reg); @@ -3885,19 +3917,26 @@ 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->contains_bindless()) { + img->accept(this); + inst->resource = this->result; + inst->resource.swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, + SWIZZLE_X, SWIZZLE_Y); + } 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; } @@ -5910,7 +5949,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) @@ -5927,7 +5971,12 @@ 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 { + /* Bindless images. */ + 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); -- 2.13.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev