Skip to content

Commit

Permalink
Revert "[DX] Add support for PSV signature elements"
Browse files Browse the repository at this point in the history
This reverts commit 8c567e6.
  • Loading branch information
llvm-beanz committed Aug 16, 2023
1 parent 8c567e6 commit 4d80063
Show file tree
Hide file tree
Showing 31 changed files with 122 additions and 813 deletions.
52 changes: 1 addition & 51 deletions llvm/include/llvm/BinaryFormat/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <stdint.h>

namespace llvm {
template <typename T> struct EnumEntry;

// The DXContainer file format is arranged as a header and "parts". Semantically
// parts are similar to sections in other object file formats. The File format
Expand Down Expand Up @@ -274,27 +273,6 @@ static_assert(sizeof(PipelinePSVInfo) == 4 * sizeof(uint32_t),

namespace PSV {

#define SEMANTIC_KIND(Val, Enum) Enum = Val,
enum class SemanticKind : uint8_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<SemanticKind>> getSemanticKinds();

#define COMPONENT_TYPE(Val, Enum) Enum = Val,
enum class ComponentType : uint8_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<ComponentType>> getComponentTypes();

#define INTERPOLATION_MODE(Val, Enum) Enum = Val,
enum class InterpolationMode : uint8_t {
#include "DXContainerConstants.def"
};

ArrayRef<EnumEntry<InterpolationMode>> getInterpolationModes();

namespace v0 {
struct RuntimeInfo {
PipelinePSVInfo StageInfo;
Expand Down Expand Up @@ -324,34 +302,6 @@ struct ResourceBindInfo {
}
};

struct SignatureElement {
uint32_t NameOffset;
uint32_t IndicesOffset;

uint8_t Rows;
uint8_t StartRow;
uint8_t Cols : 4;
uint8_t StartCol : 2;
uint8_t Allocated : 1;
uint8_t Unused : 1;
SemanticKind Kind;

ComponentType Type;
InterpolationMode Mode;
uint8_t DynamicMask : 4;
uint8_t Stream : 2;
uint8_t Unused2 : 2;
uint8_t Reserved;

void swapBytes() {
sys::swapByteOrder(NameOffset);
sys::swapByteOrder(IndicesOffset);
}
};

static_assert(sizeof(SignatureElement) == 4 * sizeof(uint32_t),
"PSV Signature elements must fit in 16 bytes.");

} // namespace v0

namespace v1 {
Expand All @@ -376,7 +326,7 @@ struct RuntimeInfo : public v0::RuntimeInfo {
// PSVSignatureElement counts
uint8_t SigInputElements;
uint8_t SigOutputElements;
uint8_t SigPatchOrPrimElements;
uint8_t SigPatchConstOrPrimElements;

// Number of packed vectors per signature
uint8_t SigInputVectors;
Expand Down
69 changes: 0 additions & 69 deletions llvm/include/llvm/BinaryFormat/DXContainerConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,72 +46,3 @@ SHADER_FLAG(31, NextUnusedBit, "Next reserved shader flag bit (not a flag)")

#undef SHADER_FLAG
#endif

#ifdef SEMANTIC_KIND

SEMANTIC_KIND(0, Arbitrary)
SEMANTIC_KIND(1, VertexID)
SEMANTIC_KIND(2, InstanceID)
SEMANTIC_KIND(3, Position)
SEMANTIC_KIND(4, RenderTargetArrayIndex)
SEMANTIC_KIND(5, ViewPortArrayIndex)
SEMANTIC_KIND(6, ClipDistance)
SEMANTIC_KIND(7, CullDistance)
SEMANTIC_KIND(8, OutputControlPointID)
SEMANTIC_KIND(9, DomainLocation)
SEMANTIC_KIND(10, PrimitiveID)
SEMANTIC_KIND(11, GSInstanceID)
SEMANTIC_KIND(12, SampleIndex)
SEMANTIC_KIND(13, IsFrontFace)
SEMANTIC_KIND(14, Coverage)
SEMANTIC_KIND(15, InnerCoverage)
SEMANTIC_KIND(16, Target)
SEMANTIC_KIND(17, Depth)
SEMANTIC_KIND(18, DepthLessEqual)
SEMANTIC_KIND(19, DepthGreaterEqual)
SEMANTIC_KIND(20, StencilRef)
SEMANTIC_KIND(21, DispatchThreadID)
SEMANTIC_KIND(22, GroupID)
SEMANTIC_KIND(23, GroupIndex)
SEMANTIC_KIND(24, GroupThreadID)
SEMANTIC_KIND(25, TessFactor)
SEMANTIC_KIND(26, InsideTessFactor)
SEMANTIC_KIND(27, ViewID)
SEMANTIC_KIND(28, Barycentrics)
SEMANTIC_KIND(29, ShadingRate)
SEMANTIC_KIND(30, CullPrimitive)
SEMANTIC_KIND(30, Invalid)

#undef SEMANTIC_KIND
#endif

#ifdef COMPONENT_TYPE

COMPONENT_TYPE(0, Unknown)
COMPONENT_TYPE(1, UInt32)
COMPONENT_TYPE(2, SInt32)
COMPONENT_TYPE(3, Float32)
COMPONENT_TYPE(4, UInt16)
COMPONENT_TYPE(5, SInt16)
COMPONENT_TYPE(6, Float16)
COMPONENT_TYPE(7, UInt64)
COMPONENT_TYPE(8, SInt64)
COMPONENT_TYPE(9, Float64)

#undef COMPONENT_TYPE
#endif

#ifdef INTERPOLATION_MODE

INTERPOLATION_MODE(0, Undefined)
INTERPOLATION_MODE(1, Constant)
INTERPOLATION_MODE(2, Linear)
INTERPOLATION_MODE(3, LinearCentroid)
INTERPOLATION_MODE(4, LinearNoperspective)
INTERPOLATION_MODE(5, LinearNoperspectiveCentroid)
INTERPOLATION_MODE(6, LinearSample)
INTERPOLATION_MODE(7, LinearNoperspectiveSample)
INTERPOLATION_MODE(8, Invalid)

#undef INTERPOLATION_MODE
#endif
33 changes: 3 additions & 30 deletions llvm/include/llvm/MC/DXContainerPSVInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,35 @@
#ifndef LLVM_MC_DXCONTAINERPSVINFO_H
#define LLVM_MC_DXCONTAINERPSVINFO_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/TargetParser/Triple.h"

#include <numeric>
#include <stdint.h>
#include <vector>

namespace llvm {

class raw_ostream;

namespace mcdxbc {

struct PSVSignatureElement {
StringRef Name;
SmallVector<uint32_t> Indices;
uint8_t StartRow;
uint8_t Cols;
uint8_t StartCol;
bool Allocated;
dxbc::PSV::SemanticKind Kind;
dxbc::PSV::ComponentType Type;
dxbc::PSV::InterpolationMode Mode;
uint8_t DynamicMask;
uint8_t Stream;
};

// This data structure is a helper for reading and writing PSV RuntimeInfo data.
// It is implemented in the BinaryFormat library so that it can be used by both
// the MC layer and Object tools.
// This structure is used to represent the extracted data in an inspectable and
// modifiable format, and can be used to serialize the data back into valid PSV
// RuntimeInfo.
struct PSVRuntimeInfo {
bool IsFinalized = false;
dxbc::PSV::v2::RuntimeInfo BaseData;
SmallVector<dxbc::PSV::v2::ResourceBindInfo> Resources;
SmallVector<PSVSignatureElement> InputElements;
SmallVector<PSVSignatureElement> OutputElements;
SmallVector<PSVSignatureElement> PatchOrPrimElements;
std::vector<dxbc::PSV::v2::ResourceBindInfo> Resources;

// Serialize PSVInfo into the provided raw_ostream. The version field
// specifies the data version to encode, the default value specifies encoding
// the highest supported version.
void write(raw_ostream &OS,
uint32_t Version = std::numeric_limits<uint32_t>::max()) const;

void finalize(Triple::EnvironmentType Stage) {
IsFinalized = true;
BaseData.SigInputElements = static_cast<uint32_t>(InputElements.size());
BaseData.SigOutputElements = static_cast<uint32_t>(OutputElements.size());
BaseData.SigPatchOrPrimElements =
static_cast<uint32_t>(PatchOrPrimElements.size());
if (!sys::IsBigEndianHost)
return;
void swapBytes(Triple::EnvironmentType Stage) {
BaseData.swapBytes();
BaseData.swapBytes(Stage);
for (auto &Res : Resources)
Expand Down
3 changes: 1 addition & 2 deletions llvm/include/llvm/MC/StringTableBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class StringTableBuilder {
MachO64Linked,
RAW,
DWARF,
XCOFF,
DXContainer
XCOFF
};

private:
Expand Down
38 changes: 6 additions & 32 deletions llvm/include/llvm/Object/DXContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class PSVRuntimeInfo {
// data is little-endian encoded and may not be properly aligned to read
// directly from. The dereference operator creates a copy of the data and byte
// swaps it as appropriate.
template <typename T> struct ViewArray {
struct ResourceArray {
StringRef Data;
uint32_t Stride; // size of each element in the list.

ViewArray() = default;
ViewArray(StringRef D, size_t S) : Data(D), Stride(S) {}
ResourceArray() = default;
ResourceArray(StringRef D, size_t S) : Data(D), Stride(S) {}

using value_type = T;
using value_type = dxbc::PSV::v2::ResourceBindInfo;
static constexpr uint32_t MaxStride() {
return static_cast<uint32_t>(sizeof(value_type));
}
Expand All @@ -50,16 +50,15 @@ class PSVRuntimeInfo {
uint32_t Stride; // size of each element in the list.
const char *Current;

iterator(const ViewArray &A, const char *C)
iterator(const ResourceArray &A, const char *C)
: Data(A.Data), Stride(A.Stride), Current(C) {}
iterator(const iterator &) = default;

value_type operator*() {
// Explicitly zero the structure so that unused fields are zeroed. It is
// up to the user to know if the fields are used by verifying the PSV
// version.
value_type Val;
std::memset(&Val, 0, sizeof(value_type));
value_type Val = {{0, 0, 0, 0}, 0, 0};
if (Current >= Data.end())
return Val;
memcpy(static_cast<void *>(&Val), Current,
Expand Down Expand Up @@ -104,21 +103,13 @@ class PSVRuntimeInfo {
size_t size() const { return Data.size() / Stride; }
};

using ResourceArray = ViewArray<dxbc::PSV::v2::ResourceBindInfo>;
using SigElementArray = ViewArray<dxbc::PSV::v0::SignatureElement>;

StringRef Data;
uint32_t Size;
using InfoStruct =
std::variant<std::monostate, dxbc::PSV::v0::RuntimeInfo,
dxbc::PSV::v1::RuntimeInfo, dxbc::PSV::v2::RuntimeInfo>;
InfoStruct BasicInfo;
ResourceArray Resources;
StringRef StringTable;
SmallVector<uint32_t> SemanticIndexTable;
SigElementArray SigInputElements;
SigElementArray SigOutputElements;
SigElementArray SigPatchOrPrimElements;

public:
PSVRuntimeInfo(StringRef D) : Data(D), Size(0) {}
Expand All @@ -139,23 +130,6 @@ class PSVRuntimeInfo {
uint32_t getResourceStride() const { return Resources.Stride; }

const InfoStruct &getInfo() const { return BasicInfo; }

StringRef getStringTable() const { return StringTable; }
ArrayRef<uint32_t> getSemanticIndexTable() const {
return SemanticIndexTable;
}

uint8_t getSigInputCount() const;
uint8_t getSigOutputCount() const;
uint8_t getSigPatchOrPrimCount() const;

SigElementArray getSigInputElements() const { return SigInputElements; }
SigElementArray getSigOutputElements() const { return SigOutputElements; }
SigElementArray getSigPatchOrPrimElements() const {
return SigPatchOrPrimElements;
}

uint32_t getSigElementStride() const { return SigInputElements.Stride; }
};

} // namespace DirectX
Expand Down
41 changes: 1 addition & 40 deletions llvm/include/llvm/ObjectYAML/DXContainerYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,6 @@ struct ShaderHash {

using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo;

struct SignatureElement {
SignatureElement() = default;

SignatureElement(dxbc::PSV::v0::SignatureElement El, StringRef StringTable,
ArrayRef<uint32_t> IdxTable)
: Name(StringTable.substr(El.NameOffset,
StringTable.find('\0', El.NameOffset) -
El.NameOffset)),
Indices(IdxTable.slice(El.IndicesOffset, El.Rows)),
StartRow(El.StartRow), Cols(El.Cols), StartCol(El.StartCol),
Allocated(El.Allocated != 0), Kind(El.Kind), Type(El.Type),
Mode(El.Mode), DynamicMask(El.DynamicMask), Stream(El.Stream) {}
StringRef Name;
SmallVector<uint32_t> Indices;

uint8_t StartRow;
uint8_t Cols;
uint8_t StartCol;
bool Allocated;
dxbc::PSV::SemanticKind Kind;

dxbc::PSV::ComponentType Type;
dxbc::PSV::InterpolationMode Mode;
llvm::yaml::Hex8 DynamicMask;
uint8_t Stream;
};

struct PSVInfo {
// The version field isn't actually encoded in the file, but it is inferred by
// the size of data regions. We include it in the yaml because it simplifies
Expand All @@ -108,10 +81,7 @@ struct PSVInfo {

dxbc::PSV::v2::RuntimeInfo Info;
uint32_t ResourceStride;
SmallVector<ResourceBindInfo> Resources;
SmallVector<SignatureElement> SigInputElements;
SmallVector<SignatureElement> SigOutputElements;
SmallVector<SignatureElement> SigPatchOrPrimElements;
std::vector<ResourceBindInfo> Resources;

void mapInfoForVersion(yaml::IO &IO);

Expand Down Expand Up @@ -142,11 +112,6 @@ struct Object {

LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::Part)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::ResourceBindInfo)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DXContainerYAML::SignatureElement)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::SemanticKind)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::ComponentType)
LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::dxbc::PSV::InterpolationMode)

namespace llvm {

class raw_ostream;
Expand Down Expand Up @@ -189,10 +154,6 @@ template <> struct MappingTraits<DXContainerYAML::ResourceBindInfo> {
static void mapping(IO &IO, DXContainerYAML::ResourceBindInfo &Res);
};

template <> struct MappingTraits<DXContainerYAML::SignatureElement> {
static void mapping(IO &IO, llvm::DXContainerYAML::SignatureElement &El);
};

} // namespace yaml

} // namespace llvm
Expand Down

0 comments on commit 4d80063

Please sign in to comment.