From ce87ab925d06a784eec194081e00a1b4c9b94d0c Mon Sep 17 00:00:00 2001 From: "Harsh Aggarwal (NVIDIA)" Date: Mon, 7 Apr 2025 13:26:11 +0530 Subject: Support for Payload Access Qualifiers (#3448) (#6595) * Add support for Ray Payload Access Qualifiers (PAQs) (#3448) - Added [raypayload] attribute for struct declarations - Implemented field validation requiring read/write access qualifiers - Added diagnostic error for missing qualifiers - Enabled PAQs in DXC compiler and HLSL emission - Added new test demonstrating PAQ syntax - Implemented proper handling of ray payload attributes in IR generation * format code * Cleanup: Remove unused vars * Add check to enablePAQ only for profile >= lib_6_7 * Review Fix - Add PAQ support for DX Raytracing add enablePAQ flag to DownstreamCompileOpitons, improve PAQ handling update raypayload-attribute-paq.slang to ensure hlsl and dxil is validated * Add diagnostic test for missing paq for lib_6_7 Compile using `-disable-payload-qualifiers` aka lib_6_6 profile raypayload-attribute-no-struct.slang and raypayload-attribute.slang --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska --- source/slang/slang-check-modifier.cpp | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'source/slang/slang-check-modifier.cpp') diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp index 741823a65..d94c77d6a 100644 --- a/source/slang/slang-check-modifier.cpp +++ b/source/slang/slang-check-modifier.cpp @@ -1413,9 +1413,20 @@ bool isModifierAllowedOnDecl(bool isGLSLInput, ASTNodeType modifierType, Decl* d case ASTNodeType::ConstRefModifier: case ASTNodeType::GLSLBufferModifier: case ASTNodeType::GLSLPatchModifier: + return (as(decl) && isGlobalDecl(decl)) || as(decl) || + as(decl); case ASTNodeType::RayPayloadAccessSemantic: case ASTNodeType::RayPayloadReadSemantic: case ASTNodeType::RayPayloadWriteSemantic: + // Allow on struct fields if the parent struct has the [raypayload] attribute + if (auto varDecl = as(decl)) + { + if (auto structDecl = as(varDecl->parentDecl)) + { + if (structDecl->findModifier()) + return true; + } + } return (as(decl) && isGlobalDecl(decl)) || as(decl) || as(decl); @@ -2179,5 +2190,36 @@ void SemanticsVisitor::checkModifiers(ModifiableSyntaxNode* syntaxNode) postProcessingOnModifiers(syntaxNode->modifiers); } +void SemanticsVisitor::checkRayPayloadStructFields(StructDecl* structDecl) +{ + // Only check structs with the [raypayload] attribute + if (!structDecl->findModifier()) + { + return; + } + + // Check each field in the struct + for (auto member : structDecl->members) + { + auto fieldVarDecl = as(member); + if (!fieldVarDecl) + { + continue; + } + + bool hasReadModifier = fieldVarDecl->findModifier() != nullptr; + bool hasWriteModifier = fieldVarDecl->findModifier() != nullptr; + + if (!hasReadModifier && !hasWriteModifier) + { + // Emit the diagnostic error + getSink()->diagnose( + fieldVarDecl, + Diagnostics::rayPayloadFieldMissingAccessQualifiers, + fieldVarDecl->getName()); + } + } +} + } // namespace Slang -- cgit v1.2.3