Re: WebGPU polyfill using WebGL2 - would it be feasible and/or make sense?

My suggestion would be to write a small portability layer that's mostly the
WebGPU API, but can be backed by WebGL 2. I have an example of such a
portability layer here:

https://github.com/magcius/noclip.website/blob/master/src/gfx/platform/GfxPlatform.ts

It is mostly inspired by an early draft of WebGPU, with some changes to
accommodate WebGL 2's unfortunate design choices in a few places.

* Rather than bind input buffers directly on the render pass, you first
need to create a GfxInputState, which is equivalent to GL's
combined-layout-and-buffers VAO. The more sane separate attribute
specification was only added in GLES 3.1 through the inclusion of
ARB_separate_vertex_binding.
* The binding model is drastically simplified. You simply specify that you
want N texture/sampler pairs, and M uniform buffers per "binding group",
and the layout is linearly allocated inside them.
* MRT is not supported. Shipping WebGL 2 implementations in browser haven't
bothered to add support for WEBGL_EXT_draw_buffers_indexed, so I haven't
bothered to try either.
* I have not explored performance on mobile. Mobile is not a target for my
current project, where scenes are rather complicated, so I haven't looked.
* Some choices are made by the backend about render target formats and such.
* The shader infrastructure is all GLSL-based, and quite old. I reworked
this in another personal API but haven't gotten around to it yet.

The big important thing I would stress is that WebGPU and GfxPlatform are
meant as platform layers. You mostly should not be interacting with them in
your rendering code. I would really recommend writing a renderer on *top*
of the platform layer, in both cases. Something that thinks about draw
calls at an abstract high level and coordinates with the platform layer to
schedule and submit calls. I have an example of one such approach here:
https://github.com/magcius/noclip.website/blob/master/src/gfx/render/GfxRenderer.ts
.
Which has its own tradeoffs.

I am happy to donate this layer to another project or try to spin it up
into its own project with documentation if there is sufficient interest.

On Thu, Nov 21, 2019 at 8:59 AM Eamon O'Tuathail <eamon.otuathail@gmail.com>
wrote:

> WebGPU and WebGL2 do not provide the exact same feature set, but there is
> a good bit of overlap. For early adopter web application developers eager
> to get started with WebGPU now, would a polyfill of a subset of WebGPU
> features implemented using WebGL2 be feasible and/or make sense?
>
> WebGL2 is widely available today in production web browsers:
>   https://caniuse.com/#feat=webgl2
> and WebGPU, though progressing nicely, still has a long way to go before
> that.
>
> So what are the options for web application developers who want to use
> some parts of WebGPU in production code today? A polyfill would seem the
> best. A polyfill will not give the same level of performance as a native
> WebGPU implementation or the full feature set, but may be sufficient for
> certain deployment scenarios - such as code samples in training courses,
> product demos, proof of concept projects. etc.. It would not be suitable
> for heavy-duty gaming or other intensive 3D rendering workloads - that is
> accepted.
>


-- 
  Jasper

Received on Thursday, 21 November 2019 17:39:39 UTC