tu: pCounterBuffers can be NULL in vkCmd*TransformFeedbackEXT()
authorDanylo Piliaiev <dpiliaiev@igalia.com>
Thu, 17 Dec 2020 12:41:52 +0000 (14:41 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 17 Dec 2020 16:33:33 +0000 (16:33 +0000)
According to the spec:

"pCounterBuffers is an optional array of buffer handles [...]
 If pCounterBuffers is NULL, then transform feedback will start
 capturing vertex data to byte offset zero in all bound transform
 feedback buffers."

"If counterBufferCount is not 0, and pCounterBuffers is not NULL,
 pCounterBuffers must be a valid pointer to an array [...]"

So counterBufferCount could be non-zero with pCounterBuffers
being NULL.

Fixes crash in RenderDoc when inspecting draw call with tesselation
or geometry shader present.

Fixes: 98b0d900 "turnip: rework streamout state and add missing counter buffer read/writes"
Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8140>

src/freedreno/vulkan/tu_cmd_buffer.c

index a675bc3..fb233da 100644 (file)
@@ -1918,7 +1918,7 @@ tu_CmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer,
    for (uint32_t i = 0; i < IR3_MAX_SO_BUFFERS; i++)
       tu_cs_emit_regs(cs, A6XX_VPC_SO_BUFFER_OFFSET(i, cmd->state.streamout_offset[i]));
 
-   for (uint32_t i = 0; i < counterBufferCount; i++) {
+   for (uint32_t i = 0; i < (pCounterBuffers ? counterBufferCount : 0); i++) {
       uint32_t idx = firstCounterBuffer + i;
       uint32_t offset = cmd->state.streamout_offset[idx];
       uint64_t counter_buffer_offset = pCounterBufferOffsets ? pCounterBufferOffsets[i] : 0u;
@@ -1967,7 +1967,7 @@ void tu_CmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer,
       tu6_emit_event_write(cmd, cs, FLUSH_SO_0 + i);
    }
 
-   for (uint32_t i = 0; i < counterBufferCount; i++) {
+   for (uint32_t i = 0; i < (pCounterBuffers ? counterBufferCount : 0); i++) {
       uint32_t idx = firstCounterBuffer + i;
       uint32_t offset = cmd->state.streamout_offset[idx];
       uint64_t counter_buffer_offset = pCounterBufferOffsets ? pCounterBufferOffsets[i] : 0u;