Skip to content

Commit

Permalink
Validate storage buffer access (#2415)
Browse files Browse the repository at this point in the history
* validate storage buffer access

* remove GLSL writeonly buffer test
  • Loading branch information
teoxoy authored Jul 31, 2023
1 parent 535701f commit 46951a0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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(
Expand All @@ -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 => {
Expand Down
6 changes: 0 additions & 6 deletions tests/in/glsl/buffer.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +12,5 @@ void main() {
uint a = testBuffer.data[0];
testBuffer.data[1] = 2;

testBufferWriteOnly.data[1] = 2;

uint b = testBufferReadOnly.data[0];
}
15 changes: 4 additions & 11 deletions tests/out/wgsl/buffer-frag.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@ struct testBufferBlock {
data: array<u32>,
}

struct testBufferWriteOnlyBlock {
data: array<u32>,
}

struct testBufferReadOnlyBlock {
data: array<u32>,
}

@group(0) @binding(0)
var<storage, read_write> testBuffer: testBufferBlock;
@group(0) @binding(1)
var<storage, read_write> testBufferWriteOnly: testBufferWriteOnlyBlock;
@group(0) @binding(2)
var<storage> testBufferReadOnly: testBufferReadOnlyBlock;

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;
}

Expand Down

0 comments on commit 46951a0

Please sign in to comment.