Live data from Hacker News

WebGPU – All of the cores, none of the canvas

surma.dev

41–50 of 54 posts

Re: WebGPU – All of the cores, none of the canvas

#41
post #15

My disappointment with WebGPU has been limited data type support. I wanted to write some compute stuff with it, but the limitation of not supporting a lot of integer sizes made it undesirable. Does anyone know if the spec is likely to be revised to add more support over time?

As an example, INT8 support in WebGPU would enable running quantized models, allowing larger LLMs to run locally in the browser.

See Limitations section here: https://fleetwood.dev/posts/running-llms-in-the-browser

Re: WebGPU – All of the cores, none of the canvas

#42

Following the article, you build a simple 2D physic simulation (only for balls). Did by chance anyone expand on that to include boxes, or know of a different approach to build a physic engine in WebGPU? I experiemented a bit with it and implemented raycasting, but it is really not trivial getting the data in and out. (Limiting it to boxes and circles would satisfy my use case and seems doable, but getting polygons wo…

> But the back and forth can really make your framerates drop - so to make it worth it, most of the simulation data has to remain on the gpu and you only put small chanks of data that have changed in and out. And ideally render it all on the gpu in the next step.

In my (limited, cuda so not webgpu) experience, memory transfers are fast and computation is fast, the thing that is slow is memory transfer _latency_. Doing a memory transfer takes a long time, but if you're doing one anyway, might as well transfer the world.

Is my recollection correct?

Re: WebGPU – All of the cores, none of the canvas

#43
post #6

I'm a graphics programmer who has quite a bit of experience with WebGL, and (disclaimer) I've also contributed to the WebGPU spec. > Quite honestly, I have no idea how ThreeJS manages to be so robust, but it does manage somehow. > To be clear, me not being able to internalize WebGL is probably a shortcoming of my own. People smarter than me have been able to build amazing stuff with WebGL (and OpenGL outside the web)…

> (mind putting a publish date on these articles?)

Off-topic, but please PLEASE put the publish date on your (technical) articles. When I'm looking for documentation and open an article without a publish date, I almost always discard it immediately. I'm not going to risk wasting my time learning outdated knowledge.

Re: WebGPU – All of the cores, none of the canvas

#44

Will there be better typography in WEbGPU?

It won't live in WebGPU itself, but I do expect to start to see more third-party libraries for text. There’s already wgpu_glyph (https://github.com/hecrj/wgpu_glyph/tree/master) which uses a glyph atlas (CPU-rendered sprite map of characters), but techniques for signed-distance field fonts have come a long way too.

Re: WebGPU – All of the cores, none of the canvas

#45

Following the article, you build a simple 2D physic simulation (only for balls). Did by chance anyone expand on that to include boxes, or know of a different approach to build a physic engine in WebGPU? I experiemented a bit with it and implemented raycasting, but it is really not trivial getting the data in and out. (Limiting it to boxes and circles would satisfy my use case and seems doable, but getting polygons wo…

> But the back and forth can really make your framerates drop - so to make it worth it, most of the simulation data has to remain on the gpu and you only put small chanks of data that have changed in and out. And ideally render it all on the gpu in the next step. In my (limited, cuda so not webgpu) experience, memory transfers are fast and computation is fast, the thing that is slow is memory transfer _latency_. Doin…

"Doing a memory transfer takes a long time, but if you're doing one anyway, might as well transfer the world."

Not in my experience and experiments. But I am pretty much a beginner with WebGPU and might be missing a lot. Otherwise yes, latency is the big issue as well. Sometimes all is well, sometimes nothing happens for 20+ms.

Re: WebGPU – All of the cores, none of the canvas

#46
Good article, but couple remarks.

> most hardware seemingly just runs workgroups in a serial order

The hardware runs them in parallel, but it’s complicated.

The nVidia GPU I’m currently using has 32-wide SIMD, which means groups of 32 threads run in parallel, exactly in lockstep. Different GPU APIs call such group of threads wavefronts or warps. Each core (my particular GPU has 28 of these) can run 4 of such wavefronts = 128 threads in parallel.

When a shader has more than 128 threads, or when the GPU core is multi-tasking running multiple workgroups of the same or different shaders, different wavefronts will run sequentially. And one more thing, the entire workgroup runs within a single GPU core, even when the shader pushes workgroup size to the limit with 1024 threads per workgroup.

“Sequentially” doesn’t mean the order of execution is fixed, or predefined, or fair. Instead, the GPU is doing rather complicated scheduling trying to hide latency of computations and memory transactions. While some wavefront is waiting for data to arrive from memory, instead of sleeping the GPU will typically switch to another active wavefront. Many modern CPUs do that too because hyperthreading, but CPUs only have 2 threads per core, they are visible to OS as two distinct virtual cores. For GPUs the number is way higher, only limited by amount of in-core memory, and amount of that memory required by the running shaders.

> as the difference between running a shader with @workgroup_size(64) or @workgroup_size(8, 8) is negligible. So this concept is considered somewhat legacy.

I think it’s convenience, not legacy. When a shader handles 2D data like a matrix or an image, it’s natural to have 2D workgroup sizes like 8x8. Similarly, when a shader processes 3D data like a field defined on elements or nodes of 3D Cartesian grid, it can be slightly easier to write compute shaders with workgroups of 4x4x4 or 8x8x8 threads.

Re: WebGPU – All of the cores, none of the canvas

#47
post #6

I'm a graphics programmer who has quite a bit of experience with WebGL, and (disclaimer) I've also contributed to the WebGPU spec. > Quite honestly, I have no idea how ThreeJS manages to be so robust, but it does manage somehow. > To be clear, me not being able to internalize WebGL is probably a shortcoming of my own. People smarter than me have been able to build amazing stuff with WebGL (and OpenGL outside the web)…

> WebGL (and OpenGL) are awful APIs that can give you a very backwards impression about how to use them, and are very state-sensitive. It is not your fault for getting stuck here. Basically one of the first things everybody does is build a sane layer on top of OpenGL; if you are using gl.enable(gl.BLEND) in your core render loop, you have basically already failed.

I really don't understand this. Why the need for relentless abstraction? Just learn the ways that OpenGL is weird and use it anyway. Most people who work on these things will need to understand OpenGL anyway.

Then again, I guess it depends what you mean by "everybody" when you say "everybody does". Clearly, you are using hyperbolae here, but who do you actually mean by everybody? For example, if everybody did it then how did some people reach your failure case? Unclear and bizarre comment. If you say "everybody" you must at least attempt to clarify who is meant, else it is a contentless comment

Re: WebGPU – All of the cores, none of the canvas

#48
post #6

I'm a graphics programmer who has quite a bit of experience with WebGL, and (disclaimer) I've also contributed to the WebGPU spec. > Quite honestly, I have no idea how ThreeJS manages to be so robust, but it does manage somehow. > To be clear, me not being able to internalize WebGL is probably a shortcoming of my own. People smarter than me have been able to build amazing stuff with WebGL (and OpenGL outside the web)…

> (mind putting a publish date on these articles?) Off-topic, but please PLEASE put the publish date on your (technical) articles. When I'm looking for documentation and open an article without a publish date, I almost always discard it immediately. I'm not going to risk wasting my time learning outdated knowledge.

This article does have a publish date, it's just easy to miss in the top right corner with a bit of a low contrast ratio (in dark mode at least)

The article is from 2022-03-08

Re: WebGPU – All of the cores, none of the canvas

#49

> The most popular of the next-gen GPU APIs are Vulkan by the Khronos Group, Metal by Apple and DirectX 12 by Microsoft. ... (WebGPU) introduces its own abstractions and doesn’t directly mirror any of these native APIs. Huh. I was wondering about that. Until now I just figured every "Web*" thing was browsers exposing (to JS alone) something that they already compiled in: - WebRTC is ffmpeg - Canvas is Skia - WebGL is…

> Canvas is Skia

Canvas is Apple Quartz. They implemented it in WebKit for their dashboard widgets (which were implemented what we called "HTML5" back then) which leaked into Safari, and it turned out to be so useful that it got adopted in other browsers as a WHATWG standard.

Re: WebGPU – All of the cores, none of the canvas

#50
post #11
post #6

I'm a graphics programmer who has quite a bit of experience with WebGL, and (disclaimer) I've also contributed to the WebGPU spec. > Quite honestly, I have no idea how ThreeJS manages to be so robust, but it does manage somehow. > To be clear, me not being able to internalize WebGL is probably a shortcoming of my own. People smarter than me have been able to build amazing stuff with WebGL (and OpenGL outside the web)…

That is what I hate on Khronos APIs, it is almost a rite of passage into adulthood to create our own mini-engine on top of their APIs to make them usable. I already have my toolbox, but that doesn't mean I am fine with them being like that.

I think OpenGL and Vulkan fail at opposite reasons for this. OpenGL is a giant ball of yarn state machine that's way too complicated to drive and doesn't do what you want. Vulkan requires spelling everything out in excruciating detail (though recent things like VK_EXT_dynamic_rendering help clean up the mess a lot).

I don't think there's a common design principle there of trying to be behind mini-engines, they just overcompensated in the other direction when designing Vulkan. D3D12 is a bit similar.

There are many possible ways to wrap these APIs for your own use case, and nobody will ever decide how those wrappers should work (e.g. automatic resource tracking makes bindless difficult, and multi-thread command recording makes automatic resource tracking difficult, but RT basically requires bindless, so, pick which feature to drop). Metal shows one very strong direction. WebGPU shows another good direction, but they all take some very deep compromises here.

Post reply on HN