https://github.com/shader-slang/slang
Raw File
Tip revision: d06a78d935b2743494d47ed5cd3f36e38ac9c5ac authored by Yong He on 04 February 2022, 03:17:30 UTC
Add gfx interop to allow more direct D3D12 usage scenarios. (#2117)
Tip revision: d06a78d
slang-emit-base.cpp
#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());
}

BaseType SourceEmitterBase::extractBaseType(IRType* inType)
{
    auto type = inType;
    for (;;)
    {
        if (auto irBaseType = as<IRBasicType>(type))
        {
            return irBaseType->getBaseType();
        }
        else if (auto vecType = as<IRVectorType>(type))
        {
            type = vecType->getElementType();
            continue;
        }
        else
        {
            return BaseType::Void;
        }
    }
}

}
back to top