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
32 changes: 23 additions & 9 deletions include/nbl/builtin/hlsl/spirv_intrinsics/raytracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_RAYTRACING_INCLUDED_

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

namespace nbl
{
Expand All @@ -13,33 +13,47 @@ namespace hlsl
namespace spirv
{

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(/* spv::OpTypeRayQueryKHR function_ptr query, spv::OpTypeAccelerationStructureKHR AS, uint32_t flags, uint32_t cull mask, float3 origin, float32_t tmin, float3 direction, float32_t tmax*/);
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(/* spv::OpTypeRayQueryKHR function_ptr query */);
bool rayQueryProceedEXT([[vk::ext_reference]] RayQueryKHR query);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionTypeKHR)]]
int rayQueryGetIntersectionTypeEXT(/* spv::OpTypeRayQueryKHR function_ptr query, uint32_t intersection (candidate 0, commited 1) */);
int rayQueryGetIntersectionTypeEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionInstanceIdKHR)]]
int rayQueryGetIntersectionInstanceIdEXT(/* spv::OpTypeRayQueryKHR function_ptr query, uint32_t intersection (candidate 0, commited 1) */);
int rayQueryGetIntersectionInstanceIdEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection);

[[vk::ext_capability(spv::CapabilityRayQueryKHR)]]
[[vk::ext_instruction(spv::OpRayQueryGetIntersectionPrimitiveIndexKHR)]]
int rayQueryGetIntersectionPrimitiveIndexEXT(/* spv::OpTypeRayQueryKHR function_ptr query, uint32_t intersection (candidate 0, commited 1) */);
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
// get intersection triangle vertex position - gl_HitTriangleVertexPositionsEXT
// returns 3-array float3 vertex positions
void rayQueryGetIntersectionTriangleVertexPositionsEXT(/* spv::OpTypeRayQueryKHR function_ptr query, uint32_t intersection (candidate 0, commited 1), out float3 positions[3] */);
void rayQueryGetIntersectionTriangleVertexPositionsEXT([[vk::ext_reference]] RayQueryKHR query, uint32_t intersection, out float32_t3 pos[3]);

}
}
Expand Down