Skip to content

P3: Reuse texture upload fences in the Vulkan renderer - #8082

Open
dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:graphics/vulkan-upload-fence-reuse
Open

dustinspace217 wants to merge 1 commit into
scp-fs2open:masterfrom
dustinspace217:graphics/vulkan-upload-fence-reuse

Conversation

@dustinspace217

@dustinspace217 dustinspace217 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What?

The Vulkan renderer now reuses the fences that track texture uploads, instead of creating and destroying one for every upload.

Why?

On my machine (RTX 5080, NVIDIA 615.78.08 open kernel module, Fedora) creating a fence takes about 0.5 ms and destroying one takes about the same. Every texture upload paid both:

  • Message portraits and other streamed animations upload a texture for each animation frame, so each new frame cost about 1 ms. The rest of the HUD is about 0.2 ms per frame here.
  • Starting the game and loading the first FS2 mission does 554 uploads, which spent about 430 ms in those two calls.

I found this while looking at HUD rendering cost after #8060. I have only measured this one GPU and driver; where fences are already cheap, this changes nothing.

How?

VulkanTextureManager keeps completed upload fences in a list. submitUploadAsync resets and takes one, or creates one when the list is empty, and shutdown() destroys them. The list cannot outgrow the existing limit of 64 pending uploads, which is now a class constant with an assertion.

Testing?

Fedora, MediaVPs 5.0.3 plus the GOTY Mission Pack 1.0.3, 1920x1080, master from November 18 against this branch.

  • Timers in a local Release build, switching reuse on and off inside one session: per portrait frame, the fence calls went from 482 µs (create) plus 457 µs (destroy) to 0.4 µs, and the whole upload from about 495 µs to 19-25 µs. Up to the first HUD frame of SM1-01, time in fence calls went from 430 ms to 7.6 ms. Total load time was not measured.
  • At 3840x2160 the numbers are the same: time in fence calls during load went from 453 ms to about 6 ms, and the upload per portrait frame from 463 µs to 24 µs.
  • Debug with -vulkan -gr_debug: load, 100 seconds of SM1-01 with a portrait, the intro cutscene and a normal quit gave no validation message about fences and none left undestroyed. Without the reset the same run reports VUID-vkQueueSubmit-fence-00063; without the shutdown cleanup, VUID-vkDestroyDevice-device-05137.
  • With the limit temporarily set to 2, the wait for a free upload slot ran at least 100 times, with the same clean result.
  • Portraits, the command briefing animation and SM1-05 look the same on master and the branch under Vulkan. OpenGL is not touched.
  • Release and Debug build with 0 warnings. Unit tests pass, but they use the stub renderer and cannot reach this code.
  • Not tested: other GPUs or drivers, Windows, device loss.

Anything Else?

The two readback paths in VulkanRenderer.cpp also create a fence per use. They are rare and already wait on the GPU, so I left them alone.

I used Claude Code to help write and test this.

Every async texture upload created a fence and destroyed it when the upload completed. On at least one driver both
calls are slow (about 0.5 ms each), so each streamed animation frame, such as a message portrait, paid about a
millisecond, and mission load paid it once per texture. Keep completed fences and reuse them for later uploads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant