Skip to content

Commit bdb3fee

Browse files
kvarkclaude
andcommitted
Store the decided memory model as an enum
Replaces the confusable pair of booleans (use_vulkan_memory_model / vulkan_memory_model) on the writer: the option keeps its name, and the per-module decision is now `memory_model: spirv::MemoryModel`, which the module header emits directly. No output changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WRD8L4KyVGxJfKTqkX3gmh
1 parent d5c588a commit bdb3fee

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

naga/src/back/spv/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,12 @@ pub struct Writer {
10131013
emit_int_div_checks: bool,
10141014
/// See [`Options::use_vulkan_memory_model`].
10151015
use_vulkan_memory_model: bool,
1016-
/// Whether the module being written declares the Vulkan memory model:
1017-
/// either requested through the options, or required by a capability the
1018-
/// module uses. Decided up front in [`Writer::write`] so that memory
1019-
/// operands can be emitted consistently throughout the module.
1020-
vulkan_memory_model: bool,
1016+
/// The memory model the module being written declares: Vulkan when
1017+
/// requested through the options or required by a capability the module
1018+
/// uses, GLSL450 otherwise. Decided up front in [`Writer::write`] so
1019+
/// that memory operands can be emitted consistently throughout the
1020+
/// module.
1021+
memory_model: spirv::MemoryModel,
10211022
/// Globals written (including atomically) by the entry points being
10221023
/// written. Only populated under the Vulkan memory model, where accesses
10231024
/// to globals outside this set stay private

naga/src/back/spv/writer.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ impl Writer {
9898
use_storage_input_output_16: options.use_storage_input_output_16,
9999
emit_int_div_checks: options.emit_int_div_checks,
100100
use_vulkan_memory_model: options.use_vulkan_memory_model,
101-
vulkan_memory_model: options.use_vulkan_memory_model,
101+
// Re-decided per module in `write`.
102+
memory_model: spirv::MemoryModel::GLSL450,
102103
written_globals: crate::FastHashSet::default(),
103104
void_type,
104105
tuple_of_u32s_ty_id: None,
@@ -189,8 +190,8 @@ impl Writer {
189190
use_vulkan_memory_model: self.use_vulkan_memory_model,
190191

191192
// Initialized afresh:
192-
// Re-decided per module in `write`; option-requested value until then.
193-
vulkan_memory_model: self.use_vulkan_memory_model,
193+
// Re-decided per module in `write`.
194+
memory_model: spirv::MemoryModel::GLSL450,
194195
written_globals: take(&mut self.written_globals),
195196
id_gen,
196197
void_type,
@@ -2815,7 +2816,7 @@ impl Writer {
28152816
spirv::MemorySemantics::IMAGE_MEMORY,
28162817
flags.contains(crate::Barrier::TEXTURE),
28172818
);
2818-
if self.vulkan_memory_model {
2819+
if self.memory_model == spirv::MemoryModel::Vulkan {
28192820
// Under the Vulkan memory model, availability and visibility are
28202821
// explicit: without these bits the barrier orders accesses but
28212822
// does not propagate them between invocations.
@@ -2875,7 +2876,7 @@ impl Writer {
28752876
decorations: crate::MemoryDecorations,
28762877
is_load: bool,
28772878
) -> Option<super::MemoryOperands> {
2878-
if !self.vulkan_memory_model {
2879+
if self.memory_model != spirv::MemoryModel::Vulkan {
28792880
return None;
28802881
}
28812882
match space {
@@ -2910,7 +2911,7 @@ impl Writer {
29102911
decorations: crate::MemoryDecorations,
29112912
) -> (spirv::MemorySemantics, spirv::Scope) {
29122913
let (mut semantics, mut scope) = space.to_spirv_semantics_and_scope();
2913-
if self.vulkan_memory_model {
2914+
if self.memory_model == spirv::MemoryModel::Vulkan {
29142915
// Device scope requires the `vulkanMemoryModelDeviceScope`
29152916
// feature; QueueFamily is the model's equivalent scope.
29162917
if scope == spirv::Scope::Device {
@@ -3502,7 +3503,7 @@ impl Writer {
35023503
// decorations are forbidden; their effects are expressed through
35033504
// memory operands on each access instead
35043505
// (see `access_memory_operands`).
3505-
if !self.vulkan_memory_model {
3506+
if self.memory_model != spirv::MemoryModel::Vulkan {
35063507
if global_variable
35073508
.memory_decorations
35083509
.contains(crate::MemoryDecorations::COHERENT)
@@ -3941,14 +3942,7 @@ impl Writer {
39413942
}
39423943

39433944
let addressing_model = spirv::AddressingModel::Logical;
3944-
let memory_model = if self
3945-
.capabilities_used
3946-
.contains(&spirv::Capability::VulkanMemoryModel)
3947-
{
3948-
spirv::MemoryModel::Vulkan
3949-
} else {
3950-
spirv::MemoryModel::GLSL450
3951-
};
3945+
let memory_model = self.memory_model;
39523946
//self.check(addressing_model.required_capabilities())?;
39533947
//self.check(memory_model.required_capabilities())?;
39543948

@@ -3986,15 +3980,18 @@ impl Writer {
39863980
// accesses depend on it, and those are written before the module
39873981
// header is assembled. Cooperative matrices require the Vulkan
39883982
// memory model regardless of what the options request.
3989-
self.vulkan_memory_model = self.use_vulkan_memory_model
3983+
let requires_vulkan_model = self.use_vulkan_memory_model
39903984
|| ir_module
39913985
.types
39923986
.iter()
39933987
.any(|(_, ty)| matches!(ty.inner, crate::TypeInner::CooperativeMatrix { .. }));
3994-
if self.vulkan_memory_model {
3988+
self.memory_model = if requires_vulkan_model {
39953989
self.require_any("memory model", &[spirv::Capability::VulkanMemoryModel])?;
39963990
self.use_extension("SPV_KHR_vulkan_memory_model");
3997-
}
3991+
spirv::MemoryModel::Vulkan
3992+
} else {
3993+
spirv::MemoryModel::GLSL450
3994+
};
39983995

39993996
// Try to find the entry point and corresponding index
40003997
let ep_index = match pipeline_options {
@@ -4009,7 +4006,7 @@ impl Writer {
40094006
None => None,
40104007
};
40114008

4012-
if self.vulkan_memory_model {
4009+
if self.memory_model == spirv::MemoryModel::Vulkan {
40134010
// Collect the globals any written entry point writes. The union
40144011
// over entry points keeps functions shared between them sound.
40154012
self.written_globals.clear();

0 commit comments

Comments
 (0)