<p>I am new to graphics programming and I'm trying to create an efficient 2D tilemap renderer (using rust and wgpu (webgpu)).</p>
<p><strong>My current implementation</strong></p>
<p>My current implementation consists of:</p>
<ol>
<li>A Rust-Vec (contains all tiles needed for rendering in a normal buffer)</li>
<li>A Vertex Buffer (contains 4 Vertices, describing a quad)</li>
<li>An Index Buffer (contains Indices to define the said quad)</li>
<li>An Instance Buffer (basically contains ALL the tile data (currently only world positions (2 u32 Integers))</li>
<li>A Uniform Buffer (contains current camera position (x, y, zoom))</li>
</ol>
<p>The 1. buffer (Rust-Vec) is updated and copied to the Instance Buffer every new frame (both buffers are fully replaced every frame). In order to improve performance a bit, the world is split up into chunks. Although that does not affect the rendering process after the needed tiles are loaded into the 1. buffer.</p>
<p>The instance data (tile coordinates) is translated to the relative normal positions in the vertex shader.</p>
<p>My project currently does not support textures etc.</p>
<p><strong>Problem</strong></p>
<p>When zooming out far enough, but not unreasonably far, the frame time starts to increase immensely. Looking at a flamegraph I have found the part of code that takes the longest is updating the 1. Vector and copying it to the instance buffer. Sadly I have not come up with a more efficient solution to rendering large amounts of 2D tiles.</p>
<p><strong>Question</strong></p>
<p>What concepts and ideas can I make use of to increase the performance of my project? Is my current solution inherently flawed, or is it somewhat acceptable?</p>

CC BY-SA 4.0
2022-05-24T20:26:55.033Z
How exactly are you drawing the tiles: one by one, or using batched rendering, or maybe instanced rendering? How many tiles do you have rendered when performance becomes an issue?
lisyarus
CC BY-SA 4.0
2022-05-25T10:13:39.050Z
The vertex and index buffer only describe a basic quad. I only reupload the whole instance buffer and render it that way (draw_instanced in wgpu). Performance becomes an issue at around 3604480 tiles.
Q4LEX
<performance><2d><2d-graphics><optimisation>
Good way of implementing an efficient tilemap renderer
Q4LEX
# Good way of implementing an efficient tilemap renderer

(Asked by: username_0 on 2022-05-24)

I am new to graphics programming and I'm trying to create an efficient 2D tilemap renderer (using rust and wgpu (webgpu)).

**My current implementation**

My current implementation consists of:

1. A Rust-Vec (contains all tiles needed for rendering in a normal buffer)
2. A Vertex Buffer (contains 4 Vertices, describing a quad)
3. An Index Buffer (contains Indices to define the said quad)
4. An Instance Buffer (basically contains ALL the tile data (currently only world positions (2 u32 Integers))
5. A Uniform Buffer (contains current camera position (x, y, zoom))

The 1. buffer (Rust-Vec) is updated and copied to the Instance Buffer every new frame (both buffers are fully replaced every frame). In order to improve performance a bit, the world is split up into chunks. Although that does not affect the rendering process after the needed tiles are loaded into the 1. buffer.

The instance data (tile coordinates) is translated to the relative normal positions in the vertex shader.

My project currently does not support textures etc.

**Problem**

When zooming out far enough, but not unreasonably far, the frame time starts to increase immensely. Looking at a flamegraph I have found the part of code that takes the longest is updating the 1. Vector and copying it to the instance buffer. Sadly I have not come up with a more efficient solution to rendering large amounts of 2D tiles.

**Question**

What concepts and ideas can I make use of to increase the performance of my project? Is my current solution inherently flawed, or is it somewhat acceptable?

**Tags:** performance, 2d, 2d-graphics, optimisation

> **Comments:**
> **username_1**: How exactly are you drawing the tiles: one by one, or using batched rendering, or maybe instanced rendering? How many tiles do you have rendered when performance becomes an issue?  
> **username_0**: The vertex and index buffer only describe a basic quad. I only reupload the whole instance buffer and render it that way (draw_instanced in wgpu). Performance becomes an issue at around 3604480 tiles.  

---

## 0 answers

