Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Basic/TypeTraits.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"

#include <algorithm>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGHLSLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "clang/AST/Type.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
#include "llvm/Frontend/HLSL/RootSignatureMetadata.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalVariable.h"
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
#include "llvm/Frontend/HLSL/RootSignatureValidations.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/ErrorHandling.h"
Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DXILABI.h"
#include "llvm/Support/raw_ostream.h"
#include <limits>
#include <variant>

Expand Down Expand Up @@ -135,6 +136,21 @@ using RootElement =
std::variant<dxbc::RootFlags, RootConstants, RootDescriptor,
DescriptorTable, DescriptorTableClause, StaticSampler>;

/// The following contains the serialization interface for root elements
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const RootConstants &Constants);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const DescriptorTableClause &Clause);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const RootDescriptor &Descriptor);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const StaticSampler &StaticSampler);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element);

LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);

} // namespace rootsig
} // namespace hlsl
} // namespace llvm
Expand Down
56 changes: 56 additions & 0 deletions llvm/include/llvm/Frontend/HLSL/RootSignatureMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//===- RootSignatureMetadata.h - HLSL Root Signature helpers --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file This file contains a library for working with HLSL Root Signatures and
/// their metadata representation.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H

#include "llvm/Frontend/HLSL/HLSLRootSignature.h"

namespace llvm {
class LLVMContext;
class MDNode;
class Metadata;

namespace hlsl {
namespace rootsig {

class MetadataBuilder {
public:
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
: Ctx(Ctx), Elements(Elements) {}

/// Iterates through the elements and dispatches onto the correct Build method
///
/// Accumulates the root signature and returns the Metadata node that is just
/// a list of all the elements
LLVM_ABI MDNode *BuildRootSignature();

private:
/// Define the various builders for the different metadata types
MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
MDNode *BuildRootConstants(const RootConstants &Constants);
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
MDNode *BuildStaticSampler(const StaticSampler &Sampler);

llvm::LLVMContext &Ctx;
ArrayRef<RootElement> Elements;
SmallVector<Metadata *> GeneratedMetadata;
};

} // namespace rootsig
} // namespace hlsl
} // namespace llvm

#endif // LLVM_FRONTEND_HLSL_ROOTSIGNATUREMETADATA_H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- HLSLRootSignatureUtils.h - HLSL Root Signature helpers -------------===//
//===- RootSignatureValidations.h - HLSL Root Signature helpers -----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -11,68 +11,16 @@
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
#ifndef LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H
#define LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"

namespace llvm {
class LLVMContext;
class MDNode;
class Metadata;

namespace hlsl {
namespace rootsig {

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const dxbc::RootFlags &Flags);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const RootConstants &Constants);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const DescriptorTableClause &Clause);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const RootDescriptor &Descriptor);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
const StaticSampler &StaticSampler);

LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element);

LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);

class MetadataBuilder {
public:
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
: Ctx(Ctx), Elements(Elements) {}

/// Iterates through the elements and dispatches onto the correct Build method
///
/// Accumulates the root signature and returns the Metadata node that is just
/// a list of all the elements
LLVM_ABI MDNode *BuildRootSignature();

private:
/// Define the various builders for the different metadata types
MDNode *BuildRootFlags(const dxbc::RootFlags &Flags);
MDNode *BuildRootConstants(const RootConstants &Constants);
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
MDNode *BuildStaticSampler(const StaticSampler &Sampler);

llvm::LLVMContext &Ctx;
ArrayRef<RootElement> Elements;
SmallVector<Metadata *> GeneratedMetadata;
};

struct RangeInfo {
const static uint32_t Unbounded = ~0u;

Expand All @@ -83,7 +31,7 @@ struct RangeInfo {
// Information retained for diagnostics
llvm::dxil::ResourceClass Class;
uint32_t Space;
dxbc::ShaderVisibility Visibility;
llvm::dxbc::ShaderVisibility Visibility;
};

class ResourceRange {
Expand All @@ -103,7 +51,7 @@ class ResourceRange {
getOverlapping(const RangeInfo &Info) const;

// Return the mapped RangeInfo at X or nullptr if no mapping exists
LLVM_ABI const RangeInfo *lookup(uint32_t X) const;
const RangeInfo *lookup(uint32_t X) const;

// Removes all entries of the ResourceRange
LLVM_ABI void clear();
Expand Down Expand Up @@ -141,4 +89,4 @@ class ResourceRange {
} // namespace hlsl
} // namespace llvm

#endif // LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
#endif // LLVM_FRONTEND_HLSL_ROOTSIGNATUREVALIDATIONS_H
4 changes: 3 additions & 1 deletion llvm/lib/Frontend/HLSL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_llvm_component_library(LLVMFrontendHLSL
CBuffer.cpp
HLSLResource.cpp
HLSLRootSignatureUtils.cpp
HLSLRootSignature.cpp
RootSignatureMetadata.cpp
RootSignatureValidations.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
Expand Down
Loading
Loading