From ae04e604d43d169bcba7f24c8c23a0fdf4cbb483 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 18 Dec 2024 11:33:55 -0800 Subject: Allow `Optional`, `Tuple` and `bool` to be used in varying input/output. (#5889) * Allow `Optional` and `Tuple` to be used in varying input/output. * Fix. * format code * Fix. * Fix test. * Fix. * enhance test. * Fix. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-parameter-binding.cpp | 53 +++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-parameter-binding.cpp') diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 7fb719053..33fa24f11 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2262,12 +2262,63 @@ static RefPtr processEntryPointVaryingParameter( return ptrTypeLayout; } + else if (auto optionalType = as(type)) + { + Array types = + makeArray(optionalType->getValueType(), context->getASTBuilder()->getBoolType()); + auto tupleType = context->getASTBuilder()->getTupleType(types.getView()); + return processEntryPointVaryingParameter(context, tupleType, state, varLayout); + } + else if (auto tupleType = as(type)) + { + RefPtr structLayout = new StructTypeLayout(); + structLayout->type = type; + for (Index i = 0; i < tupleType->getMemberCount(); i++) + { + auto fieldType = tupleType->getMember(i); + RefPtr fieldVarLayout = new VarLayout(); + + // We don't really have a "field" decl, so just use the tuple-typed decl + // itself as the varDecl of the elements. + auto fieldDecl = (VarDeclBase*)varLayout->varDecl.getDecl(); + fieldVarLayout->varDecl = fieldDecl; + + structLayout->fields.add(fieldVarLayout); + + auto fieldTypeLayout = processEntryPointVaryingParameterDecl( + context, + fieldDecl, + fieldType, + state, + fieldVarLayout); + + if (!fieldTypeLayout) + { + getSink(context)->diagnose( + varLayout->varDecl, + Diagnostics::notValidVaryingParameter, + fieldType); + continue; + } + fieldVarLayout->typeLayout = fieldTypeLayout; + + // Assign offsets in var layout for each resource kind of the type. + for (auto fieldTypeResInfo : fieldTypeLayout->resourceInfos) + { + auto kind = fieldTypeResInfo.kind; + auto structTypeResInfo = structLayout->findOrAddResourceInfo(kind); + auto fieldResInfo = fieldVarLayout->findOrAddResourceInfo(kind); + fieldResInfo->index = structTypeResInfo->count.getFiniteValue(); + structTypeResInfo->count += fieldTypeResInfo.count; + } + } + return structLayout; + } // Catch declaration-reference types late in the sequence, since // otherwise they will include all of the above cases... else if (auto declRefType = as(type)) { auto declRef = declRefType->getDeclRef(); - if (auto structDeclRef = declRef.as()) { RefPtr structLayout = new StructTypeLayout(); -- cgit v1.2.3