From 56535d7d90b09fdb20a25f80813a8fd3e08fa069 Mon Sep 17 00:00:00 2001 From: Francis De Brabandere Date: Mon, 29 Jun 2026 04:26:49 +0200 Subject: [PATCH] fix(vulkan): enable vulkanMemoryModelDeviceScope with the memory model (#9741) --- CHANGELOG.md | 1 + wgpu-hal/src/vulkan/adapter.rs | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0046bd00c..7dc999352 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -280,6 +280,7 @@ By @stuartparmenter in [#9658](https://github.com/gfx-rs/wgpu/pull/9658). - Fixed vkAcquireNextImage fence being awaited on non-Windows platforms causing frametime spikes on nvidia drivers. By @cohaereo in [#9486](https://github.com/gfx-rs/wgpu/pull/9486). - Fixed alignment and `MatrixStride` for mat2x2 in SPIR-V uniform blocks. By @39ali [#9369](https://github.com/gfx-rs/wgpu/pull/9369). - Fixed loading of `libvulkan.so` on OpenHarmony (`target_env = "ohos"`). By @jschwe in [#9649](https://github.com/gfx-rs/wgpu/pull/9649). +- Fixed `VUID-RuntimeSpirv-vulkanMemoryModel-06265` validation errors by enabling `vulkanMemoryModelDeviceScope` whenever the Vulkan memory model is enabled, since the SPIR-V backend emits storage atomics with `Device` scope. By @francisdb in [#9741](https://github.com/gfx-rs/wgpu/pull/9741). #### DX12 diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index b4d80d0c8..208a71ca0 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -628,7 +628,13 @@ impl PhysicalDeviceFeatures { requested_features.contains(wgt::Features::EXPERIMENTAL_COOPERATIVE_MATRIX); Some( vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR::default() - .vulkan_memory_model(needed), + .vulkan_memory_model(needed) + // The SPIR-V backend emits storage atomics with `Device` + // memory scope, so whenever the Vulkan memory model is + // enabled we must also enable device scope, otherwise the + // validation layers report + // `VUID-RuntimeSpirv-vulkanMemoryModel-06265`. + .vulkan_memory_model_device_scope(needed), ) } else { None @@ -1079,10 +1085,17 @@ impl PhysicalDeviceFeatures { .map(|p| p.multisample_array_image == vk::TRUE) .unwrap_or(true), ); - // Enable cooperative matrix if any configuration is supported + // Enable cooperative matrix if any configuration is supported. The SPIR-V + // we emit for it uses `Device`-scope atomics under the Vulkan memory model, + // so the device must also support `vulkanMemoryModelDeviceScope`, otherwise + // those shaders trip `VUID-RuntimeSpirv-vulkanMemoryModel-06265`. features.set( F::EXPERIMENTAL_COOPERATIVE_MATRIX, - !caps.cooperative_matrix_properties.is_empty(), + !caps.cooperative_matrix_properties.is_empty() + && self.vulkan_memory_model.is_some_and(|m| { + m.vulkan_memory_model == vk::TRUE + && m.vulkan_memory_model_device_scope == vk::TRUE + }), ); features.set( @@ -2174,6 +2187,15 @@ impl super::InstanceShared { features2 = features2.push_next(next); } + if capabilities.device_api_version >= vk::API_VERSION_1_2 + || capabilities.supports_extension(khr::vulkan_memory_model::NAME) + { + let next = features + .vulkan_memory_model + .insert(vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR::default()); + features2 = features2.push_next(next); + } + if capabilities.device_api_version >= vk::API_VERSION_1_1 { let next = features .shader_draw_parameters