You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Which corner is the origin of a copyExternalImageToTexture? #2110
@shaoboyan and I were discussing this, and we realized it's unspecified which corner of an external image is the origin (0,0) when doing a copyExternalImageToTexture operation. This is ambiguous in particular because inside WebGL, the origin of the canvas is the bottom-left.
I'm strongly inclined to say it is (at least by default) the top-left corner of the source image/canvas. However we could have an exception for WebGL that puts it at the bottom-left to match WebGL's own coordinate space.
Should we make it configurable? Prior art does so - though primarily due to the fact that WebGL is inverted relative to everything else.
We should ensure we have a fastpath that can reasonably do a resource->resource copy from WebGL without requiring a flip. If this cannot simply be the default, then we should add configuration options to allow it.
Generally speaking anything that accepts a HTMLCanvasElement should consider that canvas's coordinates to be y-down (with 0,0 at top left). (and similar for ImageBitmap)
The imageOrientation in ImageBitmapOptions was really a concession to WebGL / OpenGL, which defines the lower-left corner of textures as the origin. Note that if the flipY option is used, then the ImageBitmap will be vertically flipped when drawn normally to a 2D canvas context. This parameter was added to give web apps the highest performance when decoding images (JPEGs, PNGs, etc.) to ImageBitmaps and uploading to WebGL textures, since the web app knows how the ImageBitmap is intended to be consumed.
Considering uploading WebGL-rendered canvases to WebGPU textures: since a copy is involved, and it will be done on the GPU, it seems fine to me to just internalize the needed Y-flip and not expose this detail to web applications. The only other reason control over the vertical flip would be needed is for ImageBitmaps, and it doesn't seem necessary to me to support that; the web app should just not flip its ImageBitmaps when it intends to import them to WebGPU. All other external image sources on the web use an upper-left origin, like WebGPU's textures, so no vertical flip is needed.
since a copy is involved, and it will be done on the GPU, it seems fine to me to just internalize the needed Y-flip
I don't know much about how these flips are implemented usually. It's free to flip in a fullscreen quad (and probably in a blit), but I think using copy commands it may require one copy per row which could be expensive.
There's one other reason I could think of needing a flip in webgl->webgpu, and that's if you have some interop between them. In principle the app could just sample the texture flipped, or output flipped data from WebGL, but it could be difficult in some apps - e.g. if they followed it with a copyTextureToBuffer then they couldn't flip in sampling.
Any interop between WebGL and WebGPU textures (specifically, to bring WebGL textures more directly into WebGPU) would require at least one copy on basically all platforms, because WebGL textures aren't allocated specially - they're not backed by surfaces which would enable WebGPU to sample them directly. The y-flip could be done during that copy, hiding the semantic differences between the APIs.
Activity
kainino0x commentedon Sep 15, 2021
cc @shaoboyan
kdashg commentedon Sep 21, 2021
We should ensure we have a fastpath that can reasonably do a resource->resource copy from WebGL without requiring a flip. If this cannot simply be the default, then we should add configuration options to allow it.
Generally speaking anything that accepts a HTMLCanvasElement should consider that canvas's coordinates to be y-down (with 0,0 at top left). (and similar for ImageBitmap)
kenrussell commentedon Oct 1, 2021
The
imageOrientationinImageBitmapOptionswas really a concession to WebGL / OpenGL, which defines the lower-left corner of textures as the origin. Note that if theflipYoption is used, then theImageBitmapwill be vertically flipped when drawn normally to a 2D canvas context. This parameter was added to give web apps the highest performance when decoding images (JPEGs, PNGs, etc.) toImageBitmaps and uploading to WebGL textures, since the web app knows how theImageBitmapis intended to be consumed.Considering uploading WebGL-rendered canvases to WebGPU textures: since a copy is involved, and it will be done on the GPU, it seems fine to me to just internalize the needed Y-flip and not expose this detail to web applications. The only other reason control over the vertical flip would be needed is for
ImageBitmaps, and it doesn't seem necessary to me to support that; the web app should just not flip itsImageBitmaps when it intends to import them to WebGPU. All other external image sources on the web use an upper-left origin, like WebGPU's textures, so no vertical flip is needed.kainino0x commentedon Oct 1, 2021
I don't know much about how these flips are implemented usually. It's free to flip in a fullscreen quad (and probably in a blit), but I think using copy commands it may require one copy per row which could be expensive.
There's one other reason I could think of needing a flip in webgl->webgpu, and that's if you have some interop between them. In principle the app could just sample the texture flipped, or output flipped data from WebGL, but it could be difficult in some apps - e.g. if they followed it with a copyTextureToBuffer then they couldn't flip in sampling.
kenrussell commentedon Oct 1, 2021
Any interop between WebGL and WebGPU textures (specifically, to bring WebGL textures more directly into WebGPU) would require at least one copy on basically all platforms, because WebGL textures aren't allocated specially - they're not backed by surfaces which would enable WebGPU to sample them directly. The y-flip could be done during that copy, hiding the semantic differences between the APIs.
kainino0x commentedon Oct 1, 2021
Ah, I'm thinking only about WebGL canvases. I don't think we're considering any interop with WebGLTexture.
kainino0x commentedon Oct 4, 2021
Meeting resolution: No need to do this right now, cost to flip from webgl canvases (and opengl backed resources) should be minimal.
CopyExternalImageToTexture should always copy source from top-left or…
Unflip Y of copyExternalImageToTexture from WebGL canvas
CopyExternalImageToTexture should always copy source from top-left or…