Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes from mozilla-central gfx/wr #4841

Merged
merged 4 commits into from
Feb 22, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webrender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sw_compositor = ["swgl"]

[build-dependencies]
build-parallel = "0.1.2"
glslopt = "0.1.9"
glslopt = "0.1.10"
webrender_build = { version = "0.0.2", path = "../webrender_build" }

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/brush_linear_gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ Fragment brush_fs() {

#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuBuffer, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}

swgl_commitLinearGradientRGBA8(sGpuBuffer, address, GRADIENT_ENTRIES, true, v_gradient_repeat.x != 0.0,
swgl_commitLinearGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, true, v_gradient_repeat.x != 0.0,
v_pos, v_scale_dir, v_start_offset.x);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/cs_linear_gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void main(void) {

#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuBuffer, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x), int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}

swgl_commitLinearGradientRGBA8(sGpuBuffer, address, GRADIENT_ENTRIES, false, v_gradient_repeat.x != 0.0,
swgl_commitLinearGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, false, v_gradient_repeat.x != 0.0,
v_pos, v_scale_dir, v_start_offset.x);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/cs_radial_gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ void main(void) {

#ifdef SWGL_DRAW_SPAN
void swgl_drawSpanRGBA8() {
int address = swgl_validateGradient(sGpuBuffer, get_gpu_buffer_uv(v_gradient_address.x),
int address = swgl_validateGradient(sGpuBufferF, get_gpu_buffer_uv(v_gradient_address.x),
int(GRADIENT_ENTRIES + 2.0));
if (address < 0) {
return;
}
swgl_commitRadialGradientRGBA8(sGpuBuffer, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
swgl_commitRadialGradientRGBA8(sGpuBufferF, address, GRADIENT_ENTRIES, v_gradient_repeat.x != 0.0,
v_pos, v_start_radius.x);
}
#endif
Expand Down
31 changes: 16 additions & 15 deletions webrender/res/gpu_buffer.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
* 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/. */

uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuBuffer;
uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuBufferF;
uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuBufferI;

ivec2 get_gpu_buffer_uv(HIGHP_FS_ADDRESS int address) {
return ivec2(uint(address) % WR_MAX_VERTEX_TEXTURE_WIDTH,
uint(address) / WR_MAX_VERTEX_TEXTURE_WIDTH);
}

vec4 fetch_from_gpu_buffer_1(HIGHP_FS_ADDRESS int address) {
vec4 fetch_from_gpu_buffer_1f(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_buffer_uv(address);
return texelFetch(sGpuBuffer, uv, 0);
return texelFetch(sGpuBufferF, uv, 0);
}

vec4[2] fetch_from_gpu_buffer_2(HIGHP_FS_ADDRESS int address) {
vec4[2] fetch_from_gpu_buffer_2f(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_buffer_uv(address);
return vec4[2](
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(1, 0))
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(1, 0))
);
}

vec4[3] fetch_from_gpu_buffer_3(HIGHP_FS_ADDRESS int address) {
vec4[3] fetch_from_gpu_buffer_3f(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_buffer_uv(address);
return vec4[3](
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(2, 0))
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(2, 0))
);
}

vec4[4] fetch_from_gpu_buffer_4(HIGHP_FS_ADDRESS int address) {
vec4[4] fetch_from_gpu_buffer_4f(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_buffer_uv(address);
return vec4[4](
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuBuffer, uv, 0, ivec2(3, 0))
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuBufferF, uv, 0, ivec2(3, 0))
);
}
2 changes: 1 addition & 1 deletion webrender/res/gradient.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vec4 sample_gradient(float offset) {
float entry_fract = x - entry_index;

// Fetch the start and end color. There is a [start, end] color per entry.
vec4 texels[2] = fetch_from_gpu_buffer_2(v_gradient_address.x + 2 * int(entry_index));
vec4 texels[2] = fetch_from_gpu_buffer_2f(v_gradient_address.x + 2 * int(entry_index));

// Finally interpolate and apply dithering
return dither(texels[0] + texels[1] * entry_fract);
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/ps_quad.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct QuadPrimitive {
QuadSegment fetch_segment(int base, int index) {
QuadSegment seg;

vec4 texels[2] = fetch_from_gpu_buffer_2(base + 3 + index * 2);
vec4 texels[2] = fetch_from_gpu_buffer_2f(base + 3 + index * 2);

seg.rect = RectWithEndpoint(texels[0].xy, texels[0].zw);
seg.uv_rect = texels[1];
Expand All @@ -72,7 +72,7 @@ QuadSegment fetch_segment(int base, int index) {
QuadPrimitive fetch_primitive(int index) {
QuadPrimitive prim;

vec4 texels[3] = fetch_from_gpu_buffer_3(index);
vec4 texels[3] = fetch_from_gpu_buffer_3f(index);

prim.bounds = RectWithEndpoint(texels[0].xy, texels[0].zw);
prim.clip = RectWithEndpoint(texels[1].xy, texels[1].zw);
Expand Down
4 changes: 2 additions & 2 deletions webrender/res/ps_quad_mask.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ Clip fetch_clip(int index) {
clip.space = aClipData.z;

#ifdef WR_FEATURE_FAST_PATH
vec4 texels[3] = fetch_from_gpu_buffer_3(index);
vec4 texels[3] = fetch_from_gpu_buffer_3f(index);
clip.rect = RectWithEndpoint(texels[0].xy, texels[0].zw);
clip.radii = texels[1];
clip.mode = texels[2].x;
#else
vec4 texels[4] = fetch_from_gpu_buffer_4(index);
vec4 texels[4] = fetch_from_gpu_buffer_4f(index);
clip.rect = RectWithEndpoint(texels[0].xy, texels[0].zw);
clip.radii_top = texels[1];
clip.radii_bottom = texels[2];
Expand Down
4 changes: 2 additions & 2 deletions webrender/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::render_target::RenderTargetContext;
use crate::render_task_graph::{RenderTaskId, RenderTaskGraph};
use crate::render_task::{RenderTaskAddress, RenderTaskKind, SubPass};
use crate::renderer::{BlendMode, ShaderColorMode};
use crate::renderer::{MAX_VERTEX_TEXTURE_WIDTH, GpuBufferBuilder, GpuBufferAddress};
use crate::renderer::{MAX_VERTEX_TEXTURE_WIDTH, GpuBufferBuilderF, GpuBufferAddress};
use crate::resource_cache::{GlyphFetchResult, ImageProperties};
use crate::space::SpaceMapper;
use crate::visibility::{PrimitiveVisibilityFlags, VisibilityState};
Expand Down Expand Up @@ -857,7 +857,7 @@ impl BatchBuilder {
surface_spatial_node_index: SpatialNodeIndex,
z_generator: &mut ZBufferIdGenerator,
prim_instances: &[PrimitiveInstance],
_gpu_buffer_builder: &mut GpuBufferBuilder,
_gpu_buffer_builder: &mut GpuBufferBuilderF,
segments: &[RenderTaskId],
) {
let (prim_instance_index, extra_prim_gpu_address) = match cmd {
Expand Down
10 changes: 7 additions & 3 deletions webrender/src/device/gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ pub enum UploadMethod {
}

/// Plain old data that can be used to initialize a texture.
pub unsafe trait Texel: Copy {}
unsafe impl Texel for u8 {}
unsafe impl Texel for f32 {}
pub unsafe trait Texel: Copy + Default {
fn image_format() -> ImageFormat;
}

unsafe impl Texel for u8 {
fn image_format() -> ImageFormat { ImageFormat::R8 }
}

/// Returns the size in bytes of a depth target with the given dimensions.
fn depth_target_size_in_bytes(dimensions: &DeviceIntSize) -> usize {
Expand Down
32 changes: 20 additions & 12 deletions webrender/src/frame_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::prim_store::{PictureIndex, PrimitiveScratchBuffer};
use crate::prim_store::{DeferredResolve, PrimitiveInstance};
use crate::profiler::{self, TransactionProfile};
use crate::render_backend::{DataStores, ScratchBuffer};
use crate::renderer::{GpuBuffer, GpuBufferBuilder};
use crate::renderer::{GpuBufferF, GpuBufferBuilderF, GpuBufferI, GpuBufferBuilderI};
use crate::render_target::{RenderTarget, PictureCacheTarget, TextureCacheRenderTarget, PictureCacheTargetKind};
use crate::render_target::{RenderTargetContext, RenderTargetKind, AlphaRenderTarget, ColorRenderTarget};
use crate::render_task_graph::{RenderTaskGraph, Pass, SubPassSurface};
Expand Down Expand Up @@ -171,7 +171,8 @@ pub struct FrameBuildingState<'a> {
pub surface_builder: SurfaceBuilder,
pub cmd_buffers: &'a mut CommandBufferList,
pub clip_tree: &'a ClipTree,
pub frame_gpu_data: &'a mut GpuBufferBuilder,
pub frame_gpu_data_f: &'a mut GpuBufferBuilderF,
pub frame_gpu_data_i: &'a mut GpuBufferBuilderI,
}

impl<'a> FrameBuildingState<'a> {
Expand Down Expand Up @@ -276,7 +277,8 @@ impl FrameBuilder {
tile_caches: &mut FastHashMap<SliceId, Box<TileCacheInstance>>,
spatial_tree: &SpatialTree,
cmd_buffers: &mut CommandBufferList,
frame_gpu_data: &mut GpuBufferBuilder,
frame_gpu_data_f: &mut GpuBufferBuilderF,
frame_gpu_data_i: &mut GpuBufferBuilderI,
profile: &mut TransactionProfile,
) {
profile_scope!("build_layer_screen_rects_and_cull_layers");
Expand Down Expand Up @@ -428,7 +430,8 @@ impl FrameBuilder {
surface_builder: SurfaceBuilder::new(),
cmd_buffers,
clip_tree: &mut scene.clip_tree,
frame_gpu_data,
frame_gpu_data_f,
frame_gpu_data_i,
};

// Push a default dirty region which culls primitives
Expand Down Expand Up @@ -558,7 +561,8 @@ impl FrameBuilder {
let mut cmd_buffers = CommandBufferList::new();

// TODO(gw): Recycle backing vec buffers for gpu buffer builder between frames
let mut gpu_buffer_builder = GpuBufferBuilder::new();
let mut gpu_buffer_builder_f = GpuBufferBuilderF::new();
let mut gpu_buffer_builder_i = GpuBufferBuilderI::new();

self.build_layer_screen_rects_and_cull_layers(
scene,
Expand All @@ -576,7 +580,8 @@ impl FrameBuilder {
tile_caches,
spatial_tree,
&mut cmd_buffers,
&mut gpu_buffer_builder,
&mut gpu_buffer_builder_f,
&mut gpu_buffer_builder_i,
profile,
);

Expand Down Expand Up @@ -632,7 +637,7 @@ impl FrameBuilder {
output_size,
&mut ctx,
gpu_cache,
&mut gpu_buffer_builder,
&mut gpu_buffer_builder_f,
&render_tasks,
&scene.clip_store,
&mut transform_palette,
Expand Down Expand Up @@ -690,7 +695,8 @@ impl FrameBuilder {
scene.clip_store.end_frame(&mut scratch.clip_store);
scratch.end_frame();

let gpu_buffer = gpu_buffer_builder.finalize(&render_tasks);
let gpu_buffer_f = gpu_buffer_builder_f.finalize(&render_tasks);
let gpu_buffer_i = gpu_buffer_builder_i.finalize(&render_tasks);

Frame {
device_rect: DeviceIntRect::from_origin_and_size(
Expand All @@ -707,7 +713,8 @@ impl FrameBuilder {
prim_headers,
debug_items: mem::replace(&mut scratch.primitive.debug_items, Vec::new()),
composite_state,
gpu_buffer,
gpu_buffer_f,
gpu_buffer_i,
}
}

Expand Down Expand Up @@ -894,7 +901,7 @@ pub fn build_render_pass(
screen_size: DeviceIntSize,
ctx: &mut RenderTargetContext,
gpu_cache: &mut GpuCache,
gpu_buffer_builder: &mut GpuBufferBuilder,
gpu_buffer_builder: &mut GpuBufferBuilderF,
render_tasks: &RenderTaskGraph,
clip_store: &ClipStore,
transforms: &mut TransformPalette,
Expand Down Expand Up @@ -967,7 +974,7 @@ pub fn build_render_pass(
let task_id = sub_pass.task_ids[0];
let task = &render_tasks[task_id];
let target_rect = task.get_target_rect();
let mut gpu_buffer_builder = GpuBufferBuilder::new();
let mut gpu_buffer_builder = GpuBufferBuilderF::new();

match task.kind {
RenderTaskKind::Picture(ref pic_task) => {
Expand Down Expand Up @@ -1127,7 +1134,8 @@ pub struct Frame {

/// Main GPU data buffer constructed (primarily) during the prepare
/// pass for primitives that were visible and dirty.
pub gpu_buffer: GpuBuffer,
pub gpu_buffer_f: GpuBufferF,
pub gpu_buffer_i: GpuBufferI,
}

impl Frame {
Expand Down
Loading
Loading