};
struct Draw2dCmd {
- uint type;
+ uint packed_type;
uint words[7];
};
Draw2dCmdGlyph decode_glyph(Draw2dCmd cmd) {
return Draw2dCmdGlyph(
- cmd.words[0],
- vec2(uintBitsToFloat(cmd.words[1]), uintBitsToFloat(cmd.words[2])),
- cmd.words[3]
+ cmd.packed_type & 0xffffff,
+ vec2(uintBitsToFloat(cmd.words[0]), uintBitsToFloat(cmd.words[1])),
+ cmd.words[2]
);
}
vec2 cmd_max = vec2(-99999.9);
if (in_bounds) {
const Draw2dCmd cmd = constants.draw_buffer.values[draw_index];
- const uint type = cmd.type;
+ const uint cmd_type = cmd.packed_type >> 24;
for (;;) {
- const uint scalar_type = subgroupBroadcastFirst(type);
+ const uint scalar_type = subgroupBroadcastFirst(cmd_type);
[[branch]]
- if (scalar_type == type) {
+ if (scalar_type == cmd_type) {
switch (scalar_type) {
case DRAW_2D_CMD_RECT:
const Draw2dCmdRect cmd_rect = decode_rect(cmd);
vec2 cmd_max = vec2(-99999.9);
const Draw2dCmd cmd = constants.draw_buffer.values[draw_index];
+ const uint cmd_type = cmd.packed_type >> 24;
+
for (;;) {
- const uint scalar_type = subgroupBroadcastFirst(cmd.type);
+ const uint scalar_type = subgroupBroadcastFirst(cmd_type);
[[branch]]
- if (scalar_type == cmd.type) {
+ if (scalar_type == cmd_type) {
switch (scalar_type) {
case DRAW_2D_CMD_RECT:
const Draw2dCmdRect cmd_rect = decode_rect(cmd);
const uint base_index = (constants.coarse_buffer.values[i] & 0xffff) * 32;
const Draw2dCmd cmd = constants.draw_buffer.values[base_index + index];
+ const uint cmd_type = cmd.packed_type >> 24;
vec4 primitive_color = vec4(0.0);
- switch (cmd.type) {
+ switch (cmd_type) {
case DRAW_2D_CMD_RECT:
const Draw2dCmdRect cmd_rect = decode_rect(cmd);
const vec2 rect_min = cmd_rect.position - cmd_rect.half_extent - cmd_rect.border_width;
pub texcoord: [f32; 4],
}
-#[repr(u32)]
+#[repr(u8)]
enum Draw2dCmdType {
Rect,
Glyph,
glyph: CmdGlyph,
}
+const _: () = assert!(std::mem::size_of::<Draw2dCmd>() == 32);
+
#[repr(C)]
#[derive(Clone, Copy)]
struct CmdGlyph {
- r#type: u32,
- index: u32,
+ packed: u32,
x: f32,
y: f32,
color: u32,
- _padding: [u8; 12],
}
-const _: () = assert!(std::mem::size_of::<CmdGlyph>() == std::mem::size_of::<Draw2dCmd>());
+const _: () = assert!(std::mem::size_of::<CmdGlyph>() == 16);
#[repr(C)]
#[derive(Clone, Copy)]
struct CmdRect {
- r#type: u32,
+ packed: u32,
border_width: f32,
x: f32,
y: f32,
border_color: u32,
}
-const _: () = assert!(std::mem::size_of::<CmdRect>() == std::mem::size_of::<Draw2dCmd>());
+const _: () = assert!(std::mem::size_of::<CmdRect>() == 32);
impl Draw2dCmd {
#[inline(always)]
- pub fn glyph(glyph_index: TouchedGlyphIndex, color: u32, x: f32, y: f32) -> Self {
+ pub fn glyph(touched_glyph_index: TouchedGlyphIndex, color: u32, x: f32, y: f32) -> Self {
Self {
glyph: CmdGlyph {
- r#type: Draw2dCmdType::Glyph as u32,
- index: glyph_index.as_u32(),
+ packed: (Draw2dCmdType::Glyph as u32) << 24
+ | (touched_glyph_index.as_u32() & 0xffffff),
x,
y,
color,
- _padding: default(),
},
}
}
) -> Self {
Self {
rect: CmdRect {
- r#type: Draw2dCmdType::Rect as u32,
+ packed: (Draw2dCmdType::Rect as u32) << 24,
border_width,
x,
y,