Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLMatrixType.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLMatrixType.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "llvm/IR/IRBuilder.h"
namespace llvm {
template <typename T> class ArrayRef;
class Type;
class Value;
class Constant;
class StructType;
class VectorType;
class StoreInst;
} // namespace llvm
namespace hlsl {
class DxilFieldAnnotation;
class DxilTypeSystem;
// A high-level matrix type in LLVM IR.
//
// Matrices are represented by an llvm struct type of the following form:
// { [RowCount x <ColCount x RegReprTy>] }
// Note that the element type is always in its register representation (ie bools
// are i1s). This allows preserving the original type and is okay since matrix
// types are only manipulated in an opaque way, through intrinsics.
//
// During matrix lowering, matrices are converted to vectors of the following
// form: <RowCount*ColCount x Ty> At this point, register vs memory
// representation starts to matter and we have to imitate the codegen for scalar
// and vector bools: i1s when in llvm registers, and i32s when in memory
// (allocas, pointers, or in structs/lists, which are always in memory).
//
// This class is designed to resemble a llvm::Type-derived class.
class HLMatrixType {
public:
static constexpr const char *StructNamePrefix = "class.matrix.";
HLMatrixType() : RegReprElemTy(nullptr), NumRows(0), NumColumns(0) {}
HLMatrixType(llvm::Type *RegReprElemTy, unsigned NumRows,
unsigned NumColumns);
// We allow default construction to an invalid state to support the dynCast
// pattern. This tests whether we have a legit object.
operator bool() const { return RegReprElemTy != nullptr; }
llvm::Type *getElementType(bool MemRepr) const;
llvm::Type *getElementTypeForReg() const { return getElementType(false); }
llvm::Type *getElementTypeForMem() const { return getElementType(true); }
unsigned getNumRows() const { return NumRows; }
unsigned getNumColumns() const { return NumColumns; }
unsigned getNumElements() const { return NumRows * NumColumns; }
unsigned getRowMajorIndex(unsigned RowIdx, unsigned ColIdx) const;
unsigned getColumnMajorIndex(unsigned RowIdx, unsigned ColIdx) const;
static unsigned getRowMajorIndex(unsigned RowIdx, unsigned ColIdx,
unsigned NumRows, unsigned NumColumns);
static unsigned getColumnMajorIndex(unsigned RowIdx, unsigned ColIdx,
unsigned NumRows, unsigned NumColumns);
llvm::VectorType *getLoweredVectorType(bool MemRepr) const;
llvm::VectorType *getLoweredVectorTypeForReg() const {
return getLoweredVectorType(false);
}
llvm::VectorType *getLoweredVectorTypeForMem() const {
return getLoweredVectorType(true);
}
llvm::Value *emitLoweredMemToReg(llvm::Value *Val,
llvm::IRBuilder<> &Builder) const;
llvm::Value *emitLoweredRegToMem(llvm::Value *Val,
llvm::IRBuilder<> &Builder) const;
llvm::Value *emitLoweredLoad(llvm::Value *Ptr,
llvm::IRBuilder<> &Builder) const;
llvm::StoreInst *emitLoweredStore(llvm::Value *Val, llvm::Value *Ptr,
llvm::IRBuilder<> &Builder) const;
llvm::Value *emitLoweredVectorRowToCol(llvm::Value *VecVal,
llvm::IRBuilder<> &Builder) const;
llvm::Value *emitLoweredVectorColToRow(llvm::Value *VecVal,
llvm::IRBuilder<> &Builder) const;
static bool isa(llvm::Type *Ty);
static bool isMatrixPtr(llvm::Type *Ty);
static bool isMatrixArray(llvm::Type *Ty);
static bool isMatrixArrayPtr(llvm::Type *Ty);
static bool isMatrixPtrOrArrayPtr(llvm::Type *Ty);
static bool isMatrixOrPtrOrArrayPtr(llvm::Type *Ty);
static llvm::Type *getLoweredType(llvm::Type *Ty, bool MemRepr = false);
static HLMatrixType cast(llvm::Type *Ty);
static HLMatrixType dyn_cast(llvm::Type *Ty);
private:
llvm::Type *RegReprElemTy;
unsigned NumRows, NumColumns;
};
} // namespace hlsl |
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/DxilPackSignatureElement.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSignatureElement.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Class to pack HLSL signature element. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilCompType.h"
#include "dxc/DXIL/DxilInterpolationMode.h"
#include "dxc/DXIL/DxilSemantic.h"
#include "dxc/DXIL/DxilSignatureElement.h"
#include "dxc/HLSL/DxilSignatureAllocator.h"
#include "llvm/ADT/StringRef.h"
#include <limits.h>
#include <string>
#include <vector>
namespace hlsl {
class ShaderModel;
class DxilPackElement : public DxilSignatureAllocator::PackElement {
DxilSignatureElement *m_pSE;
bool m_bUseMinPrecision;
public:
DxilPackElement(DxilSignatureElement *pSE, bool useMinPrecision)
: m_pSE(pSE), m_bUseMinPrecision(useMinPrecision) {}
~DxilPackElement() override {}
uint32_t GetID() const override { return m_pSE->GetID(); }
DXIL::SemanticKind GetKind() const override { return m_pSE->GetKind(); }
DXIL::InterpolationMode GetInterpolationMode() const override {
return m_pSE->GetInterpolationMode()->GetKind();
}
DXIL::SemanticInterpretationKind GetInterpretation() const override {
return m_pSE->GetInterpretation();
}
DXIL::SignatureDataWidth GetDataBitWidth() const override {
uint8_t size = m_pSE->GetCompType().GetSizeInBits();
// bool, min precision, or 32 bit types map to 32 bit size.
if (size == 16) {
return m_bUseMinPrecision ? DXIL::SignatureDataWidth::Bits32
: DXIL::SignatureDataWidth::Bits16;
} else if (size == 1 || size == 32) {
return DXIL::SignatureDataWidth::Bits32;
}
return DXIL::SignatureDataWidth::Undefined;
}
uint32_t GetRows() const override { return m_pSE->GetRows(); }
uint32_t GetCols() const override { return m_pSE->GetCols(); }
bool IsAllocated() const override { return m_pSE->IsAllocated(); }
uint32_t GetStartRow() const override { return m_pSE->GetStartRow(); }
uint32_t GetStartCol() const override { return m_pSE->GetStartCol(); }
void ClearLocation() override {
m_pSE->SetStartRow(-1);
m_pSE->SetStartCol(-1);
}
void SetLocation(uint32_t Row, uint32_t Col) override {
m_pSE->SetStartRow(Row);
m_pSE->SetStartCol(Col);
}
DxilSignatureElement *Get() { return m_pSE; }
};
class DxilSignature;
// Packs the signature elements per DXIL constraints and returns the number of
// rows used for the signature.
unsigned PackDxilSignature(DxilSignature &sig, DXIL::PackingStrategy packing);
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/DxilGenerationPass.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilGenerationPass.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// This file provides a DXIL Generation pass. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
namespace llvm {
class Module;
class ModulePass;
class Function;
class FunctionPass;
class Instruction;
class PassRegistry;
class StringRef;
struct PostDominatorTree;
} // namespace llvm
namespace hlsl {
class DxilResourceBase;
class WaveSensitivityAnalysis {
public:
static WaveSensitivityAnalysis *create(llvm::PostDominatorTree &PDT);
virtual ~WaveSensitivityAnalysis() {}
virtual void Analyze(llvm::Function *F) = 0;
virtual bool IsWaveSensitive(llvm::Instruction *op) = 0;
};
class HLSLExtensionsCodegenHelper;
// Pause/resume support.
bool ClearPauseResumePasses(
llvm::Module &M); // true if modified; false if missing
void GetPauseResumePasses(llvm::Module &M, llvm::StringRef &pause,
llvm::StringRef &resume);
void SetPauseResumePasses(llvm::Module &M, llvm::StringRef pause,
llvm::StringRef resume);
} // namespace hlsl
namespace llvm {
/// \brief Create and return a pass that tranform the module into a DXIL module
/// Note that this pass is designed for use with the legacy pass manager.
ModulePass *createDxilLowerCreateHandleForLibPass();
ModulePass *createDxilAllocateResourcesForLibPass();
ModulePass *createDxilCleanupDynamicResourceHandlePass();
ModulePass *createDxilEliminateOutputDynamicIndexingPass();
ModulePass *
createDxilGenerationPass(bool NotOptimized,
hlsl::HLSLExtensionsCodegenHelper *extensionsHelper);
ModulePass *createHLEmitMetadataPass();
ModulePass *createHLEnsureMetadataPass();
ModulePass *createDxilFinalizeModulePass();
ModulePass *createDxilEmitMetadataPass();
FunctionPass *createDxilExpandTrigIntrinsicsPass();
ModulePass *createDxilConvergentMarkPass();
ModulePass *createDxilConvergentClearPass();
ModulePass *createDxilDeadFunctionEliminationPass();
ModulePass *createHLDeadFunctionEliminationPass();
ModulePass *createHLPreprocessPass();
ModulePass *createDxilPrecisePropagatePass();
FunctionPass *createDxilPreserveAllOutputsPass();
FunctionPass *createDxilPromoteLocalResources();
ModulePass *createDxilPromoteStaticResources();
ModulePass *createDxilLegalizeResources();
ModulePass *createDxilLegalizeEvalOperationsPass();
FunctionPass *createDxilLegalizeSampleOffsetPass();
FunctionPass *createDxilSimpleGVNHoistPass();
ModulePass *createInvalidateUndefResourcesPass();
FunctionPass *createSimplifyInstPass();
ModulePass *createDxilTranslateRawBuffer();
ModulePass *createNoPausePassesPass();
ModulePass *createPausePassesPass();
ModulePass *createResumePassesPass();
FunctionPass *createMatrixBitcastLowerPass();
ModulePass *createDxilCleanupAddrSpaceCastPass();
ModulePass *createDxilRenameResourcesPass();
void initializeDxilLowerCreateHandleForLibPass(llvm::PassRegistry &);
void initializeDxilAllocateResourcesForLibPass(llvm::PassRegistry &);
void initializeDxilCleanupDynamicResourceHandlePass(llvm::PassRegistry &);
void initializeDxilEliminateOutputDynamicIndexingPass(llvm::PassRegistry &);
void initializeDxilGenerationPassPass(llvm::PassRegistry &);
void initializeHLEnsureMetadataPass(llvm::PassRegistry &);
void initializeHLEmitMetadataPass(llvm::PassRegistry &);
void initializeDxilFinalizeModulePass(llvm::PassRegistry &);
void initializeDxilEmitMetadataPass(llvm::PassRegistry &);
void initializeDxilEraseDeadRegionPass(llvm::PassRegistry &);
void initializeDxilExpandTrigIntrinsicsPass(llvm::PassRegistry &);
void initializeDxilDeadFunctionEliminationPass(llvm::PassRegistry &);
void initializeHLDeadFunctionEliminationPass(llvm::PassRegistry &);
void initializeHLPreprocessPass(llvm::PassRegistry &);
void initializeDxilConvergentMarkPass(llvm::PassRegistry &);
void initializeDxilConvergentClearPass(llvm::PassRegistry &);
void initializeDxilPrecisePropagatePassPass(llvm::PassRegistry &);
void initializeDxilPreserveAllOutputsPass(llvm::PassRegistry &);
void initializeDxilPromoteLocalResourcesPass(llvm::PassRegistry &);
void initializeDxilPromoteStaticResourcesPass(llvm::PassRegistry &);
void initializeDxilLegalizeResourcesPass(llvm::PassRegistry &);
void initializeDxilLegalizeEvalOperationsPass(llvm::PassRegistry &);
void initializeDxilLegalizeSampleOffsetPassPass(llvm::PassRegistry &);
void initializeDxilSimpleGVNHoistPass(llvm::PassRegistry &);
void initializeInvalidateUndefResourcesPass(llvm::PassRegistry &);
void initializeSimplifyInstPass(llvm::PassRegistry &);
void initializeDxilTranslateRawBufferPass(llvm::PassRegistry &);
void initializeNoPausePassesPass(llvm::PassRegistry &);
void initializePausePassesPass(llvm::PassRegistry &);
void initializeResumePassesPass(llvm::PassRegistry &);
void initializeMatrixBitcastLowerPassPass(llvm::PassRegistry &);
void initializeDxilCleanupAddrSpaceCastPass(llvm::PassRegistry &);
void initializeDxilRenameResourcesPass(llvm::PassRegistry &);
ModulePass *createDxilValidateWaveSensitivityPass();
void initializeDxilValidateWaveSensitivityPass(llvm::PassRegistry &);
FunctionPass *createCleanupDxBreakPass();
void initializeCleanupDxBreakPass(llvm::PassRegistry &);
FunctionPass *createDxilLoopDeletionPass(bool NoSink);
void initializeDxilLoopDeletionPass(llvm::PassRegistry &);
ModulePass *createHLLegalizeParameter();
void initializeHLLegalizeParameterPass(llvm::PassRegistry &);
bool AreDxilResourcesDense(llvm::Module *M,
hlsl::DxilResourceBase **ppNonDense);
ModulePass *createDxilNoOptLegalizePass();
void initializeDxilNoOptLegalizePass(llvm::PassRegistry &);
ModulePass *createDxilNoOptSimplifyInstructionsPass();
void initializeDxilNoOptSimplifyInstructionsPass(llvm::PassRegistry &);
ModulePass *createDxilMutateResourceToHandlePass();
void initializeDxilMutateResourceToHandlePass(llvm::PassRegistry &);
ModulePass *createDxilDeleteRedundantDebugValuesPass();
void initializeDxilDeleteRedundantDebugValuesPass(llvm::PassRegistry &);
FunctionPass *createDxilSimpleGVNEliminateRegionPass();
void initializeDxilSimpleGVNEliminateRegionPass(llvm::PassRegistry &);
ModulePass *createDxilModuleInitPass();
void initializeDxilModuleInitPass(llvm::PassRegistry &);
} // namespace llvm
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLSLExtensionsCodegenHelper.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLSLExtensionsCodegenHelper.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Codegen support for hlsl extensions. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilOperations.h"
#include "dxc/Support/DxcOptToggles.h"
#include <string>
#include <vector>
namespace clang {
class CodeGenOptions;
}
namespace llvm {
class CallInst;
class Value;
class Module;
} // namespace llvm
namespace hlsl {
// Provide DXIL codegen support for private HLSL extensions.
// The HLSL extension mechanism has hooks for two cases:
//
// 1. You can mark certain defines as "semantic" defines which
// will be preserved as metadata in the final DXIL.
// 2. You can add new HLSL intrinsic functions.
// 3. You can read a root signature from a custom define.
//
// This class provides an interface for generating the DXIL bitcode
// needed for the types of extensions above.
//
class HLSLExtensionsCodegenHelper {
public:
// Used to indicate a semantic define was used incorrectly.
// Since semantic defines have semantic meaning it is possible
// that a programmer can use them incorrectly. This class provides
// a way to signal the error to the programmer. Semantic define
// errors will be propagated as errors to the clang frontend.
class SemanticDefineError {
public:
enum class Level { Warning, Error };
SemanticDefineError(unsigned location, Level level,
const std::string &message)
: m_location(location), m_level(level), m_message(message) {}
unsigned Location() const { return m_location; }
bool IsWarning() const { return m_level == Level::Warning; }
const std::string &Message() const { return m_message; }
private:
unsigned m_location; // Use an encoded clang::SourceLocation to avoid a
// clang include dependency.
Level m_level;
std::string m_message;
};
typedef std::vector<SemanticDefineError> SemanticDefineErrorList;
// Write semantic defines as metadata in the module.
virtual void WriteSemanticDefines(llvm::Module *M) = 0;
virtual void UpdateCodeGenOptions(clang::CodeGenOptions &CGO) = 0;
// Query the named option enable
// Needed because semantic defines may have set it since options were copied
virtual bool IsOptionEnabled(hlsl::options::Toggle toggle) = 0;
// Get the name to use for the dxil intrinsic function.
virtual std::string GetIntrinsicName(unsigned opcode) = 0;
// Get the dxil opcode the extension should use when lowering with
// dxil lowering strategy.
//
// Returns true if the opcode was successfully mapped to a dxil opcode.
virtual bool GetDxilOpcode(unsigned opcode, OP::OpCode &dxilOpcode) = 0;
// Struct to hold a root signature that is read from a define.
struct CustomRootSignature {
std::string RootSignature;
unsigned EncodedSourceLocation;
enum Status { NOT_FOUND = 0, FOUND };
};
// Get custom defined root signature.
virtual CustomRootSignature::Status
GetCustomRootSignature(CustomRootSignature *out) = 0;
// Virtual destructor.
virtual ~HLSLExtensionsCodegenHelper(){};
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/DxilSignatureAllocator.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSignatureAllocator.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Classes used for allocating signature elements. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilConstants.h"
#include <vector>
namespace hlsl {
class DxilSignatureAllocator {
public:
class PackElement {
public:
virtual ~PackElement() {}
virtual uint32_t GetID() const = 0;
virtual DXIL::SemanticKind GetKind() const = 0;
virtual DXIL::InterpolationMode GetInterpolationMode() const = 0;
virtual DXIL::SemanticInterpretationKind GetInterpretation() const = 0;
virtual DXIL::SignatureDataWidth GetDataBitWidth() const = 0;
virtual uint32_t GetRows() const = 0;
virtual uint32_t GetCols() const = 0;
virtual bool IsAllocated() const = 0;
virtual uint32_t GetStartRow() const = 0;
virtual uint32_t GetStartCol() const = 0;
virtual void ClearLocation() = 0;
virtual void SetLocation(uint32_t StartRow, uint32_t StartCol) = 0;
};
class DummyElement : public PackElement {
public:
uint32_t id;
uint32_t rows, cols;
uint32_t row, col;
DXIL::SemanticKind kind;
DXIL::InterpolationMode interpolation;
DXIL::SemanticInterpretationKind interpretation;
DXIL::SignatureDataWidth dataBitWidth;
uint32_t indexFlags;
public:
DummyElement(uint32_t index = 0)
: id(index), rows(1), cols(1), row((uint32_t)-1), col((uint32_t)-1),
kind(DXIL::SemanticKind::Arbitrary),
interpolation(DXIL::InterpolationMode::Undefined),
interpretation(DXIL::SemanticInterpretationKind::Arb),
dataBitWidth(DXIL::SignatureDataWidth::Undefined), indexFlags(0) {}
~DummyElement() override {}
uint32_t GetID() const override { return id; }
DXIL::SemanticKind GetKind() const override { return kind; }
DXIL::InterpolationMode GetInterpolationMode() const override {
return interpolation;
}
DXIL::SemanticInterpretationKind GetInterpretation() const override {
return interpretation;
}
DXIL::SignatureDataWidth GetDataBitWidth() const override {
return dataBitWidth;
}
uint32_t GetRows() const override { return rows; }
uint32_t GetCols() const override { return cols; }
bool IsAllocated() const override { return row != (uint32_t)-1; }
uint32_t GetStartRow() const override { return row; }
uint32_t GetStartCol() const override { return col; }
void ClearLocation() override { row = col = (uint32_t)-1; }
void SetLocation(uint32_t Row, uint32_t Col) override {
row = Row;
col = Col;
}
};
// index flags
static const uint8_t kIndexedUp = 1 << 0; // Indexing continues upwards
static const uint8_t kIndexedDown = 1 << 1; // Indexing continues downwards
static uint8_t GetIndexFlags(unsigned row, unsigned rows) {
return ((row > 0) ? kIndexedUp : 0) | ((row < rows - 1) ? kIndexedDown : 0);
}
// element flags
static const uint8_t kEFOccupied = 1 << 0;
static const uint8_t kEFArbitrary = 1 << 1;
static const uint8_t kEFSGV = 1 << 2;
static const uint8_t kEFSV = 1 << 3;
static const uint8_t kEFTessFactor = 1 << 4;
static const uint8_t kEFClipCull = 1 << 5;
static const uint8_t kEFConflictsWithIndexed = kEFSGV | kEFSV;
static uint8_t GetElementFlags(const PackElement *SE);
// The following two functions enforce the rules of component ordering when
// packing different kinds of elements into the same register.
// given element flags, return element flags that conflict when placed to the
// left of the element
static uint8_t GetConflictFlagsLeft(uint8_t flags);
// given element flags, return element flags that conflict when placed to the
// right of the element
static uint8_t GetConflictFlagsRight(uint8_t flags);
enum ConflictType {
kNoConflict = 0,
kConflictsWithIndexed,
kConflictsWithIndexedTessFactor,
kConflictsWithInterpolationMode,
kInsufficientFreeComponents,
kOverlapElement,
kIllegalComponentOrder,
kConflictFit,
kConflictDataWidth,
};
struct PackedRegister {
// Flags:
// - for occupied components, they signify element flags
// - for unoccupied components, they signify conflict flags
uint8_t Flags[4];
DXIL::InterpolationMode Interp : 8;
uint8_t IndexFlags : 2;
uint8_t IndexingFixed : 1;
DXIL::SignatureDataWidth
DataWidth; // length of each scalar type in bytes. (2 or 4 for now)
PackedRegister();
ConflictType DetectRowConflict(uint8_t flags, uint8_t indexFlags,
DXIL::InterpolationMode interp,
unsigned width,
DXIL::SignatureDataWidth dataWidth);
ConflictType DetectColConflict(uint8_t flags, unsigned col, unsigned width);
void PlaceElement(uint8_t flags, uint8_t indexFlags,
DXIL::InterpolationMode interp, unsigned col,
unsigned width, DXIL::SignatureDataWidth dataWidth);
};
DxilSignatureAllocator(unsigned numRegisters, bool useMinPrecision);
bool GetIgnoreIndexing() const { return m_bIgnoreIndexing; }
void SetIgnoreIndexing(bool ignoreIndexing) {
m_bIgnoreIndexing = ignoreIndexing;
}
ConflictType DetectRowConflict(const PackElement *SE, unsigned row);
ConflictType DetectColConflict(const PackElement *SE, unsigned row,
unsigned col);
void PlaceElement(const PackElement *SE, unsigned row, unsigned col);
// FindNext/PackNext return found/packed location + element rows if found,
// otherwise, they return 0.
unsigned FindNext(unsigned &foundRow, unsigned &foundCol, PackElement *SE,
unsigned startRow, unsigned numRows, unsigned startCol = 0);
unsigned PackNext(PackElement *SE, unsigned startRow, unsigned numRows,
unsigned startCol = 0);
// Simple greedy in-order packer used by PackOptimized
unsigned PackGreedy(std::vector<PackElement *> elements, unsigned startRow,
unsigned numRows, unsigned startCol = 0);
// Optimized packing algorithm - appended elements may affect positions of
// prior elements.
unsigned PackOptimized(std::vector<PackElement *> elements, unsigned startRow,
unsigned numRows);
// Pack in a prefix-stable way - appended elements do not affect positions of
// prior elements.
unsigned PackPrefixStable(std::vector<PackElement *> elements,
unsigned startRow, unsigned numRows);
bool UseMinPrecision() const { return m_bUseMinPrecision; }
protected:
std::vector<PackedRegister> m_Registers;
bool m_bIgnoreIndexing;
bool m_bUseMinPrecision;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/ViewIDPipelineValidation.inl | ///////////////////////////////////////////////////////////////////////////////
// //
// ViewIDPipelineValidation.inl //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// This file implements inter-stage validation for ViewID. //
// //
///////////////////////////////////////////////////////////////////////////////
namespace hlsl {
namespace {
typedef std::vector<DxilSignatureAllocator::DummyElement> ElementVec;
struct ComponentMask : public PSVComponentMask {
uint32_t Data[4];
ComponentMask() : PSVComponentMask(Data, 0) { memset(Data, 0, sizeof(Data)); }
ComponentMask(const ComponentMask &other)
: PSVComponentMask(Data, other.NumVectors) {
*this = other;
}
ComponentMask(const PSVComponentMask &other)
: PSVComponentMask(Data, other.NumVectors) {
*this = other;
}
ComponentMask &operator=(const PSVComponentMask &other) {
NumVectors = other.NumVectors;
if (other.Mask && NumVectors) {
memcpy(Data, other.Mask,
sizeof(uint32_t) * PSVComputeMaskDwordsFromVectors(NumVectors));
} else {
memset(Data, 0, sizeof(Data));
}
return *this;
}
ComponentMask &operator=(const ComponentMask &other) {
*this = (const PSVComponentMask &)other;
return *this;
}
ComponentMask &operator|=(const PSVComponentMask &other) {
NumVectors = std::max(NumVectors, other.NumVectors);
PSVComponentMask::operator|=(other);
return *this;
}
};
static void InitElement(DxilSignatureAllocator::DummyElement &eOut,
const PSVSignatureElement &eIn,
DXIL::SigPointKind sigPoint) {
eOut.rows = eIn.GetRows();
eOut.cols = eIn.GetCols();
eOut.row = eIn.GetStartRow();
eOut.col = eIn.GetStartCol();
eOut.kind = (DXIL::SemanticKind)eIn.GetSemanticKind();
eOut.interpolation = (DXIL::InterpolationMode)eIn.GetInterpolationMode();
eOut.interpretation = SigPoint::GetInterpretation(eOut.kind, sigPoint, 6, 1);
eOut.indexFlags = eIn.GetDynamicIndexMask();
// Tessfactors must be treated as dynamically indexed to prevent breaking them
// up
if (eOut.interpretation == DXIL::SemanticInterpretationKind::TessFactor)
eOut.indexFlags = (1 << eOut.cols) - 1;
}
static void
CopyElements(ElementVec &outElements, DXIL::SigPointKind sigPoint,
unsigned numElements, unsigned streamIndex,
std::function<PSVSignatureElement(unsigned)> getElement) {
outElements.clear();
outElements.reserve(numElements);
for (unsigned i = 0; i < numElements; i++) {
auto inEl = getElement(i);
if (!inEl.IsAllocated() || inEl.GetOutputStream() != streamIndex)
continue;
outElements.emplace_back(i);
DxilSignatureAllocator::DummyElement &el = outElements.back();
InitElement(el, inEl, sigPoint);
}
}
static void AddViewIDElements(ElementVec &outElements, ElementVec &inElements,
PSVComponentMask &mask, unsigned viewIDCount) {
// Compute needed elements
for (unsigned adding = 0; adding < 2; adding++) {
uint32_t numElements = 0;
for (auto &E : inElements) {
for (uint32_t row = 0; row < E.rows; row++) {
for (uint32_t col = 0; col < E.cols; col++) {
bool bDynIndex = E.indexFlags & (1 << col);
if (row > 0 && bDynIndex)
continue;
if (adding) {
uint32_t componentIndex =
(E.GetStartRow() + row) * 4 + E.GetStartCol() + col;
DxilSignatureAllocator::DummyElement NE(E.id);
NE.kind = E.kind;
NE.interpolation = E.interpolation;
// All elements interpreted as Arbitrary for packing purposes
NE.interpretation = DXIL::SemanticInterpretationKind::Arb;
NE.rows = bDynIndex ? E.GetRows() : 1;
for (uint32_t indexedRow = 0; indexedRow < NE.rows; indexedRow++) {
if (mask.Get(componentIndex + (4 * indexedRow))) {
NE.rows *= viewIDCount;
break;
}
}
outElements.push_back(NE);
}
numElements++;
}
}
}
if (!adding)
outElements.reserve(numElements);
}
}
static bool CheckFit(ElementVec &elements) {
std::vector<DxilSignatureAllocator::PackElement *> packElements;
packElements.reserve(elements.size());
for (auto &E : elements)
packElements.push_back(&E);
// Since we are putting an upper limit of 4x32 registers regardless of actual
// element size, we can just have allocator to use the default behavior. This
// should be fixed if we enforce loose upper limit on total number of
// signature registers based on element size.
DxilSignatureAllocator alloc(32, true);
alloc.SetIgnoreIndexing(true);
alloc.PackOptimized(packElements, 0, 32);
for (auto &E : elements) {
if (!E.IsAllocated())
return false;
}
return true;
}
static bool CheckMaxVertexCount(const ElementVec &elements,
unsigned maxVertexCount) {
unsigned numComponents = 0;
for (auto &E : elements)
numComponents += E.GetRows() * E.GetCols();
return numComponents <= 1024 && maxVertexCount <= 1024 &&
numComponents * maxVertexCount <= 1024;
}
static bool MergeElements(const ElementVec &priorElements,
ElementVec &inputElements, uint32_t &numVectors,
unsigned &mismatchElementId) {
inputElements.reserve(std::max(priorElements.size(), inputElements.size()));
unsigned minElements =
(unsigned)std::min(priorElements.size(), inputElements.size());
for (unsigned i = 0; i < minElements; i++) {
const DxilSignatureAllocator::DummyElement &priorEl = priorElements[i];
DxilSignatureAllocator::DummyElement &inputEl = inputElements[i];
// Verify elements match
if (priorEl.rows != inputEl.rows || priorEl.cols != inputEl.cols ||
priorEl.row != inputEl.row || priorEl.col != inputEl.col ||
priorEl.kind != inputEl.kind ||
// don't care about interpolation since normal signature matching
// ignores it: priorEl.interpolation != inputEl.interpolation ||
priorEl.interpretation != inputEl.interpretation) {
mismatchElementId = inputEl.id;
return false;
}
// OR prior dynamic index flags into input element
inputEl.indexFlags |= priorEl.indexFlags;
}
// Add extra incoming elements if there are more
for (unsigned i = (unsigned)inputElements.size();
i < (unsigned)priorElements.size(); i++) {
inputElements.push_back(priorElements[i]);
}
// Update numVectors to max
for (unsigned i = 0; i < inputElements.size(); i++) {
DxilSignatureAllocator::DummyElement &inputEl = inputElements[i];
numVectors = std::max(numVectors, inputEl.row + inputEl.rows);
}
return true;
}
static void PropagateMask(const ComponentMask &priorMask,
ElementVec &inputElements, ComponentMask &outMask,
std::function<PSVComponentMask(unsigned)> getMask) {
// Iterate elements
for (auto &E : inputElements) {
for (unsigned row = 0; row < E.GetRows(); row++) {
for (unsigned col = 0; col < E.GetCols(); col++) {
uint32_t componentIndex =
(E.GetStartRow() + row) * 4 + E.GetStartCol() + col;
// If bit set in priorMask
if (priorMask.Get(componentIndex)) {
// get mask of outputs affected by inputs and OR into outMask
outMask |= getMask(componentIndex);
}
}
}
}
}
bool DetectViewIDDependentTessFactor(const ElementVec &pcElements,
ComponentMask &mask) {
for (auto &E : pcElements) {
if (E.GetKind() == DXIL::SemanticKind::TessFactor ||
E.GetKind() == DXIL::SemanticKind::InsideTessFactor) {
for (unsigned row = 0; row < E.GetRows(); row++) {
for (unsigned col = 0; col < E.GetCols(); col++) {
uint32_t componentIndex =
(E.GetStartRow() + row) * 4 + E.GetStartCol() + col;
if (mask.Get(componentIndex))
return true;
}
}
}
}
return false;
}
class ViewIDValidator_impl : public hlsl::ViewIDValidator {
ComponentMask m_PriorOutputMask;
ComponentMask m_PriorPCMask;
ElementVec m_PriorOutputSignature;
ElementVec m_PriorPCSignature;
unsigned m_ViewIDCount;
unsigned m_GSRastStreamIndex;
void ClearPriorState() {
m_PriorOutputMask = ComponentMask();
m_PriorPCMask = ComponentMask();
m_PriorOutputSignature.clear();
m_PriorPCSignature.clear();
}
public:
ViewIDValidator_impl(unsigned viewIDCount, unsigned gsRastStreamIndex)
: m_PriorOutputMask(), m_ViewIDCount(viewIDCount),
m_GSRastStreamIndex(gsRastStreamIndex) {}
virtual ~ViewIDValidator_impl() {}
Result ValidateStage(const DxilPipelineStateValidation &PSV, bool bFinalStage,
bool bExpandInputOnly,
unsigned &mismatchElementId) override {
if (!PSV.GetPSVRuntimeInfo0())
return Result::InvalidPSV;
if (!PSV.GetPSVRuntimeInfo1())
return Result::InvalidPSVVersion;
switch (PSV.GetShaderKind()) {
case PSVShaderKind::Vertex: {
if (bExpandInputOnly)
return Result::InvalidUsage;
// Initialize mask with direct ViewID dependent outputs
ComponentMask mask(PSV.GetViewIDOutputMask(0));
// capture output signature
ElementVec outSig;
CopyElements(outSig, DXIL::SigPointKind::VSOut,
PSV.GetSigOutputElements(), 0,
[&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetOutputElement0(i));
});
// Copy mask to prior mask
m_PriorOutputMask = mask;
// Capture output signature for next stage
m_PriorOutputSignature = std::move(outSig);
break;
}
case PSVShaderKind::Hull: {
if (bFinalStage)
return Result::InvalidUsage;
// Initialize mask with direct ViewID dependent outputs
ComponentMask outputMask(PSV.GetViewIDOutputMask(0));
ComponentMask pcMask(PSV.GetViewIDPCOutputMask());
// capture signatures
ElementVec inSig, outSig, pcSig;
CopyElements(inSig, DXIL::SigPointKind::HSCPIn, PSV.GetSigInputElements(),
0, [&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetInputElement0(i));
});
// Merge prior and input signatures, update prior mask size if necessary
if (!MergeElements(m_PriorOutputSignature, inSig,
m_PriorOutputMask.NumVectors, mismatchElementId))
return Result::MismatchedSignatures;
// Create new version with ViewID elements from merged signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, inSig, m_PriorOutputMask, m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientInputSpace;
if (bExpandInputOnly) {
ClearPriorState();
return Result::Success;
}
CopyElements(outSig, DXIL::SigPointKind::HSCPOut,
PSV.GetSigOutputElements(), 0,
[&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetOutputElement0(i));
});
CopyElements(pcSig, DXIL::SigPointKind::PCOut,
PSV.GetSigPatchConstOrPrimElements(), 0,
[&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(
PSV.GetPatchConstOrPrimElement0(i));
});
// Propagate prior mask through input-output dependencies
if (PSV.GetInputToOutputTable(0).IsValid()) {
PropagateMask(m_PriorOutputMask, inSig, outputMask,
[&](unsigned i) -> PSVComponentMask {
return PSV.GetInputToOutputTable(0).GetMaskForInput(i);
});
}
if (PSV.GetInputToPCOutputTable().IsValid()) {
PropagateMask(m_PriorOutputMask, inSig, pcMask,
[&](unsigned i) -> PSVComponentMask {
return PSV.GetInputToPCOutputTable().GetMaskForInput(i);
});
}
// Copy mask to prior mask
m_PriorOutputMask = outputMask;
m_PriorPCMask = pcMask;
// Capture output signature for next stage
m_PriorOutputSignature = std::move(outSig);
m_PriorPCSignature = std::move(pcSig);
if (DetectViewIDDependentTessFactor(pcSig, pcMask)) {
return Result::SuccessWithViewIDDependentTessFactor;
}
break;
}
case PSVShaderKind::Domain: {
// Initialize mask with direct ViewID dependent outputs
ComponentMask mask(PSV.GetViewIDOutputMask(0));
// capture signatures
ElementVec inSig, pcSig, outSig;
CopyElements(inSig, DXIL::SigPointKind::DSCPIn, PSV.GetSigInputElements(),
0, [&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetInputElement0(i));
});
CopyElements(
pcSig, DXIL::SigPointKind::DSIn, PSV.GetSigPatchConstOrPrimElements(),
0, [&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetPatchConstOrPrimElement0(i));
});
// Merge prior and input signatures, update prior mask size if necessary
if (!MergeElements(m_PriorOutputSignature, inSig,
m_PriorOutputMask.NumVectors, mismatchElementId))
return Result::MismatchedSignatures;
if (!MergeElements(m_PriorPCSignature, pcSig, m_PriorPCMask.NumVectors,
mismatchElementId))
return Result::MismatchedPCSignatures;
{
// Create new version with ViewID elements from merged signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, inSig, m_PriorOutputMask, m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientInputSpace;
}
{
// Create new version with ViewID elements from merged signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, pcSig, m_PriorPCMask, m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientPCSpace;
}
if (bExpandInputOnly) {
ClearPriorState();
return Result::Success;
}
CopyElements(outSig, DXIL::SigPointKind::DSOut,
PSV.GetSigOutputElements(), 0,
[&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetOutputElement0(i));
});
// Propagate prior mask through input-output dependencies
if (PSV.GetInputToOutputTable(0).IsValid()) {
PropagateMask(m_PriorOutputMask, inSig, mask,
[&](unsigned i) -> PSVComponentMask {
return PSV.GetInputToOutputTable(0).GetMaskForInput(i);
});
}
if (PSV.GetPCInputToOutputTable().IsValid()) {
PropagateMask(m_PriorPCMask, pcSig, mask,
[&](unsigned i) -> PSVComponentMask {
return PSV.GetPCInputToOutputTable().GetMaskForInput(i);
});
}
// Copy mask to prior mask
m_PriorOutputMask = mask;
m_PriorPCMask = ComponentMask();
// Capture output signature for next stage
m_PriorOutputSignature = std::move(outSig);
m_PriorPCSignature.clear();
break;
}
case PSVShaderKind::Geometry: {
// capture signatures
ElementVec inSig, outSig[4];
CopyElements(inSig, DXIL::SigPointKind::GSVIn, PSV.GetSigInputElements(),
0, [&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetInputElement0(i));
});
// Merge prior and input signatures, update prior mask size if necessary
if (!MergeElements(m_PriorOutputSignature, inSig,
m_PriorOutputMask.NumVectors, mismatchElementId))
return Result::MismatchedSignatures;
// Create new version with ViewID elements from merged signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, inSig, m_PriorOutputMask, m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientInputSpace;
if (bExpandInputOnly) {
ClearPriorState();
return Result::Success;
}
for (unsigned streamIndex = 0; streamIndex < 4; streamIndex++) {
// Initialize mask with direct ViewID dependent outputs
ComponentMask mask(PSV.GetViewIDOutputMask(streamIndex));
CopyElements(outSig[streamIndex], DXIL::SigPointKind::GSOut,
PSV.GetSigOutputElements(), streamIndex,
[&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetOutputElement0(i));
});
if (!outSig[streamIndex].empty()) {
// Propagate prior mask through input-output dependencies
if (PSV.GetInputToOutputTable(streamIndex).IsValid()) {
PropagateMask(m_PriorOutputMask, inSig, mask,
[&](unsigned i) -> PSVComponentMask {
return PSV.GetInputToOutputTable(streamIndex)
.GetMaskForInput(i);
});
}
// Create new version with ViewID elements from prior signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, outSig[streamIndex], mask,
m_ViewIDCount);
// Verify fit
if (!CheckMaxVertexCount(viewIDSig,
PSV.GetPSVRuntimeInfo1()->MaxVertexCount))
return Result::InsufficientOutputSpace;
if (!CheckFit(viewIDSig))
return Result::InsufficientOutputSpace;
}
// Capture this mask for the next stage
if (m_GSRastStreamIndex == streamIndex)
m_PriorOutputMask = mask;
}
if (m_GSRastStreamIndex < 4 && !bFinalStage) {
m_PriorOutputSignature = std::move(outSig[m_GSRastStreamIndex]);
} else {
ClearPriorState();
if (!bFinalStage)
return Result::InvalidUsage;
}
return Result::Success;
}
case PSVShaderKind::Pixel: {
// capture signatures
ElementVec inSig;
CopyElements(inSig, DXIL::SigPointKind::PSIn, PSV.GetSigInputElements(),
0, [&](unsigned i) -> PSVSignatureElement {
return PSV.GetSignatureElement(PSV.GetInputElement0(i));
});
// Merge prior and input signatures, update prior mask size if necessary
if (!MergeElements(m_PriorOutputSignature, inSig,
m_PriorOutputMask.NumVectors, mismatchElementId))
return Result::MismatchedSignatures;
// Create new version with ViewID elements from merged signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, inSig, m_PriorOutputMask, m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientInputSpace;
// Final stage, so clear output state.
m_PriorOutputMask = ComponentMask();
m_PriorOutputSignature.clear();
// PS has to be the last stage, so return.
return Result::Success;
}
case PSVShaderKind::Compute:
default:
return Result::InvalidUsage;
}
if (bFinalStage) {
// Last stage was not pixel shader, so output has not yet been validated.
// Create new version with ViewID elements from prior signature
ElementVec viewIDSig;
AddViewIDElements(viewIDSig, m_PriorOutputSignature, m_PriorOutputMask,
m_ViewIDCount);
// Verify fit
if (!CheckFit(viewIDSig))
return Result::InsufficientOutputSpace;
}
return Result::Success;
}
};
} // namespace
ViewIDValidator *NewViewIDValidator(unsigned viewIDCount,
unsigned gsRastStreamIndex) {
return new ViewIDValidator_impl(viewIDCount, gsRastStreamIndex);
}
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLLowerUDT.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLLowerUDT.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Lower user defined type used directly by certain intrinsic operations. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilTypeSystem.h"
#include "dxc/Support/Global.h"
namespace llvm {
class Constant;
class Function;
class StructType;
class Type;
class Value;
} // namespace llvm
namespace hlsl {
class DxilTypeSystem;
llvm::StructType *GetLoweredUDT(llvm::StructType *structTy,
hlsl::DxilTypeSystem *pTypeSys = nullptr);
llvm::Constant *
TranslateInitForLoweredUDT(llvm::Constant *Init, llvm::Type *NewTy,
// We need orientation for matrix fields
hlsl::DxilTypeSystem *pTypeSys,
hlsl::MatrixOrientation matOrientation =
hlsl::MatrixOrientation::Undefined);
void ReplaceUsesForLoweredUDT(llvm::Value *V, llvm::Value *NewV);
} // namespace hlsl |
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLMatrixLowerPass.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLMatrixLowerPass.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// This file provides a high level matrix lower pass. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
namespace llvm {
class ModulePass;
class PassRegistry;
/// \brief Create and return a pass that lower high level matrix.
/// Note that this pass is designed for use with the legacy pass manager.
ModulePass *createHLMatrixLowerPass();
void initializeHLMatrixLowerPassPass(llvm::PassRegistry &);
} // namespace llvm
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLModule.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLModule.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// HighLevel DX IR module. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilFunctionProps.h"
#include "dxc/DXIL/DxilMetadataHelper.h"
#include "dxc/DXIL/DxilResourceProperties.h"
#include "dxc/DXIL/DxilSampler.h"
#include "dxc/DXIL/DxilShaderModel.h"
#include "dxc/DXIL/DxilSignature.h"
#include "dxc/DXIL/DxilSubobject.h"
#include "dxc/HLSL/HLOperations.h"
#include "dxc/HLSL/HLResource.h"
#include "dxc/Support/Global.h"
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace llvm {
template <typename T> class ArrayRef;
class LLVMContext;
class Module;
class Function;
class Instruction;
class CallInst;
class MDTuple;
class MDNode;
class GlobalVariable;
class DIGlobalVariable;
class DebugInfoFinder;
class GetElementPtrInst;
} // namespace llvm
namespace hlsl {
class ShaderModel;
class OP;
struct HLOptions {
HLOptions()
: bDefaultRowMajor(false), bIEEEStrict(false), bAllResourcesBound(false),
bDisableOptimizations(false), PackingStrategy(0),
bUseMinPrecision(false), bDX9CompatMode(false), bFXCCompatMode(false),
bLegacyResourceReservation(false), bForceZeroStoreLifetimes(false),
unused(0) {}
uint32_t GetHLOptionsRaw() const;
void SetHLOptionsRaw(uint32_t data);
unsigned bDefaultRowMajor : 1;
unsigned bIEEEStrict : 1;
unsigned bAllResourcesBound : 1;
unsigned bDisableOptimizations : 1;
unsigned PackingStrategy : 2;
static_assert((unsigned)DXIL::PackingStrategy::Invalid < 4,
"otherwise 2 bits is not enough to store PackingStrategy");
unsigned bUseMinPrecision : 1;
unsigned bDX9CompatMode : 1;
unsigned bFXCCompatMode : 1;
unsigned bLegacyResourceReservation : 1;
unsigned bForceZeroStoreLifetimes : 1;
unsigned bResMayAlias : 1;
unsigned unused : 19;
};
typedef std::unordered_map<const llvm::Function *,
std::unique_ptr<DxilFunctionProps>>
DxilFunctionPropsMap;
/// Use this class to manipulate HLDXIR of a shader.
class HLModule {
public:
HLModule(llvm::Module *pModule);
~HLModule();
using Domain = DXIL::TessellatorDomain;
// Subsystems.
llvm::LLVMContext &GetCtx() const;
llvm::Module *GetModule() const;
OP *GetOP() const;
void SetShaderModel(const ShaderModel *pSM);
const ShaderModel *GetShaderModel() const;
void SetValidatorVersion(unsigned ValMajor, unsigned ValMinor);
void GetValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
void SetForceZeroStoreLifetimes(bool ForceZeroStoreLifetimes);
bool GetForceZeroStoreLifetimes() const;
// HLOptions
void SetHLOptions(HLOptions &opts);
const HLOptions &GetHLOptions() const;
// AutoBindingSpace also enables automatic binding for libraries if set.
// UINT_MAX == unset
void SetAutoBindingSpace(uint32_t Space);
uint32_t GetAutoBindingSpace() const;
// Entry function.
llvm::Function *GetEntryFunction() const;
void SetEntryFunction(llvm::Function *pEntryFunc);
const std::string &GetEntryFunctionName() const;
void SetEntryFunctionName(const std::string &name);
llvm::Function *GetPatchConstantFunction();
// Resources.
unsigned AddCBuffer(std::unique_ptr<DxilCBuffer> pCB);
DxilCBuffer &GetCBuffer(unsigned idx);
const DxilCBuffer &GetCBuffer(unsigned idx) const;
const std::vector<std::unique_ptr<DxilCBuffer>> &GetCBuffers() const;
unsigned AddSampler(std::unique_ptr<DxilSampler> pSampler);
DxilSampler &GetSampler(unsigned idx);
const DxilSampler &GetSampler(unsigned idx) const;
const std::vector<std::unique_ptr<DxilSampler>> &GetSamplers() const;
unsigned AddSRV(std::unique_ptr<HLResource> pSRV);
HLResource &GetSRV(unsigned idx);
const HLResource &GetSRV(unsigned idx) const;
const std::vector<std::unique_ptr<HLResource>> &GetSRVs() const;
unsigned AddUAV(std::unique_ptr<HLResource> pUAV);
HLResource &GetUAV(unsigned idx);
const HLResource &GetUAV(unsigned idx) const;
const std::vector<std::unique_ptr<HLResource>> &GetUAVs() const;
void RemoveGlobal(llvm::GlobalVariable *GV);
void RemoveFunction(llvm::Function *F);
// ThreadGroupSharedMemory.
typedef std::vector<llvm::GlobalVariable *>::iterator tgsm_iterator;
tgsm_iterator tgsm_begin();
tgsm_iterator tgsm_end();
void AddGroupSharedVariable(llvm::GlobalVariable *GV);
// Signatures.
std::vector<uint8_t> &GetSerializedRootSignature();
void SetSerializedRootSignature(const uint8_t *pData, unsigned size);
// DxilFunctionProps.
bool HasDxilFunctionProps(llvm::Function *F);
DxilFunctionProps &GetDxilFunctionProps(llvm::Function *F);
void AddDxilFunctionProps(llvm::Function *F,
std::unique_ptr<DxilFunctionProps> &info);
void SetPatchConstantFunctionForHS(llvm::Function *hullShaderFunc,
llvm::Function *patchConstantFunc);
bool IsGraphicsShader(llvm::Function *F); // vs,hs,ds,gs,ps
bool IsPatchConstantShader(llvm::Function *F);
bool IsComputeShader(llvm::Function *F);
bool IsNodeShader(llvm::Function *F);
// Is an entry function that uses input/output signature conventions?
// Includes: vs/hs/ds/gs/ps/cs as well as the patch constant function.
bool IsEntryThatUsesSignatures(llvm::Function *F);
// Is F an entry?
// Includes: IsEntryThatUsesSignatures and all ray tracing shaders.
bool IsEntry(llvm::Function *F);
DxilFunctionAnnotation *GetFunctionAnnotation(llvm::Function *F);
DxilFunctionAnnotation *AddFunctionAnnotation(llvm::Function *F);
// Float Denorm mode.
void SetFloat32DenormMode(const DXIL::Float32DenormMode mode);
DXIL::Float32DenormMode GetFloat32DenormMode() const;
// Default function linkage for libraries
DXIL::DefaultLinkage GetDefaultLinkage() const;
void SetDefaultLinkage(const DXIL::DefaultLinkage linkage);
// HLDXIR metadata manipulation.
/// Serialize HLDXIR in-memory form to metadata form.
void EmitHLMetadata();
/// Deserialize HLDXIR metadata form into in-memory form.
void LoadHLMetadata();
/// Delete any HLDXIR from the specified module.
static void ClearHLMetadata(llvm::Module &M);
DxilResourceBase *
AddResourceWithGlobalVariableAndProps(llvm::Constant *GV,
DxilResourceProperties &RP);
unsigned GetBindingForResourceInCB(llvm::GetElementPtrInst *CbPtr,
llvm::GlobalVariable *CbGV,
DXIL::ResourceClass RC);
// Type related methods.
static bool IsStreamOutputPtrType(llvm::Type *Ty);
static bool IsStreamOutputType(llvm::Type *Ty);
static void GetParameterRowsAndCols(llvm::Type *Ty, unsigned &rows,
unsigned &cols,
DxilParameterAnnotation ¶mAnnotation);
// HL code gen.
static llvm::Function *GetHLOperationFunction(
HLOpcodeGroup group, unsigned opcode, llvm::Type *RetType,
llvm::ArrayRef<llvm::Value *> paramList, llvm::Module &M);
template <class BuilderTy>
static llvm::CallInst *
EmitHLOperationCall(BuilderTy &Builder, HLOpcodeGroup group, unsigned opcode,
llvm::Type *RetType,
llvm::ArrayRef<llvm::Value *> paramList, llvm::Module &M);
// Caller must handle conversions to bool and no-ops
static unsigned GetNumericCastOp(llvm::Type *SrcTy, bool SrcIsUnsigned,
llvm::Type *DstTy, bool DstIsUnsigned);
// Precise attribute.
// Note: Precise will be marked on alloca inst with metadata in code gen.
// But mem2reg will remove alloca inst, so need mark precise with
// function call before mem2reg.
static bool HasPreciseAttributeWithMetadata(llvm::Instruction *I);
static void MarkPreciseAttributeWithMetadata(llvm::Instruction *I);
static void ClearPreciseAttributeWithMetadata(llvm::Instruction *I);
template <class BuilderTy>
static void MarkPreciseAttributeOnValWithFunctionCall(llvm::Value *V,
BuilderTy &Builder,
llvm::Module &M);
static void MarkPreciseAttributeOnPtrWithFunctionCall(llvm::Value *Ptr,
llvm::Module &M);
static bool HasPreciseAttribute(llvm::Function *F);
// DXIL type system.
DxilTypeSystem &GetTypeSystem();
/// Emit llvm.used array to make sure that optimizations do not remove
/// unreferenced globals.
void EmitLLVMUsed();
std::vector<llvm::GlobalVariable *> &GetLLVMUsed();
// Release functions used to transfer ownership.
DxilTypeSystem *ReleaseTypeSystem();
OP *ReleaseOP();
DxilFunctionPropsMap &&ReleaseFunctionPropsMap();
llvm::DebugInfoFinder &GetOrCreateDebugInfoFinder();
// Create global variable debug info for element global variable based on the
// whole global variable.
static void CreateElementGlobalVariableDebugInfo(
llvm::GlobalVariable *GV, llvm::DebugInfoFinder &DbgInfoFinder,
llvm::GlobalVariable *EltGV, unsigned sizeInBits, unsigned alignInBits,
unsigned offsetInBits, llvm::StringRef eltName);
// Replace GV with NewGV in GlobalVariable debug info.
static void
UpdateGlobalVariableDebugInfo(llvm::GlobalVariable *GV,
llvm::DebugInfoFinder &DbgInfoFinder,
llvm::GlobalVariable *NewGV);
DxilSubobjects *GetSubobjects();
const DxilSubobjects *GetSubobjects() const;
DxilSubobjects *ReleaseSubobjects();
void ResetSubobjects(DxilSubobjects *subobjects);
// Reg binding for resource in cb.
void AddRegBinding(unsigned CbID, unsigned ConstantIdx, unsigned Srv,
unsigned Uav, unsigned Sampler);
private:
// Signatures.
std::vector<uint8_t> m_SerializedRootSignature;
// Shader resources.
std::vector<std::unique_ptr<HLResource>> m_SRVs;
std::vector<std::unique_ptr<HLResource>> m_UAVs;
std::vector<std::unique_ptr<DxilCBuffer>> m_CBuffers;
std::vector<std::unique_ptr<DxilSampler>> m_Samplers;
// ThreadGroupSharedMemory.
std::vector<llvm::GlobalVariable *> m_TGSMVariables;
// High level function info.
std::unordered_map<const llvm::Function *, std::unique_ptr<DxilFunctionProps>>
m_DxilFunctionPropsMap;
std::unordered_set<llvm::Function *> m_PatchConstantFunctions;
// Resource bindings for res in cb.
// Key = CbID << 32 | ConstantIdx. Val is reg binding.
std::unordered_map<uint64_t, unsigned> m_SrvBindingInCB;
std::unordered_map<uint64_t, unsigned> m_UavBindingInCB;
std::unordered_map<uint64_t, unsigned> m_SamplerBindingInCB;
private:
llvm::LLVMContext &m_Ctx;
llvm::Module *m_pModule;
llvm::Function *m_pEntryFunc;
std::string m_EntryName;
std::unique_ptr<DxilMDHelper> m_pMDHelper;
std::unique_ptr<llvm::DebugInfoFinder> m_pDebugInfoFinder;
const ShaderModel *m_pSM;
unsigned m_DxilMajor;
unsigned m_DxilMinor;
unsigned m_ValMajor;
unsigned m_ValMinor;
DXIL::Float32DenormMode m_Float32DenormMode;
HLOptions m_Options;
std::unique_ptr<OP> m_pOP;
size_t m_pUnused;
uint32_t m_AutoBindingSpace;
DXIL::DefaultLinkage m_DefaultLinkage;
std::unique_ptr<DxilSubobjects> m_pSubobjects;
// DXIL metadata serialization/deserialization.
llvm::MDTuple *EmitHLResources();
void LoadHLResources(const llvm::MDOperand &MDO);
llvm::MDTuple *EmitHLShaderProperties();
void LoadHLShaderProperties(const llvm::MDOperand &MDO);
llvm::MDTuple *EmitDxilShaderProperties();
// LLVM used.
std::vector<llvm::GlobalVariable *> m_LLVMUsed;
// Type annotations.
std::unique_ptr<DxilTypeSystem> m_pTypeSystem;
// Helpers.
template <typename T>
unsigned AddResource(std::vector<std::unique_ptr<T>> &Vec,
std::unique_ptr<T> pRes);
};
/// Use this class to manipulate metadata of extra metadata record properties
/// that are specific to high-level DX IR.
class HLExtraPropertyHelper : public DxilExtraPropertyHelper {
public:
HLExtraPropertyHelper(llvm::Module *pModule);
virtual ~HLExtraPropertyHelper() {}
virtual void
EmitSignatureElementProperties(const DxilSignatureElement &SE,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO,
DxilSignatureElement &SE);
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/DxilExportMap.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilExportMap.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// dxilutil::ExportMap for handling -exports option. //
// //
///////////////////////////////////////////////////////////////////////////////
// TODO: Refactor to separate name export verification part from
// llvm/Function part so first part may be have shared use without llvm
#pragma once
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
namespace llvm {
class Function;
class raw_ostream;
} // namespace llvm
namespace hlsl {
namespace dxilutil {
class ExportMap {
public:
typedef std::unordered_set<std::string> StringStore;
typedef std::set<llvm::StringRef> NameSet;
typedef llvm::MapVector<llvm::Function *, NameSet> RenameMap;
typedef llvm::StringMap<llvm::StringSet<>> ExportMapByString;
typedef ExportMapByString::iterator iterator;
typedef ExportMapByString::const_iterator const_iterator;
ExportMap() : m_ExportShadersOnly(false) {}
void clear();
bool empty() const;
void setExportShadersOnly(bool v) { m_ExportShadersOnly = v; }
bool isExportShadersOnly() const { return m_ExportShadersOnly; }
// Iterate export map by string name
iterator begin() { return m_ExportMap.begin(); }
const_iterator begin() const { return m_ExportMap.begin(); }
iterator end() { return m_ExportMap.end(); }
const_iterator end() const { return m_ExportMap.end(); }
// Initialize export map from option strings
bool ParseExports(const std::vector<std::string> &exportOpts,
llvm::raw_ostream &errors);
// Add one export to the export map
void Add(llvm::StringRef exportName,
llvm::StringRef internalName = llvm::StringRef());
// Return true if export is present, or m_ExportMap is empty
bool IsExported(llvm::StringRef original) const;
// Retrieve export entry by name. If Name is mangled, it will fallback to
// search for unmangled version if exact match fails.
// If result == end(), no matching export was found.
ExportMapByString::const_iterator
GetExportsByName(llvm::StringRef Name) const;
// Call before processing functions for renaming and cloning validation
void BeginProcessing();
// Called for each function to be processed
// In order to avoid intermediate name collisions during renaming,
// if collisionAvoidanceRenaming is true:
// non-exported functions will be renamed internal.<name>
// functions exported with a different name will be renamed temp.<name>
// returns true if function is exported
bool ProcessFunction(llvm::Function *F, bool collisionAvoidanceRenaming);
// Add function to exports without checking export map or renaming
// (useful for patch constant functions used by exported HS)
void RegisterExportedFunction(llvm::Function *F);
// Called to mark an internal name as used (remove from unused set)
void UseExport(llvm::StringRef internalName);
// Called to add an exported (full) name (for collision detection)
void ExportName(llvm::StringRef exportName);
// Called after functions are processed.
// Returns true if no name collisions or unused exports are present.
bool EndProcessing() const;
const NameSet &GetNameCollisions() const { return m_NameCollisions; }
const NameSet &GetUnusedExports() const { return m_UnusedExports; }
// GetRenames gets the map of mangled renames by function pointer
const RenameMap &GetFunctionRenames() const { return m_RenameMap; }
private:
// {"internalname": ("export1", "export2", ...), ...}
ExportMapByString m_ExportMap;
StringStore m_StringStorage;
llvm::StringRef StoreString(llvm::StringRef str);
// Renaming/Validation state
RenameMap m_RenameMap;
NameSet m_ExportNames;
NameSet m_NameCollisions;
NameSet m_UnusedExports;
bool m_ExportShadersOnly;
};
} // namespace dxilutil
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/HLSL/HLOperationLowerExtension.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLOperationLowerExtension.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Functions to lower HL operations coming from HLSL extensions to DXIL //
// operations. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/HLSL/HLSLExtensionsCodegenHelper.h"
#include "llvm/ADT/StringRef.h"
#include <string>
#include <unordered_map>
namespace llvm {
class Value;
class CallInst;
class Function;
class StringRef;
class Instruction;
} // namespace llvm
namespace hlsl {
class OP;
struct HLResourceLookup {
// Lookup resource kind based on handle. Return true on success.
virtual bool GetResourceKindName(llvm::Value *HLHandle,
const char **ppName) = 0;
virtual ~HLResourceLookup() {}
};
// Lowers HLSL extensions from HL operation to DXIL operation.
class ExtensionLowering {
public:
// Strategy used for lowering extensions.
enum class Strategy {
Unknown, // Do not know how to lower. This is an error condition.
NoTranslation, // Propagate the call arguments as is down to dxil.
Replicate, // Scalarize the vector arguments and replicate the call.
Pack, // Convert the vector arguments into structs.
Resource, // Convert return value to resource return and explode vectors.
Dxil, // Convert call to a dxil intrinsic.
Custom, // Custom lowering based on flexible json string.
};
// Create the lowering using the given strategy and custom codegen helper.
ExtensionLowering(llvm::StringRef strategy,
HLSLExtensionsCodegenHelper *helper, OP &hlslOp,
HLResourceLookup &resourceHelper);
ExtensionLowering(Strategy strategy, HLSLExtensionsCodegenHelper *helper,
OP &hlslOp, HLResourceLookup &resourceHelper);
// Translate the HL op call to a DXIL op call.
// Returns a new value if translation was successful.
// Returns nullptr if translation failed or made no changes.
llvm::Value *Translate(llvm::CallInst *CI);
// Translate the strategy string to an enum. The strategy string is
// added as a custom attribute on the high level extension function.
// It is translated as follows:
// "r" -> Replicate
// "n" -> NoTranslation
// "c" -> Custom
static Strategy GetStrategy(llvm::StringRef strategy);
// Translate the strategy enum into a name. This is the inverse of the
// GetStrategy() function.
static llvm::StringRef GetStrategyName(Strategy strategy);
// Get the name that will be used for the extension function call after
// lowering.
std::string GetExtensionName(llvm::CallInst *CI);
private:
Strategy m_strategy;
HLSLExtensionsCodegenHelper *m_helper;
OP &m_hlslOp;
HLResourceLookup &m_hlResourceLookup;
std::string m_extraStrategyInfo;
llvm::Value *Unknown(llvm::CallInst *CI);
llvm::Value *NoTranslation(llvm::CallInst *CI);
llvm::Value *Replicate(llvm::CallInst *CI);
llvm::Value *Pack(llvm::CallInst *CI);
llvm::Value *Resource(llvm::CallInst *CI);
llvm::Value *Dxil(llvm::CallInst *CI);
llvm::Value *CustomResource(llvm::CallInst *CI);
llvm::Value *Custom(llvm::CallInst *CI);
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/DxcLangExtensionsHelper.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxcLangExtensionsHelper.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides a helper class to implement language extensions to HLSL. //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef __DXCLANGEXTENSIONSHELPER_H__
#define __DXCLANGEXTENSIONSHELPER_H__
#include "dxc/Support/DxcLangExtensionsCommonHelper.h"
#include "dxc/Support/FileIOHelper.h"
#include "dxc/Support/Unicode.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaHLSL.h"
#include <vector>
namespace llvm {
class raw_string_ostream;
class CallInst;
class Value;
} // namespace llvm
namespace clang {
class CompilerInstance;
}
namespace hlsl {
class DxcLangExtensionsHelper : public DxcLangExtensionsCommonHelper,
public DxcLangExtensionsHelperApply {
private:
public:
void SetupSema(clang::Sema &S) override {
clang::ExternalASTSource *astSource = S.getASTContext().getExternalSource();
if (clang::ExternalSemaSource *externalSema =
llvm::dyn_cast_or_null<clang::ExternalSemaSource>(astSource)) {
for (auto &&table : GetIntrinsicTables()) {
hlsl::RegisterIntrinsicTable(externalSema, table);
}
}
}
void SetupPreprocessorOptions(clang::PreprocessorOptions &PPOpts) override {
for (const auto &define : GetDefines()) {
PPOpts.addMacroDef(llvm::StringRef(define.c_str()));
}
}
DxcLangExtensionsHelper *GetDxcLangExtensionsHelper() override {
return this;
}
DxcLangExtensionsHelper() {}
};
// A parsed semantic define is a semantic define that has actually been
// parsed by the compiler. It has a name (required), a value (could be
// the empty string), and a location. We use an encoded clang::SourceLocation
// for the location to avoid a clang include dependency.
struct ParsedSemanticDefine {
std::string Name;
std::string Value;
unsigned Location;
};
typedef std::vector<ParsedSemanticDefine> ParsedSemanticDefineList;
// Confirm that <name> matches the star pattern in <mask>
inline bool IsMacroMatch(StringRef name, const std::string &mask) {
return Unicode::IsStarMatchUTF8(mask.c_str(), mask.size(), name.data(),
name.size());
}
// Return the collection of semantic defines parsed by the compiler instance.
ParsedSemanticDefineList
CollectSemanticDefinesParsedByCompiler(clang::CompilerInstance &compiler,
DxcLangExtensionsHelper *helper);
} // namespace hlsl
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/microcom.h | ///////////////////////////////////////////////////////////////////////////////
// //
// microcom.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides support for basic COM-like constructs. //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef __DXC_MICROCOM__
#define __DXC_MICROCOM__
#include "dxc/Support/WinIncludes.h"
#include "llvm/Support/Atomic.h"
#include <atomic>
template <typename TIface> class CComInterfaceArray {
private:
TIface **m_pData;
unsigned m_length;
public:
CComInterfaceArray() : m_pData(nullptr), m_length(0) {}
~CComInterfaceArray() { clear(); }
bool empty() const { return m_length == 0; }
unsigned size() const { return m_length; }
TIface ***data_ref() { return &m_pData; }
unsigned *size_ref() { return &m_length; }
TIface **begin() { return m_pData; }
TIface **end() { return m_pData + m_length; }
void clear() {
if (m_length) {
for (unsigned i = 0; i < m_length; ++i) {
if (m_pData[i] != nullptr) {
m_pData[i]->Release();
m_pData[i] = nullptr;
}
}
m_length = 0;
}
if (m_pData) {
CoTaskMemFree(m_pData);
m_pData = nullptr;
}
}
HRESULT alloc(unsigned count) {
clear();
m_pData = (TIface **)CoTaskMemAlloc(sizeof(TIface *) * count);
if (m_pData == nullptr)
return E_OUTOFMEMORY;
m_length = count;
ZeroMemory(m_pData, sizeof(TIface *) * count);
return S_OK;
}
TIface **get_address_of(unsigned index) { return &(m_pData[index]); }
TIface **release() {
TIface **result = m_pData;
m_pData = nullptr;
m_length = 0;
return result;
}
void release(TIface ***pValues, unsigned *length) {
*pValues = m_pData;
m_pData = nullptr;
*length = m_length;
m_length = 0;
}
};
template <typename T> void DxcCallDestructor(T *obj) { obj->T::~T(); }
#define DXC_MICROCOM_REF_FIELD(m_dwRef) \
volatile std::atomic<llvm::sys::cas_flag> m_dwRef = {0};
#define DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE AddRef() noexcept override { \
return (ULONG)++m_dwRef; \
}
#define DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) \
DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE Release() override { \
ULONG result = (ULONG)--m_dwRef; \
if (result == 0) { \
DxcCallDestructor(this); \
operator delete(this); \
} \
return result; \
}
template <typename T, typename... Args>
inline T *CreateOnMalloc(IMalloc *pMalloc, Args &&...args) {
void *P = pMalloc->Alloc(sizeof(T));
try {
if (P)
new (P) T(pMalloc, std::forward<Args>(args)...);
} catch (...) {
pMalloc->Free(P);
throw;
}
return (T *)P;
}
// The "TM" version keep an IMalloc field that, if not null, indicate
// ownership of 'this' and of any allocations used during release.
#define DXC_MICROCOM_TM_REF_FIELDS() \
volatile std::atomic<llvm::sys::cas_flag> m_dwRef = {0}; \
CComPtr<IMalloc> m_pMalloc;
#define DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL() \
DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE Release() noexcept override { \
ULONG result = (ULONG)--m_dwRef; \
if (result == 0) { \
CComPtr<IMalloc> pTmp(m_pMalloc); \
DxcThreadMalloc M(pTmp); \
DxcCallDestructor(this); \
pTmp->Free(this); \
} \
return result; \
}
#define DXC_MICROCOM_TM_CTOR(T) \
DXC_MICROCOM_TM_CTOR_ONLY(T) \
DXC_MICROCOM_TM_ALLOC(T)
#define DXC_MICROCOM_TM_CTOR_ONLY(T) \
T(IMalloc *pMalloc) : m_dwRef(0), m_pMalloc(pMalloc) {}
#define DXC_MICROCOM_TM_ALLOC(T) \
template <typename... Args> \
static T *Alloc(IMalloc *pMalloc, Args &&...args) { \
void *P = pMalloc->Alloc(sizeof(T)); \
try { \
if (P) \
new (P) T(pMalloc, std::forward<Args>(args)...); \
} catch (...) { \
pMalloc->Free(P); \
throw; \
} \
return (T *)P; \
}
/// <summary>
/// Provides a QueryInterface implementation for a class that supports
/// any number of interfaces in addition to IUnknown.
/// </summary>
/// <remarks>
/// This implementation will also report the instance as not supporting
/// marshaling. This will help catch marshaling problems early or avoid
/// them altogether.
/// </remarks>
template <typename TObject>
HRESULT DoBasicQueryInterface_recurse(TObject *self, REFIID iid,
void **ppvObject) {
return E_NOINTERFACE;
}
template <typename TObject, typename TInterface, typename... Ts>
HRESULT DoBasicQueryInterface_recurse(TObject *self, REFIID iid,
void **ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;
if (IsEqualIID(iid, __uuidof(TInterface))) {
*(TInterface **)ppvObject = self;
self->AddRef();
return S_OK;
}
return DoBasicQueryInterface_recurse<TObject, Ts...>(self, iid, ppvObject);
}
template <typename... Ts, typename TObject>
HRESULT DoBasicQueryInterface(TObject *self, REFIID iid, void **ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;
// Support INoMarshal to void GIT shenanigans.
if (IsEqualIID(iid, __uuidof(IUnknown)) ||
IsEqualIID(iid, __uuidof(INoMarshal))) {
*ppvObject = reinterpret_cast<IUnknown *>(self);
reinterpret_cast<IUnknown *>(self)->AddRef();
return S_OK;
}
return DoBasicQueryInterface_recurse<TObject, Ts...>(self, iid, ppvObject);
}
template <typename T> HRESULT AssignToOut(T value, T *pResult) {
if (pResult == nullptr)
return E_POINTER;
*pResult = value;
return S_OK;
}
template <typename T> HRESULT AssignToOut(std::nullptr_t value, T *pResult) {
if (pResult == nullptr)
return E_POINTER;
*pResult = value;
return S_OK;
}
template <typename T> HRESULT ZeroMemoryToOut(T *pResult) {
if (pResult == nullptr)
return E_POINTER;
ZeroMemory(pResult, sizeof(*pResult));
return S_OK;
}
template <typename T> void AssignToOutOpt(T value, T *pResult) {
if (pResult != nullptr)
*pResult = value;
}
template <typename T> void AssignToOutOpt(std::nullptr_t value, T *pResult) {
if (pResult != nullptr)
*pResult = value;
}
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/WinIncludes.h | //===- WinIncludes.h --------------------------------------------*- C++ -*-===//
///////////////////////////////////////////////////////////////////////////////
// //
// WinIncludes.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifdef _MSC_VER
// mingw-w64 tends to define it as 0x0502 in its headers.
#undef _WIN32_WINNT
#undef _WIN32_IE
// Require at least Windows 7 (Updated from XP)
#define _WIN32_WINNT 0x0601
#define _WIN32_IE 0x0800 // MinGW at it again.
#define NOATOM 1
#define NOGDICAPMASKS 1
#define NOMETAFILE 1
#ifndef NOMINMAX
#define NOMINMAX 1
#endif
#define NOOPENFILE 1
#define NORASTEROPS 1
#define NOSCROLL 1
#define NOSOUND 1
#define NOSYSMETRICS 1
#define NOWH 1
#define NOCOMM 1
#define NOKANJI 1
#define NOCRYPT 1
#define NOMCX 1
#define WIN32_LEAN_AND_MEAN 1
#define VC_EXTRALEAN 1
#define NONAMELESSSTRUCT 1
#include <ObjIdl.h>
#include <atlbase.h> // atlbase.h needs to come before strsafe.h
#include <intsafe.h>
#include <strsafe.h>
#include <unknwn.h>
#include <windows.h>
#include "dxc/config.h"
// Support older atlbase.h if needed
#ifndef _ATL_DECLSPEC_ALLOCATOR
#define _ATL_DECLSPEC_ALLOCATOR
#endif
/// Swap two ComPtr classes.
template <class T> void swap(CComHeapPtr<T> &a, CComHeapPtr<T> &b) {
T *c(a.m_pData);
a.m_pData = b.m_pData;
b.m_pData = c;
}
#else // _MSC_VER
#include "dxc/WinAdapter.h"
#ifdef __cplusplus
#if !defined(DEFINE_ENUM_FLAG_OPERATORS)
// Define operator overloads to enable bit operations on enum values that are
// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable
// these operators on YOUR_TYPE.
extern "C++" {
template <size_t S> struct _ENUM_FLAG_INTEGER_FOR_SIZE;
template <> struct _ENUM_FLAG_INTEGER_FOR_SIZE<1> { typedef int8_t type; };
template <> struct _ENUM_FLAG_INTEGER_FOR_SIZE<2> { typedef int16_t type; };
template <> struct _ENUM_FLAG_INTEGER_FOR_SIZE<4> { typedef int32_t type; };
// used as an approximation of std::underlying_type<T>
template <class T> struct _ENUM_FLAG_SIZED_INTEGER {
typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
};
}
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
extern "C++" { \
inline ENUMTYPE operator|(ENUMTYPE a, ENUMTYPE b) { \
return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
inline ENUMTYPE &operator|=(ENUMTYPE &a, ENUMTYPE b) { \
return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
inline ENUMTYPE operator&(ENUMTYPE a, ENUMTYPE b) { \
return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
inline ENUMTYPE &operator&=(ENUMTYPE &a, ENUMTYPE b) { \
return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
inline ENUMTYPE operator~(ENUMTYPE a) { \
return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); \
} \
inline ENUMTYPE operator^(ENUMTYPE a, ENUMTYPE b) { \
return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
inline ENUMTYPE &operator^=(ENUMTYPE &a, ENUMTYPE b) { \
return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= \
((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); \
} \
}
#endif // !defined(DEFINE_ENUM_FLAG_OPERATORS)
#else
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) // NOP, C allows these operators.
#endif
#endif // _MSC_VER
/// DxcCoGetMalloc
#if defined(_WIN32) && !defined(DXC_DISABLE_ALLOCATOR_OVERRIDES)
#define DxcCoGetMalloc CoGetMalloc
#else // defined(_WIN32) && !defined(DXC_DISABLE_ALLOCATOR_OVERRIDES)
#ifndef _WIN32
struct IMalloc;
#endif
HRESULT DxcCoGetMalloc(DWORD dwMemContext, IMalloc **ppMalloc);
#endif // defined(_WIN32) && !defined(DXC_DISABLE_ALLOCATOR_OVERRIDES)
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/dxcfilesystem.h | ///////////////////////////////////////////////////////////////////////////////
// //
// dxcfilesystem.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides helper file system for dxcompiler. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/dxcapi.h"
#include "llvm/Support/MSFileSystem.h"
#include <string>
namespace clang {
class CompilerInstance;
}
namespace llvm {
class raw_string_ostream;
namespace sys {
namespace fs {
class MSFileSystem;
}
} // namespace sys
} // namespace llvm
namespace dxcutil {
class DxcArgsFileSystem : public ::llvm::sys::fs::MSFileSystem {
public:
virtual ~DxcArgsFileSystem(){};
virtual void SetupForCompilerInstance(clang::CompilerInstance &compiler) = 0;
virtual void GetStdOutputHandleStream(IStream **ppResultStream) = 0;
virtual void GetStdErrorHandleStream(IStream **ppResultStream) = 0;
virtual void WriteStdErrToStream(llvm::raw_string_ostream &s) = 0;
virtual void WriteStdOutToStream(llvm::raw_string_ostream &s) = 0;
virtual void EnableDisplayIncludeProcess() = 0;
virtual HRESULT CreateStdStreams(IMalloc *pMalloc) = 0;
virtual HRESULT RegisterOutputStream(LPCWSTR pName, IStream *pStream) = 0;
virtual HRESULT UnRegisterOutputStream() = 0;
};
DxcArgsFileSystem *CreateDxcArgsFileSystem(IDxcBlobUtf8 *pSource,
LPCWSTR pSourceName,
IDxcIncludeHandler *pIncludeHandler,
UINT32 defaultCodePage = CP_ACP);
void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage);
} // namespace dxcutil
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/ErrorCodes.h | ///////////////////////////////////////////////////////////////////////////////
// //
// ErrorCodes.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides error code values for the DirectX compiler and tools. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
// Redeclare some macros to not depend on winerror.h
#define DXC_SEVERITY_ERROR 1
#define DXC_MAKE_HRESULT(sev, fac, code) \
((HRESULT)(((unsigned long)(sev) << 31) | ((unsigned long)(fac) << 16) | \
((unsigned long)(code))))
#define HRESULT_IS_WIN32ERR(hr) \
((HRESULT)(hr & 0xFFFF0000) == \
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
#define HRESULT_AS_WIN32ERR(hr) (HRESULT_CODE(hr))
// Error codes from C libraries (0n150) - 0x8096xxxx
#define FACILITY_ERRNO (0x96)
#define HRESULT_FROM_ERRNO(x) \
MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_ERRNO, (x))
// Error codes from DXC libraries (0n170) - 0x8013xxxx
#define FACILITY_DXC (0xAA)
// 0x00000000 - The operation succeeded.
#define DXC_S_OK 0 // _HRESULT_TYPEDEF_(0x00000000L)
// 0x80AA0001 - The operation failed because overlapping semantics were found.
#define DXC_E_OVERLAPPING_SEMANTICS \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0001))
// 0x80AA0002 - The operation failed because multiple depth semantics were
// found.
#define DXC_E_MULTIPLE_DEPTH_SEMANTICS \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0002))
// 0x80AA0003 - Input file is too large.
#define DXC_E_INPUT_FILE_TOO_LARGE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0003))
// 0x80AA0004 - Error parsing DXBC container.
#define DXC_E_INCORRECT_DXBC \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0004))
// 0x80AA0005 - Error parsing DXBC bytecode.
#define DXC_E_ERROR_PARSING_DXBC_BYTECODE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0005))
// 0x80AA0006 - Data is too large.
#define DXC_E_DATA_TOO_LARGE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0006))
// 0x80AA0007 - Incompatible converter options.
#define DXC_E_INCOMPATIBLE_CONVERTER_OPTIONS \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0007))
// 0x80AA0008 - Irreducible control flow graph.
#define DXC_E_IRREDUCIBLE_CFG \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0008))
// 0x80AA0009 - IR verification error.
#define DXC_E_IR_VERIFICATION_FAILED \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0009))
// 0x80AA000A - Scope-nested control flow recovery failed.
#define DXC_E_SCOPE_NESTED_FAILED \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000A))
// 0x80AA000B - Operation is not supported.
#define DXC_E_NOT_SUPPORTED \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000B))
// 0x80AA000C - Unable to encode string.
#define DXC_E_STRING_ENCODING_FAILED \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000C))
// 0x80AA000D - DXIL container is invalid.
#define DXC_E_CONTAINER_INVALID \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000D))
// 0x80AA000E - DXIL container is missing the DXIL part.
#define DXC_E_CONTAINER_MISSING_DXIL \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000E))
// 0x80AA000F - Unable to parse DxilModule metadata.
#define DXC_E_INCORRECT_DXIL_METADATA \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x000F))
// 0x80AA0010 - Error parsing DDI signature.
#define DXC_E_INCORRECT_DDI_SIGNATURE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0010))
// 0x80AA0011 - Duplicate part exists in dxil container.
#define DXC_E_DUPLICATE_PART \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0011))
// 0x80AA0012 - Error finding part in dxil container.
#define DXC_E_MISSING_PART \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0012))
// 0x80AA0013 - Malformed DXIL Container.
#define DXC_E_MALFORMED_CONTAINER \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0013))
// 0x80AA0014 - Incorrect Root Signature for shader.
#define DXC_E_INCORRECT_ROOT_SIGNATURE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0014))
// 0X80AA0015 - DXIL container is missing DebugInfo part.
#define DXC_E_CONTAINER_MISSING_DEBUG \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0015))
// 0X80AA0016 - Unexpected failure in macro expansion.
#define DXC_E_MACRO_EXPANSION_FAILURE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0016))
// 0X80AA0017 - DXIL optimization pass failed.
#define DXC_E_OPTIMIZATION_FAILED \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0017))
// 0X80AA0018 - General internal error.
#define DXC_E_GENERAL_INTERNAL_ERROR \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0018))
// 0X80AA0019 - Abort compilation error.
#define DXC_E_ABORT_COMPILATION_ERROR \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x0019))
// 0X80AA001A - Error in extension mechanism.
#define DXC_E_EXTENSION_ERROR \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x001A))
// 0X80AA001B - LLVM Fatal Error
#define DXC_E_LLVM_FATAL_ERROR \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x001B))
// 0X80AA001C - LLVM Unreachable code
#define DXC_E_LLVM_UNREACHABLE \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x001C))
// 0X80AA001D - LLVM Cast Failure
#define DXC_E_LLVM_CAST_ERROR \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x001D))
// 0X80AA001E - External validator (DXIL.dll) required, and missing.
#define DXC_E_VALIDATOR_MISSING \
DXC_MAKE_HRESULT(DXC_SEVERITY_ERROR, FACILITY_DXC, (0x001E))
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/Global.h | ///////////////////////////////////////////////////////////////////////////////
// //
// Global.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides important declarations global to all DX Compiler code. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifdef _WIN32
// Redeclare some macros to not depend on winerror.h
#define DXC_FAILED(hr) (((HRESULT)(hr)) < 0)
#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED
#ifndef _Return_type_success_
typedef long HRESULT;
#else
typedef _Return_type_success_(return >= 0) long HRESULT;
#endif // _Return_type_success_
#endif // !_HRESULT_DEFINED
#endif // _WIN32
#include "dxc/Support/exception.h"
#include "dxc/WinAdapter.h"
#include <stdarg.h>
#include <system_error>
///////////////////////////////////////////////////////////////////////////////
// Memory allocation support.
//
// This mechanism ties into the C++ new and delete operators.
//
// Other allocators may be used in specific situations, eg sub-allocators or
// the COM allocator for interop. This is the preferred allocator in general,
// however, as it eventually allows the library user to specify their own.
//
struct IMalloc;
// Used by DllMain to set up and tear down per-thread tracking.
HRESULT DxcInitThreadMalloc() throw();
void DxcCleanupThreadMalloc() throw();
// Used by APIs entry points to set up per-thread/invocation allocator.
// Setting the IMalloc on the thread increases the reference count,
// clearing it decreases it.
void DxcSetThreadMallocToDefault() throw();
void DxcClearThreadMalloc() throw();
// Used to retrieve the current invocation's allocator or perform an
// alloc/free/realloc.
IMalloc *DxcGetThreadMallocNoRef() throw();
// Common implementation of operators new and delete
void *DxcNew(std::size_t size) throw();
void DxcDelete(void *ptr) throw();
class DxcThreadMalloc {
public:
explicit DxcThreadMalloc(IMalloc *pMallocOrNull) throw();
~DxcThreadMalloc();
IMalloc *GetInstalledAllocator() const { return p; }
private:
// Copy constructor and assignment are dangerous and should always be
// deleted...
DxcThreadMalloc(const DxcThreadMalloc &) = delete;
DxcThreadMalloc &operator=(const DxcThreadMalloc &) = delete;
// Move constructor and assignment should be OK to be added if needed.
DxcThreadMalloc(DxcThreadMalloc &&) = delete;
DxcThreadMalloc &operator=(DxcThreadMalloc &&) = delete;
IMalloc *p;
IMalloc *pPrior;
};
///////////////////////////////////////////////////////////////////////////////
// Error handling support.
void CheckLLVMErrorCode(const std::error_code &ec);
/******************************************************************************
Project-wide macros
******************************************************************************/
#define SAFE_RELEASE(p) \
{ \
if (p) { \
(p)->Release(); \
(p) = nullptr; \
} \
}
#define SAFE_ADDREF(p) \
{ \
if (p) { \
(p)->AddRef(); \
} \
}
#define SAFE_DELETE_ARRAY(p) \
{ \
delete[](p); \
p = nullptr; \
}
#define SAFE_DELETE(p) \
{ \
delete (p); \
p = nullptr; \
}
// VH is used in other DXC projects, but it's also a typedef in llvm.
// Use the IFC (IfFailedCleanup) set of conventions.
#define IFC(x) \
{ \
hr = (x); \
if (DXC_FAILED(hr)) \
goto Cleanup; \
}
#define IFR(x) \
{ \
HRESULT __hr = (x); \
if (DXC_FAILED(__hr)) \
return __hr; \
}
#define IFRBOOL(x, y) \
{ \
if (!(x)) \
return (y); \
}
#define IFCBOOL(x, y) \
{ \
if (!(x)) { \
hr = (y); \
goto Cleanup; \
} \
}
#define IFCOOM(x) \
{ \
if (nullptr == (x)) { \
hr = E_OUTOFMEMORY; \
goto Cleanup; \
} \
}
#define IFROOM(x) \
{ \
if (nullptr == (x)) { \
return E_OUTOFMEMORY; \
} \
}
#define IFCPTR(x) \
{ \
if (nullptr == (x)) { \
hr = E_POINTER; \
goto Cleanup; \
} \
}
#define IFT(x) \
{ \
HRESULT __hr = (x); \
if (DXC_FAILED(__hr)) \
throw ::hlsl::Exception(__hr); \
}
#define IFTBOOL(x, y) \
{ \
if (!(x)) \
throw ::hlsl::Exception(y); \
}
#define IFTOOM(x) \
{ \
if (nullptr == (x)) { \
throw ::hlsl::Exception(E_OUTOFMEMORY); \
} \
}
#define IFTPTR(x) \
{ \
if (nullptr == (x)) { \
throw ::hlsl::Exception(E_POINTER); \
} \
}
#define IFTARG(x) \
{ \
if (!(x)) { \
throw ::hlsl::Exception(E_INVALIDARG); \
} \
}
#define IFTLLVM(x) \
{ CheckLLVMErrorCode(x); }
#define IFTMSG(x, msg) \
{ \
HRESULT __hr = (x); \
if (DXC_FAILED(__hr)) \
throw ::hlsl::Exception(__hr, msg); \
}
#define IFTBOOLMSG(x, y, msg) \
{ \
if (!(x)) \
throw ::hlsl::Exception(y, msg); \
}
// Propagate an C++ exception into an HRESULT.
#define CATCH_CPP_ASSIGN_HRESULT() \
catch (std::bad_alloc &) { \
hr = E_OUTOFMEMORY; \
} \
catch (hlsl::Exception & _hlsl_exception_) { \
hr = _hlsl_exception_.hr; \
} \
catch (...) { \
hr = E_FAIL; \
}
#define CATCH_CPP_RETURN_HRESULT() \
catch (std::bad_alloc &) { \
return E_OUTOFMEMORY; \
} \
catch (hlsl::Exception & _hlsl_exception_) { \
return _hlsl_exception_.hr; \
} \
catch (...) { \
return E_FAIL; \
}
template <typename T> T *VerifyNullAndThrow(T *p) {
if (p == nullptr)
throw std::bad_alloc();
return p;
}
#define VNT(__p) VerifyNullAndThrow(__p)
#ifdef _MSC_VER
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(
const char *msg);
inline void OutputDebugBytes(const void *ptr, size_t len) {
const char digits[] = "0123456789abcdef";
const unsigned char *pBytes = (const unsigned char *)ptr;
const int bytesPerLine = 16;
char buffer[bytesPerLine * 3 + 2 + 1];
buffer[_countof(buffer) - 3] = '\r';
buffer[_countof(buffer) - 2] = '\n';
buffer[_countof(buffer) - 1] = '\0';
char *pWrite = buffer;
char *pEnd = buffer + _countof(buffer) - 3;
while (len) {
*pWrite++ = digits[(*pBytes & 0xF0) >> 4];
*pWrite++ = digits[*pBytes & 0x0f];
*pWrite++ = ' ';
if (pWrite == pEnd) {
OutputDebugStringA(buffer);
pWrite = buffer;
}
--len;
++pBytes;
}
if (pWrite != buffer) {
*pWrite = '\0';
OutputDebugStringA(buffer);
OutputDebugStringA("\r\n");
}
}
inline void OutputDebugFormatA(const char *pszFormat, ...) {
char buffer[1024];
va_list argList;
va_start(argList, pszFormat);
int count = vsnprintf_s(buffer, _countof(buffer), pszFormat, argList);
va_end(argList);
OutputDebugStringA(buffer);
if (count < 0) {
OutputDebugStringA("...\n");
}
}
#endif // _MSC_VER
#ifndef NDEBUG
#ifdef _WIN32
// DXASSERT is used to debug break when 'exp' evaluates to false and is only
// intended for internal developer use. It is compiled out in free
// builds. This means that code that should be in the final exe should
// NOT be inside of of an DXASSERT test.
//
// 'fmt' is a printf-like format string; positional arguments aren't
// supported.
//
// Example: DXASSERT(i > 10, "Hello %s", "World");
// This prints 'Hello World (i > 10)' and breaks in the debugger if the
// assertion doesn't hold.
//
#define DXASSERT_ARGS(exp, fmt, ...) \
do { \
if (!(exp)) { \
OutputDebugFormatA( \
"Error: \t%s\nFile:\n%s(%d)\nFunc:\t%s.\n\t" fmt "\n", \
"!(" #exp ")", __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__); \
__debugbreak(); \
} \
} while (0)
#define DXASSERT(exp, msg) DXASSERT_ARGS(exp, msg)
#define DXASSERT_LOCALVAR(local, exp, msg) DXASSERT(exp, msg)
#define DXASSERT_LOCALVAR_NOMSG(local, exp) DXASSERT_LOCALVAR(local, exp, "")
#define DXASSERT_NOMSG(exp) DXASSERT(exp, "")
#define DXVERIFY_NOMSG(exp) DXASSERT(exp, "")
#else // _WIN32
#include <cassert>
#define DXASSERT_NOMSG assert
#define DXASSERT_LOCALVAR(local, exp, msg) DXASSERT(exp, msg)
#define DXASSERT_LOCALVAR_NOMSG(local, exp) DXASSERT_LOCALVAR(local, exp, "")
#define DXVERIFY_NOMSG assert
#define DXASSERT_ARGS(expr, fmt, ...) \
do { \
if (!(expr)) { \
fprintf(stderr, fmt, __VA_ARGS__); \
assert(false); \
} \
} while (0)
#define DXASSERT(expr, msg) \
do { \
if (!(expr)) { \
fprintf(stderr, msg); \
assert(false && msg); \
} \
} while (0)
#endif // _WIN32
#else // NDEBUG
// DXASSERT_ARGS is disabled in free builds.
#define DXASSERT_ARGS(exp, s, ...) \
do { \
} while (0)
// DXASSERT is disabled in free builds.
#define DXASSERT(exp, msg) \
do { \
} while (0)
// DXASSERT_LOCALVAR is disabled in free builds, but we keep the local
// referenced to avoid a warning.
#define DXASSERT_LOCALVAR(local, exp, msg) \
do { \
(void)(local); \
} while (0)
#define DXASSERT_LOCALVAR_NOMSG(local, exp) DXASSERT_LOCALVAR(local, exp, "")
// DXASSERT_NOMSG is disabled in free builds.
#define DXASSERT_NOMSG(exp) \
do { \
} while (0)
// DXVERIFY is patterned after NT_VERIFY and will evaluate the expression
#define DXVERIFY_NOMSG(exp) \
do { \
(void)(exp); \
} while (0)
#endif // NDEBUG
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/exception.h | //===- exception.h ----------------------------------------------*- C++ -*-===//
///////////////////////////////////////////////////////////////////////////////
// //
// exception.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/Support/ErrorCodes.h"
#include "dxc/WinAdapter.h"
#include <exception>
#include <string>
namespace hlsl {
/// <summary>
/// Exception stores off information about an error and its error message for
/// later consumption by the hlsl compiler tools.
/// </summary>
struct Exception : public std::exception {
/// <summary>HRESULT error code. Must be a failure.</summary>
HRESULT hr;
std::string msg;
Exception(HRESULT errCode) : hr(errCode) {}
Exception(HRESULT errCode, const std::string &errMsg)
: hr(errCode), msg(errMsg) {}
// what returns a formatted message with the error code and the message used
// to create the message.
virtual const char *what() const throw() { return msg.c_str(); }
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/DxcLangExtensionsCommonHelper.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxcLangExtensionsCommonHelper.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides a helper class to implement language extensions to HLSL. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/Support/FileIOHelper.h"
#include "dxc/Support/Unicode.h"
#include "dxc/dxcapi.internal.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>
namespace llvm {
class raw_string_ostream;
class CallInst;
class Value;
} // namespace llvm
namespace hlsl {
class DxcLangExtensionsCommonHelper {
private:
llvm::SmallVector<std::string, 2> m_semanticDefines;
llvm::SmallVector<std::string, 2> m_semanticDefineExclusions;
llvm::SetVector<std::string> m_nonOptSemanticDefines;
llvm::SmallVector<std::string, 2> m_defines;
llvm::SmallVector<CComPtr<IDxcIntrinsicTable>, 2> m_intrinsicTables;
CComPtr<IDxcSemanticDefineValidator> m_semanticDefineValidator;
std::string m_semanticDefineMetaDataName;
std::string m_targetTriple;
HRESULT STDMETHODCALLTYPE
RegisterIntoVector(LPCWSTR name, llvm::SmallVector<std::string, 2> &here) {
try {
IFTPTR(name);
std::string s;
if (!Unicode::WideToUTF8String(name, &s)) {
throw ::hlsl::Exception(E_INVALIDARG);
}
here.push_back(s);
return S_OK;
}
CATCH_CPP_RETURN_HRESULT();
}
HRESULT STDMETHODCALLTYPE
RegisterIntoSet(LPCWSTR name, llvm::SetVector<std::string> &here) {
try {
IFTPTR(name);
std::string s;
if (!Unicode::WideToUTF8String(name, &s)) {
throw ::hlsl::Exception(E_INVALIDARG);
}
here.insert(s);
return S_OK;
}
CATCH_CPP_RETURN_HRESULT();
}
public:
const llvm::SmallVector<std::string, 2> &GetSemanticDefines() const {
return m_semanticDefines;
}
const llvm::SmallVector<std::string, 2> &GetSemanticDefineExclusions() const {
return m_semanticDefineExclusions;
}
const llvm::SetVector<std::string> &GetNonOptSemanticDefines() const {
return m_nonOptSemanticDefines;
}
const llvm::SmallVector<std::string, 2> &GetDefines() const {
return m_defines;
}
llvm::SmallVector<CComPtr<IDxcIntrinsicTable>, 2> &GetIntrinsicTables() {
return m_intrinsicTables;
}
const std::string &GetSemanticDefineMetadataName() {
return m_semanticDefineMetaDataName;
}
const std::string &GetTargetTriple() { return m_targetTriple; }
HRESULT STDMETHODCALLTYPE RegisterSemanticDefine(LPCWSTR name) {
return RegisterIntoVector(name, m_semanticDefines);
}
HRESULT STDMETHODCALLTYPE RegisterSemanticDefineExclusion(LPCWSTR name) {
return RegisterIntoVector(name, m_semanticDefineExclusions);
}
HRESULT STDMETHODCALLTYPE RegisterNonOptSemanticDefine(LPCWSTR name) {
return RegisterIntoSet(name, m_nonOptSemanticDefines);
}
HRESULT STDMETHODCALLTYPE RegisterDefine(LPCWSTR name) {
return RegisterIntoVector(name, m_defines);
}
HRESULT STDMETHODCALLTYPE RegisterIntrinsicTable(IDxcIntrinsicTable *pTable) {
try {
IFTPTR(pTable);
LPCSTR tableName = nullptr;
IFT(pTable->GetTableName(&tableName));
IFTPTR(tableName);
IFTARG(strcmp(tableName, "op") !=
0); // "op" is reserved for builtin intrinsics
for (auto &&table : m_intrinsicTables) {
LPCSTR otherTableName = nullptr;
IFT(table->GetTableName(&otherTableName));
IFTPTR(otherTableName);
IFTARG(strcmp(tableName, otherTableName) !=
0); // Added a duplicate table name
}
m_intrinsicTables.push_back(pTable);
return S_OK;
}
CATCH_CPP_RETURN_HRESULT();
}
// Set the validator used to validate semantic defines.
// Only one validator stored and used to run validation.
HRESULT STDMETHODCALLTYPE
SetSemanticDefineValidator(IDxcSemanticDefineValidator *pValidator) {
if (pValidator == nullptr)
return E_POINTER;
m_semanticDefineValidator = pValidator;
return S_OK;
}
HRESULT STDMETHODCALLTYPE SetSemanticDefineMetaDataName(LPCSTR name) {
try {
m_semanticDefineMetaDataName = name;
return S_OK;
}
CATCH_CPP_RETURN_HRESULT();
}
HRESULT STDMETHODCALLTYPE SetTargetTriple(LPCSTR triple) {
try {
m_targetTriple = triple;
return S_OK;
}
CATCH_CPP_RETURN_HRESULT();
}
// Get the name of the dxil intrinsic function.
std::string GetIntrinsicName(UINT opcode) {
LPCSTR pName = "";
for (IDxcIntrinsicTable *table : m_intrinsicTables) {
if (SUCCEEDED(table->GetIntrinsicName(opcode, &pName))) {
return pName;
}
}
return "";
}
// Get the dxil opcode for the extension opcode if one exists.
// Return true if the opcode was mapped successfully.
bool GetDxilOpCode(UINT opcode, UINT &dxilOpcode) {
for (IDxcIntrinsicTable *table : m_intrinsicTables) {
if (SUCCEEDED(table->GetDxilOpCode(opcode, &dxilOpcode))) {
return true;
}
}
return false;
}
// Result of validating a semantic define.
// Stores any warning or error messages produced by the validator.
// Successful validation means that there are no warning or error messages.
struct SemanticDefineValidationResult {
std::string Warning;
std::string Error;
bool HasError() { return Error.size() > 0; }
bool HasWarning() { return Warning.size() > 0; }
static SemanticDefineValidationResult Success() {
return SemanticDefineValidationResult();
}
};
// Use the contained semantice define validator to validate the given semantic
// define.
SemanticDefineValidationResult
ValidateSemanticDefine(const std::string &name, const std::string &value) {
if (!m_semanticDefineValidator)
return SemanticDefineValidationResult::Success();
// Blobs for getting restul from validator. Strings for returning results to
// caller.
CComPtr<IDxcBlobEncoding> pError;
CComPtr<IDxcBlobEncoding> pWarning;
std::string error;
std::string warning;
// Run semantic define validator.
HRESULT result =
m_semanticDefineValidator->GetSemanticDefineWarningsAndErrors(
name.c_str(), value.c_str(), &pWarning, &pError);
if (FAILED(result)) {
// Failure indicates it was not able to even run validation so
// we cannot say whether the define is invalid or not. Return a
// generic error message about failure to run the valiadator.
error = "failed to run semantic define validator for: ";
error.append(name);
error.append("=");
error.append(value);
return SemanticDefineValidationResult{warning, error};
}
// Define a little function to convert encoded blob into a string.
auto GetErrorAsString =
[&name](const CComPtr<IDxcBlobEncoding> &pBlobString) -> std::string {
CComPtr<IDxcBlobUtf8> pUTF8BlobStr;
if (SUCCEEDED(hlsl::DxcGetBlobAsUtf8(
pBlobString, DxcGetThreadMallocNoRef(), &pUTF8BlobStr)))
return std::string(pUTF8BlobStr->GetStringPointer(),
pUTF8BlobStr->GetStringLength());
else
return std::string("invalid semantic define " + name);
};
// Check to see if any warnings or errors were produced.
if (pError && pError->GetBufferSize()) {
error = GetErrorAsString(pError);
}
if (pWarning && pWarning->GetBufferSize()) {
warning = GetErrorAsString(pWarning);
}
return SemanticDefineValidationResult{warning, error};
}
DxcLangExtensionsCommonHelper()
: m_semanticDefineMetaDataName("hlsl.semdefs"),
m_targetTriple("dxil-ms-dx") {}
};
// Use this macro to embed an implementation that will delegate to a field.
// Note that QueryInterface still needs to return the vtable.
#define DXC_LANGEXTENSIONS_HELPER_IMPL(_helper_field_) \
HRESULT STDMETHODCALLTYPE RegisterIntrinsicTable(IDxcIntrinsicTable *pTable) \
override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).RegisterIntrinsicTable(pTable); \
} \
HRESULT STDMETHODCALLTYPE RegisterSemanticDefine(LPCWSTR name) override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).RegisterSemanticDefine(name); \
} \
HRESULT STDMETHODCALLTYPE RegisterSemanticDefineExclusion(LPCWSTR name) \
override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).RegisterSemanticDefineExclusion(name); \
} \
HRESULT STDMETHODCALLTYPE RegisterNonOptSemanticDefine(LPCWSTR name) \
override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).RegisterNonOptSemanticDefine(name); \
} \
HRESULT STDMETHODCALLTYPE RegisterDefine(LPCWSTR name) override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).RegisterDefine(name); \
} \
HRESULT STDMETHODCALLTYPE SetSemanticDefineValidator( \
IDxcSemanticDefineValidator *pValidator) override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).SetSemanticDefineValidator(pValidator); \
} \
HRESULT STDMETHODCALLTYPE SetSemanticDefineMetaDataName(LPCSTR name) \
override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).SetSemanticDefineMetaDataName(name); \
} \
HRESULT STDMETHODCALLTYPE SetTargetTriple(LPCSTR name) override { \
DxcThreadMalloc TM(m_pMalloc); \
return (_helper_field_).SetTargetTriple(name); \
}
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/Path.h | ///////////////////////////////////////////////////////////////////////////////
// //
// Path.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Helper for HLSL related file paths. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "llvm/ADT/StringRef.h"
#include <string>
namespace hlsl {
template <typename CharTy>
bool IsAbsoluteOrCurDirRelativeImpl(const CharTy *Path, size_t Len) {
if (Len == 1 && Path[0] == '.')
return true;
// Current dir-relative path.
if (Len >= 2 && Path[0] == '.' && (Path[1] == '/' || Path[1] == '\\')) {
return true;
}
// Disk designator, then absolute path.
if (Len >= 3 && Path[1] && Path[1] == ':' &&
(Path[2] == '\\' || Path[2] == '/')) {
return true;
}
// UNC name
if (Len >= 2 && Path[0] == '\\') {
return Path[1] == '\\';
}
#ifndef _WIN32
// Absolute paths on unix systems start with '/'
if (Len >= 1 && Path[0] == '/') {
return true;
}
#endif
//
// NOTE: there are a number of cases we don't handle, as they don't play well
// with the simple file system abstraction we use:
// - current directory on disk designator (eg, D:file.ext), requires per-disk
// current dir
// - parent paths relative to current directory (eg, ..\\file.ext)
//
// The current-directory support is available to help in-memory handlers.
// On-disk handlers will typically have absolute paths to begin with.
//
return false;
}
inline bool IsAbsoluteOrCurDirRelativeW(const wchar_t *Path) {
if (!Path)
return false;
return IsAbsoluteOrCurDirRelativeImpl<wchar_t>(Path, wcslen(Path));
}
inline bool IsAbsoluteOrCurDirRelative(const char *Path) {
if (!Path)
return false;
return IsAbsoluteOrCurDirRelativeImpl<char>(Path, strlen(Path));
}
template <typename CharT, typename StringTy>
void RemoveDoubleSlashes(StringTy &Path, CharT Slash) {
// Remove double slashes.
bool SeenNonSlash = false;
for (unsigned i = 0; i < Path.size();) {
// Remove this slash if:
// 1. It is preceded by another slash.
// 2. It is NOT part of a series of leading slashes. (E.G. \\, which on
// windows is a network path).
if (Path[i] == Slash && i > 0 && Path[i - 1] == Slash && SeenNonSlash) {
Path.erase(Path.begin() + i);
continue;
}
SeenNonSlash |= Path[i] != Slash;
i++;
}
}
// This is the new ground truth of how paths are normalized. There had been
// many inconsistent path normalization littered all over the code base.
// 1. All slashes are changed to system native: `\` for windows and `/` for all
// others.
// 2. All repeated slashes are removed (except for leading slashes, so windows
// UNC paths are not broken)
// 3. All relative paths (including ones that begin with ..) are prepended with
// ./ or .\ if not already
//
// Examples:
// F:\\\my_path////\\/my_shader.hlsl -> F:\my_path\my_shader.hlsl
// my_path/my_shader.hlsl -> .\my_path\my_shader.hlsl
// ..\\.//.\\\my_path/my_shader.hlsl -> .\..\.\.\my_path\my_shader.hlsl
// \\my_network_path/my_shader.hlsl -> \\my_network_path\my_shader.hlsl
//
template <typename CharT, typename StringTy>
StringTy NormalizePathImpl(const CharT *Path, size_t Length) {
StringTy PathCopy(Path, Length);
#ifdef _WIN32
constexpr CharT SlashFrom = '/';
constexpr CharT SlashTo = '\\';
#else
constexpr CharT SlashFrom = '\\';
constexpr CharT SlashTo = '/';
#endif
for (unsigned i = 0; i < PathCopy.size(); i++) {
if (PathCopy[i] == SlashFrom)
PathCopy[i] = SlashTo;
}
RemoveDoubleSlashes<CharT, StringTy>(PathCopy, SlashTo);
// If relative path, prefix with dot.
if (IsAbsoluteOrCurDirRelativeImpl<CharT>(PathCopy.c_str(),
PathCopy.size())) {
return PathCopy;
} else {
PathCopy = StringTy(1, CharT('.')) + StringTy(1, SlashTo) + PathCopy;
RemoveDoubleSlashes<CharT, StringTy>(PathCopy, SlashTo);
return PathCopy;
}
}
inline std::string NormalizePath(const char *Path) {
return NormalizePathImpl<char, std::string>(Path, ::strlen(Path));
}
inline std::wstring NormalizePathW(const wchar_t *Path) {
return NormalizePathImpl<wchar_t, std::wstring>(Path, ::wcslen(Path));
}
inline std::string NormalizePath(llvm::StringRef Path) {
return NormalizePathImpl<char, std::string>(Path.data(), Path.size());
}
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/WinFunctions.h | //===-- WinFunctions.h - Windows Functions for other platforms --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines Windows-specific functions used in the codebase for
// non-Windows platforms.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_WINFUNCTIONS_H
#define LLVM_SUPPORT_WINFUNCTIONS_H
#include "dxc/WinAdapter.h"
#ifndef _WIN32
HRESULT StringCchPrintfA(char *dst, size_t dstSize, const char *format, ...);
HRESULT UIntAdd(UINT uAugend, UINT uAddend, UINT *puResult);
HRESULT IntToUInt(int in, UINT *out);
HRESULT SizeTToInt(size_t in, INT *out);
HRESULT UInt32Mult(UINT a, UINT b, UINT *out);
int strnicmp(const char *str1, const char *str2, size_t count);
int _stricmp(const char *str1, const char *str2);
int _wcsicmp(const wchar_t *str1, const wchar_t *str2);
int _wcsnicmp(const wchar_t *str1, const wchar_t *str2, size_t n);
int wsprintf(wchar_t *wcs, const wchar_t *fmt, ...);
unsigned char _BitScanForward(unsigned long *Index, unsigned long Mask);
HANDLE CreateFile2(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
DWORD dwCreationDisposition, void *pCreateExParams);
HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
void *lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize);
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
LPDWORD lpNumberOfBytesRead, void *lpOverlapped);
BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, void *lpOverlapped);
BOOL CloseHandle(HANDLE hObject);
// Windows-specific heap functions
HANDLE HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize);
BOOL HeapDestroy(HANDLE heap);
LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T nBytes);
LPVOID HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
SIZE_T HeapSize(HANDLE hHeap, DWORD dwFlags, LPCVOID lpMem);
HANDLE GetProcessHeap();
#endif // _WIN32
#endif // LLVM_SUPPORT_WINFUNCTIONS_H
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/dxcapi.impl.h | ///////////////////////////////////////////////////////////////////////////////
// //
// dxcapi.impl.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides support for DXC API implementations. //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef __DXCAPI_IMPL__
#define __DXCAPI_IMPL__
#include "dxc/Support/microcom.h"
#include "dxc/dxcapi.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/raw_ostream.h"
// Simple adaptor for IStream. Can probably do better.
class raw_stream_ostream : public llvm::raw_ostream {
private:
CComPtr<hlsl::AbstractMemoryStream> m_pStream;
void write_impl(const char *Ptr, size_t Size) override {
ULONG cbWritten;
IFT(m_pStream->Write(Ptr, Size, &cbWritten));
}
uint64_t current_pos() const override { return m_pStream->GetPosition(); }
public:
raw_stream_ostream(hlsl::AbstractMemoryStream *pStream)
: m_pStream(pStream) {}
~raw_stream_ostream() override { flush(); }
};
namespace {
HRESULT TranslateUtf8StringForOutput(LPCSTR pStr, SIZE_T size, UINT32 codePage,
IDxcBlobEncoding **ppBlobEncoding) {
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(hlsl::DxcCreateBlobWithEncodingOnHeapCopy(pStr, size, DXC_CP_UTF8,
&pBlobEncoding));
if (codePage == DXC_CP_WIDE) {
CComPtr<IDxcBlobWide> pBlobWide;
IFT(hlsl::DxcGetBlobAsWide(pBlobEncoding, nullptr, &pBlobWide))
pBlobEncoding = pBlobWide;
}
*ppBlobEncoding = pBlobEncoding.Detach();
return S_OK;
}
HRESULT TranslateWideStringForOutput(LPCWSTR pStr, SIZE_T size, UINT32 codePage,
IDxcBlobEncoding **ppBlobEncoding) {
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(hlsl::DxcCreateBlobWithEncodingOnHeapCopy(pStr, size, DXC_CP_WIDE,
&pBlobEncoding));
if (codePage == DXC_CP_UTF8) {
CComPtr<IDxcBlobUtf8> pBlobUtf8;
IFT(hlsl::DxcGetBlobAsUtf8(pBlobEncoding, nullptr, &pBlobUtf8))
pBlobEncoding = pBlobUtf8;
}
*ppBlobEncoding = pBlobEncoding.Detach();
return S_OK;
}
HRESULT TranslateStringBlobForOutput(IDxcBlob *pBlob, UINT32 codePage,
IDxcBlobEncoding **ppBlobEncoding) {
CComPtr<IDxcBlobEncoding> pEncoding;
IFR(pBlob->QueryInterface(&pEncoding));
BOOL known;
UINT32 inputCP;
IFR(pEncoding->GetEncoding(&known, &inputCP));
IFRBOOL(known, E_INVALIDARG);
if (inputCP == DXC_CP_UTF8) {
return TranslateUtf8StringForOutput((LPCSTR)pBlob->GetBufferPointer(),
pBlob->GetBufferSize(), codePage,
ppBlobEncoding);
} else if (inputCP == DXC_CP_WIDE) {
return TranslateWideStringForOutput((LPCWSTR)pBlob->GetBufferPointer(),
pBlob->GetBufferSize(), codePage,
ppBlobEncoding);
}
return E_INVALIDARG;
}
} // namespace
typedef enum DxcOutputType {
DxcOutputType_None = 0,
DxcOutputType_Blob = 1,
DxcOutputType_Text = 2,
DxcOutputTypeForceDword = 0xFFFFFFFF
} DxcOutputType;
inline DxcOutputType DxcGetOutputType(DXC_OUT_KIND kind) {
switch (kind) {
case DXC_OUT_OBJECT:
case DXC_OUT_PDB:
case DXC_OUT_SHADER_HASH:
case DXC_OUT_REFLECTION:
case DXC_OUT_ROOT_SIGNATURE:
return DxcOutputType_Blob;
case DXC_OUT_ERRORS:
case DXC_OUT_DISASSEMBLY:
case DXC_OUT_HLSL:
case DXC_OUT_TEXT:
case DXC_OUT_REMARKS:
case DXC_OUT_TIME_REPORT:
case DXC_OUT_TIME_TRACE:
return DxcOutputType_Text;
default:
return DxcOutputType_None;
}
}
// Update when new results are allowed
static const unsigned kNumDxcOutputTypes = DXC_OUT_LAST;
static const SIZE_T kAutoSize = (SIZE_T)-1;
static const LPCWSTR DxcOutNoName = nullptr;
struct DxcOutputObject {
CComPtr<IUnknown> object;
CComPtr<IDxcBlobWide> name;
DXC_OUT_KIND kind = DXC_OUT_NONE;
/////////////////////////
// Convenient set methods
/////////////////////////
HRESULT SetObject(IUnknown *pUnknown, UINT32 codePage = DXC_CP_UTF8) {
DXASSERT_NOMSG(!object);
if (!pUnknown)
return S_OK;
if (codePage && DxcGetOutputType(kind) == DxcOutputType_Text) {
CComPtr<IDxcBlob> pBlob;
IFR(pUnknown->QueryInterface(&pBlob));
CComPtr<IDxcBlobEncoding> pEncoding;
// If not blob encoding, assume utf-8 text
if (FAILED(TranslateStringBlobForOutput(pBlob, codePage, &pEncoding)))
IFR(TranslateUtf8StringForOutput((LPCSTR)pBlob->GetBufferPointer(),
pBlob->GetBufferSize(), codePage,
&pEncoding));
object = pEncoding;
} else {
object = pUnknown;
}
return S_OK;
}
HRESULT SetObjectData(LPCVOID pData, SIZE_T size) {
DXASSERT_NOMSG(!object);
if (!pData || !size)
return S_OK;
IDxcBlob *pBlob;
IFR(hlsl::DxcCreateBlobOnHeapCopy(pData, size, &pBlob));
object = pBlob;
return S_OK;
}
HRESULT SetString(UINT32 codePage, LPCWSTR pText, SIZE_T size = kAutoSize) {
DXASSERT_NOMSG(!object);
if (!pText)
return S_OK;
if (size == kAutoSize)
size = wcslen(pText);
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(TranslateWideStringForOutput(pText, size, codePage, &pBlobEncoding));
object = pBlobEncoding;
return S_OK;
}
HRESULT SetString(UINT32 codePage, LPCSTR pText, SIZE_T size = kAutoSize) {
DXASSERT_NOMSG(!object);
if (!pText)
return S_OK;
if (size == kAutoSize)
size = strlen(pText);
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(TranslateUtf8StringForOutput(pText, size, codePage, &pBlobEncoding));
object = pBlobEncoding;
return S_OK;
}
HRESULT SetName(IDxcBlobWide *pName) {
DXASSERT_NOMSG(!name);
name = pName;
return S_OK;
}
HRESULT SetName(LPCWSTR pName) {
DXASSERT_NOMSG(!name);
if (!pName)
return S_OK;
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(hlsl::DxcCreateBlobWithEncodingOnHeapCopy(
pName, (wcslen(pName) + 1) * sizeof(wchar_t), DXC_CP_WIDE,
&pBlobEncoding));
return pBlobEncoding->QueryInterface(&name);
}
HRESULT SetName(LPCSTR pName) {
DXASSERT_NOMSG(!name);
if (!pName)
return S_OK;
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(TranslateUtf8StringForOutput(pName, strlen(pName) + 1, DXC_CP_WIDE,
&pBlobEncoding));
return pBlobEncoding->QueryInterface(&name);
}
HRESULT SetName(llvm::StringRef Name) {
DXASSERT_NOMSG(!name);
if (Name.empty())
return S_OK;
CComPtr<IDxcBlobEncoding> pBlobEncoding;
IFR(TranslateUtf8StringForOutput(Name.data(), Name.size(), DXC_CP_WIDE,
&pBlobEncoding));
return pBlobEncoding->QueryInterface(&name);
}
/////////////////////////////
// Static object constructors
/////////////////////////////
template <typename DataTy, typename NameTy>
static DxcOutputObject StringOutput(DXC_OUT_KIND kind, UINT32 codePage,
DataTy pText, SIZE_T size, NameTy pName) {
DxcOutputObject output;
output.kind = kind;
IFT(output.SetString(codePage, pText, size));
IFT(output.SetName(pName));
return output;
}
template <typename DataTy, typename NameTy>
static DxcOutputObject StringOutput(DXC_OUT_KIND kind, UINT32 codePage,
DataTy pText, NameTy pName) {
return StringOutput(kind, codePage, pText, kAutoSize, pName);
}
template <typename NameTy>
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, LPCVOID pData,
SIZE_T size, NameTy pName) {
DxcOutputObject output;
output.kind = kind;
IFT(output.SetObjectData(pData, size));
IFT(output.SetName(pName));
return output;
}
template <typename NameTy>
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, IDxcBlob *pBlob,
NameTy pName) {
DxcOutputObject output;
output.kind = kind;
IFT(output.SetObject(pBlob));
IFT(output.SetName(pName));
return output;
}
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, IDxcBlob *pBlob) {
return DataOutput(kind, pBlob, DxcOutNoName);
}
template <typename NameTy>
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, UINT32 codePage,
IDxcBlob *pBlob, NameTy pName) {
DxcOutputObject output;
output.kind = kind;
IFT(output.SetObject(pBlob, codePage));
IFT(output.SetName(pName));
return output;
}
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, UINT32 codePage,
IDxcBlob *pBlob) {
return DataOutput(kind, codePage, pBlob, DxcOutNoName);
}
static DxcOutputObject DataOutput(DXC_OUT_KIND kind, UINT32 codePage,
IUnknown *pBlob) {
DxcOutputObject output;
output.kind = kind;
IFT(output.SetObject(pBlob, codePage));
IFT(output.SetName(DxcOutNoName));
return output;
}
template <typename DataTy>
static DxcOutputObject ErrorOutput(UINT32 codePage, DataTy pText,
SIZE_T size) {
return StringOutput(DXC_OUT_ERRORS, codePage, pText, size, DxcOutNoName);
}
template <typename DataTy>
static DxcOutputObject ErrorOutput(UINT32 codePage, DataTy pText) {
return StringOutput(DXC_OUT_ERRORS, codePage, pText, DxcOutNoName);
}
template <typename NameTy>
static DxcOutputObject ObjectOutput(LPCVOID pData, SIZE_T size,
NameTy pName) {
return DataOutput(DXC_OUT_OBJECT, pData, size, pName);
}
static DxcOutputObject ObjectOutput(LPCVOID pData, SIZE_T size) {
return DataOutput(DXC_OUT_OBJECT, pData, size, DxcOutNoName);
}
};
struct DxcExtraOutputObject {
CComPtr<IDxcBlobWide> pType; // Custom name to identify the object
CComPtr<IDxcBlobWide> pName; // The file path for the output
CComPtr<IUnknown> pObject; // The object itself
};
class DxcExtraOutputs : public IDxcExtraOutputs {
DXC_MICROCOM_TM_REF_FIELDS()
DxcExtraOutputObject *m_Objects = nullptr;
UINT32 m_uCount = 0;
public:
DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
DXC_MICROCOM_TM_CTOR(DxcExtraOutputs)
~DxcExtraOutputs() { Clear(); }
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
void **ppvObject) override {
return DoBasicQueryInterface<IDxcExtraOutputs>(this, iid, ppvObject);
}
/////////////////////
// IDxcExtraOutputs
/////////////////////
UINT32 STDMETHODCALLTYPE GetOutputCount() override { return m_uCount; }
HRESULT STDMETHODCALLTYPE GetOutput(UINT32 uIndex, REFIID iid,
void **ppvObject,
IDxcBlobWide **ppOutputType,
IDxcBlobWide **ppOutputName) override {
if (uIndex >= m_uCount)
return E_INVALIDARG;
DxcExtraOutputObject *pObject = &m_Objects[uIndex];
if (ppOutputType) {
*ppOutputType = nullptr;
IFR(pObject->pType.CopyTo(ppOutputType));
}
if (ppOutputName) {
*ppOutputName = nullptr;
IFR(pObject->pName.CopyTo(ppOutputName));
}
if (ppvObject) {
*ppvObject = nullptr;
if (pObject->pObject) {
IFR(pObject->pObject->QueryInterface(iid, ppvObject));
}
}
return S_OK;
}
/////////////////////
// Internal Interface
/////////////////////
void Clear() {
m_uCount = 0;
if (m_Objects) {
delete[] m_Objects;
m_Objects = nullptr;
}
}
void SetOutputs(const llvm::ArrayRef<DxcExtraOutputObject> outputs) {
Clear();
m_uCount = outputs.size();
if (m_uCount > 0) {
m_Objects = new DxcExtraOutputObject[m_uCount];
for (UINT32 i = 0; i < outputs.size(); i++)
m_Objects[i] = outputs[i];
}
}
};
class DxcResult : public IDxcResult {
private:
DXC_MICROCOM_TM_REF_FIELDS()
HRESULT m_status = S_OK;
DxcOutputObject
m_outputs[kNumDxcOutputTypes]; // indexed by DXC_OUT_KIND enum - 1
DXC_OUT_KIND m_resultType = DXC_OUT_NONE; // result type for GetResult()
UINT32 m_textEncoding = DXC_CP_UTF8; // encoding for text outputs
public:
DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
DXC_MICROCOM_TM_CTOR(DxcResult)
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
void **ppvObject) override {
return DoBasicQueryInterface<IDxcResult, IDxcOperationResult>(this, iid,
ppvObject);
}
//////////////////////
// IDxcOperationResult
//////////////////////
HRESULT STDMETHODCALLTYPE GetStatus(HRESULT *pStatus) override {
if (pStatus == nullptr)
return E_INVALIDARG;
*pStatus = m_status;
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetResult(IDxcBlob **ppResult) override {
*ppResult = nullptr;
if (m_resultType == DXC_OUT_NONE)
return S_OK;
DxcOutputObject *pObject = Output(m_resultType);
if (pObject && pObject->object)
return pObject->object->QueryInterface(ppResult);
return S_OK;
}
HRESULT STDMETHODCALLTYPE
GetErrorBuffer(IDxcBlobEncoding **ppErrors) override {
*ppErrors = nullptr;
DxcOutputObject *pObject = Output(DXC_OUT_ERRORS);
if (pObject && pObject->object)
return pObject->object->QueryInterface(ppErrors);
return S_OK;
}
/////////////
// IDxcResult
/////////////
BOOL STDMETHODCALLTYPE HasOutput(DXC_OUT_KIND dxcOutKind) override {
if (dxcOutKind <= DXC_OUT_NONE || (unsigned)dxcOutKind > kNumDxcOutputTypes)
return FALSE;
return m_outputs[(unsigned)dxcOutKind - 1].kind != DXC_OUT_NONE;
}
HRESULT STDMETHODCALLTYPE GetOutput(DXC_OUT_KIND dxcOutKind, REFIID iid,
void **ppvObject,
IDxcBlobWide **ppOutputName) override {
if (ppvObject == nullptr)
return E_INVALIDARG;
if (dxcOutKind <= DXC_OUT_NONE || (unsigned)dxcOutKind > kNumDxcOutputTypes)
return E_INVALIDARG;
DxcOutputObject &object = m_outputs[(unsigned)dxcOutKind - 1];
if (object.kind == DXC_OUT_NONE)
return E_INVALIDARG;
*ppvObject = nullptr;
if (ppOutputName)
*ppOutputName = nullptr;
IFR(object.object->QueryInterface(iid, ppvObject));
if (ppOutputName && object.name) {
object.name.CopyTo(ppOutputName);
}
return S_OK;
}
UINT32 GetNumOutputs() override {
UINT32 numOutputs = 0;
for (unsigned i = 0; i < kNumDxcOutputTypes; ++i) {
if (m_outputs[i].kind != DXC_OUT_NONE)
numOutputs++;
}
return numOutputs;
}
DXC_OUT_KIND GetOutputByIndex(UINT32 Index) override {
if (!(Index < kNumDxcOutputTypes))
return DXC_OUT_NONE;
UINT32 numOutputs = 0;
unsigned i = 0;
for (; i < kNumDxcOutputTypes; ++i) {
if (Index == numOutputs)
return m_outputs[i].kind;
if (m_outputs[i].kind != DXC_OUT_NONE)
numOutputs++;
}
return DXC_OUT_NONE;
}
DXC_OUT_KIND PrimaryOutput() override { return m_resultType; }
/////////////////////
// Internal Interface
/////////////////////
HRESULT SetEncoding(UINT32 textEncoding) {
if (textEncoding != DXC_CP_ACP && textEncoding != DXC_CP_UTF8 &&
textEncoding != DXC_CP_WIDE)
return E_INVALIDARG;
m_textEncoding = textEncoding;
return S_OK;
}
DxcOutputObject *Output(DXC_OUT_KIND kind) {
if (kind <= DXC_OUT_NONE || (unsigned)kind > kNumDxcOutputTypes)
return nullptr;
return &(m_outputs[(unsigned)kind - 1]);
}
HRESULT ClearOutput(DXC_OUT_KIND kind) {
if (kind <= DXC_OUT_NONE || (unsigned)kind > kNumDxcOutputTypes)
return E_INVALIDARG;
DxcOutputObject &output = m_outputs[(unsigned)kind - 1];
output.kind = DXC_OUT_NONE;
output.object.Release();
output.name.Release();
return S_OK;
}
void ClearAllOutputs() {
for (unsigned i = DXC_OUT_NONE + 1; i <= kNumDxcOutputTypes; i++)
ClearOutput((DXC_OUT_KIND)(i));
}
HRESULT SetStatusAndPrimaryResult(HRESULT status,
DXC_OUT_KIND resultType = DXC_OUT_NONE) {
if ((unsigned)resultType > kNumDxcOutputTypes)
return E_INVALIDARG;
m_status = status;
m_resultType = resultType;
return S_OK;
}
// Set output object and name for previously uninitialized entry
HRESULT SetOutput(const DxcOutputObject &output) {
if (output.kind <= DXC_OUT_NONE ||
(unsigned)output.kind > kNumDxcOutputTypes)
return E_INVALIDARG;
if (!output.object)
return E_INVALIDARG;
DxcOutputObject &internalOutput = m_outputs[(unsigned)output.kind - 1];
// Must not be overwriting an existing output
if (internalOutput.kind != DXC_OUT_NONE)
return E_INVALIDARG;
internalOutput = output;
return S_OK;
}
// Set or overwrite output object and set the kind
HRESULT SetOutputObject(DXC_OUT_KIND kind, IUnknown *pObject) {
if (kind <= DXC_OUT_NONE || (unsigned)kind > kNumDxcOutputTypes)
return E_INVALIDARG;
DxcOutputObject &output = m_outputs[(unsigned)kind - 1];
if (!pObject)
kind = DXC_OUT_NONE;
output.kind = kind;
output.SetObject(pObject, m_textEncoding);
return S_OK;
}
// Set or overwrite output string object and set the kind
template <typename StringTy>
HRESULT SetOutputString(DXC_OUT_KIND kind, StringTy pString,
size_t size = kAutoSize) {
if (kind <= DXC_OUT_NONE || (unsigned)kind > kNumDxcOutputTypes)
return E_INVALIDARG;
DxcOutputObject &output = m_outputs[(unsigned)kind - 1];
if (!pString)
kind = DXC_OUT_NONE;
output.kind = kind;
output.SetString(m_textEncoding, pString, size);
return S_OK;
}
// Set or overwrite the output name. This does not set kind,
// since that indicates an active output, which must have an object.
template <typename NameTy>
HRESULT SetOutputName(DXC_OUT_KIND kind, NameTy Name) {
if (kind <= DXC_OUT_NONE || (unsigned)kind > kNumDxcOutputTypes)
return E_INVALIDARG;
Output(kind)->SetName(Name);
return S_OK;
}
HRESULT SetOutputs(const llvm::ArrayRef<DxcOutputObject> outputs) {
for (unsigned i = 0; i < outputs.size(); i++) {
const DxcOutputObject &output = outputs.data()[i];
// Skip if DXC_OUT_NONE or no object to store
if (output.kind == DXC_OUT_NONE || !output.object)
continue;
IFR(SetOutput(output));
}
return S_OK;
}
HRESULT CopyOutputsFromResult(IDxcResult *pResult) {
if (!pResult)
return E_INVALIDARG;
for (unsigned i = 0; i < kNumDxcOutputTypes; i++) {
DxcOutputObject &output = m_outputs[i];
DXC_OUT_KIND kind = (DXC_OUT_KIND)(i + 1);
if (pResult->HasOutput(kind)) {
IFR(pResult->GetOutput(kind, IID_PPV_ARGS(&output.object),
&output.name));
output.kind = kind;
}
}
return S_OK;
}
// All-in-one initialization
HRESULT Init(HRESULT status, DXC_OUT_KIND resultType,
const llvm::ArrayRef<DxcOutputObject> outputs) {
m_status = status;
m_resultType = resultType;
return SetOutputs(outputs);
}
// All-in-one create functions
static HRESULT Create(HRESULT status, DXC_OUT_KIND resultType,
const DxcOutputObject *pOutputs, unsigned numOutputs,
IDxcResult **ppResult) {
*ppResult = nullptr;
CComPtr<DxcResult> result = DxcResult::Alloc(DxcGetThreadMallocNoRef());
IFROOM(result.p);
IFR(result->Init(status, resultType,
llvm::ArrayRef<DxcOutputObject>(pOutputs, numOutputs)));
*ppResult = result.Detach();
return S_OK;
}
static HRESULT Create(HRESULT status, DXC_OUT_KIND resultType,
const llvm::ArrayRef<DxcOutputObject> outputs,
IDxcResult **ppResult) {
return Create(status, resultType, outputs.data(), outputs.size(), ppResult);
}
// For convenient use in legacy interface implementations
static HRESULT Create(HRESULT status, DXC_OUT_KIND resultType,
const llvm::ArrayRef<DxcOutputObject> outputs,
IDxcOperationResult **ppResult) {
IDxcResult *pResult;
IFR(Create(status, resultType, outputs.data(), outputs.size(), &pResult));
*ppResult = pResult;
return S_OK;
}
};
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/Unicode.h | ///////////////////////////////////////////////////////////////////////////////
// //
// Unicode.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides utitlity functions to work with Unicode and other encodings. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
#ifdef _WIN32
#include <specstrings.h>
#else
// MultiByteToWideChar which is a Windows-specific method.
// This is a very simplistic implementation for non-Windows platforms. This
// implementation completely ignores CodePage and dwFlags.
int MultiByteToWideChar(uint32_t CodePage, uint32_t dwFlags,
const char *lpMultiByteStr, int cbMultiByte,
wchar_t *lpWideCharStr, int cchWideChar);
// WideCharToMultiByte is a Windows-specific method.
// This is a very simplistic implementation for non-Windows platforms. This
// implementation completely ignores CodePage and dwFlags.
int WideCharToMultiByte(uint32_t CodePage, uint32_t dwFlags,
const wchar_t *lpWideCharStr, int cchWideChar,
char *lpMultiByteStr, int cbMultiByte,
const char *lpDefaultChar = nullptr,
bool *lpUsedDefaultChar = nullptr);
#endif // _WIN32
namespace Unicode {
// Based on
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd374101(v=vs.85).aspx.
enum class Encoding {
ASCII = 0,
UTF8,
UTF8_BOM,
UTF16_LE,
UTF16_BE,
UTF32_LE,
UTF32_BE
};
// An acp_char is a character encoded in the current Windows ANSI code page.
typedef char acp_char;
// A ccp_char is a character encoded in the console code page.
typedef char ccp_char;
bool UTF8ToConsoleString(const char *text, size_t textLen, std::string *pValue,
bool *lossy);
bool UTF8ToConsoleString(const char *text, std::string *pValue, bool *lossy);
bool WideToConsoleString(const wchar_t *text, size_t textLen,
std::string *pValue, bool *lossy);
bool WideToConsoleString(const wchar_t *text, std::string *pValue, bool *lossy);
bool UTF8ToWideString(const char *pUTF8, std::wstring *pWide);
bool UTF8ToWideString(const char *pUTF8, size_t cbUTF8, std::wstring *pWide);
std::wstring UTF8ToWideStringOrThrow(const char *pUTF8);
bool WideToUTF8String(const wchar_t *pWide, size_t cWide, std::string *pUTF8);
bool WideToUTF8String(const wchar_t *pWide, std::string *pUTF8);
std::string WideToUTF8StringOrThrow(const wchar_t *pWide);
bool IsStarMatchUTF8(const char *pMask, size_t maskLen, const char *pName,
size_t nameLen);
bool IsStarMatchWide(const wchar_t *pMask, size_t maskLen, const wchar_t *pName,
size_t nameLen);
bool UTF8BufferToWideComHeap(const char *pUTF8, wchar_t **ppWide) throw();
bool UTF8BufferToWideBuffer(const char *pUTF8, int cbUTF8, wchar_t **ppWide,
size_t *pcchWide) throw();
bool WideBufferToUTF8Buffer(const wchar_t *pWide, int cchWide, char **ppUTF8,
size_t *pcbUTF8) throw();
} // namespace Unicode
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/CMakeLists.txt | # Copyright (C) Microsoft Corporation. All rights reserved.
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
# TableGen HLSL options.
add_hlsl_hctgen(HLSLOptions OUTPUT HLSLOptions.td CODE_TAG)
set(LLVM_TARGET_DEFINITIONS HLSLOptions.td)
tablegen(LLVM HLSLOptions.inc -gen-opt-parser-defs)
add_public_tablegen_target(TablegenHLSLOptions)
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/d3dx12.h | //*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#ifndef __D3DX12_H__
#define __D3DX12_H__
#include "d3d12.h"
#if defined(__cplusplus)
struct CD3DX12_DEFAULT {};
extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT;
//------------------------------------------------------------------------------------------------
inline bool operator==(const D3D12_VIEWPORT &l, const D3D12_VIEWPORT &r) {
return l.TopLeftX == r.TopLeftX && l.TopLeftY == r.TopLeftY &&
l.Width == r.Width && l.Height == r.Height &&
l.MinDepth == r.MinDepth && l.MaxDepth == r.MaxDepth;
}
//------------------------------------------------------------------------------------------------
inline bool operator!=(const D3D12_VIEWPORT &l, const D3D12_VIEWPORT &r) {
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_RECT : public D3D12_RECT {
CD3DX12_RECT() = default;
explicit CD3DX12_RECT(const D3D12_RECT &o) : D3D12_RECT(o) {}
explicit CD3DX12_RECT(LONG Left, LONG Top, LONG Right, LONG Bottom) {
left = Left;
top = Top;
right = Right;
bottom = Bottom;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_VIEWPORT : public D3D12_VIEWPORT {
CD3DX12_VIEWPORT() = default;
explicit CD3DX12_VIEWPORT(const D3D12_VIEWPORT &o) : D3D12_VIEWPORT(o) {}
explicit CD3DX12_VIEWPORT(FLOAT topLeftX, FLOAT topLeftY, FLOAT width,
FLOAT height, FLOAT minDepth = D3D12_MIN_DEPTH,
FLOAT maxDepth = D3D12_MAX_DEPTH) {
TopLeftX = topLeftX;
TopLeftY = topLeftY;
Width = width;
Height = height;
MinDepth = minDepth;
MaxDepth = maxDepth;
}
explicit CD3DX12_VIEWPORT(_In_ ID3D12Resource *pResource, UINT mipSlice = 0,
FLOAT topLeftX = 0.0f, FLOAT topLeftY = 0.0f,
FLOAT minDepth = D3D12_MIN_DEPTH,
FLOAT maxDepth = D3D12_MAX_DEPTH) {
auto Desc = pResource->GetDesc();
const UINT64 SubresourceWidth = Desc.Width >> mipSlice;
const UINT64 SubresourceHeight = Desc.Height >> mipSlice;
switch (Desc.Dimension) {
case D3D12_RESOURCE_DIMENSION_BUFFER:
TopLeftX = topLeftX;
TopLeftY = 0.0f;
Width = Desc.Width - topLeftX;
Height = 1.0f;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE1D:
TopLeftX = topLeftX;
TopLeftY = 0.0f;
Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX;
Height = 1.0f;
break;
case D3D12_RESOURCE_DIMENSION_TEXTURE2D:
case D3D12_RESOURCE_DIMENSION_TEXTURE3D:
TopLeftX = topLeftX;
TopLeftY = topLeftY;
Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX;
Height = (SubresourceHeight ? SubresourceHeight : 1.0f) - topLeftY;
break;
default:
break;
}
MinDepth = minDepth;
MaxDepth = maxDepth;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_BOX : public D3D12_BOX {
CD3DX12_BOX() = default;
explicit CD3DX12_BOX(const D3D12_BOX &o) : D3D12_BOX(o) {}
explicit CD3DX12_BOX(LONG Left, LONG Right) {
left = static_cast<UINT>(Left);
top = 0;
front = 0;
right = static_cast<UINT>(Right);
bottom = 1;
back = 1;
}
explicit CD3DX12_BOX(LONG Left, LONG Top, LONG Right, LONG Bottom) {
left = static_cast<UINT>(Left);
top = static_cast<UINT>(Top);
front = 0;
right = static_cast<UINT>(Right);
bottom = static_cast<UINT>(Bottom);
back = 1;
}
explicit CD3DX12_BOX(LONG Left, LONG Top, LONG Front, LONG Right, LONG Bottom,
LONG Back) {
left = static_cast<UINT>(Left);
top = static_cast<UINT>(Top);
front = static_cast<UINT>(Front);
right = static_cast<UINT>(Right);
bottom = static_cast<UINT>(Bottom);
back = static_cast<UINT>(Back);
}
};
inline bool operator==(const D3D12_BOX &l, const D3D12_BOX &r) {
return l.left == r.left && l.top == r.top && l.front == r.front &&
l.right == r.right && l.bottom == r.bottom && l.back == r.back;
}
inline bool operator!=(const D3D12_BOX &l, const D3D12_BOX &r) {
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_DEPTH_STENCIL_DESC : public D3D12_DEPTH_STENCIL_DESC {
CD3DX12_DEPTH_STENCIL_DESC() = default;
explicit CD3DX12_DEPTH_STENCIL_DESC(const D3D12_DEPTH_STENCIL_DESC &o)
: D3D12_DEPTH_STENCIL_DESC(o) {}
explicit CD3DX12_DEPTH_STENCIL_DESC(CD3DX12_DEFAULT) {
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
DepthFunc = D3D12_COMPARISON_FUNC_LESS;
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {
D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP,
D3D12_COMPARISON_FUNC_ALWAYS};
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
}
explicit CD3DX12_DEPTH_STENCIL_DESC(BOOL depthEnable,
D3D12_DEPTH_WRITE_MASK depthWriteMask,
D3D12_COMPARISON_FUNC depthFunc,
BOOL stencilEnable, UINT8 stencilReadMask,
UINT8 stencilWriteMask,
D3D12_STENCIL_OP frontStencilFailOp,
D3D12_STENCIL_OP frontStencilDepthFailOp,
D3D12_STENCIL_OP frontStencilPassOp,
D3D12_COMPARISON_FUNC frontStencilFunc,
D3D12_STENCIL_OP backStencilFailOp,
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp,
D3D12_COMPARISON_FUNC backStencilFunc) {
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
DepthFunc = depthFunc;
StencilEnable = stencilEnable;
StencilReadMask = stencilReadMask;
StencilWriteMask = stencilWriteMask;
FrontFace.StencilFailOp = frontStencilFailOp;
FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
FrontFace.StencilPassOp = frontStencilPassOp;
FrontFace.StencilFunc = frontStencilFunc;
BackFace.StencilFailOp = backStencilFailOp;
BackFace.StencilDepthFailOp = backStencilDepthFailOp;
BackFace.StencilPassOp = backStencilPassOp;
BackFace.StencilFunc = backStencilFunc;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DEPTH_STENCIL_DESC1 : public D3D12_DEPTH_STENCIL_DESC1 {
CD3DX12_DEPTH_STENCIL_DESC1() = default;
explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC1 &o)
: D3D12_DEPTH_STENCIL_DESC1(o) {}
explicit CD3DX12_DEPTH_STENCIL_DESC1(const D3D12_DEPTH_STENCIL_DESC &o) {
DepthEnable = o.DepthEnable;
DepthWriteMask = o.DepthWriteMask;
DepthFunc = o.DepthFunc;
StencilEnable = o.StencilEnable;
StencilReadMask = o.StencilReadMask;
StencilWriteMask = o.StencilWriteMask;
FrontFace.StencilFailOp = o.FrontFace.StencilFailOp;
FrontFace.StencilDepthFailOp = o.FrontFace.StencilDepthFailOp;
FrontFace.StencilPassOp = o.FrontFace.StencilPassOp;
FrontFace.StencilFunc = o.FrontFace.StencilFunc;
BackFace.StencilFailOp = o.BackFace.StencilFailOp;
BackFace.StencilDepthFailOp = o.BackFace.StencilDepthFailOp;
BackFace.StencilPassOp = o.BackFace.StencilPassOp;
BackFace.StencilFunc = o.BackFace.StencilFunc;
DepthBoundsTestEnable = FALSE;
}
explicit CD3DX12_DEPTH_STENCIL_DESC1(CD3DX12_DEFAULT) {
DepthEnable = TRUE;
DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
DepthFunc = D3D12_COMPARISON_FUNC_LESS;
StencilEnable = FALSE;
StencilReadMask = D3D12_DEFAULT_STENCIL_READ_MASK;
StencilWriteMask = D3D12_DEFAULT_STENCIL_WRITE_MASK;
const D3D12_DEPTH_STENCILOP_DESC defaultStencilOp = {
D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP, D3D12_STENCIL_OP_KEEP,
D3D12_COMPARISON_FUNC_ALWAYS};
FrontFace = defaultStencilOp;
BackFace = defaultStencilOp;
DepthBoundsTestEnable = FALSE;
}
explicit CD3DX12_DEPTH_STENCIL_DESC1(
BOOL depthEnable, D3D12_DEPTH_WRITE_MASK depthWriteMask,
D3D12_COMPARISON_FUNC depthFunc, BOOL stencilEnable,
UINT8 stencilReadMask, UINT8 stencilWriteMask,
D3D12_STENCIL_OP frontStencilFailOp,
D3D12_STENCIL_OP frontStencilDepthFailOp,
D3D12_STENCIL_OP frontStencilPassOp,
D3D12_COMPARISON_FUNC frontStencilFunc,
D3D12_STENCIL_OP backStencilFailOp,
D3D12_STENCIL_OP backStencilDepthFailOp,
D3D12_STENCIL_OP backStencilPassOp, D3D12_COMPARISON_FUNC backStencilFunc,
BOOL depthBoundsTestEnable) {
DepthEnable = depthEnable;
DepthWriteMask = depthWriteMask;
DepthFunc = depthFunc;
StencilEnable = stencilEnable;
StencilReadMask = stencilReadMask;
StencilWriteMask = stencilWriteMask;
FrontFace.StencilFailOp = frontStencilFailOp;
FrontFace.StencilDepthFailOp = frontStencilDepthFailOp;
FrontFace.StencilPassOp = frontStencilPassOp;
FrontFace.StencilFunc = frontStencilFunc;
BackFace.StencilFailOp = backStencilFailOp;
BackFace.StencilDepthFailOp = backStencilDepthFailOp;
BackFace.StencilPassOp = backStencilPassOp;
BackFace.StencilFunc = backStencilFunc;
DepthBoundsTestEnable = depthBoundsTestEnable;
}
operator D3D12_DEPTH_STENCIL_DESC() const {
D3D12_DEPTH_STENCIL_DESC D;
D.DepthEnable = DepthEnable;
D.DepthWriteMask = DepthWriteMask;
D.DepthFunc = DepthFunc;
D.StencilEnable = StencilEnable;
D.StencilReadMask = StencilReadMask;
D.StencilWriteMask = StencilWriteMask;
D.FrontFace.StencilFailOp = FrontFace.StencilFailOp;
D.FrontFace.StencilDepthFailOp = FrontFace.StencilDepthFailOp;
D.FrontFace.StencilPassOp = FrontFace.StencilPassOp;
D.FrontFace.StencilFunc = FrontFace.StencilFunc;
D.BackFace.StencilFailOp = BackFace.StencilFailOp;
D.BackFace.StencilDepthFailOp = BackFace.StencilDepthFailOp;
D.BackFace.StencilPassOp = BackFace.StencilPassOp;
D.BackFace.StencilFunc = BackFace.StencilFunc;
return D;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_BLEND_DESC : public D3D12_BLEND_DESC {
CD3DX12_BLEND_DESC() = default;
explicit CD3DX12_BLEND_DESC(const D3D12_BLEND_DESC &o)
: D3D12_BLEND_DESC(o) {}
explicit CD3DX12_BLEND_DESC(CD3DX12_DEFAULT) {
AlphaToCoverageEnable = FALSE;
IndependentBlendEnable = FALSE;
const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc = {
FALSE,
FALSE,
D3D12_BLEND_ONE,
D3D12_BLEND_ZERO,
D3D12_BLEND_OP_ADD,
D3D12_BLEND_ONE,
D3D12_BLEND_ZERO,
D3D12_BLEND_OP_ADD,
D3D12_LOGIC_OP_NOOP,
D3D12_COLOR_WRITE_ENABLE_ALL,
};
for (UINT i = 0; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
RenderTarget[i] = defaultRenderTargetBlendDesc;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RASTERIZER_DESC : public D3D12_RASTERIZER_DESC {
CD3DX12_RASTERIZER_DESC() = default;
explicit CD3DX12_RASTERIZER_DESC(const D3D12_RASTERIZER_DESC &o)
: D3D12_RASTERIZER_DESC(o) {}
explicit CD3DX12_RASTERIZER_DESC(CD3DX12_DEFAULT) {
FillMode = D3D12_FILL_MODE_SOLID;
CullMode = D3D12_CULL_MODE_BACK;
FrontCounterClockwise = FALSE;
DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
DepthClipEnable = TRUE;
MultisampleEnable = FALSE;
AntialiasedLineEnable = FALSE;
ForcedSampleCount = 0;
ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
}
explicit CD3DX12_RASTERIZER_DESC(
D3D12_FILL_MODE fillMode, D3D12_CULL_MODE cullMode,
BOOL frontCounterClockwise, INT depthBias, FLOAT depthBiasClamp,
FLOAT slopeScaledDepthBias, BOOL depthClipEnable, BOOL multisampleEnable,
BOOL antialiasedLineEnable, UINT forcedSampleCount,
D3D12_CONSERVATIVE_RASTERIZATION_MODE conservativeRaster) {
FillMode = fillMode;
CullMode = cullMode;
FrontCounterClockwise = frontCounterClockwise;
DepthBias = depthBias;
DepthBiasClamp = depthBiasClamp;
SlopeScaledDepthBias = slopeScaledDepthBias;
DepthClipEnable = depthClipEnable;
MultisampleEnable = multisampleEnable;
AntialiasedLineEnable = antialiasedLineEnable;
ForcedSampleCount = forcedSampleCount;
ConservativeRaster = conservativeRaster;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RESOURCE_ALLOCATION_INFO
: public D3D12_RESOURCE_ALLOCATION_INFO {
CD3DX12_RESOURCE_ALLOCATION_INFO() = default;
explicit CD3DX12_RESOURCE_ALLOCATION_INFO(
const D3D12_RESOURCE_ALLOCATION_INFO &o)
: D3D12_RESOURCE_ALLOCATION_INFO(o) {}
CD3DX12_RESOURCE_ALLOCATION_INFO(UINT64 size, UINT64 alignment) {
SizeInBytes = size;
Alignment = alignment;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_HEAP_PROPERTIES : public D3D12_HEAP_PROPERTIES {
CD3DX12_HEAP_PROPERTIES() = default;
explicit CD3DX12_HEAP_PROPERTIES(const D3D12_HEAP_PROPERTIES &o)
: D3D12_HEAP_PROPERTIES(o) {}
CD3DX12_HEAP_PROPERTIES(D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
UINT creationNodeMask = 1, UINT nodeMask = 1) {
Type = D3D12_HEAP_TYPE_CUSTOM;
CPUPageProperty = cpuPageProperty;
MemoryPoolPreference = memoryPoolPreference;
CreationNodeMask = creationNodeMask;
VisibleNodeMask = nodeMask;
}
explicit CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE type,
UINT creationNodeMask = 1,
UINT nodeMask = 1) {
Type = type;
CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
CreationNodeMask = creationNodeMask;
VisibleNodeMask = nodeMask;
}
bool IsCPUAccessible() const {
return Type == D3D12_HEAP_TYPE_UPLOAD || Type == D3D12_HEAP_TYPE_READBACK ||
(Type == D3D12_HEAP_TYPE_CUSTOM &&
(CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE ||
CPUPageProperty == D3D12_CPU_PAGE_PROPERTY_WRITE_BACK));
}
};
inline bool operator==(const D3D12_HEAP_PROPERTIES &l,
const D3D12_HEAP_PROPERTIES &r) {
return l.Type == r.Type && l.CPUPageProperty == r.CPUPageProperty &&
l.MemoryPoolPreference == r.MemoryPoolPreference &&
l.CreationNodeMask == r.CreationNodeMask &&
l.VisibleNodeMask == r.VisibleNodeMask;
}
inline bool operator!=(const D3D12_HEAP_PROPERTIES &l,
const D3D12_HEAP_PROPERTIES &r) {
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_HEAP_DESC : public D3D12_HEAP_DESC {
CD3DX12_HEAP_DESC() = default;
explicit CD3DX12_HEAP_DESC(const D3D12_HEAP_DESC &o) : D3D12_HEAP_DESC(o) {}
CD3DX12_HEAP_DESC(UINT64 size, D3D12_HEAP_PROPERTIES properties,
UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = size;
Properties = properties;
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(UINT64 size, D3D12_HEAP_TYPE type, UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = size;
Properties = CD3DX12_HEAP_PROPERTIES(type);
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(UINT64 size, D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
UINT64 alignment = 0,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = size;
Properties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
Alignment = alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO &resAllocInfo,
D3D12_HEAP_PROPERTIES properties,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = properties;
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO &resAllocInfo,
D3D12_HEAP_TYPE type,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = CD3DX12_HEAP_PROPERTIES(type);
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
CD3DX12_HEAP_DESC(const D3D12_RESOURCE_ALLOCATION_INFO &resAllocInfo,
D3D12_CPU_PAGE_PROPERTY cpuPageProperty,
D3D12_MEMORY_POOL memoryPoolPreference,
D3D12_HEAP_FLAGS flags = D3D12_HEAP_FLAG_NONE) {
SizeInBytes = resAllocInfo.SizeInBytes;
Properties = CD3DX12_HEAP_PROPERTIES(cpuPageProperty, memoryPoolPreference);
Alignment = resAllocInfo.Alignment;
Flags = flags;
}
bool IsCPUAccessible() const {
return static_cast<const CD3DX12_HEAP_PROPERTIES *>(&Properties)
->IsCPUAccessible();
}
};
inline bool operator==(const D3D12_HEAP_DESC &l, const D3D12_HEAP_DESC &r) {
return l.SizeInBytes == r.SizeInBytes && l.Properties == r.Properties &&
l.Alignment == r.Alignment && l.Flags == r.Flags;
}
inline bool operator!=(const D3D12_HEAP_DESC &l, const D3D12_HEAP_DESC &r) {
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_CLEAR_VALUE : public D3D12_CLEAR_VALUE {
CD3DX12_CLEAR_VALUE() = default;
explicit CD3DX12_CLEAR_VALUE(const D3D12_CLEAR_VALUE &o)
: D3D12_CLEAR_VALUE(o) {}
CD3DX12_CLEAR_VALUE(DXGI_FORMAT format, const FLOAT color[4]) {
Format = format;
memcpy(Color, color, sizeof(Color));
}
CD3DX12_CLEAR_VALUE(DXGI_FORMAT format, FLOAT depth, UINT8 stencil) {
Format = format;
memset(&Color, 0, sizeof(Color));
/* Use memcpy to preserve NAN values */
memcpy(&DepthStencil.Depth, &depth, sizeof(depth));
DepthStencil.Stencil = stencil;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RANGE : public D3D12_RANGE {
CD3DX12_RANGE() = default;
explicit CD3DX12_RANGE(const D3D12_RANGE &o) : D3D12_RANGE(o) {}
CD3DX12_RANGE(SIZE_T begin, SIZE_T end) {
Begin = begin;
End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RANGE_UINT64 : public D3D12_RANGE_UINT64 {
CD3DX12_RANGE_UINT64() = default;
explicit CD3DX12_RANGE_UINT64(const D3D12_RANGE_UINT64 &o)
: D3D12_RANGE_UINT64(o) {}
CD3DX12_RANGE_UINT64(UINT64 begin, UINT64 end) {
Begin = begin;
End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_RANGE_UINT64
: public D3D12_SUBRESOURCE_RANGE_UINT64 {
CD3DX12_SUBRESOURCE_RANGE_UINT64() = default;
explicit CD3DX12_SUBRESOURCE_RANGE_UINT64(
const D3D12_SUBRESOURCE_RANGE_UINT64 &o)
: D3D12_SUBRESOURCE_RANGE_UINT64(o) {}
CD3DX12_SUBRESOURCE_RANGE_UINT64(UINT subresource,
const D3D12_RANGE_UINT64 &range) {
Subresource = subresource;
Range = range;
}
CD3DX12_SUBRESOURCE_RANGE_UINT64(UINT subresource, UINT64 begin, UINT64 end) {
Subresource = subresource;
Range.Begin = begin;
Range.End = end;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SHADER_BYTECODE : public D3D12_SHADER_BYTECODE {
CD3DX12_SHADER_BYTECODE() = default;
explicit CD3DX12_SHADER_BYTECODE(const D3D12_SHADER_BYTECODE &o)
: D3D12_SHADER_BYTECODE(o) {}
CD3DX12_SHADER_BYTECODE(_In_ ID3DBlob *pShaderBlob) {
pShaderBytecode = pShaderBlob->GetBufferPointer();
BytecodeLength = pShaderBlob->GetBufferSize();
}
CD3DX12_SHADER_BYTECODE(const void *_pShaderBytecode, SIZE_T bytecodeLength) {
pShaderBytecode = _pShaderBytecode;
BytecodeLength = bytecodeLength;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILED_RESOURCE_COORDINATE
: public D3D12_TILED_RESOURCE_COORDINATE {
CD3DX12_TILED_RESOURCE_COORDINATE() = default;
explicit CD3DX12_TILED_RESOURCE_COORDINATE(
const D3D12_TILED_RESOURCE_COORDINATE &o)
: D3D12_TILED_RESOURCE_COORDINATE(o) {}
CD3DX12_TILED_RESOURCE_COORDINATE(UINT x, UINT y, UINT z, UINT subresource) {
X = x;
Y = y;
Z = z;
Subresource = subresource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILE_REGION_SIZE : public D3D12_TILE_REGION_SIZE {
CD3DX12_TILE_REGION_SIZE() = default;
explicit CD3DX12_TILE_REGION_SIZE(const D3D12_TILE_REGION_SIZE &o)
: D3D12_TILE_REGION_SIZE(o) {}
CD3DX12_TILE_REGION_SIZE(UINT numTiles, BOOL useBox, UINT width,
UINT16 height, UINT16 depth) {
NumTiles = numTiles;
UseBox = useBox;
Width = width;
Height = height;
Depth = depth;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_TILING : public D3D12_SUBRESOURCE_TILING {
CD3DX12_SUBRESOURCE_TILING() = default;
explicit CD3DX12_SUBRESOURCE_TILING(const D3D12_SUBRESOURCE_TILING &o)
: D3D12_SUBRESOURCE_TILING(o) {}
CD3DX12_SUBRESOURCE_TILING(UINT widthInTiles, UINT16 heightInTiles,
UINT16 depthInTiles,
UINT startTileIndexInOverallResource) {
WidthInTiles = widthInTiles;
HeightInTiles = heightInTiles;
DepthInTiles = depthInTiles;
StartTileIndexInOverallResource = startTileIndexInOverallResource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TILE_SHAPE : public D3D12_TILE_SHAPE {
CD3DX12_TILE_SHAPE() = default;
explicit CD3DX12_TILE_SHAPE(const D3D12_TILE_SHAPE &o)
: D3D12_TILE_SHAPE(o) {}
CD3DX12_TILE_SHAPE(UINT widthInTexels, UINT heightInTexels,
UINT depthInTexels) {
WidthInTexels = widthInTexels;
HeightInTexels = heightInTexels;
DepthInTexels = depthInTexels;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER {
CD3DX12_RESOURCE_BARRIER() = default;
explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o)
: D3D12_RESOURCE_BARRIER(o) {}
static inline CD3DX12_RESOURCE_BARRIER Transition(
_In_ ID3D12Resource *pResource, D3D12_RESOURCE_STATES stateBefore,
D3D12_RESOURCE_STATES stateAfter,
UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE) {
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER &barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
result.Flags = flags;
barrier.Transition.pResource = pResource;
barrier.Transition.StateBefore = stateBefore;
barrier.Transition.StateAfter = stateAfter;
barrier.Transition.Subresource = subresource;
return result;
}
static inline CD3DX12_RESOURCE_BARRIER
Aliasing(_In_ ID3D12Resource *pResourceBefore,
_In_ ID3D12Resource *pResourceAfter) {
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER &barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING;
barrier.Aliasing.pResourceBefore = pResourceBefore;
barrier.Aliasing.pResourceAfter = pResourceAfter;
return result;
}
static inline CD3DX12_RESOURCE_BARRIER UAV(_In_ ID3D12Resource *pResource) {
CD3DX12_RESOURCE_BARRIER result = {};
D3D12_RESOURCE_BARRIER &barrier = result;
result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV;
barrier.UAV.pResource = pResource;
return result;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_PACKED_MIP_INFO : public D3D12_PACKED_MIP_INFO {
CD3DX12_PACKED_MIP_INFO() = default;
explicit CD3DX12_PACKED_MIP_INFO(const D3D12_PACKED_MIP_INFO &o)
: D3D12_PACKED_MIP_INFO(o) {}
CD3DX12_PACKED_MIP_INFO(UINT8 numStandardMips, UINT8 numPackedMips,
UINT numTilesForPackedMips,
UINT startTileIndexInOverallResource) {
NumStandardMips = numStandardMips;
NumPackedMips = numPackedMips;
NumTilesForPackedMips = numTilesForPackedMips;
StartTileIndexInOverallResource = startTileIndexInOverallResource;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_SUBRESOURCE_FOOTPRINT : public D3D12_SUBRESOURCE_FOOTPRINT {
CD3DX12_SUBRESOURCE_FOOTPRINT() = default;
explicit CD3DX12_SUBRESOURCE_FOOTPRINT(const D3D12_SUBRESOURCE_FOOTPRINT &o)
: D3D12_SUBRESOURCE_FOOTPRINT(o) {}
CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT format, UINT width, UINT height,
UINT depth, UINT rowPitch) {
Format = format;
Width = width;
Height = height;
Depth = depth;
RowPitch = rowPitch;
}
explicit CD3DX12_SUBRESOURCE_FOOTPRINT(const D3D12_RESOURCE_DESC &resDesc,
UINT rowPitch) {
Format = resDesc.Format;
Width = UINT(resDesc.Width);
Height = resDesc.Height;
Depth = (resDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D
? resDesc.DepthOrArraySize
: 1);
RowPitch = rowPitch;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_TEXTURE_COPY_LOCATION : public D3D12_TEXTURE_COPY_LOCATION {
CD3DX12_TEXTURE_COPY_LOCATION() = default;
explicit CD3DX12_TEXTURE_COPY_LOCATION(const D3D12_TEXTURE_COPY_LOCATION &o)
: D3D12_TEXTURE_COPY_LOCATION(o) {}
CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource *pRes) {
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
PlacedFootprint = {};
}
CD3DX12_TEXTURE_COPY_LOCATION(
_In_ ID3D12Resource *pRes,
D3D12_PLACED_SUBRESOURCE_FOOTPRINT const &Footprint) {
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
PlacedFootprint = Footprint;
}
CD3DX12_TEXTURE_COPY_LOCATION(_In_ ID3D12Resource *pRes, UINT Sub) {
pResource = pRes;
Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
PlacedFootprint = {};
SubresourceIndex = Sub;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DESCRIPTOR_RANGE : public D3D12_DESCRIPTOR_RANGE {
CD3DX12_DESCRIPTOR_RANGE() = default;
explicit CD3DX12_DESCRIPTOR_RANGE(const D3D12_DESCRIPTOR_RANGE &o)
: D3D12_DESCRIPTOR_RANGE(o) {}
CD3DX12_DESCRIPTOR_RANGE(D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors, UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
Init(rangeType, numDescriptors, baseShaderRegister, registerSpace,
offsetInDescriptorsFromTableStart);
}
inline void Init(D3D12_DESCRIPTOR_RANGE_TYPE rangeType, UINT numDescriptors,
UINT baseShaderRegister, UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace,
offsetInDescriptorsFromTableStart);
}
static inline void Init(_Out_ D3D12_DESCRIPTOR_RANGE &range,
D3D12_DESCRIPTOR_RANGE_TYPE rangeType,
UINT numDescriptors, UINT baseShaderRegister,
UINT registerSpace = 0,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR_TABLE : public D3D12_ROOT_DESCRIPTOR_TABLE {
CD3DX12_ROOT_DESCRIPTOR_TABLE() = default;
explicit CD3DX12_ROOT_DESCRIPTOR_TABLE(const D3D12_ROOT_DESCRIPTOR_TABLE &o)
: D3D12_ROOT_DESCRIPTOR_TABLE(o) {}
CD3DX12_ROOT_DESCRIPTOR_TABLE(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE *_pDescriptorRanges) {
Init(numDescriptorRanges, _pDescriptorRanges);
}
inline void Init(UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE *_pDescriptorRanges) {
Init(*this, numDescriptorRanges, _pDescriptorRanges);
}
static inline void
Init(_Out_ D3D12_ROOT_DESCRIPTOR_TABLE &rootDescriptorTable,
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE *_pDescriptorRanges) {
rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_CONSTANTS : public D3D12_ROOT_CONSTANTS {
CD3DX12_ROOT_CONSTANTS() = default;
explicit CD3DX12_ROOT_CONSTANTS(const D3D12_ROOT_CONSTANTS &o)
: D3D12_ROOT_CONSTANTS(o) {}
CD3DX12_ROOT_CONSTANTS(UINT num32BitValues, UINT shaderRegister,
UINT registerSpace = 0) {
Init(num32BitValues, shaderRegister, registerSpace);
}
inline void Init(UINT num32BitValues, UINT shaderRegister,
UINT registerSpace = 0) {
Init(*this, num32BitValues, shaderRegister, registerSpace);
}
static inline void Init(_Out_ D3D12_ROOT_CONSTANTS &rootConstants,
UINT num32BitValues, UINT shaderRegister,
UINT registerSpace = 0) {
rootConstants.Num32BitValues = num32BitValues;
rootConstants.ShaderRegister = shaderRegister;
rootConstants.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR : public D3D12_ROOT_DESCRIPTOR {
CD3DX12_ROOT_DESCRIPTOR() = default;
explicit CD3DX12_ROOT_DESCRIPTOR(const D3D12_ROOT_DESCRIPTOR &o)
: D3D12_ROOT_DESCRIPTOR(o) {}
CD3DX12_ROOT_DESCRIPTOR(UINT shaderRegister, UINT registerSpace = 0) {
Init(shaderRegister, registerSpace);
}
inline void Init(UINT shaderRegister, UINT registerSpace = 0) {
Init(*this, shaderRegister, registerSpace);
}
static inline void Init(_Out_ D3D12_ROOT_DESCRIPTOR &table,
UINT shaderRegister, UINT registerSpace = 0) {
table.ShaderRegister = shaderRegister;
table.RegisterSpace = registerSpace;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_PARAMETER : public D3D12_ROOT_PARAMETER {
CD3DX12_ROOT_PARAMETER() = default;
explicit CD3DX12_ROOT_PARAMETER(const D3D12_ROOT_PARAMETER &o)
: D3D12_ROOT_PARAMETER(o) {}
static inline void InitAsDescriptorTable(
_Out_ D3D12_ROOT_PARAMETER &rootParam, UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE *pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR_TABLE::Init(rootParam.DescriptorTable,
numDescriptorRanges, pDescriptorRanges);
}
static inline void InitAsConstants(
_Out_ D3D12_ROOT_PARAMETER &rootParam, UINT num32BitValues,
UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues,
shaderRegister, registerSpace);
}
static inline void InitAsConstantBufferView(
_Out_ D3D12_ROOT_PARAMETER &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister,
registerSpace);
}
static inline void InitAsShaderResourceView(
_Out_ D3D12_ROOT_PARAMETER &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister,
registerSpace);
}
static inline void InitAsUnorderedAccessView(
_Out_ D3D12_ROOT_PARAMETER &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR::Init(rootParam.Descriptor, shaderRegister,
registerSpace);
}
inline void InitAsDescriptorTable(
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE *pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges,
visibility);
}
inline void InitAsConstants(
UINT num32BitValues, UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace,
visibility);
}
inline void InitAsConstantBufferView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsConstantBufferView(*this, shaderRegister, registerSpace, visibility);
}
inline void InitAsShaderResourceView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsShaderResourceView(*this, shaderRegister, registerSpace, visibility);
}
inline void InitAsUnorderedAccessView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, visibility);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_STATIC_SAMPLER_DESC : public D3D12_STATIC_SAMPLER_DESC {
CD3DX12_STATIC_SAMPLER_DESC() = default;
explicit CD3DX12_STATIC_SAMPLER_DESC(const D3D12_STATIC_SAMPLER_DESC &o)
: D3D12_STATIC_SAMPLER_DESC(o) {}
CD3DX12_STATIC_SAMPLER_DESC(
UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0, UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor =
D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) {
Init(shaderRegister, filter, addressU, addressV, addressW, mipLODBias,
maxAnisotropy, comparisonFunc, borderColor, minLOD, maxLOD,
shaderVisibility, registerSpace);
}
static inline void
Init(_Out_ D3D12_STATIC_SAMPLER_DESC &samplerDesc, UINT shaderRegister,
D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0, UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor =
D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) {
samplerDesc.ShaderRegister = shaderRegister;
samplerDesc.Filter = filter;
samplerDesc.AddressU = addressU;
samplerDesc.AddressV = addressV;
samplerDesc.AddressW = addressW;
samplerDesc.MipLODBias = mipLODBias;
samplerDesc.MaxAnisotropy = maxAnisotropy;
samplerDesc.ComparisonFunc = comparisonFunc;
samplerDesc.BorderColor = borderColor;
samplerDesc.MinLOD = minLOD;
samplerDesc.MaxLOD = maxLOD;
samplerDesc.ShaderVisibility = shaderVisibility;
samplerDesc.RegisterSpace = registerSpace;
}
inline void
Init(UINT shaderRegister, D3D12_FILTER filter = D3D12_FILTER_ANISOTROPIC,
D3D12_TEXTURE_ADDRESS_MODE addressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
D3D12_TEXTURE_ADDRESS_MODE addressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP,
FLOAT mipLODBias = 0, UINT maxAnisotropy = 16,
D3D12_COMPARISON_FUNC comparisonFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL,
D3D12_STATIC_BORDER_COLOR borderColor =
D3D12_STATIC_BORDER_COLOR_OPAQUE_WHITE,
FLOAT minLOD = 0.f, FLOAT maxLOD = D3D12_FLOAT32_MAX,
D3D12_SHADER_VISIBILITY shaderVisibility = D3D12_SHADER_VISIBILITY_ALL,
UINT registerSpace = 0) {
Init(*this, shaderRegister, filter, addressU, addressV, addressW,
mipLODBias, maxAnisotropy, comparisonFunc, borderColor, minLOD, maxLOD,
shaderVisibility, registerSpace);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_SIGNATURE_DESC : public D3D12_ROOT_SIGNATURE_DESC {
CD3DX12_ROOT_SIGNATURE_DESC() = default;
explicit CD3DX12_ROOT_SIGNATURE_DESC(const D3D12_ROOT_SIGNATURE_DESC &o)
: D3D12_ROOT_SIGNATURE_DESC(o) {}
CD3DX12_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers,
flags);
}
CD3DX12_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) {
Init(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
}
inline void
Init(UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init(*this, numParameters, _pParameters, numStaticSamplers,
_pStaticSamplers, flags);
}
static inline void
Init(_Out_ D3D12_ROOT_SIGNATURE_DESC &desc, UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
desc.NumParameters = numParameters;
desc.pParameters = _pParameters;
desc.NumStaticSamplers = numStaticSamplers;
desc.pStaticSamplers = _pStaticSamplers;
desc.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_DESCRIPTOR_RANGE1 : public D3D12_DESCRIPTOR_RANGE1 {
CD3DX12_DESCRIPTOR_RANGE1() = default;
explicit CD3DX12_DESCRIPTOR_RANGE1(const D3D12_DESCRIPTOR_RANGE1 &o)
: D3D12_DESCRIPTOR_RANGE1(o) {}
CD3DX12_DESCRIPTOR_RANGE1(
D3D12_DESCRIPTOR_RANGE_TYPE rangeType, UINT numDescriptors,
UINT baseShaderRegister, UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
Init(rangeType, numDescriptors, baseShaderRegister, registerSpace, flags,
offsetInDescriptorsFromTableStart);
}
inline void
Init(D3D12_DESCRIPTOR_RANGE_TYPE rangeType, UINT numDescriptors,
UINT baseShaderRegister, UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
Init(*this, rangeType, numDescriptors, baseShaderRegister, registerSpace,
flags, offsetInDescriptorsFromTableStart);
}
static inline void
Init(_Out_ D3D12_DESCRIPTOR_RANGE1 &range,
D3D12_DESCRIPTOR_RANGE_TYPE rangeType, UINT numDescriptors,
UINT baseShaderRegister, UINT registerSpace = 0,
D3D12_DESCRIPTOR_RANGE_FLAGS flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE,
UINT offsetInDescriptorsFromTableStart =
D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND) {
range.RangeType = rangeType;
range.NumDescriptors = numDescriptors;
range.BaseShaderRegister = baseShaderRegister;
range.RegisterSpace = registerSpace;
range.Flags = flags;
range.OffsetInDescriptorsFromTableStart = offsetInDescriptorsFromTableStart;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR_TABLE1 : public D3D12_ROOT_DESCRIPTOR_TABLE1 {
CD3DX12_ROOT_DESCRIPTOR_TABLE1() = default;
explicit CD3DX12_ROOT_DESCRIPTOR_TABLE1(const D3D12_ROOT_DESCRIPTOR_TABLE1 &o)
: D3D12_ROOT_DESCRIPTOR_TABLE1(o) {}
CD3DX12_ROOT_DESCRIPTOR_TABLE1(
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE1 *_pDescriptorRanges) {
Init(numDescriptorRanges, _pDescriptorRanges);
}
inline void Init(UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE1 *_pDescriptorRanges) {
Init(*this, numDescriptorRanges, _pDescriptorRanges);
}
static inline void
Init(_Out_ D3D12_ROOT_DESCRIPTOR_TABLE1 &rootDescriptorTable,
UINT numDescriptorRanges,
_In_reads_opt_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE1 *_pDescriptorRanges) {
rootDescriptorTable.NumDescriptorRanges = numDescriptorRanges;
rootDescriptorTable.pDescriptorRanges = _pDescriptorRanges;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_DESCRIPTOR1 : public D3D12_ROOT_DESCRIPTOR1 {
CD3DX12_ROOT_DESCRIPTOR1() = default;
explicit CD3DX12_ROOT_DESCRIPTOR1(const D3D12_ROOT_DESCRIPTOR1 &o)
: D3D12_ROOT_DESCRIPTOR1(o) {}
CD3DX12_ROOT_DESCRIPTOR1(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) {
Init(shaderRegister, registerSpace, flags);
}
inline void
Init(UINT shaderRegister, UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) {
Init(*this, shaderRegister, registerSpace, flags);
}
static inline void
Init(_Out_ D3D12_ROOT_DESCRIPTOR1 &table, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE) {
table.ShaderRegister = shaderRegister;
table.RegisterSpace = registerSpace;
table.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_ROOT_PARAMETER1 : public D3D12_ROOT_PARAMETER1 {
CD3DX12_ROOT_PARAMETER1() = default;
explicit CD3DX12_ROOT_PARAMETER1(const D3D12_ROOT_PARAMETER1 &o)
: D3D12_ROOT_PARAMETER1(o) {}
static inline void InitAsDescriptorTable(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam, UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE1 *pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR_TABLE1::Init(
rootParam.DescriptorTable, numDescriptorRanges, pDescriptorRanges);
}
static inline void InitAsConstants(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam, UINT num32BitValues,
UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_CONSTANTS::Init(rootParam.Constants, num32BitValues,
shaderRegister, registerSpace);
}
static inline void InitAsConstantBufferView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister,
registerSpace, flags);
}
static inline void InitAsShaderResourceView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister,
registerSpace, flags);
}
static inline void InitAsUnorderedAccessView(
_Out_ D3D12_ROOT_PARAMETER1 &rootParam, UINT shaderRegister,
UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV;
rootParam.ShaderVisibility = visibility;
CD3DX12_ROOT_DESCRIPTOR1::Init(rootParam.Descriptor, shaderRegister,
registerSpace, flags);
}
inline void InitAsDescriptorTable(
UINT numDescriptorRanges,
_In_reads_(numDescriptorRanges)
const D3D12_DESCRIPTOR_RANGE1 *pDescriptorRanges,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsDescriptorTable(*this, numDescriptorRanges, pDescriptorRanges,
visibility);
}
inline void InitAsConstants(
UINT num32BitValues, UINT shaderRegister, UINT registerSpace = 0,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsConstants(*this, num32BitValues, shaderRegister, registerSpace,
visibility);
}
inline void InitAsConstantBufferView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsConstantBufferView(*this, shaderRegister, registerSpace, flags,
visibility);
}
inline void InitAsShaderResourceView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsShaderResourceView(*this, shaderRegister, registerSpace, flags,
visibility);
}
inline void InitAsUnorderedAccessView(
UINT shaderRegister, UINT registerSpace = 0,
D3D12_ROOT_DESCRIPTOR_FLAGS flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE,
D3D12_SHADER_VISIBILITY visibility = D3D12_SHADER_VISIBILITY_ALL) {
InitAsUnorderedAccessView(*this, shaderRegister, registerSpace, flags,
visibility);
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC
: public D3D12_VERSIONED_ROOT_SIGNATURE_DESC {
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC() = default;
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
const D3D12_VERSIONED_ROOT_SIGNATURE_DESC &o)
: D3D12_VERSIONED_ROOT_SIGNATURE_DESC(o) {}
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
const D3D12_ROOT_SIGNATURE_DESC &o) {
Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
Desc_1_0 = o;
}
explicit CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
const D3D12_ROOT_SIGNATURE_DESC1 &o) {
Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
Desc_1_1 = o;
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init_1_0(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers,
flags);
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(
UINT numParameters,
_In_reads_opt_(numParameters) const D3D12_ROOT_PARAMETER1 *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init_1_1(numParameters, _pParameters, numStaticSamplers, _pStaticSamplers,
flags);
}
CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC(CD3DX12_DEFAULT) {
Init_1_1(0, nullptr, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
}
inline void
Init_1_0(UINT numParameters,
_In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init_1_0(*this, numParameters, _pParameters, numStaticSamplers,
_pStaticSamplers, flags);
}
static inline void
Init_1_0(_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc, UINT numParameters,
_In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_0;
desc.Desc_1_0.NumParameters = numParameters;
desc.Desc_1_0.pParameters = _pParameters;
desc.Desc_1_0.NumStaticSamplers = numStaticSamplers;
desc.Desc_1_0.pStaticSamplers = _pStaticSamplers;
desc.Desc_1_0.Flags = flags;
}
inline void
Init_1_1(UINT numParameters,
_In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER1 *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
Init_1_1(*this, numParameters, _pParameters, numStaticSamplers,
_pStaticSamplers, flags);
}
static inline void
Init_1_1(_Out_ D3D12_VERSIONED_ROOT_SIGNATURE_DESC &desc, UINT numParameters,
_In_reads_opt_(numParameters)
const D3D12_ROOT_PARAMETER1 *_pParameters,
UINT numStaticSamplers = 0,
_In_reads_opt_(numStaticSamplers)
const D3D12_STATIC_SAMPLER_DESC *_pStaticSamplers = nullptr,
D3D12_ROOT_SIGNATURE_FLAGS flags = D3D12_ROOT_SIGNATURE_FLAG_NONE) {
desc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1;
desc.Desc_1_1.NumParameters = numParameters;
desc.Desc_1_1.pParameters = _pParameters;
desc.Desc_1_1.NumStaticSamplers = numStaticSamplers;
desc.Desc_1_1.pStaticSamplers = _pStaticSamplers;
desc.Desc_1_1.Flags = flags;
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_CPU_DESCRIPTOR_HANDLE : public D3D12_CPU_DESCRIPTOR_HANDLE {
CD3DX12_CPU_DESCRIPTOR_HANDLE() = default;
explicit CD3DX12_CPU_DESCRIPTOR_HANDLE(const D3D12_CPU_DESCRIPTOR_HANDLE &o)
: D3D12_CPU_DESCRIPTOR_HANDLE(o) {}
CD3DX12_CPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other,
INT offsetScaledByIncrementSize) {
InitOffsetted(other, offsetScaledByIncrementSize);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE &Offset(INT offsetInDescriptors,
UINT descriptorIncrementSize) {
ptr = SIZE_T(INT64(ptr) +
INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
return *this;
}
CD3DX12_CPU_DESCRIPTOR_HANDLE &Offset(INT offsetScaledByIncrementSize) {
ptr = SIZE_T(INT64(ptr) + INT64(offsetScaledByIncrementSize));
return *this;
}
bool operator==(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other) const {
return (ptr == other.ptr);
}
bool operator!=(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &other) const {
return (ptr != other.ptr);
}
CD3DX12_CPU_DESCRIPTOR_HANDLE &
operator=(const D3D12_CPU_DESCRIPTOR_HANDLE &other) {
ptr = other.ptr;
return *this;
}
inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base,
INT offsetScaledByIncrementSize) {
InitOffsetted(*this, base, offsetScaledByIncrementSize);
}
inline void InitOffsetted(_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
}
static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle,
_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base,
INT offsetScaledByIncrementSize) {
handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
}
static inline void InitOffsetted(_Out_ D3D12_CPU_DESCRIPTOR_HANDLE &handle,
_In_ const D3D12_CPU_DESCRIPTOR_HANDLE &base,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
handle.ptr = SIZE_T(INT64(base.ptr) + INT64(offsetInDescriptors) *
INT64(descriptorIncrementSize));
}
};
//------------------------------------------------------------------------------------------------
struct CD3DX12_GPU_DESCRIPTOR_HANDLE : public D3D12_GPU_DESCRIPTOR_HANDLE {
CD3DX12_GPU_DESCRIPTOR_HANDLE() = default;
explicit CD3DX12_GPU_DESCRIPTOR_HANDLE(const D3D12_GPU_DESCRIPTOR_HANDLE &o)
: D3D12_GPU_DESCRIPTOR_HANDLE(o) {}
CD3DX12_GPU_DESCRIPTOR_HANDLE(CD3DX12_DEFAULT) { ptr = 0; }
CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other,
INT offsetScaledByIncrementSize) {
InitOffsetted(other, offsetScaledByIncrementSize);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
InitOffsetted(other, offsetInDescriptors, descriptorIncrementSize);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE &Offset(INT offsetInDescriptors,
UINT descriptorIncrementSize) {
ptr = UINT64(INT64(ptr) +
INT64(offsetInDescriptors) * INT64(descriptorIncrementSize));
return *this;
}
CD3DX12_GPU_DESCRIPTOR_HANDLE &Offset(INT offsetScaledByIncrementSize) {
ptr = UINT64(INT64(ptr) + INT64(offsetScaledByIncrementSize));
return *this;
}
inline bool operator==(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other) const {
return (ptr == other.ptr);
}
inline bool operator!=(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &other) const {
return (ptr != other.ptr);
}
CD3DX12_GPU_DESCRIPTOR_HANDLE &
operator=(const D3D12_GPU_DESCRIPTOR_HANDLE &other) {
ptr = other.ptr;
return *this;
}
inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base,
INT offsetScaledByIncrementSize) {
InitOffsetted(*this, base, offsetScaledByIncrementSize);
}
inline void InitOffsetted(_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
InitOffsetted(*this, base, offsetInDescriptors, descriptorIncrementSize);
}
static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle,
_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base,
INT offsetScaledByIncrementSize) {
handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetScaledByIncrementSize));
}
static inline void InitOffsetted(_Out_ D3D12_GPU_DESCRIPTOR_HANDLE &handle,
_In_ const D3D12_GPU_DESCRIPTOR_HANDLE &base,
INT offsetInDescriptors,
UINT descriptorIncrementSize) {
handle.ptr = UINT64(INT64(base.ptr) + INT64(offsetInDescriptors) *
INT64(descriptorIncrementSize));
}
};
//------------------------------------------------------------------------------------------------
inline UINT D3D12CalcSubresource(UINT MipSlice, UINT ArraySlice,
UINT PlaneSlice, UINT MipLevels,
UINT ArraySize) {
return MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;
}
//------------------------------------------------------------------------------------------------
template <typename T, typename U, typename V>
inline void D3D12DecomposeSubresource(UINT Subresource, UINT MipLevels,
UINT ArraySize, _Out_ T &MipSlice,
_Out_ U &ArraySlice,
_Out_ V &PlaneSlice) {
MipSlice = static_cast<T>(Subresource % MipLevels);
ArraySlice = static_cast<U>((Subresource / MipLevels) % ArraySize);
PlaneSlice = static_cast<V>(Subresource / (MipLevels * ArraySize));
}
//------------------------------------------------------------------------------------------------
inline UINT8 D3D12GetFormatPlaneCount(_In_ ID3D12Device *pDevice,
DXGI_FORMAT Format) {
D3D12_FEATURE_DATA_FORMAT_INFO formatInfo = {Format, 0};
if (FAILED(pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO,
&formatInfo, sizeof(formatInfo)))) {
return 0;
}
return formatInfo.PlaneCount;
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_RESOURCE_DESC : public D3D12_RESOURCE_DESC {
CD3DX12_RESOURCE_DESC() = default;
explicit CD3DX12_RESOURCE_DESC(const D3D12_RESOURCE_DESC &o)
: D3D12_RESOURCE_DESC(o) {}
CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION dimension, UINT64 alignment,
UINT64 width, UINT height, UINT16 depthOrArraySize,
UINT16 mipLevels, DXGI_FORMAT format, UINT sampleCount,
UINT sampleQuality, D3D12_TEXTURE_LAYOUT layout,
D3D12_RESOURCE_FLAGS flags) {
Dimension = dimension;
Alignment = alignment;
Width = width;
Height = height;
DepthOrArraySize = depthOrArraySize;
MipLevels = mipLevels;
Format = format;
SampleDesc.Count = sampleCount;
SampleDesc.Quality = sampleQuality;
Layout = layout;
Flags = flags;
}
static inline CD3DX12_RESOURCE_DESC
Buffer(const D3D12_RESOURCE_ALLOCATION_INFO &resAllocInfo,
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE) {
return CD3DX12_RESOURCE_DESC(
D3D12_RESOURCE_DIMENSION_BUFFER, resAllocInfo.Alignment,
resAllocInfo.SizeInBytes, 1, 1, 1, DXGI_FORMAT_UNKNOWN, 1, 0,
D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags);
}
static inline CD3DX12_RESOURCE_DESC
Buffer(UINT64 width, D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
UINT64 alignment = 0) {
return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_BUFFER, alignment,
width, 1, 1, 1, DXGI_FORMAT_UNKNOWN, 1, 0,
D3D12_TEXTURE_LAYOUT_ROW_MAJOR, flags);
}
static inline CD3DX12_RESOURCE_DESC
Tex1D(DXGI_FORMAT format, UINT64 width, UINT16 arraySize = 1,
UINT16 mipLevels = 0,
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
UINT64 alignment = 0) {
return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE1D, alignment,
width, 1, arraySize, mipLevels, format, 1, 0,
layout, flags);
}
static inline CD3DX12_RESOURCE_DESC
Tex2D(DXGI_FORMAT format, UINT64 width, UINT height, UINT16 arraySize = 1,
UINT16 mipLevels = 0, UINT sampleCount = 1, UINT sampleQuality = 0,
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
UINT64 alignment = 0) {
return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE2D, alignment,
width, height, arraySize, mipLevels, format,
sampleCount, sampleQuality, layout, flags);
}
static inline CD3DX12_RESOURCE_DESC
Tex3D(DXGI_FORMAT format, UINT64 width, UINT height, UINT16 depth,
UINT16 mipLevels = 0,
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
UINT64 alignment = 0) {
return CD3DX12_RESOURCE_DESC(D3D12_RESOURCE_DIMENSION_TEXTURE3D, alignment,
width, height, depth, mipLevels, format, 1, 0,
layout, flags);
}
inline UINT16 Depth() const {
return (Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize
: 1);
}
inline UINT16 ArraySize() const {
return (Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D ? DepthOrArraySize
: 1);
}
inline UINT8 PlaneCount(_In_ ID3D12Device *pDevice) const {
return D3D12GetFormatPlaneCount(pDevice, Format);
}
inline UINT Subresources(_In_ ID3D12Device *pDevice) const {
return MipLevels * ArraySize() * PlaneCount(pDevice);
}
inline UINT CalcSubresource(UINT MipSlice, UINT ArraySlice, UINT PlaneSlice) {
return D3D12CalcSubresource(MipSlice, ArraySlice, PlaneSlice, MipLevels,
ArraySize());
}
};
inline bool operator==(const D3D12_RESOURCE_DESC &l,
const D3D12_RESOURCE_DESC &r) {
return l.Dimension == r.Dimension && l.Alignment == r.Alignment &&
l.Width == r.Width && l.Height == r.Height &&
l.DepthOrArraySize == r.DepthOrArraySize &&
l.MipLevels == r.MipLevels && l.Format == r.Format &&
l.SampleDesc.Count == r.SampleDesc.Count &&
l.SampleDesc.Quality == r.SampleDesc.Quality && l.Layout == r.Layout &&
l.Flags == r.Flags;
}
inline bool operator!=(const D3D12_RESOURCE_DESC &l,
const D3D12_RESOURCE_DESC &r) {
return !(l == r);
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_VIEW_INSTANCING_DESC : public D3D12_VIEW_INSTANCING_DESC {
CD3DX12_VIEW_INSTANCING_DESC() = default;
explicit CD3DX12_VIEW_INSTANCING_DESC(const D3D12_VIEW_INSTANCING_DESC &o)
: D3D12_VIEW_INSTANCING_DESC(o) {}
explicit CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT) {
ViewInstanceCount = 0;
pViewInstanceLocations = nullptr;
Flags = D3D12_VIEW_INSTANCING_FLAG_NONE;
}
explicit CD3DX12_VIEW_INSTANCING_DESC(
UINT InViewInstanceCount,
const D3D12_VIEW_INSTANCE_LOCATION *InViewInstanceLocations,
D3D12_VIEW_INSTANCING_FLAGS InFlags) {
ViewInstanceCount = InViewInstanceCount;
pViewInstanceLocations = InViewInstanceLocations;
Flags = InFlags;
}
};
//------------------------------------------------------------------------------------------------
// Row-by-row memcpy
inline void MemcpySubresource(_In_ const D3D12_MEMCPY_DEST *pDest,
_In_ const D3D12_SUBRESOURCE_DATA *pSrc,
SIZE_T RowSizeInBytes, UINT NumRows,
UINT NumSlices) {
for (UINT z = 0; z < NumSlices; ++z) {
auto pDestSlice =
reinterpret_cast<BYTE *>(pDest->pData) + pDest->SlicePitch * z;
auto pSrcSlice = reinterpret_cast<const BYTE *>(pSrc->pData) +
pSrc->SlicePitch * LONG_PTR(z);
for (UINT y = 0; y < NumRows; ++y) {
memcpy(pDestSlice + pDest->RowPitch * y,
pSrcSlice + pSrc->RowPitch * LONG_PTR(y), RowSizeInBytes);
}
}
}
//------------------------------------------------------------------------------------------------
// Returns required size of a buffer to be used for data upload
inline UINT64 GetRequiredIntermediateSize(
_In_ ID3D12Resource *pDestinationResource,
_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
UINT NumSubresources) {
auto Desc = pDestinationResource->GetDesc();
UINT64 RequiredSize = 0;
ID3D12Device *pDevice = nullptr;
pDestinationResource->GetDevice(IID_ID3D12Device,
reinterpret_cast<void **>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0,
nullptr, nullptr, nullptr, &RequiredSize);
pDevice->Release();
return RequiredSize;
}
//------------------------------------------------------------------------------------------------
// All arrays must be populated (e.g. by calling GetCopyableFootprints)
inline UINT64
UpdateSubresources(_In_ ID3D12GraphicsCommandList *pCmdList,
_In_ ID3D12Resource *pDestinationResource,
_In_ ID3D12Resource *pIntermediate,
_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
UINT NumSubresources,
UINT64 RequiredSize,
_In_reads_(NumSubresources)
const D3D12_PLACED_SUBRESOURCE_FOOTPRINT *pLayouts,
_In_reads_(NumSubresources) const UINT *pNumRows,
_In_reads_(NumSubresources) const UINT64 *pRowSizesInBytes,
_In_reads_(NumSubresources)
const D3D12_SUBRESOURCE_DATA *pSrcData) {
// Minor validation
auto IntermediateDesc = pIntermediate->GetDesc();
auto DestinationDesc = pDestinationResource->GetDesc();
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
RequiredSize > SIZE_T(-1) ||
(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
(FirstSubresource != 0 || NumSubresources != 1))) {
return 0;
}
BYTE *pData;
HRESULT hr =
pIntermediate->Map(0, nullptr, reinterpret_cast<void **>(&pData));
if (FAILED(hr)) {
return 0;
}
for (UINT i = 0; i < NumSubresources; ++i) {
if (pRowSizesInBytes[i] > SIZE_T(-1))
return 0;
D3D12_MEMCPY_DEST DestData = {
pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch,
SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i])};
MemcpySubresource(&DestData, &pSrcData[i],
static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i],
pLayouts[i].Footprint.Depth);
}
pIntermediate->Unmap(0, nullptr);
if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) {
pCmdList->CopyBufferRegion(pDestinationResource, 0, pIntermediate,
pLayouts[0].Offset, pLayouts[0].Footprint.Width);
} else {
for (UINT i = 0; i < NumSubresources; ++i) {
CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource,
i + FirstSubresource);
CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
}
}
return RequiredSize;
}
//------------------------------------------------------------------------------------------------
// Heap-allocating UpdateSubresources implementation
inline UINT64 UpdateSubresources(
_In_ ID3D12GraphicsCommandList *pCmdList,
_In_ ID3D12Resource *pDestinationResource,
_In_ ID3D12Resource *pIntermediate, UINT64 IntermediateOffset,
_In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource)
UINT NumSubresources,
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA *pSrcData) {
UINT64 RequiredSize = 0;
UINT64 MemToAlloc =
static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) +
sizeof(UINT) + sizeof(UINT64)) *
NumSubresources;
if (MemToAlloc > SIZE_MAX) {
return 0;
}
void *pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
if (pMem == nullptr) {
return 0;
}
auto pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT *>(pMem);
UINT64 *pRowSizesInBytes =
reinterpret_cast<UINT64 *>(pLayouts + NumSubresources);
UINT *pNumRows = reinterpret_cast<UINT *>(pRowSizesInBytes + NumSubresources);
auto Desc = pDestinationResource->GetDesc();
ID3D12Device *pDevice = nullptr;
pDestinationResource->GetDevice(IID_ID3D12Device,
reinterpret_cast<void **>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources,
IntermediateOffset, pLayouts, pNumRows,
pRowSizesInBytes, &RequiredSize);
pDevice->Release();
UINT64 Result =
UpdateSubresources(pCmdList, pDestinationResource, pIntermediate,
FirstSubresource, NumSubresources, RequiredSize,
pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
HeapFree(GetProcessHeap(), 0, pMem);
return Result;
}
//------------------------------------------------------------------------------------------------
// Stack-allocating UpdateSubresources implementation
template <UINT MaxSubresources>
inline UINT64 UpdateSubresources(
_In_ ID3D12GraphicsCommandList *pCmdList,
_In_ ID3D12Resource *pDestinationResource,
_In_ ID3D12Resource *pIntermediate, UINT64 IntermediateOffset,
_In_range_(0, MaxSubresources) UINT FirstSubresource,
_In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_DATA *pSrcData) {
UINT64 RequiredSize = 0;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
UINT NumRows[MaxSubresources];
UINT64 RowSizesInBytes[MaxSubresources];
auto Desc = pDestinationResource->GetDesc();
ID3D12Device *pDevice = nullptr;
pDestinationResource->GetDevice(IID_ID3D12Device,
reinterpret_cast<void **>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources,
IntermediateOffset, Layouts, NumRows,
RowSizesInBytes, &RequiredSize);
pDevice->Release();
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate,
FirstSubresource, NumSubresources, RequiredSize,
Layouts, NumRows, RowSizesInBytes, pSrcData);
}
//------------------------------------------------------------------------------------------------
inline bool D3D12IsLayoutOpaque(D3D12_TEXTURE_LAYOUT Layout) {
return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN ||
Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE;
}
//------------------------------------------------------------------------------------------------
template <typename t_CommandListType>
inline ID3D12CommandList *const *CommandListCast(t_CommandListType *const *pp) {
// This cast is useful for passing strongly typed command list pointers into
// ExecuteCommandLists.
// This cast is valid as long as the const-ness is respected. D3D12 APIs do
// respect the const-ness of their arguments.
return reinterpret_cast<ID3D12CommandList *const *>(pp);
}
//------------------------------------------------------------------------------------------------
// D3D12 exports a new method for serializing root signatures in the Windows 10
// Anniversary Update. To help enable root signature 1.1 features when they are
// available and not require maintaining two code paths for building root
// signatures, this helper method reconstructs a 1.0 signature when 1.1 is not
// supported.
inline HRESULT D3DX12SerializeVersionedRootSignature(
_In_ const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *pRootSignatureDesc,
D3D_ROOT_SIGNATURE_VERSION MaxVersion, _Outptr_ ID3DBlob **ppBlob,
_Always_(_Outptr_opt_result_maybenull_) ID3DBlob **ppErrorBlob) {
if (ppErrorBlob != nullptr) {
*ppErrorBlob = nullptr;
}
switch (MaxVersion) {
case D3D_ROOT_SIGNATURE_VERSION_1_0:
switch (pRootSignatureDesc->Version) {
case D3D_ROOT_SIGNATURE_VERSION_1_0:
return D3D12SerializeRootSignature(&pRootSignatureDesc->Desc_1_0,
D3D_ROOT_SIGNATURE_VERSION_1, ppBlob,
ppErrorBlob);
case D3D_ROOT_SIGNATURE_VERSION_1_1: {
HRESULT hr = S_OK;
const D3D12_ROOT_SIGNATURE_DESC1 &desc_1_1 = pRootSignatureDesc->Desc_1_1;
const SIZE_T ParametersSize =
sizeof(D3D12_ROOT_PARAMETER) * desc_1_1.NumParameters;
void *pParameters = (ParametersSize > 0)
? HeapAlloc(GetProcessHeap(), 0, ParametersSize)
: nullptr;
if (ParametersSize > 0 && pParameters == nullptr) {
hr = E_OUTOFMEMORY;
}
auto pParameters_1_0 =
reinterpret_cast<D3D12_ROOT_PARAMETER *>(pParameters);
if (SUCCEEDED(hr)) {
for (UINT n = 0; n < desc_1_1.NumParameters; n++) {
__analysis_assume(ParametersSize == sizeof(D3D12_ROOT_PARAMETER) *
desc_1_1.NumParameters);
pParameters_1_0[n].ParameterType =
desc_1_1.pParameters[n].ParameterType;
pParameters_1_0[n].ShaderVisibility =
desc_1_1.pParameters[n].ShaderVisibility;
switch (desc_1_1.pParameters[n].ParameterType) {
case D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS:
pParameters_1_0[n].Constants.Num32BitValues =
desc_1_1.pParameters[n].Constants.Num32BitValues;
pParameters_1_0[n].Constants.RegisterSpace =
desc_1_1.pParameters[n].Constants.RegisterSpace;
pParameters_1_0[n].Constants.ShaderRegister =
desc_1_1.pParameters[n].Constants.ShaderRegister;
break;
case D3D12_ROOT_PARAMETER_TYPE_CBV:
case D3D12_ROOT_PARAMETER_TYPE_SRV:
case D3D12_ROOT_PARAMETER_TYPE_UAV:
pParameters_1_0[n].Descriptor.RegisterSpace =
desc_1_1.pParameters[n].Descriptor.RegisterSpace;
pParameters_1_0[n].Descriptor.ShaderRegister =
desc_1_1.pParameters[n].Descriptor.ShaderRegister;
break;
case D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
const D3D12_ROOT_DESCRIPTOR_TABLE1 &table_1_1 =
desc_1_1.pParameters[n].DescriptorTable;
const SIZE_T DescriptorRangesSize =
sizeof(D3D12_DESCRIPTOR_RANGE) * table_1_1.NumDescriptorRanges;
void *pDescriptorRanges =
(DescriptorRangesSize > 0 && SUCCEEDED(hr))
? HeapAlloc(GetProcessHeap(), 0, DescriptorRangesSize)
: nullptr;
if (DescriptorRangesSize > 0 && pDescriptorRanges == nullptr) {
hr = E_OUTOFMEMORY;
}
auto pDescriptorRanges_1_0 =
reinterpret_cast<D3D12_DESCRIPTOR_RANGE *>(pDescriptorRanges);
if (SUCCEEDED(hr)) {
for (UINT x = 0; x < table_1_1.NumDescriptorRanges; x++) {
__analysis_assume(DescriptorRangesSize ==
sizeof(D3D12_DESCRIPTOR_RANGE) *
table_1_1.NumDescriptorRanges);
pDescriptorRanges_1_0[x].BaseShaderRegister =
table_1_1.pDescriptorRanges[x].BaseShaderRegister;
pDescriptorRanges_1_0[x].NumDescriptors =
table_1_1.pDescriptorRanges[x].NumDescriptors;
pDescriptorRanges_1_0[x].OffsetInDescriptorsFromTableStart =
table_1_1.pDescriptorRanges[x]
.OffsetInDescriptorsFromTableStart;
pDescriptorRanges_1_0[x].RangeType =
table_1_1.pDescriptorRanges[x].RangeType;
pDescriptorRanges_1_0[x].RegisterSpace =
table_1_1.pDescriptorRanges[x].RegisterSpace;
}
}
D3D12_ROOT_DESCRIPTOR_TABLE &table_1_0 =
pParameters_1_0[n].DescriptorTable;
table_1_0.NumDescriptorRanges = table_1_1.NumDescriptorRanges;
table_1_0.pDescriptorRanges = pDescriptorRanges_1_0;
}
}
}
if (SUCCEEDED(hr)) {
CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(
desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers,
desc_1_1.pStaticSamplers, desc_1_1.Flags);
hr = D3D12SerializeRootSignature(
&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob);
}
if (pParameters) {
for (UINT n = 0; n < desc_1_1.NumParameters; n++) {
if (desc_1_1.pParameters[n].ParameterType ==
D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) {
HeapFree(
GetProcessHeap(), 0,
reinterpret_cast<void *>(const_cast<D3D12_DESCRIPTOR_RANGE *>(
pParameters_1_0[n].DescriptorTable.pDescriptorRanges)));
}
}
HeapFree(GetProcessHeap(), 0, pParameters);
}
return hr;
}
}
break;
case D3D_ROOT_SIGNATURE_VERSION_1_1:
return D3D12SerializeVersionedRootSignature(pRootSignatureDesc, ppBlob,
ppErrorBlob);
}
return E_INVALIDARG;
}
//------------------------------------------------------------------------------------------------
struct CD3DX12_RT_FORMAT_ARRAY : public D3D12_RT_FORMAT_ARRAY {
CD3DX12_RT_FORMAT_ARRAY() = default;
explicit CD3DX12_RT_FORMAT_ARRAY(const D3D12_RT_FORMAT_ARRAY &o)
: D3D12_RT_FORMAT_ARRAY(o) {}
explicit CD3DX12_RT_FORMAT_ARRAY(_In_reads_(NumFormats)
const DXGI_FORMAT *pFormats,
UINT NumFormats) {
NumRenderTargets = NumFormats;
memcpy(RTFormats, pFormats, sizeof(RTFormats));
// assumes ARRAY_SIZE(pFormats) == ARRAY_SIZE(RTFormats)
}
};
//------------------------------------------------------------------------------------------------
// Pipeline State Stream Helpers
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
// Stream Subobjects, i.e. elements of a stream
struct DefaultSampleMask {
operator UINT() { return UINT_MAX; }
};
struct DefaultSampleDesc {
operator DXGI_SAMPLE_DESC() { return DXGI_SAMPLE_DESC{1, 0}; }
};
#pragma warning(push)
#pragma warning(disable : 4324)
template <typename InnerStructType, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE Type,
typename DefaultArg = InnerStructType>
class alignas(void *) CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT {
private:
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE _Type;
InnerStructType _Inner;
public:
CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT()
noexcept : _Type(Type), _Inner(DefaultArg()) {}
CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT(InnerStructType const &i)
: _Type(Type), _Inner(i) {}
CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT &operator=(InnerStructType const &i) {
_Type = Type;
_Inner = i;
return *this;
}
operator InnerStructType const &() const { return _Inner; }
operator InnerStructType &() { return _Inner; }
InnerStructType *operator&() { return &_Inner; }
InnerStructType const *operator&() const { return &_Inner; }
};
#pragma warning(pop)
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_PIPELINE_STATE_FLAGS, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS>
CD3DX12_PIPELINE_STATE_STREAM_FLAGS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
UINT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK>
CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
ID3D12RootSignature *, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE>
CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_INPUT_LAYOUT_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT>
CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE>
CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_PRIMITIVE_TOPOLOGY_TYPE,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY>
CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS>
CD3DX12_PIPELINE_STATE_STREAM_VS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS>
CD3DX12_PIPELINE_STATE_STREAM_GS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_STREAM_OUTPUT_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT>
CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS>
CD3DX12_PIPELINE_STATE_STREAM_HS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS>
CD3DX12_PIPELINE_STATE_STREAM_DS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS>
CD3DX12_PIPELINE_STATE_STREAM_PS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_SHADER_BYTECODE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS>
CD3DX12_PIPELINE_STATE_STREAM_CS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
CD3DX12_BLEND_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND,
CD3DX12_DEFAULT>
CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
CD3DX12_DEPTH_STENCIL_DESC,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL, CD3DX12_DEFAULT>
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
CD3DX12_DEPTH_STENCIL_DESC1,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1, CD3DX12_DEFAULT>
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
DXGI_FORMAT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT>
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
CD3DX12_RASTERIZER_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER,
CD3DX12_DEFAULT>
CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_RT_FORMAT_ARRAY,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS>
CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
DXGI_SAMPLE_DESC, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC,
DefaultSampleDesc>
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
UINT, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK, DefaultSampleMask>
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
D3D12_CACHED_PIPELINE_STATE, D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO>
CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO;
typedef CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT<
CD3DX12_VIEW_INSTANCING_DESC,
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING, CD3DX12_DEFAULT>
CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING;
//------------------------------------------------------------------------------------------------
// Stream Parser Helpers
struct ID3DX12PipelineParserCallbacks {
// Subobject Callbacks
virtual void FlagsCb(D3D12_PIPELINE_STATE_FLAGS) {}
virtual void NodeMaskCb(UINT) {}
virtual void RootSignatureCb(ID3D12RootSignature *) {}
virtual void InputLayoutCb(const D3D12_INPUT_LAYOUT_DESC &) {}
virtual void IBStripCutValueCb(D3D12_INDEX_BUFFER_STRIP_CUT_VALUE) {}
virtual void PrimitiveTopologyTypeCb(D3D12_PRIMITIVE_TOPOLOGY_TYPE) {}
virtual void VSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void GSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void StreamOutputCb(const D3D12_STREAM_OUTPUT_DESC &) {}
virtual void HSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void DSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void PSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void CSCb(const D3D12_SHADER_BYTECODE &) {}
virtual void BlendStateCb(const D3D12_BLEND_DESC &) {}
virtual void DepthStencilStateCb(const D3D12_DEPTH_STENCIL_DESC &) {}
virtual void DepthStencilState1Cb(const D3D12_DEPTH_STENCIL_DESC1 &) {}
virtual void DSVFormatCb(DXGI_FORMAT) {}
virtual void RasterizerStateCb(const D3D12_RASTERIZER_DESC &) {}
virtual void RTVFormatsCb(const D3D12_RT_FORMAT_ARRAY &) {}
virtual void SampleDescCb(const DXGI_SAMPLE_DESC &) {}
virtual void SampleMaskCb(UINT) {}
virtual void ViewInstancingCb(const D3D12_VIEW_INSTANCING_DESC &) {}
virtual void CachedPSOCb(const D3D12_CACHED_PIPELINE_STATE &) {}
// Error Callbacks
virtual void ErrorBadInputParameter(UINT /*ParameterIndex*/) {}
virtual void ErrorDuplicateSubobject(
D3D12_PIPELINE_STATE_SUBOBJECT_TYPE /*DuplicateType*/) {}
virtual void ErrorUnknownSubobject(UINT /*UnknownTypeValue*/) {}
virtual ~ID3DX12PipelineParserCallbacks() = default;
};
// CD3DX12_PIPELINE_STATE_STREAM1 Works on RS3+ (where there is a new view
// instancing subobject). Use CD3DX12_PIPELINE_STATE_STREAM for RS2+ support.
struct CD3DX12_PIPELINE_STATE_STREAM1 {
CD3DX12_PIPELINE_STATE_STREAM1() = default;
CD3DX12_PIPELINE_STATE_STREAM1(const D3D12_GRAPHICS_PIPELINE_STATE_DESC &Desc)
: Flags(Desc.Flags), NodeMask(Desc.NodeMask),
pRootSignature(Desc.pRootSignature), InputLayout(Desc.InputLayout),
IBStripCutValue(Desc.IBStripCutValue),
PrimitiveTopologyType(Desc.PrimitiveTopologyType), VS(Desc.VS),
GS(Desc.GS), StreamOutput(Desc.StreamOutput), HS(Desc.HS), DS(Desc.DS),
PS(Desc.PS), BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
DepthStencilState(CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
DSVFormat(Desc.DSVFormat),
RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
RTVFormats(
CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
SampleDesc(Desc.SampleDesc), SampleMask(Desc.SampleMask),
CachedPSO(Desc.CachedPSO),
ViewInstancingDesc(CD3DX12_VIEW_INSTANCING_DESC(CD3DX12_DEFAULT())) {}
CD3DX12_PIPELINE_STATE_STREAM1(const D3D12_COMPUTE_PIPELINE_STATE_DESC &Desc)
: Flags(Desc.Flags), NodeMask(Desc.NodeMask),
pRootSignature(Desc.pRootSignature),
CS(CD3DX12_SHADER_BYTECODE(Desc.CS)), CachedPSO(Desc.CachedPSO) {
static_cast<D3D12_DEPTH_STENCIL_DESC1 &>(DepthStencilState).DepthEnable =
false;
}
CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT InputLayout;
CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE IBStripCutValue;
CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY PrimitiveTopologyType;
CD3DX12_PIPELINE_STATE_STREAM_VS VS;
CD3DX12_PIPELINE_STATE_STREAM_GS GS;
CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT StreamOutput;
CD3DX12_PIPELINE_STATE_STREAM_HS HS;
CD3DX12_PIPELINE_STATE_STREAM_DS DS;
CD3DX12_PIPELINE_STATE_STREAM_PS PS;
CD3DX12_PIPELINE_STATE_STREAM_CS CS;
CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
CD3DX12_PIPELINE_STATE_STREAM_VIEW_INSTANCING ViewInstancingDesc;
D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const {
D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
D.Flags = this->Flags;
D.NodeMask = this->NodeMask;
D.pRootSignature = this->pRootSignature;
D.InputLayout = this->InputLayout;
D.IBStripCutValue = this->IBStripCutValue;
D.PrimitiveTopologyType = this->PrimitiveTopologyType;
D.VS = this->VS;
D.GS = this->GS;
D.StreamOutput = this->StreamOutput;
D.HS = this->HS;
D.DS = this->DS;
D.PS = this->PS;
D.BlendState = this->BlendState;
D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
D.DSVFormat = this->DSVFormat;
D.RasterizerState = this->RasterizerState;
D.NumRenderTargets =
D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
memcpy(D.RTVFormats, D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
sizeof(D.RTVFormats));
D.SampleDesc = this->SampleDesc;
D.SampleMask = this->SampleMask;
D.CachedPSO = this->CachedPSO;
return D;
}
D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const {
D3D12_COMPUTE_PIPELINE_STATE_DESC D;
D.Flags = this->Flags;
D.NodeMask = this->NodeMask;
D.pRootSignature = this->pRootSignature;
D.CS = this->CS;
D.CachedPSO = this->CachedPSO;
return D;
}
};
// CD3DX12_PIPELINE_STATE_STREAM works on RS2+ but does not support new
// subobject(s) added in RS3+. See CD3DX12_PIPELINE_STATE_STREAM1 for instance.
struct CD3DX12_PIPELINE_STATE_STREAM {
CD3DX12_PIPELINE_STATE_STREAM() = default;
CD3DX12_PIPELINE_STATE_STREAM(const D3D12_GRAPHICS_PIPELINE_STATE_DESC &Desc)
: Flags(Desc.Flags), NodeMask(Desc.NodeMask),
pRootSignature(Desc.pRootSignature), InputLayout(Desc.InputLayout),
IBStripCutValue(Desc.IBStripCutValue),
PrimitiveTopologyType(Desc.PrimitiveTopologyType), VS(Desc.VS),
GS(Desc.GS), StreamOutput(Desc.StreamOutput), HS(Desc.HS), DS(Desc.DS),
PS(Desc.PS), BlendState(CD3DX12_BLEND_DESC(Desc.BlendState)),
DepthStencilState(CD3DX12_DEPTH_STENCIL_DESC1(Desc.DepthStencilState)),
DSVFormat(Desc.DSVFormat),
RasterizerState(CD3DX12_RASTERIZER_DESC(Desc.RasterizerState)),
RTVFormats(
CD3DX12_RT_FORMAT_ARRAY(Desc.RTVFormats, Desc.NumRenderTargets)),
SampleDesc(Desc.SampleDesc), SampleMask(Desc.SampleMask),
CachedPSO(Desc.CachedPSO) {}
CD3DX12_PIPELINE_STATE_STREAM(const D3D12_COMPUTE_PIPELINE_STATE_DESC &Desc)
: Flags(Desc.Flags), NodeMask(Desc.NodeMask),
pRootSignature(Desc.pRootSignature),
CS(CD3DX12_SHADER_BYTECODE(Desc.CS)), CachedPSO(Desc.CachedPSO) {}
CD3DX12_PIPELINE_STATE_STREAM_FLAGS Flags;
CD3DX12_PIPELINE_STATE_STREAM_NODE_MASK NodeMask;
CD3DX12_PIPELINE_STATE_STREAM_ROOT_SIGNATURE pRootSignature;
CD3DX12_PIPELINE_STATE_STREAM_INPUT_LAYOUT InputLayout;
CD3DX12_PIPELINE_STATE_STREAM_IB_STRIP_CUT_VALUE IBStripCutValue;
CD3DX12_PIPELINE_STATE_STREAM_PRIMITIVE_TOPOLOGY PrimitiveTopologyType;
CD3DX12_PIPELINE_STATE_STREAM_VS VS;
CD3DX12_PIPELINE_STATE_STREAM_GS GS;
CD3DX12_PIPELINE_STATE_STREAM_STREAM_OUTPUT StreamOutput;
CD3DX12_PIPELINE_STATE_STREAM_HS HS;
CD3DX12_PIPELINE_STATE_STREAM_DS DS;
CD3DX12_PIPELINE_STATE_STREAM_PS PS;
CD3DX12_PIPELINE_STATE_STREAM_CS CS;
CD3DX12_PIPELINE_STATE_STREAM_BLEND_DESC BlendState;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL1 DepthStencilState;
CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL_FORMAT DSVFormat;
CD3DX12_PIPELINE_STATE_STREAM_RASTERIZER RasterizerState;
CD3DX12_PIPELINE_STATE_STREAM_RENDER_TARGET_FORMATS RTVFormats;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_DESC SampleDesc;
CD3DX12_PIPELINE_STATE_STREAM_SAMPLE_MASK SampleMask;
CD3DX12_PIPELINE_STATE_STREAM_CACHED_PSO CachedPSO;
D3D12_GRAPHICS_PIPELINE_STATE_DESC GraphicsDescV0() const {
D3D12_GRAPHICS_PIPELINE_STATE_DESC D;
D.Flags = this->Flags;
D.NodeMask = this->NodeMask;
D.pRootSignature = this->pRootSignature;
D.InputLayout = this->InputLayout;
D.IBStripCutValue = this->IBStripCutValue;
D.PrimitiveTopologyType = this->PrimitiveTopologyType;
D.VS = this->VS;
D.GS = this->GS;
D.StreamOutput = this->StreamOutput;
D.HS = this->HS;
D.DS = this->DS;
D.PS = this->PS;
D.BlendState = this->BlendState;
D.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC1(
D3D12_DEPTH_STENCIL_DESC1(this->DepthStencilState));
D.DSVFormat = this->DSVFormat;
D.RasterizerState = this->RasterizerState;
D.NumRenderTargets =
D3D12_RT_FORMAT_ARRAY(this->RTVFormats).NumRenderTargets;
memcpy(D.RTVFormats, D3D12_RT_FORMAT_ARRAY(this->RTVFormats).RTFormats,
sizeof(D.RTVFormats));
D.SampleDesc = this->SampleDesc;
D.SampleMask = this->SampleMask;
D.CachedPSO = this->CachedPSO;
return D;
}
D3D12_COMPUTE_PIPELINE_STATE_DESC ComputeDescV0() const {
D3D12_COMPUTE_PIPELINE_STATE_DESC D;
D.Flags = this->Flags;
D.NodeMask = this->NodeMask;
D.pRootSignature = this->pRootSignature;
D.CS = this->CS;
D.CachedPSO = this->CachedPSO;
return D;
}
};
struct CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER
: public ID3DX12PipelineParserCallbacks {
CD3DX12_PIPELINE_STATE_STREAM1 PipelineStream;
CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER() noexcept : SeenDSS(false) {
// Adjust defaults to account for absent members.
PipelineStream.PrimitiveTopologyType =
D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
// Depth disabled if no DSV format specified.
static_cast<D3D12_DEPTH_STENCIL_DESC1 &>(PipelineStream.DepthStencilState)
.DepthEnable = false;
}
// ID3DX12PipelineParserCallbacks
void FlagsCb(D3D12_PIPELINE_STATE_FLAGS Flags) override {
PipelineStream.Flags = Flags;
}
void NodeMaskCb(UINT NodeMask) override {
PipelineStream.NodeMask = NodeMask;
}
void RootSignatureCb(ID3D12RootSignature *pRootSignature) override {
PipelineStream.pRootSignature = pRootSignature;
}
void InputLayoutCb(const D3D12_INPUT_LAYOUT_DESC &InputLayout) override {
PipelineStream.InputLayout = InputLayout;
}
void IBStripCutValueCb(
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue) override {
PipelineStream.IBStripCutValue = IBStripCutValue;
}
void PrimitiveTopologyTypeCb(
D3D12_PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType) override {
PipelineStream.PrimitiveTopologyType = PrimitiveTopologyType;
}
void VSCb(const D3D12_SHADER_BYTECODE &VS) override {
PipelineStream.VS = VS;
}
void GSCb(const D3D12_SHADER_BYTECODE &GS) override {
PipelineStream.GS = GS;
}
void StreamOutputCb(const D3D12_STREAM_OUTPUT_DESC &StreamOutput) override {
PipelineStream.StreamOutput = StreamOutput;
}
void HSCb(const D3D12_SHADER_BYTECODE &HS) override {
PipelineStream.HS = HS;
}
void DSCb(const D3D12_SHADER_BYTECODE &DS) override {
PipelineStream.DS = DS;
}
void PSCb(const D3D12_SHADER_BYTECODE &PS) override {
PipelineStream.PS = PS;
}
void CSCb(const D3D12_SHADER_BYTECODE &CS) override {
PipelineStream.CS = CS;
}
void BlendStateCb(const D3D12_BLEND_DESC &BlendState) override {
PipelineStream.BlendState = CD3DX12_BLEND_DESC(BlendState);
}
void DepthStencilStateCb(
const D3D12_DEPTH_STENCIL_DESC &DepthStencilState) override {
PipelineStream.DepthStencilState =
CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
SeenDSS = true;
}
void DepthStencilState1Cb(
const D3D12_DEPTH_STENCIL_DESC1 &DepthStencilState) override {
PipelineStream.DepthStencilState =
CD3DX12_DEPTH_STENCIL_DESC1(DepthStencilState);
SeenDSS = true;
}
void DSVFormatCb(DXGI_FORMAT DSVFormat) override {
PipelineStream.DSVFormat = DSVFormat;
if (!SeenDSS && DSVFormat != DXGI_FORMAT_UNKNOWN) {
// Re-enable depth for the default state.
static_cast<D3D12_DEPTH_STENCIL_DESC1 &>(PipelineStream.DepthStencilState)
.DepthEnable = true;
}
}
void
RasterizerStateCb(const D3D12_RASTERIZER_DESC &RasterizerState) override {
PipelineStream.RasterizerState = CD3DX12_RASTERIZER_DESC(RasterizerState);
}
void RTVFormatsCb(const D3D12_RT_FORMAT_ARRAY &RTVFormats) override {
PipelineStream.RTVFormats = RTVFormats;
}
void SampleDescCb(const DXGI_SAMPLE_DESC &SampleDesc) override {
PipelineStream.SampleDesc = SampleDesc;
}
void SampleMaskCb(UINT SampleMask) override {
PipelineStream.SampleMask = SampleMask;
}
void ViewInstancingCb(
const D3D12_VIEW_INSTANCING_DESC &ViewInstancingDesc) override {
PipelineStream.ViewInstancingDesc =
CD3DX12_VIEW_INSTANCING_DESC(ViewInstancingDesc);
}
void CachedPSOCb(const D3D12_CACHED_PIPELINE_STATE &CachedPSO) override {
PipelineStream.CachedPSO = CachedPSO;
}
private:
bool SeenDSS;
};
inline D3D12_PIPELINE_STATE_SUBOBJECT_TYPE
D3DX12GetBaseSubobjectType(D3D12_PIPELINE_STATE_SUBOBJECT_TYPE SubobjectType) {
switch (SubobjectType) {
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1:
return D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL;
default:
return SubobjectType;
}
}
inline HRESULT
D3DX12ParsePipelineStream(const D3D12_PIPELINE_STATE_STREAM_DESC &Desc,
ID3DX12PipelineParserCallbacks *pCallbacks) {
if (pCallbacks == nullptr) {
return E_INVALIDARG;
}
if (Desc.SizeInBytes == 0 || Desc.pPipelineStateSubobjectStream == nullptr) {
pCallbacks->ErrorBadInputParameter(1); // first parameter issue
return E_INVALIDARG;
}
bool SubobjectSeen[D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID] = {};
for (SIZE_T CurOffset = 0, SizeOfSubobject = 0; CurOffset < Desc.SizeInBytes;
CurOffset += SizeOfSubobject) {
BYTE *pStream =
static_cast<BYTE *>(Desc.pPipelineStateSubobjectStream) + CurOffset;
auto SubobjectType =
*reinterpret_cast<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE *>(pStream);
if (SubobjectType < 0 ||
SubobjectType >= D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_MAX_VALID) {
pCallbacks->ErrorUnknownSubobject(SubobjectType);
return E_INVALIDARG;
}
if (SubobjectSeen[D3DX12GetBaseSubobjectType(SubobjectType)]) {
pCallbacks->ErrorDuplicateSubobject(SubobjectType);
return E_INVALIDARG; // disallow subobject duplicates in a stream
}
SubobjectSeen[SubobjectType] = true;
switch (SubobjectType) {
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_ROOT_SIGNATURE:
pCallbacks->RootSignatureCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::pRootSignature) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::pRootSignature);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VS:
pCallbacks->VSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::VS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::VS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PS:
pCallbacks->PSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::PS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::PS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DS:
pCallbacks->DSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::DS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::DS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_HS:
pCallbacks->HSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::HS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::HS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_GS:
pCallbacks->GSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::GS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::GS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CS:
pCallbacks->CSCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::CS) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::CS);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_STREAM_OUTPUT:
pCallbacks->StreamOutputCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::StreamOutput) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::StreamOutput);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_BLEND:
pCallbacks->BlendStateCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::BlendState) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::BlendState);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_MASK:
pCallbacks->SampleMaskCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::SampleMask) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::SampleMask);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER:
pCallbacks->RasterizerStateCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::RasterizerState) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::RasterizerState);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL:
pCallbacks->DepthStencilStateCb(
*reinterpret_cast<CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM_DEPTH_STENCIL);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1:
pCallbacks->DepthStencilState1Cb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::DepthStencilState) *>(
pStream));
SizeOfSubobject =
sizeof(CD3DX12_PIPELINE_STATE_STREAM::DepthStencilState);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_INPUT_LAYOUT:
pCallbacks->InputLayoutCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::InputLayout) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::InputLayout);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_IB_STRIP_CUT_VALUE:
pCallbacks->IBStripCutValueCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::IBStripCutValue) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::IBStripCutValue);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY:
pCallbacks->PrimitiveTopologyTypeCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::PrimitiveTopologyType) *>(
pStream));
SizeOfSubobject =
sizeof(CD3DX12_PIPELINE_STATE_STREAM::PrimitiveTopologyType);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS:
pCallbacks->RTVFormatsCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::RTVFormats) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::RTVFormats);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL_FORMAT:
pCallbacks->DSVFormatCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::DSVFormat) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::DSVFormat);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_SAMPLE_DESC:
pCallbacks->SampleDescCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::SampleDesc) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::SampleDesc);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_NODE_MASK:
pCallbacks->NodeMaskCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::NodeMask) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::NodeMask);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_CACHED_PSO:
pCallbacks->CachedPSOCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM::CachedPSO) *>(pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::CachedPSO);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_FLAGS:
pCallbacks->FlagsCb(
*reinterpret_cast<decltype(CD3DX12_PIPELINE_STATE_STREAM::Flags) *>(
pStream));
SizeOfSubobject = sizeof(CD3DX12_PIPELINE_STATE_STREAM::Flags);
break;
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_VIEW_INSTANCING:
pCallbacks->ViewInstancingCb(
*reinterpret_cast<
decltype(CD3DX12_PIPELINE_STATE_STREAM1::ViewInstancingDesc) *>(
pStream));
SizeOfSubobject =
sizeof(CD3DX12_PIPELINE_STATE_STREAM1::ViewInstancingDesc);
break;
default:
pCallbacks->ErrorUnknownSubobject(SubobjectType);
return E_INVALIDARG;
break;
}
}
return S_OK;
}
//------------------------------------------------------------------------------------------------
inline bool operator==(const D3D12_CLEAR_VALUE &a, const D3D12_CLEAR_VALUE &b) {
if (a.Format != b.Format)
return false;
if (a.Format == DXGI_FORMAT_D24_UNORM_S8_UINT ||
a.Format == DXGI_FORMAT_D16_UNORM || a.Format == DXGI_FORMAT_D32_FLOAT ||
a.Format == DXGI_FORMAT_D32_FLOAT_S8X24_UINT) {
return (a.DepthStencil.Depth == b.DepthStencil.Depth) &&
(a.DepthStencil.Stencil == b.DepthStencil.Stencil);
} else {
return (a.Color[0] == b.Color[0]) && (a.Color[1] == b.Color[1]) &&
(a.Color[2] == b.Color[2]) && (a.Color[3] == b.Color[3]);
}
}
inline bool
operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &a,
const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &b) {
return a.ClearValue == b.ClearValue;
}
inline bool
operator==(const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &a,
const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &b) {
if (a.pSrcResource != b.pSrcResource)
return false;
if (a.pDstResource != b.pDstResource)
return false;
if (a.SubresourceCount != b.SubresourceCount)
return false;
if (a.Format != b.Format)
return false;
if (a.ResolveMode != b.ResolveMode)
return false;
if (a.PreserveResolveSource != b.PreserveResolveSource)
return false;
return true;
}
inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS &a,
const D3D12_RENDER_PASS_BEGINNING_ACCESS &b) {
if (a.Type != b.Type)
return false;
if (a.Type == D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR &&
!(a.Clear == b.Clear))
return false;
return true;
}
inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS &a,
const D3D12_RENDER_PASS_ENDING_ACCESS &b) {
if (a.Type != b.Type)
return false;
if (a.Type == D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE &&
!(a.Resolve == b.Resolve))
return false;
return true;
}
inline bool operator==(const D3D12_RENDER_PASS_RENDER_TARGET_DESC &a,
const D3D12_RENDER_PASS_RENDER_TARGET_DESC &b) {
if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr)
return false;
if (!(a.BeginningAccess == b.BeginningAccess))
return false;
if (!(a.EndingAccess == b.EndingAccess))
return false;
return true;
}
inline bool operator==(const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &a,
const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &b) {
if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr)
return false;
if (!(a.DepthBeginningAccess == b.DepthBeginningAccess))
return false;
if (!(a.StencilBeginningAccess == b.StencilBeginningAccess))
return false;
if (!(a.DepthEndingAccess == b.DepthEndingAccess))
return false;
if (!(a.StencilEndingAccess == b.StencilEndingAccess))
return false;
return true;
}
#ifndef D3DX12_NO_STATE_OBJECT_HELPERS
//================================================================================================
// D3DX12 State Object Creation Helpers
//
// Helper classes for creating new style state objects out of an arbitrary set
// of subobjects. Uses STL
//
// Start by instantiating CD3DX12_STATE_OBJECT_DESC (see it's public methods).
// One of its methods is CreateSubobject(), which has a comment showing a couple
// of options for defining subobjects using the helper classes for each
// subobject (CD3DX12_DXIL_LIBRARY_SUBOBJECT etc.). The subobject helpers each
// have methods specific to the subobject for configuring it's contents.
//
//================================================================================================
#include <list>
#include <memory>
#include <string>
#include <vector>
#include <wrl/client.h>
//------------------------------------------------------------------------------------------------
class CD3DX12_STATE_OBJECT_DESC {
public:
CD3DX12_STATE_OBJECT_DESC() { Init(D3D12_STATE_OBJECT_TYPE_COLLECTION); }
CD3DX12_STATE_OBJECT_DESC(D3D12_STATE_OBJECT_TYPE Type) { Init(Type); }
void SetStateObjectType(D3D12_STATE_OBJECT_TYPE Type) { m_Desc.Type = Type; }
operator const D3D12_STATE_OBJECT_DESC &() {
// Do final preparation work
m_RepointedAssociations.clear();
m_SubobjectArray.clear();
m_SubobjectArray.reserve(m_Desc.NumSubobjects);
// Flatten subobjects into an array (each flattened subobject still has a
// member that's a pointer to it's desc that's not flattened)
for (auto Iter = m_SubobjectList.begin(); Iter != m_SubobjectList.end();
Iter++) {
m_SubobjectArray.push_back(*Iter);
// Store new location in array so we can redirect pointers contained in
// subobjects
Iter->pSubobjectArrayLocation = &m_SubobjectArray.back();
}
// For subobjects with pointer fields, create a new copy of those subobject
// definitions with fixed pointers
for (UINT i = 0; i < m_Desc.NumSubobjects; i++) {
if (m_SubobjectArray[i].Type ==
D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION) {
auto pOriginalSubobjectAssociation =
reinterpret_cast<const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION *>(
m_SubobjectArray[i].pDesc);
D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION Repointed =
*pOriginalSubobjectAssociation;
auto pWrapper = static_cast<const SUBOBJECT_WRAPPER *>(
pOriginalSubobjectAssociation->pSubobjectToAssociate);
Repointed.pSubobjectToAssociate = pWrapper->pSubobjectArrayLocation;
m_RepointedAssociations.push_back(Repointed);
m_SubobjectArray[i].pDesc = &m_RepointedAssociations.back();
}
}
// Below: using ugly way to get pointer in case .data() is not defined
m_Desc.pSubobjects = m_Desc.NumSubobjects ? &m_SubobjectArray[0] : nullptr;
return m_Desc;
}
operator const D3D12_STATE_OBJECT_DESC *() {
// Cast calls the above final preparation work
return &static_cast<const D3D12_STATE_OBJECT_DESC &>(*this);
}
// CreateSubobject creates a sububject helper (e.g.
// CD3DX12_HIT_GROUP_SUBOBJECT) whose lifetime is owned by this class. e.g.
//
// CD3DX12_STATE_OBJECT_DESC
// Collection1(D3D12_STATE_OBJECT_TYPE_COLLECTION); auto Lib0 =
// Collection1.CreateSubobject<CD3DX12_DXIL_LIBRARY_SUBOBJECT>();
// Lib0->SetDXILLibrary(&pMyAppDxilLibs[0]);
// Lib0->DefineExport(L"rayGenShader0"); // in practice these export
// listings might be
// // data/engine driven
// etc.
//
// Alternatively, users can instantiate sububject helpers explicitly, such as
// via local variables instead, passing the state object desc that should
// point to it into the helper constructor (or call
// mySubobjectHelper.AddToStateObject(Collection1)). In this alternative
// scenario, the user must keep the subobject alive as long as the state
// object it is associated with is alive, else it's pointer references will be
// stale. e.g.
//
// CD3DX12_STATE_OBJECT_DESC
// RaytracingState2(D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE);
// CD3DX12_DXIL_LIBRARY_SUBOBJECT LibA(RaytracingState2);
// LibA.SetDXILLibrary(&pMyAppDxilLibs[4]); // not manually specifying
// exports
// // - meaning all exports in the
// libraries
// // are exported
// etc.
template <typename T> T *CreateSubobject() {
T *pSubobject = new T(*this);
m_OwnedSubobjectHelpers.emplace_back(pSubobject);
return pSubobject;
}
private:
D3D12_STATE_SUBOBJECT *TrackSubobject(D3D12_STATE_SUBOBJECT_TYPE Type,
void *pDesc) {
SUBOBJECT_WRAPPER Subobject;
Subobject.pSubobjectArrayLocation = nullptr;
Subobject.Type = Type;
Subobject.pDesc = pDesc;
m_SubobjectList.push_back(Subobject);
m_Desc.NumSubobjects++;
return &m_SubobjectList.back();
}
void Init(D3D12_STATE_OBJECT_TYPE Type) {
SetStateObjectType(Type);
m_Desc.pSubobjects = nullptr;
m_Desc.NumSubobjects = 0;
m_SubobjectList.clear();
m_SubobjectArray.clear();
m_RepointedAssociations.clear();
}
typedef struct SUBOBJECT_WRAPPER : public D3D12_STATE_SUBOBJECT {
D3D12_STATE_SUBOBJECT
*pSubobjectArrayLocation; // new location when flattened into array
// for repointing pointers in subobjects
} SUBOBJECT_WRAPPER;
D3D12_STATE_OBJECT_DESC m_Desc;
std::list<SUBOBJECT_WRAPPER>
m_SubobjectList; // Pointers to list nodes handed out so
// these can be edited live
std::vector<D3D12_STATE_SUBOBJECT>
m_SubobjectArray; // Built at the end, copying list contents
std::list<D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION>
m_RepointedAssociations; // subobject type that contains pointers to other
// subobjects, repointed to flattened array
class StringContainer {
public:
LPCWSTR LocalCopy(LPCWSTR string, bool bSingleString = false) {
if (string) {
if (bSingleString) {
m_Strings.clear();
m_Strings.push_back(string);
} else {
m_Strings.push_back(string);
}
return m_Strings.back().c_str();
} else {
return nullptr;
}
}
void clear() { m_Strings.clear(); }
private:
std::list<std::wstring> m_Strings;
};
class SUBOBJECT_HELPER_BASE {
public:
SUBOBJECT_HELPER_BASE() { Init(); }
virtual ~SUBOBJECT_HELPER_BASE() {}
virtual D3D12_STATE_SUBOBJECT_TYPE Type() const = 0;
void AddToStateObject(CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
m_pSubobject = ContainingStateObject.TrackSubobject(Type(), Data());
}
protected:
virtual void *Data() = 0;
void Init() { m_pSubobject = nullptr; }
D3D12_STATE_SUBOBJECT *m_pSubobject;
};
#if (__cplusplus >= 201103L)
std::list<std::unique_ptr<const SUBOBJECT_HELPER_BASE>>
m_OwnedSubobjectHelpers;
#else
class OWNED_HELPER {
public:
OWNED_HELPER(const SUBOBJECT_HELPER_BASE *pHelper) { m_pHelper = pHelper; }
~OWNED_HELPER() { delete m_pHelper; }
const SUBOBJECT_HELPER_BASE *m_pHelper;
};
std::list<OWNED_HELPER> m_OwnedSubobjectHelpers;
#endif
friend class CD3DX12_DXIL_LIBRARY_SUBOBJECT;
friend class CD3DX12_EXISTING_COLLECTION_SUBOBJECT;
friend class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT;
friend class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
friend class CD3DX12_HIT_GROUP_SUBOBJECT;
friend class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT;
friend class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT;
friend class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT;
friend class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT;
friend class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT;
friend class CD3DX12_NODE_MASK_SUBOBJECT;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_DXIL_LIBRARY_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_DXIL_LIBRARY_SUBOBJECT() { Init(); }
CD3DX12_DXIL_LIBRARY_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetDXILLibrary(D3D12_SHADER_BYTECODE *pCode) {
static const D3D12_SHADER_BYTECODE Default = {};
m_Desc.DXILLibrary = pCode ? *pCode : Default;
}
void DefineExport(LPCWSTR Name, LPCWSTR ExportToRename = nullptr,
D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE) {
D3D12_EXPORT_DESC Export;
Export.Name = m_Strings.LocalCopy(Name);
Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
Export.Flags = Flags;
m_Exports.push_back(Export);
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case
// .data() is not defined
m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
}
template <size_t N> void DefineExports(LPCWSTR (&Exports)[N]) {
for (UINT i = 0; i < N; i++) {
DefineExport(Exports[i]);
}
}
void DefineExports(LPCWSTR *Exports, UINT N) {
for (UINT i = 0; i < N; i++) {
DefineExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_DXIL_LIBRARY_DESC &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_Exports.clear();
}
void *Data() { return &m_Desc; }
D3D12_DXIL_LIBRARY_DESC m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<D3D12_EXPORT_DESC> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_EXISTING_COLLECTION_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_EXISTING_COLLECTION_SUBOBJECT() { Init(); }
CD3DX12_EXISTING_COLLECTION_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetExistingCollection(ID3D12StateObject *pExistingCollection) {
m_Desc.pExistingCollection = pExistingCollection;
m_CollectionRef = pExistingCollection;
}
void DefineExport(LPCWSTR Name, LPCWSTR ExportToRename = nullptr,
D3D12_EXPORT_FLAGS Flags = D3D12_EXPORT_FLAG_NONE) {
D3D12_EXPORT_DESC Export;
Export.Name = m_Strings.LocalCopy(Name);
Export.ExportToRename = m_Strings.LocalCopy(ExportToRename);
Export.Flags = Flags;
m_Exports.push_back(Export);
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case
// .data() is not defined
m_Desc.NumExports = static_cast<UINT>(m_Exports.size());
}
template <size_t N> void DefineExports(LPCWSTR (&Exports)[N]) {
for (UINT i = 0; i < N; i++) {
DefineExport(Exports[i]);
}
}
void DefineExports(LPCWSTR *Exports, UINT N) {
for (UINT i = 0; i < N; i++) {
DefineExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_EXISTING_COLLECTION;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_EXISTING_COLLECTION_DESC &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_CollectionRef = nullptr;
m_Strings.clear();
m_Exports.clear();
}
void *Data() { return &m_Desc; }
D3D12_EXISTING_COLLECTION_DESC m_Desc;
Microsoft::WRL::ComPtr<ID3D12StateObject> m_CollectionRef;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<D3D12_EXPORT_DESC> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT() { Init(); }
CD3DX12_SUBOBJECT_TO_EXPORTS_ASSOCIATION_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void
SetSubobjectToAssociate(const D3D12_STATE_SUBOBJECT &SubobjectToAssociate) {
m_Desc.pSubobjectToAssociate = &SubobjectToAssociate;
}
void AddExport(LPCWSTR Export) {
m_Desc.NumExports++;
m_Exports.push_back(m_Strings.LocalCopy(Export));
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case
// .data() is not defined
}
template <size_t N> void AddExports(LPCWSTR (&Exports)[N]) {
for (UINT i = 0; i < N; i++) {
AddExport(Exports[i]);
}
}
void AddExports(LPCWSTR *Exports, UINT N) {
for (UINT i = 0; i < N; i++) {
AddExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION &() const {
return m_Desc;
}
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_Exports.clear();
}
void *Data() { return &m_Desc; }
D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
std::vector<LPCWSTR> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION() { Init(); }
CD3DX12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetSubobjectNameToAssociate(LPCWSTR SubobjectToAssociate) {
m_Desc.SubobjectToAssociate =
m_SubobjectName.LocalCopy(SubobjectToAssociate, true);
}
void AddExport(LPCWSTR Export) {
m_Desc.NumExports++;
m_Exports.push_back(m_Strings.LocalCopy(Export));
m_Desc.pExports = &m_Exports[0]; // using ugly way to get pointer in case
// .data() is not defined
}
template <size_t N> void AddExports(LPCWSTR (&Exports)[N]) {
for (UINT i = 0; i < N; i++) {
AddExport(Exports[i]);
}
}
void AddExports(LPCWSTR *Exports, UINT N) {
for (UINT i = 0; i < N; i++) {
AddExport(Exports[i]);
}
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION &() const {
return m_Desc;
}
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
m_Strings.clear();
m_SubobjectName.clear();
m_Exports.clear();
}
void *Data() { return &m_Desc; }
D3D12_DXIL_SUBOBJECT_TO_EXPORTS_ASSOCIATION m_Desc;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_Strings;
CD3DX12_STATE_OBJECT_DESC::StringContainer m_SubobjectName;
std::vector<LPCWSTR> m_Exports;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_HIT_GROUP_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_HIT_GROUP_SUBOBJECT() { Init(); }
CD3DX12_HIT_GROUP_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetHitGroupExport(LPCWSTR exportName) {
m_Desc.HitGroupExport = m_Strings[0].LocalCopy(exportName, true);
}
void SetHitGroupType(D3D12_HIT_GROUP_TYPE Type) { m_Desc.Type = Type; }
void SetAnyHitShaderImport(LPCWSTR importName) {
m_Desc.AnyHitShaderImport = m_Strings[1].LocalCopy(importName, true);
}
void SetClosestHitShaderImport(LPCWSTR importName) {
m_Desc.ClosestHitShaderImport = m_Strings[2].LocalCopy(importName, true);
}
void SetIntersectionShaderImport(LPCWSTR importName) {
m_Desc.IntersectionShaderImport = m_Strings[3].LocalCopy(importName, true);
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_HIT_GROUP;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_HIT_GROUP_DESC &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
for (UINT i = 0; i < m_NumStrings; i++) {
m_Strings[i].clear();
}
}
void *Data() { return &m_Desc; }
D3D12_HIT_GROUP_DESC m_Desc;
static const UINT m_NumStrings = 4;
CD3DX12_STATE_OBJECT_DESC::StringContainer
m_Strings[m_NumStrings]; // one string for every entrypoint name
};
//------------------------------------------------------------------------------------------------
class CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT() { Init(); }
CD3DX12_RAYTRACING_SHADER_CONFIG_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void Config(UINT MaxPayloadSizeInBytes, UINT MaxAttributeSizeInBytes) {
m_Desc.MaxPayloadSizeInBytes = MaxPayloadSizeInBytes;
m_Desc.MaxAttributeSizeInBytes = MaxAttributeSizeInBytes;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_SHADER_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_RAYTRACING_SHADER_CONFIG &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void *Data() { return &m_Desc; }
D3D12_RAYTRACING_SHADER_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT() { Init(); }
CD3DX12_RAYTRACING_PIPELINE_CONFIG_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void Config(UINT MaxTraceRecursionDepth) {
m_Desc.MaxTraceRecursionDepth = MaxTraceRecursionDepth;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_RAYTRACING_PIPELINE_CONFIG &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void *Data() { return &m_Desc; }
D3D12_RAYTRACING_PIPELINE_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT() { Init(); }
CD3DX12_GLOBAL_ROOT_SIGNATURE_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetRootSignature(ID3D12RootSignature *pRootSig) {
m_pRootSig = pRootSig;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator ID3D12RootSignature *() const { return m_pRootSig.Get(); }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_pRootSig = nullptr;
}
void *Data() { return m_pRootSig.GetAddressOf(); }
Microsoft::WRL::ComPtr<ID3D12RootSignature> m_pRootSig;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT() { Init(); }
CD3DX12_LOCAL_ROOT_SIGNATURE_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetRootSignature(ID3D12RootSignature *pRootSig) {
m_pRootSig = pRootSig;
}
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator ID3D12RootSignature *() const { return m_pRootSig.Get(); }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_pRootSig = nullptr;
}
void *Data() { return m_pRootSig.GetAddressOf(); }
Microsoft::WRL::ComPtr<ID3D12RootSignature> m_pRootSig;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT() { Init(); }
CD3DX12_STATE_OBJECT_CONFIG_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetFlags(D3D12_STATE_OBJECT_FLAGS Flags) { m_Desc.Flags = Flags; }
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_STATE_OBJECT_CONFIG;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_STATE_OBJECT_CONFIG &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void *Data() { return &m_Desc; }
D3D12_STATE_OBJECT_CONFIG m_Desc;
};
//------------------------------------------------------------------------------------------------
class CD3DX12_NODE_MASK_SUBOBJECT
: public CD3DX12_STATE_OBJECT_DESC::SUBOBJECT_HELPER_BASE {
public:
CD3DX12_NODE_MASK_SUBOBJECT() { Init(); }
CD3DX12_NODE_MASK_SUBOBJECT(
CD3DX12_STATE_OBJECT_DESC &ContainingStateObject) {
Init();
AddToStateObject(ContainingStateObject);
}
void SetNodeMask(UINT NodeMask) { m_Desc.NodeMask = NodeMask; }
D3D12_STATE_SUBOBJECT_TYPE Type() const {
return D3D12_STATE_SUBOBJECT_TYPE_NODE_MASK;
}
operator const D3D12_STATE_SUBOBJECT &() const { return *m_pSubobject; }
operator const D3D12_NODE_MASK &() const { return m_Desc; }
private:
void Init() {
SUBOBJECT_HELPER_BASE::Init();
m_Desc = {};
}
void *Data() { return &m_Desc; }
D3D12_NODE_MASK m_Desc;
};
#endif // #ifndef D3DX12_NO_STATE_OBJECT_HELPERS
#endif // defined( __cplusplus )
#endif //__D3DX12_H__ |
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/SPIRVOptions.h | //===------- SPIRVOptions.h -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file outlines the command-line options used by SPIR-V CodeGen.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_SPIRV_OPTIONS_H
#define LLVM_SPIRV_OPTIONS_H
#ifdef ENABLE_SPIRV_CODEGEN
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
namespace clang {
namespace spirv {
enum class SpirvLayoutRule {
Void,
GLSLStd140,
GLSLStd430,
RelaxedGLSLStd140, // std140 with relaxed vector layout
RelaxedGLSLStd430, // std430 with relaxed vector layout
FxcCTBuffer, // fxc.exe layout rule for cbuffer/tbuffer
FxcSBuffer, // fxc.exe layout rule for structured buffers
Scalar, // VK_EXT_scalar_block_layout
Max, // This is an invalid layout rule
};
struct SpirvCodeGenOptions {
/// Disable legalization and optimization and emit raw SPIR-V
bool codeGenHighLevel;
bool debugInfoFile;
bool debugInfoLine;
bool debugInfoSource;
bool debugInfoTool;
bool debugInfoRich;
/// Use NonSemantic.Vulkan.DebugInfo.100 debug info instead of
/// OpenCL.DebugInfo.100
bool debugInfoVulkan;
bool defaultRowMajor;
bool disableValidation;
bool enable16BitTypes;
bool finiteMathOnly;
bool enableReflect;
bool invertY; // Additive inverse
bool invertW; // Multiplicative inverse
bool noWarnEmulatedFeatures;
bool noWarnIgnoredFeatures;
bool preserveBindings;
bool preserveInterface;
bool useDxLayout;
bool useGlLayout;
bool useLegacyBufferMatrixOrder;
bool useScalarLayout;
bool flattenResourceArrays;
bool reduceLoadSize;
bool autoShiftBindings;
bool supportNonzeroBaseInstance;
bool supportNonzeroBaseVertex;
bool fixFuncCallArguments;
bool allowRWStructuredBufferArrays;
bool enableMaximalReconvergence;
bool useVulkanMemoryModel;
bool IEEEStrict;
/// Maximum length in words for the OpString literal containing the shader
/// source for DebugSource and DebugSourceContinued. If the source code length
/// is larger than this number, we will use DebugSourceContinued instructions
/// for follow-up source code after the first DebugSource instruction. Note
/// that this number must be less than or equal to 0xFFFDu because of the
/// limitation of a single SPIR-V instruction size (0xFFFF) - 2 operand words
/// for OpString. Currently a smaller value is only used to test
/// DebugSourceContinued generation.
uint32_t debugSourceLen;
SpirvLayoutRule cBufferLayoutRule;
SpirvLayoutRule sBufferLayoutRule;
SpirvLayoutRule tBufferLayoutRule;
SpirvLayoutRule ampPayloadLayoutRule;
llvm::StringRef stageIoOrder;
llvm::StringRef targetEnv;
uint32_t maxId;
llvm::SmallVector<int32_t, 4> bShift;
llvm::SmallVector<int32_t, 4> sShift;
llvm::SmallVector<int32_t, 4> tShift;
llvm::SmallVector<int32_t, 4> uShift;
llvm::SmallVector<llvm::StringRef, 4> allowedExtensions;
llvm::SmallVector<llvm::StringRef, 4> optConfig;
std::vector<std::string> bindRegister;
std::vector<std::string> bindGlobals;
std::string entrypointName;
std::string floatDenormalMode; // OPT_denorm
bool signaturePacking; ///< Whether signature packing is enabled or not
bool printAll; // Dump SPIR-V module before each pass and after the last one.
// String representation of all command line options and input file.
std::string clOptions;
std::string inputFile;
// String representation of original source
std::string origSource;
};
} // namespace spirv
} // namespace clang
#endif // ENABLE_SPIRV_CODEGEN
#endif // LLVM_SPIRV_OPTIONS_H
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/HLSLOptions.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLSLOptions.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Support for command-line-style option parsing. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef LLVM_HLSL_OPTIONS_H
#define LLVM_HLSL_OPTIONS_H
#include "dxc/Support/DxcOptToggles.h"
#include "dxc/Support/HLSLVersion.h"
#include "dxc/Support/SPIRVOptions.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
#include "dxc/Support/WinIncludes.h"
#include "dxc/dxcapi.h"
#include <map>
#include <set>
namespace llvm {
namespace opt {
class OptTable;
class raw_ostream;
} // namespace opt
} // namespace llvm
namespace dxc {
class DxcDllSupport;
}
namespace hlsl {
enum class SerializeDxilFlags : uint32_t;
namespace options {
/// Flags specifically for clang options. Must not overlap with
/// llvm::opt::DriverFlag or (for clarity) with clang::driver::options.
enum HlslFlags {
DriverOption = (1 << 13),
NoArgumentUnused = (1 << 14),
CoreOption = (1 << 15),
ISenseOption = (1 << 16),
RewriteOption = (1 << 17),
};
enum ID {
OPT_INVALID = 0, // This is not an option ID.
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
HELPTEXT, METAVAR) \
OPT_##ID,
#include "dxc/Support/HLSLOptions.inc"
LastOption
#undef OPTION
};
const llvm::opt::OptTable *getHlslOptTable();
std::error_code initHlslOptTable();
void cleanupHlslOptTable();
///////////////////////////////////////////////////////////////////////////////
// Helper classes to deal with options.
/// Flags for IDxcCompiler APIs.
static const unsigned CompilerFlags = HlslFlags::CoreOption;
/// Flags for dxc.exe command-line tool.
static const unsigned DxcFlags =
HlslFlags::CoreOption | HlslFlags::DriverOption;
/// Flags for dxr.exe command-line tool.
static const unsigned DxrFlags =
HlslFlags::RewriteOption | HlslFlags::DriverOption;
/// Flags for IDxcIntelliSense APIs.
static const unsigned ISenseFlags =
HlslFlags::CoreOption | HlslFlags::ISenseOption;
/// Use this class to capture preprocessor definitions and manage their
/// lifetime.
class DxcDefines {
public:
void push_back(llvm::StringRef value);
LPWSTR DefineValues = nullptr;
llvm::SmallVector<llvm::StringRef, 8> DefineStrings;
llvm::SmallVector<DxcDefine, 8> DefineVector;
~DxcDefines() { delete[] DefineValues; }
DxcDefines(const DxcDefines &) = delete;
DxcDefines() {}
void BuildDefines(); // Must be called after all defines are pushed back
UINT32 ComputeNumberOfWCharsNeededForDefines();
const DxcDefine *data() const { return DefineVector.data(); }
unsigned size() const { return DefineVector.size(); }
};
struct RewriterOpts {
bool Unchanged = false; // OPT_rw_unchanged
bool SkipFunctionBody = false; // OPT_rw_skip_function_body
bool SkipStatic = false; // OPT_rw_skip_static
bool GlobalExternByDefault = false; // OPT_rw_global_extern_by_default
bool KeepUserMacro = false; // OPT_rw_keep_user_macro
bool ExtractEntryUniforms = false; // OPT_rw_extract_entry_uniforms
bool RemoveUnusedGlobals = false; // OPT_rw_remove_unused_globals
bool RemoveUnusedFunctions = false; // OPT_rw_remove_unused_functions
bool WithLineDirective = false; // OPT_rw_line_directive
bool DeclGlobalCB = false; // OPT_rw_decl_global_cb
};
enum class ValidatorSelection : int {
Auto, // Try DXIL.dll; fallback to internal validator
Internal, // Force internal validator (even if DXIL.dll is present)
External, // Use DXIL.dll, failing compilation if not available
Invalid = -1 // Invalid
};
/// Use this class to capture all options.
class DxcOpts {
public:
DxcDefines Defines;
llvm::opt::InputArgList Args =
llvm::opt::InputArgList(nullptr, nullptr); // Original arguments.
llvm::StringRef AssemblyCode; // OPT_Fc
llvm::StringRef DebugFile; // OPT_Fd
llvm::StringRef EntryPoint; // OPT_entrypoint
llvm::StringRef ExternalFn; // OPT_external_fn
llvm::StringRef ExternalLib; // OPT_external_lib
llvm::StringRef ExtractPrivateFile; // OPT_getprivate
llvm::StringRef ForceRootSigVer; // OPT_force_rootsig_ver
llvm::StringRef InputFile; // OPT_INPUT
llvm::StringRef OutputHeader; // OPT_Fh
llvm::StringRef OutputObject; // OPT_Fo
llvm::StringRef OutputWarningsFile; // OPT_Fe
llvm::StringRef OutputReflectionFile; // OPT_Fre
llvm::StringRef OutputRootSigFile; // OPT_Frs
llvm::StringRef OutputShaderHashFile; // OPT_Fsh
llvm::StringRef OutputFileForDependencies; // OPT_write_dependencies_to
std::string Preprocess; // OPT_P
llvm::StringRef TargetProfile; // OPT_target_profile
llvm::StringRef VariableName; // OPT_Vn
llvm::StringRef PrivateSource; // OPT_setprivate
llvm::StringRef RootSignatureSource; // OPT_setrootsignature
llvm::StringRef VerifyRootSignatureSource; // OPT_verifyrootsignature
llvm::StringRef RootSignatureDefine; // OPT_rootsig_define
llvm::StringRef FloatDenormalMode; // OPT_denorm
std::vector<std::string> Exports; // OPT_exports
std::vector<std::string> PreciseOutputs; // OPT_precise_output
llvm::StringRef DefaultLinkage; // OPT_default_linkage
llvm::StringRef ImportBindingTable; // OPT_import_binding_table
llvm::StringRef BindingTableDefine; // OPT_binding_table_define
llvm::StringRef DiagnosticsFormat; // OPT_fdiagnostics_format
unsigned DefaultTextCodePage = DXC_CP_UTF8; // OPT_encoding
bool AllResourcesBound = false; // OPT_all_resources_bound
bool IgnoreOptSemDefs = false; // OPT_ignore_opt_semdefs
bool AstDump = false; // OPT_ast_dump
bool AstDumpImplicit = false; // OPT_ast_dump_implicit
bool ColorCodeAssembly = false; // OPT_Cc
bool CodeGenHighLevel = false; // OPT_fcgl
bool AllowPreserveValues = false; // OPT_preserve_intermediate_values
bool DebugInfo = false; // OPT__SLASH_Zi
bool DebugNameForBinary = false; // OPT_Zsb
bool DebugNameForSource = false; // OPT_Zss
bool DumpBin = false; // OPT_dumpbin
bool DumpDependencies = false; // OPT_dump_dependencies
bool WriteDependencies = false; // OPT_write_dependencies
bool Link = false; // OPT_link
bool WarningAsError = false; // OPT__SLASH_WX
bool IEEEStrict = false; // OPT_Gis
bool IgnoreLineDirectives = false; // OPT_ignore_line_directives
bool DefaultColMajor = false; // OPT_Zpc
bool DefaultRowMajor = false; // OPT_Zpr
bool DisableValidation = false; // OPT_VD
unsigned OptLevel = 0; // OPT_O0/O1/O2/O3
bool DisableOptimizations = false; // OPT_Od
bool AvoidFlowControl = false; // OPT_Gfa
bool PreferFlowControl = false; // OPT_Gfp
bool EnableStrictMode = false; // OPT_Ges
bool EnableDX9CompatMode = false; // OPT_Gec
bool EnableFXCCompatMode = false; // internal flag
LangStd HLSLVersion = LangStd::vUnset; // OPT_hlsl_version (2015-2021)
bool Enable16BitTypes = false; // OPT_enable_16bit_types
bool OptDump = false; // OPT_ODump - dump optimizer commands
bool OutputWarnings = true; // OPT_no_warnings
bool ShowHelp = false; // OPT_help
bool ShowHelpHidden = false; // OPT__help_hidden
bool ShowOptionNames = false; // OPT_fdiagnostics_show_option
bool ShowVersion = false; // OPT_version
bool UseColor = false; // OPT_Cc
bool UseHexLiterals = false; // OPT_Lx
bool UseInstructionByteOffsets = false; // OPT_No
bool UseInstructionNumbers = false; // OPT_Ni
bool PackPrefixStable = false; // OPT_pack_prefix_stable
bool PackOptimized = false; // OPT_pack_optimized
bool DisplayIncludeProcess = false; // OPT__vi
bool RecompileFromBinary =
false; // OPT _Recompile (Recompiling the DXBC binary file not .hlsl file)
bool StripDebug = false; // OPT Qstrip_debug
bool EmbedDebug = false; // OPT Qembed_debug
bool SourceInDebugModule = false; // OPT Zs
bool SourceOnlyDebug = false; // OPT Qsource_only_debug
bool PdbInPrivate = false; // OPT Qpdb_in_private
bool StripRootSignature = false; // OPT_Qstrip_rootsignature
bool StripPrivate = false; // OPT_Qstrip_priv
bool StripReflection = false; // OPT_Qstrip_reflect
bool KeepReflectionInDxil = false; // OPT_Qkeep_reflect_in_dxil
bool StripReflectionFromDxil = false; // OPT_Qstrip_reflect_from_dxil
bool ExtractRootSignature = false; // OPT_extractrootsignature
bool DisassembleColorCoded = false; // OPT_Cc
bool DisassembleInstNumbers = false; // OPT_Ni
bool DisassembleByteOffset = false; // OPT_No
bool DisaseembleHex = false; // OPT_Lx
bool LegacyMacroExpansion = false; // OPT_flegacy_macro_expansion
bool LegacyResourceReservation = false; // OPT_flegacy_resource_reservation
unsigned long AutoBindingSpace = UINT_MAX; // OPT_auto_binding_space
bool ExportShadersOnly = false; // OPT_export_shaders_only
bool ResMayAlias = false; // OPT_res_may_alias
unsigned long ValVerMajor = UINT_MAX,
ValVerMinor = UINT_MAX; // OPT_validator_version
ValidatorSelection SelectValidator =
ValidatorSelection::Auto; // OPT_select_validator
unsigned ScanLimit = 0; // OPT_memdep_block_scan_limit
bool ForceZeroStoreLifetimes = false; // OPT_force_zero_store_lifetimes
bool EnableLifetimeMarkers = false; // OPT_enable_lifetime_markers
bool ForceDisableLocTracking = false; // OPT_fdisable_loc_tracking
bool NewInlining = false; // OPT_fnew_inlining_behavior
bool TimeReport = false; // OPT_ftime_report
std::string TimeTrace = ""; // OPT_ftime_trace[EQ]
unsigned TimeTraceGranularity = 500; // OPT_ftime_trace_granularity_EQ
bool VerifyDiagnostics = false; // OPT_verify
// Optimization pass enables, disables and selects
OptimizationToggles
OptToggles; // OPT_opt_enable, OPT_opt_disable, OPT_opt_select
std::set<std::string> IgnoreSemDefs; // OPT_ignore_semdef
std::map<std::string, std::string> OverrideSemDefs; // OPT_override_semdef
bool PrintBeforeAll; // OPT_print_before_all
std::set<std::string> PrintBefore; // OPT_print_before
bool PrintAfterAll; // OPT_print_after_all
std::set<std::string> PrintAfter; // OPT_print_after
bool EnablePayloadQualifiers = false; // OPT_enable_payload_qualifiers
bool HandleExceptions = false; // OPT_disable_exception_handling
// Rewriter Options
RewriterOpts RWOpt;
std::vector<std::string> Warnings;
bool IsRootSignatureProfile() const;
bool IsLibraryProfile() const;
// Helpers to clarify interpretation of flags for behavior in implementation
bool GenerateFullDebugInfo() const; // Zi
bool GeneratePDB() const; // Zi or Zs
bool EmbedDebugInfo() const; // Qembed_debug
bool EmbedPDBName() const; // Zi or Fd
bool DebugFileIsDirectory() const; // Fd ends in '\\'
llvm::StringRef GetPDBName() const; // Fd name
// SPIRV Change Starts
#ifdef ENABLE_SPIRV_CODEGEN
bool GenSPIRV; // OPT_spirv
clang::spirv::SpirvCodeGenOptions
SpirvOptions; // All SPIR-V CodeGen-related options
#endif
// SPIRV Change Ends
};
/// Use this class to capture, convert and handle the lifetime for the
/// command-line arguments to a program.
class MainArgs {
public:
llvm::SmallVector<std::string, 8> Utf8StringVector;
llvm::SmallVector<const char *, 8> Utf8CharPtrVector;
MainArgs() = default;
MainArgs(int argc, const wchar_t **argv, int skipArgCount = 1);
MainArgs(int argc, const char **argv, int skipArgCount = 1);
MainArgs(llvm::ArrayRef<llvm::StringRef> args);
MainArgs &operator=(const MainArgs &other);
llvm::ArrayRef<const char *> getArrayRef() const {
return llvm::ArrayRef<const char *>(Utf8CharPtrVector.data(),
Utf8CharPtrVector.size());
}
};
/// Use this class to convert a StringRef into a wstring, handling empty values
/// as nulls.
class StringRefWide {
private:
std::wstring m_value;
public:
StringRefWide(llvm::StringRef value);
operator LPCWSTR() const { return m_value.size() ? m_value.data() : nullptr; }
};
/// Reads all options from the given argument strings, populates opts, and
/// validates reporting errors and warnings.
int ReadDxcOpts(const llvm::opt::OptTable *optionTable, unsigned flagsToInclude,
const MainArgs &argStrings, DxcOpts &opts,
llvm::raw_ostream &errors);
/// Sets up the specified DxcDllSupport instance as per the given options.
int SetupDxcDllSupport(const DxcOpts &opts, dxc::DxcDllSupport &dxcSupport,
llvm::raw_ostream &errors);
void CopyArgsToWStrings(const llvm::opt::InputArgList &inArgs,
unsigned flagsToInclude,
std::vector<std::wstring> &outArgs);
SerializeDxilFlags ComputeSerializeDxilFlags(const options::DxcOpts &opts);
} // namespace options
} // namespace hlsl
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/d3d12TokenizedProgramFormat.hpp | #pragma once
///////////////////////////////////////////////////////////////////////////////
// //
// d3d12TokenizedProgramFormat.hpp //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides declarations for the DirectX Tokenized Program Format. //
// //
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
//
// High Level Goals
//
// - Serve as the runtime/DDI representation for all D3D11 tokenized code,
// for all classes of programs, including pixel program, vertex program,
// geometry program, etc.
//
// - Any information that HLSL needs to give to drivers is encoded in
// this token format in some form.
//
// - Enable common tools and source code for managing all tokenizable
// program formats.
//
// - Support extensible token definitions, allowing full customizations for
// specific program classes, while maintaining general conventions for all
// program models.
//
// - Binary backwards compatible with D3D10. Any token name that was originally
// defined with "D3D10" in it is unchanged; D3D11 only adds new tokens.
//
// ----------------------------------------------------------------------------
//
// Low Level Feature Summary
//
// - DWORD based tokens always, for simplicity
// - Opcode token is generally a single DWORD, though there is a bit indicating
// if extended information (extra DWORD(s)) are present
// - Operand tokens are a completely self contained, extensible format,
// with scalar and 4-vector data types as first class citizens, but
// allowance for extension to n-component vectors.
// - Initial operand token identifies register type, register file
// structure/dimensionality and mode of indexing for each dimension,
// and choice of component selection mechanism (i.e. mask vs. swizzle etc).
// - Optional additional extended operand tokens can defined things like
// modifiers (which are not needed by default).
// - Operand's immediate index value(s), if needed, appear as subsequent DWORD
// values, and if relative addressing is specified, an additional completely
// self contained operand definition appears nested in the token sequence.
//
// ----------------------------------------------------------------------------
#include <winapifamily.h>
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)
// ----------------------------------------------------------------------------
// Version Token (VerTok)
//
// [07:00] minor version number (0-255)
// [15:08] major version number (0-255)
// [31:16] D3D10_SB_TOKENIZED_PROGRAM_TYPE
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_TOKENIZED_PROGRAM_TYPE
{
D3D10_SB_PIXEL_SHADER = 0,
D3D10_SB_VERTEX_SHADER = 1,
D3D10_SB_GEOMETRY_SHADER = 2,
// D3D11 Shaders
D3D11_SB_HULL_SHADER = 3,
D3D11_SB_DOMAIN_SHADER = 4,
D3D11_SB_COMPUTE_SHADER = 5,
// Subset of D3D12 Shaders where this field is referenced by runtime
// Entries from 6-12 are unique to state objects
// (e.g. library, callable and raytracing shaders)
D3D12_SB_MESH_SHADER = 13,
D3D12_SB_AMPLIFICATION_SHADER = 14,
D3D11_SB_RESERVED0 = 0xFFF0
} D3D10_SB_TOKENIZED_PROGRAM_TYPE;
#define D3D10_SB_TOKENIZED_PROGRAM_TYPE_MASK 0xffff0000
#define D3D10_SB_TOKENIZED_PROGRAM_TYPE_SHIFT 16
// DECODER MACRO: Retrieve program type from version token
#define DECODE_D3D10_SB_TOKENIZED_PROGRAM_TYPE(VerTok) ((D3D10_SB_TOKENIZED_PROGRAM_TYPE)(((VerTok)&D3D10_SB_TOKENIZED_PROGRAM_TYPE_MASK)>>D3D10_SB_TOKENIZED_PROGRAM_TYPE_SHIFT))
#define D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_MASK 0x000000f0
#define D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_SHIFT 4
#define D3D10_SB_TOKENIZED_PROGRAM_MINOR_VERSION_MASK 0x0000000f
// DECODER MACRO: Retrieve major version # from version token
#define DECODE_D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION(VerTok) (((VerTok)&D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_MASK)>>D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_SHIFT)
// DECODER MACRO: Retrieve minor version # from version token
#define DECODE_D3D10_SB_TOKENIZED_PROGRAM_MINOR_VERSION(VerTok) ((VerTok)&D3D10_SB_TOKENIZED_PROGRAM_MINOR_VERSION_MASK)
// ENCODER MACRO: Create complete VerTok
#define ENCODE_D3D10_SB_TOKENIZED_PROGRAM_VERSION_TOKEN(ProgType,MajorVer,MinorVer) ((((ProgType)<<D3D10_SB_TOKENIZED_PROGRAM_TYPE_SHIFT)&D3D10_SB_TOKENIZED_PROGRAM_TYPE_MASK)|\
((((MajorVer)<<D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_SHIFT)&D3D10_SB_TOKENIZED_PROGRAM_MAJOR_VERSION_MASK))|\
((MinorVer)&D3D10_SB_TOKENIZED_PROGRAM_MINOR_VERSION_MASK))
// ----------------------------------------------------------------------------
// Length Token (LenTok)
//
// Always follows VerTok
//
// [31:00] Unsigned integer count of number of
// DWORDs in program code, including version
// and length tokens. So the minimum value
// is 0x00000002 (if an empty program is ever
// valid).
//
// ----------------------------------------------------------------------------
// DECODER MACRO: Retrieve program length
#define DECODE_D3D10_SB_TOKENIZED_PROGRAM_LENGTH(LenTok) (LenTok)
// ENCODER MACRO: Create complete LenTok
#define ENCODE_D3D10_SB_TOKENIZED_PROGRAM_LENGTH(Length) (Length)
#define MAX_D3D10_SB_TOKENIZED_PROGRAM_LENGTH (0xffffffff)
// ----------------------------------------------------------------------------
// Opcode Format (OpcodeToken0)
//
// [10:00] D3D10_SB_OPCODE_TYPE
// if( [10:00] == D3D10_SB_OPCODE_CUSTOMDATA )
// {
// Token starts a custom-data block. See "Custom-Data Block Format".
// }
// else // standard opcode token
// {
// [23:11] Opcode-Specific Controls
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended opcode token.
// }
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_OPCODE_TYPE {
D3D10_SB_OPCODE_ADD ,
D3D10_SB_OPCODE_AND ,
D3D10_SB_OPCODE_BREAK ,
D3D10_SB_OPCODE_BREAKC ,
D3D10_SB_OPCODE_CALL ,
D3D10_SB_OPCODE_CALLC ,
D3D10_SB_OPCODE_CASE ,
D3D10_SB_OPCODE_CONTINUE ,
D3D10_SB_OPCODE_CONTINUEC ,
D3D10_SB_OPCODE_CUT ,
D3D10_SB_OPCODE_DEFAULT ,
D3D10_SB_OPCODE_DERIV_RTX ,
D3D10_SB_OPCODE_DERIV_RTY ,
D3D10_SB_OPCODE_DISCARD ,
D3D10_SB_OPCODE_DIV ,
D3D10_SB_OPCODE_DP2 ,
D3D10_SB_OPCODE_DP3 ,
D3D10_SB_OPCODE_DP4 ,
D3D10_SB_OPCODE_ELSE ,
D3D10_SB_OPCODE_EMIT ,
D3D10_SB_OPCODE_EMITTHENCUT ,
D3D10_SB_OPCODE_ENDIF ,
D3D10_SB_OPCODE_ENDLOOP ,
D3D10_SB_OPCODE_ENDSWITCH ,
D3D10_SB_OPCODE_EQ ,
D3D10_SB_OPCODE_EXP ,
D3D10_SB_OPCODE_FRC ,
D3D10_SB_OPCODE_FTOI ,
D3D10_SB_OPCODE_FTOU ,
D3D10_SB_OPCODE_GE ,
D3D10_SB_OPCODE_IADD ,
D3D10_SB_OPCODE_IF ,
D3D10_SB_OPCODE_IEQ ,
D3D10_SB_OPCODE_IGE ,
D3D10_SB_OPCODE_ILT ,
D3D10_SB_OPCODE_IMAD ,
D3D10_SB_OPCODE_IMAX ,
D3D10_SB_OPCODE_IMIN ,
D3D10_SB_OPCODE_IMUL ,
D3D10_SB_OPCODE_INE ,
D3D10_SB_OPCODE_INEG ,
D3D10_SB_OPCODE_ISHL ,
D3D10_SB_OPCODE_ISHR ,
D3D10_SB_OPCODE_ITOF ,
D3D10_SB_OPCODE_LABEL ,
D3D10_SB_OPCODE_LD ,
D3D10_SB_OPCODE_LD_MS ,
D3D10_SB_OPCODE_LOG ,
D3D10_SB_OPCODE_LOOP ,
D3D10_SB_OPCODE_LT ,
D3D10_SB_OPCODE_MAD ,
D3D10_SB_OPCODE_MIN ,
D3D10_SB_OPCODE_MAX ,
D3D10_SB_OPCODE_CUSTOMDATA ,
D3D10_SB_OPCODE_MOV ,
D3D10_SB_OPCODE_MOVC ,
D3D10_SB_OPCODE_MUL ,
D3D10_SB_OPCODE_NE ,
D3D10_SB_OPCODE_NOP ,
D3D10_SB_OPCODE_NOT ,
D3D10_SB_OPCODE_OR ,
D3D10_SB_OPCODE_RESINFO ,
D3D10_SB_OPCODE_RET ,
D3D10_SB_OPCODE_RETC ,
D3D10_SB_OPCODE_ROUND_NE ,
D3D10_SB_OPCODE_ROUND_NI ,
D3D10_SB_OPCODE_ROUND_PI ,
D3D10_SB_OPCODE_ROUND_Z ,
D3D10_SB_OPCODE_RSQ ,
D3D10_SB_OPCODE_SAMPLE ,
D3D10_SB_OPCODE_SAMPLE_C ,
D3D10_SB_OPCODE_SAMPLE_C_LZ ,
D3D10_SB_OPCODE_SAMPLE_L ,
D3D10_SB_OPCODE_SAMPLE_D ,
D3D10_SB_OPCODE_SAMPLE_B ,
D3D10_SB_OPCODE_SQRT ,
D3D10_SB_OPCODE_SWITCH ,
D3D10_SB_OPCODE_SINCOS ,
D3D10_SB_OPCODE_UDIV ,
D3D10_SB_OPCODE_ULT ,
D3D10_SB_OPCODE_UGE ,
D3D10_SB_OPCODE_UMUL ,
D3D10_SB_OPCODE_UMAD ,
D3D10_SB_OPCODE_UMAX ,
D3D10_SB_OPCODE_UMIN ,
D3D10_SB_OPCODE_USHR ,
D3D10_SB_OPCODE_UTOF ,
D3D10_SB_OPCODE_XOR ,
D3D10_SB_OPCODE_DCL_RESOURCE , // DCL* opcodes have
D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER , // custom operand formats.
D3D10_SB_OPCODE_DCL_SAMPLER ,
D3D10_SB_OPCODE_DCL_INDEX_RANGE ,
D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY ,
D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE ,
D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT ,
D3D10_SB_OPCODE_DCL_INPUT ,
D3D10_SB_OPCODE_DCL_INPUT_SGV ,
D3D10_SB_OPCODE_DCL_INPUT_SIV ,
D3D10_SB_OPCODE_DCL_INPUT_PS ,
D3D10_SB_OPCODE_DCL_INPUT_PS_SGV ,
D3D10_SB_OPCODE_DCL_INPUT_PS_SIV ,
D3D10_SB_OPCODE_DCL_OUTPUT ,
D3D10_SB_OPCODE_DCL_OUTPUT_SGV ,
D3D10_SB_OPCODE_DCL_OUTPUT_SIV ,
D3D10_SB_OPCODE_DCL_TEMPS ,
D3D10_SB_OPCODE_DCL_INDEXABLE_TEMP ,
D3D10_SB_OPCODE_DCL_GLOBAL_FLAGS ,
// -----------------------------------------------
// This marks the end of D3D10.0 opcodes
D3D10_SB_OPCODE_RESERVED0,
// ---------- DX 10.1 op codes---------------------
D3D10_1_SB_OPCODE_LOD,
D3D10_1_SB_OPCODE_GATHER4,
D3D10_1_SB_OPCODE_SAMPLE_POS,
D3D10_1_SB_OPCODE_SAMPLE_INFO,
// -----------------------------------------------
// This marks the end of D3D10.1 opcodes
D3D10_1_SB_OPCODE_RESERVED1,
// ---------- DX 11 op codes---------------------
D3D11_SB_OPCODE_HS_DECLS , // token marks beginning of HS sub-shader
D3D11_SB_OPCODE_HS_CONTROL_POINT_PHASE , // token marks beginning of HS sub-shader
D3D11_SB_OPCODE_HS_FORK_PHASE , // token marks beginning of HS sub-shader
D3D11_SB_OPCODE_HS_JOIN_PHASE , // token marks beginning of HS sub-shader
D3D11_SB_OPCODE_EMIT_STREAM ,
D3D11_SB_OPCODE_CUT_STREAM ,
D3D11_SB_OPCODE_EMITTHENCUT_STREAM ,
D3D11_SB_OPCODE_INTERFACE_CALL ,
D3D11_SB_OPCODE_BUFINFO ,
D3D11_SB_OPCODE_DERIV_RTX_COARSE ,
D3D11_SB_OPCODE_DERIV_RTX_FINE ,
D3D11_SB_OPCODE_DERIV_RTY_COARSE ,
D3D11_SB_OPCODE_DERIV_RTY_FINE ,
D3D11_SB_OPCODE_GATHER4_C ,
D3D11_SB_OPCODE_GATHER4_PO ,
D3D11_SB_OPCODE_GATHER4_PO_C ,
D3D11_SB_OPCODE_RCP ,
D3D11_SB_OPCODE_F32TOF16 ,
D3D11_SB_OPCODE_F16TOF32 ,
D3D11_SB_OPCODE_UADDC ,
D3D11_SB_OPCODE_USUBB ,
D3D11_SB_OPCODE_COUNTBITS ,
D3D11_SB_OPCODE_FIRSTBIT_HI ,
D3D11_SB_OPCODE_FIRSTBIT_LO ,
D3D11_SB_OPCODE_FIRSTBIT_SHI ,
D3D11_SB_OPCODE_UBFE ,
D3D11_SB_OPCODE_IBFE ,
D3D11_SB_OPCODE_BFI ,
D3D11_SB_OPCODE_BFREV ,
D3D11_SB_OPCODE_SWAPC ,
D3D11_SB_OPCODE_DCL_STREAM ,
D3D11_SB_OPCODE_DCL_FUNCTION_BODY ,
D3D11_SB_OPCODE_DCL_FUNCTION_TABLE ,
D3D11_SB_OPCODE_DCL_INTERFACE ,
D3D11_SB_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT ,
D3D11_SB_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT ,
D3D11_SB_OPCODE_DCL_TESS_DOMAIN ,
D3D11_SB_OPCODE_DCL_TESS_PARTITIONING ,
D3D11_SB_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE ,
D3D11_SB_OPCODE_DCL_HS_MAX_TESSFACTOR ,
D3D11_SB_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT ,
D3D11_SB_OPCODE_DCL_HS_JOIN_PHASE_INSTANCE_COUNT ,
D3D11_SB_OPCODE_DCL_THREAD_GROUP ,
D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED ,
D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW ,
D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED,
D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW,
D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED,
D3D11_SB_OPCODE_DCL_RESOURCE_RAW ,
D3D11_SB_OPCODE_DCL_RESOURCE_STRUCTURED ,
D3D11_SB_OPCODE_LD_UAV_TYPED ,
D3D11_SB_OPCODE_STORE_UAV_TYPED ,
D3D11_SB_OPCODE_LD_RAW ,
D3D11_SB_OPCODE_STORE_RAW ,
D3D11_SB_OPCODE_LD_STRUCTURED ,
D3D11_SB_OPCODE_STORE_STRUCTURED ,
D3D11_SB_OPCODE_ATOMIC_AND ,
D3D11_SB_OPCODE_ATOMIC_OR ,
D3D11_SB_OPCODE_ATOMIC_XOR ,
D3D11_SB_OPCODE_ATOMIC_CMP_STORE ,
D3D11_SB_OPCODE_ATOMIC_IADD ,
D3D11_SB_OPCODE_ATOMIC_IMAX ,
D3D11_SB_OPCODE_ATOMIC_IMIN ,
D3D11_SB_OPCODE_ATOMIC_UMAX ,
D3D11_SB_OPCODE_ATOMIC_UMIN ,
D3D11_SB_OPCODE_IMM_ATOMIC_ALLOC ,
D3D11_SB_OPCODE_IMM_ATOMIC_CONSUME ,
D3D11_SB_OPCODE_IMM_ATOMIC_IADD ,
D3D11_SB_OPCODE_IMM_ATOMIC_AND ,
D3D11_SB_OPCODE_IMM_ATOMIC_OR ,
D3D11_SB_OPCODE_IMM_ATOMIC_XOR ,
D3D11_SB_OPCODE_IMM_ATOMIC_EXCH ,
D3D11_SB_OPCODE_IMM_ATOMIC_CMP_EXCH ,
D3D11_SB_OPCODE_IMM_ATOMIC_IMAX ,
D3D11_SB_OPCODE_IMM_ATOMIC_IMIN ,
D3D11_SB_OPCODE_IMM_ATOMIC_UMAX ,
D3D11_SB_OPCODE_IMM_ATOMIC_UMIN ,
D3D11_SB_OPCODE_SYNC ,
D3D11_SB_OPCODE_DADD ,
D3D11_SB_OPCODE_DMAX ,
D3D11_SB_OPCODE_DMIN ,
D3D11_SB_OPCODE_DMUL ,
D3D11_SB_OPCODE_DEQ ,
D3D11_SB_OPCODE_DGE ,
D3D11_SB_OPCODE_DLT ,
D3D11_SB_OPCODE_DNE ,
D3D11_SB_OPCODE_DMOV ,
D3D11_SB_OPCODE_DMOVC ,
D3D11_SB_OPCODE_DTOF ,
D3D11_SB_OPCODE_FTOD ,
D3D11_SB_OPCODE_EVAL_SNAPPED ,
D3D11_SB_OPCODE_EVAL_SAMPLE_INDEX ,
D3D11_SB_OPCODE_EVAL_CENTROID ,
D3D11_SB_OPCODE_DCL_GS_INSTANCE_COUNT ,
D3D11_SB_OPCODE_ABORT ,
D3D11_SB_OPCODE_DEBUG_BREAK ,
// -----------------------------------------------
// This marks the end of D3D11.0 opcodes
D3D11_SB_OPCODE_RESERVED0,
D3D11_1_SB_OPCODE_DDIV,
D3D11_1_SB_OPCODE_DFMA,
D3D11_1_SB_OPCODE_DRCP,
D3D11_1_SB_OPCODE_MSAD,
D3D11_1_SB_OPCODE_DTOI,
D3D11_1_SB_OPCODE_DTOU,
D3D11_1_SB_OPCODE_ITOD,
D3D11_1_SB_OPCODE_UTOD,
// -----------------------------------------------
// This marks the end of D3D11.1 opcodes
D3D11_1_SB_OPCODE_RESERVED0,
D3DWDDM1_3_SB_OPCODE_GATHER4_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_GATHER4_C_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_GATHER4_PO_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_GATHER4_PO_C_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_LD_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_LD_MS_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_LD_UAV_TYPED_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_LD_RAW_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_LD_STRUCTURED_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_L_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_C_LZ_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_CLAMP_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_B_CLAMP_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_D_CLAMP_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_SAMPLE_C_CLAMP_FEEDBACK,
D3DWDDM1_3_SB_OPCODE_CHECK_ACCESS_FULLY_MAPPED,
// -----------------------------------------------
// This marks the end of WDDM 1.3 opcodes
D3DWDDM1_3_SB_OPCODE_RESERVED0,
D3D10_SB_NUM_OPCODES // Should be the last entry
} D3D10_SB_OPCODE_TYPE;
#define D3D10_SB_OPCODE_TYPE_MASK 0x00007ff
// DECODER MACRO: Retrieve program opcode
#define DECODE_D3D10_SB_OPCODE_TYPE(OpcodeToken0) ((D3D10_SB_OPCODE_TYPE)((OpcodeToken0)&D3D10_SB_OPCODE_TYPE_MASK))
// ENCODER MACRO: Create the opcode-type portion of OpcodeToken0
#define ENCODE_D3D10_SB_OPCODE_TYPE(OpcodeName) ((OpcodeName)&D3D10_SB_OPCODE_TYPE_MASK)
#define D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_MASK 0x7f000000
#define D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_SHIFT 24
// DECODER MACRO: Retrieve instruction length
// in # of DWORDs including the opcode token(s).
// The range is 1-127.
#define DECODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(OpcodeToken0) (((OpcodeToken0)&D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_MASK)>> D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_SHIFT)
// ENCODER MACRO: Store instruction length
// portion of OpcodeToken0, in # of DWORDs
// including the opcode token(s).
// Valid range is 1-127.
#define ENCODE_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH(Length) (((Length)<<D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_SHIFT)&D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH_MASK)
#define MAX_D3D10_SB_TOKENIZED_INSTRUCTION_LENGTH 127
#define D3D10_SB_INSTRUCTION_SATURATE_MASK 0x00002000
// DECODER MACRO: Check OpcodeToken0 to see if an instruction
// is to saturate the result [0..1]
// This flag is indicated by one of the bits in the
// opcode specific control range.
#define DECODE_IS_D3D10_SB_INSTRUCTION_SATURATE_ENABLED(OpcodeToken0) ((OpcodeToken0)&D3D10_SB_INSTRUCTION_SATURATE_MASK)
// ENCODER MACRO: Encode in OpcodeToken0 if instruction is to saturate the result.
#define ENCODE_D3D10_SB_INSTRUCTION_SATURATE(bSat) (((bSat)!=0)?D3D10_SB_INSTRUCTION_SATURATE_MASK:0)
// Boolean test for conditional instructions such as if (if_z or if_nz)
// This is part of the opcode specific control range.
typedef enum D3D10_SB_INSTRUCTION_TEST_BOOLEAN
{
D3D10_SB_INSTRUCTION_TEST_ZERO = 0,
D3D10_SB_INSTRUCTION_TEST_NONZERO = 1
} D3D10_SB_INSTRUCTION_TEST_BOOLEAN;
#define D3D10_SB_INSTRUCTION_TEST_BOOLEAN_MASK 0x00040000
#define D3D10_SB_INSTRUCTION_TEST_BOOLEAN_SHIFT 18
// DECODER MACRO: For an OpcodeToken0 for requires either a
// zero or non-zero test, determine which test was chosen.
#define DECODE_D3D10_SB_INSTRUCTION_TEST_BOOLEAN(OpcodeToken0) ((D3D10_SB_INSTRUCTION_TEST_BOOLEAN)(((OpcodeToken0)&D3D10_SB_INSTRUCTION_TEST_BOOLEAN_MASK)>>D3D10_SB_INSTRUCTION_TEST_BOOLEAN_SHIFT))
// ENCODER MACRO: Store "zero" or "nonzero" in the opcode
// specific control range of OpcodeToken0
#define ENCODE_D3D10_SB_INSTRUCTION_TEST_BOOLEAN(Boolean) (((Boolean)<<D3D10_SB_INSTRUCTION_TEST_BOOLEAN_SHIFT)&D3D10_SB_INSTRUCTION_TEST_BOOLEAN_MASK)
// Precise value mask (bits 19-22)
// This is part of the opcode specific control range.
// It's 1 bit per-channel of the output, for instructions with multiple
// output operands, it applies to that component in each operand. This
// uses the components defined in D3D10_SB_COMPONENT_NAME.
#define D3D11_SB_INSTRUCTION_PRECISE_VALUES_MASK 0x00780000
#define D3D11_SB_INSTRUCTION_PRECISE_VALUES_SHIFT 19
// DECODER MACRO: this macro extracts from OpcodeToken0 the 4 component
// (xyzw) mask, as a field of D3D10_SB_4_COMPONENT_[X|Y|Z|W] flags.
#define DECODE_D3D11_SB_INSTRUCTION_PRECISE_VALUES(OpcodeToken0) ((((OpcodeToken0)&D3D11_SB_INSTRUCTION_PRECISE_VALUES_MASK)>>D3D11_SB_INSTRUCTION_PRECISE_VALUES_SHIFT))
// ENCODER MACRO: Given a set of
// D3D10_SB_OPERAND_4_COMPONENT_[X|Y|Z|W] values
// or'd together, encode them in OpcodeToken0.
#define ENCODE_D3D11_SB_INSTRUCTION_PRECISE_VALUES(ComponentMask) (((ComponentMask)<<D3D11_SB_INSTRUCTION_PRECISE_VALUES_SHIFT)&D3D11_SB_INSTRUCTION_PRECISE_VALUES_MASK)
// resinfo instruction return type
typedef enum D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE
{
D3D10_SB_RESINFO_INSTRUCTION_RETURN_FLOAT = 0,
D3D10_SB_RESINFO_INSTRUCTION_RETURN_RCPFLOAT = 1,
D3D10_SB_RESINFO_INSTRUCTION_RETURN_UINT = 2
} D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE;
#define D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_MASK 0x00001800
#define D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_SHIFT 11
// DECODER MACRO: For an OpcodeToken0 for the resinfo instruction,
// determine the return type.
#define DECODE_D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE(OpcodeToken0) ((D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE)(((OpcodeToken0)&D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_MASK)>>D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_SHIFT))
// ENCODER MACRO: Encode the return type for the resinfo instruction
// in the opcode specific control range of OpcodeToken0
#define ENCODE_D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE(ReturnType) (((ReturnType)<<D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_SHIFT)&D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE_MASK)
// sync instruction flags
#define D3D11_SB_SYNC_THREADS_IN_GROUP 0x00000800
#define D3D11_SB_SYNC_THREAD_GROUP_SHARED_MEMORY 0x00001000
#define D3D11_SB_SYNC_UNORDERED_ACCESS_VIEW_MEMORY_GROUP 0x00002000
#define D3D11_SB_SYNC_UNORDERED_ACCESS_VIEW_MEMORY_GLOBAL 0x00004000
#define D3D11_SB_SYNC_FLAGS_MASK 0x00007800
// DECODER MACRO: Retrieve flags for sync instruction from OpcodeToken0.
#define DECODE_D3D11_SB_SYNC_FLAGS(OperandToken0) ((OperandToken0)&D3D11_SB_SYNC_FLAGS_MASK)
// ENCODER MACRO: Given a set of sync instruciton flags, encode them in OpcodeToken0.
#define ENCODE_D3D11_SB_SYNC_FLAGS(Flags) ((Flags)&D3D11_SB_SYNC_FLAGS_MASK)
#define D3D10_SB_OPCODE_EXTENDED_MASK 0x80000000
#define D3D10_SB_OPCODE_EXTENDED_SHIFT 31
// DECODER MACRO: Determine if the opcode is extended
// by an additional opcode token. Currently there are no
// extended opcodes.
#define DECODE_IS_D3D10_SB_OPCODE_EXTENDED(OpcodeToken0) (((OpcodeToken0)&D3D10_SB_OPCODE_EXTENDED_MASK)>> D3D10_SB_OPCODE_EXTENDED_SHIFT)
// ENCODER MACRO: Store in OpcodeToken0 whether the opcode is extended
// by an additional opcode token.
#define ENCODE_D3D10_SB_OPCODE_EXTENDED(bExtended) (((bExtended)!=0)?D3D10_SB_OPCODE_EXTENDED_MASK:0)
// ----------------------------------------------------------------------------
// Extended Opcode Format (OpcodeToken1)
//
// If bit31 of an opcode token is set, the
// opcode has an additional extended opcode token DWORD
// directly following OpcodeToken0. Other tokens
// expected for the opcode, such as the operand
// token(s) always follow
// OpcodeToken0 AND OpcodeToken1..n (extended
// opcode tokens, if present).
//
// [05:00] D3D10_SB_EXTENDED_OPCODE_TYPE
// [30:06] if([05:00] == D3D10_SB_EXTENDED_OPCODE_SAMPLE_CONTROLS)
// {
// This custom opcode contains controls for SAMPLE.
// [08:06] Ignored, 0.
// [12:09] U texel immediate offset (4 bit 2's comp) (0 default)
// [16:13] V texel immediate offset (4 bit 2's comp) (0 default)
// [20:17] W texel immediate offset (4 bit 2's comp) (0 default)
// [30:14] Ignored, 0.
// }
// else if( [05:00] == D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM )
// {
// [10:06] D3D10_SB_RESOURCE_DIMENSION
// [22:11] When dimension is D3D11_SB_RESOURCE_DIMENSION_STRUCTURED_BUFFER this holds the buffer stride, otherwise 0
// [30:23] Ignored, 0.
// }
// else if( [05:00] == D3D11_SB_EXTENDED_OPCODE_RESOURCE_RETURN_TYPE )
// {
// [09:06] D3D10_SB_RESOURCE_RETURN_TYPE for component X
// [13:10] D3D10_SB_RESOURCE_RETURN_TYPE for component Y
// [17:14] D3D10_SB_RESOURCE_RETURN_TYPE for component Z
// [21:18] D3D10_SB_RESOURCE_RETURN_TYPE for component W
// [30:22] Ignored, 0.
// }
// else
// {
// [30:04] Ignored, 0.
// }
// [31] 0 normally. 1 there is another extended opcode. Any number
// of extended opcode tokens can be chained. It is possible that some extended
// opcode tokens could include multiple DWORDS - that is defined
// on a case by case basis.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_EXTENDED_OPCODE_TYPE
{
D3D10_SB_EXTENDED_OPCODE_EMPTY = 0,
D3D10_SB_EXTENDED_OPCODE_SAMPLE_CONTROLS = 1,
D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM = 2,
D3D11_SB_EXTENDED_OPCODE_RESOURCE_RETURN_TYPE = 3,
} D3D10_SB_EXTENDED_OPCODE_TYPE;
#define D3D11_SB_MAX_SIMULTANEOUS_EXTENDED_OPCODES 3
#define D3D10_SB_EXTENDED_OPCODE_TYPE_MASK 0x0000003f
// DECODER MACRO: Given an extended opcode
// token (OpcodeToken1), figure out what type
// of token it is (from D3D10_SB_EXTENDED_OPCODE_TYPE enum)
// to be able to interpret the rest of the token's contents.
#define DECODE_D3D10_SB_EXTENDED_OPCODE_TYPE(OpcodeToken1) ((D3D10_SB_EXTENDED_OPCODE_TYPE)((OpcodeToken1)&D3D10_SB_EXTENDED_OPCODE_TYPE_MASK))
// ENCODER MACRO: Store extended opcode token
// type in OpcodeToken1.
#define ENCODE_D3D10_SB_EXTENDED_OPCODE_TYPE(ExtOpcodeType) ((ExtOpcodeType)&D3D10_SB_EXTENDED_OPCODE_TYPE_MASK)
typedef enum D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_COORD
{
D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_U = 0,
D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_V = 1,
D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_W = 2,
} D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_COORD;
#define D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_COORD_MASK (3)
#define D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord) (9+4*((Coord)&D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_COORD_MASK))
#define D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_MASK(Coord) (0x0000000f<<D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord))
// DECODER MACRO: Given an extended opcode token
// (OpcodeToken1), and extended token type ==
// D3D10_SB_EXTENDED_OPCODE_SAMPLE_CONTROLS, determine the immediate
// texel address offset for u/v/w (D3D10_SB_ADDRESS_OFFSET_COORD)
// This macro returns a (signed) integer, by sign extending the
// decoded 4 bit 2's complement immediate value.
#define DECODE_IMMEDIATE_D3D10_SB_ADDRESS_OFFSET(Coord,OpcodeToken1) ((((OpcodeToken1)&D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_MASK(Coord))>>(D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord))))
// ENCODER MACRO: Store the immediate texel address offset
// for U or V or W Coord (D3D10_SB_ADDRESS_OFFSET_COORD) in an extended
// opcode token (OpcodeToken1) that has extended opcode
// type == D3D10_SB_EXTENDED_OPCODE_SAMPLE_CONTROLS (opcode type encoded separately)
// A 2's complement number is expected as input, from which the LSB 4 bits are extracted.
#define ENCODE_IMMEDIATE_D3D10_SB_ADDRESS_OFFSET(Coord,ImmediateOffset) (((ImmediateOffset)<<D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_SHIFT(Coord))&D3D10_SB_IMMEDIATE_ADDRESS_OFFSET_MASK(Coord))
#define D3D11_SB_EXTENDED_RESOURCE_DIMENSION_MASK 0x000007C0
#define D3D11_SB_EXTENDED_RESOURCE_DIMENSION_SHIFT 6
// DECODER MACRO: Given an extended resource declaration token,
// (D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM), determine the resource dimension
// (D3D10_SB_RESOURCE_DIMENSION enum)
#define DECODE_D3D11_SB_EXTENDED_RESOURCE_DIMENSION(OpcodeTokenN) ((D3D10_SB_RESOURCE_DIMENSION)(((OpcodeTokenN)&D3D11_SB_EXTENDED_RESOURCE_DIMENSION_MASK)>>D3D11_SB_EXTENDED_RESOURCE_DIMENSION_SHIFT))
// ENCODER MACRO: Store resource dimension
// (D3D10_SB_RESOURCE_DIMENSION enum) into a
// an extended resource declaration token (D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM)
#define ENCODE_D3D11_SB_EXTENDED_RESOURCE_DIMENSION(ResourceDim) (((ResourceDim)<<D3D11_SB_EXTENDED_RESOURCE_DIMENSION_SHIFT)&D3D11_SB_EXTENDED_RESOURCE_DIMENSION_MASK)
#define D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_MASK 0x007FF800
#define D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_SHIFT 11
// DECODER MACRO: Given an extended resource declaration token for a structured buffer,
// (D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM), determine the structure stride
// (12-bit unsigned integer)
#define DECODE_D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE(OpcodeTokenN) (((OpcodeTokenN)&D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_MASK)>>D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_SHIFT)
// ENCODER MACRO: Store resource dimension structure stride
// (12-bit unsigned integer) into a
// an extended resource declaration token (D3D11_SB_EXTENDED_OPCODE_RESOURCE_DIM)
#define ENCODE_D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE(Stride) (((Stride)<<D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_SHIFT)&D3D11_SB_EXTENDED_RESOURCE_DIMENSION_STRUCTURE_STRIDE_MASK)
#define D3D10_SB_RESOURCE_RETURN_TYPE_MASK 0x0000000f
#define D3D10_SB_RESOURCE_RETURN_TYPE_NUMBITS 0x00000004
#define D3D11_SB_EXTENDED_RESOURCE_RETURN_TYPE_SHIFT 6
// DECODER MACRO: Get the resource return type for component (0-3) from
// an extended resource declaration token (D3D11_SB_EXTENDED_OPCODE_RESOURCE_RETURN_TYPE)
#define DECODE_D3D11_SB_EXTENDED_RESOURCE_RETURN_TYPE(OpcodeTokenN, Component) \
((D3D10_SB_RESOURCE_RETURN_TYPE)(((OpcodeTokenN) >> \
(Component * D3D10_SB_RESOURCE_RETURN_TYPE_NUMBITS + D3D11_SB_EXTENDED_RESOURCE_RETURN_TYPE_SHIFT))&D3D10_SB_RESOURCE_RETURN_TYPE_MASK))
// ENCODER MACRO: Generate a resource return type for a component in an extended
// resource delcaration token (D3D11_SB_EXTENDED_OPCODE_RESOURCE_RETURN_TYPE)
#define ENCODE_D3D11_SB_EXTENDED_RESOURCE_RETURN_TYPE(ReturnType, Component) \
(((ReturnType)&D3D10_SB_RESOURCE_RETURN_TYPE_MASK) << (Component * D3D10_SB_RESOURCE_RETURN_TYPE_NUMBITS + D3D11_SB_EXTENDED_RESOURCE_RETURN_TYPE_SHIFT))
// ----------------------------------------------------------------------------
// Custom-Data Block Format
//
// DWORD 0 (CustomDataDescTok):
// [10:00] == D3D10_SB_OPCODE_CUSTOMDATA
// [31:11] == D3D10_SB_CUSTOMDATA_CLASS
//
// DWORD 1:
// 32-bit unsigned integer count of number
// of DWORDs in custom-data block,
// including DWORD 0 and DWORD 1.
// So the minimum value is 0x00000002,
// meaning empty custom-data.
//
// Layout of custom-data contents, for the various meta-data classes,
// not defined in this file.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_CUSTOMDATA_CLASS
{
D3D10_SB_CUSTOMDATA_COMMENT = 0,
D3D10_SB_CUSTOMDATA_DEBUGINFO,
D3D10_SB_CUSTOMDATA_OPAQUE,
D3D10_SB_CUSTOMDATA_DCL_IMMEDIATE_CONSTANT_BUFFER,
D3D11_SB_CUSTOMDATA_SHADER_MESSAGE,
D3D11_SB_CUSTOMDATA_SHADER_CLIP_PLANE_CONSTANT_MAPPINGS_FOR_DX9,
} D3D10_SB_CUSTOMDATA_CLASS;
#define D3D10_SB_CUSTOMDATA_CLASS_MASK 0xfffff800
#define D3D10_SB_CUSTOMDATA_CLASS_SHIFT 11
// DECODER MACRO: Find out what class of custom-data is present.
// The contents of the custom-data block are defined
// for each class of custom-data.
#define DECODE_D3D10_SB_CUSTOMDATA_CLASS(CustomDataDescTok) ((D3D10_SB_CUSTOMDATA_CLASS)(((CustomDataDescTok)&D3D10_SB_CUSTOMDATA_CLASS_MASK)>>D3D10_SB_CUSTOMDATA_CLASS_SHIFT))
// ENCODER MACRO: Create complete CustomDataDescTok
#define ENCODE_D3D10_SB_CUSTOMDATA_CLASS(CustomDataClass) (ENCODE_D3D10_SB_OPCODE_TYPE(D3D10_SB_OPCODE_CUSTOMDATA)|(((CustomDataClass)<<D3D10_SB_CUSTOMDATA_CLASS_SHIFT)&D3D10_SB_CUSTOMDATA_CLASS_MASK))
// ----------------------------------------------------------------------------
// Instruction Operand Format (OperandToken0)
//
// [01:00] D3D10_SB_OPERAND_NUM_COMPONENTS
// [11:02] Component Selection
// if([01:00] == D3D10_SB_OPERAND_0_COMPONENT)
// [11:02] = Ignored, 0
// else if([01:00] == D3D10_SB_OPERAND_1_COMPONENT
// [11:02] = Ignored, 0
// else if([01:00] == D3D10_SB_OPERAND_4_COMPONENT
// {
// [03:02] = D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE
// if([03:02] == D3D10_SB_OPERAND_4_COMPONENT_MASK_MODE)
// {
// [07:04] = D3D10_SB_OPERAND_4_COMPONENT_MASK
// [11:08] = Ignored, 0
// }
// else if([03:02] == D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MODE)
// {
// [11:04] = D3D10_SB_4_COMPONENT_SWIZZLE
// }
// else if([03:02] == D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MODE)
// {
// [05:04] = D3D10_SB_4_COMPONENT_NAME
// [11:06] = Ignored, 0
// }
// }
// else if([01:00] == D3D10_SB_OPERAND_N_COMPONENT)
// {
// Currently not defined.
// }
// [19:12] D3D10_SB_OPERAND_TYPE
// [21:20] D3D10_SB_OPERAND_INDEX_DIMENSION:
// Number of dimensions in the register
// file (NOT the # of dimensions in the
// individual register or memory
// resource being referenced).
// [24:22] if( [21:20] >= D3D10_SB_OPERAND_INDEX_1D )
// D3D10_SB_OPERAND_INDEX_REPRESENTATION for first operand index
// else
// Ignored, 0
// [27:25] if( [21:20] >= D3D10_SB_OPERAND_INDEX_2D )
// D3D10_SB_OPERAND_INDEX_REPRESENTATION for second operand index
// else
// Ignored, 0
// [30:28] if( [21:20] == D3D10_SB_OPERAND_INDEX_3D )
// D3D10_SB_OPERAND_INDEX_REPRESENTATION for third operand index
// else
// Ignored, 0
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description.
//
// ----------------------------------------------------------------------------
// Number of components in data vector referred to by operand.
typedef enum D3D10_SB_OPERAND_NUM_COMPONENTS
{
D3D10_SB_OPERAND_0_COMPONENT = 0,
D3D10_SB_OPERAND_1_COMPONENT = 1,
D3D10_SB_OPERAND_4_COMPONENT = 2,
D3D10_SB_OPERAND_N_COMPONENT = 3 // unused for now
} D3D10_SB_OPERAND_NUM_COMPONENTS;
#define D3D10_SB_OPERAND_NUM_COMPONENTS_MASK 0x00000003
// DECODER MACRO: Extract from OperandToken0 how many components
// the data vector referred to by the operand contains.
// (D3D10_SB_OPERAND_NUM_COMPONENTS enum)
#define DECODE_D3D10_SB_OPERAND_NUM_COMPONENTS(OperandToken0) ((D3D10_SB_OPERAND_NUM_COMPONENTS)((OperandToken0)&D3D10_SB_OPERAND_NUM_COMPONENTS_MASK))
// ENCODER MACRO: Define in OperandToken0 how many components
// the data vector referred to by the operand contains.
// (D3D10_SB_OPERAND_NUM_COMPONENTS enum).
#define ENCODE_D3D10_SB_OPERAND_NUM_COMPONENTS(NumComp) ((NumComp)&D3D10_SB_OPERAND_NUM_COMPONENTS_MASK)
typedef enum D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE
{
D3D10_SB_OPERAND_4_COMPONENT_MASK_MODE = 0, // mask 4 components
D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MODE = 1, // swizzle 4 components
D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MODE = 2, // select 1 of 4 components
} D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE;
#define D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_MASK 0x0000000c
#define D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_SHIFT 2
// DECODER MACRO: For an operand representing 4component data,
// extract from OperandToken0 the method for selecting data from
// the 4 components (D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE).
#define DECODE_D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE(OperandToken0) ((D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE)(((OperandToken0)&D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_MASK)>>D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_SHIFT))
// ENCODER MACRO: For an operand representing 4component data,
// encode in OperandToken0 a value from D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE
#define ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE(SelectionMode) (((SelectionMode)<<D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_SHIFT)&D3D10_SB_OPERAND_4_COMPONENT_SELECTION_MODE_MASK)
typedef enum D3D10_SB_4_COMPONENT_NAME
{
D3D10_SB_4_COMPONENT_X = 0,
D3D10_SB_4_COMPONENT_Y = 1,
D3D10_SB_4_COMPONENT_Z = 2,
D3D10_SB_4_COMPONENT_W = 3,
D3D10_SB_4_COMPONENT_R = 0,
D3D10_SB_4_COMPONENT_G = 1,
D3D10_SB_4_COMPONENT_B = 2,
D3D10_SB_4_COMPONENT_A = 3
} D3D10_SB_4_COMPONENT_NAME;
#define D3D10_SB_4_COMPONENT_NAME_MASK 3
// MACROS FOR USE IN D3D10_SB_OPERAND_4_COMPONENT_MASK_MODE:
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_MASK 0x000000f0
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_SHIFT 4
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_X 0x00000010
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_Y 0x00000020
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_Z 0x00000040
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_W 0x00000080
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_R D3D10_SB_OPERAND_4_COMPONENT_MASK_X
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_G D3D10_SB_OPERAND_4_COMPONENT_MASK_Y
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_B D3D10_SB_OPERAND_4_COMPONENT_MASK_Z
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_A D3D10_SB_OPERAND_4_COMPONENT_MASK_W
#define D3D10_SB_OPERAND_4_COMPONENT_MASK_ALL D3D10_SB_OPERAND_4_COMPONENT_MASK_MASK
// DECODER MACRO: When 4 component selection mode is
// D3D10_SB_OPERAND_4_COMPONENT_MASK_MODE, this macro
// extracts from OperandToken0 the 4 component (xyzw) mask,
// as a field of D3D10_SB_OPERAND_4_COMPONENT_MASK_[X|Y|Z|W] flags.
// Alternatively, the D3D10_SB_OPERAND_4_COMPONENT_MASK_[X|Y|Z|W] masks
// can be tested on OperandToken0 directly, without this macro.
#define DECODE_D3D10_SB_OPERAND_4_COMPONENT_MASK(OperandToken0) ((OperandToken0)&D3D10_SB_OPERAND_4_COMPONENT_MASK_MASK)
// ENCODER MACRO: Given a set of
// D3D10_SB_OPERAND_4_COMPONENT_MASK_[X|Y|Z|W] values
// or'd together, encode them in OperandToken0.
#define ENCODE_D3D10_SB_OPERAND_4_COMPONENT_MASK(ComponentMask) ((ComponentMask)&D3D10_SB_OPERAND_4_COMPONENT_MASK_MASK)
// ENCODER/DECODER MACRO: Given a D3D10_SB_4_COMPONENT_NAME,
// generate the 4-component mask for it.
// This can be used in loops that build masks or read masks.
// Alternatively, the D3D10_SB_OPERAND_4_COMPONENT_MASK_[X|Y|Z|W] masks
// can be used directly, without this macro.
#define D3D10_SB_OPERAND_4_COMPONENT_MASK(ComponentName) ((1<<(D3D10_SB_OPERAND_4_COMPONENT_MASK_SHIFT+ComponentName))&D3D10_SB_OPERAND_4_COMPONENT_MASK_MASK)
// MACROS FOR USE IN D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MODE:
#define D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MASK 0x00000ff0
#define D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_SHIFT 4
// DECODER MACRO: When 4 component selection mode is
// D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MODE, this macro
// extracts from OperandToken0 the 4 component swizzle,
// as a field of D3D10_SB_OPERAND_4_COMPONENT_MASK_[X|Y|Z|W] flags.
#define DECODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(OperandToken0) ((OperandToken0)&D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_MASK)
// DECODER MACRO: Pass a D3D10_SB_4_COMPONENT_NAME as "DestComp" in following
// macro to extract, from OperandToken0 or from a decoded swizzle,
// the swizzle source component (D3D10_SB_4_COMPONENT_NAME enum):
#define DECODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_SOURCE(OperandToken0,DestComp) ((D3D10_SB_4_COMPONENT_NAME)(((OperandToken0)>>(D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_SHIFT+2*((DestComp)&D3D10_SB_4_COMPONENT_NAME_MASK)))&D3D10_SB_4_COMPONENT_NAME_MASK))
// ENCODER MACRO: Generate a 4 component swizzle given
// 4 D3D10_SB_4_COMPONENT_NAME source values for dest
// components x, y, z, w respectively.
#define ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(XSrc,YSrc,ZSrc,WSrc) ((((XSrc)&D3D10_SB_4_COMPONENT_NAME_MASK)| \
(((YSrc)&D3D10_SB_4_COMPONENT_NAME_MASK)<<2)| \
(((ZSrc)&D3D10_SB_4_COMPONENT_NAME_MASK)<<4)| \
(((WSrc)&D3D10_SB_4_COMPONENT_NAME_MASK)<<6) \
)<<D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE_SHIFT)
// ENCODER/DECODER MACROS: Various common swizzle patterns
// (noswizzle and replicate of each channels)
#define D3D10_SB_OPERAND_4_COMPONENT_NOSWIZZLE ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(D3D10_SB_4_COMPONENT_X,\
D3D10_SB_4_COMPONENT_Y,\
D3D10_SB_4_COMPONENT_Z,\
D3D10_SB_4_COMPONENT_W)
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEX ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(D3D10_SB_4_COMPONENT_X,\
D3D10_SB_4_COMPONENT_X,\
D3D10_SB_4_COMPONENT_X,\
D3D10_SB_4_COMPONENT_X)
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEY ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(D3D10_SB_4_COMPONENT_Y,\
D3D10_SB_4_COMPONENT_Y,\
D3D10_SB_4_COMPONENT_Y,\
D3D10_SB_4_COMPONENT_Y)
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEZ ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(D3D10_SB_4_COMPONENT_Z,\
D3D10_SB_4_COMPONENT_Z,\
D3D10_SB_4_COMPONENT_Z,\
D3D10_SB_4_COMPONENT_Z)
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEW ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SWIZZLE(D3D10_SB_4_COMPONENT_W,\
D3D10_SB_4_COMPONENT_W,\
D3D10_SB_4_COMPONENT_W,\
D3D10_SB_4_COMPONENT_W)
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATERED D3D10_SB_OPERAND_4_COMPONENT_REPLICATEX
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEGREEN D3D10_SB_OPERAND_4_COMPONENT_REPLICATEY
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEBLUE D3D10_SB_OPERAND_4_COMPONENT_REPLICATEZ
#define D3D10_SB_OPERAND_4_COMPONENT_REPLICATEALPHA D3D10_SB_OPERAND_4_COMPONENT_REPLICATEW
// MACROS FOR USE IN D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MODE:
#define D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MASK 0x00000030
#define D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_SHIFT 4
// DECODER MACRO: When 4 component selection mode is
// D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MODE, this macro
// extracts from OperandToken0 a D3D10_SB_4_COMPONENT_NAME
// which picks one of the 4 components.
#define DECODE_D3D10_SB_OPERAND_4_COMPONENT_SELECT_1(OperandToken0) ((D3D10_SB_4_COMPONENT_NAME)(((OperandToken0)&D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MASK)>>D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_SHIFT))
// ENCODER MACRO: Given a D3D10_SB_4_COMPONENT_NAME selecting
// a single component for D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MODE,
// encode it into OperandToken0
#define ENCODE_D3D10_SB_OPERAND_4_COMPONENT_SELECT_1(SelectedComp) (((SelectedComp)<<D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_SHIFT)&D3D10_SB_OPERAND_4_COMPONENT_SELECT_1_MASK)
// MACROS FOR DETERMINING OPERAND TYPE:
typedef enum D3D10_SB_OPERAND_TYPE
{
D3D10_SB_OPERAND_TYPE_TEMP = 0, // Temporary Register File
D3D10_SB_OPERAND_TYPE_INPUT = 1, // General Input Register File
D3D10_SB_OPERAND_TYPE_OUTPUT = 2, // General Output Register File
D3D10_SB_OPERAND_TYPE_INDEXABLE_TEMP = 3, // Temporary Register File (indexable)
D3D10_SB_OPERAND_TYPE_IMMEDIATE32 = 4, // 32bit/component immediate value(s)
// If for example, operand token bits
// [01:00]==D3D10_SB_OPERAND_4_COMPONENT,
// this means that the operand type:
// D3D10_SB_OPERAND_TYPE_IMMEDIATE32
// results in 4 additional 32bit
// DWORDS present for the operand.
D3D10_SB_OPERAND_TYPE_IMMEDIATE64 = 5, // 64bit/comp.imm.val(s)HI:LO
D3D10_SB_OPERAND_TYPE_SAMPLER = 6, // Reference to sampler state
D3D10_SB_OPERAND_TYPE_RESOURCE = 7, // Reference to memory resource (e.g. texture)
D3D10_SB_OPERAND_TYPE_CONSTANT_BUFFER= 8, // Reference to constant buffer
D3D10_SB_OPERAND_TYPE_IMMEDIATE_CONSTANT_BUFFER= 9, // Reference to immediate constant buffer
D3D10_SB_OPERAND_TYPE_LABEL = 10, // Label
D3D10_SB_OPERAND_TYPE_INPUT_PRIMITIVEID = 11, // Input primitive ID
D3D10_SB_OPERAND_TYPE_OUTPUT_DEPTH = 12, // Output Depth
D3D10_SB_OPERAND_TYPE_NULL = 13, // Null register, used to discard results of operations
// Below Are operands new in DX 10.1
D3D10_SB_OPERAND_TYPE_RASTERIZER = 14, // DX10.1 Rasterizer register, used to denote the depth/stencil and render target resources
D3D10_SB_OPERAND_TYPE_OUTPUT_COVERAGE_MASK = 15, // DX10.1 PS output MSAA coverage mask (scalar)
// Below Are operands new in DX 11
D3D11_SB_OPERAND_TYPE_STREAM = 16, // Reference to GS stream output resource
D3D11_SB_OPERAND_TYPE_FUNCTION_BODY = 17, // Reference to a function definition
D3D11_SB_OPERAND_TYPE_FUNCTION_TABLE = 18, // Reference to a set of functions used by a class
D3D11_SB_OPERAND_TYPE_INTERFACE = 19, // Reference to an interface
D3D11_SB_OPERAND_TYPE_FUNCTION_INPUT = 20, // Reference to an input parameter to a function
D3D11_SB_OPERAND_TYPE_FUNCTION_OUTPUT = 21, // Reference to an output parameter to a function
D3D11_SB_OPERAND_TYPE_OUTPUT_CONTROL_POINT_ID = 22, // HS Control Point phase input saying which output control point ID this is
D3D11_SB_OPERAND_TYPE_INPUT_FORK_INSTANCE_ID = 23, // HS Fork Phase input instance ID
D3D11_SB_OPERAND_TYPE_INPUT_JOIN_INSTANCE_ID = 24, // HS Join Phase input instance ID
D3D11_SB_OPERAND_TYPE_INPUT_CONTROL_POINT = 25, // HS Fork+Join, DS phase input control points (array of them)
D3D11_SB_OPERAND_TYPE_OUTPUT_CONTROL_POINT = 26, // HS Fork+Join phase output control points (array of them)
D3D11_SB_OPERAND_TYPE_INPUT_PATCH_CONSTANT = 27, // DS+HSJoin Input Patch Constants (array of them)
D3D11_SB_OPERAND_TYPE_INPUT_DOMAIN_POINT = 28, // DS Input Domain point
D3D11_SB_OPERAND_TYPE_THIS_POINTER = 29, // Reference to an interface this pointer
D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW = 30, // Reference to UAV u#
D3D11_SB_OPERAND_TYPE_THREAD_GROUP_SHARED_MEMORY = 31, // Reference to Thread Group Shared Memory g#
D3D11_SB_OPERAND_TYPE_INPUT_THREAD_ID = 32, // Compute Shader Thread ID
D3D11_SB_OPERAND_TYPE_INPUT_THREAD_GROUP_ID = 33, // Compute Shader Thread Group ID
D3D11_SB_OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP = 34, // Compute Shader Thread ID In Thread Group
D3D11_SB_OPERAND_TYPE_INPUT_COVERAGE_MASK = 35, // Pixel shader coverage mask input
D3D11_SB_OPERAND_TYPE_INPUT_THREAD_ID_IN_GROUP_FLATTENED = 36, // Compute Shader Thread ID In Group Flattened to a 1D value.
D3D11_SB_OPERAND_TYPE_INPUT_GS_INSTANCE_ID = 37, // Input GS instance ID
D3D11_SB_OPERAND_TYPE_OUTPUT_DEPTH_GREATER_EQUAL = 38, // Output Depth, forced to be greater than or equal than current depth
D3D11_SB_OPERAND_TYPE_OUTPUT_DEPTH_LESS_EQUAL = 39, // Output Depth, forced to be less than or equal to current depth
D3D11_SB_OPERAND_TYPE_CYCLE_COUNTER = 40, // Cycle counter
D3D11_SB_OPERAND_TYPE_OUTPUT_STENCIL_REF = 41, // DX11 PS output stencil reference (scalar)
D3D11_SB_OPERAND_TYPE_INNER_COVERAGE = 42, // DX11 PS input inner coverage (scalar)
} D3D10_SB_OPERAND_TYPE;
#define D3D10_SB_OPERAND_TYPE_MASK 0x000ff000
#define D3D10_SB_OPERAND_TYPE_SHIFT 12
// DECODER MACRO: Determine operand type from OperandToken0.
#define DECODE_D3D10_SB_OPERAND_TYPE(OperandToken0) ((D3D10_SB_OPERAND_TYPE)(((OperandToken0)&D3D10_SB_OPERAND_TYPE_MASK)>>D3D10_SB_OPERAND_TYPE_SHIFT))
// ENCODER MACRO: Store operand type in OperandToken0.
#define ENCODE_D3D10_SB_OPERAND_TYPE(OperandType) (((OperandType)<<D3D10_SB_OPERAND_TYPE_SHIFT)&D3D10_SB_OPERAND_TYPE_MASK)
typedef enum D3D10_SB_OPERAND_INDEX_DIMENSION
{
D3D10_SB_OPERAND_INDEX_0D = 0, // e.g. Position
D3D10_SB_OPERAND_INDEX_1D = 1, // Most common. e.g. Temp registers.
D3D10_SB_OPERAND_INDEX_2D = 2, // e.g. Geometry Program Input registers.
D3D10_SB_OPERAND_INDEX_3D = 3, // 3D rarely if ever used.
} D3D10_SB_OPERAND_INDEX_DIMENSION;
#define D3D10_SB_OPERAND_INDEX_DIMENSION_MASK 0x00300000
#define D3D10_SB_OPERAND_INDEX_DIMENSION_SHIFT 20
// DECODER MACRO: Determine operand index dimension from OperandToken0.
#define DECODE_D3D10_SB_OPERAND_INDEX_DIMENSION(OperandToken0) ((D3D10_SB_OPERAND_INDEX_DIMENSION)(((OperandToken0)&D3D10_SB_OPERAND_INDEX_DIMENSION_MASK)>>D3D10_SB_OPERAND_INDEX_DIMENSION_SHIFT))
// ENCODER MACRO: Store operand index dimension
// (D3D10_SB_OPERAND_INDEX_DIMENSION enum) in OperandToken0.
#define ENCODE_D3D10_SB_OPERAND_INDEX_DIMENSION(OperandIndexDim) (((OperandIndexDim)<<D3D10_SB_OPERAND_INDEX_DIMENSION_SHIFT)&D3D10_SB_OPERAND_INDEX_DIMENSION_MASK)
typedef enum D3D10_SB_OPERAND_INDEX_REPRESENTATION
{
D3D10_SB_OPERAND_INDEX_IMMEDIATE32 = 0, // Extra DWORD
D3D10_SB_OPERAND_INDEX_IMMEDIATE64 = 1, // 2 Extra DWORDs
// (HI32:LO32)
D3D10_SB_OPERAND_INDEX_RELATIVE = 2, // Extra operand
D3D10_SB_OPERAND_INDEX_IMMEDIATE32_PLUS_RELATIVE = 3, // Extra DWORD followed by
// extra operand
D3D10_SB_OPERAND_INDEX_IMMEDIATE64_PLUS_RELATIVE = 4, // 2 Extra DWORDS
// (HI32:LO32) followed
// by extra operand
} D3D10_SB_OPERAND_INDEX_REPRESENTATION;
#define D3D10_SB_OPERAND_INDEX_REPRESENTATION_SHIFT(Dim) (22+3*((Dim)&3))
#define D3D10_SB_OPERAND_INDEX_REPRESENTATION_MASK(Dim) (0x3<<D3D10_SB_OPERAND_INDEX_REPRESENTATION_SHIFT(Dim))
// DECODER MACRO: Determine from OperandToken0 what representation
// an operand index is provided as (D3D10_SB_OPERAND_INDEX_REPRESENTATION enum),
// for index dimension [0], [1] or [2], depending on D3D10_SB_OPERAND_INDEX_DIMENSION.
#define DECODE_D3D10_SB_OPERAND_INDEX_REPRESENTATION(Dim,OperandToken0) ((D3D10_SB_OPERAND_INDEX_REPRESENTATION)(((OperandToken0)&D3D10_SB_OPERAND_INDEX_REPRESENTATION_MASK(Dim))>>D3D10_SB_OPERAND_INDEX_REPRESENTATION_SHIFT(Dim)))
// ENCODER MACRO: Store in OperandToken0 what representation
// an operand index is provided as (D3D10_SB_OPERAND_INDEX_REPRESENTATION enum),
// for index dimension [0], [1] or [2], depending on D3D10_SB_OPERAND_INDEX_DIMENSION.
#define ENCODE_D3D10_SB_OPERAND_INDEX_REPRESENTATION(Dim,IndexRepresentation) (((IndexRepresentation)<<D3D10_SB_OPERAND_INDEX_REPRESENTATION_SHIFT(Dim))&D3D10_SB_OPERAND_INDEX_REPRESENTATION_MASK(Dim))
#define D3D10_SB_OPERAND_EXTENDED_MASK 0x80000000
#define D3D10_SB_OPERAND_EXTENDED_SHIFT 31
// DECODER MACRO: Determine if the operand is extended
// by an additional opcode token.
#define DECODE_IS_D3D10_SB_OPERAND_EXTENDED(OperandToken0) (((OperandToken0)&D3D10_SB_OPERAND_EXTENDED_MASK)>>D3D10_SB_OPERAND_EXTENDED_SHIFT)
// ENCODER MACRO: Store in OperandToken0 whether the operand is extended
// by an additional operand token.
#define ENCODE_D3D10_SB_OPERAND_EXTENDED(bExtended) (((bExtended)!=0)?D3D10_SB_OPERAND_EXTENDED_MASK:0)
// ----------------------------------------------------------------------------
// Extended Instruction Operand Format (OperandToken1)
//
// If bit31 of an operand token is set, the
// operand has additional data in a second DWORD
// directly following OperandToken0. Other tokens
// expected for the operand, such as immmediate
// values or relative address operands (full
// operands in themselves) always follow
// OperandToken0 AND OperandToken1..n (extended
// operand tokens, if present).
//
// [05:00] D3D10_SB_EXTENDED_OPERAND_TYPE
// [16:06] if([05:00] == D3D10_SB_EXTENDED_OPERAND_MODIFIER)
// {
// [13:06] D3D10_SB_OPERAND_MODIFIER
// [16:14] Min Precision: D3D11_SB_OPERAND_MIN_PRECISION
// [17:17] Non-uniform: D3D12_SB_OPERAND_NON_UNIFORM
// }
// else
// {
// [17:06] Ignored, 0.
// }
// [30:18] Ignored, 0.
// [31] 0 normally. 1 if second order extended operand definition,
// meaning next DWORD contains yet ANOTHER extended operand
// description. Currently no second order extensions defined.
// This would be useful if a particular extended operand does
// not have enough space to store the required information in
// a single token and so is extended further.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_EXTENDED_OPERAND_TYPE
{
D3D10_SB_EXTENDED_OPERAND_EMPTY = 0, // Might be used if this
// enum is full and
// further extended opcode
// is needed.
D3D10_SB_EXTENDED_OPERAND_MODIFIER = 1,
} D3D10_SB_EXTENDED_OPERAND_TYPE;
#define D3D10_SB_EXTENDED_OPERAND_TYPE_MASK 0x0000003f
// DECODER MACRO: Given an extended operand
// token (OperandToken1), figure out what type
// of token it is (from D3D10_SB_EXTENDED_OPERAND_TYPE enum)
// to be able to interpret the rest of the token's contents.
#define DECODE_D3D10_SB_EXTENDED_OPERAND_TYPE(OperandToken1) ((D3D10_SB_EXTENDED_OPERAND_TYPE)((OperandToken1)&D3D10_SB_EXTENDED_OPERAND_TYPE_MASK))
// ENCODER MACRO: Store extended operand token
// type in OperandToken1.
#define ENCODE_D3D10_SB_EXTENDED_OPERAND_TYPE(ExtOperandType) ((ExtOperandType)&D3D10_SB_EXTENDED_OPERAND_TYPE_MASK)
typedef enum D3D10_SB_OPERAND_MODIFIER
{
D3D10_SB_OPERAND_MODIFIER_NONE = 0, // Nop. This is the implied
// default if the extended
// operand is not present for
// an operand for which source
// modifiers are meaningful
D3D10_SB_OPERAND_MODIFIER_NEG = 1, // Negate
D3D10_SB_OPERAND_MODIFIER_ABS = 2, // Absolute value, abs()
D3D10_SB_OPERAND_MODIFIER_ABSNEG = 3, // -abs()
} D3D10_SB_OPERAND_MODIFIER;
#define D3D10_SB_OPERAND_MODIFIER_MASK 0x00003fc0
#define D3D10_SB_OPERAND_MODIFIER_SHIFT 6
// DECODER MACRO: Given a D3D10_SB_EXTENDED_OPERAND_MODIFIER
// extended token (OperandToken1), determine the source modifier
// (D3D10_SB_OPERAND_MODIFIER enum)
#define DECODE_D3D10_SB_OPERAND_MODIFIER(OperandToken1) ((D3D10_SB_OPERAND_MODIFIER)(((OperandToken1)&D3D10_SB_OPERAND_MODIFIER_MASK)>>D3D10_SB_OPERAND_MODIFIER_SHIFT))
// ENCODER MACRO: Generate a complete source modifier extended token
// (OperandToken1), given D3D10_SB_OPERAND_MODIFIER enum (the
// ext. operand type is also set to D3D10_SB_EXTENDED_OPERAND_MODIFIER).
#define ENCODE_D3D10_SB_EXTENDED_OPERAND_MODIFIER(SourceMod) ((((SourceMod)<<D3D10_SB_OPERAND_MODIFIER_SHIFT)&D3D10_SB_OPERAND_MODIFIER_MASK)| \
ENCODE_D3D10_SB_EXTENDED_OPERAND_TYPE(D3D10_SB_EXTENDED_OPERAND_MODIFIER) | \
ENCODE_D3D10_SB_OPERAND_DOUBLE_EXTENDED(0))
// Min precision specifier for source/dest operands. This
// fits in the extended operand token field. Implementations are free to
// execute at higher precision than the min - details spec'ed elsewhere.
// This is part of the opcode specific control range.
typedef enum D3D11_SB_OPERAND_MIN_PRECISION
{
D3D11_SB_OPERAND_MIN_PRECISION_DEFAULT = 0, // Default precision
// for the shader model
D3D11_SB_OPERAND_MIN_PRECISION_FLOAT_16 = 1, // Min 16 bit/component float
D3D11_SB_OPERAND_MIN_PRECISION_FLOAT_2_8 = 2, // Min 10(2.8)bit/comp. float
D3D11_SB_OPERAND_MIN_PRECISION_SINT_16 = 4, // Min 16 bit/comp. signed integer
D3D11_SB_OPERAND_MIN_PRECISION_UINT_16 = 5, // Min 16 bit/comp. unsigned integer
} D3D11_SB_OPERAND_MIN_PRECISION;
#define D3D11_SB_OPERAND_MIN_PRECISION_MASK 0x0001C000
#define D3D11_SB_OPERAND_MIN_PRECISION_SHIFT 14
// DECODER MACRO: For an OperandToken1 that can specify
// a minimum precision for execution, find out what it is.
#define DECODE_D3D11_SB_OPERAND_MIN_PRECISION(OperandToken1) ((D3D11_SB_OPERAND_MIN_PRECISION)(((OperandToken1)& D3D11_SB_OPERAND_MIN_PRECISION_MASK)>> D3D11_SB_OPERAND_MIN_PRECISION_SHIFT))
// ENCODER MACRO: Encode minimum precision for execution
// into the extended operand token, OperandToken1
#define ENCODE_D3D11_SB_OPERAND_MIN_PRECISION(MinPrecision) (((MinPrecision)<< D3D11_SB_OPERAND_MIN_PRECISION_SHIFT)& D3D11_SB_OPERAND_MIN_PRECISION_MASK)
// Non-uniform extended operand modifier.
#define D3D12_SB_OPERAND_NON_UNIFORM_MASK 0x00020000
#define D3D12_SB_OPERAND_NON_UNIFORM_SHIFT 17
// DECODER MACRO: For an OperandToken1 that can specify a non-uniform operand
#define DECODE_D3D12_SB_OPERAND_NON_UNIFORM(OperandToken1) (((OperandToken1)& D3D12_SB_OPERAND_NON_UNIFORM_MASK)>> D3D12_SB_OPERAND_NON_UNIFORM_SHIFT)
// ENCODER MACRO: Encode non-uniform state into the extended operand token, OperandToken1
#define ENCODE_D3D12_SB_OPERAND_NON_UNIFORM(NonUniform) (((NonUniform)<< D3D12_SB_OPERAND_NON_UNIFORM_SHIFT)& D3D12_SB_OPERAND_NON_UNIFORM_MASK)
#define D3D10_SB_OPERAND_DOUBLE_EXTENDED_MASK 0x80000000
#define D3D10_SB_OPERAND_DOUBLE_EXTENDED_SHIFT 31
// DECODER MACRO: Determine if an extended operand token
// (OperandToken1) is further extended by yet another token
// (OperandToken2). Currently there are no secondary
// extended operand tokens.
#define DECODE_IS_D3D10_SB_OPERAND_DOUBLE_EXTENDED(OperandToken1) (((OperandToken1)&D3D10_SB_OPERAND_DOUBLE_EXTENDED_MASK)>>D3D10_SB_OPERAND_DOUBLE_EXTENDED_SHIFT)
// ENCODER MACRO: Store in OperandToken1 whether the operand is extended
// by an additional operand token. Currently there are no secondary
// extended operand tokens.
#define ENCODE_D3D10_SB_OPERAND_DOUBLE_EXTENDED(bExtended) (((bExtended)!=0)?D3D10_SB_OPERAND_DOUBLE_EXTENDED_MASK:0)
// ----------------------------------------------------------------------------
// Name Token (NameToken) (used in declaration statements)
//
// [15:00] D3D10_SB_NAME enumeration
// [31:16] Reserved, 0
//
// ----------------------------------------------------------------------------
#define D3D10_SB_NAME_MASK 0x0000ffff
// DECODER MACRO: Get the name from NameToken
#define DECODE_D3D10_SB_NAME(NameToken) ((D3D10_SB_NAME)((NameToken)&D3D10_SB_NAME_MASK))
// ENCODER MACRO: Generate a complete NameToken given a D3D10_SB_NAME
#define ENCODE_D3D10_SB_NAME(Name) ((Name)&D3D10_SB_NAME_MASK)
//---------------------------------------------------------------------
// Declaration Statements
//
// Declarations start with a standard opcode token,
// having opcode type being D3D10_SB_OPCODE_DCL*.
// Each particular declaration type has custom
// operand token(s), described below.
//---------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Global Flags Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_GLOBAL_FLAGS
// [11:11] Refactoring allowed if bit set.
// [12:12] Enable double precision float ops.
// [13:13] Force early depth-stencil test.
// [14:14] Enable RAW and structured buffers in non-CS 4.x shaders.
// [15:15] Skip optimizations of shader IL when translating to native code
// [16:16] Enable minimum-precision data types
// [17:17] Enable 11.1 double-precision floating-point instruction extensions
// [18:18] Enable 11.1 non-double instruction extensions
// [23:19] Reserved for future flags.
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by no operands.
//
// ----------------------------------------------------------------------------
#define D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED (1<<11)
#define D3D11_SB_GLOBAL_FLAG_ENABLE_DOUBLE_PRECISION_FLOAT_OPS (1<<12)
#define D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL (1<<13)
#define D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS (1<<14)
#define D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION (1<<15)
#define D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION (1<<16)
#define D3D11_1_SB_GLOBAL_FLAG_ENABLE_DOUBLE_EXTENSIONS (1<<17)
#define D3D11_1_SB_GLOBAL_FLAG_ENABLE_SHADER_EXTENSIONS (1<<18)
#define D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND (1<<19)
#define D3D10_SB_GLOBAL_FLAGS_MASK 0x00fff800
// DECODER MACRO: Get global flags
#define DECODE_D3D10_SB_GLOBAL_FLAGS(OpcodeToken0) ((OpcodeToken0)&D3D10_SB_GLOBAL_FLAGS_MASK)
// ENCODER MACRO: Encode global flags
#define ENCODE_D3D10_SB_GLOBAL_FLAGS(Flags) ((Flags)&D3D10_SB_GLOBAL_FLAGS_MASK)
// ----------------------------------------------------------------------------
// Resource Declaration (non multisampled)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_RESOURCE
// [15:11] D3D10_SB_RESOURCE_DIMENSION
// [23:16] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands on Shader Models 4.0 through 5.0:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// (2) a Resource Return Type token (ResourceReturnTypeToken)
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (t<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of resources in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the t# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (t<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of resource within space (may be dynamically indexed)
// (2) a Resource Return Type token (ResourceReturnTypeToken)
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
#define D3D10_SB_RESOURCE_DIMENSION_MASK 0x0000F800
#define D3D10_SB_RESOURCE_DIMENSION_SHIFT 11
// DECODER MACRO: Given a resource declaration token,
// (OpcodeToken0), determine the resource dimension
// (D3D10_SB_RESOURCE_DIMENSION enum)
#define DECODE_D3D10_SB_RESOURCE_DIMENSION(OpcodeToken0) ((D3D10_SB_RESOURCE_DIMENSION)(((OpcodeToken0)&D3D10_SB_RESOURCE_DIMENSION_MASK)>>D3D10_SB_RESOURCE_DIMENSION_SHIFT))
// ENCODER MACRO: Store resource dimension
// (D3D10_SB_RESOURCE_DIMENSION enum) into a
// a resource declaration token (OpcodeToken0)
#define ENCODE_D3D10_SB_RESOURCE_DIMENSION(ResourceDim) (((ResourceDim)<<D3D10_SB_RESOURCE_DIMENSION_SHIFT)&D3D10_SB_RESOURCE_DIMENSION_MASK)
// ----------------------------------------------------------------------------
// Resource Declaration (multisampled)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_RESOURCE (same opcode as non-multisampled case)
// [15:11] D3D10_SB_RESOURCE_DIMENSION (must be TEXTURE2DMS or TEXTURE2DMSARRAY)
// [22:16] Sample count 1...127. 0 is currently disallowed, though
// in future versions 0 could mean "configurable" sample count
// [23:23] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands on Shader Models 4.0 through 5.0:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// (2) a Resource Return Type token (ResourceReturnTypeToken)
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (t<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of resources in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the t# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (t<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of resource within space (may be dynamically indexed)
// (2) a Resource Return Type token (ResourceReturnTypeToken)
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
// use same macro for encoding/decoding resource dimension aas the non-msaa declaration
#define D3D10_SB_RESOURCE_SAMPLE_COUNT_MASK 0x07F0000
#define D3D10_SB_RESOURCE_SAMPLE_COUNT_SHIFT 16
// DECODER MACRO: Given a resource declaration token,
// (OpcodeToken0), determine the resource sample count (1..127)
#define DECODE_D3D10_SB_RESOURCE_SAMPLE_COUNT(OpcodeToken0) ((UINT)(((OpcodeToken0)&D3D10_SB_RESOURCE_SAMPLE_COUNT_MASK)>>D3D10_SB_RESOURCE_SAMPLE_COUNT_SHIFT))
// ENCODER MACRO: Store resource sample count up to 127 into a
// a resource declaration token (OpcodeToken0)
#define ENCODE_D3D10_SB_RESOURCE_SAMPLE_COUNT(SampleCount) (((SampleCount > 127 ? 127 : SampleCount)<<D3D10_SB_RESOURCE_SAMPLE_COUNT_SHIFT)&D3D10_SB_RESOURCE_SAMPLE_COUNT_MASK)
// ----------------------------------------------------------------------------
// Resource Return Type Token (ResourceReturnTypeToken) (used in resource
// declaration statements)
//
// [03:00] D3D10_SB_RESOURCE_RETURN_TYPE for component X
// [07:04] D3D10_SB_RESOURCE_RETURN_TYPE for component Y
// [11:08] D3D10_SB_RESOURCE_RETURN_TYPE for component Z
// [15:12] D3D10_SB_RESOURCE_RETURN_TYPE for component W
// [31:16] Reserved, 0
//
// ----------------------------------------------------------------------------
// DECODER MACRO: Get the resource return type for component (0-3) from
// ResourceReturnTypeToken
#define DECODE_D3D10_SB_RESOURCE_RETURN_TYPE(ResourceReturnTypeToken, Component) \
((D3D10_SB_RESOURCE_RETURN_TYPE)(((ResourceReturnTypeToken) >> \
(Component * D3D10_SB_RESOURCE_RETURN_TYPE_NUMBITS))&D3D10_SB_RESOURCE_RETURN_TYPE_MASK))
// ENCODER MACRO: Generate a resource return type for a component
#define ENCODE_D3D10_SB_RESOURCE_RETURN_TYPE(ReturnType, Component) \
(((ReturnType)&D3D10_SB_RESOURCE_RETURN_TYPE_MASK) << (Component * D3D10_SB_RESOURCE_RETURN_TYPE_NUMBITS))
// ----------------------------------------------------------------------------
// Sampler Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_SAMPLER
// [14:11] D3D10_SB_SAMPLER_MODE
// [23:15] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand on Shader Models 4.0 through 5.0:
// (1) Operand starting with OperandToken0, defining which sampler
// (D3D10_SB_OPERAND_TYPE_SAMPLER) register # is being declared.
//
// OpcodeToken0 is followed by 2 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// s# register (D3D10_SB_OPERAND_TYPE_SAMPLER) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (s<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of samplers in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the s# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (s<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of sampler within space (may be dynamically indexed)
// (2) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_SAMPLER_MODE
{
D3D10_SB_SAMPLER_MODE_DEFAULT = 0,
D3D10_SB_SAMPLER_MODE_COMPARISON = 1,
D3D10_SB_SAMPLER_MODE_MONO = 2,
} D3D10_SB_SAMPLER_MODE;
#define D3D10_SB_SAMPLER_MODE_MASK 0x00007800
#define D3D10_SB_SAMPLER_MODE_SHIFT 11
// DECODER MACRO: Find out if a Constant Buffer is going to be indexed or not
#define DECODE_D3D10_SB_SAMPLER_MODE(OpcodeToken0) ((D3D10_SB_SAMPLER_MODE)(((OpcodeToken0)&D3D10_SB_SAMPLER_MODE_MASK)>>D3D10_SB_SAMPLER_MODE_SHIFT))
// ENCODER MACRO: Generate a resource return type for a component
#define ENCODE_D3D10_SB_SAMPLER_MODE(SamplerMode) (((SamplerMode)<<D3D10_SB_SAMPLER_MODE_SHIFT)&D3D10_SB_SAMPLER_MODE_MASK)
// ----------------------------------------------------------------------------
// Input Register Declaration (see separate declarations for Pixel Shaders)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared,
// including writemask.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Input Register Declaration w/System Interpreted Value
// (see separate declarations for Pixel Shaders)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT_SIV
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared,
// including writemask. For Geometry Shaders, the input is
// v[vertex][attribute], and this declaration is only for which register
// on the attribute axis is being declared. The vertex axis value must
// be equal to the # of vertices in the current input primitive for the GS
// (i.e. 6 for triangle + adjacency).
// (2) a System Interpreted Value Name (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Input Register Declaration w/System Generated Value
// (available for all shaders incl. Pixel Shader, no interpolation mode needed)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT_SGV
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared,
// including writemask.
// (2) a System Generated Value Name (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Pixel Shader Input Register Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT_PS
// [14:11] D3D10_SB_INTERPOLATION_MODE
// [23:15] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared,
// including writemask.
//
// ----------------------------------------------------------------------------
#define D3D10_SB_INPUT_INTERPOLATION_MODE_MASK 0x00007800
#define D3D10_SB_INPUT_INTERPOLATION_MODE_SHIFT 11
// DECODER MACRO: Find out interpolation mode for the input register
#define DECODE_D3D10_SB_INPUT_INTERPOLATION_MODE(OpcodeToken0) ((D3D10_SB_INTERPOLATION_MODE)(((OpcodeToken0)&D3D10_SB_INPUT_INTERPOLATION_MODE_MASK)>>D3D10_SB_INPUT_INTERPOLATION_MODE_SHIFT))
// ENCODER MACRO: Encode interpolation mode for a register.
#define ENCODE_D3D10_SB_INPUT_INTERPOLATION_MODE(InterpolationMode) (((InterpolationMode)<<D3D10_SB_INPUT_INTERPOLATION_MODE_SHIFT)&D3D10_SB_INPUT_INTERPOLATION_MODE_MASK)
// ----------------------------------------------------------------------------
// Pixel Shader Input Register Declaration w/System Interpreted Value
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT_PS_SIV
// [14:11] D3D10_SB_INTERPOLATION_MODE
// [23:15] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared.
// (2) a System Interpreted Value Name (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Pixel Shader Input Register Declaration w/System Generated Value
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INPUT_PS_SGV
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) Operand, starting with OperandToken0, defining which input
// v# register (D3D10_SB_OPERAND_TYPE_INPUT) is being declared.
// (2) a System Generated Value Name (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Output Register Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_OUTPUT
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand:
// (1) Operand, starting with OperandToken0, defining which
// o# register (D3D10_SB_OPERAND_TYPE_OUTPUT) is being declared,
// including writemask.
// (in Pixel Shader, output can also be one of
// D3D10_SB_OPERAND_TYPE_OUTPUT_DEPTH,
// D3D11_SB_OPERAND_TYPE_OUTPUT_DEPTH_GREATER_EQUAL, or
// D3D11_SB_OPERAND_TYPE_OUTPUT_DEPTH_LESS_EQUAL )
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Output Register Declaration w/System Interpreted Value
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_OUTPUT_SIV
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// o# register (D3D10_SB_OPERAND_TYPE_OUTPUT) is being declared,
// including writemask.
// (2) a System Interpreted Name token (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Output Register Declaration w/System Generated Value
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_OUTPUT_SGV
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// o# register (D3D10_SB_OPERAND_TYPE_OUTPUT) is being declared,
// including writemask.
// (2) a System Generated Name token (NameToken)
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Input or Output Register Indexing Range Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INDEX_RANGE
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// input (v#) or output (o#) register is having its array indexing range
// declared, including writemask. For Geometry Shader inputs,
// it is assumed that the vertex axis is always fully indexable,
// and 0 must be specified as the vertex# in this declaration, so that
// only the a range of attributes are having their index range defined.
//
// (2) a DWORD representing the count of registers starting from the one
// indicated in (1).
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Temp Register Declaration r0...r(n-1)
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_TEMPS
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand:
// (1) DWORD (unsigned int) indicating how many temps are being declared.
// i.e. 5 means r0...r4 are declared.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Indexable Temp Register (x#[size]) Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INDEXABLE_TEMP
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 3 DWORDs:
// (1) Register index (defines which x# register is declared)
// (2) Number of registers in this register bank
// (3) Number of components in the array (1-4). 1 means .x, 2 means .xy etc.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Constant Buffer Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_CONSTANT_BUFFER
// [11] D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN
// [23:12] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand on Shader Model 4.0 through 5.0:
// (1) Operand, starting with OperandToken0, defining which CB slot (cb#[size])
// is being declared. (operand type: D3D10_SB_OPERAND_TYPE_CONSTANT_BUFFER)
// The indexing dimension for the register must be
// D3D10_SB_OPERAND_INDEX_DIMENSION_2D, where the first index specifies
// which cb#[] is being declared, and the second (array) index specifies the size
// of the buffer, as a count of 32-bit*4 elements. (As opposed to when the
// cb#[] is used in shader instructions, and the array index represents which
// location in the constant buffer is being referenced.)
// If the size is specified as 0, the CB size is not known (any size CB
// can be bound to the slot).
//
// The order of constant buffer declarations in a shader indicates their
// relative priority from highest to lowest (hint to driver).
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) Operand, starting with OperandToken0, defining which CB range (ID and bounds)
// is being declared. (operand type: D3D10_SB_OPERAND_TYPE_CONSTANT_BUFFER)
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (cb<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of constant buffers in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the cb#[] is used in shader instructions: (cb<id>[<idx>][<loc>])
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of constant buffer within space (may be dynamically indexed)
// 3 <loc>: location of vector within constant buffer being referenced,
// which may also be dynamically indexed, with no access pattern flag required.
// (2) a DWORD indicating the size of the constant buffer as a count of 16-byte vectors.
// Each vector is 32-bit*4 elements == 128-bits == 16 bytes.
// If the size is specified as 0, the CB size is not known (any size CB
// can be bound to the slot).
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN
{
D3D10_SB_CONSTANT_BUFFER_IMMEDIATE_INDEXED = 0,
D3D10_SB_CONSTANT_BUFFER_DYNAMIC_INDEXED = 1
} D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN;
#define D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_MASK 0x00000800
#define D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_SHIFT 11
// DECODER MACRO: Find out if a Constant Buffer is going to be indexed or not
#define DECODE_D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN(OpcodeToken0) ((D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN)(((OpcodeToken0)&D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_MASK)>>D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_SHIFT))
// ENCODER MACRO: Encode the access pattern for the Constant Buffer
#define ENCODE_D3D10_SB_D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN(AccessPattern) (((AccessPattern)<<D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_SHIFT)&D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN_MASK)
// ----------------------------------------------------------------------------
// Immediate Constant Buffer Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_CUSTOMDATA
// [31:11] == D3D10_SB_CUSTOMDATA_DCL_IMMEDIATE_CONSTANT_BUFFER
//
// OpcodeToken0 is followed by:
// (1) DWORD indicating length of declaration, including OpcodeToken0.
// This length must = 2(for OpcodeToken0 and 1) + a multiple of 4
// (# of immediate constants)
// (2) Sequence of 4-tuples of DWORDs defining the Immediate Constant Buffer.
// The number of 4-tuples is (length above - 1) / 4
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Shader Message Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_CUSTOMDATA
// [31:11] == D3D11_SB_CUSTOMDATA_SHADER_MESSAGE
//
// OpcodeToken0 is followed by:
// (1) DWORD indicating length of declaration, including OpcodeToken0.
// (2) DWORD (D3D11_SB_SHADER_MESSAGE_ID) indicating shader message or error.
// (3) D3D11_SB_SHADER_MESSAGE_FORMAT indicating the convention for formatting the message.
// (4) DWORD indicating the number of characters in the string without the terminator.
// (5) DWORD indicating the number of operands.
// (6) DWORD indicating length of operands.
// (7) Encoded operands.
// (8) String with trailing zero, padded to a multiple of DWORDs.
// The string is in the given format and the operands given should
// be used for argument substitutions when formatting.
// ----------------------------------------------------------------------------
typedef enum D3D11_SB_SHADER_MESSAGE_ID
{
D3D11_SB_SHADER_MESSAGE_ID_MESSAGE = 0x00200102,
D3D11_SB_SHADER_MESSAGE_ID_ERROR = 0x00200103
} D3D11_SB_SHADER_MESSAGE_ID;
typedef enum D3D11_SB_SHADER_MESSAGE_FORMAT
{
// No formatting, just a text string. Operands are ignored.
D3D11_SB_SHADER_MESSAGE_FORMAT_ANSI_TEXT,
// Format string follows C/C++ printf conventions.
D3D11_SB_SHADER_MESSAGE_FORMAT_ANSI_PRINTF,
} D3D11_SB_SHADER_MESSAGE_FORMAT;
// ----------------------------------------------------------------------------
// Shader Clip Plane Constant Mappings for DX9 hardware
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_CUSTOMDATA
// [31:11] == D3D11_SB_CUSTOMDATA_SHADER_CLIP_PLANE_CONSTANT_MAPPINGS_FOR_DX9
//
// OpcodeToken0 is followed by:
// (1) DWORD indicating length of declaration, including OpcodeToken0.
// (2) DWORD indicating number of constant mappings (up to 6 mappings).
// (3+) Constant mapping tables in following format.
//
// struct _Clip_Plane_Constant_Mapping
// {
// WORD ConstantBufferIndex; // cb[n]
// WORD StartConstantElement; // starting index of cb[n][m]
// WORD ConstantElemntCount; // number of elements cb[n][m] ~ cb[n][m+l]
// WORD Reserved; //
// };
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Geometry Shader Input Primitive Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_GS_INPUT_PRIMITIVE
// [16:11] D3D10_SB_PRIMITIVE [not D3D10_SB_PRIMITIVE_TOPOLOGY]
// [23:17] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
#define D3D10_SB_GS_INPUT_PRIMITIVE_MASK 0x0001f800
#define D3D10_SB_GS_INPUT_PRIMITIVE_SHIFT 11
// DECODER MACRO: Given a primitive topology declaration,
// (OpcodeToken0), determine the primitive topology
// (D3D10_SB_PRIMITIVE enum)
#define DECODE_D3D10_SB_GS_INPUT_PRIMITIVE(OpcodeToken0) ((D3D10_SB_PRIMITIVE)(((OpcodeToken0)&D3D10_SB_GS_INPUT_PRIMITIVE_MASK)>>D3D10_SB_GS_INPUT_PRIMITIVE_SHIFT))
// ENCODER MACRO: Store primitive topology
// (D3D10_SB_PRIMITIVE enum) into a
// a primitive topology declaration token (OpcodeToken0)
#define ENCODE_D3D10_SB_GS_INPUT_PRIMITIVE(Prim) (((Prim)<<D3D10_SB_GS_INPUT_PRIMITIVE_SHIFT)&D3D10_SB_GS_INPUT_PRIMITIVE_MASK)
// ----------------------------------------------------------------------------
// Geometry Shader Output Topology Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY
// [17:11] D3D10_SB_PRIMITIVE_TOPOLOGY
// [23:18] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
#define D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_MASK 0x0001f800
#define D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_SHIFT 11
// DECODER MACRO: Given a primitive topology declaration,
// (OpcodeToken0), determine the primitive topology
// (D3D10_SB_PRIMITIVE_TOPOLOGY enum)
#define DECODE_D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY(OpcodeToken0) ((D3D10_SB_PRIMITIVE_TOPOLOGY)(((OpcodeToken0)&D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_MASK)>>D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_SHIFT))
// ENCODER MACRO: Store primitive topology
// (D3D10_SB_PRIMITIVE_TOPOLOGY enum) into a
// a primitive topology declaration token (OpcodeToken0)
#define ENCODE_D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY(PrimTopology) (((PrimTopology)<<D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_SHIFT)&D3D10_SB_GS_OUTPUT_PRIMITIVE_TOPOLOGY_MASK)
// ----------------------------------------------------------------------------
// Geometry Shader Maximum Output Vertex Count Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by a DWORD representing the
// maximum number of primitives that could be output
// by the Geometry Shader.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Geometry Shader Instance Count Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_GS_INSTANCE_COUNT
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by a UINT32 representing the
// number of instances of the geometry shader program to execute.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: HS/DS Input Control Point Count
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT
// [16:11] Control point count
// [23:17] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
#define D3D11_SB_INPUT_CONTROL_POINT_COUNT_MASK 0x0001f800
#define D3D11_SB_INPUT_CONTROL_POINT_COUNT_SHIFT 11
// DECODER MACRO: Given an input control point count declaration token,
// (OpcodeToken0), determine the control point count
#define DECODE_D3D11_SB_INPUT_CONTROL_POINT_COUNT(OpcodeToken0) ((UINT)(((OpcodeToken0)&D3D11_SB_INPUT_CONTROL_POINT_COUNT_MASK)>>D3D11_SB_INPUT_CONTROL_POINT_COUNT_SHIFT))
// ENCODER MACRO: Store input control point count into a declaration token
#define ENCODE_D3D11_SB_INPUT_CONTROL_POINT_COUNT(Count) (((Count)<<D3D11_SB_INPUT_CONTROL_POINT_COUNT_SHIFT)&D3D11_SB_INPUT_CONTROL_POINT_COUNT_MASK)
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: HS Output Control Point Count
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT
// [16:11] Control point count
// [23:17] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
#define D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_MASK 0x0001f800
#define D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_SHIFT 11
// DECODER MACRO: Given an output control point count declaration token,
// (OpcodeToken0), determine the control point count
#define DECODE_D3D11_SB_OUTPUT_CONTROL_POINT_COUNT(OpcodeToken0) ((UINT)(((OpcodeToken0)&D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_MASK)>>D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_SHIFT))
// ENCODER MACRO: Store output control point count into a declaration token
#define ENCODE_D3D11_SB_OUTPUT_CONTROL_POINT_COUNT(Count) (((Count)<<D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_SHIFT)&D3D11_SB_OUTPUT_CONTROL_POINT_COUNT_MASK)
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: Tessellator Domain
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_TESS_DOMAIN
// [12:11] Domain
// [23:13] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
typedef enum D3D11_SB_TESSELLATOR_DOMAIN
{
D3D11_SB_TESSELLATOR_DOMAIN_UNDEFINED = 0,
D3D11_SB_TESSELLATOR_DOMAIN_ISOLINE = 1,
D3D11_SB_TESSELLATOR_DOMAIN_TRI = 2,
D3D11_SB_TESSELLATOR_DOMAIN_QUAD = 3
} D3D11_SB_TESSELLATOR_DOMAIN;
#define D3D11_SB_TESS_DOMAIN_MASK 0x00001800
#define D3D11_SB_TESS_DOMAIN_SHIFT 11
// DECODER MACRO: Given a tessellator domain declaration,
// (OpcodeToken0), determine the domain
// (D3D11_SB_TESSELLATOR_DOMAIN enum)
#define DECODE_D3D11_SB_TESS_DOMAIN(OpcodeToken0) ((D3D11_SB_TESSELLATOR_DOMAIN)(((OpcodeToken0)&D3D11_SB_TESS_DOMAIN_MASK)>>D3D11_SB_TESS_DOMAIN_SHIFT))
// ENCODER MACRO: Store tessellator domain
// (D3D11_SB_TESSELLATOR_DOMAIN enum) into a
// a tessellator domain declaration token (OpcodeToken0)
#define ENCODE_D3D11_SB_TESS_DOMAIN(Domain) (((Domain)<<D3D11_SB_TESS_DOMAIN_SHIFT)&D3D11_SB_TESS_DOMAIN_MASK)
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: Tessellator Partitioning
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_TESS_PARTITIONING
// [13:11] Partitioning
// [23:14] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
typedef enum D3D11_SB_TESSELLATOR_PARTITIONING
{
D3D11_SB_TESSELLATOR_PARTITIONING_UNDEFINED = 0,
D3D11_SB_TESSELLATOR_PARTITIONING_INTEGER = 1,
D3D11_SB_TESSELLATOR_PARTITIONING_POW2 = 2,
D3D11_SB_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
D3D11_SB_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4
} D3D11_SB_TESSELLATOR_PARTITIONING;
#define D3D11_SB_TESS_PARTITIONING_MASK 0x00003800
#define D3D11_SB_TESS_PARTITIONING_SHIFT 11
// DECODER MACRO: Given a tessellator partitioning declaration,
// (OpcodeToken0), determine the domain
// (D3D11_SB_TESSELLATOR_PARTITIONING enum)
#define DECODE_D3D11_SB_TESS_PARTITIONING(OpcodeToken0) ((D3D11_SB_TESSELLATOR_PARTITIONING)(((OpcodeToken0)&D3D11_SB_TESS_PARTITIONING_MASK)>>D3D11_SB_TESS_PARTITIONING_SHIFT))
// ENCODER MACRO: Store tessellator partitioning
// (D3D11_SB_TESSELLATOR_PARTITIONING enum) into a
// a tessellator partitioning declaration token (OpcodeToken0)
#define ENCODE_D3D11_SB_TESS_PARTITIONING(Partitioning) (((Partitioning)<<D3D11_SB_TESS_PARTITIONING_SHIFT)&D3D11_SB_TESS_PARTITIONING_MASK)
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: Tessellator Output Primitive
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE
// [13:11] Output Primitive
// [23:14] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token. == 1
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// ----------------------------------------------------------------------------
typedef enum D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE
{
D3D11_SB_TESSELLATOR_OUTPUT_UNDEFINED = 0,
D3D11_SB_TESSELLATOR_OUTPUT_POINT = 1,
D3D11_SB_TESSELLATOR_OUTPUT_LINE = 2,
D3D11_SB_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
D3D11_SB_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4
} D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE;
#define D3D11_SB_TESS_OUTPUT_PRIMITIVE_MASK 0x00003800
#define D3D11_SB_TESS_OUTPUT_PRIMITIVE_SHIFT 11
// DECODER MACRO: Given a tessellator output primitive declaration,
// (OpcodeToken0), determine the domain
// (D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE enum)
#define DECODE_D3D11_SB_TESS_OUTPUT_PRIMITIVE(OpcodeToken0) ((D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE)(((OpcodeToken0)&D3D11_SB_TESS_OUTPUT_PRIMITIVE_MASK)>>D3D11_SB_TESS_OUTPUT_PRIMITIVE_SHIFT))
// ENCODER MACRO: Store tessellator output primitive
// (D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE enum) into a
// a tessellator output primitive declaration token (OpcodeToken0)
#define ENCODE_D3D11_SB_TESS_OUTPUT_PRIMITIVE(OutputPrimitive) (((OutputPrimitive)<<D3D11_SB_TESS_OUTPUT_PRIMITIVE_SHIFT)&D3D11_SB_TESS_OUTPUT_PRIMITIVE_MASK)
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: Hull Shader Max Tessfactor
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_HS_MAX_TESSFACTOR
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by a float32 representing the
// maximum TessFactor.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Hull Shader Declaration Phase: Hull Shader Fork Phase Instance Count
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by a UINT32 representing the
// number of instances of the current fork phase program to execute.
//
// ----------------------------------------------------------------------------
typedef enum D3D10_SB_INTERPOLATION_MODE
{
D3D10_SB_INTERPOLATION_UNDEFINED = 0,
D3D10_SB_INTERPOLATION_CONSTANT = 1,
D3D10_SB_INTERPOLATION_LINEAR = 2,
D3D10_SB_INTERPOLATION_LINEAR_CENTROID = 3,
D3D10_SB_INTERPOLATION_LINEAR_NOPERSPECTIVE = 4,
D3D10_SB_INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5,
D3D10_SB_INTERPOLATION_LINEAR_SAMPLE = 6, // DX10.1
D3D10_SB_INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7, // DX10.1
} D3D10_SB_INTERPOLATION_MODE;
// Keep PRIMITIVE_TOPOLOGY values in sync with earlier DX versions (HW consumes values directly).
typedef enum D3D10_SB_PRIMITIVE_TOPOLOGY
{
D3D10_SB_PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
D3D10_SB_PRIMITIVE_TOPOLOGY_POINTLIST = 1,
D3D10_SB_PRIMITIVE_TOPOLOGY_LINELIST = 2,
D3D10_SB_PRIMITIVE_TOPOLOGY_LINESTRIP = 3,
D3D10_SB_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4,
D3D10_SB_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5,
// 6 is reserved for legacy triangle fans
// Adjacency values should be equal to (0x8 & non-adjacency):
D3D10_SB_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10,
D3D10_SB_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11,
D3D10_SB_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12,
D3D10_SB_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13,
} D3D10_SB_PRIMITIVE_TOPOLOGY;
typedef enum D3D10_SB_PRIMITIVE
{
D3D10_SB_PRIMITIVE_UNDEFINED = 0,
D3D10_SB_PRIMITIVE_POINT = 1,
D3D10_SB_PRIMITIVE_LINE = 2,
D3D10_SB_PRIMITIVE_TRIANGLE = 3,
// Adjacency values should be equal to (0x4 & non-adjacency):
D3D10_SB_PRIMITIVE_LINE_ADJ = 6,
D3D10_SB_PRIMITIVE_TRIANGLE_ADJ = 7,
D3D11_SB_PRIMITIVE_1_CONTROL_POINT_PATCH = 8,
D3D11_SB_PRIMITIVE_2_CONTROL_POINT_PATCH = 9,
D3D11_SB_PRIMITIVE_3_CONTROL_POINT_PATCH = 10,
D3D11_SB_PRIMITIVE_4_CONTROL_POINT_PATCH = 11,
D3D11_SB_PRIMITIVE_5_CONTROL_POINT_PATCH = 12,
D3D11_SB_PRIMITIVE_6_CONTROL_POINT_PATCH = 13,
D3D11_SB_PRIMITIVE_7_CONTROL_POINT_PATCH = 14,
D3D11_SB_PRIMITIVE_8_CONTROL_POINT_PATCH = 15,
D3D11_SB_PRIMITIVE_9_CONTROL_POINT_PATCH = 16,
D3D11_SB_PRIMITIVE_10_CONTROL_POINT_PATCH = 17,
D3D11_SB_PRIMITIVE_11_CONTROL_POINT_PATCH = 18,
D3D11_SB_PRIMITIVE_12_CONTROL_POINT_PATCH = 19,
D3D11_SB_PRIMITIVE_13_CONTROL_POINT_PATCH = 20,
D3D11_SB_PRIMITIVE_14_CONTROL_POINT_PATCH = 21,
D3D11_SB_PRIMITIVE_15_CONTROL_POINT_PATCH = 22,
D3D11_SB_PRIMITIVE_16_CONTROL_POINT_PATCH = 23,
D3D11_SB_PRIMITIVE_17_CONTROL_POINT_PATCH = 24,
D3D11_SB_PRIMITIVE_18_CONTROL_POINT_PATCH = 25,
D3D11_SB_PRIMITIVE_19_CONTROL_POINT_PATCH = 26,
D3D11_SB_PRIMITIVE_20_CONTROL_POINT_PATCH = 27,
D3D11_SB_PRIMITIVE_21_CONTROL_POINT_PATCH = 28,
D3D11_SB_PRIMITIVE_22_CONTROL_POINT_PATCH = 29,
D3D11_SB_PRIMITIVE_23_CONTROL_POINT_PATCH = 30,
D3D11_SB_PRIMITIVE_24_CONTROL_POINT_PATCH = 31,
D3D11_SB_PRIMITIVE_25_CONTROL_POINT_PATCH = 32,
D3D11_SB_PRIMITIVE_26_CONTROL_POINT_PATCH = 33,
D3D11_SB_PRIMITIVE_27_CONTROL_POINT_PATCH = 34,
D3D11_SB_PRIMITIVE_28_CONTROL_POINT_PATCH = 35,
D3D11_SB_PRIMITIVE_29_CONTROL_POINT_PATCH = 36,
D3D11_SB_PRIMITIVE_30_CONTROL_POINT_PATCH = 37,
D3D11_SB_PRIMITIVE_31_CONTROL_POINT_PATCH = 38,
D3D11_SB_PRIMITIVE_32_CONTROL_POINT_PATCH = 39,
} D3D10_SB_PRIMITIVE;
typedef enum D3D10_SB_COMPONENT_MASK
{
D3D10_SB_COMPONENT_MASK_X = 1,
D3D10_SB_COMPONENT_MASK_Y = 2,
D3D10_SB_COMPONENT_MASK_Z = 4,
D3D10_SB_COMPONENT_MASK_W = 8,
D3D10_SB_COMPONENT_MASK_R = 1,
D3D10_SB_COMPONENT_MASK_G = 2,
D3D10_SB_COMPONENT_MASK_B = 4,
D3D10_SB_COMPONENT_MASK_A = 8,
D3D10_SB_COMPONENT_MASK_ALL = 15,
} D3D10_SB_COMPONENT_MASK;
typedef enum D3D10_SB_NAME
{
D3D10_SB_NAME_UNDEFINED = 0,
D3D10_SB_NAME_POSITION = 1,
D3D10_SB_NAME_CLIP_DISTANCE = 2,
D3D10_SB_NAME_CULL_DISTANCE = 3,
D3D10_SB_NAME_RENDER_TARGET_ARRAY_INDEX = 4,
D3D10_SB_NAME_VIEWPORT_ARRAY_INDEX = 5,
D3D10_SB_NAME_VERTEX_ID = 6,
D3D10_SB_NAME_PRIMITIVE_ID = 7,
D3D10_SB_NAME_INSTANCE_ID = 8,
D3D10_SB_NAME_IS_FRONT_FACE = 9,
D3D10_SB_NAME_SAMPLE_INDEX = 10,
// The following are added for D3D11
D3D11_SB_NAME_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR = 11,
D3D11_SB_NAME_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR = 12,
D3D11_SB_NAME_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR = 13,
D3D11_SB_NAME_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR = 14,
D3D11_SB_NAME_FINAL_QUAD_U_INSIDE_TESSFACTOR = 15,
D3D11_SB_NAME_FINAL_QUAD_V_INSIDE_TESSFACTOR = 16,
D3D11_SB_NAME_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR = 17,
D3D11_SB_NAME_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR = 18,
D3D11_SB_NAME_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR = 19,
D3D11_SB_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 20,
D3D11_SB_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 21,
D3D11_SB_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 22,
// The following are added for D3D12
D3D12_SB_NAME_BARYCENTRICS = 23,
D3D12_SB_NAME_SHADINGRATE = 24,
D3D12_SB_NAME_CULLPRIMITIVE = 25,
} D3D10_SB_NAME;
typedef enum D3D10_SB_RESOURCE_DIMENSION
{
D3D10_SB_RESOURCE_DIMENSION_UNKNOWN = 0,
D3D10_SB_RESOURCE_DIMENSION_BUFFER = 1,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE1D = 2,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE2D = 3,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE2DMS = 4,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE3D = 5,
D3D10_SB_RESOURCE_DIMENSION_TEXTURECUBE = 6,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE1DARRAY = 7,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE2DARRAY = 8,
D3D10_SB_RESOURCE_DIMENSION_TEXTURE2DMSARRAY = 9,
D3D10_SB_RESOURCE_DIMENSION_TEXTURECUBEARRAY = 10,
D3D11_SB_RESOURCE_DIMENSION_RAW_BUFFER = 11,
D3D11_SB_RESOURCE_DIMENSION_STRUCTURED_BUFFER = 12,
} D3D10_SB_RESOURCE_DIMENSION;
typedef enum D3D10_SB_RESOURCE_RETURN_TYPE
{
D3D10_SB_RETURN_TYPE_UNORM = 1,
D3D10_SB_RETURN_TYPE_SNORM = 2,
D3D10_SB_RETURN_TYPE_SINT = 3,
D3D10_SB_RETURN_TYPE_UINT = 4,
D3D10_SB_RETURN_TYPE_FLOAT = 5,
D3D10_SB_RETURN_TYPE_MIXED = 6,
D3D11_SB_RETURN_TYPE_DOUBLE = 7,
D3D11_SB_RETURN_TYPE_CONTINUED = 8,
D3D11_SB_RETURN_TYPE_UNUSED = 9,
} D3D10_SB_RESOURCE_RETURN_TYPE;
typedef enum D3D10_SB_REGISTER_COMPONENT_TYPE
{
D3D10_SB_REGISTER_COMPONENT_UNKNOWN = 0,
D3D10_SB_REGISTER_COMPONENT_UINT32 = 1,
D3D10_SB_REGISTER_COMPONENT_SINT32 = 2,
D3D10_SB_REGISTER_COMPONENT_FLOAT32 = 3
} D3D10_SB_REGISTER_COMPONENT_TYPE;
typedef enum D3D10_SB_INSTRUCTION_RETURN_TYPE
{
D3D10_SB_INSTRUCTION_RETURN_FLOAT = 0,
D3D10_SB_INSTRUCTION_RETURN_UINT = 1
} D3D10_SB_INSTRUCTION_RETURN_TYPE;
#define D3D10_SB_INSTRUCTION_RETURN_TYPE_MASK 0x00001800
#define D3D10_SB_INSTRUCTION_RETURN_TYPE_SHIFT 11
// DECODER MACRO: For an OpcodeToken0 with the return type
// determine the return type.
#define DECODE_D3D10_SB_INSTRUCTION_RETURN_TYPE(OpcodeToken0) ((D3D10_SB_INSTRUCTION_RETURN_TYPE)(((OpcodeToken0)&D3D10_SB_INSTRUCTION_RETURN_TYPE_MASK)>>D3D10_SB_INSTRUCTION_RETURN_TYPE_SHIFT))
// ENCODER MACRO: Encode the return type for instructions
// in the opcode specific control range of OpcodeToken0
#define ENCODE_D3D10_SB_INSTRUCTION_RETURN_TYPE(ReturnType) (((ReturnType)<<D3D10_SB_INSTRUCTION_RETURN_TYPE_SHIFT)&D3D10_SB_INSTRUCTION_RETURN_TYPE_MASK)
// ----------------------------------------------------------------------------
// Interface function body Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_FUNCTION_BODY
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. If it is extended, then
// it contains the actual instruction length in DWORDs, since
// it may not fit into 7 bits if enough operands are defined.
//
// OpcodeToken0 is followed by a DWORD that represents the function body
// identifier.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Interface function table Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_FUNCTION_TABLE
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. If it is extended, then
// it contains the actual instruction length in DWORDs, since
// it may not fit into 7 bits if enough functions are defined.
//
// OpcodeToken0 is followed by a DWORD that represents the function table
// identifier and another DWORD (TableLength) that gives the number of
// functions in the table.
//
// This is followed by TableLength DWORDs which are function body indices.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Interface Declaration
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_DCL_INTERFACE
// [11] 1 if the interface is indexed dynamically, 0 otherwise.
// [23:12] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. If it is extended, then
// it contains the actual instruction length in DWORDs, since
// it may not fit into 7 bits if enough types are used.
//
// OpcodeToken0 is followed by a DWORD that represents the interface
// identifier. Next is a DWORD that gives the expected function table
// length. Then another DWORD (OpcodeToken3) with the following layout:
//
// [15:00] TableLength, the number of types that implement this interface
// [31:16] ArrayLength, the number of interfaces that are defined in this array.
//
// This is followed by TableLength DWORDs which are function table
// identifiers, representing possible tables for a given interface.
//
// ----------------------------------------------------------------------------
#define D3D11_SB_INTERFACE_INDEXED_BIT_MASK 0x00000800
#define D3D11_SB_INTERFACE_INDEXED_BIT_SHIFT 11
#define D3D11_SB_INTERFACE_TABLE_LENGTH_MASK 0x0000ffff
#define D3D11_SB_INTERFACE_TABLE_LENGTH_SHIFT 0
#define D3D11_SB_INTERFACE_ARRAY_LENGTH_MASK 0xffff0000
#define D3D11_SB_INTERFACE_ARRAY_LENGTH_SHIFT 16
// get/set the indexed bit for an interface definition
#define DECODE_D3D11_SB_INTERFACE_INDEXED_BIT(OpcodeToken0) ((((OpcodeToken0)&D3D11_SB_INTERFACE_INDEXED_BIT_MASK)>>D3D11_SB_INTERFACE_INDEXED_BIT_SHIFT) ? true : false)
#define ENCODE_D3D11_SB_INTERFACE_INDEXED_BIT(IndexedBit) (((IndexedBit)<<D3D11_SB_INTERFACE_INDEXED_BIT_SHIFT)&D3D11_SB_INTERFACE_INDEXED_BIT_MASK)
// get/set the table length for an interface definition
#define DECODE_D3D11_SB_INTERFACE_TABLE_LENGTH(OpcodeToken0) ((UINT)(((OpcodeToken0)&D3D11_SB_INTERFACE_TABLE_LENGTH_MASK)>>D3D11_SB_INTERFACE_TABLE_LENGTH_SHIFT))
#define ENCODE_D3D11_SB_INTERFACE_TABLE_LENGTH(TableLength) (((TableLength)<<D3D11_SB_INTERFACE_TABLE_LENGTH_SHIFT)&D3D11_SB_INTERFACE_TABLE_LENGTH_MASK)
// get/set the array length for an interface definition
#define DECODE_D3D11_SB_INTERFACE_ARRAY_LENGTH(OpcodeToken0) ((UINT)(((OpcodeToken0)&D3D11_SB_INTERFACE_ARRAY_LENGTH_MASK)>>D3D11_SB_INTERFACE_ARRAY_LENGTH_SHIFT))
#define ENCODE_D3D11_SB_INTERFACE_ARRAY_LENGTH(ArrayLength) (((ArrayLength)<<D3D11_SB_INTERFACE_ARRAY_LENGTH_SHIFT)&D3D11_SB_INTERFACE_ARRAY_LENGTH_MASK)
// ----------------------------------------------------------------------------
// Interface call
//
// OpcodeToken0:
//
// [10:00] D3D10_SB_OPCODE_INTERFACE_CALL
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. If it is extended, then
// it contains the actual instruction length in DWORDs, since
// it may not fit into 7 bits if enough types are used.
//
// OpcodeToken0 is followed by a DWORD that gives the function index to
// call in the function table specified for the given interface.
// Next is the interface operand.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Thread Group Declaration (Compute Shader)
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_THREAD_GROUP
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. If it is extended, then
// it contains the actual instruction length in DWORDs, since
// it may not fit into 7 bits if enough types are used.
//
// OpcodeToken0 is followed by 3 DWORDs, the Thread Group dimensions as UINT32:
// x, y, z
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Typed Unordered Access View Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED
// [15:11] D3D10_SB_RESOURCE_DIMENSION
// [16:16] D3D11_SB_GLOBALLY_COHERENT_ACCESS or 0 (LOCALLY_COHERENT)
// [17:17] D3D11_SB_RASTERIZER_ORDERED_ACCESS or 0
// [23:18] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands on Shader Models 4.0 through 5.0:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is being declared.
// (2) a Resource Return Type token (ResourceReturnTypeToken)
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (u<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of UAV's in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the u# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (u<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of uav within space (may be dynamically indexed)
// (2) a Resource Return Type token (ResourceReturnTypeToken)
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
// UAV access scope flags
#define D3D11_SB_GLOBALLY_COHERENT_ACCESS 0x00010000
#define D3D11_SB_ACCESS_COHERENCY_MASK 0x00010000
// DECODER MACRO: Retrieve flags for sync instruction from OpcodeToken0.
#define DECODE_D3D11_SB_ACCESS_COHERENCY_FLAGS(OperandToken0) ((OperandToken0)&D3D11_SB_ACCESS_COHERENCY_MASK)
// ENCODER MACRO: Given a set of sync instruciton flags, encode them in OpcodeToken0.
#define ENCODE_D3D11_SB_ACCESS_COHERENCY_FLAGS(Flags) ((Flags)&D3D11_SB_ACCESS_COHERENCY_MASK)
// Additional UAV access flags
#define D3D11_SB_RASTERIZER_ORDERED_ACCESS 0x00020000
// Resource flags mask. Use to retrieve all resource flags, including the order preserving counter.
#define D3D11_SB_RESOURCE_FLAGS_MASK (D3D11_SB_GLOBALLY_COHERENT_ACCESS|D3D11_SB_RASTERIZER_ORDERED_ACCESS|D3D11_SB_UAV_HAS_ORDER_PRESERVING_COUNTER)
// DECODER MACRO: Retrieve UAV access flags for from OpcodeToken0.
#define DECODE_D3D11_SB_RESOURCE_FLAGS(OperandToken0) ((OperandToken0)&D3D11_SB_RESOURCE_FLAGS_MASK)
// ENCODER MACRO: Given UAV access flags, encode them in OpcodeToken0.
#define ENCODE_D3D11_SB_RESOURCE_FLAGS(Flags) ((Flags)&D3D11_SB_RESOURCE_FLAGS_MASK)
// ----------------------------------------------------------------------------
// Raw Unordered Access View Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW
// [15:11] Ignored, 0
// [16:16] D3D11_SB_GLOBALLY_COHERENT_ACCESS or 0 (LOCALLY_COHERENT)
// [17:17] D3D11_SB_RASTERIZER_ORDERED_ACCESS or 0
// [23:18] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand on Shader Models 4.0 through 5.0:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is being declared.
//
// OpcodeToken0 is followed by 2 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (u<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of UAV's in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the u# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (u<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of uav within space (may be dynamically indexed)
// (2) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Structured Unordered Access View Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED
// [15:11] Ignored, 0
// [16:16] D3D11_SB_GLOBALLY_COHERENT_ACCESS or 0 (LOCALLY_COHERENT)
// [17:17] D3D11_SB_RASTERIZER_ORDERED_ACCESS or 0
// [22:18] Ignored, 0
// [23:23] D3D11_SB_UAV_HAS_ORDER_PRESERVING_COUNTER or 0
//
// The presence of this flag means that if a UAV is bound to the
// corresponding slot, it must have been created with
// D3D11_BUFFER_UAV_FLAG_COUNTER at the API. Also, the shader
// can contain either imm_atomic_alloc or _consume instructions
// operating on the given UAV.
//
// If this flag is not present, the shader can still contain
// either imm_atomic_alloc or imm_atomic_consume instructions for
// this UAV. But if such instructions are present in this case,
// and a UAV is bound corresponding slot, it must have been created
// with the D3D11_BUFFER_UAV_FLAG_APPEND flag at the API.
// Append buffers have a counter as well, but values returned
// to the shader are only valid for the lifetime of the shader
// invocation.
//
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is
// being declared.
// (2) a DWORD indicating UINT32 byte stride
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// u# register (D3D11_SB_OPERAND_TYPE_UNORDERED_ACCESS_VIEW) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (u<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of UAV's in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the u# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (u<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of uav within space (may be dynamically indexed)
// (2) a DWORD indicating UINT32 byte stride
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
// UAV flags
#define D3D11_SB_UAV_HAS_ORDER_PRESERVING_COUNTER 0x00800000
#define D3D11_SB_UAV_FLAGS_MASK 0x00800000
// DECODER MACRO: Retrieve flags about UAV from OpcodeToken0.
#define DECODE_D3D11_SB_UAV_FLAGS(OperandToken0) ((OperandToken0)&D3D11_SB_UAV_FLAGS_MASK)
// ENCODER MACRO: Given a set of UAV flags, encode them in OpcodeToken0.
#define ENCODE_D3D11_SB_UAV_FLAGS(Flags) ((Flags)&D3D11_SB_UAV_FLAGS_MASK)
// ----------------------------------------------------------------------------
// Raw Thread Group Shared Memory Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// g# register (D3D11_SB_OPERAND_TYPE_THREAD_GROUP_SHARED_MEMORY) is being declared.
// (2) a DWORD indicating the byte count, which must be a multiple of 4.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Structured Thread Group Shared Memory Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 3 operands:
// (1) an operand, starting with OperandToken0, defining which
// g# register (D3D11_SB_OPERAND_TYPE_THREAD_GROUP_SHARED_MEMORY) is
// being declared.
// (2) a DWORD indicating UINT32 struct byte stride
// (3) a DWORD indicating UINT32 struct count
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Raw Shader Resource View Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_RESOURCE_RAW
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 1 operand:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
//
// OpcodeToken0 is followed by 2 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (t<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of resources in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the t# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (t<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of resource within space (may be dynamically indexed)
// (2) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Structured Shader Resource View Declaration
//
// OpcodeToken0:
//
// [10:00] D3D11_SB_OPCODE_DCL_RESOURCE_STRUCTURED
// [23:11] Ignored, 0
// [30:24] Instruction length in DWORDs including the opcode token.
// [31] 0 normally. 1 if extended operand definition, meaning next DWORD
// contains extended operand description. This dcl is currently not
// extended.
//
// OpcodeToken0 is followed by 2 operands:
// (1) an operand, starting with OperandToken0, defining which
// g# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is
// being declared.
// (2) a DWORD indicating UINT32 struct byte stride
//
// OpcodeToken0 is followed by 3 operands on Shader Model 5.1 and later:
// (1) an operand, starting with OperandToken0, defining which
// t# register (D3D10_SB_OPERAND_TYPE_RESOURCE) is being declared.
// The indexing dimension for the register must be D3D10_SB_OPERAND_INDEX_DIMENSION_3D,
// and the meaning of the index dimensions are as follows: (t<id>[<lbound>:<ubound>])
// 1 <id>: variable ID being declared
// 2 <lbound>: the lower bound of the range of resources in the space
// 3 <ubound>: the upper bound (inclusive) of this range
// As opposed to when the t# is used in shader instructions, where the register
// must be D3D10_SB_OPERAND_INDEX_DIMENSION_2D, and the meaning of the index
// dimensions are as follows: (t<id>[<idx>]):
// 1 <id>: variable ID being used (matches dcl)
// 2 <idx>: absolute index of resource within space (may be dynamically indexed)
// (2) a DWORD indicating UINT32 struct byte stride
// (3) a DWORD indicating the space index.
//
// ----------------------------------------------------------------------------
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */
#pragma endregion
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/D3DReflection.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxReflection.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides the needed headers and defines for D3D reflection. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef _WIN32
#include "dxc/WinAdapter.h"
// need to disable this as it is voilated by this header
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
// Need to instruct non-windows compilers on what an interface is
#define interface struct
#include "d3d12shader.h"
#undef interface
#pragma GCC diagnostic pop
#else
#include <d3d12shader.h>
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/dxcapi.use.h | //////////////////////////////////////////////////////////////////////////////
// //
// dxcapi.use.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides support for DXC API users. //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef __DXCAPI_USE_H__
#define __DXCAPI_USE_H__
#include "dxc/dxcapi.h"
namespace dxc {
extern const char *kDxCompilerLib;
extern const char *kDxilLib;
// Helper class to dynamically load the dxcompiler or a compatible libraries.
class DxcDllSupport {
protected:
HMODULE m_dll;
DxcCreateInstanceProc m_createFn;
DxcCreateInstance2Proc m_createFn2;
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
if (m_dll != nullptr)
return S_OK;
#ifdef _WIN32
m_dll = LoadLibraryA(dllName);
if (m_dll == nullptr)
return HRESULT_FROM_WIN32(GetLastError());
m_createFn = (DxcCreateInstanceProc)GetProcAddress(m_dll, fnName);
if (m_createFn == nullptr) {
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
FreeLibrary(m_dll);
m_dll = nullptr;
return hr;
}
#else
m_dll = ::dlopen(dllName, RTLD_LAZY);
if (m_dll == nullptr)
return E_FAIL;
m_createFn = (DxcCreateInstanceProc)::dlsym(m_dll, fnName);
if (m_createFn == nullptr) {
::dlclose(m_dll);
m_dll = nullptr;
return E_FAIL;
}
#endif
// Only basic functions used to avoid requiring additional headers.
m_createFn2 = nullptr;
char fnName2[128];
size_t s = strlen(fnName);
if (s < sizeof(fnName2) - 2) {
memcpy(fnName2, fnName, s);
fnName2[s] = '2';
fnName2[s + 1] = '\0';
#ifdef _WIN32
m_createFn2 = (DxcCreateInstance2Proc)GetProcAddress(m_dll, fnName2);
#else
m_createFn2 = (DxcCreateInstance2Proc)::dlsym(m_dll, fnName2);
#endif
}
return S_OK;
}
public:
DxcDllSupport() : m_dll(nullptr), m_createFn(nullptr), m_createFn2(nullptr) {}
DxcDllSupport(DxcDllSupport &&other) {
m_dll = other.m_dll;
other.m_dll = nullptr;
m_createFn = other.m_createFn;
other.m_createFn = nullptr;
m_createFn2 = other.m_createFn2;
other.m_createFn2 = nullptr;
}
~DxcDllSupport() { Cleanup(); }
HRESULT Initialize() {
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
}
HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) {
return InitializeInternal(dll, entryPoint);
}
template <typename TInterface>
HRESULT CreateInstance(REFCLSID clsid, TInterface **pResult) {
return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult);
}
HRESULT CreateInstance(REFCLSID clsid, REFIID riid, IUnknown **pResult) {
if (pResult == nullptr)
return E_POINTER;
if (m_dll == nullptr)
return E_FAIL;
HRESULT hr = m_createFn(clsid, riid, (LPVOID *)pResult);
return hr;
}
template <typename TInterface>
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid,
TInterface **pResult) {
return CreateInstance2(pMalloc, clsid, __uuidof(TInterface),
(IUnknown **)pResult);
}
HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
IUnknown **pResult) {
if (pResult == nullptr)
return E_POINTER;
if (m_dll == nullptr)
return E_FAIL;
if (m_createFn2 == nullptr)
return E_FAIL;
HRESULT hr = m_createFn2(pMalloc, clsid, riid, (LPVOID *)pResult);
return hr;
}
bool HasCreateWithMalloc() const { return m_createFn2 != nullptr; }
bool IsEnabled() const { return m_dll != nullptr; }
void Cleanup() {
if (m_dll != nullptr) {
m_createFn = nullptr;
m_createFn2 = nullptr;
#ifdef _WIN32
FreeLibrary(m_dll);
#else
::dlclose(m_dll);
#endif
m_dll = nullptr;
}
}
HMODULE Detach() {
HMODULE hModule = m_dll;
m_dll = nullptr;
return hModule;
}
};
inline DxcDefine GetDefine(LPCWSTR name, LPCWSTR value) {
DxcDefine result;
result.Name = name;
result.Value = value;
return result;
}
// Checks an HRESULT and formats an error message with the appended data.
void IFT_Data(HRESULT hr, LPCWSTR data);
void EnsureEnabled(DxcDllSupport &dxcSupport);
void ReadFileIntoBlob(DxcDllSupport &dxcSupport, LPCWSTR pFileName,
IDxcBlobEncoding **ppBlobEncoding);
void WriteBlobToConsole(IDxcBlob *pBlob, DWORD streamType = STD_OUTPUT_HANDLE);
void WriteBlobToFile(IDxcBlob *pBlob, LPCWSTR pFileName, UINT32 textCodePage);
void WriteBlobToHandle(IDxcBlob *pBlob, HANDLE hFile, LPCWSTR pFileName,
UINT32 textCodePage);
void WriteUtf8ToConsole(const char *pText, int charCount,
DWORD streamType = STD_OUTPUT_HANDLE);
void WriteUtf8ToConsoleSizeT(const char *pText, size_t charCount,
DWORD streamType = STD_OUTPUT_HANDLE);
void WriteOperationErrorsToConsole(IDxcOperationResult *pResult,
bool outputWarnings);
void WriteOperationResultToConsole(IDxcOperationResult *pRewriteResult,
bool outputWarnings);
} // namespace dxc
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/FileIOHelper.h | ///////////////////////////////////////////////////////////////////////////////
// //
// FileIOHelper.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Provides utitlity functions to work with files. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "Global.h"
#include "dxc/Support/WinIncludes.h"
#ifndef _ATL_DECLSPEC_ALLOCATOR
#define _ATL_DECLSPEC_ALLOCATOR
#endif
// Forward declarations.
struct IDxcBlob;
struct IDxcBlobEncoding;
struct IDxcBlobUtf8;
struct IDxcBlobWide;
namespace hlsl {
IMalloc *GetGlobalHeapMalloc() throw();
class CDxcThreadMallocAllocator {
public:
_ATL_DECLSPEC_ALLOCATOR
static void *Reallocate(void *p, size_t nBytes) throw() {
return DxcGetThreadMallocNoRef()->Realloc(p, nBytes);
}
_ATL_DECLSPEC_ALLOCATOR
static void *Allocate(size_t nBytes) throw() {
return DxcGetThreadMallocNoRef()->Alloc(nBytes);
}
static void Free(void *p) throw() {
return DxcGetThreadMallocNoRef()->Free(p);
}
};
// Like CComHeapPtr, but with CDxcThreadMallocAllocator.
template <typename T>
class CDxcTMHeapPtr : public CHeapPtr<T, CDxcThreadMallocAllocator> {
public:
CDxcTMHeapPtr() throw() {}
explicit CDxcTMHeapPtr(T *pData) throw()
: CHeapPtr<T, CDxcThreadMallocAllocator>(pData) {}
};
// Like CComHeapPtr, but with a stateful allocator.
template <typename T> class CDxcMallocHeapPtr {
private:
CComPtr<IMalloc> m_pMalloc;
public:
T *m_pData;
CDxcMallocHeapPtr(IMalloc *pMalloc) throw()
: m_pMalloc(pMalloc), m_pData(nullptr) {}
~CDxcMallocHeapPtr() {
if (m_pData)
m_pMalloc->Free(m_pData);
}
operator T *() const throw() { return m_pData; }
IMalloc *GetMallocNoRef() const throw() { return m_pMalloc.p; }
bool Allocate(SIZE_T ElementCount) throw() {
ATLASSERT(m_pData == NULL);
SIZE_T nBytes = ElementCount * sizeof(T);
m_pData = static_cast<T *>(m_pMalloc->Alloc(nBytes));
if (m_pData == NULL)
return false;
return true;
}
void AllocateBytes(SIZE_T ByteCount) throw() {
if (m_pData)
m_pMalloc->Free(m_pData);
m_pData = static_cast<T *>(m_pMalloc->Alloc(ByteCount));
}
// Attach to an existing pointer (takes ownership)
void Attach(T *pData) throw() {
m_pMalloc->Free(m_pData);
m_pData = pData;
}
// Detach the pointer (releases ownership)
T *Detach() throw() {
T *pTemp = m_pData;
m_pData = NULL;
return pTemp;
}
// Free the memory pointed to, and set the pointer to NULL
void Free() throw() {
m_pMalloc->Free(m_pData);
m_pData = NULL;
}
};
HRESULT ReadBinaryFile(IMalloc *pMalloc, LPCWSTR pFileName, void **ppData,
DWORD *pDataSize) throw();
HRESULT ReadBinaryFile(LPCWSTR pFileName, void **ppData,
DWORD *pDataSize) throw();
HRESULT WriteBinaryFile(LPCWSTR pFileName, const void *pData,
DWORD DataSize) throw();
///////////////////////////////////////////////////////////////////////////////
// Blob and encoding manipulation functions.
UINT32 DxcCodePageFromBytes(const char *bytes, size_t byteLen) throw();
// More general create blob functions, used by other functions
// Null pMalloc means use current thread malloc.
// bPinned will point to existing memory without managing it;
// bCopy will copy to heap; bPinned and bCopy are mutually exclusive.
// If encodingKnown, UTF-8 or wide, and null-termination possible,
// an IDxcBlobUtf8 or IDxcBlobWide will be constructed.
// If text, it's best if size includes null terminator when not copying,
// otherwise IDxcBlobUtf8 or IDxcBlobWide will not be constructed.
HRESULT DxcCreateBlob(LPCVOID pPtr, SIZE_T size, bool bPinned, bool bCopy,
bool encodingKnown, UINT32 codePage, IMalloc *pMalloc,
IDxcBlobEncoding **ppBlobEncoding) throw();
// Create from blob references original blob.
// Pass nonzero for offset or length for sub-blob reference.
HRESULT
DxcCreateBlobEncodingFromBlob(IDxcBlob *pFromBlob, UINT32 offset, UINT32 length,
bool encodingKnown, UINT32 codePage,
IMalloc *pMalloc,
IDxcBlobEncoding **ppBlobEncoding) throw();
// Load files
HRESULT DxcCreateBlobFromFile(IMalloc *pMalloc, LPCWSTR pFileName,
UINT32 *pCodePage,
IDxcBlobEncoding **pBlobEncoding) throw();
HRESULT DxcCreateBlobFromFile(LPCWSTR pFileName, UINT32 *pCodePage,
IDxcBlobEncoding **ppBlobEncoding) throw();
// Given a blob, creates a subrange view.
HRESULT DxcCreateBlobFromBlob(IDxcBlob *pBlob, UINT32 offset, UINT32 length,
IDxcBlob **ppResult) throw();
// Creates a blob wrapping a buffer to be freed with the provided IMalloc
HRESULT
DxcCreateBlobOnMalloc(LPCVOID pData, IMalloc *pIMalloc, UINT32 size,
IDxcBlob **ppResult) throw();
// Creates a blob with a copy of the provided data
HRESULT
DxcCreateBlobOnHeapCopy(LPCVOID pData, UINT32 size,
IDxcBlob **ppResult) throw();
// Given a blob, creates a new instance with a specific code page set.
HRESULT
DxcCreateBlobWithEncodingSet(IDxcBlob *pBlob, UINT32 codePage,
IDxcBlobEncoding **ppBlobEncoding) throw();
HRESULT
DxcCreateBlobWithEncodingSet(IMalloc *pMalloc, IDxcBlob *pBlob, UINT32 codePage,
IDxcBlobEncoding **ppBlobEncoding) throw();
// Creates a blob around encoded text without ownership transfer
HRESULT
DxcCreateBlobWithEncodingFromPinned(LPCVOID pText, UINT32 size, UINT32 codePage,
IDxcBlobEncoding **pBlobEncoding) throw();
HRESULT DxcCreateBlobFromPinned(LPCVOID pText, UINT32 size,
IDxcBlob **pBlob) throw();
HRESULT
DxcCreateBlobWithEncodingFromStream(IStream *pStream, bool newInstanceAlways,
UINT32 codePage,
IDxcBlobEncoding **pBlobEncoding) throw();
// Creates a blob with a copy of the encoded text
HRESULT
DxcCreateBlobWithEncodingOnHeapCopy(LPCVOID pText, UINT32 size, UINT32 codePage,
IDxcBlobEncoding **pBlobEncoding) throw();
// Creates a blob wrapping encoded text to be freed with the provided IMalloc
HRESULT
DxcCreateBlobWithEncodingOnMalloc(LPCVOID pText, IMalloc *pIMalloc, UINT32 size,
UINT32 codePage,
IDxcBlobEncoding **pBlobEncoding) throw();
// Creates a blob with a copy of encoded text, allocated using the provided
// IMalloc
HRESULT
DxcCreateBlobWithEncodingOnMallocCopy(IMalloc *pIMalloc, LPCVOID pText,
UINT32 size, UINT32 codePage,
IDxcBlobEncoding **pBlobEncoding) throw();
HRESULT DxcGetBlobAsUtf8(IDxcBlob *pBlob, IMalloc *pMalloc,
IDxcBlobUtf8 **pBlobEncoding,
UINT32 defaultCodePage = CP_ACP) throw();
HRESULT
DxcGetBlobAsWide(IDxcBlob *pBlob, IMalloc *pMalloc,
IDxcBlobWide **pBlobEncoding) throw();
bool IsBlobNullOrEmpty(IDxcBlob *pBlob) throw();
///////////////////////////////////////////////////////////////////////////////
// Stream implementations.
class AbstractMemoryStream : public IStream {
public:
virtual LPBYTE GetPtr() throw() = 0;
virtual ULONG GetPtrSize() throw() = 0;
virtual LPBYTE Detach() throw() = 0;
virtual UINT64 GetPosition() throw() = 0;
virtual HRESULT Reserve(ULONG targetSize) throw() = 0;
};
HRESULT CreateMemoryStream(IMalloc *pMalloc,
AbstractMemoryStream **ppResult) throw();
HRESULT CreateReadOnlyBlobStream(IDxcBlob *pSource, IStream **ppResult) throw();
HRESULT CreateFixedSizeMemoryStream(LPBYTE pBuffer, size_t size,
AbstractMemoryStream **ppResult) throw();
template <typename T>
HRESULT WriteStreamValue(IStream *pStream, const T &value) {
ULONG cb;
return pStream->Write(&value, sizeof(value), &cb);
}
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/HLSLVersion.h | ///////////////////////////////////////////////////////////////////////////////
// //
// HLSLOptions.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// HLSL version enumeration and parsing support //
// //
///////////////////////////////////////////////////////////////////////////////
#ifndef LLVM_HLSL_HLSLVERSION_H
#define LLVM_HLSL_HLSLVERSION_H
#include "llvm/ADT/StringRef.h"
namespace hlsl {
// This Updates to this enum must be reflected in HLSLOptions.td and Options.td
// for the hlsl_version option.
enum class LangStd : unsigned long {
vUnset = 0,
vError = 1,
v2015 = 2015,
v2016 = 2016,
v2017 = 2017,
v2018 = 2018,
v2021 = 2021,
v202x = 2029,
vLatest = v2021
};
constexpr const char *ValidVersionsStr = "2015, 2016, 2017, 2018, and 2021";
LangStd parseHLSLVersion(llvm::StringRef Ver);
} // namespace hlsl
#endif // LLVM_HLSL_HLSLVERSION_H
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/Support/DxcOptToggles.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxcOptToggles.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Helper code for representing -opt-disable, -opt-enable, -opt-select //
// options //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef LLVM_HLSL_DXC_OPT_TOGGLES_H
#define LLVM_HLSL_DXC_OPT_TOGGLES_H
#include "llvm/ADT/StringRef.h"
#include <map>
#include <set>
#include <string>
namespace hlsl {
namespace options {
struct Toggle {
llvm::StringRef Name;
bool Default = false;
Toggle(llvm::StringRef Name, bool Default) : Name(Name), Default(Default) {}
};
enum {
DEFAULT_ON = 1,
DEFAULT_OFF = 0,
};
static const Toggle TOGGLE_GVN = {"gvn", DEFAULT_ON};
static const Toggle TOGGLE_LICM = {"licm", DEFAULT_ON};
static const Toggle TOGGLE_SINK = {"sink", DEFAULT_ON};
static const Toggle TOGGLE_ENABLE_AGGRESSIVE_REASSOCIATION = {
"aggressive-reassociation", DEFAULT_ON};
static const Toggle TOGGLE_LIFETIME_MARKERS = {"lifetime-markers", DEFAULT_ON};
static const Toggle TOGGLE_PARTIAL_LIFETIME_MARKERS = {
"partial-lifetime-markers", DEFAULT_OFF};
static const Toggle TOGGLE_STRUCTURIZE_LOOP_EXITS_FOR_UNROLL = {
"structurize-loop-exits-for-unroll", DEFAULT_ON};
static const Toggle TOGGLE_DEBUG_NOPS = {"debug-nops", DEFAULT_ON};
static const Toggle TOGGLE_STRUCTURIZE_RETURNS = {"structurize-returns",
DEFAULT_OFF};
struct OptimizationToggles {
// Optimization pass enables, disables and selects
std::map<std::string, bool> Toggles; // OPT_opt_enable & OPT_opt_disable
std::map<std::string, std::string> Selects; // OPT_opt_select
void Set(Toggle Opt, bool Value) { Toggles[Opt.Name] = Value; }
bool IsSet(Toggle Opt) const {
return Toggles.find(Opt.Name) != Toggles.end();
}
bool IsEnabled(Toggle Opt) const {
auto It = Toggles.find(Opt.Name);
const bool Found = It != Toggles.end();
if (Found)
return It->second;
return Opt.Default;
}
};
} // namespace options
} // namespace hlsl
#endif
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilInterpolationMode.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilInterpolationMode.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL interpolation mode. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
namespace hlsl {
/// Use this class to represent signature element interpolation mode.
class InterpolationMode {
public:
using Kind = DXIL::InterpolationMode;
InterpolationMode();
InterpolationMode(const InterpolationMode &Mode) = default;
InterpolationMode(Kind Kind);
InterpolationMode(unsigned long long Kind);
InterpolationMode(bool bNoInterpolation, bool bLinear, bool bNoperspective,
bool bCentroid, bool bSample);
InterpolationMode &operator=(const InterpolationMode &o);
bool operator==(const InterpolationMode &o) const;
bool IsValid() const {
return m_Kind >= Kind::Undefined && m_Kind < Kind::Invalid;
}
bool IsUndefined() const { return m_Kind == Kind::Undefined; }
bool IsConstant() const { return m_Kind == Kind::Constant; }
bool IsLinear() const { return m_Kind == Kind::Linear; }
bool IsLinearCentroid() const { return m_Kind == Kind::LinearCentroid; }
bool IsLinearNoperspective() const {
return m_Kind == Kind::LinearNoperspective;
}
bool IsLinearNoperspectiveCentroid() const {
return m_Kind == Kind::LinearNoperspectiveCentroid;
}
bool IsLinearSample() const { return m_Kind == Kind::LinearSample; }
bool IsLinearNoperspectiveSample() const {
return m_Kind == Kind::LinearNoperspectiveSample;
}
bool IsAnyLinear() const;
bool IsAnyNoPerspective() const;
bool IsAnyCentroid() const;
bool IsAnySample() const;
Kind GetKind() const { return m_Kind; }
const char *GetName() const;
private:
Kind m_Kind;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilShaderFlags.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilShaderFlags.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Shader flags for a dxil shader function. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <stdint.h>
namespace hlsl {
class DxilModule;
struct DxilFunctionProps;
}
namespace llvm {
class Function;
}
namespace hlsl {
// Shader properties.
class ShaderFlags {
public:
ShaderFlags();
static ShaderFlags CollectShaderFlags(const llvm::Function *F,
const hlsl::DxilModule *M);
unsigned GetGlobalFlags() const;
uint64_t GetFeatureInfo() const;
static uint64_t
GetShaderFlagsRawForCollection(); // some flags are collected (eg use 64-bit),
// some provided (eg allow refactoring)
uint64_t GetShaderFlagsRaw() const;
void SetShaderFlagsRaw(uint64_t data);
void CombineShaderFlags(const ShaderFlags &other);
void ClearLocalFlags();
void SetDisableOptimizations(bool flag) { m_bDisableOptimizations = flag; }
bool GetDisableOptimizations() const { return m_bDisableOptimizations; }
void SetDisableMathRefactoring(bool flag) {
m_bDisableMathRefactoring = flag;
}
bool GetDisableMathRefactoring() const { return m_bDisableMathRefactoring; }
void SetEnableDoublePrecision(bool flag) { m_bEnableDoublePrecision = flag; }
bool GetEnableDoublePrecision() const { return m_bEnableDoublePrecision; }
void SetForceEarlyDepthStencil(bool flag) {
m_bForceEarlyDepthStencil = flag;
}
bool GetForceEarlyDepthStencil() const { return m_bForceEarlyDepthStencil; }
void SetEnableRawAndStructuredBuffers(bool flag) {
m_bEnableRawAndStructuredBuffers = flag;
}
bool GetEnableRawAndStructuredBuffers() const {
return m_bEnableRawAndStructuredBuffers;
}
void SetLowPrecisionPresent(bool flag) { m_bLowPrecisionPresent = flag; }
bool GetLowPrecisionPresent() const { return m_bLowPrecisionPresent; }
void SetEnableDoubleExtensions(bool flag) {
m_bEnableDoubleExtensions = flag;
}
bool GetEnableDoubleExtensions() const { return m_bEnableDoubleExtensions; }
void SetEnableMSAD(bool flag) { m_bEnableMSAD = flag; }
bool GetEnableMSAD() const { return m_bEnableMSAD; }
void SetAllResourcesBound(bool flag) { m_bAllResourcesBound = flag; }
bool GetAllResourcesBound() const { return m_bAllResourcesBound; }
void SetCSRawAndStructuredViaShader4X(bool flag) {
m_bCSRawAndStructuredViaShader4X = flag;
}
bool GetCSRawAndStructuredViaShader4X() const {
return m_bCSRawAndStructuredViaShader4X;
}
void SetROVs(bool flag) { m_bROVS = flag; }
bool GetROVs() const { return m_bROVS; }
void SetWaveOps(bool flag) { m_bWaveOps = flag; }
bool GetWaveOps() const { return m_bWaveOps; }
void SetInt64Ops(bool flag) { m_bInt64Ops = flag; }
bool GetInt64Ops() const { return m_bInt64Ops; }
void SetTiledResources(bool flag) { m_bTiledResources = flag; }
bool GetTiledResources() const { return m_bTiledResources; }
void SetStencilRef(bool flag) { m_bStencilRef = flag; }
bool GetStencilRef() const { return m_bStencilRef; }
void SetInnerCoverage(bool flag) { m_bInnerCoverage = flag; }
bool GetInnerCoverage() const { return m_bInnerCoverage; }
void SetViewportAndRTArrayIndex(bool flag) {
m_bViewportAndRTArrayIndex = flag;
}
bool GetViewportAndRTArrayIndex() const { return m_bViewportAndRTArrayIndex; }
void SetUAVLoadAdditionalFormats(bool flag) {
m_bUAVLoadAdditionalFormats = flag;
}
bool GetUAVLoadAdditionalFormats() const {
return m_bUAVLoadAdditionalFormats;
}
void SetLevel9ComparisonFiltering(bool flag) {
m_bLevel9ComparisonFiltering = flag;
}
bool GetLevel9ComparisonFiltering() const {
return m_bLevel9ComparisonFiltering;
}
void Set64UAVs(bool flag) { m_b64UAVs = flag; }
bool Get64UAVs() const { return m_b64UAVs; }
void SetUAVsAtEveryStage(bool flag) { m_UAVsAtEveryStage = flag; }
bool GetUAVsAtEveryStage() const { return m_UAVsAtEveryStage; }
// SM 6.1+
void SetViewID(bool flag) { m_bViewID = flag; }
bool GetViewID() const { return m_bViewID; }
void SetBarycentrics(bool flag) { m_bBarycentrics = flag; }
bool GetBarycentrics() const { return m_bBarycentrics; }
// SM 6.2+
void SetUseNativeLowPrecision(bool flag) { m_bUseNativeLowPrecision = flag; }
bool GetUseNativeLowPrecision() const { return m_bUseNativeLowPrecision; }
// SM 6.4+
void SetShadingRate(bool flag) { m_bShadingRate = flag; }
bool GetShadingRate() const { return m_bShadingRate; }
// SM 6.5+
void SetRaytracingTier1_1(bool flag) { m_bRaytracingTier1_1 = flag; }
bool GetRaytracingTier1_1() const { return m_bRaytracingTier1_1; }
void SetSamplerFeedback(bool flag) { m_bSamplerFeedback = flag; }
bool GetSamplerFeedback() const { return m_bSamplerFeedback; }
// SM 6.6+
void SetAtomicInt64OnTypedResource(bool flag) {
m_bAtomicInt64OnTypedResource = flag;
}
bool GetAtomicInt64OnTypedResource() const {
return m_bAtomicInt64OnTypedResource;
}
void SetAtomicInt64OnGroupShared(bool flag) {
m_bAtomicInt64OnGroupShared = flag;
}
bool GetAtomicInt64OnGroupShared() const {
return m_bAtomicInt64OnGroupShared;
}
void SetDerivativesInMeshAndAmpShaders(bool flag) {
m_bDerivativesInMeshAndAmpShaders = flag;
}
bool GetDerivativesInMeshAndAmpShaders() const {
return m_bDerivativesInMeshAndAmpShaders;
}
void SetAtomicInt64OnHeapResource(bool flag) {
m_bAtomicInt64OnHeapResource = flag;
}
bool GetAtomicInt64OnHeapResource() const {
return m_bAtomicInt64OnHeapResource;
}
void SetResourceDescriptorHeapIndexing(bool flag) {
m_bResourceDescriptorHeapIndexing = flag;
}
bool GetResourceDescriptorHeapIndexing() const {
return m_bResourceDescriptorHeapIndexing;
}
void SetSamplerDescriptorHeapIndexing(bool flag) {
m_bSamplerDescriptorHeapIndexing = flag;
}
bool GetSamplerDescriptorHeapIndexing() const {
return m_bSamplerDescriptorHeapIndexing;
}
// SM 6.7+
void SetResMayNotAlias(bool flag) { m_bResMayNotAlias = flag; }
bool GetResMayNotAlias() const { return m_bResMayNotAlias; }
void SetAdvancedTextureOps(bool flag) { m_bAdvancedTextureOps = flag; }
bool GetAdvancedTextureOps() const { return m_bAdvancedTextureOps; }
void SetWriteableMSAATextures(bool flag) { m_bWriteableMSAATextures = flag; }
bool GetWriteableMSAATextures() const { return m_bWriteableMSAATextures; }
// SM 6.8+
void SetSampleCmpGradientOrBias(bool flag) {
m_bSampleCmpGradientOrBias = flag;
}
bool GetSampleCmpGradientOrBias() const { return m_bSampleCmpGradientOrBias; }
void SetExtendedCommandInfo(bool flag) { m_bExtendedCommandInfo = flag; }
bool GetExtendedCommandInfo() const { return m_bExtendedCommandInfo; }
// Per-function flags
void SetUsesDerivatives(bool flag) { m_bUsesDerivatives = flag; }
bool GetUsesDerivatives() const { return m_bUsesDerivatives; }
void SetRequiresGroup(bool flag) { m_bRequiresGroup = flag; }
bool GetRequiresGroup() const { return m_bRequiresGroup; }
private:
// Bit: 0
unsigned
m_bDisableOptimizations : 1; // D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION
unsigned
m_bDisableMathRefactoring : 1; //~D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED
unsigned
m_bEnableDoublePrecision : 1; // D3D11_SB_GLOBAL_FLAG_ENABLE_DOUBLE_PRECISION_FLOAT_OPS
unsigned
m_bForceEarlyDepthStencil : 1; // D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL
// Bit: 4
unsigned
m_bEnableRawAndStructuredBuffers : 1; // D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
unsigned
m_bLowPrecisionPresent : 1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION
unsigned
m_bEnableDoubleExtensions : 1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_DOUBLE_EXTENSIONS
unsigned m_bEnableMSAD : 1; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_SHADER_EXTENSIONS
// Bit: 8
unsigned m_bAllResourcesBound : 1; // D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND
unsigned
m_bViewportAndRTArrayIndex : 1; // SHADER_FEATURE_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER
unsigned m_bInnerCoverage : 1; // SHADER_FEATURE_INNER_COVERAGE
unsigned m_bStencilRef : 1; // SHADER_FEATURE_STENCIL_REF
// Bit: 12
unsigned m_bTiledResources : 1; // SHADER_FEATURE_TILED_RESOURCES
unsigned
m_bUAVLoadAdditionalFormats : 1; // SHADER_FEATURE_TYPED_UAV_LOAD_ADDITIONAL_FORMATS
unsigned
m_bLevel9ComparisonFiltering : 1; // SHADER_FEATURE_LEVEL_9_COMPARISON_FILTERING
// SHADER_FEATURE_11_1_SHADER_EXTENSIONS
// shared with EnableMSAD
unsigned m_b64UAVs : 1; // SHADER_FEATURE_64_UAVS
// Bit: 16
unsigned m_UAVsAtEveryStage : 1; // SHADER_FEATURE_UAVS_AT_EVERY_STAGE
unsigned
m_bCSRawAndStructuredViaShader4X : 1; // SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X
// SHADER_FEATURE_COMPUTE_SHADERS_PLUS_RAW_AND_STRUCTURED_BUFFERS_VIA_SHADER_4_X
// is specifically about shader model 4.x.
// Bit: 18
unsigned m_bROVS : 1; // SHADER_FEATURE_ROVS
unsigned m_bWaveOps : 1; // SHADER_FEATURE_WAVE_OPS
// Bit: 20
unsigned m_bInt64Ops : 1; // SHADER_FEATURE_INT64_OPS
// SM 6.1+
unsigned m_bViewID : 1; // SHADER_FEATURE_VIEWID
unsigned m_bBarycentrics : 1; // SHADER_FEATURE_BARYCENTRICS
// SM 6.2+
unsigned m_bUseNativeLowPrecision : 1;
// SM 6.4+
// Bit: 24
unsigned m_bShadingRate : 1; // SHADER_FEATURE_SHADINGRATE
// SM 6.5+
// Bit: 25
unsigned m_bRaytracingTier1_1 : 1; // SHADER_FEATURE_RAYTRACING_TIER_1_1
unsigned m_bSamplerFeedback : 1; // SHADER_FEATURE_SAMPLER_FEEDBACK
// SM 6.6+
// Bit: 27
unsigned
m_bAtomicInt64OnTypedResource : 1; // SHADER_FEATURE_ATOMIC_INT64_ON_TYPED_RESOURCE
unsigned
m_bAtomicInt64OnGroupShared : 1; // SHADER_FEATURE_ATOMIC_INT64_ON_GROUP_SHARED
// Bit: 29
unsigned
m_bDerivativesInMeshAndAmpShaders : 1; // SHADER_FEATURE_DERIVATIVES_IN_MESH_AND_AMPLIFICATION_SHADERS
// Bit: 30
unsigned
m_bResourceDescriptorHeapIndexing : 1; // SHADER_FEATURE_RESOURCE_DESCRIPTOR_HEAP_INDEXING
unsigned
m_bSamplerDescriptorHeapIndexing : 1; // SHADER_FEATURE_SAMPLER_DESCRIPTOR_HEAP_INDEXING
// Bit: 32
unsigned
m_bAtomicInt64OnHeapResource : 1; // SHADER_FEATURE_ATOMIC_INT64_ON_DESCRIPTOR_HEAP_RESOURCE
// SM 6.7+
// Global flag indicating that any UAV may not alias any other UAV.
// Set if UAVs are used, unless -res-may-alias was specified.
// For modules compiled against validator version < 1.7, this flag will be
// cleared, and it must be assumed that UAV resources may alias.
// Bit: 33
unsigned m_bResMayNotAlias : 1;
// Bit: 34
unsigned m_bAdvancedTextureOps : 1; // SHADER_FEATURE_ADVANCED_TEXTURE_OPS
unsigned
m_bWriteableMSAATextures : 1; // SHADER_FEATURE_WRITEABLE_MSAA_TEXTURES
// Experimental SM 6.9+ - Reserved, not yet supported.
// Bit: 36
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-private-field"
#endif
unsigned m_bReserved : 1; // SHADER_FEATURE_RESERVED
#ifdef __clang__
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
// SM 6.8+
// Bit: 37
unsigned
m_bSampleCmpGradientOrBias : 1; // SHADER_FEATURE_SAMPLE_CMP_GRADIENT_OR_BIAS
unsigned m_bExtendedCommandInfo : 1; // SHADER_FEATURE_EXTENDED_COMMAND_INFO
// Per-function flags
// Bit: 39
unsigned m_bUsesDerivatives : 1; // SHADER_FEATURE_OPT_USES_DERIVATIVES
// (OptFeatureInfo_UsesDerivatives)
// m_bRequiresGroup indicates that the function requires a visible group.
// For instance, to access group shared memory or use group sync.
// This is necessary because shader stage is insufficient to indicate group
// availability with the advent of thread launch node shaders.
// Bit: 40
unsigned m_bRequiresGroup : 1; // SHADER_FEATURE_OPT_REQUIRES_GROUP
// (OptFeatureInfo_RequiresGroup)
uint32_t m_align1 : 23; // align to 64 bit.
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilUtil.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilUtil.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// DXIL helper functions. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <memory>
#include <string>
#include <unordered_set>
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/IRBuilder.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilResourceProperties.h"
namespace llvm {
class Type;
class GlobalVariable;
class Function;
class Module;
class MemoryBuffer;
class LLVMContext;
class DiagnosticInfo;
class Value;
class Instruction;
class CallInst;
class BasicBlock;
class raw_ostream;
class ModulePass;
class PassRegistry;
class DebugInfoFinder;
class DebugLoc;
class DIGlobalVariable;
class ConstantInt;
class SwitchInst;
class GEPOperator;
ModulePass *createDxilLoadMetadataPass();
void initializeDxilLoadMetadataPass(llvm::PassRegistry &);
} // namespace llvm
namespace hlsl {
class DxilFieldAnnotation;
class DxilModule;
class DxilTypeSystem;
class OP;
namespace dxilutil {
extern const char ManglingPrefix[];
extern const char EntryPrefix[];
extern const char *kResourceMapErrorMsg;
unsigned GetLegacyCBufferFieldElementSize(DxilFieldAnnotation &fieldAnnotation,
llvm::Type *Ty,
DxilTypeSystem &typeSys);
llvm::Type *GetArrayEltTy(llvm::Type *Ty);
bool HasDynamicIndexing(llvm::Value *V);
// Cleans up unnecessary chains of GEPs and bitcasts left over from certain
// optimizations. This function is NOT safe to call while iterating
// instructions either forward or backward. If V happens to be a GEP or
// bitcast, the function may delete V, instructions preceding V it, and
// instructions following V.
bool MergeGepUse(llvm::Value *V);
// Find alloca insertion point, given instruction
llvm::Instruction *
FindAllocaInsertionPt(llvm::Instruction *I); // Considers entire parent function
llvm::Instruction *
FindAllocaInsertionPt(llvm::BasicBlock *BB); // Only considers provided block
llvm::Instruction *FindAllocaInsertionPt(llvm::Function *F);
llvm::Instruction *SkipAllocas(llvm::Instruction *I);
// Get first non-alloca insertion point, to avoid inserting non-allocas before
// alloca
llvm::Instruction *FirstNonAllocaInsertionPt(
llvm::Instruction *I); // Considers entire parent function
llvm::Instruction *FirstNonAllocaInsertionPt(
llvm::BasicBlock *BB); // Only considers provided block
llvm::Instruction *FirstNonAllocaInsertionPt(llvm::Function *F);
bool IsStaticGlobal(llvm::GlobalVariable *GV);
bool IsSharedMemoryGlobal(llvm::GlobalVariable *GV);
bool RemoveUnusedFunctions(llvm::Module &M, llvm::Function *EntryFunc,
llvm::Function *PatchConstantFunc, bool IsLib);
llvm::DIGlobalVariable *
FindGlobalVariableDebugInfo(llvm::GlobalVariable *GV,
llvm::DebugInfoFinder &DbgInfoFinder);
void EmitErrorOnInstruction(llvm::Instruction *I, llvm::Twine Msg);
void EmitWarningOnInstruction(llvm::Instruction *I, llvm::Twine Msg);
void EmitErrorOnFunction(llvm::LLVMContext &Ctx, llvm::Function *F,
llvm::Twine Msg);
void EmitWarningOnFunction(llvm::LLVMContext &Ctx, llvm::Function *F,
llvm::Twine Msg);
void EmitErrorOnGlobalVariable(llvm::LLVMContext &Ctx, llvm::GlobalVariable *GV,
llvm::Twine Msg);
void EmitWarningOnGlobalVariable(llvm::LLVMContext &Ctx,
llvm::GlobalVariable *GV, llvm::Twine Msg);
void EmitErrorOnContext(llvm::LLVMContext &Ctx, llvm::Twine Msg);
void EmitWarningOnContext(llvm::LLVMContext &Ctx, llvm::Twine Msg);
void EmitNoteOnContext(llvm::LLVMContext &Ctx, llvm::Twine Msg);
void EmitResMappingError(llvm::Instruction *Res);
// Simple demangle just support case "\01?name@" pattern.
llvm::StringRef DemangleFunctionName(llvm::StringRef name);
// ReplaceFunctionName replaces the undecorated portion of originalName with
// undecorated newName
std::string ReplaceFunctionName(llvm::StringRef originalName,
llvm::StringRef newName);
void PrintEscapedString(llvm::StringRef Name, llvm::raw_ostream &Out);
void PrintUnescapedString(llvm::StringRef Name, llvm::raw_ostream &Out);
// Change select/phi on operands into select/phi on operation.
// phi0 = phi a0, b0, c0
// phi1 = phi a1, b1, c1
// Inst = Add(phi0, phi1);
// into
// A = Add(a0, a1);
// B = Add(b0, b1);
// C = Add(c0, c1);
// NewInst = phi A, B, C
// Only support 1 operand now, other oerands should be Constant.
llvm::Value *SelectOnOperation(llvm::Instruction *Inst, unsigned operandIdx);
// Collect all select operand used by Inst.
void CollectSelect(llvm::Instruction *Inst,
std::unordered_set<llvm::Instruction *> &selectSet);
// If all operands are the same for a select inst, replace it with the operand.
// Returns replacement value if successful
llvm::Value *MergeSelectOnSameValue(llvm::Instruction *SelInst,
unsigned startOpIdx, unsigned numOperands);
bool SimplifyTrivialPHIs(llvm::BasicBlock *BB);
llvm::BasicBlock *GetSwitchSuccessorForCond(llvm::SwitchInst *Switch,
llvm::ConstantInt *Cond);
void MigrateDebugValue(llvm::Value *Old, llvm::Value *New);
void TryScatterDebugValueToVectorElements(llvm::Value *Val);
std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::StringRef BC,
llvm::LLVMContext &Ctx,
std::string &DiagStr);
std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::MemoryBuffer *MB,
llvm::LLVMContext &Ctx,
std::string &DiagStr);
std::unique_ptr<llvm::Module>
LoadModuleFromBitcodeLazy(std::unique_ptr<llvm::MemoryBuffer> &&MB,
llvm::LLVMContext &Ctx, std::string &DiagStr);
void PrintDiagnosticHandler(const llvm::DiagnosticInfo &DI, void *Context);
bool IsIntegerOrFloatingPointType(llvm::Type *Ty);
// Returns true if type contains HLSL Object type (resource)
bool ContainsHLSLObjectType(llvm::Type *Ty);
std::pair<bool, DxilResourceProperties>
GetHLSLResourceProperties(llvm::Type *Ty);
bool IsHLSLResourceType(llvm::Type *Ty);
bool IsHLSLObjectType(llvm::Type *Ty);
bool IsHLSLRayQueryType(llvm::Type *Ty);
bool IsHLSLResourceDescType(llvm::Type *Ty);
bool IsResourceSingleComponent(llvm::Type *Ty);
uint8_t GetResourceComponentCount(llvm::Type *Ty);
bool IsSplat(llvm::ConstantDataVector *cdv);
bool IsHLSLNodeIOType(llvm::Type *Ty);
bool IsHLSLNodeOutputType(llvm::Type *Ty);
bool IsHLSLNodeOutputArrayType(llvm::Type *Ty);
bool IsHLSLEmptyNodeOutputType(llvm::Type *Ty);
bool IsHLSLEmptyNodeOutputArrayType(llvm::Type *Ty);
bool IsHLSLNodeInputRecordType(llvm::Type *Ty);
bool IsHLSLRWNodeInputRecordType(llvm::Type *Ty);
bool IsHLSLNodeOutputRecordType(llvm::Type *Ty);
bool IsHLSLGSNodeOutputRecordType(llvm::Type *Ty);
bool IsHLSLNodeRecordType(llvm::Type *Ty);
bool IsHLSLNodeInputOutputType(llvm::Type *Ty);
llvm::Type *
StripArrayTypes(llvm::Type *Ty,
llvm::SmallVectorImpl<unsigned> *OuterToInnerLengths = nullptr);
llvm::Type *WrapInArrayTypes(llvm::Type *Ty,
llvm::ArrayRef<unsigned> OuterToInnerLengths);
llvm::Value *MirrorGEP(llvm::GEPOperator *GEP, llvm::Value *NewBasePtr);
llvm::CallInst *TranslateCallRawBufferLoadToBufferLoad(
llvm::CallInst *CI, llvm::Function *newFunction, hlsl::OP *op);
void ReplaceRawBufferLoadWithBufferLoad(llvm::Function *F, hlsl::OP *op);
llvm::CallInst *TranslateCallRawBufferStoreToBufferStore(
llvm::CallInst *CI, llvm::Function *newFunction, hlsl::OP *op);
void ReplaceRawBufferStoreWithBufferStore(llvm::Function *F, hlsl::OP *op);
void ReplaceRawBufferLoad64Bit(llvm::Function *F, llvm::Type *EltTy,
hlsl::OP *hlslOP);
void ReplaceRawBufferStore64Bit(llvm::Function *F, llvm::Type *ETy,
hlsl::OP *hlslOP);
bool IsConvergentMarker(llvm::Value *V);
llvm::Value *GetConvergentSource(llvm::Value *V);
/// If value is a bitcast to base class pattern, equivalent
/// to a getelementptr X, 0, 0, 0... turn it into the appropriate gep.
/// This can enhance SROA and other transforms that want type-safe pointers,
/// and enables merging with other getelementptr's.
llvm::Value *TryReplaceBaseCastWithGep(llvm::Value *V);
bool FunctionHasNoSideEffects(llvm::Instruction *I);
llvm::Value::user_iterator mdv_users_end(llvm::Value *V);
llvm::Value::user_iterator mdv_users_begin(llvm::Value *V);
inline bool mdv_user_empty(llvm::Value *V) {
return mdv_users_begin(V) == mdv_users_end(V);
}
/// Finds all allocas that only have stores and delete them.
/// These allocas hold on to values that do not contribute to the
/// shader's results.
bool DeleteDeadAllocas(llvm::Function &F);
llvm::Value *GEPIdxToOffset(llvm::GetElementPtrInst *GEP,
llvm::IRBuilder<> &Builder, hlsl::OP *OP,
const llvm::DataLayout &DL);
} // namespace dxilutil
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSubobject.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSubobject.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Defines Subobject types for DxilModule. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include <map>
#include <memory>
#include <unordered_map>
#include <vector>
namespace hlsl {
class DxilSubobjects;
namespace RDAT {
class DxilRuntimeData;
}
class DxilSubobject {
public:
using Kind = DXIL::SubobjectKind;
DxilSubobject() = delete;
DxilSubobject(const DxilSubobject &other) = delete;
DxilSubobject(DxilSubobject &&other);
~DxilSubobject();
DxilSubobject &operator=(const DxilSubobject &other) = delete;
Kind GetKind() const { return m_Kind; }
llvm::StringRef GetName() const { return m_Name; }
// Note: strings and root signature data is owned by DxilModule
// When creating subobjects, use canonical strings from module
bool GetStateObjectConfig(uint32_t &Flags) const;
bool GetRootSignature(bool local, const void *&Data, uint32_t &Size,
const char **pText = nullptr) const;
bool GetSubobjectToExportsAssociation(llvm::StringRef &Subobject,
const char *const *&Exports,
uint32_t &NumExports) const;
bool GetRaytracingShaderConfig(uint32_t &MaxPayloadSizeInBytes,
uint32_t &MaxAttributeSizeInBytes) const;
bool GetRaytracingPipelineConfig(uint32_t &MaxTraceRecursionDepth) const;
bool GetRaytracingPipelineConfig1(uint32_t &MaxTraceRecursionDepth,
uint32_t &Flags) const;
bool GetHitGroup(DXIL::HitGroupType &hitGroupType, llvm::StringRef &AnyHit,
llvm::StringRef &ClosestHit,
llvm::StringRef &Intersection) const;
private:
DxilSubobject(DxilSubobjects &owner, Kind kind, llvm::StringRef name);
DxilSubobject(DxilSubobjects &owner, const DxilSubobject &other,
llvm::StringRef name);
void CopyUnionedContents(const DxilSubobject &other);
void InternStrings();
DxilSubobjects &m_Owner;
Kind m_Kind;
llvm::StringRef m_Name;
std::vector<const char *> m_Exports;
struct StateObjectConfig_t {
uint32_t Flags; // DXIL::StateObjectFlags
};
struct RootSignature_t {
uint32_t Size;
const void *Data;
const char *Text; // can be null
};
struct SubobjectToExportsAssociation_t {
const char *Subobject;
// see m_Exports for export list
};
struct RaytracingShaderConfig_t {
uint32_t MaxPayloadSizeInBytes;
uint32_t MaxAttributeSizeInBytes;
};
struct RaytracingPipelineConfig_t {
uint32_t MaxTraceRecursionDepth;
};
struct RaytracingPipelineConfig1_t {
uint32_t MaxTraceRecursionDepth;
uint32_t Flags; // DXIL::RaytracingPipelineFlags
};
struct HitGroup_t {
DXIL::HitGroupType Type;
const char *AnyHit;
const char *ClosestHit;
const char *Intersection;
};
union {
StateObjectConfig_t StateObjectConfig;
RootSignature_t RootSignature;
SubobjectToExportsAssociation_t SubobjectToExportsAssociation;
RaytracingShaderConfig_t RaytracingShaderConfig;
RaytracingPipelineConfig_t RaytracingPipelineConfig;
HitGroup_t HitGroup;
RaytracingPipelineConfig1_t RaytracingPipelineConfig1;
};
friend class DxilSubobjects;
};
class DxilSubobjects {
public:
typedef std::pair<std::unique_ptr<char[]>, size_t> StoredBytes;
typedef llvm::MapVector<llvm::StringRef, StoredBytes> BytesStorage;
typedef llvm::MapVector<llvm::StringRef, std::unique_ptr<DxilSubobject>>
SubobjectStorage;
using Kind = DXIL::SubobjectKind;
DxilSubobjects();
DxilSubobjects(const DxilSubobjects &other) = delete;
DxilSubobjects(DxilSubobjects &&other);
~DxilSubobjects();
DxilSubobjects &operator=(const DxilSubobjects &other) = delete;
// Add/find string in owned subobject strings, returning canonical ptr
llvm::StringRef InternString(llvm::StringRef value);
// Add/find raw bytes, returning canonical ptr
const void *InternRawBytes(const void *ptr, size_t size);
DxilSubobject *FindSubobject(llvm::StringRef name);
void RemoveSubobject(llvm::StringRef name);
DxilSubobject &CloneSubobject(const DxilSubobject &Subobject,
llvm::StringRef Name);
const SubobjectStorage &GetSubobjects() const { return m_Subobjects; }
// Create DxilSubobjects
DxilSubobject &CreateStateObjectConfig(llvm::StringRef Name, uint32_t Flags);
// Local/Global RootSignature
DxilSubobject &CreateRootSignature(llvm::StringRef Name, bool local,
const void *Data, uint32_t Size,
llvm::StringRef *pText = nullptr);
DxilSubobject &CreateSubobjectToExportsAssociation(llvm::StringRef Name,
llvm::StringRef Subobject,
llvm::StringRef *Exports,
uint32_t NumExports);
DxilSubobject &CreateRaytracingShaderConfig(llvm::StringRef Name,
uint32_t MaxPayloadSizeInBytes,
uint32_t MaxAttributeSizeInBytes);
DxilSubobject &
CreateRaytracingPipelineConfig(llvm::StringRef Name,
uint32_t MaxTraceRecursionDepth);
DxilSubobject &CreateRaytracingPipelineConfig1(
llvm::StringRef Name, uint32_t MaxTraceRecursionDepth, uint32_t Flags);
DxilSubobject &CreateHitGroup(llvm::StringRef Name,
DXIL::HitGroupType hitGroupType,
llvm::StringRef AnyHit,
llvm::StringRef ClosestHit,
llvm::StringRef Intersection);
private:
DxilSubobject &CreateSubobject(Kind kind, llvm::StringRef Name);
BytesStorage m_BytesStorage;
SubobjectStorage m_Subobjects;
};
bool LoadSubobjectsFromRDAT(DxilSubobjects &subobjects,
const RDAT::DxilRuntimeData &rdat);
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSampler.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSampler.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL sampler state. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilResourceBase.h"
namespace hlsl {
/// Use this class to represent HLSL sampler state.
class DxilSampler : public DxilResourceBase {
public:
using SamplerKind = DXIL::SamplerKind;
DxilSampler();
SamplerKind GetSamplerKind() const;
bool IsCompSampler() const;
void SetSamplerKind(SamplerKind K);
private:
SamplerKind m_SamplerKind; // Sampler mode.
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DXIL.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DXIL.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Main public header for DXIL. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilCBuffer.h"
#include "dxc/DXIL/DxilCompType.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilInterpolationMode.h"
#include "dxc/DXIL/DxilModule.h"
#include "dxc/DXIL/DxilNodeProps.h"
#include "dxc/DXIL/DxilOperations.h"
#include "dxc/DXIL/DxilResource.h"
#include "dxc/DXIL/DxilSampler.h"
#include "dxc/DXIL/DxilSemantic.h"
#include "dxc/DXIL/DxilShaderModel.h"
#include "dxc/DXIL/DxilSignatureElement.h"
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilFunctionProps.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilFunctionProps.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Function properties for a dxil shader function. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
// for memset dependency:
#include <cstring>
#include <vector>
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilNodeProps.h"
#include "llvm/ADT/StringRef.h"
namespace llvm {
class Function;
class Constant;
} // namespace llvm
namespace hlsl {
// SM 6.6 allows WaveSize specification for only a single required size.
// SM 6.8+ allows specification of WaveSize as a min, max and preferred value.
struct DxilWaveSize {
unsigned Min = 0;
unsigned Max = 0;
unsigned Preferred = 0;
DxilWaveSize() = default;
DxilWaveSize(unsigned min, unsigned max = 0, unsigned preferred = 0)
: Min(min), Max(max), Preferred(preferred) {}
DxilWaveSize(const DxilWaveSize &other) = default;
DxilWaveSize &operator=(const DxilWaveSize &other) = default;
bool operator==(const DxilWaveSize &other) const {
return Min == other.Min && Max == other.Max && Preferred == other.Preferred;
}
// Create DxilWaveSize, translating potential degenerate cases.
static DxilWaveSize Translate(unsigned min, unsigned max = 0,
unsigned preferred = 0) {
if (max == min)
max = 0;
if (max == 0 && preferred == min)
preferred = 0;
return DxilWaveSize(min, max, preferred);
}
// Valid non-zero values are powers of 2 between 4 and 128, inclusive.
static bool IsValidValue(unsigned Value) {
return (Value >= 4 && Value <= 128 && ((Value & (Value - 1)) == 0));
}
// Valid representations:
// (not to be confused with encodings in metadata, PSV0, or RDAT)
// 0, 0, 0: Not defined
// Min, 0, 0: single WaveSize (SM 6.6/6.7)
// (single WaveSize is represented in metadata with the single Min value)
// Min, Max (> Min), 0 or Preferred (>= Min and <= Max): Range (SM 6.8+)
// (WaveSizeRange represenation in metadata is the same)
enum class ValidationResult {
Success,
InvalidMin,
InvalidMax,
InvalidPreferred,
MaxOrPreferredWhenUndefined,
PreferredWhenNoRange,
MaxEqualsMin,
MaxLessThanMin,
PreferredOutOfRange,
NoRangeOrMin,
};
ValidationResult Validate() const {
if (Min == 0) { // Not defined
if (Max != 0 || Preferred != 0)
return ValidationResult::MaxOrPreferredWhenUndefined;
else
// all 3 parameters are 0
return ValidationResult::NoRangeOrMin;
} else if (!IsValidValue(Min)) {
return ValidationResult::InvalidMin;
} else if (Max == 0) { // single WaveSize (SM 6.6/6.7)
if (Preferred != 0)
return ValidationResult::PreferredWhenNoRange;
} else if (!IsValidValue(Max)) {
return ValidationResult::InvalidMax;
} else if (Min == Max) {
return ValidationResult::MaxEqualsMin;
} else if (Max < Min) {
return ValidationResult::MaxLessThanMin;
} else if (Preferred != 0) {
if (!IsValidValue(Preferred))
return ValidationResult::InvalidPreferred;
if (Preferred < Min || Preferred > Max)
return ValidationResult::PreferredOutOfRange;
}
return ValidationResult::Success;
}
bool IsValid() const { return Validate() == ValidationResult::Success; }
bool IsDefined() const { return Min != 0; }
bool IsRange() const { return Max != 0; }
bool HasPreferred() const { return Preferred != 0; }
};
struct DxilFunctionProps {
DxilFunctionProps() {
memset(&ShaderProps, 0, sizeof(ShaderProps));
shaderKind = DXIL::ShaderKind::Invalid;
NodeShaderID = {};
NodeShaderSharedInput = {};
memset(&Node, 0, sizeof(Node));
Node.LaunchType = DXIL::NodeLaunchType::Invalid;
Node.LocalRootArgumentsTableIndex = -1;
}
union {
// Geometry shader.
struct {
DXIL::InputPrimitive inputPrimitive;
unsigned maxVertexCount;
unsigned instanceCount;
DXIL::PrimitiveTopology
streamPrimitiveTopologies[DXIL::kNumOutputStreams];
} GS;
// Hull shader.
struct {
llvm::Function *patchConstantFunc;
DXIL::TessellatorDomain domain;
DXIL::TessellatorPartitioning partition;
DXIL::TessellatorOutputPrimitive outputPrimitive;
unsigned inputControlPoints;
unsigned outputControlPoints;
float maxTessFactor;
} HS;
// Domain shader.
struct {
DXIL::TessellatorDomain domain;
unsigned inputControlPoints;
} DS;
// Vertex shader.
struct {
llvm::Constant *clipPlanes[DXIL::kNumClipPlanes];
} VS;
// Pixel shader.
struct {
bool EarlyDepthStencil;
} PS;
// Ray Tracing shaders
struct {
union {
unsigned payloadSizeInBytes;
unsigned paramSizeInBytes;
};
unsigned attributeSizeInBytes;
} Ray;
// Mesh shader.
struct {
unsigned maxVertexCount;
unsigned maxPrimitiveCount;
DXIL::MeshOutputTopology outputTopology;
unsigned payloadSizeInBytes;
} MS;
// Amplification shader.
struct {
unsigned payloadSizeInBytes;
} AS;
} ShaderProps;
// numThreads shared between multiple shader types and node shaders.
unsigned numThreads[3];
struct NodeProps {
DXIL::NodeLaunchType LaunchType = DXIL::NodeLaunchType::Invalid;
bool IsProgramEntry;
int LocalRootArgumentsTableIndex;
unsigned DispatchGrid[3];
unsigned MaxDispatchGrid[3];
unsigned MaxRecursionDepth;
} Node;
DXIL::ShaderKind shaderKind;
NodeID NodeShaderID;
NodeID NodeShaderSharedInput;
std::vector<NodeIOProperties> InputNodes;
std::vector<NodeIOProperties> OutputNodes;
DxilWaveSize WaveSize;
// Save root signature for lib profile entry.
std::vector<uint8_t> serializedRootSignature;
void SetSerializedRootSignature(const uint8_t *pData, unsigned size) {
serializedRootSignature.assign(pData, pData + size);
}
// TODO: Should we have an unmangled name here for ray tracing shaders?
bool IsPS() const { return shaderKind == DXIL::ShaderKind::Pixel; }
bool IsVS() const { return shaderKind == DXIL::ShaderKind::Vertex; }
bool IsGS() const { return shaderKind == DXIL::ShaderKind::Geometry; }
bool IsHS() const { return shaderKind == DXIL::ShaderKind::Hull; }
bool IsDS() const { return shaderKind == DXIL::ShaderKind::Domain; }
bool IsCS() const { return shaderKind == DXIL::ShaderKind::Compute; }
bool IsGraphics() const {
return (shaderKind >= DXIL::ShaderKind::Pixel &&
shaderKind <= DXIL::ShaderKind::Domain) ||
shaderKind == DXIL::ShaderKind::Mesh ||
shaderKind == DXIL::ShaderKind::Amplification;
}
bool IsRayGeneration() const {
return shaderKind == DXIL::ShaderKind::RayGeneration;
}
bool IsIntersection() const {
return shaderKind == DXIL::ShaderKind::Intersection;
}
bool IsAnyHit() const { return shaderKind == DXIL::ShaderKind::AnyHit; }
bool IsClosestHit() const {
return shaderKind == DXIL::ShaderKind::ClosestHit;
}
bool IsMiss() const { return shaderKind == DXIL::ShaderKind::Miss; }
bool IsCallable() const { return shaderKind == DXIL::ShaderKind::Callable; }
bool IsRay() const {
return (shaderKind >= DXIL::ShaderKind::RayGeneration &&
shaderKind <= DXIL::ShaderKind::Callable);
}
bool IsMS() const { return shaderKind == DXIL::ShaderKind::Mesh; }
bool IsAS() const { return shaderKind == DXIL::ShaderKind::Amplification; }
bool IsNode() const {
return shaderKind == DXIL::ShaderKind::Node ||
Node.LaunchType != DXIL::NodeLaunchType::Invalid;
};
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilTypeSystem.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilTypeSystem.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// DXIL extension to LLVM type system. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilCompType.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilInterpolationMode.h"
#include "dxc/DXIL/DxilResourceProperties.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include <memory>
#include <string>
#include <vector>
namespace llvm {
class LLVMContext;
class Module;
class Function;
class MDNode;
class Type;
class StructType;
} // namespace llvm
namespace hlsl {
enum class MatrixOrientation {
Undefined = 0,
RowMajor,
ColumnMajor,
LastEntry
};
struct DxilMatrixAnnotation {
unsigned Rows;
unsigned Cols;
MatrixOrientation Orientation;
DxilMatrixAnnotation();
};
/// Use this class to represent type annotation for structure field.
class DxilFieldAnnotation {
public:
DxilFieldAnnotation();
bool IsPrecise() const;
void SetPrecise(bool b = true);
bool HasMatrixAnnotation() const;
const DxilMatrixAnnotation &GetMatrixAnnotation() const;
void SetMatrixAnnotation(const DxilMatrixAnnotation &MA);
unsigned GetVectorSize() const;
void SetVectorSize(unsigned size);
// Currently, ResourceProperties is only used to capture resource type
// information during CodeGen for the annotate handle generated during
// AddOpcodeParamForIntrinsic.
bool HasResourceProperties() const;
const DxilResourceProperties &GetResourceProperties() const;
void SetResourceProperties(const DxilResourceProperties &RP);
bool HasCBufferOffset() const;
unsigned GetCBufferOffset() const;
void SetCBufferOffset(unsigned Offset);
bool HasCompType() const;
const CompType &GetCompType() const;
void SetCompType(CompType::Kind kind);
bool HasSemanticString() const;
const std::string &GetSemanticString() const;
llvm::StringRef GetSemanticStringRef() const;
void SetSemanticString(const std::string &SemString);
bool HasInterpolationMode() const;
const InterpolationMode &GetInterpolationMode() const;
void SetInterpolationMode(const InterpolationMode &IM);
bool HasFieldName() const;
const std::string &GetFieldName() const;
void SetFieldName(const std::string &FieldName);
bool IsCBVarUsed() const;
void SetCBVarUsed(bool used);
bool HasBitFields() const;
const std::vector<DxilFieldAnnotation> &GetBitFields() const;
void SetBitFields(const std::vector<DxilFieldAnnotation> &Fields);
bool HasBitFieldWidth() const;
unsigned GetBitFieldWidth() const;
void SetBitFieldWidth(const unsigned BitWidth);
private:
bool m_bPrecise;
CompType m_CompType;
DxilMatrixAnnotation m_Matrix;
DxilResourceProperties m_ResourceProps;
unsigned m_CBufferOffset;
std::string m_Semantic;
InterpolationMode m_InterpMode;
std::string m_FieldName;
bool m_bCBufferVarUsed; // true if this field represents a top level variable
// in CB structure, and it is used.
std::vector<DxilFieldAnnotation> m_BitFields;
unsigned m_BitFieldWidth; // For bit field. 0 means not bitfield.
unsigned m_VectorSize;
};
class DxilTemplateArgAnnotation {
public:
DxilTemplateArgAnnotation();
bool IsType() const;
const llvm::Type *GetType() const;
void SetType(const llvm::Type *pType);
bool IsIntegral() const;
int64_t GetIntegral() const;
void SetIntegral(int64_t i64);
private:
const llvm::Type *m_Type;
int64_t m_Integral;
};
/// Use this class to represent LLVM structure annotation.
class DxilStructAnnotation {
friend class DxilTypeSystem;
public:
unsigned GetNumFields() const;
DxilFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx);
const DxilFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx) const;
const llvm::StructType *GetStructType() const;
void SetStructType(const llvm::StructType *Ty);
unsigned GetCBufferSize() const;
void SetCBufferSize(unsigned size);
void MarkEmptyStruct();
bool IsEmptyStruct();
// Since resources don't take real space, IsEmptyBesidesResources
// determines if the structure is empty or contains only resources.
bool IsEmptyBesidesResources();
bool ContainsResources() const;
// For template args, GetNumTemplateArgs() will return 0 if not a template
unsigned GetNumTemplateArgs() const;
void SetNumTemplateArgs(unsigned count);
DxilTemplateArgAnnotation &GetTemplateArgAnnotation(unsigned argIdx);
const DxilTemplateArgAnnotation &
GetTemplateArgAnnotation(unsigned argIdx) const;
private:
const llvm::StructType *m_pStructType = nullptr;
std::vector<DxilFieldAnnotation> m_FieldAnnotations;
unsigned m_CBufferSize = 0; // The size of struct if inside constant buffer.
std::vector<DxilTemplateArgAnnotation> m_TemplateAnnotations;
// m_ResourcesContained property not stored to metadata
void SetContainsResources();
// HasResources::Only will be set on MarkEmptyStruct() when HasResources::True
enum class HasResources {
True,
False,
Only
} m_ResourcesContained = HasResources::False;
};
/// Use this class to represent type annotation for DXR payload field.
class DxilPayloadFieldAnnotation {
public:
static unsigned
GetBitOffsetForShaderStage(DXIL::PayloadAccessShaderStage shaderStage);
DxilPayloadFieldAnnotation() = default;
bool HasCompType() const;
const CompType &GetCompType() const;
void SetCompType(CompType::Kind kind);
uint32_t GetPayloadFieldQualifierMask() const;
void SetPayloadFieldQualifierMask(uint32_t fieldBitmask);
void AddPayloadFieldQualifier(DXIL::PayloadAccessShaderStage shaderStage,
DXIL::PayloadAccessQualifier qualifier);
DXIL::PayloadAccessQualifier
GetPayloadFieldQualifier(DXIL::PayloadAccessShaderStage shaderStage) const;
bool HasAnnotations() const;
private:
CompType m_CompType;
unsigned m_bitmask = 0;
};
/// Use this class to represent DXR payload structures.
class DxilPayloadAnnotation {
friend class DxilTypeSystem;
public:
unsigned GetNumFields() const;
DxilPayloadFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx);
const DxilPayloadFieldAnnotation &GetFieldAnnotation(unsigned FieldIdx) const;
const llvm::StructType *GetStructType() const;
void SetStructType(const llvm::StructType *Ty);
private:
const llvm::StructType *m_pStructType;
std::vector<DxilPayloadFieldAnnotation> m_FieldAnnotations;
};
enum class DxilParamInputQual {
In,
Out,
Inout,
InputPatch,
OutputPatch,
OutStream0,
OutStream1,
OutStream2,
OutStream3,
InputPrimitive,
OutIndices,
OutVertices,
OutPrimitives,
InPayload,
NodeIO
};
/// Use this class to represent type annotation for function parameter.
class DxilParameterAnnotation : public DxilFieldAnnotation {
public:
DxilParameterAnnotation();
DxilParamInputQual GetParamInputQual() const;
void SetParamInputQual(DxilParamInputQual qual);
const std::vector<unsigned> &GetSemanticIndexVec() const;
void SetSemanticIndexVec(const std::vector<unsigned> &Vec);
void AppendSemanticIndex(unsigned SemIdx);
bool IsParamInputQualNode();
private:
DxilParamInputQual m_inputQual;
std::vector<unsigned> m_semanticIndex;
};
/// Use this class to represent LLVM function annotation.
class DxilFunctionAnnotation {
friend class DxilTypeSystem;
public:
unsigned GetNumParameters() const;
DxilParameterAnnotation &GetParameterAnnotation(unsigned ParamIdx);
const DxilParameterAnnotation &
GetParameterAnnotation(unsigned ParamIdx) const;
const llvm::Function *GetFunction() const;
DxilParameterAnnotation &GetRetTypeAnnotation();
const DxilParameterAnnotation &GetRetTypeAnnotation() const;
bool ContainsResourceArgs() { return m_bContainsResourceArgs; }
private:
const llvm::Function *m_pFunction;
std::vector<DxilParameterAnnotation> m_parameterAnnotations;
DxilParameterAnnotation m_retTypeAnnotation;
// m_bContainsResourceArgs property not stored to metadata
void SetContainsResourceArgs() { m_bContainsResourceArgs = true; }
bool m_bContainsResourceArgs = false;
};
/// Use this class to represent structure type annotations in HL and DXIL.
class DxilTypeSystem {
public:
using StructAnnotationMap =
llvm::MapVector<const llvm::StructType *,
std::unique_ptr<DxilStructAnnotation>>;
using PayloadAnnotationMap =
llvm::MapVector<const llvm::StructType *,
std::unique_ptr<DxilPayloadAnnotation>>;
using FunctionAnnotationMap =
llvm::MapVector<const llvm::Function *,
std::unique_ptr<DxilFunctionAnnotation>>;
DxilTypeSystem(llvm::Module *pModule);
DxilStructAnnotation *AddStructAnnotation(const llvm::StructType *pStructType,
unsigned numTemplateArgs = 0);
void FinishStructAnnotation(DxilStructAnnotation &SA);
DxilStructAnnotation *
GetStructAnnotation(const llvm::StructType *pStructType);
const DxilStructAnnotation *
GetStructAnnotation(const llvm::StructType *pStructType) const;
void EraseStructAnnotation(const llvm::StructType *pStructType);
void EraseUnusedStructAnnotations();
StructAnnotationMap &GetStructAnnotationMap();
const StructAnnotationMap &GetStructAnnotationMap() const;
DxilPayloadAnnotation *
AddPayloadAnnotation(const llvm::StructType *pStructType);
DxilPayloadAnnotation *
GetPayloadAnnotation(const llvm::StructType *pStructType);
const DxilPayloadAnnotation *
GetPayloadAnnotation(const llvm::StructType *pStructType) const;
void ErasePayloadAnnotation(const llvm::StructType *pStructType);
PayloadAnnotationMap &GetPayloadAnnotationMap();
const PayloadAnnotationMap &GetPayloadAnnotationMap() const;
DxilFunctionAnnotation *
AddFunctionAnnotation(const llvm::Function *pFunction);
void FinishFunctionAnnotation(DxilFunctionAnnotation &FA);
DxilFunctionAnnotation *
GetFunctionAnnotation(const llvm::Function *pFunction);
const DxilFunctionAnnotation *
GetFunctionAnnotation(const llvm::Function *pFunction) const;
void EraseFunctionAnnotation(const llvm::Function *pFunction);
FunctionAnnotationMap &GetFunctionAnnotationMap();
// Utility methods to create stand-alone SNORM and UNORM.
// We may want to move them to a more centralized place for most utilities.
llvm::StructType *GetSNormF32Type(unsigned NumComps);
llvm::StructType *GetUNormF32Type(unsigned NumComps);
// Methods to copy annotation from another DxilTypeSystem.
void CopyTypeAnnotation(const llvm::Type *Ty, const DxilTypeSystem &src);
void CopyFunctionAnnotation(const llvm::Function *pDstFunction,
const llvm::Function *pSrcFunction,
const DxilTypeSystem &src);
bool UseMinPrecision();
void SetMinPrecision(bool bMinPrecision);
// Determines whether type is a resource or contains a resource
bool IsResourceContained(llvm::Type *Ty);
private:
llvm::Module *m_pModule;
StructAnnotationMap m_StructAnnotations;
PayloadAnnotationMap m_PayloadAnnotations;
FunctionAnnotationMap m_FunctionAnnotations;
DXIL::LowPrecisionMode m_LowPrecisionMode;
llvm::StructType *GetNormFloatType(CompType CT, unsigned NumComps);
};
DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q,
DXIL::ShaderKind SK, bool isPC);
void RemapObsoleteSemantic(DxilParameterAnnotation ¶mInfo,
DXIL::SigPointKind sigPoint,
llvm::LLVMContext &Context);
class DxilStructTypeIterator {
private:
llvm::StructType *STy;
DxilStructAnnotation *SAnnotation;
unsigned index;
public:
using iterator_category = std::input_iterator_tag;
using value_type = std::pair<llvm::Type *, DxilFieldAnnotation *>;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
using reference = value_type &;
DxilStructTypeIterator(llvm::StructType *sTy,
DxilStructAnnotation *sAnnotation, unsigned idx = 0);
// prefix
DxilStructTypeIterator &operator++();
// postfix
DxilStructTypeIterator operator++(int);
bool operator==(DxilStructTypeIterator iter);
bool operator!=(DxilStructTypeIterator iter);
std::pair<llvm::Type *, DxilFieldAnnotation *> operator*();
};
DxilStructTypeIterator begin(llvm::StructType *STy,
DxilStructAnnotation *SAnno);
DxilStructTypeIterator end(llvm::StructType *STy, DxilStructAnnotation *SAnno);
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSemantic.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSemantic.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL parameter semantics. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "llvm/ADT/StringRef.h"
#include "DxilConstants.h"
#include "DxilShaderModel.h"
namespace hlsl {
/// Use this class to represent HLSL parameter semantic.
class Semantic {
public:
using Kind = DXIL::SemanticKind;
static const int kUndefinedRow = -1;
static const int kUndefinedCol = -1;
static const Semantic *GetByName(llvm::StringRef name);
static const Semantic *
GetByName(llvm::StringRef Name, DXIL::SigPointKind sigPointKind,
unsigned MajorVersion = ShaderModel::kHighestMajor,
unsigned MinorVersion = ShaderModel::kHighestMinor);
static const Semantic *Get(Kind kind);
static const Semantic *
Get(Kind kind, DXIL::SigPointKind sigPointKind,
unsigned MajorVersion = ShaderModel::kHighestMajor,
unsigned MinorVersion = ShaderModel::kHighestMinor);
static const Semantic *GetInvalid();
static const Semantic *GetArbitrary();
static bool HasSVPrefix(llvm::StringRef Name);
static void DecomposeNameAndIndex(llvm::StringRef FullName,
llvm::StringRef *pName, unsigned *pIndex);
Kind GetKind() const;
const char *GetName() const;
bool IsArbitrary() const;
bool IsInvalid() const;
private:
Kind m_Kind; // Semantic kind.
const char *m_pszName; // Canonical name (for system semantics).
Semantic() = delete;
Semantic(Kind Kind, const char *pszName);
// Table of all semantic properties.
static const unsigned kNumSemanticRecords = (unsigned)Kind::Invalid + 1;
static const Semantic ms_SemanticTable[kNumSemanticRecords];
friend class ShaderModel;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSignature.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSignature.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL shader signature. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilSignatureElement.h"
#include <memory>
#include <string>
#include <vector>
namespace hlsl {
/// Use this class to represent HLSL signature.
class DxilSignature {
public:
using Kind = DXIL::SignatureKind;
DxilSignature(DXIL::ShaderKind shaderKind, DXIL::SignatureKind sigKind,
bool useMinPrecision);
DxilSignature(DXIL::SigPointKind sigPointKind, bool useMinPrecision);
DxilSignature(const DxilSignature &src);
virtual ~DxilSignature();
bool IsInput() const;
bool IsOutput() const;
virtual std::unique_ptr<DxilSignatureElement> CreateElement();
unsigned AppendElement(std::unique_ptr<DxilSignatureElement> pSE,
bool bSetID = true);
DxilSignatureElement &GetElement(unsigned idx);
const DxilSignatureElement &GetElement(unsigned idx) const;
const std::vector<std::unique_ptr<DxilSignatureElement>> &GetElements() const;
// Returns true if all signature elements that should be allocated are
// allocated
bool IsFullyAllocated() const;
// Returns the number of allocated vectors used to contain signature
unsigned NumVectorsUsed(unsigned streamIndex = 0) const;
bool UseMinPrecision() const { return m_UseMinPrecision; }
DXIL::SigPointKind GetSigPointKind() const { return m_sigPointKind; }
static bool ShouldBeAllocated(DXIL::SemanticInterpretationKind);
unsigned GetRowCount() const;
private:
DXIL::SigPointKind m_sigPointKind;
std::vector<std::unique_ptr<DxilSignatureElement>> m_Elements;
bool m_UseMinPrecision;
};
struct DxilEntrySignature {
DxilEntrySignature(DXIL::ShaderKind shaderKind, bool useMinPrecision)
: InputSignature(shaderKind, DxilSignature::Kind::Input, useMinPrecision),
OutputSignature(shaderKind, DxilSignature::Kind::Output,
useMinPrecision),
PatchConstOrPrimSignature(shaderKind,
DxilSignature::Kind::PatchConstOrPrim,
useMinPrecision) {}
DxilEntrySignature(const DxilEntrySignature &src);
DxilSignature InputSignature;
DxilSignature OutputSignature;
DxilSignature PatchConstOrPrimSignature;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSignatureElement.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSignatureElement.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL signature element. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilCompType.h"
#include "dxc/DXIL/DxilInterpolationMode.h"
#include "dxc/DXIL/DxilSemantic.h"
#include "llvm/ADT/StringRef.h"
#include <limits.h>
#include <string>
#include <vector>
namespace hlsl {
class ShaderModel;
/// Use this class to represent HLSL signature elements.
class DxilSignatureElement {
friend class DxilSignature;
public:
using Kind = DXIL::SigPointKind;
static const unsigned kUndefinedID = UINT_MAX;
DxilSignatureElement(Kind K);
virtual ~DxilSignatureElement();
void Initialize(
llvm::StringRef Name, const CompType &ElementType,
const InterpolationMode &InterpMode, unsigned Rows, unsigned Cols,
int StartRow = Semantic::kUndefinedRow,
int StartCol = Semantic::kUndefinedCol, unsigned ID = kUndefinedID,
const std::vector<unsigned> &IndexVector = std::vector<unsigned>());
unsigned GetID() const;
void SetID(unsigned ID);
DXIL::ShaderKind GetShaderKind() const;
DXIL::SigPointKind GetSigPointKind() const;
void SetSigPointKind(DXIL::SigPointKind K);
bool IsInput() const;
bool IsOutput() const;
bool IsPatchConstOrPrim() const;
const char *GetName() const;
unsigned GetRows() const;
void SetRows(unsigned Rows);
unsigned GetCols() const;
void SetCols(unsigned Cols);
const InterpolationMode *GetInterpolationMode() const;
CompType GetCompType() const;
unsigned GetOutputStream() const;
void SetOutputStream(unsigned Stream);
// Semantic properties.
const Semantic *GetSemantic() const;
void SetKind(Semantic::Kind kind);
Semantic::Kind GetKind() const;
bool IsArbitrary() const;
bool IsDepth() const;
bool IsDepthLE() const;
bool IsDepthGE() const;
bool IsAnyDepth() const;
DXIL::SemanticInterpretationKind GetInterpretation() const;
llvm::StringRef GetSemanticName() const;
unsigned GetSemanticStartIndex() const;
// Low-level properties.
int GetStartRow() const;
void SetStartRow(int StartRow);
int GetStartCol() const;
void SetStartCol(int Component);
const std::vector<unsigned> &GetSemanticIndexVec() const;
void SetSemanticIndexVec(const std::vector<unsigned> &Vec);
void AppendSemanticIndex(unsigned SemIdx);
void SetCompType(CompType CT);
uint8_t GetColsAsMask() const;
bool IsAllocated() const;
unsigned GetDynIdxCompMask() const;
void SetDynIdxCompMask(unsigned DynIdxCompMask);
uint8_t GetUsageMask() const;
void SetUsageMask(unsigned UsageMask);
protected:
DXIL::SigPointKind m_sigPointKind;
const Semantic *m_pSemantic;
unsigned m_ID;
std::string m_Name;
llvm::StringRef m_SemanticName;
unsigned m_SemanticStartIndex;
CompType m_CompType;
InterpolationMode m_InterpMode;
std::vector<unsigned> m_SemanticIndex;
unsigned m_Rows;
unsigned m_Cols;
int m_StartRow;
int m_StartCol;
unsigned m_OutputStream;
unsigned m_DynIdxCompMask;
// UsageMask is meant to match the signature usage mask, used for validation:
// for output: may-write, for input: always-reads
unsigned m_UsageMask;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilCBuffer.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilCBuffer.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL constant buffer (cbuffer). //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilResourceBase.h"
namespace hlsl {
/// Use this class to represent HLSL cbuffer.
class DxilCBuffer : public DxilResourceBase {
public:
DxilCBuffer();
virtual ~DxilCBuffer();
unsigned GetSize() const;
void SetSize(unsigned InstanceSizeInBytes);
private:
unsigned m_SizeInBytes; // Cbuffer instance size in bytes.
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilResourceBinding.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilResourceBinding.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation properties for DXIL resource binding. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
namespace llvm {
class Constant;
class Type;
} // namespace llvm
namespace hlsl {
struct DxilResourceBinding {
uint32_t rangeLowerBound;
uint32_t rangeUpperBound;
uint32_t spaceID;
uint8_t resourceClass;
uint8_t Reserved1;
uint8_t Reserved2;
uint8_t Reserved3;
bool operator==(const DxilResourceBinding &);
bool operator!=(const DxilResourceBinding &);
};
static_assert(sizeof(DxilResourceBinding) == 4 * sizeof(uint32_t),
"update shader model and functions read/write "
"DxilResourceBinding when size is changed");
class ShaderModel;
class DxilResourceBase;
struct DxilInst_CreateHandleFromBinding;
namespace resource_helper {
llvm::Constant *getAsConstant(const DxilResourceBinding &, llvm::Type *Ty,
const ShaderModel &);
DxilResourceBinding loadBindingFromConstant(const llvm::Constant &C);
DxilResourceBinding loadBindingFromCreateHandleFromBinding(
const DxilInst_CreateHandleFromBinding &createHandle, llvm::Type *Ty,
const ShaderModel &);
DxilResourceBinding loadBindingFromResourceBase(DxilResourceBase *);
} // namespace resource_helper
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilCounters.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilCounters.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Counters for Dxil instructions types. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <stdint.h>
namespace llvm {
class Module;
class StringRef;
} // namespace llvm
namespace hlsl {
struct DxilCounters {
// clang-format off
// Python lines need to be not formatted.
// <py::lines('OPCODE-COUNTERS')>['uint32_t %s = 0;' % c for c in hctdb_instrhelp.get_counters()]</py>
// clang-format on
// OPCODE-COUNTERS:BEGIN
uint32_t array_local_bytes = 0;
uint32_t array_local_ldst = 0;
uint32_t array_static_bytes = 0;
uint32_t array_static_ldst = 0;
uint32_t array_tgsm_bytes = 0;
uint32_t array_tgsm_ldst = 0;
uint32_t atomic = 0;
uint32_t barrier = 0;
uint32_t branches = 0;
uint32_t fence = 0;
uint32_t floats = 0;
uint32_t gs_cut = 0;
uint32_t gs_emit = 0;
uint32_t insts = 0;
uint32_t ints = 0;
uint32_t sig_ld = 0;
uint32_t sig_st = 0;
uint32_t tex_bias = 0;
uint32_t tex_cmp = 0;
uint32_t tex_grad = 0;
uint32_t tex_load = 0;
uint32_t tex_norm = 0;
uint32_t tex_store = 0;
uint32_t uints = 0;
// OPCODE-COUNTERS:END
uint32_t AllArrayBytes() {
return array_local_bytes + array_static_bytes + array_tgsm_bytes;
}
uint32_t AllArrayAccesses() {
return array_local_ldst + array_static_ldst + array_tgsm_ldst;
}
};
void CountInstructions(llvm::Module &M, DxilCounters &counters);
uint32_t *LookupByName(llvm::StringRef name, DxilCounters &counters);
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSigPoint.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSigPoint.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL signature points. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
namespace hlsl {
struct VersionedSemanticInterpretation {
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind k,
unsigned MajorVersion = 0,
unsigned MinorVersion = 0)
: Kind(k), Major((unsigned short)MajorVersion),
Minor((unsigned short)MinorVersion) {}
DXIL::SemanticInterpretationKind Kind;
unsigned short Major, Minor;
};
/// Use this class to describe an HLSL signature point.
/// A signature point is a set of signature parameters at a particular shader
/// stage, grouped by input/output/patch constant and value frequency.
class SigPoint {
public:
using Kind = DXIL::SigPointKind;
SigPoint(DXIL::SigPointKind spk, const char *name, DXIL::SigPointKind rspk,
DXIL::ShaderKind shk, DXIL::SignatureKind sigk,
DXIL::PackingKind pk);
bool IsInput() const { return m_SignatureKind == DXIL::SignatureKind::Input; }
bool IsOutput() const {
return m_SignatureKind == DXIL::SignatureKind::Output;
}
bool IsPatchConstOrPrim() const {
return m_SignatureKind == DXIL::SignatureKind::PatchConstOrPrim;
}
Kind GetKind() const { return m_Kind; }
const char *GetName() const { return m_pszName; }
DXIL::ShaderKind GetShaderKind() const { return m_ShaderKind; }
Kind GetRelatedKind() const { return m_RelatedKind; }
DXIL::SignatureKind GetSignatureKind() const { return m_SignatureKind; }
DXIL::SignatureKind GetSignatureKindWithFallback() const;
DXIL::PackingKind GetPackingKind() const { return m_PackingKind; }
bool NeedsInterpMode() const {
return m_PackingKind == DXIL::PackingKind::Vertex;
}
static const SigPoint *GetSigPoint(Kind K);
// isSpecialInput selects a signature point outside the normal
// input/output/patch constant signatures. These are used for a few system
// values that should not be included as part of the regular input structure
// because they do not have the same dimensionality as other inputs, such as
// SV_PrimitiveID for Geometry, Hull, and Patch Constant Functions.
static DXIL::SigPointKind GetKind(DXIL::ShaderKind shaderKind,
DXIL::SignatureKind sigKind,
bool isPatchConstantFunction,
bool isSpecialInput);
// Interpretations are how system values are intrepeted at a particular
// signature point.
static DXIL::SemanticInterpretationKind
GetInterpretation(DXIL::SemanticKind SK, Kind K, unsigned MajorVersion,
unsigned MinorVersion);
// For Shadow elements, recover original SigPointKind
static Kind RecoverKind(DXIL::SemanticKind SK, Kind K);
private:
static const unsigned kNumSigPointRecords = (unsigned)Kind::Invalid + 1;
static const SigPoint ms_SigPoints[kNumSigPointRecords];
static const VersionedSemanticInterpretation ms_SemanticInterpretationTable[(
unsigned)DXIL::SemanticKind::Invalid][(unsigned)Kind::Invalid];
Kind m_Kind;
Kind m_RelatedKind;
DXIL::ShaderKind m_ShaderKind;
DXIL::SignatureKind m_SignatureKind;
const char *m_pszName;
DXIL::PackingKind m_PackingKind;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilConstants.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilConstants.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Essential DXIL constants. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <stdint.h>
namespace hlsl {
/* <py>
import hctdb_instrhelp
</py> */
// TODO:
// 2. get rid of DXIL namespace.
// 3. use class enum for shader flags.
// 4. use class enum for address spaces.
namespace DXIL {
// DXIL version.
const unsigned kDxilMajor = 1;
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_dxil_version_minor()</py>*/
// VALRULE-TEXT:BEGIN
const unsigned kDxilMinor = 8;
// VALRULE-TEXT:END
inline unsigned MakeDxilVersion(unsigned DxilMajor, unsigned DxilMinor) {
return 0 | (DxilMajor << 8) | (DxilMinor);
}
inline unsigned GetCurrentDxilVersion() {
return MakeDxilVersion(kDxilMajor, kDxilMinor);
}
inline unsigned GetDxilVersionMajor(unsigned DxilVersion) {
return (DxilVersion >> 8) & 0xFF;
}
inline unsigned GetDxilVersionMinor(unsigned DxilVersion) {
return DxilVersion & 0xFF;
}
// Return positive if v1 > v2, negative if v1 < v2, zero if equal
inline int CompareVersions(unsigned Major1, unsigned Minor1, unsigned Major2,
unsigned Minor2) {
if (Major1 != Major2) {
// Special case for Major == 0 (latest/unbound)
if (Major1 == 0 || Major2 == 0)
return Major1 > 0 ? -1 : 1;
return Major1 < Major2 ? -1 : 1;
}
if (Minor1 < Minor2)
return -1;
if (Minor1 > Minor2)
return 1;
return 0;
}
// Utility for updating major,minor to max of current and new.
inline bool UpdateToMaxOfVersions(unsigned &major, unsigned &minor,
unsigned newMajor, unsigned newMinor) {
if (newMajor > major) {
major = newMajor;
minor = newMinor;
return true;
} else if (newMajor == major) {
if (newMinor > minor) {
minor = newMinor;
return true;
}
}
return false;
}
// Shader flags.
const unsigned kDisableOptimizations =
0x00000001; // D3D11_1_SB_GLOBAL_FLAG_SKIP_OPTIMIZATION
const unsigned kDisableMathRefactoring =
0x00000002; //~D3D10_SB_GLOBAL_FLAG_REFACTORING_ALLOWED
const unsigned kEnableDoublePrecision =
0x00000004; // D3D11_SB_GLOBAL_FLAG_ENABLE_DOUBLE_PRECISION_FLOAT_OPS
const unsigned kForceEarlyDepthStencil =
0x00000008; // D3D11_SB_GLOBAL_FLAG_FORCE_EARLY_DEPTH_STENCIL
const unsigned kEnableRawAndStructuredBuffers =
0x00000010; // D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS
const unsigned kEnableMinPrecision =
0x00000020; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_MINIMUM_PRECISION
const unsigned kEnableDoubleExtensions =
0x00000040; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_DOUBLE_EXTENSIONS
const unsigned kEnableMSAD =
0x00000080; // D3D11_1_SB_GLOBAL_FLAG_ENABLE_SHADER_EXTENSIONS
const unsigned kAllResourcesBound =
0x00000100; // D3D12_SB_GLOBAL_FLAG_ALL_RESOURCES_BOUND
const unsigned kNumOutputStreams = 4;
const unsigned kNumClipPlanes = 6;
// TODO: move these to appropriate places (ShaderModel.cpp?)
const unsigned kMaxTempRegCount = 4096; // DXBC only
const unsigned kMaxCBufferSize = 4096;
const unsigned kMaxStructBufferStride = 2048;
const unsigned kMaxHSOutputControlPointsTotalScalars = 3968;
const unsigned kMaxHSOutputPatchConstantTotalScalars = 32 * 4;
const unsigned kMaxSignatureTotalVectors = 32;
const unsigned kMaxOutputTotalScalars = kMaxSignatureTotalVectors * 4;
const unsigned kMaxInputTotalScalars = kMaxSignatureTotalVectors * 4;
const unsigned kMaxClipOrCullDistanceElementCount = 2;
const unsigned kMaxClipOrCullDistanceCount = 2 * 4;
const unsigned kMaxGSOutputVertexCount = 1024;
const unsigned kMaxGSInstanceCount = 32;
const unsigned kMinIAPatchControlPointCount = 1;
const unsigned kMaxIAPatchControlPointCount = 32;
const float kHSMaxTessFactorLowerBound = 1.0f;
const float kHSMaxTessFactorUpperBound = 64.0f;
const unsigned kHSDefaultInputControlPointCount = 1;
const unsigned kMaxCSThreadsPerGroup = 1024;
const unsigned kMaxCSThreadGroupX = 1024;
const unsigned kMaxCSThreadGroupY = 1024;
const unsigned kMaxCSThreadGroupZ = 64;
const unsigned kMinCSThreadGroupX = 1;
const unsigned kMinCSThreadGroupY = 1;
const unsigned kMinCSThreadGroupZ = 1;
const unsigned kMaxCS4XThreadsPerGroup = 768;
const unsigned kMaxCS4XThreadGroupX = 768;
const unsigned kMaxCS4XThreadGroupY = 768;
const unsigned kMaxTGSMSize = 8192 * 4;
const unsigned kMaxGSOutputTotalScalars = 1024;
const unsigned kMaxMSASThreadsPerGroup = 128;
const unsigned kMaxMSASThreadGroupX = 128;
const unsigned kMaxMSASThreadGroupY = 128;
const unsigned kMaxMSASThreadGroupZ = 128;
const unsigned kMinMSASThreadGroupX = 1;
const unsigned kMinMSASThreadGroupY = 1;
const unsigned kMinMSASThreadGroupZ = 1;
const unsigned kMaxMSASPayloadBytes = 1024 * 16;
const unsigned kMaxMSOutputPrimitiveCount = 256;
const unsigned kMaxMSOutputVertexCount = 256;
const unsigned kMaxMSOutputTotalBytes = 1024 * 32;
const unsigned kMaxMSInputOutputTotalBytes = 1024 * 47;
const unsigned kMaxMSVSigRows = 32;
const unsigned kMaxMSPSigRows = 32;
const unsigned kMaxMSTotalSigRows = 32;
const unsigned kMaxMSSMSize = 1024 * 28;
const unsigned kMinWaveSize = 4;
const unsigned kMaxWaveSize = 128;
const float kMaxMipLodBias = 15.99f;
const float kMinMipLodBias = -16.0f;
const unsigned kResRetStatusIndex = 4;
enum class ComponentType : uint32_t {
Invalid = 0,
I1,
I16,
U16,
I32,
U32,
I64,
U64,
F16,
F32,
F64,
SNormF16,
UNormF16,
SNormF32,
UNormF32,
SNormF64,
UNormF64,
PackedS8x32,
PackedU8x32,
LastEntry
};
// Must match D3D_INTERPOLATION_MODE
enum class InterpolationMode : uint8_t {
Undefined = 0,
Constant = 1,
Linear = 2,
LinearCentroid = 3,
LinearNoperspective = 4,
LinearNoperspectiveCentroid = 5,
LinearSample = 6,
LinearNoperspectiveSample = 7,
Invalid = 8
};
// size of each scalar type in signature element in bits
enum class SignatureDataWidth : uint8_t {
Undefined = 0,
Bits16 = 16,
Bits32 = 32,
};
enum class SignatureKind {
Invalid = 0,
Input,
Output,
PatchConstOrPrim,
};
// Must match D3D11_SHADER_VERSION_TYPE
enum class ShaderKind {
Pixel = 0,
Vertex,
Geometry,
Hull,
Domain,
Compute,
Library,
RayGeneration,
Intersection,
AnyHit,
ClosestHit,
Miss,
Callable,
Mesh,
Amplification,
Node,
Invalid,
// Last* values identify the last shader kind recognized by the highest
// validator version before additional kinds were added.
Last_1_2 = Compute,
Last_1_4 = Callable,
Last_1_7 = Amplification,
Last_1_8 = Node,
LastValid = Last_1_8,
};
static_assert((unsigned)DXIL::ShaderKind::LastValid + 1 ==
(unsigned)DXIL::ShaderKind::Invalid,
"otherwise, enum needs updating.");
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('SemanticKind-ENUM')>hctdb_instrhelp.get_enum_decl("SemanticKind", hide_val=True, sort_val=False)</py>*/
// clang-format on
// SemanticKind-ENUM:BEGIN
// Semantic kind; Arbitrary or specific system value.
enum class SemanticKind : unsigned {
Arbitrary,
VertexID,
InstanceID,
Position,
RenderTargetArrayIndex,
ViewPortArrayIndex,
ClipDistance,
CullDistance,
OutputControlPointID,
DomainLocation,
PrimitiveID,
GSInstanceID,
SampleIndex,
IsFrontFace,
Coverage,
InnerCoverage,
Target,
Depth,
DepthLessEqual,
DepthGreaterEqual,
StencilRef,
DispatchThreadID,
GroupID,
GroupIndex,
GroupThreadID,
TessFactor,
InsideTessFactor,
ViewID,
Barycentrics,
ShadingRate,
CullPrimitive,
StartVertexLocation,
StartInstanceLocation,
Invalid,
};
// SemanticKind-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('SigPointKind-ENUM')>hctdb_instrhelp.get_enum_decl("SigPointKind", hide_val=True, sort_val=False)</py>*/
// clang-format on
// SigPointKind-ENUM:BEGIN
// Signature Point is more specific than shader stage or signature as it is
// unique in both stage and item dimensionality or frequency.
enum class SigPointKind : unsigned {
VSIn, // Ordinary Vertex Shader input from Input Assembler
VSOut, // Ordinary Vertex Shader output that may feed Rasterizer
PCIn, // Patch Constant function non-patch inputs
HSIn, // Hull Shader function non-patch inputs
HSCPIn, // Hull Shader patch inputs - Control Points
HSCPOut, // Hull Shader function output - Control Point
PCOut, // Patch Constant function output - Patch Constant data passed to
// Domain Shader
DSIn, // Domain Shader regular input - Patch Constant data plus system values
DSCPIn, // Domain Shader patch input - Control Points
DSOut, // Domain Shader output - vertex data that may feed Rasterizer
GSVIn, // Geometry Shader vertex input - qualified with primitive type
GSIn, // Geometry Shader non-vertex inputs (system values)
GSOut, // Geometry Shader output - vertex data that may feed Rasterizer
PSIn, // Pixel Shader input
PSOut, // Pixel Shader output
CSIn, // Compute Shader input
MSIn, // Mesh Shader input
MSOut, // Mesh Shader vertices output
MSPOut, // Mesh Shader primitives output
ASIn, // Amplification Shader input
Invalid,
};
// SigPointKind-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('SemanticInterpretationKind-ENUM')>hctdb_instrhelp.get_enum_decl("SemanticInterpretationKind", hide_val=True, sort_val=False)</py>*/
// clang-format on
// SemanticInterpretationKind-ENUM:BEGIN
// Defines how a semantic is interpreted at a particular SignaturePoint
enum class SemanticInterpretationKind : unsigned {
NA, // Not Available
SV, // Normal System Value
SGV, // System Generated Value (sorted last)
Arb, // Treated as Arbitrary
NotInSig, // Not included in signature (intrinsic access)
NotPacked, // Included in signature, but does not contribute to packing
Target, // Special handling for SV_Target
TessFactor, // Special handling for tessellation factors
Shadow, // Shadow element must be added to a signature for compatibility
ClipCull, // Special packing rules for SV_ClipDistance or SV_CullDistance
Invalid,
};
// SemanticInterpretationKind-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('PackingKind-ENUM')>hctdb_instrhelp.get_enum_decl("PackingKind", hide_val=True, sort_val=False)</py>*/
// clang-format on
// PackingKind-ENUM:BEGIN
// Kind of signature point
enum class PackingKind : unsigned {
None, // No packing should be performed
InputAssembler, // Vertex Shader input from Input Assembler
Vertex, // Vertex that may feed the Rasterizer
PatchConstant, // Patch constant signature
Target, // Render Target (Pixel Shader Output)
Invalid,
};
// PackingKind-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('FPDenormMode-ENUM')>hctdb_instrhelp.get_enum_decl("Float32DenormMode", hide_val=False, sort_val=False)</py>*/
// clang-format on
// FPDenormMode-ENUM:BEGIN
// float32 denorm behavior
enum class Float32DenormMode : unsigned {
Any = 0, // Undefined behavior for denormal numbers
Preserve = 1, // Preserve both input and output
FTZ = 2, // Preserve denormal inputs. Flush denorm outputs
Reserve3 = 3, // Reserved Value. Not used for now
Reserve4 = 4, // Reserved Value. Not used for now
Reserve5 = 5, // Reserved Value. Not used for now
Reserve6 = 6, // Reserved Value. Not used for now
Reserve7 = 7, // Reserved Value. Not used for now
};
// FPDenormMode-ENUM:END
enum class PackingStrategy : unsigned {
Default = 0, // Choose default packing algorithm based on target (currently
// PrefixStable)
PrefixStable, // Maintain assumption that all elements are packed in order and
// stable as new elements are added.
Optimized, // Optimize packing of all elements together (all elements must be
// present, in the same order, for identical placement of any
// individual element)
Invalid,
};
enum class DefaultLinkage : unsigned {
Default = 0,
Internal = 1,
External = 2,
};
enum class SamplerKind : unsigned {
Default = 0,
Comparison,
Mono,
Invalid,
};
enum class ResourceClass { SRV = 0, UAV, CBuffer, Sampler, Invalid };
enum class ResourceKind : unsigned {
Invalid = 0,
Texture1D,
Texture2D,
Texture2DMS,
Texture3D,
TextureCube,
Texture1DArray,
Texture2DArray,
Texture2DMSArray,
TextureCubeArray,
TypedBuffer,
RawBuffer,
StructuredBuffer,
CBuffer,
Sampler,
TBuffer,
RTAccelerationStructure,
FeedbackTexture2D,
FeedbackTexture2DArray,
NumEntries,
};
/// Whether the resource kind is a texture. This does not include
/// FeedbackTextures.
inline bool IsAnyTexture(DXIL::ResourceKind ResourceKind) {
return DXIL::ResourceKind::Texture1D <= ResourceKind &&
ResourceKind <= DXIL::ResourceKind::TextureCubeArray;
}
/// Whether the resource kind is an array of textures. This does not include
/// FeedbackTextures.
inline bool IsAnyArrayTexture(DXIL::ResourceKind ResourceKind) {
return DXIL::ResourceKind::Texture1DArray <= ResourceKind &&
ResourceKind <= DXIL::ResourceKind::TextureCubeArray;
}
/// Whether the resource kind is a Texture or FeedbackTexture with array
/// dimension.
inline bool IsArrayKind(DXIL::ResourceKind ResourceKind) {
return IsAnyArrayTexture(ResourceKind) ||
ResourceKind == DXIL::ResourceKind::FeedbackTexture2DArray;
}
/// Whether the resource kind is a TextureCube or TextureCubeArray.
inline bool IsAnyTextureCube(DXIL::ResourceKind ResourceKind) {
return DXIL::ResourceKind::TextureCube == ResourceKind ||
DXIL::ResourceKind::TextureCubeArray == ResourceKind;
}
inline bool IsStructuredBuffer(DXIL::ResourceKind ResourceKind) {
return ResourceKind == DXIL::ResourceKind::StructuredBuffer;
}
inline bool IsTypedBuffer(DXIL::ResourceKind ResourceKind) {
return ResourceKind == DXIL::ResourceKind::TypedBuffer;
}
inline bool IsTyped(DXIL::ResourceKind ResourceKind) {
return IsTypedBuffer(ResourceKind) || IsAnyTexture(ResourceKind);
}
inline bool IsRawBuffer(DXIL::ResourceKind ResourceKind) {
return ResourceKind == DXIL::ResourceKind::RawBuffer;
}
inline bool IsTBuffer(DXIL::ResourceKind ResourceKind) {
return ResourceKind == DXIL::ResourceKind::TBuffer;
}
/// Whether the resource kind is a FeedbackTexture.
inline bool IsFeedbackTexture(DXIL::ResourceKind ResourceKind) {
return ResourceKind == DXIL::ResourceKind::FeedbackTexture2D ||
ResourceKind == DXIL::ResourceKind::FeedbackTexture2DArray;
}
// TODO: change opcodes.
/* <py::lines('OPCODE-ENUM')>hctdb_instrhelp.get_enum_decl("OpCode")</py>*/
// OPCODE-ENUM:BEGIN
// Enumeration for operations specified by DXIL
enum class OpCode : unsigned {
//
Reserved0 = 226, // Reserved
Reserved1 = 227, // Reserved
Reserved10 = 236, // Reserved
Reserved11 = 237, // Reserved
Reserved2 = 228, // Reserved
Reserved3 = 229, // Reserved
Reserved4 = 230, // Reserved
Reserved5 = 231, // Reserved
Reserved6 = 232, // Reserved
Reserved7 = 233, // Reserved
Reserved8 = 234, // Reserved
Reserved9 = 235, // Reserved
// Amplification shader instructions
DispatchMesh = 173, // Amplification shader intrinsic DispatchMesh
// AnyHit Terminals
AcceptHitAndEndSearch =
156, // Used in an any hit shader to abort the ray query and the
// intersection shader (if any). The current hit is committed and
// execution passes to the closest hit shader with the closest hit
// recorded so far
IgnoreHit = 155, // Used in an any hit shader to reject an intersection and
// terminate the shader
// Binary float
FMax = 35, // returns a if a >= b, else b
FMin = 36, // returns a if a < b, else b
// Binary int with two outputs
IMul = 41, // multiply of 32-bit operands to produce the correct full 64-bit
// result.
// Binary int
IMax = 37, // IMax(a,b) returns a if a > b, else b
IMin = 38, // IMin(a,b) returns a if a < b, else b
// Binary uint with carry or borrow
UAddc = 44, // unsigned add of 32-bit operand with the carry
USubb = 45, // unsigned subtract of 32-bit operands with the borrow
// Binary uint with two outputs
UDiv = 43, // unsigned divide of the 32-bit operand src0 by the 32-bit operand
// src1.
UMul = 42, // multiply of 32-bit operands to produce the correct full 64-bit
// result.
// Binary uint
UMax = 39, // unsigned integer maximum. UMax(a,b) = a > b ? a : b
UMin = 40, // unsigned integer minimum. UMin(a,b) = a < b ? a : b
// Bitcasts with different sizes
BitcastF16toI16 = 125, // bitcast between different sizes
BitcastF32toI32 = 127, // bitcast between different sizes
BitcastF64toI64 = 129, // bitcast between different sizes
BitcastI16toF16 = 124, // bitcast between different sizes
BitcastI32toF32 = 126, // bitcast between different sizes
BitcastI64toF64 = 128, // bitcast between different sizes
// Comparison Samples
SampleCmpBias = 255, // samples a texture after applying the input bias to the
// mipmap level and compares a single component against
// the specified comparison value
SampleCmpGrad =
254, // samples a texture using a gradient and compares a single component
// against the specified comparison value
// Compute/Mesh/Amplification/Node shader
FlattenedThreadIdInGroup = 96, // provides a flattened index for a given
// thread within a given group (SV_GroupIndex)
GroupId = 94, // reads the group ID (SV_GroupID)
ThreadId = 93, // reads the thread ID
ThreadIdInGroup =
95, // reads the thread ID within the group (SV_GroupThreadID)
// Create/Annotate Node Handles
AllocateNodeOutputRecords = 238, // returns a handle for the output records
AnnotateNodeHandle = 249, // annotate handle with node properties
AnnotateNodeRecordHandle = 251, // annotate handle with node record properties
CreateNodeInputRecordHandle = 250, // create a handle for an InputRecord
CreateNodeOutputHandle = 247, // Creates a handle to a NodeOutput
IndexNodeHandle = 248, // returns the handle for the location in the output
// node array at the indicated index
// Derivatives
CalculateLOD = 81, // calculates the level of detail
DerivCoarseX = 83, // computes the rate of change per stamp in x direction.
DerivCoarseY = 84, // computes the rate of change per stamp in y direction.
DerivFineX = 85, // computes the rate of change per pixel in x direction.
DerivFineY = 86, // computes the rate of change per pixel in y direction.
// Domain and hull shader
LoadOutputControlPoint = 103, // LoadOutputControlPoint
LoadPatchConstant = 104, // LoadPatchConstant
// Domain shader
DomainLocation = 105, // DomainLocation
// Dot product with accumulate
Dot2AddHalf = 162, // 2D half dot product with accumulate to float
Dot4AddI8Packed = 163, // signed dot product of 4 x i8 vectors packed into
// i32, with accumulate to i32
Dot4AddU8Packed = 164, // unsigned dot product of 4 x u8 vectors packed into
// i32, with accumulate to i32
// Dot
Dot2 = 54, // Two-dimensional vector dot-product
Dot3 = 55, // Three-dimensional vector dot-product
Dot4 = 56, // Four-dimensional vector dot-product
// Double precision
LegacyDoubleToFloat = 132, // legacy fuction to convert double to float
LegacyDoubleToSInt32 = 133, // legacy fuction to convert double to int32
LegacyDoubleToUInt32 = 134, // legacy fuction to convert double to uint32
MakeDouble = 101, // creates a double value
SplitDouble = 102, // splits a double into low and high parts
// Extended Command Information
StartInstanceLocation =
257, // returns the StartInstanceLocation from Draw*Instanced
StartVertexLocation =
256, // returns the BaseVertexLocation from DrawIndexedInstanced or
// StartVertexLocation from DrawInstanced
// Geometry shader
CutStream =
98, // completes the current primitive topology at the specified stream
EmitStream = 97, // emits a vertex to a given stream
EmitThenCutStream = 99, // equivalent to an EmitStream followed by a CutStream
GSInstanceID = 100, // GSInstanceID
// Get Pointer to Node Record in Address Space 6
GetNodeRecordPtr =
239, // retrieve node input/output record pointer in address space 6
// Get handle from heap
AnnotateHandle = 216, // annotate handle with resource properties
CreateHandleFromBinding = 217, // create resource handle from binding
CreateHandleFromHeap = 218, // create resource handle from heap
// Graphics shader
ViewID = 138, // returns the view index
// Helper Lanes
IsHelperLane = 221, // returns true on helper lanes in pixel shaders
// Hull shader
OutputControlPointID = 107, // OutputControlPointID
StorePatchConstant = 106, // StorePatchConstant
// Hull, Domain and Geometry shaders
PrimitiveID = 108, // PrimitiveID
// Indirect Shader Invocation
CallShader = 159, // Call a shader in the callable shader table supplied
// through the DispatchRays() API
ReportHit = 158, // returns true if hit was accepted
TraceRay = 157, // initiates raytrace
// Inline Ray Query
AllocateRayQuery = 178, // allocates space for RayQuery and return handle
RayQuery_Abort = 181, // aborts a ray query
RayQuery_CandidateGeometryIndex = 203, // returns candidate hit geometry index
RayQuery_CandidateInstanceContributionToHitGroupIndex =
214, // returns candidate hit InstanceContributionToHitGroupIndex
RayQuery_CandidateInstanceID = 202, // returns candidate hit instance ID
RayQuery_CandidateInstanceIndex = 201, // returns candidate hit instance index
RayQuery_CandidateObjectRayDirection =
206, // returns candidate object ray direction
RayQuery_CandidateObjectRayOrigin =
205, // returns candidate hit object ray origin
RayQuery_CandidateObjectToWorld3x4 =
186, // returns matrix for transforming from object-space to world-space
// for a candidate hit.
RayQuery_CandidatePrimitiveIndex =
204, // returns candidate hit geometry index
RayQuery_CandidateProceduralPrimitiveNonOpaque =
190, // returns if current candidate procedural primitive is non opaque
RayQuery_CandidateTriangleBarycentrics =
193, // returns candidate triangle hit barycentrics
RayQuery_CandidateTriangleFrontFace =
191, // returns if current candidate triangle is front facing
RayQuery_CandidateTriangleRayT =
199, // returns float representing the parametric point on the ray for the
// current candidate triangle hit.
RayQuery_CandidateType =
185, // returns uint candidate type (CANDIDATE_TYPE) of the current hit
// candidate in a ray query, after Proceed() has returned true
RayQuery_CandidateWorldToObject3x4 =
187, // returns matrix for transforming from world-space to object-space
// for a candidate hit.
RayQuery_CommitNonOpaqueTriangleHit =
182, // commits a non opaque triangle hit
RayQuery_CommitProceduralPrimitiveHit =
183, // commits a procedural primitive hit
RayQuery_CommittedGeometryIndex = 209, // returns committed hit geometry index
RayQuery_CommittedInstanceContributionToHitGroupIndex =
215, // returns committed hit InstanceContributionToHitGroupIndex
RayQuery_CommittedInstanceID = 208, // returns committed hit instance ID
RayQuery_CommittedInstanceIndex = 207, // returns committed hit instance index
RayQuery_CommittedObjectRayDirection =
212, // returns committed object ray direction
RayQuery_CommittedObjectRayOrigin =
211, // returns committed hit object ray origin
RayQuery_CommittedObjectToWorld3x4 =
188, // returns matrix for transforming from object-space to world-space
// for a Committed hit.
RayQuery_CommittedPrimitiveIndex =
210, // returns committed hit geometry index
RayQuery_CommittedRayT =
200, // returns float representing the parametric point on the ray for the
// current committed hit.
RayQuery_CommittedStatus = 184, // returns uint status (COMMITTED_STATUS) of
// the committed hit in a ray query
RayQuery_CommittedTriangleBarycentrics =
194, // returns committed triangle hit barycentrics
RayQuery_CommittedTriangleFrontFace =
192, // returns if current committed triangle is front facing
RayQuery_CommittedWorldToObject3x4 =
189, // returns matrix for transforming from world-space to object-space
// for a Committed hit.
RayQuery_Proceed = 180, // advances a ray query
RayQuery_RayFlags = 195, // returns ray flags
RayQuery_RayTMin = 198, // returns float representing the parametric starting
// point for the ray.
RayQuery_TraceRayInline = 179, // initializes RayQuery for raytrace
RayQuery_WorldRayDirection = 197, // returns world ray direction
RayQuery_WorldRayOrigin = 196, // returns world ray origin
// Legacy floating-point
LegacyF16ToF32 = 131, // legacy fuction to convert half (f16) to float (f32)
// (this is not related to min-precision)
LegacyF32ToF16 = 130, // legacy fuction to convert float (f32) to half (f16)
// (this is not related to min-precision)
// Library create handle from resource struct (like HL intrinsic)
CreateHandleForLib =
160, // create resource handle from resource struct for library
// Mesh shader instructions
EmitIndices = 169, // emit a primitive's vertex indices in a mesh shader
GetMeshPayload =
170, // get the mesh payload which is from amplification shader
SetMeshOutputCounts = 168, // Mesh shader intrinsic SetMeshOutputCounts
StorePrimitiveOutput =
172, // stores the value to mesh shader primitive output
StoreVertexOutput = 171, // stores the value to mesh shader vertex output
// Other
CycleCounterLegacy = 109, // CycleCounterLegacy
// Packing intrinsics
Pack4x8 = 220, // packs vector of 4 signed or unsigned values into a packed
// datatype, drops or clamps unused bits
// Pixel shader
AttributeAtVertex =
137, // returns the values of the attributes at the vertex.
Coverage = 91, // returns the coverage mask input in a pixel shader
Discard = 82, // discard the current pixel
EvalCentroid = 89, // evaluates an input attribute at pixel center
EvalSampleIndex = 88, // evaluates an input attribute at a sample location
EvalSnapped =
87, // evaluates an input attribute at pixel center with an offset
InnerCoverage = 92, // returns underestimated coverage input from conservative
// rasterization in a pixel shader
SampleIndex =
90, // returns the sample index in a sample-frequency pixel shader
// Quad Wave Ops
QuadOp = 123, // returns the result of a quad-level operation
QuadReadLaneAt = 122, // reads from a lane in the quad
QuadVote = 222, // compares boolean accross a quad
// Quaternary
Bfi = 53, // Given a bit range from the LSB of a number, places that number of
// bits in another number at any offset
// Ray Dispatch Arguments
DispatchRaysDimensions =
146, // The Width and Height values from the D3D12_DISPATCH_RAYS_DESC
// structure provided to the originating DispatchRays() call.
DispatchRaysIndex =
145, // The current x and y location within the Width and Height
// Ray Transforms
ObjectToWorld =
151, // Matrix for transforming from object-space to world-space.
WorldToObject =
152, // Matrix for transforming from world-space to object-space.
// Ray Vectors
WorldRayDirection = 148, // The world-space direction for the current ray.
WorldRayOrigin = 147, // The world-space origin for the current ray.
// Ray object space Vectors
ObjectRayDirection = 150, // Object-space direction for the current ray.
ObjectRayOrigin = 149, // Object-space origin for the current ray.
// RayT
RayTCurrent =
154, // float representing the current parametric ending point for the ray
RayTMin =
153, // float representing the parametric starting point for the ray.
// Raytracing hit uint System Values
HitKind = 143, // Returns the value passed as HitKind in ReportIntersection().
// If intersection was reported by fixed-function triangle
// intersection, HitKind will be one of
// HIT_KIND_TRIANGLE_FRONT_FACE or HIT_KIND_TRIANGLE_BACK_FACE.
// Raytracing object space uint System Values, raytracing tier 1.1
GeometryIndex = 213, // The autogenerated index of the current geometry in the
// bottom-level structure
// Raytracing object space uint System Values
InstanceID =
141, // The user-provided InstanceID on the bottom-level acceleration
// structure instance within the top-level structure
InstanceIndex = 142, // The autogenerated index of the current instance in the
// top-level structure
PrimitiveIndex = 161, // PrimitiveIndex for raytracing shaders
// Raytracing uint System Values
RayFlags = 144, // uint containing the current ray flags.
// Resources - gather
TextureGather = 73, // gathers the four texels that would be used in a
// bi-linear filtering operation
TextureGatherCmp = 74, // same as TextureGather, except this instrution
// performs comparison on texels, similar to SampleCmp
TextureGatherRaw = 223, // Gather raw elements from 4 texels with no type
// conversions (SRV type is constrained)
// Resources - sample
RenderTargetGetSampleCount =
77, // gets the number of samples for a render target
RenderTargetGetSamplePosition =
76, // gets the position of the specified sample
Sample = 60, // samples a texture
SampleBias =
61, // samples a texture after applying the input bias to the mipmap level
SampleCmp = 64, // samples a texture and compares a single component against
// the specified comparison value
SampleCmpLevel = 224, // samples a texture and compares a single component
// against the specified comparison value
SampleCmpLevelZero = 65, // samples a texture and compares a single component
// against the specified comparison value
SampleGrad = 63, // samples a texture using a gradient to influence the way
// the sample location is calculated
SampleLevel = 62, // samples a texture using a mipmap-level offset
Texture2DMSGetSamplePosition =
75, // gets the position of the specified sample
// Resources
BufferLoad = 68, // reads from a TypedBuffer
BufferStore = 69, // writes to a RWTypedBuffer
BufferUpdateCounter = 70, // atomically increments/decrements the hidden
// 32-bit counter stored with a Count or Append UAV
CBufferLoad = 58, // loads a value from a constant buffer resource
CBufferLoadLegacy = 59, // loads a value from a constant buffer resource
CheckAccessFullyMapped =
71, // determines whether all values from a Sample, Gather, or Load
// operation accessed mapped tiles in a tiled resource
CreateHandle = 57, // creates the handle to a resource
GetDimensions = 72, // gets texture size information
RawBufferLoad = 139, // reads from a raw buffer and structured buffer
RawBufferStore = 140, // writes to a RWByteAddressBuffer or RWStructuredBuffer
TextureLoad = 66, // reads texel data without any filtering or sampling
TextureStore = 67, // reads texel data without any filtering or sampling
TextureStoreSample = 225, // stores texel data at specified sample index
// Sampler Feedback
WriteSamplerFeedback =
174, // updates a feedback texture for a sampling operation
WriteSamplerFeedbackBias = 175, // updates a feedback texture for a sampling
// operation with a bias on the mipmap level
WriteSamplerFeedbackGrad = 177, // updates a feedback texture for a sampling
// operation with explicit gradients
WriteSamplerFeedbackLevel = 176, // updates a feedback texture for a sampling
// operation with a mipmap-level offset
// Synchronization
AtomicBinOp = 78, // performs an atomic operation on two operands
AtomicCompareExchange = 79, // atomic compare and exchange to memory
Barrier = 80, // inserts a memory barrier in the shader
BarrierByMemoryHandle =
245, // Request a barrier for just the memory used by the specified object
BarrierByMemoryType = 244, // Request a barrier for a set of memory types
// and/or thread group execution sync
BarrierByNodeRecordHandle =
246, // Request a barrier for just the memory used by the node record
// Temporary, indexable, input, output registers
LoadInput = 4, // Loads the value from shader input
MinPrecXRegLoad = 2, // Helper load operation for minprecision
MinPrecXRegStore = 3, // Helper store operation for minprecision
StoreOutput = 5, // Stores the value to shader output
TempRegLoad = 0, // Helper load operation
TempRegStore = 1, // Helper store operation
// Tertiary float
FMad = 46, // floating point multiply & add
Fma = 47, // fused multiply-add
// Tertiary int
IMad = 48, // Signed integer multiply & add
Ibfe = 51, // Integer bitfield extract
Msad = 50, // masked Sum of Absolute Differences.
// Tertiary uint
UMad = 49, // Unsigned integer multiply & add
Ubfe = 52, // Unsigned integer bitfield extract
// Unary float - rounding
Round_ne = 26, // floating-point round to integral float.
Round_ni = 27, // floating-point round to integral float.
Round_pi = 28, // floating-point round to integral float.
Round_z = 29, // floating-point round to integral float.
// Unary float
Acos = 15, // Returns the arccosine of the specified value. Input should be a
// floating-point value within the range of -1 to 1.
Asin = 16, // Returns the arccosine of the specified value. Input should be a
// floating-point value within the range of -1 to 1
Atan = 17, // Returns the arctangent of the specified value. The return value
// is within the range of -PI/2 to PI/2.
Cos = 12, // returns cosine(theta) for theta in radians.
Exp = 21, // returns 2^exponent
FAbs = 6, // returns the absolute value of the input value.
Frc = 22, // extract fracitonal component.
Hcos = 18, // returns the hyperbolic cosine of the specified value.
Hsin = 19, // returns the hyperbolic sine of the specified value.
Htan = 20, // returns the hyperbolic tangent of the specified value.
IsFinite = 10, // Returns true if x is finite, false otherwise.
IsInf = 9, // Returns true if x is +INF or -INF, false otherwise.
IsNaN = 8, // Returns true if x is NAN or QNAN, false otherwise.
IsNormal = 11, // returns IsNormal
Log = 23, // returns log base 2.
Rsqrt = 25, // returns reciprocal square root (1 / sqrt(src)
Saturate = 7, // clamps the result of a single or double precision floating
// point value to [0.0f...1.0f]
Sin = 13, // returns sine(theta) for theta in radians.
Sqrt = 24, // returns square root
Tan = 14, // returns tan(theta) for theta in radians.
// Unary int
Bfrev = 30, // Reverses the order of the bits.
Countbits = 31, // Counts the number of bits in the input integer.
FirstbitLo = 32, // Returns the location of the first set bit starting from
// the lowest order bit and working upward.
FirstbitSHi = 34, // Returns the location of the first set bit from the
// highest order bit based on the sign.
// Unary uint
FirstbitHi = 33, // Returns the location of the first set bit starting from
// the highest order bit and working downward.
// Unpacking intrinsics
Unpack4x8 = 219, // unpacks 4 8-bit signed or unsigned values into int32 or
// int16 vector
// Wave
WaveActiveAllEqual = 115, // returns 1 if all the lanes have the same value
WaveActiveBallot = 116, // returns a struct with a bit set for each lane where
// the condition is true
WaveActiveBit = 120, // returns the result of the operation across all lanes
WaveActiveOp = 119, // returns the result the operation across waves
WaveAllBitCount = 135, // returns the count of bits set to 1 across the wave
WaveAllTrue = 114, // returns 1 if all the lanes evaluate the value to true
WaveAnyTrue = 113, // returns 1 if any of the lane evaluates the value to true
WaveGetLaneCount = 112, // returns the number of lanes in the wave
WaveGetLaneIndex = 111, // returns the index of the current lane in the wave
WaveIsFirstLane = 110, // returns 1 for the first lane in the wave
WaveMatch =
165, // returns the bitmask of active lanes that have the same value
WaveMultiPrefixBitCount = 167, // returns the count of bits set to 1 on groups
// of lanes identified by a bitmask
WaveMultiPrefixOp = 166, // returns the result of the operation on groups of
// lanes identified by a bitmask
WavePrefixBitCount = 136, // returns the count of bits set to 1 on prior lanes
WavePrefixOp = 121, // returns the result of the operation on prior lanes
WaveReadLaneAt = 117, // returns the value from the specified lane
WaveReadLaneFirst = 118, // returns the value from the first lane
// Work Graph intrinsics
FinishedCrossGroupSharing = 243, // returns true if the current thread group
// is the last to access the input
GetInputRecordCount = 242, // returns the number of records that have been
// coalesced into the current thread group
GetRemainingRecursionLevels =
253, // returns how many levels of recursion remain
IncrementOutputCount =
240, // Select the next logical output count for an EmptyNodeOutput for
// the whole group or per thread.
NodeOutputIsValid = 252, // returns true if the specified output node is
// present in the work graph
OutputComplete =
241, // indicates all outputs for a given records are complete
NumOpCodes_Dxil_1_0 = 137,
NumOpCodes_Dxil_1_1 = 139,
NumOpCodes_Dxil_1_2 = 141,
NumOpCodes_Dxil_1_3 = 162,
NumOpCodes_Dxil_1_4 = 165,
NumOpCodes_Dxil_1_5 = 216,
NumOpCodes_Dxil_1_6 = 222,
NumOpCodes_Dxil_1_7 = 226,
NumOpCodes_Dxil_1_8 = 258,
NumOpCodes = 258 // exclusive last value of enumeration
};
// OPCODE-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('OPCODECLASS-ENUM')>hctdb_instrhelp.get_enum_decl("OpCodeClass")</py>*/
// clang-format on
// OPCODECLASS-ENUM:BEGIN
// Groups for DXIL operations with equivalent function templates
enum class OpCodeClass : unsigned {
//
Reserved,
// Amplification shader instructions
DispatchMesh,
// AnyHit Terminals
AcceptHitAndEndSearch,
IgnoreHit,
// Binary uint with carry or borrow
BinaryWithCarryOrBorrow,
// Binary uint with two outputs
BinaryWithTwoOuts,
// Binary uint
Binary,
// Bitcasts with different sizes
BitcastF16toI16,
BitcastF32toI32,
BitcastF64toI64,
BitcastI16toF16,
BitcastI32toF32,
BitcastI64toF64,
// Comparison Samples
SampleCmpBias,
SampleCmpGrad,
// Compute/Mesh/Amplification/Node shader
FlattenedThreadIdInGroup,
GroupId,
ThreadId,
ThreadIdInGroup,
// Create/Annotate Node Handles
AllocateNodeOutputRecords,
AnnotateNodeHandle,
AnnotateNodeRecordHandle,
CreateNodeInputRecordHandle,
IndexNodeHandle,
createNodeOutputHandle,
// Derivatives
CalculateLOD,
Unary,
// Domain and hull shader
LoadOutputControlPoint,
LoadPatchConstant,
// Domain shader
DomainLocation,
// Dot product with accumulate
Dot2AddHalf,
Dot4AddPacked,
// Dot
Dot2,
Dot3,
Dot4,
// Double precision
LegacyDoubleToFloat,
LegacyDoubleToSInt32,
LegacyDoubleToUInt32,
MakeDouble,
SplitDouble,
// Extended Command Information
StartInstanceLocation,
StartVertexLocation,
// Geometry shader
CutStream,
EmitStream,
EmitThenCutStream,
GSInstanceID,
// Get Pointer to Node Record in Address Space 6
GetNodeRecordPtr,
// Get handle from heap
AnnotateHandle,
CreateHandleFromBinding,
CreateHandleFromHeap,
// Graphics shader
ViewID,
// Helper Lanes
IsHelperLane,
// Hull shader
OutputControlPointID,
StorePatchConstant,
// Hull, Domain and Geometry shaders
PrimitiveID,
// Indirect Shader Invocation
CallShader,
ReportHit,
TraceRay,
// Inline Ray Query
AllocateRayQuery,
RayQuery_Abort,
RayQuery_CommitNonOpaqueTriangleHit,
RayQuery_CommitProceduralPrimitiveHit,
RayQuery_Proceed,
RayQuery_StateMatrix,
RayQuery_StateScalar,
RayQuery_StateVector,
RayQuery_TraceRayInline,
// LLVM Instructions
LlvmInst,
// Legacy floating-point
LegacyF16ToF32,
LegacyF32ToF16,
// Library create handle from resource struct (like HL intrinsic)
CreateHandleForLib,
// Mesh shader instructions
EmitIndices,
GetMeshPayload,
SetMeshOutputCounts,
StorePrimitiveOutput,
StoreVertexOutput,
// Other
CycleCounterLegacy,
// Packing intrinsics
Pack4x8,
// Pixel shader
AttributeAtVertex,
Coverage,
Discard,
EvalCentroid,
EvalSampleIndex,
EvalSnapped,
InnerCoverage,
SampleIndex,
// Quad Wave Ops
QuadOp,
QuadReadLaneAt,
QuadVote,
// Quaternary
Quaternary,
// Ray Dispatch Arguments
DispatchRaysDimensions,
DispatchRaysIndex,
// Ray Transforms
ObjectToWorld,
WorldToObject,
// Ray Vectors
WorldRayDirection,
WorldRayOrigin,
// Ray object space Vectors
ObjectRayDirection,
ObjectRayOrigin,
// RayT
RayTCurrent,
RayTMin,
// Raytracing hit uint System Values
HitKind,
// Raytracing object space uint System Values, raytracing tier 1.1
GeometryIndex,
// Raytracing object space uint System Values
InstanceID,
InstanceIndex,
PrimitiveIndex,
// Raytracing uint System Values
RayFlags,
// Resources - gather
TextureGather,
TextureGatherCmp,
TextureGatherRaw,
// Resources - sample
RenderTargetGetSampleCount,
RenderTargetGetSamplePosition,
Sample,
SampleBias,
SampleCmp,
SampleCmpLevel,
SampleCmpLevelZero,
SampleGrad,
SampleLevel,
Texture2DMSGetSamplePosition,
// Resources
BufferLoad,
BufferStore,
BufferUpdateCounter,
CBufferLoad,
CBufferLoadLegacy,
CheckAccessFullyMapped,
CreateHandle,
GetDimensions,
RawBufferLoad,
RawBufferStore,
TextureLoad,
TextureStore,
TextureStoreSample,
// Sampler Feedback
WriteSamplerFeedback,
WriteSamplerFeedbackBias,
WriteSamplerFeedbackGrad,
WriteSamplerFeedbackLevel,
// Synchronization
AtomicBinOp,
AtomicCompareExchange,
Barrier,
BarrierByMemoryHandle,
BarrierByMemoryType,
BarrierByNodeRecordHandle,
// Temporary, indexable, input, output registers
LoadInput,
MinPrecXRegLoad,
MinPrecXRegStore,
StoreOutput,
TempRegLoad,
TempRegStore,
// Tertiary uint
Tertiary,
// Unary float
IsSpecialFloat,
// Unary int
UnaryBits,
// Unpacking intrinsics
Unpack4x8,
// Wave
WaveActiveAllEqual,
WaveActiveBallot,
WaveActiveBit,
WaveActiveOp,
WaveAllOp,
WaveAllTrue,
WaveAnyTrue,
WaveGetLaneCount,
WaveGetLaneIndex,
WaveIsFirstLane,
WaveMatch,
WaveMultiPrefixBitCount,
WaveMultiPrefixOp,
WavePrefixOp,
WaveReadLaneAt,
WaveReadLaneFirst,
// Work Graph intrinsics
FinishedCrossGroupSharing,
GetInputRecordCount,
GetRemainingRecursionLevels,
IncrementOutputCount,
NodeOutputIsValid,
OutputComplete,
NumOpClasses_Dxil_1_0 = 93,
NumOpClasses_Dxil_1_1 = 95,
NumOpClasses_Dxil_1_2 = 97,
NumOpClasses_Dxil_1_3 = 118,
NumOpClasses_Dxil_1_4 = 120,
NumOpClasses_Dxil_1_5 = 143,
NumOpClasses_Dxil_1_6 = 149,
NumOpClasses_Dxil_1_7 = 153,
NumOpClasses_Dxil_1_8 = 174,
NumOpClasses = 174 // exclusive last value of enumeration
};
// OPCODECLASS-ENUM:END
// Operand Index for every OpCodeClass.
namespace OperandIndex {
// Opcode is always operand 0.
const unsigned kOpcodeIdx = 0;
// Unary operators.
const unsigned kUnarySrc0OpIdx = 1;
// Binary operators.
const unsigned kBinarySrc0OpIdx = 1;
const unsigned kBinarySrc1OpIdx = 2;
// Trinary operators.
const unsigned kTrinarySrc0OpIdx = 1;
const unsigned kTrinarySrc1OpIdx = 2;
const unsigned kTrinarySrc2OpIdx = 3;
// LoadInput.
const unsigned kLoadInputIDOpIdx = 1;
const unsigned kLoadInputRowOpIdx = 2;
const unsigned kLoadInputColOpIdx = 3;
const unsigned kLoadInputVertexIDOpIdx = 4;
// StoreOutput, StoreVertexOutput, StorePrimitiveOutput
const unsigned kStoreOutputIDOpIdx = 1;
const unsigned kStoreOutputRowOpIdx = 2;
const unsigned kStoreOutputColOpIdx = 3;
const unsigned kStoreOutputValOpIdx = 4;
const unsigned kStoreOutputVPIDOpIdx = 5;
// DomainLocation.
const unsigned kDomainLocationColOpIdx = 1;
// BufferLoad.
const unsigned kBufferLoadHandleOpIdx = 1;
const unsigned kBufferLoadCoord0OpIdx = 2;
const unsigned kBufferLoadCoord1OpIdx = 3;
// BufferStore.
const unsigned kBufferStoreHandleOpIdx = 1;
const unsigned kBufferStoreCoord0OpIdx = 2;
const unsigned kBufferStoreCoord1OpIdx = 3;
const unsigned kBufferStoreVal0OpIdx = 4;
const unsigned kBufferStoreVal1OpIdx = 5;
const unsigned kBufferStoreVal2OpIdx = 6;
const unsigned kBufferStoreVal3OpIdx = 7;
const unsigned kBufferStoreMaskOpIdx = 8;
// RawBufferLoad.
const unsigned kRawBufferLoadHandleOpIdx = 1;
const unsigned kRawBufferLoadIndexOpIdx = 2;
const unsigned kRawBufferLoadElementOffsetOpIdx = 3;
const unsigned kRawBufferLoadMaskOpIdx = 4;
const unsigned kRawBufferLoadAlignmentOpIdx = 5;
// RawBufferStore
const unsigned kRawBufferStoreHandleOpIdx = 1;
const unsigned kRawBufferStoreIndexOpIdx = 2;
const unsigned kRawBufferStoreElementOffsetOpIdx = 3;
const unsigned kRawBufferStoreVal0OpIdx = 4;
const unsigned kRawBufferStoreVal1OpIdx = 5;
const unsigned kRawBufferStoreVal2OpIdx = 6;
const unsigned kRawBufferStoreVal3OpIdx = 7;
const unsigned kRawBufferStoreMaskOpIdx = 8;
const unsigned kRawBufferStoreAlignmentOpIdx = 8;
// TextureStore.
const unsigned kTextureStoreHandleOpIdx = 1;
const unsigned kTextureStoreCoord0OpIdx = 2;
const unsigned kTextureStoreCoord1OpIdx = 3;
const unsigned kTextureStoreCoord2OpIdx = 4;
const unsigned kTextureStoreVal0OpIdx = 5;
const unsigned kTextureStoreVal1OpIdx = 6;
const unsigned kTextureStoreVal2OpIdx = 7;
const unsigned kTextureStoreVal3OpIdx = 8;
const unsigned kTextureStoreMaskOpIdx = 9;
// TextureGather.
const unsigned kTextureGatherTexHandleOpIdx = 1;
const unsigned kTextureGatherSamplerHandleOpIdx = 2;
const unsigned kTextureGatherCoord0OpIdx = 3;
const unsigned kTextureGatherCoord1OpIdx = 4;
const unsigned kTextureGatherCoord2OpIdx = 5;
const unsigned kTextureGatherCoord3OpIdx = 6;
const unsigned kTextureGatherOffset0OpIdx = 7;
const unsigned kTextureGatherOffset1OpIdx = 8;
const unsigned kTextureGatherChannelOpIdx = 9;
// TextureGatherCmp.
const unsigned kTextureGatherCmpCmpValOpIdx = 11;
// TextureSample.
const unsigned kTextureSampleTexHandleOpIdx = 1;
const unsigned kTextureSampleSamplerHandleOpIdx = 2;
const unsigned kTextureSampleCoord0OpIdx = 3;
const unsigned kTextureSampleCoord1OpIdx = 4;
const unsigned kTextureSampleCoord2OpIdx = 5;
const unsigned kTextureSampleCoord3OpIdx = 6;
const unsigned kTextureSampleOffset0OpIdx = 7;
const unsigned kTextureSampleOffset1OpIdx = 8;
const unsigned kTextureSampleOffset2OpIdx = 9;
const unsigned kTextureSampleClampOpIdx = 10;
// TextureLoad.
const unsigned kTextureLoadOffset0OpIdx = 6;
const unsigned kTextureLoadOffset1OpIdx = 8;
const unsigned kTextureLoadOffset2OpIdx = 9;
// AtomicBinOp.
const unsigned kAtomicBinOpHandleOpIdx = 1;
const unsigned kAtomicBinOpCoord0OpIdx = 3;
const unsigned kAtomicBinOpCoord1OpIdx = 4;
const unsigned kAtomicBinOpCoord2OpIdx = 5;
// AtomicCmpExchange.
const unsigned kAtomicCmpExchangeCoord0OpIdx = 2;
const unsigned kAtomicCmpExchangeCoord1OpIdx = 3;
const unsigned kAtomicCmpExchangeCoord2OpIdx = 4;
// CreateHandle
const unsigned kCreateHandleResClassOpIdx = 1;
const unsigned kCreateHandleResIDOpIdx = 2;
const unsigned kCreateHandleResIndexOpIdx = 3;
const unsigned kCreateHandleIsUniformOpIdx = 4;
// CreateHandleFromResource
const unsigned kCreateHandleForLibResOpIdx = 1;
// CreateHandleFromHeap
const unsigned kCreateHandleFromHeapHeapIndexOpIdx = 1;
const unsigned kCreateHandleFromHeapSamplerHeapOpIdx = 2;
const unsigned kCreateHandleFromHeapNonUniformIndexOpIdx = 3;
// CreateHandleFromBinding
const unsigned kCreateHandleFromBindingResIndexOpIdx = 2;
// TraceRay
const unsigned kTraceRayRayDescOpIdx = 7;
const unsigned kTraceRayPayloadOpIdx = 15;
const unsigned kTraceRayNumOp = 16;
// TraceRayInline
const unsigned kTraceRayInlineRayDescOpIdx = 5;
const unsigned kTraceRayInlineNumOp = 13;
// Emit/Cut
const unsigned kStreamEmitCutIDOpIdx = 1;
// StoreVectorOutput/StorePrimitiveOutput.
const unsigned kMSStoreOutputIDOpIdx = 1;
const unsigned kMSStoreOutputRowOpIdx = 2;
const unsigned kMSStoreOutputColOpIdx = 3;
const unsigned kMSStoreOutputVIdxOpIdx = 4;
const unsigned kMSStoreOutputValOpIdx = 5;
// TODO: add operand index for all the OpCodeClass.
} // namespace OperandIndex
// Atomic binary operation kind.
enum class AtomicBinOpCode : unsigned {
Add,
And,
Or,
Xor,
IMin,
IMax,
UMin,
UMax,
Exchange,
Invalid // Must be last.
};
// Barrier/fence modes.
enum class BarrierMode : unsigned {
Invalid = 0,
SyncThreadGroup = 0x00000001,
UAVFenceGlobal = 0x00000002,
UAVFenceThreadGroup = 0x00000004,
TGSMFence = 0x00000008,
};
// Address space.
const unsigned kDefaultAddrSpace = 0;
const unsigned kDeviceMemoryAddrSpace = 1;
const unsigned kCBufferAddrSpace = 2;
const unsigned kTGSMAddrSpace = 3;
const unsigned kGenericPointerAddrSpace = 4;
const unsigned kImmediateCBufferAddrSpace = 5;
const unsigned kNodeRecordAddrSpace = 6;
// Input primitive, must match D3D_PRIMITIVE
enum class InputPrimitive : unsigned {
Undefined = 0,
Point = 1,
Line = 2,
Triangle = 3,
Reserved4 = 4,
Reserved5 = 5,
LineWithAdjacency = 6,
TriangleWithAdjacency = 7,
ControlPointPatch1 = 8,
ControlPointPatch2 = 9,
ControlPointPatch3 = 10,
ControlPointPatch4 = 11,
ControlPointPatch5 = 12,
ControlPointPatch6 = 13,
ControlPointPatch7 = 14,
ControlPointPatch8 = 15,
ControlPointPatch9 = 16,
ControlPointPatch10 = 17,
ControlPointPatch11 = 18,
ControlPointPatch12 = 19,
ControlPointPatch13 = 20,
ControlPointPatch14 = 21,
ControlPointPatch15 = 22,
ControlPointPatch16 = 23,
ControlPointPatch17 = 24,
ControlPointPatch18 = 25,
ControlPointPatch19 = 26,
ControlPointPatch20 = 27,
ControlPointPatch21 = 28,
ControlPointPatch22 = 29,
ControlPointPatch23 = 30,
ControlPointPatch24 = 31,
ControlPointPatch25 = 32,
ControlPointPatch26 = 33,
ControlPointPatch27 = 34,
ControlPointPatch28 = 35,
ControlPointPatch29 = 36,
ControlPointPatch30 = 37,
ControlPointPatch31 = 38,
ControlPointPatch32 = 39,
LastEntry,
};
// Primitive topology, must match D3D_PRIMITIVE_TOPOLOGY
enum class PrimitiveTopology : unsigned {
Undefined = 0,
PointList = 1,
LineList = 2,
LineStrip = 3,
TriangleList = 4,
TriangleStrip = 5,
LastEntry,
};
// Must match D3D_TESSELLATOR_DOMAIN
enum class TessellatorDomain {
Undefined = 0,
IsoLine = 1,
Tri = 2,
Quad = 3,
LastEntry,
};
// Must match D3D_TESSELLATOR_OUTPUT_PRIMITIVE
enum class TessellatorOutputPrimitive {
Undefined = 0,
Point = 1,
Line = 2,
TriangleCW = 3,
TriangleCCW = 4,
LastEntry,
};
enum class MeshOutputTopology {
Undefined = 0,
Line = 1,
Triangle = 2,
LastEntry,
};
// Tessellator partitioning, must match D3D_TESSELLATOR_PARTITIONING
enum class TessellatorPartitioning : unsigned {
Undefined = 0,
Integer,
Pow2,
FractionalOdd,
FractionalEven,
LastEntry,
};
enum class NodeLaunchType {
Invalid = 0,
Broadcasting,
Coalescing,
Thread,
Reserved_Mesh,
LastEntry
};
enum class NodeIOFlags : uint32_t {
None = 0x0,
Input = 0x1,
Output = 0x2,
ReadWrite = 0x4,
EmptyRecord = 0x8, // EmptyNodeOutput[Array], EmptyNodeInput
NodeArray = 0x10, // NodeOutputArray, EmptyNodeOutputArray
// Record granularity (enum in 2 bits)
ThreadRecord = 0x20, // [RW]ThreadNodeInputRecord, ThreadNodeOutputRecords
GroupRecord = 0x40, // [RW]GroupNodeInputRecord, GroupNodeOutputRecords
DispatchRecord = 0x60, // [RW]DispatchNodeInputRecord
RecordGranularityMask = 0x60,
NodeIOKindMask = 0x7F,
TrackRWInputSharing = 0x100, // TrackRWInputSharing tracked on all non-empty
// input/output record/node types
GloballyCoherent = 0x200, // applies to RWDispatchNodeInputRecord
// Mask for node/record properties beyond NodeIOKind
RecordFlagsMask = 0x300,
NodeFlagsMask = 0x100,
};
enum class NodeIOKind : uint32_t {
Invalid = 0,
EmptyInput =
(uint32_t)NodeIOFlags::EmptyRecord | (uint32_t)NodeIOFlags::Input,
NodeOutput = (uint32_t)NodeIOFlags::ReadWrite | (uint32_t)NodeIOFlags::Output,
NodeOutputArray = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Output |
(uint32_t)NodeIOFlags::NodeArray,
EmptyOutput =
(uint32_t)NodeIOFlags::EmptyRecord | (uint32_t)NodeIOFlags::Output,
EmptyOutputArray = (uint32_t)NodeIOFlags::EmptyRecord |
(uint32_t)NodeIOFlags::Output |
(uint32_t)NodeIOFlags::NodeArray,
DispatchNodeInputRecord =
(uint32_t)NodeIOFlags::Input | (uint32_t)NodeIOFlags::DispatchRecord,
GroupNodeInputRecords =
(uint32_t)NodeIOFlags::Input | (uint32_t)NodeIOFlags::GroupRecord,
ThreadNodeInputRecord =
(uint32_t)NodeIOFlags::Input | (uint32_t)NodeIOFlags::ThreadRecord,
RWDispatchNodeInputRecord = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Input |
(uint32_t)NodeIOFlags::DispatchRecord,
RWGroupNodeInputRecords = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Input |
(uint32_t)NodeIOFlags::GroupRecord,
RWThreadNodeInputRecord = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Input |
(uint32_t)NodeIOFlags::ThreadRecord,
GroupNodeOutputRecords = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Output |
(uint32_t)NodeIOFlags::GroupRecord,
ThreadNodeOutputRecords = (uint32_t)NodeIOFlags::ReadWrite |
(uint32_t)NodeIOFlags::Output |
(uint32_t)NodeIOFlags::ThreadRecord,
};
// Kind of quad-level operation
enum class QuadOpKind {
ReadAcrossX = 0, // returns the value from the other lane in the quad in the
// horizontal direction
ReadAcrossY = 1, // returns the value from the other lane in the quad in the
// vertical direction
ReadAcrossDiagonal = 2, // returns the value from the lane across the quad in
// horizontal and vertical direction
};
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('WAVEBITOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveBitOpKind")</py>*/
// clang-format on
// WAVEBITOPKIND-ENUM:BEGIN
// Kind of bitwise cross-lane operation
enum class WaveBitOpKind : unsigned {
And = 0, // bitwise and of values
Or = 1, // bitwise or of values
Xor = 2, // bitwise xor of values
};
// WAVEBITOPKIND-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('WAVEOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveOpKind")</py>*/
// clang-format on
// WAVEOPKIND-ENUM:BEGIN
// Kind of cross-lane operation
enum class WaveOpKind : unsigned {
Max = 3, // maximum value
Min = 2, // minimum value
Product = 1, // product of values
Sum = 0, // sum of values
};
// WAVEOPKIND-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('WAVEMULTIPREFIXOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("WaveMultiPrefixOpKind")</py>*/
// clang-format on
// WAVEMULTIPREFIXOPKIND-ENUM:BEGIN
// Kind of cross-lane for multi-prefix operation
enum class WaveMultiPrefixOpKind : unsigned {
And = 1, // bitwise and of values
Or = 2, // bitwise or of values
Product = 4, // product of values
Sum = 0, // sum of values
Xor = 3, // bitwise xor of values
};
// WAVEMULTIPREFIXOPKIND-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('SIGNEDOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("SignedOpKind")</py>*/
// clang-format on
// SIGNEDOPKIND-ENUM:BEGIN
// Sign vs. unsigned operands for operation
enum class SignedOpKind : unsigned {
Signed = 0, // signed integer or floating-point operands
Unsigned = 1, // unsigned integer operands
};
// SIGNEDOPKIND-ENUM:END
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('QUADVOTEOPKIND-ENUM')>hctdb_instrhelp.get_enum_decl("QuadVoteOpKind")</py>*/
// clang-format on
// QUADVOTEOPKIND-ENUM:BEGIN
// Kind of cross-quad vote operation
enum class QuadVoteOpKind : unsigned {
All = 1, // true if all conditions are true in this quad
Any = 0, // true if any condition is true in this quad
};
// QUADVOTEOPKIND-ENUM:END
// Kind of control flow hint
enum class ControlFlowHint : unsigned {
Undefined = 0,
Branch = 1,
Flatten = 2,
FastOpt = 3,
AllowUavCondition = 4,
ForceCase = 5,
Call = 6,
// Loop and Unroll is using llvm.loop.unroll Metadata.
LastEntry,
};
// XYZW component mask.
const uint8_t kCompMask_X = 0x1;
const uint8_t kCompMask_Y = 0x2;
const uint8_t kCompMask_Z = 0x4;
const uint8_t kCompMask_W = 0x8;
const uint8_t kCompMask_All = 0xF;
enum class LowPrecisionMode {
Undefined = 0,
UseMinPrecision,
UseNativeLowPrecision
};
// Corresponds to RAY_FLAG_* in HLSL
enum class RayFlag : uint32_t {
None = 0x00,
ForceOpaque = 0x01,
ForceNonOpaque = 0x02,
AcceptFirstHitAndEndSearch = 0x04,
SkipClosestHitShader = 0x08,
CullBackFacingTriangles = 0x10,
CullFrontFacingTriangles = 0x20,
CullOpaque = 0x40,
CullNonOpaque = 0x80,
SkipTriangles = 0x100,
SkipProceduralPrimitives = 0x200,
};
// Packing/unpacking intrinsics
enum class UnpackMode : uint8_t {
Unsigned = 0, // not sign extended
Signed = 1, // sign extended
};
enum class PackMode : uint8_t {
Trunc = 0, // Pack low bits, drop the rest
UClamp = 1, // Unsigned clamp - [0, 255] for 8-bits
SClamp = 2, // Signed clamp - [-128, 127] for 8-bits
};
// Corresponds to HIT_KIND_* in HLSL
enum class HitKind : uint8_t {
None = 0x00,
TriangleFrontFace = 0xFE,
TriangleBackFace = 0xFF,
};
enum class SamplerFeedbackType : uint8_t {
MinMip = 0,
MipRegionUsed = 1,
LastEntry = 2
};
// Corresponds to MEMORY_TYPE_FLAG enums in HLSL
enum class MemoryTypeFlag : uint32_t {
UavMemory = 0x00000001, // UAV_MEMORY
GroupSharedMemory = 0x00000002, // GROUP_SHARED_MEMORY
NodeInputMemory = 0x00000004, // NODE_INPUT_MEMORY
NodeOutputMemory = 0x00000008, // NODE_OUTPUT_MEMORY
AllMemory = 0x0000000F, // ALL_MEMORY
ValidMask = 0x0000000F,
NodeFlags = NodeInputMemory | NodeOutputMemory,
LegacyFlags = UavMemory | GroupSharedMemory,
GroupFlags = GroupSharedMemory,
};
// Corresponds to SEMANTIC_FLAG enums in HLSL
enum class BarrierSemanticFlag : uint32_t {
GroupSync = 0x00000001, // GROUP_SYNC
GroupScope = 0x00000002, // GROUP_SCOPE
DeviceScope = 0x00000004, // DEVICE_SCOPE
ValidMask = 0x00000007,
GroupFlags = GroupSync | GroupScope,
};
// Constant for Container.
const uint8_t DxilProgramSigMaskX = 1;
const uint8_t DxilProgramSigMaskY = 2;
const uint8_t DxilProgramSigMaskZ = 4;
const uint8_t DxilProgramSigMaskW = 8;
// DFCC_FeatureInfo is a uint64_t value with these flags.
const uint64_t ShaderFeatureInfo_Doubles = 0x0001;
const uint64_t
ShaderFeatureInfo_ComputeShadersPlusRawAndStructuredBuffersViaShader4X =
0x0002;
const uint64_t ShaderFeatureInfo_UAVsAtEveryStage = 0x0004;
const uint64_t ShaderFeatureInfo_64UAVs = 0x0008;
const uint64_t ShaderFeatureInfo_MinimumPrecision = 0x0010;
const uint64_t ShaderFeatureInfo_11_1_DoubleExtensions = 0x0020;
const uint64_t ShaderFeatureInfo_11_1_ShaderExtensions = 0x0040;
const uint64_t ShaderFeatureInfo_LEVEL9ComparisonFiltering = 0x0080;
const uint64_t ShaderFeatureInfo_TiledResources = 0x0100;
const uint64_t ShaderFeatureInfo_StencilRef = 0x0200;
const uint64_t ShaderFeatureInfo_InnerCoverage = 0x0400;
const uint64_t ShaderFeatureInfo_TypedUAVLoadAdditionalFormats = 0x0800;
const uint64_t ShaderFeatureInfo_ROVs = 0x1000;
const uint64_t
ShaderFeatureInfo_ViewportAndRTArrayIndexFromAnyShaderFeedingRasterizer =
0x2000;
const uint64_t ShaderFeatureInfo_WaveOps = 0x4000;
const uint64_t ShaderFeatureInfo_Int64Ops = 0x8000;
// SM 6.1+
const uint64_t ShaderFeatureInfo_ViewID = 0x10000;
const uint64_t ShaderFeatureInfo_Barycentrics = 0x20000;
// SM 6.2+
const uint64_t ShaderFeatureInfo_NativeLowPrecision = 0x40000;
// SM 6.4+
const uint64_t ShaderFeatureInfo_ShadingRate = 0x80000;
// SM 6.5+
const uint64_t ShaderFeatureInfo_Raytracing_Tier_1_1 = 0x100000;
const uint64_t ShaderFeatureInfo_SamplerFeedback = 0x200000;
// SM 6.6+
const uint64_t ShaderFeatureInfo_AtomicInt64OnTypedResource = 0x400000;
const uint64_t ShaderFeatureInfo_AtomicInt64OnGroupShared = 0x800000;
const uint64_t ShaderFeatureInfo_DerivativesInMeshAndAmpShaders = 0x1000000;
const uint64_t ShaderFeatureInfo_ResourceDescriptorHeapIndexing = 0x2000000;
const uint64_t ShaderFeatureInfo_SamplerDescriptorHeapIndexing = 0x4000000;
const uint64_t ShaderFeatureInfo_AtomicInt64OnHeapResource = 0x10000000;
// SM 6.7+
const uint64_t ShaderFeatureInfo_AdvancedTextureOps = 0x20000000;
const uint64_t ShaderFeatureInfo_WriteableMSAATextures = 0x40000000;
// SM 6.8+
const uint64_t ShaderFeatureInfo_SampleCmpGradientOrBias = 0x80000000;
const uint64_t ShaderFeatureInfo_ExtendedCommandInfo = 0x100000000;
// Experimental SM 6.9+ - Reserved, not yet supported.
const uint64_t ShaderFeatureInfo_Reserved = 0x8000000;
// Maximum count without rolling over into another 64-bit field is 40,
// so the last flag we can use for a feature requirement is: 0x8000000000
// This is because of the following set of flags, considered optional
// and ignored by the runtime if not recognized:
// D3D11_OPTIONAL_FEATURE_FLAGS 0x7FFFFF0000000000
const unsigned ShaderFeatureInfoCount = 33;
static_assert(ShaderFeatureInfoCount <= 40,
"ShaderFeatureInfo flags must fit within the first 40 bits; "
"after that we need to expand the FeatureInfo blob part and "
"start defining a new set of flags for ShaderFeatureInfo2.");
// OptFeatureInfo flags in higher bits of DFCC_FeatureInfo uint64_t value.
// This section is for flags that do not necessarily indicate a required
// feature, but are used to indicate something about the shader.
// Some of these flags may not actually show up in DFCC_FeatureInfo, instead
// only being used in intermediate feature info and in RDAT's FeatureInfo.
// Create flag here for any derivative use. This allows call-graph validation
// in the runtime to detect misuse of derivatives for an entry point that cannot
// support it, or to determine when the flag
// ShaderFeatureInfo_DerivativesInMeshAndAmpShaders is required.
const uint64_t OptFeatureInfo_UsesDerivatives = 0x0000010000000000ULL;
// OptFeatureInfo_RequiresGroup tracks whether a function requires a visible
// group that supports things like groupshared memory and group sync.
const uint64_t OptFeatureInfo_RequiresGroup = 0x0000020000000000ULL;
const uint64_t OptFeatureInfoShift = 40;
const unsigned OptFeatureInfoCount = 2;
static_assert(OptFeatureInfoCount <= 23,
"OptFeatureInfo flags must fit in 23 bits; after that we need to "
"expand the FeatureInfo blob part and start defining a new set "
"of flags for OptFeatureInfo2.");
// DxilSubobjectType must match D3D12_STATE_SUBOBJECT_TYPE, with
// certain values reserved, since they cannot be used from Dxil.
enum class SubobjectKind : uint32_t {
StateObjectConfig = 0,
GlobalRootSignature = 1,
LocalRootSignature = 2,
// 3-7 are reserved (not supported in Dxil)
SubobjectToExportsAssociation = 8,
RaytracingShaderConfig = 9,
RaytracingPipelineConfig = 10,
HitGroup = 11,
RaytracingPipelineConfig1 = 12,
NumKinds // aka D3D12_STATE_SUBOBJECT_TYPE_MAX_VALID
};
inline bool IsValidSubobjectKind(SubobjectKind kind) {
return (kind < SubobjectKind::NumKinds &&
(kind <= SubobjectKind::LocalRootSignature ||
kind >= SubobjectKind::SubobjectToExportsAssociation));
}
enum class StateObjectFlags : uint32_t {
AllowLocalDependenciesOnExternalDefinitions = 0x1,
AllowExternalDependenciesOnLocalDefinitions = 0x2,
AllowStateObjectAdditions = 0x4,
ValidMask_1_4 = 0x3,
ValidMask = 0x7,
};
enum class HitGroupType : uint32_t {
Triangle = 0x0,
ProceduralPrimitive = 0x1,
LastEntry,
};
enum class RaytracingPipelineFlags : uint32_t {
None = 0x0,
SkipTriangles = 0x100,
SkipProceduralPrimitives = 0x200,
ValidMask = 0x300,
};
enum class CommittedStatus : uint32_t {
CommittedNothing = 0,
CommittedTriangleHit = 1,
CommittedProceduralPrimitiveHit = 2,
};
enum class CandidateType : uint32_t {
CandidateNonOpaqueTriangle = 0,
CandidateProceduralPrimitive = 1,
};
enum class PayloadAccessQualifier : uint32_t {
NoAccess = 0,
Read = 1,
Write = 2,
ReadWrite = 3
};
enum class PayloadAccessShaderStage : uint32_t {
Caller = 0,
Closesthit = 1,
Miss = 2,
Anyhit = 3,
Invalid = 0xffffffffu
};
// Allocate 4 bits per shader stage:
// bits 0-1 for payload access qualifiers
// bits 2-3 reserved for future use
const uint32_t PayloadAccessQualifierBitsPerStage = 4;
const uint32_t PayloadAccessQualifierValidMaskPerStage = 3;
const uint32_t PayloadAccessQualifierValidMask = 0x00003333;
inline bool IsValidHitGroupType(HitGroupType type) {
return (type >= HitGroupType::Triangle && type < HitGroupType::LastEntry);
}
extern const char *kLegacyLayoutString;
extern const char *kNewLayoutString;
extern const char *kFP32DenormKindString;
extern const char *kFP32DenormValueAnyString;
extern const char *kFP32DenormValuePreserveString;
extern const char *kFP32DenormValueFtzString;
extern const char *kDxBreakFuncName;
extern const char *kDxBreakCondName;
extern const char *kDxBreakMDName;
extern const char *kDxIsHelperGlobalName;
extern const char *kHostLayoutTypePrefix;
extern const char *kWaveOpsIncludeHelperLanesString;
} // namespace DXIL
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/CMakeLists.txt | add_hlsl_hctgen(DxilConstants OUTPUT DxilConstants.h CODE_TAG)
add_hlsl_hctgen(DxilInstructions OUTPUT DxilInstructions.h CODE_TAG)
add_hlsl_hctgen(DxilSigPoint OUTPUT DxilSigPoint.inl CODE_TAG)
add_hlsl_hctgen(DxilCounters OUTPUT DxilCounters.h CODE_TAG)
add_hlsl_hctgen(DxilShaderModelInc OUTPUT DxilShaderModel.h CODE_TAG)
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilShaderModel.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilShaderModel.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL shader models. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilConstants.h"
#include "llvm/ADT/StringRef.h"
namespace hlsl {
class Semantic;
/// <summary>
/// Use this class to represent HLSL shader model.
/// </summary>
class ShaderModel {
public:
using Kind = DXIL::ShaderKind;
// Major/Minor version of highest shader model
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_highest_shader_model()</py>*/
// clang-format on
// VALRULE-TEXT:BEGIN
static const unsigned kHighestMajor = 6;
static const unsigned kHighestMinor = 8;
// VALRULE-TEXT:END
static const unsigned kOfflineMinor = 0xF;
bool IsPS() const { return m_Kind == Kind::Pixel; }
bool IsVS() const { return m_Kind == Kind::Vertex; }
bool IsGS() const { return m_Kind == Kind::Geometry; }
bool IsHS() const { return m_Kind == Kind::Hull; }
bool IsDS() const { return m_Kind == Kind::Domain; }
bool IsCS() const { return m_Kind == Kind::Compute; }
bool IsLib() const { return m_Kind == Kind::Library; }
bool IsMS() const { return m_Kind == Kind::Mesh; }
bool IsAS() const { return m_Kind == Kind::Amplification; }
bool IsValid() const;
bool IsValidForDxil() const;
Kind GetKind() const { return m_Kind; }
unsigned GetMajor() const { return m_Major; }
unsigned GetMinor() const { return m_Minor; }
void GetDxilVersion(unsigned &DxilMajor, unsigned &DxilMinor) const;
void GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
bool IsSMAtLeast(unsigned Major, unsigned Minor) const {
return m_Major > Major || (m_Major == Major && m_Minor >= Minor);
}
bool IsSM50Plus() const { return IsSMAtLeast(5, 0); }
bool IsSM51Plus() const { return IsSMAtLeast(5, 1); }
bool AllowDerivatives(DXIL::ShaderKind sk) const;
// clang-format off
// Python lines need to be not formatted.
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_is_shader_model_plus()</py>*/
// clang-format on
// VALRULE-TEXT:BEGIN
bool IsSM60Plus() const { return IsSMAtLeast(6, 0); }
bool IsSM61Plus() const { return IsSMAtLeast(6, 1); }
bool IsSM62Plus() const { return IsSMAtLeast(6, 2); }
bool IsSM63Plus() const { return IsSMAtLeast(6, 3); }
bool IsSM64Plus() const { return IsSMAtLeast(6, 4); }
bool IsSM65Plus() const { return IsSMAtLeast(6, 5); }
bool IsSM66Plus() const { return IsSMAtLeast(6, 6); }
bool IsSM67Plus() const { return IsSMAtLeast(6, 7); }
bool IsSM68Plus() const { return IsSMAtLeast(6, 8); }
// VALRULE-TEXT:END
const char *GetName() const { return m_pszName; }
const char *GetKindName() const;
DXIL::PackingStrategy GetDefaultPackingStrategy() const {
return DXIL::PackingStrategy::PrefixStable;
}
static const ShaderModel *Get(Kind Kind, unsigned Major, unsigned Minor);
static const ShaderModel *GetByName(llvm::StringRef Name);
static const char *GetKindName(Kind kind);
static DXIL::ShaderKind KindFromFullName(llvm::StringRef Name);
static const llvm::StringRef FullNameFromKind(DXIL::ShaderKind sk);
static const char *GetNodeLaunchTypeName(DXIL::NodeLaunchType launchTy);
static DXIL::NodeLaunchType NodeLaunchTypeFromName(llvm::StringRef name);
static bool HasVisibleGroup(
DXIL::ShaderKind SK,
DXIL::NodeLaunchType launchType = DXIL::NodeLaunchType::Invalid) {
// Note: Library case is permissive; enforced at entry point.
return SK == DXIL::ShaderKind::Compute || SK == DXIL::ShaderKind::Mesh ||
SK == DXIL::ShaderKind::Amplification ||
SK == DXIL::ShaderKind::Library ||
(SK == DXIL::ShaderKind::Node &&
(launchType == DXIL::NodeLaunchType::Broadcasting ||
launchType == DXIL::NodeLaunchType::Coalescing));
}
bool operator==(const ShaderModel &other) const;
bool operator!=(const ShaderModel &other) const { return !(*this == other); }
private:
Kind m_Kind;
unsigned m_Major;
unsigned m_Minor;
const char *m_pszName;
unsigned m_NumInputRegs;
unsigned m_NumOutputRegs;
bool m_bTypedUavs;
unsigned m_NumUAVRegs;
ShaderModel() = delete;
ShaderModel(Kind Kind, unsigned Major, unsigned Minor, const char *pszName,
unsigned m_NumInputRegs, unsigned m_NumOutputRegs, bool m_bUAVs,
bool m_bTypedUavs, unsigned m_UAVRegsLim);
/* <py::lines('VALRULE-TEXT')>hctdb_instrhelp.get_num_shader_models()</py>*/
// VALRULE-TEXT:BEGIN
static const unsigned kNumShaderModels = 92;
// VALRULE-TEXT:END
static const ShaderModel ms_ShaderModels[kNumShaderModels];
static const ShaderModel *GetInvalid();
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilMetadataHelper.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilMetadataHelper.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Helper to serialize/desialize metadata for DxilModule. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilFunctionProps.h"
#include "llvm/ADT/ArrayRef.h"
#include <memory>
#include <string>
#include <vector>
namespace llvm {
class LLVMContext;
class Module;
class Function;
class Instruction;
class DbgDeclareInst;
class Value;
class MDOperand;
class Metadata;
class ConstantAsMetadata;
class MDTuple;
class MDNode;
class NamedMDNode;
class GlobalVariable;
class StringRef;
class Type;
} // namespace llvm
namespace hlsl {
class ShaderModel;
class DxilSignature;
struct DxilEntrySignature;
class DxilSignatureElement;
class DxilModule;
class DxilResourceBase;
class DxilCBuffer;
class DxilResource;
class DxilSampler;
class DxilTypeSystem;
class DxilStructAnnotation;
class DxilFieldAnnotation;
class DxilPayloadAnnotation;
class DxilPayloadFieldAnnotation;
class DxilTemplateArgAnnotation;
class DxilFunctionAnnotation;
class DxilParameterAnnotation;
class RootSignatureHandle;
struct DxilFunctionProps;
class DxilSubobjects;
class DxilSubobject;
struct DxilCounters;
// Additional debug information for SROA'ed array variables,
// where adjacent elements in DXIL might not have been adjacent
// in the original user variable.
struct DxilDIArrayDim {
unsigned StrideInBits;
unsigned NumElements;
};
/// Use this class to manipulate DXIL-spcific metadata.
// In our code, only DxilModule and HLModule should use this class.
class DxilMDHelper {
public:
//
// Constants for metadata names and field positions.
//
// Dxil version.
static const char kDxilVersionMDName[];
static const unsigned kDxilVersionNumFields = 2;
static const unsigned kDxilVersionMajorIdx = 0; // DXIL version major.
static const unsigned kDxilVersionMinorIdx = 1; // DXIL version minor.
// Shader model.
static const char kDxilShaderModelMDName[];
static const unsigned kDxilShaderModelNumFields = 3;
static const unsigned kDxilShaderModelTypeIdx =
0; // Shader type (vs,ps,cs,gs,ds,hs).
static const unsigned kDxilShaderModelMajorIdx = 1; // Shader model major.
static const unsigned kDxilShaderModelMinorIdx = 2; // Shader model minor.
// Intermediate codegen/optimizer options, not valid in final DXIL module.
static const char kDxilIntermediateOptionsMDName[];
static const unsigned kDxilIntermediateOptionsFlags = 0; // Unique element ID.
// DxilCounters
static const char kDxilCountersMDName[];
// !{!"<counter>", i32 <count>, !"<counter>", i32 <count>, ...}
// Entry points.
static const char kDxilEntryPointsMDName[];
// Root Signature, for intermediate use, not valid in final DXIL module.
static const char kDxilRootSignatureMDName[];
// ViewId state.
static const char kDxilViewIdStateMDName[];
// Subobjects
static const char kDxilSubobjectsMDName[];
// Source info.
static const char kDxilSourceContentsMDName[];
static const char kDxilSourceDefinesMDName[];
static const char kDxilSourceMainFileNameMDName[];
static const char kDxilSourceArgsMDName[];
// Resource binding data
static const char kDxilDxcBindingTableMDName[];
static const unsigned kDxilDxcBindingTableResourceName = 0;
static const unsigned kDxilDxcBindingTableResourceClass = 1;
static const unsigned kDxilDxcBindingTableResourceIndex = 2;
static const unsigned kDxilDxcBindingTableResourceSpace = 3;
// Old source info.
static const char kDxilSourceContentsOldMDName[];
static const char kDxilSourceDefinesOldMDName[];
static const char kDxilSourceMainFileNameOldMDName[];
static const char kDxilSourceArgsOldMDName[];
static const unsigned kDxilEntryPointNumFields = 5;
static const unsigned kDxilEntryPointFunction =
0; // Entry point function symbol.
static const unsigned kDxilEntryPointName = 1; // Entry point unmangled name.
static const unsigned kDxilEntryPointSignatures =
2; // Entry point signature tuple.
static const unsigned kDxilEntryPointResources =
3; // Entry point resource tuple.
static const unsigned kDxilEntryPointProperties =
4; // Entry point properties tuple.
// Signatures.
static const unsigned kDxilNumSignatureFields = 3;
static const unsigned kDxilInputSignature = 0; // Shader input signature.
static const unsigned kDxilOutputSignature = 1; // Shader output signature.
static const unsigned kDxilPatchConstantSignature =
2; // Shader patch constant (PC) signature.
// Signature Element.
static const unsigned kDxilSignatureElementNumFields = 11;
static const unsigned kDxilSignatureElementID = 0; // Unique element ID.
static const unsigned kDxilSignatureElementName = 1; // Element name.
static const unsigned kDxilSignatureElementType = 2; // Element type.
static const unsigned kDxilSignatureElementSystemValue =
3; // Effective system value.
static const unsigned kDxilSignatureElementIndexVector =
4; // Semantic index vector.
static const unsigned kDxilSignatureElementInterpMode =
5; // Interpolation mode.
static const unsigned kDxilSignatureElementRows = 6; // Number of rows.
static const unsigned kDxilSignatureElementCols = 7; // Number of columns.
static const unsigned kDxilSignatureElementStartRow =
8; // Element packing start row.
static const unsigned kDxilSignatureElementStartCol =
9; // Element packing start column.
static const unsigned kDxilSignatureElementNameValueList =
10; // Name-value list for extended properties.
// Signature Element Extended Properties.
static const unsigned kDxilSignatureElementOutputStreamTag = 0;
static const unsigned kHLSignatureElementGlobalSymbolTag = 1;
static const unsigned kDxilSignatureElementDynIdxCompMaskTag = 2;
static const unsigned kDxilSignatureElementUsageCompMaskTag = 3;
// Resources.
static const char kDxilResourcesMDName[];
static const unsigned kDxilNumResourceFields = 4;
static const unsigned kDxilResourceSRVs = 0;
static const unsigned kDxilResourceUAVs = 1;
static const unsigned kDxilResourceCBuffers = 2;
static const unsigned kDxilResourceSamplers = 3;
// ResourceBase.
static const unsigned kDxilResourceBaseNumFields = 6;
static const unsigned kDxilResourceBaseID =
0; // Unique (per type) resource ID.
static const unsigned kDxilResourceBaseVariable =
1; // Resource global variable.
static const unsigned kDxilResourceBaseName =
2; // Original (HLSL) name of the resource.
static const unsigned kDxilResourceBaseSpaceID =
3; // Resource range space ID.
static const unsigned kDxilResourceBaseLowerBound =
4; // Resource range lower bound.
static const unsigned kDxilResourceBaseRangeSize = 5; // Resource range size.
// SRV-specific.
static const unsigned kDxilSRVNumFields = 9;
static const unsigned kDxilSRVShape = 6; // SRV shape.
static const unsigned kDxilSRVSampleCount = 7; // SRV sample count.
static const unsigned kDxilSRVNameValueList =
8; // Name-value list for extended properties.
// UAV-specific.
static const unsigned kDxilUAVNumFields = 11;
static const unsigned kDxilUAVShape = 6; // UAV shape.
static const unsigned kDxilUAVGloballyCoherent = 7; // Globally-coherent UAV.
static const unsigned kDxilUAVCounter = 8; // UAV with a counter.
static const unsigned kDxilUAVRasterizerOrderedView = 9; // UAV that is a ROV.
static const unsigned kDxilUAVNameValueList =
10; // Name-value list for extended properties.
// CBuffer-specific.
static const unsigned kDxilCBufferNumFields = 8;
static const unsigned kDxilCBufferSizeInBytes = 6; // CBuffer size in bytes.
static const unsigned kDxilCBufferNameValueList =
7; // Name-value list for extended properties.
// CBuffer extended properties
static const unsigned kHLCBufferIsTBufferTag =
0; // CBuffer is actually TBuffer, not yet converted to SRV.
// Sampler-specific.
static const unsigned kDxilSamplerNumFields = 8;
static const unsigned kDxilSamplerType = 6; // Sampler type.
static const unsigned kDxilSamplerNameValueList =
7; // Name-value list for extended properties.
// Resource extended property tags.
static const unsigned kDxilTypedBufferElementTypeTag = 0;
static const unsigned kDxilStructuredBufferElementStrideTag = 1;
static const unsigned kDxilSamplerFeedbackKindTag = 2;
static const unsigned kDxilAtomic64UseTag = 3;
// Type system.
static const char kDxilTypeSystemMDName[];
static const char kDxilTypeSystemHelperVariablePrefix[];
static const unsigned kDxilTypeSystemStructTag = 0;
static const unsigned kDxilTypeSystemFunctionTag = 1;
static const unsigned kDxilFieldAnnotationSNormTag = 0;
static const unsigned kDxilFieldAnnotationUNormTag = 1;
static const unsigned kDxilFieldAnnotationMatrixTag = 2;
static const unsigned kDxilFieldAnnotationCBufferOffsetTag = 3;
static const unsigned kDxilFieldAnnotationSemanticStringTag = 4;
static const unsigned kDxilFieldAnnotationInterpolationModeTag = 5;
static const unsigned kDxilFieldAnnotationFieldNameTag = 6;
static const unsigned kDxilFieldAnnotationCompTypeTag = 7;
static const unsigned kDxilFieldAnnotationPreciseTag = 8;
static const unsigned kDxilFieldAnnotationCBUsedTag = 9;
static const unsigned kDxilFieldAnnotationResPropTag = 10;
static const unsigned kDxilFieldAnnotationBitFieldsTag = 11;
static const unsigned kDxilFieldAnnotationBitFieldWidthTag = 12;
static const unsigned kDxilFieldAnnotationVectorSizeTag = 13;
// DXR Payload Annotations
static const unsigned kDxilPayloadAnnotationStructTag = 0;
static const unsigned kDxilPayloadFieldAnnotationAccessTag = 0;
// StructAnnotation extended property tags (DXIL 1.5+ only, appended)
static const unsigned kDxilTemplateArgumentsTag =
0; // Name for name-value list of extended struct properties
// TemplateArgument tags
static const unsigned kDxilTemplateArgTypeTag =
0; // Type template argument, followed by undef of type
static const unsigned kDxilTemplateArgIntegralTag =
1; // Integral template argument, followed by i64 value
static const unsigned kDxilTemplateArgValue =
1; // Position of template arg value (type or int)
// Control flow hint.
static const char kDxilControlFlowHintMDName[];
// Precise attribute.
static const char kDxilPreciseAttributeMDName[];
// NonUniform attribute.
static const char kDxilNonUniformAttributeMDName[];
// Variable debug layout metadata.
static const char kDxilVariableDebugLayoutMDName[];
// Indication of temporary storage metadata.
static const char kDxilTempAllocaMDName[];
// Validator version.
static const char kDxilValidatorVersionMDName[];
// Validator version uses the same constants for fields as kDxilVersion*
// DXR Payload Annotations metadata.
static const char kDxilDxrPayloadAnnotationsMDName[];
// Extended shader property tags.
static const unsigned kDxilShaderFlagsTag = 0;
static const unsigned kDxilGSStateTag = 1;
static const unsigned kDxilDSStateTag = 2;
static const unsigned kDxilHSStateTag = 3;
static const unsigned kDxilNumThreadsTag = 4;
static const unsigned kDxilAutoBindingSpaceTag = 5;
static const unsigned kDxilRayPayloadSizeTag = 6;
static const unsigned kDxilRayAttribSizeTag = 7;
static const unsigned kDxilShaderKindTag = 8;
static const unsigned kDxilMSStateTag = 9;
static const unsigned kDxilASStateTag = 10;
static const unsigned kDxilWaveSizeTag = 11;
static const unsigned kDxilEntryRootSigTag = 12;
// Node Tags ( extension of shader property tags)
static const unsigned kDxilNodeLaunchTypeTag = 13;
static const unsigned kDxilNodeIsProgramEntryTag = 14;
static const unsigned kDxilNodeIdTag = 15;
static const unsigned kDxilNodeLocalRootArgumentsTableIndexTag = 16;
static const unsigned kDxilShareInputOfTag = 17;
static const unsigned kDxilNodeDispatchGridTag = 18;
static const unsigned kDxilNodeMaxRecursionDepthTag = 19;
static const unsigned kDxilNodeInputsTag = 20;
static const unsigned kDxilNodeOutputsTag = 21;
static const unsigned kDxilNodeMaxDispatchGridTag = 22;
static const unsigned kDxilRangedWaveSizeTag = 23;
// Node Input/Output State.
static const unsigned kDxilNodeOutputIDTag = 0;
static const unsigned kDxilNodeIOFlagsTag = 1;
static const unsigned kDxilNodeRecordTypeTag = 2;
static const unsigned kDxilNodeMaxRecordsTag = 3;
static const unsigned kDxilNodeMaxRecordsSharedWithTag = 4;
static const unsigned kDxilNodeOutputArraySizeTag = 5;
static const unsigned kDxilNodeAllowSparseNodesTag = 6;
// Node Record Type
static const unsigned kDxilNodeRecordSizeTag = 0;
static const unsigned kDxilNodeSVDispatchGridTag = 1;
static const unsigned kDxilNodeRecordAlignmentTag = 2;
// GSState.
static const unsigned kDxilGSStateNumFields = 5;
static const unsigned kDxilGSStateInputPrimitive = 0;
static const unsigned kDxilGSStateMaxVertexCount = 1;
static const unsigned kDxilGSStateActiveStreamMask = 2;
static const unsigned kDxilGSStateOutputStreamTopology = 3;
static const unsigned kDxilGSStateGSInstanceCount = 4;
// DSState.
static const unsigned kDxilDSStateNumFields = 2;
static const unsigned kDxilDSStateTessellatorDomain = 0;
static const unsigned kDxilDSStateInputControlPointCount = 1;
// HSState.
static const unsigned kDxilHSStateNumFields = 7;
static const unsigned kDxilHSStatePatchConstantFunction = 0;
static const unsigned kDxilHSStateInputControlPointCount = 1;
static const unsigned kDxilHSStateOutputControlPointCount = 2;
static const unsigned kDxilHSStateTessellatorDomain = 3;
static const unsigned kDxilHSStateTessellatorPartitioning = 4;
static const unsigned kDxilHSStateTessellatorOutputPrimitive = 5;
static const unsigned kDxilHSStateMaxTessellationFactor = 6;
// MSState.
static const unsigned kDxilMSStateNumFields = 5;
static const unsigned kDxilMSStateNumThreads = 0;
static const unsigned kDxilMSStateMaxVertexCount = 1;
static const unsigned kDxilMSStateMaxPrimitiveCount = 2;
static const unsigned kDxilMSStateOutputTopology = 3;
static const unsigned kDxilMSStatePayloadSizeInBytes = 4;
// ASState.
static const unsigned kDxilASStateNumFields = 2;
static const unsigned kDxilASStateNumThreads = 0;
static const unsigned kDxilASStatePayloadSizeInBytes = 1;
public:
/// Use this class to manipulate metadata of DXIL or high-level DX IR specific
/// fields in the record.
class ExtraPropertyHelper {
public:
ExtraPropertyHelper(llvm::Module *pModule);
virtual ~ExtraPropertyHelper() {}
virtual void EmitSRVProperties(const DxilResource &SRV,
std::vector<llvm::Metadata *> &MDVals) = 0;
virtual void LoadSRVProperties(const llvm::MDOperand &MDO,
DxilResource &SRV) = 0;
virtual void EmitUAVProperties(const DxilResource &UAV,
std::vector<llvm::Metadata *> &MDVals) = 0;
virtual void LoadUAVProperties(const llvm::MDOperand &MDO,
DxilResource &UAV) = 0;
virtual void
EmitCBufferProperties(const DxilCBuffer &CB,
std::vector<llvm::Metadata *> &MDVals) = 0;
virtual void LoadCBufferProperties(const llvm::MDOperand &MDO,
DxilCBuffer &CB) = 0;
virtual void
EmitSamplerProperties(const DxilSampler &S,
std::vector<llvm::Metadata *> &MDVals) = 0;
virtual void LoadSamplerProperties(const llvm::MDOperand &MDO,
DxilSampler &S) = 0;
virtual void
EmitSignatureElementProperties(const DxilSignatureElement &SE,
std::vector<llvm::Metadata *> &MDVals) = 0;
virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO,
DxilSignatureElement &SE) = 0;
protected:
llvm::LLVMContext &m_Ctx;
llvm::Module *m_pModule;
public:
unsigned m_ValMajor, m_ValMinor; // Reported validation version in DXIL
unsigned m_MinValMajor,
m_MinValMinor; // Minimum validation version dictated by shader model
bool m_bExtraMetadata;
};
public:
DxilMDHelper(llvm::Module *pModule, std::unique_ptr<ExtraPropertyHelper> EPH);
~DxilMDHelper();
void SetShaderModel(const ShaderModel *pSM);
const ShaderModel *GetShaderModel() const;
// Dxil version.
void EmitDxilVersion(unsigned Major, unsigned Minor);
void LoadDxilVersion(unsigned &Major, unsigned &Minor);
// Validator version.
void EmitValidatorVersion(unsigned Major, unsigned Minor);
void LoadValidatorVersion(unsigned &Major, unsigned &Minor);
// Shader model.
void EmitDxilShaderModel(const ShaderModel *pSM);
void LoadDxilShaderModel(const ShaderModel *&pSM);
// Intermediate flags
void EmitDxilIntermediateOptions(uint32_t flags);
void LoadDxilIntermediateOptions(uint32_t &flags);
// Entry points.
void EmitDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
void UpdateDxilEntryPoints(std::vector<llvm::MDNode *> &MDEntries);
const llvm::NamedMDNode *GetDxilEntryPoints();
llvm::MDTuple *EmitDxilEntryPointTuple(llvm::Function *pFunc,
const std::string &Name,
llvm::MDTuple *pSignatures,
llvm::MDTuple *pResources,
llvm::MDTuple *pProperties);
void GetDxilEntryPoint(const llvm::MDNode *MDO, llvm::Function *&pFunc,
std::string &Name, const llvm::MDOperand *&pSignatures,
const llvm::MDOperand *&pResources,
const llvm::MDOperand *&pProperties);
// Signatures.
llvm::MDTuple *EmitDxilSignatures(const DxilEntrySignature &EntrySig);
void LoadDxilSignatures(const llvm::MDOperand &MDO,
DxilEntrySignature &EntrySig);
llvm::MDTuple *EmitSignatureMetadata(const DxilSignature &Sig);
void EmitRootSignature(std::vector<uint8_t> &SerializedRootSignature);
void LoadSignatureMetadata(const llvm::MDOperand &MDO, DxilSignature &Sig);
llvm::MDTuple *EmitSignatureElement(const DxilSignatureElement &SE);
void LoadSignatureElement(const llvm::MDOperand &MDO,
DxilSignatureElement &SE);
void LoadRootSignature(std::vector<uint8_t> &SerializedRootSignature);
// Resources.
llvm::MDTuple *EmitDxilResourceTuple(llvm::MDTuple *pSRVs,
llvm::MDTuple *pUAVs,
llvm::MDTuple *pCBuffers,
llvm::MDTuple *pSamplers);
void EmitDxilResources(llvm::MDTuple *pDxilResourceTuple);
void UpdateDxilResources(llvm::MDTuple *pDxilResourceTuple);
void GetDxilResources(const llvm::MDOperand &MDO, const llvm::MDTuple *&pSRVs,
const llvm::MDTuple *&pUAVs,
const llvm::MDTuple *&pCBuffers,
const llvm::MDTuple *&pSamplers);
void EmitDxilResourceBase(const DxilResourceBase &R,
llvm::Metadata *ppMDVals[]);
void LoadDxilResourceBase(const llvm::MDOperand &MDO, DxilResourceBase &R);
llvm::MDTuple *EmitDxilSRV(const DxilResource &SRV);
void LoadDxilSRV(const llvm::MDOperand &MDO, DxilResource &SRV);
llvm::MDTuple *EmitDxilUAV(const DxilResource &UAV);
void LoadDxilUAV(const llvm::MDOperand &MDO, DxilResource &UAV);
llvm::MDTuple *EmitDxilCBuffer(const DxilCBuffer &CB);
void LoadDxilCBuffer(const llvm::MDOperand &MDO, DxilCBuffer &CB);
llvm::MDTuple *EmitDxilSampler(const DxilSampler &S);
void LoadDxilSampler(const llvm::MDOperand &MDO, DxilSampler &S);
const llvm::MDOperand &GetResourceClass(llvm::MDNode *MD,
DXIL::ResourceClass &RC);
// Type system.
void EmitDxilTypeSystem(DxilTypeSystem &TypeSystem,
std::vector<llvm::GlobalVariable *> &LLVMUsed);
void LoadDxilTypeSystemNode(const llvm::MDTuple &MDT,
DxilTypeSystem &TypeSystem);
void LoadDxilTypeSystem(DxilTypeSystem &TypeSystem);
llvm::Metadata *EmitDxilStructAnnotation(const DxilStructAnnotation &SA);
void LoadDxilStructAnnotation(const llvm::MDOperand &MDO,
DxilStructAnnotation &SA);
llvm::Metadata *EmitDxilFieldAnnotation(const DxilFieldAnnotation &FA);
void LoadDxilFieldAnnotation(const llvm::MDOperand &MDO,
DxilFieldAnnotation &FA);
llvm::Metadata *EmitDxilFunctionAnnotation(const DxilFunctionAnnotation &FA);
void LoadDxilFunctionAnnotation(const llvm::MDOperand &MDO,
DxilFunctionAnnotation &FA);
llvm::Metadata *EmitDxilParamAnnotation(const DxilParameterAnnotation &PA);
void LoadDxilParamAnnotation(const llvm::MDOperand &MDO,
DxilParameterAnnotation &PA);
llvm::Metadata *EmitDxilParamAnnotations(const DxilFunctionAnnotation &FA);
void LoadDxilParamAnnotations(const llvm::MDOperand &MDO,
DxilFunctionAnnotation &FA);
llvm::Metadata *
EmitDxilTemplateArgAnnotation(const DxilTemplateArgAnnotation &annotation);
void LoadDxilTemplateArgAnnotation(const llvm::MDOperand &MDO,
DxilTemplateArgAnnotation &annotation);
// DXR Payload Annotations
void EmitDxrPayloadAnnotations(DxilTypeSystem &TypeSystem);
llvm::Metadata *
EmitDxrPayloadStructAnnotation(const DxilPayloadAnnotation &SA);
llvm::Metadata *
EmitDxrPayloadFieldAnnotation(const DxilPayloadFieldAnnotation &FA,
llvm::Type *fieldType);
void LoadDxrPayloadAnnotationNode(const llvm::MDTuple &MDT,
DxilTypeSystem &TypeSystem);
void LoadDxrPayloadAnnotations(DxilTypeSystem &TypeSystem);
void LoadDxrPayloadFieldAnnoations(const llvm::MDOperand &MDO,
DxilPayloadAnnotation &SA);
void LoadDxrPayloadFieldAnnoation(const llvm::MDOperand &MDO,
DxilPayloadFieldAnnotation &FA);
void LoadDxrPayloadAccessQualifiers(const llvm::MDOperand &MDO,
DxilPayloadFieldAnnotation &FA);
// Function props.
void SerializeNodeProps(llvm::SmallVectorImpl<llvm::Metadata *> &MDVals,
unsigned &valIdx,
const hlsl::DxilFunctionProps *props);
void DeserializeNodeProps(const llvm::MDTuple *pProps, unsigned &idx,
hlsl::DxilFunctionProps *props);
llvm::MDTuple *EmitDxilFunctionProps(const hlsl::DxilFunctionProps *props,
const llvm::Function *F);
const llvm::Function *LoadDxilFunctionProps(const llvm::MDTuple *pProps,
hlsl::DxilFunctionProps *props);
llvm::MDTuple *EmitDxilEntryProperties(uint64_t rawShaderFlag,
const hlsl::DxilFunctionProps &props,
uint32_t autoBindingSpace);
void LoadDxilEntryProperties(const llvm::MDOperand &MDO,
uint64_t &rawShaderFlag,
hlsl::DxilFunctionProps &props,
uint32_t &autoBindingSpace);
// ViewId state.
void EmitDxilViewIdState(std::vector<unsigned> &SerializedState);
void LoadDxilViewIdState(std::vector<unsigned> &SerializedState);
// Control flow hints.
static llvm::MDNode *
EmitControlFlowHints(llvm::LLVMContext &Ctx,
std::vector<DXIL::ControlFlowHint> &hints);
static unsigned GetControlFlowHintMask(const llvm::Instruction *I);
static bool HasControlFlowHintToPreventFlatten(const llvm::Instruction *I);
// Subobjects
void EmitSubobjects(const DxilSubobjects &Subobjects);
void LoadSubobjects(DxilSubobjects &Subobjects);
llvm::Metadata *EmitSubobject(const DxilSubobject &obj);
void LoadSubobject(const llvm::MDNode &MDO, DxilSubobjects &Subobjects);
// Extra metadata present
bool HasExtraMetadata() { return m_bExtraMetadata; }
// Instruction Counters
void EmitDxilCounters(const DxilCounters &counters);
void LoadDxilCounters(DxilCounters &counters) const;
// Shader specific.
private:
llvm::MDTuple *
EmitDxilGSState(DXIL::InputPrimitive Primitive, unsigned MaxVertexCount,
unsigned ActiveStreamMask,
DXIL::PrimitiveTopology StreamPrimitiveTopology,
unsigned GSInstanceCount);
void LoadDxilGSState(const llvm::MDOperand &MDO,
DXIL::InputPrimitive &Primitive,
unsigned &MaxVertexCount, unsigned &ActiveStreamMask,
DXIL::PrimitiveTopology &StreamPrimitiveTopology,
unsigned &GSInstanceCount);
llvm::MDTuple *EmitDxilDSState(DXIL::TessellatorDomain Domain,
unsigned InputControlPointCount);
void LoadDxilDSState(const llvm::MDOperand &MDO,
DXIL::TessellatorDomain &Domain,
unsigned &InputControlPointCount);
llvm::MDTuple *EmitDxilHSState(
llvm::Function *pPatchConstantFunction, unsigned InputControlPointCount,
unsigned OutputControlPointCount, DXIL::TessellatorDomain TessDomain,
DXIL::TessellatorPartitioning TessPartitioning,
DXIL::TessellatorOutputPrimitive TessOutputPrimitive,
float MaxTessFactor);
void LoadDxilHSState(const llvm::MDOperand &MDO,
llvm::Function *&pPatchConstantFunction,
unsigned &InputControlPointCount,
unsigned &OutputControlPointCount,
DXIL::TessellatorDomain &TessDomain,
DXIL::TessellatorPartitioning &TessPartitioning,
DXIL::TessellatorOutputPrimitive &TessOutputPrimitive,
float &MaxTessFactor);
llvm::MDTuple *EmitDxilMSState(const unsigned *NumThreads,
unsigned MaxVertexCount,
unsigned MaxPrimitiveCount,
DXIL::MeshOutputTopology OutputTopology,
unsigned payloadSizeInBytes);
void LoadDxilMSState(const llvm::MDOperand &MDO, unsigned *NumThreads,
unsigned &MaxVertexCount, unsigned &MaxPrimitiveCount,
DXIL::MeshOutputTopology &OutputTopology,
unsigned &payloadSizeInBytes);
llvm::MDTuple *EmitDxilASState(const unsigned *NumThreads,
unsigned payloadSizeInBytes);
void LoadDxilASState(const llvm::MDOperand &MDO, unsigned *NumThreads,
unsigned &payloadSizeInBytes);
llvm::MDTuple *EmitDxilNodeIOState(const NodeIOProperties &Node);
llvm::MDTuple *EmitDxilNodeRecordType(const NodeRecordType &RecordType);
hlsl::NodeIOProperties LoadDxilNodeIOState(const llvm::MDOperand &MDO);
hlsl::NodeRecordType LoadDxilNodeRecordType(const llvm::MDOperand &MDO);
void EmitDxilNodeState(std::vector<llvm::Metadata *> &MDVals,
const DxilFunctionProps &props);
void AddCounterIfNonZero(uint32_t value, llvm::StringRef name,
std::vector<llvm::Metadata *> &MDVals);
void LoadCounterMD(const llvm::MDOperand &MDName,
const llvm::MDOperand &MDValue,
DxilCounters &counters) const;
public:
// Utility functions.
static bool IsKnownNamedMetaData(const llvm::NamedMDNode &Node);
static bool IsKnownMetadataID(llvm::LLVMContext &Ctx, unsigned ID);
static void GetKnownMetadataIDs(llvm::LLVMContext &Ctx,
llvm::SmallVectorImpl<unsigned> *pIDs);
static void combineDxilMetadata(llvm::Instruction *K,
const llvm::Instruction *J);
static llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v,
llvm::LLVMContext &Ctx);
llvm::ConstantAsMetadata *Int32ToConstMD(int32_t v);
static llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v,
llvm::LLVMContext &Ctx);
llvm::ConstantAsMetadata *Uint32ToConstMD(unsigned v);
static llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v,
llvm::LLVMContext &Ctx);
llvm::ConstantAsMetadata *Uint64ToConstMD(uint64_t v);
llvm::ConstantAsMetadata *Int8ToConstMD(int8_t v);
llvm::ConstantAsMetadata *Uint8ToConstMD(uint8_t v);
static llvm::ConstantAsMetadata *BoolToConstMD(bool v,
llvm::LLVMContext &Ctx);
llvm::ConstantAsMetadata *BoolToConstMD(bool v);
llvm::ConstantAsMetadata *FloatToConstMD(float v);
static int32_t ConstMDToInt32(const llvm::MDOperand &MDO);
static unsigned ConstMDToUint32(const llvm::MDOperand &MDO);
static uint64_t ConstMDToUint64(const llvm::MDOperand &MDO);
static int8_t ConstMDToInt8(const llvm::MDOperand &MDO);
static uint8_t ConstMDToUint8(const llvm::MDOperand &MDO);
static bool ConstMDToBool(const llvm::MDOperand &MDO);
static float ConstMDToFloat(const llvm::MDOperand &MDO);
static std::string StringMDToString(const llvm::MDOperand &MDO);
static llvm::StringRef StringMDToStringRef(const llvm::MDOperand &MDO);
static llvm::Value *ValueMDToValue(const llvm::MDOperand &MDO);
llvm::MDTuple *Uint32VectorToConstMDTuple(const std::vector<unsigned> &Vec);
void ConstMDTupleToUint32Vector(llvm::MDTuple *pTupleMD,
std::vector<unsigned> &Vec);
static bool IsMarkedPrecise(const llvm::Instruction *inst);
static void MarkPrecise(llvm::Instruction *inst);
static bool IsMarkedNonUniform(const llvm::Instruction *inst);
static void MarkNonUniform(llvm::Instruction *inst);
static bool GetVariableDebugLayout(llvm::DbgDeclareInst *inst,
unsigned &StartOffsetInBits,
std::vector<DxilDIArrayDim> &ArrayDims);
static void
SetVariableDebugLayout(llvm::DbgDeclareInst *inst, unsigned StartOffsetInBits,
const std::vector<DxilDIArrayDim> &ArrayDims);
static void
CopyMetadata(llvm::Instruction &I, llvm::Instruction &SrcInst,
llvm::ArrayRef<unsigned> WL = llvm::ArrayRef<unsigned>());
private:
llvm::LLVMContext &m_Ctx;
llvm::Module *m_pModule;
const ShaderModel *m_pSM;
std::unique_ptr<ExtraPropertyHelper> m_ExtraPropertyHelper;
unsigned m_ValMajor, m_ValMinor; // Reported validation version in DXIL
unsigned m_MinValMajor,
m_MinValMinor; // Minimum validation version dictated by shader model
// Non-fatal if extra metadata is found, but will fail validation.
// This is how metadata can be exteneded.
bool m_bExtraMetadata;
};
/// Use this class to manipulate metadata of extra metadata record properties
/// that are specific to DXIL.
class DxilExtraPropertyHelper : public DxilMDHelper::ExtraPropertyHelper {
public:
DxilExtraPropertyHelper(llvm::Module *pModule);
virtual ~DxilExtraPropertyHelper() {}
virtual void EmitSRVProperties(const DxilResource &SRV,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadSRVProperties(const llvm::MDOperand &MDO, DxilResource &SRV);
virtual void EmitUAVProperties(const DxilResource &UAV,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadUAVProperties(const llvm::MDOperand &MDO, DxilResource &UAV);
virtual void EmitCBufferProperties(const DxilCBuffer &CB,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadCBufferProperties(const llvm::MDOperand &MDO,
DxilCBuffer &CB);
virtual void EmitSamplerProperties(const DxilSampler &S,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadSamplerProperties(const llvm::MDOperand &MDO,
DxilSampler &S);
virtual void
EmitSignatureElementProperties(const DxilSignatureElement &SE,
std::vector<llvm::Metadata *> &MDVals);
virtual void LoadSignatureElementProperties(const llvm::MDOperand &MDO,
DxilSignatureElement &SE);
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilPDB.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilPDB.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Helpers to wrap debug information in a PDB container. //
// //
///////////////////////////////////////////////////////////////////////////////
#include "dxc/Support/WinIncludes.h"
#include "llvm/ADT/ArrayRef.h"
struct IDxcBlob;
struct IStream;
struct IMalloc;
namespace hlsl {
namespace pdb {
HRESULT LoadDataFromStream(IMalloc *pMalloc, IStream *pIStream,
IDxcBlob **ppHash, IDxcBlob **ppContainer);
HRESULT LoadDataFromStream(IMalloc *pMalloc, IStream *pIStream,
IDxcBlob **pOutContainer);
HRESULT WriteDxilPDB(IMalloc *pMalloc, IDxcBlob *pContainer,
llvm::ArrayRef<BYTE> HashData, IDxcBlob **ppOutBlob);
HRESULT WriteDxilPDB(IMalloc *pMalloc, llvm::ArrayRef<BYTE> ContainerData,
llvm::ArrayRef<BYTE> HashData, IDxcBlob **ppOutBlob);
} // namespace pdb
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilModule.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilModule.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// The main class to work with DXIL, similar to LLVM module. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilCBuffer.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilMetadataHelper.h"
#include "dxc/DXIL/DxilResource.h"
#include "dxc/DXIL/DxilSampler.h"
#include "dxc/DXIL/DxilShaderFlags.h"
#include "dxc/DXIL/DxilSignature.h"
#include "dxc/DXIL/DxilSubobject.h"
#include "dxc/DXIL/DxilTypeSystem.h"
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace llvm {
class LLVMContext;
class Module;
class Function;
class Instruction;
class MDTuple;
class MDOperand;
class DebugInfoFinder;
} // namespace llvm
namespace hlsl {
class ShaderModel;
class OP;
struct DxilFunctionProps;
class DxilEntryProps;
using DxilEntryPropsMap =
std::unordered_map<const llvm::Function *, std::unique_ptr<DxilEntryProps>>;
/// Use this class to manipulate DXIL of a shader.
class DxilModule {
public:
DxilModule(llvm::Module *pModule);
~DxilModule();
// Subsystems.
llvm::LLVMContext &GetCtx() const;
llvm::Module *GetModule() const;
OP *GetOP() const;
void SetShaderModel(const ShaderModel *pSM, bool bUseMinPrecision = true);
const ShaderModel *GetShaderModel() const;
void GetDxilVersion(unsigned &DxilMajor, unsigned &DxilMinor) const;
void SetValidatorVersion(unsigned ValMajor, unsigned ValMinor);
bool UpgradeValidatorVersion(unsigned ValMajor, unsigned ValMinor);
void GetValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
void SetForceZeroStoreLifetimes(bool ForceZeroStoreLifetimes);
bool GetForceZeroStoreLifetimes() const;
// Return true on success, requires valid shader model and CollectShaderFlags
// to have been set
bool GetMinValidatorVersion(unsigned &ValMajor, unsigned &ValMinor) const;
// Update validator version to minimum if higher than current (ex: after
// CollectShaderFlags)
bool UpgradeToMinValidatorVersion();
// Entry functions.
llvm::Function *GetEntryFunction();
const llvm::Function *GetEntryFunction() const;
void SetEntryFunction(llvm::Function *pEntryFunc);
const std::string &GetEntryFunctionName() const;
void SetEntryFunctionName(const std::string &name);
llvm::Function *GetPatchConstantFunction();
const llvm::Function *GetPatchConstantFunction() const;
void SetPatchConstantFunction(llvm::Function *pFunc);
bool IsEntryOrPatchConstantFunction(const llvm::Function *pFunc) const;
llvm::SmallVector<llvm::Function *, 64> GetExportedFunctions();
// Flags.
unsigned GetGlobalFlags() const;
void CollectShaderFlagsForModule();
// Resources.
unsigned AddCBuffer(std::unique_ptr<DxilCBuffer> pCB);
DxilCBuffer &GetCBuffer(unsigned idx);
const DxilCBuffer &GetCBuffer(unsigned idx) const;
const std::vector<std::unique_ptr<DxilCBuffer>> &GetCBuffers() const;
unsigned AddSampler(std::unique_ptr<DxilSampler> pSampler);
DxilSampler &GetSampler(unsigned idx);
const DxilSampler &GetSampler(unsigned idx) const;
const std::vector<std::unique_ptr<DxilSampler>> &GetSamplers() const;
unsigned AddSRV(std::unique_ptr<DxilResource> pSRV);
DxilResource &GetSRV(unsigned idx);
const DxilResource &GetSRV(unsigned idx) const;
const std::vector<std::unique_ptr<DxilResource>> &GetSRVs() const;
unsigned AddUAV(std::unique_ptr<DxilResource> pUAV);
DxilResource &GetUAV(unsigned idx);
const DxilResource &GetUAV(unsigned idx) const;
const std::vector<std::unique_ptr<DxilResource>> &GetUAVs() const;
void RemoveUnusedResources();
void RemoveResourcesWithUnusedSymbols();
void RemoveFunction(llvm::Function *F);
bool RenameResourcesWithPrefix(const std::string &prefix);
bool RenameResourceGlobalsWithBinding(bool bKeepName = true);
// Signatures.
DxilSignature &GetInputSignature();
const DxilSignature &GetInputSignature() const;
DxilSignature &GetOutputSignature();
const DxilSignature &GetOutputSignature() const;
DxilSignature &GetPatchConstOrPrimSignature();
const DxilSignature &GetPatchConstOrPrimSignature() const;
const std::vector<uint8_t> &GetSerializedRootSignature() const;
std::vector<uint8_t> &GetSerializedRootSignature();
bool HasDxilEntrySignature(const llvm::Function *F) const;
DxilEntrySignature &GetDxilEntrySignature(const llvm::Function *F);
// Move DxilEntryProps of F to NewF.
void ReplaceDxilEntryProps(llvm::Function *F, llvm::Function *NewF);
// Clone DxilEntryProps of F to NewF.
void CloneDxilEntryProps(llvm::Function *F, llvm::Function *NewF);
bool HasDxilEntryProps(const llvm::Function *F) const;
DxilEntryProps &GetDxilEntryProps(const llvm::Function *F);
const DxilEntryProps &GetDxilEntryProps(const llvm::Function *F) const;
// DxilFunctionProps.
bool HasDxilFunctionProps(const llvm::Function *F) const;
DxilFunctionProps &GetDxilFunctionProps(const llvm::Function *F);
const DxilFunctionProps &GetDxilFunctionProps(const llvm::Function *F) const;
// Move DxilFunctionProps of F to NewF.
void SetPatchConstantFunctionForHS(llvm::Function *hullShaderFunc,
llvm::Function *patchConstantFunc);
bool IsGraphicsShader(const llvm::Function *F) const; // vs,hs,ds,gs,ps
bool IsPatchConstantShader(const llvm::Function *F) const;
bool IsComputeShader(const llvm::Function *F) const;
// Is an entry function that uses input/output signature conventions?
// Includes: vs/hs/ds/gs/ps/cs as well as the patch constant function.
bool IsEntryThatUsesSignatures(const llvm::Function *F) const;
// Is F an entry?
// Includes: IsEntryThatUsesSignatures and all ray tracing shaders.
bool IsEntry(const llvm::Function *F) const;
// Remove Root Signature from module metadata, return true if changed
bool StripRootSignatureFromMetadata();
// Remove Subobjects from module metadata, return true if changed
bool StripSubobjectsFromMetadata();
// Update validator version metadata to current setting
void UpdateValidatorVersionMetadata();
// DXIL type system.
DxilTypeSystem &GetTypeSystem();
const DxilTypeSystem &GetTypeSystem() const;
/// Emit llvm.used array to make sure that optimizations do not remove
/// unreferenced globals.
void EmitLLVMUsed();
std::vector<llvm::GlobalVariable *> &GetLLVMUsed();
void ClearLLVMUsed();
// ViewId state.
std::vector<unsigned> &GetSerializedViewIdState();
const std::vector<unsigned> &GetSerializedViewIdState() const;
// DXIL metadata manipulation.
/// Clear all DXIL data that exists in in-memory form.
static void ClearDxilMetadata(llvm::Module &M);
/// Serialize DXIL in-memory form to metadata form.
void EmitDxilMetadata();
/// Update resource metadata.
/// Note: this method not update Metadata for ViewIdState.
void ReEmitDxilResources();
/// Deserialize DXIL metadata form into in-memory form.
void LoadDxilMetadata();
/// Return true if non-fatal metadata error was detected.
bool HasMetadataErrors();
void EmitDxilCounters();
void LoadDxilCounters(DxilCounters &counters) const;
/// Check if a Named meta data node is known by dxil module.
static bool IsKnownNamedMetaData(llvm::NamedMDNode &Node);
// Reset functions used to transfer ownership.
void ResetEntrySignature(DxilEntrySignature *pValue);
void ResetSerializedRootSignature(std::vector<uint8_t> &Value);
void ResetTypeSystem(DxilTypeSystem *pValue);
void ResetOP(hlsl::OP *hlslOP);
void ResetEntryPropsMap(DxilEntryPropsMap &&PropMap);
bool StripReflection();
void StripDebugRelatedCode();
void RemoveUnusedTypeAnnotations();
// Copy resource reflection back to this module's resources.
void RestoreResourceReflection(const DxilModule &SourceDM);
// Helper to remove dx.* metadata with source and compile options.
// If the parameter `bReplaceWithDummyData` is true, the named metadata
// are replaced with valid empty data that satisfy tools.
void StripShaderSourcesAndCompileOptions(bool bReplaceWithDummyData = false);
llvm::DebugInfoFinder &GetOrCreateDebugInfoFinder();
static DxilModule *TryGetDxilModule(llvm::Module *pModule);
// Helpers for working with precise.
// Return true if the instruction should be considered precise.
//
// An instruction can be marked precise in the following ways:
//
// 1. Global refactoring is disabled.
// 2. The instruction has a precise metadata annotation.
// 3. The instruction has precise fast math flags set.
//
bool IsPrecise(const llvm::Instruction *inst) const;
// Check if the instruction has fast math flags configured to indicate
// the instruction is precise.
static bool HasPreciseFastMathFlags(const llvm::Instruction *inst);
// Set fast math flags configured to indicate the instruction is precise.
static void SetPreciseFastMathFlags(llvm::Instruction *inst);
// True if fast math flags are preserved across serialize/deserialize.
static bool PreservesFastMathFlags(const llvm::Instruction *inst);
public:
ShaderFlags m_ShaderFlags;
void CollectShaderFlagsForModule(ShaderFlags &Flags);
// Check if DxilModule contains multi component UAV Loads.
// This funciton must be called after unused resources are removed from
// DxilModule
bool ModuleHasMulticomponentUAVLoads();
// Compute/Mesh/Amplification shader.
void SetNumThreads(unsigned x, unsigned y, unsigned z);
unsigned GetNumThreads(unsigned idx) const;
// Compute shader
DxilWaveSize &GetWaveSize();
const DxilWaveSize &GetWaveSize() const;
// Geometry shader.
DXIL::InputPrimitive GetInputPrimitive() const;
void SetInputPrimitive(DXIL::InputPrimitive IP);
unsigned GetMaxVertexCount() const;
void SetMaxVertexCount(unsigned Count);
DXIL::PrimitiveTopology GetStreamPrimitiveTopology() const;
void SetStreamPrimitiveTopology(DXIL::PrimitiveTopology Topology);
bool HasMultipleOutputStreams() const;
unsigned GetOutputStream() const;
unsigned GetGSInstanceCount() const;
void SetGSInstanceCount(unsigned Count);
bool IsStreamActive(unsigned Stream) const;
void SetStreamActive(unsigned Stream, bool bActive);
void SetActiveStreamMask(unsigned Mask);
unsigned GetActiveStreamMask() const;
// Language options
// UseMinPrecision must be set at SetShaderModel time.
bool GetUseMinPrecision() const;
void SetDisableOptimization(bool disableOptimization);
bool GetDisableOptimization() const;
void SetAllResourcesBound(bool resourcesBound);
bool GetAllResourcesBound() const;
void SetResMayAlias(bool resMayAlias);
bool GetResMayAlias() const;
// Intermediate options that do not make it to DXIL
void SetLegacyResourceReservation(bool legacyResourceReservation);
bool GetLegacyResourceReservation() const;
void ClearIntermediateOptions();
// Hull and Domain shaders.
unsigned GetInputControlPointCount() const;
void SetInputControlPointCount(unsigned NumICPs);
DXIL::TessellatorDomain GetTessellatorDomain() const;
void SetTessellatorDomain(DXIL::TessellatorDomain TessDomain);
// Hull shader.
unsigned GetOutputControlPointCount() const;
void SetOutputControlPointCount(unsigned NumOCPs);
DXIL::TessellatorPartitioning GetTessellatorPartitioning() const;
void
SetTessellatorPartitioning(DXIL::TessellatorPartitioning TessPartitioning);
DXIL::TessellatorOutputPrimitive GetTessellatorOutputPrimitive() const;
void SetTessellatorOutputPrimitive(
DXIL::TessellatorOutputPrimitive TessOutputPrimitive);
float GetMaxTessellationFactor() const;
void SetMaxTessellationFactor(float MaxTessellationFactor);
// Mesh shader
unsigned GetMaxOutputVertices() const;
void SetMaxOutputVertices(unsigned NumOVs);
unsigned GetMaxOutputPrimitives() const;
void SetMaxOutputPrimitives(unsigned NumOPs);
DXIL::MeshOutputTopology GetMeshOutputTopology() const;
void SetMeshOutputTopology(DXIL::MeshOutputTopology MeshOutputTopology);
unsigned GetPayloadSizeInBytes() const;
void SetPayloadSizeInBytes(unsigned Size);
// AutoBindingSpace also enables automatic binding for libraries if set.
// UINT_MAX == unset
void SetAutoBindingSpace(uint32_t Space);
uint32_t GetAutoBindingSpace() const;
void SetShaderProperties(DxilFunctionProps *props);
DxilSubobjects *GetSubobjects();
const DxilSubobjects *GetSubobjects() const;
DxilSubobjects *ReleaseSubobjects();
void ResetSubobjects(DxilSubobjects *subobjects);
private:
// Signatures.
std::vector<uint8_t> m_SerializedRootSignature;
// Shader resources.
std::vector<std::unique_ptr<DxilResource>> m_SRVs;
std::vector<std::unique_ptr<DxilResource>> m_UAVs;
std::vector<std::unique_ptr<DxilCBuffer>> m_CBuffers;
std::vector<std::unique_ptr<DxilSampler>> m_Samplers;
// Geometry shader.
DXIL::PrimitiveTopology m_StreamPrimitiveTopology =
DXIL::PrimitiveTopology::Undefined;
unsigned m_ActiveStreamMask = 0;
enum IntermediateFlags : uint32_t {
LegacyResourceReservation = 1 << 0,
};
llvm::LLVMContext &m_Ctx;
llvm::Module *m_pModule = nullptr;
llvm::Function *m_pEntryFunc = nullptr;
std::string m_EntryName = "";
std::unique_ptr<DxilMDHelper> m_pMDHelper;
std::unique_ptr<llvm::DebugInfoFinder> m_pDebugInfoFinder;
const ShaderModel *m_pSM = nullptr;
unsigned m_DxilMajor = DXIL::kDxilMajor;
unsigned m_DxilMinor = DXIL::kDxilMinor;
unsigned m_ValMajor = 1;
unsigned m_ValMinor = 0;
bool m_ForceZeroStoreLifetimes = false;
std::unique_ptr<OP> m_pOP;
// LLVM used.
std::vector<llvm::GlobalVariable *> m_LLVMUsed;
// Type annotations.
std::unique_ptr<DxilTypeSystem> m_pTypeSystem;
// EntryProps for shader functions.
DxilEntryPropsMap m_DxilEntryPropsMap;
// Keeps track of patch constant functions used by hull shaders
std::unordered_set<const llvm::Function *> m_PatchConstantFunctions;
// Serialized ViewId state.
std::vector<unsigned> m_SerializedState;
// properties from HLModule preserved as ShaderFlags
bool m_bDisableOptimizations = false;
bool m_bUseMinPrecision = true; // use min precision by default;
bool m_bAllResourcesBound = false;
bool m_bResMayAlias = false;
// properties from HLModule that should not make it to the final DXIL
uint32_t m_IntermediateFlags = 0;
uint32_t m_AutoBindingSpace = UINT_MAX;
std::unique_ptr<DxilSubobjects> m_pSubobjects;
// m_bMetadataErrors is true if non-fatal metadata errors were encountered.
// Validator will fail in this case, but should not block module load.
bool m_bMetadataErrors = false;
// DXIL metadata serialization/deserialization.
llvm::MDTuple *EmitDxilResources();
void LoadDxilResources(const llvm::MDOperand &MDO);
// Helpers.
template <typename T>
unsigned AddResource(std::vector<std::unique_ptr<T>> &Vec,
std::unique_ptr<T> pRes);
void LoadDxilSignature(const llvm::MDTuple *pSigTuple, DxilSignature &Sig,
bool bInput);
public:
// ShaderCompatInfo tracks requirements per-function, subsequently merged into
// final entry function requirements.
struct ShaderCompatInfo {
unsigned minMajor = 6, minMinor = 0;
// 'mask' is a set of bits representing each compatible shader kind.
// Mapping is: 1 << (unsigned)DXIL::ShaderKind::<kind>.
// Starts out with all kinds valid, will be masked down based on features
// used and by known shader kinds for a particular validation version.
unsigned mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Invalid) - 1;
ShaderFlags shaderFlags;
bool Merge(ShaderCompatInfo &other);
};
// Compute ShaderCompatInfo for all functions in module.
void ComputeShaderCompatInfo();
const ShaderCompatInfo *
GetCompatInfoForFunction(const llvm::Function *F) const;
private:
typedef std::unordered_map<const llvm::Function *, ShaderCompatInfo>
FunctionShaderCompatMap;
FunctionShaderCompatMap m_FuncToShaderCompat;
void UpdateFunctionToShaderCompat(const llvm::Function *dxilFunc);
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilSigPoint.inl | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilSigPoint.inl //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
///////////////////////////////////////////////////////////////////////////////
/* <py>
import hctdb_instrhelp
</py> */
namespace hlsl {
// Related points to a SigPoint that would contain the signature element for a
// "Shadow" element. A "Shadow" element isn't actually accessed through that
// signature's Load/Store Input/Output. Instead, it uses a dedicated intrinsic,
// but still requires that an entry exist in the signature for compatibility
// purposes.
// <py::lines('SIGPOINT-TABLE')>hctdb_instrhelp.get_sigpoint_table()</py>
// SIGPOINT-TABLE:BEGIN
// SigPoint, Related, ShaderKind, PackingKind, SignatureKind
#define DO_SIGPOINTS(ROW) \
ROW(VSIn, Invalid, Vertex, InputAssembler, Input) \
ROW(VSOut, Invalid, Vertex, Vertex, Output) \
ROW(PCIn, HSCPIn, Hull, None, Invalid) \
ROW(HSIn, HSCPIn, Hull, None, Invalid) \
ROW(HSCPIn, Invalid, Hull, Vertex, Input) \
ROW(HSCPOut, Invalid, Hull, Vertex, Output) \
ROW(PCOut, Invalid, Hull, PatchConstant, PatchConstOrPrim) \
ROW(DSIn, Invalid, Domain, PatchConstant, PatchConstOrPrim) \
ROW(DSCPIn, Invalid, Domain, Vertex, Input) \
ROW(DSOut, Invalid, Domain, Vertex, Output) \
ROW(GSVIn, Invalid, Geometry, Vertex, Input) \
ROW(GSIn, GSVIn, Geometry, None, Invalid) \
ROW(GSOut, Invalid, Geometry, Vertex, Output) \
ROW(PSIn, Invalid, Pixel, Vertex, Input) \
ROW(PSOut, Invalid, Pixel, Target, Output) \
ROW(CSIn, Invalid, Compute, None, Invalid) \
ROW(MSIn, Invalid, Mesh, None, Invalid) \
ROW(MSOut, Invalid, Mesh, Vertex, Output) \
ROW(MSPOut, Invalid, Mesh, Vertex, PatchConstOrPrim) \
ROW(ASIn, Invalid, Amplification, None, Invalid) \
ROW(Invalid, Invalid, Invalid, Invalid, Invalid)
// SIGPOINT-TABLE:END
const SigPoint SigPoint::ms_SigPoints[kNumSigPointRecords] = {
#define DEF_SIGPOINT(spk, rspk, shk, pk, sigk) \
SigPoint(DXIL::SigPointKind::spk, #spk, DXIL::SigPointKind::rspk, \
DXIL::ShaderKind::shk, DXIL::SignatureKind::sigk, \
DXIL::PackingKind::pk),
DO_SIGPOINTS(DEF_SIGPOINT)
#undef DEF_SIGPOINT
};
// clang-format off
// Python lines need to be not formatted.
// <py::lines('INTERPRETATION-TABLE')>hctdb_instrhelp.get_interpretation_table()</py>
// clang-format on
// INTERPRETATION-TABLE:BEGIN
// Semantic, VSIn, VSOut, PCIn, HSIn, HSCPIn,
// HSCPOut, PCOut, DSIn, DSCPIn, DSOut, GSVIn, GSIn,
// GSOut, PSIn, PSOut, CSIn, MSIn, MSOut, MSPOut,
// ASIn
#define DO_INTERPRETATION_TABLE(ROW) \
ROW(Arbitrary, Arb, Arb, NA, NA, Arb, Arb, Arb, Arb, Arb, Arb, Arb, NA, Arb, \
Arb, NA, NA, NA, Arb, Arb, NA) \
ROW(VertexID, SV, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NA, NA, NA, NA) \
ROW(InstanceID, SV, Arb, NA, NA, Arb, Arb, NA, NA, Arb, Arb, Arb, NA, Arb, \
Arb, NA, NA, NA, NA, NA, NA) \
ROW(Position, Arb, SV, NA, NA, SV, SV, Arb, Arb, SV, SV, SV, NA, SV, SV, NA, \
NA, NA, SV, NA, NA) \
ROW(RenderTargetArrayIndex, Arb, SV, NA, NA, SV, SV, Arb, Arb, SV, SV, SV, \
NA, SV, SV, NA, NA, NA, NA, SV, NA) \
ROW(ViewPortArrayIndex, Arb, SV, NA, NA, SV, SV, Arb, Arb, SV, SV, SV, NA, \
SV, SV, NA, NA, NA, NA, SV, NA) \
ROW(ClipDistance, Arb, ClipCull, NA, NA, ClipCull, ClipCull, Arb, Arb, \
ClipCull, ClipCull, ClipCull, NA, ClipCull, ClipCull, NA, NA, NA, \
ClipCull, NA, NA) \
ROW(CullDistance, Arb, ClipCull, NA, NA, ClipCull, ClipCull, Arb, Arb, \
ClipCull, ClipCull, ClipCull, NA, ClipCull, ClipCull, NA, NA, NA, \
ClipCull, NA, NA) \
ROW(OutputControlPointID, NA, NA, NA, NotInSig, NA, NA, NA, NA, NA, NA, NA, \
NA, NA, NA, NA, NA, NA, NA, NA, NA) \
ROW(DomainLocation, NA, NA, NA, NA, NA, NA, NA, NotInSig, NA, NA, NA, NA, \
NA, NA, NA, NA, NA, NA, NA, NA) \
ROW(PrimitiveID, NA, NA, NotInSig, NotInSig, NA, NA, NA, NotInSig, NA, NA, \
NA, Shadow, SGV, SGV, NA, NA, NA, NA, SV, NA) \
ROW(GSInstanceID, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NotInSig, NA, \
NA, NA, NA, NA, NA, NA, NA) \
ROW(SampleIndex, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
Shadow _41, NA, NA, NA, NA, NA, NA) \
ROW(IsFrontFace, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, SGV, SGV, \
NA, NA, NA, NA, NA, NA) \
ROW(Coverage, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotInSig _50, NotPacked _41, NA, NA, NA, NA, NA) \
ROW(InnerCoverage, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotInSig _50, NA, NA, NA, NA, NA, NA) \
ROW(Target, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, Target, \
NA, NA, NA, NA, NA) \
ROW(Depth, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotPacked, NA, NA, NA, NA, NA) \
ROW(DepthLessEqual, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotPacked _50, NA, NA, NA, NA, NA) \
ROW(DepthGreaterEqual, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NotPacked _50, NA, NA, NA, NA, NA) \
ROW(StencilRef, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotPacked _50, NA, NA, NA, NA, NA) \
ROW(DispatchThreadID, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NA, NotInSig, NotInSig, NA, NA, NotInSig) \
ROW(GroupID, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotInSig, NotInSig, NA, NA, NotInSig) \
ROW(GroupIndex, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotInSig, NotInSig, NA, NA, NotInSig) \
ROW(GroupThreadID, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NotInSig, NotInSig, NA, NA, NotInSig) \
ROW(TessFactor, NA, NA, NA, NA, NA, NA, TessFactor, TessFactor, NA, NA, NA, \
NA, NA, NA, NA, NA, NA, NA, NA, NA) \
ROW(InsideTessFactor, NA, NA, NA, NA, NA, NA, TessFactor, TessFactor, NA, \
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA) \
ROW(ViewID, NotInSig _61, NA, NotInSig _61, NotInSig _61, NA, NA, NA, \
NotInSig _61, NA, NA, NA, NotInSig _61, NA, NotInSig _61, NA, NA, \
NotInSig, NA, NA, NA) \
ROW(Barycentrics, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotPacked _61, NA, NA, NA, NA, NA, NA) \
ROW(ShadingRate, NA, SV _64, NA, NA, SV _64, SV _64, NA, NA, SV _64, SV _64, \
SV _64, NA, SV _64, SV _64, NA, NA, NA, NA, SV, NA) \
ROW(CullPrimitive, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NotInSig, NA, NA, NA, NA, NotPacked, NA) \
ROW(StartVertexLocation, NotInSig _68, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA) \
ROW(StartInstanceLocation, NotInSig _68, NA, NA, NA, NA, NA, NA, NA, NA, NA, \
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)
// INTERPRETATION-TABLE:END
const VersionedSemanticInterpretation SigPoint::ms_SemanticInterpretationTable[(
unsigned)DXIL::SemanticKind::Invalid][(unsigned)SigPoint::Kind::Invalid] = {
#define _41 , 4, 1
#define _50 , 5, 0
#define _61 , 6, 1
#define _64 , 6, 4
#define _65 , 6, 5
#define _68 , 6, 8
#define DO_ROW(SEM, VSIn, VSOut, PCIn, HSIn, HSCPIn, HSCPOut, PCOut, DSIn, \
DSCPIn, DSOut, GSVIn, GSIn, GSOut, PSIn, PSOut, CSIn, MSIn, \
MSOut, MSPOut, ASIn) \
{ \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::VSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::VSOut), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::PCIn), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::HSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::HSCPIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::HSCPOut), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::PCOut), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::DSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::DSCPIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::DSOut), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::GSVIn), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::GSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::GSOut), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::PSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::PSOut), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::CSIn), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::MSIn), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::MSOut), \
VersionedSemanticInterpretation( \
DXIL::SemanticInterpretationKind::MSPOut), \
VersionedSemanticInterpretation(DXIL::SemanticInterpretationKind::ASIn), \
},
DO_INTERPRETATION_TABLE(DO_ROW)
#undef DO_ROW
};
// -----------------------
// SigPoint Implementation
SigPoint::SigPoint(DXIL::SigPointKind spk, const char *name,
DXIL::SigPointKind rspk, DXIL::ShaderKind shk,
DXIL::SignatureKind sigk, DXIL::PackingKind pk)
: m_Kind(spk), m_RelatedKind(rspk), m_ShaderKind(shk),
m_SignatureKind(sigk), m_pszName(name), m_PackingKind(pk) {}
DXIL::SignatureKind SigPoint::GetSignatureKindWithFallback() const {
DXIL::SignatureKind sigKind = GetSignatureKind();
if (sigKind == DXIL::SignatureKind::Invalid) {
DXIL::SigPointKind RK = GetRelatedKind();
if (RK != DXIL::SigPointKind::Invalid)
sigKind = SigPoint::GetSigPoint(RK)->GetSignatureKind();
}
return sigKind;
}
DXIL::SemanticInterpretationKind
SigPoint::GetInterpretation(DXIL::SemanticKind SK, Kind K,
unsigned MajorVersion, unsigned MinorVersion) {
if (SK < DXIL::SemanticKind::Invalid && K < Kind::Invalid) {
const VersionedSemanticInterpretation &VSI =
ms_SemanticInterpretationTable[(unsigned)SK][(unsigned)K];
if (VSI.Kind != DXIL::SemanticInterpretationKind::NA) {
if (MajorVersion > (unsigned)VSI.Major ||
(MajorVersion == (unsigned)VSI.Major &&
MinorVersion >= (unsigned)VSI.Minor))
return VSI.Kind;
}
}
return DXIL::SemanticInterpretationKind::NA;
}
SigPoint::Kind SigPoint::RecoverKind(DXIL::SemanticKind SK, Kind K) {
if (SK == DXIL::SemanticKind::PrimitiveID && K == Kind::GSVIn)
return Kind::GSIn;
return K;
}
// --------------
// Static methods
const SigPoint *SigPoint::GetSigPoint(Kind K) {
return ((unsigned)K < kNumSigPointRecords)
? &ms_SigPoints[(unsigned)K]
: &ms_SigPoints[(unsigned)Kind::Invalid];
}
DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind,
DXIL::SignatureKind sigKind,
bool isPatchConstantFunction,
bool isSpecialInput) {
if (isSpecialInput) {
switch (shaderKind) {
case DXIL::ShaderKind::Hull:
if (sigKind == DXIL::SignatureKind::Input)
return isPatchConstantFunction ? DXIL::SigPointKind::PCIn
: DXIL::SigPointKind::HSIn;
break;
case DXIL::ShaderKind::Geometry:
if (sigKind == DXIL::SignatureKind::Input)
return DXIL::SigPointKind::GSIn;
break;
default:
break;
}
}
switch (shaderKind) {
case DXIL::ShaderKind::Vertex:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::VSIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::VSOut;
default:
break;
}
break;
case DXIL::ShaderKind::Hull:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::HSCPIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::HSCPOut;
case DXIL::SignatureKind::PatchConstOrPrim:
return DXIL::SigPointKind::PCOut;
default:
break;
}
break;
case DXIL::ShaderKind::Domain:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::DSCPIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::DSOut;
case DXIL::SignatureKind::PatchConstOrPrim:
return DXIL::SigPointKind::DSIn;
default:
break;
}
break;
case DXIL::ShaderKind::Geometry:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::GSVIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::GSOut;
default:
break;
}
break;
case DXIL::ShaderKind::Pixel:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::PSIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::PSOut;
default:
break;
}
break;
case DXIL::ShaderKind::Compute:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::CSIn;
default:
break;
}
break;
case DXIL::ShaderKind::Mesh:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::MSIn;
case DXIL::SignatureKind::Output:
return DXIL::SigPointKind::MSOut;
case DXIL::SignatureKind::PatchConstOrPrim:
return DXIL::SigPointKind::MSPOut;
default:
break;
}
break;
case DXIL::ShaderKind::Amplification:
switch (sigKind) {
case DXIL::SignatureKind::Input:
return DXIL::SigPointKind::ASIn;
default:
break;
}
break;
default:
break;
}
return DXIL::SigPointKind::Invalid;
}
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilOperations.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilOperations.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Implementation of DXIL operation tables. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
namespace llvm {
class LLVMContext;
class Module;
class Type;
class StructType;
class PointerType;
class Function;
class Constant;
class Value;
class Instruction;
class CallInst;
} // namespace llvm
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/IR/Attributes.h"
#include "DxilConstants.h"
#include <unordered_map>
namespace hlsl {
/// Use this utility class to interact with DXIL operations.
class OP {
public:
using OpCode = DXIL::OpCode;
using OpCodeClass = DXIL::OpCodeClass;
public:
OP() = delete;
OP(llvm::LLVMContext &Ctx, llvm::Module *pModule);
// InitWithMinPrecision sets the low-precision mode and calls
// FixOverloadNames() and RefreshCache() to set up caches for any existing
// DXIL operations and types used in the module.
void InitWithMinPrecision(bool bMinPrecision);
// FixOverloadNames fixes the names of DXIL operation overloads, particularly
// when they depend on user defined type names. User defined type names can be
// modified by name collisions from multiple modules being loaded into the
// same llvm context, such as during module linking.
void FixOverloadNames();
// RefreshCache places DXIL types and operation overloads from the module into
// caches.
void RefreshCache();
llvm::Function *GetOpFunc(OpCode OpCode, llvm::Type *pOverloadType);
const llvm::SmallMapVector<llvm::Type *, llvm::Function *, 8> &
GetOpFuncList(OpCode OpCode) const;
bool IsDxilOpUsed(OpCode opcode) const;
void RemoveFunction(llvm::Function *F);
llvm::LLVMContext &GetCtx() { return m_Ctx; }
llvm::Type *GetHandleType() const;
llvm::Type *GetNodeHandleType() const;
llvm::Type *GetNodeRecordHandleType() const;
llvm::Type *GetResourcePropertiesType() const;
llvm::Type *GetNodePropertiesType() const;
llvm::Type *GetNodeRecordPropertiesType() const;
llvm::Type *GetResourceBindingType() const;
llvm::Type *GetDimensionsType() const;
llvm::Type *GetSamplePosType() const;
llvm::Type *GetBinaryWithCarryType() const;
llvm::Type *GetBinaryWithTwoOutputsType() const;
llvm::Type *GetSplitDoubleType() const;
llvm::Type *GetFourI32Type() const;
llvm::Type *GetFourI16Type() const;
llvm::Type *GetResRetType(llvm::Type *pOverloadType);
llvm::Type *GetCBufferRetType(llvm::Type *pOverloadType);
llvm::Type *GetVectorType(unsigned numElements, llvm::Type *pOverloadType);
bool IsResRetType(llvm::Type *Ty);
// Try to get the opcode class for a function.
// Return true and set `opClass` if the given function is a dxil function.
// Return false if the given function is not a dxil function.
bool GetOpCodeClass(const llvm::Function *F, OpCodeClass &opClass);
// To check if operation uses strict precision types
bool UseMinPrecision();
// Get the size of the type for a given layout
uint64_t GetAllocSizeForType(llvm::Type *Ty);
// LLVM helpers. Perhaps, move to a separate utility class.
llvm::Constant *GetI1Const(bool v);
llvm::Constant *GetI8Const(char v);
llvm::Constant *GetU8Const(unsigned char v);
llvm::Constant *GetI16Const(int v);
llvm::Constant *GetU16Const(unsigned v);
llvm::Constant *GetI32Const(int v);
llvm::Constant *GetU32Const(unsigned v);
llvm::Constant *GetU64Const(unsigned long long v);
llvm::Constant *GetFloatConst(float v);
llvm::Constant *GetDoubleConst(double v);
static OP::OpCode getOpCode(const llvm::Instruction *I);
static llvm::Type *GetOverloadType(OpCode OpCode, llvm::Function *F);
static OpCode GetDxilOpFuncCallInst(const llvm::Instruction *I);
static const char *GetOpCodeName(OpCode OpCode);
static const char *GetAtomicOpName(DXIL::AtomicBinOpCode OpCode);
static OpCodeClass GetOpCodeClass(OpCode OpCode);
static const char *GetOpCodeClassName(OpCode OpCode);
static llvm::Attribute::AttrKind GetMemAccessAttr(OpCode opCode);
static bool IsOverloadLegal(OpCode OpCode, llvm::Type *pType);
static bool CheckOpCodeTable();
static bool IsDxilOpFuncName(llvm::StringRef name);
static bool IsDxilOpFunc(const llvm::Function *F);
static bool IsDxilOpFuncCallInst(const llvm::Instruction *I);
static bool IsDxilOpFuncCallInst(const llvm::Instruction *I, OpCode opcode);
static bool IsDxilOpWave(OpCode C);
static bool IsDxilOpGradient(OpCode C);
static bool IsDxilOpFeedback(OpCode C);
static bool IsDxilOpBarrier(OpCode C);
static bool BarrierRequiresGroup(const llvm::CallInst *CI);
static bool BarrierRequiresNode(const llvm::CallInst *CI);
static DXIL::BarrierMode TranslateToBarrierMode(const llvm::CallInst *CI);
static bool IsDxilOpTypeName(llvm::StringRef name);
static bool IsDxilOpType(llvm::StructType *ST);
static bool IsDupDxilOpType(llvm::StructType *ST);
static llvm::StructType *GetOriginalDxilOpType(llvm::StructType *ST,
llvm::Module &M);
static void GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
unsigned &major, unsigned &minor,
unsigned &mask);
static void GetMinShaderModelAndMask(const llvm::CallInst *CI,
bool bWithTranslation, unsigned valMajor,
unsigned valMinor, unsigned &major,
unsigned &minor, unsigned &mask);
private:
// Per-module properties.
llvm::LLVMContext &m_Ctx;
llvm::Module *m_pModule;
llvm::Type *m_pHandleType;
llvm::Type *m_pNodeHandleType;
llvm::Type *m_pNodeRecordHandleType;
llvm::Type *m_pResourcePropertiesType;
llvm::Type *m_pNodePropertiesType;
llvm::Type *m_pNodeRecordPropertiesType;
llvm::Type *m_pResourceBindingType;
llvm::Type *m_pDimensionsType;
llvm::Type *m_pSamplePosType;
llvm::Type *m_pBinaryWithCarryType;
llvm::Type *m_pBinaryWithTwoOutputsType;
llvm::Type *m_pSplitDoubleType;
llvm::Type *m_pFourI32Type;
llvm::Type *m_pFourI16Type;
DXIL::LowPrecisionMode m_LowPrecisionMode;
static const unsigned kUserDefineTypeSlot = 9;
static const unsigned kObjectTypeSlot = 10;
static const unsigned kNumTypeOverloads =
11; // void, h,f,d, i1, i8,i16,i32,i64, udt, obj
llvm::Type *m_pResRetType[kNumTypeOverloads];
llvm::Type *m_pCBufferRetType[kNumTypeOverloads];
struct OpCodeCacheItem {
llvm::SmallMapVector<llvm::Type *, llvm::Function *, 8> pOverloads;
};
OpCodeCacheItem m_OpCodeClassCache[(unsigned)OpCodeClass::NumOpClasses];
std::unordered_map<const llvm::Function *, OpCodeClass> m_FunctionToOpClass;
void UpdateCache(OpCodeClass opClass, llvm::Type *Ty, llvm::Function *F);
private:
// Static properties.
struct OpCodeProperty {
OpCode opCode;
const char *pOpCodeName;
OpCodeClass opCodeClass;
const char *pOpCodeClassName;
bool bAllowOverload[kNumTypeOverloads]; // void, h,f,d, i1, i8,i16,i32,i64,
// udt
llvm::Attribute::AttrKind FuncAttr;
};
static const OpCodeProperty m_OpCodeProps[(unsigned)OpCode::NumOpCodes];
static const char *m_OverloadTypeName[kNumTypeOverloads];
static const char *m_NamePrefix;
static const char *m_TypePrefix;
static const char *m_MatrixTypePrefix;
static unsigned GetTypeSlot(llvm::Type *pType);
static const char *GetOverloadTypeName(unsigned TypeSlot);
static llvm::StringRef GetTypeName(llvm::Type *Ty, std::string &str);
static llvm::StringRef ConstructOverloadName(llvm::Type *Ty,
DXIL::OpCode opCode,
std::string &funcNameStorage);
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilEntryProps.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilEntryProps.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Put entry signature and function props together. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilFunctionProps.h"
#include "dxc/DXIL/DxilSignature.h"
namespace hlsl {
class DxilEntryProps {
public:
DxilEntrySignature sig;
DxilFunctionProps props;
DxilEntryProps(DxilFunctionProps &p, bool bUseMinPrecision)
: sig(p.shaderKind, bUseMinPrecision), props(p) {}
DxilEntryProps(DxilEntryProps &p) : sig(p.sig), props(p.props) {}
};
} // namespace hlsl |
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilResourceBase.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilResourceBase.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Base class to represent DXIL SRVs, UAVs, CBuffers, and Samplers. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
#include "DxilConstants.h"
namespace llvm {
class Value;
class Constant;
class Type;
} // namespace llvm
namespace hlsl {
/// Base class to represent HLSL SRVs, UAVs, CBuffers, and Samplers.
class DxilResourceBase {
public:
using Class = DXIL::ResourceClass;
using Kind = DXIL::ResourceKind;
public:
DxilResourceBase(Class C);
virtual ~DxilResourceBase() {}
Class GetClass() const;
DxilResourceBase::Kind GetKind() const;
unsigned GetID() const;
unsigned GetSpaceID() const;
unsigned GetLowerBound() const;
unsigned GetUpperBound() const;
unsigned GetRangeSize() const;
llvm::Constant *GetGlobalSymbol() const;
llvm::Type *GetHLSLType() const;
const std::string &GetGlobalName() const;
llvm::Value *GetHandle() const;
bool IsAllocated() const;
bool IsUnbounded() const;
void SetKind(DxilResourceBase::Kind ResourceKind);
void SetSpaceID(unsigned SpaceID);
void SetLowerBound(unsigned LB);
void SetRangeSize(unsigned RangeSize);
void SetGlobalSymbol(llvm::Constant *pGV);
void SetGlobalName(const std::string &Name);
void SetHandle(llvm::Value *pHandle);
void SetHLSLType(llvm::Type *Ty);
// TODO: check whether we can make this a protected method.
void SetID(unsigned ID);
const char *GetResClassName() const;
const char *GetResDimName() const;
const char *GetResIDPrefix() const;
const char *GetResBindPrefix() const;
const char *GetResKindName() const;
protected:
void SetClass(Class C);
private:
Class m_Class; // Resource class (SRV, UAV, CBuffer, Sampler).
Kind m_Kind; // Detail resource kind( texture2D...).
unsigned m_ID; // Unique ID within the class.
unsigned m_SpaceID; // Root signature space.
unsigned m_LowerBound; // Range lower bound.
unsigned m_RangeSize; // Range size in entries.
llvm::Constant *m_pSymbol; // Global variable.
std::string m_Name; // Unmangled name of the global variable.
llvm::Value
*m_pHandle; // Cached resource handle for SM5.0- (and maybe SM5.1).
llvm::Type *m_pHLSLTy; // The original hlsl type for reflection.
};
const char *GetResourceKindName(DXIL::ResourceKind K);
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilInstructions.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilInstructions.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// This file provides a library of instruction helper classes. //
// MUCH WORK YET TO BE DONE - EXPECT THIS WILL CHANGE - GENERATED FILE //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "dxc/DXIL/DxilOperations.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
// TODO: add accessors with values
// TODO: add validation support code, including calling into right fn
// TODO: add type hierarchy
namespace hlsl {
/* <py>
import hctdb_instrhelp
</py> */
/* <py::lines('INSTR-HELPER')>hctdb_instrhelp.get_instrhelper()</py>*/
// INSTR-HELPER:BEGIN
/// This instruction returns a value (possibly void), from a function.
struct LlvmInst_Ret {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Ret(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Ret; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction branches (conditional or unconditional)
struct LlvmInst_Br {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Br(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Br; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction performs a multiway switch
struct LlvmInst_Switch {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Switch(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Switch;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction branches indirectly
struct LlvmInst_IndirectBr {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_IndirectBr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::IndirectBr;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction invokes function with normal and exceptional returns
struct LlvmInst_Invoke {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Invoke(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Invoke;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction resumes the propagation of an exception
struct LlvmInst_Resume {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Resume(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Resume;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction is unreachable
struct LlvmInst_Unreachable {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Unreachable(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Unreachable;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction returns the sum of its two operands
struct LlvmInst_Add {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Add(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Add; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the sum of its two operands
struct LlvmInst_FAdd {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FAdd(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FAdd;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the difference of its two operands
struct LlvmInst_Sub {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Sub(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Sub; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the difference of its two operands
struct LlvmInst_FSub {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FSub(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FSub;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the product of its two operands
struct LlvmInst_Mul {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Mul(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Mul; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the product of its two operands
struct LlvmInst_FMul {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FMul(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FMul;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the quotient of its two unsigned operands
struct LlvmInst_UDiv {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_UDiv(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::UDiv;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the quotient of its two signed operands
struct LlvmInst_SDiv {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_SDiv(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::SDiv;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the quotient of its two operands
struct LlvmInst_FDiv {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FDiv(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FDiv;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the remainder from the unsigned division of its two
/// operands
struct LlvmInst_URem {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_URem(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::URem;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the remainder from the signed division of its two
/// operands
struct LlvmInst_SRem {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_SRem(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::SRem;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns the remainder from the division of its two operands
struct LlvmInst_FRem {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FRem(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FRem;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction shifts left (logical)
struct LlvmInst_Shl {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Shl(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Shl; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction shifts right (logical), with zero bit fill
struct LlvmInst_LShr {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_LShr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::LShr;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction shifts right (arithmetic), with 'a' operand sign bit fill
struct LlvmInst_AShr {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_AShr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::AShr;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns a bitwise logical and of its two operands
struct LlvmInst_And {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_And(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::And; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns a bitwise logical or of its two operands
struct LlvmInst_Or {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Or(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Or; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction returns a bitwise logical xor of its two operands
struct LlvmInst_Xor {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Xor(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::Xor; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction allocates memory on the stack frame of the currently
/// executing function
struct LlvmInst_Alloca {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Alloca(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Alloca;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction reads from memory
struct LlvmInst_Load {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Load(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Load;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction writes to memory
struct LlvmInst_Store {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Store(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Store;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction gets the address of a subelement of an aggregate value
struct LlvmInst_GetElementPtr {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_GetElementPtr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::GetElementPtr;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction introduces happens-before edges between operations
struct LlvmInst_Fence {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Fence(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Fence;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction atomically modifies memory
struct LlvmInst_AtomicCmpXchg {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_AtomicCmpXchg(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::AtomicCmpXchg;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction atomically modifies memory
struct LlvmInst_AtomicRMW {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_AtomicRMW(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::AtomicRMW;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction truncates an integer
struct LlvmInst_Trunc {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Trunc(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Trunc;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction zero extends an integer
struct LlvmInst_ZExt {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_ZExt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::ZExt;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction sign extends an integer
struct LlvmInst_SExt {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_SExt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::SExt;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction converts a floating point to UInt
struct LlvmInst_FPToUI {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FPToUI(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FPToUI;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction converts a floating point to SInt
struct LlvmInst_FPToSI {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FPToSI(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FPToSI;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction converts a UInt to floating point
struct LlvmInst_UIToFP {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_UIToFP(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::UIToFP;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction converts a SInt to floating point
struct LlvmInst_SIToFP {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_SIToFP(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::SIToFP;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction truncates a floating point
struct LlvmInst_FPTrunc {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FPTrunc(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FPTrunc;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction extends a floating point
struct LlvmInst_FPExt {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FPExt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FPExt;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction converts a pointer to integer
struct LlvmInst_PtrToInt {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_PtrToInt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::PtrToInt;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction converts an integer to Pointer
struct LlvmInst_IntToPtr {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_IntToPtr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::IntToPtr;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction performs a bit-preserving type cast
struct LlvmInst_BitCast {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_BitCast(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::BitCast;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction casts a value addrspace
struct LlvmInst_AddrSpaceCast {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_AddrSpaceCast(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::AddrSpaceCast;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction compares integers
struct LlvmInst_ICmp {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_ICmp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::ICmp;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction compares floating points
struct LlvmInst_FCmp {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_FCmp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::FCmp;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction is a PHI node instruction
struct LlvmInst_PHI {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_PHI(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const { return Instr->getOpcode() == llvm::Instruction::PHI; }
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction calls a function
struct LlvmInst_Call {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Call(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Call;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction selects an instruction
struct LlvmInst_Select {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_Select(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::Select;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction may be used internally in a pass
struct LlvmInst_UserOp1 {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_UserOp1(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::UserOp1;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction internal to passes only
struct LlvmInst_UserOp2 {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_UserOp2(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::UserOp2;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction vaarg instruction
struct LlvmInst_VAArg {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_VAArg(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::VAArg;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction extracts from aggregate
struct LlvmInst_ExtractValue {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_ExtractValue(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::ExtractValue;
}
// Validation support
bool isAllowed() const { return true; }
};
/// This instruction represents a landing pad
struct LlvmInst_LandingPad {
llvm::Instruction *Instr;
// Construction and identification
LlvmInst_LandingPad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return Instr->getOpcode() == llvm::Instruction::LandingPad;
}
// Validation support
bool isAllowed() const { return false; }
};
/// This instruction Helper load operation
struct DxilInst_TempRegLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TempRegLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::TempRegLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_index = 1,
};
// Accessors
llvm::Value *get_index() const { return Instr->getOperand(1); }
void set_index(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Helper store operation
struct DxilInst_TempRegStore {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TempRegStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TempRegStore);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_index = 1,
arg_value = 2,
};
// Accessors
llvm::Value *get_index() const { return Instr->getOperand(1); }
void set_index(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_value() const { return Instr->getOperand(2); }
void set_value(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction Helper load operation for minprecision
struct DxilInst_MinPrecXRegLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_MinPrecXRegLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::MinPrecXRegLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_regIndex = 1,
arg_index = 2,
arg_component = 3,
};
// Accessors
llvm::Value *get_regIndex() const { return Instr->getOperand(1); }
void set_regIndex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_component() const { return Instr->getOperand(3); }
void set_component(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Helper store operation for minprecision
struct DxilInst_MinPrecXRegStore {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_MinPrecXRegStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::MinPrecXRegStore);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_regIndex = 1,
arg_index = 2,
arg_component = 3,
arg_value = 4,
};
// Accessors
llvm::Value *get_regIndex() const { return Instr->getOperand(1); }
void set_regIndex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_component() const { return Instr->getOperand(3); }
void set_component(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value() const { return Instr->getOperand(4); }
void set_value(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction Loads the value from shader input
struct DxilInst_LoadInput {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LoadInput(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::LoadInput);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_rowIndex = 2,
arg_colIndex = 3,
arg_gsVertexAxis = 4,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_rowIndex() const { return Instr->getOperand(2); }
void set_rowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_colIndex() const { return Instr->getOperand(3); }
void set_colIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_gsVertexAxis() const { return Instr->getOperand(4); }
void set_gsVertexAxis(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction Stores the value to shader output
struct DxilInst_StoreOutput {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StoreOutput(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::StoreOutput);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_outputSigId = 1,
arg_rowIndex = 2,
arg_colIndex = 3,
arg_value = 4,
};
// Accessors
llvm::Value *get_outputSigId() const { return Instr->getOperand(1); }
void set_outputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_rowIndex() const { return Instr->getOperand(2); }
void set_rowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_colIndex() const { return Instr->getOperand(3); }
void set_colIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value() const { return Instr->getOperand(4); }
void set_value(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction returns the absolute value of the input value.
struct DxilInst_FAbs {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FAbs(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FAbs);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction clamps the result of a single or double precision floating
/// point value to [0.0f...1.0f]
struct DxilInst_Saturate {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Saturate(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Saturate);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns true if x is NAN or QNAN, false otherwise.
struct DxilInst_IsNaN {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IsNaN(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IsNaN);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns true if x is +INF or -INF, false otherwise.
struct DxilInst_IsInf {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IsInf(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IsInf);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns true if x is finite, false otherwise.
struct DxilInst_IsFinite {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IsFinite(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IsFinite);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns IsNormal
struct DxilInst_IsNormal {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IsNormal(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IsNormal);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns cosine(theta) for theta in radians.
struct DxilInst_Cos {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Cos(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Cos);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns sine(theta) for theta in radians.
struct DxilInst_Sin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Sin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Sin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns tan(theta) for theta in radians.
struct DxilInst_Tan {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Tan(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Tan);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the arccosine of the specified value. Input should
/// be a floating-point value within the range of -1 to 1.
struct DxilInst_Acos {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Acos(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Acos);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the arccosine of the specified value. Input should
/// be a floating-point value within the range of -1 to 1
struct DxilInst_Asin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Asin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Asin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the arctangent of the specified value. The return
/// value is within the range of -PI/2 to PI/2.
struct DxilInst_Atan {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Atan(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Atan);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the hyperbolic cosine of the specified value.
struct DxilInst_Hcos {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Hcos(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Hcos);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the hyperbolic sine of the specified value.
struct DxilInst_Hsin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Hsin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Hsin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the hyperbolic tangent of the specified value.
struct DxilInst_Htan {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Htan(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Htan);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns 2^exponent
struct DxilInst_Exp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Exp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Exp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction extract fracitonal component.
struct DxilInst_Frc {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Frc(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Frc);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns log base 2.
struct DxilInst_Log {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Log(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Log);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns square root
struct DxilInst_Sqrt {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Sqrt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Sqrt);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns reciprocal square root (1 / sqrt(src)
struct DxilInst_Rsqrt {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Rsqrt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Rsqrt);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction floating-point round to integral float.
struct DxilInst_Round_ne {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Round_ne(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Round_ne);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction floating-point round to integral float.
struct DxilInst_Round_ni {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Round_ni(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Round_ni);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction floating-point round to integral float.
struct DxilInst_Round_pi {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Round_pi(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Round_pi);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction floating-point round to integral float.
struct DxilInst_Round_z {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Round_z(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Round_z);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Reverses the order of the bits.
struct DxilInst_Bfrev {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Bfrev(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Bfrev);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Counts the number of bits in the input integer.
struct DxilInst_Countbits {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Countbits(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Countbits);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the location of the first set bit starting from the
/// lowest order bit and working upward.
struct DxilInst_FirstbitLo {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FirstbitLo(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FirstbitLo);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the location of the first set bit starting from the
/// highest order bit and working downward.
struct DxilInst_FirstbitHi {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FirstbitHi(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FirstbitHi);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Returns the location of the first set bit from the highest
/// order bit based on the sign.
struct DxilInst_FirstbitSHi {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FirstbitSHi(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FirstbitSHi);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns a if a >= b, else b
struct DxilInst_FMax {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FMax(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FMax);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction returns a if a < b, else b
struct DxilInst_FMin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FMin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FMin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction IMax(a,b) returns a if a > b, else b
struct DxilInst_IMax {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IMax(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IMax);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction IMin(a,b) returns a if a < b, else b
struct DxilInst_IMin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IMin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IMin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction unsigned integer maximum. UMax(a,b) = a > b ? a : b
struct DxilInst_UMax {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UMax(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UMax);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction unsigned integer minimum. UMin(a,b) = a < b ? a : b
struct DxilInst_UMin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UMin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UMin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction multiply of 32-bit operands to produce the correct full
/// 64-bit result.
struct DxilInst_IMul {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IMul(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IMul);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction multiply of 32-bit operands to produce the correct full
/// 64-bit result.
struct DxilInst_UMul {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UMul(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UMul);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction unsigned divide of the 32-bit operand src0 by the 32-bit
/// operand src1.
struct DxilInst_UDiv {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UDiv(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UDiv);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction unsigned add of 32-bit operand with the carry
struct DxilInst_UAddc {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UAddc(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UAddc);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction unsigned subtract of 32-bit operands with the borrow
struct DxilInst_USubb {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_USubb(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::USubb);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction floating point multiply & add
struct DxilInst_FMad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FMad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::FMad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction fused multiply-add
struct DxilInst_Fma {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Fma(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Fma);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Signed integer multiply & add
struct DxilInst_IMad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IMad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IMad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Unsigned integer multiply & add
struct DxilInst_UMad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_UMad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::UMad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction masked Sum of Absolute Differences.
struct DxilInst_Msad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Msad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Msad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Integer bitfield extract
struct DxilInst_Ibfe {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Ibfe(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Ibfe);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Unsigned integer bitfield extract
struct DxilInst_Ubfe {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Ubfe(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Ubfe);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_a = 1,
arg_b = 2,
arg_c = 3,
};
// Accessors
llvm::Value *get_a() const { return Instr->getOperand(1); }
void set_a(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_c() const { return Instr->getOperand(3); }
void set_c(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Given a bit range from the LSB of a number, places that
/// number of bits in another number at any offset
struct DxilInst_Bfi {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Bfi(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Bfi);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_width = 1,
arg_offset = 2,
arg_value = 3,
arg_replacedValue = 4,
};
// Accessors
llvm::Value *get_width() const { return Instr->getOperand(1); }
void set_width(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_offset() const { return Instr->getOperand(2); }
void set_offset(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_value() const { return Instr->getOperand(3); }
void set_value(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_replacedValue() const { return Instr->getOperand(4); }
void set_replacedValue(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction Two-dimensional vector dot-product
struct DxilInst_Dot2 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot2(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Dot2);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_ax = 1,
arg_ay = 2,
arg_bx = 3,
arg_by = 4,
};
// Accessors
llvm::Value *get_ax() const { return Instr->getOperand(1); }
void set_ax(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_ay() const { return Instr->getOperand(2); }
void set_ay(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_bx() const { return Instr->getOperand(3); }
void set_bx(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_by() const { return Instr->getOperand(4); }
void set_by(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction Three-dimensional vector dot-product
struct DxilInst_Dot3 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot3(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Dot3);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (7 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_ax = 1,
arg_ay = 2,
arg_az = 3,
arg_bx = 4,
arg_by = 5,
arg_bz = 6,
};
// Accessors
llvm::Value *get_ax() const { return Instr->getOperand(1); }
void set_ax(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_ay() const { return Instr->getOperand(2); }
void set_ay(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_az() const { return Instr->getOperand(3); }
void set_az(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_bx() const { return Instr->getOperand(4); }
void set_bx(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_by() const { return Instr->getOperand(5); }
void set_by(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_bz() const { return Instr->getOperand(6); }
void set_bz(llvm::Value *val) { Instr->setOperand(6, val); }
};
/// This instruction Four-dimensional vector dot-product
struct DxilInst_Dot4 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot4(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Dot4);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_ax = 1,
arg_ay = 2,
arg_az = 3,
arg_aw = 4,
arg_bx = 5,
arg_by = 6,
arg_bz = 7,
arg_bw = 8,
};
// Accessors
llvm::Value *get_ax() const { return Instr->getOperand(1); }
void set_ax(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_ay() const { return Instr->getOperand(2); }
void set_ay(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_az() const { return Instr->getOperand(3); }
void set_az(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_aw() const { return Instr->getOperand(4); }
void set_aw(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_bx() const { return Instr->getOperand(5); }
void set_bx(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_by() const { return Instr->getOperand(6); }
void set_by(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_bz() const { return Instr->getOperand(7); }
void set_bz(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_bw() const { return Instr->getOperand(8); }
void set_bw(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction creates the handle to a resource
struct DxilInst_CreateHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::CreateHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_resourceClass = 1,
arg_rangeId = 2,
arg_index = 3,
arg_nonUniformIndex = 4,
};
// Accessors
llvm::Value *get_resourceClass() const { return Instr->getOperand(1); }
void set_resourceClass(llvm::Value *val) { Instr->setOperand(1, val); }
int8_t get_resourceClass_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_resourceClass_val(int8_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_rangeId() const { return Instr->getOperand(2); }
void set_rangeId(llvm::Value *val) { Instr->setOperand(2, val); }
int32_t get_rangeId_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_rangeId_val(int32_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
llvm::Value *get_index() const { return Instr->getOperand(3); }
void set_index(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_nonUniformIndex() const { return Instr->getOperand(4); }
void set_nonUniformIndex(llvm::Value *val) { Instr->setOperand(4, val); }
bool get_nonUniformIndex_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(4))
->getZExtValue());
}
void set_nonUniformIndex_val(bool val) {
Instr->setOperand(4, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
};
/// This instruction loads a value from a constant buffer resource
struct DxilInst_CBufferLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CBufferLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::CBufferLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_byteOffset = 2,
arg_alignment = 3,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_byteOffset() const { return Instr->getOperand(2); }
void set_byteOffset(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_alignment() const { return Instr->getOperand(3); }
void set_alignment(llvm::Value *val) { Instr->setOperand(3, val); }
uint32_t get_alignment_val() const {
return (uint32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_alignment_val(uint32_t val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction loads a value from a constant buffer resource
struct DxilInst_CBufferLoadLegacy {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CBufferLoadLegacy(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::CBufferLoadLegacy);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_regIndex = 2,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_regIndex() const { return Instr->getOperand(2); }
void set_regIndex(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction samples a texture
struct DxilInst_Sample {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Sample(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Sample);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (11 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_clamp = 10,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(10); }
void set_clamp(llvm::Value *val) { Instr->setOperand(10, val); }
};
/// This instruction samples a texture after applying the input bias to the
/// mipmap level
struct DxilInst_SampleBias {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleBias(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SampleBias);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (12 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_bias = 10,
arg_clamp = 11,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_bias() const { return Instr->getOperand(10); }
void set_bias(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(11); }
void set_clamp(llvm::Value *val) { Instr->setOperand(11, val); }
};
/// This instruction samples a texture using a mipmap-level offset
struct DxilInst_SampleLevel {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleLevel(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SampleLevel);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (11 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_LOD = 10,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_LOD() const { return Instr->getOperand(10); }
void set_LOD(llvm::Value *val) { Instr->setOperand(10, val); }
};
/// This instruction samples a texture using a gradient to influence the way the
/// sample location is calculated
struct DxilInst_SampleGrad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleGrad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SampleGrad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (17 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_ddx0 = 10,
arg_ddx1 = 11,
arg_ddx2 = 12,
arg_ddy0 = 13,
arg_ddy1 = 14,
arg_ddy2 = 15,
arg_clamp = 16,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_ddx0() const { return Instr->getOperand(10); }
void set_ddx0(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_ddx1() const { return Instr->getOperand(11); }
void set_ddx1(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_ddx2() const { return Instr->getOperand(12); }
void set_ddx2(llvm::Value *val) { Instr->setOperand(12, val); }
llvm::Value *get_ddy0() const { return Instr->getOperand(13); }
void set_ddy0(llvm::Value *val) { Instr->setOperand(13, val); }
llvm::Value *get_ddy1() const { return Instr->getOperand(14); }
void set_ddy1(llvm::Value *val) { Instr->setOperand(14, val); }
llvm::Value *get_ddy2() const { return Instr->getOperand(15); }
void set_ddy2(llvm::Value *val) { Instr->setOperand(15, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(16); }
void set_clamp(llvm::Value *val) { Instr->setOperand(16, val); }
};
/// This instruction samples a texture and compares a single component against
/// the specified comparison value
struct DxilInst_SampleCmp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleCmp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SampleCmp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (12 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_compareValue = 10,
arg_clamp = 11,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(11); }
void set_clamp(llvm::Value *val) { Instr->setOperand(11, val); }
};
/// This instruction samples a texture and compares a single component against
/// the specified comparison value
struct DxilInst_SampleCmpLevelZero {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleCmpLevelZero(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::SampleCmpLevelZero);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (11 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_compareValue = 10,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
};
/// This instruction reads texel data without any filtering or sampling
struct DxilInst_TextureLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::TextureLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_mipLevelOrSampleCount = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_offset0 = 6,
arg_offset1 = 7,
arg_offset2 = 8,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_mipLevelOrSampleCount() const {
return Instr->getOperand(2);
}
void set_mipLevelOrSampleCount(llvm::Value *val) {
Instr->setOperand(2, val);
}
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(6); }
void set_offset0(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(7); }
void set_offset1(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(8); }
void set_offset2(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction reads texel data without any filtering or sampling
struct DxilInst_TextureStore {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TextureStore);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (10 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_coord0 = 2,
arg_coord1 = 3,
arg_coord2 = 4,
arg_value0 = 5,
arg_value1 = 6,
arg_value2 = 7,
arg_value3 = 8,
arg_mask = 9,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(2); }
void set_coord0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(3); }
void set_coord1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(4); }
void set_coord2(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_value0() const { return Instr->getOperand(5); }
void set_value0(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_value1() const { return Instr->getOperand(6); }
void set_value1(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_value2() const { return Instr->getOperand(7); }
void set_value2(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_value3() const { return Instr->getOperand(8); }
void set_value3(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_mask() const { return Instr->getOperand(9); }
void set_mask(llvm::Value *val) { Instr->setOperand(9, val); }
};
/// This instruction reads from a TypedBuffer
struct DxilInst_BufferLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BufferLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::BufferLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_index = 2,
arg_wot = 3,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_wot() const { return Instr->getOperand(3); }
void set_wot(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction writes to a RWTypedBuffer
struct DxilInst_BufferStore {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BufferStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::BufferStore);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_uav = 1,
arg_coord0 = 2,
arg_coord1 = 3,
arg_value0 = 4,
arg_value1 = 5,
arg_value2 = 6,
arg_value3 = 7,
arg_mask = 8,
};
// Accessors
llvm::Value *get_uav() const { return Instr->getOperand(1); }
void set_uav(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(2); }
void set_coord0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(3); }
void set_coord1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value0() const { return Instr->getOperand(4); }
void set_value0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_value1() const { return Instr->getOperand(5); }
void set_value1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_value2() const { return Instr->getOperand(6); }
void set_value2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_value3() const { return Instr->getOperand(7); }
void set_value3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_mask() const { return Instr->getOperand(8); }
void set_mask(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction atomically increments/decrements the hidden 32-bit counter
/// stored with a Count or Append UAV
struct DxilInst_BufferUpdateCounter {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BufferUpdateCounter(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::BufferUpdateCounter);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_uav = 1,
arg_inc = 2,
};
// Accessors
llvm::Value *get_uav() const { return Instr->getOperand(1); }
void set_uav(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_inc() const { return Instr->getOperand(2); }
void set_inc(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction determines whether all values from a Sample, Gather, or
/// Load operation accessed mapped tiles in a tiled resource
struct DxilInst_CheckAccessFullyMapped {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CheckAccessFullyMapped(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::CheckAccessFullyMapped);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_status = 1,
};
// Accessors
llvm::Value *get_status() const { return Instr->getOperand(1); }
void set_status(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction gets texture size information
struct DxilInst_GetDimensions {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GetDimensions(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::GetDimensions);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_mipLevel = 2,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_mipLevel() const { return Instr->getOperand(2); }
void set_mipLevel(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction gathers the four texels that would be used in a bi-linear
/// filtering operation
struct DxilInst_TextureGather {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureGather(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TextureGather);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (10 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_channel = 9,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_channel() const { return Instr->getOperand(9); }
void set_channel(llvm::Value *val) { Instr->setOperand(9, val); }
};
/// This instruction same as TextureGather, except this instrution performs
/// comparison on texels, similar to SampleCmp
struct DxilInst_TextureGatherCmp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureGatherCmp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TextureGatherCmp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (11 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_channel = 9,
arg_compareValue = 10,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_channel() const { return Instr->getOperand(9); }
void set_channel(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
};
/// This instruction gets the position of the specified sample
struct DxilInst_Texture2DMSGetSamplePosition {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Texture2DMSGetSamplePosition(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::Texture2DMSGetSamplePosition);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_index = 2,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction gets the position of the specified sample
struct DxilInst_RenderTargetGetSamplePosition {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RenderTargetGetSamplePosition(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RenderTargetGetSamplePosition);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_index = 1,
};
// Accessors
llvm::Value *get_index() const { return Instr->getOperand(1); }
void set_index(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction gets the number of samples for a render target
struct DxilInst_RenderTargetGetSampleCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RenderTargetGetSampleCount(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RenderTargetGetSampleCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction performs an atomic operation on two operands
struct DxilInst_AtomicBinOp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AtomicBinOp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::AtomicBinOp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (7 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_atomicOp = 2,
arg_offset0 = 3,
arg_offset1 = 4,
arg_offset2 = 5,
arg_newValue = 6,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_atomicOp() const { return Instr->getOperand(2); }
void set_atomicOp(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(3); }
void set_offset0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(4); }
void set_offset1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(5); }
void set_offset2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_newValue() const { return Instr->getOperand(6); }
void set_newValue(llvm::Value *val) { Instr->setOperand(6, val); }
};
/// This instruction atomic compare and exchange to memory
struct DxilInst_AtomicCompareExchange {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AtomicCompareExchange(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::AtomicCompareExchange);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (7 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_offset0 = 2,
arg_offset1 = 3,
arg_offset2 = 4,
arg_compareValue = 5,
arg_newValue = 6,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(2); }
void set_offset0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(3); }
void set_offset1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(4); }
void set_offset2(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(5); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_newValue() const { return Instr->getOperand(6); }
void set_newValue(llvm::Value *val) { Instr->setOperand(6, val); }
};
/// This instruction inserts a memory barrier in the shader
struct DxilInst_Barrier {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Barrier(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Barrier);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_barrierMode = 1,
};
// Accessors
llvm::Value *get_barrierMode() const { return Instr->getOperand(1); }
void set_barrierMode(llvm::Value *val) { Instr->setOperand(1, val); }
int32_t get_barrierMode_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_barrierMode_val(int32_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction calculates the level of detail
struct DxilInst_CalculateLOD {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CalculateLOD(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::CalculateLOD);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (7 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_handle = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_clamped = 6,
};
// Accessors
llvm::Value *get_handle() const { return Instr->getOperand(1); }
void set_handle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_clamped() const { return Instr->getOperand(6); }
void set_clamped(llvm::Value *val) { Instr->setOperand(6, val); }
};
/// This instruction discard the current pixel
struct DxilInst_Discard {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Discard(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Discard);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_condition = 1,
};
// Accessors
llvm::Value *get_condition() const { return Instr->getOperand(1); }
void set_condition(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction computes the rate of change per stamp in x direction.
struct DxilInst_DerivCoarseX {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DerivCoarseX(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::DerivCoarseX);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction computes the rate of change per stamp in y direction.
struct DxilInst_DerivCoarseY {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DerivCoarseY(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::DerivCoarseY);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction computes the rate of change per pixel in x direction.
struct DxilInst_DerivFineX {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DerivFineX(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::DerivFineX);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction computes the rate of change per pixel in y direction.
struct DxilInst_DerivFineY {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DerivFineY(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::DerivFineY);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction evaluates an input attribute at pixel center with an offset
struct DxilInst_EvalSnapped {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EvalSnapped(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::EvalSnapped);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_inputRowIndex = 2,
arg_inputColIndex = 3,
arg_offsetX = 4,
arg_offsetY = 5,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_inputRowIndex() const { return Instr->getOperand(2); }
void set_inputRowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_inputColIndex() const { return Instr->getOperand(3); }
void set_inputColIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_offsetX() const { return Instr->getOperand(4); }
void set_offsetX(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_offsetY() const { return Instr->getOperand(5); }
void set_offsetY(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction evaluates an input attribute at a sample location
struct DxilInst_EvalSampleIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EvalSampleIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::EvalSampleIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_inputRowIndex = 2,
arg_inputColIndex = 3,
arg_sampleIndex = 4,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_inputRowIndex() const { return Instr->getOperand(2); }
void set_inputRowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_inputColIndex() const { return Instr->getOperand(3); }
void set_inputColIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_sampleIndex() const { return Instr->getOperand(4); }
void set_sampleIndex(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction evaluates an input attribute at pixel center
struct DxilInst_EvalCentroid {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EvalCentroid(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::EvalCentroid);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_inputRowIndex = 2,
arg_inputColIndex = 3,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_inputRowIndex() const { return Instr->getOperand(2); }
void set_inputRowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_inputColIndex() const { return Instr->getOperand(3); }
void set_inputColIndex(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns the sample index in a sample-frequency pixel shader
struct DxilInst_SampleIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SampleIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns the coverage mask input in a pixel shader
struct DxilInst_Coverage {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Coverage(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Coverage);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns underestimated coverage input from conservative
/// rasterization in a pixel shader
struct DxilInst_InnerCoverage {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_InnerCoverage(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::InnerCoverage);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction reads the thread ID
struct DxilInst_ThreadId {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ThreadId(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::ThreadId);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_component = 1,
};
// Accessors
llvm::Value *get_component() const { return Instr->getOperand(1); }
void set_component(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction reads the group ID (SV_GroupID)
struct DxilInst_GroupId {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GroupId(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::GroupId);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_component = 1,
};
// Accessors
llvm::Value *get_component() const { return Instr->getOperand(1); }
void set_component(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction reads the thread ID within the group (SV_GroupThreadID)
struct DxilInst_ThreadIdInGroup {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ThreadIdInGroup(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::ThreadIdInGroup);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_component = 1,
};
// Accessors
llvm::Value *get_component() const { return Instr->getOperand(1); }
void set_component(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction provides a flattened index for a given thread within a
/// given group (SV_GroupIndex)
struct DxilInst_FlattenedThreadIdInGroup {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FlattenedThreadIdInGroup(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::FlattenedThreadIdInGroup);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction emits a vertex to a given stream
struct DxilInst_EmitStream {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EmitStream(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::EmitStream);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_streamId = 1,
};
// Accessors
llvm::Value *get_streamId() const { return Instr->getOperand(1); }
void set_streamId(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction completes the current primitive topology at the specified
/// stream
struct DxilInst_CutStream {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CutStream(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::CutStream);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_streamId = 1,
};
// Accessors
llvm::Value *get_streamId() const { return Instr->getOperand(1); }
void set_streamId(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction equivalent to an EmitStream followed by a CutStream
struct DxilInst_EmitThenCutStream {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EmitThenCutStream(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::EmitThenCutStream);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_streamId = 1,
};
// Accessors
llvm::Value *get_streamId() const { return Instr->getOperand(1); }
void set_streamId(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction GSInstanceID
struct DxilInst_GSInstanceID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GSInstanceID(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::GSInstanceID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction creates a double value
struct DxilInst_MakeDouble {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_MakeDouble(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::MakeDouble);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_lo = 1,
arg_hi = 2,
};
// Accessors
llvm::Value *get_lo() const { return Instr->getOperand(1); }
void set_lo(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_hi() const { return Instr->getOperand(2); }
void set_hi(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction splits a double into low and high parts
struct DxilInst_SplitDouble {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SplitDouble(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::SplitDouble);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction LoadOutputControlPoint
struct DxilInst_LoadOutputControlPoint {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LoadOutputControlPoint(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::LoadOutputControlPoint);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_row = 2,
arg_col = 3,
arg_index = 4,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_index() const { return Instr->getOperand(4); }
void set_index(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction LoadPatchConstant
struct DxilInst_LoadPatchConstant {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LoadPatchConstant(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::LoadPatchConstant);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_row = 2,
arg_col = 3,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction DomainLocation
struct DxilInst_DomainLocation {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DomainLocation(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::DomainLocation);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_component = 1,
};
// Accessors
llvm::Value *get_component() const { return Instr->getOperand(1); }
void set_component(llvm::Value *val) { Instr->setOperand(1, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction StorePatchConstant
struct DxilInst_StorePatchConstant {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StorePatchConstant(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::StorePatchConstant);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_outputSigID = 1,
arg_row = 2,
arg_col = 3,
arg_value = 4,
};
// Accessors
llvm::Value *get_outputSigID() const { return Instr->getOperand(1); }
void set_outputSigID(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value() const { return Instr->getOperand(4); }
void set_value(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction OutputControlPointID
struct DxilInst_OutputControlPointID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_OutputControlPointID(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::OutputControlPointID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction PrimitiveID
struct DxilInst_PrimitiveID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_PrimitiveID(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::PrimitiveID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction CycleCounterLegacy
struct DxilInst_CycleCounterLegacy {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CycleCounterLegacy(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::CycleCounterLegacy);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns 1 for the first lane in the wave
struct DxilInst_WaveIsFirstLane {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveIsFirstLane(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveIsFirstLane);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns the index of the current lane in the wave
struct DxilInst_WaveGetLaneIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveGetLaneIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveGetLaneIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns the number of lanes in the wave
struct DxilInst_WaveGetLaneCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveGetLaneCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveGetLaneCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns 1 if any of the lane evaluates the value to true
struct DxilInst_WaveAnyTrue {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveAnyTrue(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::WaveAnyTrue);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_cond = 1,
};
// Accessors
llvm::Value *get_cond() const { return Instr->getOperand(1); }
void set_cond(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns 1 if all the lanes evaluate the value to true
struct DxilInst_WaveAllTrue {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveAllTrue(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::WaveAllTrue);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_cond = 1,
};
// Accessors
llvm::Value *get_cond() const { return Instr->getOperand(1); }
void set_cond(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns 1 if all the lanes have the same value
struct DxilInst_WaveActiveAllEqual {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveActiveAllEqual(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveActiveAllEqual);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns a struct with a bit set for each lane where the
/// condition is true
struct DxilInst_WaveActiveBallot {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveActiveBallot(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveActiveBallot);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_cond = 1,
};
// Accessors
llvm::Value *get_cond() const { return Instr->getOperand(1); }
void set_cond(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the value from the specified lane
struct DxilInst_WaveReadLaneAt {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveReadLaneAt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveReadLaneAt);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_lane = 2,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_lane() const { return Instr->getOperand(2); }
void set_lane(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction returns the value from the first lane
struct DxilInst_WaveReadLaneFirst {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveReadLaneFirst(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveReadLaneFirst);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the result the operation across waves
struct DxilInst_WaveActiveOp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveActiveOp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveActiveOp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_op = 2,
arg_sop = 3,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_op() const { return Instr->getOperand(2); }
void set_op(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_sop() const { return Instr->getOperand(3); }
void set_sop(llvm::Value *val) { Instr->setOperand(3, val); }
int8_t get_sop_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_sop_val(int8_t val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns the result of the operation across all lanes
struct DxilInst_WaveActiveBit {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveActiveBit(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveActiveBit);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_op = 2,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_op() const { return Instr->getOperand(2); }
void set_op(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns the result of the operation on prior lanes
struct DxilInst_WavePrefixOp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WavePrefixOp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WavePrefixOp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_op = 2,
arg_sop = 3,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_op() const { return Instr->getOperand(2); }
void set_op(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_sop() const { return Instr->getOperand(3); }
void set_sop(llvm::Value *val) { Instr->setOperand(3, val); }
int8_t get_sop_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_sop_val(int8_t val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction reads from a lane in the quad
struct DxilInst_QuadReadLaneAt {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_QuadReadLaneAt(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::QuadReadLaneAt);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_quadLane = 2,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_quadLane() const { return Instr->getOperand(2); }
void set_quadLane(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction returns the result of a quad-level operation
struct DxilInst_QuadOp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_QuadOp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::QuadOp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_op = 2,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_op() const { return Instr->getOperand(2); }
void set_op(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastI16toF16 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastI16toF16(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastI16toF16);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastF16toI16 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastF16toI16(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastF16toI16);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastI32toF32 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastI32toF32(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastI32toF32);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastF32toI32 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastF32toI32(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastF32toI32);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastI64toF64 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastI64toF64(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastI64toF64);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction bitcast between different sizes
struct DxilInst_BitcastF64toI64 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BitcastF64toI64(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::BitcastF64toI64);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction legacy fuction to convert float (f32) to half (f16) (this
/// is not related to min-precision)
struct DxilInst_LegacyF32ToF16 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LegacyF32ToF16(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::LegacyF32ToF16);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction legacy fuction to convert half (f16) to float (f32) (this
/// is not related to min-precision)
struct DxilInst_LegacyF16ToF32 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LegacyF16ToF32(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::LegacyF16ToF32);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction legacy fuction to convert double to float
struct DxilInst_LegacyDoubleToFloat {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LegacyDoubleToFloat(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::LegacyDoubleToFloat);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction legacy fuction to convert double to int32
struct DxilInst_LegacyDoubleToSInt32 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LegacyDoubleToSInt32(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::LegacyDoubleToSInt32);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction legacy fuction to convert double to uint32
struct DxilInst_LegacyDoubleToUInt32 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_LegacyDoubleToUInt32(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::LegacyDoubleToUInt32);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the count of bits set to 1 across the wave
struct DxilInst_WaveAllBitCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveAllBitCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveAllBitCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the count of bits set to 1 on prior lanes
struct DxilInst_WavePrefixBitCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WavePrefixBitCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WavePrefixBitCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the values of the attributes at the vertex.
struct DxilInst_AttributeAtVertex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AttributeAtVertex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::AttributeAtVertex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_inputSigId = 1,
arg_inputRowIndex = 2,
arg_inputColIndex = 3,
arg_VertexID = 4,
};
// Accessors
llvm::Value *get_inputSigId() const { return Instr->getOperand(1); }
void set_inputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_inputRowIndex() const { return Instr->getOperand(2); }
void set_inputRowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_inputColIndex() const { return Instr->getOperand(3); }
void set_inputColIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_VertexID() const { return Instr->getOperand(4); }
void set_VertexID(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction returns the view index
struct DxilInst_ViewID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ViewID(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::ViewID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction reads from a raw buffer and structured buffer
struct DxilInst_RawBufferLoad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RawBufferLoad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RawBufferLoad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_index = 2,
arg_elementOffset = 3,
arg_mask = 4,
arg_alignment = 5,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_mask() const { return Instr->getOperand(4); }
void set_mask(llvm::Value *val) { Instr->setOperand(4, val); }
int8_t get_mask_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(4))
->getZExtValue());
}
void set_mask_val(int8_t val) {
Instr->setOperand(4, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_alignment() const { return Instr->getOperand(5); }
void set_alignment(llvm::Value *val) { Instr->setOperand(5, val); }
int32_t get_alignment_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(5))
->getZExtValue());
}
void set_alignment_val(int32_t val) {
Instr->setOperand(5, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction writes to a RWByteAddressBuffer or RWStructuredBuffer
struct DxilInst_RawBufferStore {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RawBufferStore(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RawBufferStore);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (10 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_uav = 1,
arg_index = 2,
arg_elementOffset = 3,
arg_value0 = 4,
arg_value1 = 5,
arg_value2 = 6,
arg_value3 = 7,
arg_mask = 8,
arg_alignment = 9,
};
// Accessors
llvm::Value *get_uav() const { return Instr->getOperand(1); }
void set_uav(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_elementOffset() const { return Instr->getOperand(3); }
void set_elementOffset(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value0() const { return Instr->getOperand(4); }
void set_value0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_value1() const { return Instr->getOperand(5); }
void set_value1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_value2() const { return Instr->getOperand(6); }
void set_value2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_value3() const { return Instr->getOperand(7); }
void set_value3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_mask() const { return Instr->getOperand(8); }
void set_mask(llvm::Value *val) { Instr->setOperand(8, val); }
int8_t get_mask_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(8))
->getZExtValue());
}
void set_mask_val(int8_t val) {
Instr->setOperand(8, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_alignment() const { return Instr->getOperand(9); }
void set_alignment(llvm::Value *val) { Instr->setOperand(9, val); }
int32_t get_alignment_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(9))
->getZExtValue());
}
void set_alignment_val(int32_t val) {
Instr->setOperand(9, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction The user-provided InstanceID on the bottom-level
/// acceleration structure instance within the top-level structure
struct DxilInst_InstanceID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_InstanceID(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::InstanceID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction The autogenerated index of the current instance in the
/// top-level structure
struct DxilInst_InstanceIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_InstanceIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::InstanceIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction Returns the value passed as HitKind in
/// ReportIntersection(). If intersection was reported by fixed-function
/// triangle intersection, HitKind will be one of HIT_KIND_TRIANGLE_FRONT_FACE
/// or HIT_KIND_TRIANGLE_BACK_FACE.
struct DxilInst_HitKind {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_HitKind(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::HitKind);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction uint containing the current ray flags.
struct DxilInst_RayFlags {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayFlags(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::RayFlags);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction The current x and y location within the Width and Height
struct DxilInst_DispatchRaysIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DispatchRaysIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::DispatchRaysIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction The Width and Height values from the
/// D3D12_DISPATCH_RAYS_DESC structure provided to the originating
/// DispatchRays() call.
struct DxilInst_DispatchRaysDimensions {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DispatchRaysDimensions(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::DispatchRaysDimensions);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction The world-space origin for the current ray.
struct DxilInst_WorldRayOrigin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WorldRayOrigin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WorldRayOrigin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction The world-space direction for the current ray.
struct DxilInst_WorldRayDirection {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WorldRayDirection(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WorldRayDirection);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Object-space origin for the current ray.
struct DxilInst_ObjectRayOrigin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ObjectRayOrigin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::ObjectRayOrigin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Object-space direction for the current ray.
struct DxilInst_ObjectRayDirection {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ObjectRayDirection(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::ObjectRayDirection);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_col = 1,
};
// Accessors
llvm::Value *get_col() const { return Instr->getOperand(1); }
void set_col(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Matrix for transforming from object-space to world-space.
struct DxilInst_ObjectToWorld {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ObjectToWorld(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::ObjectToWorld);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_row = 1,
arg_col = 2,
};
// Accessors
llvm::Value *get_row() const { return Instr->getOperand(1); }
void set_row(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_col() const { return Instr->getOperand(2); }
void set_col(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction Matrix for transforming from world-space to object-space.
struct DxilInst_WorldToObject {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WorldToObject(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WorldToObject);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_row = 1,
arg_col = 2,
};
// Accessors
llvm::Value *get_row() const { return Instr->getOperand(1); }
void set_row(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_col() const { return Instr->getOperand(2); }
void set_col(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction float representing the parametric starting point for the
/// ray.
struct DxilInst_RayTMin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayTMin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::RayTMin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction float representing the current parametric ending point for
/// the ray
struct DxilInst_RayTCurrent {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayTCurrent(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::RayTCurrent);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction Used in an any hit shader to reject an intersection and
/// terminate the shader
struct DxilInst_IgnoreHit {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IgnoreHit(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::IgnoreHit);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction Used in an any hit shader to abort the ray query and the
/// intersection shader (if any). The current hit is committed and execution
/// passes to the closest hit shader with the closest hit recorded so far
struct DxilInst_AcceptHitAndEndSearch {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AcceptHitAndEndSearch(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::AcceptHitAndEndSearch);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction initiates raytrace
struct DxilInst_TraceRay {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TraceRay(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::TraceRay);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (16 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_AccelerationStructure = 1,
arg_RayFlags = 2,
arg_InstanceInclusionMask = 3,
arg_RayContributionToHitGroupIndex = 4,
arg_MultiplierForGeometryContributionToShaderIndex = 5,
arg_MissShaderIndex = 6,
arg_Origin_X = 7,
arg_Origin_Y = 8,
arg_Origin_Z = 9,
arg_TMin = 10,
arg_Direction_X = 11,
arg_Direction_Y = 12,
arg_Direction_Z = 13,
arg_TMax = 14,
arg_payload = 15,
};
// Accessors
llvm::Value *get_AccelerationStructure() const {
return Instr->getOperand(1);
}
void set_AccelerationStructure(llvm::Value *val) {
Instr->setOperand(1, val);
}
llvm::Value *get_RayFlags() const { return Instr->getOperand(2); }
void set_RayFlags(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_InstanceInclusionMask() const {
return Instr->getOperand(3);
}
void set_InstanceInclusionMask(llvm::Value *val) {
Instr->setOperand(3, val);
}
llvm::Value *get_RayContributionToHitGroupIndex() const {
return Instr->getOperand(4);
}
void set_RayContributionToHitGroupIndex(llvm::Value *val) {
Instr->setOperand(4, val);
}
llvm::Value *get_MultiplierForGeometryContributionToShaderIndex() const {
return Instr->getOperand(5);
}
void set_MultiplierForGeometryContributionToShaderIndex(llvm::Value *val) {
Instr->setOperand(5, val);
}
llvm::Value *get_MissShaderIndex() const { return Instr->getOperand(6); }
void set_MissShaderIndex(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_Origin_X() const { return Instr->getOperand(7); }
void set_Origin_X(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_Origin_Y() const { return Instr->getOperand(8); }
void set_Origin_Y(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_Origin_Z() const { return Instr->getOperand(9); }
void set_Origin_Z(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_TMin() const { return Instr->getOperand(10); }
void set_TMin(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_Direction_X() const { return Instr->getOperand(11); }
void set_Direction_X(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_Direction_Y() const { return Instr->getOperand(12); }
void set_Direction_Y(llvm::Value *val) { Instr->setOperand(12, val); }
llvm::Value *get_Direction_Z() const { return Instr->getOperand(13); }
void set_Direction_Z(llvm::Value *val) { Instr->setOperand(13, val); }
llvm::Value *get_TMax() const { return Instr->getOperand(14); }
void set_TMax(llvm::Value *val) { Instr->setOperand(14, val); }
llvm::Value *get_payload() const { return Instr->getOperand(15); }
void set_payload(llvm::Value *val) { Instr->setOperand(15, val); }
};
/// This instruction returns true if hit was accepted
struct DxilInst_ReportHit {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ReportHit(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::ReportHit);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_THit = 1,
arg_HitKind = 2,
arg_Attributes = 3,
};
// Accessors
llvm::Value *get_THit() const { return Instr->getOperand(1); }
void set_THit(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_HitKind() const { return Instr->getOperand(2); }
void set_HitKind(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_Attributes() const { return Instr->getOperand(3); }
void set_Attributes(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction Call a shader in the callable shader table supplied through
/// the DispatchRays() API
struct DxilInst_CallShader {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CallShader(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::CallShader);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_ShaderIndex = 1,
arg_Parameter = 2,
};
// Accessors
llvm::Value *get_ShaderIndex() const { return Instr->getOperand(1); }
void set_ShaderIndex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_Parameter() const { return Instr->getOperand(2); }
void set_Parameter(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction create resource handle from resource struct for library
struct DxilInst_CreateHandleForLib {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateHandleForLib(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::CreateHandleForLib);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_Resource = 1,
};
// Accessors
llvm::Value *get_Resource() const { return Instr->getOperand(1); }
void set_Resource(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction PrimitiveIndex for raytracing shaders
struct DxilInst_PrimitiveIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_PrimitiveIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::PrimitiveIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction 2D half dot product with accumulate to float
struct DxilInst_Dot2AddHalf {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot2AddHalf(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Dot2AddHalf);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_acc = 1,
arg_ax = 2,
arg_ay = 3,
arg_bx = 4,
arg_by = 5,
};
// Accessors
llvm::Value *get_acc() const { return Instr->getOperand(1); }
void set_acc(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_ax() const { return Instr->getOperand(2); }
void set_ax(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_ay() const { return Instr->getOperand(3); }
void set_ay(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_bx() const { return Instr->getOperand(4); }
void set_bx(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_by() const { return Instr->getOperand(5); }
void set_by(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction signed dot product of 4 x i8 vectors packed into i32, with
/// accumulate to i32
struct DxilInst_Dot4AddI8Packed {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot4AddI8Packed(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::Dot4AddI8Packed);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_acc = 1,
arg_a = 2,
arg_b = 3,
};
// Accessors
llvm::Value *get_acc() const { return Instr->getOperand(1); }
void set_acc(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_a() const { return Instr->getOperand(2); }
void set_a(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_b() const { return Instr->getOperand(3); }
void set_b(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction unsigned dot product of 4 x u8 vectors packed into i32,
/// with accumulate to i32
struct DxilInst_Dot4AddU8Packed {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Dot4AddU8Packed(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::Dot4AddU8Packed);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_acc = 1,
arg_a = 2,
arg_b = 3,
};
// Accessors
llvm::Value *get_acc() const { return Instr->getOperand(1); }
void set_acc(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_a() const { return Instr->getOperand(2); }
void set_a(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_b() const { return Instr->getOperand(3); }
void set_b(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns the bitmask of active lanes that have the same
/// value
struct DxilInst_WaveMatch {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveMatch(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::WaveMatch);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the result of the operation on groups of lanes
/// identified by a bitmask
struct DxilInst_WaveMultiPrefixOp {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveMultiPrefixOp(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::WaveMultiPrefixOp);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (8 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_mask0 = 2,
arg_mask1 = 3,
arg_mask2 = 4,
arg_mask3 = 5,
arg_op = 6,
arg_sop = 7,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_mask0() const { return Instr->getOperand(2); }
void set_mask0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_mask1() const { return Instr->getOperand(3); }
void set_mask1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_mask2() const { return Instr->getOperand(4); }
void set_mask2(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_mask3() const { return Instr->getOperand(5); }
void set_mask3(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_op() const { return Instr->getOperand(6); }
void set_op(llvm::Value *val) { Instr->setOperand(6, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(6))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(6, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_sop() const { return Instr->getOperand(7); }
void set_sop(llvm::Value *val) { Instr->setOperand(7, val); }
int8_t get_sop_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(7))
->getZExtValue());
}
void set_sop_val(int8_t val) {
Instr->setOperand(7, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns the count of bits set to 1 on groups of lanes
/// identified by a bitmask
struct DxilInst_WaveMultiPrefixBitCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WaveMultiPrefixBitCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::WaveMultiPrefixBitCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_value = 1,
arg_mask0 = 2,
arg_mask1 = 3,
arg_mask2 = 4,
arg_mask3 = 5,
};
// Accessors
llvm::Value *get_value() const { return Instr->getOperand(1); }
void set_value(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_mask0() const { return Instr->getOperand(2); }
void set_mask0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_mask1() const { return Instr->getOperand(3); }
void set_mask1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_mask2() const { return Instr->getOperand(4); }
void set_mask2(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_mask3() const { return Instr->getOperand(5); }
void set_mask3(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction Mesh shader intrinsic SetMeshOutputCounts
struct DxilInst_SetMeshOutputCounts {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SetMeshOutputCounts(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::SetMeshOutputCounts);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_numVertices = 1,
arg_numPrimitives = 2,
};
// Accessors
llvm::Value *get_numVertices() const { return Instr->getOperand(1); }
void set_numVertices(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_numPrimitives() const { return Instr->getOperand(2); }
void set_numPrimitives(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction emit a primitive's vertex indices in a mesh shader
struct DxilInst_EmitIndices {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_EmitIndices(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::EmitIndices);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_PrimitiveIndex = 1,
arg_VertexIndex0 = 2,
arg_VertexIndex1 = 3,
arg_VertexIndex2 = 4,
};
// Accessors
llvm::Value *get_PrimitiveIndex() const { return Instr->getOperand(1); }
void set_PrimitiveIndex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_VertexIndex0() const { return Instr->getOperand(2); }
void set_VertexIndex0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_VertexIndex1() const { return Instr->getOperand(3); }
void set_VertexIndex1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_VertexIndex2() const { return Instr->getOperand(4); }
void set_VertexIndex2(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction get the mesh payload which is from amplification shader
struct DxilInst_GetMeshPayload {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GetMeshPayload(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::GetMeshPayload);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction stores the value to mesh shader vertex output
struct DxilInst_StoreVertexOutput {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StoreVertexOutput(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::StoreVertexOutput);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_outputSigId = 1,
arg_rowIndex = 2,
arg_colIndex = 3,
arg_value = 4,
arg_vertexIndex = 5,
};
// Accessors
llvm::Value *get_outputSigId() const { return Instr->getOperand(1); }
void set_outputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_rowIndex() const { return Instr->getOperand(2); }
void set_rowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_colIndex() const { return Instr->getOperand(3); }
void set_colIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value() const { return Instr->getOperand(4); }
void set_value(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_vertexIndex() const { return Instr->getOperand(5); }
void set_vertexIndex(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction stores the value to mesh shader primitive output
struct DxilInst_StorePrimitiveOutput {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StorePrimitiveOutput(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::StorePrimitiveOutput);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_outputSigId = 1,
arg_rowIndex = 2,
arg_colIndex = 3,
arg_value = 4,
arg_primitiveIndex = 5,
};
// Accessors
llvm::Value *get_outputSigId() const { return Instr->getOperand(1); }
void set_outputSigId(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_rowIndex() const { return Instr->getOperand(2); }
void set_rowIndex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_colIndex() const { return Instr->getOperand(3); }
void set_colIndex(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_value() const { return Instr->getOperand(4); }
void set_value(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_primitiveIndex() const { return Instr->getOperand(5); }
void set_primitiveIndex(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction Amplification shader intrinsic DispatchMesh
struct DxilInst_DispatchMesh {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_DispatchMesh(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::DispatchMesh);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (5 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_threadGroupCountX = 1,
arg_threadGroupCountY = 2,
arg_threadGroupCountZ = 3,
arg_payload = 4,
};
// Accessors
llvm::Value *get_threadGroupCountX() const { return Instr->getOperand(1); }
void set_threadGroupCountX(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_threadGroupCountY() const { return Instr->getOperand(2); }
void set_threadGroupCountY(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_threadGroupCountZ() const { return Instr->getOperand(3); }
void set_threadGroupCountZ(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_payload() const { return Instr->getOperand(4); }
void set_payload(llvm::Value *val) { Instr->setOperand(4, val); }
};
/// This instruction updates a feedback texture for a sampling operation
struct DxilInst_WriteSamplerFeedback {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WriteSamplerFeedback(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::WriteSamplerFeedback);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_feedbackTex = 1,
arg_sampledTex = 2,
arg_sampler = 3,
arg_c0 = 4,
arg_c1 = 5,
arg_c2 = 6,
arg_c3 = 7,
arg_clamp = 8,
};
// Accessors
llvm::Value *get_feedbackTex() const { return Instr->getOperand(1); }
void set_feedbackTex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampledTex() const { return Instr->getOperand(2); }
void set_sampledTex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(3); }
void set_sampler(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_c0() const { return Instr->getOperand(4); }
void set_c0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_c1() const { return Instr->getOperand(5); }
void set_c1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_c2() const { return Instr->getOperand(6); }
void set_c2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_c3() const { return Instr->getOperand(7); }
void set_c3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(8); }
void set_clamp(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction updates a feedback texture for a sampling operation with a
/// bias on the mipmap level
struct DxilInst_WriteSamplerFeedbackBias {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WriteSamplerFeedbackBias(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::WriteSamplerFeedbackBias);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (10 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_feedbackTex = 1,
arg_sampledTex = 2,
arg_sampler = 3,
arg_c0 = 4,
arg_c1 = 5,
arg_c2 = 6,
arg_c3 = 7,
arg_bias = 8,
arg_clamp = 9,
};
// Accessors
llvm::Value *get_feedbackTex() const { return Instr->getOperand(1); }
void set_feedbackTex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampledTex() const { return Instr->getOperand(2); }
void set_sampledTex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(3); }
void set_sampler(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_c0() const { return Instr->getOperand(4); }
void set_c0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_c1() const { return Instr->getOperand(5); }
void set_c1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_c2() const { return Instr->getOperand(6); }
void set_c2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_c3() const { return Instr->getOperand(7); }
void set_c3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_bias() const { return Instr->getOperand(8); }
void set_bias(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(9); }
void set_clamp(llvm::Value *val) { Instr->setOperand(9, val); }
};
/// This instruction updates a feedback texture for a sampling operation with a
/// mipmap-level offset
struct DxilInst_WriteSamplerFeedbackLevel {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WriteSamplerFeedbackLevel(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::WriteSamplerFeedbackLevel);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_feedbackTex = 1,
arg_sampledTex = 2,
arg_sampler = 3,
arg_c0 = 4,
arg_c1 = 5,
arg_c2 = 6,
arg_c3 = 7,
arg_lod = 8,
};
// Accessors
llvm::Value *get_feedbackTex() const { return Instr->getOperand(1); }
void set_feedbackTex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampledTex() const { return Instr->getOperand(2); }
void set_sampledTex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(3); }
void set_sampler(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_c0() const { return Instr->getOperand(4); }
void set_c0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_c1() const { return Instr->getOperand(5); }
void set_c1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_c2() const { return Instr->getOperand(6); }
void set_c2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_c3() const { return Instr->getOperand(7); }
void set_c3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_lod() const { return Instr->getOperand(8); }
void set_lod(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction updates a feedback texture for a sampling operation with
/// explicit gradients
struct DxilInst_WriteSamplerFeedbackGrad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_WriteSamplerFeedbackGrad(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::WriteSamplerFeedbackGrad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (15 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_feedbackTex = 1,
arg_sampledTex = 2,
arg_sampler = 3,
arg_c0 = 4,
arg_c1 = 5,
arg_c2 = 6,
arg_c3 = 7,
arg_ddx0 = 8,
arg_ddx1 = 9,
arg_ddx2 = 10,
arg_ddy0 = 11,
arg_ddy1 = 12,
arg_ddy2 = 13,
arg_clamp = 14,
};
// Accessors
llvm::Value *get_feedbackTex() const { return Instr->getOperand(1); }
void set_feedbackTex(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampledTex() const { return Instr->getOperand(2); }
void set_sampledTex(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(3); }
void set_sampler(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_c0() const { return Instr->getOperand(4); }
void set_c0(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_c1() const { return Instr->getOperand(5); }
void set_c1(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_c2() const { return Instr->getOperand(6); }
void set_c2(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_c3() const { return Instr->getOperand(7); }
void set_c3(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_ddx0() const { return Instr->getOperand(8); }
void set_ddx0(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_ddx1() const { return Instr->getOperand(9); }
void set_ddx1(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_ddx2() const { return Instr->getOperand(10); }
void set_ddx2(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_ddy0() const { return Instr->getOperand(11); }
void set_ddy0(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_ddy1() const { return Instr->getOperand(12); }
void set_ddy1(llvm::Value *val) { Instr->setOperand(12, val); }
llvm::Value *get_ddy2() const { return Instr->getOperand(13); }
void set_ddy2(llvm::Value *val) { Instr->setOperand(13, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(14); }
void set_clamp(llvm::Value *val) { Instr->setOperand(14, val); }
};
/// This instruction allocates space for RayQuery and return handle
struct DxilInst_AllocateRayQuery {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AllocateRayQuery(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::AllocateRayQuery);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_constRayFlags = 1,
};
// Accessors
llvm::Value *get_constRayFlags() const { return Instr->getOperand(1); }
void set_constRayFlags(llvm::Value *val) { Instr->setOperand(1, val); }
uint32_t get_constRayFlags_val() const {
return (uint32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_constRayFlags_val(uint32_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction initializes RayQuery for raytrace
struct DxilInst_RayQuery_TraceRayInline {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_TraceRayInline(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_TraceRayInline);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (13 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_accelerationStructure = 2,
arg_rayFlags = 3,
arg_instanceInclusionMask = 4,
arg_origin_X = 5,
arg_origin_Y = 6,
arg_origin_Z = 7,
arg_tMin = 8,
arg_direction_X = 9,
arg_direction_Y = 10,
arg_direction_Z = 11,
arg_tMax = 12,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_accelerationStructure() const {
return Instr->getOperand(2);
}
void set_accelerationStructure(llvm::Value *val) {
Instr->setOperand(2, val);
}
llvm::Value *get_rayFlags() const { return Instr->getOperand(3); }
void set_rayFlags(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_instanceInclusionMask() const {
return Instr->getOperand(4);
}
void set_instanceInclusionMask(llvm::Value *val) {
Instr->setOperand(4, val);
}
llvm::Value *get_origin_X() const { return Instr->getOperand(5); }
void set_origin_X(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_origin_Y() const { return Instr->getOperand(6); }
void set_origin_Y(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_origin_Z() const { return Instr->getOperand(7); }
void set_origin_Z(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_tMin() const { return Instr->getOperand(8); }
void set_tMin(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_direction_X() const { return Instr->getOperand(9); }
void set_direction_X(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_direction_Y() const { return Instr->getOperand(10); }
void set_direction_Y(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_direction_Z() const { return Instr->getOperand(11); }
void set_direction_Z(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_tMax() const { return Instr->getOperand(12); }
void set_tMax(llvm::Value *val) { Instr->setOperand(12, val); }
};
/// This instruction advances a ray query
struct DxilInst_RayQuery_Proceed {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_Proceed(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RayQuery_Proceed);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction aborts a ray query
struct DxilInst_RayQuery_Abort {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_Abort(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RayQuery_Abort);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction commits a non opaque triangle hit
struct DxilInst_RayQuery_CommitNonOpaqueTriangleHit {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommitNonOpaqueTriangleHit(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommitNonOpaqueTriangleHit);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction commits a procedural primitive hit
struct DxilInst_RayQuery_CommitProceduralPrimitiveHit {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommitProceduralPrimitiveHit(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommitProceduralPrimitiveHit);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_t = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_t() const { return Instr->getOperand(2); }
void set_t(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction returns uint status (COMMITTED_STATUS) of the committed hit
/// in a ray query
struct DxilInst_RayQuery_CommittedStatus {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedStatus(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedStatus);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns uint candidate type (CANDIDATE_TYPE) of the current
/// hit candidate in a ray query, after Proceed() has returned true
struct DxilInst_RayQuery_CandidateType {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateType(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateType);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns matrix for transforming from object-space to
/// world-space for a candidate hit.
struct DxilInst_RayQuery_CandidateObjectToWorld3x4 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateObjectToWorld3x4(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateObjectToWorld3x4);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_row = 2,
arg_col = 3,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns matrix for transforming from world-space to
/// object-space for a candidate hit.
struct DxilInst_RayQuery_CandidateWorldToObject3x4 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateWorldToObject3x4(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateWorldToObject3x4);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_row = 2,
arg_col = 3,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns matrix for transforming from object-space to
/// world-space for a Committed hit.
struct DxilInst_RayQuery_CommittedObjectToWorld3x4 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedObjectToWorld3x4(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedObjectToWorld3x4);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_row = 2,
arg_col = 3,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns matrix for transforming from world-space to
/// object-space for a Committed hit.
struct DxilInst_RayQuery_CommittedWorldToObject3x4 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedWorldToObject3x4(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedWorldToObject3x4);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_row = 2,
arg_col = 3,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_row() const { return Instr->getOperand(2); }
void set_row(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_col() const { return Instr->getOperand(3); }
void set_col(llvm::Value *val) { Instr->setOperand(3, val); }
};
/// This instruction returns if current candidate procedural primitive is non
/// opaque
struct DxilInst_RayQuery_CandidateProceduralPrimitiveNonOpaque {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateProceduralPrimitiveNonOpaque(
llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr,
hlsl::OP::OpCode::RayQuery_CandidateProceduralPrimitiveNonOpaque);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns if current candidate triangle is front facing
struct DxilInst_RayQuery_CandidateTriangleFrontFace {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateTriangleFrontFace(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateTriangleFrontFace);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns if current committed triangle is front facing
struct DxilInst_RayQuery_CommittedTriangleFrontFace {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedTriangleFrontFace(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedTriangleFrontFace);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate triangle hit barycentrics
struct DxilInst_RayQuery_CandidateTriangleBarycentrics {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateTriangleBarycentrics(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateTriangleBarycentrics);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns committed triangle hit barycentrics
struct DxilInst_RayQuery_CommittedTriangleBarycentrics {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedTriangleBarycentrics(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedTriangleBarycentrics);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns ray flags
struct DxilInst_RayQuery_RayFlags {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_RayFlags(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RayQuery_RayFlags);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns world ray origin
struct DxilInst_RayQuery_WorldRayOrigin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_WorldRayOrigin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_WorldRayOrigin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns world ray direction
struct DxilInst_RayQuery_WorldRayDirection {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_WorldRayDirection(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_WorldRayDirection);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns float representing the parametric starting point
/// for the ray.
struct DxilInst_RayQuery_RayTMin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_RayTMin(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::RayQuery_RayTMin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns float representing the parametric point on the ray
/// for the current candidate triangle hit.
struct DxilInst_RayQuery_CandidateTriangleRayT {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateTriangleRayT(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateTriangleRayT);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns float representing the parametric point on the ray
/// for the current committed hit.
struct DxilInst_RayQuery_CommittedRayT {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedRayT(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedRayT);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate hit instance index
struct DxilInst_RayQuery_CandidateInstanceIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateInstanceIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateInstanceIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate hit instance ID
struct DxilInst_RayQuery_CandidateInstanceID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateInstanceID(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateInstanceID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate hit geometry index
struct DxilInst_RayQuery_CandidateGeometryIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateGeometryIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateGeometryIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate hit geometry index
struct DxilInst_RayQuery_CandidatePrimitiveIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidatePrimitiveIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidatePrimitiveIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns candidate hit object ray origin
struct DxilInst_RayQuery_CandidateObjectRayOrigin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateObjectRayOrigin(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateObjectRayOrigin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns candidate object ray direction
struct DxilInst_RayQuery_CandidateObjectRayDirection {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateObjectRayDirection(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CandidateObjectRayDirection);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns committed hit instance index
struct DxilInst_RayQuery_CommittedInstanceIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedInstanceIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedInstanceIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns committed hit instance ID
struct DxilInst_RayQuery_CommittedInstanceID {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedInstanceID(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedInstanceID);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns committed hit geometry index
struct DxilInst_RayQuery_CommittedGeometryIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedGeometryIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedGeometryIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns committed hit geometry index
struct DxilInst_RayQuery_CommittedPrimitiveIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedPrimitiveIndex(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedPrimitiveIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns committed hit object ray origin
struct DxilInst_RayQuery_CommittedObjectRayOrigin {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedObjectRayOrigin(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedObjectRayOrigin);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction returns committed object ray direction
struct DxilInst_RayQuery_CommittedObjectRayDirection {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedObjectRayDirection(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::RayQuery_CommittedObjectRayDirection);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
arg_component = 2,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_component() const { return Instr->getOperand(2); }
void set_component(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_component_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_component_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction The autogenerated index of the current geometry in the
/// bottom-level structure
struct DxilInst_GeometryIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GeometryIndex(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::GeometryIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns candidate hit InstanceContributionToHitGroupIndex
struct DxilInst_RayQuery_CandidateInstanceContributionToHitGroupIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CandidateInstanceContributionToHitGroupIndex(
llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::
RayQuery_CandidateInstanceContributionToHitGroupIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns committed hit InstanceContributionToHitGroupIndex
struct DxilInst_RayQuery_CommittedInstanceContributionToHitGroupIndex {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_RayQuery_CommittedInstanceContributionToHitGroupIndex(
llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::
RayQuery_CommittedInstanceContributionToHitGroupIndex);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_rayQueryHandle = 1,
};
// Accessors
llvm::Value *get_rayQueryHandle() const { return Instr->getOperand(1); }
void set_rayQueryHandle(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction annotate handle with resource properties
struct DxilInst_AnnotateHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AnnotateHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::AnnotateHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_res = 1,
arg_props = 2,
};
// Accessors
llvm::Value *get_res() const { return Instr->getOperand(1); }
void set_res(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_props() const { return Instr->getOperand(2); }
void set_props(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction create resource handle from binding
struct DxilInst_CreateHandleFromBinding {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateHandleFromBinding(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::CreateHandleFromBinding);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_bind = 1,
arg_index = 2,
arg_nonUniformIndex = 3,
};
// Accessors
llvm::Value *get_bind() const { return Instr->getOperand(1); }
void set_bind(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_index() const { return Instr->getOperand(2); }
void set_index(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_nonUniformIndex() const { return Instr->getOperand(3); }
void set_nonUniformIndex(llvm::Value *val) { Instr->setOperand(3, val); }
bool get_nonUniformIndex_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_nonUniformIndex_val(bool val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
};
/// This instruction create resource handle from heap
struct DxilInst_CreateHandleFromHeap {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateHandleFromHeap(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::CreateHandleFromHeap);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_index = 1,
arg_samplerHeap = 2,
arg_nonUniformIndex = 3,
};
// Accessors
llvm::Value *get_index() const { return Instr->getOperand(1); }
void set_index(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_samplerHeap() const { return Instr->getOperand(2); }
void set_samplerHeap(llvm::Value *val) { Instr->setOperand(2, val); }
bool get_samplerHeap_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_samplerHeap_val(bool val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
llvm::Value *get_nonUniformIndex() const { return Instr->getOperand(3); }
void set_nonUniformIndex(llvm::Value *val) { Instr->setOperand(3, val); }
bool get_nonUniformIndex_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_nonUniformIndex_val(bool val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
};
/// This instruction unpacks 4 8-bit signed or unsigned values into int32 or
/// int16 vector
struct DxilInst_Unpack4x8 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Unpack4x8(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Unpack4x8);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_unpackMode = 1,
arg_pk = 2,
};
// Accessors
llvm::Value *get_unpackMode() const { return Instr->getOperand(1); }
void set_unpackMode(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_pk() const { return Instr->getOperand(2); }
void set_pk(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction packs vector of 4 signed or unsigned values into a packed
/// datatype, drops or clamps unused bits
struct DxilInst_Pack4x8 {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_Pack4x8(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::Pack4x8);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (6 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_packMode = 1,
arg_x = 2,
arg_y = 3,
arg_z = 4,
arg_w = 5,
};
// Accessors
llvm::Value *get_packMode() const { return Instr->getOperand(1); }
void set_packMode(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_x() const { return Instr->getOperand(2); }
void set_x(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_y() const { return Instr->getOperand(3); }
void set_y(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_z() const { return Instr->getOperand(4); }
void set_z(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_w() const { return Instr->getOperand(5); }
void set_w(llvm::Value *val) { Instr->setOperand(5, val); }
};
/// This instruction returns true on helper lanes in pixel shaders
struct DxilInst_IsHelperLane {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IsHelperLane(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::IsHelperLane);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction compares boolean accross a quad
struct DxilInst_QuadVote {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_QuadVote(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr, hlsl::OP::OpCode::QuadVote);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_cond = 1,
arg_op = 2,
};
// Accessors
llvm::Value *get_cond() const { return Instr->getOperand(1); }
void set_cond(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_op() const { return Instr->getOperand(2); }
void set_op(llvm::Value *val) { Instr->setOperand(2, val); }
int8_t get_op_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_op_val(int8_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
};
/// This instruction Gather raw elements from 4 texels with no type conversions
/// (SRV type is constrained)
struct DxilInst_TextureGatherRaw {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureGatherRaw(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TextureGatherRaw);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (9 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
};
/// This instruction samples a texture and compares a single component against
/// the specified comparison value
struct DxilInst_SampleCmpLevel {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleCmpLevel(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::SampleCmpLevel);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (12 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_compareValue = 10,
arg_lod = 11,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_lod() const { return Instr->getOperand(11); }
void set_lod(llvm::Value *val) { Instr->setOperand(11, val); }
};
/// This instruction stores texel data at specified sample index
struct DxilInst_TextureStoreSample {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_TextureStoreSample(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::TextureStoreSample);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (11 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_coord0 = 2,
arg_coord1 = 3,
arg_coord2 = 4,
arg_value0 = 5,
arg_value1 = 6,
arg_value2 = 7,
arg_value3 = 8,
arg_mask = 9,
arg_sampleIdx = 10,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(2); }
void set_coord0(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(3); }
void set_coord1(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(4); }
void set_coord2(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_value0() const { return Instr->getOperand(5); }
void set_value0(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_value1() const { return Instr->getOperand(6); }
void set_value1(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_value2() const { return Instr->getOperand(7); }
void set_value2(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_value3() const { return Instr->getOperand(8); }
void set_value3(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_mask() const { return Instr->getOperand(9); }
void set_mask(llvm::Value *val) { Instr->setOperand(9, val); }
int8_t get_mask_val() const {
return (int8_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(9))
->getZExtValue());
}
void set_mask_val(int8_t val) {
Instr->setOperand(9, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 8),
llvm::APInt(8, (uint64_t)val)));
}
llvm::Value *get_sampleIdx() const { return Instr->getOperand(10); }
void set_sampleIdx(llvm::Value *val) { Instr->setOperand(10, val); }
};
/// This instruction returns a handle for the output records
struct DxilInst_AllocateNodeOutputRecords {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AllocateNodeOutputRecords(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::AllocateNodeOutputRecords);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_output = 1,
arg_numRecords = 2,
arg_perThread = 3,
};
// Accessors
llvm::Value *get_output() const { return Instr->getOperand(1); }
void set_output(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_numRecords() const { return Instr->getOperand(2); }
void set_numRecords(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_perThread() const { return Instr->getOperand(3); }
void set_perThread(llvm::Value *val) { Instr->setOperand(3, val); }
bool get_perThread_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_perThread_val(bool val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
};
/// This instruction retrieve node input/output record pointer in address space
/// 6
struct DxilInst_GetNodeRecordPtr {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GetNodeRecordPtr(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::GetNodeRecordPtr);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_recordhandle = 1,
arg_arrayIndex = 2,
};
// Accessors
llvm::Value *get_recordhandle() const { return Instr->getOperand(1); }
void set_recordhandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_arrayIndex() const { return Instr->getOperand(2); }
void set_arrayIndex(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction Select the next logical output count for an EmptyNodeOutput
/// for the whole group or per thread.
struct DxilInst_IncrementOutputCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IncrementOutputCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::IncrementOutputCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (4 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_output = 1,
arg_count = 2,
arg_perThread = 3,
};
// Accessors
llvm::Value *get_output() const { return Instr->getOperand(1); }
void set_output(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_count() const { return Instr->getOperand(2); }
void set_count(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_perThread() const { return Instr->getOperand(3); }
void set_perThread(llvm::Value *val) { Instr->setOperand(3, val); }
bool get_perThread_val() const {
return (bool)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(3))
->getZExtValue());
}
void set_perThread_val(bool val) {
Instr->setOperand(3, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 1),
llvm::APInt(1, (uint64_t)val)));
}
};
/// This instruction indicates all outputs for a given records are complete
struct DxilInst_OutputComplete {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_OutputComplete(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::OutputComplete);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_output = 1,
};
// Accessors
llvm::Value *get_output() const { return Instr->getOperand(1); }
void set_output(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns the number of records that have been coalesced into
/// the current thread group
struct DxilInst_GetInputRecordCount {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GetInputRecordCount(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::GetInputRecordCount);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_input = 1,
};
// Accessors
llvm::Value *get_input() const { return Instr->getOperand(1); }
void set_input(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns true if the current thread group is the last to
/// access the input
struct DxilInst_FinishedCrossGroupSharing {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_FinishedCrossGroupSharing(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::FinishedCrossGroupSharing);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_input = 1,
};
// Accessors
llvm::Value *get_input() const { return Instr->getOperand(1); }
void set_input(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction Request a barrier for a set of memory types and/or thread
/// group execution sync
struct DxilInst_BarrierByMemoryType {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BarrierByMemoryType(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::BarrierByMemoryType);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_MemoryTypeFlags = 1,
arg_SemanticFlags = 2,
};
// Accessors
llvm::Value *get_MemoryTypeFlags() const { return Instr->getOperand(1); }
void set_MemoryTypeFlags(llvm::Value *val) { Instr->setOperand(1, val); }
int32_t get_MemoryTypeFlags_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_MemoryTypeFlags_val(int32_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
llvm::Value *get_SemanticFlags() const { return Instr->getOperand(2); }
void set_SemanticFlags(llvm::Value *val) { Instr->setOperand(2, val); }
int32_t get_SemanticFlags_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_SemanticFlags_val(int32_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction Request a barrier for just the memory used by the specified
/// object
struct DxilInst_BarrierByMemoryHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BarrierByMemoryHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::BarrierByMemoryHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_object = 1,
arg_SemanticFlags = 2,
};
// Accessors
llvm::Value *get_object() const { return Instr->getOperand(1); }
void set_object(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_SemanticFlags() const { return Instr->getOperand(2); }
void set_SemanticFlags(llvm::Value *val) { Instr->setOperand(2, val); }
int32_t get_SemanticFlags_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_SemanticFlags_val(int32_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction Request a barrier for just the memory used by the node
/// record
struct DxilInst_BarrierByNodeRecordHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_BarrierByNodeRecordHandle(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::BarrierByNodeRecordHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_object = 1,
arg_SemanticFlags = 2,
};
// Accessors
llvm::Value *get_object() const { return Instr->getOperand(1); }
void set_object(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_SemanticFlags() const { return Instr->getOperand(2); }
void set_SemanticFlags(llvm::Value *val) { Instr->setOperand(2, val); }
int32_t get_SemanticFlags_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(2))
->getZExtValue());
}
void set_SemanticFlags_val(int32_t val) {
Instr->setOperand(2, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction Creates a handle to a NodeOutput
struct DxilInst_CreateNodeOutputHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateNodeOutputHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::CreateNodeOutputHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_MetadataIdx = 1,
};
// Accessors
llvm::Value *get_MetadataIdx() const { return Instr->getOperand(1); }
void set_MetadataIdx(llvm::Value *val) { Instr->setOperand(1, val); }
int32_t get_MetadataIdx_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_MetadataIdx_val(int32_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction returns the handle for the location in the output node
/// array at the indicated index
struct DxilInst_IndexNodeHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_IndexNodeHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::IndexNodeHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_NodeOutputHandle = 1,
arg_ArrayIndex = 2,
};
// Accessors
llvm::Value *get_NodeOutputHandle() const { return Instr->getOperand(1); }
void set_NodeOutputHandle(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_ArrayIndex() const { return Instr->getOperand(2); }
void set_ArrayIndex(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction annotate handle with node properties
struct DxilInst_AnnotateNodeHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AnnotateNodeHandle(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::AnnotateNodeHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_node = 1,
arg_props = 2,
};
// Accessors
llvm::Value *get_node() const { return Instr->getOperand(1); }
void set_node(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_props() const { return Instr->getOperand(2); }
void set_props(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction create a handle for an InputRecord
struct DxilInst_CreateNodeInputRecordHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_CreateNodeInputRecordHandle(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::CreateNodeInputRecordHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_MetadataIdx = 1,
};
// Accessors
llvm::Value *get_MetadataIdx() const { return Instr->getOperand(1); }
void set_MetadataIdx(llvm::Value *val) { Instr->setOperand(1, val); }
int32_t get_MetadataIdx_val() const {
return (int32_t)(llvm::dyn_cast<llvm::ConstantInt>(Instr->getOperand(1))
->getZExtValue());
}
void set_MetadataIdx_val(int32_t val) {
Instr->setOperand(1, llvm::Constant::getIntegerValue(
llvm::IntegerType::get(Instr->getContext(), 32),
llvm::APInt(32, (uint64_t)val)));
}
};
/// This instruction annotate handle with node record properties
struct DxilInst_AnnotateNodeRecordHandle {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_AnnotateNodeRecordHandle(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::AnnotateNodeRecordHandle);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (3 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_noderecord = 1,
arg_props = 2,
};
// Accessors
llvm::Value *get_noderecord() const { return Instr->getOperand(1); }
void set_noderecord(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_props() const { return Instr->getOperand(2); }
void set_props(llvm::Value *val) { Instr->setOperand(2, val); }
};
/// This instruction returns true if the specified output node is present in the
/// work graph
struct DxilInst_NodeOutputIsValid {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_NodeOutputIsValid(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::NodeOutputIsValid);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (2 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_output = 1,
};
// Accessors
llvm::Value *get_output() const { return Instr->getOperand(1); }
void set_output(llvm::Value *val) { Instr->setOperand(1, val); }
};
/// This instruction returns how many levels of recursion remain
struct DxilInst_GetRemainingRecursionLevels {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_GetRemainingRecursionLevels(llvm::Instruction *pInstr)
: Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::GetRemainingRecursionLevels);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction samples a texture using a gradient and compares a single
/// component against the specified comparison value
struct DxilInst_SampleCmpGrad {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleCmpGrad(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::SampleCmpGrad);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (18 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_compareValue = 10,
arg_ddx0 = 11,
arg_ddx1 = 12,
arg_ddx2 = 13,
arg_ddy0 = 14,
arg_ddy1 = 15,
arg_ddy2 = 16,
arg_clamp = 17,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_ddx0() const { return Instr->getOperand(11); }
void set_ddx0(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_ddx1() const { return Instr->getOperand(12); }
void set_ddx1(llvm::Value *val) { Instr->setOperand(12, val); }
llvm::Value *get_ddx2() const { return Instr->getOperand(13); }
void set_ddx2(llvm::Value *val) { Instr->setOperand(13, val); }
llvm::Value *get_ddy0() const { return Instr->getOperand(14); }
void set_ddy0(llvm::Value *val) { Instr->setOperand(14, val); }
llvm::Value *get_ddy1() const { return Instr->getOperand(15); }
void set_ddy1(llvm::Value *val) { Instr->setOperand(15, val); }
llvm::Value *get_ddy2() const { return Instr->getOperand(16); }
void set_ddy2(llvm::Value *val) { Instr->setOperand(16, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(17); }
void set_clamp(llvm::Value *val) { Instr->setOperand(17, val); }
};
/// This instruction samples a texture after applying the input bias to the
/// mipmap level and compares a single component against the specified
/// comparison value
struct DxilInst_SampleCmpBias {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_SampleCmpBias(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::SampleCmpBias);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (13 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
// Operand indexes
enum OperandIdx {
arg_srv = 1,
arg_sampler = 2,
arg_coord0 = 3,
arg_coord1 = 4,
arg_coord2 = 5,
arg_coord3 = 6,
arg_offset0 = 7,
arg_offset1 = 8,
arg_offset2 = 9,
arg_compareValue = 10,
arg_bias = 11,
arg_clamp = 12,
};
// Accessors
llvm::Value *get_srv() const { return Instr->getOperand(1); }
void set_srv(llvm::Value *val) { Instr->setOperand(1, val); }
llvm::Value *get_sampler() const { return Instr->getOperand(2); }
void set_sampler(llvm::Value *val) { Instr->setOperand(2, val); }
llvm::Value *get_coord0() const { return Instr->getOperand(3); }
void set_coord0(llvm::Value *val) { Instr->setOperand(3, val); }
llvm::Value *get_coord1() const { return Instr->getOperand(4); }
void set_coord1(llvm::Value *val) { Instr->setOperand(4, val); }
llvm::Value *get_coord2() const { return Instr->getOperand(5); }
void set_coord2(llvm::Value *val) { Instr->setOperand(5, val); }
llvm::Value *get_coord3() const { return Instr->getOperand(6); }
void set_coord3(llvm::Value *val) { Instr->setOperand(6, val); }
llvm::Value *get_offset0() const { return Instr->getOperand(7); }
void set_offset0(llvm::Value *val) { Instr->setOperand(7, val); }
llvm::Value *get_offset1() const { return Instr->getOperand(8); }
void set_offset1(llvm::Value *val) { Instr->setOperand(8, val); }
llvm::Value *get_offset2() const { return Instr->getOperand(9); }
void set_offset2(llvm::Value *val) { Instr->setOperand(9, val); }
llvm::Value *get_compareValue() const { return Instr->getOperand(10); }
void set_compareValue(llvm::Value *val) { Instr->setOperand(10, val); }
llvm::Value *get_bias() const { return Instr->getOperand(11); }
void set_bias(llvm::Value *val) { Instr->setOperand(11, val); }
llvm::Value *get_clamp() const { return Instr->getOperand(12); }
void set_clamp(llvm::Value *val) { Instr->setOperand(12, val); }
};
/// This instruction returns the BaseVertexLocation from DrawIndexedInstanced or
/// StartVertexLocation from DrawInstanced
struct DxilInst_StartVertexLocation {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StartVertexLocation(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::StartVertexLocation);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
/// This instruction returns the StartInstanceLocation from Draw*Instanced
struct DxilInst_StartInstanceLocation {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_StartInstanceLocation(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(
Instr, hlsl::OP::OpCode::StartInstanceLocation);
}
// Validation support
bool isAllowed() const { return true; }
bool isArgumentListValid() const {
if (1 != llvm::dyn_cast<llvm::CallInst>(Instr)->getNumArgOperands())
return false;
return true;
}
// Metadata
bool requiresUniformInputs() const { return false; }
};
// INSTR-HELPER:END
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilResource.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilResource.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of HLSL SRVs and UAVs. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
#include "dxc/DXIL/DxilCompType.h"
#include "dxc/DXIL/DxilResourceBase.h"
namespace hlsl {
/// Use this class to represent an HLSL resource (SRV/UAV).
class DxilResource : public DxilResourceBase {
public:
/// Total number of coordinates necessary to access resource.
static unsigned GetNumCoords(Kind ResourceKind);
/// Total number of resource dimensions (Only width and height for cube).
static unsigned GetNumDimensions(Kind ResourceKind);
/// Total number of resource dimensions for CalcLOD (no array).
static unsigned GetNumDimensionsForCalcLOD(Kind ResourceKind);
/// Total number of offsets (in [-8,7]) necessary to access resource.
static unsigned GetNumOffsets(Kind ResourceKind);
/// Whether the resource kind is a texture. This does not include
/// FeedbackTextures.
static bool IsAnyTexture(Kind ResourceKind);
/// Whether the resource kind is an array of textures. This does not include
/// FeedbackTextures.
static bool IsAnyArrayTexture(Kind ResourceKind);
/// Whether the resource kind is a TextureCube or TextureCubeArray.
static bool IsAnyTextureCube(Kind ResourceKind);
/// Whether the resource kind is a FeedbackTexture.
static bool IsFeedbackTexture(Kind ResourceKind);
/// Whether the resource kind is a Texture or FeedbackTexture kind with array
/// dimension.
static bool IsArrayKind(Kind ResourceKind);
DxilResource();
CompType GetCompType() const;
void SetCompType(const CompType CT);
llvm::Type *GetRetType() const;
unsigned GetSampleCount() const;
void SetSampleCount(unsigned SampleCount);
unsigned GetElementStride() const;
void SetElementStride(unsigned ElemStride);
unsigned GetBaseAlignLog2() const;
void SetBaseAlignLog2(unsigned baseAlignLog2);
DXIL::SamplerFeedbackType GetSamplerFeedbackType() const;
void SetSamplerFeedbackType(DXIL::SamplerFeedbackType Value);
bool IsGloballyCoherent() const;
void SetGloballyCoherent(bool b);
bool HasCounter() const;
void SetHasCounter(bool b);
bool IsRO() const;
bool IsRW() const;
void SetRW(bool bRW);
bool IsROV() const;
void SetROV(bool bROV);
bool IsAnyTexture() const;
bool IsStructuredBuffer() const;
bool IsTypedBuffer() const;
bool IsRawBuffer() const;
bool IsTBuffer() const;
bool IsFeedbackTexture() const;
bool IsAnyArrayTexture() const;
bool IsAnyTextureCube() const;
bool IsArrayKind() const;
bool HasAtomic64Use() const;
void SetHasAtomic64Use(bool b);
static bool classof(const DxilResourceBase *R) {
return R->GetClass() == DXIL::ResourceClass::SRV ||
R->GetClass() == DXIL::ResourceClass::UAV;
}
private:
unsigned m_SampleCount;
unsigned m_ElementStride; // in bytes
unsigned m_baseAlignLog2 = 0; // worst-case alignment
CompType m_CompType;
DXIL::SamplerFeedbackType m_SamplerFeedbackType;
bool m_bGloballyCoherent;
bool m_bHasCounter;
bool m_bROV;
bool m_bHasAtomic64Use;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilResourceProperties.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilResourceProperties.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation properties for DXIL handle. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
namespace llvm {
class Constant;
class Type;
} // namespace llvm
namespace hlsl {
struct DxilResourceProperties {
struct TypedProps {
uint8_t CompType; // TypedBuffer/Image component type.
uint8_t CompCount; // Number of components known to shader.
uint8_t SampleCount; // Number of samples for multisample texture if defined
// in HLSL.
uint8_t Reserved3;
};
struct BasicProps {
// BYTE 0
uint8_t ResourceKind; // DXIL::ResourceKind
// BYTE 1
// Alignment of SRV/UAV base in 2^n. 0 is unknown/worst-case.
uint8_t BaseAlignLog2 : 4;
uint8_t IsUAV : 1;
uint8_t IsROV : 1;
uint8_t IsGloballyCoherent : 1;
// Depending on ResourceKind, this indicates:
// Sampler: SamplerKind::Comparison
// StructuredBuffer: HasCounter
// Other: must be 0
uint8_t SamplerCmpOrHasCounter : 1;
// BYTE 2
uint8_t Reserved2;
// BYTE 3
uint8_t Reserved3;
};
union {
BasicProps Basic;
uint32_t RawDword0;
};
// DWORD
union {
TypedProps Typed;
uint32_t StructStrideInBytes; // in bytes for StructuredBuffer.
DXIL::SamplerFeedbackType SamplerFeedbackType; // FeedbackTexture2D.
uint32_t CBufferSizeInBytes; // Cbuffer used size in bytes.
uint32_t RawDword1;
};
DxilResourceProperties();
DXIL::ResourceClass getResourceClass() const;
DXIL::ResourceKind getResourceKind() const;
DXIL::ComponentType getCompType() const;
unsigned getElementStride() const;
void setResourceKind(DXIL::ResourceKind RK);
bool isUAV() const;
bool operator==(const DxilResourceProperties &) const;
bool operator!=(const DxilResourceProperties &) const;
bool isValid() const;
};
static_assert(sizeof(DxilResourceProperties) == 2 * sizeof(uint32_t),
"update shader model and functions read/write "
"DxilResourceProperties when size is changed");
class ShaderModel;
class DxilResourceBase;
struct DxilInst_AnnotateHandle;
namespace resource_helper {
llvm::Constant *getAsConstant(const DxilResourceProperties &, llvm::Type *Ty,
const ShaderModel &);
DxilResourceProperties loadPropsFromConstant(const llvm::Constant &C);
DxilResourceProperties
loadPropsFromAnnotateHandle(DxilInst_AnnotateHandle &annotateHandle,
const ShaderModel &);
DxilResourceProperties loadPropsFromResourceBase(const DxilResourceBase *);
DxilResourceProperties tryMergeProps(DxilResourceProperties,
DxilResourceProperties);
llvm::Constant *tryMergeProps(const llvm::Constant *, const llvm::Constant *,
llvm::Type *Ty, const ShaderModel &);
} // namespace resource_helper
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilCompType.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilCompType.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Represenation of HLSL component type. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
namespace llvm {
class Type;
class PointerType;
class LLVMContext;
} // namespace llvm
namespace hlsl {
/// Use this class to represent HLSL component/element types.
class CompType {
public:
using Kind = DXIL::ComponentType;
CompType();
CompType(Kind K);
CompType(unsigned int K);
bool operator==(const CompType &o) const;
Kind GetKind() const;
uint8_t GetSizeInBits() const;
static CompType getInvalid();
static CompType getF16();
static CompType getF32();
static CompType getF64();
static CompType getI16();
static CompType getI32();
static CompType getI64();
static CompType getU16();
static CompType getU32();
static CompType getU64();
static CompType getI1();
static CompType getSNormF16();
static CompType getUNormF16();
static CompType getSNormF32();
static CompType getUNormF32();
static CompType getSNormF64();
static CompType getUNormF64();
bool IsInvalid() const;
bool IsFloatTy() const;
bool IsIntTy() const;
bool IsSIntTy() const;
bool IsUIntTy() const;
bool IsBoolTy() const;
bool IsSNorm() const;
bool IsUNorm() const;
bool Is64Bit() const;
bool Is16Bit() const;
/// For min-precision types, returns upconverted (base) type.
CompType GetBaseCompType() const;
bool HasMinPrec() const;
llvm::Type *GetLLVMType(llvm::LLVMContext &Ctx) const;
llvm::PointerType *GetLLVMPtrType(llvm::LLVMContext &Ctx,
const unsigned AddrSpace = 0) const;
llvm::Type *GetLLVMBaseType(llvm::LLVMContext &Ctx) const;
/// Get the component type for a given llvm type.
///
/// LLVM types do not hold sign information so there is no 1-1
/// correspondence between llvm types and component types.
/// This method returns the signed version for all integer
/// types.
///
/// TODO: decide if we should distinguish between signed
/// and unsigned types in this api.
static CompType GetCompType(llvm::Type *type);
const char *GetName() const;
const char *GetHLSLName(bool MinPrecision) const;
private:
Kind m_Kind;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DXIL/DxilNodeProps.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilNodeProps.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Representation of DXIL nodes and node records properties //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "DxilConstants.h"
#include <string>
namespace llvm {
class StringRef;
}
namespace hlsl {
//------------------------------------------------------------------------------
//
// NodeID
//
struct NodeID {
std::string Name;
unsigned Index;
};
//------------------------------------------------------------------------------
//
// SVDispatchGrid
//
struct SVDispatchGrid {
unsigned ByteOffset;
DXIL::ComponentType ComponentType;
unsigned NumComponents;
};
//------------------------------------------------------------------------------
//
// NodeRecordType
//
struct NodeRecordType {
unsigned size;
unsigned alignment;
SVDispatchGrid SV_DispatchGrid;
};
//------------------------------------------------------------------------------
//
// NodeInfo
//
struct NodeInfo {
NodeInfo() : NodeInfo(DXIL::NodeIOFlags::None) {}
NodeInfo(DXIL::NodeIOFlags flags, unsigned recordSize = 0)
: IOFlags((unsigned)flags), RecordSize(recordSize) {}
NodeInfo(DXIL::NodeIOKind kind, unsigned recordSize = 0)
: NodeInfo((DXIL::NodeIOFlags)kind, recordSize) {}
unsigned IOFlags;
unsigned RecordSize; // 0 if EmptyNodeOutput
};
//------------------------------------------------------------------------------
//
// NodeRecordInfo
//
typedef NodeInfo NodeRecordInfo;
//------------------------------------------------------------------------------
//
// NodeProps
//
struct NodeProps {
unsigned MetadataIdx;
NodeInfo Info;
};
//------------------------------------------------------------------------------
//
// NodeInputRecerdProps
//
struct NodeInputRecordProps {
unsigned MetadataIdx;
NodeRecordInfo RecordInfo;
};
//------------------------------------------------------------------------------
//
// NodeFlags - helper class for working with DXIL::NodeIOFlags and
// DXIL::NodeIOKind
//
struct NodeFlags {
public:
NodeFlags();
NodeFlags(DXIL::NodeIOFlags flags);
NodeFlags(DXIL::NodeIOKind kind);
NodeFlags(uint32_t F);
bool operator==(const NodeFlags &o) const;
operator uint32_t() const;
DXIL::NodeIOKind GetNodeIOKind() const;
DXIL::NodeIOFlags GetNodeIOFlags() const;
bool IsInputRecord() const;
bool IsRecord() const;
bool IsOutput() const;
bool IsOutputNode() const;
bool IsOutputRecord() const;
bool IsReadWrite() const;
bool IsEmpty() const;
bool IsEmptyInput() const;
bool IsValidNodeKind() const;
bool RecordTypeMatchesLaunchType(DXIL::NodeLaunchType launchType) const;
void SetTrackRWInputSharing();
bool GetTrackRWInputSharing() const;
void SetGloballyCoherent();
bool GetGloballyCoherent() const;
private:
DXIL::NodeIOFlags m_Flags;
}; // end of NodeFlags
//------------------------------------------------------------------------------
//
// NodeIOProperties
//
struct NodeIOProperties {
NodeFlags Flags = NodeFlags();
NodeRecordType RecordType = {};
NodeID OutputID = {};
unsigned MaxRecords = 0;
int MaxRecordsSharedWith = -1;
unsigned OutputArraySize = 0;
bool AllowSparseNodes = false;
public:
NodeIOProperties() {}
NodeIOProperties(NodeFlags flags) : Flags(flags) {}
NodeInfo GetNodeInfo() const;
NodeRecordInfo GetNodeRecordInfo() const;
};
} // namespace hlsl
|
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DxilPIXPasses/DxilPIXVirtualRegisters.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilPIXVirtualRegisters.cpp //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Declares functions for dealing with the virtual register annotations in //
// DXIL instructions. //
// //
///////////////////////////////////////////////////////////////////////////////
#include <cstdint>
namespace llvm {
class AllocaInst;
class Instruction;
class LLVMContext;
class MDNode;
class StoreInst;
class Value;
} // namespace llvm
namespace pix_dxil {
namespace PixDxilInstNum {
static constexpr char MDName[] = "pix-dxil-inst-num";
static constexpr uint32_t ID = 3;
void AddMD(llvm::LLVMContext &Ctx, llvm::Instruction *pI,
std::uint32_t InstNum);
bool FromInst(llvm::Instruction const *pI, std::uint32_t *pInstNum);
} // namespace PixDxilInstNum
namespace PixDxilReg {
static constexpr char MDName[] = "pix-dxil-reg";
static constexpr uint32_t ID = 0;
void AddMD(llvm::LLVMContext &Ctx, llvm::Instruction *pI, std::uint32_t RegNum);
bool FromInst(llvm::Instruction const *pI, std::uint32_t *pRegNum);
} // namespace PixDxilReg
namespace PixAllocaReg {
static constexpr char MDName[] = "pix-alloca-reg";
static constexpr uint32_t ID = 1;
void AddMD(llvm::LLVMContext &Ctx, llvm::AllocaInst *pAlloca,
std::uint32_t RegNum, std::uint32_t Count);
bool FromInst(llvm::AllocaInst const *pAlloca, std::uint32_t *pRegBase,
std::uint32_t *pRegSize);
} // namespace PixAllocaReg
namespace PixAllocaRegWrite {
static constexpr char MDName[] = "pix-alloca-reg-write";
static constexpr uint32_t ID = 2;
void AddMD(llvm::LLVMContext &Ctx, llvm::StoreInst *pSt,
llvm::MDNode *pAllocaReg, llvm::Value *Index);
bool FromInst(llvm::StoreInst *pI, std::uint32_t *pRegBase,
std::uint32_t *pRegSize, llvm::Value **pIndex);
} // namespace PixAllocaRegWrite
} // namespace pix_dxil |
0 | repos/DirectXShaderCompiler/include/dxc | repos/DirectXShaderCompiler/include/dxc/DxilPIXPasses/DxilPIXPasses.h | ///////////////////////////////////////////////////////////////////////////////
// //
// DxilPixPasses.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// This file provides a DXIL passes to support PIX. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
namespace llvm {
class ModulePass;
class PassRegistry;
ModulePass *createDxilAddPixelHitInstrumentationPass();
ModulePass *createDxilDbgValueToDbgDeclarePass();
ModulePass *createDxilAnnotateWithVirtualRegisterPass();
ModulePass *createDxilOutputColorBecomesConstantPass();
ModulePass *createDxilDxilPIXMeshShaderOutputInstrumentation();
ModulePass *createDxilRemoveDiscardsPass();
ModulePass *createDxilReduceMSAAToSingleSamplePass();
ModulePass *createDxilForceEarlyZPass();
ModulePass *createDxilDebugInstrumentationPass();
ModulePass *createDxilShaderAccessTrackingPass();
ModulePass *createDxilPIXAddTidToAmplificationShaderPayloadPass();
ModulePass *createDxilPIXDXRInvocationsLogPass();
void initializeDxilAddPixelHitInstrumentationPass(llvm::PassRegistry &);
void initializeDxilDbgValueToDbgDeclarePass(llvm::PassRegistry &);
void initializeDxilAnnotateWithVirtualRegisterPass(llvm::PassRegistry &);
void initializeDxilOutputColorBecomesConstantPass(llvm::PassRegistry &);
void initializeDxilPIXMeshShaderOutputInstrumentationPass(llvm::PassRegistry &);
void initializeDxilRemoveDiscardsPass(llvm::PassRegistry &);
void initializeDxilReduceMSAAToSingleSamplePass(llvm::PassRegistry &);
void initializeDxilForceEarlyZPass(llvm::PassRegistry &);
void initializeDxilDebugInstrumentationPass(llvm::PassRegistry &);
void initializeDxilShaderAccessTrackingPass(llvm::PassRegistry &);
void initializeDxilPIXAddTidToAmplificationShaderPayloadPass(
llvm::PassRegistry &);
void initializeDxilPIXDXRInvocationsLogPass(llvm::PassRegistry &);
} // namespace llvm
|
0 | repos/DirectXShaderCompiler | repos/DirectXShaderCompiler/lib/CMakeLists.txt | # `Support' and `TableGen' libraries are added on the top-level CMakeLists.txt
add_subdirectory(IR)
add_subdirectory(IRReader)
# add_subdirectory(CodeGen) # HLSL Change
add_subdirectory(Bitcode)
add_subdirectory(Transforms)
add_subdirectory(Linker)
add_subdirectory(Analysis)
# add_subdirectory(LTO) # HLSL Change
# add_subdirectory(MC) # HLSL Change
# add_subdirectory(Object) # HLSL Change
add_subdirectory(Option)
# add_subdirectory(DebugInfo) # HLSL Change
# add_subdirectory(ExecutionEngine) # HLSL Change
add_subdirectory(Target)
add_subdirectory(AsmParser)
# add_subdirectory(LineEditor) # HLSL Change
add_subdirectory(ProfileData)
# add_subdirectory(Fuzzer) # HLSL Change
add_subdirectory(Passes) # HLSL Change
add_subdirectory(PassPrinters) # HLSL Change
# add_subdirectory(LibDriver) # HLSL Change
add_subdirectory(DxcSupport) # HLSL Change
add_subdirectory(HLSL) # HLSL Change
add_subdirectory(DXIL) # HLSL Change
add_subdirectory(DxilContainer) # HLSL Change
add_subdirectory(DxilHash) # HLSL Change
add_subdirectory(DxilPdbInfo) # HLSL Change
add_subdirectory(DxilPIXPasses) # HLSL Change
add_subdirectory(DxilDia) # HLSL Change
add_subdirectory(DxilRootSignature) # HLSL Change
add_subdirectory(DxilValidation) # HLSL Change
add_subdirectory(DxcBindingTable) # HLSL Change
add_subdirectory(DxrFallback) # HLSL Change
add_subdirectory(DxilCompression) # HLSL Change
|
0 | repos/DirectXShaderCompiler | repos/DirectXShaderCompiler/lib/LLVMBuild.txt | ;===- ./lib/LLVMBuild.txt --------------------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[common]
subdirectories =
Analysis
AsmParser
Bitcode
CodeGen
DebugInfo
DxcSupport
DxilPIXPasses
ExecutionEngine
Linker
IR
IRReader
MC
Object
Option
Passes
PassPrinters
ProfileData
Support
TableGen
Target
Transforms
HLSL
DXIL
DxilContainer
DxilPdbInfo
DxilDia
DxrFallback
DxilRootSignature
DxcBindingTable
DxilCompression
; HLSL Change: remove LibDriver, LineEditor, add HLSL, DxrtFallback, DXIL, DxilContainer, DxilDia, DxilPIXPasses, DxilRootSignature, DxcBindingTable, LTO
[component_0]
type = Group
name = Libraries
parent = $ROOT
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCLabel.cpp | //===- lib/MC/MCLabel.cpp - MCLabel implementation ----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCLabel.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
void MCLabel::print(raw_ostream &OS) const {
OS << '"' << getInstance() << '"';
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MCLabel::dump() const {
print(dbgs());
}
#endif
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCValue.cpp | //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCValue.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
void MCValue::print(raw_ostream &OS) const {
if (isAbsolute()) {
OS << getConstant();
return;
}
// FIXME: prints as a number, which isn't ideal. But the meaning will be
// target-specific anyway.
if (getRefKind())
OS << ':' << getRefKind() << ':';
OS << *getSymA();
if (getSymB()) {
OS << " - ";
OS << *getSymB();
}
if (getConstant())
OS << " + " << getConstant();
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MCValue::dump() const {
print(dbgs());
}
#endif
MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
const MCSymbolRefExpr *B = getSymB();
if (B) {
if (B->getKind() != MCSymbolRefExpr::VK_None)
llvm_unreachable("unsupported");
}
const MCSymbolRefExpr *A = getSymA();
if (!A)
return MCSymbolRefExpr::VK_None;
MCSymbolRefExpr::VariantKind Kind = A->getKind();
if (Kind == MCSymbolRefExpr::VK_WEAKREF)
return MCSymbolRefExpr::VK_None;
return Kind;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCContext.cpp | //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCContext.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCLabel.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbolCOFF.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCSymbolMachO.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include <map>
using namespace llvm;
MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
const MCObjectFileInfo *mofi, const SourceMgr *mgr,
bool DoAutoReset)
: SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), Allocator(),
Symbols(Allocator), UsedNames(Allocator),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0), DwarfLocSeen(false),
GenDwarfForAssembly(false), GenDwarfFileNumber(0), DwarfVersion(4),
AllowTemporaryLabels(true), DwarfCompileUnitID(0),
AutoReset(DoAutoReset) {
std::error_code EC = llvm::sys::fs::current_path(CompilationDir);
if (EC)
CompilationDir.clear();
SecureLogFile = getenv("AS_SECURE_LOG_FILE");
SecureLog = nullptr;
SecureLogUsed = false;
if (SrcMgr && SrcMgr->getNumBuffers())
MainFileName =
SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
}
MCContext::~MCContext() {
if (AutoReset)
reset();
// NOTE: The symbols are all allocated out of a bump pointer allocator,
// we don't need to free them here.
// If the stream for the .secure_log_unique directive was created free it.
delete (raw_ostream *)SecureLog;
}
//===----------------------------------------------------------------------===//
// Module Lifetime Management
//===----------------------------------------------------------------------===//
void MCContext::reset() {
// Call the destructors so the fragments are freed
for (auto &I : ELFUniquingMap)
I.second->~MCSectionELF();
for (auto &I : COFFUniquingMap)
I.second->~MCSectionCOFF();
for (auto &I : MachOUniquingMap)
I.second->~MCSectionMachO();
UsedNames.clear();
Symbols.clear();
Allocator.Reset();
Instances.clear();
CompilationDir.clear();
MainFileName.clear();
MCDwarfLineTablesCUMap.clear();
SectionsForRanges.clear();
MCGenDwarfLabelEntries.clear();
DwarfDebugFlags = StringRef();
DwarfCompileUnitID = 0;
CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
MachOUniquingMap.clear();
ELFUniquingMap.clear();
COFFUniquingMap.clear();
NextID.clear();
AllowTemporaryLabels = true;
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
}
//===----------------------------------------------------------------------===//
// Symbol Manipulation
//===----------------------------------------------------------------------===//
MCSymbol *MCContext::getOrCreateSymbol(const Twine &Name) {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
MCSymbol *&Sym = Symbols[NameRef];
if (!Sym)
Sym = createSymbol(NameRef, false, false);
return Sym;
}
MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
MCSymbolELF *&Sym = SectionSymbols[&Section];
if (Sym)
return Sym;
StringRef Name = Section.getSectionName();
MCSymbol *&OldSym = Symbols[Name];
if (OldSym && OldSym->isUndefined()) {
Sym = cast<MCSymbolELF>(OldSym);
return Sym;
}
auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first;
Sym = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
if (!OldSym)
OldSym = Sym;
return Sym;
}
MCSymbol *MCContext::getOrCreateFrameAllocSymbol(StringRef FuncName,
unsigned Idx) {
return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
"$frame_escape_" + Twine(Idx));
}
MCSymbol *MCContext::getOrCreateParentFrameOffsetSymbol(StringRef FuncName) {
return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
"$parent_frame_offset");
}
MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
FuncName);
}
MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
bool IsTemporary) {
if (MOFI) {
switch (MOFI->getObjectFileType()) {
case MCObjectFileInfo::IsCOFF:
return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
case MCObjectFileInfo::IsELF:
return new (Name, *this) MCSymbolELF(Name, IsTemporary);
case MCObjectFileInfo::IsMachO:
return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
}
}
return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
IsTemporary);
}
MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
bool CanBeUnnamed) {
if (CanBeUnnamed && !UseNamesOnTempLabels)
return createSymbolImpl(nullptr, true);
// Determine whether this is an user writter assembler temporary or normal
// label, if used.
bool IsTemporary = CanBeUnnamed;
if (AllowTemporaryLabels && !IsTemporary)
IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
SmallString<128> NewName = Name;
bool AddSuffix = AlwaysAddSuffix;
unsigned &NextUniqueID = NextID[Name];
for (;;) {
if (AddSuffix) {
NewName.resize(Name.size());
raw_svector_ostream(NewName) << NextUniqueID++;
}
auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
if (NameEntry.second) {
// Ok, we found a name. Have the MCSymbol object itself refer to the copy
// of the string that is embedded in the UsedNames entry.
return createSymbolImpl(&*NameEntry.first, IsTemporary);
}
assert(IsTemporary && "Cannot rename non-temporary symbols");
AddSuffix = true;
}
llvm_unreachable("Infinite loop");
}
MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
bool CanBeUnnamed) {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
}
MCSymbol *MCContext::createLinkerPrivateTempSymbol() {
SmallString<128> NameSV;
raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
return createSymbol(NameSV, true, false);
}
MCSymbol *MCContext::createTempSymbol(bool CanBeUnnamed) {
return createTempSymbol("tmp", true, CanBeUnnamed);
}
unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
MCLabel *&Label = Instances[LocalLabelVal];
if (!Label)
Label = new (*this) MCLabel(0);
return Label->incInstance();
}
unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
MCLabel *&Label = Instances[LocalLabelVal];
if (!Label)
Label = new (*this) MCLabel(0);
return Label->getInstance();
}
MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
unsigned Instance) {
MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
if (!Sym)
Sym = createTempSymbol(false);
return Sym;
}
MCSymbol *MCContext::createDirectionalLocalSymbol(unsigned LocalLabelVal) {
unsigned Instance = NextInstance(LocalLabelVal);
return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
}
MCSymbol *MCContext::getDirectionalLocalSymbol(unsigned LocalLabelVal,
bool Before) {
unsigned Instance = GetInstance(LocalLabelVal);
if (!Before)
++Instance;
return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
}
MCSymbol *MCContext::lookupSymbol(const Twine &Name) const {
SmallString<128> NameSV;
StringRef NameRef = Name.toStringRef(NameSV);
return Symbols.lookup(NameRef);
}
//===----------------------------------------------------------------------===//
// Section Management
//===----------------------------------------------------------------------===//
MCSectionMachO *MCContext::getMachOSection(StringRef Segment, StringRef Section,
unsigned TypeAndAttributes,
unsigned Reserved2, SectionKind Kind,
const char *BeginSymName) {
// We unique sections by their segment/section pair. The returned section
// may not have the same flags as the requested section, if so this should be
// diagnosed by the client as an error.
// Form the name to look up.
SmallString<64> Name;
Name += Segment;
Name.push_back(',');
Name += Section;
// Do the lookup, if we have a hit, return it.
MCSectionMachO *&Entry = MachOUniquingMap[Name];
if (Entry)
return Entry;
MCSymbol *Begin = nullptr;
if (BeginSymName)
Begin = createTempSymbol(BeginSymName, false);
// Otherwise, return a new section.
return Entry = new (*this) MCSectionMachO(Segment, Section, TypeAndAttributes,
Reserved2, Kind, Begin);
}
void MCContext::renameELFSection(MCSectionELF *Section, StringRef Name) {
StringRef GroupName;
if (const MCSymbol *Group = Section->getGroup())
GroupName = Group->getName();
unsigned UniqueID = Section->getUniqueID();
ELFUniquingMap.erase(
ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});
auto I = ELFUniquingMap.insert(std::make_pair(
ELFSectionKey{Name, GroupName, UniqueID},
Section))
.first;
StringRef CachedName = I->first.SectionName;
const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
}
MCSectionELF *MCContext::createELFRelSection(StringRef Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *Group,
const MCSectionELF *Associated) {
StringMap<bool>::iterator I;
bool Inserted;
std::tie(I, Inserted) = ELFRelSecNames.insert(std::make_pair(Name, true));
return new (*this)
MCSectionELF(I->getKey(), Type, Flags, SectionKind::getReadOnly(),
EntrySize, Group, true, nullptr, Associated);
}
MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
StringRef Group, unsigned UniqueID,
const char *BeginSymName) {
MCSymbolELF *GroupSym = nullptr;
if (!Group.empty())
GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
BeginSymName, nullptr);
}
MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbolELF *GroupSym,
unsigned UniqueID,
const char *BeginSymName,
const MCSectionELF *Associated) {
StringRef Group = "";
if (GroupSym)
Group = GroupSym->getName();
// Do the lookup, if we have a hit, return it.
auto IterBool = ELFUniquingMap.insert(
std::make_pair(ELFSectionKey{Section, Group, UniqueID}, nullptr));
auto &Entry = *IterBool.first;
if (!IterBool.second)
return Entry.second;
StringRef CachedName = Entry.first.SectionName;
SectionKind Kind;
if (Flags & ELF::SHF_EXECINSTR)
Kind = SectionKind::getText();
else
Kind = SectionKind::getReadOnly();
MCSymbol *Begin = nullptr;
if (BeginSymName)
Begin = createTempSymbol(BeginSymName, false);
MCSectionELF *Result =
new (*this) MCSectionELF(CachedName, Type, Flags, Kind, EntrySize,
GroupSym, UniqueID, Begin, Associated);
Entry.second = Result;
return Result;
}
MCSectionELF *MCContext::createELFGroupSection(const MCSymbolELF *Group) {
MCSectionELF *Result = new (*this)
MCSectionELF(".group", ELF::SHT_GROUP, 0, SectionKind::getReadOnly(), 4,
Group, ~0, nullptr, nullptr);
return Result;
}
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
unsigned Characteristics,
SectionKind Kind,
StringRef COMDATSymName, int Selection,
const char *BeginSymName) {
MCSymbol *COMDATSymbol = nullptr;
if (!COMDATSymName.empty()) {
COMDATSymbol = getOrCreateSymbol(COMDATSymName);
COMDATSymName = COMDATSymbol->getName();
}
// Do the lookup, if we have a hit, return it.
COFFSectionKey T{Section, COMDATSymName, Selection};
auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
auto Iter = IterBool.first;
if (!IterBool.second)
return Iter->second;
MCSymbol *Begin = nullptr;
if (BeginSymName)
Begin = createTempSymbol(BeginSymName, false);
StringRef CachedName = Iter->first.SectionName;
MCSectionCOFF *Result = new (*this) MCSectionCOFF(
CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
Iter->second = Result;
return Result;
}
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
unsigned Characteristics,
SectionKind Kind,
const char *BeginSymName) {
return getCOFFSection(Section, Characteristics, Kind, "", 0, BeginSymName);
}
MCSectionCOFF *MCContext::getCOFFSection(StringRef Section) {
COFFSectionKey T{Section, "", 0};
auto Iter = COFFUniquingMap.find(T);
if (Iter == COFFUniquingMap.end())
return nullptr;
return Iter->second;
}
MCSectionCOFF *MCContext::getAssociativeCOFFSection(MCSectionCOFF *Sec,
const MCSymbol *KeySym) {
// Return the normal section if we don't have to be associative.
if (!KeySym)
return Sec;
// Make an associative section with the same name and kind as the normal
// section.
unsigned Characteristics =
Sec->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT;
return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(),
KeySym->getName(),
COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE);
}
//===----------------------------------------------------------------------===//
// Dwarf Management
//===----------------------------------------------------------------------===//
/// getDwarfFile - takes a file name an number to place in the dwarf file and
/// directory tables. If the file number has already been allocated it is an
/// error and zero is returned and the client reports the error, else the
/// allocated file number is returned. The file numbers may be in any order.
unsigned MCContext::getDwarfFile(StringRef Directory, StringRef FileName,
unsigned FileNumber, unsigned CUID) {
MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
return Table.getFile(Directory, FileName, FileNumber);
}
/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
/// currently is assigned and false otherwise.
bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles = getMCDwarfFiles(CUID);
if (FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
return false;
return !MCDwarfFiles[FileNumber].Name.empty();
}
/// Remove empty sections from SectionStartEndSyms, to avoid generating
/// useless debug info for them.
void MCContext::finalizeDwarfSections(MCStreamer &MCOS) {
SectionsForRanges.remove_if(
[&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
}
void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) const {
#if 0 // HLSL Change - analysis shows this isn't called on corruption but on paths with no recovery; unwind instead of terminating
// If we have a source manager and a location, use it. Otherwise just
// use the generic report_fatal_error().
if (!SrcMgr || Loc == SMLoc())
report_fatal_error(Msg, false);
// Use the source manager to print the message.
SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
// If we reached here, we are failing ungracefully. Run the interrupt handlers
// to make sure any special cleanups get done, in particular that we remove
// files registered with RemoveFileOnSignal.
sys::RunInterruptHandlers();
exit(1);
#else
throw std::exception();
#endif
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCAsmInfoDarwin.cpp | //===-- MCAsmInfoDarwin.cpp - Darwin asm properties -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines target asm properties related what form asm statements
// should take in general on Darwin-based targets
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmInfoDarwin.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCSectionMachO.h"
using namespace llvm;
bool MCAsmInfoDarwin::isSectionAtomizableBySymbols(
const MCSection &Section) const {
const MCSectionMachO &SMO = static_cast<const MCSectionMachO &>(Section);
// Sections holding 1 byte strings are atomized based on the data they
// contain.
// Sections holding 2 byte strings require symbols in order to be atomized.
// There is no dedicated section for 4 byte strings.
if (SMO.getType() == MachO::S_CSTRING_LITERALS)
return false;
if (SMO.getSegmentName() == "__DATA" && SMO.getSectionName() == "__cfstring")
return false;
if (SMO.getSegmentName() == "__DATA" &&
SMO.getSectionName() == "__objc_classrefs")
return false;
switch (SMO.getType()) {
default:
return true;
// These sections are atomized at the element boundaries without using
// symbols.
case MachO::S_4BYTE_LITERALS:
case MachO::S_8BYTE_LITERALS:
case MachO::S_16BYTE_LITERALS:
case MachO::S_LITERAL_POINTERS:
case MachO::S_NON_LAZY_SYMBOL_POINTERS:
case MachO::S_LAZY_SYMBOL_POINTERS:
case MachO::S_MOD_INIT_FUNC_POINTERS:
case MachO::S_MOD_TERM_FUNC_POINTERS:
case MachO::S_INTERPOSING:
return false;
}
}
MCAsmInfoDarwin::MCAsmInfoDarwin() {
// Common settings for all Darwin targets.
// Syntax:
LinkerPrivateGlobalPrefix = "l";
HasSingleParameterDotFile = false;
HasSubsectionsViaSymbols = true;
AlignmentIsInBytes = false;
COMMDirectiveAlignmentIsInBytes = false;
LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
InlineAsmStart = " InlineAsm Start";
InlineAsmEnd = " InlineAsm End";
// Directives:
HasWeakDefDirective = true;
HasWeakDefCanBeHiddenDirective = true;
WeakRefDirective = "\t.weak_reference ";
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
HasMachoZeroFillDirective = true; // Uses .zerofill
HasMachoTBSSDirective = true; // Uses .tbss
HasStaticCtorDtorReferenceInStaticMode = true;
// FIXME: Change this once MC is the system assembler.
HasAggressiveSymbolFolding = false;
HiddenVisibilityAttr = MCSA_PrivateExtern;
HiddenDeclarationVisibilityAttr = MCSA_Invalid;
// Doesn't support protected visibility.
ProtectedVisibilityAttr = MCSA_Invalid;
HasDotTypeDotSizeDirective = false;
HasNoDeadStrip = true;
DwarfUsesRelocationsAcrossSections = false;
UseIntegratedAssembler = true;
SetDirectiveSuppressesReloc = true;
// FIXME: For now keep the previous behavior, AShr, matching the previous
// behavior of as(1) (both -q and -Q: resp. LLVM and gas v1.38).
// If/when this changes, the AArch64 Darwin special case can go away.
UseLogicalShr = false;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCExpr.cpp | //===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCExpr.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "mcexpr"
namespace {
namespace stats {
STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations");
}
}
void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
switch (getKind()) {
case MCExpr::Target:
return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
case MCExpr::Constant:
OS << cast<MCConstantExpr>(*this).getValue();
return;
case MCExpr::SymbolRef: {
const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
const MCSymbol &Sym = SRE.getSymbol();
// Parenthesize names that start with $ so that they don't look like
// absolute names.
bool UseParens = Sym.getName()[0] == '$';
if (UseParens) {
OS << '(';
Sym.print(OS, MAI);
OS << ')';
} else
Sym.print(OS, MAI);
if (SRE.getKind() != MCSymbolRefExpr::VK_None)
SRE.printVariantKind(OS);
return;
}
case MCExpr::Unary: {
const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this);
switch (UE.getOpcode()) {
case MCUnaryExpr::LNot: OS << '!'; break;
case MCUnaryExpr::Minus: OS << '-'; break;
case MCUnaryExpr::Not: OS << '~'; break;
case MCUnaryExpr::Plus: OS << '+'; break;
}
UE.getSubExpr()->print(OS, MAI);
return;
}
case MCExpr::Binary: {
const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this);
// Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
BE.getLHS()->print(OS, MAI);
} else {
OS << '(';
BE.getLHS()->print(OS, MAI);
OS << ')';
}
switch (BE.getOpcode()) {
case MCBinaryExpr::Add:
// Print "X-42" instead of "X+-42".
if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) {
if (RHSC->getValue() < 0) {
OS << RHSC->getValue();
return;
}
}
OS << '+';
break;
case MCBinaryExpr::AShr: OS << ">>"; break;
case MCBinaryExpr::And: OS << '&'; break;
case MCBinaryExpr::Div: OS << '/'; break;
case MCBinaryExpr::EQ: OS << "=="; break;
case MCBinaryExpr::GT: OS << '>'; break;
case MCBinaryExpr::GTE: OS << ">="; break;
case MCBinaryExpr::LAnd: OS << "&&"; break;
case MCBinaryExpr::LOr: OS << "||"; break;
case MCBinaryExpr::LShr: OS << ">>"; break;
case MCBinaryExpr::LT: OS << '<'; break;
case MCBinaryExpr::LTE: OS << "<="; break;
case MCBinaryExpr::Mod: OS << '%'; break;
case MCBinaryExpr::Mul: OS << '*'; break;
case MCBinaryExpr::NE: OS << "!="; break;
case MCBinaryExpr::Or: OS << '|'; break;
case MCBinaryExpr::Shl: OS << "<<"; break;
case MCBinaryExpr::Sub: OS << '-'; break;
case MCBinaryExpr::Xor: OS << '^'; break;
}
// Only print parens around the LHS if it is non-trivial.
if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
BE.getRHS()->print(OS, MAI);
} else {
OS << '(';
BE.getRHS()->print(OS, MAI);
OS << ')';
}
return;
}
}
llvm_unreachable("Invalid expression kind!");
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void MCExpr::dump() const {
dbgs() << *this;
dbgs() << '\n';
}
#endif
/* *** */
const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,
const MCExpr *RHS, MCContext &Ctx) {
return new (Ctx) MCBinaryExpr(Opc, LHS, RHS);
}
const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
MCContext &Ctx) {
return new (Ctx) MCUnaryExpr(Opc, Expr);
}
const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {
return new (Ctx) MCConstantExpr(Value);
}
/* *** */
MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
const MCAsmInfo *MAI)
: MCExpr(MCExpr::SymbolRef), Kind(Kind),
UseParensForSymbolVariant(MAI->useParensForSymbolVariant()),
HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()),
Symbol(Symbol) {
assert(Symbol);
}
const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym,
VariantKind Kind,
MCContext &Ctx) {
return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo());
}
const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind,
MCContext &Ctx) {
return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
}
StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
switch (Kind) {
case VK_Invalid: return "<<invalid>>";
case VK_None: return "<<none>>";
case VK_GOT: return "GOT";
case VK_GOTOFF: return "GOTOFF";
case VK_GOTPCREL: return "GOTPCREL";
case VK_GOTTPOFF: return "GOTTPOFF";
case VK_INDNTPOFF: return "INDNTPOFF";
case VK_NTPOFF: return "NTPOFF";
case VK_GOTNTPOFF: return "GOTNTPOFF";
case VK_PLT: return "PLT";
case VK_TLSGD: return "TLSGD";
case VK_TLSLD: return "TLSLD";
case VK_TLSLDM: return "TLSLDM";
case VK_TPOFF: return "TPOFF";
case VK_DTPOFF: return "DTPOFF";
case VK_TLVP: return "TLVP";
case VK_TLVPPAGE: return "TLVPPAGE";
case VK_TLVPPAGEOFF: return "TLVPPAGEOFF";
case VK_PAGE: return "PAGE";
case VK_PAGEOFF: return "PAGEOFF";
case VK_GOTPAGE: return "GOTPAGE";
case VK_GOTPAGEOFF: return "GOTPAGEOFF";
case VK_SECREL: return "SECREL32";
case VK_SIZE: return "SIZE";
case VK_WEAKREF: return "WEAKREF";
case VK_ARM_NONE: return "none";
case VK_ARM_TARGET1: return "target1";
case VK_ARM_TARGET2: return "target2";
case VK_ARM_PREL31: return "prel31";
case VK_ARM_SBREL: return "sbrel";
case VK_ARM_TLSLDO: return "tlsldo";
case VK_ARM_TLSCALL: return "tlscall";
case VK_ARM_TLSDESC: return "tlsdesc";
case VK_ARM_TLSDESCSEQ: return "tlsdescseq";
case VK_PPC_LO: return "l";
case VK_PPC_HI: return "h";
case VK_PPC_HA: return "ha";
case VK_PPC_HIGHER: return "higher";
case VK_PPC_HIGHERA: return "highera";
case VK_PPC_HIGHEST: return "highest";
case VK_PPC_HIGHESTA: return "highesta";
case VK_PPC_GOT_LO: return "got@l";
case VK_PPC_GOT_HI: return "got@h";
case VK_PPC_GOT_HA: return "got@ha";
case VK_PPC_TOCBASE: return "tocbase";
case VK_PPC_TOC: return "toc";
case VK_PPC_TOC_LO: return "toc@l";
case VK_PPC_TOC_HI: return "toc@h";
case VK_PPC_TOC_HA: return "toc@ha";
case VK_PPC_DTPMOD: return "dtpmod";
case VK_PPC_TPREL: return "tprel";
case VK_PPC_TPREL_LO: return "tprel@l";
case VK_PPC_TPREL_HI: return "tprel@h";
case VK_PPC_TPREL_HA: return "tprel@ha";
case VK_PPC_TPREL_HIGHER: return "tprel@higher";
case VK_PPC_TPREL_HIGHERA: return "tprel@highera";
case VK_PPC_TPREL_HIGHEST: return "tprel@highest";
case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta";
case VK_PPC_DTPREL: return "dtprel";
case VK_PPC_DTPREL_LO: return "dtprel@l";
case VK_PPC_DTPREL_HI: return "dtprel@h";
case VK_PPC_DTPREL_HA: return "dtprel@ha";
case VK_PPC_DTPREL_HIGHER: return "dtprel@higher";
case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera";
case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest";
case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta";
case VK_PPC_GOT_TPREL: return "got@tprel";
case VK_PPC_GOT_TPREL_LO: return "got@tprel@l";
case VK_PPC_GOT_TPREL_HI: return "got@tprel@h";
case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha";
case VK_PPC_GOT_DTPREL: return "got@dtprel";
case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l";
case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h";
case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha";
case VK_PPC_TLS: return "tls";
case VK_PPC_GOT_TLSGD: return "got@tlsgd";
case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l";
case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h";
case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha";
case VK_PPC_TLSGD: return "tlsgd";
case VK_PPC_GOT_TLSLD: return "got@tlsld";
case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l";
case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h";
case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha";
case VK_PPC_TLSLD: return "tlsld";
case VK_PPC_LOCAL: return "local";
case VK_Mips_GPREL: return "GPREL";
case VK_Mips_GOT_CALL: return "GOT_CALL";
case VK_Mips_GOT16: return "GOT16";
case VK_Mips_GOT: return "GOT";
case VK_Mips_ABS_HI: return "ABS_HI";
case VK_Mips_ABS_LO: return "ABS_LO";
case VK_Mips_TLSGD: return "TLSGD";
case VK_Mips_TLSLDM: return "TLSLDM";
case VK_Mips_DTPREL_HI: return "DTPREL_HI";
case VK_Mips_DTPREL_LO: return "DTPREL_LO";
case VK_Mips_GOTTPREL: return "GOTTPREL";
case VK_Mips_TPREL_HI: return "TPREL_HI";
case VK_Mips_TPREL_LO: return "TPREL_LO";
case VK_Mips_GPOFF_HI: return "GPOFF_HI";
case VK_Mips_GPOFF_LO: return "GPOFF_LO";
case VK_Mips_GOT_DISP: return "GOT_DISP";
case VK_Mips_GOT_PAGE: return "GOT_PAGE";
case VK_Mips_GOT_OFST: return "GOT_OFST";
case VK_Mips_HIGHER: return "HIGHER";
case VK_Mips_HIGHEST: return "HIGHEST";
case VK_Mips_GOT_HI16: return "GOT_HI16";
case VK_Mips_GOT_LO16: return "GOT_LO16";
case VK_Mips_CALL_HI16: return "CALL_HI16";
case VK_Mips_CALL_LO16: return "CALL_LO16";
case VK_Mips_PCREL_HI16: return "PCREL_HI16";
case VK_Mips_PCREL_LO16: return "PCREL_LO16";
case VK_COFF_IMGREL32: return "IMGREL";
case VK_Hexagon_PCREL: return "PCREL";
case VK_Hexagon_LO16: return "LO16";
case VK_Hexagon_HI16: return "HI16";
case VK_Hexagon_GPREL: return "GPREL";
case VK_Hexagon_GD_GOT: return "GDGOT";
case VK_Hexagon_LD_GOT: return "LDGOT";
case VK_Hexagon_GD_PLT: return "GDPLT";
case VK_Hexagon_LD_PLT: return "LDPLT";
case VK_Hexagon_IE: return "IE";
case VK_Hexagon_IE_GOT: return "IEGOT";
case VK_TPREL: return "tprel";
case VK_DTPREL: return "dtprel";
}
llvm_unreachable("Invalid variant kind");
}
MCSymbolRefExpr::VariantKind
MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
return StringSwitch<VariantKind>(Name.lower())
.Case("got", VK_GOT)
.Case("gotoff", VK_GOTOFF)
.Case("gotpcrel", VK_GOTPCREL)
.Case("got_prel", VK_GOTPCREL)
.Case("gottpoff", VK_GOTTPOFF)
.Case("indntpoff", VK_INDNTPOFF)
.Case("ntpoff", VK_NTPOFF)
.Case("gotntpoff", VK_GOTNTPOFF)
.Case("plt", VK_PLT)
.Case("tlsgd", VK_TLSGD)
.Case("tlsld", VK_TLSLD)
.Case("tlsldm", VK_TLSLDM)
.Case("tpoff", VK_TPOFF)
.Case("dtpoff", VK_DTPOFF)
.Case("tlvp", VK_TLVP)
.Case("tlvppage", VK_TLVPPAGE)
.Case("tlvppageoff", VK_TLVPPAGEOFF)
.Case("page", VK_PAGE)
.Case("pageoff", VK_PAGEOFF)
.Case("gotpage", VK_GOTPAGE)
.Case("gotpageoff", VK_GOTPAGEOFF)
.Case("imgrel", VK_COFF_IMGREL32)
.Case("secrel32", VK_SECREL)
.Case("size", VK_SIZE)
.Case("l", VK_PPC_LO)
.Case("h", VK_PPC_HI)
.Case("ha", VK_PPC_HA)
.Case("higher", VK_PPC_HIGHER)
.Case("highera", VK_PPC_HIGHERA)
.Case("highest", VK_PPC_HIGHEST)
.Case("highesta", VK_PPC_HIGHESTA)
.Case("got@l", VK_PPC_GOT_LO)
.Case("got@h", VK_PPC_GOT_HI)
.Case("got@ha", VK_PPC_GOT_HA)
.Case("local", VK_PPC_LOCAL)
.Case("tocbase", VK_PPC_TOCBASE)
.Case("toc", VK_PPC_TOC)
.Case("toc@l", VK_PPC_TOC_LO)
.Case("toc@h", VK_PPC_TOC_HI)
.Case("toc@ha", VK_PPC_TOC_HA)
.Case("tls", VK_PPC_TLS)
.Case("dtpmod", VK_PPC_DTPMOD)
.Case("tprel", VK_PPC_TPREL)
.Case("tprel@l", VK_PPC_TPREL_LO)
.Case("tprel@h", VK_PPC_TPREL_HI)
.Case("tprel@ha", VK_PPC_TPREL_HA)
.Case("tprel@higher", VK_PPC_TPREL_HIGHER)
.Case("tprel@highera", VK_PPC_TPREL_HIGHERA)
.Case("tprel@highest", VK_PPC_TPREL_HIGHEST)
.Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA)
.Case("dtprel", VK_PPC_DTPREL)
.Case("dtprel@l", VK_PPC_DTPREL_LO)
.Case("dtprel@h", VK_PPC_DTPREL_HI)
.Case("dtprel@ha", VK_PPC_DTPREL_HA)
.Case("dtprel@higher", VK_PPC_DTPREL_HIGHER)
.Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA)
.Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST)
.Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA)
.Case("got@tprel", VK_PPC_GOT_TPREL)
.Case("got@tprel@l", VK_PPC_GOT_TPREL_LO)
.Case("got@tprel@h", VK_PPC_GOT_TPREL_HI)
.Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA)
.Case("got@dtprel", VK_PPC_GOT_DTPREL)
.Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO)
.Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI)
.Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA)
.Case("got@tlsgd", VK_PPC_GOT_TLSGD)
.Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO)
.Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI)
.Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
.Case("got@tlsld", VK_PPC_GOT_TLSLD)
.Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO)
.Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI)
.Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA)
.Case("none", VK_ARM_NONE)
.Case("target1", VK_ARM_TARGET1)
.Case("target2", VK_ARM_TARGET2)
.Case("prel31", VK_ARM_PREL31)
.Case("sbrel", VK_ARM_SBREL)
.Case("tlsldo", VK_ARM_TLSLDO)
.Case("tlscall", VK_ARM_TLSCALL)
.Case("tlsdesc", VK_ARM_TLSDESC)
.Default(VK_Invalid);
}
void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const {
if (UseParensForSymbolVariant)
OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')';
else
OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind());
}
/* *** */
void MCTargetExpr::anchor() {}
/* *** */
bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res,
const MCAsmLayout &Layout) const {
return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res,
const MCAsmLayout &Layout,
const SectionAddrMap &Addrs) const {
return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
}
bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
const MCAsmLayout &Layout) const {
return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
true);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs) const {
// FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
// absolutize differences across sections and that is what the MachO writer
// uses Addrs for.
return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs);
}
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const SectionAddrMap *Addrs, bool InSet) const {
MCValue Value;
// Fast path constants.
if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) {
Res = CE->getValue();
return true;
}
bool IsRelocatable =
evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
// Record the current value.
Res = Value.getConstant();
return IsRelocatable && Value.isAbsolute();
}
/// \brief Helper method for \see EvaluateSymbolAdd().
static void AttemptToFoldSymbolOffsetDifference(
const MCAssembler *Asm, const MCAsmLayout *Layout,
const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
const MCSymbolRefExpr *&B, int64_t &Addend) {
if (!A || !B)
return;
const MCSymbol &SA = A->getSymbol();
const MCSymbol &SB = B->getSymbol();
if (SA.isUndefined() || SB.isUndefined())
return;
if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
return;
if (SA.getFragment() == SB.getFragment()) {
Addend += (SA.getOffset() - SB.getOffset());
// Pointers to Thumb symbols need to have their low-bit set to allow
// for interworking.
if (Asm->isThumbFunc(&SA))
Addend |= 1;
// Clear the symbol expr pointers to indicate we have folded these
// operands.
A = B = nullptr;
return;
}
if (!Layout)
return;
const MCSection &SecA = *SA.getFragment()->getParent();
const MCSection &SecB = *SB.getFragment()->getParent();
if ((&SecA != &SecB) && !Addrs)
return;
// Eagerly evaluate.
Addend += Layout->getSymbolOffset(A->getSymbol()) -
Layout->getSymbolOffset(B->getSymbol());
if (Addrs && (&SecA != &SecB))
Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
// Pointers to Thumb symbols need to have their low-bit set to allow
// for interworking.
if (Asm->isThumbFunc(&SA))
Addend |= 1;
// Clear the symbol expr pointers to indicate we have folded these
// operands.
A = B = nullptr;
}
/// \brief Evaluate the result of an add between (conceptually) two MCValues.
///
/// This routine conceptually attempts to construct an MCValue:
/// Result = (Result_A - Result_B + Result_Cst)
/// from two MCValue's LHS and RHS where
/// Result = LHS + RHS
/// and
/// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
///
/// This routine attempts to aggresively fold the operands such that the result
/// is representable in an MCValue, but may not always succeed.
///
/// \returns True on success, false if the result is not representable in an
/// MCValue.
/// NOTE: It is really important to have both the Asm and Layout arguments.
/// They might look redundant, but this function can be used before layout
/// is done (see the object streamer for example) and having the Asm argument
/// lets us avoid relaxations early.
static bool
EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS,
const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B,
int64_t RHS_Cst, MCValue &Res) {
// FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
// about dealing with modifiers. This will ultimately bite us, one day.
const MCSymbolRefExpr *LHS_A = LHS.getSymA();
const MCSymbolRefExpr *LHS_B = LHS.getSymB();
int64_t LHS_Cst = LHS.getConstant();
// Fold the result constant immediately.
int64_t Result_Cst = LHS_Cst + RHS_Cst;
assert((!Layout || Asm) &&
"Must have an assembler object if layout is given!");
// If we have a layout, we can fold resolved differences.
if (Asm) {
// First, fold out any differences which are fully resolved. By
// reassociating terms in
// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
// we have the four possible differences:
// (LHS_A - LHS_B),
// (LHS_A - RHS_B),
// (RHS_A - LHS_B),
// (RHS_A - RHS_B).
// Since we are attempting to be as aggressive as possible about folding, we
// attempt to evaluate each possible alternative.
AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
Result_Cst);
AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
Result_Cst);
AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
Result_Cst);
AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
Result_Cst);
}
// We can't represent the addition or subtraction of two symbols.
if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
return false;
// At this point, we have at most one additive symbol and one subtractive
// symbol -- find them.
const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
// If we have a negated symbol, then we must have also have a non-negated
// symbol in order to encode the expression.
if (B && !A)
return false;
Res = MCValue::get(A, B, Result_Cst);
return true;
}
bool MCExpr::evaluateAsRelocatable(MCValue &Res,
const MCAsmLayout *Layout,
const MCFixup *Fixup) const {
MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
false);
}
bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
MCAssembler *Assembler = &Layout.getAssembler();
return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
true);
}
static bool canExpand(const MCSymbol &Sym, const MCAssembler *Asm, bool InSet) {
const MCExpr *Expr = Sym.getVariableValue();
const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
if (Inner) {
if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
return false;
}
if (InSet)
return true;
if (!Asm)
return false;
return !Asm->getWriter().isWeak(Sym);
}
bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const MCFixup *Fixup,
const SectionAddrMap *Addrs,
bool InSet) const {
++stats::MCExprEvaluate;
switch (getKind()) {
case Target:
return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout,
Fixup);
case Constant:
Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
return true;
case SymbolRef: {
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
const MCSymbol &Sym = SRE->getSymbol();
// Evaluate recursively if this is a variable.
if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
canExpand(Sym, Asm, InSet)) {
bool IsMachO = SRE->hasSubsectionsViaSymbols();
if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
if (!IsMachO)
return true;
const MCSymbolRefExpr *A = Res.getSymA();
const MCSymbolRefExpr *B = Res.getSymB();
// FIXME: This is small hack. Given
// a = b + 4
// .long a
// the OS X assembler will completely drop the 4. We should probably
// include it in the relocation or produce an error if that is not
// possible.
if (!A && !B)
return true;
}
}
Res = MCValue::get(SRE, nullptr, 0);
return true;
}
case Unary: {
const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
MCValue Value;
if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
Addrs, InSet))
return false;
switch (AUE->getOpcode()) {
case MCUnaryExpr::LNot:
if (!Value.isAbsolute())
return false;
Res = MCValue::get(!Value.getConstant());
break;
case MCUnaryExpr::Minus:
/// -(a - b + const) ==> (b - a - const)
if (Value.getSymA() && !Value.getSymB())
return false;
Res = MCValue::get(Value.getSymB(), Value.getSymA(),
-Value.getConstant());
break;
case MCUnaryExpr::Not:
if (!Value.isAbsolute())
return false;
Res = MCValue::get(~Value.getConstant());
break;
case MCUnaryExpr::Plus:
Res = Value;
break;
}
return true;
}
case Binary: {
const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
MCValue LHSValue, RHSValue;
if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
Addrs, InSet) ||
!ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
Addrs, InSet))
return false;
// We only support a few operations on non-constant expressions, handle
// those first.
if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
switch (ABE->getOpcode()) {
default:
return false;
case MCBinaryExpr::Sub:
// Negate RHS and add.
return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
RHSValue.getSymB(), RHSValue.getSymA(),
-RHSValue.getConstant(), Res);
case MCBinaryExpr::Add:
return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
RHSValue.getSymA(), RHSValue.getSymB(),
RHSValue.getConstant(), Res);
}
}
// FIXME: We need target hooks for the evaluation. It may be limited in
// width, and gas defines the result of comparisons differently from
// Apple as.
int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
int64_t Result = 0;
switch (ABE->getOpcode()) {
case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
case MCBinaryExpr::Add: Result = LHS + RHS; break;
case MCBinaryExpr::And: Result = LHS & RHS; break;
case MCBinaryExpr::Div: Result = LHS / RHS; break;
case MCBinaryExpr::EQ: Result = LHS == RHS; break;
case MCBinaryExpr::GT: Result = LHS > RHS; break;
case MCBinaryExpr::GTE: Result = LHS >= RHS; break;
case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
case MCBinaryExpr::LOr: Result = LHS || RHS; break;
case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
case MCBinaryExpr::LT: Result = LHS < RHS; break;
case MCBinaryExpr::LTE: Result = LHS <= RHS; break;
case MCBinaryExpr::Mod: Result = LHS % RHS; break;
case MCBinaryExpr::Mul: Result = LHS * RHS; break;
case MCBinaryExpr::NE: Result = LHS != RHS; break;
case MCBinaryExpr::Or: Result = LHS | RHS; break;
case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break;
case MCBinaryExpr::Sub: Result = LHS - RHS; break;
case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
}
Res = MCValue::get(Result);
return true;
}
}
llvm_unreachable("Invalid assembly expression kind!");
}
MCSection *MCExpr::findAssociatedSection() const {
switch (getKind()) {
case Target:
// We never look through target specific expressions.
return cast<MCTargetExpr>(this)->findAssociatedSection();
case Constant:
return MCSymbol::AbsolutePseudoSection;
case SymbolRef: {
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
const MCSymbol &Sym = SRE->getSymbol();
if (Sym.isDefined())
return &Sym.getSection();
return nullptr;
}
case Unary:
return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedSection();
case Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
MCSection *LHS_S = BE->getLHS()->findAssociatedSection();
MCSection *RHS_S = BE->getRHS()->findAssociatedSection();
// If either section is absolute, return the other.
if (LHS_S == MCSymbol::AbsolutePseudoSection)
return RHS_S;
if (RHS_S == MCSymbol::AbsolutePseudoSection)
return LHS_S;
// Not always correct, but probably the best we can do without more context.
if (BE->getOpcode() == MCBinaryExpr::Sub)
return MCSymbol::AbsolutePseudoSection;
// Otherwise, return the first non-null section.
return LHS_S ? LHS_S : RHS_S;
}
}
llvm_unreachable("Invalid assembly expression kind!");
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCAsmInfoELF.cpp | //===-- MCAsmInfoELF.cpp - ELF asm properties -------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines target asm properties related what form asm statements
// should take in general on ELF-based targets
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmInfoELF.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/Support/ELF.h"
using namespace llvm;
void MCAsmInfoELF::anchor() { }
MCSection *MCAsmInfoELF::getNonexecutableStackSection(MCContext &Ctx) const {
return Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0);
}
MCAsmInfoELF::MCAsmInfoELF() {
HasIdentDirective = true;
WeakRefDirective = "\t.weak\t";
PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = ".L";
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCCodeEmitter.cpp | //===-- MCCodeEmitter.cpp - Instruction Encoding --------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCCodeEmitter.h"
using namespace llvm;
MCCodeEmitter::MCCodeEmitter() {
}
MCCodeEmitter::~MCCodeEmitter() {
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCWin64EH.cpp | //===- lib/MC/MCWin64EH.cpp - MCWin64EH implementation --------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCWin64EH.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Win64EH.h"
namespace llvm {
// NOTE: All relocations generated here are 4-byte image-relative.
static uint8_t CountOfUnwindCodes(std::vector<WinEH::Instruction> &Insns) {
uint8_t Count = 0;
for (const auto &I : Insns) {
switch (static_cast<Win64EH::UnwindOpcodes>(I.Operation)) {
case Win64EH::UOP_PushNonVol:
case Win64EH::UOP_AllocSmall:
case Win64EH::UOP_SetFPReg:
case Win64EH::UOP_PushMachFrame:
Count += 1;
break;
case Win64EH::UOP_SaveNonVol:
case Win64EH::UOP_SaveXMM128:
Count += 2;
break;
case Win64EH::UOP_SaveNonVolBig:
case Win64EH::UOP_SaveXMM128Big:
Count += 3;
break;
case Win64EH::UOP_AllocLarge:
Count += (I.Offset > 512 * 1024 - 8) ? 3 : 2;
break;
}
}
return Count;
}
static void EmitAbsDifference(MCStreamer &Streamer, const MCSymbol *LHS,
const MCSymbol *RHS) {
MCContext &Context = Streamer.getContext();
const MCExpr *Diff =
MCBinaryExpr::createSub(MCSymbolRefExpr::create(LHS, Context),
MCSymbolRefExpr::create(RHS, Context), Context);
Streamer.EmitValue(Diff, 1);
}
static void EmitUnwindCode(MCStreamer &streamer, const MCSymbol *begin,
WinEH::Instruction &inst) {
uint8_t b2;
uint16_t w;
b2 = (inst.Operation & 0x0F);
switch (static_cast<Win64EH::UnwindOpcodes>(inst.Operation)) {
case Win64EH::UOP_PushNonVol:
EmitAbsDifference(streamer, inst.Label, begin);
b2 |= (inst.Register & 0x0F) << 4;
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_AllocLarge:
EmitAbsDifference(streamer, inst.Label, begin);
if (inst.Offset > 512 * 1024 - 8) {
b2 |= 0x10;
streamer.EmitIntValue(b2, 1);
w = inst.Offset & 0xFFF8;
streamer.EmitIntValue(w, 2);
w = inst.Offset >> 16;
} else {
streamer.EmitIntValue(b2, 1);
w = inst.Offset >> 3;
}
streamer.EmitIntValue(w, 2);
break;
case Win64EH::UOP_AllocSmall:
b2 |= (((inst.Offset - 8) >> 3) & 0x0F) << 4;
EmitAbsDifference(streamer, inst.Label, begin);
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_SetFPReg:
EmitAbsDifference(streamer, inst.Label, begin);
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_SaveNonVol:
case Win64EH::UOP_SaveXMM128:
b2 |= (inst.Register & 0x0F) << 4;
EmitAbsDifference(streamer, inst.Label, begin);
streamer.EmitIntValue(b2, 1);
w = inst.Offset >> 3;
if (inst.Operation == Win64EH::UOP_SaveXMM128)
w >>= 1;
streamer.EmitIntValue(w, 2);
break;
case Win64EH::UOP_SaveNonVolBig:
case Win64EH::UOP_SaveXMM128Big:
b2 |= (inst.Register & 0x0F) << 4;
EmitAbsDifference(streamer, inst.Label, begin);
streamer.EmitIntValue(b2, 1);
if (inst.Operation == Win64EH::UOP_SaveXMM128Big)
w = inst.Offset & 0xFFF0;
else
w = inst.Offset & 0xFFF8;
streamer.EmitIntValue(w, 2);
w = inst.Offset >> 16;
streamer.EmitIntValue(w, 2);
break;
case Win64EH::UOP_PushMachFrame:
if (inst.Offset == 1)
b2 |= 0x10;
EmitAbsDifference(streamer, inst.Label, begin);
streamer.EmitIntValue(b2, 1);
break;
}
}
static void EmitSymbolRefWithOfs(MCStreamer &streamer,
const MCSymbol *Base,
const MCSymbol *Other) {
MCContext &Context = streamer.getContext();
const MCSymbolRefExpr *BaseRef = MCSymbolRefExpr::create(Base, Context);
const MCSymbolRefExpr *OtherRef = MCSymbolRefExpr::create(Other, Context);
const MCExpr *Ofs = MCBinaryExpr::createSub(OtherRef, BaseRef, Context);
const MCSymbolRefExpr *BaseRefRel = MCSymbolRefExpr::create(Base,
MCSymbolRefExpr::VK_COFF_IMGREL32,
Context);
streamer.EmitValue(MCBinaryExpr::createAdd(BaseRefRel, Ofs, Context), 4);
}
static void EmitRuntimeFunction(MCStreamer &streamer,
const WinEH::FrameInfo *info) {
MCContext &context = streamer.getContext();
streamer.EmitValueToAlignment(4);
EmitSymbolRefWithOfs(streamer, info->Function, info->Begin);
EmitSymbolRefWithOfs(streamer, info->Function, info->End);
streamer.EmitValue(MCSymbolRefExpr::create(info->Symbol,
MCSymbolRefExpr::VK_COFF_IMGREL32,
context), 4);
}
static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
// If this UNWIND_INFO already has a symbol, it's already been emitted.
if (info->Symbol)
return;
MCContext &context = streamer.getContext();
MCSymbol *Label = context.createTempSymbol();
streamer.EmitValueToAlignment(4);
streamer.EmitLabel(Label);
info->Symbol = Label;
// Upper 3 bits are the version number (currently 1).
uint8_t flags = 0x01;
if (info->ChainedParent)
flags |= Win64EH::UNW_ChainInfo << 3;
else {
if (info->HandlesUnwind)
flags |= Win64EH::UNW_TerminateHandler << 3;
if (info->HandlesExceptions)
flags |= Win64EH::UNW_ExceptionHandler << 3;
}
streamer.EmitIntValue(flags, 1);
if (info->PrologEnd)
EmitAbsDifference(streamer, info->PrologEnd, info->Begin);
else
streamer.EmitIntValue(0, 1);
uint8_t numCodes = CountOfUnwindCodes(info->Instructions);
streamer.EmitIntValue(numCodes, 1);
uint8_t frame = 0;
if (info->LastFrameInst >= 0) {
WinEH::Instruction &frameInst = info->Instructions[info->LastFrameInst];
assert(frameInst.Operation == Win64EH::UOP_SetFPReg);
frame = (frameInst.Register & 0x0F) | (frameInst.Offset & 0xF0);
}
streamer.EmitIntValue(frame, 1);
// Emit unwind instructions (in reverse order).
uint8_t numInst = info->Instructions.size();
for (uint8_t c = 0; c < numInst; ++c) {
WinEH::Instruction inst = info->Instructions.back();
info->Instructions.pop_back();
EmitUnwindCode(streamer, info->Begin, inst);
}
// For alignment purposes, the instruction array will always have an even
// number of entries, with the final entry potentially unused (in which case
// the array will be one longer than indicated by the count of unwind codes
// field).
if (numCodes & 1) {
streamer.EmitIntValue(0, 2);
}
if (flags & (Win64EH::UNW_ChainInfo << 3))
EmitRuntimeFunction(streamer, info->ChainedParent);
else if (flags &
((Win64EH::UNW_TerminateHandler|Win64EH::UNW_ExceptionHandler) << 3))
streamer.EmitValue(MCSymbolRefExpr::create(info->ExceptionHandler,
MCSymbolRefExpr::VK_COFF_IMGREL32,
context), 4);
else if (numCodes == 0) {
// The minimum size of an UNWIND_INFO struct is 8 bytes. If we're not
// a chained unwind info, if there is no handler, and if there are fewer
// than 2 slots used in the unwind code array, we have to pad to 8 bytes.
streamer.EmitIntValue(0, 4);
}
}
namespace Win64EH {
void UnwindEmitter::Emit(MCStreamer &Streamer) const {
MCContext &Context = Streamer.getContext();
// Emit the unwind info structs first.
for (const auto &CFI : Streamer.getWinFrameInfos()) {
MCSection *XData = getXDataSection(CFI->Function, Context);
Streamer.SwitchSection(XData);
EmitUnwindInfo(Streamer, CFI);
}
// Now emit RUNTIME_FUNCTION entries.
for (const auto &CFI : Streamer.getWinFrameInfos()) {
MCSection *PData = getPDataSection(CFI->Function, Context);
Streamer.SwitchSection(PData);
EmitRuntimeFunction(Streamer, CFI);
}
}
void UnwindEmitter::EmitUnwindInfo(MCStreamer &Streamer,
WinEH::FrameInfo *info) const {
// Switch sections (the static function above is meant to be called from
// here and from Emit().
MCContext &context = Streamer.getContext();
MCSection *xdataSect = getXDataSection(info->Function, context);
Streamer.SwitchSection(xdataSect);
llvm::EmitUnwindInfo(Streamer, info);
}
}
} // End of namespace llvm
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCObjectFileInfo.cpp | //===-- MObjectFileInfo.cpp - Object File Information ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
using namespace llvm;
static bool useCompactUnwind(const Triple &T) {
// Only on darwin.
if (!T.isOSDarwin())
return false;
// aarch64 always has it.
if (T.getArch() == Triple::aarch64)
return true;
// Use it on newer version of OS X.
if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))
return true;
// And the iOS simulator.
if (T.isiOS() &&
(T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86))
return true;
return false;
}
void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
// MachO
SupportsWeakOmittedEHFrame = false;
if (T.isOSDarwin() && T.getArch() == Triple::aarch64)
SupportsCompactUnwindWithoutEHFrame = true;
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel
| dwarf::DW_EH_PE_sdata4;
LSDAEncoding = FDECFIEncoding = dwarf::DW_EH_PE_pcrel;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
// .comm doesn't support alignment before Leopard.
if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5))
CommDirectiveSupportsAlignment = false;
TextSection // .text
= Ctx->getMachOSection("__TEXT", "__text",
MachO::S_ATTR_PURE_INSTRUCTIONS,
SectionKind::getText());
DataSection // .data
= Ctx->getMachOSection("__DATA", "__data", 0,
SectionKind::getDataRel());
// BSSSection might not be expected initialized on msvc.
BSSSection = nullptr;
TLSDataSection // .tdata
= Ctx->getMachOSection("__DATA", "__thread_data",
MachO::S_THREAD_LOCAL_REGULAR,
SectionKind::getDataRel());
TLSBSSSection // .tbss
= Ctx->getMachOSection("__DATA", "__thread_bss",
MachO::S_THREAD_LOCAL_ZEROFILL,
SectionKind::getThreadBSS());
// TODO: Verify datarel below.
TLSTLVSection // .tlv
= Ctx->getMachOSection("__DATA", "__thread_vars",
MachO::S_THREAD_LOCAL_VARIABLES,
SectionKind::getDataRel());
TLSThreadInitSection
= Ctx->getMachOSection("__DATA", "__thread_init",
MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,
SectionKind::getDataRel());
CStringSection // .cstring
= Ctx->getMachOSection("__TEXT", "__cstring",
MachO::S_CSTRING_LITERALS,
SectionKind::getMergeable1ByteCString());
UStringSection
= Ctx->getMachOSection("__TEXT","__ustring", 0,
SectionKind::getMergeable2ByteCString());
FourByteConstantSection // .literal4
= Ctx->getMachOSection("__TEXT", "__literal4",
MachO::S_4BYTE_LITERALS,
SectionKind::getMergeableConst4());
EightByteConstantSection // .literal8
= Ctx->getMachOSection("__TEXT", "__literal8",
MachO::S_8BYTE_LITERALS,
SectionKind::getMergeableConst8());
SixteenByteConstantSection // .literal16
= Ctx->getMachOSection("__TEXT", "__literal16",
MachO::S_16BYTE_LITERALS,
SectionKind::getMergeableConst16());
ReadOnlySection // .const
= Ctx->getMachOSection("__TEXT", "__const", 0,
SectionKind::getReadOnly());
TextCoalSection
= Ctx->getMachOSection("__TEXT", "__textcoal_nt",
MachO::S_COALESCED |
MachO::S_ATTR_PURE_INSTRUCTIONS,
SectionKind::getText());
ConstTextCoalSection
= Ctx->getMachOSection("__TEXT", "__const_coal",
MachO::S_COALESCED,
SectionKind::getReadOnly());
ConstDataSection // .const_data
= Ctx->getMachOSection("__DATA", "__const", 0,
SectionKind::getReadOnlyWithRel());
DataCoalSection
= Ctx->getMachOSection("__DATA","__datacoal_nt",
MachO::S_COALESCED,
SectionKind::getDataRel());
DataCommonSection
= Ctx->getMachOSection("__DATA","__common",
MachO::S_ZEROFILL,
SectionKind::getBSS());
DataBSSSection
= Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,
SectionKind::getBSS());
LazySymbolPointerSection
= Ctx->getMachOSection("__DATA", "__la_symbol_ptr",
MachO::S_LAZY_SYMBOL_POINTERS,
SectionKind::getMetadata());
NonLazySymbolPointerSection
= Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",
MachO::S_NON_LAZY_SYMBOL_POINTERS,
SectionKind::getMetadata());
if (RelocM == Reloc::Static) {
StaticCtorSection
= Ctx->getMachOSection("__TEXT", "__constructor", 0,
SectionKind::getDataRel());
StaticDtorSection
= Ctx->getMachOSection("__TEXT", "__destructor", 0,
SectionKind::getDataRel());
} else {
StaticCtorSection
= Ctx->getMachOSection("__DATA", "__mod_init_func",
MachO::S_MOD_INIT_FUNC_POINTERS,
SectionKind::getDataRel());
StaticDtorSection
= Ctx->getMachOSection("__DATA", "__mod_term_func",
MachO::S_MOD_TERM_FUNC_POINTERS,
SectionKind::getDataRel());
}
// Exception Handling.
LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
SectionKind::getReadOnlyWithRel());
COFFDebugSymbolsSection = nullptr;
if (useCompactUnwind(T)) {
CompactUnwindSection =
Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,
SectionKind::getReadOnly());
if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::x86)
CompactUnwindDwarfEHFrameOnly = 0x04000000;
else if (T.getArch() == Triple::aarch64)
CompactUnwindDwarfEHFrameOnly = 0x03000000;
}
// Debug Information.
DwarfAccelNamesSection =
Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "names_begin");
DwarfAccelObjCSection =
Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "objc_begin");
// 16 character section limit...
DwarfAccelNamespaceSection =
Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "namespac_begin");
DwarfAccelTypesSection =
Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "types_begin");
DwarfAbbrevSection =
Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "section_abbrev");
DwarfInfoSection =
Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "section_info");
DwarfLineSection =
Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "section_line");
DwarfFrameSection =
Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfPubNamesSection =
Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfPubTypesSection =
Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfGnuPubNamesSection =
Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfGnuPubTypesSection =
Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfStrSection =
Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "info_string");
DwarfLocSection =
Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "section_debug_loc");
DwarfARangesSection =
Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
DwarfRangesSection =
Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata(), "debug_range");
DwarfDebugInlineSection =
Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
0, SectionKind::getMetadata());
FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",
0, SectionKind::getMetadata());
TLSExtraDataSection = TLSTLVSection;
}
void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
switch (T.getArch()) {
case Triple::mips:
case Triple::mipsel:
FDECFIEncoding = dwarf::DW_EH_PE_sdata4;
break;
case Triple::mips64:
case Triple::mips64el:
FDECFIEncoding = dwarf::DW_EH_PE_sdata8;
break;
case Triple::x86_64:
FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
: dwarf::DW_EH_PE_sdata4);
break;
default:
FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
break;
}
switch (T.getArch()) {
case Triple::arm:
case Triple::armeb:
case Triple::thumb:
case Triple::thumbeb:
if (Ctx->getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
break;
// Fallthrough if not using EHABI
case Triple::ppc:
case Triple::x86:
PersonalityEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
LSDAEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
TTypeEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
break;
case Triple::x86_64:
if (RelocM == Reloc::PIC_) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
LSDAEncoding = dwarf::DW_EH_PE_pcrel |
(CMModel == CodeModel::Small
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
} else {
PersonalityEncoding =
(CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
LSDAEncoding = (CMModel == CodeModel::Small)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
TTypeEncoding = (CMModel == CodeModel::Small)
? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
}
break;
case Triple::aarch64:
case Triple::aarch64_be:
// The small model guarantees static code/data size < 4GB, but not where it
// will be in memory. Most of these could end up >2GB away so even a signed
// pc-relative 32-bit address is insufficient, theoretically.
if (RelocM == Reloc::PIC_) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata8;
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata8;
} else {
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
LSDAEncoding = dwarf::DW_EH_PE_absptr;
TTypeEncoding = dwarf::DW_EH_PE_absptr;
}
break;
case Triple::mips:
case Triple::mipsel:
case Triple::mips64:
case Triple::mips64el:
// MIPS uses indirect pointer to refer personality functions and types, so
// that the eh_frame section can be read-only. DW.ref.personality will be
// generated for relocation.
PersonalityEncoding = dwarf::DW_EH_PE_indirect;
// FIXME: The N64 ABI probably ought to use DW_EH_PE_sdata8 but we can't
// identify N64 from just a triple.
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
// We don't support PC-relative LSDA references in GAS so we use the default
// DW_EH_PE_absptr for those.
break;
case Triple::ppc64:
case Triple::ppc64le:
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_udata8;
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_udata8;
break;
case Triple::sparcel:
case Triple::sparc:
if (RelocM == Reloc::PIC_) {
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
} else {
LSDAEncoding = dwarf::DW_EH_PE_absptr;
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
TTypeEncoding = dwarf::DW_EH_PE_absptr;
}
break;
case Triple::sparcv9:
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
if (RelocM == Reloc::PIC_) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
} else {
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
TTypeEncoding = dwarf::DW_EH_PE_absptr;
}
break;
case Triple::systemz:
// All currently-defined code models guarantee that 4-byte PC-relative
// values will be in range.
if (RelocM == Reloc::PIC_) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
} else {
PersonalityEncoding = dwarf::DW_EH_PE_absptr;
LSDAEncoding = dwarf::DW_EH_PE_absptr;
TTypeEncoding = dwarf::DW_EH_PE_absptr;
}
break;
default:
break;
}
// Solaris requires different flags for .eh_frame to seemingly every other
// platform.
EHSectionType = ELF::SHT_PROGBITS;
EHSectionFlags = ELF::SHF_ALLOC;
if (T.isOSSolaris()) {
if (T.getArch() == Triple::x86_64)
EHSectionType = ELF::SHT_X86_64_UNWIND;
else
EHSectionFlags |= ELF::SHF_WRITE;
}
// ELF
BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,
ELF::SHF_WRITE | ELF::SHF_ALLOC);
TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,
ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);
DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,
ELF::SHF_WRITE | ELF::SHF_ALLOC);
ReadOnlySection =
Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
TLSDataSection =
Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
TLSBSSSection = Ctx->getELFSection(
".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);
DataRelSection = Ctx->getELFSection(".data.rel", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE);
DataRelLocalSection = Ctx->getELFSection(".data.rel.local", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE);
DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE);
DataRelROLocalSection = Ctx->getELFSection(
".data.rel.ro.local", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_WRITE);
MergeableConst4Section =
Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, "");
MergeableConst8Section =
Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, "");
MergeableConst16Section =
Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE);
StaticDtorSection = Ctx->getELFSection(".dtors", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_WRITE);
// Exception Handling Sections.
// FIXME: We're emitting LSDA info into a readonly section on ELF, even though
// it contains relocatable pointers. In PIC mode, this is probably a big
// runtime hit for C++ apps. Either the contents of the LSDA need to be
// adjusted or this should be a data section.
LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC);
COFFDebugSymbolsSection = nullptr;
// Debug Info Sections.
DwarfAbbrevSection = Ctx->getELFSection(".debug_abbrev", ELF::SHT_PROGBITS, 0,
"section_abbrev");
DwarfInfoSection =
Ctx->getELFSection(".debug_info", ELF::SHT_PROGBITS, 0, "section_info");
DwarfLineSection = Ctx->getELFSection(".debug_line", ELF::SHT_PROGBITS, 0);
DwarfFrameSection = Ctx->getELFSection(".debug_frame", ELF::SHT_PROGBITS, 0);
DwarfPubNamesSection =
Ctx->getELFSection(".debug_pubnames", ELF::SHT_PROGBITS, 0);
DwarfPubTypesSection =
Ctx->getELFSection(".debug_pubtypes", ELF::SHT_PROGBITS, 0);
DwarfGnuPubNamesSection =
Ctx->getELFSection(".debug_gnu_pubnames", ELF::SHT_PROGBITS, 0);
DwarfGnuPubTypesSection =
Ctx->getELFSection(".debug_gnu_pubtypes", ELF::SHT_PROGBITS, 0);
DwarfStrSection =
Ctx->getELFSection(".debug_str", ELF::SHT_PROGBITS,
ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
DwarfLocSection = Ctx->getELFSection(".debug_loc", ELF::SHT_PROGBITS, 0);
DwarfARangesSection =
Ctx->getELFSection(".debug_aranges", ELF::SHT_PROGBITS, 0);
DwarfRangesSection =
Ctx->getELFSection(".debug_ranges", ELF::SHT_PROGBITS, 0, "debug_range");
// DWARF5 Experimental Debug Info
// Accelerator Tables
DwarfAccelNamesSection =
Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0, "names_begin");
DwarfAccelObjCSection =
Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0, "objc_begin");
DwarfAccelNamespaceSection = Ctx->getELFSection(
".apple_namespaces", ELF::SHT_PROGBITS, 0, "namespac_begin");
DwarfAccelTypesSection =
Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0, "types_begin");
// Fission Sections
DwarfInfoDWOSection =
Ctx->getELFSection(".debug_info.dwo", ELF::SHT_PROGBITS, 0);
DwarfTypesDWOSection =
Ctx->getELFSection(".debug_types.dwo", ELF::SHT_PROGBITS, 0);
DwarfAbbrevDWOSection =
Ctx->getELFSection(".debug_abbrev.dwo", ELF::SHT_PROGBITS, 0);
DwarfStrDWOSection =
Ctx->getELFSection(".debug_str.dwo", ELF::SHT_PROGBITS,
ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
DwarfLineDWOSection =
Ctx->getELFSection(".debug_line.dwo", ELF::SHT_PROGBITS, 0);
DwarfLocDWOSection =
Ctx->getELFSection(".debug_loc.dwo", ELF::SHT_PROGBITS, 0, "skel_loc");
DwarfStrOffDWOSection =
Ctx->getELFSection(".debug_str_offsets.dwo", ELF::SHT_PROGBITS, 0);
DwarfAddrSection =
Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
StackMapSection =
Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
FaultMapSection =
Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
}
void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
bool IsWoA = T.getArch() == Triple::arm || T.getArch() == Triple::thumb;
CommDirectiveSupportsAlignment = true;
// COFF
BSSSection = Ctx->getCOFFSection(
".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getBSS());
TextSection = Ctx->getCOFFSection(
".text",
(IsWoA ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |
COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getText());
DataSection = Ctx->getCOFFSection(
".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
ReadOnlySection = Ctx->getCOFFSection(
".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
if (T.isKnownWindowsMSVCEnvironment() || T.isWindowsItaniumEnvironment()) {
StaticCtorSection =
Ctx->getCOFFSection(".CRT$XCU", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
StaticDtorSection =
Ctx->getCOFFSection(".CRT$XTX", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
} else {
StaticCtorSection = Ctx->getCOFFSection(
".ctors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
StaticDtorSection = Ctx->getCOFFSection(
".dtors", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
}
// FIXME: We're emitting LSDA info into a readonly section on COFF, even
// though it contains relocatable pointers. In PIC mode, this is probably a
// big runtime hit for C++ apps. Either the contents of the LSDA need to be
// adjusted or this should be a data section.
assert(T.isOSWindows() && "Windows is the only supported COFF target");
if (T.getArch() == Triple::x86_64) {
// On Windows 64 with SEH, the LSDA is emitted into the .xdata section
LSDASection = 0;
} else {
LSDASection = Ctx->getCOFFSection(".gcc_except_table",
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
}
// Debug info.
COFFDebugSymbolsSection =
Ctx->getCOFFSection(".debug$S", COFF::IMAGE_SCN_MEM_DISCARDABLE |
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfAbbrevSection = Ctx->getCOFFSection(
".debug_abbrev",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_abbrev");
DwarfInfoSection = Ctx->getCOFFSection(
".debug_info",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_info");
DwarfLineSection = Ctx->getCOFFSection(
".debug_line",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_line");
DwarfFrameSection = Ctx->getCOFFSection(
".debug_frame",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfPubNamesSection = Ctx->getCOFFSection(
".debug_pubnames",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfPubTypesSection = Ctx->getCOFFSection(
".debug_pubtypes",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfGnuPubNamesSection = Ctx->getCOFFSection(
".debug_gnu_pubnames",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfGnuPubTypesSection = Ctx->getCOFFSection(
".debug_gnu_pubtypes",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfStrSection = Ctx->getCOFFSection(
".debug_str",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "info_string");
DwarfLocSection = Ctx->getCOFFSection(
".debug_loc",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_debug_loc");
DwarfARangesSection = Ctx->getCOFFSection(
".debug_aranges",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfRangesSection = Ctx->getCOFFSection(
".debug_ranges",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "debug_range");
DwarfInfoDWOSection = Ctx->getCOFFSection(
".debug_info.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_info_dwo");
DwarfTypesDWOSection = Ctx->getCOFFSection(
".debug_types.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_types_dwo");
DwarfAbbrevDWOSection = Ctx->getCOFFSection(
".debug_abbrev.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "section_abbrev_dwo");
DwarfStrDWOSection = Ctx->getCOFFSection(
".debug_str.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "skel_string");
DwarfLineDWOSection = Ctx->getCOFFSection(
".debug_line.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfLocDWOSection = Ctx->getCOFFSection(
".debug_loc.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "skel_loc");
DwarfStrOffDWOSection = Ctx->getCOFFSection(
".debug_str_offsets.dwo",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata());
DwarfAddrSection = Ctx->getCOFFSection(
".debug_addr",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "addr_sec");
DwarfAccelNamesSection = Ctx->getCOFFSection(
".apple_names",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "names_begin");
DwarfAccelNamespaceSection = Ctx->getCOFFSection(
".apple_namespaces",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "namespac_begin");
DwarfAccelTypesSection = Ctx->getCOFFSection(
".apple_types",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "types_begin");
DwarfAccelObjCSection = Ctx->getCOFFSection(
".apple_objc",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "objc_begin");
DrectveSection = Ctx->getCOFFSection(
".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE,
SectionKind::getMetadata());
PDataSection = Ctx->getCOFFSection(
".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getDataRel());
XDataSection = Ctx->getCOFFSection(
".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getDataRel());
SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO,
SectionKind::getMetadata());
TLSDataSection = Ctx->getCOFFSection(
".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
}
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
Reloc::Model relocm,
CodeModel::Model cm,
MCContext &ctx) {
RelocM = relocm;
CMModel = cm;
Ctx = &ctx;
// Common.
CommDirectiveSupportsAlignment = true;
SupportsWeakOmittedEHFrame = true;
SupportsCompactUnwindWithoutEHFrame = false;
PersonalityEncoding = LSDAEncoding = FDECFIEncoding = TTypeEncoding =
dwarf::DW_EH_PE_absptr;
CompactUnwindDwarfEHFrameOnly = 0;
EHFrameSection = nullptr; // Created on demand.
CompactUnwindSection = nullptr; // Used only by selected targets.
DwarfAccelNamesSection = nullptr; // Used only by selected targets.
DwarfAccelObjCSection = nullptr; // Used only by selected targets.
DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
DwarfAccelTypesSection = nullptr; // Used only by selected targets.
TT = TheTriple;
Triple::ArchType Arch = TT.getArch();
// FIXME: Checking for Arch here to filter out bogus triples such as
// cellspu-apple-darwin. Perhaps we should fix in Triple?
if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
Arch == Triple::arm || Arch == Triple::thumb ||
Arch == Triple::aarch64 ||
Arch == Triple::ppc || Arch == Triple::ppc64 ||
Arch == Triple::UnknownArch) &&
TT.isOSBinFormatMachO()) {
Env = IsMachO;
initMachOMCObjectFileInfo(TT);
} else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
Arch == Triple::arm || Arch == Triple::thumb) &&
(TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
Env = IsCOFF;
initCOFFMCObjectFileInfo(TT);
} else {
Env = IsELF;
initELFMCObjectFileInfo(TT);
}
}
void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
CodeModel::Model CM,
MCContext &ctx) {
InitMCObjectFileInfo(Triple(TT), RM, CM, ctx);
}
MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
0, utostr(Hash));
}
void MCObjectFileInfo::InitEHFrameSection() {
if (Env == IsMachO)
EHFrameSection =
Ctx->getMachOSection("__TEXT", "__eh_frame",
MachO::S_COALESCED |
MachO::S_ATTR_NO_TOC |
MachO::S_ATTR_STRIP_STATIC_SYMS |
MachO::S_ATTR_LIVE_SUPPORT,
SectionKind::getReadOnly());
else if (Env == IsELF)
EHFrameSection =
Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
else
EHFrameSection =
Ctx->getCOFFSection(".eh_frame",
COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ |
COFF::IMAGE_SCN_MEM_WRITE,
SectionKind::getDataRel());
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCObjectWriter.cpp | //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSymbol.h"
using namespace llvm;
MCObjectWriter::~MCObjectWriter() {
}
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
bool InSet) const {
// Modified symbol references cannot be resolved.
if (A->getKind() != MCSymbolRefExpr::VK_None ||
B->getKind() != MCSymbolRefExpr::VK_None)
return false;
const MCSymbol &SA = A->getSymbol();
const MCSymbol &SB = B->getSymbol();
if (SA.isUndefined() || SB.isUndefined())
return false;
if (!SA.getFragment() || !SB.getFragment())
return false;
return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *SB.getFragment(),
InSet, false);
}
bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
bool InSet, bool IsPCRel) const {
const MCSection &SecA = SymA.getSection();
const MCSection &SecB = *FB.getParent();
// On ELF and COFF A - B is absolute if A and B are in the same section.
return &SecA == &SecB;
}
bool MCObjectWriter::isWeak(const MCSymbol &) const { return false; }
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCAsmStreamer.cpp | //===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output --------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCStreamer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include <cctype>
using namespace llvm;
namespace {
class MCAsmStreamer final : public MCStreamer {
std::unique_ptr<formatted_raw_ostream> OSOwner;
formatted_raw_ostream &OS;
const MCAsmInfo *MAI;
std::unique_ptr<MCInstPrinter> InstPrinter;
std::unique_ptr<MCCodeEmitter> Emitter;
std::unique_ptr<MCAsmBackend> AsmBackend;
SmallString<128> CommentToEmit;
raw_svector_ostream CommentStream;
unsigned IsVerboseAsm : 1;
unsigned ShowInst : 1;
unsigned UseDwarfDirectory : 1;
void EmitRegisterName(int64_t Register);
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
public:
MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *printer, MCCodeEmitter *emitter,
MCAsmBackend *asmbackend, bool showInst)
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
MAI(Context.getAsmInfo()), InstPrinter(printer), Emitter(emitter),
AsmBackend(asmbackend), CommentStream(CommentToEmit),
IsVerboseAsm(isVerboseAsm), ShowInst(showInst),
UseDwarfDirectory(useDwarfDirectory) {
assert(InstPrinter);
if (IsVerboseAsm)
InstPrinter->setCommentStream(CommentStream);
}
inline void EmitEOL() {
// If we don't have any comments, just emit a \n.
if (!IsVerboseAsm) {
OS << '\n';
return;
}
EmitCommentsAndEOL();
}
void EmitCommentsAndEOL();
/// isVerboseAsm - Return true if this streamer supports verbose assembly at
/// all.
bool isVerboseAsm() const override { return IsVerboseAsm; }
/// hasRawTextSupport - We support EmitRawText.
bool hasRawTextSupport() const override { return true; }
/// AddComment - Add a comment that can be emitted to the generated .s
/// file if applicable as a QoI issue to make the output of the compiler
/// more readable. This only affects the MCAsmStreamer, and only when
/// verbose assembly output is enabled.
void AddComment(const Twine &T) override;
/// AddEncodingComment - Add a comment showing the encoding of an instruction.
void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
/// GetCommentOS - Return a raw_ostream that comments can be written to.
/// Unlike AddComment, you are required to terminate comments with \n if you
/// use this method.
raw_ostream &GetCommentOS() override {
if (!IsVerboseAsm)
return nulls(); // Discard comments unless in verbose asm mode.
return CommentStream;
}
void emitRawComment(const Twine &T, bool TabPrefix = true) override;
/// AddBlankLine - Emit a blank line to a .s file to pretty it up.
void AddBlankLine() override {
EmitEOL();
}
/// @name MCStreamer Interface
/// @{
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
void EmitLinkerOptions(ArrayRef<std::string> Options) override;
void EmitDataRegion(MCDataRegionType Kind) override;
void EmitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor,
unsigned Update) override;
void EmitThumbFunc(MCSymbol *Func) override;
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override;
void EmitCOFFSymbolStorageClass(int StorageClass) override;
void EmitCOFFSymbolType(int Type) override;
void EndCOFFSymbolDef() override;
void EmitCOFFSafeSEH(MCSymbol const *Symbol) override;
void EmitCOFFSectionIndex(MCSymbol const *Symbol) override;
void EmitCOFFSecRel32(MCSymbol const *Symbol) override;
void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
///
/// @param Symbol - The common symbol to emit.
/// @param Size - The size of the common symbol.
/// @param ByteAlignment - The alignment of the common symbol in bytes.
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, unsigned ByteAlignment = 0) override;
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment = 0) override;
void EmitBytes(StringRef Data) override;
void EmitValueImpl(const MCExpr *Value, unsigned Size,
const SMLoc &Loc = SMLoc()) override;
void EmitIntValue(uint64_t Value, unsigned Size) override;
void EmitULEB128Value(const MCExpr *Value) override;
void EmitSLEB128Value(const MCExpr *Value) override;
void EmitGPRel64Value(const MCExpr *Value) override;
void EmitGPRel32Value(const MCExpr *Value) override;
void EmitFill(uint64_t NumBytes, uint8_t FillValue) override;
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
unsigned ValueSize = 1,
unsigned MaxBytesToEmit = 0) override;
void EmitCodeAlignment(unsigned ByteAlignment,
unsigned MaxBytesToEmit = 0) override;
bool EmitValueToOffset(const MCExpr *Offset,
unsigned char Value = 0) override;
void EmitFileDirective(StringRef Filename) override;
unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
StringRef Filename,
unsigned CUID = 0) override;
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa, unsigned Discriminator,
StringRef FileName) override;
MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
void EmitIdent(StringRef IdentString) override;
void EmitCFISections(bool EH, bool Debug) override;
void EmitCFIDefCfa(int64_t Register, int64_t Offset) override;
void EmitCFIDefCfaOffset(int64_t Offset) override;
void EmitCFIDefCfaRegister(int64_t Register) override;
void EmitCFIOffset(int64_t Register, int64_t Offset) override;
void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding) override;
void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) override;
void EmitCFIRememberState() override;
void EmitCFIRestoreState() override;
void EmitCFISameValue(int64_t Register) override;
void EmitCFIRelOffset(int64_t Register, int64_t Offset) override;
void EmitCFIAdjustCfaOffset(int64_t Adjustment) override;
void EmitCFISignalFrame() override;
void EmitCFIUndefined(int64_t Register) override;
void EmitCFIRegister(int64_t Register1, int64_t Register2) override;
void EmitCFIWindowSave() override;
void EmitWinCFIStartProc(const MCSymbol *Symbol) override;
void EmitWinCFIEndProc() override;
void EmitWinCFIStartChained() override;
void EmitWinCFIEndChained() override;
void EmitWinCFIPushReg(unsigned Register) override;
void EmitWinCFISetFrame(unsigned Register, unsigned Offset) override;
void EmitWinCFIAllocStack(unsigned Size) override;
void EmitWinCFISaveReg(unsigned Register, unsigned Offset) override;
void EmitWinCFISaveXMM(unsigned Register, unsigned Offset) override;
void EmitWinCFIPushFrame(bool Code) override;
void EmitWinCFIEndProlog() override;
void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except) override;
void EmitWinEHHandlerData() override;
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
void EmitBundleAlignMode(unsigned AlignPow2) override;
void EmitBundleLock(bool AlignToEnd) override;
void EmitBundleUnlock() override;
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
/// the specified string in the output .s file. This capability is
/// indicated by the hasRawTextSupport() predicate.
void EmitRawTextImpl(StringRef String) override;
void FinishImpl() override;
};
} // end anonymous namespace.
/// AddComment - Add a comment that can be emitted to the generated .s
/// file if applicable as a QoI issue to make the output of the compiler
/// more readable. This only affects the MCAsmStreamer, and only when
/// verbose assembly output is enabled.
void MCAsmStreamer::AddComment(const Twine &T) {
if (!IsVerboseAsm) return;
// Make sure that CommentStream is flushed.
CommentStream.flush();
T.toVector(CommentToEmit);
// Each comment goes on its own line.
CommentToEmit.push_back('\n');
// Tell the comment stream that the vector changed underneath it.
CommentStream.resync();
}
void MCAsmStreamer::EmitCommentsAndEOL() {
if (CommentToEmit.empty() && CommentStream.GetNumBytesInBuffer() == 0) {
OS << '\n';
return;
}
CommentStream.flush();
StringRef Comments = CommentToEmit;
assert(Comments.back() == '\n' &&
"Comment array not newline terminated");
do {
// Emit a line of comments.
OS.PadToColumn(MAI->getCommentColumn());
size_t Position = Comments.find('\n');
OS << MAI->getCommentString() << ' ' << Comments.substr(0, Position) <<'\n';
Comments = Comments.substr(Position+1);
} while (!Comments.empty());
CommentToEmit.clear();
// Tell the comment stream that the vector changed underneath it.
CommentStream.resync();
}
static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
assert(Bytes && "Invalid size!");
return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
}
void MCAsmStreamer::emitRawComment(const Twine &T, bool TabPrefix) {
if (TabPrefix)
OS << '\t';
OS << MAI->getCommentString() << T;
EmitEOL();
}
void MCAsmStreamer::ChangeSection(MCSection *Section,
const MCExpr *Subsection) {
assert(Section && "Cannot switch to a null section!");
Section->PrintSwitchToSection(*MAI, OS, Subsection);
}
void MCAsmStreamer::EmitLabel(MCSymbol *Symbol) {
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
MCStreamer::EmitLabel(Symbol);
Symbol->print(OS, MAI);
OS << MAI->getLabelSuffix();
EmitEOL();
}
void MCAsmStreamer::EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {
StringRef str = MCLOHIdToName(Kind);
#ifndef NDEBUG
int NbArgs = MCLOHIdToNbArgs(Kind);
assert(NbArgs != -1 && ((size_t)NbArgs) == Args.size() && "Malformed LOH!");
assert(str != "" && "Invalid LOH name");
#endif
OS << "\t" << MCLOHDirectiveName() << " " << str << "\t";
bool IsFirst = true;
for (MCLOHArgs::const_iterator It = Args.begin(), EndIt = Args.end();
It != EndIt; ++It) {
if (!IsFirst)
OS << ", ";
IsFirst = false;
(*It)->print(OS, MAI);
}
EmitEOL();
}
void MCAsmStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
switch (Flag) {
case MCAF_SyntaxUnified: OS << "\t.syntax unified"; break;
case MCAF_SubsectionsViaSymbols: OS << ".subsections_via_symbols"; break;
case MCAF_Code16: OS << '\t'<< MAI->getCode16Directive();break;
case MCAF_Code32: OS << '\t'<< MAI->getCode32Directive();break;
case MCAF_Code64: OS << '\t'<< MAI->getCode64Directive();break;
}
EmitEOL();
}
void MCAsmStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
assert(!Options.empty() && "At least one option is required!");
OS << "\t.linker_option \"" << Options[0] << '"';
for (ArrayRef<std::string>::iterator it = Options.begin() + 1,
ie = Options.end(); it != ie; ++it) {
OS << ", " << '"' << *it << '"';
}
OS << "\n";
}
void MCAsmStreamer::EmitDataRegion(MCDataRegionType Kind) {
if (!MAI->doesSupportDataRegionDirectives())
return;
switch (Kind) {
case MCDR_DataRegion: OS << "\t.data_region"; break;
case MCDR_DataRegionJT8: OS << "\t.data_region jt8"; break;
case MCDR_DataRegionJT16: OS << "\t.data_region jt16"; break;
case MCDR_DataRegionJT32: OS << "\t.data_region jt32"; break;
case MCDR_DataRegionEnd: OS << "\t.end_data_region"; break;
}
EmitEOL();
}
void MCAsmStreamer::EmitVersionMin(MCVersionMinType Kind, unsigned Major,
unsigned Minor, unsigned Update) {
switch (Kind) {
case MCVM_IOSVersionMin: OS << "\t.ios_version_min"; break;
case MCVM_OSXVersionMin: OS << "\t.macosx_version_min"; break;
}
OS << " " << Major << ", " << Minor;
if (Update)
OS << ", " << Update;
EmitEOL();
}
void MCAsmStreamer::EmitThumbFunc(MCSymbol *Func) {
// This needs to emit to a temporary string to get properly quoted
// MCSymbols when they have spaces in them.
OS << "\t.thumb_func";
// Only Mach-O hasSubsectionsViaSymbols()
if (MAI->hasSubsectionsViaSymbols()) {
OS << '\t';
Func->print(OS, MAI);
}
EmitEOL();
}
void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
Symbol->print(OS, MAI);
OS << " = ";
Value->print(OS, MAI);
EmitEOL();
MCStreamer::EmitAssignment(Symbol, Value);
}
void MCAsmStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
OS << ".weakref ";
Alias->print(OS, MAI);
OS << ", ";
Symbol->print(OS, MAI);
EmitEOL();
}
bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) {
switch (Attribute) {
case MCSA_Invalid: llvm_unreachable("Invalid symbol attribute");
case MCSA_ELF_TypeFunction: /// .type _foo, STT_FUNC # aka @function
case MCSA_ELF_TypeIndFunction: /// .type _foo, STT_GNU_IFUNC
case MCSA_ELF_TypeObject: /// .type _foo, STT_OBJECT # aka @object
case MCSA_ELF_TypeTLS: /// .type _foo, STT_TLS # aka @tls_object
case MCSA_ELF_TypeCommon: /// .type _foo, STT_COMMON # aka @common
case MCSA_ELF_TypeNoType: /// .type _foo, STT_NOTYPE # aka @notype
case MCSA_ELF_TypeGnuUniqueObject: /// .type _foo, @gnu_unique_object
if (!MAI->hasDotTypeDotSizeDirective())
return false; // Symbol attribute not supported
OS << "\t.type\t";
Symbol->print(OS, MAI);
OS << ',' << ((MAI->getCommentString()[0] != '@') ? '@' : '%');
switch (Attribute) {
default: return false;
case MCSA_ELF_TypeFunction: OS << "function"; break;
case MCSA_ELF_TypeIndFunction: OS << "gnu_indirect_function"; break;
case MCSA_ELF_TypeObject: OS << "object"; break;
case MCSA_ELF_TypeTLS: OS << "tls_object"; break;
case MCSA_ELF_TypeCommon: OS << "common"; break;
case MCSA_ELF_TypeNoType: OS << "no_type"; break;
case MCSA_ELF_TypeGnuUniqueObject: OS << "gnu_unique_object"; break;
}
EmitEOL();
return true;
case MCSA_Global: // .globl/.global
OS << MAI->getGlobalDirective();
break;
case MCSA_Hidden: OS << "\t.hidden\t"; break;
case MCSA_IndirectSymbol: OS << "\t.indirect_symbol\t"; break;
case MCSA_Internal: OS << "\t.internal\t"; break;
case MCSA_LazyReference: OS << "\t.lazy_reference\t"; break;
case MCSA_Local: OS << "\t.local\t"; break;
case MCSA_NoDeadStrip:
if (!MAI->hasNoDeadStrip())
return false;
OS << "\t.no_dead_strip\t";
break;
case MCSA_SymbolResolver: OS << "\t.symbol_resolver\t"; break;
case MCSA_PrivateExtern:
OS << "\t.private_extern\t";
break;
case MCSA_Protected: OS << "\t.protected\t"; break;
case MCSA_Reference: OS << "\t.reference\t"; break;
case MCSA_Weak: OS << MAI->getWeakDirective(); break;
case MCSA_WeakDefinition:
OS << "\t.weak_definition\t";
break;
// .weak_reference
case MCSA_WeakReference: OS << MAI->getWeakRefDirective(); break;
case MCSA_WeakDefAutoPrivate: OS << "\t.weak_def_can_be_hidden\t"; break;
}
Symbol->print(OS, MAI);
EmitEOL();
return true;
}
void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
OS << ".desc" << ' ';
Symbol->print(OS, MAI);
OS << ',' << DescValue;
EmitEOL();
}
void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
OS << "\t.def\t ";
Symbol->print(OS, MAI);
OS << ';';
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
OS << "\t.scl\t" << StorageClass << ';';
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
OS << "\t.type\t" << Type << ';';
EmitEOL();
}
void MCAsmStreamer::EndCOFFSymbolDef() {
OS << "\t.endef";
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
OS << "\t.safeseh\t";
Symbol->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
OS << "\t.secidx\t";
Symbol->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
OS << "\t.secrel32\t";
Symbol->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
assert(MAI->hasDotTypeDotSizeDirective());
OS << "\t.size\t";
Symbol->print(OS, MAI);
OS << ", ";
Value->print(OS, MAI);
OS << '\n';
}
void MCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
// Common symbols do not belong to any actual section.
AssignSection(Symbol, nullptr);
OS << "\t.comm\t";
Symbol->print(OS, MAI);
OS << ',' << Size;
if (ByteAlignment != 0) {
if (MAI->getCOMMDirectiveAlignmentIsInBytes())
OS << ',' << ByteAlignment;
else
OS << ',' << Log2_32(ByteAlignment);
}
EmitEOL();
}
/// EmitLocalCommonSymbol - Emit a local common (.lcomm) symbol.
///
/// @param Symbol - The common symbol to emit.
/// @param Size - The size of the common symbol.
void MCAsmStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlign) {
// Common symbols do not belong to any actual section.
AssignSection(Symbol, nullptr);
OS << "\t.lcomm\t";
Symbol->print(OS, MAI);
OS << ',' << Size;
if (ByteAlign > 1) {
switch (MAI->getLCOMMDirectiveAlignmentType()) {
case LCOMM::NoAlignment:
llvm_unreachable("alignment not supported on .lcomm!");
case LCOMM::ByteAlignment:
OS << ',' << ByteAlign;
break;
case LCOMM::Log2Alignment:
assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
OS << ',' << Log2_32(ByteAlign);
break;
}
}
EmitEOL();
}
void MCAsmStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
if (Symbol)
AssignSection(Symbol, Section);
// Note: a .zerofill directive does not switch sections.
OS << ".zerofill ";
// This is a mach-o specific directive.
const MCSectionMachO *MOSection = ((const MCSectionMachO*)Section);
OS << MOSection->getSegmentName() << "," << MOSection->getSectionName();
if (Symbol) {
OS << ',';
Symbol->print(OS, MAI);
OS << ',' << Size;
if (ByteAlignment != 0)
OS << ',' << Log2_32(ByteAlignment);
}
EmitEOL();
}
// .tbss sym, size, align
// This depends that the symbol has already been mangled from the original,
// e.g. _a.
void MCAsmStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
AssignSection(Symbol, Section);
assert(Symbol && "Symbol shouldn't be NULL!");
// Instead of using the Section we'll just use the shortcut.
// This is a mach-o specific directive and section.
OS << ".tbss ";
Symbol->print(OS, MAI);
OS << ", " << Size;
// Output align if we have it. We default to 1 so don't bother printing
// that.
if (ByteAlignment > 1) OS << ", " << Log2_32(ByteAlignment);
EmitEOL();
}
static inline char toOctal(int X) { return (X&7)+'0'; }
static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
OS << '"';
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
unsigned char C = Data[i];
if (C == '"' || C == '\\') {
OS << '\\' << (char)C;
continue;
}
if (isprint((unsigned char)C)) {
OS << (char)C;
continue;
}
switch (C) {
case '\b': OS << "\\b"; break;
case '\f': OS << "\\f"; break;
case '\n': OS << "\\n"; break;
case '\r': OS << "\\r"; break;
case '\t': OS << "\\t"; break;
default:
OS << '\\';
OS << toOctal(C >> 6);
OS << toOctal(C >> 3);
OS << toOctal(C >> 0);
break;
}
}
OS << '"';
}
void MCAsmStreamer::EmitBytes(StringRef Data) {
assert(getCurrentSection().first &&
"Cannot emit contents before setting section!");
if (Data.empty()) return;
if (Data.size() == 1) {
OS << MAI->getData8bitsDirective();
OS << (unsigned)(unsigned char)Data[0];
EmitEOL();
return;
}
// If the data ends with 0 and the target supports .asciz, use it, otherwise
// use .ascii
if (MAI->getAscizDirective() && Data.back() == 0) {
OS << MAI->getAscizDirective();
Data = Data.substr(0, Data.size()-1);
} else {
OS << MAI->getAsciiDirective();
}
PrintQuotedString(Data, OS);
EmitEOL();
}
void MCAsmStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
EmitValue(MCConstantExpr::create(Value, getContext()), Size);
}
void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
const SMLoc &Loc) {
assert(Size <= 8 && "Invalid size");
assert(getCurrentSection().first &&
"Cannot emit contents before setting section!");
const char *Directive = nullptr;
switch (Size) {
default: break;
case 1: Directive = MAI->getData8bitsDirective(); break;
case 2: Directive = MAI->getData16bitsDirective(); break;
case 4: Directive = MAI->getData32bitsDirective(); break;
case 8: Directive = MAI->getData64bitsDirective(); break;
}
if (!Directive) {
int64_t IntValue;
if (!Value->evaluateAsAbsolute(IntValue))
report_fatal_error("Don't know how to emit this value.");
// We couldn't handle the requested integer size so we fallback by breaking
// the request down into several, smaller, integers. Since sizes greater
// than eight are invalid and size equivalent to eight should have been
// handled earlier, we use four bytes as our largest piece of granularity.
bool IsLittleEndian = MAI->isLittleEndian();
for (unsigned Emitted = 0; Emitted != Size;) {
unsigned Remaining = Size - Emitted;
// The size of our partial emission must be a power of two less than
// eight.
unsigned EmissionSize = PowerOf2Floor(Remaining);
if (EmissionSize > 4)
EmissionSize = 4;
// Calculate the byte offset of our partial emission taking into account
// the endianness of the target.
unsigned ByteOffset =
IsLittleEndian ? Emitted : (Remaining - EmissionSize);
uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
// We truncate our partial emission to fit within the bounds of the
// emission domain. This produces nicer output and silences potential
// truncation warnings when round tripping through another assembler.
uint64_t Shift = 64 - EmissionSize * 8;
assert(Shift < static_cast<uint64_t>(
std::numeric_limits<unsigned long long>::digits) &&
"undefined behavior");
ValueToEmit &= ~0ULL >> Shift;
EmitIntValue(ValueToEmit, EmissionSize);
Emitted += EmissionSize;
}
return;
}
assert(Directive && "Invalid size for machine code value!");
OS << Directive;
Value->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
int64_t IntValue;
if (Value->evaluateAsAbsolute(IntValue)) {
EmitULEB128IntValue(IntValue);
return;
}
OS << ".uleb128 ";
Value->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitSLEB128Value(const MCExpr *Value) {
int64_t IntValue;
if (Value->evaluateAsAbsolute(IntValue)) {
EmitSLEB128IntValue(IntValue);
return;
}
OS << ".sleb128 ";
Value->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitGPRel64Value(const MCExpr *Value) {
assert(MAI->getGPRel64Directive() != nullptr);
OS << MAI->getGPRel64Directive();
Value->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitGPRel32Value(const MCExpr *Value) {
assert(MAI->getGPRel32Directive() != nullptr);
OS << MAI->getGPRel32Directive();
Value->print(OS, MAI);
EmitEOL();
}
/// EmitFill - Emit NumBytes bytes worth of the value specified by
/// FillValue. This implements directives such as '.space'.
void MCAsmStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
if (NumBytes == 0) return;
if (const char *ZeroDirective = MAI->getZeroDirective()) {
OS << ZeroDirective << NumBytes;
if (FillValue != 0)
OS << ',' << (int)FillValue;
EmitEOL();
return;
}
// Emit a byte at a time.
MCStreamer::EmitFill(NumBytes, FillValue);
}
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
// Some assemblers don't support non-power of two alignments, so we always
// emit alignments as a power of two if possible.
if (isPowerOf2_32(ByteAlignment)) {
switch (ValueSize) {
default:
llvm_unreachable("Invalid size for machine code value!");
case 1:
OS << "\t.align\t";
break;
case 2:
OS << ".p2alignw ";
break;
case 4:
OS << ".p2alignl ";
break;
case 8:
llvm_unreachable("Unsupported alignment size!");
}
if (MAI->getAlignmentIsInBytes())
OS << ByteAlignment;
else
OS << Log2_32(ByteAlignment);
if (Value || MaxBytesToEmit) {
OS << ", 0x";
OS.write_hex(truncateToSize(Value, ValueSize));
if (MaxBytesToEmit)
OS << ", " << MaxBytesToEmit;
}
EmitEOL();
return;
}
// Non-power of two alignment. This is not widely supported by assemblers.
// FIXME: Parameterize this based on MAI.
switch (ValueSize) {
default: llvm_unreachable("Invalid size for machine code value!");
case 1: OS << ".balign"; break;
case 2: OS << ".balignw"; break;
case 4: OS << ".balignl"; break;
case 8: llvm_unreachable("Unsupported alignment size!");
}
OS << ' ' << ByteAlignment;
OS << ", " << truncateToSize(Value, ValueSize);
if (MaxBytesToEmit)
OS << ", " << MaxBytesToEmit;
EmitEOL();
}
void MCAsmStreamer::EmitCodeAlignment(unsigned ByteAlignment,
unsigned MaxBytesToEmit) {
// Emit with a text fill value.
EmitValueToAlignment(ByteAlignment, MAI->getTextAlignFillValue(),
1, MaxBytesToEmit);
}
bool MCAsmStreamer::EmitValueToOffset(const MCExpr *Offset,
unsigned char Value) {
// FIXME: Verify that Offset is associated with the current section.
OS << ".org ";
Offset->print(OS, MAI);
OS << ", " << (unsigned)Value;
EmitEOL();
return false;
}
void MCAsmStreamer::EmitFileDirective(StringRef Filename) {
assert(MAI->hasSingleParameterDotFile());
OS << "\t.file\t";
PrintQuotedString(Filename, OS);
EmitEOL();
}
unsigned MCAsmStreamer::EmitDwarfFileDirective(unsigned FileNo,
StringRef Directory,
StringRef Filename,
unsigned CUID) {
assert(CUID == 0);
MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
unsigned NumFiles = Table.getMCDwarfFiles().size();
FileNo = Table.getFile(Directory, Filename, FileNo);
if (FileNo == 0)
return 0;
if (NumFiles == Table.getMCDwarfFiles().size())
return FileNo;
SmallString<128> FullPathName;
if (!UseDwarfDirectory && !Directory.empty()) {
if (sys::path::is_absolute(Filename))
Directory = "";
else {
FullPathName = Directory;
sys::path::append(FullPathName, Filename);
Directory = "";
Filename = FullPathName;
}
}
OS << "\t.file\t" << FileNo << ' ';
if (!Directory.empty()) {
PrintQuotedString(Directory, OS);
OS << ' ';
}
PrintQuotedString(Filename, OS);
EmitEOL();
return FileNo;
}
void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
unsigned Discriminator,
StringRef FileName) {
OS << "\t.loc\t" << FileNo << " " << Line << " " << Column;
if (Flags & DWARF2_FLAG_BASIC_BLOCK)
OS << " basic_block";
if (Flags & DWARF2_FLAG_PROLOGUE_END)
OS << " prologue_end";
if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
OS << " epilogue_begin";
unsigned OldFlags = getContext().getCurrentDwarfLoc().getFlags();
if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
OS << " is_stmt ";
if (Flags & DWARF2_FLAG_IS_STMT)
OS << "1";
else
OS << "0";
}
if (Isa)
OS << " isa " << Isa;
if (Discriminator)
OS << " discriminator " << Discriminator;
if (IsVerboseAsm) {
OS.PadToColumn(MAI->getCommentColumn());
OS << MAI->getCommentString() << ' ' << FileName << ':'
<< Line << ':' << Column;
}
EmitEOL();
this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
Isa, Discriminator, FileName);
}
MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
// Always use the zeroth line table, since asm syntax only supports one line
// table for now.
return MCStreamer::getDwarfLineTableSymbol(0);
}
void MCAsmStreamer::EmitIdent(StringRef IdentString) {
assert(MAI->hasIdentDirective() && ".ident directive not supported");
OS << "\t.ident\t";
PrintQuotedString(IdentString, OS);
EmitEOL();
}
void MCAsmStreamer::EmitCFISections(bool EH, bool Debug) {
MCStreamer::EmitCFISections(EH, Debug);
OS << "\t.cfi_sections ";
if (EH) {
OS << ".eh_frame";
if (Debug)
OS << ", .debug_frame";
} else if (Debug) {
OS << ".debug_frame";
}
EmitEOL();
}
void MCAsmStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
OS << "\t.cfi_startproc";
if (Frame.IsSimple)
OS << " simple";
EmitEOL();
}
void MCAsmStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
MCStreamer::EmitCFIEndProcImpl(Frame);
OS << "\t.cfi_endproc";
EmitEOL();
}
void MCAsmStreamer::EmitRegisterName(int64_t Register) {
if (!MAI->useDwarfRegNumForCFI()) {
const MCRegisterInfo *MRI = getContext().getRegisterInfo();
unsigned LLVMRegister = MRI->getLLVMRegNum(Register, true);
InstPrinter->printRegName(OS, LLVMRegister);
} else {
OS << Register;
}
}
void MCAsmStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
MCStreamer::EmitCFIDefCfa(Register, Offset);
OS << "\t.cfi_def_cfa ";
EmitRegisterName(Register);
OS << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
MCStreamer::EmitCFIDefCfaOffset(Offset);
OS << "\t.cfi_def_cfa_offset " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {
MCStreamer::EmitCFIDefCfaRegister(Register);
OS << "\t.cfi_def_cfa_register ";
EmitRegisterName(Register);
EmitEOL();
}
void MCAsmStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
this->MCStreamer::EmitCFIOffset(Register, Offset);
OS << "\t.cfi_offset ";
EmitRegisterName(Register);
OS << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitCFIPersonality(const MCSymbol *Sym,
unsigned Encoding) {
MCStreamer::EmitCFIPersonality(Sym, Encoding);
OS << "\t.cfi_personality " << Encoding << ", ";
Sym->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
MCStreamer::EmitCFILsda(Sym, Encoding);
OS << "\t.cfi_lsda " << Encoding << ", ";
Sym->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitCFIRememberState() {
MCStreamer::EmitCFIRememberState();
OS << "\t.cfi_remember_state";
EmitEOL();
}
void MCAsmStreamer::EmitCFIRestoreState() {
MCStreamer::EmitCFIRestoreState();
OS << "\t.cfi_restore_state";
EmitEOL();
}
void MCAsmStreamer::EmitCFISameValue(int64_t Register) {
MCStreamer::EmitCFISameValue(Register);
OS << "\t.cfi_same_value ";
EmitRegisterName(Register);
EmitEOL();
}
void MCAsmStreamer::EmitCFIRelOffset(int64_t Register, int64_t Offset) {
MCStreamer::EmitCFIRelOffset(Register, Offset);
OS << "\t.cfi_rel_offset ";
EmitRegisterName(Register);
OS << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
MCStreamer::EmitCFIAdjustCfaOffset(Adjustment);
OS << "\t.cfi_adjust_cfa_offset " << Adjustment;
EmitEOL();
}
void MCAsmStreamer::EmitCFISignalFrame() {
MCStreamer::EmitCFISignalFrame();
OS << "\t.cfi_signal_frame";
EmitEOL();
}
void MCAsmStreamer::EmitCFIUndefined(int64_t Register) {
MCStreamer::EmitCFIUndefined(Register);
OS << "\t.cfi_undefined " << Register;
EmitEOL();
}
void MCAsmStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
MCStreamer::EmitCFIRegister(Register1, Register2);
OS << "\t.cfi_register " << Register1 << ", " << Register2;
EmitEOL();
}
void MCAsmStreamer::EmitCFIWindowSave() {
MCStreamer::EmitCFIWindowSave();
OS << "\t.cfi_window_save";
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIStartProc(const MCSymbol *Symbol) {
MCStreamer::EmitWinCFIStartProc(Symbol);
OS << ".seh_proc ";
Symbol->print(OS, MAI);
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIEndProc() {
MCStreamer::EmitWinCFIEndProc();
OS << "\t.seh_endproc";
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIStartChained() {
MCStreamer::EmitWinCFIStartChained();
OS << "\t.seh_startchained";
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIEndChained() {
MCStreamer::EmitWinCFIEndChained();
OS << "\t.seh_endchained";
EmitEOL();
}
void MCAsmStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind,
bool Except) {
MCStreamer::EmitWinEHHandler(Sym, Unwind, Except);
OS << "\t.seh_handler ";
Sym->print(OS, MAI);
if (Unwind)
OS << ", @unwind";
if (Except)
OS << ", @except";
EmitEOL();
}
void MCAsmStreamer::EmitWinEHHandlerData() {
MCStreamer::EmitWinEHHandlerData();
// Switch sections. Don't call SwitchSection directly, because that will
// cause the section switch to be visible in the emitted assembly.
// We only do this so the section switch that terminates the handler
// data block is visible.
WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
MCSection *XData =
WinEH::UnwindEmitter::getXDataSection(CurFrame->Function, getContext());
SwitchSectionNoChange(XData);
OS << "\t.seh_handlerdata";
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIPushReg(unsigned Register) {
MCStreamer::EmitWinCFIPushReg(Register);
OS << "\t.seh_pushreg " << Register;
EmitEOL();
}
void MCAsmStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISetFrame(Register, Offset);
OS << "\t.seh_setframe " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIAllocStack(unsigned Size) {
MCStreamer::EmitWinCFIAllocStack(Size);
OS << "\t.seh_stackalloc " << Size;
EmitEOL();
}
void MCAsmStreamer::EmitWinCFISaveReg(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISaveReg(Register, Offset);
OS << "\t.seh_savereg " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWinCFISaveXMM(unsigned Register, unsigned Offset) {
MCStreamer::EmitWinCFISaveXMM(Register, Offset);
OS << "\t.seh_savexmm " << Register << ", " << Offset;
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIPushFrame(bool Code) {
MCStreamer::EmitWinCFIPushFrame(Code);
OS << "\t.seh_pushframe";
if (Code)
OS << " @code";
EmitEOL();
}
void MCAsmStreamer::EmitWinCFIEndProlog(void) {
MCStreamer::EmitWinCFIEndProlog();
OS << "\t.seh_endprologue";
EmitEOL();
}
void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
const MCSubtargetInfo &STI) {
raw_ostream &OS = GetCommentOS();
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
raw_svector_ostream VecOS(Code);
Emitter->encodeInstruction(Inst, VecOS, Fixups, STI);
VecOS.flush();
// If we are showing fixups, create symbolic markers in the encoded
// representation. We do this by making a per-bit map to the fixup item index,
// then trying to display it as nicely as possible.
SmallVector<uint8_t, 64> FixupMap;
FixupMap.resize(Code.size() * 8);
for (unsigned i = 0, e = Code.size() * 8; i != e; ++i)
FixupMap[i] = 0;
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCFixup &F = Fixups[i];
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
for (unsigned j = 0; j != Info.TargetSize; ++j) {
unsigned Index = F.getOffset() * 8 + Info.TargetOffset + j;
assert(Index < Code.size() * 8 && "Invalid offset in fixup!");
FixupMap[Index] = 1 + i;
}
}
// FIXME: Note the fixup comments for Thumb2 are completely bogus since the
// high order halfword of a 32-bit Thumb2 instruction is emitted first.
OS << "encoding: [";
for (unsigned i = 0, e = Code.size(); i != e; ++i) {
if (i)
OS << ',';
// See if all bits are the same map entry.
uint8_t MapEntry = FixupMap[i * 8 + 0];
for (unsigned j = 1; j != 8; ++j) {
if (FixupMap[i * 8 + j] == MapEntry)
continue;
MapEntry = uint8_t(~0U);
break;
}
if (MapEntry != uint8_t(~0U)) {
if (MapEntry == 0) {
OS << format("0x%02x", uint8_t(Code[i]));
} else {
if (Code[i]) {
// FIXME: Some of the 8 bits require fix up.
OS << format("0x%02x", uint8_t(Code[i])) << '\''
<< char('A' + MapEntry - 1) << '\'';
} else
OS << char('A' + MapEntry - 1);
}
} else {
// Otherwise, write out in binary.
OS << "0b";
for (unsigned j = 8; j--;) {
unsigned Bit = (Code[i] >> j) & 1;
unsigned FixupBit;
if (MAI->isLittleEndian())
FixupBit = i * 8 + j;
else
FixupBit = i * 8 + (7-j);
if (uint8_t MapEntry = FixupMap[FixupBit]) {
assert(Bit == 0 && "Encoder wrote into fixed up bit!");
OS << char('A' + MapEntry - 1);
} else
OS << Bit;
}
}
}
OS << "]\n";
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
MCFixup &F = Fixups[i];
const MCFixupKindInfo &Info = AsmBackend->getFixupKindInfo(F.getKind());
OS << " fixup " << char('A' + i) << " - " << "offset: " << F.getOffset()
<< ", value: " << *F.getValue() << ", kind: " << Info.Name << "\n";
}
}
void MCAsmStreamer::EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) {
assert(getCurrentSection().first &&
"Cannot emit contents before setting section!");
// Show the encoding in a comment if we have a code emitter.
if (Emitter)
AddEncodingComment(Inst, STI);
// Show the MCInst if enabled.
if (ShowInst) {
Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
GetCommentOS() << "\n";
}
if(getTargetStreamer())
getTargetStreamer()->prettyPrintAsm(*InstPrinter, OS, Inst, STI);
else
InstPrinter->printInst(&Inst, OS, "", STI);
EmitEOL();
}
void MCAsmStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
OS << "\t.bundle_align_mode " << AlignPow2;
EmitEOL();
}
void MCAsmStreamer::EmitBundleLock(bool AlignToEnd) {
OS << "\t.bundle_lock";
if (AlignToEnd)
OS << " align_to_end";
EmitEOL();
}
void MCAsmStreamer::EmitBundleUnlock() {
OS << "\t.bundle_unlock";
EmitEOL();
}
/// EmitRawText - If this file is backed by an assembly streamer, this dumps
/// the specified string in the output .s file. This capability is
/// indicated by the hasRawTextSupport() predicate.
void MCAsmStreamer::EmitRawTextImpl(StringRef String) {
if (!String.empty() && String.back() == '\n')
String = String.substr(0, String.size()-1);
OS << String;
EmitEOL();
}
void MCAsmStreamer::FinishImpl() {
// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
MCGenDwarfInfo::Emit(this);
// Emit the label for the line table, if requested - since the rest of the
// line table will be defined by .loc/.file directives, and not emitted
// directly, the label is the only work required here.
auto &Tables = getContext().getMCDwarfLineTables();
if (!Tables.empty()) {
assert(Tables.size() == 1 && "asm output only supports one line table");
if (auto *Label = Tables.begin()->second.getLabel()) {
SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
EmitLabel(Label);
}
}
}
MCStreamer *llvm::createAsmStreamer(MCContext &Context,
std::unique_ptr<formatted_raw_ostream> OS,
bool isVerboseAsm, bool useDwarfDirectory,
MCInstPrinter *IP, MCCodeEmitter *CE,
MCAsmBackend *MAB, bool ShowInst) {
return new MCAsmStreamer(Context, std::move(OS), isVerboseAsm,
useDwarfDirectory, IP, CE, MAB, ShowInst);
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCTargetOptions.cpp | //===- lib/MC/MCTargetOptions.cpp - MC Target Options --------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCTargetOptions.h"
#if 0 // HLSL Change
namespace llvm {
MCTargetOptions::MCTargetOptions()
: SanitizeAddress(false), MCRelaxAll(false), MCNoExecStack(false),
MCFatalWarnings(false), MCSaveTempLabels(false),
MCUseDwarfDirectory(false), ShowMCEncoding(false), ShowMCInst(false),
AsmVerbose(false), DwarfVersion(0), ABIName() {}
StringRef MCTargetOptions::getABIName() const {
return ABIName;
}
} // end namespace llvm
#endif // HLSL Change
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/YAML.cpp | //===- YAML.cpp - YAMLIO utilities for object files -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines utility classes for handling the YAML representation of
// object files.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/YAML.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
using namespace llvm;
void yaml::ScalarTraits<yaml::BinaryRef>::output(
const yaml::BinaryRef &Val, void *, llvm::raw_ostream &Out) {
Val.writeAsHex(Out);
}
StringRef yaml::ScalarTraits<yaml::BinaryRef>::input(StringRef Scalar, void *,
yaml::BinaryRef &Val) {
if (Scalar.size() % 2 != 0)
return "BinaryRef hex string must contain an even number of nybbles.";
// TODO: Can we improve YAMLIO to permit a more accurate diagnostic here?
// (e.g. a caret pointing to the offending character).
for (unsigned I = 0, N = Scalar.size(); I != N; ++I)
if (!isxdigit(Scalar[I]))
return "BinaryRef hex string must contain only hex digits.";
Val = yaml::BinaryRef(Scalar);
return StringRef();
}
void yaml::BinaryRef::writeAsBinary(raw_ostream &OS) const {
if (!DataIsHexString) {
OS.write((const char *)Data.data(), Data.size());
return;
}
for (unsigned I = 0, N = Data.size(); I != N; I += 2) {
uint8_t Byte;
StringRef((const char *)&Data[I], 2).getAsInteger(16, Byte);
OS.write(Byte);
}
}
void yaml::BinaryRef::writeAsHex(raw_ostream &OS) const {
if (binary_size() == 0)
return;
if (DataIsHexString) {
OS.write((const char *)Data.data(), Data.size());
return;
}
for (ArrayRef<uint8_t>::iterator I = Data.begin(), E = Data.end(); I != E;
++I) {
uint8_t Byte = *I;
OS << hexdigit(Byte >> 4);
OS << hexdigit(Byte & 0xf);
}
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/SubtargetFeature.cpp | //===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the SubtargetFeature interface.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
using namespace llvm;
//===----------------------------------------------------------------------===//
// Static Helper Functions
//===----------------------------------------------------------------------===//
/// hasFlag - Determine if a feature has a flag; '+' or '-'
///
static inline bool hasFlag(StringRef Feature) {
assert(!Feature.empty() && "Empty string");
// Get first character
char Ch = Feature[0];
// Check if first character is '+' or '-' flag
return Ch == '+' || Ch =='-';
}
/// StripFlag - Return string stripped of flag.
///
static inline std::string StripFlag(StringRef Feature) {
return hasFlag(Feature) ? Feature.substr(1) : Feature;
}
/// isEnabled - Return true if enable flag; '+'.
///
static inline bool isEnabled(StringRef Feature) {
assert(!Feature.empty() && "Empty string");
// Get first character
char Ch = Feature[0];
// Check if first character is '+' for enabled
return Ch == '+';
}
/// Split - Splits a string of comma separated items in to a vector of strings.
///
static void Split(std::vector<std::string> &V, StringRef S) {
SmallVector<StringRef, 3> Tmp;
S.split(Tmp, ",", -1, false /* KeepEmpty */);
V.assign(Tmp.begin(), Tmp.end());
}
/// Adding features.
void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
// Don't add empty features.
if (!String.empty())
// Convert to lowercase, prepend flag if we don't already have a flag.
Features.push_back(hasFlag(String) ? String.lower()
: (Enable ? "+" : "-") + String.lower());
}
/// Find KV in array using binary search.
static const SubtargetFeatureKV *Find(StringRef S,
ArrayRef<SubtargetFeatureKV> A) {
// Binary search the array
auto F = std::lower_bound(A.begin(), A.end(), S);
// If not found then return NULL
if (F == A.end() || StringRef(F->Key) != S) return nullptr;
// Return the found array item
return F;
}
/// getLongestEntryLength - Return the length of the longest entry in the table.
///
static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
size_t MaxLen = 0;
for (auto &I : Table)
MaxLen = std::max(MaxLen, std::strlen(I.Key));
return MaxLen;
}
/// Display help for feature choices.
///
static void Help(ArrayRef<SubtargetFeatureKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatTable) {
// Determine the length of the longest CPU and Feature entries.
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
// Print the CPU table.
errs() << "Available CPUs for this target:\n\n";
for (auto &CPU : CPUTable)
errs() << format(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
errs() << '\n';
// Print the Feature table.
errs() << "Available features for this target:\n\n";
for (auto &Feature : FeatTable)
errs() << format(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
errs() << '\n';
errs() << "Use +feature to enable a feature, or -feature to disable it.\n"
"For example, llc -mcpu=mycpu -mattr=+feature1,-feature2\n";
}
//===----------------------------------------------------------------------===//
// SubtargetFeatures Implementation
//===----------------------------------------------------------------------===//
SubtargetFeatures::SubtargetFeatures(StringRef Initial) {
// Break up string into separate features
Split(Features, Initial);
}
std::string SubtargetFeatures::getString() const {
return join(Features.begin(), Features.end(), ",");
}
/// SetImpliedBits - For each feature that is (transitively) implied by this
/// feature, set it.
///
static
void SetImpliedBits(FeatureBitset &Bits, const SubtargetFeatureKV *FeatureEntry,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
for (auto &FE : FeatureTable) {
if (FeatureEntry->Value == FE.Value) continue;
if ((FeatureEntry->Implies & FE.Value).any()) {
Bits |= FE.Value;
SetImpliedBits(Bits, &FE, FeatureTable);
}
}
}
/// ClearImpliedBits - For each feature that (transitively) implies this
/// feature, clear it.
///
static
void ClearImpliedBits(FeatureBitset &Bits,
const SubtargetFeatureKV *FeatureEntry,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
for (auto &FE : FeatureTable) {
if (FeatureEntry->Value == FE.Value) continue;
if ((FE.Implies & FeatureEntry->Value).any()) {
Bits &= ~FE.Value;
ClearImpliedBits(Bits, &FE, FeatureTable);
}
}
}
/// ToggleFeature - Toggle a feature and returns the newly updated feature
/// bits.
FeatureBitset
SubtargetFeatures::ToggleFeature(FeatureBitset Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
// Find feature in table.
const SubtargetFeatureKV *FeatureEntry =
Find(StripFlag(Feature), FeatureTable);
// If there is a match
if (FeatureEntry) {
if ((Bits & FeatureEntry->Value) == FeatureEntry->Value) {
Bits &= ~FeatureEntry->Value;
// For each feature that implies this, clear it.
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
} else {
Bits |= FeatureEntry->Value;
// For each feature that this implies, set it.
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
}
} else {
errs() << "'" << Feature
<< "' is not a recognized feature for this target"
<< " (ignoring feature)\n";
}
return Bits;
}
FeatureBitset
SubtargetFeatures::ApplyFeatureFlag(FeatureBitset Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
assert(hasFlag(Feature));
// Find feature in table.
const SubtargetFeatureKV *FeatureEntry =
Find(StripFlag(Feature), FeatureTable);
// If there is a match
if (FeatureEntry) {
// Enable/disable feature in bits
if (isEnabled(Feature)) {
Bits |= FeatureEntry->Value;
// For each feature that this implies, set it.
SetImpliedBits(Bits, FeatureEntry, FeatureTable);
} else {
Bits &= ~FeatureEntry->Value;
// For each feature that implies this, clear it.
ClearImpliedBits(Bits, FeatureEntry, FeatureTable);
}
} else {
errs() << "'" << Feature
<< "' is not a recognized feature for this target"
<< " (ignoring feature)\n";
}
return Bits;
}
/// getFeatureBits - Get feature bits a CPU.
///
FeatureBitset
SubtargetFeatures::getFeatureBits(StringRef CPU,
ArrayRef<SubtargetFeatureKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
if (CPUTable.empty() || FeatureTable.empty())
return FeatureBitset();
#ifndef NDEBUG
for (size_t i = 1, e = CPUTable.size(); i != e; ++i) {
assert(strcmp(CPUTable[i - 1].Key, CPUTable[i].Key) < 0 &&
"CPU table is not sorted");
}
for (size_t i = 1, e = FeatureTable.size(); i != e; ++i) {
assert(strcmp(FeatureTable[i - 1].Key, FeatureTable[i].Key) < 0 &&
"CPU features table is not sorted");
}
#endif
// Resulting bits
FeatureBitset Bits;
// Check if help is needed
if (CPU == "help")
Help(CPUTable, FeatureTable);
// Find CPU entry if CPU name is specified.
else if (!CPU.empty()) {
const SubtargetFeatureKV *CPUEntry = Find(CPU, CPUTable);
// If there is a match
if (CPUEntry) {
// Set base feature bits
Bits = CPUEntry->Value;
// Set the feature implied by this CPU feature, if any.
for (auto &FE : FeatureTable) {
if ((CPUEntry->Value & FE.Value).any())
SetImpliedBits(Bits, &FE, FeatureTable);
}
} else {
errs() << "'" << CPU
<< "' is not a recognized processor for this target"
<< " (ignoring processor)\n";
}
}
// Iterate through each feature
for (auto &Feature : Features) {
// Check for help
if (Feature == "+help")
Help(CPUTable, FeatureTable);
Bits = ApplyFeatureFlag(Bits, Feature, FeatureTable);
}
return Bits;
}
/// print - Print feature string.
///
void SubtargetFeatures::print(raw_ostream &OS) const {
for (auto &F : Features)
OS << F << " ";
OS << "\n";
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// dump - Dump feature info.
///
void SubtargetFeatures::dump() const {
print(dbgs());
}
#endif
/// Adds the default features for the specified target triple.
///
/// FIXME: This is an inelegant way of specifying the features of a
/// subtarget. It would be better if we could encode this information
/// into the IR. See <rdar://5972456>.
///
void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) {
if (Triple.getVendor() == Triple::Apple) {
if (Triple.getArch() == Triple::ppc) {
// powerpc-apple-*
AddFeature("altivec");
} else if (Triple.getArch() == Triple::ppc64) {
// powerpc64-apple-*
AddFeature("64bit");
AddFeature("altivec");
}
}
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCInstrDesc.cpp | //===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines methods on the MCOperandInfo and MCInstrDesc classes, which
// are used to describe target instructions and their operands.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
using namespace llvm;
bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
std::string &Info) const {
if (ComplexDeprecationInfo)
return ComplexDeprecationInfo(MI, STI, Info);
if (DeprecatedFeature != -1 && STI.getFeatureBits()[DeprecatedFeature]) {
// FIXME: it would be nice to include the subtarget feature here.
Info = "deprecated";
return true;
}
return false;
}
bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI,
const MCRegisterInfo &RI) const {
if (isBranch() || isCall() || isReturn() || isIndirectBranch())
return true;
unsigned PC = RI.getProgramCounter();
if (PC == 0)
return false;
if (hasDefOfPhysReg(MI, PC, RI))
return true;
// A variadic instruction may define PC in the variable operand list.
// There's currently no indication of which entries in a variable
// list are defs and which are uses. While that's the case, this function
// needs to assume they're defs in order to be conservatively correct.
for (int i = NumOperands, e = MI.getNumOperands(); i != e; ++i) {
if (MI.getOperand(i).isReg() &&
RI.isSubRegisterEq(PC, MI.getOperand(i).getReg()))
return true;
}
return false;
}
bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
const MCRegisterInfo *MRI) const {
if (const uint16_t *ImpDefs = ImplicitDefs)
for (; *ImpDefs; ++ImpDefs)
if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
return true;
return false;
}
bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
const MCRegisterInfo &RI) const {
for (int i = 0, e = NumDefs; i != e; ++i)
if (MI.getOperand(i).isReg() &&
RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
return true;
return hasImplicitDefOfPhysReg(Reg, &RI);
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCInstrAnalysis.cpp | //===-- MCInstrAnalysis.cpp - InstrDesc target hooks ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCInstrAnalysis.h"
using namespace llvm;
bool MCInstrAnalysis::evaluateBranch(const MCInst &Inst, uint64_t Addr,
uint64_t Size, uint64_t &Target) const {
if (Inst.getNumOperands() == 0 ||
Info->get(Inst.getOpcode()).OpInfo[0].OperandType != MCOI::OPERAND_PCREL)
return false;
int64_t Imm = Inst.getOperand(0).getImm();
Target = Addr+Size+Imm;
return true;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCObjectStreamer.cpp | //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetRegistry.h"
using namespace llvm;
MCObjectStreamer::MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB,
raw_pwrite_stream &OS,
MCCodeEmitter *Emitter_)
: MCStreamer(Context),
Assembler(new MCAssembler(Context, TAB, *Emitter_,
*TAB.createObjectWriter(OS), OS)),
EmitEHFrame(true), EmitDebugFrame(false) {}
MCObjectStreamer::~MCObjectStreamer() {
delete &Assembler->getBackend();
delete &Assembler->getEmitter();
delete &Assembler->getWriter();
delete Assembler;
}
void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) {
if (PendingLabels.size()) {
if (!F) {
F = new MCDataFragment();
MCSection *CurSection = getCurrentSectionOnly();
CurSection->getFragmentList().insert(CurInsertionPoint, F);
F->setParent(CurSection);
}
for (MCSymbol *Sym : PendingLabels) {
Sym->setFragment(F);
Sym->setOffset(FOffset);
}
PendingLabels.clear();
}
}
void MCObjectStreamer::emitAbsoluteSymbolDiff(const MCSymbol *Hi,
const MCSymbol *Lo,
unsigned Size) {
// If not assigned to the same (valid) fragment, fallback.
if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment()) {
MCStreamer::emitAbsoluteSymbolDiff(Hi, Lo, Size);
return;
}
assert(Hi->getOffset() >= Lo->getOffset() &&
"Expected Hi to be greater than Lo");
EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size);
}
void MCObjectStreamer::reset() {
if (Assembler)
Assembler->reset();
CurInsertionPoint = MCSection::iterator();
EmitEHFrame = true;
EmitDebugFrame = false;
PendingLabels.clear();
MCStreamer::reset();
}
void MCObjectStreamer::EmitFrames(MCAsmBackend *MAB) {
if (!getNumFrameInfos())
return;
if (EmitEHFrame)
MCDwarfFrameEmitter::Emit(*this, MAB, true);
if (EmitDebugFrame)
MCDwarfFrameEmitter::Emit(*this, MAB, false);
}
MCFragment *MCObjectStreamer::getCurrentFragment() const {
assert(getCurrentSectionOnly() && "No current section!");
if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
return std::prev(CurInsertionPoint);
return nullptr;
}
MCDataFragment *MCObjectStreamer::getOrCreateDataFragment() {
MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
// When bundling is enabled, we don't want to add data to a fragment that
// already has instructions (see MCELFStreamer::EmitInstToData for details)
if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
F->hasInstructions())) {
F = new MCDataFragment();
insert(F);
}
return F;
}
void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
Assembler->registerSymbol(Sym);
}
void MCObjectStreamer::EmitCFISections(bool EH, bool Debug) {
MCStreamer::EmitCFISections(EH, Debug);
EmitEHFrame = EH;
EmitDebugFrame = Debug;
}
void MCObjectStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
const SMLoc &Loc) {
MCStreamer::EmitValueImpl(Value, Size, Loc);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
MCLineEntry::Make(this, getCurrentSection().first);
// Avoid fixups when possible.
int64_t AbsValue;
if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
EmitIntValue(AbsValue, Size);
return;
}
DF->getFixups().push_back(
MCFixup::create(DF->getContents().size(), Value,
MCFixup::getKindForSize(Size, false), Loc));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
// We need to create a local symbol to avoid relocations.
Frame.Begin = getContext().createTempSymbol();
EmitLabel(Frame.Begin);
}
void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
Frame.End = getContext().createTempSymbol();
EmitLabel(Frame.End);
}
void MCObjectStreamer::EmitLabel(MCSymbol *Symbol) {
MCStreamer::EmitLabel(Symbol);
getAssembler().registerSymbol(*Symbol);
assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
// If there is a current fragment, mark the symbol as pointing into it.
// Otherwise queue the label and set its fragment pointer when we emit the
// next fragment.
auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
if (F && !(getAssembler().isBundlingEnabled() &&
getAssembler().getRelaxAll())) {
Symbol->setFragment(F);
Symbol->setOffset(F->getContents().size());
} else {
PendingLabels.push_back(Symbol);
}
}
void MCObjectStreamer::EmitULEB128Value(const MCExpr *Value) {
int64_t IntValue;
if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
EmitULEB128IntValue(IntValue);
return;
}
insert(new MCLEBFragment(*Value, false));
}
void MCObjectStreamer::EmitSLEB128Value(const MCExpr *Value) {
int64_t IntValue;
if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
EmitSLEB128IntValue(IntValue);
return;
}
insert(new MCLEBFragment(*Value, true));
}
void MCObjectStreamer::EmitWeakReference(MCSymbol *Alias,
const MCSymbol *Symbol) {
report_fatal_error("This file format doesn't support weak aliases.");
}
void MCObjectStreamer::ChangeSection(MCSection *Section,
const MCExpr *Subsection) {
changeSectionImpl(Section, Subsection);
}
bool MCObjectStreamer::changeSectionImpl(MCSection *Section,
const MCExpr *Subsection) {
assert(Section && "Cannot switch to a null section!");
flushPendingLabels(nullptr);
bool Created = getAssembler().registerSection(*Section);
int64_t IntSubsection = 0;
if (Subsection &&
!Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
report_fatal_error("Cannot evaluate subsection number");
if (IntSubsection < 0 || IntSubsection > 8192)
report_fatal_error("Subsection number out of range");
CurInsertionPoint =
Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
return Created;
}
void MCObjectStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
getAssembler().registerSymbol(*Symbol);
MCStreamer::EmitAssignment(Symbol, Value);
}
bool MCObjectStreamer::mayHaveInstructions(MCSection &Sec) const {
return Sec.hasInstructions();
}
void MCObjectStreamer::EmitInstruction(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCStreamer::EmitInstruction(Inst, STI);
MCSection *Sec = getCurrentSectionOnly();
Sec->setHasInstructions(true);
// Now that a machine instruction has been assembled into this section, make
// a line entry for any .loc directive that has been seen.
MCLineEntry::Make(this, getCurrentSection().first);
// If this instruction doesn't need relaxation, just emit it as data.
MCAssembler &Assembler = getAssembler();
if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
EmitInstToData(Inst, STI);
return;
}
// Otherwise, relax and emit it as data if either:
// - The RelaxAll flag was passed
// - Bundling is enabled and this instruction is inside a bundle-locked
// group. We want to emit all such instructions into the same data
// fragment.
if (Assembler.getRelaxAll() ||
(Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
MCInst Relaxed;
getAssembler().getBackend().relaxInstruction(Inst, Relaxed);
while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
getAssembler().getBackend().relaxInstruction(Relaxed, Relaxed);
EmitInstToData(Relaxed, STI);
return;
}
// Otherwise emit to a separate fragment.
EmitInstToFragment(Inst, STI);
}
void MCObjectStreamer::EmitInstToFragment(const MCInst &Inst,
const MCSubtargetInfo &STI) {
if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
llvm_unreachable("All instructions should have already been relaxed");
// Always create a new, separate fragment here, because its size can change
// during relaxation.
MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
insert(IF);
SmallString<128> Code;
raw_svector_ostream VecOS(Code);
getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
STI);
VecOS.flush();
IF->getContents().append(Code.begin(), Code.end());
}
static const char *const BundlingNotImplementedMsg =
"Aligned bundling is not implemented for this object format";
void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
llvm_unreachable(BundlingNotImplementedMsg);
}
void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
llvm_unreachable(BundlingNotImplementedMsg);
}
void MCObjectStreamer::EmitBundleUnlock() {
llvm_unreachable(BundlingNotImplementedMsg);
}
void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
unsigned Column, unsigned Flags,
unsigned Isa,
unsigned Discriminator,
StringRef FileName) {
// In case we see two .loc directives in a row, make sure the
// first one gets a line entry.
MCLineEntry::Make(this, getCurrentSection().first);
this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
Isa, Discriminator, FileName);
}
static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
const MCSymbol *B) {
MCContext &Context = OS.getContext();
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
const MCExpr *AddrDelta =
MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
return AddrDelta;
}
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, int64_t LineDelta,
const MCSymbol *Label, int PointerSize) {
// emit the sequence to set the address
OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
OS.EmitULEB128IntValue(PointerSize + 1);
OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
OS.EmitSymbolValue(Label, PointerSize);
// emit the sequence for the LineDelta (from 1) and a zero address delta.
MCDwarfLineAddr::Emit(&OS, LineDelta, 0);
}
void MCObjectStreamer::EmitDwarfAdvanceLineAddr(int64_t LineDelta,
const MCSymbol *LastLabel,
const MCSymbol *Label,
unsigned PointerSize) {
if (!LastLabel) {
emitDwarfSetLineAddr(*this, LineDelta, Label, PointerSize);
return;
}
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
int64_t Res;
if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
MCDwarfLineAddr::Emit(this, LineDelta, Res);
return;
}
insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
}
void MCObjectStreamer::EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
const MCSymbol *Label) {
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
int64_t Res;
if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
MCDwarfFrameEmitter::EmitAdvanceLoc(*this, Res);
return;
}
insert(new MCDwarfCallFrameFragment(*AddrDelta));
}
void MCObjectStreamer::EmitBytes(StringRef Data) {
MCLineEntry::Make(this, getCurrentSection().first);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getContents().append(Data.begin(), Data.end());
}
void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
if (MaxBytesToEmit == 0)
MaxBytesToEmit = ByteAlignment;
insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
// Update the maximum alignment on the current section if necessary.
MCSection *CurSec = getCurrentSection().first;
if (ByteAlignment > CurSec->getAlignment())
CurSec->setAlignment(ByteAlignment);
}
void MCObjectStreamer::EmitCodeAlignment(unsigned ByteAlignment,
unsigned MaxBytesToEmit) {
EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
}
bool MCObjectStreamer::EmitValueToOffset(const MCExpr *Offset,
unsigned char Value) {
int64_t Res;
if (Offset->evaluateAsAbsolute(Res, getAssembler())) {
insert(new MCOrgFragment(*Offset, Value));
return false;
}
MCSymbol *CurrentPos = getContext().createTempSymbol();
EmitLabel(CurrentPos);
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
const MCExpr *Ref =
MCSymbolRefExpr::create(CurrentPos, Variant, getContext());
const MCExpr *Delta =
MCBinaryExpr::create(MCBinaryExpr::Sub, Offset, Ref, getContext());
if (!Delta->evaluateAsAbsolute(Res, getAssembler()))
return true;
EmitFill(Res, Value);
return false;
}
// Associate GPRel32 fixup with data and resize data area
void MCObjectStreamer::EmitGPRel32Value(const MCExpr *Value) {
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
Value, FK_GPRel_4));
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
// Associate GPRel32 fixup with data and resize data area
void MCObjectStreamer::EmitGPRel64Value(const MCExpr *Value) {
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
Value, FK_GPRel_4));
DF->getContents().resize(DF->getContents().size() + 8, 0);
}
void MCObjectStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) {
// FIXME: A MCFillFragment would be more memory efficient but MCExpr has
// problems evaluating expressions across multiple fragments.
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
DF->getContents().append(NumBytes, FillValue);
}
void MCObjectStreamer::EmitZeros(uint64_t NumBytes) {
const MCSection *Sec = getCurrentSection().first;
assert(Sec && "need a section");
unsigned ItemSize = Sec->isVirtualSection() ? 0 : 1;
insert(new MCFillFragment(0, ItemSize, NumBytes));
}
void MCObjectStreamer::FinishImpl() {
// If we are generating dwarf for assembly source files dump out the sections.
if (getContext().getGenDwarfForAssembly())
MCGenDwarfInfo::Emit(this);
// Dump out the dwarf file & directory tables and line tables.
MCDwarfLineTable::Emit(this);
flushPendingLabels(nullptr);
getAssembler().Finish();
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCELFStreamer.cpp | //===- lib/MC/MCELFStreamer.cpp - ELF Object Output -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file assembles .s files and emits ELF .o object files.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCELFStreamer.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
bool MCELFStreamer::isBundleLocked() const {
return getCurrentSectionOnly()->isBundleLocked();
}
MCELFStreamer::~MCELFStreamer() {
}
void MCELFStreamer::mergeFragment(MCDataFragment *DF,
MCDataFragment *EF) {
MCAssembler &Assembler = getAssembler();
if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
uint64_t FSize = EF->getContents().size();
if (FSize > Assembler.getBundleAlignSize())
report_fatal_error("Fragment can't be larger than a bundle size");
uint64_t RequiredBundlePadding = computeBundlePadding(
Assembler, EF, DF->getContents().size(), FSize);
if (RequiredBundlePadding > UINT8_MAX)
report_fatal_error("Padding cannot exceed 255 bytes");
if (RequiredBundlePadding > 0) {
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
MCObjectWriter *OW = Assembler.getBackend().createObjectWriter(VecOS);
EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
Assembler.writeFragmentPadding(*EF, FSize, OW);
VecOS.flush();
delete OW;
DF->getContents().append(Code.begin(), Code.end());
}
}
flushPendingLabels(DF, DF->getContents().size());
for (unsigned i = 0, e = EF->getFixups().size(); i != e; ++i) {
EF->getFixups()[i].setOffset(EF->getFixups()[i].getOffset() +
DF->getContents().size());
DF->getFixups().push_back(EF->getFixups()[i]);
}
DF->setHasInstructions(true);
DF->getContents().append(EF->getContents().begin(), EF->getContents().end());
}
void MCELFStreamer::InitSections(bool NoExecStack) {
// This emulates the same behavior of GNU as. This makes it easier
// to compare the output as the major sections are in the same order.
MCContext &Ctx = getContext();
SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
EmitCodeAlignment(4);
SwitchSection(Ctx.getObjectFileInfo()->getDataSection());
EmitCodeAlignment(4);
SwitchSection(Ctx.getObjectFileInfo()->getBSSSection());
EmitCodeAlignment(4);
SwitchSection(Ctx.getObjectFileInfo()->getTextSection());
if (NoExecStack)
SwitchSection(Ctx.getAsmInfo()->getNonexecutableStackSection(Ctx));
}
void MCELFStreamer::EmitLabel(MCSymbol *S) {
auto *Symbol = cast<MCSymbolELF>(S);
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
MCObjectStreamer::EmitLabel(Symbol);
const MCSectionELF &Section =
static_cast<const MCSectionELF&>(Symbol->getSection());
if (Section.getFlags() & ELF::SHF_TLS)
Symbol->setType(ELF::STT_TLS);
}
void MCELFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
// Let the target do whatever target specific stuff it needs to do.
getAssembler().getBackend().handleAssemblerFlag(Flag);
// Do any generic stuff we need to do.
switch (Flag) {
case MCAF_SyntaxUnified: return; // no-op here.
case MCAF_Code16: return; // Change parsing mode; no-op here.
case MCAF_Code32: return; // Change parsing mode; no-op here.
case MCAF_Code64: return; // Change parsing mode; no-op here.
case MCAF_SubsectionsViaSymbols:
getAssembler().setSubsectionsViaSymbols(true);
return;
}
llvm_unreachable("invalid assembler flag!");
}
// If bundle aligment is used and there are any instructions in the section, it
// needs to be aligned to at least the bundle size.
static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
MCSection *Section) {
if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
Section->getAlignment() < Assembler.getBundleAlignSize())
Section->setAlignment(Assembler.getBundleAlignSize());
}
void MCELFStreamer::ChangeSection(MCSection *Section,
const MCExpr *Subsection) {
MCSection *CurSection = getCurrentSectionOnly();
if (CurSection && isBundleLocked())
report_fatal_error("Unterminated .bundle_lock when changing a section");
MCAssembler &Asm = getAssembler();
// Ensure the previous section gets aligned if necessary.
setSectionAlignmentForBundling(Asm, CurSection);
auto *SectionELF = static_cast<const MCSectionELF *>(Section);
const MCSymbol *Grp = SectionELF->getGroup();
if (Grp)
Asm.registerSymbol(*Grp);
this->MCObjectStreamer::ChangeSection(Section, Subsection);
MCContext &Ctx = getContext();
auto *Begin = cast_or_null<MCSymbolELF>(Section->getBeginSymbol());
if (!Begin) {
Begin = Ctx.getOrCreateSectionSymbol(*SectionELF);
Section->setBeginSymbol(Begin);
}
if (Begin->isUndefined()) {
Asm.registerSymbol(*Begin);
Begin->setType(ELF::STT_SECTION);
}
}
void MCELFStreamer::EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {
getAssembler().registerSymbol(*Symbol);
const MCExpr *Value = MCSymbolRefExpr::create(
Symbol, MCSymbolRefExpr::VK_WEAKREF, getContext());
Alias->setVariableValue(Value);
}
// When GNU as encounters more than one .type declaration for an object it seems
// to use a mechanism similar to the one below to decide which type is actually
// used in the object file. The greater of T1 and T2 is selected based on the
// following ordering:
// STT_NOTYPE < STT_OBJECT < STT_FUNC < STT_GNU_IFUNC < STT_TLS < anything else
// If neither T1 < T2 nor T2 < T1 according to this ordering, use T2 (the user
// provided type).
static unsigned CombineSymbolTypes(unsigned T1, unsigned T2) {
for (unsigned Type : {ELF::STT_NOTYPE, ELF::STT_OBJECT, ELF::STT_FUNC,
ELF::STT_GNU_IFUNC, ELF::STT_TLS}) {
if (T1 == Type)
return T2;
if (T2 == Type)
return T1;
}
return T2;
}
bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
auto *Symbol = cast<MCSymbolELF>(S);
// Indirect symbols are handled differently, to match how 'as' handles
// them. This makes writing matching .o files easier.
if (Attribute == MCSA_IndirectSymbol) {
// Note that we intentionally cannot use the symbol data here; this is
// important for matching the string table that 'as' generates.
IndirectSymbolData ISD;
ISD.Symbol = Symbol;
ISD.Section = getCurrentSectionOnly();
getAssembler().getIndirectSymbols().push_back(ISD);
return true;
}
// Adding a symbol attribute always introduces the symbol, note that an
// important side effect of calling registerSymbol here is to register
// the symbol with the assembler.
getAssembler().registerSymbol(*Symbol);
// The implementation of symbol attributes is designed to match 'as', but it
// leaves much to desired. It doesn't really make sense to arbitrarily add and
// remove flags, but 'as' allows this (in particular, see .desc).
//
// In the future it might be worth trying to make these operations more well
// defined.
switch (Attribute) {
case MCSA_LazyReference:
case MCSA_Reference:
case MCSA_SymbolResolver:
case MCSA_PrivateExtern:
case MCSA_WeakDefinition:
case MCSA_WeakDefAutoPrivate:
case MCSA_Invalid:
case MCSA_IndirectSymbol:
return false;
case MCSA_NoDeadStrip:
// Ignore for now.
break;
case MCSA_ELF_TypeGnuUniqueObject:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
Symbol->setBinding(ELF::STB_GNU_UNIQUE);
Symbol->setExternal(true);
break;
case MCSA_Global:
Symbol->setBinding(ELF::STB_GLOBAL);
Symbol->setExternal(true);
break;
case MCSA_WeakReference:
case MCSA_Weak:
Symbol->setBinding(ELF::STB_WEAK);
Symbol->setExternal(true);
break;
case MCSA_Local:
Symbol->setBinding(ELF::STB_LOCAL);
Symbol->setExternal(false);
break;
case MCSA_ELF_TypeFunction:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_FUNC));
break;
case MCSA_ELF_TypeIndFunction:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_GNU_IFUNC));
break;
case MCSA_ELF_TypeObject:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
break;
case MCSA_ELF_TypeTLS:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_TLS));
break;
case MCSA_ELF_TypeCommon:
// TODO: Emit these as a common symbol.
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_OBJECT));
break;
case MCSA_ELF_TypeNoType:
Symbol->setType(CombineSymbolTypes(Symbol->getType(), ELF::STT_NOTYPE));
break;
case MCSA_Protected:
Symbol->setVisibility(ELF::STV_PROTECTED);
break;
case MCSA_Hidden:
Symbol->setVisibility(ELF::STV_HIDDEN);
break;
case MCSA_Internal:
Symbol->setVisibility(ELF::STV_INTERNAL);
break;
}
return true;
}
void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
auto *Symbol = cast<MCSymbolELF>(S);
getAssembler().registerSymbol(*Symbol);
if (!Symbol->isBindingSet()) {
Symbol->setBinding(ELF::STB_GLOBAL);
Symbol->setExternal(true);
}
Symbol->setType(ELF::STT_OBJECT);
if (Symbol->getBinding() == ELF::STB_LOCAL) {
MCSection *Section = getAssembler().getContext().getELFSection(
".bss", ELF::SHT_NOBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC);
AssignSection(Symbol, Section);
struct LocalCommon L = {Symbol, Size, ByteAlignment};
LocalCommons.push_back(L);
} else {
if(Symbol->declareCommon(Size, ByteAlignment))
report_fatal_error("Symbol: " + Symbol->getName() +
" redeclared as different type");
}
cast<MCSymbolELF>(Symbol)
->setSize(MCConstantExpr::create(Size, getContext()));
}
void MCELFStreamer::emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value) {
Symbol->setSize(Value);
}
void MCELFStreamer::EmitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
unsigned ByteAlignment) {
auto *Symbol = cast<MCSymbolELF>(S);
// FIXME: Should this be caught and done earlier?
getAssembler().registerSymbol(*Symbol);
Symbol->setBinding(ELF::STB_LOCAL);
Symbol->setExternal(false);
EmitCommonSymbol(Symbol, Size, ByteAlignment);
}
void MCELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
const SMLoc &Loc) {
if (isBundleLocked())
report_fatal_error("Emitting values inside a locked bundle is forbidden");
fixSymbolsInTLSFixups(Value);
MCObjectStreamer::EmitValueImpl(Value, Size, Loc);
}
void MCELFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
if (isBundleLocked())
report_fatal_error("Emitting values inside a locked bundle is forbidden");
MCObjectStreamer::EmitValueToAlignment(ByteAlignment, Value,
ValueSize, MaxBytesToEmit);
}
// Add a symbol for the file name of this module. They start after the
// null symbol and don't count as normal symbol, i.e. a non-STT_FILE symbol
// with the same name may appear.
void MCELFStreamer::EmitFileDirective(StringRef Filename) {
getAssembler().addFileName(Filename);
}
void MCELFStreamer::EmitIdent(StringRef IdentString) {
MCSection *Comment = getAssembler().getContext().getELFSection(
".comment", ELF::SHT_PROGBITS, ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, "");
PushSection();
SwitchSection(Comment);
if (!SeenIdent) {
EmitIntValue(0, 1);
SeenIdent = true;
}
EmitBytes(IdentString);
EmitIntValue(0, 1);
PopSection();
}
void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
switch (expr->getKind()) {
case MCExpr::Target:
cast<MCTargetExpr>(expr)->fixELFSymbolsInTLSFixups(getAssembler());
break;
case MCExpr::Constant:
break;
case MCExpr::Binary: {
const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
fixSymbolsInTLSFixups(be->getLHS());
fixSymbolsInTLSFixups(be->getRHS());
break;
}
case MCExpr::SymbolRef: {
const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
switch (symRef.getKind()) {
default:
return;
case MCSymbolRefExpr::VK_GOTTPOFF:
case MCSymbolRefExpr::VK_INDNTPOFF:
case MCSymbolRefExpr::VK_NTPOFF:
case MCSymbolRefExpr::VK_GOTNTPOFF:
case MCSymbolRefExpr::VK_TLSGD:
case MCSymbolRefExpr::VK_TLSLD:
case MCSymbolRefExpr::VK_TLSLDM:
case MCSymbolRefExpr::VK_TPOFF:
case MCSymbolRefExpr::VK_DTPOFF:
case MCSymbolRefExpr::VK_Mips_TLSGD:
case MCSymbolRefExpr::VK_Mips_GOTTPREL:
case MCSymbolRefExpr::VK_Mips_TPREL_HI:
case MCSymbolRefExpr::VK_Mips_TPREL_LO:
case MCSymbolRefExpr::VK_PPC_DTPMOD:
case MCSymbolRefExpr::VK_PPC_TPREL:
case MCSymbolRefExpr::VK_PPC_TPREL_LO:
case MCSymbolRefExpr::VK_PPC_TPREL_HI:
case MCSymbolRefExpr::VK_PPC_TPREL_HA:
case MCSymbolRefExpr::VK_PPC_TPREL_HIGHER:
case MCSymbolRefExpr::VK_PPC_TPREL_HIGHERA:
case MCSymbolRefExpr::VK_PPC_TPREL_HIGHEST:
case MCSymbolRefExpr::VK_PPC_TPREL_HIGHESTA:
case MCSymbolRefExpr::VK_PPC_DTPREL:
case MCSymbolRefExpr::VK_PPC_DTPREL_LO:
case MCSymbolRefExpr::VK_PPC_DTPREL_HI:
case MCSymbolRefExpr::VK_PPC_DTPREL_HA:
case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHER:
case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHERA:
case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHEST:
case MCSymbolRefExpr::VK_PPC_DTPREL_HIGHESTA:
case MCSymbolRefExpr::VK_PPC_GOT_TPREL:
case MCSymbolRefExpr::VK_PPC_GOT_TPREL_LO:
case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HI:
case MCSymbolRefExpr::VK_PPC_GOT_TPREL_HA:
case MCSymbolRefExpr::VK_PPC_GOT_DTPREL:
case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_LO:
case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HI:
case MCSymbolRefExpr::VK_PPC_GOT_DTPREL_HA:
case MCSymbolRefExpr::VK_PPC_TLS:
case MCSymbolRefExpr::VK_PPC_GOT_TLSGD:
case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_LO:
case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HI:
case MCSymbolRefExpr::VK_PPC_GOT_TLSGD_HA:
case MCSymbolRefExpr::VK_PPC_TLSGD:
case MCSymbolRefExpr::VK_PPC_GOT_TLSLD:
case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_LO:
case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HI:
case MCSymbolRefExpr::VK_PPC_GOT_TLSLD_HA:
case MCSymbolRefExpr::VK_PPC_TLSLD:
break;
}
getAssembler().registerSymbol(symRef.getSymbol());
cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
break;
}
case MCExpr::Unary:
fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
break;
}
}
void MCELFStreamer::EmitInstToFragment(const MCInst &Inst,
const MCSubtargetInfo &STI) {
this->MCObjectStreamer::EmitInstToFragment(Inst, STI);
MCRelaxableFragment &F = *cast<MCRelaxableFragment>(getCurrentFragment());
for (unsigned i = 0, e = F.getFixups().size(); i != e; ++i)
fixSymbolsInTLSFixups(F.getFixups()[i].getValue());
}
void MCELFStreamer::EmitInstToData(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCAssembler &Assembler = getAssembler();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
Assembler.getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
VecOS.flush();
for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
fixSymbolsInTLSFixups(Fixups[i].getValue());
// There are several possibilities here:
//
// If bundling is disabled, append the encoded instruction to the current data
// fragment (or create a new such fragment if the current fragment is not a
// data fragment).
//
// If bundling is enabled:
// - If we're not in a bundle-locked group, emit the instruction into a
// fragment of its own. If there are no fixups registered for the
// instruction, emit a MCCompactEncodedInstFragment. Otherwise, emit a
// MCDataFragment.
// - If we're in a bundle-locked group, append the instruction to the current
// data fragment because we want all the instructions in a group to get into
// the same fragment. Be careful not to do that for the first instruction in
// the group, though.
MCDataFragment *DF;
if (Assembler.isBundlingEnabled()) {
MCSection &Sec = *getCurrentSectionOnly();
if (Assembler.getRelaxAll() && isBundleLocked())
// If the -mc-relax-all flag is used and we are bundle-locked, we re-use
// the current bundle group.
DF = BundleGroups.back();
else if (Assembler.getRelaxAll() && !isBundleLocked())
// When not in a bundle-locked group and the -mc-relax-all flag is used,
// we create a new temporary fragment which will be later merged into
// the current fragment.
DF = new MCDataFragment();
else if (isBundleLocked() && !Sec.isBundleGroupBeforeFirstInst())
// If we are bundle-locked, we re-use the current fragment.
// The bundle-locking directive ensures this is a new data fragment.
DF = cast<MCDataFragment>(getCurrentFragment());
else if (!isBundleLocked() && Fixups.size() == 0) {
// Optimize memory usage by emitting the instruction to a
// MCCompactEncodedInstFragment when not in a bundle-locked group and
// there are no fixups registered.
MCCompactEncodedInstFragment *CEIF = new MCCompactEncodedInstFragment();
insert(CEIF);
CEIF->getContents().append(Code.begin(), Code.end());
return;
} else {
DF = new MCDataFragment();
insert(DF);
}
if (Sec.getBundleLockState() == MCSection::BundleLockedAlignToEnd) {
// If this fragment is for a group marked "align_to_end", set a flag
// in the fragment. This can happen after the fragment has already been
// created if there are nested bundle_align groups and an inner one
// is the one marked align_to_end.
DF->setAlignToBundleEnd(true);
}
// We're now emitting an instruction in a bundle group, so this flag has
// to be turned off.
Sec.setBundleGroupBeforeFirstInst(false);
} else {
DF = getOrCreateDataFragment();
}
// Add the fixups and data.
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
DF->getFixups().push_back(Fixups[i]);
}
DF->setHasInstructions(true);
DF->getContents().append(Code.begin(), Code.end());
if (Assembler.isBundlingEnabled() && Assembler.getRelaxAll()) {
if (!isBundleLocked()) {
mergeFragment(getOrCreateDataFragment(), DF);
delete DF;
}
}
}
void MCELFStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
assert(AlignPow2 <= 30 && "Invalid bundle alignment");
MCAssembler &Assembler = getAssembler();
if (AlignPow2 > 0 && (Assembler.getBundleAlignSize() == 0 ||
Assembler.getBundleAlignSize() == 1U << AlignPow2))
Assembler.setBundleAlignSize(1U << AlignPow2);
else
report_fatal_error(".bundle_align_mode cannot be changed once set");
}
void MCELFStreamer::EmitBundleLock(bool AlignToEnd) {
MCSection &Sec = *getCurrentSectionOnly();
// Sanity checks
//
if (!getAssembler().isBundlingEnabled())
report_fatal_error(".bundle_lock forbidden when bundling is disabled");
if (!isBundleLocked())
Sec.setBundleGroupBeforeFirstInst(true);
if (getAssembler().getRelaxAll() && !isBundleLocked()) {
// TODO: drop the lock state and set directly in the fragment
MCDataFragment *DF = new MCDataFragment();
BundleGroups.push_back(DF);
}
Sec.setBundleLockState(AlignToEnd ? MCSection::BundleLockedAlignToEnd
: MCSection::BundleLocked);
}
void MCELFStreamer::EmitBundleUnlock() {
MCSection &Sec = *getCurrentSectionOnly();
// Sanity checks
if (!getAssembler().isBundlingEnabled())
report_fatal_error(".bundle_unlock forbidden when bundling is disabled");
else if (!isBundleLocked())
report_fatal_error(".bundle_unlock without matching lock");
else if (Sec.isBundleGroupBeforeFirstInst())
report_fatal_error("Empty bundle-locked group is forbidden");
// When the -mc-relax-all flag is used, we emit instructions to fragments
// stored on a stack. When the bundle unlock is emited, we pop a fragment
// from the stack a merge it to the one below.
if (getAssembler().getRelaxAll()) {
assert(!BundleGroups.empty() && "There are no bundle groups");
MCDataFragment *DF = BundleGroups.back();
// FIXME: Use BundleGroups to track the lock state instead.
Sec.setBundleLockState(MCSection::NotBundleLocked);
// FIXME: Use more separate fragments for nested groups.
if (!isBundleLocked()) {
mergeFragment(getOrCreateDataFragment(), DF);
BundleGroups.pop_back();
delete DF;
}
if (Sec.getBundleLockState() != MCSection::BundleLockedAlignToEnd)
getOrCreateDataFragment()->setAlignToBundleEnd(false);
} else
Sec.setBundleLockState(MCSection::NotBundleLocked);
}
void MCELFStreamer::Flush() {
for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
e = LocalCommons.end();
i != e; ++i) {
const MCSymbol &Symbol = *i->Symbol;
uint64_t Size = i->Size;
unsigned ByteAlignment = i->ByteAlignment;
MCSection &Section = Symbol.getSection();
getAssembler().registerSection(Section);
new MCAlignFragment(ByteAlignment, 0, 1, ByteAlignment, &Section);
MCFragment *F = new MCFillFragment(0, 0, Size, &Section);
Symbol.setFragment(F);
// Update the maximum alignment of the section if necessary.
if (ByteAlignment > Section.getAlignment())
Section.setAlignment(ByteAlignment);
}
LocalCommons.clear();
}
void MCELFStreamer::FinishImpl() {
// Ensure the last section gets aligned if necessary.
MCSection *CurSection = getCurrentSectionOnly();
setSectionAlignmentForBundling(getAssembler(), CurSection);
EmitFrames(nullptr);
Flush();
this->MCObjectStreamer::FinishImpl();
}
MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,
raw_pwrite_stream &OS, MCCodeEmitter *CE,
bool RelaxAll) {
MCELFStreamer *S = new MCELFStreamer(Context, MAB, OS, CE);
if (RelaxAll)
S->getAssembler().setRelaxAll(true);
return S;
}
void MCELFStreamer::EmitThumbFunc(MCSymbol *Func) {
llvm_unreachable("Generic ELF doesn't support this directive");
}
void MCELFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::EmitCOFFSymbolType(int Type) {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::EndCOFFSymbolDef() {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
llvm_unreachable("ELF doesn't support this directive");
}
void MCELFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
llvm_unreachable("ELF doesn't support this directive");
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCAsmInfoCOFF.cpp | //===-- MCAsmInfoCOFF.cpp - COFF asm properties -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines target asm properties related what form asm statements
// should take in general on COFF-based targets
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmInfoCOFF.h"
using namespace llvm;
void MCAsmInfoCOFF::anchor() { }
MCAsmInfoCOFF::MCAsmInfoCOFF() {
// MingW 4.5 and later support .comm with log2 alignment, but .lcomm uses byte
// alignment.
COMMDirectiveAlignmentIsInBytes = false;
LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
HasDotTypeDotSizeDirective = false;
HasSingleParameterDotFile = false;
WeakRefDirective = "\t.weak\t";
HasLinkOnceDirective = true;
// Doesn't support visibility:
HiddenVisibilityAttr = HiddenDeclarationVisibilityAttr = MCSA_Invalid;
ProtectedVisibilityAttr = MCSA_Invalid;
// Set up DWARF directives
SupportsDebugInformation = true;
NeedsDwarfSectionOffsetDirective = true;
UseIntegratedAssembler = true;
// FIXME: For now keep the previous behavior, AShr. Need to double-check
// other COFF-targeting assemblers and change this if necessary.
UseLogicalShr = false;
}
void MCAsmInfoMicrosoft::anchor() { }
MCAsmInfoMicrosoft::MCAsmInfoMicrosoft() {
}
void MCAsmInfoGNUCOFF::anchor() { }
MCAsmInfoGNUCOFF::MCAsmInfoGNUCOFF() {
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCSectionCOFF.cpp | //===- lib/MC/MCSectionCOFF.cpp - COFF Code Section Representation --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
MCSectionCOFF::~MCSectionCOFF() {} // anchor.
// ShouldOmitSectionDirective - Decides whether a '.section' directive
// should be printed before the section name
bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name,
const MCAsmInfo &MAI) const {
if (COMDATSymbol)
return false;
// FIXME: Does .section .bss/.data/.text work everywhere??
if (Name == ".text" || Name == ".data" || Name == ".bss")
return true;
return false;
}
void MCSectionCOFF::setSelection(int Selection) const {
assert(Selection != 0 && "invalid COMDAT selection type");
this->Selection = Selection;
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
}
void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS,
const MCExpr *Subsection) const {
// standard sections don't require the '.section'
if (ShouldOmitSectionDirective(SectionName, MAI)) {
OS << '\t' << getSectionName() << '\n';
return;
}
OS << "\t.section\t" << getSectionName() << ",\"";
if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
OS << 'd';
if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
OS << 'b';
if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE)
OS << 'x';
if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE)
OS << 'w';
else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ)
OS << 'r';
else
OS << 'y';
if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE)
OS << 'n';
if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED)
OS << 's';
OS << '"';
if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
OS << ",";
switch (Selection) {
case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES:
OS << "one_only,";
break;
case COFF::IMAGE_COMDAT_SELECT_ANY:
OS << "discard,";
break;
case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE:
OS << "same_size,";
break;
case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH:
OS << "same_contents,";
break;
case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE:
OS << "associative,";
break;
case COFF::IMAGE_COMDAT_SELECT_LARGEST:
OS << "largest,";
break;
case COFF::IMAGE_COMDAT_SELECT_NEWEST:
OS << "newest,";
break;
default:
assert (0 && "unsupported COFF selection type");
break;
}
assert(COMDATSymbol);
COMDATSymbol->print(OS, &MAI);
}
OS << '\n';
}
bool MCSectionCOFF::UseCodeAlign() const {
return getKind().isText();
}
bool MCSectionCOFF::isVirtualSection() const {
return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCMachOStreamer.cpp | //===-- MCMachOStreamer.cpp - MachO Streamer ------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCStreamer.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCLinkerOptimizationHint.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbolMachO.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
namespace {
class MCMachOStreamer : public MCObjectStreamer {
private:
/// LabelSections - true if each section change should emit a linker local
/// label for use in relocations for assembler local references. Obviates the
/// need for local relocations. False by default.
bool LabelSections;
bool DWARFMustBeAtTheEnd;
bool CreatedADWARFSection;
/// HasSectionLabel - map of which sections have already had a non-local
/// label emitted to them. Used so we don't emit extraneous linker local
/// labels in the middle of the section.
DenseMap<const MCSection*, bool> HasSectionLabel;
void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
void EmitDataRegion(DataRegionData::KindTy Kind);
void EmitDataRegionEnd();
public:
MCMachOStreamer(MCContext &Context, MCAsmBackend &MAB, raw_pwrite_stream &OS,
MCCodeEmitter *Emitter, bool DWARFMustBeAtTheEnd, bool label)
: MCObjectStreamer(Context, MAB, OS, Emitter), LabelSections(label),
DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd), CreatedADWARFSection(false) {}
/// state management
void reset() override {
HasSectionLabel.clear();
MCObjectStreamer::reset();
}
/// @name MCStreamer Interface
/// @{
void ChangeSection(MCSection *Sect, const MCExpr *Subsect) override;
void EmitLabel(MCSymbol *Symbol) override;
void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
void EmitAssemblerFlag(MCAssemblerFlag Flag) override;
void EmitLinkerOptions(ArrayRef<std::string> Options) override;
void EmitDataRegion(MCDataRegionType Kind) override;
void EmitVersionMin(MCVersionMinType Kind, unsigned Major,
unsigned Minor, unsigned Update) override;
void EmitThumbFunc(MCSymbol *Func) override;
bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {
llvm_unreachable("macho doesn't support this directive");
}
void EmitCOFFSymbolStorageClass(int StorageClass) override {
llvm_unreachable("macho doesn't support this directive");
}
void EmitCOFFSymbolType(int Type) override {
llvm_unreachable("macho doesn't support this directive");
}
void EndCOFFSymbolDef() override {
llvm_unreachable("macho doesn't support this directive");
}
void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, unsigned ByteAlignment = 0) override;
void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment = 0) override;
void EmitFileDirective(StringRef Filename) override {
// FIXME: Just ignore the .file; it isn't important enough to fail the
// entire assembly.
// report_fatal_error("unsupported directive: '.file'");
}
void EmitIdent(StringRef IdentString) override {
llvm_unreachable("macho doesn't support this directive");
}
void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override {
getAssembler().getLOHContainer().addDirective(Kind, Args);
}
void FinishImpl() override;
};
} // end anonymous namespace.
static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
// These sections are created by the assembler itself after the end of
// the .s file.
StringRef SegName = MSec.getSegmentName();
StringRef SecName = MSec.getSectionName();
if (SegName == "__LD" && SecName == "__compact_unwind")
return true;
if (SegName == "__IMPORT") {
if (SecName == "__jump_table")
return true;
if (SecName == "__pointers")
return true;
}
if (SegName == "__TEXT" && SecName == "__eh_frame")
return true;
if (SegName == "__DATA" && SecName == "__nl_symbol_ptr")
return true;
return false;
}
void MCMachOStreamer::ChangeSection(MCSection *Section,
const MCExpr *Subsection) {
// Change the section normally.
bool Created = MCObjectStreamer::changeSectionImpl(Section, Subsection);
const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
StringRef SegName = MSec.getSegmentName();
if (SegName == "__DWARF")
CreatedADWARFSection = true;
else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
assert(!CreatedADWARFSection && "Creating regular section after DWARF");
// Output a linker-local symbol so we don't need section-relative local
// relocations. The linker hates us when we do that.
if (LabelSections && !HasSectionLabel[Section] &&
!Section->getBeginSymbol()) {
MCSymbol *Label = getContext().createLinkerPrivateTempSymbol();
Section->setBeginSymbol(Label);
HasSectionLabel[Section] = true;
}
}
void MCMachOStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
MCSymbol *EHSymbol) {
getAssembler().registerSymbol(*Symbol);
if (Symbol->isExternal())
EmitSymbolAttribute(EHSymbol, MCSA_Global);
if (cast<MCSymbolMachO>(Symbol)->isWeakDefinition())
EmitSymbolAttribute(EHSymbol, MCSA_WeakDefinition);
if (Symbol->isPrivateExtern())
EmitSymbolAttribute(EHSymbol, MCSA_PrivateExtern);
}
void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) {
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
// isSymbolLinkerVisible uses the section.
AssignSection(Symbol, getCurrentSection().first);
// We have to create a new fragment if this is an atom defining symbol,
// fragments cannot span atoms.
if (getAssembler().isSymbolLinkerVisible(*Symbol))
insert(new MCDataFragment());
MCObjectStreamer::EmitLabel(Symbol);
// This causes the reference type flag to be cleared. Darwin 'as' was "trying"
// to clear the weak reference and weak definition bits too, but the
// implementation was buggy. For now we just try to match 'as', for
// diffability.
//
// FIXME: Cleanup this code, these bits should be emitted based on semantic
// properties, not on the order of definition, etc.
cast<MCSymbolMachO>(Symbol)->clearReferenceType();
}
void MCMachOStreamer::EmitDataRegion(DataRegionData::KindTy Kind) {
if (!getAssembler().getBackend().hasDataInCodeSupport())
return;
// Create a temporary label to mark the start of the data region.
MCSymbol *Start = getContext().createTempSymbol();
EmitLabel(Start);
// Record the region for the object writer to use.
DataRegionData Data = { Kind, Start, nullptr };
std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
Regions.push_back(Data);
}
void MCMachOStreamer::EmitDataRegionEnd() {
if (!getAssembler().getBackend().hasDataInCodeSupport())
return;
std::vector<DataRegionData> &Regions = getAssembler().getDataRegions();
assert(!Regions.empty() && "Mismatched .end_data_region!");
DataRegionData &Data = Regions.back();
assert(!Data.End && "Mismatched .end_data_region!");
// Create a temporary label to mark the end of the data region.
Data.End = getContext().createTempSymbol();
EmitLabel(Data.End);
}
void MCMachOStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
// Let the target do whatever target specific stuff it needs to do.
getAssembler().getBackend().handleAssemblerFlag(Flag);
// Do any generic stuff we need to do.
switch (Flag) {
case MCAF_SyntaxUnified: return; // no-op here.
case MCAF_Code16: return; // Change parsing mode; no-op here.
case MCAF_Code32: return; // Change parsing mode; no-op here.
case MCAF_Code64: return; // Change parsing mode; no-op here.
case MCAF_SubsectionsViaSymbols:
getAssembler().setSubsectionsViaSymbols(true);
return;
}
}
void MCMachOStreamer::EmitLinkerOptions(ArrayRef<std::string> Options) {
getAssembler().getLinkerOptions().push_back(Options);
}
void MCMachOStreamer::EmitDataRegion(MCDataRegionType Kind) {
switch (Kind) {
case MCDR_DataRegion:
EmitDataRegion(DataRegionData::Data);
return;
case MCDR_DataRegionJT8:
EmitDataRegion(DataRegionData::JumpTable8);
return;
case MCDR_DataRegionJT16:
EmitDataRegion(DataRegionData::JumpTable16);
return;
case MCDR_DataRegionJT32:
EmitDataRegion(DataRegionData::JumpTable32);
return;
case MCDR_DataRegionEnd:
EmitDataRegionEnd();
return;
}
}
void MCMachOStreamer::EmitVersionMin(MCVersionMinType Kind, unsigned Major,
unsigned Minor, unsigned Update) {
getAssembler().setVersionMinInfo(Kind, Major, Minor, Update);
}
void MCMachOStreamer::EmitThumbFunc(MCSymbol *Symbol) {
// Remember that the function is a thumb function. Fixup and relocation
// values will need adjusted.
getAssembler().setIsThumbFunc(Symbol);
cast<MCSymbolMachO>(Symbol)->setThumbFunc();
}
bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Sym,
MCSymbolAttr Attribute) {
MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
// Indirect symbols are handled differently, to match how 'as' handles
// them. This makes writing matching .o files easier.
if (Attribute == MCSA_IndirectSymbol) {
// Note that we intentionally cannot use the symbol data here; this is
// important for matching the string table that 'as' generates.
IndirectSymbolData ISD;
ISD.Symbol = Symbol;
ISD.Section = getCurrentSectionOnly();
getAssembler().getIndirectSymbols().push_back(ISD);
return true;
}
// Adding a symbol attribute always introduces the symbol, note that an
// important side effect of calling registerSymbol here is to register
// the symbol with the assembler.
getAssembler().registerSymbol(*Symbol);
// The implementation of symbol attributes is designed to match 'as', but it
// leaves much to desired. It doesn't really make sense to arbitrarily add and
// remove flags, but 'as' allows this (in particular, see .desc).
//
// In the future it might be worth trying to make these operations more well
// defined.
switch (Attribute) {
case MCSA_Invalid:
case MCSA_ELF_TypeFunction:
case MCSA_ELF_TypeIndFunction:
case MCSA_ELF_TypeObject:
case MCSA_ELF_TypeTLS:
case MCSA_ELF_TypeCommon:
case MCSA_ELF_TypeNoType:
case MCSA_ELF_TypeGnuUniqueObject:
case MCSA_Hidden:
case MCSA_IndirectSymbol:
case MCSA_Internal:
case MCSA_Protected:
case MCSA_Weak:
case MCSA_Local:
return false;
case MCSA_Global:
Symbol->setExternal(true);
// This effectively clears the undefined lazy bit, in Darwin 'as', although
// it isn't very consistent because it implements this as part of symbol
// lookup.
//
// FIXME: Cleanup this code, these bits should be emitted based on semantic
// properties, not on the order of definition, etc.
Symbol->setReferenceTypeUndefinedLazy(false);
break;
case MCSA_LazyReference:
// FIXME: This requires -dynamic.
Symbol->setNoDeadStrip();
if (Symbol->isUndefined())
Symbol->setReferenceTypeUndefinedLazy(true);
break;
// Since .reference sets the no dead strip bit, it is equivalent to
// .no_dead_strip in practice.
case MCSA_Reference:
case MCSA_NoDeadStrip:
Symbol->setNoDeadStrip();
break;
case MCSA_SymbolResolver:
Symbol->setSymbolResolver();
break;
case MCSA_PrivateExtern:
Symbol->setExternal(true);
Symbol->setPrivateExtern(true);
break;
case MCSA_WeakReference:
// FIXME: This requires -dynamic.
if (Symbol->isUndefined())
Symbol->setWeakReference();
break;
case MCSA_WeakDefinition:
// FIXME: 'as' enforces that this is defined and global. The manual claims
// it has to be in a coalesced section, but this isn't enforced.
Symbol->setWeakDefinition();
break;
case MCSA_WeakDefAutoPrivate:
Symbol->setWeakDefinition();
Symbol->setWeakReference();
break;
}
return true;
}
void MCMachOStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
// Encode the 'desc' value into the lowest implementation defined bits.
getAssembler().registerSymbol(*Symbol);
cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
}
void MCMachOStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
// FIXME: Darwin 'as' does appear to allow redef of a .comm by itself.
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
AssignSection(Symbol, nullptr);
getAssembler().registerSymbol(*Symbol);
Symbol->setExternal(true);
Symbol->setCommon(Size, ByteAlignment);
}
void MCMachOStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
// '.lcomm' is equivalent to '.zerofill'.
return EmitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(),
Symbol, Size, ByteAlignment);
}
void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
getAssembler().registerSection(*Section);
// The symbol may not be present, which only creates the section.
if (!Symbol)
return;
// On darwin all virtual sections have zerofill type.
assert(Section->isVirtualSection() && "Section does not have zerofill type!");
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
getAssembler().registerSymbol(*Symbol);
// Emit an align fragment if necessary.
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, Section);
AssignSection(Symbol, Section);
MCFragment *F = new MCFillFragment(0, 0, Size, Section);
Symbol->setFragment(F);
// Update the maximum alignment on the zero fill section if necessary.
if (ByteAlignment > Section->getAlignment())
Section->setAlignment(ByteAlignment);
}
// This should always be called with the thread local bss section. Like the
// .zerofill directive this doesn't actually switch sections on us.
void MCMachOStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
EmitZerofill(Section, Symbol, Size, ByteAlignment);
return;
}
void MCMachOStreamer::EmitInstToData(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCDataFragment *DF = getOrCreateDataFragment();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
VecOS.flush();
// Add the fixups and data.
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
DF->getFixups().push_back(Fixups[i]);
}
DF->getContents().append(Code.begin(), Code.end());
}
void MCMachOStreamer::FinishImpl() {
EmitFrames(&getAssembler().getBackend());
// We have to set the fragment atom associations so we can relax properly for
// Mach-O.
// First, scan the symbol table to build a lookup table from fragments to
// defining symbols.
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
for (const MCSymbol &Symbol : getAssembler().symbols()) {
if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.getFragment()) {
// An atom defining symbol should never be internal to a fragment.
assert(Symbol.getOffset() == 0 &&
"Invalid offset in atom defining symbol!");
DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
}
}
// Set the fragment atom associations by tracking the last seen atom defining
// symbol.
for (MCAssembler::iterator it = getAssembler().begin(),
ie = getAssembler().end(); it != ie; ++it) {
const MCSymbol *CurrentAtom = nullptr;
for (MCSection::iterator it2 = it->begin(), ie2 = it->end(); it2 != ie2;
++it2) {
if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(it2))
CurrentAtom = Symbol;
it2->setAtom(CurrentAtom);
}
}
this->MCObjectStreamer::FinishImpl();
}
MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB,
raw_pwrite_stream &OS, MCCodeEmitter *CE,
bool RelaxAll, bool DWARFMustBeAtTheEnd,
bool LabelSections) {
MCMachOStreamer *S = new MCMachOStreamer(Context, MAB, OS, CE,
DWARFMustBeAtTheEnd, LabelSections);
if (RelaxAll)
S->getAssembler().setRelaxAll(true);
return S;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCMachObjectTargetWriter.cpp | //===-- MCMachObjectTargetWriter.cpp - Mach-O Target Writer Subclass ------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCMachObjectWriter.h"
using namespace llvm;
MCMachObjectTargetWriter::MCMachObjectTargetWriter(bool Is64Bit_,
uint32_t CPUType_,
uint32_t CPUSubtype_)
: Is64Bit(Is64Bit_), CPUType(CPUType_), CPUSubtype(CPUSubtype_) {}
MCMachObjectTargetWriter::~MCMachObjectTargetWriter() {}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCSymbolELF.cpp | //===- lib/MC/MCSymbolELF.cpp ---------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCSymbolELF.h"
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/Support/ELF.h"
namespace llvm {
namespace {
enum {
// Shift value for STT_* flags. 7 possible values. 3 bits.
ELF_STT_Shift = 0,
// Shift value for STB_* flags. 4 possible values, 2 bits.
ELF_STB_Shift = 3,
// Shift value for STV_* flags. 4 possible values, 2 bits.
ELF_STV_Shift = 5,
// Shift value for STO_* flags. 3 bits. All the values are between 0x20 and
// 0xe0, so we shift right by 5 before storing.
ELF_STO_Shift = 7,
// One bit.
ELF_IsSignature_Shift = 10,
// One bit.
ELF_WeakrefUsedInReloc_Shift = 11,
// One bit.
ELF_BindingSet_Shift = 12
};
}
void MCSymbolELF::setBinding(unsigned Binding) const {
setIsBindingSet();
unsigned Val;
switch (Binding) {
default:
llvm_unreachable("Unsupported Binding");
case ELF::STB_LOCAL:
Val = 0;
break;
case ELF::STB_GLOBAL:
Val = 1;
break;
case ELF::STB_WEAK:
Val = 2;
break;
case ELF::STB_GNU_UNIQUE:
Val = 3;
break;
}
uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STB_Shift);
setFlags(OtherFlags | (Val << ELF_STB_Shift));
}
unsigned MCSymbolELF::getBinding() const {
if (isBindingSet()) {
uint32_t Val = (getFlags() & (0x3 << ELF_STB_Shift)) >> ELF_STB_Shift;
switch (Val) {
default:
llvm_unreachable("Invalid value");
case 0:
return ELF::STB_LOCAL;
case 1:
return ELF::STB_GLOBAL;
case 2:
return ELF::STB_WEAK;
case 3:
return ELF::STB_GNU_UNIQUE;
}
}
if (isDefined())
return ELF::STB_LOCAL;
if (isUsedInReloc())
return ELF::STB_GLOBAL;
if (isWeakrefUsedInReloc())
return ELF::STB_WEAK;
if (isSignature())
return ELF::STB_LOCAL;
return ELF::STB_GLOBAL;
}
void MCSymbolELF::setType(unsigned Type) const {
unsigned Val;
switch (Type) {
default:
llvm_unreachable("Unsupported Binding");
case ELF::STT_NOTYPE:
Val = 0;
break;
case ELF::STT_OBJECT:
Val = 1;
break;
case ELF::STT_FUNC:
Val = 2;
break;
case ELF::STT_SECTION:
Val = 3;
break;
case ELF::STT_COMMON:
Val = 4;
break;
case ELF::STT_TLS:
Val = 5;
break;
case ELF::STT_GNU_IFUNC:
Val = 6;
break;
}
uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STT_Shift);
setFlags(OtherFlags | (Val << ELF_STT_Shift));
}
unsigned MCSymbolELF::getType() const {
uint32_t Val = (getFlags() & (0x7 << ELF_STT_Shift)) >> ELF_STT_Shift;
switch (Val) {
default:
llvm_unreachable("Invalid value");
case 0:
return ELF::STT_NOTYPE;
case 1:
return ELF::STT_OBJECT;
case 2:
return ELF::STT_FUNC;
case 3:
return ELF::STT_SECTION;
case 4:
return ELF::STT_COMMON;
case 5:
return ELF::STT_TLS;
case 6:
return ELF::STT_GNU_IFUNC;
}
}
void MCSymbolELF::setVisibility(unsigned Visibility) {
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
uint32_t OtherFlags = getFlags() & ~(0x3 << ELF_STV_Shift);
setFlags(OtherFlags | (Visibility << ELF_STV_Shift));
}
unsigned MCSymbolELF::getVisibility() const {
unsigned Visibility = (getFlags() & (0x3 << ELF_STV_Shift)) >> ELF_STV_Shift;
assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
return Visibility;
}
void MCSymbolELF::setOther(unsigned Other) {
assert((Other & 0x1f) == 0);
Other >>= 5;
assert(Other <= 0x7);
uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STO_Shift);
setFlags(OtherFlags | (Other << ELF_STO_Shift));
}
unsigned MCSymbolELF::getOther() const {
unsigned Other = (getFlags() & (0x7 << ELF_STO_Shift)) >> ELF_STO_Shift;
return Other << 5;
}
void MCSymbolELF::setIsWeakrefUsedInReloc() const {
uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_WeakrefUsedInReloc_Shift);
setFlags(OtherFlags | (1 << ELF_WeakrefUsedInReloc_Shift));
}
bool MCSymbolELF::isWeakrefUsedInReloc() const {
return getFlags() & (0x1 << ELF_WeakrefUsedInReloc_Shift);
}
void MCSymbolELF::setIsSignature() const {
uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_IsSignature_Shift);
setFlags(OtherFlags | (1 << ELF_IsSignature_Shift));
}
bool MCSymbolELF::isSignature() const {
return getFlags() & (0x1 << ELF_IsSignature_Shift);
}
void MCSymbolELF::setIsBindingSet() const {
uint32_t OtherFlags = getFlags() & ~(0x1 << ELF_BindingSet_Shift);
setFlags(OtherFlags | (1 << ELF_BindingSet_Shift));
}
bool MCSymbolELF::isBindingSet() const {
return getFlags() & (0x1 << ELF_BindingSet_Shift);
}
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/StringTableBuilder.cpp | //===-- StringTableBuilder.cpp - String table building utility ------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
static bool compareBySuffix(StringRef a, StringRef b) {
size_t sizeA = a.size();
size_t sizeB = b.size();
size_t len = std::min(sizeA, sizeB);
for (size_t i = 0; i < len; ++i) {
char ca = a[sizeA - i - 1];
char cb = b[sizeB - i - 1];
if (ca != cb)
return ca > cb;
}
return sizeA > sizeB;
}
void StringTableBuilder::finalize(Kind kind) {
SmallVector<StringRef, 8> Strings;
Strings.reserve(StringIndexMap.size());
for (auto i = StringIndexMap.begin(), e = StringIndexMap.end(); i != e; ++i)
Strings.push_back(i->getKey());
std::sort(Strings.begin(), Strings.end(), compareBySuffix);
switch (kind) {
case ELF:
case MachO:
// Start the table with a NUL byte.
StringTable += '\x00';
break;
case WinCOFF:
// Make room to write the table size later.
StringTable.append(4, '\x00');
break;
}
StringRef Previous;
for (StringRef s : Strings) {
if (kind == WinCOFF)
assert(s.size() > COFF::NameSize && "Short string in COFF string table!");
if (Previous.endswith(s)) {
StringIndexMap[s] = StringTable.size() - 1 - s.size();
continue;
}
StringIndexMap[s] = StringTable.size();
StringTable += s;
StringTable += '\x00';
Previous = s;
}
switch (kind) {
case ELF:
break;
case MachO:
// Pad to multiple of 4.
while (StringTable.size() % 4)
StringTable += '\x00';
break;
case WinCOFF:
// Write the table size in the first word.
assert(StringTable.size() <= std::numeric_limits<uint32_t>::max());
uint32_t size = static_cast<uint32_t>(StringTable.size());
support::endian::write<uint32_t, support::little, support::unaligned>(
StringTable.data(), size);
break;
}
}
void StringTableBuilder::clear() {
StringTable.clear();
StringIndexMap.clear();
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCInstPrinter.cpp | //===-- MCInstPrinter.cpp - Convert an MCInst to target assembly syntax ---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
void llvm::dumpBytes(ArrayRef<uint8_t> bytes, raw_ostream &OS) {
static const char hex_rep[] = "0123456789abcdef";
for (char i: bytes) {
OS << hex_rep[(i & 0xF0) >> 4];
OS << hex_rep[i & 0xF];
OS << ' ';
}
}
MCInstPrinter::~MCInstPrinter() {
}
/// getOpcodeName - Return the name of the specified opcode enum (e.g.
/// "MOV32ri") or empty if we can't resolve it.
StringRef MCInstPrinter::getOpcodeName(unsigned Opcode) const {
return MII.getName(Opcode);
}
void MCInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
llvm_unreachable("Target should implement this");
}
void MCInstPrinter::printAnnotation(raw_ostream &OS, StringRef Annot) {
if (!Annot.empty()) {
if (CommentStream) {
(*CommentStream) << Annot;
// By definition (see MCInstPrinter.h), CommentStream must end with
// a newline after each comment.
if (Annot.back() != '\n')
(*CommentStream) << '\n';
} else
OS << " " << MAI.getCommentString() << " " << Annot;
}
}
/// Utility functions to make adding mark ups simpler.
StringRef MCInstPrinter::markup(StringRef s) const {
if (getUseMarkup())
return s;
else
return "";
}
StringRef MCInstPrinter::markup(StringRef a, StringRef b) const {
if (getUseMarkup())
return a;
else
return b;
}
// For asm-style hex (e.g. 0ffh) the first digit always has to be a number.
static bool needsLeadingZero(uint64_t Value)
{
while(Value)
{
uint64_t digit = (Value >> 60) & 0xf;
if (digit != 0)
return (digit >= 0xa);
Value <<= 4;
}
return false;
}
format_object<int64_t> MCInstPrinter::formatDec(int64_t Value) const {
return format("%" PRId64, Value);
}
format_object<int64_t> MCInstPrinter::formatHex(int64_t Value) const {
switch(PrintHexStyle) {
case HexStyle::C:
if (Value < 0)
return format("-0x%" PRIx64, -Value);
else
return format("0x%" PRIx64, Value);
case HexStyle::Asm:
if (Value < 0) {
if (needsLeadingZero((uint64_t)(-Value)))
return format("-0%" PRIx64 "h", -Value);
else
return format("-%" PRIx64 "h", -Value);
} else {
if (needsLeadingZero((uint64_t)(Value)))
return format("0%" PRIx64 "h", Value);
else
return format("%" PRIx64 "h", Value);
}
}
llvm_unreachable("unsupported print style");
}
format_object<uint64_t> MCInstPrinter::formatHex(uint64_t Value) const {
switch(PrintHexStyle) {
case HexStyle::C:
return format("0x%" PRIx64, Value);
case HexStyle::Asm:
if (needsLeadingZero(Value))
return format("0%" PRIx64 "h", Value);
else
return format("%" PRIx64 "h", Value);
}
llvm_unreachable("unsupported print style");
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCSymbolizer.cpp | //===-- llvm/MC/MCSymbolizer.cpp - MCSymbolizer class -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSymbolizer.h"
using namespace llvm;
MCSymbolizer::~MCSymbolizer() {
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/WinCOFFStreamer.cpp | //===-- llvm/MC/WinCOFFStreamer.cpp -----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains an implementation of a Windows COFF object file streamer.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmLayout.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCObjectStreamer.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbolCOFF.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/MCWinCOFFStreamer.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
#define DEBUG_TYPE "WinCOFFStreamer"
namespace llvm {
MCWinCOFFStreamer::MCWinCOFFStreamer(MCContext &Context, MCAsmBackend &MAB,
MCCodeEmitter &CE, raw_pwrite_stream &OS)
: MCObjectStreamer(Context, MAB, OS, &CE), CurSymbol(nullptr) {}
void MCWinCOFFStreamer::EmitInstToData(const MCInst &Inst,
const MCSubtargetInfo &STI) {
MCDataFragment *DF = getOrCreateDataFragment();
SmallVector<MCFixup, 4> Fixups;
SmallString<256> Code;
raw_svector_ostream VecOS(Code);
getAssembler().getEmitter().encodeInstruction(Inst, VecOS, Fixups, STI);
VecOS.flush();
// Add the fixups and data.
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
DF->getFixups().push_back(Fixups[i]);
}
DF->getContents().append(Code.begin(), Code.end());
}
void MCWinCOFFStreamer::InitSections(bool NoExecStack) {
// FIXME: this is identical to the ELF one.
// This emulates the same behavior of GNU as. This makes it easier
// to compare the output as the major sections are in the same order.
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
EmitCodeAlignment(4);
SwitchSection(getContext().getObjectFileInfo()->getDataSection());
EmitCodeAlignment(4);
SwitchSection(getContext().getObjectFileInfo()->getBSSSection());
EmitCodeAlignment(4);
SwitchSection(getContext().getObjectFileInfo()->getTextSection());
}
void MCWinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
MCObjectStreamer::EmitLabel(Symbol);
}
void MCWinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::EmitThumbFunc(MCSymbol *Func) {
llvm_unreachable("not implemented");
}
bool MCWinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) {
assert(Symbol && "Symbol must be non-null!");
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
getAssembler().registerSymbol(*Symbol);
switch (Attribute) {
default: return false;
case MCSA_WeakReference:
case MCSA_Weak:
cast<MCSymbolCOFF>(Symbol)->setIsWeakExternal();
Symbol->setExternal(true);
break;
case MCSA_Global:
Symbol->setExternal(true);
break;
}
return true;
}
void MCWinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
if (CurSymbol)
FatalError("starting a new symbol definition without completing the "
"previous one");
CurSymbol = Symbol;
}
void MCWinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
if (!CurSymbol)
FatalError("storage class specified outside of symbol definition");
if (StorageClass & ~COFF::SSC_Invalid)
FatalError("storage class value '" + Twine(StorageClass) +
"' out of range");
getAssembler().registerSymbol(*CurSymbol);
cast<MCSymbolCOFF>(CurSymbol)->setClass((uint16_t)StorageClass);
}
void MCWinCOFFStreamer::EmitCOFFSymbolType(int Type) {
if (!CurSymbol)
FatalError("symbol type specified outside of a symbol definition");
if (Type & ~0xffff)
FatalError("type value '" + Twine(Type) + "' out of range");
getAssembler().registerSymbol(*CurSymbol);
cast<MCSymbolCOFF>(CurSymbol)->setType((uint16_t)Type);
}
void MCWinCOFFStreamer::EndCOFFSymbolDef() {
if (!CurSymbol)
FatalError("ending symbol definition without starting one");
CurSymbol = nullptr;
}
void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
// SafeSEH is a feature specific to 32-bit x86. It does not exist (and is
// unnecessary) on all platforms which use table-based exception dispatch.
if (getContext().getObjectFileInfo()->getTargetTriple().getArch() !=
Triple::x86)
return;
const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
if (CSymbol->isSafeSEH())
return;
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
getAssembler().registerSection(*SXData);
if (SXData->getAlignment() < 4)
SXData->setAlignment(4);
new MCSafeSEHFragment(Symbol, SXData);
getAssembler().registerSymbol(*Symbol);
CSymbol->setIsSafeSEH();
// The Microsoft linker requires that the symbol type of a handler be
// function. Go ahead and oblige it here.
CSymbol->setType(COFF::IMAGE_SYM_DTYPE_FUNCTION
<< COFF::SCT_COMPLEX_TYPE_SHIFT);
}
void MCWinCOFFStreamer::EmitCOFFSectionIndex(MCSymbol const *Symbol) {
MCDataFragment *DF = getOrCreateDataFragment();
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
DF->getFixups().push_back(Fixup);
DF->getContents().resize(DF->getContents().size() + 2, 0);
}
void MCWinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
MCDataFragment *DF = getOrCreateDataFragment();
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_4);
DF->getFixups().push_back(Fixup);
DF->getContents().resize(DF->getContents().size() + 4, 0);
}
void MCWinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
if (T.isKnownWindowsMSVCEnvironment()) {
if (ByteAlignment > 32)
report_fatal_error("alignment is limited to 32-bytes");
// Round size up to alignment so that we will honor the alignment request.
Size = std::max(Size, static_cast<uint64_t>(ByteAlignment));
}
AssignSection(Symbol, nullptr);
getAssembler().registerSymbol(*Symbol);
Symbol->setExternal(true);
Symbol->setCommon(Size, ByteAlignment);
if (!T.isKnownWindowsMSVCEnvironment() && ByteAlignment > 1) {
SmallString<128> Directive;
raw_svector_ostream OS(Directive);
const MCObjectFileInfo *MFI = getContext().getObjectFileInfo();
OS << " -aligncomm:\"" << Symbol->getName() << "\","
<< Log2_32_Ceil(ByteAlignment);
OS.flush();
PushSection();
SwitchSection(MFI->getDrectveSection());
EmitBytes(Directive);
PopSection();
}
}
void MCWinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {
assert(!Symbol->isInSection() && "Symbol must not already have a section!");
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
getAssembler().registerSection(*Section);
if (Section->getAlignment() < ByteAlignment)
Section->setAlignment(ByteAlignment);
getAssembler().registerSymbol(*Symbol);
Symbol->setExternal(false);
AssignSection(Symbol, Section);
if (ByteAlignment != 1)
new MCAlignFragment(ByteAlignment, /*Value=*/0, /*ValueSize=*/0,
ByteAlignment, Section);
MCFillFragment *Fragment = new MCFillFragment(
/*Value=*/0, /*ValueSize=*/0, Size, Section);
Symbol->setFragment(Fragment);
}
void MCWinCOFFStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
uint64_t Size, unsigned ByteAlignment) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::EmitFileDirective(StringRef Filename) {
getAssembler().addFileName(Filename);
}
// TODO: Implement this if you want to emit .comment section in COFF obj files.
void MCWinCOFFStreamer::EmitIdent(StringRef IdentString) {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::EmitWinEHHandlerData() {
llvm_unreachable("not implemented");
}
void MCWinCOFFStreamer::FinishImpl() {
MCObjectStreamer::FinishImpl();
}
LLVM_ATTRIBUTE_NORETURN
void MCWinCOFFStreamer::FatalError(const Twine &Msg) const {
getContext().reportFatalError(SMLoc(), Msg);
}
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCSchedule.cpp | //===- MCSchedule.cpp - Scheduling ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the default scheduling model.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSchedule.h"
#include <type_traits>
using namespace llvm;
static_assert(std::is_pod<MCSchedModel>::value,
"We shouldn't have a static constructor here");
const MCSchedModel MCSchedModel::Default = {DefaultIssueWidth,
DefaultMicroOpBufferSize,
DefaultLoopMicroOpBufferSize,
DefaultLoadLatency,
DefaultHighLatency,
DefaultMispredictPenalty,
false,
true,
0,
nullptr,
nullptr,
0,
0,
nullptr};
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/CMakeLists.txt | add_llvm_library(LLVMMC
ConstantPools.cpp
ELFObjectWriter.cpp
MCAsmBackend.cpp
MCAsmInfo.cpp
MCAsmInfoCOFF.cpp
MCAsmInfoDarwin.cpp
MCAsmInfoELF.cpp
MCAsmStreamer.cpp
MCAssembler.cpp
MCCodeEmitter.cpp
MCCodeGenInfo.cpp
MCContext.cpp
MCDwarf.cpp
MCELFObjectTargetWriter.cpp
MCELFStreamer.cpp
MCExpr.cpp
MCInst.cpp
MCInstPrinter.cpp
MCInstrAnalysis.cpp
MCInstrDesc.cpp
MCLabel.cpp
MCLinkerOptimizationHint.cpp
MCMachOStreamer.cpp
MCMachObjectTargetWriter.cpp
MCNullStreamer.cpp
MCObjectFileInfo.cpp
MCObjectStreamer.cpp
MCObjectWriter.cpp
MCRegisterInfo.cpp
MCSchedule.cpp
MCSection.cpp
MCSectionCOFF.cpp
MCSectionELF.cpp
MCSectionMachO.cpp
MCStreamer.cpp
MCSubtargetInfo.cpp
MCSymbol.cpp
MCSymbolELF.cpp
MCSymbolizer.cpp
MCTargetOptions.cpp
MCValue.cpp
MCWin64EH.cpp
MCWinEH.cpp
MachObjectWriter.cpp
StringTableBuilder.cpp
SubtargetFeature.cpp
WinCOFFObjectWriter.cpp
WinCOFFStreamer.cpp
YAML.cpp
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/MC
)
add_subdirectory(MCParser)
add_subdirectory(MCDisassembler)
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCAsmBackend.cpp | //===-- MCAsmBackend.cpp - Target MC Assembly Backend ----------------------==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/MC/MCFixupKindInfo.h"
using namespace llvm;
MCAsmBackend::MCAsmBackend() : HasDataInCodeSupport(false) {}
MCAsmBackend::~MCAsmBackend() {}
const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
static const MCFixupKindInfo Builtins[] = {
{"FK_Data_1", 0, 8, 0},
{"FK_Data_2", 0, 16, 0},
{"FK_Data_4", 0, 32, 0},
{"FK_Data_8", 0, 64, 0},
{"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
{"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
{"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
{"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
{"FK_GPRel_1", 0, 8, 0},
{"FK_GPRel_2", 0, 16, 0},
{"FK_GPRel_4", 0, 32, 0},
{"FK_GPRel_8", 0, 64, 0},
{"FK_SecRel_1", 0, 8, 0},
{"FK_SecRel_2", 0, 16, 0},
{"FK_SecRel_4", 0, 32, 0},
{"FK_SecRel_8", 0, 64, 0}};
assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
return Builtins[Kind];
}
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
const MCFixup &Fixup, bool Resolved, uint64_t Value,
const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const {
if (!Resolved)
return true;
return fixupNeedsRelaxation(Fixup, Value, DF, Layout);
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCSectionMachO.cpp | //===- lib/MC/MCSectionMachO.cpp - MachO Code Section Representation ------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCContext.h"
#include "llvm/Support/raw_ostream.h"
#include <cctype>
using namespace llvm;
/// SectionTypeDescriptors - These are strings that describe the various section
/// types. This *must* be kept in order with and stay synchronized with the
/// section type list.
static const struct {
const char *AssemblerName, *EnumName;
} SectionTypeDescriptors[MachO::LAST_KNOWN_SECTION_TYPE+1] = {
{ "regular", "S_REGULAR" }, // 0x00
{ nullptr, "S_ZEROFILL" }, // 0x01
{ "cstring_literals", "S_CSTRING_LITERALS" }, // 0x02
{ "4byte_literals", "S_4BYTE_LITERALS" }, // 0x03
{ "8byte_literals", "S_8BYTE_LITERALS" }, // 0x04
{ "literal_pointers", "S_LITERAL_POINTERS" }, // 0x05
{ "non_lazy_symbol_pointers", "S_NON_LAZY_SYMBOL_POINTERS" }, // 0x06
{ "lazy_symbol_pointers", "S_LAZY_SYMBOL_POINTERS" }, // 0x07
{ "symbol_stubs", "S_SYMBOL_STUBS" }, // 0x08
{ "mod_init_funcs", "S_MOD_INIT_FUNC_POINTERS" }, // 0x09
{ "mod_term_funcs", "S_MOD_TERM_FUNC_POINTERS" }, // 0x0A
{ "coalesced", "S_COALESCED" }, // 0x0B
{ nullptr, /*FIXME??*/ "S_GB_ZEROFILL" }, // 0x0C
{ "interposing", "S_INTERPOSING" }, // 0x0D
{ "16byte_literals", "S_16BYTE_LITERALS" }, // 0x0E
{ nullptr, /*FIXME??*/ "S_DTRACE_DOF" }, // 0x0F
{ nullptr, /*FIXME??*/ "S_LAZY_DYLIB_SYMBOL_POINTERS" }, // 0x10
{ "thread_local_regular", "S_THREAD_LOCAL_REGULAR" }, // 0x11
{ "thread_local_zerofill", "S_THREAD_LOCAL_ZEROFILL" }, // 0x12
{ "thread_local_variables", "S_THREAD_LOCAL_VARIABLES" }, // 0x13
{ "thread_local_variable_pointers",
"S_THREAD_LOCAL_VARIABLE_POINTERS" }, // 0x14
{ "thread_local_init_function_pointers",
"S_THREAD_LOCAL_INIT_FUNCTION_POINTERS"}, // 0x15
};
/// SectionAttrDescriptors - This is an array of descriptors for section
/// attributes. Unlike the SectionTypeDescriptors, this is not directly indexed
/// by attribute, instead it is searched.
static const struct {
unsigned AttrFlag;
const char *AssemblerName, *EnumName;
} SectionAttrDescriptors[] = {
#define ENTRY(ASMNAME, ENUM) \
{ MachO::ENUM, ASMNAME, #ENUM },
ENTRY("pure_instructions", S_ATTR_PURE_INSTRUCTIONS)
ENTRY("no_toc", S_ATTR_NO_TOC)
ENTRY("strip_static_syms", S_ATTR_STRIP_STATIC_SYMS)
ENTRY("no_dead_strip", S_ATTR_NO_DEAD_STRIP)
ENTRY("live_support", S_ATTR_LIVE_SUPPORT)
ENTRY("self_modifying_code", S_ATTR_SELF_MODIFYING_CODE)
ENTRY("debug", S_ATTR_DEBUG)
ENTRY(nullptr /*FIXME*/, S_ATTR_SOME_INSTRUCTIONS)
ENTRY(nullptr /*FIXME*/, S_ATTR_EXT_RELOC)
ENTRY(nullptr /*FIXME*/, S_ATTR_LOC_RELOC)
#undef ENTRY
{ 0, "none", nullptr }, // used if section has no attributes but has a stub size
};
MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
unsigned TAA, unsigned reserved2, SectionKind K,
MCSymbol *Begin)
: MCSection(SV_MachO, K, Begin), TypeAndAttributes(TAA),
Reserved2(reserved2) {
assert(Segment.size() <= 16 && Section.size() <= 16 &&
"Segment or section string too long");
for (unsigned i = 0; i != 16; ++i) {
if (i < Segment.size())
SegmentName[i] = Segment[i];
else
SegmentName[i] = 0;
if (i < Section.size())
SectionName[i] = Section[i];
else
SectionName[i] = 0;
}
}
void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS,
const MCExpr *Subsection) const {
OS << "\t.section\t" << getSegmentName() << ',' << getSectionName();
// Get the section type and attributes.
unsigned TAA = getTypeAndAttributes();
if (TAA == 0) {
OS << '\n';
return;
}
MachO::SectionType SectionType = getType();
assert(SectionType <= MachO::LAST_KNOWN_SECTION_TYPE &&
"Invalid SectionType specified!");
if (SectionTypeDescriptors[SectionType].AssemblerName) {
OS << ',';
OS << SectionTypeDescriptors[SectionType].AssemblerName;
} else {
// If we have no name for the attribute, stop here.
OS << '\n';
return;
}
// If we don't have any attributes, we're done.
unsigned SectionAttrs = TAA & MachO::SECTION_ATTRIBUTES;
if (SectionAttrs == 0) {
// If we have a S_SYMBOL_STUBS size specified, print it along with 'none' as
// the attribute specifier.
if (Reserved2 != 0)
OS << ",none," << Reserved2;
OS << '\n';
return;
}
// Check each attribute to see if we have it.
char Separator = ',';
for (unsigned i = 0;
SectionAttrs != 0 && SectionAttrDescriptors[i].AttrFlag;
++i) {
// Check to see if we have this attribute.
if ((SectionAttrDescriptors[i].AttrFlag & SectionAttrs) == 0)
continue;
// Yep, clear it and print it.
SectionAttrs &= ~SectionAttrDescriptors[i].AttrFlag;
OS << Separator;
if (SectionAttrDescriptors[i].AssemblerName)
OS << SectionAttrDescriptors[i].AssemblerName;
else
OS << "<<" << SectionAttrDescriptors[i].EnumName << ">>";
Separator = '+';
}
assert(SectionAttrs == 0 && "Unknown section attributes!");
// If we have a S_SYMBOL_STUBS size specified, print it.
if (Reserved2 != 0)
OS << ',' << Reserved2;
OS << '\n';
}
bool MCSectionMachO::UseCodeAlign() const {
return hasAttribute(MachO::S_ATTR_PURE_INSTRUCTIONS);
}
bool MCSectionMachO::isVirtualSection() const {
return (getType() == MachO::S_ZEROFILL ||
getType() == MachO::S_GB_ZEROFILL ||
getType() == MachO::S_THREAD_LOCAL_ZEROFILL);
}
/// ParseSectionSpecifier - Parse the section specifier indicated by "Spec".
/// This is a string that can appear after a .section directive in a mach-o
/// flavored .s file. If successful, this fills in the specified Out
/// parameters and returns an empty string. When an invalid section
/// specifier is present, this returns a string indicating the problem.
std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec, // In.
StringRef &Segment, // Out.
StringRef &Section, // Out.
unsigned &TAA, // Out.
bool &TAAParsed, // Out.
unsigned &StubSize) { // Out.
TAAParsed = false;
SmallVector<StringRef, 5> SplitSpec;
Spec.split(SplitSpec, ",");
// Remove leading and trailing whitespace.
auto GetEmptyOrTrim = [&SplitSpec](size_t Idx) -> StringRef {
return SplitSpec.size() > Idx ? SplitSpec[Idx].trim() : StringRef();
};
Segment = GetEmptyOrTrim(0);
Section = GetEmptyOrTrim(1);
StringRef SectionType = GetEmptyOrTrim(2);
StringRef Attrs = GetEmptyOrTrim(3);
StringRef StubSizeStr = GetEmptyOrTrim(4);
// Verify that the segment is present and not too long.
if (Segment.empty() || Segment.size() > 16)
return "mach-o section specifier requires a segment whose length is "
"between 1 and 16 characters";
// Verify that the section is present and not too long.
if (Section.empty())
return "mach-o section specifier requires a segment and section "
"separated by a comma";
if (Section.size() > 16)
return "mach-o section specifier requires a section whose length is "
"between 1 and 16 characters";
// If there is no comma after the section, we're done.
TAA = 0;
StubSize = 0;
if (SectionType.empty())
return "";
// Figure out which section type it is.
auto TypeDescriptor = std::find_if(
std::begin(SectionTypeDescriptors), std::end(SectionTypeDescriptors),
[&](decltype(*SectionTypeDescriptors) &Descriptor) {
return Descriptor.AssemblerName &&
SectionType == Descriptor.AssemblerName;
});
// If we didn't find the section type, reject it.
if (TypeDescriptor == std::end(SectionTypeDescriptors))
return "mach-o section specifier uses an unknown section type";
// Remember the TypeID.
TAA = TypeDescriptor - std::begin(SectionTypeDescriptors);
TAAParsed = true;
// If we have no comma after the section type, there are no attributes.
if (Attrs.empty()) {
// S_SYMBOL_STUBS always require a symbol stub size specifier.
if (TAA == MachO::S_SYMBOL_STUBS)
return "mach-o section specifier of type 'symbol_stubs' requires a size "
"specifier";
return "";
}
// The attribute list is a '+' separated list of attributes.
SmallVector<StringRef, 1> SectionAttrs;
Attrs.split(SectionAttrs, "+", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
for (StringRef &SectionAttr : SectionAttrs) {
auto AttrDescriptorI = std::find_if(
std::begin(SectionAttrDescriptors), std::end(SectionAttrDescriptors),
[&](decltype(*SectionAttrDescriptors) &Descriptor) {
return Descriptor.AssemblerName &&
SectionAttr.trim() == Descriptor.AssemblerName;
});
if (AttrDescriptorI == std::end(SectionAttrDescriptors))
return "mach-o section specifier has invalid attribute";
TAA |= AttrDescriptorI->AttrFlag;
}
// Okay, we've parsed the section attributes, see if we have a stub size spec.
if (StubSizeStr.empty()) {
// S_SYMBOL_STUBS always require a symbol stub size specifier.
if (TAA == MachO::S_SYMBOL_STUBS)
return "mach-o section specifier of type 'symbol_stubs' requires a size "
"specifier";
return "";
}
// If we have a stub size spec, we must have a sectiontype of S_SYMBOL_STUBS.
if ((TAA & MachO::SECTION_TYPE) != MachO::S_SYMBOL_STUBS)
return "mach-o section specifier cannot have a stub size specified because "
"it does not have type 'symbol_stubs'";
// Convert the stub size from a string to an integer.
if (StubSizeStr.getAsInteger(0, StubSize))
return "mach-o section specifier has a malformed stub size";
return "";
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCCodeGenInfo.cpp | //===-- MCCodeGenInfo.cpp - Target CodeGen Info -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file tracks information about the target which can affect codegen,
// asm parsing, and asm printing. For example, relocation model.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCCodeGenInfo.h"
using namespace llvm;
void MCCodeGenInfo::initMCCodeGenInfo(Reloc::Model RM, CodeModel::Model CM,
CodeGenOpt::Level OL) {
RelocationModel = RM;
CMModel = CM;
OptLevel = OL;
}
|
0 | repos/DirectXShaderCompiler/lib | repos/DirectXShaderCompiler/lib/MC/MCNullStreamer.cpp | //===- lib/MC/MCNullStreamer.cpp - Dummy Streamer Implementation ----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCSymbol.h"
using namespace llvm;
namespace {
class MCNullStreamer : public MCStreamer {
public:
MCNullStreamer(MCContext &Context) : MCStreamer(Context) {}
/// @name MCStreamer Interface
/// @{
bool EmitSymbolAttribute(MCSymbol *Symbol,
MCSymbolAttr Attribute) override {
return true;
}
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override {}
void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, unsigned ByteAlignment = 0) override {}
void EmitGPRel32Value(const MCExpr *Value) override {}
};
}
MCStreamer *llvm::createNullStreamer(MCContext &Context) {
return new MCNullStreamer(Context);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.