[glsl-in] Make sure to Load on a ValuePointer as well

Fixes issues with indexing vectors.
This commit is contained in:
Jasper St. Pierre 2021-07-01 22:40:53 -07:00 committed by Dzmitry Malyshau
parent 78e1304d42
commit 0b9af95793
2 changed files with 27 additions and 6 deletions

View File

@ -485,12 +485,15 @@ impl<'function> Context<'function> {
self.add_expression(Expression::Access { base, index }, body)
});
if let TypeInner::Pointer { .. } = *program.resolve_type(self, pointer, meta)? {
if !lhs {
return Ok((
Some(self.add_expression(Expression::Load { pointer }, body)),
meta,
));
if !lhs {
match *program.resolve_type(self, pointer, meta)? {
TypeInner::Pointer { .. } | TypeInner::ValuePointer { .. } => {
return Ok((
Some(self.add_expression(Expression::Load { pointer }, body)),
meta,
));
},
_ => {},
}
}

View File

@ -673,3 +673,21 @@ fn swizzles() {
)
.unwrap_err();
}
#[test]
fn vector_indexing() {
let mut entry_points = crate::FastHashMap::default();
entry_points.insert("".to_string(), ShaderStage::Fragment);
parse_program(
r#"
# version 450
float main(int index) {
vec4 v = vec4(1.0, 2.0, 3.0, 4.0);
return v[index] + 1.0;
}
"#,
&entry_points,
)
.unwrap();
}