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 b1205690cb516307f0360bd5511d4557c29808c8
Author: Vincent Torri <vto...@outlook.fr>
AuthorDate: Tue Apr 16 07:23:32 2024 +0200

    add debug in all files
---
 src/d3d_2.c | 63 +++++++++++++++++++++++++++++++++++++++++------
 src/d3d_3.c | 65 ++++++++++++++++++++++++++++++++++++++++++------
 src/d3d_4.c | 67 ++++++++++++++++++++++++++++++++++++++++++++------
 src/d3d_5.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++------
 src/d3d_6.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-------
 src/d3d_7.c | 82 +++++++++++++++++++++++++++++++++++++++----------------------
 6 files changed, 351 insertions(+), 69 deletions(-)

diff --git a/src/d3d_2.c b/src/d3d_2.c
index 48d8aee..1e2dfbe 100644
--- a/src/d3d_2.c
+++ b/src/d3d_2.c
@@ -7,11 +7,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_2 d3d_2.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_2 d3d_2.c win.c -ld3d11 -ld3dcompiler -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,14 +22,18 @@
 #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_) \
 do { } while (0)
 #endif
 
@@ -38,6 +43,9 @@ do { } while (0)
 struct D3d
 {
     /* DXGI */
+#ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
+#endif
     IDXGIFactory2 *dxgi_factory;
     IDXGISwapChain1 *dxgi_swapchain;
     /* D3D11 */
@@ -89,6 +97,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))
@@ -190,6 +200,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;
@@ -217,12 +237,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;
 
@@ -265,6 +290,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;
@@ -283,6 +310,8 @@ D3d *d3d_init(Window *win, int vsync)
     if (FAILED(res))
         goto release_dxgi_swapchain;
 
+    DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
     /* Vertex shader */
     flags = D3DCOMPILE_ENABLE_STRICTNESS;
 #ifdef _DEBUG
@@ -318,6 +347,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_d3D_rasterizer;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_vertex_shader, "Vertex Shader");
+
     /* create the input layout */
     res = ID3D11Device_CreateInputLayout(d3d->d3d_device,
                                          desc_ie,
@@ -332,6 +363,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_vertex_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_input_layout, "Input Layout");
+
     /* Pixel shader */
     ps_blob = NULL;
     res = D3DCompileFromFile(L"shader_2.hlsl",
@@ -362,6 +395,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_pixel_shader, "Pixel Shader");
+
     return d3d;
 
   release_input_layout:
@@ -391,6 +426,7 @@ D3d *d3d_init(Window *win, int vsync)
 void d3d_shutdown(D3d *d3d)
 {
 #ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
     ID3D11Debug *d3d_debug;
 #endif
 
@@ -398,6 +434,7 @@ void d3d_shutdown(D3d *d3d)
         return;
 
 #ifdef _DEBUG
+    dxgi_debug = d3d->dxgi_debug;
     d3d_debug = d3d->d3d_debug;
 #endif
 
@@ -415,7 +452,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
 }
 
@@ -425,7 +464,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,
@@ -466,6 +505,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;
@@ -476,6 +517,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 */
@@ -511,6 +554,8 @@ Object *triangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -551,6 +596,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -573,6 +620,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -629,7 +678,7 @@ void d3d_render(D3d *d3d)
     int w;
     int h;
 
-    FCT;
+    DBG_FCT;
 
     res = IDXGISwapChain1_GetDesc1(d3d->dxgi_swapchain, &desc);
     if (FAILED(res))
diff --git a/src/d3d_3.c b/src/d3d_3.c
index 65bba77..1223633 100644
--- a/src/d3d_3.c
+++ b/src/d3d_3.c
@@ -7,11 +7,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_3 d3d_3.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_3 d3d_3.c win.c -ld3d11 -ld3dcompiler -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,27 @@
 #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_) \
 do { } while (0)
 #endif
 
 struct D3d
 {
     /* DXGI */
+#ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
+#endif
     IDXGIFactory2 *dxgi_factory;
     IDXGISwapChain1 *dxgi_swapchain;
     /* D3D11 */
@@ -93,6 +101,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))
@@ -195,6 +205,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;
@@ -222,12 +242,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;
 
