diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-12-08 14:23:12 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-08 14:23:12 -0800 |
| commit | 0f55649cc1aa8ad3218b7f8ba7b1eabdd2ec6526 (patch) | |
| tree | 0dc7fd5e88fbc530dc121946f4a20085aa5518d8 /source/slang/legalize-types.cpp | |
| parent | 301cdf5ef42797b1073d9e6c741ef0ba98a38792 (diff) | |
Cleanups to `ParameterBlock<T>` behavior. (#304)
* Cleanups to `ParameterBlock<T>` behavior.
These add some more realistic tests using the `ParameterBlock<T>` support, and show that it can work with the "rewriter" mode.
Unfortunately, this code does *not* currently work with the rewriter + the IR at once. That will need to be fixed in a follow-on change, because I now see that the root problem is pretty ugly.
* cleanup
Diffstat (limited to 'source/slang/legalize-types.cpp')
| -rw-r--r-- | source/slang/legalize-types.cpp | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/source/slang/legalize-types.cpp b/source/slang/legalize-types.cpp index 510b9acd3..fb9c70c97 100644 --- a/source/slang/legalize-types.cpp +++ b/source/slang/legalize-types.cpp @@ -194,9 +194,23 @@ struct TupleTypeBuilder { // The field's type had both special and non-special parts auto pairType = legalLeafType.getPair(); - ordinaryType = pairType->ordinaryType; - specialType = pairType->specialType; - elementPairInfo = pairType->pairInfo; + + // If things originally started as a resource type, then + // we want to externalize all the fields that arose, even + // if there is (nominally) ordinary data. + // + // This is because the "ordinary" side of the legalization + // of `ConstantBuffer<Foo>` will still be a resource type. + if(isResource) + { + specialType = legalFieldType; + } + else + { + ordinaryType = pairType->ordinaryType; + specialType = pairType->specialType; + elementPairInfo = pairType->pairInfo; + } } break; @@ -777,23 +791,21 @@ LegalType legalizeType( TypeLegalizationContext* context, Type* type) { - if (auto parameterBlockType = type->As<ParameterBlockType>()) - { - // We basically legalize the `ParameterBlock<T>` type - // over to `T`. In order to represent this preoperly, - // we need to be careful to wrap it up in a way that - // tells us to eliminate downstream deferences... - - auto legalElementType = legalizeType(context, - parameterBlockType->getElementType()); - return LegalType::implicitDeref(legalElementType); - } - else if (auto uniformBufferType = type->As<UniformParameterGroupType>()) + if (auto uniformBufferType = type->As<UniformParameterGroupType>()) { - // We have a `ConstantBuffer<T>` or `TextureBuffer<T>` or - // other pointer-like type that represents uniform parameters. - // We need to pull any resource-type fields out of it, but - // leave the non-resource fields where they are. + // We have one of: + // + // ConstantBuffer<T> + // TextureBuffer<T> + // ParameterBlock<T> + // + // or some other pointer-like type that represents uniform + // parameters. We need to pull any resource-type fields out + // of it, but leave non-resource fields where they are. + // + // As a special case, if the type contains *no* uniform data, + // we'll want to completely eliminate the uniform/ordinary + // part. // Legalize the element type to see what we are working with. auto legalElementType = legalizeType(context, @@ -973,11 +985,23 @@ RefPtr<VarLayout> getFieldLayout( if (!typeLayout) return nullptr; - while(auto arrayTypeLayout = dynamic_cast<ArrayTypeLayout*>(typeLayout)) + for(;;) { - typeLayout = arrayTypeLayout->elementTypeLayout; + if(auto arrayTypeLayout = dynamic_cast<ArrayTypeLayout*>(typeLayout)) + { + typeLayout = arrayTypeLayout->elementTypeLayout; + } + else if(auto parameterGroupTypeLayotu = dynamic_cast<ParameterGroupTypeLayout*>(typeLayout)) + { + typeLayout = parameterGroupTypeLayotu->elementTypeLayout; + } + else + { + break; + } } + if (auto structTypeLayout = dynamic_cast<StructTypeLayout*>(typeLayout)) { RefPtr<VarLayout> fieldLayout; |
