[clang] [llvm] [HLSL] Add support for dynamic resources (PR #221103)
Helena Kotas via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 14:52:14 PDT 2026
https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/221103
>From 3e70d41f6223c89dd318cdcf57be14c250eb3557 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 3 Sep 2026 13:02:10 -0700
Subject: [PATCH 01/10] [HLSL] Add support for dynamic resources
---
clang/include/clang/Basic/Builtins.td | 12 ++
.../clang/Sema/HLSLExternalSemaSource.h | 2 +
clang/lib/CodeGen/CGHLSLBuiltins.cpp | 22 +++
clang/lib/CodeGen/CGHLSLRuntime.h | 2 +
clang/lib/Headers/CMakeLists.txt | 1 +
clang/lib/Headers/hlsl.h | 1 +
clang/lib/Headers/hlsl/hlsl_resources.h | 36 +++++
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 68 +++++++++
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h | 3 +
clang/lib/Sema/HLSLExternalSemaSource.cpp | 27 ++++
clang/lib/Sema/SemaHLSL.cpp | 26 ++++
.../test/AST/HLSL/ByteAddressBuffers-AST.hlsl | 18 +++
clang/test/AST/HLSL/DynamicResources-AST.hlsl | 132 ++++++++++++++++++
.../test/AST/HLSL/StructuredBuffers-AST.hlsl | 27 ++++
clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 17 +++
.../resources/dynamic-resources.hlsl | 109 +++++++++++++++
clang/test/SemaHLSL/Language/InitLists.hlsl | 1 +
.../Textures-SampleCmpLevelZero.hlsl | 5 +-
.../dynamic-resources-availability.hlsl | 13 ++
.../SemaHLSL/Resources/dynamic-resources.hlsl | 50 +++++++
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 9 ++
21 files changed, 579 insertions(+), 2 deletions(-)
create mode 100644 clang/lib/Headers/hlsl/hlsl_resources.h
create mode 100644 clang/test/AST/HLSL/DynamicResources-AST.hlsl
create mode 100644 clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
create mode 100644 clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
create mode 100644 clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 49fe879c6add15..2b33b4a8541b32 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5431,6 +5431,18 @@ def HLSLResourceCounterHandleFromImplicitBinding : LangBuiltin<"HLSL_LANG"> {
let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t, uint32_t)";
}
+def HLSLResourceHandleFromHeap : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_resource_handlefromheap"];
+ let Attributes = [NoThrow];
+ let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t)";
+}
+
+def HLSLResourceCounterHandleFromHeap : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_resource_counterhandlefromheap"];
+ let Attributes = [NoThrow];
+ let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t)";
+}
+
def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_resource_nonuniformindex"];
let Attributes = [NoThrow];
diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 77fd3fafc6d771..840cd3e0a082aa 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -43,8 +43,10 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
private:
void defineTrivialHLSLTypes();
+ void defineInternalHLSLTypes();
void defineHLSLVectorAlias();
void defineHLSLMatrixAlias();
+ void defineHeapResourceInfoTypes();
void defineHLSLTypesWithForwardDeclarations();
void defineHLSLAtomicIntrinsics();
void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index 062faadcdcab27..42c107405dff3f 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -1063,6 +1063,28 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
return EmitIntrinsicCall(IntrinsicID, {HandleTy, MainHandle->getType()},
Args);
}
+ case Builtin::BI__builtin_hlsl_resource_handlefromheap: {
+ llvm::Type *HandleTy = CGM.getTypes().ConvertType(E->getType());
+ Value *IndexOp = EmitScalarExpr(E->getArg(1));
+ llvm::Intrinsic::ID IntrinsicID =
+ CGM.getHLSLRuntime().getCreateHandleFromHeapIntrinsic();
+ SmallVector<Value *> Args{IndexOp};
+ return Builder.CreateIntrinsic(HandleTy, IntrinsicID, Args);
+ }
+ case Builtin::BI__builtin_hlsl_resource_counterhandlefromheap: {
+ Value *MainHandle = EmitScalarExpr(E->getArg(0));
+ if (!CGM.getTriple().isSPIRV())
+ return MainHandle;
+
+ llvm::Type *HandleTy = CGM.getTypes().ConvertType(E->getType());
+ Value *IndexOp = EmitScalarExpr(E->getArg(1));
+ llvm::Intrinsic::ID IntrinsicID =
+ llvm::Intrinsic::spv_resource_counterhandlefromheap;
+ SmallVector<Value *> Args{MainHandle, IndexOp};
+ return EmitIntrinsicCall(IntrinsicID, {HandleTy, MainHandle->getType()},
+ Args);
+ }
+
case Builtin::BI__builtin_hlsl_resource_nonuniformindex: {
Value *IndexOp = EmitScalarExpr(E->getArg(0));
llvm::Type *RetTy = ConvertType(E->getType());
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 381653e8f83456..2ceafcc94a0b86 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -186,6 +186,8 @@ class CGHLSLRuntime {
resource_handlefrombinding)
GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromImplicitBinding,
resource_handlefromimplicitbinding)
+ GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromHeap,
+ resource_handlefromheap)
GENERATE_HLSL_INTRINSIC_FUNCTION(NonUniformResourceIndex,
resource_nonuniformindex)
GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, resource_updatecounter)
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 3d845423759acf..9befd7b192af7f 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -98,6 +98,7 @@ set(hlsl_subdir_files
hlsl/hlsl_intrinsic_helpers.h
hlsl/hlsl_intrinsics.h
hlsl/hlsl_detail.h
+ hlsl/hlsl_resources.h
hlsl/hlsl_spirv.h
)
set(hlsl_files
diff --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index 8a144191c46953..ff50c9f9b7ac21 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -26,6 +26,7 @@
#if __HLSL_VERSION <= __HLSL_202x
#include "hlsl/hlsl_compat_overloads.h"
#endif
+#include "hlsl/hlsl_resources.h"
#ifdef __spirv__
#include "hlsl/hlsl_spirv.h"
diff --git a/clang/lib/Headers/hlsl/hlsl_resources.h b/clang/lib/Headers/hlsl/hlsl_resources.h
new file mode 100644
index 00000000000000..d43c94dbff572e
--- /dev/null
+++ b/clang/lib/Headers/hlsl/hlsl_resources.h
@@ -0,0 +1,36 @@
+//===----- hlsl_resources.h - HLSL definitions for resources ----------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _HLSL_HLSL_RESOURCES_H_
+#define _HLSL_HLSL_RESOURCES_H_
+
+namespace hlsl {
+
+#define _HLSL_AVAILABILITY(platform, version) \
+ __attribute__((availability(platform, introduced = version)))
+
+struct __hlsl_resource_descriptor_heap_struct {
+ __hlsl_heap_resource_info operator[](uint32_t Index) {
+ return __hlsl_heap_resource_info{Index};
+ }
+};
+
+struct __hlsl_sampler_descriptor_heap_struct {
+ __hlsl_heap_sampler_info operator[](uint32_t Index) {
+ return __hlsl_heap_sampler_info{Index};
+ }
+};
+
+_HLSL_AVAILABILITY(shadermodel, 6.6)
+static __hlsl_resource_descriptor_heap_struct ResourceDescriptorHeap;
+
+_HLSL_AVAILABILITY(shadermodel, 6.6)
+static __hlsl_sampler_descriptor_heap_struct SamplerDescriptorHeap;
+
+} // namespace hlsl
+#endif //_HLSL_HLSL_RESOURCES_H_
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
index 34e883264b5b3c..15f78eadad4e2a 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -1216,6 +1216,74 @@ BuiltinTypeDeclBuilder::addDefaultHandleConstructor(AccessSpecifier Access) {
.finalize(Access);
}
+// Adds constructor that takes __hlsl_heap_resource_info:
+// Resource::Resource(__hlsl_heap_resource_info info) {
+// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
+// }
+BuiltinTypeDeclBuilder &
+BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
+ assert(!Record->isCompleteDefinition() && "record is already complete");
+
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+ ASTContext &AST = SemaRef.getASTContext();
+ QualType HandleType = getResourceHandleField()->getType();
+
+ QualType HeapResInfoType = lookupBuiltinType(
+ SemaRef, "__hlsl_heap_resource_info", Record->getDeclContext());
+ CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
+
+ FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
+ assert(IndexField && IndexField->getType() == AST.UnsignedIntTy &&
+ "Index field not as expected");
+
+ auto MB = BuiltinTypeMethodBuilder(*this, "", AST.VoidTy, false, true);
+ MB.addParam("HeapResInfo", HeapResInfoType)
+ .callBuiltin("__builtin_hlsl_resource_handlefromheap", HandleType,
+ PH::Handle, MB.createMemberExpr(PH::_0, IndexField))
+ .assign(PH::Handle, PH::LastStmt);
+
+ if (HasCounter) {
+ QualType CounterHandleType = getResourceCounterHandleField()->getType();
+ MB.callBuiltin("__builtin_hlsl_resource_counterhandlefromheap",
+ CounterHandleType, PH::Handle,
+ MB.createMemberExpr(PH::_0, IndexField))
+ .assign(PH::CounterHandle, PH::LastStmt);
+ }
+
+ return MB.finalize();
+}
+
+// Adds constructor that takes __hlsl_heap_sampler_info:
+// Resource::Resource(__hlsl_heap_sampler_info info) {
+// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
+// }
+BuiltinTypeDeclBuilder &
+BuiltinTypeDeclBuilder::addHeapSamplerInfoConstructor() {
+ assert(!Record->isCompleteDefinition() && "record is already complete");
+
+ using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+ ASTContext &AST = SemaRef.getASTContext();
+ QualType HandleType = getResourceHandleField()->getType();
+
+ QualType HeapResInfoType = lookupBuiltinType(
+ SemaRef, "__hlsl_heap_sampler_info", Record->getDeclContext());
+ CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
+
+ FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
+ assert(IndexField && IndexField->getType() == AST.UnsignedIntTy &&
+ "Index field not as expected");
+
+ auto MB = BuiltinTypeMethodBuilder(*this, "", AST.VoidTy, false, true);
+ MB.addParam("HeapResInfo", HeapResInfoType);
+ MB.callBuiltin("__builtin_hlsl_resource_handlefromheap", HandleType,
+ PH::Handle, MB.createMemberExpr(PH::_0, IndexField))
+ .assign(PH::Handle, PH::LastStmt);
+
+ return MB.finalize();
+}
+
BuiltinTypeDeclBuilder &
BuiltinTypeDeclBuilder::addStaticInitializationFunctions(bool HasCounter) {
if (HasCounter) {
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h
index 62dea7fab80647..226f1026876cae 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h
@@ -99,6 +99,9 @@ class BuiltinTypeDeclBuilder {
BuiltinTypeDeclBuilder &addDefaultHandleConstructor(
AccessSpecifier Access = AccessSpecifier::AS_public);
BuiltinTypeDeclBuilder &
+ addHeapResourceInfoConstructor(bool HasCounter = false);
+ BuiltinTypeDeclBuilder &addHeapSamplerInfoConstructor();
+ BuiltinTypeDeclBuilder &
addCopyConstructor(AccessSpecifier Access = AccessSpecifier::AS_public);
BuiltinTypeDeclBuilder &addCopyAssignmentOperator(
AccessSpecifier Access = AccessSpecifier::AS_public);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index d2d9c97b98a576..75932dc8a136e0 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -55,6 +55,7 @@ void HLSLExternalSemaSource::InitializeSema(Sema &S) {
// Force external decls in the HLSL namespace to load from the PCH.
(void)HLSLNamespace->getCanonicalDecl()->decls_begin();
defineTrivialHLSLTypes();
+ defineInternalHLSLTypes();
defineHLSLTypesWithForwardDeclarations();
defineHLSLAtomicIntrinsics();
@@ -233,6 +234,29 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
defineHLSLMatrixAlias();
}
+void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
+ ASTContext &AST = SemaPtr->getASTContext();
+ CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
+ "__hlsl_heap_resource_info")
+ .finalizeForwardDeclaration();
+ if (!ResDecl->isCompleteDefinition())
+ BuiltinTypeDeclBuilder(*SemaPtr, ResDecl)
+ .addMemberVariable("Index", AST.UnsignedIntTy, {})
+ .completeDefinition();
+
+ CXXRecordDecl *SampDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
+ "__hlsl_heap_sampler_info")
+ .finalizeForwardDeclaration();
+ if (!SampDecl->isCompleteDefinition())
+ BuiltinTypeDeclBuilder(*SemaPtr, SampDecl)
+ .addMemberVariable("Index", AST.UnsignedIntTy, {})
+ .completeDefinition();
+}
+
+void HLSLExternalSemaSource::defineInternalHLSLTypes() {
+ defineHeapResourceInfoTypes();
+}
+
/// Set up common members and attributes for buffer types
static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
ResourceClass RC, bool IsROV,
@@ -242,6 +266,7 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
.addDefaultHandleConstructor()
.addCopyConstructor()
.addCopyAssignmentOperator()
+ .addHeapResourceInfoConstructor(HasCounter)
.addStaticInitializationFunctions(HasCounter);
}
@@ -252,6 +277,7 @@ static BuiltinTypeDeclBuilder setupSamplerType(CXXRecordDecl *Decl, Sema &S) {
.addDefaultHandleConstructor()
.addCopyConstructor()
.addCopyAssignmentOperator()
+ .addHeapSamplerInfoConstructor()
.addStaticInitializationFunctions(false);
}
@@ -361,6 +387,7 @@ static BuiltinTypeDeclBuilder setupTextureType(CXXRecordDecl *Decl, Sema &S,
B.addDefaultHandleConstructor()
.addCopyConstructor()
.addCopyAssignmentOperator()
+ .addHeapResourceInfoConstructor()
.addStaticInitializationFunctions(false);
if (T.has(TexCap::Load))
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 06828b9ec7fc0a..7c64266d855de5 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -4397,9 +4397,35 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
}
case Builtin::BI__builtin_hlsl_resource_counterhandlefromimplicitbinding: {
assert(TheCall->getNumArgs() == 3 && "expected 3 args");
+ // Update return type to be the attributed resource type from arg0
+ // with added IsCounter flag.
QualType MainHandleTy = TheCall->getArg(0)->getType();
+ QualType CounterHandleTy =
+ createCounterHandleType(SemaRef.getASTContext(), MainHandleTy);
+ TheCall->setType(CounterHandleTy);
+ break;
+ }
+ case Builtin::BI__builtin_hlsl_resource_handlefromheap: {
+ if (SemaRef.checkArgCount(TheCall, 2) ||
+ CheckResourceHandle(&SemaRef, TheCall, 0) ||
+ CheckArgTypeMatches(&SemaRef, TheCall->getArg(1),
+ SemaRef.getASTContext().UnsignedIntTy))
+ return true;
+
+ // Update return type to be the attributed resource type from arg0.
+ QualType ResourceTy = TheCall->getArg(0)->getType();
+ TheCall->setType(ResourceTy);
+ break;
+ }
+ case Builtin::BI__builtin_hlsl_resource_counterhandlefromheap: {
+ if (SemaRef.checkArgCount(TheCall, 2) ||
+ CheckResourceHandle(&SemaRef, TheCall, 0) ||
+ CheckArgTypeMatches(&SemaRef, TheCall->getArg(1),
+ SemaRef.getASTContext().UnsignedIntTy))
+ return true;
// Update return type to be the attributed resource type from arg0
// with added IsCounter flag.
+ QualType MainHandleTy = TheCall->getArg(0)->getType();
QualType CounterHandleTy =
createCounterHandleType(SemaRef.getASTContext(), MainHandleTy);
TheCall->setType(CounterHandleTy);
diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
index d6d2aa0819e7b4..3312045cf4def8 100644
--- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
@@ -82,6 +82,24 @@ RESOURCE Buffer;
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this
// CHECK-NEXT: AlwaysInlineAttr
+// Heap info constructor
+
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]] 'void (hlsl::__hlsl_heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: BinaryOperator {{.*}} '='
+// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this
+// CHECK-NEXT: CallExpr {{.*}} '__hlsl_resource_t
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_resource_t (*)(__hlsl_resource_t, unsigned int) noexcept' <BuiltinFnToFnPtr>
+// CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromheap' '__hlsl_resource_t (__hlsl_resource_t, unsigned int) noexcept'
+// CHECK-NEXT: MemberExpr {{.*}} '__hlsl_resource_t {{.*}}' lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: AlwaysInlineAttr
+
// Static __createFromBinding method
// CHECK: CXXMethodDecl {{.*}} __createFromBinding 'hlsl::[[RESOURCE]] (unsigned int, unsigned int, int, unsigned int, const char *)' static
diff --git a/clang/test/AST/HLSL/DynamicResources-AST.hlsl b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
new file mode 100644
index 00000000000000..00d181388a9778
--- /dev/null
+++ b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
@@ -0,0 +1,132 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -ast-dump %s | FileCheck %s
+
+// Global variables for ResourceDescriptorHeap and SamplerDescriptorHeap
+// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __hlsl_resource_descriptor_heap_struct' static internal-linkage
+// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
+
+// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __hlsl_sampler_descriptor_heap_struct' static internal-linkage
+// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
+
+void useBuffer(RWBuffer<int> Buffer) {}
+
+// CHECK-LABEL: FunctionDecl {{.*}} testInvocations
+export void testInvocations(unsigned Index) {
+
+// Buf1 declaration with direct initialization
+// CHECK: VarDecl {{.*}} Buf1 'RWBuffer<int>':'hlsl::RWBuffer<int>' cinit
+// CHECK-NEXT: ExprWithCleanups{{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>'
+
+// RWBuffer copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+
+// __hlsl_heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
+
+// Buf2 declaration initialized with default constructor (handle is poison)
+// CHECK: VarDecl {{.*}} Buf2 'RWBuffer<int>':'hlsl::RWBuffer<int>' callinit
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void ()'
+
+// Buf2 assignment operator
+// CHECK-NEXT: ExprWithCleanups
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'hlsl::RWBuffer<int>' lvalue '='
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int> &(*)(const hlsl::RWBuffer<int> &)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)' lvalue CXXMethod {{.*}} 'operator=' 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' lvalue Var {{.*}} 'Buf2' 'RWBuffer<int>':'hlsl::RWBuffer<int>'
+
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+
+// __hlsl_heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ RWBuffer<int> Buf2;
+ Buf2 = ResourceDescriptorHeap[Index];
+
+// Call to useBuffer with a temporary RWBuffer constructed from ResourceDescriptorHeap[Index]
+// CHECK: CallExpr {{.*}} 'void'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(RWBuffer<int>)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'void (RWBuffer<int>)' lvalue Function {{.*}} 'useBuffer' 'void (RWBuffer<int>)'
+
+// RWBuffer copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+
+// __hlsl_heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ useBuffer(ResourceDescriptorHeap[Index]);
+
+// CHECK: VarDecl {{.*}} Sampler 'SamplerState' cinit
+// CHECK-NEXT: ExprWithCleanups {{.*}} 'SamplerState'
+
+// SamplerState copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:16, col:53> 'SamplerState' 'void (const hlsl::SamplerState &)' elidable
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'const SamplerState' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'const SamplerState' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'SamplerState' <ConstructorConversion>
+
+// SamplerState heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__hlsl_heap_sampler_info)'
+
+// __hlsl_heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__hlsl_heap_sampler_info' 'void (__hlsl_heap_sampler_info &&) noexcept' elidable
+
+// Indexing into SamplerDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> '__hlsl_heap_sampler_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> '__hlsl_heap_sampler_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> '__hlsl_heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> '__hlsl_heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_sampler_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__hlsl_sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __hlsl_sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __hlsl_sampler_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:48> 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:48> 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+}
diff --git a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
index 6b38b73d823214..eb858cd51cdb60 100644
--- a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
@@ -139,6 +139,33 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: AlwaysInlineAttr
+// Heap info constructor
+
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__hlsl_heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: BinaryOperator {{.*}} '='
+// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-NEXT: CStyleCastExpr {{.*}} '__hlsl_resource_t
+// CHECK-NEXT: CallExpr {{.*}} '<dependent type>'
+// CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromheap' '__hlsl_resource_t (__hlsl_resource_t, unsigned int) noexcept'
+// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-COUNTER-HANDLE-NEXT: BinaryOperator {{.*}} '='
+// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} lvalue .__counter_handle
+// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-COUNTER-HANDLE-NEXT: CStyleCastExpr {{.*}} '__hlsl_resource_t
+// CHECK-COUNTER-HANDLE-NEXT: CallExpr {{.*}} '<dependent type>'
+// CHECK-COUNTER-HANDLE-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_counterhandlefromheap' '__hlsl_resource_t (__hlsl_resource_t, unsigned int) noexcept'
+// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
+// CHECK-COUNTER-HANDLE-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: AlwaysInlineAttr
+
// Static __createFromBinding method
// CHECK-BINDING: CXXMethodDecl {{.*}} __createFromBinding 'hlsl::[[RESOURCE]]<element_type> (unsigned int, unsigned int, int, unsigned int, const char *)' static
diff --git a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
index a2708e0782beff..667486b34e84fa 100644
--- a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
@@ -104,6 +104,23 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: AlwaysInlineAttr
+// Heap info constructor
+
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__hlsl_heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: BinaryOperator {{.*}} '='
+// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-NEXT: CStyleCastExpr {{.*}} '__hlsl_resource_t
+// CHECK-NEXT: CallExpr {{.*}} '<dependent type>'
+// CHECK-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_handlefromheap' '__hlsl_resource_t (__hlsl_resource_t, unsigned int) noexcept'
+// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
+// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
+// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: AlwaysInlineAttr
+
// Static __createFromBinding method
// CHECK: CXXMethodDecl {{.*}} __createFromBinding 'hlsl::[[RESOURCE]]<element_type> (unsigned int, unsigned int, int, unsigned int, const char *)' static
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
new file mode 100644
index 00000000000000..02d641fdeef5f6
--- /dev/null
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library \
+// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,DXIL
+// RUN: %clang_cc1 -finclude-default-header -triple spirv-vulkan-library \
+// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,SPV
+
+// CHECK: %S = type <{ i32 }>
+
+// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__hlsl_resource_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__hlsl_sampler_descriptor_heap_struct" zeroinitializer, align 1
+
+// CHECK-LABEL: testTypedBuffer
+export void testTypedBuffer(unsigned Index) {
+// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+
+// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__hlsl_heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]])
+ RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
+}
+
+struct S {
+ int Value;
+};
+
+// CHECK-LABEL: testConstantBuffer
+export void testConstantBuffer(unsigned Index) {
+
+// CHECK: %CBS = alloca %"class.hlsl::ConstantBuffer"
+// CHECK: [[TMP1:%.*]] = alloca %"class.hlsl::ConstantBuffer"
+// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer()(ptr {{.*}} %CBS)
+
+// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP2]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP2]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__hlsl_heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 %{{.*}})
+
+// CHECK: call {{.*}} ptr @hlsl::ConstantBuffer<S>::operator=(hlsl::ConstantBuffer<S> const&)
+// CHECK-SAME: (ptr {{.*}} %CBS, ptr {{.*}} [[TMP1]])
+ ConstantBuffer<S> CBS;
+ CBS = ResourceDescriptorHeap[Index];
+}
+
+// CHECK: define {{(spir_func )*}}void @testSampler(unsigned int)(ptr {{.*}} sret(%"class.hlsl::SamplerState") align {{(4|8)}} [[RESULT:%.*]], i32 noundef %Index)
+// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__hlsl_heap_sampler_info"
+export SamplerState testSampler(unsigned Index) {
+
+// DXIL: call void @hlsl::__hlsl_sampler_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]],
+// DXIL-SAME: ptr {{.*}} @hlsl::SamplerDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__hlsl_sampler_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::SamplerDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__hlsl_heap_sampler_info)
+// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]])
+ return SamplerDescriptorHeap[Index];
+}
+
+void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
+ Buffer.Append(1);
+}
+
+// CHECK-LABEL: testCounterBuffer
+export void testCounterBuffer(unsigned Index) {
+// CHECK: [[TMP_BUFFER:%.*]] = alloca %"class.hlsl::AppendStructuredBuffer"
+// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+
+// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__hlsl_heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]])
+
+// CHECK: call {{(spir_func )*}}void @useAppendBuffer(hlsl::AppendStructuredBuffer<int>, int)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], i32 noundef 10)
+ useAppendBuffer(ResourceDescriptorHeap[Index], 10);
+}
+
+// DXIL-DAG: call target("dx.TypedBuffer", i32, 1, 0, 1) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.CBuffer", %S) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.Sampler", 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-NOT: counterhandlefromheap
+
+// SPV-DAG: call target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 24) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", %S, 2, 0) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.Sampler") @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", i32, 12, 1) @llvm.spv.resource.counterhandlefromheap{{.*}}(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %{{.*}}, i32 %{{.*}}) [ "convergencectrl"(token %{{.*}}) ]
diff --git a/clang/test/SemaHLSL/Language/InitLists.hlsl b/clang/test/SemaHLSL/Language/InitLists.hlsl
index 33c5700544449b..f86b029713515a 100644
--- a/clang/test/SemaHLSL/Language/InitLists.hlsl
+++ b/clang/test/SemaHLSL/Language/InitLists.hlsl
@@ -117,3 +117,4 @@ void Err2(RWBuffer<float4> B) {
// This note refers to the RWBuffer copy constructor that do not have a source locations
// expected-note@*{{candidate constructor not viable}}
+// expected-note@*{{candidate constructor not viable}}
diff --git a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
index c3d7b41fba2ea2..5dbcc3dd5fc056 100644
--- a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
+++ b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
@@ -74,8 +74,9 @@ void main(COORD_TYPE loc, float cmp) {
// offset-note@*:* {{candidate function not viable: no known conversion from 'SamplerState' to 'hlsl::SamplerComparisonState' for 1st argument}}
// offset-note@*:* {{candidate function not viable: requires 4 arguments, but 3 were provided}}
// nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'const hlsl::SamplerComparisonState &' for 1st argument}}
- // offset-error at +2 {{no matching member function for call to 'SampleCmpLevelZero'}}
- // nooffset-error at +1 {{no viable conversion from 'SamplerState' to 'hlsl::SamplerComparisonState'}}
+ // offset-error at +3 {{no matching member function for call to 'SampleCmpLevelZero'}}
+ // nooffset-error at +2 {{no viable conversion from 'SamplerState' to 'hlsl::SamplerComparisonState'}}
+ // nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'hlsl::__hlsl_heap_sampler_info' for 1st argument}}
t.SampleCmpLevelZero(s2, loc, cmp);
#ifdef HAS_OFFSET
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
new file mode 100644
index 00000000000000..dc9f0332da9c9d
--- /dev/null
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -finclude-default-header -fhlsl-strict-availability \
+// RUN: -triple dxil-pc-shadermodel6.5-library -verify %s
+
+export void testUnavailable(unsigned Index) {
+
+ // expected-error at +2 {{'ResourceDescriptorHeap' is only available on Shader Model 6.6 or newer}}
+ // expected-note at hlsl/hlsl_resources.h:* {{'ResourceDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
+ RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{'SamplerDescriptorHeap' is only available on Shader Model 6.6 or newer}}
+ // expected-note at hlsl/hlsl_resources.h:* {{'SamplerDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+}
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
new file mode 100644
index 00000000000000..f3300de0f7ce5a
--- /dev/null
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -verify %s
+
+void useBuffer(RWBuffer<int> Buffer) {}
+void useSampler(SamplerState Sampler) {}
+
+export void test(unsigned Index) {
+
+ // valid
+ RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
+ Buf1 = ResourceDescriptorHeap[Index + 1];
+ useBuffer(ResourceDescriptorHeap[Index + 2]);
+
+ // valid
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+ Sampler = SamplerDescriptorHeap[Index + 1];
+ useSampler(SamplerDescriptorHeap[Index + 2]);
+
+ // expected-error at +3 {{no viable conversion from '__hlsl_heap_sampler_info' to 'RWBuffer<int>'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_sampler_info' to 'hlsl::__hlsl_heap_resource_info' for 1st argument}}
+ RWBuffer<int> Buf2 = SamplerDescriptorHeap[Index];
+
+ // expected-error at +3 {{no viable conversion from '__hlsl_heap_resource_info' to 'SamplerState'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_resource_info' to 'hlsl::__hlsl_heap_sampler_info' for 1st argument}}
+ SamplerState Sampler2 = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{no viable overloaded '='}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
+ Buf2 = SamplerDescriptorHeap[Index];
+
+ // expected-error at +2 {{no viable overloaded '='}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_resource_info' to 'SamplerState' for 1st argument}}
+ Sampler2 = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{no matching function for call to 'useBuffer'}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
+ useBuffer(SamplerDescriptorHeap[Index]);
+
+ // expected-error at +2 {{no matching function for call to 'useSampler'}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
+ useSampler(ResourceDescriptorHeap[Index]);
+
+ // expected-error at +1 {{no member named 'Load'}}
+ ResourceDescriptorHeap[Index].Load(0);
+
+ // expected-error at +1 {{no member named 'Sample'}}
+ SamplerDescriptorHeap[Index].Sample(0);
+
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsSPIRV.td b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
index 86b49a8ee446a2..28b75badee3060 100644
--- a/llvm/include/llvm/IR/IntrinsicsSPIRV.td
+++ b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
@@ -207,6 +207,15 @@ def int_spv_rsqrt : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
[llvm_any_ty, llvm_i32_ty, llvm_i32_ty],
[IntrNoMem, IntrConvergent]>;
+ def int_spv_resource_handlefromheap
+ : DefaultAttrsIntrinsic<[llvm_any_ty],
+ [llvm_i32_ty],
+ [IntrNoMem]>;
+ def int_spv_resource_counterhandlefromheap
+ : DefaultAttrsIntrinsic<[llvm_any_ty],
+ [llvm_any_ty, llvm_i32_ty],
+ [IntrNoMem, IntrConvergent]>;
+
def int_spv_firstbituhigh : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
def int_spv_firstbitshigh : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
def int_spv_firstbitlow : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
>From 3d582681329f0d11b669470533f92e5e1875cf14 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 10 Sep 2026 22:56:41 -0700
Subject: [PATCH 02/10] Remove heap index argument from
llvm.spv.resource.counterhandlefromheap
The index is not needed - it is copied from the main handle initialization call.
---
clang/include/clang/Basic/Builtins.td | 2 +-
clang/lib/CodeGen/CGHLSLBuiltins.cpp | 3 +--
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 3 +--
clang/lib/Sema/SemaHLSL.cpp | 6 ++----
clang/test/AST/HLSL/StructuredBuffers-AST.hlsl | 4 +---
clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl | 2 +-
llvm/include/llvm/IR/IntrinsicsSPIRV.td | 2 +-
7 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 2b33b4a8541b32..8b15aecbfde921 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5440,7 +5440,7 @@ def HLSLResourceHandleFromHeap : LangBuiltin<"HLSL_LANG"> {
def HLSLResourceCounterHandleFromHeap : LangBuiltin<"HLSL_LANG"> {
let Spellings = ["__builtin_hlsl_resource_counterhandlefromheap"];
let Attributes = [NoThrow];
- let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t)";
+ let Prototype = "__hlsl_resource_t(__hlsl_resource_t)";
}
def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index 42c107405dff3f..e4f5ada9a0aef1 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -1077,10 +1077,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
return MainHandle;
llvm::Type *HandleTy = CGM.getTypes().ConvertType(E->getType());
- Value *IndexOp = EmitScalarExpr(E->getArg(1));
llvm::Intrinsic::ID IntrinsicID =
llvm::Intrinsic::spv_resource_counterhandlefromheap;
- SmallVector<Value *> Args{MainHandle, IndexOp};
+ SmallVector<Value *> Args{MainHandle};
return EmitIntrinsicCall(IntrinsicID, {HandleTy, MainHandle->getType()},
Args);
}
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
index 15f78eadad4e2a..a5e56154984ebc 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -1246,8 +1246,7 @@ BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
if (HasCounter) {
QualType CounterHandleType = getResourceCounterHandleField()->getType();
MB.callBuiltin("__builtin_hlsl_resource_counterhandlefromheap",
- CounterHandleType, PH::Handle,
- MB.createMemberExpr(PH::_0, IndexField))
+ CounterHandleType, PH::Handle)
.assign(PH::CounterHandle, PH::LastStmt);
}
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 7c64266d855de5..2d03487e99db6b 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -4418,10 +4418,8 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
break;
}
case Builtin::BI__builtin_hlsl_resource_counterhandlefromheap: {
- if (SemaRef.checkArgCount(TheCall, 2) ||
- CheckResourceHandle(&SemaRef, TheCall, 0) ||
- CheckArgTypeMatches(&SemaRef, TheCall->getArg(1),
- SemaRef.getASTContext().UnsignedIntTy))
+ if (SemaRef.checkArgCount(TheCall, 1) ||
+ CheckResourceHandle(&SemaRef, TheCall, 0))
return true;
// Update return type to be the attributed resource type from arg0
// with added IsCounter flag.
diff --git a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
index eb858cd51cdb60..c86a4115f412cb 100644
--- a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
@@ -159,11 +159,9 @@ RESOURCE<float> Buffer;
// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-COUNTER-HANDLE-NEXT: CStyleCastExpr {{.*}} '__hlsl_resource_t
// CHECK-COUNTER-HANDLE-NEXT: CallExpr {{.*}} '<dependent type>'
-// CHECK-COUNTER-HANDLE-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_counterhandlefromheap' '__hlsl_resource_t (__hlsl_resource_t, unsigned int) noexcept'
+// CHECK-COUNTER-HANDLE-NEXT: DeclRefExpr {{.*}} '<builtin fn type>' Function {{.*}} '__builtin_hlsl_resource_counterhandlefromheap' '__hlsl_resource_t (__hlsl_resource_t) noexcept'
// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} lvalue .__handle
// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
-// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-COUNTER-HANDLE-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
// CHECK-NEXT: AlwaysInlineAttr
// Static __createFromBinding method
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
index 02d641fdeef5f6..39cf212cee889e 100644
--- a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -106,4 +106,4 @@ export void testCounterBuffer(unsigned Index) {
// SPV-DAG: call target("spirv.VulkanBuffer", %S, 2, 0) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
// SPV-DAG: call target("spirv.Sampler") @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
// SPV-DAG: call target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// SPV-DAG: call target("spirv.VulkanBuffer", i32, 12, 1) @llvm.spv.resource.counterhandlefromheap{{.*}}(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %{{.*}}, i32 %{{.*}}) [ "convergencectrl"(token %{{.*}}) ]
+// SPV-DAG: call target("spirv.VulkanBuffer", i32, 12, 1) @llvm.spv.resource.counterhandlefromheap{{.*}}(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %{{.*}}) [ "convergencectrl"(token %{{.*}}) ]
diff --git a/llvm/include/llvm/IR/IntrinsicsSPIRV.td b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
index 28b75badee3060..3f6eba60821526 100644
--- a/llvm/include/llvm/IR/IntrinsicsSPIRV.td
+++ b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
@@ -213,7 +213,7 @@ def int_spv_rsqrt : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
[IntrNoMem]>;
def int_spv_resource_counterhandlefromheap
: DefaultAttrsIntrinsic<[llvm_any_ty],
- [llvm_any_ty, llvm_i32_ty],
+ [llvm_any_ty],
[IntrNoMem, IntrConvergent]>;
def int_spv_firstbituhigh : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
>From c2b7db47dfa813fa0773e74a5e404e8822acc580 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Tue, 15 Sep 2026 14:02:15 -0700
Subject: [PATCH 03/10] code review feedback - add docs, use hlsl::__detail
namespace for heap structs
---
clang/docs/HLSL/DynamicResources.md | 46 +++++++++++
.../clang/Sema/HLSLExternalSemaSource.h | 1 +
clang/lib/CodeGen/CGHLSLBuiltins.cpp | 6 +-
clang/lib/Headers/hlsl/hlsl_detail.h | 12 +++
clang/lib/Headers/hlsl/hlsl_resources.h | 18 +----
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 30 ++++++--
clang/lib/Sema/HLSLExternalSemaSource.cpp | 51 ++++++++-----
.../test/AST/HLSL/ByteAddressBuffers-AST.hlsl | 6 +-
clang/test/AST/HLSL/DynamicResources-AST.hlsl | 76 +++++++++----------
.../test/AST/HLSL/StructuredBuffers-AST.hlsl | 6 +-
clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 6 +-
clang/test/AST/HLSL/matrix-alias.hlsl | 2 +-
.../resources/dynamic-resources.hlsl | 60 +++++++--------
.../Textures-SampleCmpLevelZero.hlsl | 2 +-
.../SemaHLSL/Resources/dynamic-resources.hlsl | 20 ++---
15 files changed, 208 insertions(+), 134 deletions(-)
create mode 100644 clang/docs/HLSL/DynamicResources.md
diff --git a/clang/docs/HLSL/DynamicResources.md b/clang/docs/HLSL/DynamicResources.md
new file mode 100644
index 00000000000000..c2c4b84128d2c3
--- /dev/null
+++ b/clang/docs/HLSL/DynamicResources.md
@@ -0,0 +1,46 @@
+# HLSL Dynamic Resources
+
+```{contents}
+:local: true
+```
+
+## Introduction
+
+[HLSL Dynamic Resources][dynamicresources] is a feature introduced in Shader
+Model 6.6 that allows shaders to create resources from descriptors by directly
+indexing the CBV/SRV/UAV heap or the sampler heap. Dynamic resources are also
+known as _bindless resources_ or _directly indexed resources_.
+
+HLSL exposes these heaps through two built-in global objects:
+`ResourceDescriptorHeap` and `SamplerDescriptorHeap`. Indexing either object
+yields an intermediate value that can be converted to a resource or sampler
+object. Resources created this way do not require binding locations or root
+signature descriptor-table mappings.
+
+## Implementation Details
+
+The global variables `ResourceDescriptorHeap` and `SamplerDescriptorHeap` are
+declared in the built-in header `hlsl/hlsl_resources.h`, which is included by
+the default header `hlsl.h`. Indexing either global variable returns a small
+internal struct that carries the heap index.
+
+Indexing `ResourceDescriptorHeap` returns `__heap_resource_info`, and indexing
+`SamplerDescriptorHeap` returns `__heap_sampler_info`. These structs are
+defined by `HLSLExternalSemaSource` in the `hlsl::__detail` namespace. Using
+distinct struct types allows the compiler to diagnose heap mismatches during
+overload resolution: a sampler type can only be constructed from
+`__heap_sampler_info`, while a CBV/SRV/UAV resource type can only be constructed
+from `__heap_resource_info`.
+
+Every resource class has an implicit constructor that accepts the
+corresponding heap info struct. The constructor passes this information to the
+Clang built-in function `__builtin_hlsl_resource_handlefromheap`, which creates
+a concrete handle from the heap. Standard C++ implicit conversion rules allow
+assignment, initialization, and function arguments to work without special
+handling in `Sema`. For resources with counters, the constructor also uses
+`__builtin_hlsl_resource_handlefromheap` to create the counter handle.
+
+During code generation, the built-in function is lowered to target-specific
+intrinsics for heap resources.
+
+[dynamicresources]: https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_DynamicResources.html
\ No newline at end of file
diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 840cd3e0a082aa..d98a6067ee83a3 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -22,6 +22,7 @@ class Sema;
class HLSLExternalSemaSource : public ExternalSemaSource {
Sema *SemaPtr = nullptr;
NamespaceDecl *HLSLNamespace = nullptr;
+ NamespaceDecl *HLSLDetailNamespace = nullptr;
using CompletionFunction = std::function<void(CXXRecordDecl *)>;
llvm::DenseMap<CXXRecordDecl *, CompletionFunction> Completions;
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index e4f5ada9a0aef1..bc39514cd8c571 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -1068,8 +1068,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
Value *IndexOp = EmitScalarExpr(E->getArg(1));
llvm::Intrinsic::ID IntrinsicID =
CGM.getHLSLRuntime().getCreateHandleFromHeapIntrinsic();
- SmallVector<Value *> Args{IndexOp};
- return Builder.CreateIntrinsic(HandleTy, IntrinsicID, Args);
+ return Builder.CreateIntrinsic(HandleTy, IntrinsicID, {IndexOp});
}
case Builtin::BI__builtin_hlsl_resource_counterhandlefromheap: {
Value *MainHandle = EmitScalarExpr(E->getArg(0));
@@ -1079,9 +1078,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
llvm::Type *HandleTy = CGM.getTypes().ConvertType(E->getType());
llvm::Intrinsic::ID IntrinsicID =
llvm::Intrinsic::spv_resource_counterhandlefromheap;
- SmallVector<Value *> Args{MainHandle};
return EmitIntrinsicCall(IntrinsicID, {HandleTy, MainHandle->getType()},
- Args);
+ {MainHandle});
}
case Builtin::BI__builtin_hlsl_resource_nonuniformindex: {
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h
index 922b381eb8d791..73e03ef2d2200a 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -70,6 +70,18 @@ template <typename T, int R, int C> struct elem_type<matrix<T, R, C>> {
};
template <typename T> using elem_type_t = typename elem_type<T>::Type;
+struct __resource_descriptor_heap_struct {
+ __heap_resource_info operator[](uint32_t Index) {
+ return __heap_resource_info{Index};
+ }
+};
+
+struct __sampler_descriptor_heap_struct {
+ __heap_sampler_info operator[](uint32_t Index) {
+ return __heap_sampler_info{Index};
+ }
+};
+
} // namespace __detail
} // namespace hlsl
#endif //_HLSL_HLSL_DETAILS_H_
diff --git a/clang/lib/Headers/hlsl/hlsl_resources.h b/clang/lib/Headers/hlsl/hlsl_resources.h
index d43c94dbff572e..0926f2488bf015 100644
--- a/clang/lib/Headers/hlsl/hlsl_resources.h
+++ b/clang/lib/Headers/hlsl/hlsl_resources.h
@@ -9,28 +9,18 @@
#ifndef _HLSL_HLSL_RESOURCES_H_
#define _HLSL_HLSL_RESOURCES_H_
+#include "hlsl_detail.h"
+
namespace hlsl {
#define _HLSL_AVAILABILITY(platform, version) \
__attribute__((availability(platform, introduced = version)))
-struct __hlsl_resource_descriptor_heap_struct {
- __hlsl_heap_resource_info operator[](uint32_t Index) {
- return __hlsl_heap_resource_info{Index};
- }
-};
-
-struct __hlsl_sampler_descriptor_heap_struct {
- __hlsl_heap_sampler_info operator[](uint32_t Index) {
- return __hlsl_heap_sampler_info{Index};
- }
-};
-
_HLSL_AVAILABILITY(shadermodel, 6.6)
-static __hlsl_resource_descriptor_heap_struct ResourceDescriptorHeap;
+static __detail::__resource_descriptor_heap_struct ResourceDescriptorHeap;
_HLSL_AVAILABILITY(shadermodel, 6.6)
-static __hlsl_sampler_descriptor_heap_struct SamplerDescriptorHeap;
+static __detail::__sampler_descriptor_heap_struct SamplerDescriptorHeap;
} // namespace hlsl
#endif //_HLSL_HLSL_RESOURCES_H_
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
index a5e56154984ebc..973d4747d13963 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -53,6 +53,16 @@ static FunctionDecl *lookupBuiltinFunction(Sema &S, StringRef Name) {
return cast<FunctionDecl>(R.getFoundDecl());
}
+static NamespaceDecl *lookupBuiltinNamespace(Sema &S, StringRef Name,
+ DeclContext *DC) {
+ IdentifierInfo &II =
+ S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
+ LookupResult Result(S, &II, SourceLocation(), Sema::LookupNamespaceName);
+ S.LookupQualifiedName(Result, DC);
+ assert(!Result.empty() && "Builtin namespace not found");
+ return Result.getAsSingle<NamespaceDecl>();
+}
+
static QualType lookupBuiltinType(Sema &S, StringRef Name, DeclContext *DC) {
IdentifierInfo &II =
S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
@@ -1216,8 +1226,8 @@ BuiltinTypeDeclBuilder::addDefaultHandleConstructor(AccessSpecifier Access) {
.finalize(Access);
}
-// Adds constructor that takes __hlsl_heap_resource_info:
-// Resource::Resource(__hlsl_heap_resource_info info) {
+// Adds constructor that takes hlsl::__detail::__heap_resource_info:
+// Resource::Resource(hlsl::__detail::__heap_resource_info info) {
// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
// }
BuiltinTypeDeclBuilder &
@@ -1229,8 +1239,10 @@ BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
ASTContext &AST = SemaRef.getASTContext();
QualType HandleType = getResourceHandleField()->getType();
- QualType HeapResInfoType = lookupBuiltinType(
- SemaRef, "__hlsl_heap_resource_info", Record->getDeclContext());
+ NamespaceDecl *HLSLDetailNS =
+ lookupBuiltinNamespace(SemaRef, "__detail", Record->getDeclContext());
+ QualType HeapResInfoType =
+ lookupBuiltinType(SemaRef, "__heap_resource_info", HLSLDetailNS);
CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
@@ -1253,8 +1265,8 @@ BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
return MB.finalize();
}
-// Adds constructor that takes __hlsl_heap_sampler_info:
-// Resource::Resource(__hlsl_heap_sampler_info info) {
+// Adds constructor that takes hlsl::__detail::__heap_sampler_info:
+// Resource::Resource(hlsl::__detail::__heap_sampler_info info) {
// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
// }
BuiltinTypeDeclBuilder &
@@ -1266,8 +1278,10 @@ BuiltinTypeDeclBuilder::addHeapSamplerInfoConstructor() {
ASTContext &AST = SemaRef.getASTContext();
QualType HandleType = getResourceHandleField()->getType();
- QualType HeapResInfoType = lookupBuiltinType(
- SemaRef, "__hlsl_heap_sampler_info", Record->getDeclContext());
+ NamespaceDecl *HLSLDetailNS =
+ lookupBuiltinNamespace(SemaRef, "__detail", Record->getDeclContext());
+ QualType HeapResInfoType =
+ lookupBuiltinType(SemaRef, "__heap_sampler_info", HLSLDetailNS);
CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 75932dc8a136e0..70752a23bb40e2 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -33,6 +33,28 @@ using namespace llvm::hlsl;
using clang::hlsl::BuiltinTypeDeclBuilder;
+static NamespaceDecl *createImplicitNamespace(Sema &S, StringRef Name,
+ DeclContext *DC) {
+ ASTContext &AST = S.getASTContext();
+ IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
+ LookupResult Result(S, &II, SourceLocation(), Sema::LookupNamespaceName);
+ NamespaceDecl *PrevDecl = nullptr;
+ if (S.LookupQualifiedName(Result, AST.getTranslationUnitDecl()))
+ PrevDecl = Result.getAsSingle<NamespaceDecl>();
+
+ NamespaceDecl *NS =
+ NamespaceDecl::Create(AST, DC, /*Inline=*/false, SourceLocation(),
+ SourceLocation(), &II, PrevDecl, /*Nested=*/false);
+ NS->setImplicit(true);
+ NS->setHasExternalLexicalStorage();
+ DC->addDecl(NS);
+
+ // Force external decls in the namespace to load from the PCH.
+ (void)NS->getCanonicalDecl()->decls_begin();
+
+ return NS;
+}
+
void HLSLExternalSemaSource::InitializeSema(Sema &S) {
SemaPtr = &S;
ASTContext &AST = SemaPtr->getASTContext();
@@ -40,20 +62,10 @@ void HLSLExternalSemaSource::InitializeSema(Sema &S) {
if (AST.getTranslationUnitDecl()->hasExternalLexicalStorage())
(void)AST.getTranslationUnitDecl()->decls_begin();
- IdentifierInfo &HLSL = AST.Idents.get("hlsl", tok::TokenKind::identifier);
- LookupResult Result(S, &HLSL, SourceLocation(), Sema::LookupNamespaceName);
- NamespaceDecl *PrevDecl = nullptr;
- if (S.LookupQualifiedName(Result, AST.getTranslationUnitDecl()))
- PrevDecl = Result.getAsSingle<NamespaceDecl>();
- HLSLNamespace = NamespaceDecl::Create(
- AST, AST.getTranslationUnitDecl(), /*Inline=*/false, SourceLocation(),
- SourceLocation(), &HLSL, PrevDecl, /*Nested=*/false);
- HLSLNamespace->setImplicit(true);
- HLSLNamespace->setHasExternalLexicalStorage();
- AST.getTranslationUnitDecl()->addDecl(HLSLNamespace);
-
- // Force external decls in the HLSL namespace to load from the PCH.
- (void)HLSLNamespace->getCanonicalDecl()->decls_begin();
+ HLSLNamespace = createImplicitNamespace(
+ S, "hlsl", cast<DeclContext>(AST.getTranslationUnitDecl()));
+ HLSLDetailNamespace = createImplicitNamespace(S, "__detail", HLSLNamespace);
+
defineTrivialHLSLTypes();
defineInternalHLSLTypes();
defineHLSLTypesWithForwardDeclarations();
@@ -236,17 +248,18 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
ASTContext &AST = SemaPtr->getASTContext();
- CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
- "__hlsl_heap_resource_info")
+ CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
+ "__heap_resource_info")
.finalizeForwardDeclaration();
if (!ResDecl->isCompleteDefinition())
BuiltinTypeDeclBuilder(*SemaPtr, ResDecl)
.addMemberVariable("Index", AST.UnsignedIntTy, {})
.completeDefinition();
- CXXRecordDecl *SampDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
- "__hlsl_heap_sampler_info")
- .finalizeForwardDeclaration();
+ CXXRecordDecl *SampDecl =
+ BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
+ "__heap_sampler_info")
+ .finalizeForwardDeclaration();
if (!SampDecl->isCompleteDefinition())
BuiltinTypeDeclBuilder(*SemaPtr, SampDecl)
.addMemberVariable("Index", AST.UnsignedIntTy, {})
diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
index 3312045cf4def8..cd56b4b4c543b8 100644
--- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
@@ -84,8 +84,8 @@ RESOURCE Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]] 'void (hlsl::__hlsl_heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]] 'void (hlsl::__detail::__heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -97,7 +97,7 @@ RESOURCE Buffer;
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
// CHECK-NEXT: AlwaysInlineAttr
// Static __createFromBinding method
diff --git a/clang/test/AST/HLSL/DynamicResources-AST.hlsl b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
index 00d181388a9778..af99a2a927a5bc 100644
--- a/clang/test/AST/HLSL/DynamicResources-AST.hlsl
+++ b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
@@ -1,10 +1,10 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -ast-dump %s | FileCheck %s
// Global variables for ResourceDescriptorHeap and SamplerDescriptorHeap
-// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __hlsl_resource_descriptor_heap_struct' static internal-linkage
+// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __detail::__resource_descriptor_heap_struct' static internal-linkage
// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
-// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __hlsl_sampler_descriptor_heap_struct' static internal-linkage
+// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __detail::__sampler_descriptor_heap_struct' static internal-linkage
// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
void useBuffer(RWBuffer<int> Buffer) {}
@@ -23,18 +23,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
-// __hlsl_heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+// __heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -56,18 +56,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
-// __hlsl_heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+// __heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -86,18 +86,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__hlsl_heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
-// __hlsl_heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' 'void (__hlsl_heap_resource_info &&) noexcept' elidable
+// __heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__hlsl_heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__hlsl_heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__hlsl_heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__hlsl_heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__hlsl_resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __hlsl_resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __hlsl_resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -113,18 +113,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'SamplerState' <ConstructorConversion>
// SamplerState heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__hlsl_heap_sampler_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__detail::__heap_sampler_info)'
-// __hlsl_heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__hlsl_heap_sampler_info' 'void (__hlsl_heap_sampler_info &&) noexcept' elidable
+// __heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__detail::__heap_sampler_info' 'void (__heap_sampler_info &&) noexcept' elidable
// Indexing into SamplerDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> '__hlsl_heap_sampler_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> '__hlsl_heap_sampler_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> '__hlsl_heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> '__hlsl_heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__hlsl_heap_sampler_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__hlsl_sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __hlsl_sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __hlsl_sampler_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> '__heap_sampler_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> '__heap_sampler_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> '__heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> '__heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_sampler_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__detail::__sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __detail::__sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __detail::__sampler_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:48> 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} <col:48> 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
diff --git a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
index c86a4115f412cb..6238aae2ee0f66 100644
--- a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
@@ -141,8 +141,8 @@ RESOURCE<float> Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__hlsl_heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::__heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -153,7 +153,7 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
// CHECK-COUNTER-HANDLE-NEXT: BinaryOperator {{.*}} '='
// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} lvalue .__counter_handle
// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
diff --git a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
index 667486b34e84fa..80148bb1865478 100644
--- a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
@@ -106,8 +106,8 @@ RESOURCE<float> Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__hlsl_heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__hlsl_heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::__heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -118,7 +118,7 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__hlsl_heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__hlsl_heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
// CHECK-NEXT: AlwaysInlineAttr
// Static __createFromBinding method
diff --git a/clang/test/AST/HLSL/matrix-alias.hlsl b/clang/test/AST/HLSL/matrix-alias.hlsl
index e3a3c6c5dd015b..f922683e7b2fcd 100644
--- a/clang/test/AST/HLSL/matrix-alias.hlsl
+++ b/clang/test/AST/HLSL/matrix-alias.hlsl
@@ -3,7 +3,7 @@
// Test that matrix aliases are set up properly for HLSL
// CHECK: NamespaceDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit referenced hlsl
-// CHECK-NEXT: TypeAliasTemplateDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit vector
+// CHECK: TypeAliasTemplateDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit vector
// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> class depth 0 index 0 element
// CHECK-NEXT: TemplateArgument type 'float'
// CHECK-NEXT: BuiltinType 0x{{[0-9a-fA-F]+}} 'float'
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
index 39cf212cee889e..36d43fd7d6fb5e 100644
--- a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -5,23 +5,23 @@
// CHECK: %S = type <{ i32 }>
-// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__hlsl_resource_descriptor_heap_struct" zeroinitializer, align 1
-// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__hlsl_sampler_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::__resource_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::__sampler_descriptor_heap_struct" zeroinitializer, align 1
// CHECK-LABEL: testTypedBuffer
export void testTypedBuffer(unsigned Index) {
-// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
-// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]],
+// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]],
+// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__hlsl_heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP0]])
+// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__detail::__heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]])
RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
}
@@ -34,19 +34,19 @@ export void testConstantBuffer(unsigned Index) {
// CHECK: %CBS = alloca %"class.hlsl::ConstantBuffer"
// CHECK: [[TMP1:%.*]] = alloca %"class.hlsl::ConstantBuffer"
-// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer()(ptr {{.*}} %CBS)
-// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP2]],
+// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP2]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP2]],
+// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP2]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__hlsl_heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 %{{.*}})
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__detail::__heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 %{{.*}})
// CHECK: call {{.*}} ptr @hlsl::ConstantBuffer<S>::operator=(hlsl::ConstantBuffer<S> const&)
// CHECK-SAME: (ptr {{.*}} %CBS, ptr {{.*}} [[TMP1]])
@@ -55,19 +55,19 @@ export void testConstantBuffer(unsigned Index) {
}
// CHECK: define {{(spir_func )*}}void @testSampler(unsigned int)(ptr {{.*}} sret(%"class.hlsl::SamplerState") align {{(4|8)}} [[RESULT:%.*]], i32 noundef %Index)
-// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__hlsl_heap_sampler_info"
+// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__detail::__heap_sampler_info"
export SamplerState testSampler(unsigned Index) {
-// DXIL: call void @hlsl::__hlsl_sampler_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]],
+// DXIL: call void @hlsl::__detail::__sampler_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]],
// DXIL-SAME: ptr {{.*}} @hlsl::SamplerDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__hlsl_sampler_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]],
+// SPV: call spir_func void @hlsl::__detail::__sampler_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::SamplerDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__hlsl_heap_sampler_info)
-// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__hlsl_heap_sampler_info") align 4 [[TMP3]])
+// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__detail::__heap_sampler_info)
+// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]])
return SamplerDescriptorHeap[Index];
}
@@ -78,18 +78,18 @@ void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
// CHECK-LABEL: testCounterBuffer
export void testCounterBuffer(unsigned Index) {
// CHECK: [[TMP_BUFFER:%.*]] = alloca %"class.hlsl::AppendStructuredBuffer"
-// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__hlsl_heap_resource_info"
+// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
-// DXIL: call void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]],
+// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__hlsl_resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]],
+// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__hlsl_heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__hlsl_heap_resource_info") align 4 [[TMP4]])
+// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__detail::__heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]])
// CHECK: call {{(spir_func )*}}void @useAppendBuffer(hlsl::AppendStructuredBuffer<int>, int)
// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], i32 noundef 10)
diff --git a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
index 5dbcc3dd5fc056..cdc8f49808874a 100644
--- a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
+++ b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
@@ -76,7 +76,7 @@ void main(COORD_TYPE loc, float cmp) {
// nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'const hlsl::SamplerComparisonState &' for 1st argument}}
// offset-error at +3 {{no matching member function for call to 'SampleCmpLevelZero'}}
// nooffset-error at +2 {{no viable conversion from 'SamplerState' to 'hlsl::SamplerComparisonState'}}
- // nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'hlsl::__hlsl_heap_sampler_info' for 1st argument}}
+ // nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'hlsl::__detail::__heap_sampler_info' for 1st argument}}
t.SampleCmpLevelZero(s2, loc, cmp);
#ifdef HAS_OFFSET
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
index f3300de0f7ce5a..bf99b7196366e2 100644
--- a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
@@ -15,30 +15,30 @@ export void test(unsigned Index) {
Sampler = SamplerDescriptorHeap[Index + 1];
useSampler(SamplerDescriptorHeap[Index + 2]);
- // expected-error at +3 {{no viable conversion from '__hlsl_heap_sampler_info' to 'RWBuffer<int>'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_sampler_info' to 'hlsl::__hlsl_heap_resource_info' for 1st argument}}
+ // expected-error at +3 {{no viable conversion from '__heap_sampler_info' to 'RWBuffer<int>'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_sampler_info' to 'hlsl::__detail::__heap_resource_info' for 1st argument}}
RWBuffer<int> Buf2 = SamplerDescriptorHeap[Index];
- // expected-error at +3 {{no viable conversion from '__hlsl_heap_resource_info' to 'SamplerState'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__hlsl_heap_resource_info' to 'hlsl::__hlsl_heap_sampler_info' for 1st argument}}
+ // expected-error at +3 {{no viable conversion from '__heap_resource_info' to 'SamplerState'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_resource_info' to 'hlsl::__detail::__heap_sampler_info' for 1st argument}}
SamplerState Sampler2 = ResourceDescriptorHeap[Index];
// expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
Buf2 = SamplerDescriptorHeap[Index];
// expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_resource_info' to 'SamplerState' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_resource_info' to 'SamplerState' for 1st argument}}
Sampler2 = ResourceDescriptorHeap[Index];
// expected-error at +2 {{no matching function for call to 'useBuffer'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
useBuffer(SamplerDescriptorHeap[Index]);
// expected-error at +2 {{no matching function for call to 'useSampler'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__hlsl_heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
useSampler(ResourceDescriptorHeap[Index]);
// expected-error at +1 {{no member named 'Load'}}
>From 87ecde1b758b6658c7118642e4b2253be2bd0b56 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Tue, 15 Sep 2026 15:13:16 -0700
Subject: [PATCH 04/10] loose the __
---
clang/docs/HLSL/DynamicResources.md | 45 +++++------
clang/lib/Headers/hlsl/hlsl_detail.h | 12 +--
clang/lib/Headers/hlsl/hlsl_resources.h | 4 +-
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 12 +--
clang/lib/Sema/HLSLExternalSemaSource.cpp | 5 +-
.../test/AST/HLSL/ByteAddressBuffers-AST.hlsl | 6 +-
clang/test/AST/HLSL/DynamicResources-AST.hlsl | 76 +++++++++----------
.../test/AST/HLSL/StructuredBuffers-AST.hlsl | 6 +-
clang/test/AST/HLSL/TypedBuffers-AST.hlsl | 6 +-
.../resources/dynamic-resources.hlsl | 60 +++++++--------
.../Textures-SampleCmpLevelZero.hlsl | 2 +-
.../SemaHLSL/Resources/dynamic-resources.hlsl | 20 ++---
12 files changed, 127 insertions(+), 127 deletions(-)
diff --git a/clang/docs/HLSL/DynamicResources.md b/clang/docs/HLSL/DynamicResources.md
index c2c4b84128d2c3..3b5c4afccf6593 100644
--- a/clang/docs/HLSL/DynamicResources.md
+++ b/clang/docs/HLSL/DynamicResources.md
@@ -19,28 +19,29 @@ signature descriptor-table mappings.
## Implementation Details
-The global variables `ResourceDescriptorHeap` and `SamplerDescriptorHeap` are
-declared in the built-in header `hlsl/hlsl_resources.h`, which is included by
-the default header `hlsl.h`. Indexing either global variable returns a small
-internal struct that carries the heap index.
-
-Indexing `ResourceDescriptorHeap` returns `__heap_resource_info`, and indexing
-`SamplerDescriptorHeap` returns `__heap_sampler_info`. These structs are
-defined by `HLSLExternalSemaSource` in the `hlsl::__detail` namespace. Using
-distinct struct types allows the compiler to diagnose heap mismatches during
-overload resolution: a sampler type can only be constructed from
-`__heap_sampler_info`, while a CBV/SRV/UAV resource type can only be constructed
-from `__heap_resource_info`.
-
-Every resource class has an implicit constructor that accepts the
-corresponding heap info struct. The constructor passes this information to the
-Clang built-in function `__builtin_hlsl_resource_handlefromheap`, which creates
-a concrete handle from the heap. Standard C++ implicit conversion rules allow
-assignment, initialization, and function arguments to work without special
-handling in `Sema`. For resources with counters, the constructor also uses
-`__builtin_hlsl_resource_handlefromheap` to create the counter handle.
-
-During code generation, the built-in function is lowered to target-specific
+The built-in header `hlsl/hlsl_resources.h` declares the global variables
+`ResourceDescriptorHeap` and `SamplerDescriptorHeap` and is included by the
+default header `hlsl.h`. Their types, `resource_descriptor_heap_struct` and
+`sampler_descriptor_heap_struct`, are defined in the `hlsl::__detail` namespace
+in `hlsl/hlsl_detail.h`.
+
+Each global's indexing operator returns a small internal struct containing the
+heap index: `ResourceDescriptorHeap` returns `heap_resource_info`, while
+`SamplerDescriptorHeap` returns `heap_sampler_info`. `HLSLExternalSemaSource`
+defines both structs in the `hlsl::__detail` namespace. Their distinct types
+allow overload resolution to reject attempts to construct a resource from the
+wrong heap: sampler types accept only `heap_sampler_info`, while CBV/SRV/UAV
+resource types accept only `heap_resource_info`.
+
+Each resource class has an implicit constructor that accepts the corresponding
+heap info struct and passes it to `__builtin_hlsl_resource_handlefromheap` to
+create a concrete resource handle. This allows assignments, initializations,
+and function arguments to use standard C++ implicit conversions without special
+handling in `Sema`. For resources with counters, the constructor creates the
+counter handle with the separate
+`__builtin_hlsl_resource_counterhandlefromheap` built-in.
+
+During code generation, each call to the built-in is lowered to target-specific
intrinsics for heap resources.
[dynamicresources]: https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_DynamicResources.html
\ No newline at end of file
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h b/clang/lib/Headers/hlsl/hlsl_detail.h
index 73e03ef2d2200a..a0461387d56692 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -70,15 +70,15 @@ template <typename T, int R, int C> struct elem_type<matrix<T, R, C>> {
};
template <typename T> using elem_type_t = typename elem_type<T>::Type;
-struct __resource_descriptor_heap_struct {
- __heap_resource_info operator[](uint32_t Index) {
- return __heap_resource_info{Index};
+struct resource_descriptor_heap_struct {
+ heap_resource_info operator[](uint32_t Index) {
+ return heap_resource_info{Index};
}
};
-struct __sampler_descriptor_heap_struct {
- __heap_sampler_info operator[](uint32_t Index) {
- return __heap_sampler_info{Index};
+struct sampler_descriptor_heap_struct {
+ heap_sampler_info operator[](uint32_t Index) {
+ return heap_sampler_info{Index};
}
};
diff --git a/clang/lib/Headers/hlsl/hlsl_resources.h b/clang/lib/Headers/hlsl/hlsl_resources.h
index 0926f2488bf015..4a304e76e61bda 100644
--- a/clang/lib/Headers/hlsl/hlsl_resources.h
+++ b/clang/lib/Headers/hlsl/hlsl_resources.h
@@ -17,10 +17,10 @@ namespace hlsl {
__attribute__((availability(platform, introduced = version)))
_HLSL_AVAILABILITY(shadermodel, 6.6)
-static __detail::__resource_descriptor_heap_struct ResourceDescriptorHeap;
+static __detail::resource_descriptor_heap_struct ResourceDescriptorHeap;
_HLSL_AVAILABILITY(shadermodel, 6.6)
-static __detail::__sampler_descriptor_heap_struct SamplerDescriptorHeap;
+static __detail::sampler_descriptor_heap_struct SamplerDescriptorHeap;
} // namespace hlsl
#endif //_HLSL_HLSL_RESOURCES_H_
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
index 7108e4a322888a..4d7445c59da291 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -1237,8 +1237,8 @@ BuiltinTypeDeclBuilder::addDefaultHandleConstructor(AccessSpecifier Access) {
.finalize(Access);
}
-// Adds constructor that takes hlsl::__detail::__heap_resource_info:
-// Resource::Resource(hlsl::__detail::__heap_resource_info info) {
+// Adds constructor that takes hlsl::__detail::heap_resource_info:
+// Resource::Resource(hlsl::__detail::heap_resource_info info) {
// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
// }
BuiltinTypeDeclBuilder &
@@ -1253,7 +1253,7 @@ BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
NamespaceDecl *HLSLDetailNS =
lookupBuiltinNamespace(SemaRef, "__detail", Record->getDeclContext());
QualType HeapResInfoType =
- lookupBuiltinType(SemaRef, "__heap_resource_info", HLSLDetailNS);
+ lookupBuiltinType(SemaRef, "heap_resource_info", HLSLDetailNS);
CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
@@ -1276,8 +1276,8 @@ BuiltinTypeDeclBuilder::addHeapResourceInfoConstructor(bool HasCounter) {
return MB.finalize();
}
-// Adds constructor that takes hlsl::__detail::__heap_sampler_info:
-// Resource::Resource(hlsl::__detail::__heap_sampler_info info) {
+// Adds constructor that takes hlsl::__detail::heap_sampler_info:
+// Resource::Resource(hlsl::__detail::heap_sampler_info info) {
// __handle = __builtin_hlsl_resource_handlefromheap(__handle, info.Index);
// }
BuiltinTypeDeclBuilder &
@@ -1292,7 +1292,7 @@ BuiltinTypeDeclBuilder::addHeapSamplerInfoConstructor() {
NamespaceDecl *HLSLDetailNS =
lookupBuiltinNamespace(SemaRef, "__detail", Record->getDeclContext());
QualType HeapResInfoType =
- lookupBuiltinType(SemaRef, "__heap_sampler_info", HLSLDetailNS);
+ lookupBuiltinType(SemaRef, "heap_sampler_info", HLSLDetailNS);
CXXRecordDecl *HeapResInfoDecl = HeapResInfoType->getAsCXXRecordDecl();
FieldDecl *IndexField = *HeapResInfoDecl->field_begin();
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 7c56d90e28dad9..2a6708ddab7c2c 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -249,7 +249,7 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
ASTContext &AST = SemaPtr->getASTContext();
CXXRecordDecl *ResDecl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
- "__heap_resource_info")
+ "heap_resource_info")
.finalizeForwardDeclaration();
if (!ResDecl->isCompleteDefinition())
BuiltinTypeDeclBuilder(*SemaPtr, ResDecl)
@@ -257,8 +257,7 @@ void HLSLExternalSemaSource::defineHeapResourceInfoTypes() {
.completeDefinition();
CXXRecordDecl *SampDecl =
- BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace,
- "__heap_sampler_info")
+ BuiltinTypeDeclBuilder(*SemaPtr, HLSLDetailNamespace, "heap_sampler_info")
.finalizeForwardDeclaration();
if (!SampDecl->isCompleteDefinition())
BuiltinTypeDeclBuilder(*SemaPtr, SampDecl)
diff --git a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
index cd56b4b4c543b8..374e8ce2154453 100644
--- a/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
@@ -84,8 +84,8 @@ RESOURCE Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]] 'void (hlsl::__detail::__heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]] 'void (hlsl::__detail::heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -97,7 +97,7 @@ RESOURCE Buffer;
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]' lvalue implicit this
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::heap_resource_info'
// CHECK-NEXT: AlwaysInlineAttr
// Static __createFromBinding method
diff --git a/clang/test/AST/HLSL/DynamicResources-AST.hlsl b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
index af99a2a927a5bc..7ec0ed7594e355 100644
--- a/clang/test/AST/HLSL/DynamicResources-AST.hlsl
+++ b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
@@ -1,10 +1,10 @@
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -ast-dump %s | FileCheck %s
// Global variables for ResourceDescriptorHeap and SamplerDescriptorHeap
-// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __detail::__resource_descriptor_heap_struct' static internal-linkage
+// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __detail::resource_descriptor_heap_struct' static internal-linkage
// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
-// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __detail::__sampler_descriptor_heap_struct' static internal-linkage
+// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __detail::sampler_descriptor_heap_struct' static internal-linkage
// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
void useBuffer(RWBuffer<int> Buffer) {}
@@ -23,18 +23,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-// __heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -56,18 +56,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-// __heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -86,18 +86,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::__heap_resource_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-// __heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::__heap_resource_info' 'void (__heap_resource_info &&) noexcept' elidable
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} '__heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} '__heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} '__heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} '__heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::__resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::__resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::__resource_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
@@ -113,18 +113,18 @@ export void testInvocations(unsigned Index) {
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'SamplerState' <ConstructorConversion>
// SamplerState heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__detail::__heap_sampler_info)'
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__detail::heap_sampler_info)'
-// __heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__detail::__heap_sampler_info' 'void (__heap_sampler_info &&) noexcept' elidable
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__detail::heap_sampler_info' 'void (heap_sampler_info &&) noexcept' elidable
// Indexing into SamplerDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> '__heap_sampler_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> '__heap_sampler_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> '__heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> '__heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' '__heap_sampler_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__detail::__sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __detail::__sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __detail::__sampler_descriptor_heap_struct'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'heap_sampler_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> 'heap_sampler_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> 'heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> 'heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_sampler_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__detail::sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __detail::sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __detail::sampler_descriptor_heap_struct'
// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:48> 'unsigned int' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr {{.*}} <col:48> 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
diff --git a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
index 6238aae2ee0f66..4cfced0fd9c7ef 100644
--- a/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
@@ -141,8 +141,8 @@ RESOURCE<float> Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::__heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -153,7 +153,7 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::heap_resource_info'
// CHECK-COUNTER-HANDLE-NEXT: BinaryOperator {{.*}} '='
// CHECK-COUNTER-HANDLE-NEXT: MemberExpr {{.*}} lvalue .__counter_handle
// CHECK-COUNTER-HANDLE-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
diff --git a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
index 80148bb1865478..048ffe3845679d 100644
--- a/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
+++ b/clang/test/AST/HLSL/TypedBuffers-AST.hlsl
@@ -106,8 +106,8 @@ RESOURCE<float> Buffer;
// Heap info constructor
-// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::__heap_resource_info)' inline
-// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::__heap_resource_info'
+// CHECK: CXXConstructorDecl {{.*}} [[RESOURCE]]<element_type> 'void (hlsl::__detail::heap_resource_info)' inline
+// CHECK-NEXT: ParmVarDecl {{.*}} HeapResInfo 'hlsl::__detail::heap_resource_info'
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: BinaryOperator {{.*}} '='
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
@@ -118,7 +118,7 @@ RESOURCE<float> Buffer;
// CHECK-NEXT: MemberExpr {{.*}} lvalue .__handle
// CHECK-NEXT: CXXThisExpr {{.*}} 'hlsl::[[RESOURCE]]<element_type>' lvalue implicit this
// CHECK-NEXT: MemberExpr {{.*}} 'unsigned int' lvalue .Index
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::__heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::__heap_resource_info'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::__detail::heap_resource_info' lvalue ParmVar {{.*}} 'HeapResInfo' 'hlsl::__detail::heap_resource_info'
// CHECK-NEXT: AlwaysInlineAttr
// Static __createFromBinding method
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
index 36d43fd7d6fb5e..2b1a7c275f7fb5 100644
--- a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -5,23 +5,23 @@
// CHECK: %S = type <{ i32 }>
-// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::__resource_descriptor_heap_struct" zeroinitializer, align 1
-// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::__sampler_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::resource_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::sampler_descriptor_heap_struct" zeroinitializer, align 1
// CHECK-LABEL: testTypedBuffer
export void testTypedBuffer(unsigned Index) {
-// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
+// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
-// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]],
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]],
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__detail::__heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP0]])
+// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]])
RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
}
@@ -34,19 +34,19 @@ export void testConstantBuffer(unsigned Index) {
// CHECK: %CBS = alloca %"class.hlsl::ConstantBuffer"
// CHECK: [[TMP1:%.*]] = alloca %"class.hlsl::ConstantBuffer"
-// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
+// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer()(ptr {{.*}} %CBS)
-// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP2]],
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP2]],
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__detail::__heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 %{{.*}})
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 %{{.*}})
// CHECK: call {{.*}} ptr @hlsl::ConstantBuffer<S>::operator=(hlsl::ConstantBuffer<S> const&)
// CHECK-SAME: (ptr {{.*}} %CBS, ptr {{.*}} [[TMP1]])
@@ -55,19 +55,19 @@ export void testConstantBuffer(unsigned Index) {
}
// CHECK: define {{(spir_func )*}}void @testSampler(unsigned int)(ptr {{.*}} sret(%"class.hlsl::SamplerState") align {{(4|8)}} [[RESULT:%.*]], i32 noundef %Index)
-// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__detail::__heap_sampler_info"
+// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__detail::heap_sampler_info"
export SamplerState testSampler(unsigned Index) {
-// DXIL: call void @hlsl::__detail::__sampler_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]],
+// DXIL: call void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
// DXIL-SAME: ptr {{.*}} @hlsl::SamplerDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__detail::__sampler_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]],
+// SPV: call spir_func void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::SamplerDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__detail::__heap_sampler_info)
-// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__detail::__heap_sampler_info") align 4 [[TMP3]])
+// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__detail::heap_sampler_info)
+// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]])
return SamplerDescriptorHeap[Index];
}
@@ -78,18 +78,18 @@ void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
// CHECK-LABEL: testCounterBuffer
export void testCounterBuffer(unsigned Index) {
// CHECK: [[TMP_BUFFER:%.*]] = alloca %"class.hlsl::AppendStructuredBuffer"
-// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__detail::__heap_resource_info"
+// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
-// DXIL: call void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]],
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-// SPV: call spir_func void @hlsl::__detail::__resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]],
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__detail::__heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__detail::__heap_resource_info") align 4 [[TMP4]])
+// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]])
// CHECK: call {{(spir_func )*}}void @useAppendBuffer(hlsl::AppendStructuredBuffer<int>, int)
// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], i32 noundef 10)
diff --git a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
index 6356c54815f805..55ef4a1952f1a8 100644
--- a/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
+++ b/clang/test/SemaHLSL/Resources/Textures-SampleCmpLevelZero.hlsl
@@ -85,7 +85,7 @@ void main(COORD_TYPE loc, float cmp) {
// nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'const hlsl::SamplerComparisonState &' for 1st argument}}
// offset-error at +3 {{no matching member function for call to 'SampleCmpLevelZero'}}
// nooffset-error at +2 {{no viable conversion from 'SamplerState' to 'hlsl::SamplerComparisonState'}}
- // nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'hlsl::__detail::__heap_sampler_info' for 1st argument}}
+ // nooffset-note@*:* {{candidate constructor not viable: no known conversion from 'SamplerState' to 'hlsl::__detail::heap_sampler_info' for 1st argument}}
t.SampleCmpLevelZero(s2, loc, cmp);
#ifdef HAS_OFFSET
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
index bf99b7196366e2..a0337930831216 100644
--- a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
@@ -15,30 +15,30 @@ export void test(unsigned Index) {
Sampler = SamplerDescriptorHeap[Index + 1];
useSampler(SamplerDescriptorHeap[Index + 2]);
- // expected-error at +3 {{no viable conversion from '__heap_sampler_info' to 'RWBuffer<int>'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_sampler_info' to 'hlsl::__detail::__heap_resource_info' for 1st argument}}
+ // expected-error at +3 {{no viable conversion from 'heap_sampler_info' to 'RWBuffer<int>'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'hlsl::__detail::heap_resource_info' for 1st argument}}
RWBuffer<int> Buf2 = SamplerDescriptorHeap[Index];
- // expected-error at +3 {{no viable conversion from '__heap_resource_info' to 'SamplerState'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from '__heap_resource_info' to 'hlsl::__detail::__heap_sampler_info' for 1st argument}}
+ // expected-error at +3 {{no viable conversion from 'heap_resource_info' to 'SamplerState'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'hlsl::__detail::heap_sampler_info' for 1st argument}}
SamplerState Sampler2 = ResourceDescriptorHeap[Index];
// expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
Buf2 = SamplerDescriptorHeap[Index];
// expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_resource_info' to 'SamplerState' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'SamplerState' for 1st argument}}
Sampler2 = ResourceDescriptorHeap[Index];
// expected-error at +2 {{no matching function for call to 'useBuffer'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
useBuffer(SamplerDescriptorHeap[Index]);
// expected-error at +2 {{no matching function for call to 'useSampler'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from '__heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
useSampler(ResourceDescriptorHeap[Index]);
// expected-error at +1 {{no member named 'Load'}}
>From f4bea70990057f3bfee5c6860ac0041ab9da318e Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Tue, 15 Sep 2026 15:28:25 -0700
Subject: [PATCH 05/10] Remove TOC from doc
---
clang/docs/HLSL/DynamicResources.md | 4 ----
1 file changed, 4 deletions(-)
diff --git a/clang/docs/HLSL/DynamicResources.md b/clang/docs/HLSL/DynamicResources.md
index 3b5c4afccf6593..1f35bebd9bb863 100644
--- a/clang/docs/HLSL/DynamicResources.md
+++ b/clang/docs/HLSL/DynamicResources.md
@@ -1,9 +1,5 @@
# HLSL Dynamic Resources
-```{contents}
-:local: true
-```
-
## Introduction
[HLSL Dynamic Resources][dynamicresources] is a feature introduced in Shader
>From f702a109eb5f7732bb465379f9e5ca8178cae335 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Tue, 15 Sep 2026 19:25:57 -0700
Subject: [PATCH 06/10] Add DynamicResource.md to HLSL/HLSLDocs.md
---
clang/docs/HLSL/HLSLDocs.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/docs/HLSL/HLSLDocs.md b/clang/docs/HLSL/HLSLDocs.md
index 8b72ef88ee0c02..a52d11b9bc81a7 100644
--- a/clang/docs/HLSL/HLSLDocs.md
+++ b/clang/docs/HLSL/HLSLDocs.md
@@ -14,6 +14,7 @@ HLSLSupport
ExpectedDifferences
HLSLIRReference
ResourceTypes
+DynamicResources
EntryFunctions
FunctionCalls
AvailabilityDiagnostics
>From 525ff801feea67a55778d8f8af53a39228c9afb6 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Wed, 16 Sep 2026 15:07:11 -0700
Subject: [PATCH 07/10] update test to use Value
---
clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
index 2b1a7c275f7fb5..676dac794c3d90 100644
--- a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -72,7 +72,7 @@ export SamplerState testSampler(unsigned Index) {
}
void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
- Buffer.Append(1);
+ Buffer.Append(Value);
}
// CHECK-LABEL: testCounterBuffer
>From 914e02d9742aa0b0557a253d85419efc8fb99001 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Tue, 22 Sep 2026 17:10:29 -0700
Subject: [PATCH 08/10] fix decl context
---
clang/lib/Sema/HLSLExternalSemaSource.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index 02ad153e4f3a4a..48b18c3e02df7d 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -39,7 +39,7 @@ static NamespaceDecl *createImplicitNamespace(Sema &S, StringRef Name,
IdentifierInfo &II = AST.Idents.get(Name, tok::TokenKind::identifier);
LookupResult Result(S, &II, SourceLocation(), Sema::LookupNamespaceName);
NamespaceDecl *PrevDecl = nullptr;
- if (S.LookupQualifiedName(Result, AST.getTranslationUnitDecl()))
+ if (S.LookupQualifiedName(Result, DC))
PrevDecl = Result.getAsSingle<NamespaceDecl>();
NamespaceDecl *NS =
>From 575b45f33ea82f1ff988094840706d3418244fba Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 24 Sep 2026 11:03:09 -0700
Subject: [PATCH 09/10] fix new lines
---
clang/test/AST/HLSL/DynamicResources-AST.hlsl | 264 +++++++++---------
.../resources/dynamic-resources.hlsl | 218 +++++++--------
.../dynamic-resources-availability.hlsl | 26 +-
.../SemaHLSL/Resources/dynamic-resources.hlsl | 100 +++----
4 files changed, 304 insertions(+), 304 deletions(-)
diff --git a/clang/test/AST/HLSL/DynamicResources-AST.hlsl b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
index 7ec0ed7594e355..44acc5fd1ea189 100644
--- a/clang/test/AST/HLSL/DynamicResources-AST.hlsl
+++ b/clang/test/AST/HLSL/DynamicResources-AST.hlsl
@@ -1,132 +1,132 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -ast-dump %s | FileCheck %s
-
-// Global variables for ResourceDescriptorHeap and SamplerDescriptorHeap
-// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __detail::resource_descriptor_heap_struct' static internal-linkage
-// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
-
-// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __detail::sampler_descriptor_heap_struct' static internal-linkage
-// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
-
-void useBuffer(RWBuffer<int> Buffer) {}
-
-// CHECK-LABEL: FunctionDecl {{.*}} testInvocations
-export void testInvocations(unsigned Index) {
-
-// Buf1 declaration with direct initialization
-// CHECK: VarDecl {{.*}} Buf1 'RWBuffer<int>':'hlsl::RWBuffer<int>' cinit
-// CHECK-NEXT: ExprWithCleanups{{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>'
-
-// RWBuffer copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
-
-// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-
-// heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
-
-// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
-
- RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
-
-// Buf2 declaration initialized with default constructor (handle is poison)
-// CHECK: VarDecl {{.*}} Buf2 'RWBuffer<int>':'hlsl::RWBuffer<int>' callinit
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void ()'
-
-// Buf2 assignment operator
-// CHECK-NEXT: ExprWithCleanups
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'hlsl::RWBuffer<int>' lvalue '='
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int> &(*)(const hlsl::RWBuffer<int> &)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)' lvalue CXXMethod {{.*}} 'operator=' 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)'
-// CHECK-NEXT: DeclRefExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' lvalue Var {{.*}} 'Buf2' 'RWBuffer<int>':'hlsl::RWBuffer<int>'
-
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const hlsl::RWBuffer<int>' lvalue
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const hlsl::RWBuffer<int>' <NoOp>
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int>' <ConstructorConversion>
-
-// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-
-// heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
-
-// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
-
- RWBuffer<int> Buf2;
- Buf2 = ResourceDescriptorHeap[Index];
-
-// Call to useBuffer with a temporary RWBuffer constructed from ResourceDescriptorHeap[Index]
-// CHECK: CallExpr {{.*}} 'void'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(RWBuffer<int>)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'void (RWBuffer<int>)' lvalue Function {{.*}} 'useBuffer' 'void (RWBuffer<int>)'
-
-// RWBuffer copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
-
-// RWBuffer heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
-
-// heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
-
-// Indexing into ResourceDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
-// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
-
- useBuffer(ResourceDescriptorHeap[Index]);
-
-// CHECK: VarDecl {{.*}} Sampler 'SamplerState' cinit
-// CHECK-NEXT: ExprWithCleanups {{.*}} 'SamplerState'
-
-// SamplerState copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:16, col:53> 'SamplerState' 'void (const hlsl::SamplerState &)' elidable
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'const SamplerState' lvalue
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'const SamplerState' <NoOp>
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'SamplerState' <ConstructorConversion>
-
-// SamplerState heap info constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__detail::heap_sampler_info)'
-
-// heap_resource_info copy constructor
-// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__detail::heap_sampler_info' 'void (heap_sampler_info &&) noexcept' elidable
-
-// Indexing into SamplerDescriptorHeap
-// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'heap_sampler_info' xvalue
-// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> 'heap_sampler_info' '[]'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> 'heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> 'heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_sampler_info (uint32_t)'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__detail::sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __detail::sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __detail::sampler_descriptor_heap_struct'
-// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:48> 'unsigned int' <LValueToRValue>
-// CHECK-NEXT: DeclRefExpr {{.*}} <col:48> 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
-
- SamplerState Sampler = SamplerDescriptorHeap[Index];
-}
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -ast-dump %s | FileCheck %s
+
+// Global variables for ResourceDescriptorHeap and SamplerDescriptorHeap
+// CHECK: VarDecl {{.*}} used ResourceDescriptorHeap 'hlsl_private __detail::resource_descriptor_heap_struct' static internal-linkage
+// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
+
+// CHECK: VarDecl {{.*}} used SamplerDescriptorHeap 'hlsl_private __detail::sampler_descriptor_heap_struct' static internal-linkage
+// CHECK-NEXT: AvailabilityAttr {{.*}} shadermodel 6.6 0 0 "" "" 0
+
+void useBuffer(RWBuffer<int> Buffer) {}
+
+// CHECK-LABEL: FunctionDecl {{.*}} testInvocations
+export void testInvocations(unsigned Index) {
+
+// Buf1 declaration with direct initialization
+// CHECK: VarDecl {{.*}} Buf1 'RWBuffer<int>':'hlsl::RWBuffer<int>' cinit
+// CHECK-NEXT: ExprWithCleanups{{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>'
+
+// RWBuffer copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
+
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
+
+// Buf2 declaration initialized with default constructor (handle is poison)
+// CHECK: VarDecl {{.*}} Buf2 'RWBuffer<int>':'hlsl::RWBuffer<int>' callinit
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void ()'
+
+// Buf2 assignment operator
+// CHECK-NEXT: ExprWithCleanups
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'hlsl::RWBuffer<int>' lvalue '='
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int> &(*)(const hlsl::RWBuffer<int> &)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)' lvalue CXXMethod {{.*}} 'operator=' 'hlsl::RWBuffer<int> &(const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: DeclRefExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' lvalue Var {{.*}} 'Buf2' 'RWBuffer<int>':'hlsl::RWBuffer<int>'
+
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
+
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ RWBuffer<int> Buf2;
+ Buf2 = ResourceDescriptorHeap[Index];
+
+// Call to useBuffer with a temporary RWBuffer constructed from ResourceDescriptorHeap[Index]
+// CHECK: CallExpr {{.*}} 'void'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'void (*)(RWBuffer<int>)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'void (RWBuffer<int>)' lvalue Function {{.*}} 'useBuffer' 'void (RWBuffer<int>)'
+
+// RWBuffer copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (const hlsl::RWBuffer<int> &)'
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'const RWBuffer<int>':'const hlsl::RWBuffer<int>' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' <ConstructorConversion>
+
+// RWBuffer heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'RWBuffer<int>':'hlsl::RWBuffer<int>' 'void (hlsl::__detail::heap_resource_info)'
+
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} 'hlsl::__detail::heap_resource_info' 'void (heap_resource_info &&) noexcept' elidable
+
+// Indexing into ResourceDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} 'heap_resource_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} 'heap_resource_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'heap_resource_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'heap_resource_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_resource_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'hlsl::__detail::resource_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'hlsl_private __detail::resource_descriptor_heap_struct' lvalue Var {{.*}} 'ResourceDescriptorHeap' 'hlsl_private __detail::resource_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ useBuffer(ResourceDescriptorHeap[Index]);
+
+// CHECK: VarDecl {{.*}} Sampler 'SamplerState' cinit
+// CHECK-NEXT: ExprWithCleanups {{.*}} 'SamplerState'
+
+// SamplerState copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:16, col:53> 'SamplerState' 'void (const hlsl::SamplerState &)' elidable
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'const SamplerState' lvalue
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'const SamplerState' <NoOp>
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26, col:53> 'SamplerState' <ConstructorConversion>
+
+// SamplerState heap info constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'SamplerState' 'void (hlsl::__detail::heap_sampler_info)'
+
+// heap_resource_info copy constructor
+// CHECK-NEXT: CXXConstructExpr {{.*}} <col:26, col:53> 'hlsl::__detail::heap_sampler_info' 'void (heap_sampler_info &&) noexcept' elidable
+
+// Indexing into SamplerDescriptorHeap
+// CHECK-NEXT: MaterializeTemporaryExpr {{.*}} <col:26, col:53> 'heap_sampler_info' xvalue
+// CHECK-NEXT: CXXOperatorCallExpr {{.*}} <col:26, col:53> 'heap_sampler_info' '[]'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:47, col:53> 'heap_sampler_info (*)(uint32_t)' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:47, col:53> 'heap_sampler_info (uint32_t)' lvalue CXXMethod {{.*}} 'operator[]' 'heap_sampler_info (uint32_t)'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:26> 'hlsl::__detail::sampler_descriptor_heap_struct' lvalue <AddressSpaceConversion>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:26> 'hlsl_private __detail::sampler_descriptor_heap_struct' lvalue Var {{.*}} 'SamplerDescriptorHeap' 'hlsl_private __detail::sampler_descriptor_heap_struct'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} <col:48> 'unsigned int' <LValueToRValue>
+// CHECK-NEXT: DeclRefExpr {{.*}} <col:48> 'unsigned int' lvalue ParmVar {{.*}} 'Index' 'unsigned int'
+
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+}
diff --git a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
index 676dac794c3d90..18b3a7957a0e44 100644
--- a/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
+++ b/clang/test/CodeGenHLSL/resources/dynamic-resources.hlsl
@@ -1,109 +1,109 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library \
-// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,DXIL
-// RUN: %clang_cc1 -finclude-default-header -triple spirv-vulkan-library \
-// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,SPV
-
-// CHECK: %S = type <{ i32 }>
-
-// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::resource_descriptor_heap_struct" zeroinitializer, align 1
-// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::sampler_descriptor_heap_struct" zeroinitializer, align 1
-
-// CHECK-LABEL: testTypedBuffer
-export void testTypedBuffer(unsigned Index) {
-// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
-
-// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
-// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-
-// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
-// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-
-// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__detail::heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]])
- RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
-}
-
-struct S {
- int Value;
-};
-
-// CHECK-LABEL: testConstantBuffer
-export void testConstantBuffer(unsigned Index) {
-
-// CHECK: %CBS = alloca %"class.hlsl::ConstantBuffer"
-// CHECK: [[TMP1:%.*]] = alloca %"class.hlsl::ConstantBuffer"
-// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
-// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer()(ptr {{.*}} %CBS)
-
-// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
-// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-
-// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
-// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-
-// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__detail::heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 %{{.*}})
-
-// CHECK: call {{.*}} ptr @hlsl::ConstantBuffer<S>::operator=(hlsl::ConstantBuffer<S> const&)
-// CHECK-SAME: (ptr {{.*}} %CBS, ptr {{.*}} [[TMP1]])
- ConstantBuffer<S> CBS;
- CBS = ResourceDescriptorHeap[Index];
-}
-
-// CHECK: define {{(spir_func )*}}void @testSampler(unsigned int)(ptr {{.*}} sret(%"class.hlsl::SamplerState") align {{(4|8)}} [[RESULT:%.*]], i32 noundef %Index)
-// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__detail::heap_sampler_info"
-export SamplerState testSampler(unsigned Index) {
-
-// DXIL: call void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
-// DXIL-SAME: ptr {{.*}} @hlsl::SamplerDescriptorHeap, i32 noundef %{{[0-9]+}})
-
-// SPV: call spir_func void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
-// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::SamplerDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-
-// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__detail::heap_sampler_info)
-// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]])
- return SamplerDescriptorHeap[Index];
-}
-
-void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
- Buffer.Append(Value);
-}
-
-// CHECK-LABEL: testCounterBuffer
-export void testCounterBuffer(unsigned Index) {
-// CHECK: [[TMP_BUFFER:%.*]] = alloca %"class.hlsl::AppendStructuredBuffer"
-// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
-
-// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
-// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
-
-// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
-// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
-// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
-
-// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__detail::heap_resource_info)
-// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]])
-
-// CHECK: call {{(spir_func )*}}void @useAppendBuffer(hlsl::AppendStructuredBuffer<int>, int)
-// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], i32 noundef 10)
- useAppendBuffer(ResourceDescriptorHeap[Index], 10);
-}
-
-// DXIL-DAG: call target("dx.TypedBuffer", i32, 1, 0, 1) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// DXIL-DAG: call target("dx.CBuffer", %S) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// DXIL-DAG: call target("dx.Sampler", 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// DXIL-DAG: call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// DXIL-NOT: counterhandlefromheap
-
-// SPV-DAG: call target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 24) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// SPV-DAG: call target("spirv.VulkanBuffer", %S, 2, 0) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// SPV-DAG: call target("spirv.Sampler") @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// SPV-DAG: call target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
-// SPV-DAG: call target("spirv.VulkanBuffer", i32, 12, 1) @llvm.spv.resource.counterhandlefromheap{{.*}}(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %{{.*}}) [ "convergencectrl"(token %{{.*}}) ]
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library \
+// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,DXIL
+// RUN: %clang_cc1 -finclude-default-header -triple spirv-vulkan-library \
+// RUN: -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt | FileCheck %s --check-prefixes=CHECK,SPV
+
+// CHECK: %S = type <{ i32 }>
+
+// CHECK: @hlsl::ResourceDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::resource_descriptor_heap_struct" zeroinitializer, align 1
+// CHECK: @hlsl::SamplerDescriptorHeap = internal {{.*}}global %"struct.hlsl::__detail::sampler_descriptor_heap_struct" zeroinitializer, align 1
+
+// CHECK-LABEL: testTypedBuffer
+export void testTypedBuffer(unsigned Index) {
+// CHECK: [[TMP0:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
+
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::RWBuffer<int>::RWBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} %Buffer, ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP0]])
+ RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
+}
+
+struct S {
+ int Value;
+};
+
+// CHECK-LABEL: testConstantBuffer
+export void testConstantBuffer(unsigned Index) {
+
+// CHECK: %CBS = alloca %"class.hlsl::ConstantBuffer"
+// CHECK: [[TMP1:%.*]] = alloca %"class.hlsl::ConstantBuffer"
+// CHECK: [[TMP2:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer()(ptr {{.*}} %CBS)
+
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP2]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::ConstantBuffer<S>::ConstantBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP1]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 %{{.*}})
+
+// CHECK: call {{.*}} ptr @hlsl::ConstantBuffer<S>::operator=(hlsl::ConstantBuffer<S> const&)
+// CHECK-SAME: (ptr {{.*}} %CBS, ptr {{.*}} [[TMP1]])
+ ConstantBuffer<S> CBS;
+ CBS = ResourceDescriptorHeap[Index];
+}
+
+// CHECK: define {{(spir_func )*}}void @testSampler(unsigned int)(ptr {{.*}} sret(%"class.hlsl::SamplerState") align {{(4|8)}} [[RESULT:%.*]], i32 noundef %Index)
+// CHECK: [[TMP3:%.*]] = alloca %"class.hlsl::__detail::heap_sampler_info"
+export SamplerState testSampler(unsigned Index) {
+
+// DXIL: call void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
+// DXIL-SAME: ptr {{.*}} @hlsl::SamplerDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__detail::sampler_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::SamplerDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::SamplerState::SamplerState(hlsl::__detail::heap_sampler_info)
+// CHECK-SAME: (ptr {{.*}} [[RESULT]], ptr noundef byval(%"class.hlsl::__detail::heap_sampler_info") align 4 [[TMP3]])
+ return SamplerDescriptorHeap[Index];
+}
+
+void useAppendBuffer(AppendStructuredBuffer<int> Buffer, int Value) {
+ Buffer.Append(Value);
+}
+
+// CHECK-LABEL: testCounterBuffer
+export void testCounterBuffer(unsigned Index) {
+// CHECK: [[TMP_BUFFER:%.*]] = alloca %"class.hlsl::AppendStructuredBuffer"
+// CHECK: [[TMP4:%.*]] = alloca %"class.hlsl::__detail::heap_resource_info"
+
+// DXIL: call void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// DXIL-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
+// DXIL-SAME: ptr {{.*}} @hlsl::ResourceDescriptorHeap, i32 noundef %{{[0-9]+}})
+
+// SPV: call spir_func void @hlsl::__detail::resource_descriptor_heap_struct::operator[](unsigned int)
+// SPV-SAME: (ptr {{.*}} sret(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]],
+// SPV-SAME: ptr {{.*}} addrspacecast ({{.*}} @hlsl::ResourceDescriptorHeap to ptr), i32 noundef %{{[0-9]+}})
+
+// CHECK: call {{(spir_func )*}}void @hlsl::AppendStructuredBuffer<int>::AppendStructuredBuffer(hlsl::__detail::heap_resource_info)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], ptr noundef byval(%"class.hlsl::__detail::heap_resource_info") align 4 [[TMP4]])
+
+// CHECK: call {{(spir_func )*}}void @useAppendBuffer(hlsl::AppendStructuredBuffer<int>, int)
+// CHECK-SAME: (ptr {{.*}} [[TMP_BUFFER]], i32 noundef 10)
+ useAppendBuffer(ResourceDescriptorHeap[Index], 10);
+}
+
+// DXIL-DAG: call target("dx.TypedBuffer", i32, 1, 0, 1) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.CBuffer", %S) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.Sampler", 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-DAG: call target("dx.RawBuffer", i32, 1, 0) @llvm.dx.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// DXIL-NOT: counterhandlefromheap
+
+// SPV-DAG: call target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 24) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", %S, 2, 0) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.Sampler") @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", [0 x i32], 12, 1) @llvm.spv.resource.handlefromheap{{.*}}(i32 %{{.*}})
+// SPV-DAG: call target("spirv.VulkanBuffer", i32, 12, 1) @llvm.spv.resource.counterhandlefromheap{{.*}}(target("spirv.VulkanBuffer", [0 x i32], 12, 1) %{{.*}}) [ "convergencectrl"(token %{{.*}}) ]
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
index dc9f0332da9c9d..f1fb89790d0105 100644
--- a/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources-availability.hlsl
@@ -1,13 +1,13 @@
-// RUN: %clang_cc1 -finclude-default-header -fhlsl-strict-availability \
-// RUN: -triple dxil-pc-shadermodel6.5-library -verify %s
-
-export void testUnavailable(unsigned Index) {
-
- // expected-error at +2 {{'ResourceDescriptorHeap' is only available on Shader Model 6.6 or newer}}
- // expected-note at hlsl/hlsl_resources.h:* {{'ResourceDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
- RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
-
- // expected-error at +2 {{'SamplerDescriptorHeap' is only available on Shader Model 6.6 or newer}}
- // expected-note at hlsl/hlsl_resources.h:* {{'SamplerDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
- SamplerState Sampler = SamplerDescriptorHeap[Index];
-}
+// RUN: %clang_cc1 -finclude-default-header -fhlsl-strict-availability \
+// RUN: -triple dxil-pc-shadermodel6.5-library -verify %s
+
+export void testUnavailable(unsigned Index) {
+
+ // expected-error at +2 {{'ResourceDescriptorHeap' is only available on Shader Model 6.6 or newer}}
+ // expected-note at hlsl/hlsl_resources.h:* {{'ResourceDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
+ RWBuffer<int> Buffer = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{'SamplerDescriptorHeap' is only available on Shader Model 6.6 or newer}}
+ // expected-note at hlsl/hlsl_resources.h:* {{'SamplerDescriptorHeap' has been marked as being introduced in Shader Model 6.6 here, but the deployment target is Shader Model 6.5}}
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+}
diff --git a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
index a0337930831216..03eab490b65cb6 100644
--- a/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
+++ b/clang/test/SemaHLSL/Resources/dynamic-resources.hlsl
@@ -1,50 +1,50 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -verify %s
-
-void useBuffer(RWBuffer<int> Buffer) {}
-void useSampler(SamplerState Sampler) {}
-
-export void test(unsigned Index) {
-
- // valid
- RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
- Buf1 = ResourceDescriptorHeap[Index + 1];
- useBuffer(ResourceDescriptorHeap[Index + 2]);
-
- // valid
- SamplerState Sampler = SamplerDescriptorHeap[Index];
- Sampler = SamplerDescriptorHeap[Index + 1];
- useSampler(SamplerDescriptorHeap[Index + 2]);
-
- // expected-error at +3 {{no viable conversion from 'heap_sampler_info' to 'RWBuffer<int>'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'hlsl::__detail::heap_resource_info' for 1st argument}}
- RWBuffer<int> Buf2 = SamplerDescriptorHeap[Index];
-
- // expected-error at +3 {{no viable conversion from 'heap_resource_info' to 'SamplerState'}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
- // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'hlsl::__detail::heap_sampler_info' for 1st argument}}
- SamplerState Sampler2 = ResourceDescriptorHeap[Index];
-
- // expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
- Buf2 = SamplerDescriptorHeap[Index];
-
- // expected-error at +2 {{no viable overloaded '='}}
- // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'SamplerState' for 1st argument}}
- Sampler2 = ResourceDescriptorHeap[Index];
-
- // expected-error at +2 {{no matching function for call to 'useBuffer'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
- useBuffer(SamplerDescriptorHeap[Index]);
-
- // expected-error at +2 {{no matching function for call to 'useSampler'}}
- // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
- useSampler(ResourceDescriptorHeap[Index]);
-
- // expected-error at +1 {{no member named 'Load'}}
- ResourceDescriptorHeap[Index].Load(0);
-
- // expected-error at +1 {{no member named 'Sample'}}
- SamplerDescriptorHeap[Index].Sample(0);
-
-}
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library -verify %s
+
+void useBuffer(RWBuffer<int> Buffer) {}
+void useSampler(SamplerState Sampler) {}
+
+export void test(unsigned Index) {
+
+ // valid
+ RWBuffer<int> Buf1 = ResourceDescriptorHeap[Index];
+ Buf1 = ResourceDescriptorHeap[Index + 1];
+ useBuffer(ResourceDescriptorHeap[Index + 2]);
+
+ // valid
+ SamplerState Sampler = SamplerDescriptorHeap[Index];
+ Sampler = SamplerDescriptorHeap[Index + 1];
+ useSampler(SamplerDescriptorHeap[Index + 2]);
+
+ // expected-error at +3 {{no viable conversion from 'heap_sampler_info' to 'RWBuffer<int>'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int> &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_sampler_info' to 'hlsl::__detail::heap_resource_info' for 1st argument}}
+ RWBuffer<int> Buf2 = SamplerDescriptorHeap[Index];
+
+ // expected-error at +3 {{no viable conversion from 'heap_resource_info' to 'SamplerState'}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState &' for 1st argument}}
+ // expected-note@*:* {{candidate constructor not viable: no known conversion from 'heap_resource_info' to 'hlsl::__detail::heap_sampler_info' for 1st argument}}
+ SamplerState Sampler2 = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{no viable overloaded '='}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'RWBuffer<int>' for 1st argument}}
+ Buf2 = SamplerDescriptorHeap[Index];
+
+ // expected-error at +2 {{no viable overloaded '='}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'SamplerState' for 1st argument}}
+ Sampler2 = ResourceDescriptorHeap[Index];
+
+ // expected-error at +2 {{no matching function for call to 'useBuffer'}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_sampler_info' to 'const hlsl::RWBuffer<int>' for 1st argument}}
+ useBuffer(SamplerDescriptorHeap[Index]);
+
+ // expected-error at +2 {{no matching function for call to 'useSampler'}}
+ // expected-note@*:* {{candidate function not viable: no known conversion from 'heap_resource_info' to 'const hlsl::SamplerState' for 1st argument}}
+ useSampler(ResourceDescriptorHeap[Index]);
+
+ // expected-error at +1 {{no member named 'Load'}}
+ ResourceDescriptorHeap[Index].Load(0);
+
+ // expected-error at +1 {{no member named 'Sample'}}
+ SamplerDescriptorHeap[Index].Sample(0);
+
+}
>From a0bc24787fa54236053d7c8eaffbe235ea2de5bf Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 24 Sep 2026 11:04:07 -0700
Subject: [PATCH 10/10] Add new header to list
---
llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
index dcf48343fd8048..84e16126231acb 100644
--- a/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -272,6 +272,7 @@ copy("Headers") {
"hlsl/hlsl_detail.h",
"hlsl/hlsl_intrinsic_helpers.h",
"hlsl/hlsl_intrinsics.h",
+ "hlsl/hlsl_resources.h",
"hlsl/hlsl_spirv.h",
"hresetintrin.h",
"htmintrin.h",
More information about the llvm-commits
mailing list