Skip to content

[HLSL] cbuffer: Create host layout structs #122553

@hekota

Description

@hekota

The cbuffer language syntax allows declarations inside cbuffer context that do not contribute to the constant buffer layout, such as static variables, function definitions, declarations of classes and namespaces, resources, or empty struct and zero-sized arrays. As part of semantic analysis we need to create a "layout struct" for the constant buffer that will only include elements that affect the buffer memory layout. This layout struct will be used later on as the contained type of the cbuffer resource handle type and for layout calculations.

If the constant buffer includes a struct that contains any of the above undesirable declarations, a new version of this struct should be created with these declarations filtered out as well.

The buffer layout struct will be declared within the HLSLBufferDecl context. Layout structs for embedded structures will be added there as well.

For example:

struct Something {
  int a;
  float f[0];
};

cbuffer CB {
    float x;
    RWBuffer<float> buf;
    Something s;
    static float y;
}

The buffer layout should look like this:

;   __layout.CB
;   {
;       float x;                                      ; Offset:    0
;       struct __layout.Something
;       {
;           int a;                                    ; Offset:   16
;       } s;                                          ; Offset:   16
;   } CB;                                             ; Offset:    0 Size:    20
;

https://godbolt.org/z/j37r1Tede

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions