diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2019-03-01 09:43:47 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-01 09:43:47 -0800 |
| commit | 620af1c60a2e84bbbc0e74f11cb9bc6a6976d9e4 (patch) | |
| tree | bba1e1d60c950f71506dd235ecc3309e6aa4880f /source/slang/compiler.h | |
| parent | efca2bb38700847adb2385d311b8b801376659bb (diff) | |
Move enumeration of shader parameters to Program/EntryPoint (#870)
There's a certain amount of logic in `parameter-binding.cpp` that just has to do with the basic problem of enumerating the shader parameters of a `Program`. The main source of complexity is that for legacy/compatibility reasons we need to consider two shader parameters with the same name as being the "same" parameter for layout purposes, and then we need to do a bunch of validation to ensure that these parameters have compatible types.
The biggest part of this change is moving that logic to `Program`, so that it builds up a list of its shader parameters during the front-end work, so that any errors related to bad redeclarations will now come up even if we aren't generated target-specific layouts/code.
All of the code for `getReflectionName`, `StructuralTypeMatchStack`, etc. is pretty much copy-pasted from `parameter-binding.cpp` over to `check.cpp`, with the `ParameterBindingContext` replaced with a `DiagnosticSink`.
The `Program::_collectShaderParameters` function (renamed from `_collectExistentialParams`) then deals with the enumeration and deduplication logic that used to happen in `collectGlobalScopeParameters()`.
The new declarations in `compiler.h` reveal the underlying reason for this change: by letting `Program` and `EntryPoint` handle the canonical enumeration of parameters, we can associate each parameter with the range of existential type slots it uses, which will simplify certain work around interfaces (not in this change...).
Moving the code out of parameter binding and into `check.cpp` revealed some unused GLSL-related code that I removed while I was at it.
I also found that the `IsDeclaration` case of `VarLayoutFlag` wasn't actually being used, so I went ahead and removed it (we can easily re-add it if we ever find a need for it).
Overall this isn't a big cleanup (mostly just code moving, rather than being eliminated), but it will facilitate other changes, and it seems cleaner overall to do this work once in target-independent logic, rather than per-target.
Diffstat (limited to 'source/slang/compiler.h')
| -rw-r--r-- | source/slang/compiler.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/source/slang/compiler.h b/source/slang/compiler.h index d3b872054..843cae1b3 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -137,6 +137,22 @@ namespace Slang List<Arg> args; }; + /// Information collected about global or entry-point shader parameters + struct ShaderParamInfo + { + DeclRef<VarDeclBase> paramDeclRef; + UInt firstExistentialTypeSlot = 0; + UInt existentialTypeSlotCount = 0; + }; + + /// Extended information specific to global shader parameters + struct GlobalShaderParamInfo : ShaderParamInfo + { + // Additional global-scope declarations that are conceptually + // declaring the "same" parameter as the `paramDeclRef`. + List<DeclRef<VarDeclBase>> additionalParamDeclRefs; + }; + /// A request for the front-end to find and validate an entry-point function struct FrontEndEntryPointRequest : RefObject { @@ -287,6 +303,8 @@ namespace Slang Type* getExistentialSlotType(UInt index) { return m_existentialSlots.types[index]; } ExistentialSlots::Arg getExistentialSlotArg(UInt index) { return m_existentialSlots.args[index]; } + List<ShaderParamInfo> const& getShaderParams() { return m_shaderParams; } + void _specializeExistentialSlots( List<RefPtr<Expr>> const& args, DiagnosticSink* sink); @@ -297,7 +315,7 @@ namespace Slang Profile profile, DeclRef<FuncDecl> funcDeclRef); - void _collectExistentialParams(); + void _collectShaderParams(); // The name of the entry point function (e.g., `main`) // @@ -310,6 +328,9 @@ namespace Slang /// The existential/interface slots associated with the entry point parameter scope. ExistentialSlots m_existentialSlots; + /// Information about entry-point parameters + List<ShaderParamInfo> m_shaderParams; + // The profile that the entry point will be compiled for // (this is a combination of the target stage, and also // a feature level that sets capabilities) @@ -920,7 +941,9 @@ namespace Slang Type* getExistentialSlotType(UInt index) { return m_globalExistentialSlots.types[index]; } ExistentialSlots::Arg getExistentialSlotArg(UInt index) { return m_globalExistentialSlots.args[index]; } - void _collectExistentialParams(); + List<GlobalShaderParamInfo> const& getShaderParams() { return m_shaderParams; } + + void _collectShaderParams(DiagnosticSink* sink); void _specializeExistentialSlots( List<RefPtr<Expr>> const& args, DiagnosticSink* sink); @@ -949,6 +972,9 @@ namespace Slang // The existential/interface slots associated with the global scope. ExistentialSlots m_globalExistentialSlots; + /// Information about global shader parameters + List<GlobalShaderParamInfo> m_shaderParams; + // Generated IR for this program. RefPtr<IRModule> m_irModule; |
