diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-18 11:33:55 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-18 11:33:55 -0800 |
| commit | ae04e604d43d169bcba7f24c8c23a0fdf4cbb483 (patch) | |
| tree | 899c872ec5cc5c6ccc27930ef6971a0baf018569 /source/slang/slang-parameter-binding.cpp | |
| parent | 41c627fd420a644f0ae86e36f4752e820e2d683c (diff) | |
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>
Diffstat (limited to 'source/slang/slang-parameter-binding.cpp')
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
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<TypeLayout> processEntryPointVaryingParameter( return ptrTypeLayout; } + else if (auto optionalType = as<OptionalType>(type)) + { + Array<Type*, 2> 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<TupleType>(type)) + { + RefPtr<StructTypeLayout> structLayout = new StructTypeLayout(); + structLayout->type = type; + for (Index i = 0; i < tupleType->getMemberCount(); i++) + { + auto fieldType = tupleType->getMember(i); + RefPtr<VarLayout> 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<DeclRefType>(type)) { auto declRef = declRefType->getDeclRef(); - if (auto structDeclRef = declRef.as<StructDecl>()) { RefPtr<StructTypeLayout> structLayout = new StructTypeLayout(); |
