diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 0f74c354c84..6f2b6d84401 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -65,6 +65,7 @@ #include "vk_instance.h" #include "vk_log.h" #include "vk_physical_device.h" +#include "vk_query_pool.h" #include "vk_queue.h" #include "vk_sampler.h" #include "vk_shader_module.h" @@ -2939,14 +2940,12 @@ VkResult radv_device_init_meta(struct radv_device *device); void radv_device_finish_meta(struct radv_device *device); struct radv_query_pool { - struct vk_object_base base; + struct vk_query_pool vk; struct radeon_winsys_bo *bo; uint32_t stride; uint32_t availability_offset; uint64_t size; char *ptr; - VkQueryType type; - uint32_t pipeline_stats_mask; bool uses_gds; /* For NGG GS on GFX10+ */ }; @@ -3661,7 +3660,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(radv_indirect_command_layout, base, VkIndirectCom VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV) VK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, base, VkPipeline, VK_OBJECT_TYPE_PIPELINE) VK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, base, VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT) -VK_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, base, VkQueryPool, VK_OBJECT_TYPE_QUERY_POOL) +VK_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, vk.base, VkQueryPool, VK_OBJECT_TYPE_QUERY_POOL) VK_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, vk.base, VkSampler, VK_OBJECT_TYPE_SAMPLER) VK_DEFINE_NONDISP_HANDLE_CASTS(radv_video_session, vk.base, VkVideoSessionKHR, VK_OBJECT_TYPE_VIDEO_SESSION_KHR) diff --git a/src/amd/vulkan/radv_query.c b/src/amd/vulkan/radv_query.c index fb295de8e1d..1ae65d0cc82 100644 --- a/src/amd/vulkan/radv_query.c +++ b/src/amd/vulkan/radv_query.c @@ -1027,7 +1027,7 @@ static void radv_destroy_query_pool(struct radv_device *device, const VkAllocationCallbacks *pAllocator, struct radv_query_pool *pool) { - if (pool->type == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) + if (pool->vk.query_type == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) radv_pc_deinit_query_pool((struct radv_pc_query_pool *)pool); if (pool->bo) { @@ -1036,7 +1036,7 @@ radv_destroy_query_pool(struct radv_device *device, const VkAllocationCallbacks } radv_rmv_log_resource_destroy(device, (uint64_t)radv_query_pool_to_handle(pool)); - vk_object_base_finish(&pool->base); + vk_query_pool_finish(&pool->vk); vk_free2(&device->vk.alloc, pAllocator, pool); } @@ -1055,10 +1055,7 @@ radv_create_query_pool(struct radv_device *device, const VkQueryPoolCreateInfo * if (!pool) return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); - vk_object_base_init(&device->vk, &pool->base, VK_OBJECT_TYPE_QUERY_POOL); - - pool->type = pCreateInfo->queryType; - pool->pipeline_stats_mask = pCreateInfo->pipelineStatistics; + vk_query_pool_init(&device->vk, &pool->vk, pCreateInfo); /* The number of primitives generated by geometry shader invocations is only counted by the * hardware if GS uses the legacy path. When NGG GS is used, the hardware can't know the number @@ -1070,8 +1067,8 @@ radv_create_query_pool(struct radv_device *device, const VkQueryPoolCreateInfo * */ pool->uses_gds = (device->physical_device->emulate_ngg_gs_query_pipeline_stat && - (pool->pipeline_stats_mask & (VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT | - VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT))) || + (pool->vk.pipeline_statistics & (VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT | + VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT))) || (device->physical_device->use_ngg && pCreateInfo->queryType == VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT); switch (pCreateInfo->queryType) { @@ -1175,7 +1172,7 @@ radv_GetQueryPoolResults(VkDevice _device, VkQueryPool queryPool, uint32_t first char *src = pool->ptr + query * pool->stride; uint32_t available; - switch (pool->type) { + switch (pool->vk.query_type) { case VK_QUERY_TYPE_TIMESTAMP: case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR: case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR: @@ -1258,9 +1255,9 @@ radv_GetQueryPoolResults(VkDevice _device, VkQueryPool queryPool, uint32_t first const uint64_t *stop = (uint64_t *)(src + pipelinestat_block_size); if (flags & VK_QUERY_RESULT_64_BIT) { uint64_t *dst = (uint64_t *)dest; - dest += util_bitcount(pool->pipeline_stats_mask) * 8; + dest += util_bitcount(pool->vk.pipeline_statistics) * 8; for (int i = 0; i < ARRAY_SIZE(pipeline_statistics_indices); ++i) { - if (pool->pipeline_stats_mask & (1u << i)) { + if (pool->vk.pipeline_statistics & (1u << i)) { if (available || (flags & VK_QUERY_RESULT_PARTIAL_BIT)) { *dst = stop[pipeline_statistics_indices[i]] - start[pipeline_statistics_indices[i]]; } @@ -1270,9 +1267,9 @@ radv_GetQueryPoolResults(VkDevice _device, VkQueryPool queryPool, uint32_t first } else { uint32_t *dst = (uint32_t *)dest; - dest += util_bitcount(pool->pipeline_stats_mask) * 4; + dest += util_bitcount(pool->vk.pipeline_statistics) * 4; for (int i = 0; i < ARRAY_SIZE(pipeline_statistics_indices); ++i) { - if (pool->pipeline_stats_mask & (1u << i)) { + if (pool->vk.pipeline_statistics & (1u << i)) { if (available || (flags & VK_QUERY_RESULT_PARTIAL_BIT)) { *dst = stop[pipeline_statistics_indices[i]] - start[pipeline_statistics_indices[i]]; } @@ -1417,7 +1414,7 @@ static size_t radv_query_result_size(const struct radv_query_pool *pool, VkQueryResultFlags flags) { unsigned values = (flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) ? 1 : 0; - switch (pool->type) { + switch (pool->vk.query_type) { case VK_QUERY_TYPE_TIMESTAMP: case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR: case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR: @@ -1427,7 +1424,7 @@ radv_query_result_size(const struct radv_query_pool *pool, VkQueryResultFlags fl values += 1; break; case VK_QUERY_TYPE_PIPELINE_STATISTICS: - values += util_bitcount(pool->pipeline_stats_mask); + values += util_bitcount(pool->vk.pipeline_statistics); break; case VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT: values += 2; @@ -1477,7 +1474,7 @@ radv_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPoo */ emit_query_flush(cmd_buffer, pool); - switch (pool->type) { + switch (pool->vk.query_type) { case VK_QUERY_TYPE_OCCLUSION: radv_query_shader(cmd_buffer, &cmd_buffer->device->meta_state.query.occlusion_query_pipeline, pool->bo, dst_buffer->bo, firstQuery * pool->stride, dst_buffer->offset + dstOffset, pool->stride, stride, @@ -1498,7 +1495,7 @@ radv_CmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPoo } radv_query_shader(cmd_buffer, &cmd_buffer->device->meta_state.query.pipeline_statistics_query_pipeline, pool->bo, dst_buffer->bo, firstQuery * pool->stride, dst_buffer->offset + dstOffset, pool->stride, stride, - dst_size, queryCount, flags, pool->pipeline_stats_mask, + dst_size, queryCount, flags, pool->vk.pipeline_statistics, pool->availability_offset + 4 * firstQuery, false); break; case VK_QUERY_TYPE_TIMESTAMP: @@ -1587,7 +1584,7 @@ radv_CmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uin { RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer); RADV_FROM_HANDLE(radv_query_pool, pool, queryPool); - uint32_t value = query_clear_value(pool->type); + uint32_t value = query_clear_value(pool->vk.query_type); uint32_t flush_bits = 0; /* Make sure to sync all previous work if the given command buffer has @@ -1599,7 +1596,7 @@ radv_CmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uin flush_bits |= radv_fill_buffer(cmd_buffer, NULL, pool->bo, radv_buffer_get_va(pool->bo) + firstQuery * pool->stride, queryCount * pool->stride, value); - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { flush_bits |= radv_fill_buffer(cmd_buffer, NULL, pool->bo, radv_buffer_get_va(pool->bo) + pool->availability_offset + firstQuery * 4, queryCount * 4, 0); @@ -1617,14 +1614,14 @@ radv_ResetQueryPool(VkDevice _device, VkQueryPool queryPool, uint32_t firstQuery { RADV_FROM_HANDLE(radv_query_pool, pool, queryPool); - uint32_t value = query_clear_value(pool->type); + uint32_t value = query_clear_value(pool->vk.query_type); uint32_t *data = (uint32_t *)(pool->ptr + firstQuery * pool->stride); uint32_t *data_end = (uint32_t *)(pool->ptr + (firstQuery + queryCount) * pool->stride); for (uint32_t *p = data; p != data_end; ++p) *p = value; - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { memset(pool->ptr + pool->availability_offset + firstQuery * 4, 0, queryCount * 4); } } @@ -1737,13 +1734,13 @@ emit_begin_query(struct radv_cmd_buffer *cmd_buffer, struct radv_query_pool *poo radeon_emit(cs, va >> 32); if (pool->uses_gds) { - if (pool->pipeline_stats_mask & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT) { + if (pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT) { uint32_t gs_prim_offset = radv_get_pipelinestat_query_offset(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT); gfx10_copy_gds_query(cmd_buffer, RADV_SHADER_QUERY_GS_PRIM_EMIT_OFFSET, va + gs_prim_offset); } else { - assert(pool->pipeline_stats_mask & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); + assert(pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); uint32_t gs_invoc_offset = radv_get_pipelinestat_query_offset(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); @@ -1886,13 +1883,13 @@ emit_end_query(struct radv_cmd_buffer *cmd_buffer, struct radv_query_pool *pool, EOP_DATA_SEL_VALUE_32BIT, avail_va, 1, cmd_buffer->gfx9_eop_bug_va); if (pool->uses_gds) { - if (pool->pipeline_stats_mask & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT) { + if (pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT) { uint32_t gs_prim_offset = radv_get_pipelinestat_query_offset(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT); gfx10_copy_gds_query(cmd_buffer, RADV_SHADER_QUERY_GS_PRIM_EMIT_OFFSET, va + gs_prim_offset); } else { - assert(pool->pipeline_stats_mask & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); + assert(pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); uint32_t gs_invoc_offset = radv_get_pipelinestat_query_offset(VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT); @@ -1991,7 +1988,7 @@ radv_CmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPoo va += pool->stride * query; - emit_begin_query(cmd_buffer, pool, va, pool->type, flags, index); + emit_begin_query(cmd_buffer, pool, va, pool->vk.query_type, flags, index); } VKAPI_ATTR void VKAPI_CALL @@ -2006,7 +2003,7 @@ radv_CmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, /* Do not need to add the pool BO to the list because the query must * currently be active, which means the BO is already in the list. */ - emit_end_query(cmd_buffer, pool, va, avail_va, pool->type, index); + emit_end_query(cmd_buffer, pool, va, avail_va, pool->vk.query_type, index); /* * For multiview we have to emit a query for each bit in the mask, @@ -2020,8 +2017,8 @@ radv_CmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool, for (unsigned i = 1; i < util_bitcount(cmd_buffer->state.render.view_mask); i++) { va += pool->stride; avail_va += 4; - emit_begin_query(cmd_buffer, pool, va, pool->type, 0, 0); - emit_end_query(cmd_buffer, pool, va, avail_va, pool->type, 0); + emit_begin_query(cmd_buffer, pool, va, pool->vk.query_type, 0, 0); + emit_end_query(cmd_buffer, pool, va, avail_va, pool->vk.query_type, 0); } } } diff --git a/src/amd/vulkan/radv_rmv.c b/src/amd/vulkan/radv_rmv.c index 1564b8d75ed..082f48a058b 100644 --- a/src/amd/vulkan/radv_rmv.c +++ b/src/amd/vulkan/radv_rmv.c @@ -607,8 +607,8 @@ radv_rmv_log_query_pool_create(struct radv_device *device, VkQueryPool _pool, bo RADV_FROM_HANDLE(radv_query_pool, pool, _pool); - if (pool->type != VK_QUERY_TYPE_OCCLUSION && pool->type != VK_QUERY_TYPE_PIPELINE_STATISTICS && - pool->type != VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) + if (pool->vk.query_type != VK_QUERY_TYPE_OCCLUSION && pool->vk.query_type != VK_QUERY_TYPE_PIPELINE_STATISTICS && + pool->vk.query_type != VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) return; radv_rmv_log_bo_allocate(device, pool->bo, pool->size, is_internal); @@ -618,7 +618,7 @@ radv_rmv_log_query_pool_create(struct radv_device *device, VkQueryPool _pool, bo create_token.is_driver_internal = is_internal; create_token.resource_id = vk_rmv_get_resource_id_locked(&device->vk, (uint64_t)_pool); create_token.type = VK_RMV_RESOURCE_TYPE_QUERY_HEAP; - create_token.query_pool.type = pool->type; + create_token.query_pool.type = pool->vk.query_type; create_token.query_pool.has_cpu_access = true; vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_RESOURCE_CREATE, &create_token);