[HLSL] Add parsing for the resource dimension attribute. (#185039)
The resource attribute was added, but the code to be able to parse it as we do with other resource attributes was missing. This means we are not able to test the attribute in isolation. This change adds the parsing for the attribute, and adds more testing for it. Assisted-by: Gemini <!-- branch-stack-start --> ------------------------- - main - https://github.com/llvm/llvm-project/pull/185039 👈 <sup>[Stack](https://www.git-town.com/how-to/proposal-breadcrumb.html) generated by [Git Town](https://github.com/git-town/git-town)</sup> <!-- branch-stack-end -->
This commit is contained in:
parent
7b7ff905f4
commit
afedb030d6
@ -2142,6 +2142,24 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) {
|
||||
break;
|
||||
}
|
||||
|
||||
case ParsedAttr::AT_HLSLResourceDimension: {
|
||||
StringRef Identifier;
|
||||
SourceLocation ArgLoc;
|
||||
if (!SemaRef.checkStringLiteralArgumentAttr(AL, 0, Identifier, &ArgLoc))
|
||||
return false;
|
||||
|
||||
// Validate resource dimension value
|
||||
llvm::dxil::ResourceDimension RD;
|
||||
if (!HLSLResourceDimensionAttr::ConvertStrToResourceDimension(Identifier,
|
||||
RD)) {
|
||||
Diag(ArgLoc, diag::warn_attribute_type_not_supported)
|
||||
<< "ResourceDimension" << Identifier;
|
||||
return false;
|
||||
}
|
||||
A = HLSLResourceDimensionAttr::Create(getASTContext(), RD, ACI);
|
||||
break;
|
||||
}
|
||||
|
||||
case ParsedAttr::AT_HLSLROV:
|
||||
A = HLSLROVAttr::Create(getASTContext(), ACI);
|
||||
break;
|
||||
|
||||
@ -9329,6 +9329,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
|
||||
break;
|
||||
}
|
||||
case ParsedAttr::AT_HLSLResourceClass:
|
||||
case ParsedAttr::AT_HLSLResourceDimension:
|
||||
case ParsedAttr::AT_HLSLROV:
|
||||
case ParsedAttr::AT_HLSLRawBuffer:
|
||||
case ParsedAttr::AT_HLSLContainedType: {
|
||||
|
||||
17
clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl
Normal file
17
clang/test/ParserHLSL/hlsl_resource_dimension_attr.hlsl
Normal file
@ -0,0 +1,17 @@
|
||||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o - %s | FileCheck %s
|
||||
|
||||
// CHECK: VarDecl {{.*}} res1D '__hlsl_resource_t
|
||||
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(1D)]]
|
||||
__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("1D")]] res1D;
|
||||
|
||||
// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} res2D '__hlsl_resource_t
|
||||
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(2D)]]
|
||||
__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("2D")]] res2D;
|
||||
|
||||
// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} res3D '__hlsl_resource_t
|
||||
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(3D)]]
|
||||
__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("3D")]] res3D;
|
||||
|
||||
// CHECK: VarDecl 0x{{[0-9a-f]+}} {{.*}} resCube '__hlsl_resource_t
|
||||
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(SRV)]] [[hlsl::resource_dimension(Cube)]]
|
||||
__hlsl_resource_t [[hlsl::resource_class(SRV)]] [[hlsl::dimension("Cube")]] resCube;
|
||||
@ -0,0 +1,19 @@
|
||||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - %s -verify
|
||||
|
||||
// expected-error@+1{{'hlsl::dimension' attribute cannot be applied to a declaration}}
|
||||
[[hlsl::dimension("2D")]] __hlsl_resource_t e0;
|
||||
|
||||
// expected-error@+1{{'hlsl::dimension' attribute takes one argument}}
|
||||
__hlsl_resource_t [[hlsl::dimension()]] e1;
|
||||
|
||||
// expected-error@+1{{expected string literal as argument of 'dimension' attribute}}
|
||||
__hlsl_resource_t [[hlsl::dimension(2)]] e2;
|
||||
|
||||
// expected-warning@+1{{ResourceDimension attribute argument not supported: gibberish}}
|
||||
__hlsl_resource_t [[hlsl::dimension("gibberish")]] e3;
|
||||
|
||||
// expected-error@+1{{'hlsl::dimension' attribute takes one argument}}
|
||||
__hlsl_resource_t [[hlsl::dimension("2D", "3D")]] e4;
|
||||
|
||||
// expected-error@+1{{attribute 'hlsl::dimension' can be used only on HLSL intangible type '__hlsl_resource_t'}}
|
||||
float [[hlsl::dimension("2D")]] e5;
|
||||
Loading…
x
Reference in New Issue
Block a user