Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ray query inline spirv example #788

Merged
merged 13 commits into from
Nov 22, 2024
62 changes: 62 additions & 0 deletions include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (C) 2023 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_

#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"

namespace nbl
{
namespace hlsl
{
namespace spirv
{

devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
using RayQueryKHR = vk::SpirvOpaqueType<spv::OpTypeRayQueryKHR>;
using AccelerationStructureKHR = vk::SpirvOpaqueType<spv::OpTypeAccelerationStructureKHR>;
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved

// matching Ray Query Committed Intersection Type
static const uint32_t RayQueryCommittedIntersectionNoneKHR = 0;
static const uint32_t RayQueryCommittedIntersectionTriangleKHR = 1;
static const uint32_t RayQueryCommittedIntersectionGeneratedKHR = 2;

// matching Ray Query Candidate Intersection Type
static const uint32_t RayQueryCandidateIntersectionTriangleKHR = 0;
static const uint32_t RayQueryCandidateIntersectionAABBKHR = 1;
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryInitializeKHR)]]
void rayQueryInitializeEXT([[vk::ext_reference]] RayQueryKHR query, [[vk::ext_reference]] AccelerationStructureKHR AS, uint32_t flags, uint32_t cull mask, float3 origin, float32_t tmin, float3 direction, float32_t tmax);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryInitializeKHR)]]
void rayQueryInitializeEXT([[vk::ext_reference]] RayQueryKHR query, [[vk::ext_reference]] RaytracingAccelerationStructure AS, uint32_t flags, uint32_t cull mask, float3 origin, float32_t tmin, float3 direction, float32_t tmax);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryProceedKHR)]]
bool rayQueryProceedEXT([[vk::ext_reference]] RayQueryKHR query);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionTypeKHR)]]
int rayQueryGetIntersectionTypeEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionInstanceIdKHR)]]
int rayQueryGetIntersectionInstanceIdEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionPrimitiveIndexKHR)]]
int rayQueryGetIntersectionPrimitiveIndexEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection);

// position fetch for ray tracing uses gl_HitTriangleVertexPositionsEXT -> HitTriangleVertexPositionsKHR decorated OpVariable

[[vk::ext_capability(spv::CapabilityRayQueryPositionFetchKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionTriangleVertexPositionsKHR)]] // ray query version
void rayQueryGetIntersectionTriangleVertexPositionsEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection, out float32_t3 pos[3]);

}
}
}

#endif // _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_
6 changes: 6 additions & 0 deletions src/nbl/video/CVulkanPhysicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR workgroupMemoryExplicitLayout = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR };
VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR raytracingMaintenance1Features = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_MAINTENANCE_1_FEATURES_KHR };
VkPhysicalDeviceRasterizationOrderAttachmentAccessFeaturesARM rasterizationOrderAttachmentAccessFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_FEATURES_ARM };
VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR rayTracingPositionFetchFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR };
VkPhysicalDeviceColorWriteEnableFeaturesEXT colorWriteEnableFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COLOR_WRITE_ENABLE_FEATURES_EXT };
#if 0
VkPhysicalDeviceCooperativeMatrixFeaturesKHR cooperativeMatrixFeatures = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COOPERATIVE_MATRIX_FEATURES_KHR };
Expand Down Expand Up @@ -768,6 +769,8 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
addToPNextChain(&workgroupMemoryExplicitLayout);
if (isExtensionSupported(VK_ARM_RASTERIZATION_ORDER_ATTACHMENT_ACCESS_EXTENSION_NAME))
addToPNextChain(&rasterizationOrderAttachmentAccessFeatures);
if (isExtensionSupported(VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME))
addToPNextChain(&rayTracingPositionFetchFeatures);
if (isExtensionSupported(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME))
addToPNextChain(&colorWriteEnableFeatures);
// call
Expand Down Expand Up @@ -1196,6 +1199,9 @@ std::unique_ptr<CVulkanPhysicalDevice> CVulkanPhysicalDevice::create(core::smart
properties.limits.workgroupMemoryExplicitLayout16BitAccess = workgroupMemoryExplicitLayout.workgroupMemoryExplicitLayout16BitAccess;
}

if (isExtensionSupported(VK_KHR_RAY_TRACING_POSITION_FETCH_EXTENSION_NAME) && isExtensionSupported(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME))
properties.limits.rayTracingPositionFetch = rayTracingPositionFetchFeatures.rayTracingPositionFetch;

if (isExtensionSupported(VK_EXT_COLOR_WRITE_ENABLE_EXTENSION_NAME))
properties.limits.colorWriteEnable = colorWriteEnableFeatures.colorWriteEnable;
#if 0 //TODO
devshgraphicsprogramming marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
12 changes: 10 additions & 2 deletions src/nbl/video/device_capabilities/device_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -4023,8 +4023,16 @@
"VK_AMD_extension_478",
"VK_AMD_extension_479",
"VK_EXT_extension_480",
"VK_EXT_extension_481",
"TODO: implement",
"VK_EXT_extension_481"
]
},
{
"type": "bool",
"name": "rayTracingPositionFetch",
"value": false,
"expose": "MOVE_TO_LIMIT",
"comment": [
"RayTracingPositionFetchFeaturesKHR",
"VK_KHR_ray_tracing_position_fetch"
]
},
Expand Down