diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index 682875457cf..04383015958 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -2842,8 +2842,8 @@ static void handle_begin_query(struct vk_cmd_queue_entry *cmd, struct vk_cmd_begin_query *qcmd = &cmd->u.begin_query; VK_FROM_HANDLE(lvp_query_pool, pool, qcmd->query_pool); - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS && - pool->pipeline_stats & VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT) + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS && + pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT) emit_compute_state(state); emit_state(state); @@ -2879,8 +2879,8 @@ static void handle_begin_query_indexed_ext(struct vk_cmd_queue_entry *cmd, struct vk_cmd_begin_query_indexed_ext *qcmd = &cmd->u.begin_query_indexed_ext; VK_FROM_HANDLE(lvp_query_pool, pool, qcmd->query_pool); - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS && - pool->pipeline_stats & VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT) + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS && + pool->vk.pipeline_statistics & VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT) emit_compute_state(state); emit_state(state); @@ -2985,10 +2985,10 @@ static void handle_copy_query_pool_results(struct vk_cmd_queue_entry *cmd, if (pool->queries[i]) { unsigned num_results = 0; if (copycmd->flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) { - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { - num_results = util_bitcount(pool->pipeline_stats); + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + num_results = util_bitcount(pool->vk.pipeline_statistics); } else - num_results = pool-> type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT ? 2 : 1; + num_results = pool->vk.query_type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT ? 2 : 1; state->pctx->get_query_result_resource(state->pctx, pool->queries[i], flags, @@ -2997,9 +2997,9 @@ static void handle_copy_query_pool_results(struct vk_cmd_queue_entry *cmd, lvp_buffer_from_handle(copycmd->dst_buffer)->bo, offset + num_results * result_size); } - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { num_results = 0; - u_foreach_bit(bit, pool->pipeline_stats) + u_foreach_bit(bit, pool->vk.pipeline_statistics) state->pctx->get_query_result_resource(state->pctx, pool->queries[i], flags, diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index c24d38215d0..89f9972130d 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -81,6 +81,7 @@ typedef uint32_t xcb_window_t; #include "vk_graphics_state.h" #include "vk_pipeline_layout.h" #include "vk_queue.h" +#include "vk_query_pool.h" #include "vk_sampler.h" #include "vk_sync.h" #include "vk_sync_timeline.h" @@ -599,10 +600,7 @@ struct lvp_buffer_view { #define LVP_QUERY_ACCELERATION_STRUCTURE_INSTANCE_COUNT (PIPE_QUERY_TYPES + 3) struct lvp_query_pool { - struct vk_object_base base; - VkQueryType type; - uint32_t count; - VkQueryPipelineStatisticFlags pipeline_stats; + struct vk_query_pool vk; enum pipe_query_type base_type; void *data; /* Used by queries that are not implemented by pipe_query */ struct pipe_query *queries[0]; @@ -700,7 +698,7 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_shader, base, VkShaderEXT, VK_OBJECT_TYPE_SHADER_EXT) VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_pipeline_layout, vk.base, VkPipelineLayout, VK_OBJECT_TYPE_PIPELINE_LAYOUT) -VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_query_pool, base, VkQueryPool, +VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_query_pool, vk.base, VkQueryPool, VK_OBJECT_TYPE_QUERY_POOL) VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_sampler, vk.base, VkSampler, VK_OBJECT_TYPE_SAMPLER) diff --git a/src/gallium/frontends/lavapipe/lvp_query.c b/src/gallium/frontends/lavapipe/lvp_query.c index f0b025f8148..267f0c965d8 100644 --- a/src/gallium/frontends/lavapipe/lvp_query.c +++ b/src/gallium/frontends/lavapipe/lvp_query.c @@ -71,22 +71,16 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateQueryPool( return VK_ERROR_FEATURE_NOT_PRESENT; } - struct lvp_query_pool *pool; - size_t pool_size = sizeof(*pool) - + pCreateInfo->queryCount * query_size; + struct lvp_query_pool *pool = vk_query_pool_create(&device->vk, + pCreateInfo, + pAllocator, + sizeof(*pool) + + pCreateInfo->queryCount * query_size); - pool = vk_zalloc2(&device->vk.alloc, pAllocator, - pool_size, 8, - VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); 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->count = pCreateInfo->queryCount; pool->base_type = pipeq; - pool->pipeline_stats = pCreateInfo->pipelineStatistics; pool->data = &pool->queries; *pQueryPool = lvp_query_pool_to_handle(pool); @@ -105,12 +99,11 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyQueryPool( return; if (pool->base_type < PIPE_QUERY_TYPES) { - for (unsigned i = 0; i < pool->count; i++) + for (unsigned i = 0; i < pool->vk.query_count; i++) if (pool->queries[i]) device->queue.ctx->destroy_query(device->queue.ctx, pool->queries[i]); } - vk_object_base_finish(&pool->base); - vk_free2(&device->vk.alloc, pAllocator, pool); + vk_query_pool_destroy(&device->vk, pAllocator, &pool->vk); } VKAPI_ATTR VkResult VKAPI_CALL lvp_GetQueryPoolResults( @@ -166,21 +159,21 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_GetQueryPoolResults( if (flags & VK_QUERY_RESULT_64_BIT) { uint64_t *dest64 = (uint64_t *) dest; if (ready || (flags & VK_QUERY_RESULT_PARTIAL_BIT)) { - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { - uint32_t mask = pool->pipeline_stats; + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + uint32_t mask = pool->vk.pipeline_statistics; const uint64_t *pstats = result.pipeline_statistics.counters; while (mask) { uint32_t i = u_bit_scan(&mask); *dest64++ = pstats[i]; } - } else if (pool->type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { + } else if (pool->vk.query_type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { *dest64++ = result.so_statistics.num_primitives_written; *dest64++ = result.so_statistics.primitives_storage_needed; } else { *dest64++ = result.u64; } } else { - if (pool->type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { + if (pool->vk.query_type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { dest64 += 2; // 16 bytes } else { dest64 += 1; // 8 bytes @@ -192,14 +185,14 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_GetQueryPoolResults( } else { uint32_t *dest32 = (uint32_t *) dest; if (ready || (flags & VK_QUERY_RESULT_PARTIAL_BIT)) { - if (pool->type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { - uint32_t mask = pool->pipeline_stats; + if (pool->vk.query_type == VK_QUERY_TYPE_PIPELINE_STATISTICS) { + uint32_t mask = pool->vk.pipeline_statistics; const uint64_t *pstats = result.pipeline_statistics.counters; while (mask) { uint32_t i = u_bit_scan(&mask); *dest32++ = (uint32_t) MIN2(pstats[i], UINT32_MAX); } - } else if (pool->type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { + } else if (pool->vk.query_type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { *dest32++ = (uint32_t) MIN2(result.so_statistics.num_primitives_written, UINT32_MAX); *dest32++ = (uint32_t) @@ -208,7 +201,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_GetQueryPoolResults( *dest32++ = (uint32_t) (result.u64 & UINT32_MAX); } } else { - if (pool->type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { + if (pool->vk.query_type == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) { dest32 += 2; // 8 bytes } else { dest32 += 1; // 4 bytes