diff options
Diffstat (limited to 'src/gpu/texture_readback.cc')
| -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) |
