[Mesa-dev] [PATCH 6/7] anv: emit DrawID if needed
Jason Ekstrand
jason at jlekstrand.net
Wed Feb 1 03:10:19 UTC 2017
On Tue, Jan 31, 2017 at 7:00 AM, Lionel Landwerlin <
lionel.g.landwerlin at intel.com> wrote:
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> ---
> src/intel/vulkan/genX_cmd_buffer.c | 43 ++++++++++++++++++++++++++++++
> +++-----
> src/intel/vulkan/genX_pipeline.c | 25 +++++++++++++++++++++-
> 2 files changed, 62 insertions(+), 6 deletions(-)
>
> diff --git a/src/intel/vulkan/genX_cmd_buffer.c
> b/src/intel/vulkan/genX_cmd_buffer.c
> index 91b97abec6..23cb9f8f4d 100644
> --- a/src/intel/vulkan/genX_cmd_buffer.c
> +++ b/src/intel/vulkan/genX_cmd_buffer.c
> @@ -1585,30 +1585,39 @@ genX(cmd_buffer_flush_state)(struct
> anv_cmd_buffer *cmd_buffer)
> }
>
> static void
> -emit_base_vertex_instance_bo(struct anv_cmd_buffer *cmd_buffer,
> - struct anv_bo *bo, uint32_t offset)
> +emit_vertex_bo(struct anv_cmd_buffer *cmd_buffer,
> + struct anv_bo *bo, uint32_t offset,
> + uint32_t size, uint32_t index)
> {
> uint32_t *p = anv_batch_emitn(&cmd_buffer->batch, 5,
> GENX(3DSTATE_VERTEX_BUFFERS));
>
> GENX(VERTEX_BUFFER_STATE_pack)(&cmd_buffer->batch, p + 1,
> &(struct GENX(VERTEX_BUFFER_STATE)) {
> - .VertexBufferIndex = 31, /* Reserved for this */
> + .VertexBufferIndex = index,
> .AddressModifyEnable = true,
> .BufferPitch = 0,
> #if (GEN_GEN >= 8)
> .MemoryObjectControlState = GENX(MOCS),
> .BufferStartingAddress = { bo, offset },
> - .BufferSize = 8
> + .BufferSize = size
> #else
> .VertexBufferMemoryObjectControlState = GENX(MOCS),
> .BufferStartingAddress = { bo, offset },
> - .EndAddress = { bo, offset + 8 },
> + .EndAddress = { bo, offset + size },
> #endif
> });
> }
>
> static void
> +emit_base_vertex_instance_bo(struct anv_cmd_buffer *cmd_buffer,
> + struct anv_bo *bo, uint32_t offset)
> +{
> + emit_vertex_bo(cmd_buffer, bo, offset, 8,
> + 31 /* Reserved for this */);
>
Good place for ANV_SVGS_VB_INDEX
> +}
> +
> +static void
> emit_base_vertex_instance(struct anv_cmd_buffer *cmd_buffer,
> uint32_t base_vertex, uint32_t base_instance)
> {
> @@ -1625,6 +1634,22 @@ emit_base_vertex_instance(struct anv_cmd_buffer
> *cmd_buffer,
> &cmd_buffer->device->dynamic_state_block_pool.bo, id_state.offset);
> }
>
> +static void
> +emit_draw_index(struct anv_cmd_buffer *cmd_buffer, uint32_t draw_index)
> +{
> + struct anv_state state =
> + anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, 4, 4);
> +
> + ((uint32_t *)state.map)[0] = draw_index;
> +
> + if (!cmd_buffer->device->info.has_llc)
> + anv_state_clflush(state);
> +
> + emit_vertex_bo(cmd_buffer,
> + &cmd_buffer->device->dynamic_state_block_pool.bo,
> + state.offset, 4, 32 /* Reserved for this */);
>
ANV_DRAWID_VB_INDEX
> +}
> +
> void genX(CmdDraw)(
> VkCommandBuffer commandBuffer,
> uint32_t vertexCount,
> @@ -1640,6 +1665,8 @@ void genX(CmdDraw)(
>
> if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
> emit_base_vertex_instance(cmd_buffer, firstVertex, firstInstance);
> + if (vs_prog_data->uses_drawid)
> + emit_draw_index(cmd_buffer, 0);
>
> anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
> prim.VertexAccessType = SEQUENTIAL;
> @@ -1668,6 +1695,8 @@ void genX(CmdDrawIndexed)(
>
> if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
> emit_base_vertex_instance(cmd_buffer, vertexOffset, firstInstance);
> + if (vs_prog_data->uses_drawid)
> + emit_draw_index(cmd_buffer, 0);
>
> anv_batch_emit(&cmd_buffer->batch, GENX(3DPRIMITIVE), prim) {
> prim.VertexAccessType = RANDOM;
> @@ -1706,6 +1735,8 @@ void genX(CmdDrawIndirect)(
>
> if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
> emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 8);
> + if (vs_prog_data->uses_drawid)
> + emit_draw_index(cmd_buffer, 0);
>
> emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
> emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset
> + 4);
> @@ -1739,6 +1770,8 @@ void genX(CmdDrawIndexedIndirect)(
> /* TODO: We need to stomp base vertex to 0 somehow */
> if (vs_prog_data->uses_basevertex || vs_prog_data->uses_baseinstance)
> emit_base_vertex_instance_bo(cmd_buffer, bo, bo_offset + 12);
> + if (vs_prog_data->uses_drawid)
> + emit_draw_index(cmd_buffer, 0);
>
> emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);
> emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset
> + 4);
> diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_
> pipeline.c
> index 4c1afd0319..37cdbb87a2 100644
> --- a/src/intel/vulkan/genX_pipeline.c
> +++ b/src/intel/vulkan/genX_pipeline.c
> @@ -102,7 +102,8 @@ emit_vertex_input(struct anv_pipeline *pipeline,
> uint32_t elem_count = __builtin_popcount(elements) -
> __builtin_popcount(elements_double) / 2;
>
> - uint32_t total_elems = elem_count + needs_svgs_elem;
> + const uint32_t total_elems =
> + elem_count + needs_svgs_elem + vs_prog_data->uses_drawid;
> if (total_elems == 0)
> return;
>
> @@ -201,6 +202,28 @@ emit_vertex_input(struct anv_pipeline *pipeline,
> sgvs.InstanceIDElementOffset = id_slot;
> }
> #endif
> +
> + const uint32_t drawid_slot = elem_count + needs_svgs_elem;
> + if (vs_prog_data->uses_drawid) {
> + struct GENX(VERTEX_ELEMENT_STATE) element = {
> + .VertexBufferIndex = 32, /* Reserved for this */
>
ANV_DRAWID_VB_INDEX
> + .Valid = true,
> + .SourceElementFormat = ISL_FORMAT_R32_UINT,
> + .Component0Control = VFCOMP_STORE_SRC,
> + .Component1Control = VFCOMP_STORE_0,
> + .Component2Control = VFCOMP_STORE_0,
> + .Component3Control = VFCOMP_STORE_0,
> + };
> + GENX(VERTEX_ELEMENT_STATE_pack)(NULL,
> + &p[1 + drawid_slot * 2],
> + &element);
> +
> +#if GEN_GEN >= 8
> + anv_batch_emit(&pipeline->batch, GENX(3DSTATE_VF_INSTANCING), vfi)
> {
> + vfi.VertexElementIndex = drawid_slot;
> + }
> +#endif
> + }
> }
>
> void
> --
> 2.11.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170131/1b66b17f/attachment.html>
More information about the mesa-dev
mailing list