Skip to content

Commit 7343d95

Browse files
author
joaosaffran
committed
adding more tests
1 parent 39d4b08 commit 7343d95

File tree

5 files changed

+55
-20
lines changed

5 files changed

+55
-20
lines changed

llvm/include/llvm/ObjectYAML/DXContainerYAML.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ struct RootParameterYamlDesc {
9292
};
9393

9494
struct RootSignatureYamlDesc {
95-
RootSignatureYamlDesc() = default;
96-
RootSignatureYamlDesc(const object::DirectX::RootSignature &Data);
97-
9895
uint32_t Version;
9996
uint32_t NumStaticSamplers;
10097
uint32_t StaticSamplersOffset;
@@ -107,7 +104,12 @@ struct RootSignatureYamlDesc {
107104
return make_range(Parameters.begin(), Parameters.end());
108105
}
109106

107+
static llvm::Expected<DXContainerYAML::RootSignatureYamlDesc>
108+
create(const object::DirectX::RootSignature &Data);
109+
110110
#include "llvm/BinaryFormat/DXContainerConstants.def"
111+
112+
RootSignatureYamlDesc() = default;
111113
};
112114

113115
using ResourceFlags = dxbc::PSV::ResourceFlags;

llvm/lib/ObjectYAML/DXContainerYAML.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#include "llvm/ObjectYAML/DXContainerYAML.h"
1515
#include "llvm/ADT/ScopeExit.h"
1616
#include "llvm/BinaryFormat/DXContainer.h"
17+
#include "llvm/Support/Error.h"
1718
#include "llvm/Support/ScopedPrinter.h"
19+
#include <utility>
1820

1921
namespace llvm {
2022

@@ -29,11 +31,16 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
2931
#include "llvm/BinaryFormat/DXContainerConstants.def"
3032
}
3133

