Skip to content

fix(render): bind params as storage and write colours in the target's encoding - #8

Merged
physwkim merged 6 commits into
mainfrom
fix/dx12-curve-params
Oct 17, 2026
Merged

physwkim merged 6 commits into
mainfrom
fix/dx12-curve-params

Conversation

@physwkim

Copy link
Copy Markdown
Owner

Found on a GPU-less Windows VM (DX12/WARP), where every draw in a pass read the last-bound uniform params block so all overlaid curves took one colour, and where everything rsplot wrote linear to egui-wgpu's non-sRGB swapchain showed darker than its Color32; the storage-buffer fix is empirical from that VM, the wgpu-side cause is not identified. The headless tests read the kittest target's bytes back verbatim, so each colour fix comes with a readback that fails on the pre-fix renderer; the sRGB-target volume test rebuilds the RenderState with the sRGB variant of its format.

On Windows' DX12 backend with the WARP software adapter every curve in
a pass read the last curve's uniform block, so all curves took the last
curve's colour; the storage buffers in the same bind groups read
per-curve. Vulkan on hardware and on lavapipe never showed it. The
blocks hold no arrays or vec3, so the layouts coincide and the repr(C)
structs are unchanged.
egui-wgpu picks a non-sRGB swapchain format and gamma-encodes in its
own shader, while rsplot wrote linearised colours into it, so every
curve came out darker than its Color32 and than egui's legend swatch
(#4f9bff showed as (20, 84, 255)); PNG export the same. gpu_color now
keeps the sRGB bytes for a non-sRGB target and linearises only for an
sRGB one, and the clear colour follows the same rule.
The data-area clear, the image tiles, the three 3D scene pipelines and
the volume ray-caster still bound their params as uniforms, the binding
type under which DX12/WARP read every draw's block from the last one
bound. Same rule for every block now; none holds arrays or nested
structs, so the repr(C) layouts and sizes are unchanged.
The colormap LUT and the direct-RGBA tiles were Rgba8UnormSrgb and the
nan colour was linearised, so on egui-wgpu's non-sRGB swapchain the
image shaders wrote linear values and every image came out darker than
its colormap (viridis mid teal (33, 145, 140) read back as (4, 71, 66)).
color_texel_format / nan_color_for_target now pick the encoding from
the target, the same rule gpu_color applies to curve colours.
The scene shades in linear light and the blit copied it unconverted onto
egui-wgpu's non-sRGB swapchain, so every 3D colour showed darker than its
Color32. Scene3dPipeline now renders into the sRGB variant of the surface
format and the blit encodes only for a non-sRGB surface; snapshot_scene
reads back that sRGB target, so its bytes are gamma-encoded too.
…coding

premultiply_rgba kept the caller's sRGB bytes whatever the colour target:
right for egui-wgpu's non-sRGB swapchain, encoded twice on an sRGB one,
where an opaque (255, 128, 0) voxel stored as (255, 188, 0). The voxels now
go through rgba8_for_target (the image path's nan_color_for_target, shared).
@physwkim
physwkim merged commit e534047 into main Oct 17, 2026
4 checks passed
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