Skip to content

Commit

Permalink
Implemented Acceleration Structure Compatibility
Browse files Browse the repository at this point in the history
Added in a function to check for acceleration structure compatibility. Also made sure to properly add the device features for acceleration structures.
  • Loading branch information
AntarticCoder committed Jul 11, 2023
1 parent 43a987c commit 542c3f8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
7 changes: 2 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Commands that need to be implemented
vkCmdBuildAccelerationStructuresIndirectKHR
vkCmdBuildAccelerationStructuresKHR - IN PROGRESS
vkCmdBuildAccelerationStructuresKHR - DONE
vkCmdCopyAccelerationStructureKHR - DONE
vkCmdCopyAccelerationStructureToMemoryKHR
vkCmdCopyMemoryToAccelerationStructureKHR
Expand Down Expand Up @@ -57,10 +57,7 @@ class MVKAccelerationStructure : public MVKVulkanAPIDeviceObject {
static VkAccelerationStructureBuildSizesInfoKHR getBuildSizes();

/** Gets the device address of the acceleration structure*/
void getDeviceAddress();

/** Builds the acceleration structure as a device command*/
void build();
uint64_t getDeviceAddress();

#pragma mark Construction
MVKAccelerationStructure(MVKDevice* device) : MVKVulkanAPIDeviceObject(device) {}
Expand Down
10 changes: 4 additions & 6 deletions MoltenVK/MoltenVK/GPUObjects/MVKAccelerationStructure.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
{
VkAccelerationStructureBuildSizesInfoKHR vkBuildSizes{};

#if MVK_XCODE_12
MTLAccelerationStructureSizes mtlBuildSizes;
vkBuildSizes.accelerationStructureSize = mtlBuildSizes.accelerationStructureSize;
vkBuildSizes.buildScratchSize = mtlBuildSizes.buildScratchBufferSize;
vkBuildSizes.updateScratchSize = mtlBuildSizes.refitScratchBufferSize;
#endif
MTLAccelerationStructureSizes mtlBuildSizes;
vkBuildSizes.accelerationStructureSize = mtlBuildSizes.accelerationStructureSize;
vkBuildSizes.buildScratchSize = mtlBuildSizes.buildScratchBufferSize;
vkBuildSizes.updateScratchSize = mtlBuildSizes.refitScratchBufferSize;

return vkBuildSizes;
}
Expand Down
5 changes: 4 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,10 @@ class MVKDevice : public MVKDispatchableVulkanAPIObject {
uint64_t* pMaxDeviation);

/** Returns a pointer to the buffer at the provided address*/
MVKBuffer* getBufferAtAddress(uint64_t address);
MVKBuffer* getBufferAtAddress(uint64_t address); // Unsure where to place

/** Returns whether or not the device supports acceleration structures*/
VkAccelerationStructureCompatibilityKHR getAccelerationStructureCompatibility(const VkAccelerationStructureVersionInfoKHR* pVersionInfo);

#pragma mark Object lifecycle

Expand Down
16 changes: 14 additions & 2 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR: {
// In the future we should update this to allow for more advanced features if they can be supported.
auto* storageFeatures = (VkPhysicalDeviceAccelerationStructureFeaturesKHR*)next;
storageFeatures->accelerationStructure = true;
storageFeatures->accelerationStructure = false;
storageFeatures->accelerationStructure = mvkOSVersionIsAtLeast(11.0, 14.0);
storageFeatures->accelerationStructureCaptureReplay = false;
storageFeatures->accelerationStructureIndirectBuild = false;
storageFeatures->accelerationStructureHostCommands = false;
Expand Down Expand Up @@ -3654,6 +3653,19 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
}

VkAccelerationStructureCompatibilityKHR MVKDevice::getAccelerationStructureCompatibility(const VkAccelerationStructureVersionInfoKHR* pVersionInfo)
{
VkAccelerationStructureCompatibilityKHR compat = VK_ACCELERATION_STRUCTURE_COMPATIBILITY_INCOMPATIBLE_KHR;

if(_enabledAccelerationStructureFeatures.accelerationStructure)
{
compat = VK_ACCELERATION_STRUCTURE_COMPATIBILITY_COMPATIBLE_KHR;
}

return compat;
}


#pragma mark Object lifecycle

uint32_t MVKDevice::getVulkanMemoryTypeIndex(MTLStorageMode mtlStorageMode) {
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDeviceFeatureStructs.def
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ MVK_DEVICE_FEATURE(TimelineSemaphore, TIMELINE_SEMAPHORE,
MVK_DEVICE_FEATURE(UniformBufferStandardLayout, UNIFORM_BUFFER_STANDARD_LAYOUT, 1)
MVK_DEVICE_FEATURE(VariablePointer, VARIABLE_POINTER, 2)
MVK_DEVICE_FEATURE(VulkanMemoryModel, VULKAN_MEMORY_MODEL, 3)
MVK_DEVICE_FEATURE_EXTN(AccelerationStructure, ACCELERATION_STRUCTURE, KHR, 5)
MVK_DEVICE_FEATURE_EXTN(FragmentShaderBarycentric, FRAGMENT_SHADER_BARYCENTRIC, KHR, 1)
MVK_DEVICE_FEATURE_EXTN(PortabilitySubset, PORTABILITY_SUBSET, KHR, 15)
MVK_DEVICE_FEATURE_EXTN(4444Formats, 4444_FORMATS, EXT, 2)
Expand Down
11 changes: 11 additions & 0 deletions MoltenVK/MoltenVK/Vulkan/vulkan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,17 @@ MVK_PUBLIC_VULKAN_SYMBOL void vkCmdCopyAccelerationStructureKHR(
MVKTraceVulkanCallEnd();
}

MVK_PUBLIC_VULKAN_SYMBOL void vkGetDeviceAccelerationStructureCompatibilityKHR(
VkDevice device,
const VkAccelerationStructureVersionInfoKHR* pVersionInfo,
VkAccelerationStructureCompatibilityKHR* pCompatibility) {

MVKTraceVulkanCallStart();
MVKDevice* mvkDev = (MVKDevice*)device;
*pCompatibility = mvkDev->getAccelerationStructureCompatibility(pVersionInfo);
MVKTraceVulkanCallEnd();
}

#pragma mark -
#pragma mark VK_KHR_bind_memory2 extension

Expand Down

0 comments on commit 542c3f8

Please sign in to comment.