32-
DXContainerYAML::RootSignatureYamlDesc::RootSignatureYamlDesc(
33-
const object::DirectX::RootSignature &Data)
34-
: Version(Data.getVersion()),
35-
NumStaticSamplers(Data.getNumStaticSamplers()),
36-
StaticSamplersOffset(Data.getStaticSamplersOffset()) {
34+
llvm::Expected<DXContainerYAML::RootSignatureYamlDesc>
35+
DXContainerYAML::RootSignatureYamlDesc::create(
36+
const object::DirectX::RootSignature &Data) {
37+
38+
RootSignatureYamlDesc RootSigDesc;
39+
40+
RootSigDesc.Version = Data.getVersion();
41+
RootSigDesc.NumStaticSamplers = Data.getNumStaticSamplers();
42+
RootSigDesc.StaticSamplersOffset = Data.getStaticSamplersOffset();
43+
3744
uint32_t Flags = Data.getFlags();
3845
for (const auto &PH : Data.param_headers()) {
3946

@@ -43,33 +50,29 @@ DXContainerYAML::RootSignatureYamlDesc::RootSignatureYamlDesc(
4350
llvm::Expected<dxbc::RootParameterType> TypeOrErr =
4451
dxbc::safeParseParameterType(PH.ParameterType);
4552
if (Error E = TypeOrErr.takeError()) {
46-
llvm::errs() << "Error: " << E << "\n";
47-
continue;
53+
return std::move(E);
4854
}
4955

5056
NewP.Type = TypeOrErr.get();
5157

5258
llvm::Expected<dxbc::ShaderVisibility> VisibilityOrErr =
5359
dxbc::safeParseShaderVisibility(PH.ShaderVisibility);
5460
if (Error E = VisibilityOrErr.takeError()) {
55-
llvm::errs() << "Error: " << E << "\n";
56-
continue;
61+
return std::move(E);
5762
}
5863
NewP.Visibility = VisibilityOrErr.get();
5964

6065
llvm::Expected<object::DirectX::RootParameterView> ParamViewOrErr =
6166
Data.getParameter(PH);
6267
if (Error E = ParamViewOrErr.takeError()) {
63-
llvm::errs() << "Error: " << E << "\n";
64-
continue;
68+
return std::move(E);
6569
}
6670
object::DirectX::RootParameterView ParamView = ParamViewOrErr.get();
6771

6872
if (auto *RCV = dyn_cast<object::DirectX::RootConstantView>(&ParamView)) {
6973
llvm::Expected<dxbc::RootConstants> ConstantsOrErr = RCV->read();
7074
if (Error E = ConstantsOrErr.takeError()) {
71-
llvm::errs() << "Error: " << E << "\n";
72-
continue;
75+
return std::move(E);
7376
}
7477

7578
auto Constants = *ConstantsOrErr;
@@ -78,11 +81,12 @@ DXContainerYAML::RootSignatureYamlDesc::RootSignatureYamlDesc(
7881
NewP.Constants.ShaderRegister = Constants.ShaderRegister;
7982
NewP.Constants.RegisterSpace = Constants.RegisterSpace;
8083
}
81-
Parameters.push_back(NewP);
84+
RootSigDesc.Parameters.push_back(NewP);
8285
}
8386
#define ROOT_ELEMENT_FLAG(Num, Val) \
84-
Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
87+
RootSigDesc.Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
8588
#include "llvm/BinaryFormat/DXContainerConstants.def"
89+
return RootSigDesc;
8690
}
8791

8892
uint32_t DXContainerYAML::RootSignatureYamlDesc::getEncodedFlags() {

llvm/tools/obj2yaml/dxcontainer2yaml.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,13 @@ dumpDXContainer(MemoryBufferRef Source) {
155155
break;
156156
case dxbc::PartType::RTS0:
157157
std::optional<DirectX::RootSignature> RS = Container.getRootSignature();
158-
if (RS.has_value())
159-
NewPart.RootSignature = DXContainerYAML::RootSignatureYamlDesc(*RS);
158+
if (RS.has_value()) {
159+
auto RootSigDescOrErr =
160+
DXContainerYAML::RootSignatureYamlDesc::create(*RS);
161+
if (Error E = RootSigDescOrErr.takeError())
162+
return std::move(E);
163+
NewPart.RootSignature = RootSigDescOrErr.get();
164+
}
160165
break;
161166
}
162167
}

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Object/DXContainer.h"
10+
#include "../../tools/obj2yaml/dxcontainer2yaml.cpp"
11+
#include "llvm/ADT/SmallString.h"
1012
#include "llvm/ADT/StringRef.h"
1113
#include "llvm/BinaryFormat/Magic.h"
1214
#include "llvm/ObjectYAML/DXContainerYAML.h"
1315
#include "llvm/ObjectYAML/yaml2obj.h"
1416
#include "llvm/Support/MemoryBufferRef.h"
1517
#include "llvm/Testing/Support/Error.h"
18+
#include "gmock/gmock.h"
1619
#include "gtest/gtest.h"
1720

1821
using namespace llvm;
@@ -907,4 +910,24 @@ TEST(RootSignature, ParseRootConstant) {
907910
ASSERT_EQ(Constants->RegisterSpace, 14u);
908911
ASSERT_EQ(Constants->Num32BitValues, 16u);
909912
}
913+
{
914+
uint8_t Buffer[] = {
915+
0x44, 0x58, 0x42, 0x43, 0x32, 0x9a, 0x53, 0xd8, 0xec, 0xbe, 0x35, 0x6f,
916+
0x05, 0x39, 0xe1, 0xfe, 0x31, 0x20, 0xf0, 0xc1, 0x01, 0x00, 0x00, 0x00,
917+
0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
918+
0x52, 0x54, 0x53, 0x30, 0x59, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
919+
0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
920+
0x2c, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
921+
0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00,
922+
0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
923+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
924+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
925+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
926+
0x00};
927+
928+
SmallString<256> Storage;
929+
raw_svector_ostream OS(Storage);
930+
EXPECT_THAT_ERROR(dxcontainer2yaml(OS, getMemoryBuffer<133>(Buffer)),
931+
FailedWithMessage("Invalid value for parameter type"));
932+
}
910933
}

llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "llvm/ADT/SmallString.h"
910
#include "llvm/ADT/StringRef.h"
1011
#include "llvm/ADT/Twine.h"
1112
#include "llvm/ObjectYAML/ObjectYAML.h"

0 commit comments

Comments
 (0)