Skip to content

Commit

Permalink
Implement Write Acc Structure Properties - WIP
Browse files Browse the repository at this point in the history
This commit adds the device command 'kCmdWriteAccelerationStructuresPropertiesKHR'.
  • Loading branch information
AntarticCoder committed Jul 25, 2024
1 parent 3f1fbde commit 4dea75c
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
22 changes: 22 additions & 0 deletions MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;

uint32_t _accelerationStructureCount;
const MVKAccelerationStructure* _pAccelerationStructures;
VkQueryType _queryType;
VkQueryPool _queryPool;
uint32_t _firstQuery;
};
44 changes: 44 additions & 0 deletions MoltenVK/MoltenVK/Commands/MVKCmdAccelerationStructure.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/Commands/MVKCommandTypePools.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<MTLBuffer> getMTLBuffer() { return _buffer; }
id<MTLBuffer> getMTLBuffer() const { return _buffer; }

/** Gets the heap allocation that the acceleration structure, and buffer share*/
id<MTLHeap> getMTLHeap() { return _heap; }
id<MTLHeap> getMTLHeap() const { return _heap; }

MTLAccelerationStructureTriangleGeometryDescriptor* getTriangleDescriptor();
#pragma mark -
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
{
accStructDescriptor = [MTLInstanceAccelerationStructureDescriptor new];
MTLInstanceAccelerationStructureDescriptor* instanceAccStructDescriptor = (MTLInstanceAccelerationStructureDescriptor*)accStructDescriptor;
// add bottom level acceleration structures

instanceAccStructDescriptor.instanceDescriptorType = MTLAccelerationStructureInstanceDescriptorTypeDefault;
}
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/Utility/MVKFoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
13 changes: 13 additions & 0 deletions MoltenVK/MoltenVK/Vulkan/vulkan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4dea75c

Please sign in to comment.