diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-09-10 21:41:07 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 18:41:07 +0000 |
| commit | ec42c4a20facbcae441cd172bfd607614e761907 (patch) | |
| tree | e0fa1af4e12d8cc5324777e380fd1e144d3c763a /source | |
| parent | b03cbb02c6486274d46865f3995953f2105cefc9 (diff) | |
Fix pointers and C-like layout in varying parameters (#8425)
Closes #8409, but ended up being more about fixing another bug. While
the issue itself seems to only be a simple typo fix (see second commit
in this PR), I found out during writing a test that pointers never got
correct locations regardless of layout. Their locations were always
assigned to zero due to lacking a resource usage entry in `TypeLayout`.
They were also missing the `Flat` decoration, so I went ahead and added
that too.
I can split this up into two separate PRs if that's preferred; both
aspects just share a test right now and fix a similar-looking issue in
the resulting SPIR-V.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 5 | ||||
| -rw-r--r-- | source/slang/slang-parameter-binding.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-type-layout.cpp | 16 |
3 files changed, 21 insertions, 6 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index e8bcad1c1..f82bf24c1 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -3020,7 +3020,7 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex bool anyModifiers = (var->findDecoration<IRInterpolationModeDecoration>() != nullptr); // If the user didn't explicitly qualify a varying - // with integer type, then we need to explicitly + // with integer or pointer type, then we need to explicitly // add the `flat` modifier for GLSL. if (!anyModifiers) { @@ -3030,7 +3030,8 @@ struct SPIRVEmitContext : public SourceEmitterBase, public SPIRVEmitSharedContex layout->usesResourceKind(LayoutResourceKind::VaryingInput)) { const auto ptrType = as<IRPtrTypeBase>(var->getDataType()); - if (ptrType && isIntegralScalarOrCompositeType(ptrType->getValueType())) + if (ptrType && (isIntegralScalarOrCompositeType(ptrType->getValueType()) || + as<IRPtrTypeBase>(ptrType->getValueType()))) emitOpDecorate( getSection(SpvLogicalSectionID::Annotations), nullptr, diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index b79f96022..605e50d41 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2344,13 +2344,13 @@ static RefPtr<TypeLayout> processEntryPointVaryingParameter( { SLANG_ASSERT(ptrType->astNodeType == ASTNodeType::PtrType); + auto typeLayout = processSimpleEntryPointParameter(context, ptrType, state, varLayout); + RefPtr<PointerTypeLayout> ptrTypeLayout = typeLayout.as<PointerTypeLayout>(); + // Work out the layout for the value/target type auto valueTypeLayout = processEntryPointVaryingParameter(context, ptrType->getValueType(), state, varLayout); - - RefPtr<PointerTypeLayout> ptrTypeLayout = new PointerTypeLayout(); ptrTypeLayout->valueTypeLayout = valueTypeLayout; - return ptrTypeLayout; } else if (auto optionalType = as<OptionalType>(type)) diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp index fb40382c5..519b3ab06 100644 --- a/source/slang/slang-type-layout.cpp +++ b/source/slang/slang-type-layout.cpp @@ -1387,7 +1387,7 @@ LayoutRulesImpl kCPushConstantRulesImpl_ = { LayoutRulesImpl kCVaryingInputLayoutRulesImpl_ = { &kCLayoutRulesFamilyImpl, - &kGLSLVaryingOutputLayoutRulesImpl, + &kGLSLVaryingInputLayoutRulesImpl, &kGLSLObjectLayoutRulesImpl, }; @@ -5680,6 +5680,20 @@ RefPtr<TypeLayout> getSimpleVaryingParameterTypeLayout( return typeLayout; } + else if (as<PtrType>(type)) + { + RefPtr<TypeLayout> typeLayout = new PointerTypeLayout(); + typeLayout->type = type; + typeLayout->rules = rules; + + for (int rr = 0; rr < varyingRulesCount; ++rr) + { + auto info = varyingRules[rr]->GetPointerLayout(); + typeLayout->addResourceUsage(info.kind, info.size); + } + + return typeLayout; + } else if (auto vecType = as<VectorExpressionType>(type)) { auto elementType = vecType->getElementType(); |
