@@ -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