yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
b118451e3
master
1// vk-query.cpp 2#include "vk-query.h" 3 4#include "vk-util.h" 5 6namespace gfx 7{ 8 9using namespace Slang ; 10 11namespace vk 12{ 13Result QueryPoolImpl ::init (const IQueryPool ::Desc & desc ,DeviceImpl * device ) 14{ 15m_device = device ; 16m_pool = VK_NULL_HANDLE ; 17VkQueryPoolCreateInfo createInfo = {}; 18createInfo .sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO ; 19createInfo .queryCount = (uint32_t )desc .count ; 20switch (desc .type ) 21 { 22case QueryType ::Timestamp : 23createInfo .queryType = VK_QUERY_TYPE_TIMESTAMP ; 24break ; 25case QueryType ::AccelerationStructureCompactedSize : 26createInfo .queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR ; 27break ; 28case QueryType ::AccelerationStructureSerializedSize : 29createInfo .queryType = VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR ; 30break ; 31case QueryType ::AccelerationStructureCurrentSize : 32// Vulkan does not support CurrentSize query, will not create actual pools here. 33return SLANG_OK ; 34default : 35return SLANG_E_INVALID_ARG ; 36 } 37SLANG_VK_RETURN_ON_FAIL ( 38m_device -> m_api .vkCreateQueryPool (m_device -> m_api .m_device ,& createInfo ,nullptr ,& m_pool )); 39return SLANG_OK ; 40} 41 42QueryPoolImpl ::~QueryPoolImpl () 43{ 44m_device -> m_api .vkDestroyQueryPool (m_device -> m_api .m_device ,m_pool ,nullptr ); 45} 46 47Result QueryPoolImpl ::getResult (GfxIndex index ,GfxCount count ,uint64_t * data ) 48{ 49if (!m_pool ) 50 { 51// Vulkan does not support CurrentSize query, return 0 here. 52for (SlangInt i = 0 ;i < count ;i ++ ) 53data [i ]= 0 ; 54return SLANG_OK ; 55 } 56 57SLANG_VK_RETURN_ON_FAIL (m_device -> m_api .vkGetQueryPoolResults ( 58m_device -> m_api .m_device , 59m_pool , 60 (uint32_t )index , 61 (uint32_t )count , 62sizeof (uint64_t )* count , 63data , 64sizeof (uint64_t ), 65VK_QUERY_RESULT_64_BIT |VK_QUERY_RESULT_WAIT_BIT )); 66return SLANG_OK ; 67} 68 69void _writeTimestamp ( 70VulkanApi * api , 71VkCommandBuffer vkCmdBuffer , 72IQueryPool * queryPool , 73SlangInt index ) 74{ 75auto queryPoolImpl = static_cast < QueryPoolImpl *> (queryPool ); 76api -> vkCmdResetQueryPool (vkCmdBuffer ,queryPoolImpl -> m_pool , (uint32_t )index ,1 ); 77api -> vkCmdWriteTimestamp ( 78vkCmdBuffer , 79VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT , 80queryPoolImpl -> m_pool , 81 (uint32_t )index ); 82} 83 84}// namespace vk 85}// namespace gfx