Skip to content

Commit 6cef567

Browse files
author
joaosaffran
committed
adding tests and fixing code
1 parent d747bcc commit 6cef567

File tree

8 files changed

+45
-26
lines changed

8 files changed

+45
-26
lines changed

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ struct RootSignatureDesc {
2525

2626
uint32_t Version = 2U;
2727
uint32_t Flags = 0U;
28+
uint32_t RootParameterOffset = 0U;
29+
uint32_t StaticSamplersOffset = 0u;
30+
uint32_t NumStaticSamplers = 0u;
2831
SmallVector<mcdxbc::RootParameter> Parameters;
2932

3033
void write(raw_ostream &OS) const;

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
4848
BOS.reserveExtraSpace(getSize());
4949

5050
const uint32_t NumParameters = Parameters.size();
51-
const uint32_t StaticSamplerOffset = 0u;
52-
const uint32_t NumStaticSamplers = 0u;
5351

5452
support::endian::write(BOS, Version, llvm::endianness::little);
5553
support::endian::write(BOS, NumParameters, llvm::endianness::little);
56-
support::endian::write(BOS, (uint32_t)sizeof(dxbc::RootSignatureHeader),
57-
llvm::endianness::little);
58-
support::endian::write(BOS, StaticSamplerOffset, llvm::endianness::little);
54+
support::endian::write(BOS, RootParameterOffset, llvm::endianness::little);
5955
support::endian::write(BOS, NumStaticSamplers, llvm::endianness::little);
56+
support::endian::write(BOS, StaticSamplersOffset, llvm::endianness::little);
6057
support::endian::write(BOS, Flags, llvm::endianness::little);
6158

6259
SmallVector<uint32_t> ParamsOffsets;

llvm/lib/ObjectYAML/DXContainerEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
270270
mcdxbc::RootSignatureDesc RS;
271271
RS.Flags = P.RootSignature->getEncodedFlags();
272272
RS.Version = P.RootSignature->Version;
273+
RS.RootParameterOffset = P.RootSignature->RootParametersOffset;
274+
RS.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
275+
RS.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
276+
273277
for (const auto &Param : P.RootSignature->Parameters) {
274278
mcdxbc::RootParameter NewParam;
275279
NewParam.Header = dxbc::RootParameterHeader{

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
2323
; DXC-NEXT: RootSignature:
2424
; DXC-NEXT: Version: 2
2525
; DXC-NEXT: NumRootParameters: 0
26-
; DXC-NEXT: RootParametersOffset: 24
26+
; DXC-NEXT: RootParametersOffset: 0
2727
; DXC-NEXT: NumStaticSamplers: 0
2828
; DXC-NEXT: StaticSamplersOffset: 0
2929
; DXC-NEXT: Parameters: []

llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Parts:
1616
Version: 2
1717
NumRootParameters: 0
1818
RootParametersOffset: 24
19-
NumStaticSamplers: 4
20-
StaticSamplersOffset: 5
19+
NumStaticSamplers: 0
20+
StaticSamplersOffset: 12
2121
Parameters: []
2222
AllowInputAssemblerInputLayout: true
2323
DenyGeometryShaderRootAccess: true
@@ -29,7 +29,7 @@ Parts:
2929
# CHECK-NEXT: NumRootParameters: 0
3030
# CHECK-NEXT: RootParametersOffset: 24
3131
# CHECK-NEXT: NumStaticSamplers: 0
32-
# CHECK-NEXT: StaticSamplersOffset: 0
32+
# CHECK-NEXT: StaticSamplersOffset: 12
3333
# CHECK-NEXT: Parameters: []
3434
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
3535
# CHECK-NEXT: DenyGeometryShaderRootAccess: true

llvm/test/ObjectYAML/DXContainer/RootSignature-MultipleParameters.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Parts:
1717
NumRootParameters: 2
1818
RootParametersOffset: 24
1919
NumStaticSamplers: 0
20-
StaticSamplersOffset: 64
20+
StaticSamplersOffset: 12
2121
Parameters:
2222
- ParameterType: 1 # Constants32Bit
2323
ShaderVisibility: 2 # Hull
@@ -41,7 +41,7 @@ Parts:
4141
# CHECK-NEXT: NumRootParameters: 2
4242
# CHECK-NEXT: RootParametersOffset: 24
4343
# CHECK-NEXT: NumStaticSamplers: 0
44-
# CHECK-NEXT: StaticSamplersOffset: 0
44+
# CHECK-NEXT: StaticSamplersOffset: 12
4545
# CHECK-NEXT: Parameters:
4646
# CHECK-NEXT: - ParameterType: 1
4747
# CHECK-NEXT: ShaderVisibility: 2

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/BinaryFormat/Magic.h"
1212
#include "llvm/ObjectYAML/DXContainerYAML.h"
1313
#include "llvm/ObjectYAML/yaml2obj.h"
14+
#include "llvm/Support/Error.h"
1415
#include "llvm/Support/MemoryBufferRef.h"
1516
#include "llvm/Testing/Support/Error.h"
1617
#include "gtest/gtest.h"
@@ -824,38 +825,52 @@ TEST(DXCFile, MalformedSignature) {
824825

825826
TEST(RootSignature, MalformedData) {
826827
{
827-
// RootParametersOffset is 255.
828+
// Root Parameters offset has changed to 36, additional padding was added,
829+
// as well as fixing the parameter offset.
828830
uint8_t Buffer[] = {
829831
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
830832
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
831833
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
832834
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
833-
0x01, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
835-
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
835+
0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
836+
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
838+
0x02, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
836839
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837840
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
838841
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
839842
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
840843
0x00};
844+
841845
DXContainer C =
842-
llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
846+
llvm::cantFail(DXContainer::create(getMemoryBuffer<144>(Buffer)));
843847

844848
auto MaybeRS = C.getRootSignature();
845849
ASSERT_TRUE(MaybeRS.has_value());
846850
const auto &RS = MaybeRS.value();
847851
ASSERT_EQ(RS.getVersion(), 2u);
848852
ASSERT_EQ(RS.getNumParameters(), 1u);
849-
ASSERT_EQ(RS.getRootParametersOffset(), 255u);
853+
ASSERT_EQ(RS.getRootParametersOffset(), 36u);
850854
ASSERT_EQ(RS.getNumStaticSamplers(), 0u);
851855
ASSERT_EQ(RS.getStaticSamplersOffset(), 44u);
852856
ASSERT_EQ(RS.getFlags(), 17u);
853857

854-
// Since the offset is wrong, the data becomes invalid.
855858
auto RootParam = *RS.param_headers().begin();
859+
ASSERT_EQ((unsigned)RootParam.ParameterType, 1u);
860+
ASSERT_EQ((unsigned)RootParam.ShaderVisibility, 2u);
856861
auto ParamView = RS.getParameter(RootParam);
857-
ASSERT_THAT_ERROR(ParamView.takeError(),
858-
FailedWithMessage("invalid parameter type"));
862+
ASSERT_THAT_ERROR(ParamView.takeError(), Succeeded());
863+
864+
DirectX::RootConstantView *RootConstantsView =
865+
dyn_cast<DirectX::RootConstantView>(&*ParamView);
866+
ASSERT_TRUE(RootConstantsView != nullptr);
867+
auto Constants = RootConstantsView->read();
868+
869+
ASSERT_THAT_ERROR(Constants.takeError(), Succeeded());
870+
871+
ASSERT_EQ(Constants->ShaderRegister, 15u);
872+
ASSERT_EQ(Constants->RegisterSpace, 14u);
873+
ASSERT_EQ(Constants->Num32BitValues, 16u);
859874
}
860875
}
861876

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ TEST(RootSignature, ParseRootFlags) {
148148
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 68u) == 0);
149149
}
150150

151-
TEST(RootSignature, MalformedData) {
151+
TEST(RootSignature, HeaderData) {
152152
SmallString<128> Storage;
153153

154154
// First read a fully explicit yaml with all sizes and offsets provided
@@ -170,7 +170,7 @@ TEST(RootSignature, MalformedData) {
170170
NumRootParameters: 1
171171
RootParametersOffset: 255
172172
NumStaticSamplers: 0
173-
StaticSamplersOffset: 56
173+
StaticSamplersOffset: 0
174174
Parameters:
175175
- ParameterType: 1
176176
ShaderVisibility: 2
@@ -187,7 +187,7 @@ TEST(RootSignature, MalformedData) {
187187
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
188188
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
189189
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
190-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190+
0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191191
0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
192192
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
193193
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -220,9 +220,9 @@ TEST(RootSignature, ParseRootConstants) {
220220
RootSignature:
221221
Version: 2
222222
NumRootParameters: 1
223-
RootParametersOffset: 24
223+
RootParametersOffset: 36
224224
NumStaticSamplers: 0
225-
StaticSamplersOffset: 56
225+
StaticSamplersOffset: 0
226226
Parameters:
227227
- ParameterType: 1
228228
ShaderVisibility: 2
@@ -239,7 +239,7 @@ TEST(RootSignature, ParseRootConstants) {
239239
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
240240
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
241241
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
242-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242+
0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243243
0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
244244
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
245245
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0 commit comments

Comments
 (0)