Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion include/dxc/HlslIntrinsicOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ enum class IntrinsicOp {
IOP_VkReadClock = 223,
IOP_Vkext_execution_mode = 224,
IOP_Vkext_execution_mode_id = 225,
IOP_Vkreinterpret_pointer_cast = 360,
IOP_Vkstatic_pointer_cast = 361,
MOP_GetBufferContents = 362,
MOP_Append = 226,
MOP_RestartStrip = 227,
MOP_CalculateLevelOfDetail = 228,
Expand Down Expand Up @@ -366,7 +369,7 @@ enum class IntrinsicOp {
IOP_usign = 355,
MOP_InterlockedUMax = 356,
MOP_InterlockedUMin = 357,
Num_Intrinsics = 360,
Num_Intrinsics = 363,
};
inline bool HasUnsignedIntrinsicOpcode(IntrinsicOp opcode) {
switch (opcode) {
Expand Down
8 changes: 7 additions & 1 deletion include/dxc/dxcapi.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// //
// Provides non-public declarations for the DirectX Compiler component. //
// //
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
// All rights reserved. //
// //
///////////////////////////////////////////////////////////////////////////////

#ifndef __DXC_API_INTERNAL__
Expand Down Expand Up @@ -35,6 +38,7 @@ typedef struct ID3D10Blob ID3D10Blob;
static const BYTE INTRIN_TEMPLATE_FROM_TYPE = 0xff;
static const BYTE INTRIN_TEMPLATE_VARARGS = 0xfe;
static const BYTE INTRIN_TEMPLATE_FROM_FUNCTION = 0xfd;
static const BYTE INTRIN_TEMPLATE_FROM_FUNCTION_2 = 0xfc;

// Use this enumeration to describe allowed templates (layouts) in intrinsics.
enum LEGAL_INTRINSIC_TEMPLATES {
Expand Down Expand Up @@ -128,7 +132,9 @@ enum LEGAL_INTRINSIC_COMPTYPES {

LICOMPTYPE_HIT_OBJECT = 51,

LICOMPTYPE_COUNT = 52
LICOMPTYPE_VK_BUFFER_POINTER = 52,

LICOMPTYPE_COUNT = 53
};

static const BYTE IA_SPECIAL_BASE = 0xf0;
Expand Down
9 changes: 9 additions & 0 deletions lib/HLSL/HLOperationLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// //
// Lower functions to lower HL operations to DXIL operations. //
// //
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
// All rights reserved. //
// //
///////////////////////////////////////////////////////////////////////////////

#define _USE_MATH_DEFINES
Expand Down Expand Up @@ -6818,6 +6821,12 @@ IntrinsicLower gLowerTable[] = {
{IntrinsicOp::IOP_DxMaybeReorderThread, TranslateMaybeReorderThread,
DXIL::OpCode::NumOpCodes_Dxil_1_8}, // FIXME: Just a placeholder Dxil
// opcode
{IntrinsicOp::IOP_Vkstatic_pointer_cast, UnsupportedVulkanIntrinsic,
DXIL::OpCode::NumOpCodes},
{IntrinsicOp::IOP_Vkreinterpret_pointer_cast, UnsupportedVulkanIntrinsic,
DXIL::OpCode::NumOpCodes},
{IntrinsicOp::MOP_GetBufferContents, UnsupportedVulkanIntrinsic,
DXIL::OpCode::NumOpCodes},
};
} // namespace
static_assert(
Expand Down
33 changes: 32 additions & 1 deletion tools/clang/include/clang/AST/HlslTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
// All rights reserved. //
// //
///
/// \file //
/// \brief Defines the HLSL type system interface. //
Expand All @@ -31,6 +34,7 @@
namespace clang {
class ASTContext;
class AttributeList;
class CXXConstructorDecl;
class CXXMethodDecl;
class CXXRecordDecl;
class ClassTemplateDecl;
Expand Down Expand Up @@ -402,6 +406,10 @@ DeclareNodeOrRecordType(clang::ASTContext &Ctx, DXIL::NodeIOKind Type,
bool IsCompleteType = false);

#ifdef ENABLE_SPIRV_CODEGEN
clang::CXXRecordDecl *
DeclareVkBufferPointerType(clang::ASTContext &context,
clang::DeclContext *declContext);

clang::CXXRecordDecl *DeclareInlineSpirvType(clang::ASTContext &context,
clang::DeclContext *declContext,
llvm::StringRef typeName,
Expand All @@ -427,7 +435,7 @@ clang::VarDecl *DeclareBuiltinGlobal(llvm::StringRef name, clang::QualType Ty,
/// method.</summary> <param name="context">AST context in which to
/// work.</param> <param name="recordDecl">Class in which the function template
/// is declared.</param> <param name="functionDecl">Function for which a
/// template is created.</params> <param
/// template is created.</param> <param
/// name="templateParamNamedDecls">Declarations for templates to the
/// function.</param> <param name="templateParamNamedDeclsCount">Count of
/// template declarations.</param> <returns>A new function template declaration
Expand Down Expand Up @@ -533,6 +541,29 @@ bool DoesTypeDefineOverloadedOperator(clang::QualType typeWithOperator,
clang::QualType paramType);
bool IsPatchConstantFunctionDecl(const clang::FunctionDecl *FD);

#ifdef ENABLE_SPIRV_CODEGEN
bool IsVKBufferPointerType(clang::QualType type);
clang::QualType GetVKBufferPointerBufferType(clang::QualType type);
unsigned GetVKBufferPointerAlignment(clang::QualType type);
#endif

/// <summary>Adds a constructor declaration to the specified class
/// record.</summary> <param name="context">ASTContext that owns
/// declarations.</param> <param name="recordDecl">Record declaration in which
/// to add constructor.</param> <param name="resultType">Result type for
/// constructor.</param> <param name="paramTypes">Types for constructor
/// parameters.</param> <param name="paramNames">Names for constructor
/// parameters.</param> <param name="declarationName">Name for
/// constructor.</param> <param name="isConst">Whether the constructor is a
/// const function.</param> <returns>The method declaration for the
/// constructor.</returns>
Comment on lines +550 to +559
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
Is doxygen still generatable? (Couldn't make it work).
If no, might be more readable to have a normal comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but I did it that way for consistency with the rest of the file. Let me know if you still want it changed.

clang::CXXConstructorDecl *CreateConstructorDeclarationWithParams(
clang::ASTContext &context, clang::CXXRecordDecl *recordDecl,
clang::QualType resultType, llvm::ArrayRef<clang::QualType> paramTypes,
llvm::ArrayRef<clang::StringRef> paramNames,
clang::DeclarationName declarationName, bool isConst,
bool isTemplateFunction = false);

/// <summary>Adds a function declaration to the specified class
/// record.</summary> <param name="context">ASTContext that owns
/// declarations.</param> <param name="recordDecl">Record declaration in which
Expand Down
5 changes: 5 additions & 0 deletions tools/clang/include/clang/AST/OperationKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//
//
// This file enumerates the different kinds of operations that can be
Expand Down Expand Up @@ -321,6 +324,8 @@ enum CastKind {
CK_HLSLCC_FloatingToIntegral,
CK_HLSLCC_FloatingToBoolean,
CK_HLSLCC_FloatingCast,
CK_VK_BufferPointerToIntegral,
CK_VK_IntegralToBufferPointer,

// HLSL Change - Made CK_Invalid an enum case because otherwise it is UB to
// assign it to a value of CastKind.
Expand Down
17 changes: 17 additions & 0 deletions tools/clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//

class DocumentationCategory<string name> {
Expand Down Expand Up @@ -1440,6 +1443,20 @@ def VKStorageClassExt : InheritableAttr {
let Documentation = [Undocumented];
}

def VKBufferPointer : InheritableAttr {
let Spellings = [CXX11<"", "hlsl_vk_buffer_pointer", 2021>];
let LangOpts = [SPIRV];
let Documentation = [Undocumented];
}

def VKAliasedPointer : InheritableAttr {
let Spellings = [CXX11<"vk", "aliased_pointer">];
let Subjects = SubjectList<[Var, ParmVar], ErrorDiag>;
let Args = [];
let LangOpts = [SPIRV];
let Documentation = [Undocumented];
}

// Global variables that are of struct type
def StructGlobalVar : SubsetSubject<Var, [{S->hasGlobalStorage() && S->getType()->isStructureType()}]>;

Expand Down
9 changes: 8 additions & 1 deletion tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -7838,7 +7841,7 @@ def warn_hlsl_intrinsic_in_wrong_shader_model : Warning<
"intrinsic %0 potentially used by '%1' requires shader model %2 or greater">,
DefaultError, InGroup<HLSLAvailability>;
def warn_hlsl_intrinsic_overload_in_wrong_shader_model : Warning<
"overload of intrinsic %0 requires shader model %1 or greater">,
"overload of intrinsic %0 requires shader model %1 or greater">,
DefaultError, InGroup<HLSLAvailability>;
def err_hlsl_intrinsic_template_arg_unsupported: Error<
"Explicit template arguments on intrinsic %0 are not supported">;
Expand Down Expand Up @@ -8004,6 +8007,10 @@ def err_hlsl_hitobject_unsupported_stage : Error<

// SPIRV Change Starts
def err_hlsl_vulkan_specific_feature: Error<"%0 is a Vulkan specific feature">;
def err_hlsl_vk_pointer_cast_alignment: Error<
"Vulkan buffer pointer cannot be cast to greater alignment">;
def err_hlsl_vk_static_pointer_cast_type: Error<
"vk::static_pointer_cast() content type must be base class of argument's content type">;
// SPIRV Change Ends

let CategoryName = "OpenMP Issue" in {
Expand Down
11 changes: 11 additions & 0 deletions tools/clang/include/clang/SPIRV/SpirvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SPIRV_SPIRVBUILDER_H
#define LLVM_CLANG_SPIRV_SPIRVBUILDER_H
Expand Down Expand Up @@ -273,6 +276,14 @@ class SpirvBuilder {
SpirvInstruction *sample,
SourceLocation);

/// \brief Creates an OpConverPtrToU SPIR-V instruction with the given
/// parameters.
SpirvConvertPtrToU *createConvertPtrToU(SpirvInstruction *ptr, QualType type);

/// \brief Creates an OpConverUToPtr SPIR-V instruction with the given
/// parameters.
SpirvConvertUToPtr *createConvertUToPtr(SpirvInstruction *val, QualType type);

/// \brief Creates SPIR-V instructions for sampling the given image.
///
/// If compareVal is given a non-zero value, *Dref* variants of OpImageSample*
Expand Down
12 changes: 12 additions & 0 deletions tools/clang/include/clang/SPIRV/SpirvContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SPIRV_SPIRVCONTEXT_H
#define LLVM_CLANG_SPIRV_SPIRVCONTEXT_H
Expand Down Expand Up @@ -317,6 +320,13 @@ class SpirvContext {

const HybridPointerType *getPointerType(QualType pointee, spv::StorageClass);

const ForwardPointerType *getForwardPointerType(QualType pointee);

const SpirvPointerType *getForwardReference(QualType type);

void registerForwardReference(QualType type,
const SpirvPointerType *pointerType);

/// Generates (or reuses an existing) OpString for the given string literal.
SpirvString *getSpirvString(llvm::StringRef str);

Expand Down Expand Up @@ -478,6 +488,8 @@ class SpirvContext {
llvm::SmallVector<const HybridStructType *, 8> hybridStructTypes;
llvm::DenseMap<const SpirvType *, SCToPtrTyMap> pointerTypes;
llvm::SmallVector<const HybridPointerType *, 8> hybridPointerTypes;
llvm::MapVector<QualType, const ForwardPointerType *> forwardPointerTypes;
llvm::MapVector<QualType, const SpirvPointerType *> forwardReferences;
llvm::DenseSet<FunctionType *, FunctionTypeMapInfo> functionTypes;
llvm::DenseMap<unsigned, SpirvIntrinsicType *> spirvIntrinsicTypesById;
llvm::SmallVector<const SpirvIntrinsicType *, 8> spirvIntrinsicTypes;
Expand Down
52 changes: 52 additions & 0 deletions tools/clang/include/clang/SPIRV/SpirvInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SPIRV_SPIRVINSTRUCTION_H
#define LLVM_CLANG_SPIRV_SPIRVINSTRUCTION_H
Expand Down Expand Up @@ -67,6 +71,10 @@ class SpirvInstruction {
IK_ConstantComposite,
IK_ConstantNull,

// Pointer <-> uint conversions.
IK_ConvertPtrToU,
IK_ConvertUToPtr,

// OpUndef
IK_Undef,

Expand Down Expand Up @@ -1306,6 +1314,50 @@ class SpirvConstantNull : public SpirvConstant {
bool operator==(const SpirvConstantNull &that) const;
};

class SpirvConvertPtrToU : public SpirvInstruction {
public:
SpirvConvertPtrToU(SpirvInstruction *ptr, QualType type,
SourceLocation loc = {}, SourceRange range = {});

DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvConvertPtrToU)

// For LLVM-style RTTI
static bool classof(const SpirvInstruction *inst) {
return inst->getKind() == IK_ConvertPtrToU;
}

bool operator==(const SpirvConvertPtrToU &that) const;

bool invokeVisitor(Visitor *v) override;

SpirvInstruction *getPtr() const { return ptr; }

private:
SpirvInstruction *ptr;
};

class SpirvConvertUToPtr : public SpirvInstruction {
public:
SpirvConvertUToPtr(SpirvInstruction *intValue, QualType type,
SourceLocation loc = {}, SourceRange range = {});

DEFINE_RELEASE_MEMORY_FOR_CLASS(SpirvConvertUToPtr)

// For LLVM-style RTTI
static bool classof(const SpirvInstruction *inst) {
return inst->getKind() == IK_ConvertUToPtr;
}

bool operator==(const SpirvConvertUToPtr &that) const;

bool invokeVisitor(Visitor *v) override;

SpirvInstruction *getVal() const { return val; }

private:
SpirvInstruction *val;
};

class SpirvUndef : public SpirvInstruction {
public:
SpirvUndef(QualType type);
Expand Down
24 changes: 24 additions & 0 deletions tools/clang/include/clang/SPIRV/SpirvType.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
// All rights reserved.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_SPIRV_SPIRVTYPE_H
#define LLVM_CLANG_SPIRV_SPIRVTYPE_H
Expand Down Expand Up @@ -53,6 +56,7 @@ class SpirvType {
TK_RuntimeArray,
TK_Struct,
TK_Pointer,
TK_ForwardPointer,
TK_Function,
TK_AccelerationStructureNV,
TK_RayQueryKHR,
Expand Down Expand Up @@ -387,6 +391,26 @@ class SpirvPointerType : public SpirvType {
spv::StorageClass storageClass;
};

/// Represents a SPIR-V forwarding pointer type.
class ForwardPointerType : public SpirvType {
public:
ForwardPointerType(QualType pointee)
: SpirvType(TK_ForwardPointer), pointeeType(pointee) {}

static bool classof(const SpirvType *t) {
return t->getKind() == TK_ForwardPointer;
}

const QualType getPointeeType() const { return pointeeType; }

bool operator==(const ForwardPointerType &that) const {
return pointeeType == that.pointeeType;
}

private:
const QualType pointeeType;
};

/// Represents a SPIR-V function type. None of the parameters nor the return
/// type is allowed to be a hybrid type.
class FunctionType : public SpirvType {
Expand Down
Loading