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 <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10508>
This commit is contained in:
Mike Blumenkrantz 2021-04-01 16:50:45 -04:00 committed by Marge Bot
parent d7a1bd94fb
commit 7ca64c1c4d
6 changed files with 21 additions and 36 deletions

View File

@ -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;
}
}

View File

@ -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 = {};

View File

@ -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;
};

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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 {