diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-17 21:26:21 -0500 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-17 18:26:21 -0800 |
| commit | 54bf54bd0dda378f8400860b25855558f39cb52b (patch) | |
| tree | 955931f37df819f3c6e22bc981089f644c1141e1 /source/slang/type-layout.h | |
| parent | 0298a0427bbfe19700169c4e239a1b9e91baa410 (diff) | |
Add support for global generic parameters (#285)
* Add support for global generic parameters
(In-progress work)
This commit include:
1. Update Slang API to allow specification of generic type arguments in an `EntryPointRequest`
2. Add parsing of `__generic_param` construct, which becomes a GlobalGenericParamDecl, contains members of `GenericTypeConstraintDecl`.
3. Semantics checking will check whether the provided type arguments conform to the interfaces as defined by the generic parameter, and store SubtypeWitness values in the EntryPointRequest, which will be used by `specializeIRForEntryPoint` when generating final IR.
4. Add a new type of substitution - `GlobalGenericParamSubstitution` for subsittuting references to `__generic_param` decls or to its member `GenericTypeConsraintDecl` with the actual type argument or witness tables.
5. Update `IRSpecContext` to apply `GlobalGenericParamSubstitution` when specializing the IR for an EntryPointRequest.
6. Update `render-test` to take additional `type` inputs, which specifies the type arguments to substitute into the global `__generic_param` types.
This commit does not include ProgramLayout specialization.
* IR: pass through `[unroll]` attribute (#284)
The initial lowering was adding an `IRLoopControlDecoration` to the instruction at the head of a loop, but this was getting dropped when the IR gets cloned for a particular entry point.
The fix was simply to add a case for loop-control decorations to `cloneDecoration`.
* fix warnings
* IR: support `CompileTimeForStmt` (#286)
This statement type is a bit of a hack, to support loops that *must* be unrolled.
The AST-to-AST pass handles them by cloning the AST for the loop body N times, and it was easy enough to do the same thing for the IR: emit the instructions for the body N times.
The only thing that requires a bit of care is that now we might see the same variable declarations multiple times, so we need to play it safe and overwrite existing entries in our map from declarations to their IR values.
Of course a better answer long-term would be to do the actual unrolling in the IR. This is especially true because we might some day want to support compile-time/must-unroll loops in functions, where the loop counter comes in as a parameter (but must still be compile-time-constant at every call site).
* Add support for global generic parameters
(In-progress work)
This commit include:
1. Update Slang API to allow specification of generic type arguments in an `EntryPointRequest`
2. Add parsing of `__generic_param` construct, which becomes a GlobalGenericParamDecl, contains members of `GenericTypeConstraintDecl`.
3. Semantics checking will check whether the provided type arguments conform to the interfaces as defined by the generic parameter, and store SubtypeWitness values in the EntryPointRequest, which will be used by `specializeIRForEntryPoint` when generating final IR.
4. Add a new type of substitution - `GlobalGenericParamSubstitution` for subsittuting references to `__generic_param` decls or to its member `GenericTypeConsraintDecl` with the actual type argument or witness tables.
5. Update `IRSpecContext` to apply `GlobalGenericParamSubstitution` when specializing the IR for an EntryPointRequest.
6. Update `render-test` to take additional `type` inputs, which specifies the type arguments to substitute into the global `__generic_param` types.
progress on parameter binding
* Add a more contrived test case for specializing parameter bindings
* update render-test to align buffers to 256 bytes (to get rid of D3D complains on minimal buffer size).
* adding one more test case for parameter binding specialization.
* Cleanup according to @tfoleyNV 's suggestions.
* fix a bug introduced in the cleanup
Diffstat (limited to 'source/slang/type-layout.h')
| -rw-r--r-- | source/slang/type-layout.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index 363b01486..4ce6dc355 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -220,7 +220,7 @@ typedef unsigned int VarLayoutFlags; enum VarLayoutFlag : VarLayoutFlags { IsRedeclaration = 1 << 0, ///< This is a redeclaration of some shader parameter - HasSemantic = 1 << 1, + HasSemantic = 1 << 1 }; // A reified layout for a particular variable, field, etc. @@ -358,6 +358,13 @@ public: Dictionary<Decl*, RefPtr<VarLayout>> mapVarToLayout; }; +class GenericParamTypeLayout : public TypeLayout +{ +public: + RefPtr<GlobalGenericParamDecl> getGlobalGenericParamDecl(); + int paramIndex = 0; +}; + // Layout information for a single shader entry point // within a program // @@ -386,6 +393,13 @@ public: unsigned flags = 0; }; +class GenericParamLayout : public Layout +{ +public: + RefPtr<GlobalGenericParamDecl> decl; + int index; +}; + // Layout information for the global scope of a program class ProgramLayout : public Layout { @@ -403,13 +417,15 @@ public: // (since a constant buffer will have to be allocated // to store them). // - RefPtr<TypeLayout> globalScopeLayout; + RefPtr<VarLayout> globalScopeLayout; // We catalog the requested entry points here, // and any entry-point-specific parameter data // will (eventually) belong there... List<RefPtr<EntryPointLayout>> entryPoints; + List<RefPtr<GenericParamLayout>> globalGenericParams; + // HACK: binding to use when we have to create // a dummy sampler just to appease glslang int bindingForHackSampler = 0; |
