Bug 1882414 - Remove cs_clip_image shader and related code r=gfx-reviewers,lsalzman

It's no longer used now that the quad-based image mask code
is stable and used everywhere.

Differential Revision: https://phabricator.services.mozilla.com/D202889
This commit is contained in:
Glenn Watson 2024-02-28 01:49:28 +00:00
parent 86c0d58f4d
commit a7467e3971
7 changed files with 6 additions and 252 deletions

View file

@ -1,117 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include shared,clip_shared
varying highp vec2 vLocalPos;
varying highp vec2 vClipMaskImageUv;
flat varying highp vec4 vClipMaskUvInnerRect;
#ifdef WR_VERTEX_SHADER
PER_INSTANCE in vec4 aClipTileRect;
PER_INSTANCE in ivec2 aClipDataResourceAddress;
PER_INSTANCE in vec4 aClipLocalRect;
struct ClipMaskInstanceImage {
ClipMaskInstanceCommon base;
RectWithEndpoint tile_rect;
ivec2 resource_address;
RectWithEndpoint local_rect;
};
ClipMaskInstanceImage fetch_clip_item() {
ClipMaskInstanceImage cmi;
cmi.base = fetch_clip_item_common();
cmi.tile_rect = RectWithEndpoint(aClipTileRect.xy, aClipTileRect.zw);
cmi.resource_address = aClipDataResourceAddress;
cmi.local_rect = RectWithEndpoint(aClipLocalRect.xy, aClipLocalRect.zw);
return cmi;
}
struct ClipImageVertexInfo {
vec2 local_pos;
vec4 world_pos;
};
// This differs from write_clip_tile_vertex in that we forward transform the
// primitive's local-space tile rect into the target space. We use scissoring
// to ensure that the primitive does not draw outside the target bounds.
ClipImageVertexInfo write_clip_image_vertex(RectWithEndpoint tile_rect,
RectWithEndpoint local_clip_rect,
Transform prim_transform,
Transform clip_transform,
RectWithEndpoint sub_rect,
vec2 task_origin,
vec2 screen_origin,
float device_pixel_scale) {
vec2 local_pos = rect_clamp(local_clip_rect, mix(tile_rect.p0, tile_rect.p1, aPosition.xy));
vec4 world_pos = prim_transform.m * vec4(local_pos, 0.0, 1.0);
vec4 final_pos = vec4(
world_pos.xy * device_pixel_scale + (task_origin - screen_origin) * world_pos.w,
0.0,
world_pos.w
);
gl_Position = uTransform * final_pos;
init_transform_vs(
clip_transform.is_axis_aligned
? vec4(vec2(-1.0e16), vec2(1.0e16))
: vec4(local_clip_rect.p0, local_clip_rect.p1));
ClipImageVertexInfo vi = ClipImageVertexInfo(local_pos, world_pos);
return vi;
}
void main(void) {
ClipMaskInstanceImage cmi = fetch_clip_item();
Transform clip_transform = fetch_transform(cmi.base.clip_transform_id);
Transform prim_transform = fetch_transform(cmi.base.prim_transform_id);
ImageSource res = fetch_image_source_direct(cmi.resource_address);
ClipImageVertexInfo vi = write_clip_image_vertex(
cmi.tile_rect,
cmi.local_rect,
prim_transform,
clip_transform,
cmi.base.sub_rect,
cmi.base.task_origin,
cmi.base.screen_origin,
cmi.base.device_pixel_scale
);
vLocalPos = vi.local_pos;
vec2 uv = (vi.local_pos - cmi.tile_rect.p0) / rect_size(cmi.tile_rect);
vec2 texture_size = vec2(TEX_SIZE(sColor0));
vec4 uv_rect = vec4(res.uv_rect.p0, res.uv_rect.p1);
vClipMaskImageUv = mix(uv_rect.xy, uv_rect.zw, uv) / texture_size;
// applying a half-texel offset to the UV boundaries to prevent linear samples from the outside
vClipMaskUvInnerRect = (uv_rect + vec4(0.5, 0.5, -0.5, -0.5)) / texture_size.xyxy;
}
#endif
#ifdef WR_FRAGMENT_SHADER
void main(void) {
float alpha = init_transform_rough_fs(vLocalPos);
vec2 source_uv = clamp(vClipMaskImageUv, vClipMaskUvInnerRect.xy, vClipMaskUvInnerRect.zw);
float clip_alpha = texture(sColor0, source_uv).r; //careful: texture has type A8
oFragColor = vec4(mix(1.0, clip_alpha, alpha), 0.0, 0.0, 1.0);
}
#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanR8() {
if (has_valid_transform_bounds()) {
return;
}
swgl_commitTextureLinearR8(sColor0, vClipMaskImageUv, vClipMaskUvInnerRect);
}
#endif
#endif

