namespace vk
{
+
struct DeferredThreadParams
{
const DeviceInterface& vk;
return m_storageSize;
}
+deUint64 SerialStorage::getDeserializedSize ()
+{
+ deUint64 result = 0;
+ const deUint8* startPtr = static_cast<deUint8*>(m_buffer->getAllocation().getHostPtr());
+
+ DE_ASSERT(sizeof(result) == DESERIALIZED_SIZE_SIZE);
+
+ deMemcpy(&result, startPtr + DESERIALIZED_SIZE_OFFSET, sizeof(result));
+
+ return result;
+}
+
BottomLevelAccelerationStructure::~BottomLevelAccelerationStructure ()
{
}
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);
}
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);
}
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,
VkDeviceOrHostAddressConstKHR getAddressConst (const DeviceInterface& vk,
const VkDevice device);
VkDeviceSize getStorageSize ();
+ deUint64 getDeserializedSize ();
+
protected:
VkAccelerationStructureBuildTypeKHR m_buildType;
de::MovePtr<BufferWithMemory> m_buffer;
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<BottomLevelAccelerationStructure> asCopy = makeBottomLevelAccelerationStructure();
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();
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<BottomLevelAccelerationStructure> asCopy = makeBottomLevelAccelerationStructure();
}
case OP_SERIALIZE:
{
- de::SharedPtr<SerialStorage> storage( new SerialStorage(vkd, device, allocator, m_data.buildType, topBlasSerialSize[0]));
+ de::SharedPtr<SerialStorage> storage = de::SharedPtr<SerialStorage>(new SerialStorage(vkd, device, allocator, m_data.buildType, topBlasSerialSize[0]));
topLevelAccelerationStructure->setDeferredOperation(htSerialize, workerThreadsCount);
topLevelAccelerationStructure->serialize(vkd, device, *cmdBuffer, storage.get());
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();
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<BottomLevelAccelerationStructure> asCopy = makeBottomLevelAccelerationStructure();
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();
/** 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 */