Wgpu Buffer vs Texture?

I’m learning wgpu and graphics/GPU compute for the first time but I’ve yet to see an explanation of what the difference is between a buffer and a texture. As far as I can tell they’re both used for storing data.

A buffer is a generic memory allocation which can contain whatever kind of data layout you want. You can even put multiple unrelated things in one buffer.

A texture is specifically a multi-dimensional array; it may be laid out in a way which supports efficient 2D/3D lookups on the hardware, and the GPU has hardware for efficiently "sampling" it (interpolating between nearby texels; mipmapping).

In principle you can use a storage buffer (if supported) in place of a texture, but you lose the benefit of any specialized hardware or instructions that the GPU has for texturing-like applications.

2 Likes