# gpui: Store GPU-facing bools as PaddedBool32 to avoid uninitialized padding \(\#60482\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f28177003499ec9c5052d1883fee62b148451c59)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f28177003499ec9c5052d1883fee62b148451c59

Requested commit: f28177003499ec9c5052d1883fee62b148451c59

Commit: f28177003499ec9c5052d1883fee62b148451c59

Tree: bacacc805ec2fd96403d3231cada8da81ca8d620

Author: Richard Feldman

Committer: GitHub

## Message

```
gpui: Store GPU-facing bools as PaddedBool32 to avoid uninitialized padding (#60482)

`PolychromeSprite` in `crates/gpui/src/scene.rs` is `#[repr(C)]` and had
a `grayscale: bool` field followed by 3 compiler-inserted padding bytes
that were never written. The wgpu renderer's `instance_bytes`
reinterprets `&[PolychromeSprite]` as `&[u8]` via
`slice::from_raw_parts` and passes it to `queue.write_buffer`, so those
uninitialized padding bytes were exposed behind a shared `&[u8]` on
every frame that draws an image or emoji, which is undefined behavior.

Rather than widening the field to a raw `u32` (which would suggest
values other than 0 and 1 are meaningful), this introduces
`PaddedBool32`: a `#[repr(transparent)]` wrapper around `u32` whose only
public constructor is `From<bool>`, so the 0-or-1 invariant is enforced
by the type while the layout has no padding. `Underline.wavy`, which was
already a raw `u32` for the same reason, is converted too.

cbindgen emits the wrapper as `typedef uint32_t PaddedBool32;`, so the
generated Metal header and shaders are unchanged. The WGSL and HLSL
shaders already declared these fields as `u32`/`uint`; their `& 0xFFu`
masks, which existed to ignore the garbage padding bytes, are now
simplified to plain comparisons.

Release Notes:

- N/A
```

## Parents

- [10504e3ce18bb1d2444baf1047fa4ea9835ff1cc](https://git.cafe/gitcafe/zed/commit/10504e3ce18bb1d2444baf1047fa4ea9835ff1cc?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f28177003499ec9c5052d1883fee62b148451c59?format=markdown)
