From 0f55649cc1aa8ad3218b7f8ba7b1eabdd2ec6526 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 8 Dec 2017 14:23:12 -0800 Subject: Cleanups to `ParameterBlock` behavior. (#304) * Cleanups to `ParameterBlock` behavior. These add some more realistic tests using the `ParameterBlock` 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 --- source/slang/legalize-types.cpp | 66 ++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) (limited to 'source/slang/legalize-types.cpp') 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` 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()) - { - // We basically legalize the `ParameterBlock` 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()) + if (auto uniformBufferType = type->As()) { - // We have a `ConstantBuffer` or `TextureBuffer` 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 + // TextureBuffer + // ParameterBlock + // + // 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 getFieldLayout( if (!typeLayout) return nullptr; - while(auto arrayTypeLayout = dynamic_cast(typeLayout)) + for(;;) { - typeLayout = arrayTypeLayout->elementTypeLayout; + if(auto arrayTypeLayout = dynamic_cast(typeLayout)) + { + typeLayout = arrayTypeLayout->elementTypeLayout; + } + else if(auto parameterGroupTypeLayotu = dynamic_cast(typeLayout)) + { + typeLayout = parameterGroupTypeLayotu->elementTypeLayout; + } + else + { + break; + } } + if (auto structTypeLayout = dynamic_cast(typeLayout)) { RefPtr fieldLayout; -- cgit v1.2.3