@@ -270,6 +295,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;
@@ -288,6 +315,8 @@ D3d *d3d_init(Window *win, int vsync)
     if (FAILED(res))
         goto release_dxgi_swapchain;
 
+    DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
     /* Vertex shader */
     flags = D3DCOMPILE_ENABLE_STRICTNESS;
 #ifdef _DEBUG
@@ -323,6 +352,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_d3D_rasterizer;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_vertex_shader, "Vertex Shader");
+
     /* create the input layout */
     res = ID3D11Device_CreateInputLayout(d3d->d3d_device,
                                          desc_ie,
@@ -337,6 +368,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_vertex_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_input_layout, "Input Layout");
+
     /* Pixel shader */
     ps_blob = NULL;
     res = D3DCompileFromFile(L"shader_3.hlsl",
@@ -367,6 +400,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_pixel_shader, "Pixel Shader");
+
     desc_buf.ByteWidth = sizeof(Const_Buffer);
     desc_buf.Usage = D3D11_USAGE_DYNAMIC; /* because buffer is updated when the window has resized */
     desc_buf.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
@@ -384,6 +419,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_pixel_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_const_buffer, "Constant Buffer");
+
     return d3d;
 
   release_pixel_shader:
@@ -415,6 +452,7 @@ D3d *d3d_init(Window *win, int vsync)
 void d3d_shutdown(D3d *d3d)
 {
 #ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
     ID3D11Debug *d3d_debug;
 #endif
 
@@ -422,6 +460,7 @@ void d3d_shutdown(D3d *d3d)
         return;
 
 #ifdef _DEBUG
+    dxgi_debug = d3d->dxgi_debug;
     d3d_debug = d3d->d3d_debug;
 #endif
 
@@ -440,7 +479,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
 }
 
@@ -451,7 +492,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
                                   (ID3D11Resource *)d3d->d3d_const_buffer,
@@ -510,6 +551,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;
@@ -520,6 +563,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 */
@@ -554,6 +599,8 @@ Object *triangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -594,6 +641,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -616,6 +665,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -654,7 +705,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,
diff --git a/src/d3d_4.c b/src/d3d_4.c
index 3e7a6fd..e5ff3ec 100644
--- a/src/d3d_4.c
+++ b/src/d3d_4.c
@@ -5,11 +5,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_4 d3d_4.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_4 d3d_4.c win.c -ld3d11 -ld3dcompiler -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
 
@@ -19,20 +20,27 @@
 #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_) \
 do { } while (0)
 #endif
 
 struct D3d
 {
     /* DXGI */
+#ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
+#endif
     IDXGIFactory2 *dxgi_factory;
     IDXGISwapChain1 *dxgi_swapchain;
     /* D3D11 */
@@ -95,6 +103,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))
@@ -165,7 +175,7 @@ D3d *d3d_init(Window *win, int vsync)
     D3D11_INPUT_ELEMENT_DESC desc_ie[] =
     {
         { "POSITION", 0, DXGI_FORMAT_R32G32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
-        { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 2 * sizeof(UINT), D3D11_INPUT_PER_VERTEX_DATA, 0 }
+        { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
     };
     DXGI_SWAP_CHAIN_DESC1 desc_sw;
     DXGI_SWAP_CHAIN_FULLSCREEN_DESC desc_fs;
@@ -198,6 +208,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;
@@ -225,12 +245,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;
 
@@ -273,6 +298,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;
@@ -291,6 +318,8 @@ D3d *d3d_init(Window *win, int vsync)
     if (FAILED(res))
         goto release_dxgi_swapchain;
 
+    DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
     /* Vertex shader */
     flags = D3DCOMPILE_ENABLE_STRICTNESS;
 #ifdef _DEBUG
@@ -326,6 +355,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_d3D_rasterizer;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_vertex_shader, "Vertex Shader");
+
     /* create the input layout */
     res = ID3D11Device_CreateInputLayout(d3d->d3d_device,
                                          desc_ie,
@@ -340,6 +371,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_vertex_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_input_layout, "Input Layout");
+
     /* Pixel shader */
     ps_blob = NULL;
     res = D3DCompileFromFile(L"shader_4.hlsl",
@@ -370,6 +403,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_pixel_shader, "Pixel Shader");
+
     desc_buf.ByteWidth = sizeof(Const_Buffer);
     desc_buf.Usage = D3D11_USAGE_DYNAMIC; /* because buffer is updated when the window has resized */
     desc_buf.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
@@ -387,6 +422,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_pixel_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_const_buffer, "Constant Buffer");
+
     return d3d;
 
   release_pixel_shader:
