Skip to content

Commit

Permalink
expose VULKAN_EXTERNAL_MEMORY_WIN32 feature (#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaopengli89 authored Jan 3, 2025
1 parent 03ff99e commit 15a77b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
8 changes: 5 additions & 3 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,11 @@ impl PhysicalDeviceFeatures {
caps.supports_extension(google::display_timing::NAME),
);

features.set(
F::VULKAN_EXTERNAL_MEMORY_WIN32,
caps.supports_extension(khr::external_memory_win32::NAME),
);

(features, dl_flags)
}

Expand Down Expand Up @@ -1554,9 +1559,6 @@ impl super::Instance {
.is_some_and(|ext| ext.shader_zero_initialize_workgroup_memory == vk::TRUE),
image_format_list: phd_capabilities.device_api_version >= vk::API_VERSION_1_2
|| phd_capabilities.supports_extension(khr::image_format_list::NAME),
#[cfg(windows)]
external_memory_win32: phd_capabilities
.supports_extension(khr::external_memory_win32::NAME),
};
let capabilities = crate::Capabilities {
limits: phd_capabilities.to_wgpu_limits(),
Expand Down
10 changes: 7 additions & 3 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl super::Device {

/// # Safety
///
/// - Vulkan 1.1+ (or VK_KHR_external_memory)
/// - Vulkan (with VK_KHR_external_memory_win32)
/// - The `d3d11_shared_handle` must be valid and respecting `desc`
/// - `VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT` flag is used because we need to hold a reference to the handle
#[cfg(windows)]
Expand All @@ -795,8 +795,12 @@ impl super::Device {
d3d11_shared_handle: windows::Win32::Foundation::HANDLE,
desc: &crate::TextureDescriptor,
) -> Result<super::Texture, crate::DeviceError> {
if !self.shared.private_caps.external_memory_win32 {
log::error!("VK_KHR_external_memory extension is required");
if !self
.shared
.features
.contains(wgt::Features::VULKAN_EXTERNAL_MEMORY_WIN32)
{
log::error!("Vulkan driver does not support VK_KHR_external_memory_win32");
return Err(crate::DeviceError::ResourceCreationFailed);
}

Expand Down
2 changes: 0 additions & 2 deletions wgpu-hal/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ struct PrivateCapabilities {
robust_image_access2: bool,
zero_initialize_workgroup_memory: bool,
image_format_list: bool,
#[cfg(windows)]
external_memory_win32: bool,
}

bitflags::bitflags!(
Expand Down
10 changes: 10 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,16 @@ bitflags::bitflags! {
/// [VK_GOOGLE_display_timing]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_GOOGLE_display_timing.html
/// [`Surface::as_hal()`]: https://docs.rs/wgpu/latest/wgpu/struct.Surface.html#method.as_hal
const VULKAN_GOOGLE_DISPLAY_TIMING = 1 << 62;

/// Allows using the [VK_KHR_external_memory_win32] Vulkan extension.
///
/// Supported platforms:
/// - Vulkan (with [VK_KHR_external_memory_win32])
///
/// This is a native only feature.
///
/// [VK_KHR_external_memory_win32]: https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_external_memory_win32.html
const VULKAN_EXTERNAL_MEMORY_WIN32 = 1 << 63;
}
}

Expand Down

0 comments on commit 15a77b5

Please sign in to comment.