Keep the glyph uvs as vectors on both sides
Review response: `GlyphInfo` goes back to two `vec2<f32>`, which is what the uvs are, and `GlyphPrimitive` takes `#[repr(C, align(8))]` to match. That leaves four padding bytes, which the `primitives!` macro's `unsafe impl Pod` accepts. Measured at 32 bytes, align 8, the same as WGSL's layout for the struct.
This commit is contained in:
1 parent
0106257be0
commit
f5864da3c4
2 files changed
+9
-10
No files matched your search
@@ -89,6 +89,8 @@ macro_rules! primitives {
|
||||
}
|
||||
|
||||
$(
|
||||
// Each is uploaded as its WGSL counterpart, so its fields have to
|
||||
// sit at WGSL's offsets -- including an align Rust would not pick.
|
||||
unsafe impl bytemuck::Pod for $ty {}
|
||||
unsafe impl bytemuck::Zeroable for $ty {}
|
||||
impl Primitive for $ty {
|
||||
@@ -263,7 +265,10 @@ impl RectPrimitive {
|
||||
|
||||
/// `color` is multiplied by the atlas alpha for a mask glyph; a colour glyph
|
||||
/// takes the texel unchanged, which `GlyphEntry::IS_COLORED` selects.
|
||||
#[repr(C)]
|
||||
///
|
||||
/// `align(8)` because `vec2<f32>` aligns `GlyphInfo` to 8, which pads it to
|
||||
/// 32 bytes.
|
||||
#[repr(C, align(8))]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct GlyphPrimitive {
|
||||
pub uv_min: Vec2,
|
||||
|
||||
@@ -17,13 +17,9 @@ struct Rect {
|
||||
inner_radius: f32,
|
||||
}
|
||||
|
||||
// Scalars rather than two vec2<f32>: a vec2 member would align the struct to
|
||||
// 8 and pad it to 32 bytes, which GlyphPrimitive has no field to fill.
|
||||
struct GlyphInfo {
|
||||
uv_min_x: f32,
|
||||
uv_min_y: f32,
|
||||
uv_max_x: f32,
|
||||
uv_max_y: f32,
|
||||
uv_min: vec2<f32>,
|
||||
uv_max: vec2<f32>,
|
||||
layer: u32,
|
||||
color: u32,
|
||||
flags: u32,
|
||||
@@ -162,9 +158,7 @@ fn draw_texture(region: Region) -> vec4<f32> {
|
||||
}
|
||||
|
||||
fn draw_glyph(region: Region, g: GlyphInfo) -> vec4<f32> {
|
||||
let uv_min = vec2(g.uv_min_x, g.uv_min_y);
|
||||
let uv_max = vec2(g.uv_max_x, g.uv_max_y);
|
||||
let uv = mix(uv_min, uv_max, region.uv);
|
||||
let uv = mix(g.uv_min, g.uv_max, region.uv);
|
||||
let texel = textureSample(tex, samp, uv, i32(g.layer));
|
||||
if (g.flags & 1u) != 0u {
|
||||
return texel;
|
||||
|
||||
Reference in new issue
Block a user