commit b598f6fc9a6ce7ec3696f7e3b235da380824f3af
parent 23c67c96b4f2a2e8c56efec21e7b61970aee3631
Author: Nicolas Silva <nical@fastmail.com>
Date: Tue, 9 Dec 2025 08:19:04 +0000
Bug 2000393 - Add BrushSegmentGpuData. r=gw
Differential Revision: https://phabricator.services.mozilla.com/D272809
Diffstat:
9 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/gfx/wr/webrender/res/brush.glsl b/gfx/wr/webrender/res/brush.glsl
@@ -109,6 +109,7 @@ void brush_shader_main_vs(
segment_rect = ph.local_rect;
segment_data = vec4(0.0);
} else {
+ // See BrushSegmentGpuData
int segment_address = ph.specific_prim_address +
VECS_PER_SPECIFIC_BRUSH +
instance.segment_index * VECS_PER_SEGMENT;
diff --git a/gfx/wr/webrender/src/gpu_types.rs b/gfx/wr/webrender/src/gpu_types.rs
@@ -9,7 +9,7 @@ use crate::composite::{CompositeFeatures, CompositorClip};
use crate::segment::EdgeAaSegmentMask;
use crate::spatial_tree::{SpatialTree, SpatialNodeIndex};
use crate::internal_types::{FastHashMap, FrameVec, FrameMemory};
-use crate::prim_store::ClipData;
+use crate::prim_store::{ClipData, VECS_PER_SEGMENT};
use crate::render_task::RenderTaskAddress;
use crate::render_task_graph::RenderTaskId;
use crate::renderer::{GpuBufferAddress, GpuBufferBuilderF, GpuBufferHandle, GpuBufferWriterF, GpuBufferDataF, ShaderColorMode};
@@ -1058,6 +1058,24 @@ impl GpuBufferDataF for ImageBrushPrimitiveData {
}
}
+#[cfg_attr(feature = "capture", derive(Serialize))]
+#[cfg_attr(feature = "replay", derive(Deserialize))]
+#[derive(Debug, Clone, MallocSizeOf)]
+pub struct BrushSegmentGpuData {
+ pub local_rect: LayoutRect,
+ /// Each brush shader has its own interpretation of this field.
+ pub extra_data: [f32; 4],
+}
+
+impl GpuBufferDataF for BrushSegmentGpuData {
+ const NUM_BLOCKS: usize = VECS_PER_SEGMENT;
+ fn write(&self, writer: &mut GpuBufferWriterF) {
+ writer.push_one(self.local_rect);
+ writer.push_one(self.extra_data);
+ }
+}
+
+
// Set the local -> world transform for a given spatial
// node in the transform palette.
fn register_transform(
diff --git a/gfx/wr/webrender/src/picture.rs b/gfx/wr/webrender/src/picture.rs
@@ -116,7 +116,7 @@ use crate::intern::ItemUid;
use crate::internal_types::{FastHashMap, FastHashSet, PlaneSplitter, FilterGraphOp, FilterGraphNode, Filter, FrameId};
use crate::internal_types::{PlaneSplitterIndex, PlaneSplitAnchor, TextureSource};
use crate::frame_builder::{FrameBuildingContext, FrameBuildingState, PictureState, PictureContext};
-use crate::gpu_types::{BlurEdgeMode, ImageBrushPrimitiveData, UvRectKind, ZBufferId};
+use crate::gpu_types::{BlurEdgeMode, BrushSegmentGpuData, ImageBrushPrimitiveData, UvRectKind, ZBufferId};
use peek_poke::{PeekPoke, poke_into_vec, peek_from_slice, ensure_red_zone};
use plane_split::{Clipper, Polygon};
use crate::prim_store::{PrimitiveTemplateKind, PictureIndex, PrimitiveInstance, PrimitiveInstanceKind};
@@ -7279,9 +7279,10 @@ impl PicturePrimitive {
stretch_size: shadow_rect.size(),
});
- // segment rect / extra data
- writer.push_one(shadow_rect);
- writer.push_one([0.0, 0.0, 0.0, 0.0]);
+ writer.push(&BrushSegmentGpuData {
+ local_rect: shadow_rect,
+ extra_data: [0.0; 4],
+ });
*extra_handle = writer.finish();
}
diff --git a/gfx/wr/webrender/src/prepare.rs b/gfx/wr/webrender/src/prepare.rs
@@ -1228,8 +1228,7 @@ fn write_segment<F>(
f(&mut writer);
for segment in segments {
- writer.push_one(segment.local_rect);
- writer.push_one([0.0; 4]);
+ segment.write_gpu_blocks(&mut writer);
}
segment_instance.gpu_data = writer.finish();
diff --git a/gfx/wr/webrender/src/prim_store/borders.rs b/gfx/wr/webrender/src/prim_store/borders.rs
@@ -92,11 +92,9 @@ impl NormalBorderData {
writer: &mut GpuBufferWriterF,
) {
for segment in &self.brush_segments {
- // has to match VECS_PER_SEGMENT
- writer.push_one(segment.local_rect);
- writer.push_one(segment.extra_data);
+ segment.write_gpu_blocks(writer);
}
- }
+ }
}
pub type NormalBorderTemplate = PrimTemplate<NormalBorderData>;
@@ -289,9 +287,7 @@ impl ImageBorderData {
writer: &mut GpuBufferWriterF,
) {
for segment in &self.brush_segments {
- // has to match VECS_PER_SEGMENT
- writer.push_one(segment.local_rect);
- writer.push_one(segment.extra_data);
+ segment.write_gpu_blocks(writer);
}
}
}
diff --git a/gfx/wr/webrender/src/prim_store/gradient/conic.rs b/gfx/wr/webrender/src/prim_store/gradient/conic.rs
@@ -271,9 +271,7 @@ impl ConicGradientTemplate {
});
// write_segment_gpu_blocks
for segment in &self.brush_segments {
- // has to match VECS_PER_SEGMENT
- writer.push_one(segment.local_rect);
- writer.push_one(segment.extra_data);
+ segment.write_gpu_blocks(&mut writer);
}
self.common.gpu_buffer_address = writer.finish();
diff --git a/gfx/wr/webrender/src/prim_store/gradient/linear.rs b/gfx/wr/webrender/src/prim_store/gradient/linear.rs
@@ -522,9 +522,7 @@ impl LinearGradientTemplate {
// write_segment_gpu_blocks
for segment in &self.brush_segments {
- // has to match VECS_PER_SEGMENT
- writer.push_one(segment.local_rect);
- writer.push_one(segment.extra_data);
+ segment.write_gpu_blocks(&mut writer);
}
self.common.gpu_buffer_address = writer.finish();
diff --git a/gfx/wr/webrender/src/prim_store/gradient/radial.rs b/gfx/wr/webrender/src/prim_store/gradient/radial.rs
@@ -240,9 +240,7 @@ impl RadialGradientTemplate {
// write_segment_gpu_blocks
for segment in &self.brush_segments {
- // has to match VECS_PER_SEGMENT
- writer.push_one(segment.local_rect);
- writer.push_one(segment.extra_data);
+ segment.write_gpu_blocks(&mut writer);
}
self.common.gpu_buffer_address = writer.finish();
diff --git a/gfx/wr/webrender/src/prim_store/mod.rs b/gfx/wr/webrender/src/prim_store/mod.rs
@@ -21,7 +21,7 @@ use crate::debug_colors;
use crate::scene_building::{CreateShadow, IsVisible};
use crate::frame_builder::FrameBuildingState;
use glyph_rasterizer::GlyphKey;
-use crate::gpu_types::{BrushFlags, QuadSegment};
+use crate::gpu_types::{BrushFlags, BrushSegmentGpuData, QuadSegment};
use crate::intern;
use crate::picture::PicturePrimitive;
use crate::render_task_graph::RenderTaskId;
@@ -767,6 +767,17 @@ impl BrushSegment {
brush_flags,
}
}
+
+ pub fn gpu_data(&self) -> BrushSegmentGpuData {
+ BrushSegmentGpuData {
+ local_rect: self.local_rect,
+ extra_data: self.extra_data,
+ }
+ }
+
+ pub fn write_gpu_blocks(&self, writer: &mut GpuBufferWriterF) {
+ writer.push(&self.gpu_data());
+ }
}
#[derive(Debug, Clone)]