mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 17:21:49 -10:00
Drop the bool-uniform shadowing fix
It came from reading an LGPL pack's source (Pixel Perfect), which CONTRIBUTING puts off limits even to read. The other four fixes rest on the GLSL specification and an MIT pack, and stay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0d171868af
commit
6e554aaa1f
2 files changed
+1
-34
No files matched your search
@@ -1766,24 +1766,6 @@ mod tests {
|
||||
.unwrap_or_else(|e| panic!("{e:?}"));
|
||||
}
|
||||
|
||||
/// A parameter or local named like a `bool` uniform hides it in its function (Pixel
|
||||
/// Perfect's `fogify(..., in bool isSpectator, ...)`); elsewhere the uniform is read.
|
||||
#[test]
|
||||
fn bool_uniforms_hidden_by_parameters_and_locals() {
|
||||
let fsh = "#version 330\nuniform bool hideGUI;\nout vec4 c;\n\
|
||||
float proto(bool hideGUI);\n\
|
||||
float f(in bool hideGUI) { return hideGUI ? 1.0 : 0.0; }\n\
|
||||
float g() { bool hideGUI = gl_FragCoord.x > 0.5; return hideGUI ? 2.0 : 0.0; }\n\
|
||||
void main() { c = vec4(f(true), g(), proto(false), hideGUI ? 1.0 : 0.0); }\n\
|
||||
float proto(bool hideGUI) { return hideGUI ? 3.0 : 0.0; }\n";
|
||||
let p = program(
|
||||
&[("composite.vsh", VSH_120), ("composite.fsh", fsh)],
|
||||
Target::Buffers,
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("{e:?}"));
|
||||
assert!(p.interface.uniforms.iter().any(|u| u.name == "hideGUI"));
|
||||
}
|
||||
|
||||
/// GLSL's `dot` and `normalize` take a `float` too (genType); naga's take vectors only. A
|
||||
/// pack's own `dot` is kept.
|
||||
#[test]
|
||||
|
||||
@@ -108,8 +108,6 @@ impl Stage<'_> {
|
||||
let mut params: HashMap<String, String> = HashMap::new();
|
||||
// Names of samplers a local variable or parameter of the function hides.
|
||||
let mut hidden: Vec<(&str, usize)> = Vec::new();
|
||||
// Names of `bool` uniforms a parameter or local of the function hides.
|
||||
let mut hidden_bools: Vec<&str> = Vec::new();
|
||||
let mut depth = 0;
|
||||
let mut skip_until = 0;
|
||||
// The `;` that closes a statement we rewrite, and what is written in its place.
|
||||
@@ -230,12 +228,9 @@ impl Stage<'_> {
|
||||
if depth == 0 {
|
||||
params.clear();
|
||||
hidden.clear();
|
||||
hidden_bools.clear();
|
||||
returns = None;
|
||||
}
|
||||
}
|
||||
// A prototype's parameters hide nothing past it.
|
||||
";" if depth == 0 => hidden_bools.clear(),
|
||||
"(" => {
|
||||
let callee = prev(i).map_or("", |j| self.tokens[j]);
|
||||
let close = if matches!(callee, "shadow2D" | "shadow2DLod" | "shadow2DProj") {
|
||||
@@ -330,17 +325,7 @@ impl Stage<'_> {
|
||||
continue;
|
||||
}
|
||||
if uniforms.get(t).is_some_and(|ty| ty == "bool") {
|
||||
// `bool hideGUI`: a parameter or local of the same name hides the uniform to
|
||||
// the function's end; `.hideGUI` is a member.
|
||||
let before = prev(i).map(|j| self.tokens[j]);
|
||||
if before.is_some_and(|b| is_ident(b) && !matches!(b, "return" | "case" | "else")) {
|
||||
hidden_bools.push(t);
|
||||
}
|
||||
if before == Some(".") || hidden_bools.contains(&t) {
|
||||
out.push_str(t);
|
||||
} else {
|
||||
write!(out, "(hz_bool_{t} != 0)").unwrap();
|
||||
}
|
||||
write!(out, "(hz_bool_{t} != 0)").unwrap();
|
||||
continue;
|
||||
}
|
||||
let replaced: Option<String> = match t {
|
||||
|
||||
Reference in new issue
Block a user