From: Josh Simmons Date: Sun, 10 Nov 2024 13:15:51 +0000 (+0100) Subject: shark-shaders: Shrink glyph draw command slightly X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=192bc953cc64d15cac231f6e4f49b6064e4e6d30;p=josh%2Fnarcissus shark-shaders: Shrink glyph draw command slightly --- diff --git a/title/shark-shaders/shaders/draw_2d.h b/title/shark-shaders/shaders/draw_2d.h index b39368e..f79e3dd 100644 --- a/title/shark-shaders/shaders/draw_2d.h +++ b/title/shark-shaders/shaders/draw_2d.h @@ -20,7 +20,7 @@ struct Glyph { }; struct Draw2dCmd { - uint type; + uint packed_type; uint words[7]; }; @@ -50,9 +50,9 @@ Draw2dCmdRect decode_rect(Draw2dCmd cmd) { 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] ); } diff --git a/title/shark-shaders/shaders/draw_2d_bin_1_scatter.comp b/title/shark-shaders/shaders/draw_2d_bin_1_scatter.comp index 7c11783..935c380 100644 --- a/title/shark-shaders/shaders/draw_2d_bin_1_scatter.comp +++ b/title/shark-shaders/shaders/draw_2d_bin_1_scatter.comp @@ -47,11 +47,11 @@ void main() { 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); diff --git a/title/shark-shaders/shaders/draw_2d_bin_3_resolve.comp b/title/shark-shaders/shaders/draw_2d_bin_3_resolve.comp index 9ffd05e..bde745d 100644 --- a/title/shark-shaders/shaders/draw_2d_bin_3_resolve.comp +++ b/title/shark-shaders/shaders/draw_2d_bin_3_resolve.comp @@ -85,10 +85,12 @@ void main() { 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); diff --git a/title/shark-shaders/shaders/draw_2d_rasterize.comp b/title/shark-shaders/shaders/draw_2d_rasterize.comp index bdcc6f1..d36bf76 100644 --- a/title/shark-shaders/shaders/draw_2d_rasterize.comp +++ b/title/shark-shaders/shaders/draw_2d_rasterize.comp @@ -88,9 +88,10 @@ void main() { 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; diff --git a/title/shark-shaders/src/pipelines.rs b/title/shark-shaders/src/pipelines.rs index 9eb8155..5a4fb36 100644 --- a/title/shark-shaders/src/pipelines.rs +++ b/title/shark-shaders/src/pipelines.rs @@ -19,7 +19,7 @@ pub struct Vertex { pub texcoord: [f32; 4], } -#[repr(u32)] +#[repr(u8)] enum Draw2dCmdType { Rect, Glyph, @@ -32,23 +32,23 @@ pub union Draw2dCmd { glyph: CmdGlyph, } +const _: () = assert!(std::mem::size_of::() == 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::() == std::mem::size_of::()); +const _: () = assert!(std::mem::size_of::() == 16); #[repr(C)] #[derive(Clone, Copy)] struct CmdRect { - r#type: u32, + packed: u32, border_width: f32, x: f32, y: f32, @@ -58,19 +58,18 @@ struct CmdRect { border_color: u32, } -const _: () = assert!(std::mem::size_of::() == std::mem::size_of::()); +const _: () = assert!(std::mem::size_of::() == 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(), }, } } @@ -87,7 +86,7 @@ impl Draw2dCmd { ) -> Self { Self { rect: CmdRect { - r#type: Draw2dCmdType::Rect as u32, + packed: (Draw2dCmdType::Rect as u32) << 24, border_width, x, y,