summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-12 13:19:35 -0800
committerGitHub <noreply@github.com>2024-02-12 13:19:35 -0800
commit0c15582efcec6c7b163ae3a20c04e1aee958d24a (patch)
treedcc3ed41eb993cf5202cc4d995383cd14cbba9f7 /source
parent4f7d1f44a4b2a5eab2e2dec1edf3a156da78aae3 (diff)
Fix lowering of static consts in a generic function. (#3573)
* Fix lowering of static consts in a generic function. * Fix. * Fix. * Fix lowering of shading rate builtin.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp9
-rw-r--r--source/slang/slang-lower-to-ir.cpp69
2 files changed, 43 insertions, 35 deletions
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index dd165769c..0f9e88d20 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -929,7 +929,14 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
}
else if (semanticName == "sv_shadingrate")
{
- name = "gl_PrimitiveShadingRateEXT";
+ if (kind == LayoutResourceKind::VaryingInput)
+ {
+ name = "gl_ShadingRateEXT";
+ }
+ else
+ {
+ name = "gl_PrimitiveShadingRateEXT";
+ }
}
if( name )
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index f5d743bb1..8fef6f535 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -724,6 +724,31 @@ LoweredValInfo emitDeclRef(
DeclRef<Decl> declRef,
IRType* type);
+
+bool isFunctionVarDecl(VarDeclBase* decl)
+{
+ // The immediate parent of a function-scope variable
+ // declaration will be a `ScopeDecl`.
+ //
+ // TODO: right now the parent links for scopes are *not*
+ // set correctly, so we can't just scan up and look
+ // for a function in the parent chain...
+ auto parent = decl->parentDecl;
+ if (as<ScopeDecl>(parent))
+ {
+ return true;
+ }
+ return false;
+}
+
+bool isFunctionStaticVarDecl(VarDeclBase* decl)
+{
+ // Only a variable marked `static` can be static.
+ if (!decl->findModifier<HLSLStaticModifier>())
+ return false;
+ return isFunctionVarDecl(decl);
+}
+
IRInst* getSimpleVal(IRGenContext* context, LoweredValInfo lowered);
int32_t getIntrinsicOp(
@@ -7439,25 +7464,22 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
NestedContext nested(this);
auto subBuilder = nested.getBuilder();
auto subContext = nested.getContext();
- IRGeneric* outerGeneric = emitOuterGenerics(subContext, decl, decl);
- // TODO(JS): Is this right?
- //
- // If we *are* in a generic, then outputting this in the (current) generic scope would be correct.
- // If we *aren't* we want to go the level above for insertion
- //
- // Just inserting into the parent doesn't work with a generic that holds a function that has a static const
- // variable.
- //
+ IRGeneric* outerGeneric = nullptr;
+
+ // If we are static, then we need to insert the declaration before the parent.
// This tries to match the behavior of previous `lowerFunctionStaticConstVarDecl` functionality
- if (!outerGeneric && isFunctionStaticVarDecl(decl))
+ if (isFunctionStaticVarDecl(decl))
{
// We need to insert the constant at a level above
// the function being emitted. This will usually
// be the global scope, but it might be an outer
// generic if we are lowering a generic function.
-
- subBuilder->setInsertInto(subBuilder->getFunc()->getParent());
+ subBuilder->setInsertBefore(subBuilder->getFunc());
+ }
+ else if (!isFunctionVarDecl(decl))
+ {
+ outerGeneric = emitOuterGenerics(subContext, decl, decl);
}
auto initExpr = decl->initExpr;
@@ -7613,27 +7635,6 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
return globalVal;
}
- bool isFunctionStaticVarDecl(VarDeclBase* decl)
- {
- // Only a variable marked `static` can be static.
- if(!decl->findModifier<HLSLStaticModifier>())
- return false;
-
- // The immediate parent of a function-scope variable
- // declaration will be a `ScopeDecl`.
- //
- // TODO: right now the parent links for scopes are *not*
- // set correctly, so we can't just scan up and look
- // for a function in the parent chain...
- auto parent = decl->parentDecl;
- if( as<ScopeDecl>(parent) )
- {
- return true;
- }
-
- return false;
- }
-
struct NestedContext
{
IRGenEnv subEnvStorage;
@@ -9782,7 +9783,7 @@ bool canDeclLowerToAGeneric(Decl* decl)
{
if (varDecl->hasModifier<HLSLStaticModifier>() && varDecl->hasModifier<ConstModifier>())
{
- return true;
+ return !isFunctionVarDecl(varDecl);
}
}