Skip to content

Commit d04b289

Browse files
lmurrayslouken
authored andcommitted
GPU: Make D3D12 debug layers optional
1 parent 695cad4 commit d04b289

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

src/gpu/d3d12/SDL_gpu_d3d12.c

+32-21
Original file line numberDiff line numberDiff line change
@@ -8328,38 +8328,38 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this)
83288328
}
83298329

83308330
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) && defined(HAVE_IDXGIINFOQUEUE)
8331-
static void D3D12_INTERNAL_TryInitializeDXGIDebug(D3D12Renderer *renderer)
8331+
static bool D3D12_INTERNAL_TryInitializeDXGIDebug(D3D12Renderer *renderer)
83328332
{
83338333
PFN_DXGI_GET_DEBUG_INTERFACE DXGIGetDebugInterfaceFunc;
83348334
HRESULT res;
83358335

83368336
renderer->dxgidebug_dll = SDL_LoadObject(DXGIDEBUG_DLL);
83378337
if (renderer->dxgidebug_dll == NULL) {
8338-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not find " DXGIDEBUG_DLL);
8339-
return;
8338+
return false;
83408339
}
83418340

83428341
DXGIGetDebugInterfaceFunc = (PFN_DXGI_GET_DEBUG_INTERFACE)SDL_LoadFunction(
83438342
renderer->dxgidebug_dll,
83448343
DXGI_GET_DEBUG_INTERFACE_FUNC);
83458344
if (DXGIGetDebugInterfaceFunc == NULL) {
8346-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not load function: " DXGI_GET_DEBUG_INTERFACE_FUNC);
8347-
return;
8345+
return false;
83488346
}
83498347

83508348
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIDebug, (void **)&renderer->dxgiDebug);
83518349
if (FAILED(res)) {
8352-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get IDXGIDebug interface");
8350+
return false;
83538351
}
83548352

83558353
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIInfoQueue, (void **)&renderer->dxgiInfoQueue);
83568354
if (FAILED(res)) {
8357-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get IDXGIInfoQueue interface");
8355+
return false;
83588356
}
8357+
8358+
return true;
83598359
}
83608360
#endif
83618361

8362-
static void D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
8362+
static bool D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
83638363
{
83648364
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterfaceFunc;
83658365
HRESULT res;
@@ -8368,21 +8368,20 @@ static void D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
83688368
renderer->d3d12_dll,
83698369
D3D12_GET_DEBUG_INTERFACE_FUNC);
83708370
if (D3D12GetDebugInterfaceFunc == NULL) {
8371-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not load function: " D3D12_GET_DEBUG_INTERFACE_FUNC);
8372-
return;
8371+
return false;
83738372
}
83748373

83758374
res = D3D12GetDebugInterfaceFunc(D3D_GUID(D3D_IID_ID3D12Debug), (void **)&renderer->d3d12Debug);
83768375
if (FAILED(res)) {
8377-
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get ID3D12Debug interface");
8378-
return;
8376+
return false;
83798377
}
83808378

83818379
ID3D12Debug_EnableDebugLayer(renderer->d3d12Debug);
8380+
return true;
83828381
}
83838382

83848383
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
8385-
static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *renderer)
8384+
static void D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *renderer)
83868385
{
83878386
ID3D12InfoQueue *infoQueue = NULL;
83888387
D3D12_MESSAGE_SEVERITY severities[] = { D3D12_MESSAGE_SEVERITY_INFO };
@@ -8394,7 +8393,7 @@ static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *rende
83948393
D3D_GUID(D3D_IID_ID3D12InfoQueue),
83958394
(void **)&infoQueue);
83968395
if (FAILED(res)) {
8397-
CHECK_D3D12_ERROR_AND_RETURN("Failed to convert ID3D12Device to ID3D12InfoQueue", false);
8396+
return;
83988397
}
83998398

84008399
SDL_zero(filter);
@@ -8410,8 +8409,6 @@ static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *rende
84108409
true);
84118410

84128411
ID3D12InfoQueue_Release(infoQueue);
8413-
8414-
return true;
84158412
}
84168413

84178414
static void WINAPI D3D12_INTERNAL_OnD3D12DebugInfoMsg(
@@ -8565,9 +8562,12 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
85658562

85668563
#ifdef HAVE_IDXGIINFOQUEUE
85678564
// Initialize the DXGI debug layer, if applicable
8565+
bool hasDxgiDebug = false;
85688566
if (debugMode) {
8569-
D3D12_INTERNAL_TryInitializeDXGIDebug(renderer);
8567+
hasDxgiDebug = D3D12_INTERNAL_TryInitializeDXGIDebug(renderer);
85708568
}
8569+
#else
8570+
bool hasDxgiDebug = true;
85718571
#endif
85728572

85738573
// Load the CreateDXGIFactory1 function
@@ -8724,7 +8724,20 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
87248724

87258725
// Initialize the D3D12 debug layer, if applicable
87268726
if (debugMode) {
8727-
D3D12_INTERNAL_TryInitializeD3D12Debug(renderer);
8727+
bool hasD3d12Debug = D3D12_INTERNAL_TryInitializeD3D12Debug(renderer);
8728+
if (hasDxgiDebug && hasD3d12Debug) {
8729+
SDL_LogInfo(
8730+
SDL_LOG_CATEGORY_GPU,
8731+
"Validation layers enabled, expect debug level performance!");
8732+
} else if (hasDxgiDebug || hasD3d12Debug) {
8733+
SDL_LogWarn(
8734+
SDL_LOG_CATEGORY_GPU,
8735+
"Validation layers partially enabled, some warnings may not be available");
8736+
} else {
8737+
SDL_LogWarn(
8738+
SDL_LOG_CATEGORY_GPU,
8739+
"Validation layers not found, continuing without validation");
8740+
}
87288741
}
87298742

87308743
// Create the D3D12Device
@@ -8771,9 +8784,7 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
87718784

87728785
// Initialize the D3D12 debug info queue, if applicable
87738786
if (debugMode) {
8774-
if (!D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(renderer)) {
8775-
return NULL;
8776-
}
8787+
D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(renderer);
87778788
D3D12_INTERNAL_TryInitializeD3D12DebugInfoLogger(renderer);
87788789
}
87798790
#endif

0 commit comments

Comments
 (0)