llvm-project/clang/test/CodeGenHLSL/semantics/semantic-struct-nested.hlsl
Nathan Gauër 865cd8ea02
[HLSL] Allow input semantics on structs (#159047)
This PR is an incremental improvement regarding semantics I/O in HLSL.
This PR allows
system semantics to be used on struct type in addition to parameters
(state today).
This PR doesn't consider implicit indexing increment that happens when
placing a semantic on an aggregate/array as implemented system semantics
don't allow such use yet.

The next step will be to enable user semantics, which will bring the
need to properly determine semantic indices depending on context.
This PR diverge from the initial wg-hlsl proposal as all diagnostics are
done in Sema (initial proposal suggested running diags in codegen).

This is not yet a solid semantic implementation, but increases the test
coverage and improves the status from where we are now.
2025-10-23 15:49:35 +02:00

31 lines
1.5 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL -DTARGET=dx
// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV -DTARGET=spv
struct Inner {
uint Gid : SV_GroupID;
};
struct Input {
uint Idx : SV_DispatchThreadID;
Inner inner;
};
// Make sure SV_DispatchThreadID translated into dx.thread.id.
// CHECK: define void @foo()
// CHECK-DXIL: %[[#ID:]] = call i32 @llvm.[[TARGET]].thread.id(i32 0)
// CHECK-SPIRV: %[[#ID:]] = call i32 @llvm.[[TARGET]].thread.id.i32(i32 0)
// CHECK: %[[#TMP1:]] = insertvalue %struct.Input poison, i32 %[[#ID]], 0
// CHECK-DXIL: %[[#GID:]] = call i32 @llvm.[[TARGET]].group.id(i32 0)
// CHECK-SPIRV:%[[#GID:]] = call i32 @llvm.[[TARGET]].group.id.i32(i32 0)
// CHECK: %[[#TMP2:]] = insertvalue %struct.Inner poison, i32 %[[#GID]], 0
// CHECK: %[[#TMP3:]] = insertvalue %struct.Input %[[#TMP1]], %struct.Inner %[[#TMP2]], 1
// CHECK: %[[#VAR:]] = alloca %struct.Input, align 8
// CHECK: store %struct.Input %[[#TMP3]], ptr %[[#VAR]], align 4
// CHECK-DXIL: call void @{{.*}}foo{{.*}}(ptr %[[#VAR]])
// CHECK-SPIRV: call spir_func void @{{.*}}foo{{.*}}(ptr %[[#VAR]])
[shader("compute")]
[numthreads(8,8,1)]
void foo(Input input) {}