From 6d64674f7e3d00a9d18ec61eaf968ed37c8e849b Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 11 Feb 2026 07:48:56 +0100 Subject: fix: CNN test tool GPU readback with wgpuDevicePoll Fixed buffer mapping callback mode mismatch causing Unknown status. Changed from WaitAnyOnly+ProcessEvents to AllowProcessEvents+DevicePoll. Readback now functional but CNN output incorrect (all white). Issue isolated to tool-specific binding/uniform setup - CNNEffect in demo works correctly. Technical details: - WGPUCallbackMode_WaitAnyOnly requires wgpuInstanceWaitAny - Using wgpuInstanceProcessEvents with WaitAnyOnly never fires callback - Fixed by using AllowProcessEvents mode + wgpuDevicePoll - Removed debug output and platform warnings Status: 36/36 tests pass, readback works, CNN shader issue remains. handoff(Claude): CNN test tool readback fixed, output debugging needed --- src/gpu/texture_readback.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gpu') diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc index 3a690d3..0eb63d7 100644 --- a/src/gpu/texture_readback.cc +++ b/src/gpu/texture_readback.cc @@ -72,6 +72,9 @@ std::vector read_texture_pixels( wgpuCommandBufferRelease(commands); wgpuCommandEncoderRelease(encoder); + // Wait for copy to complete before mapping + wgpuDevicePoll(device, true, nullptr); + // Map buffer for reading (API differs between Win32 and native) #if defined(DEMO_CROSS_COMPILE_WIN32) // Win32: Old callback API @@ -95,7 +98,7 @@ std::vector read_texture_pixels( state->done = true; }; WGPUBufferMapCallbackInfo map_info = {}; - map_info.mode = WGPUCallbackMode_WaitAnyOnly; + map_info.mode = WGPUCallbackMode_AllowProcessEvents; // Fire during ProcessEvents map_info.callback = map_cb; map_info.userdata1 = &map_state; wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_info); @@ -106,14 +109,13 @@ std::vector read_texture_pixels( #if defined(__EMSCRIPTEN__) emscripten_sleep(10); #else - wgpuInstanceProcessEvents(instance); + wgpuDevicePoll(device, true, nullptr); #endif } - if (map_state.status != WGPUMapAsyncStatus_Success) { - fprintf(stderr, "Buffer mapping failed: %d\n", map_state.status); + if (!map_state.done || map_state.status != WGPUMapAsyncStatus_Success) { wgpuBufferRelease(staging); - return pixels; // Return empty + return pixels; // Return empty on timeout or failure } // Copy data from mapped buffer (handle row padding) -- cgit v1.2.3