Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion docs/DXIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,8 @@ Opcodes are defined on a dense range and will be provided as enum in a header fi
.. <py::lines('OPCODES-RST')>hctdb_instrhelp.get_opcodes_rst()</py>
.. OPCODES-RST:BEGIN

Opcode Table CoreOps, id=0: Core DXIL operations

=== ===================================================== =======================================================================================================================================================================================================================
ID Name Description
=== ===================================================== =======================================================================================================================================================================================================================
Expand Down Expand Up @@ -3055,6 +3057,18 @@ Given width, offset:
ushr dest, src2, offset
}




Opcode Table ExperimentalOps, id=32768: Experimental DXIL operations

========== =============== ================
ID Name Description
========== =============== ================
2147483648 ExperimentalNop nop does nothing
========== =============== ================


.. OPCODES-RST:END


Expand Down Expand Up @@ -3134,10 +3148,11 @@ INSTR.CREATEHANDLEIMMRANGEID Local resource mus
INSTR.DXILSTRUCTUSER Dxil struct types should only be used by ExtractValue.
INSTR.DXILSTRUCTUSEROUTOFBOUND Index out of bound when extract value from dxil struct types.
INSTR.EVALINTERPOLATIONMODE Interpolation mode on %0 used with eval_* instruction must be linear, linear_centroid, linear_noperspective, linear_noperspective_centroid, linear_sample or linear_noperspective_sample.
INSTR.EXPDXILOPCODEREQUIRESEXPSM Use of experimental DXILOpCode requires an experimental shader model.
INSTR.EXTRACTVALUE ExtractValue should only be used on dxil struct types and cmpxchg.
INSTR.FAILTORESLOVETGSMPOINTER TGSM pointers must originate from an unambiguous TGSM global variable.
INSTR.HANDLENOTFROMCREATEHANDLE Resource handle should returned by createHandle.
INSTR.ILLEGALDXILOPCODE DXILOpCode must be [0..%0]. %1 specified.
INSTR.ILLEGALDXILOPCODE DXILOpCode must be valid or a supported experimental opcode.
INSTR.ILLEGALDXILOPFUNCTION '%0' is not a DXILOpFuncition for DXILOpcode '%1'.
INSTR.IMMBIASFORSAMPLEB bias amount for sample_b must be in the range [%0,%1], but %2 was specified as an immediate.
INSTR.INBOUNDSACCESS Access to out-of-bounds memory is disallowed.
Expand Down
69 changes: 55 additions & 14 deletions include/dxc/DXIL/DxilConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,44 @@ inline bool IsFeedbackTexture(DXIL::ResourceKind ResourceKind) {
ResourceKind == DXIL::ResourceKind::FeedbackTexture2DArray;
}

// clang-format off
// Python lines need to be not formatted.
/* <py::lines('OPCODETABLE-ENUM')>hctdb_instrhelp.get_enum_decl("OpCodeTableID")</py>*/
// clang-format on
// OPCODETABLE-ENUM:BEGIN
// Enumeration for DXIL opcode tables
enum class OpCodeTableID : unsigned {
CoreOps = 0, // Core DXIL operations
ExperimentalOps = 32768, // Experimental DXIL operations

NumOpCodeTables = 2, // exclusive last value of enumeration
};
// OPCODETABLE-ENUM:END

// clang-format off
// Python lines need to be not formatted.
/* <py::lines('EXTOPCODES-ENUM')>hctdb_instrhelp.get_extended_table_opcode_enum_decls()</py>*/
// clang-format on
// EXTOPCODES-ENUM:BEGIN
namespace ExperimentalOps {
static const OpCodeTableID TableID = OpCodeTableID::ExperimentalOps;
// Enumeration for ExperimentalOps DXIL operations
enum class OpCode : unsigned {
ExperimentalNop = 0, // nop does nothing

NumOpCodes = 1, // exclusive last value of enumeration
};
} // namespace ExperimentalOps
// EXTOPCODES-ENUM:END

#define EXP_OPCODE(feature, opcode) \
opcode = \
(((unsigned)feature::TableID << 16) | (unsigned)feature::OpCode::opcode)

