mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 15:06:36 +00:00

The space parameter in the register binding annotation may not be used for global constants. There was previously no diagnostic emitted when this case occurred. This PR adds a diagnostic when this case occurs, and tests these cases. A new file was made to specifically test the space parameter, so some cases in `\clang\test\SemaHLSL\resource_binding_attr_error.hlsl` were moved over to this new file. Fixes #104521
68 lines
2.3 KiB
HLSL
68 lines
2.3 KiB
HLSL
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
|
|
|
|
template<typename T>
|
|
struct MyTemplatedSRV {
|
|
__hlsl_resource_t [[hlsl::resource_class(SRV)]] x;
|
|
};
|
|
|
|
// valid, The register keyword in this statement isn't binding a resource, rather it is
|
|
// specifying a constant register binding offset within the $Globals cbuffer, which is legacy behavior from DX9.
|
|
float a : register(c0);
|
|
|
|
// expected-error@+1 {{binding type 'i' ignored. The 'integer constant' binding type is no longer supported}}
|
|
cbuffer b : register(i0) {
|
|
|
|
}
|
|
|
|
// expected-error@+1 {{register number should be an integer}}
|
|
cbuffer c : register(bf, s2) {
|
|
|
|
}
|
|
|
|
// expected-error@+1 {{expected identifier}}
|
|
cbuffer A : register() {}
|
|
|
|
// expected-error@+1 {{register number should be an integer}}
|
|
cbuffer B : register(space1) {}
|
|
|
|
// expected-error@+1 {{wrong argument format for hlsl attribute, use b2 instead}}
|
|
cbuffer C : register(b 2) {}
|
|
|
|
// expected-error@+1 {{wrong argument format for hlsl attribute, use b2 instead}}
|
|
cbuffer D : register(b 2, space3) {}
|
|
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
static MyTemplatedSRV<float> U : register(u5);
|
|
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
static float sa : register(c1);
|
|
|
|
float x[2] : register(c2); // valid
|
|
float y[2][2] : register(c3); // valid
|
|
float z[2][2][3] : register(c4); // valid
|
|
|
|
// expected-error@+1 {{binding type 'c' only applies to numeric variables in the global scope}}
|
|
groupshared float fa[10] : register(c5);
|
|
|
|
void foo() {
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
MyTemplatedSRV<float> U : register(u3);
|
|
}
|
|
void foo2() {
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
extern MyTemplatedSRV<float> U2 : register(u5);
|
|
}
|
|
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
void bar(MyTemplatedSRV<float> U : register(u3)) {
|
|
|
|
}
|
|
|
|
struct S {
|
|
// expected-error@+1 {{'register' attribute only applies to cbuffer/tbuffer and external global variables}}
|
|
MyTemplatedSRV<float> U : register(u3);
|
|
};
|
|
|
|
// expected-error@+1 {{binding type 'z' is invalid}}
|
|
MyTemplatedSRV<float> U3 : register(z5);
|