-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[DirectX] adding support in obj2yaml and yaml2obj to root constants #127840
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
Changes from 123 commits
526b34a
e84a8e1
f25fd64
16552f0
a6eb4c0
7d080b3
504527b
2425672
08c17bb
395a536
f93dff9
1c1edb8
5bef775
628545a
c5c2ab6
b9db72c
f4af043
496b922
422578f
b1423eb
b6262b6
16d0e8e
0a9e468
8295031
c8e1e38
434b862
2bfc5ad
479422d
f61ee77
499d879
c4af535
819fa0d
d347a87
d8824ed
25c0384
5eb0ad2
559427d
8ca5b2a
d52cd2c
5930dcb
fc72988
2d1ee0d
92a85fe
979ee91
d089674
980e7d9
04667f3
8ec40aa
b0ac6be
6a36503
f7d2c12
d6c98ed
36746f5
b5208e8
1fd6568
cde4634
4410e7b
cbdb114
667ee17
d0dae8b
b1b28f8
0efd8cc
11256d8
3c5046e
5d4505c
3117530
0af845c
bf49a3a
78826a5
4e689e9
b0d0180
3c6894f
08f6ddc
b232967
1026a8e
00175bf
9ed2adc
e8252ba
4de5c29
fe13b61
767b7d0
8434dc2
d391727
68c7513
23069ab
d14471b
216341c
85f012c
1e2bcf5
0e277d9
5cd0044
7a7c34d
d3fafab
15d1a8c
7485640
17abc82
4b177e2
ec1dd87
eb9d7d3
f2a4f04
7c4236c
2894f96
7b5e9d8
f0e6a46
4fe30df
cbc334a
31bcd73
30098e1
1bf6408
d1b32f3
3b9bf27
89632a4
67da709
3991c5d
cfc6bfb
82a31fa
e6865a7
021976d
102ff4b
39d4b08
7343d95
6986945
c0ac522
8511fa9
330369a
d747bcc
6cef567
246d5d3
bb6c0cf
7885eed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ | |||||
#include "llvm/ADT/SmallVector.h" | ||||||
#include "llvm/ADT/StringRef.h" | ||||||
#include "llvm/BinaryFormat/DXContainer.h" | ||||||
#include "llvm/Object/Error.h" | ||||||
#include "llvm/Support/Error.h" | ||||||
#include "llvm/Support/MemoryBufferRef.h" | ||||||
#include "llvm/TargetParser/Triple.h" | ||||||
|
@@ -116,6 +117,39 @@ template <typename T> struct ViewArray { | |||||
}; | ||||||
|
||||||
namespace DirectX { | ||||||
struct RootParameterView { | ||||||
const dxbc::RootParameterHeader &Header; | ||||||
StringRef ParamData; | ||||||
RootParameterView(const dxbc::RootParameterHeader &H, StringRef P) | ||||||
: Header(H), ParamData(P) {} | ||||||
|
||||||
template <typename T> Expected<T> readParameter() { | ||||||
T Struct; | ||||||
if (sizeof(T) != ParamData.size()) | ||||||
return make_error<GenericBinaryError>( | ||||||
"Reading structure out of file bounds", object_error::parse_failed); | ||||||
|
||||||
memcpy(&Struct, ParamData.data(), sizeof(T)); | ||||||
// DXContainer is always little endian | ||||||
if (sys::IsBigEndianHost) | ||||||
Struct.swapBytes(); | ||||||
return Struct; | ||||||
} | ||||||
}; | ||||||
|
||||||
struct RootConstantView : RootParameterView { | ||||||
static bool classof(const RootParameterView *V) { | ||||||
return V->Header.ParameterType == dxbc::RootParameterType::Constants32Bit; | ||||||
} | ||||||
|
||||||
llvm::Expected<dxbc::RootConstants> read() { | ||||||
return readParameter<dxbc::RootConstants>(); | ||||||
} | ||||||
}; | ||||||
|
||||||
static Error parseFailed(const Twine &Msg) { | ||||||
return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed); | ||||||
} | ||||||
|
||||||
class RootSignature { | ||||||
private: | ||||||
|
@@ -125,17 +159,46 @@ class RootSignature { | |||||
uint32_t NumStaticSamplers; | ||||||
uint32_t StaticSamplersOffset; | ||||||
uint32_t Flags; | ||||||
ViewArray<dxbc::RootParameterHeader> ParametersHeaders; | ||||||
StringRef PartData; | ||||||
|
||||||
using param_header_iterator = ViewArray<dxbc::RootParameterHeader>::iterator; | ||||||
|
||||||
public: | ||||||
RootSignature() {} | ||||||
RootSignature(StringRef PD) : PartData(PD) {} | ||||||
|
||||||
Error parse(StringRef Data); | ||||||
Error parse(); | ||||||
uint32_t getVersion() const { return Version; } | ||||||
uint32_t getNumParameters() const { return NumParameters; } | ||||||
uint32_t getRootParametersOffset() const { return RootParametersOffset; } | ||||||
uint32_t getNumStaticSamplers() const { return NumStaticSamplers; } | ||||||
uint32_t getStaticSamplersOffset() const { return StaticSamplersOffset; } | ||||||
uint32_t getNumRootParameters() const { return ParametersHeaders.size(); } | ||||||
llvm::iterator_range<param_header_iterator> param_headers() const { | ||||||
return llvm::make_range(ParametersHeaders.begin(), ParametersHeaders.end()); | ||||||
} | ||||||
uint32_t getFlags() const { return Flags; } | ||||||
|
||||||
llvm::Expected<RootParameterView> | ||||||
getParameter(const dxbc::RootParameterHeader &Header) const { | ||||||
size_t DataSize; | ||||||
|
||||||
switch (Header.ParameterType) { | ||||||
case dxbc::RootParameterType::Constants32Bit: | ||||||
DataSize = sizeof(dxbc::RootConstants); | ||||||
break; | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a bit of an awkard problem here if the value of Here is a place where using a fully covered switch is a bit awkward, since we allow values outside of our enum values since We'll either need to do some silly stuff with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've converted |
||||||
auto EndOfSectionByte = getNumStaticSamplers() == 0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size_t is clearer here.
Suggested change
|
||||||
? PartData.size() | ||||||
: getStaticSamplersOffset(); | ||||||
|
||||||
if (Header.ParameterOffset + DataSize > EndOfSectionByte) | ||||||
return parseFailed("Reading structure out of file bounds"); | ||||||
|
||||||
StringRef Buff = PartData.substr(Header.ParameterOffset, DataSize); | ||||||
RootParameterView View = RootParameterView(Header, Buff); | ||||||
return View; | ||||||
} | ||||||
}; | ||||||
|
||||||
class PSVRuntimeInfo { | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.