diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 07:48:56 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 07:48:56 +0100 |
| commit | 6d64674f7e3d00a9d18ec61eaf968ed37c8e849b (patch) | |
| tree | 4fcffcc28b866daa61543f48a8c3e76fed982951 /src | |
| parent | badf6907dd071afa7a5438fdf575d73c4c417e3f (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/texture_readback.cc | 12 |
1 files changed, 7 insertions, 5 deletions
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<uint8_t> 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<uint8_t> 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<uint8_t> 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) |
