diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-07-14 12:00:29 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-07-14 12:00:29 -0700 |
| commit | f4ac13d6718d6433f69eb21311110c8225a95aee (patch) | |
| tree | fb6ab85174f2f630dd49910bc69bb23309f9eee0 /source/slang/type-layout.h | |
| parent | d9366db8993c566fbb0af780c13db438dbf74022 (diff) | |
Adjust type layout when parameter block constains member using the same resource
If we have something like to following in HLSL:
cbuffer C { Texture2D t; ... }
and we are compiling to GLSL, then both `C` and `C.t` consume the same kind of resource (a descriptor-table slot).
The way reflection was working right now, querying the index of `C` would return its binding (let's say it is `4` just to be concrete) and then a query on `C::t` would give its offset, which was being computed as `0` because it is the first field in the logical `struct` type.
That obviously leads to bad math and requires some subtle `+1`s in cases to get things right (e.g., when scalaring during lowering, I had to carefully add one in some cases).
It is unreasonable to expect users to deal with this.
This commit changes it so that the offset of field `C::t` is `1` so that hopefully more things Just Work.
The special-case logic in lowering is now gone.
One important catch here is that this pretty much only works in the case where the element type of a parameter block is a `struct` type (which is really all that makes sense right now).
If we ever want to generalize this in the future, then it will probably be necessary to change the `TypeLayout` case for parameter blocks to store a `VarLayout` for the element, rather than just a `TypeLayout`.
Diffstat (limited to 'source/slang/type-layout.h')
| -rw-r--r-- | source/slang/type-layout.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/source/slang/type-layout.h b/source/slang/type-layout.h index d2254c9e5..d5c96abf2 100644 --- a/source/slang/type-layout.h +++ b/source/slang/type-layout.h @@ -535,6 +535,7 @@ SimpleLayoutInfo GetLayout(ExpressionType* type, LayoutRulesImpl* rules); SimpleLayoutInfo GetLayout(ExpressionType* type, LayoutRule rule = LayoutRule::Std430); RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules); +RefPtr<TypeLayout> CreateTypeLayout(ExpressionType* type, LayoutRulesImpl* rules, SimpleLayoutInfo offset); // @@ -544,15 +545,19 @@ createParameterBlockTypeLayout( RefPtr<ParameterBlockType> parameterBlockType, LayoutRulesImpl* rules); -// Create a type layout for a constant buffer type, -// in the case where we already know the layout -// for the element type. RefPtr<ParameterBlockTypeLayout> createParameterBlockTypeLayout( RefPtr<ParameterBlockType> parameterBlockType, - RefPtr<TypeLayout> elementTypeLayout, - LayoutRulesImpl* rules); + LayoutRulesImpl* parameterBlockRules, + RefPtr<ExpressionType> elementType, + LayoutRulesImpl* elementTypeRules); +RefPtr<ParameterBlockTypeLayout> +createParameterBlockTypeLayout( + RefPtr<ParameterBlockType> parameterBlockType, + LayoutRulesImpl* parameterBlockRules, + SimpleLayoutInfo parameterBlockInfo, + RefPtr<TypeLayout> elementTypeLayout); // Create a type layout for a structured buffer type. RefPtr<StructuredBufferTypeLayout> |
