summaryrefslogtreecommitdiffstats
path: root/source/slang/lower.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-12 11:07:45 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-12 11:07:45 -0700
commit74963469a169b49d61196e3a3b33a903ea8bfede (patch)
treea3d8f4f8873946f58111ae5e7f5034b071c1e824 /source/slang/lower.cpp
parent2c6c501b36db9e7991c3f7999451b70f12329ecc (diff)
Add basic reflection query for checking if entry point is "sample-rate"
- This really just checks two basic things: 1. Was there any global variable declared with `in` and `sample`? 2. Did any code encountered during lowering referenece `gl_SampleIndex`? - This doesn't cover what HLSL could need, nor what we would need for cross-compilation. Consider it GLSL-specific for now. - In order to generate the information with even a reasonable chance of being accurate (not giving a ton of false positives) I tried to integrate the checks into the lowering process (so they only see code that is referenced, one hopes). - For this to work with my testing setup, I needed to make sure that lowering is always performed, prior to emitting reflection info - This change broke several reflection tests, because they had been using code that wouldn't actually pass the downstream compiler. I checked in fixes for those.
Diffstat (limited to 'source/slang/lower.cpp')
-rw-r--r--source/slang/lower.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index ecf23d9ed..02da47ccb 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -210,7 +210,8 @@ struct SharedLoweringContext
{
CompileRequest* compileRequest;
- ProgramLayout* programLayout;
+ ProgramLayout* programLayout;
+ EntryPointLayout* entryPointLayout;
// The target we are going to generate code for.
//
@@ -607,6 +608,8 @@ struct LoweringVisitor
RefPtr<ExpressionSyntaxNode> visitVarExpressionSyntaxNode(
VarExpressionSyntaxNode* expr)
{
+ doSampleRateInputCheck(expr->name);
+
// If the expression didn't get resolved, we can leave it as-is
if (!expr->declRef)
return expr;
@@ -1019,6 +1022,12 @@ struct LoweringVisitor
RefPtr<UnparsedStmt> loweredStmt = new UnparsedStmt();
lowerStmtFields(loweredStmt, stmt);
+ for (auto token : stmt->tokens)
+ {
+ if (token.Type == TokenType::Identifier)
+ doSampleRateInputCheck(token.Content);
+ }
+
loweredStmt->tokens = stmt->tokens;
addStmt(loweredStmt);
@@ -2052,9 +2061,39 @@ struct LoweringVisitor
return SourceLanguage::Unknown;
}
+ void setSampleRateFlag()
+ {
+ shared->entryPointLayout->flags |= EntryPointLayout::Flag::usesAnySampleRateInput;
+ }
+
+ void doSampleRateInputCheck(VarDeclBase* decl)
+ {
+ if (decl->HasModifier<HLSLSampleModifier>())
+ {
+ setSampleRateFlag();
+ }
+ }
+
+ void doSampleRateInputCheck(String const& name)
+ {
+ if (name == "gl_SampleIndex")
+ {
+ setSampleRateFlag();
+ }
+ }
+
RefPtr<VarDeclBase> visitVariable(
Variable* decl)
{
+ // Global variable? Check if it is a sample-rate input.
+ if (dynamic_cast<ProgramSyntaxNode*>(decl->ParentDecl))
+ {
+ if (decl->HasModifier<InModifier>())
+ {
+ doSampleRateInputCheck(decl);
+ }
+ }
+
auto loweredDecl = lowerVarDeclCommon(decl, getClass<Variable>());
if(!loweredDecl)
return nullptr;
@@ -2905,6 +2944,8 @@ LoweredEntryPoint lowerEntryPoint(
bool isRewrite = isRewriteRequest(translationUnit->sourceLanguage, target);
sharedContext.isRewrite = isRewrite;
+ sharedContext.entryPointLayout = visitor.findEntryPointLayout(entryPoint);
+
LoweredEntryPoint result;
if (isRewrite)
{