summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-emit.cpp6
-rw-r--r--source/slang/slang-ir-specialize-buffer-load-arg.cpp2
2 files changed, 7 insertions, 1 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 804a44b81..7d72fb77f 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -1402,6 +1402,12 @@ Result linkAndOptimizeIR(
// function parameters, reults, etc. is invalid.
// We clean up the usages of resource values here.
specializeResourceUsage(codeGenContext, irModule);
+
+ // Specialize calls to functions with values loaded from an immutable location,
+ // so that we directly load the value inside the callee, instead of loading the
+ // value outside of the callee and copy it in. This is necessary to avoid copying
+ // large values (e.g. arrays) in registers, where most of the elements are not
+ // actually used.
specializeFuncsForBufferLoadArgs(codeGenContext, irModule);
// Push `structuredBufferLoad` to the end of access chain to avoid loading unnecessary data.
diff --git a/source/slang/slang-ir-specialize-buffer-load-arg.cpp b/source/slang/slang-ir-specialize-buffer-load-arg.cpp
index a5a3dd2d9..c473c6047 100644
--- a/source/slang/slang-ir-specialize-buffer-load-arg.cpp
+++ b/source/slang/slang-ir-specialize-buffer-load-arg.cpp
@@ -89,7 +89,7 @@ struct FuncBufferLoadSpecializationCondition : FunctionCallSpecializeCondition
a = argLoad->getPtr();
// We can safely defer a load to the callee if the source dest is immutable.
- if (isPointerToImmutableLocation(a))
+ if (isPointerToImmutableLocation(getRootAddr(a)))
continue;
// Otherwise, we check if there is no other instructions in between the load and the