Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 46951a0

Browse files
authored
Validate storage buffer access (#2415)
* validate storage buffer access * remove GLSL writeonly buffer test
1 parent 535701f commit 46951a0

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/valid/interface.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum GlobalVariableError {
3333
),
3434
#[error("Initializer doesn't match the variable type")]
3535
InitializerType,
36+
#[error("Storage address space doesn't support write-only access")]
37+
StorageAddressSpaceWriteOnlyNotSupported,
3638
}
3739

3840
#[derive(Clone, Debug, thiserror::Error)]
@@ -416,7 +418,7 @@ impl super::Validator {
416418
crate::AddressSpace::Function => {
417419
return Err(GlobalVariableError::InvalidUsage(var.space))
418420
}
419-
crate::AddressSpace::Storage { .. } => {
421+
crate::AddressSpace::Storage { access } => {
420422
if let Err((ty_handle, disalignment)) = type_info.storage_layout {
421423
if self.flags.contains(super::ValidationFlags::STRUCT_LAYOUTS) {
422424
return Err(GlobalVariableError::Alignment(
@@ -426,6 +428,9 @@ impl super::Validator {
426428
));
427429
}
428430
}
431+
if access == crate::StorageAccess::STORE {
432+
return Err(GlobalVariableError::StorageAddressSpaceWriteOnlyNotSupported);
433+
}
429434
(TypeFlags::DATA | TypeFlags::HOST_SHAREABLE, true)
430435
}
431436
crate::AddressSpace::Uniform => {

tests/in/glsl/buffer.frag

-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ layout(set = 0, binding = 0) buffer testBufferBlock {
44
uint[] data;
55
} testBuffer;
66

7-
layout(set = 0, binding = 1) writeonly buffer testBufferWriteOnlyBlock {
8-
uint[] data;
9-
} testBufferWriteOnly;
10-
117
layout(set = 0, binding = 2) readonly buffer testBufferReadOnlyBlock {
128
uint[] data;
139
} testBufferReadOnly;
@@ -16,7 +12,5 @@ void main() {
1612
uint a = testBuffer.data[0];
1713
testBuffer.data[1] = 2;
1814

19-
testBufferWriteOnly.data[1] = 2;
20-
2115
uint b = testBufferReadOnly.data[0];
2216
}

tests/out/wgsl/buffer-frag.wgsl

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,24 @@ struct testBufferBlock {
22
data: array<u32>,
33
}
44

5-
struct testBufferWriteOnlyBlock {
6-
data: array<u32>,
7-
}
8-
95
struct testBufferReadOnlyBlock {
106
data: array<u32>,
117
}
128

139
@group(0) @binding(0)
1410
var<storage, read_write> testBuffer: testBufferBlock;
15-
@group(0) @binding(1)
16-
var<storage, read_write> testBufferWriteOnly: testBufferWriteOnlyBlock;
1711
@group(0) @binding(2)
1812
var<storage> testBufferReadOnly: testBufferReadOnlyBlock;
1913

2014
fn main_1() {
2115
var a: u32;
2216
var b: u32;
2317

24-
let _e12 = testBuffer.data[0];
25-
a = _e12;
18+
let _e9 = testBuffer.data[0];
19+
a = _e9;
2620
testBuffer.data[1] = u32(2);
27-
testBufferWriteOnly.data[1] = u32(2);
28-
let _e27 = testBufferReadOnly.data[0];
29-
b = _e27;
21+
let _e19 = testBufferReadOnly.data[0];
22+
b = _e19;
3023
return;
3124
}
3225

0 commit comments

Comments
 (0)