Skip to content

Commit 159a030

Browse files
committed
debug: Add VK_CHECK_FRIENDLY user-friendly assertion macro
This extends the VK_CHECK macro to print additional information intended to allow users to self-diagnose very common problems (like lack of VRAM, the usecase included here).
1 parent 157c335 commit 159a030

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

hw/xbox/nv2a/pgraph/vk/debug.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ extern int nv2a_vk_dgroup_indent;
6161
} \
6262
} while (0)
6363

64+
#define VK_CHECK_FRIENDLY(x, msg) \
65+
do { \
66+
VkResult vk_result = (x); \
67+
if (vk_result != VK_SUCCESS) { \
68+
fprintf(stderr, "vk_result = %d\n", vk_result); \
69+
nv2a_log_fatal_error( \
70+
"%s\nvk check failed: vk_result = %d\nat %s:%d\n", msg, \
71+
vk_result, __FILE__, __LINE__); \
72+
assert((x) && msg && \
73+
"A fatal error occurred. Check the xemu fatal error log " \
74+
"in your home directory for details."); \
75+
exit(127); \
76+
} \
77+
} while (0)
78+
79+
6480
void pgraph_vk_debug_frame_terminator(void);
6581

6682
#endif

hw/xbox/nv2a/pgraph/vk/surface.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,13 +786,16 @@ static void create_surface_image(PGRAPHState *pg, SurfaceBinding *surface)
786786
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
787787
};
788788

789-
VK_CHECK(vmaCreateImage(r->allocator, &image_create_info,
790-
&alloc_create_info, &surface->image,
791-
&surface->allocation, NULL));
792-
793-
VK_CHECK(vmaCreateImage(r->allocator, &image_create_info,
794-
&alloc_create_info, &surface->image_scratch,
795-
&surface->allocation_scratch, NULL));
789+
VK_CHECK_FRIENDLY(vmaCreateImage(r->allocator, &image_create_info,
790+
&alloc_create_info, &surface->image,
791+
&surface->allocation, NULL),
792+
"Likely out of video memory");
793+
794+
VK_CHECK_FRIENDLY(vmaCreateImage(r->allocator, &image_create_info,
795+
&alloc_create_info,
796+
&surface->image_scratch,
797+
&surface->allocation_scratch, NULL),
798+
"Likely out of video memory");
796799
surface->image_scratch_current_layout = VK_IMAGE_LAYOUT_UNDEFINED;
797800

798801
VkImageViewCreateInfo image_view_create_info = {

0 commit comments

Comments
 (0)