Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DirectX] adding support to read/write descriptor table data using obj2yaml/yaml2obj #138315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
0abacfc
adding support for Root Descriptors
Apr 24, 2025
8b8c02a
clean up
Apr 24, 2025
7ac9641
addressing comments
Apr 25, 2025
c105458
formating
Apr 26, 2025
efe76aa
try fix test
Apr 26, 2025
a928e9d
addressing comments
Apr 26, 2025
a38f10b
refactoring mcdxbc struct to store root parameters out of order
Apr 25, 2025
9a7c359
changing name
Apr 28, 2025
d6c2b55
changing variant to host pointers
Apr 28, 2025
93e4cf2
clean up
Apr 28, 2025
b45b1b6
fix
Apr 28, 2025
f804a23
fix
Apr 28, 2025
44bd13a
making read work
Apr 29, 2025
ac51bf6
adding reading logic
May 2, 2025
97fb003
test pass locally
May 2, 2025
93e04bd
adding tests
May 2, 2025
2f6d579
adding more tests
May 2, 2025
76b1b75
clean up
May 2, 2025
b2bfb02
refactoring root signature dxcontainer yaml representation
May 2, 2025
9ee2964
clean up
May 2, 2025
2527580
fix test
May 2, 2025
c3a46da
copy test
May 2, 2025
15eb6f5
fix naming
May 5, 2025
3e26364
moving root signature binary representation to RTS0 namespace
May 5, 2025
b9d7f07
fix naming
May 5, 2025
46cc8c1
addressing comments
May 8, 2025
1b3e10a
addressing comments
May 8, 2025
1f31957
addressing comments
May 8, 2025
e8fbfce
clean up
May 8, 2025
a31e5a5
removing v parameter
May 9, 2025
a394ad0
Merge branch 'obj2yaml/root-descriptors' into refactoring/remove-union
May 9, 2025
ad415a7
clean up
May 9, 2025
8ff4845
Merge branch 'main' into refactoring/remove-union
May 9, 2025
98c6a5f
updating namespace naming
May 14, 2025
d67f7d3
addressing comment
May 14, 2025
5453ad0
clean up
May 14, 2025
836a8a8
format
May 14, 2025
5bd57a6
adding comment
May 14, 2025
960cb9c
adrresing comments
May 14, 2025
a60c7a3
clean up
May 14, 2025
2a4c2cb
formatting
May 15, 2025
c29d3f2
addressing comments
May 15, 2025
1513dab
Merge branch 'refactoring/remove-union' into obj2yaml/descriptor-table
May 16, 2025
95f3e99
Merge branch 'main' into obj2yaml/descriptor-table
May 16, 2025
eb97f1b
fixing test issues
May 16, 2025
a9b87c2
format
May 16, 2025
28be2f8
format
May 20, 2025
76a2b07
clean up
May 21, 2025
b891126
clean up
May 21, 2025
2a93252
fix formating issue
May 21, 2025
d616b65
fix formating issue
May 21, 2025
6eac7c4
making NumDescriptors uint32_t
May 22, 2025
df194b0
Merge branch 'main' into refactoring/dxcontainer-yaml
May 22, 2025
0136cfc
fix testing issues
May 22, 2025
b589d10
clean up
May 22, 2025
c7042b2
clean up
May 22, 2025
70a9b7f
addressing PR Comments
May 22, 2025
e3489a4
Merge branch 'refactoring/dxcontainer-yaml' into users/joaosaffran/13…
May 22, 2025
f1dd0ce
formating
May 22, 2025
6aa895e
Merge branch 'users/joaosaffran/138318' into obj2yaml/descriptor-table
May 22, 2025
f8080c4
fix tests
May 22, 2025
aabd424
addressing comments
May 23, 2025
e655315
move to namespace
May 23, 2025
3094a75
cleanup
May 23, 2025
984baf6
movin all to RTS0
May 23, 2025
3979151
clean up
May 23, 2025
e65f850
Merge branch 'main' into obj2yaml/descriptor-table
May 28, 2025
f5bffca
fix
May 28, 2025
a585134
adding check
May 28, 2025
08c5207
fix format?
May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 49 additions & 135 deletions 184 llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,50 @@ enum class FeatureFlags : uint64_t {
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
"Shader flag bits exceed enum size.");

