<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 31, 2017 at 7:00 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
---<br>
src/intel/vulkan/genX_cmd_<wbr>buffer.c | 43 ++++++++++++++++++++++++++++++<wbr>+++-----<br>
src/intel/vulkan/genX_<wbr>pipeline.c | 25 +++++++++++++++++++++-<br>
2 files changed, 62 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/genX_cmd_<wbr>buffer.c b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
index 91b97abec6..23cb9f8f4d 100644<br>
--- a/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
+++ b/src/intel/vulkan/genX_cmd_<wbr>buffer.c<br>
@@ -1585,30 +1585,39 @@ genX(cmd_buffer_flush_state)(<wbr>struct anv_cmd_buffer *cmd_buffer)<br>
}<br>
<br>
static void<br>
-emit_base_vertex_instance_bo(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
- struct anv_bo *bo, uint32_t offset)<br>
+emit_vertex_bo(struct anv_cmd_buffer *cmd_buffer,<br>
+ struct anv_bo *bo, uint32_t offset,<br>
+ uint32_t size, uint32_t index)<br>
{<br>
uint32_t *p = anv_batch_emitn(&cmd_buffer-><wbr>batch, 5,<br>
GENX(3DSTATE_VERTEX_BUFFERS));<br>
<br>
GENX(VERTEX_BUFFER_STATE_pack)<wbr>(&cmd_buffer->batch, p + 1,<br>
&(struct GENX(VERTEX_BUFFER_STATE)) {<br>
- .VertexBufferIndex = 31, /* Reserved for this */<br>
+ .VertexBufferIndex = index,<br>
.AddressModifyEnable = true,<br>
.BufferPitch = 0,<br>
#if (GEN_GEN >= 8)<br>
.MemoryObjectControlState = GENX(MOCS),<br>
.BufferStartingAddress = { bo, offset },<br>
- .BufferSize = 8<br>
+ .BufferSize = size<br>
#else<br>
.<wbr>VertexBufferMemoryObjectContro<wbr>lState = GENX(MOCS),<br>
.BufferStartingAddress = { bo, offset },<br>
- .EndAddress = { bo, offset + 8 },<br>
+ .EndAddress = { bo, offset + size },<br>
#endif<br>
});<br>
}<br>
<br>
static void<br>
+emit_base_vertex_instance_bo(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
+ struct anv_bo *bo, uint32_t offset)<br>
+{<br>
+ emit_vertex_bo(cmd_buffer, bo, offset, 8,<br>
+ 31 /* Reserved for this */);<br></blockquote><div><br></div><div>Good place for ANV_SVGS_VB_INDEX<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
+static void<br>
emit_base_vertex_instance(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
uint32_t base_vertex, uint32_t base_instance)<br>
{<br>
@@ -1625,6 +1634,22 @@ emit_base_vertex_instance(<wbr>struct anv_cmd_buffer *cmd_buffer,<br>
&cmd_buffer->device-><a href="http://dynamic_state_block_pool.bo" rel="noreferrer" target="_blank">dynamic_<wbr>state_block_pool.bo</a>, id_state.offset);<br>
}<br>
<br>
+static void<br>
+emit_draw_index(struct anv_cmd_buffer *cmd_buffer, uint32_t draw_index)<br>
+{<br>
+ struct anv_state state =<br>
+ anv_cmd_buffer_alloc_dynamic_<wbr>state(cmd_buffer, 4, 4);<br>
+<br>
+ ((uint32_t *)state.map)[0] = draw_index;<br>
+<br>
+ if (!cmd_buffer->device->info.<wbr>has_llc)<br>
+ anv_state_clflush(state);<br>
+<br>
+ emit_vertex_bo(cmd_buffer,<br>
+ &cmd_buffer->device-><a href="http://dynamic_state_block_pool.bo" rel="noreferrer" target="_blank">dynamic_<wbr>state_block_pool.bo</a>,<br>
+ state.offset, 4, 32 /* Reserved for this */);<br></blockquote><div><br></div><div>ANV_DRAWID_VB_INDEX<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+}<br>
+<br>
void genX(CmdDraw)(<br>
VkCommandBuffer commandBuffer,<br>
uint32_t vertexCount,<br>
@@ -1640,6 +1665,8 @@ void genX(CmdDraw)(<br>
<br>
if (vs_prog_data->uses_basevertex || vs_prog_data->uses_<wbr>baseinstance)<br>
emit_base_vertex_instance(cmd_<wbr>buffer, firstVertex, firstInstance);<br>
+ if (vs_prog_data->uses_drawid)<br>
+ emit_draw_index(cmd_buffer, 0);<br>
<br>
anv_batch_emit(&cmd_buffer-><wbr>batch, GENX(3DPRIMITIVE), prim) {<br>
prim.VertexAccessType = SEQUENTIAL;<br>
@@ -1668,6 +1695,8 @@ void genX(CmdDrawIndexed)(<br>
<br>
if (vs_prog_data->uses_basevertex || vs_prog_data->uses_<wbr>baseinstance)<br>
emit_base_vertex_instance(cmd_<wbr>buffer, vertexOffset, firstInstance);<br>
+ if (vs_prog_data->uses_drawid)<br>
+ emit_draw_index(cmd_buffer, 0);<br>
<br>
anv_batch_emit(&cmd_buffer-><wbr>batch, GENX(3DPRIMITIVE), prim) {<br>
prim.VertexAccessType = RANDOM;<br>
@@ -1706,6 +1735,8 @@ void genX(CmdDrawIndirect)(<br>
<br>
if (vs_prog_data->uses_basevertex || vs_prog_data->uses_<wbr>baseinstance)<br>
emit_base_vertex_instance_bo(<wbr>cmd_buffer, bo, bo_offset + 8);<br>
+ if (vs_prog_data->uses_drawid)<br>
+ emit_draw_index(cmd_buffer, 0);<br>
<br>
emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);<br>
emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);<br>
@@ -1739,6 +1770,8 @@ void genX(CmdDrawIndexedIndirect)(<br>
/* TODO: We need to stomp base vertex to 0 somehow */<br>
if (vs_prog_data->uses_basevertex || vs_prog_data->uses_<wbr>baseinstance)<br>
emit_base_vertex_instance_bo(<wbr>cmd_buffer, bo, bo_offset + 12);<br>
+ if (vs_prog_data->uses_drawid)<br>
+ emit_draw_index(cmd_buffer, 0);<br>
<br>
emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_VERTEX_COUNT, bo, bo_offset);<br>
emit_lrm(&cmd_buffer->batch, GEN7_3DPRIM_INSTANCE_COUNT, bo, bo_offset + 4);<br>
diff --git a/src/intel/vulkan/genX_<wbr>pipeline.c b/src/intel/vulkan/genX_<wbr>pipeline.c<br>
index 4c1afd0319..37cdbb87a2 100644<br>
--- a/src/intel/vulkan/genX_<wbr>pipeline.c<br>
+++ b/src/intel/vulkan/genX_<wbr>pipeline.c<br>
@@ -102,7 +102,8 @@ emit_vertex_input(struct anv_pipeline *pipeline,<br>
uint32_t elem_count = __builtin_popcount(elements) -<br>
__builtin_popcount(elements_<wbr>double) / 2;<br>
<br>
- uint32_t total_elems = elem_count + needs_svgs_elem;<br>
+ const uint32_t total_elems =<br>
+ elem_count + needs_svgs_elem + vs_prog_data->uses_drawid;<br>
if (total_elems == 0)<br>
return;<br>
<br>
@@ -201,6 +202,28 @@ emit_vertex_input(struct anv_pipeline *pipeline,<br>
sgvs.InstanceIDElementOffset = id_slot;<br>
}<br>
#endif<br>
+<br>
+ const uint32_t drawid_slot = elem_count + needs_svgs_elem;<br>
+ if (vs_prog_data->uses_drawid) {<br>
+ struct GENX(VERTEX_ELEMENT_STATE) element = {<br>
+ .VertexBufferIndex = 32, /* Reserved for this */<br></blockquote><div><br></div><div>ANV_DRAWID_VB_INDEX<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ .Valid = true,<br>
+ .SourceElementFormat = ISL_FORMAT_R32_UINT,<br>
+ .Component0Control = VFCOMP_STORE_SRC,<br>
+ .Component1Control = VFCOMP_STORE_0,<br>
+ .Component2Control = VFCOMP_STORE_0,<br>
+ .Component3Control = VFCOMP_STORE_0,<br>
+ };<br>
+ GENX(VERTEX_ELEMENT_STATE_<wbr>pack)(NULL,<br>
+ &p[1 + drawid_slot * 2],<br>
+ &element);<br>
+<br>
+#if GEN_GEN >= 8<br>
+ anv_batch_emit(&pipeline-><wbr>batch, GENX(3DSTATE_VF_INSTANCING), vfi) {<br>
+ vfi.VertexElementIndex = drawid_slot;<br>
+ }<br>
+#endif<br>
+ }<br>
}<br>
<br>
void<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>