summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTheresa Foley <tfoleyNV@users.noreply.github.com>2021-08-11 11:00:16 -0700
committerGitHub <noreply@github.com>2021-08-11 11:00:16 -0700
commit4323a15708cafa6411ec10ef8fefb736f8bda82c (patch)
treed8f348c6db794a7e1128334e3f95023452c6ee1d /source
parent08e36dd6c3c03eb0af7b090d30afee864e309de9 (diff)
Fix a few issues around opaque types as outputs (#1918)
* Fix a few issues around opaque types as outputs Slang and HLSL support opaque types (textures, buffers, samplers, etc.) as members of `struct`s, mutable local variables, function results, and `out`/`inout` parameters. GLSL and SPIR-V do not. In order to translate Slang code over to GLSL/SPIR-V we use a variety of passes that seek to eliminate all of the above use cases and produce code that only uses opaque types in the limited ways that GLSL/SPIR-V allow. This change relates to the passes that deal with function results and `out`/`inout` parameters. There are two basic changes here: 1. The `specializeResourceOutputs` pass was only dealing with resource (texture/buffer) types. This change updates it to process sampler types as well. 2. The sequencing of the passes made it possible that an opaque-typed local variable might be left around after `specializeResourceOutputs`, which would mean the code is still invalid for GLSL/SPIR-V. This change adds an additional SSA-formation pass which would eliminate any opaque-type local variables whose lifetimes were made simple enough by the optimizations. Together these changes fix a problem-case user shader that was failing to compile for Vulkan. * Update slang-emit.cpp Fix typo 'reuslt' * Update slang-emit.cpp Comment change to re-trigger CI build. Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit.cpp14
-rw-r--r--source/slang/slang-ir-specialize-resources.cpp3
2 files changed, 17 insertions, 0 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 5ecebddad..352a27746 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -459,6 +459,20 @@ Result linkAndOptimizeIR(
// pass down the target request along with the IR.
//
specializeResourceOutputs(compileRequest, targetRequest, irModule);
+ //
+ // After specialization of function outputs, we may find that there
+ // are cases where opaque-typed local variables can now be eliminated
+ // and turned into SSA temporaries. Such optimization may enable
+ // the following passes to "see" and specialize more cases.
+ //
+ // TODO: We should consider whether there are cases that will require
+ // iterating the passes as given here in order to achieve a fully
+ // specialized result. If that is the case, we might consider implementing
+ // a single combined pass that makes all of the relevant changes and
+ // iterates to convergence.
+ //
+ constructSSA(irModule);
+ //
specializeFuncsForBufferLoadArgs(compileRequest, targetRequest, irModule);
specializeResourceParameters(compileRequest, targetRequest, irModule);
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp
index 00357ca50..09db3391f 100644
--- a/source/slang/slang-ir-specialize-resources.cpp
+++ b/source/slang/slang-ir-specialize-resources.cpp
@@ -342,6 +342,9 @@ struct ResourceOutputSpecializationPass
if(as<IRByteAddressBufferTypeBase>(type))
return true;
+ if(as<IRSamplerStateTypeBase>(type))
+ return true;
+
// TODO: more cases here?
return false;