From 3abe628a8bf62f64c760bd5487c3b7a4ba24f4c0 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 07:36:14 +0300 Subject: [PATCH 1/5] gfx: scan every shader for a multi-declarator uniform, varying or attribute A host test, red against vs_ambient.vert's four-name uniform statement. Co-Authored-By: Claude Opus 5.5 --- rust-modules/gfx/src/gfx.rs | 198 ++++++++++++++++++++++++++++++++++-- 1 file changed, 188 insertions(+), 10 deletions(-) diff --git a/rust-modules/gfx/src/gfx.rs b/rust-modules/gfx/src/gfx.rs index 4f85e72e1..34a317e77 100644 --- a/rust-modules/gfx/src/gfx.rs +++ b/rust-modules/gfx/src/gfx.rs @@ -9554,23 +9554,14 @@ mod tests { /// directory, so a new shader is covered by being added. #[test] fn no_shader_source_names_a_dev_trigger() { - let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/shaders"); - let mut scanned = 0; let mut found = Vec::new(); - for entry in std::fs::read_dir(&dir).unwrap_or_else(|e| panic!("{}: {e}", dir.display())) { - let path = entry.expect("a directory entry").path(); - // Lossy: a stray non-UTF-8 file (a Finder `.DS_Store`) is not a shader and must not - // turn this red; the bytes the scan reads are the same either way. - let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); - let text = String::from_utf8_lossy(&bytes); - scanned += 1; + for (path, text) in shader_files() { for (n, line) in text.lines().enumerate() { if line.contains("plxnative-") { found.push(format!("{}:{}: {}", path.display(), n + 1, line.trim())); } } } - assert!(scanned > 0, "no shader sources under {}", dir.display()); assert!( found.is_empty(), "shader sources are embedded verbatim in the binary, comments included, and the \ @@ -9580,6 +9571,193 @@ mod tests { ); } + /// Every file under `shaders/`, as (path, text), in path order: the one directory walk the + /// whole-directory source scans share, so a new shader is covered by being added. + fn shader_files() -> Vec<(std::path::PathBuf, String)> { + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/shaders"); + let mut files = Vec::new(); + for entry in std::fs::read_dir(&dir).unwrap_or_else(|e| panic!("{}: {e}", dir.display())) { + let path = entry.expect("a directory entry").path(); + // Lossy: a stray non-UTF-8 file (a Finder `.DS_Store`) is not a shader and must not + // turn a scan red; the bytes a scan reads are the same either way. + let bytes = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + files.push((path, String::from_utf8_lossy(&bytes).into_owned())); + } + assert!(!files.is_empty(), "no shader sources under {}", dir.display()); + files.sort(); + files + } + + /// The `uniform` / `varying` / `attribute` statements in `src` that declare more than one name + /// (`uniform vec4 a, b;`), as (line of the storage keyword, the statement on one line). + /// + /// Comments and preprocessor lines are blanked first (a trailing `// (x, y, 1/w, 1/h)` note + /// holds commas), then the text is cut into statements at `;`, `{` and `}`; a statement + /// holding a storage keyword as a whole word is multi-declarator when a comma sits outside + /// every `(…)` and `[…]`, which keeps an array size such as `u_sc[12]` out of the count and + /// catches `u_a[2], u_b` and a statement that runs over several lines. + fn multi_declarator_statements(src: &str) -> Vec<(usize, String)> { + // Pass 1: blank comments and preprocessor lines, keeping every newline so line numbers hold. + let mut code = String::with_capacity(src.len()); + let mut chars = src.chars().peekable(); + let mut line_start = true; + while let Some(c) = chars.next() { + match (c, chars.peek().copied()) { + ('/', Some('/')) => { + while chars.peek().is_some_and(|&n| n != '\n') { + chars.next(); + } + } + ('/', Some('*')) => { + chars.next(); + let mut prev = ' '; + for n in chars.by_ref() { + if n == '\n' { + code.push('\n'); + } + if prev == '*' && n == '/' { + break; + } + prev = n; + } + } + ('#', _) if line_start => { + // A directive runs to the end of its line, or past a `\` continuation. + let mut prev = ' '; + while let Some(&n) = chars.peek() { + if n == '\n' && prev != '\\' { + break; + } + if n == '\n' { + code.push('\n'); + } + prev = n; + chars.next(); + } + } + _ => { + code.push(c); + if c == '\n' { + line_start = true; + } else if !c.is_whitespace() { + line_start = false; + } + } + } + } + // Pass 2: statements, and the commas at depth 0 of the storage-qualified ones. + let mut found = Vec::new(); + let mut line = 1; + let mut stmt = String::new(); + let mut stmt_line = 1; + for c in code.chars().chain(std::iter::once(';')) { + if !matches!(c, ';' | '{' | '}') { + if stmt.is_empty() && c.is_whitespace() { + if c == '\n' { + line += 1; + } + continue; + } + if stmt.is_empty() { + stmt_line = line; + } + stmt.push(c); + if c == '\n' { + line += 1; + } + continue; + } + let storage = stmt + .split(|ch: char| !(ch.is_alphanumeric() || ch == '_')) + .any(|w| matches!(w, "uniform" | "varying" | "attribute")); + if storage { + let mut depth = 0i32; + let mut multi = false; + for ch in stmt.chars() { + match ch { + '(' | '[' => depth += 1, + ')' | ']' => depth -= 1, + ',' if depth == 0 => multi = true, + _ => {} + } + } + if multi { + found.push((stmt_line, stmt.split_whitespace().collect::>().join(" "))); + } + } + stmt.clear(); + } + found + } + + /// **The scan that keeps a shader to one name per `uniform` / `varying` / `attribute` + /// statement is itself right.** It must count `uniform vec4 a, b;` and its array and multi-line + /// forms, and must not count a comma in a comment, a function's parameter list, an array + /// size, a local declaration or a longer identifier that merely contains a storage keyword. + #[test] + fn the_one_name_per_declaration_scan_counts_exactly_the_storage_statements_with_two_names() { + let hits = |src: &str| multi_declarator_statements(src).len(); + for src in [ + "uniform vec4 a, b;", + "varying highp vec2 a, b;", + "attribute vec2 a, b;", + "uniform vec4 u_a[2], u_b;", + "uniform vec4 u_a, u_b[2];", + "invariant varying vec4 a, b;", + "uniform float a,\n b;", + "uniform vec4 a, b, c;", + "#ifdef X\nuniform vec4 a, b;\n#endif", + "float f(int i) { return 1.0; }\nuniform vec4 a, b;", + ] { + assert_eq!(hits(src), 1, "must count: {src:?}"); + } + for src in [ + "uniform vec4 a;\nuniform vec4 b;", + "uniform vec4 u_sc[12];", + "uniform highp vec4 u_art; // the art quad: (x, y, 1/w, 1/h) in authored pixels", + "// uniform vec4 a, b;", + "/* uniform vec4 a,\n b; */ uniform vec4 c;", + "float shade_block(int i, vec2 px) { return 1.0; }", + "void main(){ vec2 a, b; a = b; }", + "float uniform_scale = 1.0, y;", + "#define PAIR uniform vec4 a, b;", + "#define LONG(a) \\\n uniform vec4 a, b;\nuniform vec4 c;", + "uniform vec4 u_m[2 * (1 + 2)];", + "", + ] { + assert_eq!(hits(src), 0, "must not count: {src:?}"); + } + // The line is that of the storage keyword, past the blanked comments and directives. + assert_eq!( + multi_declarator_statements("// note\n#define A 1\n\nuniform vec4 a,\n b;\nuniform vec4 c;"), + vec![(4, "uniform vec4 a, b".to_string())] + ); + } + + /// **A shader declares one name per `uniform` / `varying` / `attribute` statement.** The Samsung + /// TV 10.0 emulator's GL translation (YaGL, under Mesa llvmpipe) mishandled + /// `vs_ambient.vert`'s `uniform vec4 u_atl, u_atr, u_abr, u_abl;`, the only multi-declarator in + /// `shaders/`: the pairs built on it failed to link ("all shaders must use same shading language + /// version") while the eleven others linked. Every other source already spelled one name per + /// statement, and a driver that reads either spelling sees the same program, so the sources keep + /// to the spelling every driver has read. It lists the directory, so a new shader is covered + /// by being added. + #[test] + fn every_shader_keeps_one_name_per_declaration_in_a_uniform_varying_or_attribute_statement() { + let mut found = Vec::new(); + for (path, text) in shader_files() { + for (line, stmt) in multi_declarator_statements(&text) { + found.push(format!("{}:{line}: {stmt}", path.display())); + } + } + assert!( + found.is_empty(), + "the TV 10.0 emulator's GL translation (YaGL) mishandles a multi-declarator, so a \ + `uniform` / `varying` / `attribute` statement names one variable; split these:\n{}", + found.join("\n") + ); + } + /// **A frozen menu glass reads its ground ONCE per fragment, dim included.** The modal dim's /// ink on a menu is the latched underlay field times a weight (`underlay::Role::Dim`), and the /// glass's body is that same field (`UnderlayField::ground_tex`), both read at the screen point From 7c020168324c6aad8c61b1162321a39acc2e7f9c Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 07:38:55 +0300 Subject: [PATCH 2/5] gfx: vs_ambient declares its four corner uniforms one per statement On the Samsung TV 10.0 emulator (YaGL, which hands shaders to Mesa llvmpipe) the three programs built on vs_ambient.vert fail to link with "all shaders must use same shading language version", while the eleven other required pairs link. `uniform vec4 u_atl, u_atr, u_abr, u_abl;` is the only multi-declarator statement in shaders/, so it is split into four one-name declarations. The uniforms are looked up by name, so a conforming driver reads the same program. The scan test the previous commit added now passes. Co-Authored-By: Claude Opus 5.5 --- rust-modules/gfx/src/shaders/vs_ambient.vert | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rust-modules/gfx/src/shaders/vs_ambient.vert b/rust-modules/gfx/src/shaders/vs_ambient.vert index 18d82628f..12d88f3f6 100644 --- a/rust-modules/gfx/src/shaders/vs_ambient.vert +++ b/rust-modules/gfx/src/shaders/vs_ambient.vert @@ -25,7 +25,13 @@ attribute vec2 a_pos; uniform vec4 u_rect; uniform vec2 u_screen; -uniform vec4 u_atl, u_atr, u_abr, u_abl; +// One name per declaration, here and in every shader: the Samsung TV 10.0 emulator's GL translation +// (YaGL) mishandles `uniform vec4 a, b;`, and a host test in `gfx.rs` keeps the sources this way. The +// uniforms are found by name, so a driver that reads either spelling sees the same program. +uniform vec4 u_atl; +uniform vec4 u_atr; +uniform vec4 u_abr; +uniform vec4 u_abl; varying vec4 v_col; #ifdef PLX_DITHER_NC // The dither tile's coordinate (`shaders/dither.glsl`, cost rule 4): target px / NOISE_DIM, linear From 6f523df2a472668d180bb808069880a09bf84b0b Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 07:43:18 +0300 Subject: [PATCH 3/5] gfx: word the one-declaration comments as the suspected cause The emulator rejects VS_AMBIENT_DITHERED at its dither varying; the four-name uniform statement was the only multi-declarator, which makes it the suspected cause, not a confirmed one. The test's doc, its failure message and the shader's comment now say that. Co-Authored-By: Claude Opus 5.5 --- rust-modules/gfx/src/gfx.rs | 20 +++++++++++--------- rust-modules/gfx/src/shaders/vs_ambient.vert | 8 +++++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/rust-modules/gfx/src/gfx.rs b/rust-modules/gfx/src/gfx.rs index 34a317e77..967b1144b 100644 --- a/rust-modules/gfx/src/gfx.rs +++ b/rust-modules/gfx/src/gfx.rs @@ -9735,13 +9735,14 @@ mod tests { } /// **A shader declares one name per `uniform` / `varying` / `attribute` statement.** The Samsung - /// TV 10.0 emulator's GL translation (YaGL, under Mesa llvmpipe) mishandled - /// `vs_ambient.vert`'s `uniform vec4 u_atl, u_atr, u_abr, u_abl;`, the only multi-declarator in - /// `shaders/`: the pairs built on it failed to link ("all shaders must use same shading language - /// version") while the eleven others linked. Every other source already spelled one name per - /// statement, and a driver that reads either spelling sees the same program, so the sources keep - /// to the spelling every driver has read. It lists the directory, so a new shader is covered - /// by being added. + /// TV 10.0 emulator (YaGL over Mesa llvmpipe) rejects `VS_AMBIENT_DITHERED` at + /// `varying highp vec2 v_dither_nc;` ("syntax error, unexpected NEW_IDENTIFIER"), and + /// `gfx_compile` exits the process on a required shader's rejection. `vs_ambient.vert`'s + /// `uniform vec4 u_atl, u_atr, u_abr, u_abl;` was the only multi-declarator in `shaders/`, which + /// makes it the suspected cause; that it is the cause is not yet confirmed on the emulator. + /// Every other source already spelled one name per statement, and a driver that reads either + /// spelling sees the same program, so the sources keep to the spelling the other drivers have + /// read. It lists the directory, so a new shader is covered by being added. #[test] fn every_shader_keeps_one_name_per_declaration_in_a_uniform_varying_or_attribute_statement() { let mut found = Vec::new(); @@ -9752,8 +9753,9 @@ mod tests { } assert!( found.is_empty(), - "the TV 10.0 emulator's GL translation (YaGL) mishandles a multi-declarator, so a \ - `uniform` / `varying` / `attribute` statement names one variable; split these:\n{}", + "a multi-declarator is the suspected cause of the TV 10.0 emulator (YaGL) rejecting \ + `vs_ambient.vert`, so a `uniform` / `varying` / `attribute` statement names one \ + variable; split these:\n{}", found.join("\n") ); } diff --git a/rust-modules/gfx/src/shaders/vs_ambient.vert b/rust-modules/gfx/src/shaders/vs_ambient.vert index 12d88f3f6..06fbbd3c2 100644 --- a/rust-modules/gfx/src/shaders/vs_ambient.vert +++ b/rust-modules/gfx/src/shaders/vs_ambient.vert @@ -25,9 +25,11 @@ attribute vec2 a_pos; uniform vec4 u_rect; uniform vec2 u_screen; -// One name per declaration, here and in every shader: the Samsung TV 10.0 emulator's GL translation -// (YaGL) mishandles `uniform vec4 a, b;`, and a host test in `gfx.rs` keeps the sources this way. The -// uniforms are found by name, so a driver that reads either spelling sees the same program. +// One name per declaration, here and in every shader. The four corners below were one +// `uniform vec4 a, b, c, d;` statement, the only multi-declarator in `shaders/`, when the Samsung +// TV 10.0 emulator (YaGL over Mesa) rejected this program; a host test in `gfx.rs` keeps the sources +// one-per-statement. The uniforms are found by name, so a driver that reads either spelling sees the +// same program. uniform vec4 u_atl; uniform vec4 u_atr; uniform vec4 u_abr; From 9ed56b066d6b2bf67fc69262ccb363d7bbebdb85 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 08:06:19 +0300 Subject: [PATCH 4/5] gfx: state the confirmed cause of the vs_ambient rejection On the TV 10.0 x86_64 emulator, with the Tizen hello-world probe (samsung/hello-tpk at e8da14ce6), the unsplit vs_ambient.vert failed, the split source compiled, a cut-down variant did the same, and with the split all 14 required programs compiled and linked and plx_gfx drew. The host test's doc comment and the shader's comment said the split was only the suspected cause; they now state what was measured and what is still not established (why YaGL rejects the statement, and the optional straighten program that still fails there). The doc comment also no longer says that gfx_compile exits the process: a required shader's rejection stops the app from starting, whichever way that is done. The test's assertion message says the same as the comment. Co-Authored-By: Claude --- rust-modules/gfx/src/gfx.rs | 28 ++++++++++++-------- rust-modules/gfx/src/shaders/vs_ambient.vert | 8 +++--- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/rust-modules/gfx/src/gfx.rs b/rust-modules/gfx/src/gfx.rs index 8338e13a8..6eae04414 100644 --- a/rust-modules/gfx/src/gfx.rs +++ b/rust-modules/gfx/src/gfx.rs @@ -9735,14 +9735,20 @@ mod tests { } /// **A shader declares one name per `uniform` / `varying` / `attribute` statement.** The Samsung - /// TV 10.0 emulator (YaGL over Mesa llvmpipe) rejects `VS_AMBIENT_DITHERED` at - /// `varying highp vec2 v_dither_nc;` ("syntax error, unexpected NEW_IDENTIFIER"), and - /// `gfx_compile` exits the process on a required shader's rejection. `vs_ambient.vert`'s - /// `uniform vec4 u_atl, u_atr, u_abr, u_abl;` was the only multi-declarator in `shaders/`, which - /// makes it the suspected cause; that it is the cause is not yet confirmed on the emulator. - /// Every other source already spelled one name per statement, and a driver that reads either - /// spelling sees the same program, so the sources keep to the spelling the other drivers have - /// read. It lists the directory, so a new shader is covered by being added. + /// TV 10.0 emulator (YaGL over Mesa llvmpipe) rejected `VS_AMBIENT_DITHERED` at + /// `varying highp vec2 v_dither_nc;` ("syntax error, unexpected NEW_IDENTIFIER"), and a required + /// shader's rejection stops the app from starting. `vs_ambient.vert`'s + /// `uniform vec4 u_atl, u_atr, u_abr, u_abl;` was the only multi-declarator in `shaders/`, and + /// splitting it is what made the program compile there. Measured on that emulator with the Tizen + /// hello-world probe (`samsung/hello-tpk` at `e8da14ce6`): the unsplit source failed, the split + /// source compiled, a cut-down variant did the same, and with the split all 14 required programs + /// compiled and linked and `plx_gfx` drew. Why YaGL rejects the statement is not established (the + /// message is the one Mesa gives for raw desktop GLSL 1.10, where `highp` is an ordinary + /// identifier), and an optional program, the straighten copy variant, still fails there with the + /// same kind of error and no multi-declarator, its cause also not established. Every other source + /// already spelled one name per statement, and a driver that reads either spelling sees the same + /// program, so the sources keep to the spelling the other drivers have read. It lists the + /// directory, so a new shader is covered by being added. #[test] fn every_shader_keeps_one_name_per_declaration_in_a_uniform_varying_or_attribute_statement() { let mut found = Vec::new(); @@ -9753,9 +9759,9 @@ mod tests { } assert!( found.is_empty(), - "a multi-declarator is the suspected cause of the TV 10.0 emulator (YaGL) rejecting \ - `vs_ambient.vert`, so a `uniform` / `varying` / `attribute` statement names one \ - variable; split these:\n{}", + "a multi-declarator made the TV 10.0 emulator (YaGL) reject `vs_ambient.vert` until it \ + was split, so a `uniform` / `varying` / `attribute` statement names one variable; \ + split these:\n{}", found.join("\n") ); } diff --git a/rust-modules/gfx/src/shaders/vs_ambient.vert b/rust-modules/gfx/src/shaders/vs_ambient.vert index 06fbbd3c2..c61c5bdad 100644 --- a/rust-modules/gfx/src/shaders/vs_ambient.vert +++ b/rust-modules/gfx/src/shaders/vs_ambient.vert @@ -26,10 +26,10 @@ attribute vec2 a_pos; uniform vec4 u_rect; uniform vec2 u_screen; // One name per declaration, here and in every shader. The four corners below were one -// `uniform vec4 a, b, c, d;` statement, the only multi-declarator in `shaders/`, when the Samsung -// TV 10.0 emulator (YaGL over Mesa) rejected this program; a host test in `gfx.rs` keeps the sources -// one-per-statement. The uniforms are found by name, so a driver that reads either spelling sees the -// same program. +// `uniform vec4 a, b, c, d;` statement, the only multi-declarator in `shaders/`. The Samsung TV 10.0 +// emulator (YaGL over Mesa) rejected this program with that statement and compiles it with the split +// (measured there; a host test in `gfx.rs` keeps the sources one-per-statement). The uniforms are found +// by name, so a driver that reads either spelling sees the same program. uniform vec4 u_atl; uniform vec4 u_atr; uniform vec4 u_abr; From 9dea74a3401117f990c081600dab35f6278e25b9 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 08:33:34 +0300 Subject: [PATCH 5/5] gfx: say what the one-name rule covers in vs_ambient.vert The comment said every declaration names one variable, and that the host test keeps the sources one-per-statement. The test enforces only uniform, varying and attribute statements, and its self-test allows a local `vec2 a, b;`. The comment now says the same as the test's doc comment. Co-Authored-By: Claude --- rust-modules/gfx/src/shaders/vs_ambient.vert | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rust-modules/gfx/src/shaders/vs_ambient.vert b/rust-modules/gfx/src/shaders/vs_ambient.vert index c61c5bdad..18d46a094 100644 --- a/rust-modules/gfx/src/shaders/vs_ambient.vert +++ b/rust-modules/gfx/src/shaders/vs_ambient.vert @@ -25,11 +25,11 @@ attribute vec2 a_pos; uniform vec4 u_rect; uniform vec2 u_screen; -// One name per declaration, here and in every shader. The four corners below were one -// `uniform vec4 a, b, c, d;` statement, the only multi-declarator in `shaders/`. The Samsung TV 10.0 -// emulator (YaGL over Mesa) rejected this program with that statement and compiles it with the split -// (measured there; a host test in `gfx.rs` keeps the sources one-per-statement). The uniforms are found -// by name, so a driver that reads either spelling sees the same program. +// One name per `uniform` / `varying` / `attribute` statement, here and in every shader. The four +// corners below were one `uniform vec4 a, b, c, d;` statement, the only multi-declarator in `shaders/`. +// The Samsung TV 10.0 emulator (YaGL over Mesa) rejected this program with that statement and compiles +// it with the split (measured there; a host test in `gfx.rs` keeps every such statement to one name). +// The uniforms are found by name, so a driver that reads either spelling sees the same program. uniform vec4 u_atl; uniform vec4 u_atr; uniform vec4 u_abr;