File: cbuffer_and_namespaces.hlsl

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (96 lines) | stat: -rw-r--r-- 3,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s

// CHECK: CXXRecordDecl {{.*}} struct EmptyStruct definition
struct EmptyStruct {
};

// CHECK: NamespaceDecl {{.*}} NS1
namespace NS1 {
  // CHECK: CXXRecordDecl {{.*}} struct Foo definition
  struct Foo {
    float a;
    EmptyStruct es;
  };

  // CHECK: CXXRecordDecl {{.*}} struct Bar definition
  struct Bar {
    // CHECK: CXXRecordDecl {{.*}} struct Foo definition
    struct Foo {
      int b;
      EmptyStruct es;
    };
    // CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition
    // CHECK: FieldDecl {{.*}} b 'int'
  };
  // CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition
  // CHECK: FieldDecl {{.*}} a 'float'
}

struct Foo {
  double c;
  EmptyStruct es;
};

// CHECK: HLSLBufferDecl {{.*}}  line:[[# @LINE + 2]]:9 cbuffer CB1
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
cbuffer CB1 {
  // CHECK: VarDecl {{.*}} foo1 'hlsl_constant Foo'
  Foo foo1;
  // CHECK: VarDecl {{.*}} foo2 'hlsl_constant NS1::Foo'
  NS1::Foo foo2;
  // CHECK: VarDecl {{.*}} foo3 'hlsl_constant NS1::Bar::Foo'
  NS1::Bar::Foo foo3;
  // CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB1 definition
  // CHECK: FieldDecl {{.*}} foo1 '__cblayout_Foo'
  // CHECK: FieldDecl {{.*}} foo2 'NS1::__cblayout_Foo'
  // CHECK: FieldDecl {{.*}} foo3 'NS1::Bar::__cblayout_Foo'
}
// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition
// CHECK: FieldDecl {{.*}} c 'double'

struct CB1ExpectedShape {
    double a1;
    float a2;
    int a;
};
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(CB1ExpectedShape, __cblayout_CB1), "");

namespace NS2 {
  struct Foo {
    float d[4];
    EmptyStruct es;
  };
  // CHECK: HLSLBufferDecl {{.*}} line:[[# @LINE + 2]]:11 cbuffer CB2
  // CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
  cbuffer CB2 {
    // CHECK: VarDecl {{.*}} foo0 'hlsl_constant ::Foo':'hlsl_constant Foo'
    ::Foo foo0;
    // CHECK: VarDecl {{.*}} foo1 'hlsl_constant Foo':'hlsl_constant NS2::Foo'
    Foo foo1;
    // CHECK: VarDecl {{.*}} foo2 'hlsl_constant NS1::Foo'
    NS1::Foo foo2;
    // CHECK: VarDecl {{.*}} foo3 'hlsl_constant NS1::Bar::Foo'
    NS1::Bar::Foo foo3;
    // CHECK: CXXRecordDecl {{.*}} implicit referenced struct __cblayout_CB2 definition
    // CHECK: FieldDecl {{.*}} foo0 '__cblayout_Foo'
    // CHECK: FieldDecl {{.*}} foo1 'NS2::__cblayout_Foo'
    // CHECK: FieldDecl {{.*}} foo2 'NS1::__cblayout_Foo'
    // CHECK: FieldDecl {{.*}} foo3 'NS1::Bar::__cblayout_Foo'
  }
  // CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_Foo definition
  // CHECK: FieldDecl {{.*}} d 'float[4]'
}

struct CB2ExpectedShape {
    double a1;
    float d[4];
    float a2;
    int a;
};
_Static_assert(__builtin_hlsl_is_scalarized_layout_compatible(CB2ExpectedShape, NS2::__cblayout_CB2), "");

// Add uses for the constant buffer declarations so they are not optimized away
// CHECK: ExportDecl
export float f() {
  return foo2.a + NS2::foo2.a;
}