llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-directx Author: None (joaosaffran) <details> <summary>Changes</summary> As requested in a previous PR, this change moves all structs related to RTS0 to RTS0 namespace. --- Full diff: https://github.com/llvm/llvm-project/pull/141173.diff 8 Files Affected: - (modified) llvm/include/llvm/BinaryFormat/DXContainer.h (+19-16) - (modified) llvm/include/llvm/MC/DXContainerRootSignature.h (+10-10) - (modified) llvm/include/llvm/Object/DXContainer.h (+9-8) - (modified) llvm/lib/MC/DXContainerRootSignature.cpp (+5-4) - (modified) llvm/lib/Object/DXContainer.cpp (+2-1) - (modified) llvm/lib/ObjectYAML/DXContainerEmitter.cpp (+3-3) - (modified) llvm/lib/ObjectYAML/DXContainerYAML.cpp (+3-2) - (modified) llvm/lib/Target/DirectX/DXILRootSignature.cpp (+5-5) ``````````diff diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h index 82890bf814935..3494e0fe1a0e9 100644 --- a/llvm/include/llvm/BinaryFormat/DXContainer.h +++ b/llvm/include/llvm/BinaryFormat/DXContainer.h @@ -585,6 +585,7 @@ struct ProgramSignatureElement { static_assert(sizeof(ProgramSignatureElement) == 32, "ProgramSignatureElement is misaligned"); + namespace RTS0 { namespace v1 { struct RootDescriptor { @@ -595,23 +596,7 @@ struct RootDescriptor { sys::swapByteOrder(RegisterSpace); } }; -} // namespace v1 - -namespace v2 { -struct RootDescriptor : public v1::RootDescriptor { - uint32_t Flags; - - RootDescriptor() = default; - explicit RootDescriptor(v1::RootDescriptor &Base) - : v1::RootDescriptor(Base), Flags(0u) {} - void swapBytes() { - v1::RootDescriptor::swapBytes(); - sys::swapByteOrder(Flags); - } -}; -} // namespace v2 -} // namespace RTS0 // following dx12 naming // https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_root_constants struct RootConstants { @@ -655,6 +640,24 @@ struct RootSignatureHeader { sys::swapByteOrder(Flags); } }; +} // namespace v1 + +namespace v2 { +struct RootDescriptor : public v1::RootDescriptor { + uint32_t Flags; + + RootDescriptor() = default; + explicit RootDescriptor(v1::RootDescriptor &Base) + : v1::RootDescriptor(Base), Flags(0u) {} + + void swapBytes() { + v1::RootDescriptor::swapBytes(); + sys::swapByteOrder(Flags); + } +}; +} // namespace v2 +} // namespace RTS0 + } // namespace dxbc } // namespace llvm diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h index 3496b5fff398f..5f5919122b3c5 100644 --- a/llvm/include/llvm/MC/DXContainerRootSignature.h +++ b/llvm/include/llvm/MC/DXContainerRootSignature.h @@ -16,36 +16,36 @@ class raw_ostream; namespace mcdxbc { struct RootParameterInfo { - dxbc::RootParameterHeader Header; + dxbc::RTS0::v1::RootParameterHeader Header; size_t Location; RootParameterInfo() = default; - RootParameterInfo(dxbc::RootParameterHeader Header, size_t Location) + RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) : Header(Header), Location(Location) {} }; struct RootParametersContainer { SmallVector<RootParameterInfo> ParametersInfo; - SmallVector<dxbc::RootConstants> Constants; + SmallVector<dxbc::RTS0::v1::RootConstants> Constants; SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors; - void addInfo(dxbc::RootParameterHeader Header, size_t Location) { + void addInfo(dxbc::RTS0::v1::RootParameterHeader Header, size_t Location) { ParametersInfo.push_back(RootParameterInfo(Header, Location)); } - void addParameter(dxbc::RootParameterHeader Header, - dxbc::RootConstants Constant) { + void addParameter(dxbc::RTS0::v1::RootParameterHeader Header, + dxbc::RTS0::v1::RootConstants Constant) { addInfo(Header, Constants.size()); Constants.push_back(Constant); } - void addInvalidParameter(dxbc::RootParameterHeader Header) { + void addInvalidParameter(dxbc::RTS0::v1::RootParameterHeader Header) { addInfo(Header, -1); } - void addParameter(dxbc::RootParameterHeader Header, + void addParameter(dxbc::RTS0::v1::RootParameterHeader Header, dxbc::RTS0::v2::RootDescriptor Descriptor) { addInfo(Header, Descriptors.size()); Descriptors.push_back(Descriptor); @@ -57,12 +57,12 @@ struct RootParametersContainer { return {Info.Header.ParameterType, Info.Location}; } - const dxbc::RootParameterHeader &getHeader(size_t Location) const { + const dxbc::RTS0::v1::RootParameterHeader &getHeader(size_t Location) const { const RootParameterInfo &Info = ParametersInfo[Location]; return Info.Header; } - const dxbc::RootConstants &getConstant(size_t Index) const { + const dxbc::RTS0::v1::RootConstants &getConstant(size_t Index) const { return Constants[Index]; } diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h index 61bfa9411cc57..37cd5ca7dc935 100644 --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -121,10 +121,10 @@ template <typename T> struct ViewArray { namespace DirectX { struct RootParameterView { - const dxbc::RootParameterHeader &Header; + const dxbc::RTS0::v1::RootParameterHeader &Header; StringRef ParamData; - RootParameterView(const dxbc::RootParameterHeader &H, StringRef P) + RootParameterView(const dxbc::RTS0::v1::RootParameterHeader &H, StringRef P) : Header(H), ParamData(P) {} template <typename T> Expected<T> readParameter() { @@ -147,8 +147,8 @@ struct RootConstantView : RootParameterView { (uint32_t)dxbc::RootParameterType::Constants32Bit; } - llvm::Expected<dxbc::RootConstants> read() { - return readParameter<dxbc::RootConstants>(); + llvm::Expected<dxbc::RTS0::v1::RootConstants> read() { + return readParameter<dxbc::RTS0::v1::RootConstants>(); } }; @@ -189,10 +189,11 @@ class RootSignature { uint32_t NumStaticSamplers; uint32_t StaticSamplersOffset; uint32_t Flags; - ViewArray<dxbc::RootParameterHeader> ParametersHeaders; + ViewArray<dxbc::RTS0::v1::RootParameterHeader> ParametersHeaders; StringRef PartData; - using param_header_iterator = ViewArray<dxbc::RootParameterHeader>::iterator; + using param_header_iterator = + ViewArray<dxbc::RTS0::v1::RootParameterHeader>::iterator; public: RootSignature(StringRef PD) : PartData(PD) {} @@ -210,7 +211,7 @@ class RootSignature { uint32_t getFlags() const { return Flags; } llvm::Expected<RootParameterView> - getParameter(const dxbc::RootParameterHeader &Header) const { + getParameter(const dxbc::RTS0::v1::RootParameterHeader &Header) const { size_t DataSize; if (!dxbc::isValidParameterType(Header.ParameterType)) @@ -218,7 +219,7 @@ class RootSignature { switch (static_cast<dxbc::RootParameterType>(Header.ParameterType)) { case dxbc::RootParameterType::Constants32Bit: - DataSize = sizeof(dxbc::RootConstants); + DataSize = sizeof(dxbc::RTS0::v1::RootConstants); break; case dxbc::RootParameterType::CBV: case dxbc::RootParameterType::SRV: diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp index a9394541d18da..3a4bd8321eb95 100644 --- a/llvm/lib/MC/DXContainerRootSignature.cpp +++ b/llvm/lib/MC/DXContainerRootSignature.cpp @@ -29,13 +29,14 @@ static void rewriteOffsetToCurrentByte(raw_svector_ostream &Stream, } size_t RootSignatureDesc::getSize() const { - size_t Size = sizeof(dxbc::RootSignatureHeader) + - ParametersContainer.size() * sizeof(dxbc::RootParameterHeader); + size_t Size = + sizeof(dxbc::RTS0::v1::RootSignatureHeader) + + ParametersContainer.size() * sizeof(dxbc::RTS0::v1::RootParameterHeader); for (const RootParameterInfo &I : ParametersContainer) { switch (I.Header.ParameterType) { case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): - Size += sizeof(dxbc::RootConstants); + Size += sizeof(dxbc::RTS0::v1::RootConstants); break; case llvm::to_underlying(dxbc::RootParameterType::CBV): case llvm::to_underlying(dxbc::RootParameterType::SRV): @@ -81,7 +82,7 @@ void RootSignatureDesc::write(raw_ostream &OS) const { const auto &[Type, Loc] = ParametersContainer.getTypeAndLocForParameter(I); switch (Type) { case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): { - const dxbc::RootConstants &Constants = + const dxbc::RTS0::v1::RootConstants &Constants = ParametersContainer.getConstant(Loc); support::endian::write(BOS, Constants.ShaderRegister, llvm::endianness::little); diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp index 95f6788e75aa6..2d05566626bfc 100644 --- a/llvm/lib/Object/DXContainer.cpp +++ b/llvm/lib/Object/DXContainer.cpp @@ -273,7 +273,8 @@ Error DirectX::RootSignature::parse() { Current += sizeof(uint32_t); ParametersHeaders.Data = PartData.substr( - RootParametersOffset, NumParameters * sizeof(dxbc::RootParameterHeader)); + RootParametersOffset, + NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader)); return Error::success(); } diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp index ace2eca5072bd..71a87f6aa24fc 100644 --- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp +++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp @@ -274,12 +274,12 @@ void DXContainerWriter::writeParts(raw_ostream &OS) { RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset; for (const auto &Param : P.RootSignature->Parameters) { - auto Header = dxbc::RootParameterHeader{Param.Type, Param.Visibility, - Param.Offset}; + auto Header = dxbc::RTS0::v1::RootParameterHeader{ + Param.Type, Param.Visibility, Param.Offset}; if (auto *ConstantYaml = std::get_if<DXContainerYAML::RootConstantsYaml>(&Param.Data)) { - dxbc::RootConstants Constants; + dxbc::RTS0::v1::RootConstants Constants; Constants.Num32BitValues = ConstantYaml->Num32BitValues; Constants.RegisterSpace = ConstantYaml->RegisterSpace; Constants.ShaderRegister = ConstantYaml->ShaderRegister; diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp index fdb039e75fdda..b824a408e30a6 100644 --- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp +++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp @@ -47,7 +47,7 @@ DXContainerYAML::RootSignatureYamlDesc::create( RootSigDesc.RootParametersOffset = Data.getRootParametersOffset(); uint32_t Flags = Data.getFlags(); - for (const dxbc::RootParameterHeader &PH : Data.param_headers()) { + for (const dxbc::RTS0::v1::RootParameterHeader &PH : Data.param_headers()) { if (!dxbc::isValidParameterType(PH.ParameterType)) return createStringError(std::errc::invalid_argument, @@ -70,7 +70,8 @@ DXContainerYAML::RootSignatureYamlDesc::create( object::DirectX::RootParameterView ParamView = ParamViewOrErr.get(); if (auto *RCV = dyn_cast<object::DirectX::RootConstantView>(&ParamView)) { - llvm::Expected<dxbc::RootConstants> ConstantsOrErr = RCV->read(); + llvm::Expected<dxbc::RTS0::v1::RootConstants> ConstantsOrErr = + RCV->read(); if (Error E = ConstantsOrErr.takeError()) return std::move(E); diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 43e06ee278b49..40277899b5c7e 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -75,7 +75,7 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, if (RootConstantNode->getNumOperands() != 5) return reportError(Ctx, "Invalid format for RootConstants Element"); - dxbc::RootParameterHeader Header; + dxbc::RTS0::v1::RootParameterHeader Header; // The parameter offset doesn't matter here - we recalculate it during // serialization Header.ParameterOffset = 0; Header.ParameterType = @@ -86,7 +86,7 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, else return reportError(Ctx, "Invalid value for ShaderVisibility"); - dxbc::RootConstants Constants; + dxbc::RTS0::v1::RootConstants Constants; if (std::optional<uint32_t> Val = extractMdIntValue(RootConstantNode, 2)) Constants.ShaderRegister = *Val; else @@ -247,7 +247,7 @@ analyzeModule(Module &M) { // Clang emits the root signature data in dxcontainer following a specific // sequence. First the header, then the root parameters. So the header // offset will always equal to the header size. - RSD.RootParameterOffset = sizeof(dxbc::RootSignatureHeader); + RSD.RootParameterOffset = sizeof(dxbc::RTS0::v1::RootSignatureHeader); if (parse(Ctx, RSD, RootElementListNode) || validate(Ctx, RSD)) { return RSDMap; @@ -296,7 +296,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M, for (size_t I = 0; I < RS.ParametersContainer.size(); I++) { const auto &[Type, Loc] = RS.ParametersContainer.getTypeAndLocForParameter(I); - const dxbc::RootParameterHeader Header = + const dxbc::RTS0::v1::RootParameterHeader Header = RS.ParametersContainer.getHeader(I); OS << indent(Space) << "- Parameter Type: " << Type << "\n"; @@ -305,7 +305,7 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M, switch (Type) { case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): { - const dxbc::RootConstants &Constants = + const dxbc::RTS0::v1::RootConstants &Constants = RS.ParametersContainer.getConstant(Loc); OS << indent(Space + 2) << "Register Space: " << Constants.RegisterSpace << "\n"; `````````` </details> https://github.com/llvm/llvm-project/pull/141173 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits