diff options
| author | Yong He <yonghe@outlook.com> | 2023-02-27 15:18:07 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-27 15:18:07 -0800 |
| commit | a3ba22b51c371d5a20d61aa4e35233ba4f4f68db (patch) | |
| tree | 704f8e9575fdd888d01137054b4c3887aaac9360 /source/slang/slang-emit-c-like.cpp | |
| parent | b1b76f06ca5bdfc4b688d99095dfb7d561a04d80 (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-emit-c-like.cpp')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 7840dc450..a31c16505 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1344,6 +1344,30 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst) } } + // If this is a call to a ResourceType's member function, don't fold for readability. + if (auto call = as<IRCall>(inst)) + { + auto callee = getResolvedInstForDecorations(call->getCallee()); + if (callee->findDecoration<IRTargetIntrinsicDecoration>()) + { + auto funcType = as<IRFuncType>(callee->getDataType()); + if (funcType) + { + if (funcType->getParamCount() > 0) + { + auto firstParamType = funcType->getParamType(0); + if (as<IRResourceTypeBase>(firstParamType)) + return false; + if (as<IRHLSLStructuredBufferTypeBase>(firstParamType)) + return false; + if (as<IRUntypedBufferResourceType>(firstParamType)) + return false; + if (as<IRSamplerStateTypeBase>(firstParamType)) + return false; + } + } + } + } // We'd like to figure out if it is safe to fold our instruction into `user` // First, let's make sure they are in the same block/parent: |
