QueryPool object creation Added QueryPool object. Fixes all tests in: dEQP-VK.api.object_management.*.query_pool Change-Id: Ie564848b616714c39961e7a80bc421ec7bb0ef58 Reviewed-on: https://swiftshader-review.googlesource.com/c/23948 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Chris Forbes <chrisforbes@google.com> Reviewed-by: Corentin Wallez <cwallez@google.com>
diff --git a/src/Vulkan/VkDestroy.h b/src/Vulkan/VkDestroy.h index f147aab..25ef90a 100644 --- a/src/Vulkan/VkDestroy.h +++ b/src/Vulkan/VkDestroy.h
@@ -28,6 +28,7 @@ #include "VkPipelineCache.hpp" #include "VkPipelineLayout.hpp" #include "VkPhysicalDevice.hpp" +#include "VkQueryPool.hpp" #include "VkQueue.hpp" #include "VkSampler.hpp" #include "VkSemaphore.hpp"
diff --git a/src/Vulkan/VkQueryPool.cpp b/src/Vulkan/VkQueryPool.cpp new file mode 100644 index 0000000..8a63208 --- /dev/null +++ b/src/Vulkan/VkQueryPool.cpp
@@ -0,0 +1,54 @@ +// Copyright 2018 The SwiftShader Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "VkQueryPool.hpp" + +namespace vk +{ + QueryPool::QueryPool(const VkQueryPoolCreateInfo* pCreateInfo, void* mem) : + queryCount(pCreateInfo->queryCount) + { + // According to the Vulkan spec, section 34.1. Features: + // "pipelineStatisticsQuery specifies whether the pipeline statistics + // queries are supported. If this feature is not enabled, queries of + // type VK_QUERY_TYPE_PIPELINE_STATISTICS cannot be created, and + // none of the VkQueryPipelineStatisticFlagBits bits can be set in the + // pipelineStatistics member of the VkQueryPoolCreateInfo structure." + if(pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) + { + UNIMPLEMENTED(); + } + } + + size_t QueryPool::ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo* pCreateInfo) + { + return 0; + } + + void QueryPool::getResults(uint32_t pFirstQuery, uint32_t pQueryCount, size_t pDataSize, + void* pData, VkDeviceSize pStride, VkQueryResultFlags pFlags) const + { + // dataSize must be large enough to contain the result of each query + ASSERT(static_cast<size_t>(pStride * pQueryCount) <= pDataSize); + + // The sum of firstQuery and queryCount must be less than or equal to the number of queries + ASSERT((pFirstQuery + pQueryCount) <= queryCount); + + char* data = static_cast<char*>(pData); + for(uint32_t i = 0; i < pQueryCount; i++, data += pStride) + { + UNIMPLEMENTED(); + } + } +} // namespace vk
diff --git a/src/Vulkan/VkQueryPool.hpp b/src/Vulkan/VkQueryPool.hpp new file mode 100644 index 0000000..9f8072e --- /dev/null +++ b/src/Vulkan/VkQueryPool.hpp
@@ -0,0 +1,45 @@ +// Copyright 2018 The SwiftShader Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef VK_QUERY_POOL_HPP_ +#define VK_QUERY_POOL_HPP_ + +#include "VkObject.hpp" + +namespace vk +{ + +class QueryPool : public Object<QueryPool, VkQueryPool> +{ +public: + QueryPool(const VkQueryPoolCreateInfo* pCreateInfo, void* mem); + ~QueryPool() = delete; + + static size_t ComputeRequiredAllocationSize(const VkQueryPoolCreateInfo* pCreateInfo); + + void getResults(uint32_t pFirstQuery, uint32_t pQueryCount, size_t pDataSize, + void* pData, VkDeviceSize pStride, VkQueryResultFlags pFlags) const; + +private: + uint32_t queryCount; +}; + +static inline QueryPool* Cast(VkQueryPool object) +{ + return reinterpret_cast<QueryPool*>(object); +} + +} // namespace vk + +#endif // VK_QUERY_POOL_HPP_
diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp index e222213..0fc4adb 100644 --- a/src/Vulkan/libVulkan.cpp +++ b/src/Vulkan/libVulkan.cpp
@@ -32,6 +32,7 @@ #include "VkPipeline.hpp" #include "VkPipelineCache.hpp" #include "VkPipelineLayout.hpp" +#include "VkQueryPool.hpp" #include "VkQueue.hpp" #include "VkSampler.hpp" #include "VkSemaphore.hpp" @@ -747,21 +748,32 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkQueryPool* pQueryPool) { - TRACE("()"); - UNIMPLEMENTED(); - return VK_SUCCESS; + TRACE("(VkDevice device = 0x%X, const VkQueryPoolCreateInfo* pCreateInfo = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X, VkQueryPool* pQueryPool = 0x%X)", + device, pCreateInfo, pAllocator, pQueryPool); + + if(pCreateInfo->pNext || pCreateInfo->flags) + { + UNIMPLEMENTED(); + } + + return vk::QueryPool::Create(pAllocator, pCreateInfo, pQueryPool); } VKAPI_ATTR void VKAPI_CALL vkDestroyQueryPool(VkDevice device, VkQueryPool queryPool, const VkAllocationCallbacks* pAllocator) { - TRACE("()"); - UNIMPLEMENTED(); + TRACE("(VkDevice device = 0x%X, VkQueryPool queryPool = 0x%X, const VkAllocationCallbacks* pAllocator = 0x%X)", + device, queryPool, pAllocator); + + vk::destroy(queryPool, pAllocator); } VKAPI_ATTR VkResult VKAPI_CALL vkGetQueryPoolResults(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void* pData, VkDeviceSize stride, VkQueryResultFlags flags) { - TRACE("()"); - UNIMPLEMENTED(); + TRACE("(VkDevice device = 0x%X, VkQueryPool queryPool = 0x%X, uint32_t firstQuery = %d, uint32_t queryCount = %d, size_t dataSize = %d, void* pData = 0x%X, VkDeviceSize stride = 0x%X, VkQueryResultFlags flags = %d)", + device, queryPool, firstQuery, queryCount, dataSize, pData, stride, flags); + + vk::Cast(queryPool)->getResults(firstQuery, queryCount, dataSize, pData, stride, flags); + return VK_SUCCESS; }
diff --git a/src/Vulkan/vulkan.vcxproj b/src/Vulkan/vulkan.vcxproj index 32abd27..4c18fcb 100644 --- a/src/Vulkan/vulkan.vcxproj +++ b/src/Vulkan/vulkan.vcxproj
@@ -116,6 +116,7 @@ <ClCompile Include="VkPipeline.cpp" /> <ClCompile Include="VkPipelineLayout.cpp" /> <ClCompile Include="VkPromotedExtensions.cpp" /> + <ClCompile Include="VkQueryPool.cpp" /> <ClCompile Include="VkQueue.cpp" /> <ClCompile Include="VkRenderPass.cpp" /> <ClCompile Include="VkShaderModule.cpp" /> @@ -213,6 +214,7 @@ <ClInclude Include="VkPipeline.hpp" /> <ClInclude Include="VkPipelineCache.hpp" /> <ClInclude Include="VkPipelineLayout.hpp" /> + <ClInclude Include="VkQueryPool.hpp" /> <ClInclude Include="VkQueue.hpp" /> <ClInclude Include="VkRenderPass.hpp" /> <ClInclude Include="VkSampler.hpp" />
diff --git a/src/Vulkan/vulkan.vcxproj.filters b/src/Vulkan/vulkan.vcxproj.filters index 865fa0b..823aeb9 100644 --- a/src/Vulkan/vulkan.vcxproj.filters +++ b/src/Vulkan/vulkan.vcxproj.filters
@@ -255,6 +255,9 @@ <ClCompile Include="VkShaderModule.cpp"> <Filter>Source Files\Vulkan</Filter> </ClCompile> + <ClCompile Include="VkQueryPool.cpp"> + <Filter>Source Files\Vulkan</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="resource.h"> @@ -320,6 +323,9 @@ <ClInclude Include="VkPhysicalDevice.hpp"> <Filter>Header Files\Vulkan</Filter> </ClInclude> + <ClInclude Include="VkQueryPool.hpp"> + <Filter>Header Files\Vulkan</Filter> + </ClInclude> <ClInclude Include="VkQueue.hpp"> <Filter>Header Files\Vulkan</Filter> </ClInclude>