From 195350c5da0caf25fa62672bdd0a9359f1a4cadc Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Fri, 15 Nov 2024 00:18:16 +0200 Subject: [PATCH] anv: rework vertex input helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lionel Landwerlin Reviewed-by: Tapani Pälli Reviewed-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_genX.h | 9 +++--- src/intel/vulkan/genX_gfx_state.c | 31 ++---------------- src/intel/vulkan/genX_pipeline.c | 53 +++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/intel/vulkan/anv_genX.h b/src/intel/vulkan/anv_genX.h index badd059c18b..fa77cff014e 100644 --- a/src/intel/vulkan/anv_genX.h +++ b/src/intel/vulkan/anv_genX.h @@ -104,11 +104,10 @@ void genX(emit_pipeline_select)(struct anv_batch *batch, uint32_t pipeline, void genX(apply_task_urb_workaround)(struct anv_cmd_buffer *cmd_buffer); -void genX(emit_vertex_input)(struct anv_batch *batch, - uint32_t *vertex_element_dws, - struct anv_graphics_pipeline *pipeline, - const struct vk_vertex_input_state *vi, - bool emit_in_pipeline); +void genX(batch_emit_vertex_input)(struct anv_batch *batch, + struct anv_device *device, + struct anv_graphics_pipeline *pipeline, + const struct vk_vertex_input_state *vi); enum anv_pipe_bits genX(emit_apply_pipe_flushes)(struct anv_batch *batch, diff --git a/src/intel/vulkan/genX_gfx_state.c b/src/intel/vulkan/genX_gfx_state.c index 39c141c4a06..7d752777b3f 100644 --- a/src/intel/vulkan/genX_gfx_state.c +++ b/src/intel/vulkan/genX_gfx_state.c @@ -2178,35 +2178,8 @@ cmd_buffer_gfx_state_emission(struct anv_cmd_buffer *cmd_buffer) } if (BITSET_TEST(hw_state->dirty, ANV_GFX_STATE_VERTEX_INPUT)) { - const uint32_t ve_count = - pipeline->vs_input_elements + pipeline->svgs_count; - const uint32_t num_dwords = 1 + 2 * MAX2(1, ve_count); - uint32_t *p = anv_batch_emitn(&cmd_buffer->batch, num_dwords, - GENX(3DSTATE_VERTEX_ELEMENTS)); - - if (p) { - if (ve_count == 0) { - memcpy(p + 1, cmd_buffer->device->physical->empty_vs_input, - sizeof(cmd_buffer->device->physical->empty_vs_input)); - } else if (ve_count == pipeline->vertex_input_elems) { - /* MESA_VK_DYNAMIC_VI is not dynamic for this pipeline, so - * everything is in pipeline->vertex_input_data and we can just - * memcpy - */ - memcpy(p + 1, pipeline->vertex_input_data, 4 * 2 * ve_count); - anv_batch_emit_pipeline_state(&cmd_buffer->batch, pipeline, - final.vf_instancing); - } else { - assert(pipeline->final.vf_instancing.len == 0); - /* Use dyn->vi to emit the dynamic VERTEX_ELEMENT_STATE input. */ - genX(emit_vertex_input)(&cmd_buffer->batch, p + 1, - pipeline, dyn->vi, false /* emit_in_pipeline */); - /* Then append the VERTEX_ELEMENT_STATE for the draw parameters */ - memcpy(p + 1 + 2 * pipeline->vs_input_elements, - pipeline->vertex_input_data, - 4 * 2 * pipeline->vertex_input_elems); - } - } + genX(batch_emit_vertex_input)(&cmd_buffer->batch, device, + pipeline, dyn->vi); } if (BITSET_TEST(hw_state->dirty, ANV_GFX_STATE_TE)) { diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index 64a9fb8bbd2..7e207774c11 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -166,12 +166,12 @@ vertex_element_comp_control(enum isl_format format, unsigned comp) } } -void -genX(emit_vertex_input)(struct anv_batch *batch, - uint32_t *vertex_element_dws, - struct anv_graphics_pipeline *pipeline, - const struct vk_vertex_input_state *vi, - bool emit_in_pipeline) +static void +emit_ves_vf_instancing(struct anv_batch *batch, + uint32_t *vertex_element_dws, + struct anv_graphics_pipeline *pipeline, + const struct vk_vertex_input_state *vi, + bool emit_in_pipeline) { const struct anv_device *device = pipeline->base.base.device; const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline); @@ -275,6 +275,41 @@ genX(emit_vertex_input)(struct anv_batch *batch, } } +void +genX(batch_emit_vertex_input)(struct anv_batch *batch, + struct anv_device *device, + struct anv_graphics_pipeline *pipeline, + const struct vk_vertex_input_state *vi) +{ + const uint32_t ve_count = + pipeline->vs_input_elements + pipeline->svgs_count; + const uint32_t num_dwords = 1 + 2 * MAX2(1, ve_count); + uint32_t *p = anv_batch_emitn(batch, num_dwords, + GENX(3DSTATE_VERTEX_ELEMENTS)); + if (p == NULL) + return; + + if (ve_count == 0) { + memcpy(p + 1, device->physical->empty_vs_input, + sizeof(device->physical->empty_vs_input)); + } else if (ve_count == pipeline->vertex_input_elems) { + /* MESA_VK_DYNAMIC_VI is not dynamic for this pipeline, so everything is + * in pipeline->vertex_input_data and we can just memcpy + */ + memcpy(p + 1, pipeline->vertex_input_data, 4 * 2 * ve_count); + anv_batch_emit_pipeline_state(batch, pipeline, final.vf_instancing); + } else { + assert(pipeline->final.vf_instancing.len == 0); + /* Use dyn->vi to emit the dynamic VERTEX_ELEMENT_STATE input. */ + emit_ves_vf_instancing(batch, p + 1, pipeline, vi, + false /* emit_in_pipeline */); + /* Then append the VERTEX_ELEMENT_STATE for the draw parameters */ + memcpy(p + 1 + 2 * pipeline->vs_input_elements, + pipeline->vertex_input_data, + 4 * 2 * pipeline->vertex_input_elems); + } +} + static void emit_vertex_input(struct anv_graphics_pipeline *pipeline, const struct vk_graphics_pipeline_state *state, @@ -284,9 +319,9 @@ emit_vertex_input(struct anv_graphics_pipeline *pipeline, * everything in gfx8_cmd_buffer.c */ if (!BITSET_TEST(state->dynamic, MESA_VK_DYNAMIC_VI)) { - genX(emit_vertex_input)(NULL, - pipeline->vertex_input_data, - pipeline, vi, true /* emit_in_pipeline */); + emit_ves_vf_instancing(NULL, + pipeline->vertex_input_data, + pipeline, vi, true /* emit_in_pipeline */); } const struct brw_vs_prog_data *vs_prog_data = get_vs_prog_data(pipeline);