6 ms·
Some context: browser vendors are working on a successor to WebGL, and there's been a debate over what shading language to use. A text based language would be
by throwaway34241 7y ago
Some context: browser vendors are working on a successor to WebGL, and there's been a debate over what shading language to use.
A text based language would be easier for beginners (since they wouldn't need to install a separate shader compiler) and would avoid sites that need dynamic shaders having to download and run a shader compiler in the browser.
Using SPIR-V bytecode would benefit from a large amount of work put into an existing standard and an open source compiler ecosystem that many companies are already using.
It looks like a decision has been made to accept a text based language, but one that is defined based on SPIR-V semantics and is easily convertible back and forth from SPIR-V. This seems like a great trade off since if it works out it should have the main advantages of both approaches.
- pcwalton 7y ago> A text based language would be easier for beginners (since they wouldn't need to install a separate shader compiler) and would avoid sites that need dynamic shaders having to download and run a shader compiler in the browser. That is more or less the official rationale, but it's pretty clear that the real reason is that Apple is organizationally opposed to SPIR-V (and Khronos generally). This is a tough needle to thread, so I'm glad forward progress is being made.
- throwaway34241 7y agoRegardless of Apple’s motivations those still are real benefits, I think at least one major WebGL framework uses dynamic shader generation and was looking at going the bundled-shader-compiler route. Hopefully this approach cuts back on the projects that find it necessary to do that and encourages faster adoption from WebGL.
- kevingadd 7y agoIf you're willing to do dynamic shader generation as text, you can generate shader bytecode. The real question is which of the two options produces more performant shaders and faster compile times, since naively-generated shader bytecode isn't being optimized like your text is. If you care about compile times text-based can be a lot worse (this matters for the Dolphin emulator, for example)
- throwaway34241 7y agoThat’s true, even if the semantics are the same (and parsing time isn’t a big factor) the assumptions for what optimizations have been applied to bytecode might be different. I remember seeing in one of the meeting notes that they didn’t expect browsers to end up making assumptions about the optimization level of the SPIR-V they ingest anyway but I don’t remember the specific rationale for that. There’s of course also the time for the SPIR-V -> gpu native step. It would be nice if they could just cache that and skip the whole process most of the time.
- kvark 7y agoThat is correct, in theory, but there is a large gap between theory and practice. How practical would it be for, say Three.JS to generate shader bytecode? Would it need to depend on a sophisticated WASM module that allows to build such bytecode? Who is going to build that? Google has spent a lot of effort trying to answer these questions, and they got close, but in the end the text-based solution prevailed. In part, because it was easy to agree on for all parties.
- Jasper_ 7y agoDo you not expect GLSL -> WGSL compilers in actual practice? I don't think anybody using Three.JS today would switch to writing WGSL unless they could also ingest it on WebGL.
- kvark 7y agoIn one of the futures, our shader translation infrastructure will support GLSL input and produce WGSL output :)
- jfkebwjsbx 7y agoIndeed. A text-based language makes no sense in 2020. WASM already took the approach of going binary-first.
- antoineMoPa 7y agoIf you want live-tweakable or generated webgpu shaders, which will be useful in many applications text based is much better as no complex tooling is required.
- rubber_duck 7y agoUseful to what applications ? Even writing modern JS requires a compiler stack, adding a shading language would be a matter of writing a webpack loader.
- antoineMoPa 7y agoAs an example, ShaderToy (and ShaderGif which I built) compile shaders directly in the browser.
- jfkebwjsbx 7y agoAs they have already told you, shaders being in binary or text form is orthogonal to making a tool like ShaderToy. However, binary form is way more compact for transmission, storage and performance. Almost nobody will use the text form except developers.
- xenadu02 7y agoI strongly favor sticking to DRM-free text-based formats for the web. I remember learning a lot just from looking at the HTML and JS sources from web pages. It's been a great boon for the web up until now. Besides lots of apps already ship shaders as text. They get dynamically compiled and cached, just like JS does. Being text-based hasn't stopped JS from greatly improving performance. Khronos sat on their hands for years and only moved after Apple shipped Metal and AMD dumped Mantle in their laps (I'll note that Metal came first). SPIR-V is not the be-all end-all of shader programming. Personally I don't believe we should accept some lowest-common-denominator that puts the future of GPU development in the hands of an organization with the track record Khronos has wrt managing OpenGL. That goes double for the future of WebGPU. However I recognize those are just personal opinions and reasonable people may disagree. To those offering opinions here: If you've never written a renderer or shader can I suggest you write a toy project using both then see if you still have the same opinion?
- pcwalton 7y agoThe problem with the view-source argument is that source is often minified these days, so you need a decompiler of some sort to go from the bits on the wire to something human-readable no matter what. A pretty-printer can sometimes be simpler than an IR decompiler, but often not really.
- tylerchilds 7y agoI purposefully don't minify the source on my personal website, so people can still learn from inspecting it, if they'd like to.
- Athas 7y agoIs there really such a great need to make the lowest level shader API more accessible to beginners? You can always build things on top that make a low-level API more friendly, but you can never build something below the lowest available level (short of inventing a new standard). What kind of beginners are these that want to do low-level shader programming, but without any tooling? Don't web programmers already accept the use of heavyweight build tools even for their plan old ordinary Javascript? My enthusiasm for seeing yet another GPU language is very restricted. I simply cannot see the rational arguments in favour of this design. We were so close to having a standard IR for this stuff.
- throwaway34241 7y agoI think the goal here is for the semantics to basically be SPIR-V, and for people using SPIR-V toolchains to be able to expect WebGPU platforms with a Vulkan backend to execute basically the same SPIR-V after the conversions to/from text.
- interartdev 7y agoKnowing Vulkan, WebGL, and OpenGL and working a bit with some of those technologies while hobbying the others, WebGPU will take about a decade to be fully adopted, and even then, only by a fraction of companies that are willing to spend manpower resources into developing something interfacing low level graphics directly.
- username90 7y agoWebGPU is important for game engines, currently it is missing a lot of features so you can't write the shaders you want.
- moron4hire 7y agoThat's because there is no rational reason. The reason this is at it all an issue is because Apple put their foot down and flat out refused to implement SPIR-V.
- 7y ago
- tenaciousDaniel 7y ago> browser vendors are working on a successor to WebGL Interesting, what's the successor? I haven't heard of this.
- pjmlp 7y agoWebGPU https://webkit.org/blog/9528/webgpu-and-wsl-in-safari/ https://webkit.org/blog/9528/webgpu-and-wsl-in-safari/ https://developers.google.com/web/updates/2019/08/get-started-with-gpu-compute-on-the-web https://developers.google.com/web/updates/2019/08/get-starte... https://doc.babylonjs.com/extensions/webgpu https://doc.babylonjs.com/extensions/webgpu Basically, the Web version of Metal, DirectX12, Vulkan, LibGNM, NVN.
- rolltiide 7y ago> Some context: browser vendors are working on a successor to WebGL What's wrong with WebGL?