llvm-project/clang/test/SemaHLSL/Texture2D-Load-errors.hlsl
Steven Perron f3752dcb60
[HLSL] Implement Texture2D::Load methods and builtin (#185708)
Implements the Textur2D::Load methods. A new HLSL buildin is added to
implement the method. The HLSL builtin is lowered to the
resource_load_level intrinsic.

We chose to have have a single operand hold both the coordinate and the
level in the builtin, as is done in the Load method itself. This was to
make the external sema source easier. It is easier to split the vector
during codegen than in sema.

Assisted-by: Gemini
2026-03-12 07:08:26 -04:00

44 lines
2.3 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -finclude-default-header -verify %s
Texture2D<float4> t;
float4 test_too_few_args() {
return t.Load(); // expected-error {{no matching member function for call to 'Load'}}
// expected-note@*:* {{candidate function not viable: requires single argument 'Location', but no arguments were provided}}
// expected-note@*:* {{candidate function not viable: requires 2 arguments, but 0 were provided}}
}
float4 test_too_many_args(int2 loc) {
return t.Load(int3(loc, 0), int2(1, 1), 1); // expected-error {{no matching member function for call to 'Load'}}
// expected-note@*:* {{candidate function not viable: requires 2 arguments, but 3 were provided}}
// expected-note@*:* {{candidate function not viable: requires single argument 'Location', but 3 arguments were provided}}
}
float4 test_invalid_coord_type(float2 loc) {
return t.Load(float3(loc, 0)); // expected-warning {{implicit conversion turns floating-point number into integer: 'float3' (aka 'vector<float, 3>') to 'vector<int, 3>'}}
}
float4 test_invalid_offset_type(int2 loc, float2 offset) {
return t.Load(int3(loc, 0), offset); // expected-warning {{implicit conversion turns floating-point number into integer: 'float2' (aka 'vector<float, 2>') to 'vector<int, 2>'}}
}
float4 test_invalid_location_count(int2 loc) {
return t.Load(loc); // expected-error {{no matching member function for call to 'Load'}}
// expected-note@*:* {{candidate function not viable: no known conversion from 'int2' (aka 'vector<int, 2>') to 'vector<int, 3>' (vector of 3 'int' values) for 1st argument}}
// expected-note@*:* {{candidate function not viable: requires 2 arguments, but 1 was provided}}
}
float4 test_truncated_location_count(int4 loc) {
return t.Load(loc); // expected-warning {{implicit conversion truncates vector: 'int4' (aka 'vector<int, 4>') to 'vector<int, 3>' (vector of 3 'int' values)}}
}
float4 test_splatted_offset_count(int3 loc, int offset) {
// No errors expected. The vector will be generated by splatting `offset`.
return t.Load(loc, offset);
}
float4 test_truncated_offset_count(int2 loc, int3 offset) {
return t.Load(int3(loc, 0), offset); // expected-warning {{implicit conversion truncates vector: 'int3' (aka 'vector<int, 3>') to 'vector<int, 2>' (vector of 2 'int' values)}}
}