@@ -418,6 +455,7 @@ D3d *d3d_init(Window *win, int vsync)
 void d3d_shutdown(D3d *d3d)
 {
 #ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
     ID3D11Debug *d3d_debug;
 #endif
 
@@ -425,6 +463,7 @@ void d3d_shutdown(D3d *d3d)
         return;
 
 #ifdef _DEBUG
+    dxgi_debug = d3d->dxgi_debug;
     d3d_debug = d3d->d3d_debug;
 #endif
 
@@ -443,7 +482,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
 }
 
@@ -454,7 +495,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
                                   (ID3D11Resource *)d3d->d3d_const_buffer,
@@ -513,6 +554,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;
@@ -523,6 +566,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 */
@@ -561,6 +606,8 @@ Object *triangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -613,6 +660,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -635,6 +684,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -674,7 +725,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,
diff --git a/src/d3d_5.c b/src/d3d_5.c
index 94338af..6916f9d 100644
--- a/src/d3d_5.c
+++ b/src/d3d_5.c
@@ -5,11 +5,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_5 d3d_5.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_5 d3d_5.c win.c -ld3d11 -ld3dcompiler -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
 
@@ -19,20 +20,27 @@
 #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_) \
 do { } while (0)
 #endif
 
 struct D3d
 {
     /* DXGI */
+#ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
+#endif
     IDXGIFactory2 *dxgi_factory;
     IDXGISwapChain1 *dxgi_swapchain;
     /* D3D11 */
@@ -95,6 +103,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))
@@ -165,7 +175,7 @@ D3d *d3d_init(Window *win, int vsync)
     D3D11_INPUT_ELEMENT_DESC desc_ie[] =
     {
         { "POSITION", 0, DXGI_FORMAT_R32G32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
-        { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 2 * sizeof(UINT), D3D11_INPUT_PER_VERTEX_DATA, 0 }
+        { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
     };
     DXGI_SWAP_CHAIN_DESC1 desc_sw;
     DXGI_SWAP_CHAIN_FULLSCREEN_DESC desc_fs;
@@ -198,6 +208,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;
@@ -225,12 +245,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;
 
@@ -273,6 +298,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;
@@ -291,6 +318,8 @@ D3d *d3d_init(Window *win, int vsync)
     if (FAILED(res))
         goto release_dxgi_swapchain;
 
+    DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
     /* Vertex shader */
     flags = D3DCOMPILE_ENABLE_STRICTNESS;
 #ifdef _DEBUG
@@ -326,6 +355,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_d3D_rasterizer;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_vertex_shader, "Vertex Shader");
+
     /* create the input layout */
     res = ID3D11Device_CreateInputLayout(d3d->d3d_device,
                                          desc_ie,
@@ -340,6 +371,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_vertex_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_input_layout, "Input Layout");
+
     /* Pixel shader */
     ps_blob = NULL;
     res = D3DCompileFromFile(L"shader_5.hlsl",
@@ -370,6 +403,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_pixel_shader, "Pixel Shader");
+
     desc_buf.ByteWidth = sizeof(Const_Buffer);
     desc_buf.Usage = D3D11_USAGE_DYNAMIC; /* because buffer is updated when the window has resized */
     desc_buf.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
@@ -387,6 +422,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_pixel_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_const_buffer, "Constant Buffer");
+
     return d3d;
 
   release_pixel_shader:
