Skip to content

Wrong size of packed struct with bit flags #6418

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

Closed
michal-z opened this issue Sep 25, 2020 · 2 comments
Closed

Wrong size of packed struct with bit flags #6418

michal-z opened this issue Sep 25, 2020 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@michal-z
Copy link
Contributor

michal-z commented Sep 25, 2020

I have defined below packed struct. There are 14 'bool' fields and u18 padding field. I was expecting @sizeof(RESOURCE_STATES) to be 4. Unfortunately @sizeof(RESOURCE_STATES) is 5.

pub const RESOURCE_STATES = packed struct {
    VERTEX_AND_CONSTANT_BUFFER: bool = false,
    INDEX_BUFFER: bool = false,
    RENDER_TARGET: bool = false,
    UNORDERED_ACCESS: bool = false,
    DEPTH_WRITE: bool = false,
    DEPTH_READ: bool = false,
    NON_PIXEL_SHADER_RESOURCE: bool = false,
    PIXEL_SHADER_RESOURCE: bool = false,
    STREAM_OUT: bool = false,
    INDIRECT_ARGUMENT_AND_PREDICATION: bool = false,
    COPY_DEST: bool = false,
    COPY_SOURCE: bool = false,
    RESOLVE_DEST: bool = false,
    RESOLVE_SOURCE: bool = false,

    padding: u18 = 0,
};

The same technique but for smaller structs works as expected:

pub const HEAP_FLAGS = packed struct {
    SHARED: bool = false,
    DENY_BUFFERS: bool = false,
    ALLOW_DISPLAY: bool = false,
    SHARED_CROSS_ADAPTER: bool = false,
    DENY_RT_DS_TEXTURES: bool = false,
    DENY_NON_RT_DS_TEXTURES: bool = false,
    HARDWARE_PROTECTED: bool = false,

    padding: u25 = 0,
};

@sizeof(HEAP_FLAGS) == 4.

As a workaround I have to define 18 'bool' padding fields in RESOURCE_STATES struct.

Thanks,
Michal

@pfgithub
Copy link
Contributor

Packed structs are currently a bit broken unfortunately. The issues to watch about this are #2627 and #3133

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Oct 4, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 4, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@Vexu
Copy link
Member

Vexu commented Jan 19, 2023

Fixed in self-hosted.

@Vexu Vexu closed this as completed Jan 19, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.11.0 Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

4 participants