Validate storage buffer access (#2415)

* validate storage buffer access

* remove GLSL writeonly buffer test
This commit is contained in:
Teodor Tanasoaia authored and GitHub committed 2023-07-31 15:59:17 +02:00
1 parent 535701f6b2
commit 46951a09c0
3 files changed
+10 -18

No files matched your search

+6 -1
View File
@@ -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 => {
-6
View File
@@ -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];
}
+4 -11
View File
@@ -2,18 +2,12 @@ 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;
@@ -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;
}