This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository direct3d.
View the commit online.
commit e9dd42690ca332d9bf08c990da285ea9dde116f8
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Mon Apr 15 11:02:03 2024 +0200
d3d_1.c: add debug support
---
src/d3d_1.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 7 deletions(-)
diff --git a/src/d3d_1.c b/src/d3d_1.c
index 7800079..f596c28 100644
--- a/src/d3d_1.c
+++ b/src/d3d_1.c
@@ -7,11 +7,12 @@
*
* Compilation:
*
- * gcc -g -O2 -Wall -Wextra -o d3d_1 d3d_1.c win.c -ld3d11 -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_1 d3d_1.c win.c -ld3d11 -ldxgi /c/Windows/system32/DXGIDebug.dll -ldxguid -luuid -D_WIN32_WINNT=0x0A00
*/
-#include <stdlib.h> /* calloc() free() malloc() */
-#include <stdio.h> /* printf() fflush() */
+#include <stdlib.h> /* calloc() free() malloc() */
+#include <stdio.h> /* printf() fflush() */
+#include <string.h> /* strlen() */
#define _DEBUG
@@ -21,20 +22,26 @@
#include <dxgi1_3.h> /* DXGI interface */
#include <d3d11.h> /* D3D11 interface */
#include <d3dcompiler.h> /* compilation of shader */
+#include <dxgidebug.h> /* IDXGIDebug interface */
#include "win.h"
#ifdef _DEBUG
-# define FCT \
+# define DBG_FCT \
do { printf(" * %s\n", __FUNCTION__); fflush(stdout); } while (0)
+# define DBG_NAME(interface_, child_, name_) interface_ ## _SetPrivateData(child_, &WKPDID_D3DDebugObjectName, strlen(name_), name_)
#else
-# define FCT \
+# define DBG_FCT \
do { } while (0)
+# define DBG_NAME(interface_, child_, name_)
#endif
struct D3d
{
/* DXGI */
+#ifdef _DEBUG
+ IDXGIDebug *dxgi_debug;
+#endif
IDXGIFactory2 *dxgi_factory;
IDXGISwapChain1 *dxgi_swapchain;
/* D3D11 */
@@ -69,6 +76,8 @@ static void d3d_refresh_rate_get(D3d *d3d, UINT *num, UINT *den)
if (!d3d->vsync)
return;
+ DBG_FCT;
+
/* adapter of primary desktop : pass 0U */
res = IDXGIFactory_EnumAdapters(d3d->dxgi_factory, 0U, &dxgi_adapter);
if (FAILED(res))
@@ -163,6 +172,16 @@ D3d *d3d_init(Window *win, int vsync)
if (FAILED(res))
goto free_d3d;
+#ifdef _DEBUG
+ IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
+ &WKPDID_D3DDebugObjectName,
+ strlen("Factory2"), "Factory2");
+ res = DXGIGetDebugInterface(&IID_IDXGIDebug,
+ (void **)&d3d->dxgi_debug);
+ if (FAILED(res))
+ goto release_dxgi_factory2;
+#endif
+
/* software engine functions are called from the main loop */
flags = D3D11_CREATE_DEVICE_SINGLETHREADED |
D3D11_CREATE_DEVICE_BGRA_SUPPORT;
@@ -190,12 +209,17 @@ D3d *d3d_init(Window *win, int vsync)
goto release_dxgi_factory2;
#ifdef _DEBUG
+ ID3D11Device_SetPrivateData(d3d->d3d_device,
+ &WKPDID_D3DDebugObjectName,
+ strlen("Device"), "Device");
res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
(void **)&d3d->d3d_debug);
if (FAILED(res))
goto release_d3d_device;
#endif
+ DBG_NAME(ID3D11DeviceContext, d3d->d3d_device_ctx, "Device Context");
+
if (!GetClientRect(win->win, &r))
goto release_d3d_device;
@@ -238,6 +262,8 @@ D3d *d3d_init(Window *win, int vsync)
if (FAILED(res))
goto release_d3d_device;
+ DBG_NAME(IDXGIFactory, d3d->dxgi_swapchain, "Swap Chain");
+
/* rasterizer */
desc_rs.FillMode = D3D11_FILL_SOLID;
desc_rs.CullMode = D3D11_CULL_NONE;
@@ -256,6 +282,8 @@ D3d *d3d_init(Window *win, int vsync)
if (FAILED(res))
goto release_dxgi_swapchain;
+ DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
return d3d;
release_dxgi_swapchain:
@@ -279,6 +307,7 @@ D3d *d3d_init(Window *win, int vsync)
void d3d_shutdown(D3d *d3d)
{
#ifdef _DEBUG
+ IDXGIDebug *dxgi_debug;
ID3D11Debug *d3d_debug;
#endif
@@ -286,6 +315,7 @@ void d3d_shutdown(D3d *d3d)
return;
#ifdef _DEBUG
+ dxgi_debug = d3d->dxgi_debug;
d3d_debug = d3d->d3d_debug;
#endif
@@ -300,7 +330,9 @@ void d3d_shutdown(D3d *d3d)
#ifdef _DEBUG
ID3D11Debug_ReportLiveDeviceObjects(d3d_debug, D3D11_RLDO_DETAIL);
+ IDXGIDebug_ReportLiveObjects(dxgi_debug, DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL);
ID3D11Debug_Release(d3d_debug);
+ IDXGIDebug_Release(dxgi_debug);
#endif
}
@@ -310,7 +342,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
ID3D11Texture2D *back_buffer;
HRESULT res;
- FCT;
+ DBG_FCT;
/* unset the render target view in the output merger */
ID3D11DeviceContext_OMSetRenderTargets(d3d->d3d_device_ctx,
@@ -351,6 +383,8 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
return;
}
+ DBG_NAME(ID3D11Device, back_buffer, "Texture2D buffer resized");
+
ZeroMemory(&desc_rtv, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));
desc_rtv.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc_rtv.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
@@ -361,6 +395,8 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
&desc_rtv,
&d3d->d3d_render_target_view);
+ DBG_NAME(ID3D11Device, d3d->d3d_render_target_view, "Render Target View resized");
+
ID3D11Texture2D_Release(back_buffer);
/* update the pipeline with the new render target view */
@@ -396,7 +432,7 @@ void d3d_render(D3d *d3d)
const FLOAT color[4] = { 0.10f, 0.18f, 0.24f, 1.0f };
HRESULT res;
- FCT;
+ DBG_FCT;
/* clear render target */
ID3D11DeviceContext_ClearRenderTargetView(d3d->d3d_device_ctx,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.