@@ -418,6 +455,7 @@ D3d *d3d_init(Window *win, int vsync)
 void d3d_shutdown(D3d *d3d)
 {
 #ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
     ID3D11Debug *d3d_debug;
 #endif
 
@@ -425,6 +463,7 @@ void d3d_shutdown(D3d *d3d)
         return;
 
 #ifdef _DEBUG
+    dxgi_debug = d3d->dxgi_debug;
     d3d_debug = d3d->d3d_debug;
 #endif
 
@@ -443,7 +482,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
 }
 
@@ -454,7 +495,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
                                   (ID3D11Resource *)d3d->d3d_const_buffer,
@@ -513,6 +554,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;
@@ -523,6 +566,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 */
@@ -561,6 +606,8 @@ Object *triangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -613,6 +660,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -635,6 +684,8 @@ Object *triangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -655,6 +706,8 @@ Object *rectangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -722,6 +775,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -744,6 +799,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -790,7 +847,7 @@ void d3d_render(D3d *d3d)
     size_t i;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     /* clear render target */
     ID3D11DeviceContext_ClearRenderTargetView(d3d->d3d_device_ctx,
diff --git a/src/d3d_6.c b/src/d3d_6.c
index 01844e6..db89da3 100644
--- a/src/d3d_6.c
+++ b/src/d3d_6.c
@@ -5,11 +5,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_6 d3d_6.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_6 d3d_6.c win.c -ld3d11 -ld3dcompiler -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
 
@@ -19,20 +20,27 @@
 #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_) \
 do { } while (0)
 #endif
 
 struct D3d
 {
     /* DXGI */
+#ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
+#endif
     IDXGIFactory2 *dxgi_factory;
     IDXGISwapChain1 *dxgi_swapchain;
     /* D3D11 */
@@ -64,8 +72,8 @@ typedef struct
 typedef struct
 {
     int rotation[2][4];
-    float ivps[2];
-    float dummy[2];
+    float ivps[2]; /* inverse viewport size */
+    float dummy[2]; /* for 16 bytes padding */
 } Const_Buffer;
 
 typedef struct
@@ -96,6 +104,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))
@@ -199,6 +209,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;
@@ -226,12 +246,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;
 
@@ -274,6 +299,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;
@@ -292,6 +319,8 @@ D3d *d3d_init(Window *win, int vsync)
     if (FAILED(res))
         goto release_dxgi_swapchain;
 
+    DBG_NAME(ID3D11Device, d3d->d3d_rasterizer_state, "Rasterizer State");
+
     /* Vertex shader */
     flags = D3DCOMPILE_ENABLE_STRICTNESS;
 #ifdef _DEBUG
@@ -327,6 +356,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_d3D_rasterizer;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_vertex_shader, "Vertex Shader");
+
     /* create the input layout */
     res = ID3D11Device_CreateInputLayout(d3d->d3d_device,
                                          desc_ie,
@@ -341,6 +372,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_vertex_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_input_layout, "Input Layout");
+
     /* Pixel shader */
     ps_blob = NULL;
     res = D3DCompileFromFile(L"shader_6.hlsl",
@@ -371,6 +404,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_input_layout;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_pixel_shader, "Pixel Shader");
+
     desc_buf.ByteWidth = sizeof(Const_Buffer);
     desc_buf.Usage = D3D11_USAGE_DYNAMIC; /* because buffer is updated when the window has resized */
     desc_buf.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
@@ -388,6 +423,8 @@ D3d *d3d_init(Window *win, int vsync)
         goto release_pixel_shader;
     }
 
+    DBG_NAME(ID3D11Device, d3d->d3d_const_buffer, "Constant Buffer");
+
     return d3d;
 
   release_pixel_shader:
