tweak(scorch): Increase scorch buffers to 16-bit limit - #3186
tweak(scorch): Increase scorch buffers to 16-bit limit#3186stephanmeesters wants to merge 3 commits into
Conversation
PR Summary by QodoIncrease scorch buffers to 16-bit max and preflight per-scorch capacity
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Overflow bypasses buffer guard
|
| MAX_SCORCH_VERTEX = 8194, | ||
| MAX_SCORCH_INDEX = 6 * 8194, | ||
| MAX_SCORCH_VERTEX = 65535 / 2, | ||
| MAX_SCORCH_INDEX = 65535, |
There was a problem hiding this comment.
Can you explain why the ratio is 2 to 1 ?
There was a problem hiding this comment.
The precise ratio is a maximum of 22844 vertices needed for 65535 indices (more indices than vertices because of vertex sharing), and 32768 is the nearest power of two up from 22844.
Actually 65535/2 is wrong and will be off by one due to rounding down, will correct that.
There was a problem hiding this comment.
I would have expected 3 indices for 1 vertex.
There was a problem hiding this comment.
It depends on the size of the scorch, for large scorches an inside vertex of the mesh is typically shared by 6 surrounding triangles and we get an average ratio of 6:1, while for small scorches the boundaries become more important where we have less vertex sharing (max 2 triangles in corners, max 4 at edges) and we see the ratio shrinking towards 3:1. The 32768 vertex limit gives a safe value with some margin.
|
|
||
| const Int vertexCountX = maxX - minX; | ||
| const Int vertexCountY = maxY - minY; | ||
| if (vertexCountX <= 0 || vertexCountY <= 0) |
There was a problem hiding this comment.
Under what conditions does this hit? Maybe it should be an assert instead?
There was a problem hiding this comment.
In ordinary gameplay I would not expect scorches outside the map, but it can happen in World Builder. This is just an early return, without it it would run through the for loops and end up writing nothing to the buffers.
There was a problem hiding this comment.
Maybe return enum values to make the return meaning more explicit?
Merge by rebase
This PR upgrades the maximum number of scorches on screen (see table). This is done by bumping the index/vertex buffers capacity to the 16-bit limit. Since the index buffer is the bottleneck, the vertex buffer was resized to the nearest power of two that can safely hold all needed vertices.
Additionally, a fix was added to make scorch writes "atomic" by determining the number of vertices/indices it requires beforehand, otherwise we could see scorches being partially rendered, but this problem only appeared after increasing the buffer capacity.
Performance impact is very small:
W3DScorch::updateScorchesmeasures well below 0.1ms with a filled buffer.W3DScorch::updateScorchesonly runs when the scorches have changed, or if the terrain/lighting has changed.Max number of scorches rendered, per scorch radius, before and after
Note: 500 is the current cap on the number of scorches.
Increasing capacity further
This PR applied a simple way to increase the capacity. Going for a higher capacity will need 32-bit buffers, or a different approach. To make "unlimited" scorches possible we could in the future switch to something like a baked terrain texture.
Todo