Skip to content

Commit 89632a4

Browse files
author
joaosaffran
committed
removing validations from obj2yaml
1 parent 3b9bf27 commit 89632a4

File tree

5 files changed

+14
-187
lines changed

5 files changed

+14
-187
lines changed

llvm/include/llvm/BinaryFormat/RootSignatureVerifier.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

llvm/include/llvm/Object/DXContainer.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,14 @@ static Error parseFailed(const Twine &Msg) {
166166

167167
class RootSignature {
168168
private:
169-
uint32_t Version = 2;
170-
uint32_t NumParameters = 0;
171-
uint32_t RootParametersOffset = 0;
172-
uint32_t NumStaticSamplers = 0;
173-
uint32_t StaticSamplersOffset = 0;
174-
uint32_t Flags = 0;
175-
169+
uint32_t Version;
170+
uint32_t NumParameters;
171+
uint32_t RootParametersOffset;
172+
uint32_t NumStaticSamplers;
173+
uint32_t StaticSamplersOffset;
174+
uint32_t Flags;
176175
ViewArray<dxbc::RootParameterHeader> ParametersHeaders;
177-
size_t ParameterSpaceOffset;
176+
uint32_t ParameterSpaceOffset;
178177
StringRef ParameterSpace;
179178

180179
using param_header_iterator = ViewArray<dxbc::RootParameterHeader>::iterator;
@@ -199,9 +198,10 @@ class RootSignature {
199198

200199
llvm::Expected<RootParameterView>
201200
getParameter(const dxbc::RootParameterHeader &Header) const {
201+
assert(ParameterSpaceOffset != 0 &&
202+
"This should be initialized before reading parameters");
202203
size_t CorrectOffset = Header.ParameterOffset - ParameterSpaceOffset;
203204
StringRef Data;
204-
205205
size_t DataSize;
206206

207207
switch (Header.ParameterType) {
@@ -214,7 +214,6 @@ class RootSignature {
214214
return parseFailed("Reading structure out of file bounds");
215215

216216
Data = ParameterSpace.substr(CorrectOffset, DataSize);
217-
218217
RootParameterView View = RootParameterView(Header, Data);
219218
return View;
220219
}

llvm/lib/Object/DXContainer.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "llvm/Object/DXContainer.h"
1010
#include "llvm/BinaryFormat/DXContainer.h"
11-
#include "llvm/BinaryFormat/RootSignatureVerifier.h"
1211
#include "llvm/Object/Error.h"
1312
#include "llvm/Support/Alignment.h"
1413
#include "llvm/Support/Endian.h"
@@ -258,15 +257,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
258257
return parseFailed(
259258
"Invalid root signature, insufficient space for header.");
260259

261-
uint32_t VValue =
262-
support::endian::read<uint32_t, llvm::endianness::little>(Current);
260+
Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
263261
Current += sizeof(uint32_t);
264262

265-
if (!dxbc::RootSignatureVerifier::verifyVersion(VValue))
266-
return validationFailed("unsupported root signature version read: " +
267-
llvm::Twine(VValue));
268-
Version = VValue;
269-
270263
NumParameters =
271264
support::endian::read<uint32_t, llvm::endianness::little>(Current);
272265
Current += sizeof(uint32_t);
@@ -283,15 +276,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
283276
support::endian::read<uint32_t, llvm::endianness::little>(Current);
284277
Current += sizeof(uint32_t);
285278

286-
uint32_t FValue =
287-
support::endian::read<uint32_t, llvm::endianness::little>(Current);
279+
Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
288280
Current += sizeof(uint32_t);
289281

290-
if (!dxbc::RootSignatureVerifier::verifyRootFlag(FValue))
291-
return validationFailed("unsupported root signature flag value read: " +
292-
llvm::Twine(FValue));
293-
Flags = FValue;
294-
295282
assert(Current == Begin + RootParametersOffset);
296283

297284
ParametersHeaders.Data = Data.substr(
@@ -305,17 +292,6 @@ Error DirectX::RootSignature::parse(StringRef Data) {
305292
ParameterSpace = Data.substr(ParameterSpaceOffset,
306293
ParameterSpaceEnd - ParameterSpaceOffset);
307294

308-
for (auto P : param_header()) {
309-
310-
if (!dxbc::RootSignatureVerifier::verifyParameterType(P.ParameterType))
311-
return validationFailed("unsupported parameter type value read: " +
312-
llvm::Twine((uint32_t)P.ParameterType));
313-
314-
if (!dxbc::RootSignatureVerifier::verifyShaderVisibility(
315-
P.ShaderVisibility))
316-
return validationFailed("unsupported shader visility flag value read: " +
317-
llvm::Twine((uint32_t)P.ShaderVisibility));
318-
}
319295
return Error::success();
320296
}
321297

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/Twine.h"
1717
#include "llvm/Analysis/DXILMetadataAnalysis.h"
1818
#include "llvm/BinaryFormat/DXContainer.h"
19-
#include "llvm/BinaryFormat/RootSignatureVerifier.h"
2019
#include "llvm/IR/Constants.h"
2120
#include "llvm/IR/DiagnosticInfo.h"
2221
#include "llvm/IR/Function.h"
@@ -93,8 +92,10 @@ static bool parse(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
9392
return HasError;
9493
}
9594

95+
static bool verifyRootFlag(uint32_t Flags) { return (Flags & ~0xfff) == 0; }
96+
9697
static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
97-
if (!dxbc::RootSignatureVerifier::verifyRootFlag(RSD.Header.Flags)) {
98+
if (!verifyRootFlag(RSD.Header.Flags)) {
9899
return reportError(Ctx, "Invalid Root Signature flag value");
99100
}
100101
return false;

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -863,35 +863,6 @@ TEST(RootSignature, ParseRootFlags) {
863863
FailedWithMessage(
864864
"Invalid root signature, insufficient space for header."));
865865
}
866-
{
867-
// Version has been changed to an invalid number.
868-
uint8_t Buffer[] = {
869-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
870-
0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
871-
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
872-
0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
873-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
874-
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
875-
};
876-
EXPECT_THAT_EXPECTED(
877-
DXContainer::create(getMemoryBuffer<100>(Buffer)),
878-
FailedWithMessage("unsupported root signature version read: 3"));
879-
}
880-
{
881-
// Flag has been set to an invalid value
882-
uint8_t Buffer[] = {
883-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
884-
0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
885-
0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
886-
0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
887-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
888-
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
889-
};
890-
EXPECT_THAT_EXPECTED(
891-
DXContainer::create(getMemoryBuffer<100>(Buffer)),
892-
FailedWithMessage(
893-
"unsupported root signature flag value read: 4278190081"));
894-
}
895866
}
896867

897868
TEST(RootSignature, ParseRootConstant) {
@@ -939,69 +910,4 @@ TEST(RootSignature, ParseRootConstant) {
939910
ASSERT_EQ(Constants->Space, 14u);
940911
ASSERT_EQ(Constants->NumOfConstants, 16u);
941912
}
942-
{
943-
// ParameterType has been set to an invalid value
944-
uint8_t Buffer[] = {
945-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
946-
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
947-
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
948-
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
949-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
950-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
951-
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
952-
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
953-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
954-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
955-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
956-
0x00};
957-
EXPECT_THAT_EXPECTED(
958-
DXContainer::create(getMemoryBuffer<133>(Buffer)),
959-
FailedWithMessage("unsupported parameter type value read: 255"));
960-
}
961-
{
962-
// ShaderVisibility has been set to an invalid value
963-
uint8_t Buffer[] = {
964-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
965-
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
966-
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
967-
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
968-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
969-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
970-
0xFF, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
971-
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
972-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
973-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
974-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
975-
0x00};
976-
EXPECT_THAT_EXPECTED(
977-
DXContainer::create(getMemoryBuffer<133>(Buffer)),
978-
FailedWithMessage("unsupported shader visility flag value read: 255"));
979-
}
980-
{
981-
// Offset has been set to an invalid value
982-
uint8_t Buffer[] = {
983-
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
984-
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
985-
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
986-
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
987-
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
988-
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
989-
0x02, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
990-
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
991-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
992-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
993-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
994-
0x00};
995-
DXContainer C =
996-
llvm::cantFail(DXContainer::create(getMemoryBuffer<133>(Buffer)));
997-
998-
auto MaybeRS = C.getRootSignature();
999-
ASSERT_TRUE(MaybeRS.has_value());
1000-
const auto &RS = MaybeRS.value();
1001-
auto RootParam = *RS.param_header().begin();
1002-
auto ParamView = RS.getParameter(RootParam);
1003-
ASSERT_THAT_ERROR(
1004-
ParamView.takeError(),
1005-
FailedWithMessage("Reading structure out of file bounds"));
1006-
}
1007913
}

0 commit comments

Comments
 (0)