Skip to content

Clean up depth and stencil buffers #7325

@BMagnu

Description

@BMagnu

FSO keeps a whole bunch of partially redundant or unused render buffers, which should be tidied up to not waste storage and bandwidth.
Notably we have:

Type Storage Format Attachment Type Usage Created in
Position Texture 16-bit float, compressed z Color Attachment (G-Buffer) MSAA, deferred shading, soft particles gropengldraw.cpp, L165-181
Depth Component Texture 24-bit implementation defined Depth Attachment Depth testing, (volumetric) nebula depth fogging, post-proc depth, lightshafts, decals, distortions gropengldraw.cpp, L295-310
Cockpit Depth Component Texture 24-bit implementation defined Depth Attachment Depth testing in cockpit pass gropengldraw.cpp, L274-292
Stencil Buffer 24-bit implementation defined (depth) + 8-bit implementation defined (stencil) non-attached Renderbuffer likely none (possibly some stencil purpose, but I'd imagine it should be attached to that then) gropengldraw.cpp, L313-315
Back Depth Component Texture 24-bit implementation defined Depth Attachment likely none, can serve as depth testing in immediate rendering if back stencil buffer is disabled gropengldraw.cpp, L533-550
Back Stencil Buffer 24-bit implementation defined (depth) + 8-bit implementation defined (stencil) Depth-Stencil attached Renderbuffer Depth testing in immediate rendering (i.e. techroom) and stencil operations gropengldraw.cpp, L556-559

That's 6 depth buffers, 2 of which likely do nothing at all, and with usages all over the place when we likely should really be using either the position texture or the depth component texture for everything.

I suppose there's three different strategies to solving this:

  1. Remove all depth-attachment-based buffers, and use the renderbuffers instead, and create an additional renderbuffer for the cockpit pass. This implies changing the shader uses of the depth texture to the position texture, since you cannot read from renderbuffers from shaders. Likely the most performant option.
  2. Remove all renderbuffer-based buffers. This requires adding stencil bits to the depth textures and attaching them. That in turn likely means we'll need to either change the reads from the depth texture to only pull from the depth bits, or use the position texture instead.
  3. Keep the current setup, and change the renderbuffers to only store 8-bit stencil data and no depth data. And also properly attach the stencil buffer for the main scene. By far the least invasive change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cleanupA modification or rewrite of code to make it more understandable or easier to maintain.discussionThis issue has (or wants) a discussiongraphicsA feature or issue related to graphics (2d and 3d)openglFeatures and Issues related to OpenGL

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions