summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-util.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-27 15:18:07 -0800
committerGitHub <noreply@github.com>2023-02-27 15:18:07 -0800
commita3ba22b51c371d5a20d61aa4e35233ba4f4f68db (patch)
tree704f8e9575fdd888d01137054b4c3887aaac9360 /source/slang/slang-ir-util.cpp
parentb1b76f06ca5bdfc4b688d99095dfb7d561a04d80 (diff)
Detect and deduplicate read-only resource access. (#2680)
* Detect and deduplicate read-only resource access. * Fix tests. * Fix tests. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
-rw-r--r--source/slang/slang-ir-util.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index 339521f41..13920b011 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -157,6 +157,7 @@ IRInst* maybeSpecializeWithGeneric(IRBuilder& builder, IRInst* genericToSpecaili
return genericToSpecailize;
}
+// Returns true if is not possible to produce side-effect from a value of `dataType`.
bool isValueType(IRInst* dataType)
{
dataType = getResolvedInstForDecorations(unwrapAttributedType(dataType));
@@ -179,6 +180,15 @@ bool isValueType(IRInst* dataType)
case kIROp_FuncType:
return true;
default:
+ // Read-only resource handles are considered as Value type.
+ if (auto resType = as<IRResourceTypeBase>(dataType))
+ return (resType->getAccess() == SLANG_RESOURCE_ACCESS_READ);
+ else if (as<IRSamplerStateTypeBase>(dataType))
+ return true;
+ else if (as<IRHLSLByteAddressBufferType>(dataType))
+ return true;
+ else if (as<IRHLSLStructuredBufferType>(dataType))
+ return true;
return false;
}
}