From b82ee6ac144cf0c61450864dac2e348213e6e257 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 16 Aug 2024 14:34:51 +0100 Subject: [PATCH] Stub out PSV structures for external access * We move some commonly used enums to more general spots for ease of use in the encoded data. --- .../driver/shaders/dxbc/dxbc_bytecode.cpp | 2 +- renderdoc/driver/shaders/dxbc/dxbc_bytecode.h | 100 +-------- .../driver/shaders/dxbc/dxbc_bytecode_ops.cpp | 42 ++-- .../driver/shaders/dxbc/dxbc_bytecode_ops.h | 10 +- renderdoc/driver/shaders/dxbc/dxbc_common.h | 95 +++++++- .../driver/shaders/dxbc/dxbc_container.cpp | 18 +- renderdoc/driver/shaders/dxbc/dxbc_debug.cpp | 22 +- .../driver/shaders/dxbc/dxbc_stringise.cpp | 4 +- .../shaders/dxil/dxil_bytecode_editor.h | 14 -- renderdoc/driver/shaders/dxil/dxil_common.h | 54 ++++- .../driver/shaders/dxil/dxil_metadata.cpp | 14 +- renderdoc/driver/shaders/dxil/dxil_metadata.h | 210 +++++++++++++++++- 12 files changed, 419 insertions(+), 166 deletions(-) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_bytecode.cpp b/renderdoc/driver/shaders/dxbc/dxbc_bytecode.cpp index b9ab1de3d..4fe081e01 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_bytecode.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_bytecode.cpp @@ -577,7 +577,7 @@ D3D_PRIMITIVE_TOPOLOGY Program::GetOutputTopology() return decl.geomOutputTopology; if(decl.declaration == DXBCBytecode::OPCODE_DCL_TESS_DOMAIN) { - if(decl.tessDomain == DXBCBytecode::DOMAIN_ISOLINE) + if(decl.tessDomain == DXBC::TessellatorDomain::DOMAIN_ISOLINE) return D3D_PRIMITIVE_TOPOLOGY_LINELIST; else return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_bytecode.h b/renderdoc/driver/shaders/dxbc/dxbc_bytecode.h index ad5d26237..5e67dcd2b 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_bytecode.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_bytecode.h @@ -540,96 +540,6 @@ enum CBufferAccessPattern NUM_PATTERNS, }; -enum TessellatorDomain -{ - DOMAIN_UNDEFINED = 0, - DOMAIN_ISOLINE, - DOMAIN_TRI, - DOMAIN_QUAD, - - NUM_DOMAINS, -}; - -enum TessellatorPartitioning -{ - PARTITIONING_UNDEFINED = 0, - PARTITIONING_INTEGER, - PARTITIONING_POW2, - PARTITIONING_FRACTIONAL_ODD, - PARTITIONING_FRACTIONAL_EVEN, - - NUM_PARTITIONINGS, -}; - -enum TessellatorOutputPrimitive -{ - OUTPUT_PRIMITIVE_UNDEFINED = 0, - OUTPUT_PRIMITIVE_POINT, - OUTPUT_PRIMITIVE_LINE, - OUTPUT_PRIMITIVE_TRIANGLE_CW, - OUTPUT_PRIMITIVE_TRIANGLE_CCW, - - NUM_OUTPUT_PRIMITIVES, -}; - -enum InterpolationMode -{ - INTERPOLATION_UNDEFINED = 0, - INTERPOLATION_CONSTANT, - INTERPOLATION_LINEAR, - INTERPOLATION_LINEAR_CENTROID, - INTERPOLATION_LINEAR_NOPERSPECTIVE, - INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID, - INTERPOLATION_LINEAR_SAMPLE, - INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE, - - NUM_INTERPOLATIONS, -}; - -enum PrimitiveType -{ - PRIMITIVE_UNDEFINED = 0, - PRIMITIVE_POINT, - PRIMITIVE_LINE, - PRIMITIVE_TRIANGLE, - PRIMITIVE_LINE_ADJ, - PRIMITIVE_TRIANGLE_ADJ, - PRIMITIVE_1_CONTROL_POINT_PATCH, - PRIMITIVE_2_CONTROL_POINT_PATCH, - PRIMITIVE_3_CONTROL_POINT_PATCH, - PRIMITIVE_4_CONTROL_POINT_PATCH, - PRIMITIVE_5_CONTROL_POINT_PATCH, - PRIMITIVE_6_CONTROL_POINT_PATCH, - PRIMITIVE_7_CONTROL_POINT_PATCH, - PRIMITIVE_8_CONTROL_POINT_PATCH, - PRIMITIVE_9_CONTROL_POINT_PATCH, - PRIMITIVE_10_CONTROL_POINT_PATCH, - PRIMITIVE_11_CONTROL_POINT_PATCH, - PRIMITIVE_12_CONTROL_POINT_PATCH, - PRIMITIVE_13_CONTROL_POINT_PATCH, - PRIMITIVE_14_CONTROL_POINT_PATCH, - PRIMITIVE_15_CONTROL_POINT_PATCH, - PRIMITIVE_16_CONTROL_POINT_PATCH, - PRIMITIVE_17_CONTROL_POINT_PATCH, - PRIMITIVE_18_CONTROL_POINT_PATCH, - PRIMITIVE_19_CONTROL_POINT_PATCH, - PRIMITIVE_20_CONTROL_POINT_PATCH, - PRIMITIVE_21_CONTROL_POINT_PATCH, - PRIMITIVE_22_CONTROL_POINT_PATCH, - PRIMITIVE_23_CONTROL_POINT_PATCH, - PRIMITIVE_24_CONTROL_POINT_PATCH, - PRIMITIVE_25_CONTROL_POINT_PATCH, - PRIMITIVE_26_CONTROL_POINT_PATCH, - PRIMITIVE_27_CONTROL_POINT_PATCH, - PRIMITIVE_28_CONTROL_POINT_PATCH, - PRIMITIVE_29_CONTROL_POINT_PATCH, - PRIMITIVE_30_CONTROL_POINT_PATCH, - PRIMITIVE_31_CONTROL_POINT_PATCH, - PRIMITIVE_32_CONTROL_POINT_PATCH, - - NUM_PRIMITIVES, -}; - enum SemanticName { SEMANTIC_UNDEFINED = 0, @@ -1068,7 +978,7 @@ struct Declaration struct { // only used for PS inputs - InterpolationMode inputInterpolation; + DXBC::InterpolationMode inputInterpolation; DXBC::SVSemantic systemValue; } inputOutput; @@ -1079,19 +989,19 @@ struct Declaration SamplerMode samplerMode; // OPCODE_DCL_TESS_DOMAIN - TessellatorDomain tessDomain; + DXBC::TessellatorDomain tessDomain; // OPCODE_DCL_INPUT_CONTROL_POINT_COUNT uint32_t controlPointCount; // OPCODE_DCL_TESS_PARTITIONING - TessellatorPartitioning tessPartition; + DXBC::TessellatorPartitioning tessPartition; // OPCODE_DCL_TESS_OUTPUT_PRIMITIVE - TessellatorOutputPrimitive tessOutputPrimitive; + DXBC::TessellatorOutputPrimitive tessOutputPrimitive; // OPCODE_DCL_GS_INPUT_PRIMITIVE - PrimitiveType geomInputPrimitive; + DXBC::PrimitiveType geomInputPrimitive; // OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY D3D_PRIMITIVE_TOPOLOGY geomOutputTopology; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.cpp b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.cpp index ea5b365f6..21454c362 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.cpp @@ -2218,11 +2218,11 @@ bool Program::DecodeDecl(uint32_t *&tokenStream, Declaration &retDecl, bool frie retDecl.tessDomain = Decl::TessDomain.Get(OpcodeToken0); retDecl.str += " "; - if(retDecl.tessDomain == DOMAIN_ISOLINE) + if(retDecl.tessDomain == DXBC::TessellatorDomain::DOMAIN_ISOLINE) retDecl.str += "domain_isoline"; - else if(retDecl.tessDomain == DOMAIN_TRI) + else if(retDecl.tessDomain == DXBC::TessellatorDomain::DOMAIN_TRI) retDecl.str += "domain_tri"; - else if(retDecl.tessDomain == DOMAIN_QUAD) + else if(retDecl.tessDomain == DXBC::TessellatorDomain::DOMAIN_QUAD) retDecl.str += "domain_quad"; else RDCERR("Unexpected Tessellation domain"); @@ -2232,13 +2232,13 @@ bool Program::DecodeDecl(uint32_t *&tokenStream, Declaration &retDecl, bool frie retDecl.tessPartition = Decl::TessPartitioning.Get(OpcodeToken0); retDecl.str += " "; - if(retDecl.tessPartition == PARTITIONING_INTEGER) + if(retDecl.tessPartition == DXBC::PARTITIONING_INTEGER) retDecl.str += "partitioning_integer"; - else if(retDecl.tessPartition == PARTITIONING_POW2) + else if(retDecl.tessPartition == DXBC::PARTITIONING_POW2) retDecl.str += "partitioning_pow2"; - else if(retDecl.tessPartition == PARTITIONING_FRACTIONAL_ODD) + else if(retDecl.tessPartition == DXBC::PARTITIONING_FRACTIONAL_ODD) retDecl.str += "partitioning_fractional_odd"; - else if(retDecl.tessPartition == PARTITIONING_FRACTIONAL_EVEN) + else if(retDecl.tessPartition == DXBC::PARTITIONING_FRACTIONAL_EVEN) retDecl.str += "partitioning_fractional_even"; else RDCERR("Unexpected Partitioning"); @@ -2248,22 +2248,22 @@ bool Program::DecodeDecl(uint32_t *&tokenStream, Declaration &retDecl, bool frie retDecl.geomInputPrimitive = Decl::InputPrimitive.Get(OpcodeToken0); retDecl.str += " "; - if(retDecl.geomInputPrimitive == PRIMITIVE_POINT) + if(retDecl.geomInputPrimitive == DXBC::PRIMITIVE_POINT) retDecl.str += "point"; - else if(retDecl.geomInputPrimitive == PRIMITIVE_LINE) + else if(retDecl.geomInputPrimitive == DXBC::PRIMITIVE_LINE) retDecl.str += "line"; - else if(retDecl.geomInputPrimitive == PRIMITIVE_TRIANGLE) + else if(retDecl.geomInputPrimitive == DXBC::PRIMITIVE_TRIANGLE) retDecl.str += "triangle"; - else if(retDecl.geomInputPrimitive == PRIMITIVE_LINE_ADJ) + else if(retDecl.geomInputPrimitive == DXBC::PRIMITIVE_LINE_ADJ) retDecl.str += "line_adj"; - else if(retDecl.geomInputPrimitive == PRIMITIVE_TRIANGLE_ADJ) + else if(retDecl.geomInputPrimitive == DXBC::PRIMITIVE_TRIANGLE_ADJ) retDecl.str += "triangle_adj"; - else if(retDecl.geomInputPrimitive >= PRIMITIVE_1_CONTROL_POINT_PATCH && - retDecl.geomInputPrimitive <= PRIMITIVE_32_CONTROL_POINT_PATCH) + else if(retDecl.geomInputPrimitive >= DXBC::PRIMITIVE_1_CONTROL_POINT_PATCH && + retDecl.geomInputPrimitive <= DXBC::PRIMITIVE_32_CONTROL_POINT_PATCH) { - retDecl.str += - StringFormat::Fmt("control_point_patch_%u", - 1 + int(retDecl.geomInputPrimitive - PRIMITIVE_1_CONTROL_POINT_PATCH)); + retDecl.str += StringFormat::Fmt( + "control_point_patch_%u", + 1 + int(retDecl.geomInputPrimitive - DXBC::PRIMITIVE_1_CONTROL_POINT_PATCH)); } else RDCERR("Unexpected primitive type"); @@ -2299,13 +2299,13 @@ bool Program::DecodeDecl(uint32_t *&tokenStream, Declaration &retDecl, bool frie retDecl.tessOutputPrimitive = Decl::OutputPrimitive.Get(OpcodeToken0); retDecl.str += " "; - if(retDecl.tessOutputPrimitive == OUTPUT_PRIMITIVE_POINT) + if(retDecl.tessOutputPrimitive == DXBC::OUTPUT_PRIMITIVE_POINT) retDecl.str += "output_point"; - else if(retDecl.tessOutputPrimitive == OUTPUT_PRIMITIVE_LINE) + else if(retDecl.tessOutputPrimitive == DXBC::OUTPUT_PRIMITIVE_LINE) retDecl.str += "output_line"; - else if(retDecl.tessOutputPrimitive == OUTPUT_PRIMITIVE_TRIANGLE_CW) + else if(retDecl.tessOutputPrimitive == DXBC::OUTPUT_PRIMITIVE_TRIANGLE_CW) retDecl.str += "output_triangle_cw"; - else if(retDecl.tessOutputPrimitive == OUTPUT_PRIMITIVE_TRIANGLE_CCW) + else if(retDecl.tessOutputPrimitive == DXBC::OUTPUT_PRIMITIVE_TRIANGLE_CCW) retDecl.str += "output_triangle_ccw"; else RDCERR("Unexpected output primitive"); diff --git a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.h b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.h index eb86c93d6..6e0ef061a 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_bytecode_ops.h @@ -166,26 +166,26 @@ static MaskedElement ReturnTypeW; // OPCODE_DCL_INPUT_PS // OPCODE_DCL_INPUT_PS_SIV -static MaskedElement InterpolationMode; +static MaskedElement InterpolationMode; // OPCODE_DCL_INPUT_CONTROL_POINT_COUNT // OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT static MaskedElement ControlPointCount; // OPCODE_DCL_TESS_DOMAIN -static MaskedElement TessDomain; +static MaskedElement TessDomain; // OPCODE_DCL_TESS_PARTITIONING -static MaskedElement TessPartitioning; +static MaskedElement TessPartitioning; // OPCODE_DCL_GS_INPUT_PRIMITIVE -static MaskedElement InputPrimitive; +static MaskedElement InputPrimitive; // OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY static MaskedElement OutputPrimitiveTopology; // OPCODE_DCL_TESS_OUTPUT_PRIMITIVE -static MaskedElement OutputPrimitive; +static MaskedElement OutputPrimitive; // OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED static MaskedElement GloballyCoherent; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_common.h b/renderdoc/driver/shaders/dxbc/dxbc_common.h index 9526ad69f..468869f7d 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_common.h +++ b/renderdoc/driver/shaders/dxbc/dxbc_common.h @@ -56,7 +56,7 @@ struct CountOffset }; // matches D3D11_SHADER_VERSION_TYPE from d3d11shader.h -enum class ShaderType : uint32_t +enum class ShaderType : uint8_t { // D3D10 Shaders Pixel = 0, @@ -106,7 +106,7 @@ enum ResourceRetType : uint8_t NUM_RETURN_TYPES, }; -enum SigCompType +enum class SigCompType : uint8_t { COMPONENT_TYPE_UNKNOWN = 0, COMPONENT_TYPE_UINT32, @@ -122,6 +122,20 @@ enum SigCompType NUM_COMP_TYPES, }; +enum class InterpolationMode : uint8_t +{ + INTERPOLATION_UNDEFINED = 0, + INTERPOLATION_CONSTANT, + INTERPOLATION_LINEAR, + INTERPOLATION_LINEAR_CENTROID, + INTERPOLATION_LINEAR_NOPERSPECTIVE, + INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID, + INTERPOLATION_LINEAR_SAMPLE, + INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE, + + NUM_INTERPOLATIONS, +}; + enum SVSemantic { SVNAME_UNDEFINED = 0, @@ -238,6 +252,83 @@ enum VariableType VARTYPE_UINT64, }; +enum class TessellatorDomain : uint8_t +{ + DOMAIN_UNDEFINED = 0, + DOMAIN_ISOLINE, + DOMAIN_TRI, + DOMAIN_QUAD, + + NUM_DOMAINS, +}; + +enum TessellatorPartitioning +{ + PARTITIONING_UNDEFINED = 0, + PARTITIONING_INTEGER, + PARTITIONING_POW2, + PARTITIONING_FRACTIONAL_ODD, + PARTITIONING_FRACTIONAL_EVEN, + + NUM_PARTITIONINGS, +}; + +enum TessellatorOutputPrimitive +{ + OUTPUT_PRIMITIVE_UNDEFINED = 0, + OUTPUT_PRIMITIVE_POINT, + OUTPUT_PRIMITIVE_LINE, + OUTPUT_PRIMITIVE_TRIANGLE_CW, + OUTPUT_PRIMITIVE_TRIANGLE_CCW, + + NUM_OUTPUT_PRIMITIVES, +}; + +enum PrimitiveType +{ + PRIMITIVE_UNDEFINED = 0, + PRIMITIVE_POINT, + PRIMITIVE_LINE, + PRIMITIVE_TRIANGLE, + // 4 and 5 are skipped + PRIMITIVE_LINE_ADJ = 6, + PRIMITIVE_TRIANGLE_ADJ, + PRIMITIVE_1_CONTROL_POINT_PATCH, + PRIMITIVE_2_CONTROL_POINT_PATCH, + PRIMITIVE_3_CONTROL_POINT_PATCH, + PRIMITIVE_4_CONTROL_POINT_PATCH, + PRIMITIVE_5_CONTROL_POINT_PATCH, + PRIMITIVE_6_CONTROL_POINT_PATCH, + PRIMITIVE_7_CONTROL_POINT_PATCH, + PRIMITIVE_8_CONTROL_POINT_PATCH, + PRIMITIVE_9_CONTROL_POINT_PATCH, + PRIMITIVE_10_CONTROL_POINT_PATCH, + PRIMITIVE_11_CONTROL_POINT_PATCH, + PRIMITIVE_12_CONTROL_POINT_PATCH, + PRIMITIVE_13_CONTROL_POINT_PATCH, + PRIMITIVE_14_CONTROL_POINT_PATCH, + PRIMITIVE_15_CONTROL_POINT_PATCH, + PRIMITIVE_16_CONTROL_POINT_PATCH, + PRIMITIVE_17_CONTROL_POINT_PATCH, + PRIMITIVE_18_CONTROL_POINT_PATCH, + PRIMITIVE_19_CONTROL_POINT_PATCH, + PRIMITIVE_20_CONTROL_POINT_PATCH, + PRIMITIVE_21_CONTROL_POINT_PATCH, + PRIMITIVE_22_CONTROL_POINT_PATCH, + PRIMITIVE_23_CONTROL_POINT_PATCH, + PRIMITIVE_24_CONTROL_POINT_PATCH, + PRIMITIVE_25_CONTROL_POINT_PATCH, + PRIMITIVE_26_CONTROL_POINT_PATCH, + PRIMITIVE_27_CONTROL_POINT_PATCH, + PRIMITIVE_28_CONTROL_POINT_PATCH, + PRIMITIVE_29_CONTROL_POINT_PATCH, + PRIMITIVE_30_CONTROL_POINT_PATCH, + PRIMITIVE_31_CONTROL_POINT_PATCH, + PRIMITIVE_32_CONTROL_POINT_PATCH, + + NUM_PRIMITIVES, +}; + struct ShaderInputBind { rdcstr name; diff --git a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp index b0053e900..32fe13c0b 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_container.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_container.cpp @@ -1949,23 +1949,23 @@ DXBCContainer::DXBCContainer(const bytebuf &ByteCode, const rdcstr &debugInfoPat SigCompType compType = (SigCompType)el->componentType; desc.varType = VarType::Float; - if(compType == COMPONENT_TYPE_UINT32) + if(compType == DXBC::SigCompType::COMPONENT_TYPE_UINT32) desc.varType = VarType::UInt; - else if(compType == COMPONENT_TYPE_SINT32) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_SINT32) desc.varType = VarType::SInt; - else if(compType == COMPONENT_TYPE_FLOAT32) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_FLOAT32) desc.varType = VarType::Float; - else if(compType == COMPONENT_TYPE_UINT16) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_UINT16) desc.varType = VarType::UShort; - else if(compType == COMPONENT_TYPE_SINT16) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_SINT16) desc.varType = VarType::SShort; - else if(compType == COMPONENT_TYPE_FLOAT16) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_FLOAT16) desc.varType = VarType::Half; - else if(compType == COMPONENT_TYPE_UINT64) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_UINT64) desc.varType = VarType::ULong; - else if(compType == COMPONENT_TYPE_SINT64) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_SINT64) desc.varType = VarType::SLong; - else if(compType == COMPONENT_TYPE_FLOAT64) + else if(compType == DXBC::SigCompType::COMPONENT_TYPE_FLOAT64) desc.varType = VarType::Double; desc.regChannelMask = (uint8_t)(el->mask & 0xff); diff --git a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp index a9b6da6ab..649b8b41f 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_debug.cpp @@ -4730,12 +4730,12 @@ void LookupSRVFormatFromShaderReflection(const DXBC::Reflection &reflection, } } -DXBCBytecode::InterpolationMode GetInterpolationModeForInputParam(const SigParameter &sig, - const DXBC::Reflection &psDxbc, - const DXBCBytecode::Program *program) +DXBC::InterpolationMode GetInterpolationModeForInputParam(const SigParameter &sig, + const DXBC::Reflection &psDxbc, + const DXBCBytecode::Program *program) { if(sig.varType == VarType::SInt || sig.varType == VarType::UInt) - return DXBCBytecode::InterpolationMode::INTERPOLATION_CONSTANT; + return DXBC::InterpolationMode::INTERPOLATION_CONSTANT; if(sig.varType == VarType::Float) { @@ -4744,10 +4744,10 @@ DXBCBytecode::InterpolationMode GetInterpolationModeForInputParam(const SigParam for(size_t j = 0; j < numInputs; j++) { if(sig.regIndex == psDxbc.InputSig[j].regIndex && psDxbc.InputSig[j].varType != VarType::Float) - return DXBCBytecode::InterpolationMode::INTERPOLATION_CONSTANT; + return DXBC::InterpolationMode::INTERPOLATION_CONSTANT; } - DXBCBytecode::InterpolationMode interpolation = DXBCBytecode::INTERPOLATION_UNDEFINED; + DXBC::InterpolationMode interpolation = DXBC::InterpolationMode::INTERPOLATION_UNDEFINED; if(program) { @@ -4768,7 +4768,7 @@ DXBCBytecode::InterpolationMode GetInterpolationModeForInputParam(const SigParam } RDCERR("Unexpected input signature type: %s", ToStr(sig.varType).c_str()); - return DXBCBytecode::InterpolationMode::INTERPOLATION_UNDEFINED; + return DXBC::InterpolationMode::INTERPOLATION_UNDEFINED; } void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, @@ -4906,9 +4906,8 @@ void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, nextreg = sig.regIndex + 1; - DXBCBytecode::InterpolationMode interpolation = - GetInterpolationModeForInputParam(sig, psDxbc, program); - if(interpolation != DXBCBytecode::INTERPOLATION_UNDEFINED) + DXBC::InterpolationMode interpolation = GetInterpolationModeForInputParam(sig, psDxbc, program); + if(interpolation != DXBC::InterpolationMode::INTERPOLATION_UNDEFINED) psInputDefinition += ToStr(interpolation) + " "; psInputDefinition += ToStr(sig.varType); @@ -4951,8 +4950,7 @@ void GatherPSInputDataForInitialValues(const DXBC::DXBCContainer *dxbc, int jNumCols = (jSig.regChannelMask & 0x1 ? 1 : 0) + (jSig.regChannelMask & 0x2 ? 1 : 0) + (jSig.regChannelMask & 0x4 ? 1 : 0) + (jSig.regChannelMask & 0x8 ? 1 : 0); - DXBCBytecode::InterpolationMode jInterp = - GetInterpolationModeForInputParam(jSig, psDxbc, program); + DXBC::InterpolationMode jInterp = GetInterpolationModeForInputParam(jSig, psDxbc, program); // if it's the same size, type, and interpolation mode, then it could potentially be // packed into an array. Check if it's using the first channel component to tell whether diff --git a/renderdoc/driver/shaders/dxbc/dxbc_stringise.cpp b/renderdoc/driver/shaders/dxbc/dxbc_stringise.cpp index 3f04c787a..561bf2c9d 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_stringise.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_stringise.cpp @@ -434,9 +434,9 @@ rdcstr DoStringise(const DXBCBytecode::ResinfoRetType &el) } template <> -rdcstr DoStringise(const DXBCBytecode::InterpolationMode &el) +rdcstr DoStringise(const DXBC::InterpolationMode &el) { - BEGIN_ENUM_STRINGISE(DXBCBytecode::InterpolationMode) + BEGIN_ENUM_STRINGISE(DXBC::InterpolationMode) { STRINGISE_ENUM_CLASS_NAMED(INTERPOLATION_UNDEFINED, "undefined"); // differs slightly from fxc but it's very convenient to use the hlsl terms, which are used in diff --git a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.h b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.h index 455e5a4b6..be3f38ed3 100644 --- a/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.h +++ b/renderdoc/driver/shaders/dxil/dxil_bytecode_editor.h @@ -40,20 +40,6 @@ class BitcodeWriter; namespace DXIL { -enum class DXILResourceType -{ - Unknown, - Sampler, - CBuffer, - TypedSRV, - ByteAddressSRV, - StructuredSRV, - TypedUAV, - ByteAddressUAV, - StructuredUAV, - StructuredUAVWithCounter, -}; - enum class HandleKind { SRV = 0, diff --git a/renderdoc/driver/shaders/dxil/dxil_common.h b/renderdoc/driver/shaders/dxil/dxil_common.h index 2f3a025b6..e51563a4a 100644 --- a/renderdoc/driver/shaders/dxil/dxil_common.h +++ b/renderdoc/driver/shaders/dxil/dxil_common.h @@ -26,7 +26,7 @@ namespace DXBC { -enum class ShaderType : uint32_t; +enum class ShaderType : uint8_t; enum class GlobalShaderFlags : int64_t; }; @@ -89,6 +89,58 @@ enum class ResourceKind SamplerComparison, }; +// different semantic enum +enum class SigSemantic : uint8_t +{ + Undefined = 0, + VertexIndex, + InstanceIndex, + Position, + RTIndex, + ViewportIndex, + ClipDistance, + CullDistance, + OutputControlPointIndex, + DomainLocation, + PrimitiveIndex, + GSInstanceIndex, + MSAASampleIndex, + IsFrontFace, + MSAACoverage, + IsFullyCovered, + ColorOutput, + DepthOutput, + DepthOutputLessEqual, + DepthOutputGreaterEqual, + StencilReference, + DispatchThreadIndex, + GroupIndex, + GroupFlatIndex, + GroupThreadIndex, + OuterTessFactor, + InsideTessFactor, + MultiViewIndex, + Barycentrics, + PackedFragRate, + CullPrimitive, + BaseVertex, + BaseInstance, +}; + +enum class DXILResourceType : uint32_t +{ + Unknown, + Sampler, + CBuffer, + TypedSRV, + ByteAddressSRV, + StructuredSRV, + TypedUAV, + ByteAddressUAV, + StructuredUAV, + StructuredUAVWithCounter, +}; + enum class SamplerKind { Default = 0, diff --git a/renderdoc/driver/shaders/dxil/dxil_metadata.cpp b/renderdoc/driver/shaders/dxil/dxil_metadata.cpp index c30856e57..4537ca5c4 100644 --- a/renderdoc/driver/shaders/dxil/dxil_metadata.cpp +++ b/renderdoc/driver/shaders/dxil/dxil_metadata.cpp @@ -161,7 +161,11 @@ struct EncodedFunctionInfo IndexReference unmangledName; IndexReference globalResourcesIndexArrayRef; IndexReference functionDependenciesArrayRef; - DXBC::ShaderType type; + union + { + DXBC::ShaderType type; + uint32_t type_padding_; // pad to 32-bit so the enum can be 8-bit + }; uint32_t payloadBytes; uint32_t attribBytes; // extremely annoyingly this is two 32-bit integers which is relevant since 64-bit alignment @@ -267,6 +271,14 @@ namespace DXBC { bool DXBCContainer::GetPipelineValidation(DXIL::PSVData &psv) const { + RDCCOMPILE_ASSERT(sizeof(DXIL::PSVData0) == DXIL::PSVData0::ExpectedSize, + "PSVData0 is not sized/packed correctly"); + RDCCOMPILE_ASSERT(sizeof(DXIL::PSVData1) == DXIL::PSVData1::ExpectedSize, + "PSVData1 is not sized/packed correctly"); + RDCCOMPILE_ASSERT(sizeof(DXIL::PSVData2) == DXIL::PSVData2::ExpectedSize, + "PSVData2 is not sized/packed correctly"); + RDCCOMPILE_ASSERT(offsetof(DXIL::PSVData1, inputSigElems) == sizeof(DXIL::PSVData0) + 4, "!!!"); + using namespace DXIL; if(m_PSVOffset == 0) diff --git a/renderdoc/driver/shaders/dxil/dxil_metadata.h b/renderdoc/driver/shaders/dxil/dxil_metadata.h index 0542f4192..5f6b91801 100644 --- a/renderdoc/driver/shaders/dxil/dxil_metadata.h +++ b/renderdoc/driver/shaders/dxil/dxil_metadata.h @@ -24,19 +24,222 @@ #pragma once +#include "driver/dx/official/d3dcommon.h" +#include "driver/shaders/dxbc/dxbc_common.h" #include "dxil_common.h" namespace DXBC { -enum class ShaderType : uint32_t; +enum class ShaderType : uint8_t; enum class GlobalShaderFlags : int64_t; }; namespace DXIL { -struct PSVData +struct PSVData0 { + struct VSInfo + { + bool SVPositionOutput; + }; + + struct HSInfo + { + uint32_t inputCPs; + uint32_t outputCPs; + DXBC::TessellatorDomain tessDomain; + DXBC::TessellatorOutputPrimitive outPrim; + }; + + struct DSInfo + { + uint32_t inputCPs; + bool SVPositionOutput; + DXBC::TessellatorDomain tessDomain; + }; + + struct GSInfo + { + DXBC::PrimitiveType inputPrim; + D3D_PRIMITIVE_TOPOLOGY outputTopo; + uint32_t outputStreams; + bool SVPositionOutput; + }; + + struct PSInfo + { + bool SVDepthOutput; + bool SampleRate; + }; + + struct ASInfo + { + uint32_t payloadBytes; + }; + + struct MSInfo + { + uint32_t groupsharedBytes; + uint32_t groupsharedViewIDDepBytes; + uint32_t payloadBytes; + uint16_t maxVerts; + uint16_t maxPrims; + }; + + union + { + VSInfo vs; + HSInfo hs; + DSInfo ds; + GSInfo gs; + PSInfo ps; + ASInfo as; + MSInfo ms; + }; + uint32_t minWaveCount; + uint32_t maxWaveCount; + + static const size_t ExpectedSize = sizeof(uint32_t) * 6; +}; + +struct PSVData1 : public PSVData0 +{ + static const uint32_t NumOutputStreams = 4; + + DXBC::ShaderType shaderType; + bool useViewID; + + union + { + struct + { + uint16_t maxVerts; + } gs1; + + struct + { + uint8_t sigPatchConstVectors; + } hs, gs; + + struct + { + uint8_t sigPrimVectors; + DXBC::TessellatorDomain topology; + } ms; + }; + + uint8_t inputSigElems; + uint8_t outputSigElems; + uint8_t patchConstPrimSigElems; + + uint8_t inputSigVectors; + uint8_t outputSigVectors[NumOutputStreams]; // one per geometry stream + + static const size_t ExpectedSize = sizeof(PSVData0) + sizeof(uint16_t) + 10 * sizeof(uint8_t); +}; + +struct PSVData2 : public PSVData1 +{ + uint32_t threadCount[3]; + + static const size_t ExpectedSize = sizeof(PSVData1) + 3 * sizeof(uint32_t); +}; + +struct PSVResource0 +{ + DXILResourceType type; + uint32_t space; // register space + uint32_t regStart; // start register (inclusive - for single register bind it's == reg) + uint32_t regEnd; // end register (inclusive - for single register bind it's == reg) +}; + +enum class PSVResourceFlags +{ + None = 0x0, + Atomic64 = 0x1, +}; + +struct PSVResource1 : public PSVResource0 +{ + DXIL::ResourceKind kind; + PSVResourceFlags flags; +}; + +using PSVResource = PSVResource1; + +struct PSVSignature0 +{ + rdcstr name; + rdcarray semIndices; + uint8_t rows; + uint8_t firstRow; + uint8_t cols; // : 4 + uint8_t startCol; // :2 + uint8_t alloc; // :2 + SigSemantic semantic; + DXBC::SigCompType compType; + DXBC::InterpolationMode interpMode; + uint8_t dynamicMask; // :4 + uint8_t stream; // :2 + uint8_t padding; +}; + +using PSVSignature = PSVSignature0; + +inline const uint32_t VectorBitmaskBitSize(uint32_t numVectors) +{ + return AlignUp(numVectors * 4, 64U); +} + +struct PSVData : public PSVData2 +{ + enum class Version + { + Version0 = 0, + Version1, + Version2, + VersionLatest = Version2, + } version = Version::VersionLatest; + + rdcarray resources; + + // stringtable + // semanticindexs + + rdcarray inputSig; + rdcarray outputSig; + rdcarray patchConstPrimSig; + + // in the tables below we assume no more than 64 dwords in any signature (16 vectors) so store + // bitmasks as 64-bit. + + // if view ID is used, a bitmask per output stream, the bitmask containing one bit per dword as + // in PSVData1::outputSigVectors indicating if that output vector depends on view ID + struct + { + uint64_t outputMask; + uint64_t patchConstMask; + } viewIDAffects[PSVData1::NumOutputStreams]; + + // for each stream, a bitmask for each input vector with the bitmask containing which output + // vectors have a dependency on the input vector. + struct + { + rdcarray dependentOutputsForInput; + } IODependencies[PSVData1::NumOutputStreams]; + + // same as above, but for patch constant outputs on inputs - HS only + struct + { + rdcarray dependentPCOutputsForInput; + } PCOutDependencies; + + // same as above, but for outputs on patch constant inputs - DS only + struct + { + rdcarray dependentOutputsForPCInput; + } PCInDependencies; }; struct RDATData @@ -116,7 +319,7 @@ struct RDATData uint16_t minType; // looks to always be equal to type above }; - struct FunctionInfo2 : FunctionInfo + struct FunctionInfo2 : public FunctionInfo { FunctionInfo2(FunctionInfo &info) : FunctionInfo(info) { @@ -233,5 +436,6 @@ struct RDATData }; +BITMASK_OPERATORS(DXIL::PSVResourceFlags); BITMASK_OPERATORS(DXIL::RDATData::ResourceFlags); BITMASK_OPERATORS(DXIL::RDATData::ShaderBehaviourFlags);