diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-07-21 16:28:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-21 13:28:01 -0700 |
| commit | 32043a48b6503fe3e493082c33eac02865503031 (patch) | |
| tree | 163ec769bb2fabcd267e96b635d822d5b2c8dc19 /source/slang/slang-emit-c-like.cpp | |
| parent | e0a856b8f101ad66159fa9779c36fcc723f611f6 (diff) | |
Better handling of bindings with multiple resource kind "aliases" for GLSL emit (#3009)
* A more way robust way to handle resource consumption might use multiple `kind`s on GLSL emit.
* Improve method naming and some comments.
* Small consistency fix.
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 718653545..b05174b0a 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -605,6 +605,48 @@ void CLikeSourceEmitter::emitVal(IRInst* val, EmitOpInfo const& outerPrec) } } +UInt CLikeSourceEmitter::getBindingOffsetForKinds(EmitVarChain* chain, LayoutResourceKindFlags kindFlags) +{ + UInt offset = 0; + for (auto cc = chain; cc; cc = cc->next) + { + for (auto offsetAttr : cc->varLayout->getOffsetAttrs()) + { + // Accumulate offset for all matching kind + if (LayoutResourceKindFlag::make(offsetAttr->getResourceKind()) & kindFlags) + { + offset += offsetAttr->getOffset(); + } + } + } + + return offset; +} + +UInt CLikeSourceEmitter::getBindingSpaceForKinds(EmitVarChain* chain, LayoutResourceKindFlags kindFlags) +{ + UInt space = 0; + for (auto cc = chain; cc; cc = cc->next) + { + auto varLayout = cc->varLayout; + + for (auto offsetAttr : cc->varLayout->getOffsetAttrs()) + { + // Accumulate offset for all matching kinds + if (LayoutResourceKindFlag::make(offsetAttr->getResourceKind()) & kindFlags) + { + space += offsetAttr->getSpace(); + } + } + + if (auto resInfo = varLayout->findOffsetAttr(LayoutResourceKind::RegisterSpace)) + { + space += resInfo->getOffset(); + } + } + return space; +} + UInt CLikeSourceEmitter::getBindingOffset(EmitVarChain* chain, LayoutResourceKind kind) { UInt offset = 0; |
