Skip to content

Commit

Permalink
Require only DXGI 1.2 when not debugging D3D
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed May 18, 2024
1 parent 818ff73 commit b5a39be
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/renderer/d3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use windows::Win32::Graphics::Direct3D12::{
D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_QUEUE_DESC, D3D12_COMMAND_QUEUE_FLAG_NONE,
D3D12_FENCE_FLAG_NONE, D3D12_RESOURCE_STATE_PRESENT,
};
#[cfg(feature = "d3d_debug")]
use windows::Win32::Graphics::Direct3D12::{D3D12GetDebugInterface, ID3D12Debug};
use windows::Win32::Graphics::DirectComposition::{
DCompositionCreateDevice2, IDCompositionDevice, IDCompositionTarget, IDCompositionVisual,
};
Expand All @@ -25,10 +23,15 @@ use windows::Win32::Graphics::Dxgi::Common::{
DXGI_SAMPLE_DESC,
};
use windows::Win32::Graphics::Dxgi::{
CreateDXGIFactory2, IDXGIAdapter1, IDXGIFactory4, IDXGISwapChain1, IDXGISwapChain3,
DXGI_ADAPTER_FLAG, DXGI_ADAPTER_FLAG_SOFTWARE, DXGI_CREATE_FACTORY_DEBUG, DXGI_SCALING_STRETCH,
DXGI_SWAP_CHAIN_DESC1, DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT,
DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL, DXGI_USAGE_RENDER_TARGET_OUTPUT,
CreateDXGIFactory1, IDXGIAdapter1, IDXGIFactory2, IDXGISwapChain1, IDXGISwapChain3,
DXGI_ADAPTER_FLAG, DXGI_ADAPTER_FLAG_SOFTWARE, DXGI_SCALING_STRETCH, DXGI_SWAP_CHAIN_DESC1,
DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT, DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
DXGI_USAGE_RENDER_TARGET_OUTPUT,
};
#[cfg(feature = "d3d_debug")]
use windows::Win32::Graphics::{
Direct3D12::{D3D12GetDebugInterface, ID3D12Debug},
Dxgi::{CreateDXGIFactory2, DXGI_CREATE_FACTORY_DEBUG},
};
use windows::Win32::System::Threading::{CreateEventW, WaitForSingleObjectEx, INFINITE};
use winit::{
Expand All @@ -42,7 +45,7 @@ use super::{vsync::VSyncWinSwapChain, RendererSettings, SkiaRenderer, VSync};
use crate::profiling::{d3d::create_d3d_gpu_context, GpuCtx};
use crate::{profiling::tracy_gpu_zone, settings::SETTINGS, window::UserEvent};

fn get_hardware_adapter(factory: &IDXGIFactory4) -> Result<IDXGIAdapter1> {
fn get_hardware_adapter(factory: &IDXGIFactory2) -> Result<IDXGIAdapter1> {
for i in 0.. {
let adapter = unsafe { factory.EnumAdapters1(i)? };
let mut desc = Default::default();
Expand Down Expand Up @@ -98,20 +101,22 @@ pub struct D3DSkiaRenderer {
impl D3DSkiaRenderer {
pub fn new(window: Window) -> Self {
#[cfg(feature = "d3d_debug")]
unsafe {
let dxgi_factory: IDXGIFactory2 = unsafe {
let mut debug_controller: Option<ID3D12Debug> = None;
D3D12GetDebugInterface(&mut debug_controller)
.expect("Failed to create Direct3D debug controller");

debug_controller
.expect("Failed to enable debug layer")
.EnableDebugLayer();
}

let dxgi_factory: IDXGIFactory4 = unsafe {
CreateDXGIFactory2(DXGI_CREATE_FACTORY_DEBUG).expect("Failed to create DXGI factory")
};

#[cfg(not(feature = "d3d_debug"))]
let dxgi_factory: IDXGIFactory2 =
unsafe { CreateDXGIFactory1().expect("Failed to create DXGI factory") };

let adapter = get_hardware_adapter(&dxgi_factory)
.expect("Failed to find any suitable Direct3D 12 adapters");

Expand Down

0 comments on commit b5a39be

Please sign in to comment.