llvm-project/clang/test/CodeGenHLSL/semantics/semantic-struct-2-output.hlsl
Nathan Gauër 2fc42c7163
[HLSL] Add initial support for output semantics (#168095)
This commits adds the first part of the output semantics. It only
considers return values (and sret), but does not handle `inout` or `out`
parameters yet.
Those missing bits will reuse the same code, but will require additional
testing & some fixups, so planning on adding them separately.
2025-11-19 14:51:46 +01:00

36 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-DX,CHECK
// 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-VK,CHECK
struct Input {
float Idx : SV_Position0;
float Gid : SV_Position1;
};
struct Output {
float a : A;
float b : B;
};
// Make sure SV_DispatchThreadID translated into dx.thread.id.
// CHECK-DX: define hidden void @_Z3foo5Input(ptr dead_on_unwind noalias writable sret(%struct.Output) align 1 %agg.result, ptr noundef byval(%struct.Input) align 1 %input)
// CHECK-VK: define hidden spir_func void @_Z3foo5Input(ptr dead_on_unwind noalias writable sret(%struct.Output) align 1 %agg.result, ptr noundef byval(%struct.Input) align 1 %input)
// CHECK: %Idx = getelementptr inbounds nuw %struct.Input, ptr %input, i32 0, i32 0
// CHECK: %[[#tmp:]] = load float, ptr %Idx, align 1
// CHECK: %a = getelementptr inbounds nuw %struct.Output, ptr %agg.result, i32 0, i32 0
// CHECK: store float %[[#tmp]], ptr %a, align 1
// CHECK: %Gid = getelementptr inbounds nuw %struct.Input, ptr %input, i32 0, i32 1
// CHECK: %[[#tmp:]] = load float, ptr %Gid, align 1
// CHECK: %b = getelementptr inbounds nuw %struct.Output, ptr %agg.result, i32 0, i32 1
// CHECK: store float %[[#tmp]], ptr %b, align 1
Output foo(Input input) {
Output o;
o.a = input.Idx;
o.b = input.Gid;
return o;
}