r/wgpu • u/LelsersLasers • Sep 25 '22
r/wgpu • u/Mrfoogles5 • Feb 28 '22
News/Info Community-maintained wgpu learning resource
sotrh.github.ior/wgpu • u/jackny1232 • Mar 22 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (4)
4. Creare Point and Line Primitives: https://youtu.be/-QXj0UexUw0
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/LelsersLasers • Oct 17 '22
"I made this" Customizable 3D Cellular Automata on the web!
r/wgpu • u/jackny1232 • Mar 15 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (3)
3. Create a Colorful Triangle: https://youtu.be/hOojFOho_lI
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/jackny1232 • Mar 09 '22
Tutorial wgpu graphics programming Tutorial
Introduction to wgpu: https://youtu.be/i6WMfY-XTZE
Set up Development Environment: https://youtu.be/LULQtc5CUJ8
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/[deleted] • Jun 03 '23
Question Can someone please explain to me the whole buffer mapping thing and why there can be a write_buffer without mapping but not read_buffer?
Solved; this is now a guide (at least I've finally got a reasonably satisfactory answer from my research learning Vulkan) (see below.)
Question: Everything I find on this topic is just 'mapping lets the cpu access the memory but the gpu needs it to be unmapped'. I'd really like to know what's actually going on in the gpu under the hood when it comes to buffer mapping and what write_buffer does, why it doesn't need the buffer to be mapped, and why the same technique can't be applied to create a read_buffer. It'd be nice to just be able to not use a staging buffer when it comes to compute shaders.
My answer for others looking this up: To my understanding, graphics cards have memory that can be accessed outside of the graphics card and internal-only memory that can only be accessed by the GPU. A buffer being "mappable" means that it is accessible by the CPU. The problem with the publicly accessible memory is that it is to some apparently significant degree, slower than the internal memory. For that reason, some APIs (including WebGPU which WGPU is an implementation of) straight-up don't allow you to use public/"mappable" buffers for anything but memory transfers. Note though that WGPU provides an adapter feature, "MAPPABLE_PRIMARY_BUFFERS" that allows you to do just that but only works for certain backends (backends that don't suffer from a difference in speed between these two types of memory) without significant slowdowns.
This explains why buffers that have a mappable usage can only be used in specific ways; they're going to be stored in fundamentally different parts of memory (again, how this translates to hardware is where I'm still shaky).
The process of "mapping" means obtaining a pointer to the memory in VRAM to be used by the CPU. I'm going to be talking here about pointers like it's C or unsafe Rust so just have that be in your mind. Mapping doesn't do anything to the memory formatting wise; to my understanding, it just retrieves a pointer that can be used like any other pointer for performing accesses and memcpy's.
Well then, why not have the mappable buffers mapped all the time? Well in some APIs, you can! WGPU is an implementation of WebGPU though and WebGPU disallows this and WGPU doesn't include a feature to bypass it for the same reason! Because you can never quite tell what the GPU is doing and when, having a CPU pointer to memory the GPU is actively using is a dangerous game. WebGPU avoids nasty race conditions by taking a page out of Rust's book and sort of thinking of either the CPU or GPU having "ownership" of the buffer through mapping. When the memory is mapped and thus could be being accessed by the CPU, the GPU isn't allowed to use it and vica versa.
Learning Vulkan has been a huge help in learning what's actually going on in the GPU and what's just a formality by WebGPU and thus WGPU.
I hope someone now finds this useful!
r/wgpu • u/jackny1232 • Jun 08 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (11) - (15)
11. Sphere with Lighting: https://youtu.be/2bW_uCOKiKc
12. Torus with Lighting: https://youtu.be/CC3stU82iZg
13. Colormap: https://youtu.be/D0wrVy7lAcg
14. 3D Simple Surfaces: https://youtu.be/XfVeMrumi7o
15. 3D Sinc Surface: https://youtu.be/O7xIQudPKmA
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/pragmojo • Oct 10 '22
Discussion WebGPU is not a replacement for Vulkan (yet) | Hacker News
news.ycombinator.comr/wgpu • u/TobTobXX • Apr 06 '22
Question Why is the WGSL used by WGPU different from the spec?
All over the WGPU tutorials and guides, I see this kind of code:
[[stage(fragment)]]
fn main() -> [[location(0)]] vec4<f32> {
return vec4<f32>(0.1, 0.2, 0.3, 1.0);
}But the very first example of the WebGPU Shader Language spec looks quite a bit different:
@stage(fragment)
fn main() -> @location(0) vec4<f32> {
return vec4<f32>(0.1, 0.2, 0.3, 1.0);
}Especially the square brackets look irritating. Are the differences documented anywhere?
Thanks!
r/wgpu • u/Anjpressplay • Jun 02 '23
Question Should I learn Opengl first
I'm just starting my journey into graphics programming and I have been looking for an opportunity to learn rust. I wanted to know if its okay to begin with wgpu without much graphics programming experience or should I learn opengl first before diving into wgpu, since I do know a bit of c++. I only have an m1 macbook so I don't if opengl is a good graphics api to start with too.
r/wgpu • u/[deleted] • Dec 12 '22
WebGPU status in Chrome, Firefox, Safari (MacOS)
What's the best way of running WebGPU in the browser for Mac right now? I'm on a MacBook Pro @ Ventura / AMD Radeon Pro 5300. So far I've tested the following:
Chrome 108: in chrome://flags I enabled WebGPU Developer Features but in the console navigator.gpu remains undefined
Chrome Canary: downloaded the latest and set enable-unsafe-webgou in chrome://flags. This actually worked for a few days, now I can't get Canary started anymore (unresponsive). Reinstalled multiple times either works for a few sec then dies or doesn't start at all.
Firefox 107: after I set dom.webgpu.enabled to True in about:config navigator.gpu actually exists. However, requesting an adapter via adapter = await navigator.gpu.requestAdapter() yields Uncaught (in promise) DOMException: WebGPU is not enabled!. There's another flag gfx.webgpu.force-enabled don't know what it does but setting to true/false doesn't have an effect here.
Safari 16.1: Develop > Experimental features does not contain a WebGPU option, it doesn't seem to be supported in Safari 16.
EDIT: got Chrome Canary working again after cleaning the file system from all Canary files and reinstalling. Still keen on others' thoughts on best browser setup for dev
r/wgpu • u/jackny1232 • Jun 28 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (17) - (18)
Create parametric 3D surfaces:
17. Parametric 3D Surfaces: https://youtu.be/ODLGjzR9mWY
18. Parametric 3D Surface Examples: https://youtu.be/AjDU7eegt4g
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/jackny1232 • May 03 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (8), (9), (10)
8. Animate a 3D Cube: https://youtu.be/9SsjhrxH08o
9. Light Model: https://youtu.be/YF6VepGkUJs
10. Cube with Lighting: https://youtu.be/mPbsgFYb2z8
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/jackny1232 • Mar 29 '22
Tutorial Rust wgpu graphics programming tutorial: YouTube Video Series (5)
5. Create Triangle Primitives: https://youtu.be/TFVjMmSRDxs
Source code: https://github.com/jack1232/wgpu-step-by-step
r/wgpu • u/[deleted] • Sep 15 '22
What's the WGSL equivalent of GLSL's "in" keyword? I'd like to pass a mutable reference of a variable in one of my functions.
I have the following GLSL function which uses the in keyword
float fbm (in vec2 st) {
st *= 2.;
..
}How can I accomplish the same thing in WGSL? I'd like to pass uv as a mutable reference so I can modify it.
fn fbm2 (uv: vec2<f32>) -> vec3<f32> {
uv = uv * 2.;
..
}I tried searching DuckDuckGo and also looked at the spec documentation, but I'm honestly lost on how to accomplish this.
r/wgpu • u/Coompt_King • Feb 22 '22
Tutorial How to initialize a window with WGPU
r/wgpu • u/Coompt_King • Feb 21 '22
Question How do you get a window working in WGPU?
I've been trying to find a good tutorial on WGPU, but I can't find one, so I decided to go here.
r/wgpu • u/singerjonny • Jun 06 '23
Prospecting: wgpu app in visionOS / RealityKit
Welp, looks like we have another graphics platform to support.
What are the prospects for making multi-platform Rust+WGPU games/interactives, with support for Apple's RealityKit (which has actually been around for a while already) on the new Vision Pro's App Store?
Is anyone running wgpu graphics on iOS RealityKit yet? Can a Rust-wgpu app be (theoretically) applicable to Apple's walled garden?
Discussion Is your wgpu world left or right handed?
I just discovered (the hard way, of course) that wgpu's coordinate system is left handed by default. If you came from OpenGL, Vulkan, or another right handed system, do you build left handed worlds in wgpu, or do you multiply Z by -1 and stay with what you know?
DirectX is left handed, but Microsoft seems to be gradually migrating to right-handed systems.
I'm leaning toward staying right handed for my personal projects.
r/wgpu • u/pragmojo • Oct 18 '22
Discussion What is the outlook for WebGPU being available in most browsers?
WebGPU is super interesting, and even with its many limitations it would be a huge step up compared to WebGL in terms of what it would enable.
What is a reasonable outlook for when WebGPU will be a feature available in most browsers? I guess it is still quite early days, but are we talking about a year? Two years? Five years or even 10? What might the process look like from here.
r/wgpu • u/[deleted] • Sep 18 '22
Number of bindings in bind group descriptor (2) does not match the number of bindings defined in the bind group layout (1)
I'm working on making a compute shader that calculates the mandelbrot set. I've recently written a cellular automata simulator using compute shaders and I've got that working great. But I can't figure out this problem.
In my other project, I grab the bind group layout from the pipeline using
pipeline.get_bind_group_layout(0)and everything works great. However, in this new project, I'm getting an error saying that the number of bindings doesn't match the bindings defined in the layout.
My compute shader has the following bindings:
@group(0) @binding(0) var output_texture : texture_storage_2d<rgba8unorm, write>;
@group(0) @binding(1) var<uniform> m_params: MandelbrotParams;Why is my code telling me that my bind_group_layout only has 1 binding when there are clearly 2 bindings in my compute shader code?
Would it be better to provide by bind group layout explicitly instead of grabbing it from my compute pipeline? I tried that already and there was a different error about the bindings. It seems like my pipeline is somehow missing the second binding I've providing in the shader code.
Edit: I just tried to put my Mandelbrot params into their own BindGroup by using
@group(1) @binding(0) and got the following: "thread 'main' panicked at 'Error reflecting bind group 1: invalid group index 1', "
It seems like my second binding is being ignored for some reason regardless of what group and binding index I give it in the shader.
r/wgpu • u/[deleted] • Sep 04 '22
Updating Textures?
I'm working on making a cellular automata simulator using wgpu-rs. I've been looking at the documentation but I can't find a way to update texture data. The only way I've found to do this so far is by creating a new texture, and recreating my bind group with this new texture. Is there a way to update the existing texture data?
I was planning on firstly updating the texture data on the cpu, and eventually updating it using a compute shader once I figure it out. Basically I need to ping-pong 2 textures. One for reading the current state and one for writing the next state. Then I'll render the new texture to screen. On the next frame, I'll swap the textures and repeat this process. Are there any examples out there that use this ping pong technique either with compute shaders or even just on the cpu?
r/wgpu • u/[deleted] • Aug 21 '22