@@ -419,6 +456,7 @@ D3d *d3d_init(Window *win, int vsync)
 void d3d_shutdown(D3d *d3d)
 {
 #ifdef _DEBUG
+    IDXGIDebug *dxgi_debug;
     ID3D11Debug *d3d_debug;
 #endif
 
@@ -426,6 +464,7 @@ void d3d_shutdown(D3d *d3d)
         return;
 
 #ifdef _DEBUG
+    dxgi_debug = d3d->dxgi_debug;
     d3d_debug = d3d->d3d_debug;
 #endif
 
@@ -444,7 +483,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
 }
 
@@ -455,7 +496,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
                                   (ID3D11Resource *)d3d->d3d_const_buffer,
@@ -573,6 +614,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;
@@ -583,6 +626,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 */
@@ -620,6 +665,8 @@ Object *rectangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)malloc(sizeof(Object));
     if (!o)
         return NULL;
@@ -687,6 +734,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc.ByteWidth = sizeof(indices);
     desc.Usage = D3D11_USAGE_DYNAMIC;
     desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -709,6 +758,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     return o;
 }
 
@@ -754,7 +805,7 @@ void d3d_render(D3d *d3d)
     size_t i;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     /* clear render target */
     ID3D11DeviceContext_ClearRenderTargetView(d3d->d3d_device_ctx,
@@ -810,6 +861,7 @@ void d3d_render(D3d *d3d)
                                              objects[i]->index_buffer,
                                              DXGI_FORMAT_R32_UINT,
                                              0);
+
         /* draw */
         ID3D11DeviceContext_DrawIndexed(d3d->d3d_device_ctx,
                                         objects[i]->index_count,
diff --git a/src/d3d_7.c b/src/d3d_7.c
index 3faedee..c6ae763 100644
--- a/src/d3d_7.c
+++ b/src/d3d_7.c
@@ -5,11 +5,12 @@
  *
  * Compilation:
  *
- * gcc -g -O2 -Wall -Wextra -o d3d_7 d3d_7.c win.c -ld3d11 -ld3dcompiler -ldxgi -luuid -D_WIN32_WINNT=0x0A00
+ * gcc -g -O2 -Wall -Wextra -o d3d_7 d3d_7.c win.c -ld3d11 -ld3dcompiler -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
 
@@ -24,13 +25,14 @@
 #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_) \
 do { } while (0)
-# define DBG_NAME(interface_, child_, name_)
 #endif
 
 typedef enum
@@ -79,8 +81,8 @@ typedef struct
 typedef struct
 {
     int rotation[2][4];
-    float ivps[2];
-    float dummy[2];
+    float ivps[2]; /* inverse viewport size */
+    float dummy[2]; /* for 16 bytes padding */
 } Const_Buffer;
 
 typedef struct
@@ -114,6 +116,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))
@@ -222,7 +226,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     IDXGIFactory2_SetPrivateData(d3d->dxgi_factory,
                                  &WKPDID_D3DDebugObjectName,
-                                 sizeof("Factory2") - 1, "Factory2");
+                                 strlen("Factory2"), "Factory2");
     res = DXGIGetDebugInterface(&IID_IDXGIDebug,
                                 (void **)&d3d->dxgi_debug);
     if (FAILED(res))
@@ -258,7 +262,7 @@ D3d *d3d_init(Window *win, int vsync)
 #ifdef _DEBUG
     ID3D11Device_SetPrivateData(d3d->d3d_device,
                                 &WKPDID_D3DDebugObjectName,
-                                sizeof("Device") - 1, "Device");
+                                strlen("Device"), "Device");
     res = ID3D11Debug_QueryInterface(d3d->d3d_device, &IID_ID3D11Debug,
                                      (void **)&d3d->d3d_debug);
     if (FAILED(res))
@@ -532,7 +536,7 @@ void d3d_resize(D3d *d3d, int rot, UINT width, UINT height)
     ID3D11Texture2D *back_buffer;
     HRESULT res;
 
