Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions apps/desktop/src-tauri/src/gpu_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,32 @@ pub struct SharedGpuContext {
static GPU: OnceCell<Option<SharedGpuContext>> = OnceCell::const_new();

async fn init_gpu_inner() -> Option<SharedGpuContext> {
#[cfg(target_os = "windows")]
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::Backends::DX12 | wgpu::Backends::VULKAN,
..Default::default()
});
#[cfg(not(target_os = "windows"))]
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());

#[cfg(target_os = "windows")]
let instance = {
let dx12_instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::Backends::DX12,
..Default::default()
});
let has_dx12 = dx12_instance
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: logging the DX12 probe error can help distinguish “no adapter” vs driver/init failures (same pattern exists in crates/rendering/src/lib.rs).

Suggested change
let has_dx12 = dx12_instance
let has_dx12 = dx12_instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
force_fallback_adapter: false,
compatible_surface: None,
})
.await
.inspect_err(|e| {
tracing::debug!(error = %e, "DX12 adapter probe failed for shared GPU context");
})
.is_ok();

.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
force_fallback_adapter: false,
compatible_surface: None,
})
.await
.is_ok();
if has_dx12 {
tracing::info!("Using DX12 backend for shared GPU context");
dx12_instance
} else {
tracing::info!("DX12 not available for shared context, falling back to all backends");
wgpu::Instance::new(&wgpu::InstanceDescriptor::default())
}
};
Comment on lines +55 to +76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated DX12 probe logic

This block is identical to the one in crates/rendering/src/lib.rs:985-1006. Both create a DX12-only instance, probe for a DX12 adapter, and fall back to default backends. Consider extracting this into a shared helper (e.g., in the rendering crate or a common utility) to keep the two initialization paths in sync and avoid divergence over time.

Additionally, the probe adapter returned by request_adapter on line 61-68 is immediately discarded (only .is_ok() is checked), and then request_adapter is called again on line 78-85 with the exact same options on the same dx12_instance. You could reuse the probe adapter directly instead of requesting it twice.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src-tauri/src/gpu_context.rs
Line: 55:76

Comment:
**Duplicated DX12 probe logic**

This block is identical to the one in `crates/rendering/src/lib.rs:985-1006`. Both create a DX12-only instance, probe for a DX12 adapter, and fall back to default backends. Consider extracting this into a shared helper (e.g., in the rendering crate or a common utility) to keep the two initialization paths in sync and avoid divergence over time.

Additionally, the probe adapter returned by `request_adapter` on line 61-68 is immediately discarded (only `.is_ok()` is checked), and then `request_adapter` is called again on line 78-85 with the exact same options on the same `dx12_instance`. You could reuse the probe adapter directly instead of requesting it twice.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.


let hardware_adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
Expand Down
46 changes: 9 additions & 37 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,48 +147,20 @@ impl Renderer {
break;
}
}
let nv12_result = frame_renderer
.render_nv12(
current.segment_frames.clone(),
current.uniforms.clone(),
match frame_renderer
.render_immediate(
current.segment_frames,
current.uniforms,
&current.cursor,
&mut layers,
)
.await;

match nv12_result {
Ok(pipeline_frame) => {
if let Some(prev) = pipeline_frame {
(self.frame_cb)(EditorFrameOutput::Nv12(prev));
}
match frame_renderer.flush_pipeline_nv12().await {
Some(Ok(current_frame)) => {
(self.frame_cb)(EditorFrameOutput::Nv12(current_frame));
}
Some(Err(e)) => {
tracing::warn!(error = %e, "Failed to flush NV12 pipeline frame");
}
None => {}
}
.await
{
Ok(frame) => {
(self.frame_cb)(EditorFrameOutput::Rgba(frame));
}
Err(e) => {
tracing::warn!(error = %e, "NV12 render failed, falling back to RGBA");
match frame_renderer
.render_immediate(
current.segment_frames,
current.uniforms,
&current.cursor,
&mut layers,
)
.await
{
Ok(frame) => {
(self.frame_cb)(EditorFrameOutput::Rgba(frame));
}
Err(e) => {
tracing::error!(error = %e, "Failed to render frame in editor");
}
}
tracing::error!(error = %e, "Failed to render frame in editor");
}
}

Expand Down
28 changes: 23 additions & 5 deletions crates/rendering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,32 @@ impl RenderVideoConstants {
.map(|c| XY::new(c.width, c.height)),
};

#[cfg(target_os = "windows")]
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::Backends::DX12 | wgpu::Backends::VULKAN,
..Default::default()
});
#[cfg(not(target_os = "windows"))]
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());

#[cfg(target_os = "windows")]
let instance = {
let dx12_instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends: wgpu::Backends::DX12,
..Default::default()
});
let has_dx12 = dx12_instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
force_fallback_adapter: false,
compatible_surface: None,
})
.await
.is_ok();
if has_dx12 {
tracing::info!("Using DX12 backend for optimal D3D11 interop");
dx12_instance
} else {
tracing::info!("DX12 not available, falling back to all backends");
wgpu::Instance::new(&wgpu::InstanceDescriptor::default())
}
};

let hardware_adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
Expand Down
Loading