Repository: google/filament
File: filament/backend/src/webgpu/WebGPUDriver.cpp (C++)

Code before:
                            memcpy(dst + i * data->unpaddedBytesPerRow,
                                    src + i * data->paddedBytesPerRow, data->unpaddedBytesPerRow);
                        }
                    }
                    data->buffer.Unmap();
                } else {
                    FWGPU_LOGE << "Failed to map staging buffer for readPixels: " << message;
                }
                data->driver->scheduleDestroy(std::move(data->pixelBufferDescriptor));
                data->driver->mReadPixelMapsCounter.finishTask();
            },
            userData.release());
}

void WebGPUDriver::readBufferSubData(Handle<HwBufferObject> bufferObjectHandle,
        const uint32_t offset, const uint32_t size, backend::BufferDescriptor&& bufferDescriptor) {
    // todo
    scheduleDestroy(std::move(bufferDescriptor));
}

void WebGPUDriver::blitDEPRECATED(TargetBufferFlags buffers,
        Handle<HwRenderTarget> destinationRenderTargetHandle, const Viewport destinationViewport,
        Handle<HwRenderTarget> sourceRenderTargetHandle, const Viewport sourceViewport,
        const SamplerMagFilter filter) {

    auto const srcTarget = handleCast<WebGPURenderTarget>(sourceRenderTargetHandle);
    auto const dstTarget = handleCast<WebGPURenderTarget>(destinationRenderTargetHandle);
    assert_invariant(srcTarget && dstTarget);

    FILAMENT_CHECK_PRECONDITION(buffers == TargetBufferFlags::COLOR0)
            << "blitDEPRECATED only supports COLOR0";

    FILAMENT_CHECK_PRECONDITION(sourceViewport.left >= 0 && sourceViewport.bottom >= 0 &&
                                destinationViewport.left >= 0 && destinationViewport.bottom >= 0)
            << "Source and destination viewports must be positive.";

    // We always blit from/to the COLOR0 attachment.
    Handle<HwTexture> sourceTextureHandle = srcTarget->getColorAttachmentInfos()[0].handle;
    Handle<HwTexture> destinationTextureHandle = dstTarget->getColorAttachmentInfos()[0].handle;

    if (UTILS_UNLIKELY(!sourceTextureHandle || !destinationTextureHandle)) {
        FWGPU_LOGE << "blitDEPRECATED could not find a valid color attachment to blit.";
        return;
    }

    // WebGPU's texture coordinates are top-left, while Filament's are bottom-left.
    // We need to flip the y-coordinate for both source and destination.
    auto const srcTexture = handleCast<WebGPUTexture>(sourceTextureHandle);
    const uint32_t srcTextureHeight = srcTexture->height;
    const uint32_t flippedSourceY =
            srcTextureHeight - sourceViewport.bottom - sourceViewport.height;

Review comment (suggestion):
nit: looks like sometimes we use `src`, others `source`. Sometimes we use `dst` and other others `destination`. IMO I would prefer explicit naming, e.g. `source` and `destination`.

Code after:
                            memcpy(dst + i * data->unpaddedBytesPerRow,
                                    src + i * data->paddedBytesPerRow, data->unpaddedBytesPerRow);
                        }
                    }
                    data->buffer.Unmap();
                } else {
                    FWGPU_LOGE << "Failed to map staging buffer for readPixels: " << message;
                }
                data->driver->scheduleDestroy(std::move(data->pixelBufferDescriptor));
                data->driver->mReadPixelMapsCounter.finishTask();
            },
            userData.release());
}

void WebGPUDriver::readBufferSubData(Handle<HwBufferObject> bufferObjectHandle,
        const uint32_t offset, const uint32_t size, backend::BufferDescriptor&& bufferDescriptor) {
    // todo
    scheduleDestroy(std::move(bufferDescriptor));
}

void WebGPUDriver::blitDEPRECATED(TargetBufferFlags buffers,
        Handle<HwRenderTarget> destinationRenderTargetHandle, const Viewport destinationViewport,
        Handle<HwRenderTarget> sourceRenderTargetHandle, const Viewport sourceViewport,
        const SamplerMagFilter filter) {

    auto const sourceTarget{ handleCast<WebGPURenderTarget>(sourceRenderTargetHandle) };
    auto const destinationTarget{ handleCast<WebGPURenderTarget>(destinationRenderTargetHandle) };
    assert_invariant(sourceTarget && destinationTarget);

    FILAMENT_CHECK_PRECONDITION(buffers == TargetBufferFlags::COLOR0)
            << "blitDEPRECATED only supports COLOR0";

    FILAMENT_CHECK_PRECONDITION(sourceViewport.left >= 0 && sourceViewport.bottom >= 0 &&
                                destinationViewport.left >= 0 && destinationViewport.bottom >= 0)
            << "Source and destination viewports must be positive.";

    // We always blit from/to the COLOR0 attachment.
    auto sourceAttachment {sourceTarget->getColorAttachmentInfos()[0]};
    Handle<HwTexture> sourceTextureHandle{ sourceAttachment.handle };
    auto destinationAttachment {destinationTarget->getColorAttachmentInfos()[0]};
    Handle<HwTexture> destinationTextureHandle{
        destinationAttachment.handle
    };

    if (UTILS_UNLIKELY(!sourceTextureHandle || !destinationTextureHandle)) {
        FWGPU_LOGE << "blitDEPRECATED could not find a valid color attachment to blit.";
        return;
    }

    // WebGPU's texture coordinates are top-left, while Filament's are bottom-left.
    // We need to flip the y-coordinate for both source and destination.