diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.h b/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.h index e9eb11a55..4971f1efe 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.h +++ b/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.h @@ -117,4 +117,26 @@ class MVKCmdCopyMemoryToAccelerationStructure: public MVKCommand { VkCopyAccelerationStructureModeKHR _copyMode; }; +#pragma mark - +#pragma mark MVKCmdWriteAccelerationStructuresProperties +class MVKCmdWriteAccelerationStructuresProperties: public MVKCommand { + +public: + VkResult setContent(MVKCommandBuffer* cmdBuff, + uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR* pAccelerationStructures, + VkQueryType queryType, + VkQueryPool queryPool, + uint32_t firstQuery); + + void encode(MVKCommandEncoder* cmdEncoder) override; +protected: + MVKCommandTypePool* getTypePool(MVKCommandPool* cmdPool) override; + + uint32_t _accelerationStructureCount; + const MVKAccelerationStructure* _pAccelerationStructures; + VkQueryType _queryType; + VkQueryPool _queryPool; + uint32_t _firstQuery; +}; diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.mm b/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.mm index 50ff7bf38..2943f718c 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.mm @@ -250,3 +250,47 @@ [blitEncoder copyFromBuffer:_srcBuffer->getMTLBuffer() sourceOffset:0 toBuffer:_dstAccelerationStructureBuffer destinationOffset:0 size:_copySize]; } + +#pragma mark - +#pragma mark MVKCmdWriteAccelerationStructuresProperties + +VkResult MVKCmdWriteAccelerationStructuresProperties::setContent(MVKCommandBuffer* cmdBuff, + uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR* pAccelerationStructures, + VkQueryType queryType, + VkQueryPool queryPool, + uint32_t firstQuery) { + + _accelerationStructureCount = accelerationStructureCount; + _pAccelerationStructures = (const MVKAccelerationStructure*)pAccelerationStructures; + _queryType = queryType; + _queryPool = queryPool; + _firstQuery = firstQuery; + return VK_SUCCESS; +} + +void MVKCmdWriteAccelerationStructuresProperties::encode(MVKCommandEncoder* cmdEncoder) { + + for(int i = 0; i < _accelerationStructureCount; i++) + { + if(!_pAccelerationStructures[i].getBuildStatus()) { + return; + } + + // actually finish up the meat of the code here + } + + switch(_queryType) + { + case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SIZE_KHR: + break; + case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_BOTTOM_LEVEL_POINTERS_KHR: + break; + case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_COMPACTED_SIZE_KHR: + break; + case VK_QUERY_TYPE_ACCELERATION_STRUCTURE_SERIALIZATION_SIZE_KHR: + break; + default: + break; + } +} diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandTypePools.def b/MoltenVK/MoltenVK/Commands/MVKCommandTypePools.def index 6b2e1b90f..dea1ade84 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandTypePools.def +++ b/MoltenVK/MoltenVK/Commands/MVKCommandTypePools.def @@ -145,7 +145,8 @@ MVK_CMD_TYPE_POOL(ResetEvent) MVK_CMD_TYPE_POOL(BuildAccelerationStructure) MVK_CMD_TYPE_POOL(CopyAccelerationStructure) MVK_CMD_TYPE_POOL(CopyAccelerationStructureToMemory) -MVK_CMD_TYPE_POOL_LAST(CopyMemoryToAccelerationStructure) +MVK_CMD_TYPE_POOL(CopyMemoryToAccelerationStructure) +MVK_CMD_TYPE_POOL_LAST(WriteAccelerationStructuresProperties) #undef MVK_CMD_TYPE_POOL #undef MVK_CMD_TYPE_POOL_LAST diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h b/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h index 965a7d2ab..159a45087 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h @@ -65,25 +65,25 @@ class MVKAccelerationStructure : public MVKVulkanAPIDeviceObject { void setAllowUpdate(bool value) { _allowUpdate = value; } /** Checks if this acceleration structure is allowed to be updated*/ - bool getAllowUpdate() { return _allowUpdate; } + bool getAllowUpdate() const { return _allowUpdate; } /** Only to be called by the MVKCmdBuildAccelerationStructure, and sets the build status*/ void setBuildStatus(bool value) { _built = value; } /** Checks if this acceleration structure has been built*/ - bool getBuildStatus() { return _built; } + bool getBuildStatus() const { return _built; } /** Sets the address of the acceleration structure, only to be used by MVKDevice*/ void setDeviceAddress(uint64_t address) { _address = address; } /** Gets the address of the acceleration structure*/ - uint64_t getDeviceAddress() { return _address; } + uint64_t getDeviceAddress() const { return _address; } /** Returns the Metal buffer using the same memory as the acceleration structure*/ - id getMTLBuffer() { return _buffer; } + id getMTLBuffer() const { return _buffer; } /** Gets the heap allocation that the acceleration structure, and buffer share*/ - id getMTLHeap() { return _heap; } + id getMTLHeap() const { return _heap; } MTLAccelerationStructureTriangleGeometryDescriptor* getTriangleDescriptor(); #pragma mark - diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm b/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm index 4852c27dd..b94b64800 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm @@ -99,6 +99,7 @@ { accStructDescriptor = [MTLInstanceAccelerationStructureDescriptor new]; MTLInstanceAccelerationStructureDescriptor* instanceAccStructDescriptor = (MTLInstanceAccelerationStructureDescriptor*)accStructDescriptor; + // add bottom level acceleration structures instanceAccStructDescriptor.instanceDescriptorType = MTLAccelerationStructureInstanceDescriptorTypeDefault; } diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm index ae1940115..a1364331c 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm @@ -721,6 +721,7 @@ ADD_DVC_EXT_ENTRY_POINT(vkCmdCopyAccelerationStructureKHR, KHR_ACCELERATION_STRUCTURE); ADD_DVC_EXT_ENTRY_POINT(vkCmdCopyAccelerationStructureToMemoryKHR, KHR_ACCELERATION_STRUCTURE); ADD_DVC_EXT_ENTRY_POINT(vkCmdCopyMemoryToAccelerationStructureKHR, KHR_ACCELERATION_STRUCTURE); + ADD_DVC_EXT_ENTRY_POINT(vkCmdCopyMemoryToAccelerationStructureKHR, KHR_ACCELERATION_STRUCTURE); ADD_DVC_EXT_ENTRY_POINT(vkCreateDeferredOperationKHR, KHR_DEFERRED_HOST_OPERATIONS); ADD_DVC_EXT_ENTRY_POINT(vkDeferredOperationJoinKHR, KHR_DEFERRED_HOST_OPERATIONS); diff --git a/MoltenVK/MoltenVK/Utility/MVKFoundation.h b/MoltenVK/MoltenVK/Utility/MVKFoundation.h index cb7294bfb..0d1c23cf8 100644 --- a/MoltenVK/MoltenVK/Utility/MVKFoundation.h +++ b/MoltenVK/MoltenVK/Utility/MVKFoundation.h @@ -102,6 +102,7 @@ typedef enum : uint8_t { kMVKCommandUseCopyAccelerationStructure, /**< vkCmdCopyAccelerationStructure- Copies an acceleration structure to another acceleration structure*/ kMVKCommandUseCopyAccelerationStructureToMemory,/**< vkCmdCopyAccelerationStructureToMemory - Copies and serializes an acceleration structure to a buffer*/ kMVKCommandUseCopyMemoryToAccelerationStructure,/**< vkCmdCopyMemoryToAccelerationStructure - Copies and deserializes an acceleration structure from a buffer*/ + kMVKCommandUseWriteAccelerationStructuresProperties, } MVKCommandUse; /** Represents a given stage of a graphics pipeline. */ diff --git a/MoltenVK/MoltenVK/Vulkan/vulkan.mm b/MoltenVK/MoltenVK/Vulkan/vulkan.mm index 6ec16ba9c..cedb0cc87 100644 --- a/MoltenVK/MoltenVK/Vulkan/vulkan.mm +++ b/MoltenVK/MoltenVK/Vulkan/vulkan.mm @@ -2973,6 +2973,19 @@ MVK_PUBLIC_VULKAN_SYMBOL void vkCmdCopyMemoryToAccelerationStructureKHR( MVKTraceVulkanCallEnd(); } +MVK_PUBLIC_VULKAN_SYMBOL void vkCmdWriteAccelerationStructuresPropertiesKHR( + VkCommandBuffer commandBuffer, + uint32_t accelerationStructureCount, + const VkAccelerationStructureKHR* pAccelerationStructures, + VkQueryType queryType, + VkQueryPool queryPool, + uint32_t firstQuery) { + + MVKTraceVulkanCallStart(); + MVKAddCmd(WriteAccelerationStructuresProperties, commandBuffer, accelerationStructureCount, pAccelerationStructures, queryType, queryPool, firstQuery); + MVKTraceVulkanCallEnd(); +} + #pragma mark - #pragma mark VK_KHR_bind_memory2 extension