From ace7c67eeb4a5c4b64e9ea2d3a5b54ef36da9ebc Mon Sep 17 00:00:00 2001 From: Boris Zanin Date: Mon, 8 Mar 2021 15:49:41 +0100 Subject: [PATCH] Read deserealization size from stream Deserialization should read deserialized data size from serialized data stream, rather than use serialized data size. To allow reading of this data from stream command buffer recording should be completed and restarted. Updates tests: * dEQP-VK.ray_tracing_pipeline.acceleration_structures.operations.serialization.* * dEQP-VK.ray_tracing_pipeline.capture_replay.acceleration_structures.serialization.* * dEQP-VK.ray_query.acceleration_structures.operations.*.serialization.* Components: Framework, Vulkan VK-GL-CTS issue: 2545 Change-Id: I460d82ae9ebfe8e43f24b4478154854a01491602 --- .../vulkancts/framework/vulkan/vkRayTracingUtil.cpp | 21 +++++++++++++++++---- .../vulkancts/framework/vulkan/vkRayTracingUtil.hpp | 12 ++++++++++++ .../vktRayQueryAccelerationStructuresTests.cpp | 16 ++++++++++++---- .../vktRayTracingAccelerationStructuresTests.cpp | 18 +++++++++++++----- .../ray_tracing/vktRayTracingCaptureReplayTests.cpp | 16 ++++++++++++---- framework/delibs/debase/deDefs.h | 3 +++ 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/external/vulkancts/framework/vulkan/vkRayTracingUtil.cpp b/external/vulkancts/framework/vulkan/vkRayTracingUtil.cpp index 329ffaa..a9a4015 100644 --- a/external/vulkancts/framework/vulkan/vkRayTracingUtil.cpp +++ b/external/vulkancts/framework/vulkan/vkRayTracingUtil.cpp @@ -36,6 +36,7 @@ namespace vk { + struct DeferredThreadParams { const DeviceInterface& vk; @@ -564,6 +565,18 @@ VkDeviceSize SerialStorage::getStorageSize () return m_storageSize; } +deUint64 SerialStorage::getDeserializedSize () +{ + deUint64 result = 0; + const deUint8* startPtr = static_cast(m_buffer->getAllocation().getHostPtr()); + + DE_ASSERT(sizeof(result) == DESERIALIZED_SIZE_SIZE); + + deMemcpy(&result, startPtr + DESERIALIZED_SIZE_OFFSET, sizeof(result)); + + return result; +} + BottomLevelAccelerationStructure::~BottomLevelAccelerationStructure () { } @@ -1368,8 +1381,8 @@ void BottomLevelAccelerationStructure::createAndDeserializeFrom (const DeviceInt VkDeviceAddress deviceAddress ) { DE_ASSERT(storage != NULL); - DE_ASSERT(storage->getStorageSize() != 0u); - create(vk, device, allocator, storage->getStorageSize(), deviceAddress); + DE_ASSERT(storage->getStorageSize() >= SerialStorage::SERIAL_STORAGE_SIZE_MIN); + create(vk, device, allocator, storage->getDeserializedSize(), deviceAddress); deserialize(vk, device, cmdBuffer, storage); } @@ -1445,8 +1458,8 @@ void TopLevelAccelerationStructure::createAndDeserializeFrom (const DeviceInterf VkDeviceAddress deviceAddress) { DE_ASSERT(storage != NULL); - DE_ASSERT(storage->getStorageSize() != 0u); - create(vk, device, allocator, storage->getStorageSize(), deviceAddress); + DE_ASSERT(storage->getStorageSize() >= SerialStorage::SERIAL_STORAGE_SIZE_MIN); + create(vk, device, allocator, storage->getDeserializedSize(), deviceAddress); deserialize(vk, device, cmdBuffer, storage); } diff --git a/external/vulkancts/framework/vulkan/vkRayTracingUtil.hpp b/external/vulkancts/framework/vulkan/vkRayTracingUtil.hpp index ca5d62e..f4f83df 100644 --- a/external/vulkancts/framework/vulkan/vkRayTracingUtil.hpp +++ b/external/vulkancts/framework/vulkan/vkRayTracingUtil.hpp @@ -458,6 +458,16 @@ VkDeviceAddress getBufferDeviceAddress ( const DeviceInterface& vkd, class SerialStorage { public: + enum + { + DE_SERIALIZED_FIELD(DRIVER_UUID, VK_UUID_SIZE), // VK_UUID_SIZE bytes of data matching VkPhysicalDeviceIDProperties::driverUUID + DE_SERIALIZED_FIELD(COMPAT_UUID, VK_UUID_SIZE), // VK_UUID_SIZE bytes of data identifying the compatibility for comparison using vkGetDeviceAccelerationStructureCompatibilityKHR + DE_SERIALIZED_FIELD(SERIALIZED_SIZE, sizeof(deUint64)), // A 64-bit integer of the total size matching the value queried using VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR + DE_SERIALIZED_FIELD(DESERIALIZED_SIZE, sizeof(deUint64)), // A 64-bit integer of the deserialized size to be passed in to VkAccelerationStructureCreateInfoKHR::size + DE_SERIALIZED_FIELD(HANDLES_COUNT, sizeof(deUint64)), // A 64-bit integer of the count of the number of acceleration structure handles following. This will be zero for a bottom-level acceleration structure. + SERIAL_STORAGE_SIZE_MIN + }; + SerialStorage () = delete; SerialStorage (const DeviceInterface& vk, const VkDevice device, @@ -470,6 +480,8 @@ public: VkDeviceOrHostAddressConstKHR getAddressConst (const DeviceInterface& vk, const VkDevice device); VkDeviceSize getStorageSize (); + deUint64 getDeserializedSize (); + protected: VkAccelerationStructureBuildTypeKHR m_buildType; de::MovePtr m_buffer; diff --git a/external/vulkancts/modules/vulkan/ray_query/vktRayQueryAccelerationStructuresTests.cpp b/external/vulkancts/modules/vulkan/ray_query/vktRayQueryAccelerationStructuresTests.cpp index 80ddce4..dd99fd3 100644 --- a/external/vulkancts/modules/vulkan/ray_query/vktRayQueryAccelerationStructuresTests.cpp +++ b/external/vulkancts/modules/vulkan/ray_query/vktRayQueryAccelerationStructuresTests.cpp @@ -2574,8 +2574,12 @@ de::MovePtr RayQueryASBasicTestInstance::runTest (TestConfigur if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } de::MovePtr asCopy = makeBottomLevelAccelerationStructure(); @@ -2677,8 +2681,12 @@ de::MovePtr RayQueryASBasicTestInstance::runTest (TestConfigur if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } topLevelAccelerationStructureCopy = makeTopLevelAccelerationStructure(); diff --git a/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingAccelerationStructuresTests.cpp b/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingAccelerationStructuresTests.cpp index cb7de7a..0c7e1dc 100644 --- a/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingAccelerationStructuresTests.cpp +++ b/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingAccelerationStructuresTests.cpp @@ -1654,8 +1654,12 @@ de::MovePtr RayTracingASBasicTestInstance::runTest(const deUin if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } de::MovePtr asCopy = makeBottomLevelAccelerationStructure(); @@ -1749,7 +1753,7 @@ de::MovePtr RayTracingASBasicTestInstance::runTest(const deUin } case OP_SERIALIZE: { - de::SharedPtr storage( new SerialStorage(vkd, device, allocator, m_data.buildType, topBlasSerialSize[0])); + de::SharedPtr storage = de::SharedPtr(new SerialStorage(vkd, device, allocator, m_data.buildType, topBlasSerialSize[0])); topLevelAccelerationStructure->setDeferredOperation(htSerialize, workerThreadsCount); topLevelAccelerationStructure->serialize(vkd, device, *cmdBuffer, storage.get()); @@ -1757,8 +1761,12 @@ de::MovePtr RayTracingASBasicTestInstance::runTest(const deUin if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } topLevelAccelerationStructureCopy = makeTopLevelAccelerationStructure(); diff --git a/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingCaptureReplayTests.cpp b/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingCaptureReplayTests.cpp index 69e3f98..fbda652 100644 --- a/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingCaptureReplayTests.cpp +++ b/external/vulkancts/modules/vulkan/ray_tracing/vktRayTracingCaptureReplayTests.cpp @@ -1197,8 +1197,12 @@ std::vector RayTracingCaptureReplayTestInstance::runTest(bool replay) if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } de::MovePtr asCopy = makeBottomLevelAccelerationStructure(); @@ -1296,8 +1300,12 @@ std::vector RayTracingCaptureReplayTestInstance::runTest(bool replay) if (m_data.buildType == VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR) { - const VkMemoryBarrier serializeMemoryBarrier = makeMemoryBarrier(VK_ACCESS_MEMORY_WRITE_BIT, VK_ACCESS_MEMORY_READ_BIT); - cmdPipelineMemoryBarrier(vkd, *cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, &serializeMemoryBarrier); + endCommandBuffer(vkd, *cmdBuffer); + + submitCommandsAndWait(vkd, device, queue, cmdBuffer.get()); + + vkd.resetCommandPool(device, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); + beginCommandBuffer(vkd, *cmdBuffer, 0u); } topLevelAccelerationStructureCopy = makeTopLevelAccelerationStructure(); diff --git a/framework/delibs/debase/deDefs.h b/framework/delibs/debase/deDefs.h index 314d2ad..6289670 100644 --- a/framework/delibs/debase/deDefs.h +++ b/framework/delibs/debase/deDefs.h @@ -340,6 +340,9 @@ DE_INLINE deBool deGetTrue (void) { return DE_TRUE; } /** Offset of a struct member. */ #define DE_OFFSET_OF(STRUCT, MEMBER) ((deUint32)(deUintptr)(deUint8*)&(((STRUCT*)0)->MEMBER)) +/** Used in enum to easify declarations for struct serialization. Declares 'NAME'_OFFSET, 'NAME'_SIZE, and offsets counter for next enum value by SIZE. */ +#define DE_SERIALIZED_FIELD(NAME, SIZE) NAME ## _OFFSET, NAME ## _SIZE = (SIZE), _DE_TMP_ ## NAME = NAME ## _OFFSET + (SIZE) - 1 + /* Pointer size. */ #if defined(DE_PTR_SIZE) /* nada */ -- 2.7.4