diff options
| author | Yong He <yonghe@outlook.com> | 2021-08-12 13:14:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-12 13:14:15 -0700 |
| commit | 6406523511037987d8b8ab881aea41389afd57eb (patch) | |
| tree | 79f24b6cba377340c2f4d3dcf9fed78fc586f3e0 /source/slang/slang-emit-base.cpp | |
| parent | 389d21d982da34815b65b10cae63088c397eecc8 (diff) | |
Further implementation of SPIRV direct emit. (#1920)
* Further implementation of SPIRV direct emit.
This change implements:
- Struct, Vector, Matrix and Unsized Array types.
- Basic arithmetic opcodes, vector construct, swizzle etc.
- getElementPtr, getElement, fieldAddress, extractField.
- SPIRV target intrinsics with SPIRV asm code in stdlib.
- RWStructuredBuffer and StructuredBuffer.
- Pointer storage class propagation.
- Control flow.
* Fix.
Diffstat (limited to 'source/slang/slang-emit-base.cpp')
| -rw-r--r-- | source/slang/slang-emit-base.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/slang/slang-emit-base.cpp b/source/slang/slang-emit-base.cpp new file mode 100644 index 000000000..d00b723ab --- /dev/null +++ b/source/slang/slang-emit-base.cpp @@ -0,0 +1,55 @@ +#include "slang-emit-base.h" + +namespace Slang +{ + +IRInst* SourceEmitterBase::getSpecializedValue(IRSpecialize* specInst) +{ + auto base = specInst->getBase(); + + // It is possible to have a `specialize(...)` where the first + // operand is also a `specialize(...)`, so that we need to + // look at what declaration is being specialized at the inner + // step to find the one being specialized at the outer step. + // + while (auto baseSpecialize = as<IRSpecialize>(base)) + { + base = getSpecializedValue(baseSpecialize); + } + + auto baseGeneric = as<IRGeneric>(base); + if (!baseGeneric) + return base; + + auto lastBlock = baseGeneric->getLastBlock(); + if (!lastBlock) + return base; + + auto returnInst = as<IRReturnVal>(lastBlock->getTerminator()); + if (!returnInst) + return base; + + return returnInst->getVal(); +} + +void SourceEmitterBase::handleRequiredCapabilities(IRInst* inst) +{ + auto decoratedValue = inst; + while (auto specInst = as<IRSpecialize>(decoratedValue)) + { + decoratedValue = getSpecializedValue(specInst); + } + + handleRequiredCapabilitiesImpl(decoratedValue); +} + +IRVarLayout* SourceEmitterBase::getVarLayout(IRInst* var) +{ + auto decoration = var->findDecoration<IRLayoutDecoration>(); + if (!decoration) + return nullptr; + + return as<IRVarLayout>(decoration->getLayout()); +} + +} |
