diff --git a/src/valid/interface.rs b/src/valid/interface.rs index f1f9548a72..58ae82ce61 100644 --- a/src/valid/interface.rs +++ b/src/valid/interface.rs @@ -33,6 +33,8 @@ pub enum GlobalVariableError { ), #[error("Initializer doesn't match the variable type")] InitializerType, + #[error("Storage address space doesn't support write-only access")] + StorageAddressSpaceWriteOnlyNotSupported, } #[derive(Clone, Debug, thiserror::Error)] @@ -416,7 +418,7 @@ impl super::Validator { crate::AddressSpace::Function => { return Err(GlobalVariableError::InvalidUsage(var.space)) } - crate::AddressSpace::Storage { .. } => { + crate::AddressSpace::Storage { access } => { if let Err((ty_handle, disalignment)) = type_info.storage_layout { if self.flags.contains(super::ValidationFlags::STRUCT_LAYOUTS) { return Err(GlobalVariableError::Alignment( @@ -426,6 +428,9 @@ impl super::Validator { )); } } + if access == crate::StorageAccess::STORE { + return Err(GlobalVariableError::StorageAddressSpaceWriteOnlyNotSupported); + } (TypeFlags::DATA | TypeFlags::HOST_SHAREABLE, true) } crate::AddressSpace::Uniform => { diff --git a/tests/in/glsl/buffer.frag b/tests/in/glsl/buffer.frag index dc50aae2ed..e57380f46e 100644 --- a/tests/in/glsl/buffer.frag +++ b/tests/in/glsl/buffer.frag @@ -4,10 +4,6 @@ layout(set = 0, binding = 0) buffer testBufferBlock { uint[] data; } testBuffer; -layout(set = 0, binding = 1) writeonly buffer testBufferWriteOnlyBlock { - uint[] data; -} testBufferWriteOnly; - layout(set = 0, binding = 2) readonly buffer testBufferReadOnlyBlock { uint[] data; } testBufferReadOnly; @@ -16,7 +12,5 @@ void main() { uint a = testBuffer.data[0]; testBuffer.data[1] = 2; - testBufferWriteOnly.data[1] = 2; - uint b = testBufferReadOnly.data[0]; } diff --git a/tests/out/wgsl/buffer-frag.wgsl b/tests/out/wgsl/buffer-frag.wgsl index 4f561b4273..73e543ca76 100644 --- a/tests/out/wgsl/buffer-frag.wgsl +++ b/tests/out/wgsl/buffer-frag.wgsl @@ -2,18 +2,12 @@ struct testBufferBlock { data: array, } -struct testBufferWriteOnlyBlock { - data: array, -} - struct testBufferReadOnlyBlock { data: array, } @group(0) @binding(0) var testBuffer: testBufferBlock; -@group(0) @binding(1) -var testBufferWriteOnly: testBufferWriteOnlyBlock; @group(0) @binding(2) var testBufferReadOnly: testBufferReadOnlyBlock; @@ -21,12 +15,11 @@ fn main_1() { var a: u32; var b: u32; - let _e12 = testBuffer.data[0]; - a = _e12; + let _e9 = testBuffer.data[0]; + a = _e9; testBuffer.data[1] = u32(2); - testBufferWriteOnly.data[1] = u32(2); - let _e27 = testBufferReadOnly.data[0]; - b = _e27; + let _e19 = testBufferReadOnly.data[0]; + b = _e19; return; }