Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[g-webgpu] 实现 readTexture 以支持拾取 #1400

Open
xiaoiver opened this issue Jun 29, 2023 · 1 comment
Open

[g-webgpu] 实现 readTexture 以支持拾取 #1400

xiaoiver opened this issue Jun 29, 2023 · 1 comment
Assignees
Labels

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Jun 29, 2023

在 WebGL 1/2 中,可以通过 readPixels 同步方法获取纹理数据。但在 WebGPU 中,类似方法需要使用异步:

gpuBuffer
        .mapAsync(GPUMapMode.READ, srcByteOffset, size)
        .then()

https://doc.babylonjs.com/setup/support/webGPU/webGPUBreakingChanges#readpixels-is-now-asynchronous

但需要注意的是,拷贝 texture 到 buffer 时,bytesPerRow 是有要求的:
https://gpuweb.github.io/gpuweb/explainer/#example-020d533f

// Copy data from the texture to the buffer.
const encoder = device.createCommandEncoder();
encoder.copyTextureToBuffer(
    { texture },
    { buffer: readbackBuffer, bytesPerRow: textureWidth * 4 },
    [textureWidth, textureHeight],
);
device.queue.submit([encoder.finish()]);

必须是 256 的倍数,否则会报错:

bytesPerRow (4) is not a multiple of 256
@xiaoiver xiaoiver added the bug label Jun 29, 2023
@xiaoiver xiaoiver self-assigned this Jun 29, 2023
xiaoiver added a commit that referenced this issue Jul 6, 2023
* fix: make pick async to support impl in WebGPU (#1398)

* fix: skip loading Box2D if it's already existed #1393

* fix: update latest physx

* fix: support 2 kinds of clip z range #863

* fix: make pick async to support impl in WebGPU #1400

* fix: use async readpixels in webgl2

* fix: use premultiplied alpha in WebGL & WebGPU #1399

* fix: use createImageBitmap to create texture if possible #1401

* chore: add test case for ssr with g-webgl

* chore: adjust examples of performance block (#1402)

* chore: adjust examples of performance block

* fix: reset transform with keyword none

* chore: add ga4 key

* fix: createImageBitmap should account for error of SVG failure

* fix: avoid overriding defXY when parsing path (#1405)

* fix: avoid overriding defXY when parsing path #1404

* chore: commit changeset

* chore(release): bump version (#1403)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@xiaoiver
Copy link
Contributor Author

xiaoiver commented Jul 7, 2023

另外 https://www.w3.org/TR/webgpu/#dom-gpu-getpreferredcanvasformat 会返回 bgra8unorm
和常规的 rgba 排布并不一样,在 decode picking color 时需要注意

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant