I believe https://book.amethyst.rs/stable/ sets up a great example.
We could have a nice description of what the API is, who is it for, what the components of the implementation are, and how to use them. In particular, these wiki pages can be moved into it entirely:
I'd love to take a stab at this!
A few questions in terms of content:
wgpu? Particularly, what should we recommend for:cgmath, ultraviolet, or one of the other 1,000 linear algebra libs)?shaderc, glsl-to-spirv)?Thank you taking this on!
glsl-to-spirv. In the future, we'll have WGSL shaders that are digested directly.I just want to link this bloody fantastic tutorial as well: https://sotrh.github.io/learn-wgpu
It was simple enough for me to follow and was up to date when I used it in early 2020.
Some 2c..
As an outside perspective, wgpu's technical offering is really second to none.
Where it lacks (although probably still the leader) is it's documentation and "marketing".
As a noob I'd really like to see a focus on improving the docs, tutorials and quality of examples over technical capabilities, I think this git book issue and the OpenGL support are really the only 2 things that turn people away at the moment.
Most tutorials leave the reader confused about threads and windows. Some of this is naturally confusing; you get an adapter from a window, a device from an adapter, and then you make a swap chain from the device for that window. But when you open a second window, what now? Same with a second thread. Hopefully we can save the new user some furious googling if we take the perspective that they will eventually want more than one window and more than one thread.
I don't think its yet a very important case, but a large number of machines also have more than one adapter, so bonus points to us if we can describe useful patterns for dealing with this, but I think its highly application specific. I think anything that's not a game will simply pick based on battery life or raw performance and only use one. Games of course will use both if they can get more fps. Maybe a simple example would be to do math on both adapters simultaneously.
@cormac-obrien What's your status on this issue? I'd be happy to run errands for you to help out.
@bzm3r There's been a significant amount of churn recently what with #478, so I took a break to allow that to settle. With 0.6 release coming up, I'm going to get back to work on it, but I'll let you know if I need any help!
I'm working on the section on shaders right now and hitting a bit of a snag. This will obviously be simplified quite a bit once WGSL is stable and wgpu consumes it directly, but until then, using glsl_to_spirv feels a bit...wonky? glsl_to_spirv::compile returns a File rather than a Vec<u32>, so an implementation is required to then read bytes from the resulting file, mapping every 4 bytes to a platform-endian (?) u32 with from_ne_bytes. This might be perfectionism on my part but this feels like a code smell.
Alternatives include:
build.rs to precompile to SPIR-V and then using include_spirv!. This strikes me as the sort of complexity that we don't want to add to the build process—it makes sense in a large application, but I wouldn't want to have to set up this kind of scaffolding just to get a triangle on the screen.shaderc, which doesn't seem like a good alternative as it also complicates the build process.naga instead. I'm not sure how stable the current interface is, or how recent the crates.io release is, but the interface seems much nicer than glsl_to_spirv's and it doesn't require non-Rust deps. Is naga meant to be user-facing?If we want to stick to the normal glsl_to_spirv method until WGSL is stabilized, I'm of course still happy to write the section that way.
afaik naga is not ready yet, and whatever we choose for now will be replaced by it eventually. I think the best compromise is to ask the user to manually run glslangValidator to compile the shader. (similar to the examples without the makefile) This will be easier to setup then shaderc and not as cursed as glsl_to_spirv.
If you do want to go the shaderc route I recommend this wrapper over shaderc instead https://github.com/Ralith/vk-shader-macros
piet-gpu used a build.ninja file to slightly smoothen glslangValidator usage: https://github.com/linebender/piet-gpu/blob/master/piet-gpu/shader/build.ninja
Most helpful comment
I'd love to take a stab at this!