-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[DXIL] Adding support to RootSignatureFlags in obj2yaml #122396
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 27 commits
8adb678
ba78f21
0a54559
557075f
e0d3dcd
80587dd
be3764d
7582ca6
6aaa0a5
916b2f1
d9bce0a
e7676ed
a0cee57
1e7a1fe
0ed658a
932062e
628937c
1378c9f
e3206c9
f93d42d
25e3f37
751cbdc
44532d6
ca21878
987901c
0fbe900
b771aea
74f7226
69f581a
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,8 @@ | |||||
#define LLVM_BINARYFORMAT_DXCONTAINER_H | ||||||
|
||||||
#include "llvm/ADT/StringRef.h" | ||||||
#include "llvm/Support/BinaryStreamError.h" | ||||||
#include "llvm/Support/Error.h" | ||||||
#include "llvm/Support/SwapByteOrder.h" | ||||||
#include "llvm/TargetParser/Triple.h" | ||||||
|
||||||
|
@@ -152,6 +154,11 @@ enum class FeatureFlags : uint64_t { | |||||
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63, | ||||||
"Shader flag bits exceed enum size."); | ||||||
|
||||||
#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num, | ||||||
enum class RootElementFlag : uint32_t { | ||||||
#include "DXContainerConstants.def" | ||||||
}; | ||||||
|
||||||
PartType parsePartType(StringRef S); | ||||||
|
||||||
struct VertexPSVInfo { | ||||||
|
@@ -541,6 +548,21 @@ struct ProgramSignatureElement { | |||||
static_assert(sizeof(ProgramSignatureElement) == 32, | ||||||
"ProgramSignatureElement is misaligned"); | ||||||
|
||||||
struct RootSignatureValidations { | ||||||
|
||||||
static Expected<uint32_t> validateRootFlag(uint32_t Flags) { | ||||||
if ((Flags & ~0x80000fff) != 0) | ||||||
return llvm::make_error<BinaryStreamError>("Invalid flag"); | ||||||
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.
Suggested change
|
||||||
return Flags; | ||||||
} | ||||||
|
||||||
static Expected<uint32_t> validateVersion(uint32_t Version) { | ||||||
if (Version < 1 || Version > 2) | ||||||
return llvm::make_error<BinaryStreamError>("Invalid Version"); | ||||||
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. What version is invalid?
Suggested change
|
||||||
return Version; | ||||||
} | ||||||
}; | ||||||
|
||||||
} // namespace dxbc | ||||||
} // namespace llvm | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===- llvm/MC/DXContainerRootSignature.h - RootSignature -*- C++ -*- ========// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <cstdint> | ||
#include <limits> | ||
|
||
namespace llvm { | ||
|
||
class raw_ostream; | ||
|
||
namespace mcdxbc { | ||
struct RootSignatureHeader { | ||
uint32_t Version = 2; | ||
uint32_t NumParameters = 0; | ||
uint32_t RootParametersOffset = 0; | ||
uint32_t NumStaticSamplers = 0; | ||
uint32_t StaticSamplersOffset = 0; | ||
uint32_t Flags = 0; | ||
|
||
void write(raw_ostream &OS); | ||
}; | ||
} // namespace mcdxbc | ||
} // namespace llvm |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===- llvm/MC/DXContainerRootSignature.cpp - RootSignature -*- C++ -*-=======// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/MC/DXContainerRootSignature.h" | ||
#include "llvm/Support/EndianStream.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::mcdxbc; | ||
|
||
void RootSignatureHeader::write(raw_ostream &OS) { | ||
|
||
support::endian::write(OS, Version, llvm::endianness::little); | ||
support::endian::write(OS, NumParameters, llvm::endianness::little); | ||
support::endian::write(OS, RootParametersOffset, llvm::endianness::little); | ||
support::endian::write(OS, NumStaticSamplers, llvm::endianness::little); | ||
support::endian::write(OS, StaticSamplersOffset, llvm::endianness::little); | ||
support::endian::write(OS, Flags, llvm::endianness::little); | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ | |||||||||||
#include "llvm/BinaryFormat/DXContainer.h" | ||||||||||||
#include "llvm/Object/Error.h" | ||||||||||||
#include "llvm/Support/Alignment.h" | ||||||||||||
#include "llvm/Support/Endian.h" | ||||||||||||
#include "llvm/Support/FormatVariadic.h" | ||||||||||||
|
||||||||||||
using namespace llvm; | ||||||||||||
|
@@ -92,6 +93,15 @@ Error DXContainer::parseHash(StringRef Part) { | |||||||||||
return Error::success(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Error DXContainer::parseRootSignature(StringRef Part) { | ||||||||||||
if (RootSignature) | ||||||||||||
return parseFailed("More than one RTS0 part is present in the file"); | ||||||||||||
RootSignature = DirectX::RootSignature(); | ||||||||||||
if (Error Err = RootSignature->parse(Part)) | ||||||||||||
return Err; | ||||||||||||
return Error::success(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
Error DXContainer::parsePSVInfo(StringRef Part) { | ||||||||||||
if (PSVInfo) | ||||||||||||
return parseFailed("More than one PSV0 part is present in the file"); | ||||||||||||
|
@@ -193,6 +203,10 @@ Error DXContainer::parsePartOffsets() { | |||||||||||
break; | ||||||||||||
case dxbc::PartType::Unknown: | ||||||||||||
break; | ||||||||||||
case dxbc::PartType::RTS0: | ||||||||||||
if (Error Err = parseRootSignature(PartData)) | ||||||||||||
return Err; | ||||||||||||
break; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
|
@@ -228,6 +242,53 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) { | |||||||||||
IteratorState.Offset = Offset; | ||||||||||||
} | ||||||||||||
|
||||||||||||
Error DirectX::RootSignature::parse(StringRef Data) { | ||||||||||||
const char *Current = Data.begin(); | ||||||||||||
|
||||||||||||
// Root Signature headers expects 6 integers to be present. | ||||||||||||
if (Data.size() < 6 * sizeof(uint32_t)) { | ||||||||||||
return parseFailed("Invalid data. Too small."); | ||||||||||||
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. The error here should probably be more descriptive. Imagine having a tool print this error? Without context it doesn't really tell you what went wrong. Maybe something more like "Invalid root signature, insufficient space for header." |
||||||||||||
} | ||||||||||||
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.
Suggested change
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. Missed that, thanks |
||||||||||||
|
||||||||||||
uint32_t VValue = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
Expected<uint32_t> MaybeVersion = | ||||||||||||
dxbc::RootSignatureValidations::validateVersion(VValue); | ||||||||||||
if (Error E = MaybeVersion.takeError()) | ||||||||||||
return E; | ||||||||||||
Version = MaybeVersion.get(); | ||||||||||||
|
||||||||||||
NumParameters = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
RootParametersOffset = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
NumStaticSamplers = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
StaticSamplersOffset = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
uint32_t FValue = | ||||||||||||
support::endian::read<uint32_t, llvm::endianness::little>(Current); | ||||||||||||
Current += sizeof(uint32_t); | ||||||||||||
|
||||||||||||
Expected<uint32_t> MaybeFlag = | ||||||||||||
dxbc::RootSignatureValidations::validateRootFlag(FValue); | ||||||||||||
if (Error E = MaybeFlag.takeError()) | ||||||||||||
return E; | ||||||||||||
Flags = MaybeFlag.get(); | ||||||||||||
|
||||||||||||
return Error::success(); | ||||||||||||
damyanp marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
} | ||||||||||||
|
||||||||||||
Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) { | ||||||||||||
Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(ShaderKind); | ||||||||||||
|
||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.