Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
65 changes: 40 additions & 25 deletions llvm/lib/MC/DXContainerRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,59 @@
using namespace llvm;
using namespace llvm::mcdxbc;

void setRewrite(raw_ostream &Stream, uint32_t &Offset) {
const uint32_t DummyValue = std::numeric_limits<uint32_t>::max();
Offset = Stream.tell();
support::endian::write(Stream, DummyValue, llvm::endianness::little);
}

void rewriteOffset(buffer_ostream &Stream, uint32_t Offset) {
uint32_t Value = Stream.tell();
auto *InsertPoint = &Stream.buffer()[Offset];
support::endian::write(InsertPoint, Value, llvm::endianness::little);
}

void RootSignatureDesc::write(raw_ostream &OS) const {
// Root signature header in dxcontainer has 6 uint_32t values.
const uint32_t HeaderSize = 24;
const uint32_t ParameterByteSize = Parameters.size_in_bytes();
const uint32_t NumParametes = Parameters.size();
buffer_ostream Writer(OS);
const uint32_t NumParameters = Parameters.size();
const uint32_t Zero = 0;

// Writing header information
support::endian::write(OS, Header.Version, llvm::endianness::little);
support::endian::write(OS, NumParametes, llvm::endianness::little);
support::endian::write(OS, HeaderSize, llvm::endianness::little);
support::endian::write(Writer, Header.Version, llvm::endianness::little);
support::endian::write(Writer, NumParameters, llvm::endianness::little);

// Static samplers still not implemented
support::endian::write(OS, Zero, llvm::endianness::little);
support::endian::write(OS, ParameterByteSize + HeaderSize,
llvm::endianness::little);
uint32_t HeaderPoint;
setRewrite(Writer, HeaderPoint);

support::endian::write(OS, Header.Flags, llvm::endianness::little);
support::endian::write(Writer, Zero, llvm::endianness::little);
support::endian::write(Writer, Zero, llvm::endianness::little);
support::endian::write(Writer, Header.Flags, llvm::endianness::little);

uint32_t ParamsOffset =
HeaderSize + (3 * sizeof(uint32_t) * Parameters.size());
for (const dxbc::RootParameter &P : Parameters) {
support::endian::write(OS, P.ParameterType, llvm::endianness::little);
support::endian::write(OS, P.ShaderVisibility, llvm::endianness::little);
support::endian::write(OS, ParamsOffset, llvm::endianness::little);
rewriteOffset(Writer, HeaderPoint);

// Size of root parameter, removing the ParameterType and ShaderVisibility.
ParamsOffset += sizeof(dxbc::RootParameter) - 2 * sizeof(uint32_t);
SmallVector<uint32_t> ParamsOffset;
for (const auto &P : Parameters) {
support::endian::write(Writer, P.ParameterType, llvm::endianness::little);
support::endian::write(Writer, P.ShaderVisibility,
llvm::endianness::little);

uint32_t Offset;
setRewrite(Writer, Offset);

ParamsOffset.push_back(Offset);
}

for (const dxbc::RootParameter &P : Parameters) {
assert(NumParameters == ParamsOffset.size());
for (size_t I = 0; I < NumParameters; ++I) {
rewriteOffset(Writer, ParamsOffset[I]);
const auto &P = Parameters[I];

switch (P.ParameterType) {
case dxbc::RootParameterType::Constants32Bit: {
support::endian::write(OS, P.Constants.ShaderRegister,
support::endian::write(Writer, P.Constants.ShaderRegister,
llvm::endianness::little);
support::endian::write(OS, P.Constants.RegisterSpace,
support::endian::write(Writer, P.Constants.RegisterSpace,
llvm::endianness::little);
support::endian::write(OS, P.Constants.Num32BitValues,
support::endian::write(Writer, P.Constants.Num32BitValues,
llvm::endianness::little);
} break;
case dxbc::RootParameterType::Empty:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; DXC-NEXT: RootSignature:
; DXC-NEXT: Version: 2
; DXC-NEXT: NumStaticSamplers: 0
; DXC-NEXT: StaticSamplersOffset: 24
; DXC-NEXT: StaticSamplersOffset: 0
; DXC-NEXT: Parameters: []
; DXC-NEXT: AllowInputAssemblerInputLayout: true
2 changes: 1 addition & 1 deletion llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Parts:
# CHECK-NEXT: RootSignature:
# CHECK-NEXT: Version: 2
# CHECK-NEXT: NumStaticSamplers: 0
# CHECK-NEXT: StaticSamplersOffset: 24
# CHECK-NEXT: StaticSamplersOffset: 0
# CHECK-NEXT: Parameters: []
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
# CHECK-NEXT: DenyGeometryShaderRootAccess: true
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Parts:
# CHECK-NEXT: RootSignature:
# CHECK-NEXT: Version: 2
# CHECK-NEXT: NumStaticSamplers: 0
# CHECK-NEXT: StaticSamplersOffset: 64
# CHECK-NEXT: StaticSamplersOffset: 0
# CHECK-NEXT: Parameters:
# CHECK-NEXT: - ParameterType: Constants32Bit
# CHECK-NEXT: ShaderVisibility: Hull
Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ TEST(RootSignature, ParseRootFlags) {
)"));

uint8_t Buffer[] = {
0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};

EXPECT_EQ(Storage.size(), 68u);
Expand Down Expand Up @@ -184,7 +184,7 @@ TEST(RootSignature, ParseRootConstants) {
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down