diff --git a/build/visual-studio/slang/slang.vcxproj b/build/visual-studio/slang/slang.vcxproj index 9277df88fb..947ab4b5f4 100644 --- a/build/visual-studio/slang/slang.vcxproj +++ b/build/visual-studio/slang/slang.vcxproj @@ -386,6 +386,7 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla + @@ -610,6 +611,7 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla + diff --git a/build/visual-studio/slang/slang.vcxproj.filters b/build/visual-studio/slang/slang.vcxproj.filters index a427febb58..85476ba7b6 100644 --- a/build/visual-studio/slang/slang.vcxproj.filters +++ b/build/visual-studio/slang/slang.vcxproj.filters @@ -246,6 +246,9 @@ Header Files + + Header Files + Header Files @@ -914,6 +917,9 @@ Source Files + + Source Files + Source Files diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index e55206ca98..27da512fa6 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -2338,7 +2338,7 @@ __attributeTarget(DeclBase) attribute_syntax [push_constant] : PushConstantAttribute; __attributeTarget(VarDeclBase) -attribute_syntax [vk_location(locaiton : int)] : GLSLLocationAttribute; +attribute_syntax [vk_location(location : int)] : GLSLLocationAttribute; __attributeTarget(VarDeclBase) attribute_syntax [vk_index(index : int)] : GLSLIndexAttribute; @@ -2476,7 +2476,7 @@ __attributeTarget(Decl) attribute_syntax [allow(diagnostic: String)] : AllowAttribute; __attributeTarget(Decl) -attribute_syntax[require(capability)] : RequireCapabilityAttribute; +attribute_syntax [require(capability)] : RequireCapabilityAttribute; // Linking __attributeTarget(Decl) @@ -2519,7 +2519,7 @@ __attributeTarget(FuncDecl) attribute_syntax [CUDAKernel] : CudaKernelAttribute; __attributeTarget(FuncDecl) -attribute_syntax[AutoPyBindCUDA] : AutoPyBindCudaAttribute; +attribute_syntax [AutoPyBindCUDA] : AutoPyBindCudaAttribute; __attributeTarget(AggTypeDecl) attribute_syntax [PyExport(name: String)] : PyExportAttribute; diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 98b7fcd823..d154bd969e 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -2821,47 +2821,1599 @@ public vec4 shadow2DProjLod(sampler2DShadow sampler, vec4 coord, float lod) return textureProjLod(sampler, coord, lod); } -// -// Ray tracing -// + +//// RayTracing + +// Ray Tracing variables public typealias rayQueryEXT = RayQuery; +public typealias accelerationStructureEXT = RaytracingAccelerationStructure; +public typealias accelerationStructureNV = RaytracingAccelerationStructure; + +public typealias hitObjectNV = HitObject; + +//GL_EXT_ray_tracing BuiltIn's + +void requireGLSLExtForRayTracingBuiltin() +{ + __target_switch + { + case glsl: + __requireGLSLExtension("GL_EXT_ray_tracing"); + __intrinsic_asm ""; + } +} + +__spirv_version(1.4) +void setupExtForRayTracingBuiltIn() +{ + __target_switch + { + case glsl: + requireGLSLExtForRayTracingBuiltin(); + case spirv: + return; + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint3 gl_LaunchIDNV +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_LaunchIDNV)"; + } + case spirv: + { + return spirv_asm + { + result:$$uint3 = OpLoad builtin(LaunchIdNV:uint3); + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint3 gl_LaunchIDEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return DispatchRaysIndex(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint3 gl_LaunchSizeNV +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_LaunchSizeNV)"; + } + case spirv: + { + return spirv_asm + { + result:$$uint3 = OpLoad builtin(LaunchSizeNV:uint3); + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint3 gl_LaunchSizeEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return DispatchRaysDimensions(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property int gl_PrimitiveID +{ + get + { + setupExtForRayTracingBuiltIn(); + return PrimitiveIndex(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property int gl_InstanceID +{ + get + { + setupExtForRayTracingBuiltIn(); + return InstanceIndex(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property int gl_InstanceCustomIndexEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return InstanceID(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property int gl_GeometryIndexEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return GeometryIndex(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property vec3 gl_WorldRayOriginEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return WorldRayOrigin(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property vec3 gl_WorldRayDirectionEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return WorldRayDirection(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property vec3 gl_ObjectRayOriginEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return ObjectRayOrigin(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property vec3 gl_ObjectRayDirectionEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return ObjectRayDirection(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property float gl_RayTminEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return RayTMin(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property float gl_RayTmaxEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return RayTCurrent(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint gl_IncomingRayFlagsEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return RayFlags(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property float gl_HitTEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_HitTEXT)"; + } + case spirv: + { + return spirv_asm + { + result:$$float = OpLoad builtin(RayTmaxKHR:float); + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property uint gl_HitKindEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + return HitKind(); + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property mat4x3 gl_ObjectToWorldEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_ObjectToWorldEXT)"; + } + case spirv: + { + return spirv_asm + { + %mat:$$mat3x4 = OpLoad builtin(ObjectToWorldKHR:mat3x4); + result:$$mat4x3 = OpTranspose %mat + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property mat3x4 gl_ObjectToWorld3x4EXT +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_ObjectToWorld3x4EXT)"; + } + case spirv: + { + return spirv_asm + { + result:$$mat3x4 = OpLoad builtin(ObjectToWorldKHR:mat3x4) + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property mat4x3 gl_WorldToObjectEXT +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_WorldToObjectEXT)"; + } + case spirv: + { + return spirv_asm + { + %mat:$$mat3x4 = OpLoad builtin(WorldToObjectKHR:mat3x4); + result:$$mat4x3 = OpTranspose %mat + }; + } + } + } +} + +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public property mat3x4 gl_WorldToObject3x4EXT +{ + get + { + setupExtForRayTracingBuiltIn(); + __target_switch + { + case glsl: + { + __intrinsic_asm "(gl_WorldToObject3x4EXT)"; + } + case spirv: + { + return spirv_asm + { + result:$$mat3x4 = OpLoad builtin(WorldToObjectKHR:mat3x4) + }; + } + } + } +} + +// GL_EXT_ray_tracing functions __glsl_extension(GL_EXT_ray_query) -__glsl_version(460) -[ForceInline] -public void rayQueryConfirmIntersectionEXT(inout rayQueryEXT q) +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public void traceRayEXT( + accelerationStructureEXT topLevel, + uint rayFlags, + uint cullMask, + uint sbtRecordOffset, + uint sbtRecordStride, + uint missIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + constexpr int payload) { - q.CommitNonOpaqueTriangleHit(); + __target_switch + { + case glsl: + { + __traceRay( + topLevel, + rayFlags, + cullMask, + sbtRecordOffset, + sbtRecordStride, + missIndex, + origin, + Tmin, + direction, + Tmax, + payload); + } + case spirv: + { + spirv_asm + { + OpTraceRayKHR + /**/ $topLevel + /**/ $rayFlags + /**/ $cullMask + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $missIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ __rayPayloadFromLocation(payload); + }; + } + } } __glsl_extension(GL_EXT_ray_query) -__glsl_version(460) -[ForceInline] -public bool rayQueryProceedEXT(inout rayQueryEXT q) +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public bool reportIntersectionEXT(float hitT, uint hitKind) { - return q.Proceed(); + return __reportIntersection(hitT, hitKind); } __glsl_extension(GL_EXT_ray_query) -__glsl_version(460) -[__NoSideEffect] -public uint rayQueryGetIntersectionTypeEXT(rayQueryEXT q, bool committed) +[require(glsl, raytracing)] +[require(spirv, raytracing)] +public void executeCallableEXT( + uint sbtRecordIndex, + int callable /*callableDataEXT and callableDataInEXT*/) { - if (committed) + __target_switch + { + case glsl: { - q.CommittedStatus(); + __executeCallable(sbtRecordIndex, callable); } - else + case spirv: { - q.CandidateType(); + spirv_asm { + OpExecuteCallableKHR $sbtRecordIndex __rayCallableFromLocation(callable) + }; } - return 0; + } +} + +// GL_EXT_ray_tracing constants + +public const uint gl_HitKindFrontFacingTriangleEXT = 0xFEU; +public const uint gl_HitKindBackFacingTriangleEXT = 0xFFU; + +/// GL_EXT_ray_query + +// GL_EXT_ray_query constants + +public const uint gl_RayFlagsNoneEXT = 0U; +public const uint gl_RayFlagsOpaqueEXT = 1U; +public const uint gl_RayFlagsNoOpaqueEXT = 2U; +public const uint gl_RayFlagsTerminateOnFirstHitEXT = 4U; +public const uint gl_RayFlagsSkipClosestHitShaderEXT = 8U; +public const uint gl_RayFlagsCullBackFacingTrianglesEXT = 16U; +public const uint gl_RayFlagsCullFrontFacingTrianglesEXT = 32U; +public const uint gl_RayFlagsCullOpaqueEXT = 64U; +public const uint gl_RayFlagsCullNoOpaqueEXT = 128U; + +public const uint gl_RayQueryCommittedIntersectionNoneEXT = 0U; +public const uint gl_RayQueryCommittedIntersectionTriangleEXT = 1U; +public const uint gl_RayQueryCommittedIntersectionGeneratedEXT = 2U; + +public const uint gl_RayQueryCandidateIntersectionTriangleEXT = 0U; +public const uint gl_RayQueryCandidateIntersectionAABBEXT = 1U; + +// GL_EXT_ray_query functions + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public void rayQueryInitializeEXT( + inout rayQueryEXT q, + accelerationStructureEXT topLevel, + uint rayFlags, uint cullMask, vec3 origin, + float tMin, vec3 direction, float tMax) +{ + q.TraceRayInline( + topLevel, + rayFlags, + cullMask, + { origin, tMin, direction, tMax }); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public bool rayQueryProceedEXT(inout rayQueryEXT q) +{ + return q.Proceed(); } -// TODO: implementation of built-in variables; proper tests; these are stubs -// likley related to the following issue since GLSL adds new -// 'system' variables: https://github.com/shader-slang/slang/issues/411 +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[mutating] +[ForceInline] +public void rayQueryTerminateEXT(inout rayQueryEXT q) +{ + q.Abort(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public void rayQueryGenerateIntersectionEXT(inout rayQueryEXT q, float tHit) +{ + q.CommitProceduralPrimitiveHit(tHit); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public void rayQueryConfirmIntersectionEXT(inout rayQueryEXT q) +{ + q.CommitNonOpaqueTriangleHit(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[__NoSideEffect] +[ForceInline] +public uint rayQueryGetIntersectionTypeEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedStatus(); + } + else + { + return q.CandidateType(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public float rayQueryGetRayTMinEXT(rayQueryEXT q) +{ + return q.RayTMin(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public uint rayQueryGetRayFlagsEXT(rayQueryEXT q) +{ + return q.RayFlags(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public vec3 rayQueryGetWorldRayOriginEXT(rayQueryEXT q) +{ + return q.WorldRayOrigin(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public vec3 rayQueryGetWorldRayDirectionEXT(rayQueryEXT q) +{ + return q.WorldRayDirection(); +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public float rayQueryGetIntersectionTEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayT(); + } + else + { + return q.CandidateTriangleRayT(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public int rayQueryGetIntersectionInstanceCustomIndexEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayInstanceCustomIndex(); + } + else + { + return q.CandidateRayInstanceCustomIndex();; + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public int rayQueryGetIntersectionInstanceIdEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayInstanceId(); + } + else + { + return q.CandidateRayInstanceId(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public uint rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayInstanceShaderBindingTableRecordOffset(); + } + else + { + return q.CandidateRayInstanceShaderBindingTableRecordOffset(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public int rayQueryGetIntersectionGeometryIndexEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayGeometryIndex(); + } + else + { + return q.CandidateRayGeometryIndex(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public int rayQueryGetIntersectionPrimitiveIndexEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayPrimitiveIndex(); + } + else + { + return q.CandidateRayPrimitiveIndex(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public vec2 rayQueryGetIntersectionBarycentricsEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayBarycentrics(); + } + else + { + return q.CandidateRayBarycentrics(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public bool rayQueryGetIntersectionFrontFaceEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayFrontFace(); + } + else + { + return q.CandidateRayFrontFace(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public bool rayQueryGetIntersectionCandidateAABBOpaqueEXT(rayQueryEXT q) +{ + return q.CandidateProceduralPrimitiveNonOpaque(); +} + +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public vec3 rayQueryGetIntersectionObjectRayDirectionEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayObjectRayDirection(); + } + else + { + return q.CandidateRayObjectRayDirection(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public vec3 rayQueryGetIntersectionObjectRayOriginEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return q.CommittedRayObjectRayOrigin(); + } + else + { + return q.CandidateRayObjectRayOrigin(); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public mat4x3 rayQueryGetIntersectionObjectToWorldEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return transpose(q.CommittedRayObjectToWorld()); + } + else + { + return transpose(q.CandidateRayObjectToWorld()); + } +} + +__glsl_extension(GL_EXT_ray_query) +[require(glsl, rayquery)] +[require(spirv, rayquery)] +[ForceInline] +public mat4x3 rayQueryGetIntersectionWorldToObjectEXT(rayQueryEXT q, bool committed) +{ + if (committed) + { + return transpose(q.CommittedRayWorldToObject()); + } + else + { + return transpose(q.CandidateRayWorldToObject()); + } +} + +/// GL_NV_shader_invocation_reorder + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectTraceRayNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + uint rayFlags, + uint cullMask, + uint sbtRecordOffset, + uint sbtRecordStride, + uint missIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + constexpr int payload) + { + __target_switch + { + case glsl: + { + HitObject::__glslTraceRay( + hitObject, + topLevel, + rayFlags, + cullMask, + sbtRecordOffset, + sbtRecordStride, + missIndex, + origin, + Tmin, + direction, + Tmax, + payload); + } + case spirv: + { + spirv_asm + { + OpHitObjectTraceRayNV + &hitObject + /**/ $topLevel + /**/ $rayFlags + /**/ $cullMask + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $missIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ __rayPayloadFromLocation(payload) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +__glsl_extension(GL_NV_ray_tracing_motion_blur) +[require(glsl, ser_motion)] +[require(spirv, ser_motion)] +[ForceInline] +public void hitObjectTraceRayMotionNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + uint rayFlags, + uint cullMask, + uint sbtRecordOffset, + uint sbtRecordStride, + uint missIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + float currentTime, + constexpr int payload) + { + __target_switch + { + case glsl: + { + HitObject::__glslTraceMotionRay( + hitObject, + topLevel, + rayFlags, + cullMask, + sbtRecordOffset, + sbtRecordStride, + missIndex, + origin, + Tmin, + direction, + Tmax, + currentTime, + payload); + } + case spirv: + { + spirv_asm + { + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpHitObjectTraceRayMotionNV + /**/ &hitObject + /**/ $topLevel + /**/ $rayFlags + /**/ $cullMask + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $missIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ $currentTime + /**/ __rayPayloadFromLocation(payload) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectRecordHitNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + int instanceid, + int primitiveid, + int geometryindex, + uint hitKind, + uint sbtRecordOffset, + uint sbtRecordStride, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + constexpr int attributeLocation) + { + __target_switch + { + case glsl: + { + HitObject::__glslMakeHit( + hitObject, + topLevel, + instanceid, + primitiveid, + geometryindex, + hitKind, + sbtRecordOffset, + sbtRecordStride, + origin, + Tmin, + direction, + Tmax, + attributeLocation); + } + case spirv: + { + spirv_asm + { + OpHitObjectRecordHitNV + /**/ &hitObject + /**/ $topLevel + /**/ $instanceid + /**/ $primitiveid + /**/ $geometryindex + /**/ $hitKind + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ __rayAttributeFromLocation(attributeLocation) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +__glsl_extension(GL_NV_ray_tracing_motion_blur) +[require(glsl, ser_motion)] +[require(spirv, ser_motion)] +[ForceInline] +public void hitObjectRecordHitMotionNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + int instanceid, + int primitiveid, + int geometryindex, + uint hitKind, + uint sbtRecordOffset, + uint sbtRecordStride, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + float currentTime, + constexpr int attributeLocation) + { + __target_switch + { + case glsl: + { + HitObject::__glslMakeMotionHit( + hitObject, + topLevel, + instanceid, + primitiveid, + geometryindex, + hitKind, + sbtRecordOffset, + sbtRecordStride, + origin, + Tmin, + direction, + Tmax, + currentTime, + attributeLocation); + } + case spirv: + { + spirv_asm + { + OpHitObjectRecordHitMotionNV + /**/ &hitObject + /**/ $topLevel + /**/ $instanceid + /**/ $primitiveid + /**/ $geometryindex + /**/ $hitKind + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ $currentTime + /**/ __rayAttributeFromLocation(attributeLocation) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectRecordHitWithIndexNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + int instanceid, + int primitiveid, + int geometryindex, + uint hitKind, + uint sbtRecordIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + constexpr int attributeLocation) +{ + __target_switch + { + case glsl: + { + HitObject::__glslMakeHitWithIndex( + hitObject, + topLevel, + instanceid, + primitiveid, + geometryindex, + hitKind, + sbtRecordIndex, + origin, + Tmin, + direction, + Tmax, + attributeLocation); + } + case spirv: + { + spirv_asm + { + OpHitObjectRecordHitWithIndexNV + /**/ &hitObject + /**/ $topLevel + /**/ $instanceid + /**/ $primitiveid + /**/ $geometryindex + /**/ $hitKind + /**/ $sbtRecordIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ __rayAttributeFromLocation(attributeLocation) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +__glsl_extension(GL_NV_ray_tracing_motion_blur) +[require(glsl, ser_motion)] +[require(spirv, ser_motion)] +[ForceInline] +public void hitObjectRecordHitWithIndexMotionNV( + inout hitObjectNV hitObject, + accelerationStructureEXT topLevel, + int instanceid, + int primitiveid, + int geometryindex, + uint hitKind, + uint sbtRecordIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + float currentTime, + constexpr int attributeLocation) + { + __target_switch + { + case glsl: + { + HitObject::__glslMakeMotionHitWithIndex( + hitObject, + topLevel, + instanceid, + primitiveid, + geometryindex, + hitKind, + sbtRecordIndex, + origin, + Tmin, + direction, + Tmax, + currentTime, + attributeLocation); + } + case spirv: + { + spirv_asm + { + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpHitObjectRecordHitWithIndexMotionNV + /**/ &hitObject + /**/ $topLevel + /**/ $instanceid + /**/ $primitiveid + /**/ $geometryindex + /**/ $hitKind + /**/ $sbtRecordIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ $currentTime + /**/ __rayAttributeFromLocation(attributeLocation) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectRecordMissNV( + inout hitObjectNV hitObject, + uint sbtRecordIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax) +{ + hitObject = HitObject::MakeMiss( + sbtRecordIndex, + { origin, Tmin, direction, Tmax } + ); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +__glsl_extension(GL_NV_ray_tracing_motion_blur) +[require(glsl, ser_motion)] +[require(spirv, ser_motion)] +[ForceInline] +public void hitObjectRecordMissMotionNV( + inout hitObjectNV hitObject, + uint sbtRecordIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + float currentTime) +{ + hitObject = HitObject::MakeMotionMiss( + sbtRecordIndex, + { origin, Tmin, direction, Tmax }, + currentTime + ); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectRecordEmptyNV(hitObjectNV hitObject) +{ + hitObject = HitObject::MakeNop(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectExecuteShaderNV( + inout hitObjectNV hitObject, + constexpr int payload) +{ + __target_switch + { + case glsl: + { + HitObject::__glslInvoke(hitObject, payload); + } + case spirv: + { + spirv_asm + { + OpHitObjectExecuteShaderNV &hitObject __rayPayloadFromLocation(payload) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public bool hitObjectIsEmptyNV(hitObjectNV hitObject) +{ + return hitObject.IsNop(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public bool hitObjectIsMissNV(hitObjectNV hitObject) +{ + return hitObject.IsMiss(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public bool hitObjectIsHitNV(hitObjectNV hitObject) +{ + return hitObject.IsHit(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public float hitObjectGetRayTMinNV(hitObjectNV hitObject) +{ + return hitObject.GetRayDesc().TMin; +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public float hitObjectGetRayTMaxNV(hitObjectNV hitObject) +{ + return hitObject.GetRayDesc().TMax; +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public vec3 hitObjectGetWorldRayOriginNV(hitObjectNV hitObject) +{ + return hitObject.GetRayDesc().Origin; +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV hitObject) +{ + return hitObject.GetRayDesc().Direction; +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public vec3 hitObjectGetObjectRayOriginNV(hitObjectNV hitObject) +{ + return hitObject.GetObjectRayOrigin(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV hitObject) +{ + return hitObject.GetObjectRayDirection(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV hitObject) +{ + return transpose(hitObject.GetObjectToWorld()); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV hitObject) +{ + return transpose(hitObject.GetWorldToObject()); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public int hitObjectGetInstanceCustomIndexNV(hitObjectNV hitObject) +{ + return hitObject.GetInstanceID(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public int hitObjectGetInstanceIdNV(hitObjectNV hitObject) +{ + return hitObject.GetInstanceIndex(); +} + +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public int hitObjectGetGeometryIndexNV(hitObjectNV hitObject) +{ + return hitObject.GetGeometryIndex(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public int hitObjectGetPrimitiveIndexNV(hitObjectNV hitObject) +{ + return hitObject.GetPrimitiveIndex(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public uint hitObjectGetHitKindNV(hitObjectNV hitObject) +{ + return hitObject.GetHitKind(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void hitObjectGetAttributesNV( + inout hitObjectNV hitObject, + constexpr int attributeLocation) +{ + __target_switch + { + case glsl: + { + __intrinsic_asm "hitObjectGetAttributesNV($0, $1)"; + } + case spirv: + { + spirv_asm + { + OpCapability ShaderInvocationReorderNV; + OpHitObjectGetAttributesNV &hitObject __rayAttributeFromLocation(attributeLocation) + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV hitObject) +{ + return hitObject.GetShaderRecordBufferHandle(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV hitObject) +{ + return hitObject.GetShaderTableIndex(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public float hitObjectGetCurrentTimeNV(hitObjectNV hitObject) +{ + return hitObject.GetCurrentTime(); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void reorderThreadNV(uint hint, uint bits) +{ + ReorderThread(hint, bits); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void reorderThreadNV(hitObjectNV hitObject) +{ + ReorderThread(hitObject); +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +__glsl_extension(GLSL_EXT_buffer_reference_uvec2) +[require(glsl, ser)] +[require(spirv, ser)] +[ForceInline] +public void reorderThreadNV(hitObjectNV hitObject, uint hint, uint bits) +{ + ReorderThread(hitObject, hint, bits); +} + +/// GL_NV_ray_tracing_motion_blur + +[require(glsl, raytracing_motionblur)] +[require(spirv, raytracing_motionblur)] +public property float gl_CurrentRayTimeNV +{ + get + { + __target_switch + { + case glsl: + __intrinsic_asm "(gl_CurrentRayTimeNV)"; + case spirv: + return spirv_asm + { + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_ray_tracing_motion_blur"; + result:$$float = OpLoad builtin(CurrentRayTimeNV:float); + }; + } + } +} + +__glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_ray_tracing_motion_blur) +[require(glsl, raytracing_motionblur)] +[require(spirv, raytracing_motionblur)] +[ForceInline] +public void traceRayMotionNV( + accelerationStructureEXT topLevel, + uint rayFlags, + uint cullMask, + uint sbtRecordOffset, + uint sbtRecordStride, + uint missIndex, + vec3 origin, + float Tmin, + vec3 direction, + float Tmax, + float currentTime, + constexpr int payload) +{ + __target_switch + { + case glsl: + { + __traceMotionRay( + topLevel, + rayFlags, + cullMask, + sbtRecordOffset, + sbtRecordStride, + missIndex, + origin, + Tmin, + direction, + Tmax, + currentTime, + payload); + } + case spirv: + { + spirv_asm + { + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpTraceRayMotionNV + /**/ $topLevel + /**/ $rayFlags + /**/ $cullMask + /**/ $sbtRecordOffset + /**/ $sbtRecordStride + /**/ $missIndex + /**/ $origin + /**/ $Tmin + /**/ $direction + /**/ $Tmax + /**/ $currentTime + /**/ __rayPayloadFromLocation(payload) + }; + } + } +} __generic [ForceInline] diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index f220a68a5c..8df7861eab 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -9520,6 +9520,7 @@ struct BuiltInTriangleIntersectionAttributes // `CallShader()` for GLSL-based targets. // __target_intrinsic(_GL_EXT_ray_tracing, "executeCallableEXT") +[require(glsl, raytracing)] void __executeCallable(uint shaderIndex, int payloadLocation); // Next is the custom intrinsic that will compute the payload location @@ -9535,6 +9536,9 @@ int __callablePayloadLocation(__ref Payload payload); // GLSL equivalent. // __generic +[require(glsl, raytracing)] +[require(spirv, raytracing)] +[require(hlsl, raytracing)] void CallShader(uint shaderIndex, inout Payload payload) { __target_switch @@ -9555,7 +9559,8 @@ void CallShader(uint shaderIndex, inout Payload payload) static Payload p; p = payload; - spirv_asm { + spirv_asm + { OpExecuteCallableKHR $shaderIndex &p }; payload = p; @@ -9565,7 +9570,9 @@ void CallShader(uint shaderIndex, inout Payload payload) // 10.3.2 + __target_intrinsic(_GL_EXT_ray_tracing, "traceRayEXT") +[require(glsl, raytracing)] void __traceRay( RaytracingAccelerationStructure AccelerationStructure, uint RayFlags, @@ -9590,6 +9597,9 @@ __generic __intrinsic_op($(kIROp_GetVulkanRayTracingPayloadLocation)) int __rayPayloadLocation(__ref Payload payload); +[require(glsl, raytracing)] +[require(spirv, raytracing)] +[require(hlsl, raytracing)] __generic void TraceRay( RaytracingAccelerationStructure AccelerationStructure, @@ -9635,7 +9645,8 @@ void TraceRay( let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { + spirv_asm + { OpTraceRayKHR /**/ $AccelerationStructure /**/ $RayFlags @@ -9660,10 +9671,9 @@ void TraceRay( // // https://github.com/KhronosGroup/GLSL/blob/master/extensions/nv/GLSL_NV_ray_tracing_motion_blur.txt -__target_intrinsic(glsl, "traceRayMotionNV") -__glsl_version(460) __glsl_extension(GL_NV_ray_tracing_motion_blur) -__glsl_extension(GL_EXT_ray_tracing) +__target_intrinsic(glsl, "traceRayMotionNV") +[require(glsl, raytracing_motionblur)] void __traceMotionRay( RaytracingAccelerationStructure AccelerationStructure, uint RayFlags, @@ -9678,6 +9688,9 @@ void __traceMotionRay( float CurrentTime, int PayloadLocation); +[require(glsl, raytracing_motionblur)] +[require(spirv, raytracing_motionblur)] +[require(hlsl, raytracing_motionblur)] __generic void TraceMotionRay( RaytracingAccelerationStructure AccelerationStructure, @@ -9725,7 +9738,8 @@ void TraceMotionRay( let tmax = Ray.TMax; p = Payload; - spirv_asm { + spirv_asm + { OpCapability RayTracingMotionBlurNV; OpExtension "SPV_NV_ray_tracing_motion_blur"; @@ -9750,15 +9764,19 @@ void TraceMotionRay( // 10.3.3 __target_intrinsic(hlsl) +[require(hlsl, raytracing)] bool ReportHit(float tHit, uint hitKind, A attributes); +[require(spirv, raytracing)] +[require(glsl, raytracing)] bool __reportIntersection(float tHit, uint hitKind) { __target_switch { case _GL_EXT_ray_tracing: __intrinsic_asm "reportIntersectionEXT"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$bool = OpReportIntersectionKHR $tHit $hitKind; }; } @@ -9777,6 +9795,9 @@ bool ReportHit(float tHit, uint hitKind, A attributes) } // 10.3.4 +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] void IgnoreHit() { __target_switch @@ -9784,11 +9805,18 @@ void IgnoreHit() case hlsl: __intrinsic_asm "IgnoreHit"; case _GL_EXT_ray_tracing: __intrinsic_asm "ignoreIntersectionEXT;"; case cuda: __intrinsic_asm "optixIgnoreIntersection"; - case spirv: spirv_asm { OpIgnoreIntersectionKHR; %_ = OpLabel }; + case spirv: + spirv_asm + { + OpIgnoreIntersectionKHR; %_ = OpLabel + }; } } // 10.3.5 +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] void AcceptHitAndEndSearch() { __target_switch @@ -9796,7 +9824,11 @@ void AcceptHitAndEndSearch() case hlsl: __intrinsic_asm "AcceptHitAndEndSearch"; case _GL_EXT_ray_tracing: __intrinsic_asm "terminateRayEXT;"; case cuda: __intrinsic_asm "optixTerminateRay"; - case spirv: spirv_asm { OpTerminateRayKHR; %_ = OpLabel }; + case spirv: + spirv_asm + { + OpTerminateRayKHR; %_ = OpLabel + }; } } @@ -9808,20 +9840,27 @@ void AcceptHitAndEndSearch() // 10.4.1 - Ray Dispatch System Values [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint3 DispatchRaysIndex() { __target_switch { - case hlsl: __intrinsic_asm "DispatchRaysIndex"; + case hlsl: __intrinsic_asm "DispatchRaysIndex"; case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_LaunchIDEXT)"; case cuda: __intrinsic_asm "optixGetLaunchIndex"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint3 = OpLoad builtin(LaunchIdKHR:uint3); }; } } +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint3 DispatchRaysDimensions() { __target_switch @@ -9830,7 +9869,8 @@ uint3 DispatchRaysDimensions() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_LaunchSizeEXT)"; case cuda: __intrinsic_asm "optixGetLaunchDimensions"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint3 = OpLoad builtin(LaunchSizeKHR:uint3); }; } @@ -9839,6 +9879,9 @@ uint3 DispatchRaysDimensions() // 10.4.2 - Ray System Values [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3 WorldRayOrigin() { __target_switch @@ -9847,13 +9890,17 @@ float3 WorldRayOrigin() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_WorldRayOriginEXT)"; case cuda: __intrinsic_asm "optixGetWorldRayOrigin"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpLoad builtin(WorldRayOriginKHR:float3); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3 WorldRayDirection() { __target_switch @@ -9862,13 +9909,17 @@ float3 WorldRayDirection() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_WorldRayDirectionEXT)"; case cuda: __intrinsic_asm "optixGetWorldRayDirection"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpLoad builtin(WorldRayDirectionKHR:float3); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float RayTMin() { __target_switch @@ -9877,7 +9928,8 @@ float RayTMin() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_RayTminEXT)"; case cuda: __intrinsic_asm "optixGetRayTmin"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float = OpLoad builtin(RayTminKHR:float); }; } @@ -9894,6 +9946,9 @@ float RayTMin() // to the appropriate Vulkan stages. // [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float RayTCurrent() { __target_switch @@ -9902,12 +9957,16 @@ float RayTCurrent() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_RayTmaxEXT)"; case cuda: __intrinsic_asm "optixGetRayTmax"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float = OpLoad builtin(RayTmaxKHR:float); }; } } +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint RayFlags() { __target_switch @@ -9916,7 +9975,8 @@ uint RayFlags() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_IncomingRayFlagsEXT)"; case cuda: __intrinsic_asm "optixGetRayFlags"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpLoad builtin(IncomingRayFlagsKHR:uint); }; } @@ -9925,6 +9985,9 @@ uint RayFlags() // 10.4.3 - Primitive/Object Space System Values [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint InstanceIndex() { __target_switch @@ -9933,13 +9996,17 @@ uint InstanceIndex() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_InstanceID)"; case cuda: __intrinsic_asm "optixGetInstanceIndex"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpLoad builtin(InstanceId:uint); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint InstanceID() { __target_switch @@ -9948,28 +10015,36 @@ uint InstanceID() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_InstanceCustomIndexEXT)"; case cuda: __intrinsic_asm "optixGetInstanceId"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpLoad builtin(InstanceCustomIndexKHR:uint); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint PrimitiveIndex() { __target_switch { case hlsl: __intrinsic_asm "PrimitiveIndex"; - case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_PrimitiveID)"; + case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_PrimitiveID)"; case cuda: __intrinsic_asm "optixGetPrimitiveIndex"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpLoad builtin(PrimitiveId:uint); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3 ObjectRayOrigin() { __target_switch @@ -9978,13 +10053,17 @@ float3 ObjectRayOrigin() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_ObjectRayOriginEXT)"; case cuda: __intrinsic_asm "optixGetObjectRayOrigin"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpLoad builtin(ObjectRayOriginKHR:float3); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3 ObjectRayDirection() { __target_switch @@ -9993,7 +10072,8 @@ float3 ObjectRayDirection() case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_ObjectRayDirectionEXT)"; case cuda: __intrinsic_asm "optixGetObjectRayDirection"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpLoad builtin(ObjectRayDirectionKHR:float3); }; } @@ -10002,6 +10082,9 @@ float3 ObjectRayDirection() // TODO: optix has an optixGetObjectToWorldTransformMatrix function that returns 12 // floats by reference. [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3x4 ObjectToWorld3x4() { __target_switch @@ -10009,7 +10092,8 @@ float3x4 ObjectToWorld3x4() case hlsl: __intrinsic_asm "ObjectToWorld3x4"; case _GL_EXT_ray_tracing: __intrinsic_asm "transpose(gl_ObjectToWorldEXT)"; case spirv: - return spirv_asm { + return spirv_asm + { %mat:$$float4x3 = OpLoad builtin(ObjectToWorldKHR:float4x3); result:$$float3x4 = OpTranspose %mat; }; @@ -10017,6 +10101,9 @@ float3x4 ObjectToWorld3x4() } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float3x4 WorldToObject3x4() { __target_switch @@ -10024,7 +10111,8 @@ float3x4 WorldToObject3x4() case hlsl: __intrinsic_asm "WorldToObject3x4"; case _GL_EXT_ray_tracing: __intrinsic_asm "transpose(gl_WorldToObjectEXT)"; case spirv: - return spirv_asm { + return spirv_asm + { %mat:$$float4x3 = OpLoad builtin(WorldToObjectKHR:float4x3); result:$$float3x4 = OpTranspose %mat; }; @@ -10032,6 +10120,9 @@ float3x4 WorldToObject3x4() } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float4x3 ObjectToWorld4x3() { __target_switch @@ -10039,13 +10130,17 @@ float4x3 ObjectToWorld4x3() case hlsl: __intrinsic_asm "ObjectToWorld4x3"; case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_ObjectToWorldEXT)"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float4x3 = OpLoad builtin(ObjectToWorldKHR:float4x3); }; } } [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] float4x3 WorldToObject4x3() { __target_switch @@ -10053,7 +10148,8 @@ float4x3 WorldToObject4x3() case hlsl: __intrinsic_asm "WorldToObject4x3"; case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_WorldToObjectEXT)"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float4x3 = OpLoad builtin(WorldToObjectKHR:float4x3); }; } @@ -10063,10 +10159,12 @@ float4x3 WorldToObject4x3() // The name of the following functions may change when DXR supports // a feature similar to the `GL_NV_ray_tracing_motion_blur` extension -__glsl_version(460) __glsl_extension(GL_NV_ray_tracing_motion_blur) __glsl_extension(GL_EXT_ray_tracing) [NonUniformReturn] +[require(hlsl, raytracing_motionblur)] +[require(glsl, raytracing_motionblur)] +[require(spirv, raytracing_motionblur)] float RayCurrentTime() { __target_switch @@ -10074,7 +10172,8 @@ float RayCurrentTime() case hlsl: __intrinsic_asm "RayCurrentTime"; case glsl: __intrinsic_asm "(gl_CurrentRayTimeNV)"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float = OpLoad builtin(CurrentRayTimeNV:float); }; } @@ -10094,15 +10193,19 @@ float RayCurrentTime() // 10.4.4 - Hit Specific System values [NonUniformReturn] +[require(hlsl, raytracing)] +[require(glsl, raytracing)] +[require(spirv, raytracing)] uint HitKind() { __target_switch { case hlsl: __intrinsic_asm "HitKind"; - case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_HitKindEXT)"; + case _GL_EXT_ray_tracing: __intrinsic_asm "(gl_HitKindEXT)"; case cuda: __intrinsic_asm "optixGetHitKind"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpLoad builtin(HitKindKHR:uint); }; } @@ -10291,6 +10394,9 @@ extension __TextureImpl @@ -10403,10 +10511,11 @@ struct RayQuery __intrinsic_op($(kIROp_AllocateOpaqueHandle)) __init(); - + __target_intrinsic(glsl, "rayQueryInitializeEXT($0, $1, $2, $3, $4, $5, $6, $7)") __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] [mutating] void __rayQueryInitializeEXT( RaytracingAccelerationStructure accelerationStructure, @@ -10439,6 +10548,9 @@ struct RayQuery // `RayQuery` to get the effective ray flags, which // must obey any API-imposed restrictions. // + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__unsafeForceInlineEarly] [mutating] void TraceRayInline( @@ -10478,7 +10590,9 @@ struct RayQuery // that was found. // __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [mutating] bool Proceed() { @@ -10500,7 +10614,9 @@ struct RayQuery // `Proceed()` calls will return `false`. // __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [mutating] void Abort() { @@ -10514,7 +10630,9 @@ struct RayQuery // Commit the current non-opaque triangle hit. __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [mutating] void CommitNonOpaqueTriangleHit() @@ -10529,7 +10647,9 @@ struct RayQuery // Commit the current procedural primitive hit, with hit time `t`. __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [mutating] void CommitProceduralPrimitiveHit(float t) @@ -10552,7 +10672,9 @@ struct RayQuery // user code. // __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] CANDIDATE_TYPE CandidateType() @@ -10571,7 +10693,9 @@ struct RayQuery // Get the status of the committed (closest) hit, if any. __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] COMMITTED_STATUS CommittedStatus() @@ -10590,7 +10714,9 @@ struct RayQuery } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] bool CandidateProceduralPrimitiveNonOpaque() @@ -10598,7 +10724,7 @@ struct RayQuery __target_switch { case hlsl: __intrinsic_asm ".CandidateProceduralPrimitiveNonOpaque"; - case glsl: __intrinsic_asm "(!rayQueryGetIntersectionCandidateAABBOpaqueEXT($0, false))"; + case glsl: __intrinsic_asm "(!rayQueryGetIntersectionCandidateAABBOpaqueEXT($0))"; case spirv: uint iCandidateOrCommitted = 0; return spirv_asm @@ -10610,7 +10736,9 @@ struct RayQuery } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float CandidateTriangleRayT() @@ -10628,7 +10756,9 @@ struct RayQuery } } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float CommittedRayT() @@ -10646,6 +10776,404 @@ struct RayQuery } } +///missing hlsl equivlent; only implemented for glsl & spirv + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CandidateRayInstanceCustomIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceCustomIndexEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionInstanceCustomIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CommittedRayInstanceCustomIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceCustomIndexEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionInstanceCustomIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CandidateRayInstanceId() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceIdEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionInstanceIdKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CommittedRayInstanceId() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceIdEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionInstanceIdKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + uint CandidateRayInstanceShaderBindingTableRecordOffset() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$uint = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + uint CommittedRayInstanceShaderBindingTableRecordOffset() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$uint = OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CandidateRayGeometryIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionGeometryIndexEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionGeometryIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CommittedRayGeometryIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionGeometryIndexEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionGeometryIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CandidateRayPrimitiveIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionPrimitiveIndexEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionPrimitiveIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + int CommittedRayPrimitiveIndex() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionPrimitiveIndexEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$int = OpRayQueryGetIntersectionPrimitiveIndexKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float2 CandidateRayBarycentrics() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionBarycentricsEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float2 = OpRayQueryGetIntersectionBarycentricsKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float2 CommittedRayBarycentrics() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionBarycentricsEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$float2 = OpRayQueryGetIntersectionBarycentricsKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + bool CandidateRayFrontFace() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionFrontFaceEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$bool = OpRayQueryGetIntersectionFrontFaceKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + bool CommittedRayFrontFace() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionFrontFaceEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$bool = OpRayQueryGetIntersectionFrontFaceKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float3 CandidateRayObjectRayDirection() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectRayDirectionEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float3 = OpRayQueryGetIntersectionObjectRayDirectionKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float3 CommittedRayObjectRayDirection() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectRayDirectionEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$float3 = OpRayQueryGetIntersectionObjectRayDirectionKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float3 CandidateRayObjectRayOrigin() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectRayOriginEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float3 = OpRayQueryGetIntersectionObjectRayOriginKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float3 CommittedRayObjectRayOrigin() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectRayOriginEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$float3 = OpRayQueryGetIntersectionObjectRayOriginKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float4x3 CandidateRayObjectToWorld() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectToWorldEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float4x3 = OpRayQueryGetIntersectionObjectToWorldKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float4x3 CommittedRayObjectToWorld() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionObjectToWorldEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + result:$$float4x3 = OpRayQueryGetIntersectionObjectToWorldKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float4x3 CandidateRayWorldToObject() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionWorldToObjectEXT($0, false)"; + case spirv: + uint iCandidateOrCommitted = 0; + return spirv_asm + { + result:$$float4x3 = OpRayQueryGetIntersectionWorldToObjectKHR &this $iCandidateOrCommitted; + }; + } + } + + __glsl_extension(GL_EXT_ray_query) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [__NoSideEffect] + float4x3 CommittedRayWorldToObject() + { + __target_switch + { + case glsl: __intrinsic_asm "rayQueryGetIntersectionWorldToObjectEXT($0, true)"; + case spirv: + uint iCandidateOrCommitted = 1; + return spirv_asm + { + OpRayQueryGetIntersectionWorldToObjectKHR $$float4x3 result &this $iCandidateOrCommitted; + }; + } + } +///~ + ${{{{ const char* kCandidateCommitted[] = {"Candidate", "Committed"}; @@ -10658,7 +11186,7 @@ ${{{{ __glsl_extension(GL_EXT_ray_query) __glsl_extension(GL_EXT_ray_tracing_position_fetch) - __glsl_version(460) + [require(glsl, rayquery_pos)] [__NoSideEffect] void __glslGetIntersectionTriangleVertexPositions$(ccName)(out float3 arr[3]) { @@ -10666,8 +11194,8 @@ ${{{{ }; __glsl_extension(GL_EXT_ray_query) - __glsl_extension(GL_EXT_ray_tracing_position_fetch) - __glsl_version(460) + [require(glsl, rayquery_pos)] + [require(spirv, rayquery_pos)] [__NoSideEffect] float3[3] $(ccName)GetIntersectionTriangleVertexPositions() { @@ -10700,7 +11228,9 @@ ${{{{ }}}} __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float3x4 $(ccName)$(matName)3x4() @@ -10711,7 +11241,8 @@ ${{{{ case hlsl: __intrinsic_asm ".$(ccName)$(matName)3x4"; case spirv: uint iCandidateOrCommitted = $(candidateOrCommitted); - return spirv_asm { + return spirv_asm + { %m:$$float4x3 = OpRayQueryGetIntersection$(matName)KHR &this $iCandidateOrCommitted; result:$$float3x4 = OpTranspose %m; }; @@ -10719,7 +11250,9 @@ ${{{{ } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__readNone] [NonUniformReturn] float4x3 $(ccName)$(matName)4x3() @@ -10730,7 +11263,8 @@ ${{{{ case hlsl: __intrinsic_asm ".$(ccName)$(matName)4x3"; case spirv: uint iCandidateOrCommitted = $(candidateOrCommitted); - return spirv_asm { + return spirv_asm + { result:$$float4x3 = OpRayQueryGetIntersection$(matName)KHR &this $iCandidateOrCommitted; }; } @@ -10761,7 +11295,9 @@ ${{{{ }}}} __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] $(method.type) $(ccName)$(method.hlslName)() @@ -10772,7 +11308,8 @@ ${{{{ case glsl: __intrinsic_asm "rayQueryGetIntersection$(method.glslName)EXT($0, $(ccTF))"; case spirv: uint iCandidateOrCommitted = $(candidateOrCommitted); - return spirv_asm { + return spirv_asm + { result:$$$(method.type) = OpRayQueryGetIntersection$(method.glslName)KHR &this $iCandidateOrCommitted; }; } @@ -10785,7 +11322,9 @@ ${{{{ // Access properties of the ray being traced. __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] uint RayFlags() @@ -10795,14 +11334,17 @@ ${{{{ case hlsl: __intrinsic_asm ".RayFlags"; case glsl: __intrinsic_asm "rayQueryGetRayFlagsEXT"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$uint = OpRayQueryGetRayFlagsKHR &this; }; } } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float3 WorldRayOrigin() @@ -10812,14 +11354,17 @@ ${{{{ case hlsl: __intrinsic_asm ".WorldRayOrigin"; case glsl: __intrinsic_asm "rayQueryGetWorldRayOriginEXT"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpRayQueryGetWorldRayOriginKHR &this; }; } } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float3 WorldRayDirection() @@ -10829,14 +11374,17 @@ ${{{{ case hlsl: __intrinsic_asm ".WorldRayDirection"; case glsl: __intrinsic_asm "rayQueryGetWorldRayDirectionEXT"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float3 = OpRayQueryGetWorldRayDirectionKHR &this; }; } } __glsl_extension(GL_EXT_ray_query) - __glsl_version(460) + [require(glsl, rayquery)] + [require(spirv, rayquery)] + [require(hlsl, rayquery)] [__NoSideEffect] [NonUniformReturn] float RayTMin() @@ -10846,7 +11394,8 @@ ${{{{ case hlsl: __intrinsic_asm ".RayTMin"; case glsl: __intrinsic_asm "rayQueryGetRayTMinEXT"; case spirv: - return spirv_asm { + return spirv_asm + { result:$$float = OpRayQueryGetRayTMinKHR &this; }; } @@ -10921,7 +11470,6 @@ int __hitObjectAttributesLocation(__ref Attributes attributes); /// Immutable data type representing a ray hit or a miss. Can be used to invoke hit or miss shading, /// or as a key in ReorderThread. Created by one of several methods described below. HitObject /// and its related functions are available in raytracing shader types only. -[__requiresNVAPI] __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) [__NonCopyableType] @@ -10933,6 +11481,9 @@ struct HitObject /// Executes ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the /// resulting hit information as a HitObject and does not trigger closesthit or miss shaders. + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static HitObject TraceRay( RaytracingAccelerationStructure AccelerationStructure, @@ -10998,7 +11549,9 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; OpCapability ShaderInvocationReorderNV; OpHitObjectTraceRayNV /**/ &__return_val @@ -11024,6 +11577,9 @@ struct HitObject /// Executes motion ray traversal (including anyhit and intersection shaders) like TraceRay, but returns the /// resulting hit information as a HitObject and does not trigger closesthit or miss shaders. [ForceInline] + [require(glsl, ser_motion)] + [require(spirv, ser_motion)] + [require(hlsl, ser_motion)] static HitObject TraceMotionRay( RaytracingAccelerationStructure AccelerationStructure, uint RayFlags, @@ -11077,9 +11633,12 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { - OpCapability RayTracingMotionBlurNV; + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpCapability RayTracingMotionBlurNV; OpHitObjectTraceRayMotionNV /**/ &__return_val /**/ $AccelerationStructure @@ -11109,6 +11668,9 @@ struct HitObject /// TraceRay. The computed index must reference a valid hit group record in the shader table. The /// Attributes parameter must either be an attribute struct, such as /// BuiltInTriangleIntersectionAttributes, or another HitObject to copy the attributes from. + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static HitObject MakeHit( RaytracingAccelerationStructure AccelerationStructure, @@ -11168,7 +11730,10 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordHitNV /**/ &__return_val /**/ $AccelerationStructure @@ -11190,6 +11755,9 @@ struct HitObject /// See MakeHit but handles Motion /// Currently only supported on VK + [require(glsl, ser_motion)] + [require(spirv, ser_motion)] + [require(hlsl, ser_motion)] [ForceInline] static HitObject MakeMotionHit( RaytracingAccelerationStructure AccelerationStructure, @@ -11238,9 +11806,12 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { - OpCapability RayTracingMotionBlurNV; + spirv_asm + { OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordHitMotionNV /**/ &__return_val /**/ $AccelerationStructure @@ -11268,6 +11839,9 @@ struct HitObject /// reference a valid hit group record in the shader table. The Attributes parameter must either be an /// attribute struct, such as BuiltInTriangleIntersectionAttributes, or another HitObject to copy the /// attributes from. + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static HitObject MakeHit( uint HitGroupRecordIndex, @@ -11301,10 +11875,10 @@ struct HitObject __glslMakeHitWithIndex( __return_val, - AccelerationStructure, + AccelerationStructure, InstanceIndex, ///? Same as instanceid ? - GeometryIndex, PrimitiveIndex, + GeometryIndex, HitKind, /// Assuming HitKinds are compatible HitGroupRecordIndex, /// sbtRecordIndex Ray.Origin, @@ -11322,7 +11896,10 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordHitWithIndexNV /**/ &__return_val /**/ $AccelerationStructure @@ -11342,7 +11919,8 @@ struct HitObject } /// See MakeHit but handles Motion /// Currently only supported on VK - + [require(glsl, ser_motion)] + [require(spirv, ser_motion)] [ForceInline] static HitObject MakeMotionHit( uint HitGroupRecordIndex, @@ -11364,10 +11942,10 @@ struct HitObject __glslMakeMotionHitWithIndex( __return_val, - AccelerationStructure, + AccelerationStructure, InstanceIndex, ///? Same as instanceid ? - GeometryIndex, - PrimitiveIndex, + PrimitiveIndex, + GeometryIndex, HitKind, /// Assuming HitKinds are compatible HitGroupRecordIndex, /// sbtRecordIndex Ray.Origin, @@ -11386,9 +11964,10 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { - OpCapability RayTracingMotionBlurNV; + spirv_asm + { OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpCapability RayTracingMotionBlurNV; OpHitObjectRecordHitWithIndexMotionNV /**/ &__return_val /**/ $AccelerationStructure @@ -11412,6 +11991,9 @@ struct HitObject /// tracing a ray. The provided shader table index must reference a valid miss record in the shader /// table. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static HitObject MakeMiss( uint MissShaderIndex, @@ -11428,7 +12010,10 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordMissNV /**/ &__return_val /**/ $MissShaderIndex @@ -11443,8 +12028,10 @@ struct HitObject /// See MakeMiss but handles Motion /// Currently only supported on VK + [require(glsl, ser_motion)] + [require(spirv, ser_motion)] + [require(hlsl, ser_motion)] [ForceInline] - __specialized_for_target(glsl) static HitObject MakeMotionMiss( uint MissShaderIndex, RayDesc Ray, @@ -11461,9 +12048,12 @@ struct HitObject let direction = Ray.Direction; let tmin = Ray.TMin; let tmax = Ray.TMax; - spirv_asm { - OpCapability RayTracingMotionBlurNV; + spirv_asm + { OpExtension "SPV_NV_ray_tracing_motion_blur"; + OpCapability RayTracingMotionBlurNV; + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordMissMotionNV /**/ &__return_val /**/ $MissShaderIndex @@ -11483,6 +12073,9 @@ struct HitObject /// scenarios where future control flow for some threads is known to process neither a hit nor a /// miss. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static HitObject MakeNop() { @@ -11493,7 +12086,10 @@ struct HitObject case glsl: __glslMakeNop(__return_val); case spirv: - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectRecordEmptyNV /**/ &__return_val; }; @@ -11503,6 +12099,9 @@ struct HitObject /// Invokes closesthit or miss shading for the specified hit object. In case of a NOP HitObject, no /// shader is invoked. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] static void Invoke( RaytracingAccelerationStructure AccelerationStructure, @@ -11533,7 +12132,10 @@ struct HitObject // Save the payload p = Payload; - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectExecuteShaderNV /**/ &HitOrMiss /**/ &p; @@ -11547,15 +12149,21 @@ struct HitObject /// Returns true if the HitObject encodes a miss, otherwise returns false. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] - __glsl_extension(GL_EXT_ray_tracing) bool IsMiss() { __target_switch { case hlsl: __intrinsic_asm ".IsMiss"; case glsl: __intrinsic_asm "hitObjectIsMissNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$bool = OpHitObjectIsMissNV &this; }; } @@ -11563,15 +12171,21 @@ struct HitObject /// Returns true if the HitObject encodes a hit, otherwise returns false. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] - __glsl_extension(GL_EXT_ray_tracing) bool IsHit() { __target_switch { case hlsl: __intrinsic_asm ".IsHit"; case glsl: __intrinsic_asm "hitObjectIsHitNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$bool = OpHitObjectIsHitNV &this; }; } @@ -11579,15 +12193,21 @@ struct HitObject /// Returns true if the HitObject encodes a nop, otherwise returns false. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] - __glsl_extension(GL_EXT_ray_tracing) bool IsNop() { __target_switch { case hlsl: __intrinsic_asm ".IsNop"; case glsl: __intrinsic_asm "hitObjectIsEmptyNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$bool = OpHitObjectIsEmptyNV &this; }; } @@ -11595,8 +12215,10 @@ struct HitObject /// Queries ray properties from HitObject. Valid if the hit object represents a hit or a miss. [__requiresNVAPI] + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] - __target_intrinsic(hlsl) RayDesc GetRayDesc() { __target_switch @@ -11609,7 +12231,10 @@ struct HitObject return ray; } case spirv: - return spirv_asm { + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; %origin:$$float3 = OpHitObjectGetWorldRayOriginNV &this; %tmin:$$float = OpHitObjectGetRayTMinNV &this; %direction:$$float3 = OpHitObjectGetWorldRayDirectionNV &this; @@ -11621,15 +12246,22 @@ struct HitObject /// Queries shader table index from HitObject. Valid if the hit object represents a hit or a miss. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetShaderTableIndex() { __target_switch { case hlsl: __intrinsic_asm ".GetShaderTableIndex"; case glsl: __intrinsic_asm "hitObjectGetShaderBindingTableRecordIndexNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetShaderBindingTableRecordIndexNV &this; }; } @@ -11637,15 +12269,22 @@ struct HitObject /// Returns the instance index of a hit. Valid if the hit object represents a hit. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetInstanceIndex() { __target_switch { case hlsl: __intrinsic_asm ".GetInstanceIndex"; case glsl: __intrinsic_asm "hitObjectGetInstanceIdNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetInstanceIdNV &this; }; } @@ -11653,15 +12292,22 @@ struct HitObject /// Returns the instance ID of a hit. Valid if the hit object represents a hit. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetInstanceID() { __target_switch { case hlsl: __intrinsic_asm ".GetInstanceID"; case glsl: __intrinsic_asm "hitObjectGetInstanceCustomIndexNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetInstanceCustomIndexNV &this; }; } @@ -11669,15 +12315,22 @@ struct HitObject /// Returns the geometry index of a hit. Valid if the hit object represents a hit. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetGeometryIndex() { __target_switch { case hlsl: __intrinsic_asm ".GetGeometryIndex"; case glsl: __intrinsic_asm "hitObjectGetGeometryIndexNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetGeometryIndexNV &this; }; } @@ -11685,15 +12338,22 @@ struct HitObject /// Returns the primitive index of a hit. Valid if the hit object represents a hit. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetPrimitiveIndex() { __target_switch { case hlsl: __intrinsic_asm ".GetPrimitiveIndex"; case glsl: __intrinsic_asm "hitObjectGetPrimitiveIndexNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetPrimitiveIndexNV &this; }; } @@ -11701,51 +12361,147 @@ struct HitObject /// Returns the hit kind. Valid if the hit object represents a hit. [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] uint GetHitKind() { __target_switch { case hlsl: __intrinsic_asm ".GetHitKind"; case glsl: __intrinsic_asm "hitObjectGetHitKindNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$uint = OpHitObjectGetHitKindNV &this; }; } } [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] float4x3 GetWorldToObject() { __target_switch { case hlsl: __intrinsic_asm ".GetWorldToObject"; case glsl: __intrinsic_asm "hitObjectGetWorldToObjectNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$float4x3 = OpHitObjectGetWorldToObjectNV &this; }; } } [__requiresNVAPI] - [ForceInline] __glsl_extension(GL_EXT_ray_tracing) + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] + [ForceInline] float4x3 GetObjectToWorld() { __target_switch { case hlsl: __intrinsic_asm ".GetObjectToWorld"; case glsl: __intrinsic_asm "hitObjectGetObjectToWorldNV($0)"; - case spirv: return spirv_asm { + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; result:$$float4x3 = OpHitObjectGetObjectToWorldNV &this; }; } } + [require(glsl, ser)] + [require(spirv, ser)] + [ForceInline] + float GetCurrentTime() { + __target_switch + { + case glsl: + __intrinsic_asm "hitObjectGetCurrentTimeNV($0)"; + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; + result:$$float = OpHitObjectGetCurrentTimeNV &this + }; + } + } + + [require(glsl, ser)] + [require(spirv, ser)] + [ForceInline] + float3 GetObjectRayOrigin() { + __target_switch + { + case glsl: + __intrinsic_asm "hitObjectGetObjectRayOriginNV($0)"; + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; + result:$$float3 = OpHitObjectGetObjectRayOriginNV &this + }; + } + } + + [require(glsl, ser)] + [require(spirv, ser)] + [ForceInline] + float3 GetObjectRayDirection() { + __target_switch + { + case glsl: + __intrinsic_asm "hitObjectGetObjectRayDirectionNV($0)"; + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; + result:$$float3 = OpHitObjectGetObjectRayDirectionNV &this + }; + } + } + + [require(glsl, ser)] + [require(spirv, ser)] + [ForceInline] + uint2 GetShaderRecordBufferHandle() { + __target_switch + { + case glsl: + __intrinsic_asm "hitObjectGetShaderRecordBufferHandleNV($0)"; + case spirv: + return spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; + result:$$uint2 = OpHitObjectGetShaderRecordBufferHandleNV &this + }; + } + } + /// Returns the attributes of a hit. Valid if the hit object represents a hit or a miss. + [require(glsl, ser)] + [require(spirv, ser)] + [require(hlsl, ser)] [ForceInline] attr_t GetAttributes() { @@ -11771,7 +12527,10 @@ struct HitObject case spirv: { Ptr attr = __allocHitObjectAttributes(); - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpHitObjectGetAttributesNV &this $attr; }; return *attr; @@ -11782,6 +12541,7 @@ struct HitObject /// represents a hit or a miss. RootConstantOffsetInBytes must be a multiple of 4. __target_intrinsic(hlsl) [__requiresNVAPI] + [require(hlsl, ser)] uint LoadLocalRootTableConstant(uint RootConstantOffsetInBytes); /// @@ -11790,10 +12550,12 @@ struct HitObject __target_intrinsic(hlsl, "NvGetAttributesFromHitObject($0, $1)") [__requiresNVAPI] + [require(hlsl, ser)] void __hlslGetAttributesFromHitObject(out T t); __target_intrinsic(hlsl, "NvMakeHitWithRecordIndex") [__requiresNVAPI] + [require(hlsl, ser)] static void __hlslMakeHitWithRecordIndex( uint HitGroupRecordIndex, RaytracingAccelerationStructure AccelerationStructure, @@ -11807,6 +12569,7 @@ struct HitObject __target_intrinsic(hlsl, "NvMakeHit") [__requiresNVAPI] + [require(hlsl, ser)] static void __hlslMakeHit(RaytracingAccelerationStructure AccelerationStructure, uint InstanceIndex, uint GeometryIndex, @@ -11820,6 +12583,7 @@ struct HitObject __target_intrinsic(hlsl, "NvTraceRayHitObject") [__requiresNVAPI] + [require(hlsl, ser)] static void __hlslTraceRay( RaytracingAccelerationStructure AccelerationStructure, uint RayFlags, @@ -11837,7 +12601,7 @@ struct HitObject __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) - __glsl_version(460) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectRecordMissNV") static void __glslMakeMiss( out HitObject hitObj, @@ -11850,8 +12614,8 @@ struct HitObject // "void hitObjectRecordMissNV(hitObjectNV, uint, vec3, float, vec3, float);" __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) - __glsl_extension(GL_NV_ray_tracing_motion_blur) - __glsl_version(460) + __glsl_extension(GL_NV_ray_tracing_motion_blur) + [require(glsl, ser_motion)] __target_intrinsic(glsl, "hitObjectRecordMissMotionNV") static void __glslMakeMotionMiss( out HitObject hitObj, @@ -11862,35 +12626,46 @@ struct HitObject float TMax, float CurrentTime); - __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) + __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectRecordEmptyNV") static void __glslMakeNop(out HitObject hitObj); + __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetObjectRayDirectionNV($0)") float3 __glslGetRayDirection(); - + + __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetWorldRayDirectionNV($0)") float3 __glslGetRayWorldDirection(); + __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetWorldRayOriginNV($0)") float3 __glslGetRayWorldOrigin(); + __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetRayTMaxNV($0)") float __glslGetTMax(); + __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetRayTMinNV($0)") float __glslGetTMin(); // "void hitObjectRecordHitWithIndexNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,int);" - __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) - __glsl_version(460) + __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectRecordHitWithIndexNV") static void __glslMakeHitWithIndex( out HitObject hitObj, @@ -11907,9 +12682,10 @@ struct HitObject int attributeLocation); // "void hitObjectRecordHitWithIndexMotionNV(hitObjectNV, accelerationStructureEXT,int,int,int,uint,uint,vec3,float,vec3,float,float,int);" - __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) + __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_NV_ray_tracing_motion_blur) + [require(glsl, ser_motion)] __target_intrinsic(glsl, "hitObjectRecordHitWithIndexMotionNV") static void __glslMakeMotionHitWithIndex( out HitObject hitObj, @@ -11929,6 +12705,7 @@ struct HitObject // "void hitObjectRecordHitNV(hitObjectNV,accelerationStructureEXT,int,int,int,uint,uint,uint,vec3,float,vec3,float,int);" __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectRecordHitNV") static void __glslMakeHit( out HitObject hitObj, @@ -11949,6 +12726,7 @@ struct HitObject __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_NV_ray_tracing_motion_blur) + [require(glsl, ser_motion)] __target_intrinsic(glsl, "hitObjectRecordHitMotionNV") static void __glslMakeMotionHit( out HitObject hitObj, @@ -11969,11 +12747,13 @@ struct HitObject __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectGetAttributesNV($0, $1)") void __glslGetAttributes(int attributeLocation); __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectTraceRayNV") static void __glslTraceRay( out HitObject hitObject, @@ -11992,6 +12772,7 @@ struct HitObject __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_NV_ray_tracing_motion_blur) + [require(glsl, ser_motion)] __target_intrinsic(glsl, "hitObjectTraceRayMotionNV") static void __glslTraceMotionRay( out HitObject hitObject, @@ -12010,6 +12791,7 @@ struct HitObject __glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) + [require(glsl, ser)] __target_intrinsic(glsl, "hitObjectExecuteShaderNV") static void __glslInvoke( HitObject hitObj, @@ -12024,8 +12806,11 @@ struct HitObject /// Where possible, reordering will also attempt to retain locality in the thread’s launch indices /// (DispatchRaysIndex in DXR). [__requiresNVAPI] -__glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +[require(glsl, ser)] +[require(spirv, ser)] +[require(hlsl, ser)] void ReorderThread( uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ) { __target_switch @@ -12033,9 +12818,10 @@ void ReorderThread( uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ) case hlsl: __intrinsic_asm "NvReorderThread"; case glsl: __intrinsic_asm "reorderThreadNV"; case spirv: - spirv_asm { - OpCapability ShaderInvocationReorderNV; + spirv_asm + { OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpReorderThreadWithHintNV $CoherenceHint $NumCoherenceHintBitsFromLSB; }; } @@ -12056,9 +12842,13 @@ void ReorderThread( uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ) /// same shader ID. (Miss shaders and NOP HitObjects are grouped separately). Within each of these /// groups, it will attempt to order threads by the value of their coherence hints. And within ranges /// of equal coherence hints, it will attempt to maximize locality in 3D space of the ray hit (if any). + [__requiresNVAPI] -__glsl_extension(GL_NV_shader_invocation_reorder) __glsl_extension(GL_EXT_ray_tracing) +__glsl_extension(GL_NV_shader_invocation_reorder) +[require(glsl, ser)] +[require(spirv, ser)] +[require(hlsl, ser)] void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ) { __target_switch @@ -12066,7 +12856,10 @@ void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHi case hlsl: __intrinsic_asm "NvReorderThread"; case glsl: __intrinsic_asm "reorderThreadNV"; case spirv: - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpReorderThreadWithHitObjectNV &HitOrMiss $CoherenceHint $NumCoherenceHintBitsFromLSB; }; } @@ -12077,8 +12870,13 @@ void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHi /// void ReorderThread( HitObject HitOrMiss, uint CoherenceHint, uint NumCoherenceHintBitsFromLSB ); /// ``` /// With CoherenceHint and NumCoherenceHintBitsFromLSB as 0, meaning they are ignored. + [__requiresNVAPI] +__glsl_extension(GL_EXT_ray_tracing) __glsl_extension(GL_NV_shader_invocation_reorder) +[require(glsl, ser)] +[require(spirv, ser)] +[require(hlsl, ser)] void ReorderThread( HitObject HitOrMiss ) { __target_switch @@ -12086,13 +12884,15 @@ void ReorderThread( HitObject HitOrMiss ) case hlsl: __intrinsic_asm "NvReorderThread"; case glsl: __intrinsic_asm "reorderThreadNV"; case spirv: - spirv_asm { + spirv_asm + { + OpExtension "SPV_NV_shader_invocation_reorder"; + OpCapability ShaderInvocationReorderNV; OpReorderThreadWithHitObjectNV &HitOrMiss; }; } } - /// /// DebugBreak support /// diff --git a/source/slang/slang-ast-dump.cpp b/source/slang/slang-ast-dump.cpp index 3bb83f80b7..5576d94016 100644 --- a/source/slang/slang-ast-dump.cpp +++ b/source/slang/slang-ast-dump.cpp @@ -666,6 +666,14 @@ struct ASTDumpContext case SPIRVAsmOperand::SlangImmediateValue: m_writer->emit("!"); break; + case SPIRVAsmOperand::RayPayloadFromLocation: + m_writer->emit("__rayPayloadFromLocation"); + break; + case SPIRVAsmOperand::RayAttributeFromLocation: + m_writer->emit("__rayAttributeFromLocation"); + break; + case SPIRVAsmOperand::RayCallableFromLocation: + m_writer->emit("__rayCallableFromLocation"); case SPIRVAsmOperand::BuiltinVar: m_writer->emit("builtin"); break; diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index fa1b27a049..3331b288e0 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -682,6 +682,9 @@ class SPIRVAsmOperand BuiltinVar, GLSL450Set, NonSemanticDebugPrintfExtSet, + RayPayloadFromLocation, //insert from scope of all payloads in the spir-v shader the payload identified by the integer value provided + RayAttributeFromLocation, + RayCallableFromLocation, }; // The flavour and token describes how this was parsed diff --git a/source/slang/slang-ast-modifier.h b/source/slang/slang-ast-modifier.h index 32852496ce..5ab7eae3c9 100644 --- a/source/slang/slang-ast-modifier.h +++ b/source/slang/slang-ast-modifier.h @@ -901,7 +901,12 @@ class VulkanRayPayloadAttribute : public Attribute int location; }; +class VulkanRayPayloadInAttribute : public Attribute +{ + SLANG_AST_CLASS(VulkanRayPayloadInAttribute) + int location; +}; // A `[__vulkanCallablePayload(location)]` attribute, which is used in the // standard library implementation to indicate that a variable @@ -913,7 +918,12 @@ class VulkanCallablePayloadAttribute : public Attribute int location; }; +class VulkanCallablePayloadInAttribute : public Attribute +{ + SLANG_AST_CLASS(VulkanCallablePayloadInAttribute) + int location; +}; // A `[__vulkanHitAttributes]` attribute, which is used in the // standard library implementation to indicate that a variable diff --git a/source/slang/slang-capabilities.capdef b/source/slang/slang-capabilities.capdef index cf2cd5791c..b8d97d021c 100644 --- a/source/slang/slang-capabilities.capdef +++ b/source/slang/slang-capabilities.capdef @@ -180,10 +180,12 @@ def _GL_ARB_fragment_shader_interlock : glsl; def _GL_ARB_gpu_shader5 : glsl; def _GL_ARB_sparse_texture_clamp : glsl; def _GL_EXT_buffer_reference : glsl; +def _GL_EXT_buffer_reference_uvec2 : glsl; def _GL_EXT_debug_printf : glsl; def _GL_EXT_fragment_shader_barycentric : glsl; def _GL_EXT_mesh_shader : glsl; def _GL_EXT_nonuniform_qualifier : glsl; +def _GL_EXT_ray_query : glsl_spirv_1_4; def _GL_EXT_ray_tracing : glsl_spirv_1_4; def _GL_EXT_ray_tracing_position_fetch : glsl_spirv_1_4; def _GL_EXT_samplerless_texture_functions : glsl; @@ -214,10 +216,12 @@ alias GL_ARB_fragment_shader_interlock = _GL_ARB_fragment_shader_interlock | spv alias GL_ARB_gpu_shader5 = _GL_ARB_fragment_shader_interlock | spirv_1_0; alias GL_ARB_sparse_texture_clamp = _GL_ARB_fragment_shader_interlock | spirv_1_0; alias GL_EXT_buffer_reference = _GL_ARB_fragment_shader_interlock | spirv_1_5; +alias GL_EXT_buffer_reference_uvec2 = _GL_EXT_buffer_reference_uvec2 | spirv_1_0; alias GL_EXT_debug_printf = _GL_EXT_debug_printf | SPV_KHR_non_semantic_info; alias GL_EXT_fragment_shader_barycentric = _GL_EXT_fragment_shader_barycentric | spvFragmentBarycentricKHR; alias GL_EXT_mesh_shader = _GL_EXT_mesh_shader | spvMeshShadingEXT; alias GL_EXT_nonuniform_qualifier = _GL_EXT_nonuniform_qualifier | spvShaderNonUniform; +alias GL_EXT_ray_query = _GL_EXT_ray_query | spvRayTracingKHR + spvRayQueryKHR; alias GL_EXT_ray_tracing = _GL_EXT_ray_tracing | spvRayTracingKHR + spvRayQueryKHR; alias GL_EXT_ray_tracing_position_fetch = _GL_EXT_ray_tracing_position_fetch | spvRayTracingPositionFetchKHR + spvRayQueryPositionFetchKHR; alias GL_EXT_samplerless_texture_functions = _GL_EXT_samplerless_texture_functions | spirv_1_0; @@ -246,11 +250,16 @@ alias GL_NV_ray_tracing = GL_EXT_ray_tracing; // Define feature names alias nvapi = hlsl_nvapi; -alias raytracing = spvRayTracingKHR + spvRayQueryKHR + spvRayQueryPositionFetchKHR | _GL_EXT_ray_tracing+_GL_EXT_ray_tracing_position_fetch | _sm_6_5 | cuda; -alias ser = spvShaderInvocationReorderNV | _GL_NV_shader_invocation_reorder | _sm_6_6 + hlsl_nvapi; +alias raytracing = GL_EXT_ray_tracing | _sm_6_5 | cuda; +alias raytracing_pos = GL_EXT_ray_tracing + GL_EXT_ray_tracing_position_fetch | _sm_6_5 | cuda; +alias rayquery_pos = GL_EXT_ray_query + GL_EXT_ray_tracing_position_fetch | _sm_6_5 | cuda; +alias rayquery = GL_EXT_ray_query | _sm_6_5 | cuda; +alias ser = GL_EXT_buffer_reference_uvec2 + GL_NV_shader_invocation_reorder + GL_EXT_ray_tracing | _sm_6_6 + hlsl_nvapi; +alias ser_motion = GL_EXT_buffer_reference_uvec2 + GL_NV_shader_invocation_reorder + GL_EXT_ray_tracing + GL_NV_ray_tracing_motion_blur | _sm_6_6 + hlsl_nvapi; alias shaderclock = spvShaderClockKHR | hlsl_nvapi | _GL_EXT_shader_realtime_clock | cpp | cuda; alias meshshading = spvMeshShadingEXT | _sm_6_5 | _GL_EXT_mesh_shader; -alias motionblur = spvRayTracingMotionBlurNV | hlsl_nvapi | _GL_NV_ray_tracing_motion_blur; +alias raytracing_motionblur = GL_EXT_ray_tracing + GL_NV_ray_tracing_motion_blur | hlsl_nvapi + _sm_6_5; +alias motionblur = GL_NV_ray_tracing_motion_blur | hlsl_nvapi; alias texturefootprint = GL_NV_shader_texture_footprint | hlsl_nvapi; alias fragmentshaderinterlock = _GL_ARB_fragment_shader_interlock | hlsl_nvapi | spvFragmentShaderPixelInterlockEXT; alias atomic64 = GL_EXT_shader_atomic_int64 | _sm_6_6 | cpp | cuda; diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 995b5e888d..f238550fd1 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4319,7 +4319,10 @@ namespace Slang || operand.flavor == SPIRVAsmOperand::SlangImmediateValue || operand.flavor == SPIRVAsmOperand::SlangValueAddr || operand.flavor == SPIRVAsmOperand::ImageType - || operand.flavor == SPIRVAsmOperand::SampledImageType) + || operand.flavor == SPIRVAsmOperand::SampledImageType + || operand.flavor == SPIRVAsmOperand::RayPayloadFromLocation + || operand.flavor == SPIRVAsmOperand::RayAttributeFromLocation + || operand.flavor == SPIRVAsmOperand::RayCallableFromLocation) { // This is a $expr operand, check the expr operand.expr = dispatch(operand.expr); diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 28c1454981..cff5b70283 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -2437,6 +2437,12 @@ namespace Slang Expr* baseExpr, OverloadResolveContext& context); + template + void trySetGenericToRayTracingWithParamAttribute( + LookupResultItem genericItem, + DeclRef genericDeclRef, + OverloadResolveContext& context); + // Add overload candidates based on use of `genericDeclRef` // in an ordinary function-call context (that is, where it // has been applied to arguments using `()` and not `<>`). diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index eae993dc7c..17215d2842 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -707,6 +707,13 @@ namespace Slang rayPayloadAttr->location = (int32_t)val->getValue(); } + else if (auto rayPayloadInAttr = as(attr)) + { + SLANG_ASSERT(attr->args.getCount() == 1); + auto val = checkConstantIntVal(attr->args[0]); + if (!val) return false; + rayPayloadInAttr->location = (int32_t)val->getValue(); + } else if (auto callablePayloadAttr = as(attr)) { SLANG_ASSERT(attr->args.getCount() == 1); @@ -716,6 +723,13 @@ namespace Slang callablePayloadAttr->location = (int32_t)val->getValue(); } + else if (auto callablePayloadInAttr = as(attr)) + { + SLANG_ASSERT(attr->args.getCount() == 1); + auto val = checkConstantIntVal(attr->args[0]); + if (!val) return false; + callablePayloadInAttr->location = (int32_t)val->getValue(); + } else if (auto hitObjectAttributesAttr = as(attr)) { SLANG_ASSERT(attr->args.getCount() == 1); diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index 47c75ab0c8..db17c92a0d 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -531,6 +531,8 @@ DIAGNOSTIC(39999, Error, expectedIntegerConstantWrongType, "expected integer con DIAGNOSTIC(39999, Error, expectedIntegerConstantNotConstant, "expression does not evaluate to a compile-time constant") DIAGNOSTIC(39999, Error, expectedIntegerConstantNotLiteral, "could not extract value from integer constant") +DIAGNOSTIC(39999, Error, expectedRayTracingPayloadObjectAtLocationButMissing, "raytracing payload expected at location $0 but it is missing") + DIAGNOSTIC(39999, Error, noApplicableOverloadForNameWithArgs, "no overload for '$0' applicable to arguments of type $1") DIAGNOSTIC(39999, Error, noApplicableWithArgs, "no overload applicable to arguments of type $0") diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 2019bfa8c1..af53b545f1 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -4268,6 +4268,27 @@ void CLikeSourceEmitter::computeEmitActions(IRModule* module, List& } } + for (auto inst : module->getGlobalInsts()) + { + // After emitting all structure types we need to emit all raytracing objects to + // ensure they are emitted before the layout location is referenced, otherwise, + // this can be a compile error if layout is emitted after location is referenced + // this is required since in GLSL, it is likley in a programs life time a raytracing + // object will never be referenced by name + for (auto dec : inst->getDecorations()) + { + switch (dec->getOp()) + { + case kIROp_VulkanRayPayloadDecoration: + case kIROp_VulkanRayPayloadInDecoration: + case kIROp_VulkanHitObjectAttributesDecoration: + case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: + case kIROp_VulkanHitAttributesDecoration: + ensureGlobalInst(&ctx, inst, EmitAction::Level::Definition); + }; + } + } for(auto inst : module->getGlobalInsts()) { if( as(inst) ) diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index d37a6840be..7e5c84533f 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -2659,10 +2659,18 @@ void GLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl) prefix = toSlice("callableData"); locationValue = getIntVal(decoration->getOperand(0)); break; + case kIROp_VulkanCallablePayloadInDecoration: + prefix = toSlice("callableDataIn"); + locationValue = getIntVal(decoration->getOperand(0)); + break; case kIROp_VulkanRayPayloadDecoration: prefix = toSlice("rayPayload"); locationValue = getIntVal(decoration->getOperand(0)); break; + case kIROp_VulkanRayPayloadInDecoration: + prefix = toSlice("rayPayloadIn"); + locationValue = getIntVal(decoration->getOperand(0)); + break; case kIROp_VulkanHitObjectAttributesDecoration: prefix = toSlice("hitObjectAttribute"); postfix = toSlice("NV"); diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index cf1ca794bf..3d45394d36 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -3,6 +3,7 @@ #include "../core/slang-writer.h" +#include "slang-ir-util.h" #include "slang-emit-source-writer.h" #include "slang-mangled-lexer.h" @@ -987,7 +988,6 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_HLSLRWByteAddressBufferType: m_writer->emit("RWByteAddressBuffer"); break; case kIROp_HLSLRasterizerOrderedByteAddressBufferType: m_writer->emit("RasterizerOrderedByteAddressBuffer"); break; case kIROp_RaytracingAccelerationStructureType: m_writer->emit("RaytracingAccelerationStructure"); break; - default: SLANG_DIAGNOSE_UNEXPECTED(getSink(), SourceLoc(), "unhandled buffer type"); break; diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 79f3249886..afb1b3a630 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2956,6 +2956,7 @@ struct SPIRVEmitContext // We will continue to use the Slang terminology here, since // this code path is a catch-all for stuff that only needs to // be emitted if the owning instruction gets emitted. + bool isRayTracingObject = false; switch( decoration->getOp() ) { @@ -3225,13 +3226,25 @@ struct SPIRVEmitContext } break; + case kIROp_VulkanHitAttributesDecoration: case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: + ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_tracing")); + requireSPIRVCapability(SpvCapabilityRayTracingKHR); + isRayTracingObject = true; + break; case kIROp_VulkanHitObjectAttributesDecoration: + // needed since GLSL will not set optypes accordingly, but will keep the decoration + ensureExtensionDeclaration(UnownedStringSlice("SPV_NV_shader_invocation_reorder")); + requireSPIRVCapability(SpvCapabilityShaderInvocationReorderNV); + isRayTracingObject = true; + break; case kIROp_VulkanRayPayloadDecoration: - emitOpDecorateLocation(getSection(SpvLogicalSectionID::Annotations), - decoration, - dstID, - SpvLiteralInteger::from32(int32_t(getIntVal(decoration->getOperand(0))))); + case kIROp_VulkanRayPayloadInDecoration: + // needed since GLSL will not set optypes accordingly, but will keep the decoration + ensureExtensionDeclaration(UnownedStringSlice("SPV_KHR_ray_query")); + requireSPIRVCapability(SpvCapabilityRayQueryKHR); + isRayTracingObject = true; break; case kIROp_GloballyCoherentDecoration: emitOpDecorate(getSection(SpvLogicalSectionID::Annotations), @@ -3242,6 +3255,17 @@ struct SPIRVEmitContext // ... } + if(isRayTracingObject) + { + if (decoration->getOperandCount() > 0) { + //if not greater than 0, this is not a layout decoration (no val) + emitOpDecorateLocation(getSection(SpvLogicalSectionID::Annotations), + decoration, + dstID, + SpvLiteralInteger::from32(int32_t(getIntVal(decoration->getOperand(0))))); + } + } + if (shouldEmitSPIRVReflectionInfo()) { switch (decoration->getOp()) @@ -5823,7 +5847,7 @@ SlangResult emitSPIRVFromIR( SPIRVEmitContext context(irModule, codeGenContext->getTargetProgram(), sink); legalizeIRForSPIRV(&context, irModule, irEntryPoints, codeGenContext); - + #if 0 { DiagnosticSinkWriter writer(codeGenContext->getSink()); diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 43f54d04f3..ee38996e6c 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -17,6 +17,7 @@ #include "slang-ir-defunctionalization.h" #include "slang-ir-dll-export.h" #include "slang-ir-dll-import.h" +#include "slang-ir-early-raytracing-intrinsic-simplification.h" #include "slang-ir-eliminate-phis.h" #include "slang-ir-eliminate-multilevel-break.h" #include "slang-ir-entry-point-uniforms.h" @@ -242,7 +243,7 @@ Result linkAndOptimizeIR( // If the user specified the flag that they want us to dump // IR, then do it here, for the target-specific, but // un-specialized IR. - dumpIRIfEnabled(codeGenContext, irModule); + dumpIRIfEnabled(codeGenContext, irModule, "POST IR VALIDATION"); if(!isKhronosTarget(targetRequest)) lowerGLSLShaderStorageBufferObjectsToStructuredBuffers(irModule, sink); @@ -1038,6 +1039,9 @@ Result linkAndOptimizeIR( } } + replaceLocationIntrinsicsWithRaytracingObject(targetProgram, irModule, sink); + validateIRModuleIfEnabled(codeGenContext, irModule); + // Run a final round of simplifications to clean up unused things after phi-elimination. simplifyNonSSAIR(targetProgram, irModule, IRSimplificationOptions::getFast()); diff --git a/source/slang/slang-ir-early-raytracing-intrinsic-simplification.cpp b/source/slang/slang-ir-early-raytracing-intrinsic-simplification.cpp new file mode 100644 index 0000000000..01f49e1c9d --- /dev/null +++ b/source/slang/slang-ir-early-raytracing-intrinsic-simplification.cpp @@ -0,0 +1,169 @@ +// slang-ir-early-raytracing-intrinsic-simplification.cpp +#include "slang-ir-early-raytracing-intrinsic-simplification.h" +#include "slang-ir.h" +#include "../core/slang-performance-profiler.h" +#include "slang-ir-util.h" + +namespace Slang +{ + // ONLY should be used in this compilation unit + struct CacheOfDataToReplaceOps + { + TargetProgram* target; + IRModule* module; + DiagnosticSink* sink; + + Dictionary m_RayLocationToPayloads; + Dictionary m_RayLocationToAttributes; + Dictionary m_RayLocationToCallables; + + List funcsToSearch; + + IRInst* getRayVariableFromLocation(IRInst* payloadVariable, Slang::IROp op) + { + IRBuilder builder(payloadVariable); + IRInst** varLayoutPointsTo = nullptr; + int intLitValue = -1; + IRIntLit* intLit = as(payloadVariable); + if (intLit) + { + intLitValue = int(intLit->getValue()); + if (kIROp_SPIRVAsmOperandRayPayloadFromLocation == op) + { + varLayoutPointsTo = m_RayLocationToPayloads.tryGetValue(intLitValue); + } + else if (kIROp_SPIRVAsmOperandRayAttributeFromLocation == op) + { + varLayoutPointsTo = m_RayLocationToAttributes.tryGetValue(intLitValue); + } + else if (kIROp_SPIRVAsmOperandRayCallableFromLocation == op) + { + SLANG_ASSERT(kIROp_SPIRVAsmOperandRayCallableFromLocation == op); //final case + varLayoutPointsTo = m_RayLocationToCallables.tryGetValue(intLitValue); + } + } + else + { + sink->diagnose(payloadVariable, Diagnostics::expectedIntegerConstantNotConstant); + } + + IRInst* resultVariable; + if (!varLayoutPointsTo) + { + // if somehow the location tied variable is missing and an error was not thrown by the compiler + resultVariable = builder.getIntValue(builder.getIntType(), 0); + sink->diagnose(payloadVariable, Diagnostics::expectedRayTracingPayloadObjectAtLocationButMissing, intLitValue); + } + else + { + resultVariable = *varLayoutPointsTo; + } + return resultVariable; + } + + void searchForGlobalsDataNeededInPass() + { + if (target->getOptionSet().getBoolOption(CompilerOptionName::AllowGLSL)) + { + for (auto i : module->getGlobalInsts()) + { + switch(i->getOp()) + { + + case kIROp_GlobalParam: + case kIROp_GlobalVar: + { + for (auto decoration : i->getDecorations()) + { + auto op = decoration->getOp(); + if (op == kIROp_VulkanRayPayloadDecoration) + { + m_RayLocationToPayloads.set(int(getIntVal(decoration->getOperand(0))), i); + } + else if (op == kIROp_VulkanRayPayloadInDecoration) + { + m_RayLocationToPayloads.set(int(getIntVal(decoration->getOperand(0))), i); + } + else if (op == kIROp_VulkanHitObjectAttributesDecoration) + { + m_RayLocationToAttributes.set(int(getIntVal(decoration->getOperand(0))), i); + } + else if (op == kIROp_VulkanCallablePayloadDecoration) + { + m_RayLocationToCallables.set(int(getIntVal(decoration->getOperand(0))), i); + } + else if (op == kIROp_VulkanCallablePayloadInDecoration) + { + m_RayLocationToCallables.set(int(getIntVal(decoration->getOperand(0))), i); + } + } + break; + } + case kIROp_Func: + { + funcsToSearch.add(i); + break; + } + }; + } + } + } + + CacheOfDataToReplaceOps(TargetProgram* target, IRModule* module, DiagnosticSink* sink) + { + this->target = target; + this->module = module; + this->sink = sink; + } + }; + + void recurseInFuncForOpsToReplace(IRInst* parent, CacheOfDataToReplaceOps* cache) + { + + if (as(parent)) + { + for (auto i : parent->getChildren()) + { + switch (i->getOp()) + { + case kIROp_SPIRVAsmOperandRayPayloadFromLocation: + case kIROp_SPIRVAsmOperandRayAttributeFromLocation: + case kIROp_SPIRVAsmOperandRayCallableFromLocation: + { + auto op = i->getOperand(0); + IRInst* globalVar = cache->getRayVariableFromLocation(op, i->getOp()); + auto builder = IRBuilder(i); + builder.setInsertBefore(i); + auto spirvASM = builder.emitSPIRVAsmOperandInst(globalVar); + i->replaceUsesWith(spirvASM); + i->removeAndDeallocate(); + break; + } + }; + } + } + + for(auto i : parent->getChildren()) + recurseInFuncForOpsToReplace(i, cache); + } + + void recurseAllOpsToReplace(CacheOfDataToReplaceOps* cache) + { + for (auto func : cache->funcsToSearch) + { + recurseInFuncForOpsToReplace(func, cache); + } + } + + void replaceLocationIntrinsicsWithRaytracingObject(TargetProgram* target, IRModule* module, DiagnosticSink* sink) + { + //currently only applies to GLSL syntax + CacheOfDataToReplaceOps cache = CacheOfDataToReplaceOps(target, module, sink); + cache.searchForGlobalsDataNeededInPass(); + + if (target->getOptionSet().getBoolOption(CompilerOptionName::AllowGLSL)) + { + recurseAllOpsToReplace(&cache); + } + } +} diff --git a/source/slang/slang-ir-early-raytracing-intrinsic-simplification.h b/source/slang/slang-ir-early-raytracing-intrinsic-simplification.h new file mode 100644 index 0000000000..e2bdc7281d --- /dev/null +++ b/source/slang/slang-ir-early-raytracing-intrinsic-simplification.h @@ -0,0 +1,15 @@ +// slang-ir-early-raytracing-intrinsic-simplification.h +#pragma once + +#include "slang-ir.h" +#include "slang-ir-util.h" + +namespace Slang +{ + struct IRModule; + struct IRGlobalValueWithCode; + class DiagnosticSink; + class TargetProgram; + + void replaceLocationIntrinsicsWithRaytracingObject(TargetProgram* target, IRModule* module, DiagnosticSink* sink); +} \ No newline at end of file diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp index c9bc1339b6..f51ae72157 100644 --- a/source/slang/slang-ir-glsl-legalize.cpp +++ b/source/slang/slang-ir-glsl-legalize.cpp @@ -2730,46 +2730,108 @@ bool shouldUseOriginalEntryPointName(CodeGenContext* codeGenContext) return false; } +void getAllNullLocationRayObjectsAndUsedLocations( + IRModule* module, + List* nullRayObjects, + HashSet* rayPayload, + HashSet* callablePayload, + HashSet* hitObjectAttribute) +{ + for (auto inst : module->getGlobalInsts()) + { + auto instOp = inst->getOp(); + IRIntegerValue intLitVal = NULL; + if (instOp != kIROp_GlobalParam && instOp != kIROp_GlobalVar) continue; + for (auto decor : inst->getDecorations()) + { + switch (decor->getOp()) + { + case kIROp_VulkanRayPayloadDecoration: + case kIROp_VulkanRayPayloadInDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal == -1) { nullRayObjects->add(inst); goto getAllNullLocationRayObjectsAndUsedLocations_end; } + rayPayload->add(intLitVal); + goto getAllNullLocationRayObjectsAndUsedLocations_end; + case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal == -1) { nullRayObjects->add(inst); goto getAllNullLocationRayObjectsAndUsedLocations_end; } + callablePayload->add(intLitVal); + goto getAllNullLocationRayObjectsAndUsedLocations_end; + case kIROp_VulkanHitObjectAttributesDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal == -1) { nullRayObjects->add(inst); goto getAllNullLocationRayObjectsAndUsedLocations_end; } + hitObjectAttribute->add(intLitVal); + goto getAllNullLocationRayObjectsAndUsedLocations_end; + } + } + getAllNullLocationRayObjectsAndUsedLocations_end:; + } +} void assignRayPayloadHitObjectAttributeLocations(IRModule* module) { + List nullRayObjects; + HashSet rayPayloadLocations; + HashSet callablePayloadLocations; + HashSet hitObjectAttributeLocations; + getAllNullLocationRayObjectsAndUsedLocations(module, &nullRayObjects, &rayPayloadLocations, &callablePayloadLocations, &hitObjectAttributeLocations); + IRIntegerValue rayPayloadCounter = 0; IRIntegerValue callablePayloadCounter = 0; IRIntegerValue hitObjectAttributeCounter = 0; IRBuilder builder(module); - for (auto inst : module->getGlobalInsts()) + for (auto inst : nullRayObjects) { - auto globalVar = as(inst); - if (!globalVar) - continue; IRInst* location = nullptr; - for (auto decor : globalVar->getDecorations()) + IRIntegerValue intLitVal = NULL; + for (auto decor : inst->getDecorations()) { switch (decor->getOp()) { case kIROp_VulkanRayPayloadDecoration: + case kIROp_VulkanRayPayloadInDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal >= 0) goto assignRayPayloadHitObjectAttributeLocations_end; + while(rayPayloadLocations.contains(rayPayloadCounter)) + { + rayPayloadCounter++; + } builder.setInsertBefore(inst); location = builder.getIntValue(builder.getIntType(), rayPayloadCounter); decor->setOperand(0, location); rayPayloadCounter++; - goto end; + goto assignRayPayloadHitObjectAttributeLocations_end; case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal >= 0) goto assignRayPayloadHitObjectAttributeLocations_end; + while (callablePayloadLocations.contains(callablePayloadCounter)) + { + callablePayloadCounter++; + } builder.setInsertBefore(inst); location = builder.getIntValue(builder.getIntType(), callablePayloadCounter); decor->setOperand(0, location); callablePayloadCounter++; - goto end; + goto assignRayPayloadHitObjectAttributeLocations_end; case kIROp_VulkanHitObjectAttributesDecoration: + intLitVal = as(decor->getOperand(0))->getValue(); + if (intLitVal >= 0) goto assignRayPayloadHitObjectAttributeLocations_end; + while (hitObjectAttributeLocations.contains(hitObjectAttributeCounter)) + { + hitObjectAttributeCounter++; + } builder.setInsertBefore(inst); location = builder.getIntValue(builder.getIntType(), hitObjectAttributeCounter); decor->setOperand(0, location); hitObjectAttributeCounter++; - goto end; + goto assignRayPayloadHitObjectAttributeLocations_end; default: break; } } - end:; + assignRayPayloadHitObjectAttributeLocations_end:; } } diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index aa0929a57f..10df5d0d77 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -705,6 +705,7 @@ INST(HighLevelDeclDecoration, highLevelDecl, 1, 0) INST(TransitoryDecoration, transitory, 0, 0) INST(VulkanRayPayloadDecoration, vulkanRayPayload, 0, 0) + INST(VulkanRayPayloadInDecoration, vulkanRayPayloadIn, 0, 0) INST(VulkanHitAttributesDecoration, vulkanHitAttributes, 0, 0) INST(VulkanHitObjectAttributesDecoration, vulkanHitObjectAttributes, 0, 0) @@ -715,6 +716,7 @@ INST(HighLevelDeclDecoration, highLevelDecl, 1, 0) INST(ReadNoneDecoration, readNone, 0, 0) INST(VulkanCallablePayloadDecoration, vulkanCallablePayload, 0, 0) + INST(VulkanCallablePayloadInDecoration, vulkanCallablePayloadIn, 0, 0) INST(EarlyDepthStencilDecoration, earlyDepthStencil, 0, 0) INST(GloballyCoherentDecoration, globallyCoherent, 0, 0) INST(PreciseDecoration, precise, 0, 0) @@ -1148,7 +1150,11 @@ INST(SPIRVAsmInst, SPIRVAsmInst, 1, 0) // A reference to a slang IRInst, either a value or a type // This isn't hoistable, as we sometimes need to change the used value and // instructions around the specific asm block - INST(SPIRVAsmOperandInst, SPIRVAsmOperandInst, 1, 0) + INST(SPIRVAsmOperandInst, SPIRVAsmOperandInst, 1, 0) + //a late resolving type to handle the case of ray objects (resolving late due to constexpr data requirment) + INST(SPIRVAsmOperandRayPayloadFromLocation, SPIRVAsmOperandRayPayloadFromLocation, 1, 0) + INST(SPIRVAsmOperandRayAttributeFromLocation, SPIRVAsmOperandRayAttributeFromLocation, 1, 0) + INST(SPIRVAsmOperandRayCallableFromLocation, SPIRVAsmOperandRayCallableFromLocation, 1, 0) // A named enumerator, the value is stored as a constant operand // It may have a second operand, which if present is a type with which to // construct a constant id to pass, instead of a literal constant diff --git a/source/slang/slang-ir-insts.h b/source/slang/slang-ir-insts.h index 3ae9f04d75..b104baca76 100644 --- a/source/slang/slang-ir-insts.h +++ b/source/slang/slang-ir-insts.h @@ -280,11 +280,13 @@ bool isSimpleDecoration(IROp op); /// a vulkan ray payload, and should have a location assigned /// to it. IR_SIMPLE_DECORATION(VulkanRayPayloadDecoration) +IR_SIMPLE_DECORATION(VulkanRayPayloadInDecoration) /// A decoration that indicates that a variable represents /// a vulkan callable shader payload, and should have a location assigned /// to it. IR_SIMPLE_DECORATION(VulkanCallablePayloadDecoration) +IR_SIMPLE_DECORATION(VulkanCallablePayloadInDecoration) /// A decoration that indicates that a variable represents /// vulkan hit attributes, and should have a location assigned @@ -4167,6 +4169,10 @@ struct IRBuilder IRSPIRVAsmOperand* emitSPIRVAsmOperandLiteral(IRInst* literal); IRSPIRVAsmOperand* emitSPIRVAsmOperandInst(IRInst* inst); + IRSPIRVAsmOperand* createSPIRVAsmOperandInst(IRInst* inst); + IRSPIRVAsmOperand* emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst); + IRSPIRVAsmOperand* emitSPIRVAsmOperandRayAttributeFromLocation(IRInst* inst); + IRSPIRVAsmOperand* emitSPIRVAsmOperandRayCallableFromLocation(IRInst* inst); IRSPIRVAsmOperand* emitSPIRVAsmOperandId(IRInst* inst); IRSPIRVAsmOperand* emitSPIRVAsmOperandResult(); IRSPIRVAsmOperand* emitSPIRVAsmOperandEnum(IRInst* inst); @@ -4742,11 +4748,21 @@ struct IRBuilder addDecoration(inst, kIROp_VulkanRayPayloadDecoration, getIntValue(getIntType(), location)); } + void addVulkanRayPayloadInDecoration(IRInst* inst, int location) + { + addDecoration(inst, kIROp_VulkanRayPayloadInDecoration, getIntValue(getIntType(), location)); + } + void addVulkanCallablePayloadDecoration(IRInst* inst, int location) { addDecoration(inst, kIROp_VulkanCallablePayloadDecoration, getIntValue(getIntType(), location)); } + void addVulkanCallablePayloadInDecoration(IRInst* inst, int location) + { + addDecoration(inst, kIROp_VulkanCallablePayloadInDecoration, getIntValue(getIntType(), location)); + } + void addVulkanHitObjectAttributesDecoration(IRInst* inst, int location) { addDecoration(inst, kIROp_VulkanHitObjectAttributesDecoration, getIntValue(getIntType(), location)); diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index a74c0c8f20..177cf4e9d6 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -4,6 +4,7 @@ #include "slang-capability.h" #include "slang-ir.h" #include "slang-ir-insts.h" +#include "slang-legalize-types.h" #include "slang-mangle.h" #include "slang-ir-string-hash.h" #include "slang-ir-autodiff.h" diff --git a/source/slang/slang-ir-spirv-legalize.cpp b/source/slang/slang-ir-spirv-legalize.cpp index 4dde2a0357..a7c14242b3 100644 --- a/source/slang/slang-ir-spirv-legalize.cpp +++ b/source/slang/slang-ir-spirv-legalize.cpp @@ -832,9 +832,15 @@ struct SPIRVLegalizationContext : public SourceEmitterBase case kIROp_VulkanRayPayloadDecoration: storageClass = SpvStorageClassRayPayloadKHR; break; + case kIROp_VulkanRayPayloadInDecoration: + storageClass = SpvStorageClassIncomingRayPayloadKHR; + break; case kIROp_VulkanCallablePayloadDecoration: storageClass = SpvStorageClassCallableDataKHR; break; + case kIROp_VulkanCallablePayloadInDecoration: + storageClass = SpvStorageClassIncomingCallableDataKHR; + break; case kIROp_VulkanHitObjectAttributesDecoration: storageClass = SpvStorageClassHitObjectAttributeNV; break; diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index d66c8d0be8..2f059d3089 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -1093,7 +1093,9 @@ IRInst* getVulkanPayloadLocation(IRInst* payloadGlobalVar) switch (decor->getOp()) { case kIROp_VulkanRayPayloadDecoration: + case kIROp_VulkanRayPayloadInDecoration: case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: case kIROp_VulkanHitObjectAttributesDecoration: return decor->getOperand(0); default: diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index fdc10e774e..104735c3e4 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -74,8 +74,10 @@ namespace Slang case kIROp_TriangleInputPrimitiveTypeDecoration: case kIROp_UnsafeForceInlineEarlyDecoration: case kIROp_VulkanCallablePayloadDecoration: + case kIROp_VulkanCallablePayloadInDecoration: case kIROp_VulkanHitAttributesDecoration: case kIROp_VulkanRayPayloadDecoration: + case kIROp_VulkanRayPayloadInDecoration: case kIROp_VulkanHitObjectAttributesDecoration: { return true; @@ -5870,6 +5872,53 @@ namespace Slang return i; } + IRSPIRVAsmOperand* IRBuilder::createSPIRVAsmOperandInst(IRInst* inst) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + auto i = createInst( + this, + kIROp_SPIRVAsmOperandInst, + inst->getFullType(), + inst + ); + return i; + } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayPayloadFromLocation(IRInst* inst) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + auto i = createInst( + this, + kIROp_SPIRVAsmOperandRayPayloadFromLocation, + inst->getFullType(), + inst + ); + addInst(i); + return i; + } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayAttributeFromLocation(IRInst* inst) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + auto i = createInst( + this, + kIROp_SPIRVAsmOperandRayAttributeFromLocation, + inst->getFullType(), + inst + ); + addInst(i); + return i; + } + IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandRayCallableFromLocation(IRInst* inst) + { + SLANG_ASSERT(as(m_insertLoc.getParent())); + auto i = createInst( + this, + kIROp_SPIRVAsmOperandRayCallableFromLocation, + inst->getFullType(), + inst + ); + addInst(i); + return i; + } IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandId(IRInst* inst) { SLANG_ASSERT(as(m_insertLoc.getParent())); @@ -6892,6 +6941,21 @@ namespace Slang case kIROp_SPIRVAsmOperandInst: dumpInstExpr(context, inst->getOperand(0)); return; + case kIROp_SPIRVAsmOperandRayPayloadFromLocation: + dump(context, "__rayPayloadFromLocation("); + dumpInstExpr(context, inst->getOperand(0)); + dump(context, ")"); + return; + case kIROp_SPIRVAsmOperandRayAttributeFromLocation: + dump(context, "__rayAttributeFromLocation("); + dumpInstExpr(context, inst->getOperand(0)); + dump(context, ")"); + return; + case kIROp_SPIRVAsmOperandRayCallableFromLocation: + dump(context, "__rayCallableFromLocation("); + dumpInstExpr(context, inst->getOperand(0)); + dump(context, ")"); + return; case kIROp_SPIRVAsmOperandId: dump(context, "%"); dumpInstExpr(context, inst->getOperand(0)); diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h index f1c079cae2..eb77127c88 100644 --- a/source/slang/slang-ir.h +++ b/source/slang/slang-ir.h @@ -24,6 +24,7 @@ namespace Slang { class Decl; +class DiagnosticSink; class GenericDecl; class FuncType; class Layout; diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 6e6ba62552..4e564f7036 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -2141,18 +2141,38 @@ void addVarDecorations( else if(auto rayPayloadAttr = as(mod)) { builder->addVulkanRayPayloadDecoration(inst, rayPayloadAttr->location); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); + } + else if(auto rayPayloadInAttr = as(mod)) + { + builder->addVulkanRayPayloadInDecoration(inst, rayPayloadInAttr->location); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); } else if(auto callablePayloadAttr = as(mod)) { builder->addVulkanCallablePayloadDecoration(inst, callablePayloadAttr->location); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); + } + else if(auto callablePayloadInAttr = as(mod)) + { + builder->addVulkanCallablePayloadInDecoration(inst, callablePayloadInAttr->location); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); } else if (auto hitObjectAttr = as(mod)) { builder->addVulkanHitObjectAttributesDecoration(inst, hitObjectAttr->location); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); } else if (as(mod)) { builder->addSimpleDecoration(inst); + // may not be referenced; adding HLSL export modifier force emits + builder->addHLSLExportDecoration(inst); } else if(as(mod)) { @@ -4063,6 +4083,36 @@ struct ExprLoweringVisitorBase : public ExprVisitor { return builder->emitSPIRVAsmOperandEntryPoint(); } + case SPIRVAsmOperand::RayPayloadFromLocation: + { + IRInst* i; + { + IRBuilderInsertLocScope insertScope(builder); + builder->setInsertBefore(spirvAsmInst); + i = getSimpleVal(context, lowerRValueExpr(context, operand.expr)); + } + return builder->emitSPIRVAsmOperandRayPayloadFromLocation(i); + } + case SPIRVAsmOperand::RayAttributeFromLocation: + { + IRInst* i; + { + IRBuilderInsertLocScope insertScope(builder); + builder->setInsertBefore(spirvAsmInst); + i = getSimpleVal(context, lowerRValueExpr(context, operand.expr)); + } + return builder->emitSPIRVAsmOperandRayAttributeFromLocation(i); + } + case SPIRVAsmOperand::RayCallableFromLocation: + { + IRInst* i; + { + IRBuilderInsertLocScope insertScope(builder); + builder->setInsertBefore(spirvAsmInst); + i = getSimpleVal(context, lowerRValueExpr(context, operand.expr)); + } + return builder->emitSPIRVAsmOperandRayCallableFromLocation(i); + } } SLANG_UNREACHABLE("Unhandled case in visitSPIRVAsmExpr"); }; diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index cc87a3daae..e1dce57318 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -7102,6 +7102,30 @@ namespace Slang { return SPIRVAsmOperand{ SPIRVAsmOperand::NonSemanticDebugPrintfExtSet, parser->ReadToken() }; } + else if (AdvanceIf(parser, "__rayPayloadFromLocation")) + { + // reference a magic number to a layout(location) for late compiler resolution of rayPayload objects + parser->ReadToken(TokenType::LParent); + auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayPayloadFromLocation, Token{}, parseAtomicExpr(parser) }; + parser->ReadToken(TokenType::RParent); + return operand; + } + else if (AdvanceIf(parser, "__rayAttributeFromLocation")) + { + // works similar to __rayPayloadFromLocation + parser->ReadToken(TokenType::LParent); + auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayAttributeFromLocation, Token{}, parseAtomicExpr(parser) }; + parser->ReadToken(TokenType::RParent); + return operand; + } + else if (AdvanceIf(parser, "__rayCallableFromLocation")) + { + // works similar to __rayPayloadFromLocation + parser->ReadToken(TokenType::LParent); + auto operand = SPIRVAsmOperand{ SPIRVAsmOperand::RayCallableFromLocation, Token{}, parseAtomicExpr(parser) }; + parser->ReadToken(TokenType::RParent); + return operand; + } // A regular identifier else if(parser->LookAheadToken(TokenType::Identifier)) { @@ -7846,6 +7870,7 @@ namespace Slang #define CASE(key, type) if (nameText == #key) { modifier = parser->astBuilder->create(); } else CASE(push_constant, PushConstantAttribute) CASE(shaderRecordNV, ShaderRecordAttribute) + CASE(shaderRecordEXT, ShaderRecordAttribute) CASE(constant_id, GLSLConstantIDLayoutModifier) CASE(std140, GLSLStd140Modifier) CASE(std430, GLSLStd430Modifier) @@ -7893,6 +7918,20 @@ namespace Slang parser->ReadToken(TokenType::Comma); } +#define CASE(key, type) if (AdvanceIf(parser, #key)) { auto modifier = parser->astBuilder->create(); \ + modifier->location = int(getIntegerLiteralValue(listBuilder.find()->valToken)); listBuilder.add(modifier); } else + + CASE(rayPayloadEXT, VulkanRayPayloadAttribute) + CASE(rayPayloadNV, VulkanRayPayloadAttribute) + CASE(rayPayloadInEXT, VulkanRayPayloadInAttribute) + CASE(rayPayloadInNV, VulkanRayPayloadInAttribute) + CASE(hitObjectAttributeNV, VulkanHitObjectAttributesAttribute) + CASE(callableDataEXT, VulkanCallablePayloadAttribute) + CASE(callableDataInEXT, VulkanCallablePayloadInAttribute) + {} + +#undef CASE + if (numThreadsAttrib) { listBuilder.add(numThreadsAttrib); @@ -7903,6 +7942,12 @@ namespace Slang return listBuilder.getFirst(); } + static NodeBase* parseHitAttributeEXTModifier(Parser* parser, void* /*userData*/) + { + VulkanHitAttributesAttribute* modifier = parser->astBuilder->create(); + return modifier; + } + static NodeBase* parseBuiltinTypeModifier(Parser* parser, void* /*userData*/) { BuiltinTypeModifier* modifier = parser->astBuilder->create(); @@ -8131,7 +8176,7 @@ namespace Slang // or expect more tokens after the initial keyword. _makeParseModifier("layout", parseLayoutModifier), - + _makeParseModifier("hitAttributeEXT", parseHitAttributeEXTModifier), _makeParseModifier("__intrinsic_op", parseIntrinsicOpModifier), _makeParseModifier("__target_intrinsic", parseTargetIntrinsicModifier), _makeParseModifier("__specialized_for_target", parseSpecializedForTargetModifier), diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayAnyhit.slang b/tests/glsl-intrinsic/raytracing/glsl-rayAnyhit.slang new file mode 100644 index 0000000000..0ad09d64d9 --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayAnyhit.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage anyhit -entry main -target glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage anyhit -entry main -target spirv-assembly + +layout(binding = 0) uniform accelerationStructureEXT as; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +bool testVars() { + return true +// CHECK_GLSL-DAG: gl_HitTEXT +// CHECK_SPV-DAG: RayTmaxNV + && gl_HitTEXT != 99.0f +// CHECK_GLSL-DAG: gl_HitKindEXT +// CHECK_SPV-DAG: HitKindNV + && gl_HitKindEXT != 0xFFFFFFFF + ; +} + +void main() +{ + outputBuffer.data[0] = true + && testVars() + ; + //BUF: 1 +} diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayCompute.slang b/tests/glsl-intrinsic/raytracing/glsl-rayCompute.slang new file mode 100644 index 0000000000..7d49502718 --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayCompute.slang @@ -0,0 +1,106 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage compute -entry computeMain -target spirv-assembly + +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -allow-glsl -vk -compute -output-using-type -render-feature ray-query -entry computeMain +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -allow-glsl -vk -compute -output-using-type -render-feature ray-query -emit-spirv-directly -entry computeMain + +// note: the referenced input data is in render-test-main kVertexData; 1 triangle at {(0,0,0.5),(0,1,0.5),(1,0,0.5)} +//TEST_INPUT: set scene = AccelerationStructure +layout(binding = 0) uniform accelerationStructureEXT scene; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +__generic +bool equals(matrix lhs, matrix rhs) +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if ( + lhs[i][j] + != + rhs[i][j] + ) + { + return false; + } + } + } + return true; +} + +bool testAbortRayTrace() { + rayQueryEXT q; + rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f); + rayQueryTerminateEXT(q); + + return true + && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionNoneEXT + ; +} + +bool testProceedRayTrace() { + rayQueryEXT q; + rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f); + rayQueryProceedEXT(q); + + return true + && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionTriangleEXT + && rayQueryGetIntersectionTEXT(q, true) == 0.5 + ; +} + +bool testProceedRayAuxInfo() { + rayQueryEXT q; + rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f); + rayQueryProceedEXT(q); + + return true + && rayQueryGetRayTMinEXT(q) == 0.01f + && rayQueryGetRayFlagsEXT(q) == gl_RayFlagsNoneEXT + && rayQueryGetWorldRayOriginEXT(q) == vec3(0.1, 0.1, 0.0) + && rayQueryGetWorldRayDirectionEXT(q) == vec3(0, 0, 1) + && rayQueryGetIntersectionInstanceCustomIndexEXT(q, true) == 0 + && rayQueryGetIntersectionInstanceIdEXT(q, true) == 0 + && rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(q, true) == 0 + && rayQueryGetIntersectionGeometryIndexEXT(q, true) == 0 + && rayQueryGetIntersectionPrimitiveIndexEXT(q, true) == 0 + && rayQueryGetIntersectionBarycentricsEXT(q, true) == vec2(0.1) + && rayQueryGetIntersectionFrontFaceEXT(q, true) == true + && rayQueryGetIntersectionCandidateAABBOpaqueEXT(q) == true + && rayQueryGetIntersectionObjectRayDirectionEXT(q, true) == vec3(0, 0, 1) + && rayQueryGetIntersectionObjectRayOriginEXT(q, true) == vec3(0.1, 0.1, 0.0) + && !equals(rayQueryGetIntersectionObjectToWorldEXT(q, true), mat4x3(0)) // some compile error to sort later + && !equals(rayQueryGetIntersectionWorldToObjectEXT(q, true), mat4x3(0)) + ; +} +bool testRayTraceGenerate() { + rayQueryEXT q; + rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f); + rayQueryGenerateIntersectionEXT(q, 0.5); + rayQueryConfirmIntersectionEXT(q); + + return true + && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionTriangleEXT + ; +} + +// CHECK_GLSL-DAG: main +// CHECK_SPV-DAG: OpEntryPoint +layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; +void computeMain() +{ + outputBuffer.data[0] = true + && testAbortRayTrace() + //&& testProceedRayTrace() + //&& testProceedRayAuxInfo() + //&& testRayTraceGenerate() + ; + // BUF: 1 +} + diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayGen.slang b/tests/glsl-intrinsic/raytracing/glsl-rayGen.slang new file mode 100644 index 0000000000..ba4663f129 --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayGen.slang @@ -0,0 +1,333 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage raygeneration -entry main -target glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage raygeneration -entry main -target spirv-assembly + +layout(binding = 0) uniform accelerationStructureEXT as; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +// CHECK_GLSL-DAG: rayPayloadEXT +// CHECK_SPV-DAG: RayPayloadNV +layout(location = 2) rayPayloadEXT vec4 payload; +// CHECK_GLSL-DAG: hitObjectAttributeNV +// CHECK_SPV-DAG: HitObjectAttributeNV +layout(location = 2) hitObjectAttributeNV vec4 attrMain; +// CHECK_GLSL-DAG: callableDataEXT +// CHECK_SPV-DAG: CallableDataNV +layout(location = 0) callableDataEXT vec4 outcall; + +__generic +bool equals(matrix lhs, matrix rhs) +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if ( + lhs[i][j] + != + rhs[i][j] + ) + { + return false; + } + } + } + return true; +} + +bool testHitObjectTraceRay() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectTraceRayNV +// CHECK_SPV-DAG: OpHitObjectTraceRayNV + hitObjectTraceRayNV(hit, as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testHitObjectTraceRayWithAuxInfo() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectTraceRayNV +// CHECK_SPV-DAG: OpHitObjectTraceRayNV + hitObjectTraceRayNV(hit, as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); +// CHECK_GLSL-DAG: hitObjectGetAttributesNV +// CHECK_SPV-DAG: OpHitObjectGetAttributesNV + hitObjectGetAttributesNV(hit, 2); + vec4 testCopy = attrMain; + +// CHECK_GLSL-DAG: reorderThreadNV +// CHECK_SPV-DAG: OpReorderThreadWithHintNV + reorderThreadNV(0, 3); +// CHECK_GLSL-DAG: reorderThreadNV +// CHECK_SPV-DAG: OpReorderThreadWithHitObjectNV + reorderThreadNV(hit); +// CHECK_GLSL-DAG: reorderThreadNV +// CHECK_SPV-DAG: OpReorderThreadWithHitObjectNV + reorderThreadNV(hit, 0, 3); + + return true +// CHECK_GLSL-DAG: hitObjectGetShaderBindingTableRecordIndexNV +// CHECK_SPV-DAG: OpHitObjectGetShaderBindingTableRecordIndexNV + && hitObjectGetShaderBindingTableRecordIndexNV(hit) == 0 +// CHECK_GLSL-DAG: hitObjectGetShaderRecordBufferHandleNV +// CHECK_SPV-DAG: OpHitObjectGetShaderRecordBufferHandleNV + && hitObjectGetShaderRecordBufferHandleNV(hit) != uvec2(0) // valid Handles are never 0, but not predictable either + && testCopy == vec4(1) +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true +// CHECK_GLSL-DAG: hitObjectGetRayTMinNV +// CHECK_SPV-DAG: OpHitObjectGetRayTMinNV + && hitObjectGetRayTMinNV(hit) == 0.01f +// CHECK_GLSL-DAG: hitObjectGetRayTMaxNV +// CHECK_SPV-DAG: OpHitObjectGetRayTMaxNV + && hitObjectGetRayTMaxNV(hit) == 1e4f +// CHECK_GLSL-DAG: hitObjectGetObjectRayOriginNV +// CHECK_SPV-DAG: OpHitObjectGetObjectRayOriginNV + && hitObjectGetObjectRayOriginNV(hit) == vec3(0.1, 0.1, 0.0) +// CHECK_GLSL-DAG: hitObjectGetObjectRayDirectionNV +// CHECK_SPV-DAG: OpHitObjectGetObjectRayDirectionNV + && hitObjectGetObjectRayDirectionNV(hit) == vec3(0, 0, 1) +// CHECK_GLSL-DAG: hitObjectGetWorldRayOriginNV +// CHECK_SPV-DAG: OpHitObjectGetWorldRayOriginNV + && hitObjectGetWorldRayOriginNV(hit) == vec3(0.1, 0.1, 0.0) +// CHECK_GLSL-DAG: hitObjectGetWorldRayDirectionNV +// CHECK_SPV-DAG: OpHitObjectGetWorldRayDirectionNV + && hitObjectGetWorldRayDirectionNV(hit) == vec3(0, 0, 1) +// CHECK_GLSL-DAG: hitObjectGetObjectToWorldNV +// CHECK_SPV-DAG: OpHitObjectGetObjectToWorldNV + && !equals(hitObjectGetObjectToWorldNV(hit), mat4x3(0)) +// CHECK_GLSL-DAG: hitObjectGetWorldToObjectNV +// CHECK_SPV-DAG: OpHitObjectGetWorldToObjectNV + && !equals(hitObjectGetWorldToObjectNV(hit), mat4x3(0)) +// CHECK_GLSL-DAG: hitObjectGetInstanceCustomIndexNV +// CHECK_SPV-DAG: OpHitObjectGetInstanceCustomIndexNV + && hitObjectGetInstanceCustomIndexNV(hit) == 0 +// CHECK_GLSL-DAG: hitObjectGetInstanceIdNV +// CHECK_SPV-DAG: OpHitObjectGetInstanceIdNV + && hitObjectGetInstanceIdNV(hit) == 0 +// CHECK_GLSL-DAG: hitObjectGetGeometryIndexNV +// CHECK_SPV-DAG: OpHitObjectGetGeometryIndexNV + && hitObjectGetGeometryIndexNV(hit) == 0 +// CHECK_GLSL-DAG: hitObjectGetPrimitiveIndexNV +// CHECK_SPV-DAG: OpHitObjectGetPrimitiveIndexNV + && hitObjectGetPrimitiveIndexNV(hit) == 0 +// CHECK_GLSL-DAG: hitObjectGetHitKindNV +// CHECK_SPV-DAG: OpHitObjectGetHitKindNV + && hitObjectGetHitKindNV(hit) == gl_HitKindFrontFacingTriangleEXT + ; +} + +bool testHitObjectTraceRayLaunchSubShaders() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectTraceRayNV +// CHECK_SPV-DAG: OpHitObjectTraceRayNV + hitObjectTraceRayNV(hit, as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); +// CHECK_GLSL-DAG: hitObjectExecuteShaderNV +// CHECK_SPV-DAG: OpHitObjectExecuteShaderNV + hitObjectExecuteShaderNV(hit, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testHitObjectTraceRayMotion() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectTraceRayMotionNV +// CHECK_SPV-DAG: OpHitObjectTraceRayMotionNV + hitObjectTraceRayMotionNV(hit, as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 0.0f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true +// CHECK_GLSL-DAG: hitObjectGetCurrentTimeNV +// CHECK_SPV-DAG: OpHitObjectGetCurrentTimeNV + && hitObjectGetCurrentTimeNV(hit) == 0.0f + ; +} + +bool testTraceRayFunctions() { +// CHECK_GLSL-DAG: traceRayEXT +// CHECK_SPV-DAG: OpTraceRayKHR + traceRayEXT(as, 0, 0, 0, 0, 0, vec3(0), 0, vec3(0), 0, 2); + return true + ; +} + +bool testTraceRayCalls() { + return true + && testHitObjectTraceRay() + && testHitObjectTraceRayWithAuxInfo() + && testHitObjectTraceRayLaunchSubShaders() + && testHitObjectTraceRayMotion() + && testTraceRayFunctions() + ; +} + +bool testHitObjectRecord() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordHitNV +// CHECK_SPV-DAG: OpHitObjectRecordHitNV + hitObjectRecordHitNV(hit, as, 0, 0, 0, gl_HitKindFrontFacingTriangleEXT, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testHitObjectRecordIndex() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordHitWithIndexNV +// CHECK_SPV-DAG: OpHitObjectRecordHitWithIndexNV + hitObjectRecordHitWithIndexNV(hit, as, 0, 0, 0, gl_HitKindFrontFacingTriangleEXT, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testHitObjectRecordMotion() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordHitMotionNV +// CHECK_SPV-DAG: OpHitObjectRecordHitMotionNV + hitObjectRecordHitMotionNV(hit, as, 0, 0, 0, gl_HitKindFrontFacingTriangleEXT, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 0.0f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testHitObjectRecordIndexMotion() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordHitWithIndexMotionNV +// CHECK_SPV-DAG: OpHitObjectRecordHitWithIndexMotionNV + hitObjectRecordHitWithIndexMotionNV(hit, as, 0, 0, 0, gl_HitKindFrontFacingTriangleEXT, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 0.0f, 2); + return true +// CHECK_GLSL-DAG: hitObjectIsHitNV +// CHECK_SPV-DAG: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +bool testRecordHitCalls() { + return true + && testHitObjectRecord() + && testHitObjectRecordIndex() + && testHitObjectRecordMotion() + && testHitObjectRecordIndexMotion() + ; +} + +bool testHitObjectRecordMiss() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordMissNV +// CHECK_SPV-DAG: OpHitObjectRecordMissNV + hitObjectRecordMissNV(hit, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f); + return true +// CHECK_GLSL-DAG: hitObjectIsMissNV +// CHECK_SPV-DAG: OpHitObjectIsMissNV + && hitObjectIsMissNV(hit) == true + ; +} + +bool testHitObjectRecordMissMotion() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordMissMotionNV +// CHECK_SPV-DAG: OpHitObjectRecordMissMotionNV + hitObjectRecordMissMotionNV(hit, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 0.0f); + return true +// CHECK_GLSL-DAG: hitObjectIsMissNV +// CHECK_SPV-DAG: OpHitObjectIsMissNV + && hitObjectIsMissNV(hit) == true + ; +} + +bool testRecordMissCalls() { + return true + && testHitObjectRecordMiss() + && testHitObjectRecordMissMotion() + ; +} + +bool testHitObjectRecordEmpty() { + hitObjectNV hit; +// CHECK_GLSL-DAG: hitObjectRecordEmptyNV +// CHECK_SPV-DAG: OpHitObjectRecordEmptyNV + hitObjectRecordEmptyNV(hit); + return true +// CHECK_GLSL-DAG: hitObjectIsEmptyNV +// CHECK_SPV-DAG: OpHitObjectIsEmptyNV + && hitObjectIsEmptyNV(hit) == true + ; +} + +bool testRecordEmptyCalls() { + return true + && testHitObjectRecordEmpty() + ; +} + +bool testTraceRayMotion() { +// CHECK_GLSL-DAG: traceRayMotionNV +// CHECK_SPV-DAG: OpTraceRayMotionNV + traceRayMotionNV(as, gl_RayFlagsNoneEXT, 0xff, 0, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 0.0f, 2); + attrMain = vec4(1); //ensure traceRayMotionNV does not get optimized out + return true && + attrMain == vec4(1) + ; +} + +bool testPayloadReadWrite() { + payload = vec4(2); + vec4 read = payload; + return true + && read != vec4(0) + ; +} + +bool testAttributeReadWrite() { + attrMain = vec4(2); + vec4 read = attrMain; + return true + && read != vec4(0) + ; +} + +bool testCallableReadWrite() { + outcall = vec4(2); + vec4 read = outcall; + return true + && read != vec4(0) + ; +} + +bool testReadWriteOfObjects(){ + return true + && testPayloadReadWrite() + && testAttributeReadWrite() + && testCallableReadWrite(); + ; +} + +void main() +{ + outputBuffer.data[0] = true + && testTraceRayCalls() + && testRecordHitCalls() + && testRecordMissCalls() + && testRecordEmptyCalls() + && testTraceRayMotion() + && testReadWriteOfObjects(); + //BUF: 1 +} diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayGenSimple.slang b/tests/glsl-intrinsic/raytracing/glsl-rayGenSimple.slang new file mode 100644 index 0000000000..444384f52d --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayGenSimple.slang @@ -0,0 +1,34 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage raygeneration -entry main -target glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage raygeneration -entry main -target spirv-assembly + +// CHECK_GLSL-DAG: hitObjectAttributeNV +// CHECK_SPV-DAG: HitObjectAttributeNV + +layout(binding = 0) uniform accelerationStructureEXT as; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +layout(location = 2) hitObjectAttributeNV vec4 attrMain; + +bool testHitObjectRecord() { + hitObjectNV hit; + // CHECK_GLSL: hitObjectRecordHitNV + // CHECK_SPV: OpHitObjectRecordHitNV + hitObjectRecordHitNV(hit, as, 0, 0, 0, gl_HitKindFrontFacingTriangleEXT, 0, 0, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f, 2); + return true + // CHECK_GLSL: hitObjectIsHitNV + // CHECK_SPV: OpHitObjectIsHitNV + && hitObjectIsHitNV(hit) == true + ; +} + +void main() +{ + outputBuffer.data[0] = true + && testHitObjectRecord(); + //BUF: 1 +} diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayIntersection.slang b/tests/glsl-intrinsic/raytracing/glsl-rayIntersection.slang new file mode 100644 index 0000000000..92549e2d7b --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayIntersection.slang @@ -0,0 +1,87 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -stage intersection -entry main -target glsl -allow-glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -stage intersection -entry main -target spirv-assembly -emit-spirv-directly -allow-glsl + +layout(binding = 0) uniform accelerationStructureEXT as; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +//CHECK_GLSL-DAG: hitAttributeEXT +//CHECK_SPV-DAG: HitAttributeNV +hitAttributeEXT vec4 hitAttr; + +__generic +bool equals(matrix lhs, matrix rhs) +{ + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if ( + lhs[i][j] + != + rhs[i][j] + ) + { + return false; + } + } + } + return true; +} + +bool testVars() { + hitAttr = vec4(1); + + return true +// CHECK_GLSL-DAG: gl_PrimitiveID +// CHECK_SPV-DAG: PrimitiveId + && gl_PrimitiveID != 10000 +// CHECK_GLSL-DAG: gl_InstanceID +// CHECK_SPV-DAG: InstanceId + && gl_InstanceID != 10000 +// CHECK_GLSL-DAG: gl_InstanceCustomIndexEXT +// CHECK_SPV-DAG: InstanceCustomIndexNV + && gl_InstanceCustomIndexEXT != 10000 +// CHECK_GLSL-DAG: gl_GeometryIndexEXT +// CHECK_SPV-DAG: RayGeometryIndexKHR + && gl_GeometryIndexEXT != 10000 +// CHECK_GLSL-DAG: gl_ObjectRayOriginEXT +// CHECK_SPV-DAG: ObjectRayOriginNV + && gl_ObjectRayOriginEXT != vec3(99) +// CHECK_GLSL-DAG: gl_ObjectRayDirectionEXT +// CHECK_SPV-DAG: ObjectRayDirectionNV + && gl_ObjectRayDirectionEXT != vec3(99) +// CHECK_GLSL-DAG: gl_ObjectToWorldEXT +//COM: CHECK_SPV-DAG: ObjectToWorldNV + && !equals(gl_ObjectToWorldEXT, mat4x3(0.0f)) +// CHECK_GLSL-DAG: gl_ObjectToWorld3x4EXT +//COM: CHECK_SPV-DAG: ObjectToWorldNV + && !equals(gl_ObjectToWorld3x4EXT, mat3x4(0.0f)) +// CHECK_GLSL-DAG: gl_WorldToObjectEXT +// CHECK_SPV-DAG-N: WorldToObjectNV + && !equals(gl_WorldToObjectEXT, mat4x3(0.0f)) +// CHECK_GLSL-DAG: gl_WorldToObject3x4EXT +// spirv checked with CHECK_SPV-DAG-N + && !equals(gl_WorldToObject3x4EXT, mat3x4(0.0f)) + ; +} + +bool testFunctions() { + return true +// CHECK_GLSL-DAG: reportIntersectionEXT +// CHECK_SPV-DAG: OpReportIntersectionKHR + && reportIntersectionEXT(99, 0); +} + +void main() +{ + outputBuffer.data[0] = true + && testVars() + && testFunctions(); + ; + //BUF: 1 +} diff --git a/tests/glsl-intrinsic/raytracing/glsl-rayMiss.slang b/tests/glsl-intrinsic/raytracing/glsl-rayMiss.slang new file mode 100644 index 0000000000..714b214e1c --- /dev/null +++ b/tests/glsl-intrinsic/raytracing/glsl-rayMiss.slang @@ -0,0 +1,62 @@ +//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage miss -entry main -target glsl +//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage miss -entry main -target spirv-assembly + +layout(binding = 0) uniform accelerationStructureEXT as; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +buffer MyBlockName +{ + uint data[]; +} outputBuffer; + +// CHECK_GLSL-DAG: rayPayloadInEXT +// CHECK_SPV-DAG: IncomingRayPayloadNV +layout(location = 2) rayPayloadInEXT vec4 payload; +// CHECK_GLSL-DAG: hitObjectAttributeNV +// CHECK_SPV-DAG: HitObjectAttributeNV +layout(location = 2) hitObjectAttributeNV vec4 attrMain; + +bool testVars() { + payload = vec4(1); + attrMain = vec4(1); + return true +// CHECK_GLSL-DAG: gl_LaunchIDNV +// CHECK_SPV-DAG-N: LaunchIdNV + && gl_LaunchIDNV != uint3(99) +// CHECK_GLSL-DAG: gl_LaunchIDEXT +// spirv checked with CHECK_SPV-DAG-N + && gl_LaunchIDEXT != uint3(99) +// CHECK_GLSL-DAG: gl_LaunchSizeNV +// CHECK_SPV-DAG-N: LaunchSizeNV + && gl_LaunchSizeNV != uint3(99) +// CHECK_GLSL-DAG: gl_LaunchSizeEXT +// spirv checked with CHECK_SPV-DAG-N + && gl_LaunchSizeEXT != uint3(99) +// CHECK_GLSL-DAG: gl_WorldRayOriginEXT +// CHECK_SPV-DAG: WorldRayOriginNV + && gl_WorldRayOriginEXT != vec3(99) +// CHECK_GLSL-DAG: gl_WorldRayDirectionEXT +// CHECK_SPV-DAG: WorldRayDirectionNV + && gl_WorldRayDirectionEXT != vec3(99) +// CHECK_GLSL-DAG: gl_RayTminEXT +// CHECK_SPV-DAG: RayTminNV + && gl_RayTminEXT != 99.0f +// CHECK_GLSL-DAG: gl_RayTmaxEXT +// CHECK_SPV-DAG: RayTmaxNV + && gl_RayTmaxEXT != 99.0f +// CHECK_GLSL-DAG: gl_IncomingRayFlagsEXT +// CHECK_SPV-DAG: IncomingRayFlagsNV + && gl_IncomingRayFlagsEXT != 0xFFFFFFFF +// CHECK_GLSL-DAG: gl_CurrentRayTimeNV +// CHECK_SPV-DAG: CurrentRayTimeNV + && gl_CurrentRayTimeNV != 0.0f + ; +} + +void main() +{ + outputBuffer.data[0] = true + && testVars() + ; + //BUF: 1 +} diff --git a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-array.slang.expected b/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-array.slang.expected deleted file mode 100644 index fdc5cf0d7e..0000000000 --- a/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-array.slang.expected +++ /dev/null @@ -1,439 +0,0 @@ -result code = 0 -standard error = { -} -standard output = { -; -; Note: shader requires additional functionality: -; UAVs at every shader stage -; -; shader hash: 1376fe501fef02e2587aacc2b18e252f -; -; Buffer Definitions: -; -; Resource bind info for g_NvidiaExt -; { -; -; struct struct.NvShaderExtnStruct -; { -; -; uint opcode; ; Offset: 0 -; uint rid; ; Offset: 4 -; uint sid; ; Offset: 8 -; uint4 dst1u; ; Offset: 12 -; uint4 src3u; ; Offset: 28 -; uint4 src4u; ; Offset: 44 -; uint4 src5u; ; Offset: 60 -; uint4 src0u; ; Offset: 76 -; uint4 src1u; ; Offset: 92 -; uint4 src2u; ; Offset: 108 -; uint4 dst0u; ; Offset: 124 -; uint markUavRef; ; Offset: 140 -; uint numOutputsForIncCounter; ; Offset: 144 -; float padding1[27]; ; Offset: 148 -; -; } $Element; ; Offset: 0 Size: 256 -; -; } -; -; Resource bind info for outputBuffer_0 -; { -; -; uint $Element; ; Offset: 0 Size: 4 -; -; } -; -; -; Resource Bindings: -; -; Name Type Format Dim ID HLSL Bind Count -; ------------------------------ ---------- ------- ----------- ------- -------------- ------ -; scene_0 texture i32 ras T0 t0 1 -; g_NvidiaExt UAV struct r/w+cnt U0 u0 1 -; outputBuffer_0 UAV struct r/w U1 u1 1 -; -target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64" -target triple = "dxil-ms-dx" - -%"class.RWStructuredBuffer" = type { %struct.NvShaderExtnStruct } -%struct.NvShaderExtnStruct = type { i32, i32, i32, <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>, <4 x i32>, i32, i32, [27 x float] } -%struct.RaytracingAccelerationStructure = type { i32 } -%"class.RWStructuredBuffer" = type { i32 } -%struct.SomeValues_0 = type { i32, float } -%struct.NvHitObjectMacroDummyPayloadType = type { i32 } -%dx.types.Handle = type { i8* } - -@"\01?g_NvidiaExt@@3V?$RWStructuredBuffer@UNvShaderExtnStruct@@@@A" = external constant %"class.RWStructuredBuffer", align 4 -@"\01?scene_0@@3URaytracingAccelerationStructure@@A" = external constant %struct.RaytracingAccelerationStructure, align 4 -@"\01?outputBuffer_0@@3V?$RWStructuredBuffer@I@@A" = external constant %"class.RWStructuredBuffer", align 4 - -; Function Attrs: nounwind -define void @"\01?rayGenerationMain@@YAXXZ"() #0 { - %1 = load %struct.RaytracingAccelerationStructure, %struct.RaytracingAccelerationStructure* @"\01?scene_0@@3URaytracingAccelerationStructure@@A", align 4, !noalias !18 - %2 = load %"class.RWStructuredBuffer", %"class.RWStructuredBuffer"* @"\01?outputBuffer_0@@3V?$RWStructuredBuffer@I@@A", align 4 - %3 = load %"class.RWStructuredBuffer", %"class.RWStructuredBuffer"* @"\01?g_NvidiaExt@@3V?$RWStructuredBuffer@UNvShaderExtnStruct@@@@A", align 4, !noalias !21 - %4 = alloca %struct.SomeValues_0, align 8 - %5 = alloca %struct.SomeValues_0, align 8 - %6 = alloca %struct.SomeValues_0, align 8 - %7 = alloca %struct.NvHitObjectMacroDummyPayloadType, align 4 - %8 = alloca %struct.SomeValues_0, align 8 - %9 = alloca %struct.NvHitObjectMacroDummyPayloadType, align 4 - %10 = call i32 @dx.op.dispatchRaysIndex.i32(i32 145, i8 0) ; DispatchRaysIndex(col) - %11 = sitofp i32 %10 to float - %12 = fmul fast float %11, 2.000000e+00 - %13 = sitofp i32 %10 to float - %14 = mul nsw i32 %10, 3 - %15 = shl nsw i32 %10, 1 - %16 = getelementptr inbounds %struct.SomeValues_0, %struct.SomeValues_0* %8, i32 0, i32 0 - store i32 %10, i32* %16, align 8 - %17 = getelementptr inbounds %struct.SomeValues_0, %struct.SomeValues_0* %8, i32 0, i32 1 - store float %12, float* %17, align 4 - %18 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %19 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %18, i8 1) ; BufferUpdateCounter(uav,inc) - %20 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %20, i32 %19, i32 0, i32 69, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %21 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %21, i32 %19, i32 144, i32 2, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %22 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %22, i32 %19, i32 76, i32 %10, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %23 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %23, i32 %19, i32 80, i32 %15, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %24 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %24, i32 %19, i32 84, i32 %14, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %25 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %25, i32 %19, i32 88, i32 0, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %26 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %26, i32 %19, i32 92, i32 0, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %27 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %28 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %27, i8 1) ; BufferUpdateCounter(uav,inc) - %29 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %30 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %29, i8 1) ; BufferUpdateCounter(uav,inc) - call void @dx.op.callShader.struct.SomeValues_0(i32 159, i32 %30, %struct.SomeValues_0* nonnull %8) ; CallShader(ShaderIndex,Parameter) - %31 = call %dx.types.Handle @dx.op.createHandleForLib.struct.RaytracingAccelerationStructure(i32 160, %struct.RaytracingAccelerationStructure %1) ; CreateHandleForLib(Resource) - call void @dx.op.traceRay.struct.NvHitObjectMacroDummyPayloadType(i32 157, %dx.types.Handle %31, i32 0, i32 0, i32 0, i32 0, i32 %30, float %13, float 0.000000e+00, float 0.000000e+00, float 0x3F847AE140000000, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+04, %struct.NvHitObjectMacroDummyPayloadType* nonnull %9) ; TraceRay(AccelerationStructure,RayFlags,InstanceInclusionMask,RayContributionToHitGroupIndex,MultiplierForGeometryContributionToShaderIndex,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) - %32 = mul nsw i32 %10, 3 - %33 = shl nsw i32 %10, 1 - %34 = getelementptr inbounds %struct.SomeValues_0, %struct.SomeValues_0* %6, i32 0, i32 0 - store i32 %10, i32* %34, align 8 - %35 = getelementptr inbounds %struct.SomeValues_0, %struct.SomeValues_0* %6, i32 0, i32 1 - store float %12, float* %35, align 4 - %36 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %37 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %36, i8 1) ; BufferUpdateCounter(uav,inc) - %38 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %38, i32 %37, i32 0, i32 68, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %39 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %39, i32 %37, i32 144, i32 2, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %40 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %40, i32 %37, i32 76, i32 %10, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %41 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %41, i32 %37, i32 80, i32 %33, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %42 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %42, i32 %37, i32 84, i32 %32, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %43 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %43, i32 %37, i32 88, i32 0, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %44 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %44, i32 %37, i32 92, i32 0, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %45 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %45, i32 %37, i32 96, i32 4, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %46 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %47 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %46, i8 1) ; BufferUpdateCounter(uav,inc) - %48 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %49 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %48, i8 1) ; BufferUpdateCounter(uav,inc) - call void @dx.op.callShader.struct.SomeValues_0(i32 159, i32 %49, %struct.SomeValues_0* nonnull %6) ; CallShader(ShaderIndex,Parameter) - %50 = call %dx.types.Handle @dx.op.createHandleForLib.struct.RaytracingAccelerationStructure(i32 160, %struct.RaytracingAccelerationStructure %1) ; CreateHandleForLib(Resource) - call void @dx.op.traceRay.struct.NvHitObjectMacroDummyPayloadType(i32 157, %dx.types.Handle %50, i32 0, i32 0, i32 0, i32 0, i32 %49, float %13, float 0.000000e+00, float 0.000000e+00, float 0x3F847AE140000000, float 0.000000e+00, float 1.000000e+00, float 0.000000e+00, float 1.000000e+04, %struct.NvHitObjectMacroDummyPayloadType* nonnull %7) ; TraceRay(AccelerationStructure,RayFlags,InstanceInclusionMask,RayContributionToHitGroupIndex,MultiplierForGeometryContributionToShaderIndex,MissShaderIndex,Origin_X,Origin_Y,Origin_Z,TMin,Direction_X,Direction_Y,Direction_Z,TMax,payload) - %51 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %52 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %51, i8 1) ; BufferUpdateCounter(uav,inc) - %53 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %53, i32 %52, i32 0, i32 83, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %54 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - call void @dx.op.rawBufferStore.i32(i32 140, %dx.types.Handle %54, i32 %52, i32 76, i32 %28, i32 undef, i32 undef, i32 undef, i8 1, i32 4) ; RawBufferStore(uav,index,elementOffset,value0,value1,value2,value3,mask,alignment) - %55 = call %dx.types.Handle @"dx.op.createHandleForLib.class.RWStructuredBuffer"(i32 160, %"class.RWStructuredBuffer" %3) ; CreateHandleForLib(Resource) - %56 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %55, i8 1) ; BufferUpdateCounter(uav,inc) - %57 = icmp eq i32 %56, 0 - br i1 %57, label %130, label %58 - -;