From d3ed08ec3073c3cb9ac24fa3670784dd6e97a164 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 24 Apr 2024 16:23:35 -0700 Subject: Parameter layout and reflection for Metal bindings. (#4022) --- source/slang/slang-legalize-types.cpp | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'source/slang/slang-legalize-types.cpp') diff --git a/source/slang/slang-legalize-types.cpp b/source/slang/slang-legalize-types.cpp index fc0947c62..393b34e68 100644 --- a/source/slang/slang-legalize-types.cpp +++ b/source/slang/slang-legalize-types.cpp @@ -1156,23 +1156,34 @@ LegalType legalizeTypeImpl( auto originalElementType = uniformBufferType->getElementType(); // Legalize the element type to see what we are working with. - auto legalElementType = legalizeType(context, - originalElementType); - - // As a bit of a corner case, if the user requested something - // like `ConstantBuffer` the element type would - // legalize to a "simple" type, and that would be interpreted - // as an *ordinary* type, but we really need to notice the - // case when the element type is simple, but *special*. - // - if( context->isSpecialType(originalElementType) ) + LegalType legalElementType; + + if (isMetalTarget(context->targetProgram->getTargetReq()) && + as(uniformBufferType)) + { + // On Metal, we do not need to legalize the element type of + // a parameter block because we can translate it directly into + // an argument buffer. + legalElementType = LegalType::simple(originalElementType); + } + else { - // Anything that has a special element type needs to - // be handled by the pass-specific logic in the context. + legalElementType = legalizeType(context, originalElementType); + // As a bit of a corner case, if the user requested something + // like `ConstantBuffer` the element type would + // legalize to a "simple" type, and that would be interpreted + // as an *ordinary* type, but we really need to notice the + // case when the element type is simple, but *special*. // - return context->createLegalUniformBufferType( - uniformBufferType->getOp(), - legalElementType); + if( context->isSpecialType(originalElementType) ) + { + // Anything that has a special element type needs to + // be handled by the pass-specific logic in the context. + // + return context->createLegalUniformBufferType( + uniformBufferType->getOp(), + legalElementType); + } } // Note that even when legalElementType.flavor == Simple -- cgit v1.2.3