View file

@ -16,7 +16,7 @@ use crate::gpu_types::{SplitCompositeInstance, QuadInstance};
use crate::gpu_types::{PrimitiveInstanceData, RasterizationSpace, GlyphInstance}; use crate::gpu_types::{PrimitiveInstanceData, RasterizationSpace, GlyphInstance};
use crate::gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, TransformPalette}; use crate::gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, TransformPalette};
use crate::gpu_types::{ImageBrushData, get_shader_opacity, BoxShadowData, MaskInstance}; use crate::gpu_types::{ImageBrushData, get_shader_opacity, BoxShadowData, MaskInstance};
use crate::gpu_types::{ClipMaskInstanceCommon, ClipMaskInstanceImage, ClipMaskInstanceRect, ClipMaskInstanceBoxShadow}; use crate::gpu_types::{ClipMaskInstanceCommon, ClipMaskInstanceRect, ClipMaskInstanceBoxShadow};
use crate::internal_types::{FastHashMap, Swizzle, TextureSource, Filter}; use crate::internal_types::{FastHashMap, Swizzle, TextureSource, Filter};
use crate::picture::{Picture3DContext, PictureCompositeMode, calculate_screen_uv}; use crate::picture::{Picture3DContext, PictureCompositeMode, calculate_screen_uv};
use crate::prim_store::{PrimitiveInstanceKind, ClipData}; use crate::prim_store::{PrimitiveInstanceKind, ClipData};
@ -3547,8 +3547,6 @@ pub struct ClipBatchList {
/// Rectangle draws fill up the rectangles with rounded corners. /// Rectangle draws fill up the rectangles with rounded corners.
pub slow_rectangles: Vec<ClipMaskInstanceRect>, pub slow_rectangles: Vec<ClipMaskInstanceRect>,
pub fast_rectangles: Vec<ClipMaskInstanceRect>, pub fast_rectangles: Vec<ClipMaskInstanceRect>,
/// Image draws apply the image masking.
pub images: FastHashMap<(TextureSource, Option<DeviceIntRect>), Vec<ClipMaskInstanceImage>>,
pub box_shadows: FastHashMap<TextureSource, Vec<ClipMaskInstanceBoxShadow>>, pub box_shadows: FastHashMap<TextureSource, Vec<ClipMaskInstanceBoxShadow>>,
} }
@ -3557,7 +3555,6 @@ impl ClipBatchList {
ClipBatchList { ClipBatchList {
slow_rectangles: Vec::new(), slow_rectangles: Vec::new(),
fast_rectangles: Vec::new(), fast_rectangles: Vec::new(),
images: FastHashMap::default(),
box_shadows: FastHashMap::default(), box_shadows: FastHashMap::default(),
} }
} }
@ -3744,20 +3741,11 @@ impl ClipBatcher {
ctx.spatial_tree, ctx.spatial_tree,
); );
// For clip mask images, we need to map from the primitive's layout space to let prim_transform_id = transforms.get_id(
// the target space, as the cs_clip_image shader needs to forward transform root_spatial_node_index,
// the local image bounds, rather than backwards transform the target bounds ctx.root_spatial_node_index,
// as in done in write_clip_tile_vertex. ctx.spatial_tree,
let prim_transform_id = match clip_node.item.kind { );
ClipItemKind::Image { .. } => { panic!("bug: old path not supported") }
_ => {
transforms.get_id(
root_spatial_node_index,
ctx.root_spatial_node_index,
ctx.spatial_tree,
)
}
};
let common = ClipMaskInstanceCommon { let common = ClipMaskInstanceCommon {
sub_rect: DeviceRect::from_size(actual_rect.size()), sub_rect: DeviceRect::from_size(actual_rect.size()),

View file

@ -172,17 +172,6 @@ pub struct ClipMaskInstanceCommon {
pub prim_transform_id: TransformPaletteId, pub prim_transform_id: TransformPaletteId,
} }
#[derive(Clone, Debug)]
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[repr(C)]
pub struct ClipMaskInstanceImage {
pub common: ClipMaskInstanceCommon,
pub tile_rect: LayoutRect,
pub resource_address: GpuCacheAddress,
pub local_rect: LayoutRect,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "capture", derive(Serialize))] #[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))] #[cfg_attr(feature = "replay", derive(Deserialize))]

