diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2021-02-12 13:48:11 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-12 13:48:11 -0800 |
| commit | e2096cf81dab8f77ff5aa9b0c3fcf6a81a81dc4a (patch) | |
| tree | cbd9515e130833ff0189212544c0da6ee9f3617e /source/slang/slang-parser.cpp | |
| parent | 0dea127d94b1fd06e3a4516803c6641700af5cc8 (diff) | |
Initial support for DXR payload access qualifiers (#1705)
This change adds initial support for a feature being proposed for inclusion in dxc: https://github.com/microsoft/DirectXShaderCompiler/pull/3171.
The main features are:
* A `[payload]` attribute that indicates which `struct` types are intended to be used as payloads. Consistent use of this attribute should mean that an application no longer needs to manually specify a maximum payload size when creating a ray-tracing pipeline.
* `read(...)` and `write(...)` qualifiers which can be attached to fields of `struct` types (usually `[payload]`-attributed types) to indicate which ray tracing pipeline stages are allowed read/write access to that part of the payload. Use of these qualifiers should allow an implementation to optimize storage of ray payload elements across RT pipeline stages.
The work in this change just adds basic parsing for these features, translation to matching IR decorations, and then emission of HLSL text based on those decorations.
Notable gaps in this first change include:
* No work is currently being done to validate access to ray payloads in RT entry points based on these qualifiers.
* The stage names in `read(...)` and `write(...)` are not being validated, and are being stored in the IR as text. These should probably use the `Stage` enumeration in some fashion, but we would need to have a way to encode the additional `caller` pseudo-stage that the feature uses.
* No work is currently being done to adjust or react to the chosen shader model when emitting HLSL code. We should *either* have these attributes force a switch to a higher shader model, *or* skip emission of these attributes if the chosen shader model / profile does not imply support for them.
* No tests are currently included for this work, because tests would rely on using a custom `dxcompiler.dll` build with the new feature supported.
Diffstat (limited to 'source/slang/slang-parser.cpp')
| -rw-r--r-- | source/slang/slang-parser.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 8ea51645a..68d06714d 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -2202,6 +2202,40 @@ namespace Slang parser->sink->diagnose(semantic, Diagnostics::packOffsetNotSupported); } + static RayPayloadAccessSemantic* _parseRayPayloadAccessSemantic(Parser* parser, RayPayloadAccessSemantic* semantic) + { + parser->FillPosition(semantic); + + // Read the keyword that introduced the semantic + semantic->name = parser->ReadToken(TokenType::Identifier); + + parser->ReadToken(TokenType::LParent); + + for(;;) + { + if(AdvanceIfMatch(parser, TokenType::RParent)) + break; + + auto stageName = parser->ReadToken(TokenType::Identifier); + semantic->stageNameTokens.add(stageName); + + if(AdvanceIfMatch(parser, TokenType::RParent)) + break; + + expect(parser, TokenType::Comma); + } + + return semantic; + } + + template<typename T> + static T* _parseRayPayloadAccessSemantic(Parser* parser) + { + T* semantic = parser->astBuilder->create<T>(); + _parseRayPayloadAccessSemantic(parser, semantic); + return semantic; + } + // // semantic ::= identifier ( '(' args ')' )? // @@ -2222,6 +2256,14 @@ namespace Slang parseHLSLPackOffsetSemantic(parser, semantic); return semantic; } + else if( parser->LookAheadToken("read") && parser->LookAheadToken(TokenType::LParent, 1) ) + { + return _parseRayPayloadAccessSemantic<RayPayloadReadSemantic>(parser); + } + else if( parser->LookAheadToken("write") && parser->LookAheadToken(TokenType::LParent, 1) ) + { + return _parseRayPayloadAccessSemantic<RayPayloadWriteSemantic>(parser); + } else if (parser->LookAheadToken(TokenType::Identifier)) { HLSLSimpleSemantic* semantic = parser->astBuilder->create<HLSLSimpleSemantic>(); @@ -3414,6 +3456,21 @@ namespace Slang FillPosition(rs); ReadToken("struct"); + // The `struct` keyword may optionally be followed by + // attributes that appertain to the struct declaration + // itself, and not to any variables declared using this + // type specifier. + // + // TODO: We don't yet correctly associate attributes with + // a variable decarlation vs. a struct type when a variable + // is declared with a struct type specified. + // + if(LookAheadToken(TokenType::LBracket)) + { + Modifier** modifierLink = &rs->modifiers.first; + ParseSquareBracketAttributes(this, &modifierLink); + } + // TODO: support `struct` declaration without tag rs->nameAndLoc = expectIdentifier(this); |
