Skip to content

Commit

Permalink
glsl-in: Fix memory qualifiers being inverted
Browse files Browse the repository at this point in the history
Adds some documentation to better explain how the memory qualifier works
troughout the parser and some storage textures tests.
  • Loading branch information
JCapucho committed Mar 17, 2022
1 parent f90e563 commit 4c68d74
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/front/glsl/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ pub struct TypeQualifiers<'a> {
pub interpolation: Option<(Interpolation, Span)>,
pub precision: Option<(Precision, Span)>,
pub sampling: Option<(Sampling, Span)>,
/// Memory qualifiers used in the declaration to reduce storage access to be used
/// in declarations that support it (storage images and buffers)
pub storage_acess: Option<(StorageAccess, Span)>,
pub layout_qualifiers: crate::FastHashMap<QualifierKey<'a>, (QualifierValue, Span)>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl<'a> Iterator for Lexer<'a> {
"mediump" => TokenValue::PrecisionQualifier(Precision::Medium),
"lowp" => TokenValue::PrecisionQualifier(Precision::Low),
"restrict" => TokenValue::Restrict,
"readonly" => TokenValue::StorageAccess(StorageAccess::LOAD),
"writeonly" => TokenValue::StorageAccess(StorageAccess::STORE),
"readonly" => TokenValue::MemoryQualifier(StorageAccess::STORE),
"writeonly" => TokenValue::MemoryQualifier(StorageAccess::LOAD),
// values
"true" => TokenValue::BoolConstant(true),
"false" => TokenValue::BoolConstant(false),
Expand Down
4 changes: 2 additions & 2 deletions src/front/glsl/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'source> ParsingContext<'source> {
| TokenValue::Shared
| TokenValue::Buffer
| TokenValue::Restrict
| TokenValue::StorageAccess(_)
| TokenValue::MemoryQualifier(_)
| TokenValue::Layout => true,
_ => false,
})
Expand Down Expand Up @@ -219,7 +219,7 @@ impl<'source> ParsingContext<'source> {

qualifiers.precision = Some((p, token.meta));
}
TokenValue::StorageAccess(access) => {
TokenValue::MemoryQualifier(access) => {
let storage_access = qualifiers
.storage_acess
.get_or_insert((crate::StorageAccess::empty(), Span::default()));
Expand Down
6 changes: 5 additions & 1 deletion src/front/glsl/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ pub enum TokenValue {
Shared,

Restrict,
StorageAccess(crate::StorageAccess),
/// A `glsl` memory qualifier such as `writeonly`
///
/// The associated [`crate::StorageAccess`] is the access being forbidden
/// (for example `writeonly` has an associated value of [`crate::StorageAccess::LOAD`])
MemoryQualifier(crate::StorageAccess),

Interpolation(Interpolation),
Sampling(Sampling),
Expand Down
18 changes: 18 additions & 0 deletions tests/in/glsl/images.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ layout(rgba8, binding = 4) uniform image1DArray img1DArray;
layout(rgba8, binding = 5) uniform image2DArray img2DArray;
// layout(rgba8, binding = 6) uniform imageCubeArray imgCubeArray;

layout(rgba8, binding = 7) readonly uniform image2D imgReadOnly;
layout(rgba8, binding = 8) writeonly uniform image2D imgWriteOnly;
layout(rgba8, binding = 9) writeonly readonly uniform image2D imgWriteReadOnly;

void testImg1D(in int coord) {
int size = imageSize(img1D);
vec4 c = imageLoad(img1D, coord);
Expand Down Expand Up @@ -52,4 +56,18 @@ void testImg3D(in ivec3 coord) {
// imageStore(imgCubeArray, coord, vec4(2));
// }

void testImgReadOnly(in ivec2 coord) {
vec2 size = imageSize(img2D);
vec4 c = imageLoad(imgReadOnly, coord);
}

void testImgWriteOnly(in ivec2 coord) {
vec2 size = imageSize(img2D);
imageStore(imgWriteOnly, coord, vec4(2));
}

void testImgWriteReadOnly(in ivec2 coord) {
vec2 size = imageSize(imgWriteReadOnly);
}

void main() {}

0 comments on commit 4c68d74

Please sign in to comment.