#include <cassert>
#include <cstdlib>
#include <unordered_set>
#include <algorithm>
#include "SpvBuilder.h"
#include "hex_float.h"
#ifndef _WIN32
#include <cstdio>
#endif
namespace spv {
Builder::Builder(unsigned int spvVersion, unsigned int magicNumber, SpvBuildLogger* buildLogger) : … { … }
Builder::~Builder()
{ … }
Id Builder::import(const char* name)
{ … }
Id Builder::makeVoidType()
{ … }
Id Builder::makeBoolType()
{ … }
Id Builder::makeSamplerType()
{ … }
Id Builder::makePointer(StorageClass storageClass, Id pointee)
{ … }
Id Builder::makeForwardPointer(StorageClass storageClass)
{ … }
Id Builder::makePointerFromForwardPointer(StorageClass storageClass, Id forwardPointerType, Id pointee)
{ … }
Id Builder::makeIntegerType(int width, bool hasSign)
{ … }
Id Builder::makeFloatType(int width)
{ … }
Id Builder::makeStructType(const std::vector<Id>& members, const char* name, bool const compilerGenerated)
{ … }
Id Builder::makeStructResultType(Id type0, Id type1)
{ … }
Id Builder::makeVectorType(Id component, int size)
{ … }
Id Builder::makeMatrixType(Id component, int cols, int rows)
{ … }
Id Builder::makeCooperativeMatrixTypeKHR(Id component, Id scope, Id rows, Id cols, Id use)
{ … }
Id Builder::makeCooperativeMatrixTypeNV(Id component, Id scope, Id rows, Id cols)
{ … }
Id Builder::makeCooperativeMatrixTypeWithSameShape(Id component, Id otherType)
{ … }
Id Builder::makeGenericType(spv::Op opcode, std::vector<spv::IdImmediate>& operands)
{ … }
Id Builder::makeArrayType(Id element, Id sizeId, int stride)
{ … }
Id Builder::makeRuntimeArray(Id element)
{ … }
Id Builder::makeFunctionType(Id returnType, const std::vector<Id>& paramTypes)
{ … }
Id Builder::makeDebugFunctionType(Id returnType, const std::vector<Id>& paramTypes)
{ … }
Id Builder::makeImageType(Id sampledType, Dim dim, bool depth, bool arrayed, bool ms, unsigned sampled,
ImageFormat format)
{ … }
Id Builder::makeSampledImageType(Id imageType)
{ … }
Id Builder::makeDebugInfoNone()
{ … }
Id Builder::makeBoolDebugType(int const size)
{ … }
Id Builder::makeIntegerDebugType(int const width, bool const hasSign)
{ … }
Id Builder::makeFloatDebugType(int const width)
{ … }
Id Builder::makeSequentialDebugType(Id const baseType, Id const componentCount, NonSemanticShaderDebugInfo100Instructions const sequenceType)
{ … }
Id Builder::makeArrayDebugType(Id const baseType, Id const componentCount)
{ … }
Id Builder::makeVectorDebugType(Id const baseType, int const componentCount)
{ … }
Id Builder::makeMatrixDebugType(Id const vectorType, int const vectorCount, bool columnMajor)
{ … }
Id Builder::makeMemberDebugType(Id const memberType, DebugTypeLoc const& debugTypeLoc)
{ … }
Id Builder::makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name,
NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType)
{ … }
Id Builder::makePointerDebugType(StorageClass storageClass, Id const baseType)
{ … }
Id Builder::makeDebugSource(const Id fileName) { … }
Id Builder::makeDebugCompilationUnit() { … }
Id Builder::createDebugGlobalVariable(Id const type, char const*const name, Id const variable)
{ … }
Id Builder::createDebugLocalVariable(Id type, char const*const name, size_t const argNumber)
{ … }
Id Builder::makeDebugExpression()
{ … }
Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const pointer)
{ … }
Id Builder::makeDebugValue(Id const debugLocalVariable, Id const value)
{ … }
Id Builder::makeAccelerationStructureType()
{ … }
Id Builder::makeRayQueryType()
{ … }
Id Builder::makeHitObjectNVType()
{ … }
Id Builder::getDerefTypeId(Id resultId) const
{ … }
Op Builder::getMostBasicTypeClass(Id typeId) const
{ … }
int Builder::getNumTypeConstituents(Id typeId) const
{ … }
Id Builder::getScalarTypeId(Id typeId) const
{ … }
Id Builder::getContainedTypeId(Id typeId, int member) const
{ … }
Id Builder::getResultingAccessChainType() const
{ … }
Id Builder::getContainedTypeId(Id typeId) const
{ … }
bool Builder::containsType(Id typeId, spv::Op typeOp, unsigned int width) const
{ … }
bool Builder::containsPhysicalStorageBufferOrArray(Id typeId) const
{ … }
Id Builder::findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value)
{ … }
Id Builder::findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2)
{ … }
bool Builder::isConstantOpCode(Op opcode) const
{ … }
bool Builder::isSpecConstantOpCode(Op opcode) const
{ … }
Id Builder::makeNullConstant(Id typeId)
{ … }
Id Builder::makeBoolConstant(bool b, bool specConstant)
{ … }
Id Builder::makeIntConstant(Id typeId, unsigned value, bool specConstant)
{ … }
Id Builder::makeInt64Constant(Id typeId, unsigned long long value, bool specConstant)
{ … }
Id Builder::makeFloatConstant(float f, bool specConstant)
{ … }
Id Builder::makeDoubleConstant(double d, bool specConstant)
{ … }
Id Builder::makeFloat16Constant(float f16, bool specConstant)
{ … }
Id Builder::makeFpConstant(Id type, double d, bool specConstant)
{ … }
Id Builder::importNonSemanticShaderDebugInfoInstructions()
{ … }
Id Builder::findCompositeConstant(Op typeClass, Id typeId, const std::vector<Id>& comps)
{ … }
Id Builder::findStructConstant(Id typeId, const std::vector<Id>& comps)
{ … }
Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, bool specConstant)
{ … }
Instruction* Builder::addEntryPoint(ExecutionModel model, Function* function, const char* name)
{ … }
void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, int value1, int value2, int value3)
{ … }
void Builder::addExecutionMode(Function* entryPoint, ExecutionMode mode, const std::vector<unsigned>& literals)
{ … }
void Builder::addExecutionModeId(Function* entryPoint, ExecutionMode mode, const std::vector<Id>& operandIds)
{ … }
void Builder::addName(Id id, const char* string)
{ … }
void Builder::addMemberName(Id id, int memberNumber, const char* string)
{ … }
void Builder::addDecoration(Id id, Decoration decoration, int num)
{ … }
void Builder::addDecoration(Id id, Decoration decoration, const char* s)
{ … }
void Builder::addDecoration(Id id, Decoration decoration, const std::vector<unsigned>& literals)
{ … }
void Builder::addDecoration(Id id, Decoration decoration, const std::vector<const char*>& strings)
{ … }
void Builder::addLinkageDecoration(Id id, const char* name, spv::LinkageType linkType) { … }
void Builder::addDecorationId(Id id, Decoration decoration, Id idDecoration)
{ … }
void Builder::addDecorationId(Id id, Decoration decoration, const std::vector<Id>& operandIds)
{ … }
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, int num)
{ … }
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const char *s)
{ … }
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<unsigned>& literals)
{ … }
void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decoration, const std::vector<const char*>& strings)
{ … }
void Builder::addInstruction(std::unique_ptr<Instruction> inst) { … }
Function* Builder::makeEntryPoint(const char* entryPoint)
{ … }
Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const char* name, LinkageType linkType,
const std::vector<Id>& paramTypes,
const std::vector<std::vector<Decoration>>& decorations, Block** entry)
{ … }
void Builder::setupDebugFunctionEntry(Function* function, const char* name, int line, const std::vector<Id>& paramTypes,
const std::vector<char const*>& paramNames)
{ … }
Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id funcTypeId)
{ … }
Id Builder::makeDebugLexicalBlock(uint32_t line) { … }
std::string Builder::unmangleFunctionName(std::string const& name) const
{ … }
void Builder::makeReturn(bool implicit, Id retVal)
{ … }
void Builder::enterLexicalBlock(uint32_t line)
{ … }
void Builder::leaveLexicalBlock()
{ … }
void Builder::enterFunction(Function const* function)
{ … }
void Builder::leaveFunction()
{ … }
void Builder::makeStatementTerminator(spv::Op opcode, const char *name)
{ … }
void Builder::makeStatementTerminator(spv::Op opcode, const std::vector<Id>& operands, const char* name)
{ … }
Id Builder::createVariable(Decoration precision, StorageClass storageClass, Id type, const char* name, Id initializer,
bool const compilerGenerated)
{ … }
Id Builder::createUndefined(Id type)
{ … }
spv::MemoryAccessMask Builder::sanitizeMemoryAccessForStorageClass(spv::MemoryAccessMask memoryAccess, StorageClass sc)
const
{ … }
void Builder::createStore(Id rValue, Id lValue, spv::MemoryAccessMask memoryAccess, spv::Scope scope,
unsigned int alignment)
{ … }
Id Builder::createLoad(Id lValue, spv::Decoration precision, spv::MemoryAccessMask memoryAccess,
spv::Scope scope, unsigned int alignment)
{ … }
Id Builder::createAccessChain(StorageClass storageClass, Id base, const std::vector<Id>& offsets)
{ … }
Id Builder::createArrayLength(Id base, unsigned int member)
{ … }
Id Builder::createCooperativeMatrixLengthKHR(Id type)
{ … }
Id Builder::createCooperativeMatrixLengthNV(Id type)
{ … }
Id Builder::createCompositeExtract(Id composite, Id typeId, unsigned index)
{ … }
Id Builder::createCompositeExtract(Id composite, Id typeId, const std::vector<unsigned>& indexes)
{ … }
Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, unsigned index)
{ … }
Id Builder::createCompositeInsert(Id object, Id composite, Id typeId, const std::vector<unsigned>& indexes)
{ … }
Id Builder::createVectorExtractDynamic(Id vector, Id typeId, Id componentIndex)
{ … }
Id Builder::createVectorInsertDynamic(Id vector, Id typeId, Id component, Id componentIndex)
{ … }
void Builder::createNoResultOp(Op opCode)
{ … }
void Builder::createNoResultOp(Op opCode, Id operand)
{ … }
void Builder::createNoResultOp(Op opCode, const std::vector<Id>& operands)
{ … }
void Builder::createNoResultOp(Op opCode, const std::vector<IdImmediate>& operands)
{ … }
void Builder::createControlBarrier(Scope execution, Scope memory, MemorySemanticsMask semantics)
{ … }
void Builder::createMemoryBarrier(unsigned executionScope, unsigned memorySemantics)
{ … }
Id Builder::createUnaryOp(Op opCode, Id typeId, Id operand)
{ … }
Id Builder::createBinOp(Op opCode, Id typeId, Id left, Id right)
{ … }
Id Builder::createTriOp(Op opCode, Id typeId, Id op1, Id op2, Id op3)
{ … }
Id Builder::createOp(Op opCode, Id typeId, const std::vector<Id>& operands)
{ … }
Id Builder::createOp(Op opCode, Id typeId, const std::vector<IdImmediate>& operands)
{ … }
Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& operands,
const std::vector<unsigned>& literals)
{ … }
Id Builder::createFunctionCall(spv::Function* function, const std::vector<spv::Id>& args)
{ … }
Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, const std::vector<unsigned>& channels)
{ … }
Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, const std::vector<unsigned>& channels)
{ … }
void Builder::promoteScalar(Decoration precision, Id& left, Id& right)
{ … }
Id Builder::smearScalar(Decoration precision, Id scalar, Id vectorType)
{ … }
Id Builder::createBuiltinCall(Id resultType, Id builtins, int entryPoint, const std::vector<Id>& args)
{ … }
Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse, bool fetch, bool proj, bool gather,
bool noImplicitLod, const TextureParameters& parameters, ImageOperandsMask signExtensionMask)
{ … }
Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameters, bool isUnsignedResult)
{ … }
Id Builder::createCompositeCompare(Decoration precision, Id value1, Id value2, bool equal)
{ … }
Id Builder::createCompositeConstruct(Id typeId, const std::vector<Id>& constituents)
{ … }
Id Builder::createConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId)
{ … }
Id Builder::createMatrixConstructor(Decoration precision, const std::vector<Id>& sources, Id resultTypeId)
{ … }
Builder::If::If(Id cond, unsigned int ctrl, Builder& gb) : … { … }
void Builder::If::makeBeginElse()
{ … }
void Builder::If::makeEndIf()
{ … }
void Builder::makeSwitch(Id selector, unsigned int control, int numSegments, const std::vector<int>& caseValues,
const std::vector<int>& valueIndexToSegment, int defaultSegment,
std::vector<Block*>& segmentBlocks)
{ … }
void Builder::addSwitchBreak()
{ … }
void Builder::nextSwitchSegment(std::vector<Block*>& segmentBlock, int nextSegment)
{ … }
void Builder::endSwitch(std::vector<Block*>& )
{ … }
Block& Builder::makeNewBlock()
{ … }
Builder::LoopBlocks& Builder::makeNewLoop()
{ … }
void Builder::createLoopContinue()
{ … }
void Builder::createLoopExit()
{ … }
void Builder::closeLoop()
{ … }
void Builder::clearAccessChain()
{ … }
void Builder::accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizzleBaseType,
AccessChain::CoherentFlags coherentFlags, unsigned int alignment)
{ … }
void Builder::accessChainStore(Id rvalue, Decoration nonUniform, spv::MemoryAccessMask memoryAccess, spv::Scope scope, unsigned int alignment)
{ … }
Id Builder::accessChainLoad(Decoration precision, Decoration l_nonUniform,
Decoration r_nonUniform, Id resultType, spv::MemoryAccessMask memoryAccess,
spv::Scope scope, unsigned int alignment)
{ … }
Id Builder::accessChainGetLValue()
{ … }
Id Builder::accessChainGetInferredType()
{ … }
void Builder::dump(std::vector<unsigned int>& out) const
{ … }
Id Builder::collapseAccessChain()
{ … }
void Builder::remapDynamicSwizzle()
{ … }
void Builder::simplifyAccessChainSwizzle()
{ … }
void Builder::transferAccessChainSwizzle(bool dynamic)
{ … }
void Builder::createAndSetNoPredecessorBlock(const char* )
{ … }
void Builder::createBranch(Block* block)
{ … }
void Builder::createSelectionMerge(Block* mergeBlock, unsigned int control)
{ … }
void Builder::createLoopMerge(Block* mergeBlock, Block* continueBlock, unsigned int control,
const std::vector<unsigned int>& operands)
{ … }
void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* elseBlock)
{ … }
void Builder::dumpSourceInstructions(const spv::Id fileId, const std::string& text,
std::vector<unsigned int>& out) const
{ … }
void Builder::dumpSourceInstructions(std::vector<unsigned int>& out) const
{ … }
void Builder::dumpInstructions(std::vector<unsigned int>& out,
const std::vector<std::unique_ptr<Instruction> >& instructions) const
{ … }
void Builder::dumpModuleProcesses(std::vector<unsigned int>& out) const
{ … }
}