<div dir="ltr">Good point, I'll fix that up and send a v2.<div><br></div><div>Thanks,</div><div>Alex<br><div class="gmail_extra"><br><div class="gmail_quote">On 11 April 2017 at 21:34, Bas Nieuwenhuizen <span dir="ltr"><<a href="mailto:bas@basnieuwenhuizen.nl" target="_blank">bas@basnieuwenhuizen.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So I think we need to reset both command buffer states (the enable and<br>
the index) when we call a secondary command buffer.<br>
<br>
With that fixed, this patch is<br>
<br>
Reviewed-by: Bas Nieuwenhuizen <<a href="mailto:bas@basnieuwenhuizen.nl">bas@basnieuwenhuizen.nl</a>><br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Apr 11, 2017 at 3:30 PM, Alex Smith <<a href="mailto:asmith@feralinteractive.com">asmith@feralinteractive.com</a>> wrote:<br>
> According to the Vulkan spec, VkPipelineInputAssemblyStateCr<wbr>eateInfo's<br>
> primitiveRestartEnable flag should only apply to indexed draws, however<br>
> it was being enabled regardless of the type of draw. This could cause<br>
> problems for non-indexed draws with >=65535 vertices if the previous<br>
> indexed draw used 16-bit indices.<br>
><br>
> Fixes corruption of the credits text in Mad Max.<br>
><br>
> Signed-off-by: Alex Smith <<a href="mailto:asmith@feralinteractive.com">asmith@feralinteractive.com</a>><br>
> ---<br>
>  src/amd/vulkan/radv_cmd_<wbr>buffer.c | 53 +++++++++++++++++++++++-------<wbr>----------<br>
>  src/amd/vulkan/radv_private.h    |  1 +<br>
>  2 files changed, 32 insertions(+), 22 deletions(-)<br>
><br>
> diff --git a/src/amd/vulkan/radv_cmd_<wbr>buffer.c b/src/amd/vulkan/radv_cmd_<wbr>buffer.c<br>
> index dbe8bf1..2a7501f 100644<br>
> --- a/src/amd/vulkan/radv_cmd_<wbr>buffer.c<br>
> +++ b/src/amd/vulkan/radv_cmd_<wbr>buffer.c<br>
> @@ -855,9 +855,6 @@ radv_emit_graphics_pipeline(<wbr>struct radv_cmd_buffer *cmd_buffer,<br>
>         radv_emit_fragment_shader(cmd_<wbr>buffer, pipeline);<br>
>         polaris_set_vgt_vertex_reuse(<wbr>cmd_buffer, pipeline);<br>
><br>
> -       radeon_set_context_reg(cmd_<wbr>buffer->cs, R_028A94_VGT_MULTI_PRIM_IB_<wbr>RESET_EN,<br>
> -                              pipeline->graphics.prim_<wbr>restart_enable);<br>
> -<br>
>         cmd_buffer->scratch_size_<wbr>needed =<br>
>                                   MAX2(cmd_buffer->scratch_size_<wbr>needed,<br>
>                                        pipeline->max_waves * pipeline->scratch_bytes_per_<wbr>wave);<br>
> @@ -1394,9 +1391,32 @@ radv_flush_constants(struct radv_cmd_buffer *cmd_buffer,<br>
>         cmd_buffer->push_constant_<wbr>stages &= ~stages;<br>
>  }<br>
><br>
> +static void radv_emit_primitive_reset_<wbr>state(struct radv_cmd_buffer *cmd_buffer,<br>
> +                                           bool indexed_draw)<br>
> +{<br>
> +       int32_t primitive_reset_en = indexed_draw && cmd_buffer->state.pipeline-><wbr>graphics.prim_restart_enable;<br>
> +<br>
> +       if (primitive_reset_en != cmd_buffer->state.last_<wbr>primitive_reset_en) {<br>
> +               cmd_buffer->state.last_<wbr>primitive_reset_en = primitive_reset_en;<br>
> +               radeon_set_context_reg(cmd_<wbr>buffer->cs, R_028A94_VGT_MULTI_PRIM_IB_<wbr>RESET_EN,<br>
> +                                      primitive_reset_en);<br>
> +       }<br>
> +<br>
> +       if (primitive_reset_en) {<br>
> +               uint32_t primitive_reset_index = cmd_buffer->state.index_type ? 0xffffffffu : 0xffffu;<br>
> +<br>
> +               if (primitive_reset_index != cmd_buffer->state.last_<wbr>primitive_reset_index) {<br>
> +                       cmd_buffer->state.last_<wbr>primitive_reset_index = primitive_reset_index;<br>
> +                       radeon_set_context_reg(cmd_<wbr>buffer->cs, R_02840C_VGT_MULTI_PRIM_IB_<wbr>RESET_INDX,<br>
> +                                              primitive_reset_index);<br>
> +               }<br>
> +       }<br>
> +}<br>
> +<br>
>  static void<br>
>  radv_cmd_buffer_flush_state(<wbr>struct radv_cmd_buffer *cmd_buffer,<br>
> -                           bool instanced_draw, bool indirect_draw,<br>
> +                           bool indexed_draw, bool instanced_draw,<br>
> +                           bool indirect_draw,<br>
>                             uint32_t draw_vertex_count)<br>
>  {<br>
>         struct radv_pipeline *pipeline = cmd_buffer->state.pipeline;<br>
> @@ -1482,6 +1502,8 @@ radv_cmd_buffer_flush_state(<wbr>struct radv_cmd_buffer *cmd_buffer,<br>
><br>
>         radv_cmd_buffer_flush_dynamic_<wbr>state(cmd_buffer);<br>
><br>
> +       radv_emit_primitive_reset_<wbr>state(cmd_buffer, indexed_draw);<br>
> +<br>
>         radv_flush_descriptors(cmd_<wbr>buffer, cmd_buffer->state.pipeline,<br>
>                                VK_SHADER_STAGE_ALL_GRAPHICS);<br>
>         radv_flush_constants(cmd_<wbr>buffer, cmd_buffer->state.pipeline,<br>
> @@ -1802,6 +1824,7 @@ VkResult radv_BeginCommandBuffer(<br>
>         radv_reset_cmd_buffer(cmd_<wbr>buffer);<br>
><br>
>         memset(&cmd_buffer->state, 0, sizeof(cmd_buffer->state));<br>
> +       cmd_buffer->state.last_<wbr>primitive_reset_en = -1;<br>
><br>
>         /* setup initial configuration into command buffer */<br>
>         if (cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_<wbr>PRIMARY) {<br>
> @@ -2444,7 +2467,7 @@ void radv_CmdDraw(<br>
>  {<br>
>         RADV_FROM_HANDLE(radv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
><br>
> -       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, (instanceCount > 1), false, vertexCount);<br>
> +       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, false, (instanceCount > 1), false, vertexCount);<br>
><br>
>         MAYBE_UNUSED unsigned cdw_max = radeon_check_space(cmd_buffer-<wbr>>device->ws, cmd_buffer->cs, 10);<br>
><br>
> @@ -2471,18 +2494,6 @@ void radv_CmdDraw(<br>
>         radv_cmd_buffer_trace_emit(<wbr>cmd_buffer);<br>
>  }<br>
><br>
> -static void radv_emit_primitive_reset_<wbr>index(struct radv_cmd_buffer *cmd_buffer)<br>
> -{<br>
> -       uint32_t primitive_reset_index = cmd_buffer->state.index_type ? 0xffffffffu : 0xffffu;<br>
> -<br>
> -       if (cmd_buffer->state.pipeline-><wbr>graphics.prim_restart_enable &&<br>
> -           primitive_reset_index != cmd_buffer->state.last_<wbr>primitive_reset_index) {<br>
> -               cmd_buffer->state.last_<wbr>primitive_reset_index = primitive_reset_index;<br>
> -               radeon_set_context_reg(cmd_<wbr>buffer->cs, R_02840C_VGT_MULTI_PRIM_IB_<wbr>RESET_INDX,<br>
> -                                      primitive_reset_index);<br>
> -       }<br>
> -}<br>
> -<br>
>  void radv_CmdDrawIndexed(<br>
>         VkCommandBuffer                             commandBuffer,<br>
>         uint32_t                                    indexCount,<br>
> @@ -2496,8 +2507,7 @@ void radv_CmdDrawIndexed(<br>
>         uint32_t index_max_size = (cmd_buffer->state.index_<wbr>buffer->size - cmd_buffer->state.index_<wbr>offset) / index_size;<br>
>         uint64_t index_va;<br>
><br>
> -       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, (instanceCount > 1), false, indexCount);<br>
> -       radv_emit_primitive_reset_<wbr>index(cmd_buffer);<br>
> +       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, true, (instanceCount > 1), false, indexCount);<br>
><br>
>         MAYBE_UNUSED unsigned cdw_max = radeon_check_space(cmd_buffer-<wbr>>device->ws, cmd_buffer->cs, 15);<br>
><br>
> @@ -2596,7 +2606,7 @@ radv_cmd_draw_indirect_count(<wbr>VkCommandBuffer                             command<br>
>                               uint32_t                                    stride)<br>
>  {<br>
>         RADV_FROM_HANDLE(radv_cmd_<wbr>buffer, cmd_buffer, commandBuffer);<br>
> -       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, false, true, 0);<br>
> +       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, false, false, true, 0);<br>
><br>
>         MAYBE_UNUSED unsigned cdw_max = radeon_check_space(cmd_buffer-<wbr>>device->ws,<br>
>                                                            cmd_buffer->cs, 14);<br>
> @@ -2621,8 +2631,7 @@ radv_cmd_draw_indexed_<wbr>indirect_count(<br>
>         int index_size = cmd_buffer->state.index_type ? 4 : 2;<br>
>         uint32_t index_max_size = (cmd_buffer->state.index_<wbr>buffer->size - cmd_buffer->state.index_<wbr>offset) / index_size;<br>
>         uint64_t index_va;<br>
> -       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, false, true, 0);<br>
> -       radv_emit_primitive_reset_<wbr>index(cmd_buffer);<br>
> +       radv_cmd_buffer_flush_state(<wbr>cmd_buffer, true, false, true, 0);<br>
><br>
>         index_va = cmd_buffer->device->ws-><wbr>buffer_get_va(cmd_buffer-><wbr>state.index_buffer->bo);<br>
>         index_va += cmd_buffer->state.index_<wbr>buffer->offset + cmd_buffer->state.index_<wbr>offset;<br>
> diff --git a/src/amd/vulkan/radv_private.<wbr>h b/src/amd/vulkan/radv_private.<wbr>h<br>
> index 2cb8cdd..e3b538b 100644<br>
> --- a/src/amd/vulkan/radv_private.<wbr>h<br>
> +++ b/src/amd/vulkan/radv_private.<wbr>h<br>
> @@ -744,6 +744,7 @@ struct radv_cmd_state {<br>
>         struct radv_buffer *                         index_buffer;<br>
>         uint32_t                                     index_type;<br>
>         uint32_t                                     index_offset;<br>
> +       int32_t                                      last_primitive_reset_en;<br>
>         uint32_t                                     last_primitive_reset_index;<br>
>         enum radv_cmd_flush_bits                     flush_bits;<br>
>         unsigned                                     active_occlusion_queries;<br>
> --<br>
> 2.9.3<br>
><br>
</div></div></blockquote></div><br></div></div></div>