editor: run on a shared VAAPI-capable wgpu device (Stage 3a)
Foundation for hardware video decode in BOTH preview and export: wgpu textures can't cross devices, and a hardware-decoded frame is a DMA-BUF-imported texture that needs the import extensions (only addable via wgpu-hal device_from_raw). So eframe + the compositor + decode + encode must share ONE custom device. - vk_device::create_windowed(): the existing import-capable DrmDevice plus VK_KHR_swapchain (the WSI surface instance extensions are already enabled by Instance::init), for use as the editor's main device. - main.rs: on Linux, build the shared device and inject it into eframe via WgpuSetup::Existing (the egui fork supports it); fall back to wgpu's normal device + software decode on any failure, on other platforms, or via LB_NO_SHARED_DEVICE. The DrmDevice's wgpu handles are cloned into eframe (Arc-backed), so the VkDevice persists with them. Runtime-verified: the editor launches and renders identically (canvas/vello, video, panels) on the shared device, and the env-var fallback works.
This commit is contained in:
@@ -22,12 +22,20 @@ pub struct DrmDevice {
|
||||
pub raw_instance: ash::Instance,
|
||||
}
|
||||
|
||||
/// Create the device, or `Err` if Vulkan/the extension isn't available (caller falls back).
|
||||
/// Create a headless DMA-BUF-import device (encoder/decoder), or `Err` if Vulkan/the extension
|
||||
/// isn't available (caller falls back).
|
||||
pub fn create() -> Result<DrmDevice, String> {
|
||||
unsafe { create_inner() }
|
||||
unsafe { create_inner(false) }
|
||||
}
|
||||
|
||||
unsafe fn create_inner() -> Result<DrmDevice, String> {
|
||||
/// Like [`create`] but also enables `VK_KHR_swapchain` so the device can present to a window —
|
||||
/// for use as the editor's **shared** wgpu device (eframe + compositor + decode + encode all on
|
||||
/// one device, so hardware-decoded DMA-BUF textures are usable by the preview compositor).
|
||||
pub fn create_windowed() -> Result<DrmDevice, String> {
|
||||
unsafe { create_inner(true) }
|
||||
}
|
||||
|
||||
unsafe fn create_inner(windowed: bool) -> Result<DrmDevice, String> {
|
||||
use wgpu_hal::vulkan::Api as Vk;
|
||||
// Bring the HAL Instance trait into scope for `init` / `enumerate_adapters`.
|
||||
use wgpu_hal::Instance as _;
|
||||
@@ -72,14 +80,19 @@ unsafe fn create_inner() -> Result<DrmDevice, String> {
|
||||
exposed.adapter.required_device_extensions(exposed.features);
|
||||
// Only the genuine extensions; external_memory / bind_memory2 / ycbcr / format_list
|
||||
// are core in Vulkan 1.1+ (this device is 1.3) so they need no enabling.
|
||||
let extra: &[&'static CStr] = &[
|
||||
let mut extra: Vec<&'static CStr> = vec![
|
||||
ash::ext::image_drm_format_modifier::NAME,
|
||||
ash::khr::external_memory_fd::NAME,
|
||||
ash::ext::external_memory_dma_buf::NAME,
|
||||
ash::ext::queue_family_foreign::NAME,
|
||||
];
|
||||
// Presentation (windowed shared device only): the WSI surface instance extensions are already
|
||||
// enabled by `Instance::init`; the device needs the swapchain extension to present.
|
||||
if windowed {
|
||||
extra.push(ash::khr::swapchain::NAME);
|
||||
}
|
||||
for e in extra {
|
||||
if !ext_names.contains(e) {
|
||||
if !ext_names.contains(&e) {
|
||||
ext_names.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user