-
Notifications
You must be signed in to change notification settings - Fork 8
feat(gpu): add --backend flag #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add explicit GPU backend selection to work around wgpu DX12 panic on Windows (issue #24). Users can now specify --backend vulkan/dx12/metal/gl or use --backend auto (default) which tries backends in order: Vulkan → Metal → DX12 → GL. Auto mode prioritizes hardware GPUs over software renderers (llvmpipe, SwiftShader, etc.), falling back to software only when no hardware is available. Co-Authored-By: Aei <aei@oad.earth>
📝 WalkthroughWalkthroughThe changes introduce a new GPU backend abstraction (GpuBackend enum) allowing users to explicitly select which graphics API—Vulkan, DirectX 12, Metal, OpenGL, or Auto with fallback logic—to use when initializing GPU contexts. Adapter discovery now filters and prioritizes by backend, with enhanced error handling and a CLI option for backend selection. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/CLI
participant Main as Main Entry
participant GpuCtx as GpuContext::new()
participant Fallback as new_with_fallback()
participant TryBack as try_backend()
participant wgpu as wgpu Instance
participant Adapt as Adapter Selection
User->>Main: Specify backend (or default Auto)
Main->>GpuCtx: new(device_index, backend)
alt Backend is Auto
GpuCtx->>Fallback: Attempt fallback chain
loop For each backend in order (Vulkan, Metal, Dx12, GL)
Fallback->>TryBack: try_backend(hw_only=true)
TryBack->>wgpu: Create Instance with backend
TryBack->>Adapt: Enumerate & filter adapters by backend
Adapt-->>TryBack: Adapters found or empty
alt Adapters found
TryBack-->>Fallback: Success, return adapter
else No adapters
TryBack-->>Fallback: Continue to next backend
end
end
alt Still no hardware adapters
Fallback->>TryBack: try_backend(hw_only=false)
TryBack->>wgpu: Create Instance with backend
TryBack->>Adapt: Enumerate all adapters (incl. software)
Adapt-->>TryBack: Adapters with software renderers
TryBack-->>Fallback: Return first adapter
end
else Backend is specific (Vulkan/Dx12/Metal/GL)
GpuCtx->>TryBack: try_backend(hw_only=true)
TryBack->>wgpu: Create Instance with specified backend
TryBack->>Adapt: Enumerate & filter by backend
Adapt-->>TryBack: Adapters or error
end
TryBack->>wgpu: Create Device from selected adapter
wgpu-->>TryBack: Device instance
TryBack-->>GpuCtx: GpuContext initialized with backend
GpuCtx-->>Main: Ready for GPU operations
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (6)
🧰 Additional context used🧬 Code graph analysis (5)src/lib.rs (1)
tests/cpu_vs_gpu.rs (1)
tests/puzzle_solve.rs (1)
examples/debug_run.rs (1)
src/gpu_crypto/context.rs (1)
🔇 Additional comments (17)
✏️ Tip: You can disable this entire section by setting Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 6 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Summary
Add explicit GPU backend selection via
--backendCLI flag to work around wgpu DX12 panic on Windows.Closes #24
Changes
GpuBackendenum with variants:Auto,Vulkan,Dx12,Metal,Gl--backendCLI flag (default:auto)GpuContext::new()to accept backend parameterUsage
Testing
cargo build --all-features✓cargo test --all-features✓cargo run -- --helpshows--backendoption ✓Co-Authored-By: Aei aei@oad.earth