mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-01 07:28:30 +00:00
GPU: Make D3D12 debug layers optional
This commit is contained in:

committed by
Sam Lantinga

parent
695cad459b
commit
d04b28926c
@@ -8328,38 +8328,38 @@ static bool D3D12_PrepareDriver(SDL_VideoDevice *_this)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) && defined(HAVE_IDXGIINFOQUEUE)
|
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) && defined(HAVE_IDXGIINFOQUEUE)
|
||||||
static void D3D12_INTERNAL_TryInitializeDXGIDebug(D3D12Renderer *renderer)
|
static bool D3D12_INTERNAL_TryInitializeDXGIDebug(D3D12Renderer *renderer)
|
||||||
{
|
{
|
||||||
PFN_DXGI_GET_DEBUG_INTERFACE DXGIGetDebugInterfaceFunc;
|
PFN_DXGI_GET_DEBUG_INTERFACE DXGIGetDebugInterfaceFunc;
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
|
|
||||||
renderer->dxgidebug_dll = SDL_LoadObject(DXGIDEBUG_DLL);
|
renderer->dxgidebug_dll = SDL_LoadObject(DXGIDEBUG_DLL);
|
||||||
if (renderer->dxgidebug_dll == NULL) {
|
if (renderer->dxgidebug_dll == NULL) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not find " DXGIDEBUG_DLL);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGIGetDebugInterfaceFunc = (PFN_DXGI_GET_DEBUG_INTERFACE)SDL_LoadFunction(
|
DXGIGetDebugInterfaceFunc = (PFN_DXGI_GET_DEBUG_INTERFACE)SDL_LoadFunction(
|
||||||
renderer->dxgidebug_dll,
|
renderer->dxgidebug_dll,
|
||||||
DXGI_GET_DEBUG_INTERFACE_FUNC);
|
DXGI_GET_DEBUG_INTERFACE_FUNC);
|
||||||
if (DXGIGetDebugInterfaceFunc == NULL) {
|
if (DXGIGetDebugInterfaceFunc == NULL) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not load function: " DXGI_GET_DEBUG_INTERFACE_FUNC);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIDebug, (void **)&renderer->dxgiDebug);
|
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIDebug, (void **)&renderer->dxgiDebug);
|
||||||
if (FAILED(res)) {
|
if (FAILED(res)) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get IDXGIDebug interface");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIInfoQueue, (void **)&renderer->dxgiInfoQueue);
|
res = DXGIGetDebugInterfaceFunc(&D3D_IID_IDXGIInfoQueue, (void **)&renderer->dxgiInfoQueue);
|
||||||
if (FAILED(res)) {
|
if (FAILED(res)) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get IDXGIInfoQueue interface");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
|
static bool D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
|
||||||
{
|
{
|
||||||
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterfaceFunc;
|
PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterfaceFunc;
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
@@ -8368,21 +8368,20 @@ static void D3D12_INTERNAL_TryInitializeD3D12Debug(D3D12Renderer *renderer)
|
|||||||
renderer->d3d12_dll,
|
renderer->d3d12_dll,
|
||||||
D3D12_GET_DEBUG_INTERFACE_FUNC);
|
D3D12_GET_DEBUG_INTERFACE_FUNC);
|
||||||
if (D3D12GetDebugInterfaceFunc == NULL) {
|
if (D3D12GetDebugInterfaceFunc == NULL) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not load function: " D3D12_GET_DEBUG_INTERFACE_FUNC);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = D3D12GetDebugInterfaceFunc(D3D_GUID(D3D_IID_ID3D12Debug), (void **)&renderer->d3d12Debug);
|
res = D3D12GetDebugInterfaceFunc(D3D_GUID(D3D_IID_ID3D12Debug), (void **)&renderer->d3d12Debug);
|
||||||
if (FAILED(res)) {
|
if (FAILED(res)) {
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Could not get ID3D12Debug interface");
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D12Debug_EnableDebugLayer(renderer->d3d12Debug);
|
ID3D12Debug_EnableDebugLayer(renderer->d3d12Debug);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
|
#if !(defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES))
|
||||||
static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *renderer)
|
static void D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *renderer)
|
||||||
{
|
{
|
||||||
ID3D12InfoQueue *infoQueue = NULL;
|
ID3D12InfoQueue *infoQueue = NULL;
|
||||||
D3D12_MESSAGE_SEVERITY severities[] = { D3D12_MESSAGE_SEVERITY_INFO };
|
D3D12_MESSAGE_SEVERITY severities[] = { D3D12_MESSAGE_SEVERITY_INFO };
|
||||||
@@ -8394,7 +8393,7 @@ static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *rende
|
|||||||
D3D_GUID(D3D_IID_ID3D12InfoQueue),
|
D3D_GUID(D3D_IID_ID3D12InfoQueue),
|
||||||
(void **)&infoQueue);
|
(void **)&infoQueue);
|
||||||
if (FAILED(res)) {
|
if (FAILED(res)) {
|
||||||
CHECK_D3D12_ERROR_AND_RETURN("Failed to convert ID3D12Device to ID3D12InfoQueue", false);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_zero(filter);
|
SDL_zero(filter);
|
||||||
@@ -8410,8 +8409,6 @@ static bool D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(D3D12Renderer *rende
|
|||||||
true);
|
true);
|
||||||
|
|
||||||
ID3D12InfoQueue_Release(infoQueue);
|
ID3D12InfoQueue_Release(infoQueue);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WINAPI D3D12_INTERNAL_OnD3D12DebugInfoMsg(
|
static void WINAPI D3D12_INTERNAL_OnD3D12DebugInfoMsg(
|
||||||
@@ -8565,9 +8562,12 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
|
|||||||
|
|
||||||
#ifdef HAVE_IDXGIINFOQUEUE
|
#ifdef HAVE_IDXGIINFOQUEUE
|
||||||
// Initialize the DXGI debug layer, if applicable
|
// Initialize the DXGI debug layer, if applicable
|
||||||
|
bool hasDxgiDebug = false;
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
D3D12_INTERNAL_TryInitializeDXGIDebug(renderer);
|
hasDxgiDebug = D3D12_INTERNAL_TryInitializeDXGIDebug(renderer);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
bool hasDxgiDebug = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Load the CreateDXGIFactory1 function
|
// Load the CreateDXGIFactory1 function
|
||||||
@@ -8724,7 +8724,20 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
|
|||||||
|
|
||||||
// Initialize the D3D12 debug layer, if applicable
|
// Initialize the D3D12 debug layer, if applicable
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
D3D12_INTERNAL_TryInitializeD3D12Debug(renderer);
|
bool hasD3d12Debug = D3D12_INTERNAL_TryInitializeD3D12Debug(renderer);
|
||||||
|
if (hasDxgiDebug && hasD3d12Debug) {
|
||||||
|
SDL_LogInfo(
|
||||||
|
SDL_LOG_CATEGORY_GPU,
|
||||||
|
"Validation layers enabled, expect debug level performance!");
|
||||||
|
} else if (hasDxgiDebug || hasD3d12Debug) {
|
||||||
|
SDL_LogWarn(
|
||||||
|
SDL_LOG_CATEGORY_GPU,
|
||||||
|
"Validation layers partially enabled, some warnings may not be available");
|
||||||
|
} else {
|
||||||
|
SDL_LogWarn(
|
||||||
|
SDL_LOG_CATEGORY_GPU,
|
||||||
|
"Validation layers not found, continuing without validation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the D3D12Device
|
// Create the D3D12Device
|
||||||
@@ -8771,9 +8784,7 @@ static SDL_GPUDevice *D3D12_CreateDevice(bool debugMode, bool preferLowPower, SD
|
|||||||
|
|
||||||
// Initialize the D3D12 debug info queue, if applicable
|
// Initialize the D3D12 debug info queue, if applicable
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
if (!D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(renderer)) {
|
D3D12_INTERNAL_TryInitializeD3D12DebugInfoQueue(renderer);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
D3D12_INTERNAL_TryInitializeD3D12DebugInfoLogger(renderer);
|
D3D12_INTERNAL_TryInitializeD3D12DebugInfoLogger(renderer);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user