View file

@ -3618,7 +3618,6 @@ impl Renderer {
fn draw_clip_batch_list( fn draw_clip_batch_list(
&mut self, &mut self,
list: &ClipBatchList, list: &ClipBatchList,
draw_target: &DrawTarget,
projection: &default::Transform3D<f32>, projection: &default::Transform3D<f32>,
stats: &mut RendererStats, stats: &mut RendererStats,
) { ) {
@ -3673,42 +3672,6 @@ impl Renderer {
stats, stats,
); );
} }
// draw image masks
let mut using_scissor = false;
for ((mask_texture_id, clip_rect), items) in list.images.iter() {
let _gm2 = self.gpu_profiler.start_marker("clip images");
// Some image masks may require scissoring to ensure they don't draw
// outside their task's target bounds. Axis-aligned primitives will
// be clamped inside the shader and should not require scissoring.
// TODO: We currently assume scissor state is off by default for
// alpha targets here, but in the future we may want to track the
// current scissor state so that this can be properly saved and
// restored here.
if let Some(clip_rect) = clip_rect {
if !using_scissor {
self.device.enable_scissor();
using_scissor = true;
}
let scissor_rect = draw_target.build_scissor_rect(Some(*clip_rect));
self.device.set_scissor_rect(scissor_rect);
} else if using_scissor {
self.device.disable_scissor();
using_scissor = false;
}
let textures = BatchTextures::composite_rgb(*mask_texture_id);
self.shaders.borrow_mut().cs_clip_image
.bind(&mut self.device, projection, None, &mut self.renderer_errors, &mut self.profile);
self.draw_instanced_batch(
items,
VertexArrayKind::ClipImage,
&textures,
stats,
);
}
if using_scissor {
self.device.disable_scissor();
}
} }
fn draw_alpha_target( fn draw_alpha_target(
@ -3863,7 +3826,6 @@ impl Renderer {
self.set_blend(false, FramebufferKind::Other); self.set_blend(false, FramebufferKind::Other);
self.draw_clip_batch_list( self.draw_clip_batch_list(
&target.clip_batcher.primary_clips, &target.clip_batcher.primary_clips,
&draw_target,
projection, projection,
stats, stats,
); );
@ -3874,7 +3836,6 @@ impl Renderer {
self.set_blend_mode_multiply(FramebufferKind::Other); self.set_blend_mode_multiply(FramebufferKind::Other);
self.draw_clip_batch_list( self.draw_clip_batch_list(
&target.clip_batcher.secondary_clips, &target.clip_batcher.secondary_clips,
&draw_target,
projection, projection,
stats, stats,
); );

View file

@ -254,7 +254,6 @@ impl LazilyCompiledShader {
VertexArrayKind::RadialGradient => &desc::RADIAL_GRADIENT, VertexArrayKind::RadialGradient => &desc::RADIAL_GRADIENT,
VertexArrayKind::ConicGradient => &desc::CONIC_GRADIENT, VertexArrayKind::ConicGradient => &desc::CONIC_GRADIENT,
VertexArrayKind::Blur => &desc::BLUR, VertexArrayKind::Blur => &desc::BLUR,
VertexArrayKind::ClipImage => &desc::CLIP_IMAGE,
VertexArrayKind::ClipRect => &desc::CLIP_RECT, VertexArrayKind::ClipRect => &desc::CLIP_RECT,
VertexArrayKind::ClipBoxShadow => &desc::CLIP_BOX_SHADOW, VertexArrayKind::ClipBoxShadow => &desc::CLIP_BOX_SHADOW,
VertexArrayKind::VectorStencil => &desc::VECTOR_STENCIL, VertexArrayKind::VectorStencil => &desc::VECTOR_STENCIL,
@ -619,7 +618,6 @@ pub struct Shaders {
pub cs_clip_rectangle_slow: LazilyCompiledShader, pub cs_clip_rectangle_slow: LazilyCompiledShader,
pub cs_clip_rectangle_fast: LazilyCompiledShader, pub cs_clip_rectangle_fast: LazilyCompiledShader,
pub cs_clip_box_shadow: LazilyCompiledShader, pub cs_clip_box_shadow: LazilyCompiledShader,
pub cs_clip_image: LazilyCompiledShader,
// The are "primitive shaders". These shaders draw and blend // The are "primitive shaders". These shaders draw and blend
// final results on screen. They are aware of tile boundaries. // final results on screen. They are aware of tile boundaries.
@ -819,16 +817,6 @@ impl Shaders {
profile, profile,
)?; )?;
let cs_clip_image = LazilyCompiledShader::new(
ShaderKind::ClipCache(VertexArrayKind::ClipImage),
"cs_clip_image",
&["TEXTURE_2D"],
device,
options.precache_flags,
&shader_list,
profile,
)?;
let mut cs_scale = Vec::new(); let mut cs_scale = Vec::new();
let scale_shader_num = IMAGE_BUFFER_KINDS.len(); let scale_shader_num = IMAGE_BUFFER_KINDS.len();
// PrimitiveShader is not clonable. Use push() to initialize the vec. // PrimitiveShader is not clonable. Use push() to initialize the vec.
@ -1130,7 +1118,6 @@ impl Shaders {
cs_clip_rectangle_slow, cs_clip_rectangle_slow,
cs_clip_rectangle_fast, cs_clip_rectangle_fast,
cs_clip_box_shadow, cs_clip_box_shadow,
cs_clip_image,
ps_text_run, ps_text_run,
ps_text_run_dual_source, ps_text_run_dual_source,
ps_quad_textured, ps_quad_textured,
@ -1276,7 +1263,6 @@ impl Shaders {
self.cs_clip_rectangle_slow.deinit(device); self.cs_clip_rectangle_slow.deinit(device);
self.cs_clip_rectangle_fast.deinit(device); self.cs_clip_rectangle_fast.deinit(device);
self.cs_clip_box_shadow.deinit(device); self.cs_clip_box_shadow.deinit(device);
self.cs_clip_image.deinit(device);
self.ps_text_run.deinit(device); self.ps_text_run.deinit(device);
if let Some(shader) = self.ps_text_run_dual_source { if let Some(shader) = self.ps_text_run_dual_source {
shader.deinit(device); shader.deinit(device);

View file

@ -488,53 +488,6 @@ pub mod desc {
], ],
}; };
pub const CLIP_IMAGE: VertexDescriptor = VertexDescriptor {
vertex_attributes: &[VertexAttribute {
name: "aPosition",
count: 2,
kind: VertexAttributeKind::U8Norm,
}],
instance_attributes: &[
// common clip attributes
VertexAttribute {
name: "aClipDeviceArea",
count: 4,
kind: VertexAttributeKind::F32,
},
VertexAttribute {
name: "aClipOrigins",
count: 4,
kind: VertexAttributeKind::F32,
},
VertexAttribute {
name: "aDevicePixelScale",
count: 1,
kind: VertexAttributeKind::F32,
},
VertexAttribute {
name: "aTransformIds",
count: 2,
kind: VertexAttributeKind::I32,
},
// specific clip attributes
VertexAttribute {
name: "aClipTileRect",
count: 4,
kind: VertexAttributeKind::F32,
},
VertexAttribute {
name: "aClipDataResourceAddress",
count: 2,
kind: VertexAttributeKind::U16,
},
VertexAttribute {
name: "aClipLocalRect",
count: 4,
kind: VertexAttributeKind::F32,
},
],
};
pub const GPU_CACHE_UPDATE: VertexDescriptor = VertexDescriptor { pub const GPU_CACHE_UPDATE: VertexDescriptor = VertexDescriptor {
vertex_attributes: &[ vertex_attributes: &[
VertexAttribute { VertexAttribute {
@ -814,7 +767,6 @@ pub mod desc {
pub enum VertexArrayKind { pub enum VertexArrayKind {
Primitive, Primitive,
Blur, Blur,
ClipImage,
ClipRect, ClipRect,
ClipBoxShadow, ClipBoxShadow,
VectorStencil, VectorStencil,
@ -1043,7 +995,6 @@ pub struct RendererVAOs {
blur_vao: VAO, blur_vao: VAO,
clip_rect_vao: VAO, clip_rect_vao: VAO,
clip_box_shadow_vao: VAO, clip_box_shadow_vao: VAO,
clip_image_vao: VAO,
border_vao: VAO, border_vao: VAO,
line_vao: VAO, line_vao: VAO,
scale_vao: VAO, scale_vao: VAO,
@ -1091,7 +1042,6 @@ impl RendererVAOs {
clip_rect_vao: device.create_vao_with_new_instances(&desc::CLIP_RECT, &prim_vao), clip_rect_vao: device.create_vao_with_new_instances(&desc::CLIP_RECT, &prim_vao),
clip_box_shadow_vao: device clip_box_shadow_vao: device
.create_vao_with_new_instances(&desc::CLIP_BOX_SHADOW, &prim_vao), .create_vao_with_new_instances(&desc::CLIP_BOX_SHADOW, &prim_vao),
clip_image_vao: device.create_vao_with_new_instances(&desc::CLIP_IMAGE, &prim_vao),
border_vao: device.create_vao_with_new_instances(&desc::BORDER, &prim_vao), border_vao: device.create_vao_with_new_instances(&desc::BORDER, &prim_vao),
scale_vao: device.create_vao_with_new_instances(&desc::SCALE, &prim_vao), scale_vao: device.create_vao_with_new_instances(&desc::SCALE, &prim_vao),
line_vao: device.create_vao_with_new_instances(&desc::LINE, &prim_vao), line_vao: device.create_vao_with_new_instances(&desc::LINE, &prim_vao),
@ -1114,7 +1064,6 @@ impl RendererVAOs {
device.delete_vao(self.resolve_vao); device.delete_vao(self.resolve_vao);
device.delete_vao(self.clip_rect_vao); device.delete_vao(self.clip_rect_vao);
device.delete_vao(self.clip_box_shadow_vao); device.delete_vao(self.clip_box_shadow_vao);
device.delete_vao(self.clip_image_vao);
device.delete_vao(self.fast_linear_gradient_vao); device.delete_vao(self.fast_linear_gradient_vao);
device.delete_vao(self.linear_gradient_vao); device.delete_vao(self.linear_gradient_vao);
device.delete_vao(self.radial_gradient_vao); device.delete_vao(self.radial_gradient_vao);
@ -1136,7 +1085,6 @@ impl ops::Index<VertexArrayKind> for RendererVAOs {
fn index(&self, kind: VertexArrayKind) -> &VAO { fn index(&self, kind: VertexArrayKind) -> &VAO {
match kind { match kind {
VertexArrayKind::Primitive => &self.prim_vao, VertexArrayKind::Primitive => &self.prim_vao,
VertexArrayKind::ClipImage => &self.clip_image_vao,
VertexArrayKind::ClipRect => &self.clip_rect_vao, VertexArrayKind::ClipRect => &self.clip_rect_vao,
VertexArrayKind::ClipBoxShadow => &self.clip_box_shadow_vao, VertexArrayKind::ClipBoxShadow => &self.clip_box_shadow_vao,
VertexArrayKind::Blur => &self.blur_vao, VertexArrayKind::Blur => &self.blur_vao,

View file

@ -66,7 +66,6 @@ pub fn get_shader_features(flags: ShaderFeatureFlags) -> ShaderFeatures {
// Clip shaders // Clip shaders
shaders.insert("cs_clip_rectangle", vec![String::new(), "FAST_PATH".to_string()]); shaders.insert("cs_clip_rectangle", vec![String::new(), "FAST_PATH".to_string()]);
shaders.insert("cs_clip_image", vec!["TEXTURE_2D".to_string()]);
shaders.insert("cs_clip_box_shadow", vec!["TEXTURE_2D".to_string()]); shaders.insert("cs_clip_box_shadow", vec!["TEXTURE_2D".to_string()]);
// Cache shaders // Cache shaders