summaryrefslogtreecommitdiff
path: root/src/gpu/texture_readback.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/texture_readback.cc')
-rw-r--r--src/gpu/texture_readback.cc31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc
index e25da9e..bd3c79c 100644
--- a/src/gpu/texture_readback.cc
+++ b/src/gpu/texture_readback.cc
@@ -15,13 +15,9 @@ struct MapState {
WGPUMapAsyncStatus status = WGPUMapAsyncStatus_Unknown;
};
-std::vector<uint8_t> read_texture_pixels(
- WGPUInstance instance,
- WGPUDevice device,
- WGPUTexture texture,
- int width,
- int height) {
-
+std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
+ WGPUDevice device, WGPUTexture texture,
+ int width, int height) {
// Align bytes per row to 256 (COPY_BYTES_PER_ROW_ALIGNMENT)
const uint32_t bytes_per_pixel = 4; // BGRA8
const uint32_t unaligned_bytes_per_row = width * bytes_per_pixel;
@@ -99,7 +95,8 @@ std::vector<uint8_t> read_texture_pixels(
state->done = true;
};
WGPUBufferMapCallbackInfo map_info = {};
- map_info.mode = WGPUCallbackMode_AllowProcessEvents; // Fire during ProcessEvents
+ 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);
@@ -178,13 +175,10 @@ static float fp16_to_float(uint16_t h) {
return result;
}
-std::vector<uint8_t> texture_readback_fp16_to_u8(
- WGPUDevice device,
- WGPUQueue queue,
- WGPUTexture texture,
- int width,
- int height) {
-
+std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
+ WGPUQueue queue,
+ WGPUTexture texture, int width,
+ int height) {
// Align bytes per row to 256
const uint32_t bytes_per_pixel = 8; // RGBA16Float = 4 × 2 bytes
const uint32_t unaligned_bytes_per_row = width * bytes_per_pixel;
@@ -271,10 +265,9 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(
std::vector<uint8_t> pixels(width * height * 4);
if (mapped_data) {
for (int y = 0; y < height; ++y) {
- const uint16_t* src_row =
- reinterpret_cast<const uint16_t*>(
- reinterpret_cast<const uint8_t*>(mapped_data) +
- y * aligned_bytes_per_row);
+ const uint16_t* src_row = reinterpret_cast<const uint16_t*>(
+ reinterpret_cast<const uint8_t*>(mapped_data) +
+ y * aligned_bytes_per_row);
for (int x = 0; x < width; ++x) {
float r = fp16_to_float(src_row[x * 4 + 0]);
float g = fp16_to_float(src_row[x * 4 + 1]);