From 9b434e50f02f9ec02ce230de9042ce7448bae451 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Fri, 15 Mar 2024 16:14:32 -0400 Subject: Implement raytracing extension(s); resolves #3560 for GLSL & SPIR-V targets (#3675) The following PR implements raytracing extensions (GLSL_EXT_ray_tracing, GLSL_EXT_ray_query, GLSL_NV_shader_invocation_reorder & GLSL_NV_ray_tracing_motion_blur); for GLSL & SPIR-V targets. Fully implements all functions, built-in variables, & syntax; resolves #3560 for GLSL & SPIR-V Targets. notes of worth: * __rayPayloadFromLocation, __rayAttributeFromLocation, and __rayCallableFromLocation, were added as SPIR-V Intrinsics to refer to location's of raytracing objects in SPIR-V for when using GLSL syntax. --- source/slang/slang-emit-spirv.cpp | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-emit-spirv.cpp') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 79f324988..afb1b3a63 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()); -- cgit v1.2.3