From: Jason Ekstrand Date: Thu, 3 Dec 2015 21:25:12 +0000 (-0800) Subject: vk/0.210.0: Update queries to the new API X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=888744cabf8daaa463394d0cf10341ab00a5ecd5;p=mesa.git vk/0.210.0: Update queries to the new API --- diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index b382f548bf8..ab6b342c733 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -432,9 +432,10 @@ typedef enum VkPhysicalDeviceType { typedef enum VkQueryType { VK_QUERY_TYPE_OCCLUSION = 0, VK_QUERY_TYPE_PIPELINE_STATISTICS = 1, + VK_QUERY_TYPE_TIMESTAMP = 2, VK_QUERY_TYPE_BEGIN_RANGE = VK_QUERY_TYPE_OCCLUSION, - VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_PIPELINE_STATISTICS, - VK_QUERY_TYPE_RANGE_SIZE = (VK_QUERY_TYPE_PIPELINE_STATISTICS - VK_QUERY_TYPE_OCCLUSION + 1), + VK_QUERY_TYPE_END_RANGE = VK_QUERY_TYPE_TIMESTAMP, + VK_QUERY_TYPE_RANGE_SIZE = (VK_QUERY_TYPE_TIMESTAMP - VK_QUERY_TYPE_OCCLUSION + 1), VK_QUERY_TYPE_MAX_ENUM = 0x7FFFFFFF } VkQueryType; @@ -752,15 +753,6 @@ typedef enum VkIndexType { VK_INDEX_TYPE_MAX_ENUM = 0x7FFFFFFF } VkIndexType; -typedef enum { - VK_TIMESTAMP_TYPE_TOP = 0, - VK_TIMESTAMP_TYPE_BOTTOM = 1, - VK_TIMESTAMP_TYPE_BEGIN_RANGE = VK_TIMESTAMP_TYPE_TOP, - VK_TIMESTAMP_TYPE_END_RANGE = VK_TIMESTAMP_TYPE_BOTTOM, - VK_TIMESTAMP_TYPE_NUM = (VK_TIMESTAMP_TYPE_BOTTOM - VK_TIMESTAMP_TYPE_TOP + 1), - VK_TIMESTAMP_TYPE_MAX_ENUM = 0x7FFFFFFF -} VkTimestampType; - typedef enum VkSubpassContents { VK_SUBPASS_CONTENTS_INLINE = 0, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS = 1, @@ -874,17 +866,17 @@ typedef VkFlags VkEventCreateFlags; typedef VkFlags VkQueryPoolCreateFlags; typedef enum VkQueryPipelineStatisticFlagBits { - VK_QUERY_PIPELINE_STATISTIC_IA_VERTICES_BIT = 0x00000001, - VK_QUERY_PIPELINE_STATISTIC_IA_PRIMITIVES_BIT = 0x00000002, - VK_QUERY_PIPELINE_STATISTIC_VS_INVOCATIONS_BIT = 0x00000004, - VK_QUERY_PIPELINE_STATISTIC_GS_INVOCATIONS_BIT = 0x00000008, - VK_QUERY_PIPELINE_STATISTIC_GS_PRIMITIVES_BIT = 0x00000010, - VK_QUERY_PIPELINE_STATISTIC_C_INVOCATIONS_BIT = 0x00000020, - VK_QUERY_PIPELINE_STATISTIC_C_PRIMITIVES_BIT = 0x00000040, - VK_QUERY_PIPELINE_STATISTIC_FS_INVOCATIONS_BIT = 0x00000080, - VK_QUERY_PIPELINE_STATISTIC_TCS_PATCHES_BIT = 0x00000100, - VK_QUERY_PIPELINE_STATISTIC_TES_INVOCATIONS_BIT = 0x00000200, - VK_QUERY_PIPELINE_STATISTIC_CS_INVOCATIONS_BIT = 0x00000400, + VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT = 0x00000001, + VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT = 0x00000002, + VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT = 0x00000004, + VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_INVOCATIONS_BIT = 0x00000008, + VK_QUERY_PIPELINE_STATISTIC_GEOMETRY_SHADER_PRIMITIVES_BIT = 0x00000010, + VK_QUERY_PIPELINE_STATISTIC_CLIPPING_INVOCATIONS_BIT = 0x00000020, + VK_QUERY_PIPELINE_STATISTIC_CLIPPING_PRIMITIVES_BIT = 0x00000040, + VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT = 0x00000080, + VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_CONTROL_SHADER_PATCHES_BIT = 0x00000100, + VK_QUERY_PIPELINE_STATISTIC_TESSELLATION_EVALUATION_SHADER_INVOCATIONS_BIT = 0x00000200, + VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT = 0x00000400, } VkQueryPipelineStatisticFlagBits; typedef VkFlags VkQueryPipelineStatisticFlags; @@ -1047,6 +1039,11 @@ typedef enum VkCommandBufferUsageFlagBits { } VkCommandBufferUsageFlagBits; typedef VkFlags VkCommandBufferUsageFlags; +typedef enum VkQueryControlFlagBits { + VK_QUERY_CONTROL_PRECISE_BIT = 0x00000001, +} VkQueryControlFlagBits; +typedef VkFlags VkQueryControlFlags; + typedef enum VkCommandBufferResetFlagBits { VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT = 0x00000001, } VkCommandBufferResetFlagBits; @@ -1060,11 +1057,6 @@ typedef enum VkStencilFaceFlagBits { } VkStencilFaceFlagBits; typedef VkFlags VkStencilFaceFlags; -typedef enum { - VK_QUERY_CONTROL_CONSERVATIVE_BIT = 0x00000001, -} VkQueryControlFlagBits; -typedef VkFlags VkQueryControlFlags; - typedef void* (VKAPI_PTR *PFN_vkAllocationFunction)( void* pUserData, size_t size, @@ -2018,6 +2010,9 @@ typedef struct VkCommandBufferBeginInfo { VkRenderPass renderPass; uint32_t subpass; VkFramebuffer framebuffer; + VkBool32 occlusionQueryEnable; + VkQueryControlFlags queryFlags; + VkQueryPipelineStatisticFlags pipelineStatistics; } VkCommandBufferBeginInfo; typedef struct VkBufferCopy { @@ -2208,7 +2203,7 @@ typedef VkResult (VKAPI_PTR *PFN_vkSetEvent)(VkDevice device, VkEvent event); typedef VkResult (VKAPI_PTR *PFN_vkResetEvent)(VkDevice device, VkEvent event); typedef VkResult (VKAPI_PTR *PFN_vkCreateQueryPool)(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool); typedef void (VKAPI_PTR *PFN_vkDestroyQueryPool)(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator); -typedef VkResult (VKAPI_PTR *PFN_vkGetQueryPoolResults)(VkDevice device, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount, size_t* pDataSize, void* pData, VkQueryResultFlags flags); +typedef VkResult (VKAPI_PTR *PFN_vkGetQueryPoolResults)(VkDevice device, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags); typedef VkResult (VKAPI_PTR *PFN_vkCreateBuffer)(VkDevice device, const VkBufferCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer); typedef void (VKAPI_PTR *PFN_vkDestroyBuffer)(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks* pAllocator); typedef VkResult (VKAPI_PTR *PFN_vkCreateBufferView)(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkBufferView* pView); @@ -2289,7 +2284,7 @@ typedef void (VKAPI_PTR *PFN_vkCmdPipelineBarrier)(VkCommandBuffer commandBuffer typedef void (VKAPI_PTR *PFN_vkCmdBeginQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t entry, VkQueryControlFlags flags); typedef void (VKAPI_PTR *PFN_vkCmdEndQuery)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t entry); typedef void (VKAPI_PTR *PFN_vkCmdResetQueryPool)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount); -typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp)(VkCommandBuffer commandBuffer, VkTimestampType timestampType, VkBuffer destBuffer, VkDeviceSize destOffset); +typedef void (VKAPI_PTR *PFN_vkCmdWriteTimestamp)(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage, VkQueryPool queryPool, uint32_t entry); typedef void (VKAPI_PTR *PFN_vkCmdCopyQueryPoolResults)(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize stride, VkQueryResultFlags flags); typedef void (VKAPI_PTR *PFN_vkCmdPushConstants)(VkCommandBuffer commandBuffer, VkPipelineLayout layout, VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size, const void* pValues); typedef void (VKAPI_PTR *PFN_vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo* pRenderPassBegin, VkSubpassContents contents); @@ -2558,8 +2553,9 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults( VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount, - size_t* pDataSize, + size_t dataSize, void* pData, + VkDeviceSize stride, VkQueryResultFlags flags); VKAPI_ATTR VkResult VKAPI_CALL vkCreateBuffer( @@ -3045,9 +3041,9 @@ VKAPI_ATTR void VKAPI_CALL vkCmdResetQueryPool( VKAPI_ATTR void VKAPI_CALL vkCmdWriteTimestamp( VkCommandBuffer commandBuffer, - VkTimestampType timestampType, - VkBuffer destBuffer, - VkDeviceSize destOffset); + VkPipelineStageFlagBits pipelineStage, + VkQueryPool queryPool, + uint32_t entry); VKAPI_ATTR void VKAPI_CALL vkCmdCopyQueryPoolResults( VkCommandBuffer commandBuffer, diff --git a/src/vulkan/anv_query.c b/src/vulkan/anv_query.c index 320d42cb6fd..911b9a41264 100644 --- a/src/vulkan/anv_query.c +++ b/src/vulkan/anv_query.c @@ -38,17 +38,22 @@ VkResult anv_CreateQueryPool( ANV_FROM_HANDLE(anv_device, device, _device); struct anv_query_pool *pool; VkResult result; - size_t size; + uint32_t slot_size; + uint64_t size; assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO); switch (pCreateInfo->queryType) { case VK_QUERY_TYPE_OCCLUSION: + slot_size = sizeof(struct anv_query_pool_slot); break; case VK_QUERY_TYPE_PIPELINE_STATISTICS: return VK_ERROR_INCOMPATIBLE_DRIVER; + case VK_QUERY_TYPE_TIMESTAMP: + slot_size = sizeof(uint64_t); + break; default: - unreachable(""); + assert(!"Invalid query type"); } pool = anv_alloc2(&device->alloc, pAllocator, sizeof(*pool), 8, @@ -56,7 +61,10 @@ VkResult anv_CreateQueryPool( if (pool == NULL) return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); - size = pCreateInfo->entryCount * sizeof(struct anv_query_pool_slot); + pool->type = pCreateInfo->queryType; + pool->slots = pCreateInfo->entryCount; + + size = pCreateInfo->entryCount * slot_size; result = anv_bo_init_new(&pool->bo, device, size); if (result != VK_SUCCESS) goto fail; @@ -91,16 +99,14 @@ VkResult anv_GetQueryPoolResults( VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount, - size_t* pDataSize, + size_t dataSize, void* pData, + VkDeviceSize stride, VkQueryResultFlags flags) { ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_query_pool, pool, queryPool); - struct anv_query_pool_slot *slot = pool->bo.map; int64_t timeout = INT64_MAX; - uint32_t *dst32 = pData; - uint64_t *dst64 = pData; uint64_t result; int ret; @@ -110,12 +116,8 @@ VkResult anv_GetQueryPoolResults( return VK_ERROR_INCOMPATIBLE_DRIVER; } - assert(pool->type == VK_QUERY_TYPE_OCCLUSION); - - if (flags & VK_QUERY_RESULT_64_BIT) - *pDataSize = queryCount * sizeof(uint64_t); - else - *pDataSize = queryCount * sizeof(uint32_t); + assert(pool->type == VK_QUERY_TYPE_OCCLUSION || + pool->type == VK_QUERY_TYPE_TIMESTAMP); if (pData == NULL) return VK_SUCCESS; @@ -129,15 +131,37 @@ VkResult anv_GetQueryPoolResults( } } + void *data_end = pData + dataSize; + for (uint32_t i = 0; i < queryCount; i++) { - result = slot[startQuery + i].end - slot[startQuery + i].begin; + switch (pool->type) { + case VK_QUERY_TYPE_OCCLUSION: { + struct anv_query_pool_slot *slot = pool->bo.map; + result = slot[startQuery + i].end - slot[startQuery + i].begin; + break; + } + case VK_QUERY_TYPE_PIPELINE_STATISTICS: + /* Not yet implemented */ + break; + case VK_QUERY_TYPE_TIMESTAMP: { + uint64_t *slot = pool->bo.map; + result = slot[startQuery + i]; + break; + } + default: + assert(!"Invalid query type"); + } + if (flags & VK_QUERY_RESULT_64_BIT) { - *dst64++ = result; + *(uint64_t *)pData = result; } else { if (result > UINT32_MAX) result = UINT32_MAX; - *dst32++ = result; + *(uint32_t *)pData = result; } + pData += stride; + if (pData >= data_end) + break; } return VK_SUCCESS; diff --git a/src/vulkan/gen8_cmd_buffer.c b/src/vulkan/gen8_cmd_buffer.c index 23dc9ad5748..6d0ac25b6d8 100644 --- a/src/vulkan/gen8_cmd_buffer.c +++ b/src/vulkan/gen8_cmd_buffer.c @@ -854,33 +854,32 @@ void genX(CmdEndQuery)( void genX(CmdWriteTimestamp)( VkCommandBuffer commandBuffer, - VkTimestampType timestampType, - VkBuffer destBuffer, - VkDeviceSize destOffset) + VkPipelineStageFlagBits pipelineStage, + VkQueryPool queryPool, + uint32_t entry) { ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer); - ANV_FROM_HANDLE(anv_buffer, buffer, destBuffer); - struct anv_bo *bo = buffer->bo; + ANV_FROM_HANDLE(anv_query_pool, pool, queryPool); - switch (timestampType) { - case VK_TIMESTAMP_TYPE_TOP: + assert(pool->type == VK_QUERY_TYPE_TIMESTAMP); + + switch (pipelineStage) { + case VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT: anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM), .RegisterAddress = TIMESTAMP, - .MemoryAddress = { bo, buffer->offset + destOffset }); + .MemoryAddress = { &pool->bo, entry * 8 }); anv_batch_emit(&cmd_buffer->batch, GENX(MI_STORE_REGISTER_MEM), .RegisterAddress = TIMESTAMP + 4, - .MemoryAddress = { bo, buffer->offset + destOffset + 4 }); + .MemoryAddress = { &pool->bo, entry * 8 + 4 }); break; - case VK_TIMESTAMP_TYPE_BOTTOM: + default: + /* Everything else is bottom-of-pipe */ anv_batch_emit(&cmd_buffer->batch, GENX(PIPE_CONTROL), .DestinationAddressType = DAT_PPGTT, .PostSyncOperation = WriteTimestamp, .Address = /* FIXME: This is only lower 32 bits */ - { bo, buffer->offset + destOffset }); - break; - - default: + { &pool->bo, entry * 8 }); break; } }