Files
clang-p2996/clang/test/CodeGenHLSL/cbuf.hlsl
Helena Kotas d92bac8a3e [HLSL] Introduce address space hlsl_constant(2) for constant buffer declarations (#123411)
Introduces a new address space `hlsl_constant(2)` for constant buffer
declarations.

This address space is applied to declarations inside `cbuffer` block.
Later on, it will also be applied to `ConstantBuffer<T>` syntax and the
default `$Globals` constant buffer.

Clang codegen translates constant buffer declarations to global
variables and loads from `hlsl_constant(2)` address space. More work
coming soon will include addition of metadata that will map these
globals to individual constant buffers and enable their transformation
to appropriate constant buffer load intrinsics later on in an LLVM pass.

Fixes #123406
2025-01-24 16:48:35 -08:00

34 lines
1.2 KiB
HLSL

// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan-library %s \
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// CHECK: @a = external addrspace(2) externally_initialized global float, align 4
// CHECK: @b = external addrspace(2) externally_initialized global double, align 8
// CHECK: @c = external addrspace(2) externally_initialized global float, align 4
// CHECK: @d = external addrspace(2) externally_initialized global double, align 8
// CHECK: @[[CB:.+]] = external constant { float, double }
cbuffer A : register(b0, space2) {
float a;
double b;
}
// CHECK: @[[TB:.+]] = external constant { float, double }
tbuffer A : register(t2, space1) {
float c;
double d;
}
float foo() {
// CHECK: load float, ptr addrspace(2) @a, align 4
// CHECK: load double, ptr addrspace(2) @b, align 8
// CHECK: load float, ptr addrspace(2) @c, align 4
// CHECK: load double, ptr addrspace(2) @d, align 8
return a + b + c*d;
}
// CHECK: !hlsl.cbufs = !{![[CBMD:[0-9]+]]}
// CHECK: ![[CBMD]] = !{ptr @[[CB]], i32 13, i32 0, i1 false, i32 0, i32 2}