summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-c-like.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-07 22:26:31 -0800
committerGitHub <noreply@github.com>2025-01-07 22:26:31 -0800
commitc43f6fa55aca23365c86c6ec1737d42be74d9d3e (patch)
tree2c49bc1dbd12ae5f46d682a3f240465931471060 /source/slang/slang-emit-c-like.cpp
parent1a56f58fdd0c704e6dc0fad0f0ec33a25a35e60b (diff)
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.
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
-rw-r--r--source/slang/slang-emit-c-like.cpp40
1 files changed, 38 insertions, 2 deletions
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<IRLoad>(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<IRPtrTypeBase>(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<IRCall>(inst))
{
@@ -4709,9 +4733,21 @@ void CLikeSourceEmitter::emitGlobalParam(IRGlobalParam* varDecl)
auto rawType = varDecl->getDataType();
auto varType = rawType;
- if (auto outType = as<IROutTypeBase>(varType))
+ if (auto ptrType = as<IRPtrTypeBase>(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<IROutTypeBase>(ptrType))
+ varType = ptrType->getValueType();
+ break;
+ }
}
if (as<IRVoidType>(varType))
return;