#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
enum class RootElementFlag : uint32_t {
#include "DXContainerConstants.def"
};

#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = 1ull << Num,
enum class RootDescriptorFlag : uint32_t {
#include "DXContainerConstants.def"
};

#define ROOT_PARAMETER(Val, Enum) Enum = Val,
enum class RootParameterType : uint32_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();

#define ROOT_PARAMETER(Val, Enum) \
case Val: \
return true;
inline bool isValidParameterType(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
enum class ShaderVisibility : uint32_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();

#define SHADER_VISIBILITY(Val, Enum) \
case Val: \
return true;
inline bool isValidShaderVisibility(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

PartType parsePartType(StringRef S);

struct VertexPSVInfo {
Expand Down Expand Up @@ -553,146 +597,16 @@ struct RootDescriptor {
};
} // namespace v1

namespace RTS0 {

#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
enum class RootElementFlag : uint32_t {
#include "DXContainerConstants.def"
};

#define ROOT_DESCRIPTOR_FLAG(Num, Val) Val = 1ull << Num,
enum class RootDescriptorFlag : uint32_t {
#include "DXContainerConstants.def"
};

#define DESCRIPTOR_RANGE_FLAG(Num, Val) Val = 1ull << Num,
enum class DescriptorRangeFlag : uint32_t {
#include "DXContainerConstants.def"
};

#define ROOT_PARAMETER(Val, Enum) Enum = Val,
enum class RootParameterType : uint32_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<RootParameterType>> getRootParameterTypes();

#define DESCRIPTOR_RANGE(Val, Enum) Enum = Val,
enum class DescriptorRangeType : uint32_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<DescriptorRangeType>> getDescriptorRangeTypes();

#define ROOT_PARAMETER(Val, Enum) \
case Val: \
return true;
inline bool isValidParameterType(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

#define SHADER_VISIBILITY(Val, Enum) Enum = Val,
enum class ShaderVisibility : uint32_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<ShaderVisibility>> getShaderVisibility();

#define SHADER_VISIBILITY(Val, Enum) \
case Val: \
return true;
inline bool isValidShaderVisibility(uint32_t V) {
switch (V) {
#include "DXContainerConstants.def"
}
return false;
}

namespace v1 {

struct RootSignatureHeader {
uint32_t Version;
uint32_t NumParameters;
uint32_t ParametersOffset;
uint32_t NumStaticSamplers;
uint32_t StaticSamplerOffset;
uint32_t Flags;

void swapBytes() {
sys::swapByteOrder(Version);
sys::swapByteOrder(NumParameters);
sys::swapByteOrder(ParametersOffset);
sys::swapByteOrder(NumStaticSamplers);
sys::swapByteOrder(StaticSamplerOffset);
sys::swapByteOrder(Flags);
}
};

struct RootParameterHeader {
uint32_t ParameterType;
uint32_t ShaderVisibility;
uint32_t ParameterOffset;

void swapBytes() {
sys::swapByteOrder(ParameterType);
sys::swapByteOrder(ShaderVisibility);
sys::swapByteOrder(ParameterOffset);
}
};

struct RootConstants {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
uint32_t Num32BitValues;

void swapBytes() {
sys::swapByteOrder(ShaderRegister);
sys::swapByteOrder(RegisterSpace);
sys::swapByteOrder(Num32BitValues);
}
};

struct RootDescriptor {
uint32_t ShaderRegister;
uint32_t RegisterSpace;
void swapBytes() {
sys::swapByteOrder(ShaderRegister);
sys::swapByteOrder(RegisterSpace);
}
};

struct DescriptorRange {
uint32_t RangeType;
uint32_t NumDescriptors;
uint32_t BaseShaderRegister;
uint32_t RegisterSpace;
int32_t OffsetInDescriptorsFromTableStart;
void swapBytes() {
sys::swapByteOrder(RangeType);
sys::swapByteOrder(NumDescriptors);
sys::swapByteOrder(BaseShaderRegister);
sys::swapByteOrder(RegisterSpace);
sys::swapByteOrder(OffsetInDescriptorsFromTableStart);
}
};
} // namespace v1

namespace v2 {
struct RootDescriptor : public v1::RootDescriptor {
uint32_t Flags;
void swapBytes() {
v1::RootDescriptor::swapBytes();
sys::swapByteOrder(Flags);
}
};

struct DescriptorRange : public v1::DescriptorRange {
uint32_t Flags;
RootDescriptor() = default;
explicit RootDescriptor(v1::RootDescriptor &Base)
: v1::RootDescriptor(Base), Flags(0u) {}

void swapBytes() {
v1::DescriptorRange::swapBytes();
v1::RootDescriptor::swapBytes();
sys::swapByteOrder(Flags);
}
};
Expand Down
23 changes: 0 additions & 23 deletions 23 llvm/include/llvm/BinaryFormat/DXContainerConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,15 @@ ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)
#endif // ROOT_DESCRIPTOR_FLAG


// DESCRIPTOR_RANGE_FLAG(bit offset for the flag, name).
#ifdef DESCRIPTOR_RANGE_FLAG

DESCRIPTOR_RANGE_FLAG(0, NONE)
DESCRIPTOR_RANGE_FLAG(1, DESCRIPTORS_VOLATILE)
DESCRIPTOR_RANGE_FLAG(2, DATA_VOLATILE)
DESCRIPTOR_RANGE_FLAG(3, DATA_STATIC_WHILE_SET_AT_EXECUTE)
DESCRIPTOR_RANGE_FLAG(4, DATA_STATIC)
DESCRIPTOR_RANGE_FLAG(16, DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG

#ifdef ROOT_PARAMETER

ROOT_PARAMETER(0, DescriptorTable)
ROOT_PARAMETER(1, Constants32Bit)
ROOT_PARAMETER(2, CBV)
ROOT_PARAMETER(3, SRV)
ROOT_PARAMETER(4, UAV)
#undef ROOT_PARAMETER
#endif // ROOT_PARAMETER


#ifdef DESCRIPTOR_RANGE

DESCRIPTOR_RANGE(0, SRV)
DESCRIPTOR_RANGE(1, UAV)
DESCRIPTOR_RANGE(2, CBV)
DESCRIPTOR_RANGE(3, Sampler)
#undef DESCRIPTOR_RANGE
#endif // DESCRIPTOR_RANGE

#ifdef SHADER_VISIBILITY

SHADER_VISIBILITY(0, All)
Expand Down
99 changes: 33 additions & 66 deletions 99 llvm/include/llvm/MC/DXContainerRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include <cstddef>
#include <cstdint>
#include <optional>
#include <utility>
#include <variant>
#include <limits>

namespace llvm {

Expand All @@ -26,81 +21,53 @@ struct RootParameterInfo {

RootParameterInfo() = default;

RootParameterInfo(dxbc::RTS0::v1::RootParameterHeader H, size_t L)
: Header(H), Location(L) {}
RootParameterInfo(dxbc::RootParameterHeader Header, size_t Location)
: Header(Header), Location(Location) {}
};
using DescriptorRanges = std::variant<dxbc::RTS0::v1::DescriptorRange,
dxbc::RTS0::v2::DescriptorRange>;
struct DescriptorTable {
SmallVector<DescriptorRanges> Ranges;

SmallVector<DescriptorRanges>::const_iterator begin() const {
return Ranges.begin();
}
SmallVector<DescriptorRanges>::const_iterator end() const {
return Ranges.end();
}
};

using RootDescriptor = std::variant<dxbc::RTS0::v1::RootDescriptor,
dxbc::RTS0::v2::RootDescriptor>;

using ParametersView = std::variant<const dxbc::RTS0::v1::RootConstants *,
const dxbc::RTS0::v1::RootDescriptor *,
const dxbc::RTS0::v2::RootDescriptor *,
const DescriptorTable *>;
struct RootParametersContainer {
SmallVector<RootParameterInfo> ParametersInfo;
SmallVector<dxbc::RTS0::v1::RootConstants> Constants;
SmallVector<RootDescriptor> Descriptors;
SmallVector<DescriptorTable> Tables;

void addInfo(dxbc::RTS0::v1::RootParameterHeader H, size_t L) {
ParametersInfo.push_back(RootParameterInfo(H, L));
SmallVector<dxbc::RootConstants> Constants;
SmallVector<dxbc::RTS0::v2::RootDescriptor> Descriptors;

void addInfo(dxbc::RootParameterHeader Header, size_t Location) {
ParametersInfo.push_back(RootParameterInfo(Header, Location));
}

void addParameter(dxbc::RootParameterHeader Header,
dxbc::RootConstants Constant) {
addInfo(Header, Constants.size());
Constants.push_back(Constant);
}

void addInvalidParameter(dxbc::RootParameterHeader Header) {
addInfo(Header, -1);
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader H,
dxbc::RTS0::v1::RootConstants C) {
addInfo(H, Constants.size());
Constants.push_back(C);
void addParameter(dxbc::RootParameterHeader Header,
dxbc::RTS0::v2::RootDescriptor Descriptor) {
addInfo(Header, Descriptors.size());
Descriptors.push_back(Descriptor);
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader H,
dxbc::RTS0::v1::RootDescriptor D) {
addInfo(H, Descriptors.size());
Descriptors.push_back(D);
const std::pair<uint32_t, uint32_t>
getTypeAndLocForParameter(uint32_t Location) const {
const RootParameterInfo &Info = ParametersInfo[Location];
return {Info.Header.ParameterType, Info.Location};
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader H,
dxbc::RTS0::v2::RootDescriptor D) {
addInfo(H, Descriptors.size());
Descriptors.push_back(D);
const dxbc::RootParameterHeader &getHeader(size_t Location) const {
const RootParameterInfo &Info = ParametersInfo[Location];
return Info.Header;
}

void addParameter(dxbc::RTS0::v1::RootParameterHeader H, DescriptorTable D) {
addInfo(H, Tables.size());
Tables.push_back(D);
const dxbc::RootConstants &getConstant(size_t Index) const {
return Constants[Index];
}

std::optional<ParametersView> getParameter(const RootParameterInfo *H) const {
switch (H->Header.ParameterType) {
case llvm::to_underlying(dxbc::RTS0::RootParameterType::Constants32Bit):
return &Constants[H->Location];
case llvm::to_underlying(dxbc::RTS0::RootParameterType::CBV):
case llvm::to_underlying(dxbc::RTS0::RootParameterType::SRV):
case llvm::to_underlying(dxbc::RTS0::RootParameterType::UAV): {
const RootDescriptor &VersionedParam = Descriptors[H->Location];
if (std::holds_alternative<dxbc::RTS0::v1::RootDescriptor>(
VersionedParam)) {
return &std::get<dxbc::RTS0::v1::RootDescriptor>(VersionedParam);
}
return &std::get<dxbc::RTS0::v2::RootDescriptor>(VersionedParam);
}
case llvm::to_underlying(dxbc::RTS0::RootParameterType::DescriptorTable):
return &Tables[H->Location];
}

return std::nullopt;
const dxbc::RTS0::v2::RootDescriptor &getRootDescriptor(size_t Index) const {
return Descriptors[Index];
}

size_t size() const { return ParametersInfo.size(); }
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.