Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Reading from tess.verts

Open slipher opened this issue 1 year ago • 2 comments

Some renderer functions attempt to read back a surface's polygons from tess.verts. There are 3 possibilities, none of them good:

  • The surface uses a static VBO with multidraw. tess.numVerts will be 0: there is nothing for it to read.
  • The surface uses a static VBO with a single data range. tess.numVerts will be nonzero so the function will think there is data there. But really it is random data left over from whichever surfaces used the buffer last.
  • The surface does not use a static VBO; it actually writes data to tess.verts. The function may at least work correctly in this case. But reading data from this GPU-mapped memory may cause poor performance as in #849.

I haven't attempted to search for all functions like this, but happened to notice the following ones:

  • SurfIsOffscreen PortalOffScreenOrOutOfRange
  • AutospriteDeform
  • Autosprite2Deform

Note that some "autosprite" code is already known to be broken (#730). We might detect more suspicious functions by mapping the buffer as write-only, or setting it to null when a static VBO is active.

slipher avatar Jun 21 '24 07:06 slipher

Another culprit: R_GetPortalOrientations. That one also has a more serious problem: #1216.

slipher avatar Jul 06 '24 18:07 slipher

For historical interest, some previous examples were fixed in f870d9f392f512ad908a71156f9708944ceabaff :)

slipher avatar Jul 16 '24 01:07 slipher

#1444 only fixes the portal case, not the autosprite case.

slipher avatar Nov 23 '24 22:11 slipher

#1444 only fixes the portal case, not the autosprite case.

Doesn't autosprite only write to it rather than read from it?

VReaperV avatar Nov 25 '24 12:11 VReaperV

Autosprite is read-modify-write.

slipher avatar Nov 25 '24 21:11 slipher

I thought it only reads from tess.vertsBuffer, which is supposedly CPU-side?

VReaperV avatar Nov 25 '24 21:11 VReaperV

Oh right, I changed it to use the CPU buffer so that performance problem should no longer happen. It's kinda hacky but good enough to close this I guess.

slipher avatar Nov 25 '24 21:11 slipher