From 9b98d3652283cf986380ffe574523c2ef2eedba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Sat, 11 Apr 2020 14:50:50 +0200 Subject: [PATCH] v3dv/descriptor: handle not having a sampler when combining texture and sampler id There are some texture operations (like mipmap query levels) that doesn't require a sampler. In fact, you should ignore it. So we need to take it into account when combining the indexes. nir_tex_instr_src_index is returning a negative value to identify that case, but as we are using a uint32_t to pack both values (for convenience, easy to pack/unpack the hash table key), we just use a uint value big enough to be a wrong sampler id. Part-of: --- src/broadcom/vulkan/v3dv_cmd_buffer.c | 18 +++++++++++------- src/broadcom/vulkan/v3dv_pipeline.c | 4 +++- src/broadcom/vulkan/v3dv_private.h | 2 ++ src/broadcom/vulkan/v3dv_uniforms.c | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index f26cc6aa199..cd77f7e7793 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -1976,13 +1976,17 @@ cmd_buffer_populate_v3d_key(struct v3d_key *key, if (image_view == NULL) return false; - const struct v3dv_sampler *sampler = - v3dv_descriptor_map_get_sampler(descriptor_state, - sampler_map, - cmd_buffer->state.pipeline->layout, - sampler_idx); - if (sampler == NULL) - return false; + + const struct v3dv_sampler *sampler = NULL; + if (sampler_idx != V3DV_NO_SAMPLER_IDX) { + sampler = + v3dv_descriptor_map_get_sampler(descriptor_state, + sampler_map, + cmd_buffer->state.pipeline->layout, + sampler_idx); + if (sampler == NULL) + return false; + } key->tex[combined_idx].return_size = v3dv_get_tex_return_size(image_view->format, diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index b9b04039197..11538ac2127 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -639,7 +639,9 @@ lower_sampler(nir_builder *b, nir_tex_instr *instr, return false; int combined_index = - get_combined_index(pipeline, instr->texture_index, instr->sampler_index); + get_combined_index(pipeline, + instr->texture_index, + sampler_idx < 0 ? V3DV_NO_SAMPLER_IDX : instr->sampler_index); instr->texture_index = combined_index; instr->sampler_index = combined_index; diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index cbbebc298a7..14af1968244 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -1030,6 +1030,8 @@ struct v3dv_sampler { struct v3dv_bo *state; }; +#define V3DV_NO_SAMPLER_IDX 666 + /* * Following two methods are using on the combined to/from texture/sampler * indices maps at v3dv_pipeline. diff --git a/src/broadcom/vulkan/v3dv_uniforms.c b/src/broadcom/vulkan/v3dv_uniforms.c index 49fac70437f..83268bf6b86 100644 --- a/src/broadcom/vulkan/v3dv_uniforms.c +++ b/src/broadcom/vulkan/v3dv_uniforms.c @@ -127,6 +127,7 @@ write_tmu_p1(struct v3dv_cmd_buffer *cmd_buffer, v3dv_pipeline_combined_index_key_unpack(pipeline->combined_index_to_key_map[unit], NULL, &sampler_idx); + assert(sampler_idx != V3DV_NO_SAMPLER_IDX); const struct v3dv_sampler *sampler = v3dv_descriptor_map_get_sampler(descriptor_state, &pipeline->sampler_map,