From 6406523511037987d8b8ab881aea41389afd57eb Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 12 Aug 2021 13:14:15 -0700 Subject: 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. --- source/slang/slang-emit-base.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 source/slang/slang-emit-base.cpp (limited to 'source/slang/slang-emit-base.cpp') 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(base)) + { + base = getSpecializedValue(baseSpecialize); + } + + auto baseGeneric = as(base); + if (!baseGeneric) + return base; + + auto lastBlock = baseGeneric->getLastBlock(); + if (!lastBlock) + return base; + + auto returnInst = as(lastBlock->getTerminator()); + if (!returnInst) + return base; + + return returnInst->getVal(); +} + +void SourceEmitterBase::handleRequiredCapabilities(IRInst* inst) +{ + auto decoratedValue = inst; + while (auto specInst = as(decoratedValue)) + { + decoratedValue = getSpecializedValue(specInst); + } + + handleRequiredCapabilitiesImpl(decoratedValue); +} + +IRVarLayout* SourceEmitterBase::getVarLayout(IRInst* var) +{ + auto decoration = var->findDecoration(); + if (!decoration) + return nullptr; + + return as(decoration->getLayout()); +} + +} -- cgit v1.2.3