radv: sync before resetting a pool if there is active pending queries
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 28 May 2019 09:08:32 +0000 (11:08 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 29 May 2019 06:47:54 +0000 (08:47 +0200)
Make sure to sync all previous work if the given command buffer
has pending active queries. Otherwise the GPU might write queries
data after the reset operation.

This fixes a bunch of new dEQP-VK.query_pool.* CTS failures.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_private.h
src/amd/vulkan/radv_query.c
src/amd/vulkan/si_cmd_buffer.c

index 0e9c1894a40c6e4ddb30529ff0a674797658d662..e524c32183205e8dc71fed0e52e2f863be148dea 100644 (file)
@@ -2950,6 +2950,12 @@ VkResult radv_EndCommandBuffer(
        if (cmd_buffer->queue_family_index != RADV_QUEUE_TRANSFER) {
                if (cmd_buffer->device->physical_device->rad_info.chip_class == GFX6)
                        cmd_buffer->state.flush_bits |= RADV_CMD_FLAG_CS_PARTIAL_FLUSH | RADV_CMD_FLAG_PS_PARTIAL_FLUSH | RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2;
+
+               /* Make sure to sync all pending active queries at the end of
+                * command buffer.
+                */
+               cmd_buffer->state.flush_bits |= cmd_buffer->active_query_flush_bits;
+
                si_emit_cache_flush(cmd_buffer);
        }
 
index 7834a505562f73fe4afd22a5d8d1ee349a8ddca0..08b2621685dfd03869eec2052a384ad729abe587 100644 (file)
@@ -1142,6 +1142,11 @@ struct radv_cmd_buffer {
         * Whether a query pool has been resetted and we have to flush caches.
         */
        bool pending_reset_query;
+
+       /**
+        * Bitmask of pending active query flushes.
+        */
+       enum radv_cmd_flush_bits active_query_flush_bits;
 };
 
 struct radv_image;
index c0f470da888d925d7ae7f099b0d8d5453c484a58..c3812e2182dd998afe1b628af01346a2058f3f0e 100644 (file)
@@ -1419,6 +1419,12 @@ void radv_CmdResetQueryPool(
                         ? TIMESTAMP_NOT_READY : 0;
        uint32_t flush_bits = 0;
 
+       /* Make sure to sync all previous work if the given command buffer has
+        * pending active queries. Otherwise the GPU might write queries data
+        * after the reset operation.
+        */
+       cmd_buffer->state.flush_bits |= cmd_buffer->active_query_flush_bits;
+
        flush_bits |= radv_fill_buffer(cmd_buffer, pool->bo,
                                       firstQuery * pool->stride,
                                       queryCount * pool->stride, value);
@@ -1614,6 +1620,11 @@ static void emit_end_query(struct radv_cmd_buffer *cmd_buffer,
        default:
                unreachable("ending unhandled query type");
        }
+
+       cmd_buffer->active_query_flush_bits |= RADV_CMD_FLAG_PS_PARTIAL_FLUSH |
+                                              RADV_CMD_FLAG_CS_PARTIAL_FLUSH |
+                                              RADV_CMD_FLAG_INV_GLOBAL_L2 |
+                                              RADV_CMD_FLAG_INV_VMEM_L1;
 }
 
 void radv_CmdBeginQueryIndexedEXT(
index c73c6ecd65c4e81e418103a3ad8fc55ff6dbd723..aae8d578c10e3a67bc1278fc30573630239c7fb8 100644 (file)
@@ -989,6 +989,11 @@ si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer)
        if (unlikely(cmd_buffer->device->trace_bo))
                radv_cmd_buffer_trace_emit(cmd_buffer);
 
+       /* Clear the caches that have been flushed to avoid syncing too much
+        * when there is some pending active queries.
+        */
+       cmd_buffer->active_query_flush_bits &= ~cmd_buffer->state.flush_bits;
+
        cmd_buffer->state.flush_bits = 0;
 
        /* If the driver used a compute shader for resetting a query pool, it