-    FCT;
+    DBG_FCT;
 
     res = ID3D11DeviceContext_Map(d3d->d3d_device_ctx,
                                   (ID3D11Resource *)d3d->d3d_const_buffer,
@@ -650,6 +654,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;
@@ -691,6 +697,8 @@ unsigned int *data_new(int w, int h)
     int i;
     int j;
 
+    DBG_FCT;
+
     d = malloc(w * h * sizeof(unsigned int));
     if (!d)
         return NULL;
@@ -733,10 +741,11 @@ Object *texture_new(D3d *d3d,
     D3D11_BUFFER_DESC desc_buffer;
     D3D11_TEXTURE2D_DESC desc_tex;
     D3D11_SUBRESOURCE_DATA data_sr;
-    ID3D11Texture2D *tex;
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)calloc(1, sizeof(Object));
     if (!o)
         return NULL;
@@ -810,9 +819,12 @@ Object *texture_new(D3d *d3d,
                                    &o->vertex_buffer);
     if (FAILED(res))
     {
-        goto free_o;
+        free(o);
+        return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc_buffer.ByteWidth = sizeof(indices);
     desc_buffer.Usage = D3D11_USAGE_DYNAMIC;
     desc_buffer.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -830,9 +842,13 @@ Object *texture_new(D3d *d3d,
                                    &o->index_buffer);
     if (FAILED(res))
     {
-        goto release_vertex_buffer;
+        ID3D11Buffer_Release(o->vertex_buffer);
+        free(o);
+        return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     /** texture 2D **/
 
     desc_tex.Width = w;
@@ -851,38 +867,38 @@ Object *texture_new(D3d *d3d,
     data_sr.SysMemPitch = 4U * (unsigned int)w;
     data_sr.SysMemSlicePitch = 0U; /* for 3D resources only */
 
-    tex = NULL;
     res = ID3D11Device_CreateTexture2D(d3d->d3d_device,
                                        &desc_tex,
                                        &data_sr,
-                                       &tex);
+                                       &o->texture);
     if (FAILED(res))
     {
-        goto release_index_buffer;
+        ID3D11Buffer_Release(o->index_buffer);
+        ID3D11Buffer_Release(o->vertex_buffer);
+        free(o);
+        return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->texture, "Texture object");
+
     res = ID3D11Device_CreateShaderResourceView(d3d->d3d_device,
-                                                (ID3D11Resource *)tex,
+                                                (ID3D11Resource *)o->texture,
                                                 NULL,
                                                 &o->texture_view);
     if (FAILED(res))
     {
-        goto release_texture;
+        ID3D11Texture2D_Release(o->texture);
+        ID3D11Buffer_Release(o->index_buffer);
+        ID3D11Buffer_Release(o->vertex_buffer);
+        free(o);
+        return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->texture_view, "Texture view object");
+
     o->type = OBJECT_TYPE_TEXTURE;
 
     return o;
-
-  release_texture:
-    ID3D11Texture2D_Release(tex);
-  release_index_buffer:
-    ID3D11Buffer_Release(o->index_buffer);
-  release_vertex_buffer:
-    ID3D11Buffer_Release(o->vertex_buffer);
-  free_o:
-    free(o);
-    return NULL;
 }
 
 /*** rectangle ***/
@@ -902,6 +918,8 @@ Object *rectangle_new(D3d *d3d,
     Object *o;
     HRESULT res;
 
+    DBG_FCT;
+
     o = (Object *)calloc(1, sizeof(Object));
     if (!o)
         return NULL;
@@ -969,6 +987,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->vertex_buffer, "Vertex buffer");
+
     desc_buffer.ByteWidth = sizeof(indices);
     desc_buffer.Usage = D3D11_USAGE_DYNAMIC;
     desc_buffer.BindFlags = D3D11_BIND_INDEX_BUFFER;
@@ -991,6 +1011,8 @@ Object *rectangle_new(D3d *d3d,
         return NULL;
     }
 
+    DBG_NAME(ID3D11Device, o->index_buffer, "Index buffer");
+
     o->type = OBJECT_TYPE_RECTANGLE;
 
     return o;
@@ -1048,7 +1070,7 @@ void d3d_render(D3d *d3d)
     size_t i;
     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.

Reply via email to