diff --git a/include/dxc/DXIL/DxilResourceProperties.h b/include/dxc/DXIL/DxilResourceProperties.h index 2f4ff58969..7136f90d7e 100644 --- a/include/dxc/DXIL/DxilResourceProperties.h +++ b/include/dxc/DXIL/DxilResourceProperties.h @@ -16,6 +16,7 @@ namespace llvm { class Constant; class Type; +class Module; } // namespace llvm namespace hlsl { @@ -89,6 +90,7 @@ struct DxilInst_AnnotateHandle; namespace resource_helper { llvm::Constant *getAsConstant(const DxilResourceProperties &, llvm::Type *Ty, const ShaderModel &); +llvm::Type *GetResourcePropertiesType(llvm::Module &M); DxilResourceProperties loadPropsFromConstant(const llvm::Constant &C); DxilResourceProperties loadPropsFromAnnotateHandle(DxilInst_AnnotateHandle &annotateHandle, diff --git a/lib/DXIL/DxilMetadataHelper.cpp b/lib/DXIL/DxilMetadataHelper.cpp index 9598fa3da4..60e7a04183 100644 --- a/lib/DXIL/DxilMetadataHelper.cpp +++ b/lib/DXIL/DxilMetadataHelper.cpp @@ -1345,8 +1345,7 @@ Metadata *DxilMDHelper::EmitDxilFieldAnnotation(const DxilFieldAnnotation &FA) { MDVals.emplace_back(Uint32ToConstMD(kDxilFieldAnnotationResPropTag)); MDVals.emplace_back(ValueAsMetadata::get(resource_helper::getAsConstant( FA.GetResourceProperties(), - m_pModule->GetDxilModule().GetOP()->GetResourcePropertiesType(), - *m_pSM))); + resource_helper::GetResourcePropertiesType(*m_pModule), *m_pSM))); } if (DXIL::CompareVersions(m_MinValMajor, m_MinValMinor, 1, 7) >= 0) { if (FA.HasBitFields()) { diff --git a/lib/DXIL/DxilOperations.cpp b/lib/DXIL/DxilOperations.cpp index b786fee9fc..101d98e2e0 100644 --- a/lib/DXIL/DxilOperations.cpp +++ b/lib/DXIL/DxilOperations.cpp @@ -4118,9 +4118,8 @@ OP::OP(LLVMContext &Ctx, Module *pModule) "dx.types.NodeHandle", pModule); m_pNodeRecordHandleType = GetOrCreateStructType( m_Ctx, Type::getInt8PtrTy(m_Ctx), "dx.types.NodeRecordHandle", pModule); - m_pResourcePropertiesType = GetOrCreateStructType( - m_Ctx, {Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx)}, - "dx.types.ResourceProperties", pModule); + m_pResourcePropertiesType = + hlsl::resource_helper::GetResourcePropertiesType(*pModule); m_pNodePropertiesType = GetOrCreateStructType( m_Ctx, {Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx)}, "dx.types.NodeInfo", pModule); diff --git a/lib/DXIL/DxilResourceProperties.cpp b/lib/DXIL/DxilResourceProperties.cpp index 54ab24f36e..8ad6db4b72 100644 --- a/lib/DXIL/DxilResourceProperties.cpp +++ b/lib/DXIL/DxilResourceProperties.cpp @@ -19,6 +19,7 @@ #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Module.h" using namespace llvm; @@ -104,6 +105,17 @@ Constant *getAsConstant(const DxilResourceProperties &RP, Type *Ty, return nullptr; } +llvm::Type *GetResourcePropertiesType(Module &M) { + LLVMContext &Ctx = M.getContext(); + StringRef Name = "dx.types.ResourceProperties"; + if (StructType *ST = M.getTypeByName(Name)) + return ST; + + Type *Int32Ty = Type::getInt32Ty(Ctx); + Type *Elements[] = {Int32Ty, Int32Ty}; + return StructType::create(Ctx, Elements, Name); +} + DxilResourceProperties loadPropsFromConstant(const Constant &C) { DxilResourceProperties RP; diff --git a/tools/clang/test/CodeGenDXIL/hlsl/functions/hl-annotation-resource-param.hlsl b/tools/clang/test/CodeGenDXIL/hlsl/functions/hl-annotation-resource-param.hlsl new file mode 100644 index 0000000000..8df685f0d5 --- /dev/null +++ b/tools/clang/test/CodeGenDXIL/hlsl/functions/hl-annotation-resource-param.hlsl @@ -0,0 +1,22 @@ +// REQUIRES: dxil-1-8 +// RUN: %dxc -T cs_6_8 -fcgl %s | FileCheck %s + +// CHECK: %dx.types.ResourceProperties = type { i32, i32 } +// CHECK: !dx.typeAnnotations = !{![[TYPE_ANNOTATIONS:[0-9]+]]} +// CHECK: ![[TYPE_ANNOTATIONS]] = !{ +// CHECK-SAME: void (%struct.RWByteAddressBuffer*)* @"\01?foo@@YAXURWByteAddressBuffer@@@Z", ![[FN_ANN:[0-9]+]] +// CHECK: ![[FN_ANN]] = !{!{{[0-9]+}}, ![[PARAM_ANN:[0-9]+]]} +// CHECK: ![[PARAM_ANN]] = !{i32 0, ![[FIELD_ANN:[0-9]+]], !{{[0-9]+}}} +// CHECK: ![[FIELD_ANN]] = !{ +// CHECK-SAME: i32 10, %dx.types.ResourceProperties { i32 4107, i32 0 } + +RWByteAddressBuffer OutBuff : register(u0); + +void foo(RWByteAddressBuffer Buf) { + Buf.Store(0, 42); +} + +[numthreads(8, 1, 1)] +void main() { + foo(OutBuff); +}