git.s-ol.nu ~forks/DiligentCore / 3d100ff
Removed mutable fields from ResourceBindingMap azhirnov authored 6 months ago assiduous committed 6 months ago
8 changed file(s) with 413 addition(s) and 290 deletion(s). Raw diff Collapse all Expand all
340340 const auto IsArray = ResDesc.ArraySize != 1;
341341
342342 d3d12RootParamType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
343 static_assert(SHADER_RESOURCE_TYPE_LAST == SHADER_RESOURCE_TYPE_ACCEL_STRUCT, "Please update the switch below to handle the new shader resource type");
343344 switch (ResDesc.ResourceType)
344345 {
345346 case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
634635 VERIFY_EXPR(BufferGPUAddress != 0);
635636
636637 auto* const pd3d12CmdList = CommitAttribs.Ctx.GetCommandList();
638 static_assert(SHADER_RESOURCE_TYPE_LAST == SHADER_RESOURCE_TYPE_ACCEL_STRUCT, "Please update the switch below to handle the new shader resource type");
637639 switch (Res.Type)
638640 {
639641 case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
791793 {
792794 Attribs.Register,
793795 Attribs.Space + BaseRegisterSpace,
794 ResDesc.ArraySize //
796 ResDesc.ArraySize,
797 ResDesc.ResourceType //
795798 };
796799 auto IsUnique = ResourceMap.emplace(HashMapStringKey{ResDesc.Name}, BindInfo).second;
797800 VERIFY(IsUnique, "Shader resource '", ResDesc.Name,
815818 {
816819 SampAttr.ShaderRegister,
817820 SampAttr.RegisterSpace + BaseRegisterSpace,
818 SampAttr.ArraySize //
821 SampAttr.ArraySize,
822 SHADER_RESOURCE_TYPE_SAMPLER //
819823 };
820824
821825 auto it_inserted = ResourceMap.emplace(HashMapStringKey{SampName}, BindInfo);
607607
608608 if (pLocalRootSig != nullptr && pLocalRootSig->IsDefined())
609609 {
610 bool IsUnique = ResourceMap.emplace(HashMapStringKey{pLocalRootSig->GetName()}, ResourceBinding::BindInfo{pLocalRootSig->GetShaderRegister(), pLocalRootSig->GetRegisterSpace(), 1}).second;
610 ResourceBinding::BindInfo BindInfo //
611 {
612 pLocalRootSig->GetShaderRegister(),
613 pLocalRootSig->GetRegisterSpace(),
614 1,
615 SHADER_RESOURCE_TYPE_CONSTANT_BUFFER //
616 };
617 bool IsUnique = ResourceMap.emplace(HashMapStringKey{pLocalRootSig->GetName()}, BindInfo).second;
611618 if (!IsUnique)
612619 LOG_ERROR_AND_THROW("Shader record constant buffer already exists in the resource signature");
613620 }
8888
8989 using BindInfo = ResourceBinding::BindInfo;
9090 using TResourceBindingMap = ResourceBinding::TMap;
91 using ShaderResType = ResourceBinding::ResType;
9291
9392 /// Remaps resource bindings (shader registers) in the source byte code using the
9493 /// resource binding map.
3030
3131 #include "Constants.h"
3232 #include "HashUtils.hpp"
33 #include "Shader.h"
3334
3435 namespace Diligent
3536 {
3637
3738 struct ResourceBinding
3839 {
39 enum ResType : Uint32
40 {
41 CBV = 0,
42 SRV = 1,
43 Sampler = 2,
44 UAV = 3,
45 Count,
46 };
47
4840 struct BindInfo
4941 {
50 // new bind point & space
5142 Uint32 BindPoint = ~0u;
5243 Uint32 Space = ~0u;
5344 Uint32 ArraySize = 0;
5445
55 // current (previous) bind point & space
56 mutable Uint32 SrcBindPoint = ~0u;
57 mutable Uint32 SrcSpace = ~0u;
58 mutable ResType Type = ResType::Count;
59 mutable Uint32 UID = ~0u; // Unique resource record ID
46 #ifdef DILIGENT_DEBUG
47 SHADER_RESOURCE_TYPE ResType = SHADER_RESOURCE_TYPE_UNKNOWN;
48 #endif
6049
61 BindInfo() {}
50 BindInfo()
51 {}
6252
63 BindInfo(Uint32 _BindPoint, Uint32 _Space, Uint32 _ArraySize) :
64 BindPoint{_BindPoint}, Space{_Space}, ArraySize{_ArraySize}
53 BindInfo(Uint32 _BindPoint, Uint32 _Space, Uint32 _ArraySize, SHADER_RESOURCE_TYPE _ResType) :
54 // clang-format off
55 BindPoint{_BindPoint},
56 Space {_Space },
57 ArraySize{_ArraySize}
58 #ifdef DILIGENT_DEBUG
59 , ResType{_ResType }
60 #endif
61 // clang-format on
6562 {}
6663 };
6764
538538 D3D11_SB_CUSTOMDATA_SHADER_CLIP_PLANE_CONSTANT_MAPPINGS_FOR_DX9,
539539 };
540540
541 using ShaderResType = ResourceBinding::ResType;
542 using ResourceBindingPerType = std::array<std::vector<DXBCUtils::BindInfo const*>, ShaderResType::Count + 1>;
541 enum RES_TYPE : Uint32
542 {
543 RES_TYPE_CBV = 0,
544 RES_TYPE_SRV = 1,
545 RES_TYPE_SAMPLER = 2,
546 RES_TYPE_UAV = 3,
547 RES_TYPE_COUNT,
548 };
549
550 struct ResourceExtendedInfo
551 {
552 Uint32 SrcBindPoint = ~0u;
553 Uint32 SrcSpace = ~0u;
554 RES_TYPE Type = RES_TYPE_COUNT;
555 };
556
557 using ResourceBindingPerType = std::array<std::vector<DXBCUtils::BindInfo const*>, RES_TYPE_COUNT + 1>;
558 using TExtendedResourceMap = std::unordered_map<DXBCUtils::BindInfo const*, ResourceExtendedInfo>;
543559
544560
545561 #define FOURCC(a, b, c, d) (Uint32{(d) << 24} | Uint32{(c) << 16} | Uint32{(b) << 8} | Uint32{a})
548564 constexpr Uint32 RDEFFourCC = FOURCC('R', 'D', 'E', 'F'); // Resource definition. Describes constant buffers and resource bindings.
549565 constexpr Uint32 SHDRFourCC = FOURCC('S', 'H', 'D', 'R'); // Shader (SM4)
550566 constexpr Uint32 SHEXFourCC = FOURCC('S', 'H', 'E', 'X'); // Shader (SM5)
551
552
553 ShaderResType ToResType(D3D_SHADER_INPUT_TYPE InputType)
567 constexpr Uint32 DXILFourCC = FOURCC('D', 'X', 'I', 'L'); // Shader (SM6)
568
569
570 RES_TYPE ToResType(D3D_SHADER_INPUT_TYPE InputType)
554571 {
555572 switch (InputType)
556573 {
557574 case D3D_SIT_CBUFFER:
558 return ShaderResType::CBV;
575 return RES_TYPE_CBV;
559576
560577 case D3D_SIT_SAMPLER:
561 return ShaderResType::Sampler;
578 return RES_TYPE_SAMPLER;
562579
563580 case D3D_SIT_TBUFFER:
564581 case D3D_SIT_TEXTURE:
565582 case D3D_SIT_STRUCTURED:
566583 case D3D_SIT_BYTEADDRESS:
567 return ShaderResType::SRV;
584 return RES_TYPE_SRV;
568585
569586 case D3D_SIT_UAV_RWSTRUCTURED:
570587 case D3D_SIT_UAV_RWTYPED:
572589 case D3D_SIT_UAV_APPEND_STRUCTURED:
573590 case D3D_SIT_UAV_CONSUME_STRUCTURED:
574591 case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
575 return ShaderResType::UAV;
592 return RES_TYPE_UAV;
576593
577594 default:
578595 UNEXPECTED("Unsupported shader input type");
579 return ShaderResType::Count;
596 return RES_TYPE_COUNT;
580597 }
581598 }
582599
822839 }
823840 }
824841
825 inline bool PatchSpace(ResourceBindingInfo51& Res, const DXBCUtils::BindInfo& Info)
826 {
827 Info.SrcSpace = Res.Space;
828 Res.Space = Info.Space;
842 inline bool PatchSpace(ResourceBindingInfo51& Res, ResourceExtendedInfo& Ext, const DXBCUtils::BindInfo& Info)
843 {
844 Ext.SrcSpace = Res.Space;
845 Res.Space = Info.Space;
829846 return true;
830847 }
831848
832 inline bool PatchSpace(ResourceBindingInfo50&, const DXBCUtils::BindInfo& Info)
833 {
849 inline bool PatchSpace(ResourceBindingInfo50&, ResourceExtendedInfo& Ext, const DXBCUtils::BindInfo& Info)
850 {
851 VERIFY_EXPR(Ext.SrcSpace == ~0u);
834852 return Info.Space == 0 || Info.Space == ~0U;
835853 }
836854
837855 template <typename ResourceBindingInfoType>
838 void RemapShaderResources(const DXBCUtils::TResourceBindingMap& ResourceMap, const void* EndPtr, ResourceDefChunkHeader* RDEFHeader, ResourceBindingPerType& BindingsPerType)
856 void RemapShaderResources(const DXBCUtils::TResourceBindingMap& ResourceMap, const void* EndPtr, ResourceDefChunkHeader* RDEFHeader, TExtendedResourceMap& ExtResMap, ResourceBindingPerType& BindingsPerType)
839857 {
840858 VERIFY_EXPR(RDEFHeader->Magic == RDEFFourCC);
841859
889907 LOG_ERROR_AND_THROW("Failed to find '", TempName, "' in the resource mapping.");
890908 }
891909
910 auto& Ext = ExtResMap[&Iter->second];
892911 auto& Binding = BindingsPerType[ResType];
893912 Binding.emplace_back(&Iter->second);
894913
895914 VERIFY_EXPR(ArrayInd < Iter->second.ArraySize);
896 VERIFY_EXPR(Iter->second.SrcBindPoint == ~0u ||
897 Iter->second.SrcBindPoint == Res.BindPoint - ArrayInd);
898 VERIFY_EXPR(Iter->second.Type == ShaderResType::Count ||
899 Iter->second.Type == ResType);
900
901 Iter->second.Type = ResType;
902 Iter->second.SrcBindPoint = Res.BindPoint - ArrayInd;
903 Res.BindPoint = Iter->second.BindPoint + ArrayInd;
904
905 if (!PatchSpace(Res, Iter->second))
915 VERIFY_EXPR(Ext.SrcBindPoint == ~0u || Ext.SrcBindPoint == Res.BindPoint - ArrayInd);
916 VERIFY_EXPR(Ext.Type == RES_TYPE_COUNT || Ext.Type == ResType);
917 VERIFY_EXPR((ResType != RES_TYPE_CBV && Res.BindCount == 0) ||
918 (ResType == RES_TYPE_CBV && Res.BindCount == ~0u) ||
919 Iter->second.ArraySize >= Res.BindCount);
920
921 #ifdef DILIGENT_DEBUG
922 static_assert(SHADER_RESOURCE_TYPE_LAST == SHADER_RESOURCE_TYPE_ACCEL_STRUCT, "Please update the switch below to handle the new shader resource type");
923 switch (Iter->second.ResType)
924 {
925 // clang-format off
926 case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: VERIFY_EXPR(ResType == RES_TYPE_CBV); break;
927 case SHADER_RESOURCE_TYPE_TEXTURE_SRV: VERIFY_EXPR(ResType == RES_TYPE_SRV); break;
928 case SHADER_RESOURCE_TYPE_BUFFER_SRV: VERIFY_EXPR(ResType == RES_TYPE_SRV); break;
929 case SHADER_RESOURCE_TYPE_TEXTURE_UAV: VERIFY_EXPR(ResType == RES_TYPE_UAV); break;
930 case SHADER_RESOURCE_TYPE_BUFFER_UAV: VERIFY_EXPR(ResType == RES_TYPE_UAV); break;
931 case SHADER_RESOURCE_TYPE_SAMPLER: VERIFY_EXPR(ResType == RES_TYPE_SAMPLER); break;
932 case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: VERIFY_EXPR(ResType == RES_TYPE_SRV); break;
933 // clang-format on
934 default: UNEXPECTED("Unsupported shader resource type.");
935 }
936 #endif
937 Ext.Type = ResType;
938 Ext.SrcBindPoint = Res.BindPoint - ArrayInd;
939 Res.BindPoint = Iter->second.BindPoint + ArrayInd;
940
941 if (!PatchSpace(Res, Ext, Iter->second))
906942 {
907943 LOG_ERROR_AND_THROW("Can not change space for resource '", TempName, "' because the shader was not compiled for SM 5.1.");
908944 }
913949 struct ShaderBytecodeRemapper
914950 {
915951 public:
916 ShaderBytecodeRemapper(ShaderChunkHeader const& _Header, ResourceBindingPerType const& _BindingsPerType) :
917 Header{_Header}, BindingsPerType{_BindingsPerType}
952 ShaderBytecodeRemapper(ShaderChunkHeader const& _Header, TExtendedResourceMap& _ExtResMap, ResourceBindingPerType const& _BindingsPerType) :
953 Header{_Header}, ExtResourceMap{_ExtResMap}, BindingsPerType{_BindingsPerType}
918954 {}
919955
920956 void PatchBytecode(Uint32* Token, const void* EndPtr) noexcept(false);
921957
922958 private:
923959 ShaderChunkHeader const& Header;
960 TExtendedResourceMap& ExtResourceMap;
924961 ResourceBindingPerType const& BindingsPerType;
925962
926963 static constexpr Uint32 RuntimeSizedArraySize = ~0u;
929966 void RemapResourceOperand(const OperandToken& Operand, Uint32* Token, const void* Finish);
930967 void RemapResourceOperandSM50(const OperandToken& Operand, Uint32* Token, const void* Finish);
931968 void RemapResourceOperandSM51(const OperandToken& Operand, Uint32* Token, const void* Finish);
932 void RemapResourceOperandSM51_2(const OperandToken& Operand, Uint32* Token, ShaderResType Type);
969 void RemapResourceOperandSM51_2(const OperandToken& Operand, Uint32* Token, RES_TYPE Type);
933970
934971 void RemapResourceBinding(const OpcodeToken& Opcode, Uint32* Token, const void* Finish);
935972 void RemapResourceBindingSM51(const OpcodeToken& Opcode, Uint32* Token, const void* Finish);
958995
959996 void ShaderBytecodeRemapper::RemapResourceOperandSM50(const OperandToken& Operand, Uint32* Token, const void* Finish)
960997 {
961 const auto FindResourceBindings = [this](ShaderResType Type, Uint32& Token) //
998 const auto FindResourceBindings = [this](RES_TYPE Type, Uint32& Token) //
962999 {
9631000 auto& Bindings = BindingsPerType[Type];
9641001 for (auto& Info : Bindings)
9651002 {
966 if (Token >= Info->SrcBindPoint && Token < Info->SrcBindPoint + Info->ArraySize)
1003 const auto& Ext = ExtResourceMap[Info];
1004 if (Token >= Ext.SrcBindPoint && Token < Ext.SrcBindPoint + Info->ArraySize)
9671005 {
968 Token = Info->BindPoint + (Token - Info->SrcBindPoint);
969 VERIFY_EXPR(Info->Type == Type);
1006 Token = Info->BindPoint + (Token - Ext.SrcBindPoint);
1007 VERIFY_EXPR(Ext.Type == Type);
9701008 return true;
9711009 }
9721010 }
9851023 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
9861024 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
9871025
988 if (!FindResourceBindings(ShaderResType::CBV, Token[0]))
1026 if (!FindResourceBindings(RES_TYPE_CBV, Token[0]))
9891027 LOG_ERROR_AND_THROW("Failed to find cbuffer with bind point (", Token[0], ").");
9901028 break;
9911029 }
9981036 VERIFY_EXPR(Operand.IndexDim == D3D10_SB_OPERAND_INDEX_1D);
9991037 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10001038
1001 if (!FindResourceBindings(ShaderResType::Sampler, Token[0]))
1039 if (!FindResourceBindings(RES_TYPE_SAMPLER, Token[0]))
10021040 LOG_ERROR_AND_THROW("Failed to find sampler with bind point (", Token[0], ").");
10031041 break;
10041042 }
10111049 VERIFY_EXPR(Operand.IndexDim == D3D10_SB_OPERAND_INDEX_1D);
10121050 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10131051
1014 if (!FindResourceBindings(ShaderResType::SRV, Token[0]))
1052 if (!FindResourceBindings(RES_TYPE_SRV, Token[0]))
10151053 LOG_ERROR_AND_THROW("Failed to find texture with bind point (", Token[0], ").");
10161054 break;
10171055 }
10251063 VERIFY_EXPR(Operand.IndexDim == D3D10_SB_OPERAND_INDEX_1D);
10261064 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10271065
1028 if (!FindResourceBindings(ShaderResType::UAV, Token[0]))
1066 if (!FindResourceBindings(RES_TYPE_UAV, Token[0]))
10291067 LOG_ERROR_AND_THROW("Failed to find UAV with bind point (", Token[0], ").");
10301068 break;
10311069 }
10321070 }
10331071 }
10341072
1035 void ShaderBytecodeRemapper::RemapResourceOperandSM51_2(const OperandToken& Operand, Uint32* Token, ShaderResType Type)
1073 void ShaderBytecodeRemapper::RemapResourceOperandSM51_2(const OperandToken& Operand, Uint32* Token, RES_TYPE Type)
10361074 {
10371075 const auto& Bindings = BindingsPerType[Type];
10381076 if (Token[0] >= Bindings.size())
10391077 LOG_ERROR_AND_THROW("Invalid resource index (", Token[0], "), the number of resources is (", Bindings.size(), ").");
10401078
1041 auto& Info = *Bindings[Token[0]];
1079 const auto& Info = *Bindings[Token[0]];
1080 const auto& Ext = ExtResourceMap[&Info];
10421081 switch (Operand.OperandIndex2D)
10431082 {
10441083 case D3D10_SB_OPERAND_INDEX_IMMEDIATE32:
10451084 case D3D10_SB_OPERAND_INDEX_IMMEDIATE32_PLUS_RELATIVE:
10461085 {
1047 if (Token[1] < Info.SrcBindPoint || Token[1] >= Info.SrcBindPoint + Info.ArraySize)
1048 LOG_ERROR_AND_THROW("Invalid bind point (", Token[1], "), expected be in range (", Info.SrcBindPoint, "..", Info.SrcBindPoint + Info.ArraySize - 1, ").");
1049
1050 Token[1] = Info.BindPoint + (Token[1] - Info.SrcBindPoint);
1086 if (Token[1] < Ext.SrcBindPoint || Token[1] >= Ext.SrcBindPoint + Info.ArraySize)
1087 LOG_ERROR_AND_THROW("Invalid bind point (", Token[1], "), expected be in range (", Ext.SrcBindPoint, "..", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1088
1089 Token[1] = Info.BindPoint + (Token[1] - Ext.SrcBindPoint);
10511090 break;
10521091 }
10531092 case D3D10_SB_OPERAND_INDEX_RELATIVE:
10571096 VERIFY_EXPR(Operand2.IndexDim == D3D10_SB_OPERAND_INDEX_1D);
10581097 VERIFY_EXPR(Operand2.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10591098
1060 if (Token[2] < Info.SrcBindPoint || Token[2] >= Info.SrcBindPoint + Info.ArraySize)
1061 LOG_ERROR_AND_THROW("Invalid bind point (", Token[2], "), expected be in range (", Info.SrcBindPoint, "..", Info.SrcBindPoint + Info.ArraySize - 1, ").");
1062
1063 Token[2] = Info.BindPoint + (Token[2] - Info.SrcBindPoint);
1099 if (Token[2] < Ext.SrcBindPoint || Token[2] >= Ext.SrcBindPoint + Info.ArraySize)
1100 LOG_ERROR_AND_THROW("Invalid bind point (", Token[2], "), expected be in range (", Ext.SrcBindPoint, "..", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1101
1102 Token[2] = Info.BindPoint + (Token[2] - Ext.SrcBindPoint);
10641103 break;
10651104 }
10661105 }
10801119 VERIFY_EXPR(Operand.IndexDim == D3D10_SB_OPERAND_INDEX_3D);
10811120 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10821121
1083 RemapResourceOperandSM51_2(Operand, Token, ShaderResType::CBV);
1122 RemapResourceOperandSM51_2(Operand, Token, RES_TYPE_CBV);
10841123 break;
10851124 }
10861125
10931132 VERIFY_EXPR(Operand.IndexDim >= D3D10_SB_OPERAND_INDEX_2D);
10941133 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
10951134
1096 RemapResourceOperandSM51_2(Operand, Token, ShaderResType::Sampler);
1135 RemapResourceOperandSM51_2(Operand, Token, RES_TYPE_SAMPLER);
10971136 break;
10981137 }
10991138
11061145 VERIFY_EXPR(Operand.IndexDim >= D3D10_SB_OPERAND_INDEX_2D);
11071146 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11081147
1109 RemapResourceOperandSM51_2(Operand, Token, ShaderResType::SRV);
1148 RemapResourceOperandSM51_2(Operand, Token, RES_TYPE_SRV);
11101149 break;
11111150 }
11121151
11191158 VERIFY_EXPR(Operand.IndexDim >= D3D10_SB_OPERAND_INDEX_2D);
11201159 VERIFY_EXPR(Operand.OperandIndex1D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11211160
1122 RemapResourceOperandSM51_2(Operand, Token, ShaderResType::UAV);
1161 RemapResourceOperandSM51_2(Operand, Token, RES_TYPE_UAV);
11231162 break;
11241163 }
11251164
11511190 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11521191 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11531192
1154 const auto& Bindings = BindingsPerType[ShaderResType::CBV];
1193 const auto& Bindings = BindingsPerType[RES_TYPE_CBV];
11551194 if (Token[1] >= Bindings.size())
11561195 LOG_ERROR_AND_THROW("Invalid cbuffer index (", Token[1], "), the number of constant buffers is (", Bindings.size(), ").");
11571196
1158 const auto& Info = Bindings[Token[1]];
1159 VERIFY_EXPR(Info->BindPoint == Token[2]);
1160 VERIFY_EXPR(Info->Type == ShaderResType::CBV);
1161
1162 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1163 LOG_ERROR_AND_THROW("Invalid cbuffer bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1164 if (Info->SrcSpace != Token[5])
1165 LOG_ERROR_AND_THROW("Invalid cbuffer register space (", Token[5], "), expected (", Info->SrcSpace, ").");
1197 const auto& Info = *Bindings[Token[1]];
1198 const auto& Ext = ExtResourceMap[&Info];
1199 VERIFY_EXPR(Info.BindPoint == Token[2]);
1200 VERIFY_EXPR(Ext.Type == RES_TYPE_CBV);
1201
1202 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1203 LOG_ERROR_AND_THROW("Invalid cbuffer bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1204 if (Ext.SrcSpace != Token[5])
1205 LOG_ERROR_AND_THROW("Invalid cbuffer register space (", Token[5], "), expected (", Ext.SrcSpace, ").");
11661206
11671207 if (Token[3] != RuntimeSizedArraySize)
1168 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1169
1170 Token[5] = Info->Space;
1208 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1209
1210 Token[5] = Info.Space;
11711211 break;
11721212 }
11731213
11871227 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11881228 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
11891229
1190 const auto& Bindings = BindingsPerType[ShaderResType::Sampler];
1230 const auto& Bindings = BindingsPerType[RES_TYPE_SAMPLER];
11911231 if (Token[1] >= Bindings.size())
11921232 LOG_ERROR_AND_THROW("Invalid sampler index (", Token[1], "), the number of samplers is (", Bindings.size(), ").");
11931233
1194 const auto& Info = Bindings[Token[1]];
1195 VERIFY_EXPR(Info->BindPoint == Token[2]);
1196 VERIFY_EXPR(Info->Type == ShaderResType::Sampler);
1197
1198 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1199 LOG_ERROR_AND_THROW("Invalid sampler bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1200 if (Info->SrcSpace != Token[4])
1201 LOG_ERROR_AND_THROW("Invalid sampler register space (", Token[4], "), expected (", Info->SrcSpace, ").");
1234 const auto& Info = *Bindings[Token[1]];
1235 const auto& Ext = ExtResourceMap[&Info];
1236 VERIFY_EXPR(Info.BindPoint == Token[2]);
1237 VERIFY_EXPR(Ext.Type == RES_TYPE_SAMPLER);
1238
1239 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1240 LOG_ERROR_AND_THROW("Invalid sampler bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1241 if (Ext.SrcSpace != Token[4])
1242 LOG_ERROR_AND_THROW("Invalid sampler register space (", Token[4], "), expected (", Ext.SrcSpace, ").");
12021243
12031244 if (Token[3] != RuntimeSizedArraySize)
1204 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1205
1206 Token[4] = Info->Space;
1245 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1246
1247 Token[4] = Info.Space;
12071248 break;
12081249 }
12091250
12261267 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
12271268 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
12281269
1229 const auto& Bindings = BindingsPerType[ShaderResType::SRV];
1270 const auto& Bindings = BindingsPerType[RES_TYPE_SRV];
12301271 if (Token[1] >= Bindings.size())
12311272 LOG_ERROR_AND_THROW("Invalid texture index (", Token[1], "), the number of textures is (", Bindings.size(), ").");
12321273
1233 const auto& Info = Bindings[Token[1]];
1234 VERIFY_EXPR(Info->BindPoint == Token[2]);
1235 VERIFY_EXPR(Info->Type == ShaderResType::SRV);
1236
1237 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1238 LOG_ERROR_AND_THROW("Invalid texture bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1239 if (Info->SrcSpace != Token[5])
1240 LOG_ERROR_AND_THROW("Invalid texture register space (", Token[5], "), expected (", Info->SrcSpace, ").");
1274 const auto& Info = *Bindings[Token[1]];
1275 const auto& Ext = ExtResourceMap[&Info];
1276 VERIFY_EXPR(Info.BindPoint == Token[2]);
1277 VERIFY_EXPR(Ext.Type == RES_TYPE_SRV);
1278
1279 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1280 LOG_ERROR_AND_THROW("Invalid texture bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1281 if (Ext.SrcSpace != Token[5])
1282 LOG_ERROR_AND_THROW("Invalid texture register space (", Token[5], "), expected (", Ext.SrcSpace, ").");
12411283
12421284 if (Token[3] != RuntimeSizedArraySize)
1243 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1244
1245 Token[5] = Info->Space;
1285 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1286
1287 Token[5] = Info.Space;
12461288 break;
12471289 }
12481290 case D3D11_SB_OPCODE_DCL_RESOURCE_RAW:
12611303 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
12621304 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
12631305
1264 const auto& Bindings = BindingsPerType[ShaderResType::SRV];
1306 const auto& Bindings = BindingsPerType[RES_TYPE_SRV];
12651307 if (Token[1] >= Bindings.size())
12661308 LOG_ERROR_AND_THROW("Invalid texture index (", Token[1], "), the number of textures is (", Bindings.size(), ").");
12671309
1268 const auto& Info = Bindings[Token[1]];
1269 VERIFY_EXPR(Info->BindPoint == Token[2]);
1270 VERIFY_EXPR(Info->Type == ShaderResType::SRV);
1271
1272 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1273 LOG_ERROR_AND_THROW("Invalid texture bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1274 if (Info->SrcSpace != Token[4])
1275 LOG_ERROR_AND_THROW("Invalid texture register space (", Token[4], "), expected (", Info->SrcSpace, ").");
1310 const auto& Info = *Bindings[Token[1]];
1311 const auto& Ext = ExtResourceMap[&Info];
1312 VERIFY_EXPR(Info.BindPoint == Token[2]);
1313 VERIFY_EXPR(Ext.Type == RES_TYPE_SRV);
1314
1315 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1316 LOG_ERROR_AND_THROW("Invalid texture bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1317 if (Ext.SrcSpace != Token[4])
1318 LOG_ERROR_AND_THROW("Invalid texture register space (", Token[4], "), expected (", Ext.SrcSpace, ").");
12761319
12771320 if (Token[3] != RuntimeSizedArraySize)
1278 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1279
1280 Token[4] = Info->Space;
1321 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1322
1323 Token[4] = Info.Space;
12811324 break;
12821325 }
12831326
13001343 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
13011344 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
13021345
1303 const auto& Bindings = BindingsPerType[ShaderResType::UAV];
1346 const auto& Bindings = BindingsPerType[RES_TYPE_UAV];
13041347 if (Token[1] >= Bindings.size())
13051348 LOG_ERROR_AND_THROW("Invalid UAV index (", Token[1], "), the number of UAVs is (", Bindings.size(), ").");
13061349
1307 const auto& Info = Bindings[Token[1]];
1308 VERIFY_EXPR(Info->BindPoint == Token[2]);
1309 VERIFY_EXPR(Info->Type == ShaderResType::UAV);
1310
1311 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1312 LOG_ERROR_AND_THROW("Invalid UAV bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1313 if (Info->SrcSpace != Token[5])
1314 LOG_ERROR_AND_THROW("Invalid UAV register space (", Token[5], "), expected (", Info->SrcSpace, ").");
1350 const auto& Info = *Bindings[Token[1]];
1351 const auto& Ext = ExtResourceMap[&Info];
1352 VERIFY_EXPR(Info.BindPoint == Token[2]);
1353 VERIFY_EXPR(Ext.Type == RES_TYPE_UAV);
1354
1355 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1356 LOG_ERROR_AND_THROW("Invalid UAV bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1357 if (Ext.SrcSpace != Token[5])
1358 LOG_ERROR_AND_THROW("Invalid UAV register space (", Token[5], "), expected (", Ext.SrcSpace, ").");
13151359
13161360 if (Token[3] != RuntimeSizedArraySize)
1317 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1318
1319 Token[5] = Info->Space;
1361 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1362
1363 Token[5] = Info.Space;
13201364 break;
13211365 }
13221366 case D3D11_SB_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW:
13351379 VERIFY_EXPR(Operand.OperandIndex2D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
13361380 VERIFY_EXPR(Operand.OperandIndex3D == D3D10_SB_OPERAND_INDEX_IMMEDIATE32);
13371381
1338 const auto& Bindings = BindingsPerType[ShaderResType::UAV];
1382 const auto& Bindings = BindingsPerType[RES_TYPE_UAV];
13391383 if (Token[1] >= Bindings.size())
13401384 LOG_ERROR_AND_THROW("Invalid UAV index (", Token[1], "), the number of UAVs is (", Bindings.size(), ").");
13411385
1342 const auto& Info = Bindings[Token[1]];
1343 VERIFY_EXPR(Info->BindPoint == Token[2]);
1344 VERIFY_EXPR(Info->Type == ShaderResType::UAV);
1345
1346 if (Token[3] != RuntimeSizedArraySize && Token[3] != Info->SrcBindPoint + Info->ArraySize - 1)
1347 LOG_ERROR_AND_THROW("Invalid UAV bind point (", Token[3], "), expected (", Info->SrcBindPoint + Info->ArraySize - 1, ").");
1348 if (Info->SrcSpace != Token[4])
1349 LOG_ERROR_AND_THROW("Invalid UAV register space (", Token[4], "), expected (", Info->SrcSpace, ").");
1386 const auto& Info = *Bindings[Token[1]];
1387 const auto& Ext = ExtResourceMap[&Info];
1388 VERIFY_EXPR(Info.BindPoint == Token[2]);
1389 VERIFY_EXPR(Ext.Type == RES_TYPE_UAV);
1390
1391 if (Token[3] != RuntimeSizedArraySize && Token[3] != Ext.SrcBindPoint + Info.ArraySize - 1)
1392 LOG_ERROR_AND_THROW("Invalid UAV bind point (", Token[3], "), expected (", Ext.SrcBindPoint + Info.ArraySize - 1, ").");
1393 if (Ext.SrcSpace != Token[4])
1394 LOG_ERROR_AND_THROW("Invalid UAV register space (", Token[4], "), expected (", Ext.SrcSpace, ").");
13501395
13511396 if (Token[3] != RuntimeSizedArraySize)
1352 Token[3] = Info->BindPoint + Info->ArraySize - 1;
1353
1354 Token[4] = Info->Space;
1397 Token[3] = Info.BindPoint + Info.ArraySize - 1;
1398
1399 Token[4] = Info.Space;
13551400 break;
13561401 }
13571402 }
16661711
16671712 const Uint32* Chunks = reinterpret_cast<Uint32*>(Ptr + sizeof(Header));
16681713 ResourceBindingPerType BindingsPerType;
1714 TExtendedResourceMap ExtResourceMap;
16691715
16701716 bool RemapResDef = false;
16711717 bool RemapBytecode = false;
16911737
16921738 if (RDEFHeader->MajorVersion == 5 && RDEFHeader->MinorVersion == 1)
16931739 {
1694 RemapShaderResources<ResourceBindingInfo51>(ResourceMap, EndPtr, RDEFHeader, BindingsPerType);
1740 RemapShaderResources<ResourceBindingInfo51>(ResourceMap, EndPtr, RDEFHeader, ExtResourceMap, BindingsPerType);
16951741 RemapResDef = true;
16961742 }
16971743 else if (RDEFHeader->MajorVersion == 5 && RDEFHeader->MinorVersion == 0 || RDEFHeader->MajorVersion < 5)
16981744 {
1699 RemapShaderResources<ResourceBindingInfo50>(ResourceMap, EndPtr, RDEFHeader, BindingsPerType);
1745 RemapShaderResources<ResourceBindingInfo50>(ResourceMap, EndPtr, RDEFHeader, ExtResourceMap, BindingsPerType);
17001746 RemapResDef = true;
17011747 }
17021748 else
17091755 {
17101756 Uint32* Token = reinterpret_cast<Uint32*>(Ptr + Chunks[i] + sizeof(ShaderChunkHeader));
17111757 const auto& SBHeader = *reinterpret_cast<ShaderChunkHeader*>(pChunk);
1712 ShaderBytecodeRemapper Remapper{SBHeader, BindingsPerType};
1758 ShaderBytecodeRemapper Remapper{SBHeader, ExtResourceMap, BindingsPerType};
17131759
17141760 Remapper.PatchBytecode(Token, EndPtr);
17151761 RemapBytecode = true;
140140
141141 bool ValidateAndSign(DxcCreateInstanceProc CreateInstance, IDxcLibrary* library, CComPtr<IDxcBlob>& compiled, IDxcBlob** ppBlobOut) const;
142142
143 static bool PatchDXIL(const TResourceBindingMap& ResourceMap, String& DXIL);
144 static void PatchResourceDeclaration(const TResourceBindingMap& ResourceMap, String& DXIL);
145 static void PatchResourceHandle(const TResourceBindingMap& ResourceMap, String& DXIL);
143 enum RES_TYPE : Uint32
144 {
145 RES_TYPE_CBV = 0,
146 RES_TYPE_SRV = 1,
147 RES_TYPE_SAMPLER = 2,
148 RES_TYPE_UAV = 3,
149 RES_TYPE_COUNT,
150 };
151
152 struct ResourceExtendedInfo
153 {
154 Uint32 SrcBindPoint = ~0u;
155 Uint32 SrcSpace = ~0u;
156 Uint32 RecordId = ~0u;
157 RES_TYPE Type = RES_TYPE_COUNT;
158 };
159 using TExtendedResourceMap = std::unordered_map<TResourceBindingMap::value_type const*, ResourceExtendedInfo>;
160
161 static bool PatchDXIL(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL);
162 static void PatchResourceDeclaration(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL);
163 static void PatchResourceHandle(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL);
146164
147165 private:
148166 DxcCreateInstanceProc m_pCreateInstance = nullptr;
825843 return false;
826844 }
827845
846 TExtendedResourceMap ExtResourceMap;
847
828848 for (auto& NameAndBinding : ResourceMap)
829849 {
830850 D3D12_SHADER_INPUT_BIND_DESC ResDesc = {};
831851 if (pShaderReflection->GetResourceBindingDescByName(NameAndBinding.first.GetStr(), &ResDesc) == S_OK)
832852 {
833 NameAndBinding.second.SrcBindPoint = ResDesc.BindPoint;
834 NameAndBinding.second.SrcSpace = ResDesc.Space;
835 // For some reason
836 // Texture2D g_Textures[]
837 // produces BindCount == 0, but
838 // ConstantBuffer<CBData> g_ConstantBuffers[]
839 // produces BindCount == UINT_MAX
840 VERIFY_EXPR(ResDesc.BindCount == 0 || ResDesc.BindCount == UINT_MAX || NameAndBinding.second.ArraySize >= ResDesc.BindCount);
853 auto& Ext = ExtResourceMap[&NameAndBinding];
854 Ext.SrcBindPoint = ResDesc.BindPoint;
855 Ext.SrcSpace = ResDesc.Space;
841856
842857 switch (ResDesc.Type)
843858 {
844859 case D3D_SIT_CBUFFER:
845 NameAndBinding.second.Type = ShaderResType::CBV;
860 Ext.Type = RES_TYPE_CBV;
846861 break;
847862 case D3D_SIT_SAMPLER:
848 NameAndBinding.second.Type = ShaderResType::Sampler;
863 Ext.Type = RES_TYPE_SAMPLER;
849864 break;
850865 case D3D_SIT_TBUFFER:
851866 case D3D_SIT_TEXTURE:
852867 case D3D_SIT_STRUCTURED:
853868 case D3D_SIT_BYTEADDRESS:
854869 case D3D_SIT_RTACCELERATIONSTRUCTURE:
855 NameAndBinding.second.Type = ShaderResType::SRV;
870 Ext.Type = RES_TYPE_SRV;
856871 break;
857872 case D3D_SIT_UAV_RWTYPED:
858873 case D3D_SIT_UAV_RWSTRUCTURED:
861876 case D3D_SIT_UAV_CONSUME_STRUCTURED:
862877 case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
863878 case D3D_SIT_UAV_FEEDBACKTEXTURE:
864 NameAndBinding.second.Type = ShaderResType::UAV;
879 Ext.Type = RES_TYPE_UAV;
865880 break;
866881 default:
867882 LOG_ERROR("Unknown shader resource type");
868883 return false;
869884 }
885
886 # ifdef DILIGENT_DEBUG
887 static_assert(SHADER_RESOURCE_TYPE_LAST == SHADER_RESOURCE_TYPE_ACCEL_STRUCT, "Please update the switch below to handle the new shader resource type");
888 switch (NameAndBinding.second.ResType)
889 {
890 // clang-format off
891 case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: VERIFY_EXPR(Ext.Type == RES_TYPE_CBV); break;
892 case SHADER_RESOURCE_TYPE_TEXTURE_SRV: VERIFY_EXPR(Ext.Type == RES_TYPE_SRV); break;
893 case SHADER_RESOURCE_TYPE_BUFFER_SRV: VERIFY_EXPR(Ext.Type == RES_TYPE_SRV); break;
894 case SHADER_RESOURCE_TYPE_TEXTURE_UAV: VERIFY_EXPR(Ext.Type == RES_TYPE_UAV); break;
895 case SHADER_RESOURCE_TYPE_BUFFER_UAV: VERIFY_EXPR(Ext.Type == RES_TYPE_UAV); break;
896 case SHADER_RESOURCE_TYPE_SAMPLER: VERIFY_EXPR(Ext.Type == RES_TYPE_SAMPLER); break;
897 case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: VERIFY_EXPR(Ext.Type == RES_TYPE_SRV); break;
898 case SHADER_RESOURCE_TYPE_ACCEL_STRUCT: VERIFY_EXPR(Ext.Type == RES_TYPE_SRV); break;
899 // clang-format on
900 default: UNEXPECTED("Unsupported shader resource type.");
901 }
902 # endif
903
904 // For some reason
905 // Texture2D g_Textures[]
906 // produces BindCount == 0, but
907 // ConstantBuffer<CBData> g_ConstantBuffers[]
908 // produces BindCount == UINT_MAX
909 VERIFY_EXPR((Ext.Type != RES_TYPE_CBV && ResDesc.BindCount == 0) ||
910 (Ext.Type == RES_TYPE_CBV && ResDesc.BindCount == UINT_MAX) ||
911 NameAndBinding.second.ArraySize >= ResDesc.BindCount);
870912 }
871913 }
872914
873915 String dxilAsm;
874916 dxilAsm.assign(static_cast<const char*>(disasm->GetBufferPointer()), disasm->GetBufferSize());
875917
876 if (!PatchDXIL(ResourceMap, dxilAsm))
918 if (!PatchDXIL(ResourceMap, ExtResourceMap, dxilAsm))
877919 {
878920 LOG_ERROR("Failed to patch resource bindings");
879921 return false;
926968 #endif // D3D12_SUPPORTED
927969 }
928970
929 bool DXCompilerImpl::PatchDXIL(const TResourceBindingMap& ResourceMap, String& DXIL)
971 bool DXCompilerImpl::PatchDXIL(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL)
930972 {
931973 try
932974 {
933 PatchResourceDeclaration(ResourceMap, DXIL);
934 PatchResourceHandle(ResourceMap, DXIL);
975 PatchResourceDeclaration(ResourceMap, ExtResMap, DXIL);
976 PatchResourceHandle(ResourceMap, ExtResMap, DXIL);
935977 return true;
936978 }
937979 catch (...)
940982 }
941983 }
942984
943 void DXCompilerImpl::PatchResourceDeclaration(const TResourceBindingMap& ResourceMap, String& DXIL)
985 void DXCompilerImpl::PatchResourceDeclaration(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL)
944986 {
945987 #define CHECK_PATCHING_ERROR(Cond, ...) \
946988 if (!(Cond)) \
10381080 const auto Space = ResPair.second.Space;
10391081 const auto BindPoint = ResPair.second.BindPoint;
10401082 const auto DxilName = String{"!\""} + Name + "\"";
1083 auto& Ext = ExtResMap[&ResPair];
10411084
10421085 size_t pos = DXIL.find(DxilName);
10431086 if (pos == String::npos)
10671110
10681111 const Uint32 RecordId = static_cast<Uint32>(std::atoi(DXIL.c_str() + RecordIdStartPos));
10691112
1070 VERIFY_EXPR(ResPair.second.UID == ~0u || ResPair.second.UID == RecordId);
1071 ResPair.second.UID = RecordId;
1113 VERIFY_EXPR(Ext.RecordId == ~0u || Ext.RecordId == RecordId);
1114 Ext.RecordId = RecordId;
10721115
10731116 // !"g_ColorBuffer", i32 -1, i32 -1,
10741117 // ^
10751118 pos = EndOfResTypeRecord + DxilName.length();
1076 ReplaceRecord(pos, std::to_string(Space), Name, "space", ResPair.second.SrcSpace);
1119 ReplaceRecord(pos, std::to_string(Space), Name, "space", Ext.SrcSpace);
10771120
10781121 // !"g_ColorBuffer", i32 0, i32 -1,
10791122 // ^
1080 ReplaceRecord(pos, std::to_string(BindPoint), Name, "binding", ResPair.second.SrcBindPoint);
1123 ReplaceRecord(pos, std::to_string(BindPoint), Name, "binding", Ext.SrcBindPoint);
10811124
10821125 // !"g_ColorBuffer", i32 0, i32 1,
10831126 // ^
11431186 // !{i32 0, %"class.Texture2D<...
11441187 // ^
11451188
1146 ShaderResType ResType = ShaderResType::Count;
1189 RES_TYPE ResType = RES_TYPE_COUNT;
11471190 if (std::strncmp(&DXIL[pos], TexturePart.c_str(), TexturePart.length()) == 0)
1148 ResType = ShaderResType::SRV;
1191 ResType = RES_TYPE_SRV;
11491192 else if (std::strncmp(&DXIL[pos], SamplerPart.c_str(), SamplerPart.length()) == 0)
1150 ResType = ShaderResType::Sampler;
1193 ResType = RES_TYPE_SAMPLER;
11511194 else
11521195 {
11531196 // Try to find constant buffer.
1154 for (auto& NameAndBinding : ResourceMap)
1197 for (auto& ResInfo : ExtResMap)
11551198 {
1156 if (NameAndBinding.second.Type != ShaderResType::CBV)
1199 const char* Name = ResInfo.first->first.GetStr();
1200 const RES_TYPE Type = ResInfo.second.Type;
1201
1202 if (Type != RES_TYPE_CBV)
11571203 continue;
11581204
1159 const String CBName = String{"%"} + NameAndBinding.first.GetStr() + "* undef";
1205 const String CBName = String{"%"} + Name + "* undef";
11601206 if (std::strncmp(&DXIL[pos], CBName.c_str(), CBName.length()) == 0)
11611207 {
1162 ResType = ShaderResType::CBV;
1208 ResType = RES_TYPE_CBV;
11631209 break;
11641210 }
11651211 }
11661212 }
11671213
1168 if (ResType == ShaderResType::Count)
1214 if (ResType == RES_TYPE_COUNT)
11691215 {
11701216 // This is not a resource declaration record, continue searching.
11711217 pos = BindingRecordStart;
11921238 continue;
11931239 }
11941240 // Search in resource map.
1195 TResourceBindingMap::value_type const* ResPair = nullptr;
1196 for (auto& NameAndBinding : ResourceMap)
1197 {
1198 if (NameAndBinding.second.SrcBindPoint == BindPoint &&
1199 NameAndBinding.second.SrcSpace == Space &&
1200 NameAndBinding.second.Type == ResType)
1241 TResourceBindingMap::value_type const* pResPair = nullptr;
1242 ResourceExtendedInfo* pExt = nullptr;
1243 for (auto& ResInfo : ExtResMap)
1244 {
1245 if (ResInfo.second.SrcBindPoint == BindPoint &&
1246 ResInfo.second.SrcSpace == Space &&
1247 ResInfo.second.Type == ResType)
12011248 {
1202 ResPair = &NameAndBinding;
1249 pResPair = ResInfo.first;
1250 pExt = &ResInfo.second;
12031251 break;
12041252 }
12051253 }
1206 CHECK_PATCHING_ERROR(ResPair != nullptr, "failed to find resource in ResourceMap");
1207
1208 VERIFY_EXPR(ResPair->second.UID == ~0u || ResPair->second.UID == RecordId);
1209 ResPair->second.UID = RecordId;
1254 CHECK_PATCHING_ERROR(pResPair != nullptr && pExt != nullptr, "failed to find resource in ResourceMap");
1255
1256 VERIFY_EXPR(pExt->RecordId == ~0u || pExt->RecordId == RecordId);
1257 pExt->RecordId = RecordId;
12101258
12111259 // Remap bindings.
12121260 pos = BindingRecordStart;
12131261
12141262 // !"", i32 -1, i32 -1,
12151263 // ^
1216 ReplaceRecord(pos, std::to_string(ResPair->second.Space), ResPair->first.GetStr(), "space", ResPair->second.SrcSpace);
1264 ReplaceRecord(pos, std::to_string(pResPair->second.Space), pResPair->first.GetStr(), "space", pExt->SrcSpace);
12171265
12181266 // !"", i32 0, i32 -1,
12191267 // ^
1220 ReplaceRecord(pos, std::to_string(ResPair->second.BindPoint), ResPair->first.GetStr(), "binding", ResPair->second.SrcBindPoint);
1268 ReplaceRecord(pos, std::to_string(pResPair->second.BindPoint), pResPair->first.GetStr(), "binding", pExt->SrcBindPoint);
12211269
12221270 // !"", i32 0, i32 1,
12231271 // ^
12251273 #undef CHECK_PATCHING_ERROR
12261274 }
12271275
1228 void DXCompilerImpl::PatchResourceHandle(const TResourceBindingMap& ResourceMap, String& DXIL)
1276 void DXCompilerImpl::PatchResourceHandle(const TResourceBindingMap& ResourceMap, TExtendedResourceMap& ExtResMap, String& DXIL)
12291277 {
12301278 // Patch createHandle command
1231 static const String CallHandlePattern = " = call %dx.types.Handle @dx.op.createHandle(";
1232 static const String i32 = "i32 ";
1233 static const String i8 = "i8 ";
1234 static const ShaderResType ResClassToType[] = {ShaderResType::SRV, ShaderResType::UAV, ShaderResType::CBV, ShaderResType::Sampler};
1279 static const String CallHandlePattern = " = call %dx.types.Handle @dx.op.createHandle(";
1280 static const String i32 = "i32 ";
1281 static const String i8 = "i8 ";
1282 static const RES_TYPE ResClassToType[] = {RES_TYPE_SRV, RES_TYPE_UAV, RES_TYPE_CBV, RES_TYPE_SAMPLER};
12351283
12361284 const auto NextArg = [&DXIL](size_t& pos) //
12371285 {
12471295 return false;
12481296 };
12491297
1250 const auto ReplaceBindPoint = [&ResourceMap, &DXIL](Uint32 ResClass, Uint32 RangeId, size_t IndexStartPos, size_t IndexEndPos) //
1298 const auto ReplaceBindPoint = [&](Uint32 ResClass, Uint32 RangeId, size_t IndexStartPos, size_t IndexEndPos) //
12511299 {
12521300 const String SrcIndexStr = DXIL.substr(IndexStartPos, IndexEndPos - IndexStartPos);
12531301 VERIFY_EXPR(SrcIndexStr.front() >= '0' && SrcIndexStr.front() <= '9');
12551303 const Uint32 SrcIndex = static_cast<Uint32>(std::stoi(SrcIndexStr));
12561304 const auto ResType = ResClassToType[ResClass];
12571305
1258 TResourceBindingMap::value_type const* ResPair = nullptr;
1259 for (auto& NameAndBinding : ResourceMap)
1260 {
1261 if (NameAndBinding.second.UID == RangeId &&
1262 NameAndBinding.second.Type == ResType &&
1263 SrcIndex >= NameAndBinding.second.SrcBindPoint &&
1264 SrcIndex < NameAndBinding.second.SrcBindPoint + NameAndBinding.second.ArraySize)
1306 BindInfo const* pBind = nullptr;
1307 ResourceExtendedInfo* pExt = nullptr;
1308 for (auto& ResInfo : ExtResMap)
1309 {
1310 if (ResInfo.second.RecordId == RangeId &&
1311 ResInfo.second.Type == ResType &&
1312 SrcIndex >= ResInfo.second.SrcBindPoint &&
1313 SrcIndex < ResInfo.second.SrcBindPoint + ResInfo.first->second.ArraySize)
12651314 {
1266 ResPair = &NameAndBinding;
1315 pBind = &ResInfo.first->second;
1316 pExt = &ResInfo.second;
12671317 break;
12681318 }
12691319 }
1270 if (ResPair == nullptr)
1320 if (pBind == nullptr || pExt == nullptr)
12711321 LOG_ERROR_AND_THROW("Failed to find resource in ResourceMap");
12721322
1273 VERIFY_EXPR(SrcIndex >= ResPair->second.SrcBindPoint);
1274 VERIFY_EXPR(ResPair->second.SrcBindPoint != ~0u);
1275
1276 const Uint32 IndexOffset = SrcIndex - ResPair->second.SrcBindPoint;
1277 VERIFY_EXPR((ResPair->second.BindPoint + IndexOffset) >= ResPair->second.BindPoint);
1278
1279 const String NewIndexStr = std::to_string(ResPair->second.BindPoint + IndexOffset);
1323 VERIFY_EXPR(SrcIndex >= pExt->SrcBindPoint);
1324 VERIFY_EXPR(pExt->SrcBindPoint != ~0u);
1325
1326 const Uint32 IndexOffset = SrcIndex - pExt->SrcBindPoint;
1327 VERIFY_EXPR((pBind->BindPoint + IndexOffset) >= pBind->BindPoint);
1328
1329 const String NewIndexStr = std::to_string(pBind->BindPoint + IndexOffset);
12801330 DXIL.replace(DXIL.begin() + IndexStartPos, DXIL.begin() + IndexEndPos, NewIndexStr);
12811331 };
12821332
7070
7171 String ResName{BindDesc.Name};
7272
73 auto Iter = ResMap.find(HashMapStringKey{ResName.c_str()});
73 auto Iter = ResMap.find(ResName.c_str());
7474 if (Iter != ResMap.end())
7575 {
7676 EXPECT_EQ(BindDesc.BindPoint, Iter->second.BindPoint);
101101 ResName.resize(ArrStart);
102102 }
103103
104 Iter = ResMap.find(HashMapStringKey{ResName.c_str()});
104 Iter = ResMap.find(ResName.c_str());
105105 if (Iter != ResMap.end())
106106 {
107107 EXPECT_LT(ArrayInd, Iter->second.ArraySize);
115115 }
116116 }
117117
118 using BindInfo = DXBCUtils::BindInfo;
119
120118
121119 TEST(DXBCUtils, PatchSM50)
122120 {
166164 const Uint32 Space = 0;
167165
168166 DXBCUtils::TResourceBindingMap ResMap;
169 ResMap.emplace(HashMapStringKey{"g_Tex2D_1"}, BindInfo{Tex++, Space, 1});
170 ResMap.emplace(HashMapStringKey{"g_Tex2D_2"}, BindInfo{Tex++, Space, 1});
171 ResMap.emplace(HashMapStringKey{"g_Tex2D_3"}, BindInfo{Tex++, Space, 1});
172 ResMap.emplace(HashMapStringKey{"g_Tex2D_4"}, BindInfo{Tex++, Space, 1});
173 ResMap.emplace(HashMapStringKey{"g_InColorArray"}, BindInfo{Tex++, Space, 1});
174 ResMap.emplace(HashMapStringKey{"g_OutColorBuffer_1"}, BindInfo{UAV++, Space, 1});
175 ResMap.emplace(HashMapStringKey{"g_OutColorBuffer_2"}, BindInfo{UAV++, Space, 1});
176 ResMap.emplace(HashMapStringKey{"g_Sampler_1"}, BindInfo{Samp++, Space, 1});
177 ResMap.emplace(HashMapStringKey{"g_Sampler_2"}, BindInfo{Samp++, Space, 4});
178 ResMap.emplace(HashMapStringKey{"Constants1"}, BindInfo{Buff++, Space, 1});
179 ResMap.emplace(HashMapStringKey{"Constants2"}, BindInfo{Buff++, Space, 1});
167 // clang-format off
168 ResMap["g_Tex2D_1"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
169 ResMap["g_Tex2D_2"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
170 ResMap["g_Tex2D_3"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
171 ResMap["g_Tex2D_4"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
172 ResMap["g_InColorArray"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_BUFFER_SRV };
173 ResMap["g_OutColorBuffer_1"] = {UAV++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
174 ResMap["g_OutColorBuffer_2"] = {UAV++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
175 ResMap["g_Sampler_1"] = {Samp++, Space, 1, SHADER_RESOURCE_TYPE_SAMPLER };
176 ResMap["g_Sampler_2"] = {Samp++, Space, 4, SHADER_RESOURCE_TYPE_SAMPLER };
177 ResMap["Constants1"] = {Buff++, Space, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
178 ResMap["Constants2"] = {Buff++, Space, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
179 // clang-format on
180180
181181 TestDXBCRemapping(Source, "PSMain", "ps_5_0", ResMap);
182182 }
231231 const Uint32 Space = 0;
232232 Uint32 Tex = 0;
233233 Uint32 Buff = 0;
234 ResMap.emplace(HashMapStringKey{"g_Tex2D_2"}, BindInfo{Tex++, Space, 1});
235 ResMap.emplace(HashMapStringKey{"g_Tex2D_3"}, BindInfo{Tex++, Space, 1});
236 ResMap.emplace(HashMapStringKey{"Constants1"}, BindInfo{Buff++, Space, 1});
237 ResMap.emplace(HashMapStringKey{"Constants2"}, BindInfo{Buff++, Space, 1});
234 // clang-format off
235 ResMap["g_Tex2D_2"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
236 ResMap["g_Tex2D_3"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
237 ResMap["Constants1"] = {Buff++, Space, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
238 ResMap["Constants2"] = {Buff++, Space, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
239 // clang-format on
238240 }
239241 // space 1
240242 {
241243 const Uint32 Space = 1;
242244 Uint32 Samp = 0;
243245 Uint32 UAV = 0;
244 ResMap.emplace(HashMapStringKey{"g_OutColorBuffer_1"}, BindInfo{UAV++, Space, 1});
245 ResMap.emplace(HashMapStringKey{"g_OutColorBuffer_2"}, BindInfo{UAV++, Space, 1});
246 ResMap.emplace(HashMapStringKey{"g_Sampler_1"}, BindInfo{Samp++, Space, 1});
247 ResMap.emplace(HashMapStringKey{"g_Sampler_2"}, BindInfo{Samp++, Space, 4});
246 // clang-format off
247 ResMap["g_OutColorBuffer_1"] = {UAV++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV};
248 ResMap["g_OutColorBuffer_2"] = {UAV++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV};
249 ResMap["g_Sampler_1"] = {Samp++, Space, 1, SHADER_RESOURCE_TYPE_SAMPLER };
250 ResMap["g_Sampler_2"] = {Samp++, Space, 4, SHADER_RESOURCE_TYPE_SAMPLER };
251 // clang-format on
248252 }
249253 // space 2
250254 {
251255 const Uint32 Space = 2;
252256 Uint32 Tex = 0;
253 ResMap.emplace(HashMapStringKey{"g_Tex2D_1"}, BindInfo{Tex++, Space, 1});
254 ResMap.emplace(HashMapStringKey{"g_Tex2D_4"}, BindInfo{Tex++, Space, 1});
255 ResMap.emplace(HashMapStringKey{"g_InColorArray"}, BindInfo{Tex++, Space, 1});
257 // clang-format off
258 ResMap["g_Tex2D_1"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV};
259 ResMap["g_Tex2D_4"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV};
260 ResMap["g_InColorArray"] = {Tex++, Space, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV};
261 // clang-format on
256262 }
257263
258264 TestDXBCRemapping(Source, "PSMain", "ps_5_1", ResMap);
290296 )hlsl";
291297
292298 DXBCUtils::TResourceBindingMap ResMap;
293 ResMap.emplace(HashMapStringKey{"g_Sampler"}, BindInfo{11, 3, 1});
294 ResMap.emplace(HashMapStringKey{"g_Tex2D_StatArray"}, BindInfo{22, 3, 8});
295 ResMap.emplace(HashMapStringKey{"g_Tex2D_DynArray"}, BindInfo{0, 2, 100});
296 ResMap.emplace(HashMapStringKey{"Constants"}, BindInfo{44, 1, 1});
299 // clang-format off
300 ResMap["g_Sampler"] = {11, 3, 1, SHADER_RESOURCE_TYPE_SAMPLER };
301 ResMap["g_Tex2D_StatArray"] = {22, 3, 8, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
302 ResMap["g_Tex2D_DynArray"] = { 0, 2, 100, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
303 ResMap["Constants"] = {44, 1, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
304 // clang-format on
297305
298306 TestDXBCRemapping(Source, "PSMain", "ps_5_1", ResMap);
299307 }
199199 ASSERT_TRUE(pDXIL) << (pOutput ? std::string{reinterpret_cast<const char*>(pOutput->GetBufferPointer()), pOutput->GetBufferSize()} : "");
200200
201201 IDXCompiler::TResourceBindingMap BindigMap;
202 BindigMap["g_TLAS"] = {15, 0, 1};
203 BindigMap["g_ColorBuffer"] = {7, 1, 1};
204 BindigMap["g_Tex"] = {101, 0, 2};
205 BindigMap["g_TexSampler"] = {0, 2, 1};
206 BindigMap["cbConstants"] = {9, 0, 1};
207 BindigMap["g_AnotherRes"] = {567, 5, 1};
202 // clang-format off
203 BindigMap["g_TLAS"] = { 15, 0, 1, SHADER_RESOURCE_TYPE_ACCEL_STRUCT };
204 BindigMap["g_ColorBuffer"] = { 7, 1, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
205 BindigMap["g_Tex"] = {101, 0, 2, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
206 BindigMap["g_TexSampler"] = { 0, 2, 1, SHADER_RESOURCE_TYPE_SAMPLER };
207 BindigMap["cbConstants"] = { 9, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
208 BindigMap["g_AnotherRes"] = {567, 5, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
209 // clang-format on
208210 CComPtr<IDxcBlob> pRemappedDXIL;
209211 pDXC->RemapResourceBindings(BindigMap, pDXIL, &pRemappedDXIL);
210212 ASSERT_TRUE(pRemappedDXIL);
236238 EXPECT_EQ(BindDesc.Space, 0U);
237239 }
238240
239 BindigMap["g_TLAS"] = {0, 0, 1};
240 BindigMap["g_ColorBuffer"] = {1, 0, 1};
241 BindigMap["g_Tex"] = {2, 0, 2};
242 BindigMap["g_TexSampler"] = {0, 1, 1};
243 BindigMap["cbConstants"] = {1, 1, 1};
241 // clang-format off
242 BindigMap["g_TLAS"] = {0, 0, 1, SHADER_RESOURCE_TYPE_ACCEL_STRUCT };
243 BindigMap["g_ColorBuffer"] = {1, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
244 BindigMap["g_Tex"] = {2, 0, 2, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
245 BindigMap["g_TexSampler"] = {0, 1, 1, SHADER_RESOURCE_TYPE_SAMPLER };
246 BindigMap["cbConstants"] = {1, 1, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
247 // clang-format on
244248 CComPtr<IDxcBlob> pRemappedDXIL2;
245249 pDXC->RemapResourceBindings(BindigMap, pRemappedDXIL, &pRemappedDXIL2);
246250 ASSERT_TRUE(pRemappedDXIL2);
316320 ASSERT_TRUE(pDXIL) << (pOutput ? std::string{reinterpret_cast<const char*>(pOutput->GetBufferPointer()), pOutput->GetBufferSize()} : "");
317321
318322 IDXCompiler::TResourceBindingMap BindigMap;
319 BindigMap["g_Tex1"] = {101, 0, 1};
320 BindigMap["g_Tex2"] = {22, 0, 1};
321 BindigMap["g_TexSampler"] = {0, 0, 1};
322 BindigMap["cbConstants1"] = {9, 0, 1};
323 BindigMap["cbConstants2"] = {3, 0, 1};
324 BindigMap["g_AnotherRes"] = {567, 0, 1};
323 // clang-format off
324 BindigMap["g_Tex1"] = {101, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
325 BindigMap["g_Tex2"] = { 22, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
326 BindigMap["g_TexSampler"] = { 0, 0, 1, SHADER_RESOURCE_TYPE_SAMPLER };
327 BindigMap["cbConstants1"] = { 9, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
328 BindigMap["cbConstants2"] = { 3, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
329 BindigMap["g_AnotherRes"] = {567, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
330 // clang-format oN
325331 CComPtr<IDxcBlob> pRemappedDXIL;
326332 pDXC->RemapResourceBindings(BindigMap, pDXIL, &pRemappedDXIL);
327333 ASSERT_TRUE(pRemappedDXIL);
354360 }
355361
356362 BindigMap.clear();
357 BindigMap["g_Tex1"] = {0, 2, 1};
358 BindigMap["g_Tex2"] = {55, 4, 1};
359 BindigMap["g_TexSampler"] = {1, 2, 1};
360 BindigMap["cbConstants1"] = {8, 3, 1};
361 BindigMap["cbConstants2"] = {4, 6, 1};
362 BindigMap["g_AnotherRes"] = {567, 0, 1};
363 // clang-format off
364 BindigMap["g_Tex1"] = { 0, 2, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
365 BindigMap["g_Tex2"] = { 55, 4, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
366 BindigMap["g_TexSampler"] = { 1, 2, 1, SHADER_RESOURCE_TYPE_SAMPLER };
367 BindigMap["cbConstants1"] = { 8, 3, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
368 BindigMap["cbConstants2"] = { 4, 6, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
369 BindigMap["g_AnotherRes"] = {567, 0, 1, SHADER_RESOURCE_TYPE_SAMPLER };
370 // clang-format oN
363371 pRemappedDXIL = nullptr;
364372 pDXC->RemapResourceBindings(BindigMap, pDXIL, &pRemappedDXIL);
365373 ASSERT_TRUE(pRemappedDXIL);
452460 ASSERT_TRUE(pDXIL) << (pOutput ? std::string{reinterpret_cast<const char*>(pOutput->GetBufferPointer()), pOutput->GetBufferSize()} : "");
453461
454462 IDXCompiler::TResourceBindingMap BindigMap;
455 BindigMap["g_Tex"] = {101, 0, 4};
456 BindigMap["g_Tex3D"] = {22, 0, 1};
457 BindigMap["g_TexSampler"] = {0, 0, 1};
458 BindigMap["g_Buffer1"] = {9, 0, 5};
459 BindigMap["g_Buffer2"] = {0, 1, 10};
460 BindigMap["g_ColorBuffer1"] = {180, 0, 1};
461 BindigMap["g_ColorBuffer2"] = {333, 0, 1};
462 BindigMap["g_ColorBuffer3"] = {1, 0, 1};
463 BindigMap["Constants"] = {8, 0, 1};
464 BindigMap["g_AnotherRes"] = {567, 0, 1};
463 // clang-format off
464 BindigMap["g_Tex"] = {101, 0, 4, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
465 BindigMap["g_Tex3D"] = { 22, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
466 BindigMap["g_TexSampler"] = { 0, 0, 1, SHADER_RESOURCE_TYPE_SAMPLER };
467 BindigMap["g_Buffer1"] = { 9, 0, 5, SHADER_RESOURCE_TYPE_BUFFER_SRV };
468 BindigMap["g_Buffer2"] = { 0, 1, 10, SHADER_RESOURCE_TYPE_BUFFER_UAV };
469 BindigMap["g_ColorBuffer1"] = {180, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
470 BindigMap["g_ColorBuffer2"] = {333, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
471 BindigMap["g_ColorBuffer3"] = { 1, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
472 BindigMap["Constants"] = { 8, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
473 BindigMap["g_AnotherRes"] = {567, 0, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
474 // clang-format on
465475 CComPtr<IDxcBlob> pRemappedDXIL;
466476 pDXC->RemapResourceBindings(BindigMap, pDXIL, &pRemappedDXIL);
467477 ASSERT_TRUE(pRemappedDXIL);
510520 }
511521
512522 BindigMap.clear();
513 BindigMap["g_Tex"] = {77, 1, 4};
514 BindigMap["g_Tex3D"] = {90, 1, 1};
515 BindigMap["g_TexSampler"] = {0, 1, 1};
516 BindigMap["g_Buffer1"] = {15, 6, 5};
517 BindigMap["g_Buffer2"] = {2, 7, 100};
518 BindigMap["g_ColorBuffer1"] = {33, 6, 1};
519 BindigMap["g_ColorBuffer2"] = {10, 100, 1};
520 BindigMap["g_ColorBuffer3"] = {11, 100, 1};
521 BindigMap["Constants"] = {9, 3, 1};
522 BindigMap["g_AnotherRes"] = {567, 0, 1};
523 pRemappedDXIL = nullptr;
523 // clang-format off
524 BindigMap["g_Tex"] = { 77, 1, 4, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
525 BindigMap["g_Tex3D"] = { 90, 1, 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV };
526 BindigMap["g_TexSampler"] = { 0, 1, 1, SHADER_RESOURCE_TYPE_SAMPLER };
527 BindigMap["g_Buffer1"] = { 15, 6, 5, SHADER_RESOURCE_TYPE_BUFFER_SRV };
528 BindigMap["g_Buffer2"] = { 2, 7, 100, SHADER_RESOURCE_TYPE_BUFFER_UAV };
529 BindigMap["g_ColorBuffer1"] = { 33, 6, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
530 BindigMap["g_ColorBuffer2"] = { 10, 100, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
531 BindigMap["g_ColorBuffer3"] = { 11, 100, 1, SHADER_RESOURCE_TYPE_TEXTURE_UAV };
532 BindigMap["Constants"] = { 9, 3, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
533 BindigMap["g_AnotherRes"] = {567, 0, 1, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER};
534 // clang-format on
535 pRemappedDXIL = nullptr;
524536 pDXC->RemapResourceBindings(BindigMap, pDXIL, &pRemappedDXIL);
525537 ASSERT_TRUE(pRemappedDXIL);
526538