Skip to content

Read a color style's image once in the shaders, so SDL GPU's first frame no longer stalls (#301) - #343

Merged
LogicalError merged 1 commit into
mainfrom
tachyonui/sdlgpu-lavapipe-speed
Nov 26, 2026
Merged

LogicalError merged 1 commit into
mainfrom
tachyonui/sdlgpu-lavapipe-speed

Conversation

@LogicalError

Copy link
Copy Markdown
Owner

Closes #301. SDL GPU took 20 to 40 s per whole-app test on Windows' lavapipe, about 1 s on Linux's. The CI step timed out, so it was dropped.

What was slow

  • It wasn't the driver alone. On the same lavapipe, the native Vulkan backend runs the slowest test in 1.6 s, and SDL GPU took 18.3 s.
  • The time was all in the first frame's SDL_BeginGPURenderPass. That is where lavapipe compiles the shaders, the first time it draws with them.
  • The shaders were large on SDL GPU:
    • SDL GPU can't index an array of images. So every image read in a shader is a switch with a case for each of the 16 images a draw binds.
    • getSDFColor read its image in each color type's branch: 17 reads in all.
    • A shader calls it up to three times. That makes hundreds of texture reads in, for example, the box shader.

The fix

  • getSDFColor (sdf_color.slang, shared by every backend) now does it in two steps:
    • Each color type works out which image it reads and where: the texture for the texture types, the gradient page for the rest.
    • Then the image is read in one place.
  • That makes three reads a call instead of 17:
    • one size query
    • one sample
    • one row of four texels (FetchImageRow), for the interpolated triangle and box. The fourth texel is clamped to the image's width, so the triangle doesn't read past it.

Results

  • Drawing: byte for byte the same as before, on Vulkan, Direct3D 12, and SDL GPU's Vulkan and Direct3D 12 drivers. I saved a frame of every color type before the change and compared it after.
  • Timing on lavapipe (Windows):
    • The ticket's test: 18.3 s before, 3.7 s after.
    • gui_gpu_tests --graphics=sdlgpu passes in about 4 minutes on this machine. That machine runs the Direct3D 12 suite about as fast as the CI runner (51 s against 48 s).

Tests

  • A new ColorTypesApp (gpu_draw_app.h) draws a shape of every color type. Six of them had no pixel test before:
    • the five gradients
    • solid
    • the interpolated box and triangle
    • an image stretched and repeated
  • EveryColorTypeDrawsAsOnVulkan compares its frame with Vulkan's. It runs in:
    • gui_d3d12_tests
    • gui_sdlgpu_tests, for each driver
  • The comparison with Vulkan, ExpectSameAsOnVulkan, is now shared with the existing draw test.
  • CI runs the whole-app tests on SDL GPU over lavapipe on Windows again, with the 15-minute timeout.
  • These pass on Debug and Release:
    • gui_vulkan_tests, gui_d3d12_tests and gui_sdlgpu_tests
    • gui_gpu_tests on Vulkan, Direct3D 12 and SDL GPU
    • gui_core_tests

Left

  • A first SDL GPU frame on lavapipe still takes about 3 s, against about 1.5 s on native Vulkan.
  • The size query could come from the draw's uniforms instead of the shader, which would cut another read per call. This change doesn't do that.

…ame no longer stalls (#301)

SDL GPU can't index its images, so each image read in a shader is a case
for every image a draw binds. getSDFColor read its image in each color
type's branch: 17 reads, each 16 cases, up to three times a shader.
lavapipe compiles that the first time it draws, and on Windows a first
frame took about 16 s.

getSDFColor now works out the image and where to read it for each type,
then reads it in one place: one size query, one sample, and one row of
four texels for the interpolated triangle and box. The drawing is the
same on every backend, byte for byte.

- The Direct3D 12 and SDL GPU tests draw every color type and compare it
  with Vulkan's drawing.
- CI runs the whole-app tests on SDL GPU over lavapipe on Windows again.
@LogicalError
LogicalError merged commit 68c01e1 into main Nov 26, 2026
9 checks passed
@LogicalError
LogicalError deleted the tachyonui/sdlgpu-lavapipe-speed branch November 26, 2026 15:01
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.

SDL GPU is about 20x slower on Windows' lavapipe than on Linux's

1 participant