From 7ca64c1c4df4ac736dcca556035fa65d800d40bb Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 1 Apr 2021 16:50:45 -0400 Subject: [PATCH] zink: move more vertex state stuff into the hw state this simplifies a lot of the hashing since only the vertex state pointer needs to be hashed Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_draw.c | 4 ++-- src/gallium/drivers/zink/zink_pipeline.c | 8 ++++---- src/gallium/drivers/zink/zink_pipeline.h | 4 +--- src/gallium/drivers/zink/zink_program.c | 18 ++---------------- src/gallium/drivers/zink/zink_state.c | 20 +++++++++----------- src/gallium/drivers/zink/zink_state.h | 3 +++ 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/src/gallium/drivers/zink/zink_draw.c b/src/gallium/drivers/zink/zink_draw.c index 653e681d9ee..e945a823874 100644 --- a/src/gallium/drivers/zink/zink_draw.c +++ b/src/gallium/drivers/zink/zink_draw.c @@ -343,8 +343,8 @@ zink_draw_vbo(struct pipe_context *pctx, for (unsigned i = 0; i < ctx->element_state->hw_state.num_bindings; i++) { unsigned binding = ctx->element_state->binding_map[i]; const struct pipe_vertex_buffer *vb = ctx->vertex_buffers + binding; - if (ctx->gfx_pipeline_state.bindings[i].stride != vb->stride) { - ctx->gfx_pipeline_state.bindings[i].stride = vb->stride; + if (ctx->gfx_pipeline_state.vertex_strides[i] != vb->stride) { + ctx->gfx_pipeline_state.vertex_strides[i] = vb->stride; ctx->gfx_pipeline_state.dirty = true; } } diff --git a/src/gallium/drivers/zink/zink_pipeline.c b/src/gallium/drivers/zink/zink_pipeline.c index 1a1b197b059..f7467cbbd59 100644 --- a/src/gallium/drivers/zink/zink_pipeline.c +++ b/src/gallium/drivers/zink/zink_pipeline.c @@ -43,17 +43,17 @@ zink_create_gfx_pipeline(struct zink_screen *screen, { VkPipelineVertexInputStateCreateInfo vertex_input_state = {}; vertex_input_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - vertex_input_state.pVertexBindingDescriptions = state->bindings; + vertex_input_state.pVertexBindingDescriptions = state->element_state->bindings; vertex_input_state.vertexBindingDescriptionCount = state->element_state->num_bindings; vertex_input_state.pVertexAttributeDescriptions = state->element_state->attribs; vertex_input_state.vertexAttributeDescriptionCount = state->element_state->num_attribs; VkPipelineVertexInputDivisorStateCreateInfoEXT vdiv_state = {}; - if (state->divisors_present) { + if (state->element_state->divisors_present) { vertex_input_state.pNext = &vdiv_state; vdiv_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT; - vdiv_state.vertexBindingDivisorCount = state->divisors_present; - vdiv_state.pVertexBindingDivisors = state->divisors; + vdiv_state.vertexBindingDivisorCount = state->element_state->divisors_present; + vdiv_state.pVertexBindingDivisors = state->element_state->divisors; } VkPipelineInputAssemblyStateCreateInfo primitive_state = {}; diff --git a/src/gallium/drivers/zink/zink_pipeline.h b/src/gallium/drivers/zink/zink_pipeline.h index 1f8b62f6a17..27a68ee02b1 100644 --- a/src/gallium/drivers/zink/zink_pipeline.h +++ b/src/gallium/drivers/zink/zink_pipeline.h @@ -41,7 +41,6 @@ struct zink_gfx_pipeline_state { struct zink_render_pass *render_pass; struct zink_vertex_elements_hw_state *element_state; - uint8_t divisors_present; uint32_t num_attachments; struct zink_blend_state *blend_state; @@ -69,9 +68,8 @@ struct zink_gfx_pipeline_state { uint32_t combined_hash; bool combined_dirty; - VkVertexInputBindingDivisorDescriptionEXT divisors[PIPE_MAX_ATTRIBS]; - VkVertexInputBindingDescription bindings[PIPE_MAX_ATTRIBS]; // combination of element_state and stride uint32_t vertex_buffers_enabled_mask; + uint32_t vertex_strides[PIPE_MAX_ATTRIBS]; bool have_EXT_extended_dynamic_state; }; diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index cdd0af50054..ddad8efb55a 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -379,11 +379,9 @@ hash_gfx_pipeline_state(const void *key) hash = XXH32(&vertex_buffers_enabled_mask, sizeof(uint32_t), hash); while (vertex_buffers_enabled_mask) { unsigned idx = u_bit_scan(&vertex_buffers_enabled_mask); - hash = XXH32(&state->bindings[idx], sizeof(VkVertexInputBindingDescription), hash); + hash = XXH32(&state->vertex_strides[idx], sizeof(uint32_t), hash); } } - for (unsigned i = 0; i < state->divisors_present; i++) - hash = XXH32(&state->divisors[i], sizeof(VkVertexInputBindingDivisorDescriptionEXT), hash); return _mesa_hash_data(key, offsetof(struct zink_gfx_pipeline_state, hash)); } @@ -401,19 +399,7 @@ equals_gfx_pipeline_state(const void *a, const void *b) while (mask_a || mask_b) { unsigned idx_a = u_bit_scan(&mask_a); unsigned idx_b = u_bit_scan(&mask_b); - if (memcmp(&sa->bindings[idx_a], &sb->bindings[idx_b], sizeof(VkVertexInputBindingDescription))) - return false; - } - } - if (sa->divisors_present != sb->divisors_present) - return false; - if (sa->divisors_present && sb->divisors_present) { - uint32_t divisors_present_a = sa->divisors_present; - uint32_t divisors_present_b = sb->divisors_present; - while (divisors_present_a || divisors_present_b) { - unsigned idx_a = u_bit_scan(&divisors_present_a); - unsigned idx_b = u_bit_scan(&divisors_present_b); - if (memcmp(&sa->divisors[idx_a], &sb->divisors[idx_b], sizeof(VkVertexInputBindingDivisorDescriptionEXT))) + if (sa->vertex_strides[idx_a] != sb->vertex_strides[idx_b]) return false; } } diff --git a/src/gallium/drivers/zink/zink_state.c b/src/gallium/drivers/zink/zink_state.c index 7ef71618dd9..33ad942438f 100644 --- a/src/gallium/drivers/zink/zink_state.c +++ b/src/gallium/drivers/zink/zink_state.c @@ -76,6 +76,15 @@ zink_create_vertex_elements_state(struct pipe_context *pctx, ves->hw_state.num_bindings = num_bindings; ves->hw_state.num_attribs = num_elements; + for (int i = 0; i < num_bindings; ++i) { + ves->hw_state.bindings[i].binding = ves->bindings[i].binding; + ves->hw_state.bindings[i].inputRate = ves->bindings[i].inputRate; + if (ves->divisor[i]) { + ves->hw_state.divisors[ves->hw_state.divisors_present].divisor = ves->divisor[i]; + ves->hw_state.divisors[ves->hw_state.divisors_present].binding = ves->bindings[i].binding; + ves->hw_state.divisors_present++; + } + } return ves; } @@ -87,19 +96,8 @@ zink_bind_vertex_elements_state(struct pipe_context *pctx, struct zink_gfx_pipeline_state *state = &ctx->gfx_pipeline_state; ctx->element_state = cso; state->dirty = true; - state->divisors_present = 0; if (cso) { state->element_state = &ctx->element_state->hw_state; - struct zink_vertex_elements_state *ves = cso; - for (int i = 0; i < state->element_state->num_bindings; ++i) { - state->bindings[i].binding = ves->bindings[i].binding; - state->bindings[i].inputRate = ves->bindings[i].inputRate; - if (ves->divisor[i]) { - state->divisors[state->divisors_present].divisor = ves->divisor[i]; - state->divisors[state->divisors_present].binding = state->bindings[i].binding; - state->divisors_present++; - } - } } else state->element_state = NULL; } diff --git a/src/gallium/drivers/zink/zink_state.h b/src/gallium/drivers/zink/zink_state.h index 998623d80a5..309bb4d33e7 100644 --- a/src/gallium/drivers/zink/zink_state.h +++ b/src/gallium/drivers/zink/zink_state.h @@ -30,7 +30,10 @@ struct zink_vertex_elements_hw_state { VkVertexInputAttributeDescription attribs[PIPE_MAX_ATTRIBS]; + VkVertexInputBindingDivisorDescriptionEXT divisors[PIPE_MAX_ATTRIBS]; + VkVertexInputBindingDescription bindings[PIPE_MAX_ATTRIBS]; // combination of element_state and stride uint32_t num_bindings, num_attribs; + uint8_t divisors_present; }; struct zink_vertex_elements_state {