summaryrefslogtreecommitdiffstats
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-02-16 09:04:44 -0800
committerGitHub <noreply@github.com>2018-02-16 09:04:44 -0800
commit1b93da040ef00836438437e998c1c9584e3fd4ac (patch)
treeaa740da003832a7c0e653883c7cc739fab12e8ba /source/slang/emit.cpp
parent32549707cc9aa67dbc19cbdc0490ffebc8ec253c (diff)
IR/Vulkan fixes (#412)
* Fix bugs around IR legalization of GLSL input/output - Add case to handle assignment of one `ScalarizedVal::Flavor::address` to another (still need to make sure we are handling all the possible cases there) - Revamp logic for creating global variable declarations for varying inputs/outputs. - Actually handle creating array declarations (not sure if binding locations will be correct) - Properly deal with offsetting of locations for nested fields - Only create varying input/output layout information as needed for the separate `in` and `out` variables we create to represent a single HLSL `inout` varying * During SSA generation, recursively remove trivial phis This is actually written up in the original paper I used as a reference, but I hadn't implemented the case yet. When you eliminate one phi as trivial (because its only operands were itself and at most one other value), you might find that another phi becomes trivial (because it had this phi as an operand, but now it will have the other value...). The one thing that made any of this tricky is that our "phi" nodes are really block parameters, and thus they don't technically have operands (`IRUse`s). The `IRUse`s for each phi were being tracked in a separate array, and had their `user` field set to null. With this change, I set their `user` to be the corresponding `IRParam` for the phi (and that means I changed `IRParam` to inherit from `IRUser` even though it shouldn't really be required). * Re-build SSA form after specialization/legalization The main reason to do this is that legalization might scalarize types, and thus might allow us to clean up resource-type local variables that we were not able to clean up when they were part of an aggregate. Note: we shouldn't really need to do this, because the front-end should actually be guaranteeing that types that include resources are used in "safe" ways, but we currently don't have the analyses required to support that. * Give an error message if we get GLSL input The API and command-line interface still recognize and nominally support GLSL input files, because they need to be supported in the "pass-through" mode. This change just adds an error message if we encounter a GLSL input file in anything other than "pass-through" mode.
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp43
1 files changed, 36 insertions, 7 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index a27492c0b..0cd896ced 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -2,6 +2,7 @@
#include "emit.h"
#include "ir-insts.h"
+#include "ir-ssa.h"
#include "legalize-types.h"
#include "lower-to-ir.h"
#include "mangle.h"
@@ -7212,15 +7213,10 @@ emitDeclImpl(decl, nullptr);
}
#endif
- void emitIRVarModifiers(
+ void emitIRMatrixLayoutModifiers(
EmitContext* ctx,
VarLayout* layout)
{
- if (!layout)
- return;
-
- auto target = ctx->shared->target;
-
// We need to handle the case where the variable has
// a matrix type, and has been given a non-standard
// layout attribute (for HLSL, `row_major` is the
@@ -7228,6 +7224,8 @@ emitDeclImpl(decl, nullptr);
//
if (auto matrixTypeLayout = layout->typeLayout.As<MatrixTypeLayout>())
{
+ auto target = ctx->shared->target;
+
switch (target)
{
case CodeGenTarget::HLSL:
@@ -7269,6 +7267,17 @@ emitDeclImpl(decl, nullptr);
}
+ }
+
+ void emitIRVarModifiers(
+ EmitContext* ctx,
+ VarLayout* layout)
+ {
+ if (!layout)
+ return;
+
+ emitIRMatrixLayoutModifiers(ctx, layout);
+
if (ctx->shared->target == CodeGenTarget::GLSL)
{
// Layout-related modifiers need to come before the declaration,
@@ -7539,7 +7548,19 @@ emitDeclImpl(decl, nullptr);
if(fieldType->Equals(getSession()->getVoidType()))
continue;
- emitIRVarModifiers(ctx, fieldLayout);
+ // Note: we will emit matrix-layout modifiers here, but
+ // we will refrain from emitting other modifiers that
+ // might not be appropriate to the context (e.g., we
+ // shouldn't go emitting `uniform` just because these
+ // things are uniform...).
+ //
+ // TODO: we need a more refined set of modifiers that
+ // we should allow on fields, because we might end
+ // up supporting layout that isn't the default for
+ // the given block type (e.g., something other than
+ // `std140` for a uniform block).
+ //
+ emitIRMatrixLayoutModifiers(ctx, fieldLayout);
emitIRType(ctx, fieldType, getIRName(ff));
@@ -8240,6 +8261,14 @@ String emitEntryPoint(
fprintf(stderr, "###\n");
#endif
+ // Once specialization and type legalization have been performed,
+ // we should perform some of our basic optimization steps again,
+ // to see if we can clean up any temporaries created by legalization.
+ // (e.g., things that used to be aggregated might now be split up,
+ // so that we can work with the individual fields).
+ constructSSA(irModule);
+
+
// After all of the required optimization and legalization
// passes have been performed, we can emit target code from
// the IR module.