summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-ir-specialize-resources.cpp11
-rw-r--r--tests/library/precompiled-module-library-resource.slang5
2 files changed, 15 insertions, 1 deletions
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp
index 5e15098d4..90e3f99a0 100644
--- a/source/slang/slang-ir-specialize-resources.cpp
+++ b/source/slang/slang-ir-specialize-resources.cpp
@@ -248,7 +248,11 @@ struct ResourceOutputSpecializationPass
newFunc->removeAndDeallocate();
// Check if `oldFunc` is the reason for failing,
// Otherwise don't add to 'unspecializableFuncs'
- if(result == SpecializeFuncResult::ThisFuncFailed)
+ //
+ // Ensure oldFunc has uses, else, there is nothing to specialize here.
+ // If oldFunc has IRKeepAlive, this code should be assumed to have a
+ // "dynamic" resource value.
+ if(result == SpecializeFuncResult::ThisFuncFailed && oldFunc->hasUses())
unspecializableFuncs->add(oldFunc);
return false;
}
@@ -315,6 +319,11 @@ struct ResourceOutputSpecializationPass
specializeCallSite(oldCall, newFunc, funcInfo);
}
specializedFuncs.add(oldFunc);
+
+ // Since we can no longer fail and we are replacing all `Func` uses, 'KeepAlive'
+ // can be removed from the oldFunc so DCE can it clean-up.
+ if(auto keepAliveDecoration = oldFunc->findDecoration<IRKeepAliveDecoration>())
+ keepAliveDecoration->removeAndDeallocate();
return true;
}
diff --git a/tests/library/precompiled-module-library-resource.slang b/tests/library/precompiled-module-library-resource.slang
index 79c3daaa1..3eeab39d8 100644
--- a/tests/library/precompiled-module-library-resource.slang
+++ b/tests/library/precompiled-module-library-resource.slang
@@ -9,6 +9,11 @@ module "precompiled-module-library-resource";
public struct ResourceStruct {
public StructuredBuffer<int> buffer;
+
+ __init(StructuredBuffer<int> bufferIn)
+ {
+ buffer = bufferIn;
+ }
};
public int resource_in_parameter(StructuredBuffer<int> buffer)