mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-23 07:51:08 +01:00
Add coherent and volatile memory decorations for storage buffers. (#9168)
This commit is contained in:
65 files changed
+658
-15
No files matched your search
@@ -154,6 +154,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
|
||||
- Initial wgsl-in ray tracing pipelines. By @Vecvec in [#8570](https://github.com/gfx-rs/wgpu/pull/8570).
|
||||
- wgsl-out ray tracing pipelines. By @Vecvec in [#8970](https://github.com/gfx-rs/wgpu/pull/8970).
|
||||
- Allow parsing shaders which make use of `SPV_KHR_non_semantic_info` for debug info. Also removes `naga::front::spv::SUPPORTED_EXT_SETS`. By @inner-daemons in #8827.
|
||||
- Added memory decorations for storage buffers: `coherent`, supported on all native backends, and `volatile`, only on Vulkan and GL. By @atlv24 in [#9168](https://github.com/gfx-rs/wgpu/pull/9168).
|
||||
|
||||
#### GLES
|
||||
|
||||
|
||||
@@ -642,4 +642,6 @@ pub fn supported_capabilities() -> valid::Capabilities {
|
||||
| Caps::SHADER_FLOAT16_IN_FLOAT32
|
||||
| Caps::SHADER_BARYCENTRICS
|
||||
| Caps::DRAW_INDEX
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::MEMORY_DECORATION_VOLATILE
|
||||
}
|
||||
@@ -699,6 +699,18 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
if let crate::AddressSpace::Storage { access } = global.space {
|
||||
self.write_storage_access(access)?;
|
||||
if global
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
{
|
||||
write!(self.out, "coherent ")?;
|
||||
}
|
||||
if global
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::VOLATILE)
|
||||
{
|
||||
write!(self.out, "volatile ")?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(storage_qualifier) = glsl_storage_qualifier(global.space) {
|
||||
|
||||
@@ -800,8 +800,10 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
// No BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
|
||||
| Caps::STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING
|
||||
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
|
||||
// No COOPERATIVE_MATRIX
|
||||
// No PER_VERTEX
|
||||
// No RAY_TRACING_PIPELINE
|
||||
// No DRAW_INDEX
|
||||
// No COOPERATIVE_MATRIX
|
||||
// No PER_VERTEX
|
||||
// No RAY_TRACING_PIPELINE
|
||||
// No DRAW_INDEX
|
||||
// No MEMORY_DECORATION_VOLATILE
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
}
|
||||
@@ -990,6 +990,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
"b"
|
||||
}
|
||||
crate::AddressSpace::Storage { access } => {
|
||||
if global
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
{
|
||||
write!(self.out, "globallycoherent ")?;
|
||||
}
|
||||
let (prefix, register) = if access.contains(crate::StorageAccess::STORE) {
|
||||
("RW", "u")
|
||||
} else {
|
||||
|
||||
@@ -871,9 +871,11 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
| Caps::STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING
|
||||
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
|
||||
| Caps::COOPERATIVE_MATRIX
|
||||
// No PER_VERTEX
|
||||
// No RAY_TRACING_PIPELINE
|
||||
// No DRAW_INDEX
|
||||
// No PER_VERTEX
|
||||
// No RAY_TRACING_PIPELINE
|
||||
// No DRAW_INDEX
|
||||
// No MEMORY_DECORATION_VOLATILE
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -428,8 +428,16 @@ impl TypedGlobalVariable<'_> {
|
||||
first_time: false,
|
||||
};
|
||||
|
||||
let (space, access, reference) = match var.space.to_msl_name() {
|
||||
let (coherent, space, access, reference) = match var.space.to_msl_name() {
|
||||
Some(space) if self.reference => {
|
||||
let coherent = if var
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
{
|
||||
"coherent "
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let access = if var.space.needs_access_qualifier()
|
||||
&& !self.usage.intersects(valid::GlobalUse::WRITE)
|
||||
{
|
||||
@@ -437,14 +445,15 @@ impl TypedGlobalVariable<'_> {
|
||||
} else {
|
||||
""
|
||||
};
|
||||
(space, access, "&")
|
||||
(coherent, space, access, "&")
|
||||
}
|
||||
_ => ("", "", ""),
|
||||
_ => ("", "", "", ""),
|
||||
};
|
||||
|
||||
Ok(write!(
|
||||
out,
|
||||
"{}{}{}{}{}{} {}",
|
||||
"{}{}{}{}{}{}{} {}",
|
||||
coherent,
|
||||
space,
|
||||
if space.is_empty() { "" } else { " " },
|
||||
ty_name,
|
||||
|
||||
@@ -1191,4 +1191,6 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
|
||||
| Caps::PER_VERTEX
|
||||
// No RAY_TRACING_PIPELINE
|
||||
| Caps::DRAW_INDEX
|
||||
| Caps::MEMORY_DECORATION_COHERENT
|
||||
| Caps::MEMORY_DECORATION_VOLATILE
|
||||
}
|
||||
@@ -3288,6 +3288,19 @@ impl Writer {
|
||||
|
||||
//self.check(class.required_capabilities())?;
|
||||
|
||||
if global_variable
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
{
|
||||
self.decorate(id, Decoration::Coherent, &[]);
|
||||
}
|
||||
if global_variable
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::VOLATILE)
|
||||
{
|
||||
self.decorate(id, Decoration::Volatile, &[]);
|
||||
}
|
||||
|
||||
if self.flags.contains(WriterFlags::DEBUG) {
|
||||
if let Some(ref name) = global_variable.name {
|
||||
self.debugs.push(Instruction::name(id, name));
|
||||
|
||||
@@ -1974,6 +1974,19 @@ impl<W: Write> Writer<W> {
|
||||
writeln!(self.out)?;
|
||||
}
|
||||
|
||||
if global
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
{
|
||||
write!(self.out, "@coherent ")?;
|
||||
}
|
||||
if global
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::VOLATILE)
|
||||
{
|
||||
write!(self.out, "@volatile ")?;
|
||||
}
|
||||
|
||||
// First write global name and address space if supported
|
||||
write!(self.out, "var")?;
|
||||
let (address, maybe_access) = address_space_str(global.space);
|
||||
|
||||
@@ -62,6 +62,7 @@ impl Frontend {
|
||||
binding: None,
|
||||
ty,
|
||||
init: None,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
},
|
||||
meta,
|
||||
);
|
||||
@@ -448,6 +449,7 @@ impl Frontend {
|
||||
binding: None,
|
||||
ty,
|
||||
init,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
},
|
||||
meta,
|
||||
);
|
||||
@@ -636,6 +638,7 @@ impl Frontend {
|
||||
binding,
|
||||
ty,
|
||||
init,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
},
|
||||
meta,
|
||||
);
|
||||
|
||||
@@ -189,6 +189,8 @@ bitflags::bitflags! {
|
||||
struct DecorationFlags: u32 {
|
||||
const NON_READABLE = 0x1;
|
||||
const NON_WRITABLE = 0x2;
|
||||
const COHERENT = 0x4;
|
||||
const VOLATILE = 0x8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +205,17 @@ impl DecorationFlags {
|
||||
}
|
||||
access
|
||||
}
|
||||
|
||||
fn to_memory_decorations(self) -> crate::MemoryDecorations {
|
||||
let mut decorations = crate::MemoryDecorations::empty();
|
||||
if self.contains(DecorationFlags::COHERENT) {
|
||||
decorations |= crate::MemoryDecorations::COHERENT;
|
||||
}
|
||||
if self.contains(DecorationFlags::VOLATILE) {
|
||||
decorations |= crate::MemoryDecorations::VOLATILE;
|
||||
}
|
||||
decorations
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -813,6 +826,12 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
spirv::Decoration::NonWritable => {
|
||||
dec.flags |= DecorationFlags::NON_WRITABLE;
|
||||
}
|
||||
spirv::Decoration::Coherent => {
|
||||
dec.flags |= DecorationFlags::COHERENT;
|
||||
}
|
||||
spirv::Decoration::Volatile => {
|
||||
dec.flags |= DecorationFlags::VOLATILE;
|
||||
}
|
||||
spirv::Decoration::ColMajor => {
|
||||
dec.matrix_major = Some(Majority::Column);
|
||||
}
|
||||
@@ -3007,6 +3026,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
space,
|
||||
ty,
|
||||
init,
|
||||
memory_decorations: dec.flags.to_memory_decorations(),
|
||||
};
|
||||
(Variable::Global, var)
|
||||
}
|
||||
@@ -3054,6 +3074,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
binding: None,
|
||||
ty,
|
||||
init: None,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
};
|
||||
|
||||
let inner = Variable::Input(crate::FunctionArgument {
|
||||
@@ -3114,6 +3135,7 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
|
||||
binding: None,
|
||||
ty,
|
||||
init,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
};
|
||||
let inner = Variable::Output(crate::FunctionResult { ty, binding });
|
||||
(inner, var)
|
||||
|
||||
@@ -1348,6 +1348,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
|
||||
binding,
|
||||
ty,
|
||||
init: initializer,
|
||||
memory_decorations: v.memory_decorations,
|
||||
},
|
||||
span,
|
||||
);
|
||||
|
||||
@@ -269,6 +269,9 @@ pub struct GlobalVariable<'a> {
|
||||
pub ty: Option<TemplateElaboratedIdent<'a>>,
|
||||
pub init: Option<Handle<Expression<'a>>>,
|
||||
pub doc_comments: Vec<&'a str>,
|
||||
|
||||
/// Memory decorations for this variable (`@coherent`, `@volatile`).
|
||||
pub memory_decorations: crate::MemoryDecorations,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -891,6 +891,7 @@ impl Parser {
|
||||
ty,
|
||||
init,
|
||||
doc_comments: Vec::new(),
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1849,6 +1850,7 @@ impl Parser {
|
||||
let mut mesh_output = ParsedAttribute::default();
|
||||
|
||||
let mut must_use: ParsedAttribute<Span> = ParsedAttribute::default();
|
||||
let mut memory_decorations = crate::MemoryDecorations::empty();
|
||||
|
||||
let mut dependencies = FastIndexSet::default();
|
||||
let mut ctx = ExpressionContext {
|
||||
@@ -2017,6 +2019,12 @@ impl Parser {
|
||||
"must_use" => {
|
||||
must_use.set(name_span, name_span)?;
|
||||
}
|
||||
"coherent" => {
|
||||
memory_decorations |= crate::MemoryDecorations::COHERENT;
|
||||
}
|
||||
"volatile" => {
|
||||
memory_decorations |= crate::MemoryDecorations::VOLATILE;
|
||||
}
|
||||
_ => return Err(Box::new(Error::UnknownAttribute(name_span))),
|
||||
}
|
||||
}
|
||||
@@ -2116,6 +2124,7 @@ impl Parser {
|
||||
let mut var = self.variable_decl(lexer, &mut ctx)?;
|
||||
var.binding = binding.take();
|
||||
var.doc_comments = doc_comments;
|
||||
var.memory_decorations = memory_decorations;
|
||||
Some(ast::GlobalDeclKind::Var(var))
|
||||
}
|
||||
(Token::Word("fn"), _) => {
|
||||
|
||||
@@ -727,6 +727,22 @@ bitflags::bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
/// Memory decorations for global variables.
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
|
||||
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||
pub struct MemoryDecorations: u8 {
|
||||
/// Reads and writes are automatically visible to other invocations
|
||||
/// without explicit barriers.
|
||||
const COHERENT = 0x1;
|
||||
/// The variable may be modified by something external to the shader,
|
||||
/// preventing certain compiler optimizations.
|
||||
const VOLATILE = 0x2;
|
||||
}
|
||||
}
|
||||
|
||||
/// Image storage format.
|
||||
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
|
||||
#[cfg_attr(feature = "serialize", derive(Serialize))]
|
||||
@@ -1170,6 +1186,13 @@ pub struct GlobalVariable {
|
||||
///
|
||||
/// This refers to an [`Expression`] in [`Module::global_expressions`].
|
||||
pub init: Option<Handle<Expression>>,
|
||||
/// Memory decorations for this variable.
|
||||
///
|
||||
/// These are meaningful for storage address space variables in SPIR-V,
|
||||
/// where they map to SPIR-V memory decorations on the variable.
|
||||
///
|
||||
/// In WGSL, these can be set with attributes like `@coherent` or `@volatile`.
|
||||
pub memory_decorations: MemoryDecorations,
|
||||
}
|
||||
|
||||
/// Variable defined at function level.
|
||||
|
||||
@@ -1323,6 +1323,7 @@ fn uniform_control_flow() {
|
||||
ty,
|
||||
space: crate::AddressSpace::Handle,
|
||||
binding: None,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
@@ -1333,6 +1334,7 @@ fn uniform_control_flow() {
|
||||
ty,
|
||||
binding: None,
|
||||
space: crate::AddressSpace::Uniform,
|
||||
memory_decorations: crate::MemoryDecorations::empty(),
|
||||
},
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
@@ -160,6 +160,7 @@ impl super::Validator {
|
||||
binding: _,
|
||||
ty,
|
||||
init,
|
||||
memory_decorations: _,
|
||||
} = global_variable;
|
||||
validate_type(ty)?;
|
||||
if let Some(init_expr) = init {
|
||||
|
||||
@@ -47,6 +47,12 @@ pub enum GlobalVariableError {
|
||||
InvalidImmediateType(#[source] ImmediateError),
|
||||
#[error("Task payload must not be zero-sized")]
|
||||
ZeroSizedTaskPayload,
|
||||
#[error("Memory decorations (`@coherent`, `@volatile`) are only valid for variables in the `storage` address space")]
|
||||
InvalidMemoryDecorationsAddressSpace,
|
||||
#[error("`@coherent` requires the MEMORY_DECORATION_COHERENT capability")]
|
||||
CoherentNotSupported,
|
||||
#[error("`@volatile` requires the MEMORY_DECORATION_VOLATILE capability")]
|
||||
VolatileNotSupported,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
@@ -1127,6 +1133,30 @@ impl super::Validator {
|
||||
}
|
||||
}
|
||||
|
||||
if !var.memory_decorations.is_empty()
|
||||
&& !matches!(var.space, crate::AddressSpace::Storage { .. })
|
||||
{
|
||||
return Err(GlobalVariableError::InvalidMemoryDecorationsAddressSpace);
|
||||
}
|
||||
if var
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::COHERENT)
|
||||
&& !self
|
||||
.capabilities
|
||||
.contains(Capabilities::MEMORY_DECORATION_COHERENT)
|
||||
{
|
||||
return Err(GlobalVariableError::CoherentNotSupported);
|
||||
}
|
||||
if var
|
||||
.memory_decorations
|
||||
.contains(crate::MemoryDecorations::VOLATILE)
|
||||
&& !self
|
||||
.capabilities
|
||||
.contains(Capabilities::MEMORY_DECORATION_VOLATILE)
|
||||
{
|
||||
return Err(GlobalVariableError::VolatileNotSupported);
|
||||
}
|
||||
|
||||
if let Some(init) = var.init {
|
||||
match var.space {
|
||||
crate::AddressSpace::Private | crate::AddressSpace::Function => {}
|
||||
|
||||
@@ -210,6 +210,10 @@ bitflags::bitflags! {
|
||||
const DRAW_INDEX = 1 << 39;
|
||||
/// Support for binding arrays of acceleration structures.
|
||||
const ACCELERATION_STRUCTURE_BINDING_ARRAY = 1 << 40;
|
||||
/// Support for the `@coherent` memory decoration on storage buffers.
|
||||
const MEMORY_DECORATION_COHERENT = 1 << 41;
|
||||
/// Support for the `@volatile` memory decoration on storage buffers.
|
||||
const MEMORY_DECORATION_VOLATILE = 1 << 42;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
capabilities = "MEMORY_DECORATION_COHERENT"
|
||||
targets = "SPIRV | HLSL | GLSL | WGSL | METAL"
|
||||
|
||||
[spv]
|
||||
version = [1, 0]
|
||||
|
||||
[glsl]
|
||||
version = { Desktop = 430 }
|
||||
|
||||
[msl]
|
||||
lang_version = [3, 2]
|
||||
@@ -0,0 +1,14 @@
|
||||
struct Data {
|
||||
values: array<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) @coherent
|
||||
var<storage, read_write> coherent_buf: Data;
|
||||
|
||||
@group(0) @binding(1)
|
||||
var<storage, read_write> plain_buf: Data;
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
coherent_buf.values[0] = plain_buf.values[0];
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
capabilities = "MEMORY_DECORATION_COHERENT | MEMORY_DECORATION_VOLATILE"
|
||||
targets = "SPIRV | GLSL | WGSL"
|
||||
|
||||
[spv]
|
||||
version = [1, 0]
|
||||
|
||||
[glsl]
|
||||
version = { Desktop = 430 }
|
||||
@@ -0,0 +1,21 @@
|
||||
struct Data {
|
||||
values: array<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) @coherent
|
||||
var<storage, read_write> coherent_buf: Data;
|
||||
|
||||
@group(0) @binding(1) @volatile
|
||||
var<storage, read_write> volatile_buf: Data;
|
||||
|
||||
@group(0) @binding(2) @coherent @volatile
|
||||
var<storage, read_write> both_buf: Data;
|
||||
|
||||
@group(0) @binding(3)
|
||||
var<storage, read_write> plain_buf: Data;
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
coherent_buf.values[0] = volatile_buf.values[0];
|
||||
both_buf.values[0] = plain_buf.values[0];
|
||||
}
|
||||
@@ -111,6 +111,7 @@ fn populate_atomic_result() {
|
||||
binding: None,
|
||||
ty: ty_atomic_u32,
|
||||
init: None,
|
||||
memory_decorations: naga::MemoryDecorations::empty(),
|
||||
},
|
||||
span,
|
||||
);
|
||||
@@ -281,6 +282,7 @@ fn emit_workgroup_uniform_load_result() {
|
||||
binding: None,
|
||||
ty: ty_u32,
|
||||
init: None,
|
||||
memory_decorations: naga::MemoryDecorations::empty(),
|
||||
},
|
||||
span,
|
||||
);
|
||||
@@ -879,6 +881,7 @@ fn invalid_local_var_override_sized_array() {
|
||||
binding: None,
|
||||
ty: ty_array,
|
||||
init: None,
|
||||
memory_decorations: naga::MemoryDecorations::empty(),
|
||||
},
|
||||
span,
|
||||
);
|
||||
@@ -1633,6 +1636,7 @@ fn unexpected_task_payload() {
|
||||
binding: None,
|
||||
ty: ty_payload,
|
||||
init: None,
|
||||
memory_decorations: ir::MemoryDecorations::empty(),
|
||||
},
|
||||
err_span,
|
||||
);
|
||||
@@ -1665,3 +1669,77 @@ fn unexpected_task_payload() {
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coherent_requires_capability() {
|
||||
let module = naga::front::wgsl::parse_str(
|
||||
"struct S { x: u32 }
|
||||
@group(0) @binding(0) @coherent var<storage, read_write> buf: S;",
|
||||
)
|
||||
.expect("module should parse");
|
||||
|
||||
let err = valid::Validator::new(ValidationFlags::default(), Capabilities::empty())
|
||||
.validate(&module)
|
||||
.expect_err("should fail without capability");
|
||||
assert!(matches!(
|
||||
err.into_inner(),
|
||||
valid::ValidationError::GlobalVariable {
|
||||
source: valid::GlobalVariableError::CoherentNotSupported,
|
||||
..
|
||||
}
|
||||
));
|
||||
|
||||
let result = valid::Validator::new(
|
||||
ValidationFlags::default(),
|
||||
Capabilities::MEMORY_DECORATION_COHERENT,
|
||||
)
|
||||
.validate(&module);
|
||||
assert!(result.is_ok(), "should succeed with capability: {result:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn volatile_requires_capability() {
|
||||
let module = naga::front::wgsl::parse_str(
|
||||
"struct S { x: u32 }
|
||||
@group(0) @binding(0) @volatile var<storage, read_write> buf: S;",
|
||||
)
|
||||
.expect("module should parse");
|
||||
|
||||
let err = valid::Validator::new(ValidationFlags::default(), Capabilities::empty())
|
||||
.validate(&module)
|
||||
.expect_err("should fail without capability");
|
||||
assert!(matches!(
|
||||
err.into_inner(),
|
||||
valid::ValidationError::GlobalVariable {
|
||||
source: valid::GlobalVariableError::VolatileNotSupported,
|
||||
..
|
||||
}
|
||||
));
|
||||
|
||||
let result = valid::Validator::new(
|
||||
ValidationFlags::default(),
|
||||
Capabilities::MEMORY_DECORATION_VOLATILE,
|
||||
)
|
||||
.validate(&module);
|
||||
assert!(result.is_ok(), "should succeed with capability: {result:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memory_decorations_require_storage_address_space() {
|
||||
let module = naga::front::wgsl::parse_str("@coherent var<workgroup> wg: array<u32, 4>;")
|
||||
.expect("module should parse");
|
||||
|
||||
let err = valid::Validator::new(
|
||||
ValidationFlags::default(),
|
||||
Capabilities::MEMORY_DECORATION_COHERENT | Capabilities::MEMORY_DECORATION_VOLATILE,
|
||||
)
|
||||
.validate(&module)
|
||||
.expect_err("should fail on non-storage address space");
|
||||
assert!(matches!(
|
||||
err.into_inner(),
|
||||
valid::ValidationError::GlobalVariable {
|
||||
source: valid::GlobalVariableError::InvalidMemoryDecorationsAddressSpace,
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#version 430 core
|
||||
#extension GL_ARB_compute_shader : require
|
||||
#extension GL_ARB_shader_storage_buffer_object : require
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
layout(std430) coherent buffer Data_block_0Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_0_cs;
|
||||
|
||||
layout(std430) buffer Data_block_1Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_1_cs;
|
||||
|
||||
|
||||
void main() {
|
||||
uint _e6 = _group_0_binding_1_cs.values[0];
|
||||
_group_0_binding_0_cs.values[0] = _e6;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#version 430 core
|
||||
#extension GL_ARB_compute_shader : require
|
||||
#extension GL_ARB_shader_storage_buffer_object : require
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
layout(std430) coherent buffer Data_block_0Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_0_cs;
|
||||
|
||||
layout(std430) volatile buffer Data_block_1Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_1_cs;
|
||||
|
||||
layout(std430) coherent volatile buffer Data_block_2Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_2_cs;
|
||||
|
||||
layout(std430) buffer Data_block_3Compute {
|
||||
uint values[];
|
||||
} _group_0_binding_3_cs;
|
||||
|
||||
|
||||
void main() {
|
||||
uint _e6 = _group_0_binding_1_cs.values[0];
|
||||
_group_0_binding_0_cs.values[0] = _e6;
|
||||
uint _e13 = _group_0_binding_3_cs.values[0];
|
||||
_group_0_binding_2_cs.values[0] = _e13;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
globallycoherent RWByteAddressBuffer coherent_buf : register(u0);
|
||||
RWByteAddressBuffer plain_buf : register(u1);
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main()
|
||||
{
|
||||
uint _e6 = asuint(plain_buf.Load(0+0));
|
||||
coherent_buf.Store(0+0, asuint(_e6));
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
(
|
||||
vertex:[
|
||||
],
|
||||
fragment:[
|
||||
],
|
||||
compute:[
|
||||
(
|
||||
entry_point:"main",
|
||||
target_profile:"cs_5_1",
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -91,6 +91,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
@@ -103,6 +104,7 @@
|
||||
)),
|
||||
ty: 4,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
@@ -113,6 +115,7 @@
|
||||
)),
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -159,6 +159,7 @@
|
||||
)),
|
||||
ty: 4,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
@@ -171,6 +172,7 @@
|
||||
)),
|
||||
ty: 7,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: None,
|
||||
@@ -181,6 +183,7 @@
|
||||
)),
|
||||
ty: 10,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -267,6 +267,7 @@
|
||||
)),
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("sampler_shadow"),
|
||||
@@ -277,6 +278,7 @@
|
||||
)),
|
||||
ty: 13,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("u_globals"),
|
||||
@@ -287,6 +289,7 @@
|
||||
)),
|
||||
ty: 8,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_lights"),
|
||||
@@ -299,6 +302,7 @@
|
||||
)),
|
||||
ty: 12,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("in_position_fs"),
|
||||
@@ -306,6 +310,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("in_normal_fs"),
|
||||
@@ -313,6 +318,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("out_color_fs"),
|
||||
@@ -320,6 +326,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -470,6 +470,7 @@
|
||||
)),
|
||||
ty: 6,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("sampler_shadow"),
|
||||
@@ -480,6 +481,7 @@
|
||||
)),
|
||||
ty: 29,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("u_globals"),
|
||||
@@ -490,6 +492,7 @@
|
||||
)),
|
||||
ty: 12,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_lights"),
|
||||
@@ -502,6 +505,7 @@
|
||||
)),
|
||||
ty: 19,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("in_position_fs"),
|
||||
@@ -509,6 +513,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("in_normal_fs"),
|
||||
@@ -516,6 +521,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("out_color_fs"),
|
||||
@@ -523,6 +529,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -215,6 +215,7 @@
|
||||
binding: None,
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Uv"),
|
||||
@@ -222,6 +223,7 @@
|
||||
binding: None,
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Position"),
|
||||
@@ -229,6 +231,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -239,6 +242,7 @@
|
||||
)),
|
||||
ty: 4,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -246,6 +250,7 @@
|
||||
binding: None,
|
||||
ty: 7,
|
||||
init: Some(11),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -256,6 +261,7 @@
|
||||
)),
|
||||
ty: 9,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -266,6 +272,7 @@
|
||||
)),
|
||||
ty: 10,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Normal"),
|
||||
@@ -273,6 +280,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -316,6 +316,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Uv"),
|
||||
@@ -323,6 +324,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Position"),
|
||||
@@ -330,6 +332,7 @@
|
||||
binding: None,
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -340,6 +343,7 @@
|
||||
)),
|
||||
ty: 8,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -347,6 +351,7 @@
|
||||
binding: None,
|
||||
ty: 15,
|
||||
init: Some(13),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -357,6 +362,7 @@
|
||||
)),
|
||||
ty: 18,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some(""),
|
||||
@@ -367,6 +373,7 @@
|
||||
)),
|
||||
ty: 21,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("Vertex_Normal"),
|
||||
@@ -374,6 +381,7 @@
|
||||
binding: None,
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -434,6 +434,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: Some(6),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("bar"),
|
||||
@@ -446,6 +447,7 @@
|
||||
)),
|
||||
ty: 14,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("baz"),
|
||||
@@ -456,6 +458,7 @@
|
||||
)),
|
||||
ty: 16,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("qux"),
|
||||
@@ -468,6 +471,7 @@
|
||||
)),
|
||||
ty: 17,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("nested_mat_cx2"),
|
||||
@@ -478,6 +482,7 @@
|
||||
)),
|
||||
ty: 20,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -434,6 +434,7 @@
|
||||
binding: None,
|
||||
ty: 3,
|
||||
init: Some(6),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("bar"),
|
||||
@@ -446,6 +447,7 @@
|
||||
)),
|
||||
ty: 14,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("baz"),
|
||||
@@ -456,6 +458,7 @@
|
||||
)),
|
||||
ty: 16,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("qux"),
|
||||
@@ -468,6 +471,7 @@
|
||||
)),
|
||||
ty: 17,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("nested_mat_cx2"),
|
||||
@@ -478,6 +482,7 @@
|
||||
)),
|
||||
ty: 20,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
binding: None,
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
binding: None,
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
)),
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
)),
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: Some(10),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("store_override"),
|
||||
@@ -95,6 +96,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: Some(10),
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("store_override"),
|
||||
@@ -95,6 +96,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
)),
|
||||
ty: 0,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rg_r"),
|
||||
@@ -97,6 +98,7 @@
|
||||
)),
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rgba_r"),
|
||||
@@ -107,6 +109,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_r_w"),
|
||||
@@ -117,6 +120,7 @@
|
||||
)),
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rg_w"),
|
||||
@@ -127,6 +131,7 @@
|
||||
)),
|
||||
ty: 4,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rgba_w"),
|
||||
@@ -137,6 +142,7 @@
|
||||
)),
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
)),
|
||||
ty: 0,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rg_r"),
|
||||
@@ -97,6 +98,7 @@
|
||||
)),
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rgba_r"),
|
||||
@@ -107,6 +109,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_r_w"),
|
||||
@@ -117,6 +120,7 @@
|
||||
)),
|
||||
ty: 3,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rg_w"),
|
||||
@@ -127,6 +131,7 @@
|
||||
)),
|
||||
ty: 4,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("s_rgba_w"),
|
||||
@@ -137,6 +142,7 @@
|
||||
)),
|
||||
ty: 5,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("sized_no_comma"),
|
||||
@@ -48,6 +49,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("unsized_comma"),
|
||||
@@ -60,6 +62,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("unsized_no_comma"),
|
||||
@@ -72,6 +75,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("sized_no_comma"),
|
||||
@@ -48,6 +49,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("unsized_comma"),
|
||||
@@ -60,6 +62,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("unsized_no_comma"),
|
||||
@@ -72,6 +75,7 @@
|
||||
)),
|
||||
ty: 2,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
)),
|
||||
ty: 8,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("samp"),
|
||||
@@ -200,6 +201,7 @@
|
||||
)),
|
||||
ty: 9,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
)),
|
||||
ty: 8,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("samp"),
|
||||
@@ -200,6 +201,7 @@
|
||||
)),
|
||||
ty: 9,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [],
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
binding: None,
|
||||
ty: 0,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
)),
|
||||
ty: 0,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("w_mem"),
|
||||
@@ -91,6 +92,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
(
|
||||
name: Some("w_mem2"),
|
||||
@@ -98,6 +100,7 @@
|
||||
binding: None,
|
||||
ty: 1,
|
||||
init: None,
|
||||
memory_decorations: (""),
|
||||
),
|
||||
],
|
||||
global_expressions: [
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// language: metal3.2
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using metal::uint;
|
||||
|
||||
struct _mslBufferSizes {
|
||||
uint size0;
|
||||
uint size1;
|
||||
};
|
||||
|
||||
typedef uint type_1[1];
|
||||
struct Data {
|
||||
type_1 values;
|
||||
};
|
||||
|
||||
kernel void main_(
|
||||
coherent device Data& coherent_buf [[user(fake0)]]
|
||||
, device Data const& plain_buf [[user(fake0)]]
|
||||
, constant _mslBufferSizes& _buffer_sizes [[user(fake0)]]
|
||||
) {
|
||||
uint _e6 = plain_buf.values[0];
|
||||
coherent_buf.values[0] = _e6;
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
; Bound: 19
|
||||
OpCapability Shader
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %10 "main"
|
||||
OpExecutionMode %10 LocalSize 1 1 1
|
||||
OpDecorate %4 ArrayStride 4
|
||||
OpMemberDecorate %5 0 Offset 0
|
||||
OpDecorate %5 Block
|
||||
OpDecorate %6 Coherent
|
||||
OpDecorate %6 DescriptorSet 0
|
||||
OpDecorate %6 Binding 0
|
||||
OpDecorate %8 DescriptorSet 0
|
||||
OpDecorate %8 Binding 1
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeInt 32 0
|
||||
%4 = OpTypeRuntimeArray %3
|
||||
%5 = OpTypeStruct %4
|
||||
%7 = OpTypePointer StorageBuffer %5
|
||||
%6 = OpVariable %7 StorageBuffer
|
||||
%8 = OpVariable %7 StorageBuffer
|
||||
%11 = OpTypeFunction %2
|
||||
%13 = OpTypePointer StorageBuffer %4
|
||||
%14 = OpTypePointer StorageBuffer %3
|
||||
%15 = OpConstant %3 0
|
||||
%10 = OpFunction %2 None %11
|
||||
%9 = OpLabel
|
||||
OpBranch %12
|
||||
%12 = OpLabel
|
||||
%16 = OpAccessChain %14 %8 %15 %15
|
||||
%17 = OpLoad %3 %16
|
||||
%18 = OpAccessChain %14 %6 %15 %15
|
||||
OpStore %18 %17
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,52 @@
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
; Bound: 24
|
||||
OpCapability Shader
|
||||
OpExtension "SPV_KHR_storage_buffer_storage_class"
|
||||
%1 = OpExtInstImport "GLSL.std.450"
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %12 "main"
|
||||
OpExecutionMode %12 LocalSize 1 1 1
|
||||
OpDecorate %4 ArrayStride 4
|
||||
OpMemberDecorate %5 0 Offset 0
|
||||
OpDecorate %5 Block
|
||||
OpDecorate %6 Coherent
|
||||
OpDecorate %6 DescriptorSet 0
|
||||
OpDecorate %6 Binding 0
|
||||
OpDecorate %8 Volatile
|
||||
OpDecorate %8 DescriptorSet 0
|
||||
OpDecorate %8 Binding 1
|
||||
OpDecorate %9 Coherent
|
||||
OpDecorate %9 Volatile
|
||||
OpDecorate %9 DescriptorSet 0
|
||||
OpDecorate %9 Binding 2
|
||||
OpDecorate %10 DescriptorSet 0
|
||||
OpDecorate %10 Binding 3
|
||||
%2 = OpTypeVoid
|
||||
%3 = OpTypeInt 32 0
|
||||
%4 = OpTypeRuntimeArray %3
|
||||
%5 = OpTypeStruct %4
|
||||
%7 = OpTypePointer StorageBuffer %5
|
||||
%6 = OpVariable %7 StorageBuffer
|
||||
%8 = OpVariable %7 StorageBuffer
|
||||
%9 = OpVariable %7 StorageBuffer
|
||||
%10 = OpVariable %7 StorageBuffer
|
||||
%13 = OpTypeFunction %2
|
||||
%15 = OpTypePointer StorageBuffer %4
|
||||
%16 = OpTypePointer StorageBuffer %3
|
||||
%17 = OpConstant %3 0
|
||||
%12 = OpFunction %2 None %13
|
||||
%11 = OpLabel
|
||||
OpBranch %14
|
||||
%14 = OpLabel
|
||||
%18 = OpAccessChain %16 %8 %17 %17
|
||||
%19 = OpLoad %3 %18
|
||||
%20 = OpAccessChain %16 %6 %17 %17
|
||||
OpStore %20 %19
|
||||
%21 = OpAccessChain %16 %10 %17 %17
|
||||
%22 = OpLoad %3 %21
|
||||
%23 = OpAccessChain %16 %9 %17 %17
|
||||
OpStore %23 %22
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,15 @@
|
||||
struct Data {
|
||||
values: array<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
@coherent var<storage, read_write> coherent_buf: Data;
|
||||
@group(0) @binding(1)
|
||||
var<storage, read_write> plain_buf: Data;
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
let _e6 = plain_buf.values[0];
|
||||
coherent_buf.values[0] = _e6;
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
struct Data {
|
||||
values: array<u32>,
|
||||
}
|
||||
|
||||
@group(0) @binding(0)
|
||||
@coherent var<storage, read_write> coherent_buf: Data;
|
||||
@group(0) @binding(1)
|
||||
@volatile var<storage, read_write> volatile_buf: Data;
|
||||
@group(0) @binding(2)
|
||||
@coherent @volatile var<storage, read_write> both_buf: Data;
|
||||
@group(0) @binding(3)
|
||||
var<storage, read_write> plain_buf: Data;
|
||||
|
||||
@compute @workgroup_size(1, 1, 1)
|
||||
fn main() {
|
||||
let _e6 = volatile_buf.values[0];
|
||||
coherent_buf.values[0] = _e6;
|
||||
let _e13 = plain_buf.values[0];
|
||||
both_buf.values[0] = _e13;
|
||||
return;
|
||||
}
|
||||
@@ -546,6 +546,14 @@ pub fn features_to_naga_capabilities(
|
||||
Caps::DRAW_INDEX,
|
||||
features.intersects(wgt::Features::SHADER_DRAW_INDEX),
|
||||
);
|
||||
caps.set(
|
||||
Caps::MEMORY_DECORATION_COHERENT,
|
||||
features.contains(wgt::Features::MEMORY_DECORATION_COHERENT),
|
||||
);
|
||||
caps.set(
|
||||
Caps::MEMORY_DECORATION_VOLATILE,
|
||||
features.contains(wgt::Features::MEMORY_DECORATION_VOLATILE),
|
||||
);
|
||||
|
||||
caps
|
||||
}
|
||||
|
||||
@@ -490,7 +490,8 @@ impl super::Adapter {
|
||||
| wgt::Features::FLOAT32_FILTERABLE
|
||||
| wgt::Features::TEXTURE_ATOMIC
|
||||
| wgt::Features::PASSTHROUGH_SHADERS
|
||||
| wgt::Features::EXTERNAL_TEXTURE;
|
||||
| wgt::Features::EXTERNAL_TEXTURE
|
||||
| wgt::Features::MEMORY_DECORATION_COHERENT;
|
||||
|
||||
//TODO: in order to expose this, we need to run a compute shader
|
||||
// that extract the necessary statistics out of the D3D12 result.
|
||||
|
||||
@@ -664,6 +664,13 @@ impl super::Adapter {
|
||||
features.set(wgt::Features::INDIRECT_FIRST_INSTANCE, supported);
|
||||
}
|
||||
|
||||
// GLSL ES 3.10+ / GLSL 4.30+ natively support coherent/volatile qualifiers
|
||||
// on storage buffers. These were introduced alongside storage buffer support.
|
||||
if supports_storage {
|
||||
features |= wgt::Features::MEMORY_DECORATION_COHERENT
|
||||
| wgt::Features::MEMORY_DECORATION_VOLATILE;
|
||||
}
|
||||
|
||||
let max_texture_size = unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) } as u32;
|
||||
let max_texture_3d_size = unsafe { gl.get_parameter_i32(glow::MAX_3D_TEXTURE_SIZE) } as u32;
|
||||
|
||||
|
||||
@@ -1091,6 +1091,10 @@ impl super::PrivateCapabilities {
|
||||
F::SHADER_FLOAT32_ATOMIC,
|
||||
self.float_atomics && self.msl_version >= MTLLanguageVersion::Version3_0,
|
||||
);
|
||||
features.set(
|
||||
F::MEMORY_DECORATION_COHERENT,
|
||||
self.msl_version >= MTLLanguageVersion::Version3_2,
|
||||
);
|
||||
|
||||
features.set(
|
||||
F::ADDRESS_MODE_CLAMP_TO_BORDER,
|
||||
|
||||
@@ -177,8 +177,9 @@ impl super::Device {
|
||||
MTLLanguageVersion::Version2_4 => (2, 4),
|
||||
MTLLanguageVersion::Version3_0 => (3, 0),
|
||||
MTLLanguageVersion::Version3_1 => (3, 1),
|
||||
// Newer version, fall back to 3.1
|
||||
_ => (3, 1),
|
||||
MTLLanguageVersion::Version3_2 => (3, 2),
|
||||
// Newer version, fall back to 3.2
|
||||
_ => (3, 2),
|
||||
},
|
||||
inline_samplers: Default::default(),
|
||||
spirv_cross_compatibility: false,
|
||||
|
||||
@@ -652,7 +652,9 @@ impl PhysicalDeviceFeatures {
|
||||
| F::PIPELINE_CACHE
|
||||
| F::SHADER_EARLY_DEPTH_TEST
|
||||
| F::TEXTURE_ATOMIC
|
||||
| F::PASSTHROUGH_SHADERS;
|
||||
| F::PASSTHROUGH_SHADERS
|
||||
| F::MEMORY_DECORATION_COHERENT
|
||||
| F::MEMORY_DECORATION_VOLATILE;
|
||||
|
||||
let mut dl_flags = Df::COMPUTE_SHADERS
|
||||
| Df::BASE_VERTEX
|
||||
|
||||
@@ -1319,6 +1319,26 @@ bitflags_array! {
|
||||
///
|
||||
/// This is a native only feature.
|
||||
const ACCELERATION_STRUCTURE_BINDING_ARRAY = 1 << 60;
|
||||
|
||||
/// Enables the `@coherent` memory decoration on storage buffer variables.
|
||||
///
|
||||
/// Backend mapping:
|
||||
/// - Vulkan
|
||||
/// - DX12
|
||||
/// - Metal (3.2+)
|
||||
/// - GLES (ES 3.1+ / GL 4.3+)
|
||||
///
|
||||
/// This is a native only feature.
|
||||
const MEMORY_DECORATION_COHERENT = 1 << 61;
|
||||
|
||||
/// Enables the `@volatile` memory decoration on storage buffer variables.
|
||||
///
|
||||
/// Backend mapping:
|
||||
/// - Vulkan
|
||||
/// - GLES (ES 3.1+ / GL 4.3+)
|
||||
///
|
||||
/// This is a native only feature.
|
||||
const MEMORY_DECORATION_VOLATILE = 1 << 62;
|
||||
}
|
||||
|
||||
/// Features that are not guaranteed to be supported.
|
||||
|
||||
Reference in new issue
Block a user