Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HLSL] cbuffer: Create host layout struct and add resource handle to AST #122553

Open
hekota opened this issue Jan 10, 2025 · 0 comments
Open

[HLSL] cbuffer: Create host layout struct and add resource handle to AST #122553

hekota opened this issue Jan 10, 2025 · 0 comments
Assignees
Labels
HLSL HLSL Language Support

Comments

@hekota
Copy link
Member

hekota commented Jan 10, 2025

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 as the contained type of the cbuffer resource handle type and for layout calculations in codegen.

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 and will be followed by 'cbuffer` resource handle declaration that will reference the layout struct as its contained type.

For example:

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

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

The buffer layout should look like this:

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

And the resource handle added to the HLSLBufferDecl will look like this:

__hlsl_resource_t [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(hostlayout.CB)] __handle;

https://godbolt.org/z/j37r1Tede

@hekota hekota added the HLSL HLSL Language Support label Jan 10, 2025
@hekota hekota moved this to Planning in HLSL Support Jan 10, 2025
@hekota hekota self-assigned this Jan 11, 2025
@hekota hekota changed the title [HLSL] cbuffer: Create host layout struct and add resource handle to AST [HLSL] cbuffer: Create host layout struct and add resource handle to AST Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLSL HLSL Language Support
Projects
Status: Planning
Development

No branches or pull requests

1 participant