WebGPU best practices with setPipeline and optimization

611 Views Asked by At

I'm learning WebGPU for the first time and, in the tutorials I'm following, I see that setPipeline is called on each rendering pass. I'm wondering if there's a performance hit if the pipeline is changed between passes? Most of the tutorials I'm reading use the same pipeline for every pass and just change the data going to it via a writeBuffer, but I don't know if that's intentional. The only thing I've read about pipeline optimization is from this tutorial

The configuration of the components of this pipeline (e.g., the shaders, vertex state, render output state, etc.) are fixed, allowing the GPU to better optimize rendering for the pipeline.

That'd lead me to believe that the pipeline shouldn't be changed between passes, but I haven't seen anything stating that explicitly. Thanks in advance for any help!

1

There are 1 best solutions below

0
On BEST ANSWER

It's fairly common for applications to use different shaders for different objects in a single render (eg: see this question). From an optimisation perspective, you'd want to set a pipeline and render all objects that use that pipeline, then set another pipeline and render all objects that use that pipeline, and so on. You'd probably want to look into instances to minimize the number of draw calls too.