diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h --- a/llvm/include/llvm/BinaryFormat/DXContainer.h +++ b/llvm/include/llvm/BinaryFormat/DXContainer.h @@ -288,6 +288,20 @@ void swapBytes(Triple::EnvironmentType Stage) { StageInfo.swapBytes(Stage); } }; +struct ResourceBindInfo { + uint32_t Type; + uint32_t Space; + uint32_t LowerBound; + uint32_t UpperBound; + + void swapBytes() { + sys::swapByteOrder(Type); + sys::swapByteOrder(Space); + sys::swapByteOrder(LowerBound); + sys::swapByteOrder(UpperBound); + } +}; + } // namespace v0 namespace v1 { @@ -348,6 +362,16 @@ } }; +struct ResourceBindInfo : public v0::ResourceBindInfo { + uint32_t Kind; + uint32_t Flags; + + void swapBytes() { + sys::swapByteOrder(Kind); + sys::swapByteOrder(Flags); + } +}; + } // namespace v2 } // namespace PSV diff --git a/llvm/include/llvm/MC/DXContainerPSVInfo.h b/llvm/include/llvm/MC/DXContainerPSVInfo.h --- a/llvm/include/llvm/MC/DXContainerPSVInfo.h +++ b/llvm/include/llvm/MC/DXContainerPSVInfo.h @@ -29,6 +29,7 @@ // RuntimeInfo. struct PSVRuntimeInfo { dxbc::PSV::v2::RuntimeInfo BaseData; + std::vector Resources; // Serialize PSVInfo into the provided raw_ostream. The version field // specifies the data version to encode, the default value specifies encoding @@ -39,6 +40,8 @@ void swapBytes(Triple::EnvironmentType Stage) { BaseData.swapBytes(); BaseData.swapBytes(Stage); + for (auto Res : Resources) + Res.swapBytes(); } }; diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -27,12 +27,84 @@ namespace DirectX { class PSVRuntimeInfo { + + // This class provides a view into the underlying resource array. The Resource + // data is little-endian encoded and may not be properly aligned to read + // directly from. The dereference operator creates a copy of the data and byte + // swaps it as appropriate. + struct ResourceArray { + StringRef Data; + size_t Stride; // size of each element in the list. + + ResourceArray() = default; + ResourceArray(StringRef D, size_t S) : Data(D), Stride(S) {} + + using value_type = dxbc::PSV::v2::ResourceBindInfo; + + struct iterator { + StringRef Data; + size_t Stride; // size of each element in the list. + const char *Current; + + iterator(const ResourceArray &A, const char *C) + : Data(A.Data), Stride(A.Stride), Current(C) {} + iterator(const iterator &) = default; + + value_type operator*() { + // Explicitly zero the structure so that unused fields are zeroed. It is + // up to the user to know if the fields are used by verifying the PSV + // version. + value_type Val = {{0, 0, 0, 0}, 0, 0}; + if (Current >= Data.end()) + return Val; + memcpy(static_cast(&Val), Current, Stride); + if (sys::IsBigEndianHost) + Val.swapBytes(); + return Val; + } + + iterator operator++() { + if (Current < Data.end()) + Current += Stride; + return *this; + } + + iterator operator++(int) { + iterator Tmp = *this; + ++*this; + return Tmp; + } + + iterator operator--() { + if (Current > Data.begin()) + Current -= Stride; + return *this; + } + + iterator operator--(int) { + iterator Tmp = *this; + --*this; + return Tmp; + } + + bool operator==(const iterator I) { return I.Current == Current; } + bool operator!=(const iterator I) { return !(*this == I); } + }; + + iterator begin() const { return iterator(*this, Data.begin()); } + + iterator end() const { return iterator(*this, Data.end()); } + + size_t size() const { return Data.size() / Stride; } + }; + StringRef Data; uint32_t Size; using InfoStruct = std::variant; InfoStruct BasicInfo; + ResourceArray Resources; public: PSVRuntimeInfo(StringRef D) : Data(D), Size(0) {} @@ -41,6 +113,9 @@ Error parse(uint16_t ShaderKind); uint32_t getSize() const { return Size; } + uint32_t getResourceCount() const { return Resources.size(); } + ResourceArray getResources() const { return Resources; } + uint32_t getVersion() const { return Size >= sizeof(dxbc::PSV::v2::RuntimeInfo) ? 2 diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h --- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h +++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h @@ -71,6 +71,8 @@ std::vector Digest; }; +using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo; + struct PSVInfo { // The version field isn't actually encoded in the file, but it is inferred by // the size of data regions. We include it in the yaml because it simplifies @@ -78,6 +80,7 @@ uint32_t Version; dxbc::PSV::v2::RuntimeInfo Info; + std::vector Resources; void mapInfoForVersion(yaml::IO &IO); @@ -107,6 +110,7 @@ } // namespace llvm LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::ResourceBindInfo) namespace llvm { class raw_ostream; @@ -145,6 +149,10 @@ static void mapping(IO &IO, DXContainerYAML::Object &Obj); }; +template <> struct MappingTraits { + static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res); +}; + } // namespace yaml } // namespace llvm diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp --- a/llvm/lib/MC/DXContainerPSVInfo.cpp +++ b/llvm/lib/MC/DXContainerPSVInfo.cpp @@ -12,6 +12,7 @@ using namespace llvm; using namespace llvm::mcdxbc; +using namespace llvm::dxbc::PSV; void PSVRuntimeInfo::write(raw_ostream &OS, uint32_t Version) const { uint32_t InfoSize; @@ -30,4 +31,14 @@ OS.write(reinterpret_cast(&InfoSize), sizeof(uint32_t)); // Write the info itself. OS.write(reinterpret_cast(&BaseData), InfoSize); + + uint32_t ResourceCount = static_cast(Resources.size()); + if (sys::IsBigEndianHost) + sys::swapByteOrder(ResourceCount); + OS.write(reinterpret_cast(&ResourceCount), sizeof(uint32_t)); + + size_t BindingSize = (Version < 2) ? sizeof(v0::ResourceBindInfo) + : sizeof(v2::ResourceBindInfo); + for (const auto &Res : Resources) + OS.write(reinterpret_cast(&Res), BindingSize); } diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp --- a/llvm/lib/Object/DXContainer.cpp +++ b/llvm/lib/Object/DXContainer.cpp @@ -229,5 +229,17 @@ } Current += Size; + uint32_t ResourceCount = 0; + if (Error Err = readInteger(Data, Current, ResourceCount)) + return Err; + Current += sizeof(uint32_t); + + Resources.Stride = (PSVVersion < 2) ? sizeof(v0::ResourceBindInfo) + : sizeof(v2::ResourceBindInfo); + size_t BindingDataSize = Resources.Stride * ResourceCount; + Resources.Data = Data.substr(Current - Data.begin(), BindingDataSize); + + Current += BindingDataSize; + return Error::success(); } diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp --- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp +++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp @@ -199,6 +199,7 @@ continue; mcdxbc::PSVRuntimeInfo PSV; memcpy(&PSV.BaseData, &P.Info->Info, sizeof(dxbc::PSV::v2::RuntimeInfo)); + PSV.Resources = P.Info->Resources; if (sys::IsBigEndianHost) PSV.swapBytes(static_cast( diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -117,10 +117,20 @@ IO &IO, DXContainerYAML::PSVInfo &PSV) { IO.mapRequired("Version", PSV.Version); + // Store the PSV version in the YAML context. + void *OldContext = IO.getContext(); + uint32_t Version = PSV.Version; + IO.setContext(&Version); + // Shader stage is only included in binaries for v1 and later, but we always // include it since it simplifies parsing and file construction. IO.mapRequired("ShaderStage", PSV.Info.ShaderStage); PSV.mapInfoForVersion(IO); + + IO.mapRequired("Resources", PSV.Resources); + + // Restore the YAML context. + IO.setContext(OldContext); } void MappingTraits::mapping(IO &IO, @@ -140,6 +150,21 @@ IO.mapRequired("Parts", Obj.Parts); } +void MappingTraits::mapping( + IO &IO, DXContainerYAML::ResourceBindInfo &Res) { + IO.mapRequired("Type", Res.Type); + IO.mapRequired("Space", Res.Space); + IO.mapRequired("LowerBound", Res.LowerBound); + IO.mapRequired("UpperBound", Res.UpperBound); + + const uint32_t *PSVVersion = static_cast(IO.getContext()); + if (*PSVVersion < 2) + return; + + IO.mapRequired("Kind", Res.Kind); + IO.mapRequired("Flags", Res.Flags); +} + } // namespace yaml void DXContainerYAML::PSVInfo::mapInfoForVersion(yaml::IO &IO) { diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-amplification.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-amplification.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-amplification.yaml @@ -17,6 +17,15 @@ PayloadSizeInBytes: 4092 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -36,4 +45,13 @@ # CHECK-NEXT: PayloadSizeInBytes: 4092 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-compute.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-compute.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-compute.yaml @@ -16,6 +16,15 @@ ShaderStage: 5 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -34,4 +43,13 @@ # CHECK-NEXT: ShaderStage: 5 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-domain.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-domain.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-domain.yaml @@ -19,6 +19,15 @@ TessellatorDomain: 2056 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -40,4 +49,13 @@ # CHECK-NEXT: TessellatorDomain: 2056 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-geometry.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-geometry.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-geometry.yaml @@ -20,6 +20,15 @@ OutputPositionPresent: 1 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -42,4 +51,13 @@ # CHECK-NEXT: OutputPositionPresent: 1 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-hull.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-hull.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-hull.yaml @@ -20,6 +20,15 @@ TessellatorOutputPrimitive: 8192 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -42,4 +51,13 @@ # CHECK-NEXT: TessellatorOutputPrimitive: 8192 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-mesh.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-mesh.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-mesh.yaml @@ -21,6 +21,15 @@ MaxOutputPrimitives: 4092 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -44,4 +53,13 @@ # CHECK-NEXT: MaxOutputPrimitives: 4092 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-pixel.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-pixel.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-pixel.yaml @@ -18,6 +18,15 @@ SampleFrequency: 96 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -38,4 +47,13 @@ # CHECK-NEXT: SampleFrequency: 96 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv0-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv0-vertex.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv0-vertex.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv0-vertex.yaml @@ -17,6 +17,15 @@ OutputPositionPresent: 1 MinimumWaveLaneCount: 0 MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -36,4 +45,13 @@ # CHECK-NEXT: OutputPositionPresent: 1 # CHECK-NEXT: MinimumWaveLaneCount: 0 # CHECK-NEXT: MaximumWaveLaneCount: 4294967295 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-amplification.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-amplification.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-amplification.yaml @@ -23,6 +23,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -48,4 +57,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-compute.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-compute.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-compute.yaml @@ -22,6 +22,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -46,4 +55,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-domain.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-domain.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-domain.yaml @@ -26,6 +26,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -54,4 +63,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-geometry.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-geometry.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-geometry.yaml @@ -27,6 +27,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -56,4 +65,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-hull.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-hull.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-hull.yaml @@ -27,6 +27,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -56,4 +65,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-mesh.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-mesh.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-mesh.yaml @@ -29,6 +29,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -60,4 +69,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-pixel.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-pixel.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-pixel.yaml @@ -24,6 +24,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -50,4 +59,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv1-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv1-vertex.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv1-vertex.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv1-vertex.yaml @@ -23,6 +23,15 @@ SigPatchConstOrPrimElements: 32 SigInputVectors: 64 SigOutputVectors: [ 8, 16, 32, 64 ] + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 - Name: DXIL Size: 24 Program: @@ -48,4 +57,13 @@ # CHECK-NEXT: SigPatchConstOrPrimElements: 32 # CHECK-NEXT: SigInputVectors: 64 # CHECK-NEXT: SigOutputVectors: [ 8, 16, 32, 64 ] +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-amplification.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-amplification.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-amplification.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-amplification.yaml @@ -26,6 +26,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -54,4 +67,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-compute.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-compute.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-compute.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-compute.yaml @@ -25,6 +25,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -52,4 +65,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-domain.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-domain.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-domain.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-domain.yaml @@ -29,6 +29,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -60,4 +73,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-geometry.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-geometry.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-geometry.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-geometry.yaml @@ -30,6 +30,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -62,4 +75,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-hull.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-hull.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-hull.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-hull.yaml @@ -30,6 +30,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -62,4 +75,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-mesh.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-mesh.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-mesh.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-mesh.yaml @@ -32,6 +32,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -66,4 +79,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-pixel.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-pixel.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-pixel.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-pixel.yaml @@ -27,6 +27,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -56,4 +69,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/test/ObjectYAML/DXContainer/PSVv2-vertex.yaml b/llvm/test/ObjectYAML/DXContainer/PSVv2-vertex.yaml --- a/llvm/test/ObjectYAML/DXContainer/PSVv2-vertex.yaml +++ b/llvm/test/ObjectYAML/DXContainer/PSVv2-vertex.yaml @@ -26,6 +26,19 @@ NumThreadsX: 512 NumThreadsY: 1024 NumThreadsZ: 2048 + Resources: + - Type: 1 + Space: 2 + LowerBound: 3 + UpperBound: 4 + Kind: 5 + Flags: 6 + - Type: 128 + Space: 32768 + LowerBound: 8388608 + UpperBound: 2147483648 + Kind: 65535 + Flags: 16776960 - Name: DXIL Size: 24 Program: @@ -54,4 +67,17 @@ # CHECK-NEXT: NumThreadsX: 512 # CHECK-NEXT: NumThreadsY: 1024 # CHECK-NEXT: NumThreadsZ: 2048 +# CHECK-NEXT: Resources: +# CHECK-NEXT: - Type: 1 +# CHECK-NEXT: Space: 2 +# CHECK-NEXT: LowerBound: 3 +# CHECK-NEXT: UpperBound: 4 +# CHECK-NEXT: Kind: 5 +# CHECK-NEXT: Flags: 6 +# CHECK-NEXT: - Type: 128 +# CHECK-NEXT: Space: 32768 +# CHECK-NEXT: LowerBound: 8388608 +# CHECK-NEXT: UpperBound: 2147483648 +# CHECK-NEXT: Kind: 65535 +# CHECK-NEXT: Flags: 16776960 # CHECK-NEXT: Name diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp --- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp +++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp @@ -89,6 +89,8 @@ else if (const auto *P = std::get_if(&PSVInfo->getInfo())) NewPart.Info = DXContainerYAML::PSVInfo(P); + for (auto Res : PSVInfo->getResources()) + NewPart.Info->Resources.push_back(Res); break; } case dxbc::PartType::Unknown: diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp --- a/llvm/unittests/Object/DXContainerTest.cpp +++ b/llvm/unittests/Object/DXContainerTest.cpp @@ -9,6 +9,8 @@ #include "llvm/Object/DXContainer.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Magic.h" +#include "llvm/ObjectYAML/DXContainerYAML.h" +#include "llvm/ObjectYAML/yaml2obj.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" @@ -171,3 +173,170 @@ EXPECT_TRUE(memcmp(It->Part.Name, "FKE6", 4) == 0); } } + +static Expected +generateDXContainer(StringRef Yaml, SmallVectorImpl &BinaryData) { + DXContainerYAML::Object Obj; + SMDiagnostic GenerateDiag; + yaml::Input YIn( + Yaml, /*Ctxt=*/nullptr, + [](const SMDiagnostic &Diag, void *DiagContext) { + *static_cast(DiagContext) = Diag; + }, + &GenerateDiag); + + YIn >> Obj; + if (YIn.error()) + return createStringError(YIn.error(), GenerateDiag.getMessage()); + + raw_svector_ostream OS(BinaryData); + std::string ErrorMsg; + if (!yaml::yaml2dxcontainer( + Obj, OS, [&ErrorMsg](const Twine &Msg) { ErrorMsg = Msg.str(); })) + return createStringError(YIn.error(), ErrorMsg); + + MemoryBufferRef BinaryDataRef = MemoryBufferRef(OS.str(), ""); + + return DXContainer::create(BinaryDataRef); +} + +TEST(DXCFile, PSVResourceIterators) { + const char *Yaml = R"( +--- !dxcontainer +Header: + Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] + Version: + Major: 1 + Minor: 0 + PartCount: 2 +Parts: + - Name: PSV0 + Size: 144 + PSVInfo: + Version: 0 + ShaderStage: 14 + PayloadSizeInBytes: 4092 + MinimumWaveLaneCount: 0 + MaximumWaveLaneCount: 4294967295 + Resources: + - Type: 1 + Space: 1 + LowerBound: 1 + UpperBound: 1 + - Type: 2 + Space: 2 + LowerBound: 2 + UpperBound: 2 + - Type: 3 + Space: 3 + LowerBound: 3 + UpperBound: 3 + - Name: DXIL + Size: 24 + Program: + MajorVersion: 6 + MinorVersion: 0 + ShaderKind: 14 + Size: 6 + DXILMajorVersion: 0 + DXILMinorVersion: 1 + DXILSize: 0 +... +)"; + + SmallVector BinaryData; + auto C = generateDXContainer(Yaml, BinaryData); + + ASSERT_THAT_EXPECTED(C, Succeeded()); + + const auto &PSVInfo = C->getPSVInfo(); + ASSERT_TRUE(PSVInfo.has_value()); + + EXPECT_EQ(PSVInfo->getResourceCount(), 3u); + + auto It = PSVInfo->getResources().begin(); + + EXPECT_TRUE(It == PSVInfo->getResources().begin()); + + dxbc::PSV::v2::ResourceBindInfo Binding; + + Binding = *It; + EXPECT_EQ(Binding.Type, 1u); + EXPECT_EQ(Binding.Flags, 0u); + + ++It; + Binding = *It; + + EXPECT_EQ(Binding.Type, 2u); + EXPECT_EQ(Binding.Flags, 0u); + + --It; + Binding = *It; + + EXPECT_TRUE(It == PSVInfo->getResources().begin()); + + EXPECT_EQ(Binding.Type, 1u); + EXPECT_EQ(Binding.Flags, 0u); + + --It; + Binding = *It; + + EXPECT_EQ(Binding.Type, 1u); + EXPECT_EQ(Binding.Flags, 0u); + + ++It; + Binding = *It; + + EXPECT_EQ(Binding.Type, 2u); + EXPECT_EQ(Binding.Flags, 0u); + + ++It; + Binding = *It; + + EXPECT_EQ(Binding.Type, 3u); + EXPECT_EQ(Binding.Flags, 0u); + + EXPECT_FALSE(It == PSVInfo->getResources().end()); + + ++It; + Binding = *It; + + EXPECT_TRUE(It == PSVInfo->getResources().end()); + EXPECT_FALSE(It != PSVInfo->getResources().end()); + + EXPECT_EQ(Binding.Type, 0u); + EXPECT_EQ(Binding.Flags, 0u); + + { + auto Old = It++; + Binding = *Old; + + EXPECT_TRUE(Old == PSVInfo->getResources().end()); + EXPECT_FALSE(Old != PSVInfo->getResources().end()); + + EXPECT_EQ(Binding.Type, 0u); + EXPECT_EQ(Binding.Flags, 0u); + } + + Binding = *It; + + EXPECT_TRUE(It == PSVInfo->getResources().end()); + + EXPECT_EQ(Binding.Type, 0u); + EXPECT_EQ(Binding.Flags, 0u); + + { + auto Old = It--; + Binding = *Old; + EXPECT_TRUE(Old == PSVInfo->getResources().end()); + + EXPECT_EQ(Binding.Type, 0u); + EXPECT_EQ(Binding.Flags, 0u); + } + + Binding = *It; + + EXPECT_EQ(Binding.Type, 3u); + EXPECT_EQ(Binding.Flags, 0u); +}