Skip to content

Commit 9ed7737

Browse files
authored
Add coherent and volatile memory decorations for storage buffers. (gfx-rs#9168)
1 parent a97a49d commit 9ed7737

65 files changed

Lines changed: 658 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
154154
- Initial wgsl-in ray tracing pipelines. By @Vecvec in [#8570](https://github.com/gfx-rs/wgpu/pull/8570).
155155
- wgsl-out ray tracing pipelines. By @Vecvec in [#8970](https://github.com/gfx-rs/wgpu/pull/8970).
156156
- 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.
157+
- 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).
157158

158159
#### GLES
159160

naga/src/back/glsl/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,4 +642,6 @@ pub fn supported_capabilities() -> valid::Capabilities {
642642
| Caps::SHADER_FLOAT16_IN_FLOAT32
643643
| Caps::SHADER_BARYCENTRICS
644644
| Caps::DRAW_INDEX
645+
| Caps::MEMORY_DECORATION_COHERENT
646+
| Caps::MEMORY_DECORATION_VOLATILE
645647
}

naga/src/back/glsl/writer.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,18 @@ impl<'a, W: Write> Writer<'a, W> {
699699

700700
if let crate::AddressSpace::Storage { access } = global.space {
701701
self.write_storage_access(access)?;
702+
if global
703+
.memory_decorations
704+
.contains(crate::MemoryDecorations::COHERENT)
705+
{
706+
write!(self.out, "coherent ")?;
707+
}
708+
if global
709+
.memory_decorations
710+
.contains(crate::MemoryDecorations::VOLATILE)
711+
{
712+
write!(self.out, "volatile ")?;
713+
}
702714
}
703715

704716
if let Some(storage_qualifier) = glsl_storage_qualifier(global.space) {

naga/src/back/hlsl/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,10 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
800800
// No BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
801801
| Caps::STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING
802802
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
803-
// No COOPERATIVE_MATRIX
804-
// No PER_VERTEX
805-
// No RAY_TRACING_PIPELINE
806-
// No DRAW_INDEX
803+
// No COOPERATIVE_MATRIX
804+
// No PER_VERTEX
805+
// No RAY_TRACING_PIPELINE
806+
// No DRAW_INDEX
807+
// No MEMORY_DECORATION_VOLATILE
808+
| Caps::MEMORY_DECORATION_COHERENT
807809
}

naga/src/back/hlsl/writer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
990990
"b"
991991
}
992992
crate::AddressSpace::Storage { access } => {
993+
if global
994+
.memory_decorations
995+
.contains(crate::MemoryDecorations::COHERENT)
996+
{
997+
write!(self.out, "globallycoherent ")?;
998+
}
993999
let (prefix, register) = if access.contains(crate::StorageAccess::STORE) {
9941000
("RW", "u")
9951001
} else {

naga/src/back/msl/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,11 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
871871
| Caps::STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING
872872
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
873873
| Caps::COOPERATIVE_MATRIX
874-
// No PER_VERTEX
875-
// No RAY_TRACING_PIPELINE
876-
// No DRAW_INDEX
874+
// No PER_VERTEX
875+
// No RAY_TRACING_PIPELINE
876+
// No DRAW_INDEX
877+
// No MEMORY_DECORATION_VOLATILE
878+
| Caps::MEMORY_DECORATION_COHERENT
877879
}
878880

879881
#[test]

naga/src/back/msl/writer.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,23 +428,32 @@ impl TypedGlobalVariable<'_> {
428428
first_time: false,
429429
};
430430

431-
let (space, access, reference) = match var.space.to_msl_name() {
431+
let (coherent, space, access, reference) = match var.space.to_msl_name() {
432432
Some(space) if self.reference => {
433+
let coherent = if var
434+
.memory_decorations
435+
.contains(crate::MemoryDecorations::COHERENT)
436+
{
437+
"coherent "
438+
} else {
439+
""
440+
};
433441
let access = if var.space.needs_access_qualifier()
434442
&& !self.usage.intersects(valid::GlobalUse::WRITE)
435443
{
436444
"const"
437445
} else {
438446
""
439447
};
440-
(space, access, "&")
448+
(coherent, space, access, "&")
441449
}
442-
_ => ("", "", ""),
450+
_ => ("", "", "", ""),
443451
};
444452

445453
Ok(write!(
446454
out,
447-
"{}{}{}{}{}{} {}",
455+
"{}{}{}{}{}{}{} {}",
456+
coherent,
448457
space,
449458
if space.is_empty() { "" } else { " " },
450459
ty_name,

naga/src/back/spv/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,4 +1191,6 @@ pub fn supported_capabilities() -> crate::valid::Capabilities {
11911191
| Caps::PER_VERTEX
11921192
// No RAY_TRACING_PIPELINE
11931193
| Caps::DRAW_INDEX
1194+
| Caps::MEMORY_DECORATION_COHERENT
1195+
| Caps::MEMORY_DECORATION_VOLATILE
11941196
}

naga/src/back/spv/writer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,19 @@ impl Writer {
32883288

32893289
//self.check(class.required_capabilities())?;
32903290

3291+
if global_variable
3292+
.memory_decorations
3293+
.contains(crate::MemoryDecorations::COHERENT)
3294+
{
3295+
self.decorate(id, Decoration::Coherent, &[]);
3296+
}
3297+
if global_variable
3298+
.memory_decorations
3299+
.contains(crate::MemoryDecorations::VOLATILE)
3300+
{
3301+
self.decorate(id, Decoration::Volatile, &[]);
3302+
}
3303+
32913304
if self.flags.contains(WriterFlags::DEBUG) {
32923305
if let Some(ref name) = global_variable.name {
32933306
self.debugs.push(Instruction::name(id, name));

naga/src/back/wgsl/writer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,19 @@ impl<W: Write> Writer<W> {
19741974
writeln!(self.out)?;
19751975
}
19761976

1977+
if global
1978+
.memory_decorations
1979+
.contains(crate::MemoryDecorations::COHERENT)
1980+
{
1981+
write!(self.out, "@coherent ")?;
1982+
}
1983+
if global
1984+
.memory_decorations
1985+
.contains(crate::MemoryDecorations::VOLATILE)
1986+
{
1987+
write!(self.out, "@volatile ")?;
1988+
}
1989+
19771990
// First write global name and address space if supported
19781991
write!(self.out, "var")?;
19791992
let (address, maybe_access) = address_space_str(global.space);

0 commit comments

Comments
 (0)