Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@ library), **rsdm** (a PyDM-style EPICS display layer built on rsplot), and

## [Unreleased]

### Fixed

- **rsplot**: every per-draw params block — the curve pipelines (line,
markers, caps, fill, error bars), the data-area clear, the image tiles, the
3D scene pipelines and the volume ray-caster — is bound as a read-only
storage buffer instead of a uniform. On Windows' DX12 backend with the WARP
software adapter (a GPU-less VM) every curve in a pass read the last
curve's uniform, so all curves took the last curve's colour; storage reads
were per-curve correct. The block layouts are unchanged.
- **rsplot**: curve, per-vertex, dashed-gap and data-background colours are
uploaded in the render target's encoding: sRGB bytes for a non-sRGB target
(egui-wgpu's swapchain), linear for an sRGB one. They were always
linearised, which on the non-sRGB target drew every colour darker than its
`Color32` and than egui's own legend swatches (`#4f9bff` showed as
`(20, 84, 255)`); PNG export was affected the same way.
- **rsplot**: the 2D image path uploads its colour texels in the render
target's encoding too: the colormap LUT and direct-RGBA tiles are
`Rgba8Unorm` for a non-sRGB target and `Rgba8UnormSrgb` for an sRGB one,
and the colormap's `nan_color` follows the same rule. They were always
sRGB-decoded to linear, which on egui-wgpu's non-sRGB swapchain drew every
colormapped image and RGBA image darker than its colormap (viridis' mid
teal `(33, 145, 140)` showed as `(4, 71, 66)`).
- **rsplot**: the 3D scene (`paint_scene3d`, `SceneWidget`, `ScalarFieldView`,
the volume cut plane and iso-surfaces) is rendered into the sRGB variant of
the surface format and the blit encodes the linear result to sRGB when the
surface is non-sRGB, so geometry, mesh shading, fog, image layers and the
background now show at their `Color32` values on egui-wgpu's swapchain
instead of darker. `snapshot_scene3d` / `SceneWidget::snapshot` read back
the sRGB offscreen target, so their PNGs carry sRGB-encoded bytes whatever
the surface format (they were as dark as the screen).
- **rsplot**: `VolumeRaycaster` uploads its voxel colours in the render
target's encoding — the sRGB bytes as is for egui-wgpu's non-sRGB swapchain
(unchanged there), linearised for an sRGB target, where the composite used
to be encoded a second time on store and showed washed out (an opaque
`(255, 128, 0)` voxel read back as `(255, 188, 0)`).

## [0.6.0] - 2026-10-16

### Changed
Expand Down
26 changes: 19 additions & 7 deletions src/render/backend_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::core::plot::{Plot, PlotId};
use crate::core::shape::{Shape, ShapeKind};
use crate::core::transform::{Margins, Scale, Transform, YAxis};
use crate::core::triangles::Triangles;
use crate::render::gpu_curve::{CurveData, CurvePipeline, GpuCurve};
use crate::render::gpu_curve::{CurveData, CurvePipeline, GpuCurve, gpu_color};
use crate::render::gpu_image::{
AggregationMode, GpuImage, ImageData, ImagePipeline, ImagePixels, aggregate_blocks,
};
Expand Down Expand Up @@ -49,6 +49,8 @@ pub struct WgpuResources {
curve_pipeline: CurvePipeline,
/// Per-plot GPU data, keyed by plot ID.
plots: HashMap<PlotId, PlotGpuData>,
/// Whether the render target is an sRGB format; see [`Self::encode_color`].
srgb_target: bool,
}

impl WgpuResources {
Expand All @@ -66,7 +68,7 @@ impl WgpuResources {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
ty: wgpu::BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: NonZeroU64::new(16),
},
Expand Down Expand Up @@ -112,9 +114,17 @@ impl WgpuResources {
image_pipeline,
curve_pipeline,
plots: HashMap::new(),
srgb_target: target_format.is_srgb(),
}
}

/// Encode a colour the way the clear pass must write it to the render
/// target (the same rule the curves use; see
/// [`gpu_color`](crate::render::gpu_curve::gpu_color)).
pub(crate) fn encode_color(&self, color: Color32) -> [f32; 4] {
gpu_color(color, self.srgb_target)
}

/// Return the [`PlotGpuData`] for `plot_id`, inserting a fresh entry if it
/// does not yet exist.
pub(crate) fn get_or_insert_plot(
Expand All @@ -126,7 +136,7 @@ impl WgpuResources {
let color_uniform = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("rsplot clear color"),
size: 16,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
Expand Down Expand Up @@ -155,7 +165,8 @@ impl WgpuResources {
/// back, and return tightly packed RGBA8 pixels (top row first). Used by
/// [`crate::render::save::save_graph`] (`doc/design.md` §13 E1).
///
/// `bg` is the linear, premultiplied clear color; the orthos/axis_log pairs
/// `bg` is the clear color as [`Self::encode_color`] encodes it for
/// `target_format`; the orthos/axis_log pairs
/// are the same matrices the on-screen [`CurveCallback`] uses for each Y
/// axis. Curves are drawn at whatever resolution they were last decimated
/// to, and dashed lines reuse the dash arc length last computed for the
Expand Down Expand Up @@ -1343,8 +1354,8 @@ pub fn update_curve_at(
/// lightweight value re-registered by the egui side every frame; the actual GPU
/// resources are looked up from [`WgpuResources`].
pub(crate) struct ClearCallback {
/// Linear color space, premultiplied RGBA.
pub color: [f32; 4],
/// The data-area background; encoded for the target in `prepare`.
pub color: Color32,
/// Which plot's GPU data to use.
pub plot_id: PlotId,
}
Expand All @@ -1361,8 +1372,9 @@ impl egui_wgpu::CallbackTrait for ClearCallback {
let res: &mut WgpuResources = resources
.get_mut()
.expect("WgpuResources not installed — call rsplot::install() at startup");
let color = res.encode_color(self.color);
let plot_data = res.get_or_insert_plot(device, self.plot_id);
queue.write_buffer(&plot_data.color_uniform, 0, bytemuck::bytes_of(&self.color));
queue.write_buffer(&plot_data.color_uniform, 0, bytemuck::bytes_of(&color));
Vec::new()
}

Expand Down
Loading
Loading