Skip to content

Commit e81a7ae

Browse files
committed
external_memory_win32 apability
1 parent 8e9f658 commit e81a7ae

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ impl PhysicalDeviceProperties {
903903
if requested_features.contains(wgt::Features::TEXTURE_FORMAT_NV12) {
904904
extensions.push(khr::sampler_ycbcr_conversion::NAME);
905905
}
906+
907+
// Optional `VK_KHR_external_memory_win32`
908+
if self.supports_extension(khr::external_memory_win32::NAME) {
909+
extensions.push(khr::external_memory_win32::NAME);
910+
}
906911
}
907912

908913
if self.device_api_version < vk::API_VERSION_1_2 {
@@ -1539,6 +1544,8 @@ impl super::Instance {
15391544
}),
15401545
image_format_list: phd_capabilities.device_api_version >= vk::API_VERSION_1_2
15411546
|| phd_capabilities.supports_extension(khr::image_format_list::NAME),
1547+
external_memory_win32: phd_capabilities.device_api_version >= vk::API_VERSION_1_1
1548+
|| phd_capabilities.supports_extension(khr::external_memory_win32::NAME),
15421549
};
15431550
let capabilities = crate::Capabilities {
15441551
limits: phd_capabilities.to_wgpu_limits(),

wgpu-hal/src/vulkan/device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,19 @@ impl super::Device {
800800
}
801801

802802
/// # Safety
803-
/// The `d3d11_shared_handle` must be valid and respecting `desc`.
803+
///
804+
/// - Vulkan 1.1+ (or VK_KHR_external_memory)
805+
/// - The `d3d11_shared_handle` must be valid and respecting `desc`
804806
#[cfg(windows)]
805807
pub unsafe fn texture_from_d3d11_shared_handle(
806808
&self,
807809
d3d11_shared_handle: *mut std::ffi::c_void,
808810
desc: &crate::TextureDescriptor,
809811
) -> Result<super::Texture, crate::DeviceError> {
812+
if !self.shared.private_caps.external_memory_win32 {
813+
return Err(crate::DeviceError::ResourceCreationFailed);
814+
}
815+
810816
let mut external_memory_image_info = vk::ExternalMemoryImageCreateInfo::default()
811817
.handle_types(vk::ExternalMemoryHandleTypeFlags::D3D11_TEXTURE_KMT);
812818

wgpu-hal/src/vulkan/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ struct PrivateCapabilities {
526526
robust_image_access2: bool,
527527
zero_initialize_workgroup_memory: bool,
528528
image_format_list: bool,
529+
external_memory_win32: bool,
529530
}
530531

531532
bitflags::bitflags!(

0 commit comments

Comments
 (0)