[PATCH] D130131: [HLSL] CodeGen hlsl cbuffer/tbuffer.
Xiang Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 8 15:39:05 PDT 2022
python3kgae marked 3 inline comments as done.
python3kgae added inline comments.
================
Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:61
+
+GlobalVariable *replaceCBuffer(CGHLSLRuntime::CBuffer &CB) {
+ const unsigned CBufferAddressSpace = 4;
----------------
Anastasia wrote:
> python3kgae wrote:
> > Anastasia wrote:
> > > I don't think I understand the intent of this function along with `CGHLSLRuntime::addConstant` that populates this collection.
> > It is translating
> >
> > ```
> > cbuffer A {
> > float a;
> > float b;
> > }
> > float foo() {
> > return a + b;
> > }
> > ```
> > into
> >
> > ```
> > struct cb.A.Ty {
> > float a;
> > float b;
> > };
> >
> > cbuffer A {
> > cb.A.Ty CBA;
> > }
> > float foo() {
> > return CBA.a + CBA.b;
> > }
> > ```
> >
> > Both a and b are in the global scope and will get a GlobalVariable in clang codeGen.
> > By doing the translation, we can ensure each buffer map to one GlobalVariable and save cbuffer layout in the value type of that GlobalVariable.
> Ok, I see, so if we are to translate it to C it would be something similar to:
>
>
> ```
> struct A {
> float a;
> float b;
> } cbuffer_A __attribute__((address_space(256)));
>
> float foo() {
> return cbuffer_A.a + cbuffer_A.b;
> }
> ```
> Maybe you can add some comments to explain the intent of this code at a higher level... not sure if the generation can reuse or be made a bit close to the regular C structs + address spaces...
>
Added comments.
Will check how union is supported in clang codeGen. The behavior feels similar, hope could share some code.
================
Comment at: clang/test/CodeGenHLSL/nest_cbuf.hlsl:8
+ // CHECK: @[[TB:.+]] = external addrspace(5) constant { float, i32, double }
+ tbuffer A : register(t2, space1) {
+ float c;
----------------
Anastasia wrote:
> is this generated as nested structs?
No. This will generate as two separate structs.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130131/new/
https://reviews.llvm.org/D130131
More information about the cfe-commits
mailing list