From c43f6fa55aca23365c86c6ec1737d42be74d9d3e Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 7 Jan 2025 22:26:31 -0800 Subject: Lower varying parameters as pointers instead of SSA values. (#5919) * Add executable test on matrix-typed vertex input. * Fix emit logic of matrix layout qualifier. * Pass fragment shader varying input by constref to allow EvaluateAttributeAtCentroid etc. to be implemented correctly. --- source/slang/slang-emit-c-like.cpp | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 3175f1b07..64cc9969c 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1537,6 +1537,30 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst) return true; } + if (auto load = as(inst)) + { + // Loads from a constref global param should always be folded. + auto ptrType = load->getPtr()->getDataType(); + if (load->getPtr()->getOp() == kIROp_GlobalParam) + { + if (ptrType->getOp() == kIROp_ConstRefType) + return true; + if (auto ptrTypeBase = as(ptrType)) + { + auto addrSpace = ptrTypeBase->getAddressSpace(); + switch (addrSpace) + { + case Slang::AddressSpace::Uniform: + case Slang::AddressSpace::Input: + case Slang::AddressSpace::BuiltinInput: + return true; + default: + break; + } + } + } + } + // Always hold if inst is a call into an [__alwaysFoldIntoUseSite] function. if (auto call = as(inst)) { @@ -4709,9 +4733,21 @@ void CLikeSourceEmitter::emitGlobalParam(IRGlobalParam* varDecl) auto rawType = varDecl->getDataType(); auto varType = rawType; - if (auto outType = as(varType)) + if (auto ptrType = as(varType)) { - varType = outType->getValueType(); + switch (ptrType->getAddressSpace()) + { + case AddressSpace::Input: + case AddressSpace::Output: + case AddressSpace::BuiltinInput: + case AddressSpace::BuiltinOutput: + varType = ptrType->getValueType(); + break; + default: + if (as(ptrType)) + varType = ptrType->getValueType(); + break; + } } if (as(varType)) return; -- cgit v1.2.3