// TODO: change opcodes.
/* <py::lines('OPCODE-ENUM')>hctdb_instrhelp.get_enum_decl("OpCode")</py>*/
// OPCODE-ENUM:BEGIN
// Enumeration for operations specified by DXIL
// Enumeration for CoreOps DXIL operations
enum class OpCode : unsigned {
//
Reserved0 = 226, // reserved
Expand Down Expand Up @@ -1089,9 +1123,24 @@ enum class OpCode : unsigned {
NumOpCodes_Dxil_1_8 = 258,
NumOpCodes_Dxil_1_9 = 312,

NumOpCodes = 312 // exclusive last value of enumeration
NumOpCodes = 312, // exclusive last value of enumeration
Invalid = 0xFFFFFFFF, // stable invalid OpCode value

// OpCodes for extended tables follow.

// OpCodeTableID = 32768
// ExperimentalOps
EXP_OPCODE(ExperimentalOps, ExperimentalNop), // nop does nothing

};
// OPCODE-ENUM:END
#undef EXP_OPCODE

// Create Core namespace for consistency with other opcode groups
namespace CoreOps {
static const OpCodeTableID TableID = OpCodeTableID::CoreOps;
using OpCode = hlsl::DXIL::OpCode;
} // namespace CoreOps

// clang-format off
// Python lines need to be not formatted.
Expand Down Expand Up @@ -1244,6 +1293,9 @@ enum class OpCodeClass : unsigned {
StorePrimitiveOutput,
StoreVertexOutput,

// No-op
Nop,

// Other
CycleCounterLegacy,

Expand Down Expand Up @@ -1414,18 +1466,7 @@ enum class OpCodeClass : unsigned {
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_Dxil_1_9 = 196,

NumOpClasses = 196 // exclusive last value of enumeration
NumOpClasses = 197, // exclusive last value of enumeration
};
// OPCODECLASS-ENUM:END

Expand Down
20 changes: 20 additions & 0 deletions include/dxc/DXIL/DxilInstructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10231,5 +10231,25 @@ struct DxilInst_FDot {
llvm::Value *get_b() const { return Instr->getOperand(2); }
void set_b(llvm::Value *val) { Instr->setOperand(2, val); }
};

/// This instruction nop does nothing
struct DxilInst_ExperimentalNop {
llvm::Instruction *Instr;
// Construction and identification
DxilInst_ExperimentalNop(llvm::Instruction *pInstr) : Instr(pInstr) {}
operator bool() const {
return hlsl::OP::IsDxilOpFuncCallInst(Instr,
hlsl::OP::OpCode::ExperimentalNop);
}
// 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
31 changes: 28 additions & 3 deletions include/dxc/DXIL/DxilOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class OP {
public:
using OpCode = DXIL::OpCode;
using OpCodeClass = DXIL::OpCodeClass;
using OpCodeTableID = DXIL::OpCodeTableID;

public:
OP() = delete;
Expand Down Expand Up @@ -131,6 +132,7 @@ class OP {
llvm::Constant *GetFloatConst(float v);
llvm::Constant *GetDoubleConst(double v);

static OP::OpCode getOpCode(unsigned OpCode);
static OP::OpCode getOpCode(const llvm::Instruction *I);
static llvm::Type *GetOverloadType(OpCode OpCode, llvm::Function *F);
static OpCode GetDxilOpFuncCallInst(const llvm::Instruction *I);
Expand Down Expand Up @@ -226,8 +228,7 @@ class OP {
std::unordered_map<const llvm::Function *, OpCodeClass> m_FunctionToOpClass;
void UpdateCache(OpCodeClass opClass, llvm::Type *Ty, llvm::Function *F);

private:
// Static properties.
public:
struct OverloadMask {
// mask of type slot bits as (1 << TypeSlot)
uint16_t SlotMask;
Expand Down Expand Up @@ -255,7 +256,31 @@ class OP {
// AllowedOverloads[n][TS_Vector] is true.
OverloadMask AllowedVectorElements[DXIL::kDxilMaxOloadDims];
};
static const OpCodeProperty m_OpCodeProps[(unsigned)OpCode::NumOpCodes];
struct OpCodeTable {
OpCodeTableID ID;
const OpCodeProperty *Table;
unsigned Count;
};

// Look up table using high 16-bits as table ID, low 16-bits as OpCode.
// Return true if valid.
// unsigned versions are for use with whatever value was in a DXIL Op
// instruction.
// OpIndex is the low 16-bits, for index lookup within the table.
static bool DecodeOpCode(unsigned EncodedOpCode, OpCodeTableID &TableID,
unsigned &OpIndex,
unsigned *OptTableIndex = nullptr);
static bool DecodeOpCode(OpCode EncodedOpCode, OpCodeTableID &TableID,
unsigned &OpIndex,
unsigned *OptTableIndex = nullptr);
static bool IsValidOpCode(unsigned EncodedOpCode);
static bool IsValidOpCode(OpCode EncodedOpCode);

private:
// Static properties.
static OpCodeTable g_OpCodeTables[(unsigned)OpCodeTableID::NumOpCodeTables];
static const OpCodeProperty &GetOpCodeProps(unsigned opCode);
static const OpCodeProperty &GetOpCodeProps(OpCode opCode);

static const char *m_OverloadTypeName[TS_BasicCount];
static const char *m_NamePrefix;
Expand Down
3 changes: 3 additions & 0 deletions include/dxc/DXIL/DxilShaderModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class ShaderModel {
bool IsSMAtLeast(unsigned Major, unsigned Minor) const {
return m_Major > Major || (m_Major == Major && m_Minor >= Minor);
}
bool IsPreReleaseShaderModel() const {
return IsPreReleaseShaderModel(m_Major, m_Minor);
}
bool IsSM50Plus() const { return IsSMAtLeast(5, 0); }
bool IsSM51Plus() const { return IsSMAtLeast(5, 1); }
bool AllowDerivatives(DXIL::ShaderKind sk) const;
Expand Down
Loading