|
| 1 | +// RUN: %dxc -T cs_6_0 -E main -HV 202x -fcgl %s -spirv | FileCheck %s |
| 2 | + |
| 3 | +// Test that the 'auto' keyword can be used to declare variables with inferred |
| 4 | +// types from initialization expressions when targeting SPIR-V. |
| 5 | + |
| 6 | +// CHECK: [[INT:%[a-zA-Z0-9_]+]] = OpTypeInt 32 1 |
| 7 | +// CHECK: [[INT_1:%[a-zA-Z0-9_]+]] = OpConstant [[INT]] 1 |
| 8 | +// CHECK: [[FLOAT:%[a-zA-Z0-9_]+]] = OpTypeFloat 32 |
| 9 | +// CHECK: [[FLOAT_2:%[a-zA-Z0-9_]+]] = OpConstant [[FLOAT]] 2 |
| 10 | +// CHECK: [[BOOL:%[a-zA-Z0-9_]+]] = OpTypeBool |
| 11 | +// CHECK: [[TRUE:%[a-zA-Z0-9_]+]] = OpConstantTrue [[BOOL]] |
| 12 | +// CHECK: [[V4FLOAT:%[a-zA-Z0-9_]+]] = OpTypeVector [[FLOAT]] 4 |
| 13 | +// CHECK: [[VEC_CONST:%[a-zA-Z0-9_]+]] = OpConstantComposite [[V4FLOAT]] {{%[a-zA-Z0-9_]+}} [[FLOAT_2]] {{%[a-zA-Z0-9_]+}} {{%[a-zA-Z0-9_]+}} |
| 14 | + |
| 15 | +// CHECK: [[PTR_INT:%_ptr_Function_int]] = OpTypePointer Function [[INT]] |
| 16 | +// CHECK: [[PTR_FLOAT:%_ptr_Function_float]] = OpTypePointer Function [[FLOAT]] |
| 17 | +// CHECK: [[PTR_BOOL:%_ptr_Function_bool]] = OpTypePointer Function [[BOOL]] |
| 18 | +// CHECK: [[PTR_V4FLOAT:%_ptr_Function_v4float]] = OpTypePointer Function [[V4FLOAT]] |
| 19 | + |
| 20 | +// CHECK: %a = OpVariable [[PTR_INT]] Function |
| 21 | +// CHECK: %b = OpVariable [[PTR_FLOAT]] Function |
| 22 | +// CHECK: %c = OpVariable [[PTR_BOOL]] Function |
| 23 | +// CHECK: %d = OpVariable [[PTR_V4FLOAT]] Function |
| 24 | +// CHECK: %sum = OpVariable [[PTR_INT]] Function |
| 25 | +// CHECK: %product = OpVariable [[PTR_FLOAT]] Function |
| 26 | + |
| 27 | +// CHECK: OpStore %a [[INT_1]] |
| 28 | +// CHECK: OpStore %b [[FLOAT_2]] |
| 29 | +// CHECK: OpStore %c [[TRUE]] |
| 30 | +// CHECK: OpStore %d [[VEC_CONST]] |
| 31 | + |
| 32 | +RWBuffer<float> output : register(u0); |
| 33 | + |
| 34 | +[numthreads(1,1,1)] |
| 35 | +void main() { |
| 36 | + // Auto deduces int from integer literal |
| 37 | + auto a = 1; |
| 38 | + // Auto deduces float from float literal |
| 39 | + auto b = 2.0f; |
| 40 | + // Auto deduces bool from bool literal |
| 41 | + auto c = true; |
| 42 | + // Auto deduces float4 from vector type |
| 43 | + auto d = float4(1.0f, 2.0f, 3.0f, 4.0f); |
| 44 | + |
| 45 | + // Auto from arithmetic expressions |
| 46 | + auto sum = a + a; |
| 47 | + auto product = b * b; |
| 48 | + |
| 49 | + // Use the values to prevent dead-code elimination |
| 50 | + output[0] = (float)sum + product + d.x + (float)c; |
| 51 | +} |
0 commit comments