From e6bb09f4d7017ac778cb05a0019d9f8ae5deb13d Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 2 Jun 2017 12:04:25 +1000 Subject: [PATCH 1/3] Port aligned, angle and radial gradients to GPU cache. Also remove the gpu64 data texture, as it's now unused. --- webrender/res/prim_shared.glsl | 28 ++++++------- webrender/src/device.rs | 5 --- webrender/src/frame_builder.rs | 60 +++++++++++--------------- webrender/src/internal_types.rs | 1 - webrender/src/prim_store.rs | 74 ++++++++++++++------------------- webrender/src/renderer.rs | 4 -- webrender/src/tiling.rs | 3 +- 7 files changed, 71 insertions(+), 104 deletions(-) diff --git a/webrender/res/prim_shared.glsl b/webrender/res/prim_shared.glsl index 1c541b9489..f48e6eb573 100644 --- a/webrender/res/prim_shared.glsl +++ b/webrender/res/prim_shared.glsl @@ -117,7 +117,6 @@ uniform sampler2D sPrimGeometry; uniform sampler2D sData16; uniform sampler2D sData32; -uniform sampler2D sData64; uniform sampler2D sResourceRects; uniform sampler2D sResourceCache; @@ -144,16 +143,6 @@ vec4[2] fetch_data_2(int index) { ); } -vec4[4] fetch_data_4(int index) { - ivec2 uv = get_fetch_uv(index, 4); - return vec4[4]( - texelFetchOffset(sData64, uv, 0, ivec2(0, 0)), - texelFetchOffset(sData64, uv, 0, ivec2(1, 0)), - texelFetchOffset(sData64, uv, 0, ivec2(2, 0)), - texelFetchOffset(sData64, uv, 0, ivec2(3, 0)) - ); -} - // TODO(gw): This is here temporarily while we have // both GPU store and cache. When the GPU // store code is removed, we can change the @@ -180,6 +169,15 @@ vec4[8] fetch_from_resource_cache_8(int address) { ); } +vec4[3] fetch_from_resource_cache_3(int address) { + ivec2 uv = get_resource_cache_uv(address); + return vec4[3]( + texelFetchOffset(sResourceCache, uv, 0, ivec2(0, 0)), + texelFetchOffset(sResourceCache, uv, 0, ivec2(1, 0)), + texelFetchOffset(sResourceCache, uv, 0, ivec2(2, 0)) + ); +} + vec4[4] fetch_from_resource_cache_4(int address) { ivec2 uv = get_resource_cache_uv(address); return vec4[4]( @@ -311,8 +309,8 @@ struct Gradient { vec4 extend_mode; }; -Gradient fetch_gradient(int index) { - vec4 data[4] = fetch_data_4(index); +Gradient fetch_gradient(int address) { + vec4 data[3] = fetch_from_resource_cache_3(address); return Gradient(data[0], data[1], data[2]); } @@ -332,8 +330,8 @@ struct RadialGradient { vec4 tile_size_repeat; }; -RadialGradient fetch_radial_gradient(int index) { - vec4 data[4] = fetch_data_4(index); +RadialGradient fetch_radial_gradient(int address) { + vec4 data[3] = fetch_from_resource_cache_3(address); return RadialGradient(data[0], data[1], data[2]); } diff --git a/webrender/src/device.rs b/webrender/src/device.rs index de1a6f6562..65cf4b7404 100644 --- a/webrender/src/device.rs +++ b/webrender/src/device.rs @@ -1569,11 +1569,6 @@ impl Device { self.gl.uniform_1i(u_data32, TextureSampler::Data32 as i32); } - let u_data64 = self.gl.get_uniform_location(program.id, "sData64"); - if u_data64 != -1 { - self.gl.uniform_1i(u_data64, TextureSampler::Data64 as i32); - } - let u_resource_cache = self.gl.get_uniform_location(program.id, "sResourceCache"); if u_resource_cache != -1 { self.gl.uniform_1i(u_resource_cache, TextureSampler::ResourceCache as i32); diff --git a/webrender/src/frame_builder.rs b/webrender/src/frame_builder.rs index 1df001928e..c871eaf9d7 100644 --- a/webrender/src/frame_builder.rs +++ b/webrender/src/frame_builder.rs @@ -8,9 +8,9 @@ use gpu_store::GpuStoreAddress; use internal_types::{HardwareCompositeOp, SourceTexture}; use mask_cache::{ClipMode, ClipSource, MaskCacheInfo, RegionMode}; use plane_split::{BspSplitter, Polygon, Splitter}; -use prim_store::{GradientPrimitiveCpu, GradientPrimitiveGpu, ImagePrimitiveCpu}; +use prim_store::{GradientPrimitiveCpu, ImagePrimitiveCpu}; use prim_store::{ImagePrimitiveKind, PrimitiveContainer, PrimitiveGeometry, PrimitiveIndex}; -use prim_store::{PrimitiveStore, RadialGradientPrimitiveCpu, RadialGradientPrimitiveGpu}; +use prim_store::{PrimitiveStore, RadialGradientPrimitiveCpu}; use prim_store::{RectanglePrimitive, SplitGeometry, TextRunPrimitiveCpu, TextRunPrimitiveGpu}; use prim_store::{BoxShadowPrimitiveCpu, TexelRect, YuvImagePrimitiveCpu}; use profiler::{FrameProfileCounters, GpuCacheProfileCounters, TextureCacheProfileCounters}; @@ -650,16 +650,6 @@ impl FrameBuilder { (start_point.x == end_point.x && start_point.y > end_point.y)); - let gradient_cpu = GradientPrimitiveCpu { - stops_range: stops, - stops_count: stops_count, - extend_mode: extend_mode, - reverse_stops: reverse_stops, - cache_dirty: true, - gpu_data_address: GpuStoreAddress(0), - gpu_data_count: 0, - }; - // To get reftests exactly matching with reverse start/end // points, it's necessary to reverse the gradient // line in some cases. @@ -669,19 +659,25 @@ impl FrameBuilder { (start_point, end_point) }; - let gradient_gpu = GradientPrimitiveGpu { - start_point: sp, - end_point: ep, - extend_mode: pack_as_float(extend_mode as u32), - tile_size: tile_size, - tile_repeat: tile_repeat, - padding: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + let gradient_cpu = GradientPrimitiveCpu { + stops_range: stops, + stops_count: stops_count, + extend_mode: extend_mode, + reverse_stops: reverse_stops, + cache_dirty: true, + gpu_data_address: GpuStoreAddress(0), + gpu_data_count: 0, + gpu_blocks: [ + [sp.x, sp.y, ep.x, ep.y].into(), + [tile_size.width, tile_size.height, tile_repeat.width, tile_repeat.height].into(), + [pack_as_float(extend_mode as u32), 0.0, 0.0, 0.0].into(), + ], }; let prim = if aligned { - PrimitiveContainer::AlignedGradient(gradient_cpu, gradient_gpu) + PrimitiveContainer::AlignedGradient(gradient_cpu) } else { - PrimitiveContainer::AngleGradient(gradient_cpu, gradient_gpu) + PrimitiveContainer::AngleGradient(gradient_cpu) }; self.add_primitive(clip_and_scroll, &rect, clip_region, &[], prim); @@ -700,31 +696,26 @@ impl FrameBuilder { extend_mode: ExtendMode, tile_size: LayerSize, tile_spacing: LayerSize) { + let tile_repeat = tile_size + tile_spacing; + let radial_gradient_cpu = RadialGradientPrimitiveCpu { stops_range: stops, extend_mode: extend_mode, cache_dirty: true, gpu_data_address: GpuStoreAddress(0), gpu_data_count: 0, - }; - - let radial_gradient_gpu = RadialGradientPrimitiveGpu { - start_center: start_center, - end_center: end_center, - start_radius: start_radius, - end_radius: end_radius, - ratio_xy: ratio_xy, - extend_mode: pack_as_float(extend_mode as u32), - tile_size: tile_size, - tile_repeat: tile_size + tile_spacing, - padding: [0.0, 0.0, 0.0, 0.0], + gpu_blocks: [ + [start_center.x, start_center.y, end_center.x, end_center.y].into(), + [start_radius, end_radius, ratio_xy, pack_as_float(extend_mode as u32)].into(), + [tile_size.width, tile_size.height, tile_repeat.width, tile_repeat.height].into(), + ], }; self.add_primitive(clip_and_scroll, &rect, clip_region, &[], - PrimitiveContainer::RadialGradient(radial_gradient_cpu, radial_gradient_gpu)); + PrimitiveContainer::RadialGradient(radial_gradient_cpu)); } pub fn add_text(&mut self, @@ -1464,7 +1455,6 @@ impl FrameBuilder { render_task_data: render_tasks.render_task_data, gpu_data16: self.prim_store.gpu_data16.build(), gpu_data32: self.prim_store.gpu_data32.build(), - gpu_data64: self.prim_store.gpu_data64.build(), gpu_geometry: self.prim_store.gpu_geometry.build(), gpu_gradient_data: self.prim_store.gpu_gradient_data.build(), gpu_split_geometry: self.prim_store.gpu_split_geometry.build(), diff --git a/webrender/src/internal_types.rs b/webrender/src/internal_types.rs index 9796f68522..c161d17e57 100644 --- a/webrender/src/internal_types.rs +++ b/webrender/src/internal_types.rs @@ -69,7 +69,6 @@ pub enum TextureSampler { CacheRGBA8, Data16, Data32, - Data64, ResourceCache, Layers, RenderTasks, diff --git a/webrender/src/prim_store.rs b/webrender/src/prim_store.rs index b617c70421..8aa639645c 100644 --- a/webrender/src/prim_store.rs +++ b/webrender/src/prim_store.rs @@ -294,17 +294,6 @@ pub struct GradientStopGpu { padding: [f32; 3], } -#[derive(Debug, Clone)] -#[repr(C)] -pub struct GradientPrimitiveGpu { - pub start_point: LayerPoint, - pub end_point: LayerPoint, - pub tile_size: LayerSize, - pub tile_repeat: LayerSize, - pub extend_mode: f32, - pub padding: [f32; 7], -} - #[derive(Debug)] pub struct GradientPrimitiveCpu { pub stops_range: ItemRange, @@ -314,20 +303,13 @@ pub struct GradientPrimitiveCpu { pub cache_dirty: bool, pub gpu_data_address: GpuStoreAddress, pub gpu_data_count: i32, + pub gpu_blocks: [GpuBlockData; 3], } -#[derive(Debug, Clone)] -#[repr(C)] -pub struct RadialGradientPrimitiveGpu { - pub start_center: LayerPoint, - pub end_center: LayerPoint, - pub start_radius: f32, - pub end_radius: f32, - pub ratio_xy: f32, - pub extend_mode: f32, - pub tile_size: LayerSize, - pub tile_repeat: LayerSize, - pub padding: [f32; 4], +impl ToGpuBlocks for GradientPrimitiveCpu { + fn write_gpu_blocks(&self, blocks: &mut Vec) { + blocks.extend_from_slice(&self.gpu_blocks); + } } #[derive(Debug)] @@ -337,6 +319,13 @@ pub struct RadialGradientPrimitiveCpu { pub cache_dirty: bool, pub gpu_data_address: GpuStoreAddress, pub gpu_data_count: i32, + pub gpu_blocks: [GpuBlockData; 3], +} + +impl ToGpuBlocks for RadialGradientPrimitiveCpu { + fn write_gpu_blocks(&self, blocks: &mut Vec) { + blocks.extend_from_slice(&self.gpu_blocks); + } } // The gradient entry index for the first color stop @@ -673,9 +662,9 @@ pub enum PrimitiveContainer { Image(ImagePrimitiveCpu), YuvImage(YuvImagePrimitiveCpu), Border(BorderPrimitiveCpu), - AlignedGradient(GradientPrimitiveCpu, GradientPrimitiveGpu), - AngleGradient(GradientPrimitiveCpu, GradientPrimitiveGpu), - RadialGradient(RadialGradientPrimitiveCpu, RadialGradientPrimitiveGpu), + AlignedGradient(GradientPrimitiveCpu), + AngleGradient(GradientPrimitiveCpu), + RadialGradient(RadialGradientPrimitiveCpu), BoxShadow(BoxShadowPrimitiveCpu), } @@ -696,7 +685,6 @@ pub struct PrimitiveStore { pub gpu_geometry: VertexDataStore, pub gpu_data16: VertexDataStore, pub gpu_data32: VertexDataStore, - pub gpu_data64: VertexDataStore, pub gpu_gradient_data: GradientDataStore, /// Geometry generated by plane splitting. @@ -726,7 +714,6 @@ impl PrimitiveStore { gpu_geometry: VertexDataStore::new(), gpu_data16: VertexDataStore::new(), gpu_data32: VertexDataStore::new(), - gpu_data64: VertexDataStore::new(), gpu_gradient_data: GradientDataStore::new(), gpu_split_geometry: SplitGeometryStore::new(), gpu_resource_rects: VertexDataStore::new(), @@ -749,7 +736,6 @@ impl PrimitiveStore { gpu_geometry: self.gpu_geometry.recycle(), gpu_data16: self.gpu_data16.recycle(), gpu_data32: self.gpu_data32.recycle(), - gpu_data64: self.gpu_data64.recycle(), gpu_gradient_data: self.gpu_gradient_data.recycle(), gpu_split_geometry: self.gpu_split_geometry.recycle(), gpu_resource_rects: self.gpu_resource_rects.recycle(), @@ -862,8 +848,7 @@ impl PrimitiveStore { self.cpu_borders.push(border_cpu); metadata } - PrimitiveContainer::AlignedGradient(mut gradient_cpu, gradient_gpu) => { - let gpu_address = self.gpu_data64.push(gradient_gpu); + PrimitiveContainer::AlignedGradient(mut gradient_cpu) => { let gpu_stops_address = self.gpu_data32.alloc(gradient_cpu.stops_count); gradient_cpu.gpu_data_address = gpu_stops_address; @@ -876,7 +861,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::AlignedGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_gradients.len()), - gpu_location: GpuLocation::GpuStore(gpu_address), + gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), render_task: None, clip_task: None, }; @@ -884,8 +869,7 @@ impl PrimitiveStore { self.cpu_gradients.push(gradient_cpu); metadata } - PrimitiveContainer::AngleGradient(mut gradient_cpu, gradient_gpu) => { - let gpu_address = self.gpu_data64.push(gradient_gpu); + PrimitiveContainer::AngleGradient(mut gradient_cpu) => { let gpu_gradient_address = self.gpu_gradient_data.alloc(1); gradient_cpu.gpu_data_address = gpu_gradient_address; @@ -898,7 +882,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::AngleGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_gradients.len()), - gpu_location: GpuLocation::GpuStore(gpu_address), + gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), render_task: None, clip_task: None, }; @@ -906,8 +890,7 @@ impl PrimitiveStore { self.cpu_gradients.push(gradient_cpu); metadata } - PrimitiveContainer::RadialGradient(mut radial_gradient_cpu, radial_gradient_gpu) => { - let gpu_address = self.gpu_data64.push(radial_gradient_gpu); + PrimitiveContainer::RadialGradient(mut radial_gradient_cpu) => { let gpu_gradient_address = self.gpu_gradient_data.alloc(1); radial_gradient_cpu.gpu_data_address = gpu_gradient_address; @@ -920,7 +903,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::RadialGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_radial_gradients.len()), - gpu_location: GpuLocation::GpuStore(gpu_address), + gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), render_task: None, clip_task: None, }; @@ -1203,6 +1186,8 @@ impl PrimitiveStore { if let GpuLocation::GpuCache(ref mut cache_id) = metadata.gpu_location { let cpu_borders = &self.cpu_borders; let cpu_box_shadows = &self.cpu_box_shadows; + let cpu_gradients = &self.cpu_gradients; + let cpu_radial_gradients = &self.cpu_radial_gradients; let cpu_images = &self.cpu_images; let cpu_yuv_images = &self.cpu_yuv_images; let cpu_rectangles = &self.cpu_rectangles; @@ -1232,6 +1217,15 @@ impl PrimitiveStore { let yuv_image = &cpu_yuv_images[cpu_prim_index.0]; yuv_image.write_gpu_blocks(blocks); } + PrimitiveKind::AlignedGradient | + PrimitiveKind::AngleGradient => { + let gradient = &cpu_gradients[cpu_prim_index.0]; + gradient.write_gpu_blocks(blocks); + } + PrimitiveKind::RadialGradient => { + let gradient = &cpu_radial_gradients[cpu_prim_index.0]; + gradient.write_gpu_blocks(blocks); + } _ => { unreachable!("Encountered a type not supported by GPU cache!"); } @@ -1483,10 +1477,6 @@ define_gpu_block!(GpuBlock32: [f32; 8] = GradientStopGpu, ClipCorner, ClipRect, ImageMaskData, BorderCornerClipData, BorderCornerDashClipData, BorderCornerDotClipData ); -define_gpu_block!(GpuBlock64: [f32; 16] = - GradientPrimitiveGpu, RadialGradientPrimitiveGpu -); - //Test for one clip region contains another trait InsideTest { diff --git a/webrender/src/renderer.rs b/webrender/src/renderer.rs index bbde84d202..263a75c7cd 100644 --- a/webrender/src/renderer.rs +++ b/webrender/src/renderer.rs @@ -533,7 +533,6 @@ struct GpuDataTextures { prim_geom_texture: VertexDataTexture, data16_texture: VertexDataTexture, data32_texture: VertexDataTexture, - data64_texture: VertexDataTexture, resource_rects_texture: VertexDataTexture, gradient_data_texture: GradientDataTexture, split_geometry_texture: SplitGeometryTexture, @@ -547,7 +546,6 @@ impl GpuDataTextures { prim_geom_texture: VertexDataTexture::new(device), data16_texture: VertexDataTexture::new(device), data32_texture: VertexDataTexture::new(device), - data64_texture: VertexDataTexture::new(device), resource_rects_texture: VertexDataTexture::new(device), gradient_data_texture: GradientDataTexture::new(device), split_geometry_texture: SplitGeometryTexture::new(device), @@ -557,7 +555,6 @@ impl GpuDataTextures { fn init_frame(&mut self, device: &mut Device, frame: &mut Frame) { self.data16_texture.init(device, &mut frame.gpu_data16); self.data32_texture.init(device, &mut frame.gpu_data32); - self.data64_texture.init(device, &mut frame.gpu_data64); self.prim_geom_texture.init(device, &mut frame.gpu_geometry); self.resource_rects_texture.init(device, &mut frame.gpu_resource_rects); self.layer_texture.init(device, &mut frame.layer_texture_data); @@ -570,7 +567,6 @@ impl GpuDataTextures { device.bind_texture(TextureSampler::Geometry, self.prim_geom_texture.id); device.bind_texture(TextureSampler::Data16, self.data16_texture.id); device.bind_texture(TextureSampler::Data32, self.data32_texture.id); - device.bind_texture(TextureSampler::Data64, self.data64_texture.id); device.bind_texture(TextureSampler::ResourceRects, self.resource_rects_texture.id); device.bind_texture(TextureSampler::Gradients, self.gradient_data_texture.id); device.bind_texture(TextureSampler::SplitGeometry, self.split_geometry_texture.id); diff --git a/webrender/src/tiling.rs b/webrender/src/tiling.rs index c0e3af74ff..340e4a0b71 100644 --- a/webrender/src/tiling.rs +++ b/webrender/src/tiling.rs @@ -12,7 +12,7 @@ use internal_types::{ANGLE_FLOAT_TO_FIXED, BatchTextures, CacheTextureId, LowLev use internal_types::SourceTexture; use mask_cache::MaskCacheInfo; use prim_store::{CLIP_DATA_GPU_SIZE, DeferredResolve, GpuBlock16, GpuBlock32}; -use prim_store::{GpuBlock64, GradientData, SplitGeometry, PrimitiveCacheKey, PrimitiveGeometry}; +use prim_store::{GradientData, SplitGeometry, PrimitiveCacheKey, PrimitiveGeometry}; use prim_store::{PrimitiveIndex, PrimitiveKind, PrimitiveMetadata, PrimitiveStore, TexelRect}; use profiler::FrameProfileCounters; use render_task::{AlphaRenderItem, MaskGeometryKind, MaskSegment, RenderTask, RenderTaskData}; @@ -1619,7 +1619,6 @@ pub struct Frame { pub render_task_data: Vec, pub gpu_data16: Vec, pub gpu_data32: Vec, - pub gpu_data64: Vec, pub gpu_geometry: Vec, pub gpu_gradient_data: Vec, pub gpu_split_geometry: Vec, From 96321b8153c230d1600f4d5acef06bc683ea9dd5 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 2 Jun 2017 12:32:36 +1000 Subject: [PATCH 2/3] Switch TextRun over to use GPU cache for main primitive. --- webrender/res/prim_shared.glsl | 4 ++-- webrender/src/frame_builder.rs | 8 ++------ webrender/src/prim_store.rs | 27 ++++++++++++++------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/webrender/res/prim_shared.glsl b/webrender/res/prim_shared.glsl index f48e6eb573..4150713cac 100644 --- a/webrender/res/prim_shared.glsl +++ b/webrender/res/prim_shared.glsl @@ -784,8 +784,8 @@ struct TextRun { vec4 color; }; -TextRun fetch_text_run(int index) { - vec4 data = fetch_data_1(index); +TextRun fetch_text_run(int address) { + vec4 data = fetch_from_resource_cache_1(address); return TextRun(data); } diff --git a/webrender/src/frame_builder.rs b/webrender/src/frame_builder.rs index c871eaf9d7..a2938e50bc 100644 --- a/webrender/src/frame_builder.rs +++ b/webrender/src/frame_builder.rs @@ -11,7 +11,7 @@ use plane_split::{BspSplitter, Polygon, Splitter}; use prim_store::{GradientPrimitiveCpu, ImagePrimitiveCpu}; use prim_store::{ImagePrimitiveKind, PrimitiveContainer, PrimitiveGeometry, PrimitiveIndex}; use prim_store::{PrimitiveStore, RadialGradientPrimitiveCpu}; -use prim_store::{RectanglePrimitive, SplitGeometry, TextRunPrimitiveCpu, TextRunPrimitiveGpu}; +use prim_store::{RectanglePrimitive, SplitGeometry, TextRunPrimitiveCpu}; use prim_store::{BoxShadowPrimitiveCpu, TexelRect, YuvImagePrimitiveCpu}; use profiler::{FrameProfileCounters, GpuCacheProfileCounters, TextureCacheProfileCounters}; use render_task::{AlphaRenderItem, MaskCacheKey, MaskResult, RenderTask, RenderTaskIndex}; @@ -780,15 +780,11 @@ impl FrameBuilder { gpu_data_count: 0, }; - let prim_gpu = TextRunPrimitiveGpu { - color: *color, - }; - self.add_primitive(clip_and_scroll, &rect, clip_region, &[], - PrimitiveContainer::TextRun(prim_cpu, prim_gpu)); + PrimitiveContainer::TextRun(prim_cpu)); } pub fn fill_box_shadow_rect(&mut self, diff --git a/webrender/src/prim_store.rs b/webrender/src/prim_store.rs index 8aa639645c..dc33c66ca1 100644 --- a/webrender/src/prim_store.rs +++ b/webrender/src/prim_store.rs @@ -497,12 +497,6 @@ struct InstanceRect { rect: LayerRect, } -#[derive(Debug, Clone)] -#[repr(C)] -pub struct TextRunPrimitiveGpu { - pub color: ColorF, -} - #[derive(Debug, Clone)] pub struct TextRunPrimitiveCpu { pub font_key: FontKey, @@ -522,6 +516,12 @@ pub struct TextRunPrimitiveCpu { pub gpu_data_count: i32, } +impl ToGpuBlocks for TextRunPrimitiveCpu { + fn write_gpu_blocks(&self, blocks: &mut Vec) { + blocks.push(self.color.into()); + } +} + #[derive(Debug, Clone)] #[repr(C)] struct GlyphPrimitive { @@ -658,7 +658,7 @@ impl ClipData { #[derive(Debug)] pub enum PrimitiveContainer { Rectangle(RectanglePrimitive), - TextRun(TextRunPrimitiveCpu, TextRunPrimitiveGpu), + TextRun(TextRunPrimitiveCpu), Image(ImagePrimitiveCpu), YuvImage(YuvImagePrimitiveCpu), Border(BorderPrimitiveCpu), @@ -778,8 +778,7 @@ impl PrimitiveStore { metadata } - PrimitiveContainer::TextRun(mut text_cpu, text_gpu) => { - let gpu_address = self.gpu_data16.push(text_gpu); + PrimitiveContainer::TextRun(mut text_cpu) => { let gpu_glyphs_address = self.gpu_data16.alloc(text_cpu.glyph_count); text_cpu.resource_address = self.gpu_resource_rects.alloc(text_cpu.glyph_count); text_cpu.gpu_data_address = gpu_glyphs_address; @@ -791,7 +790,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::TextRun, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_text_runs.len()), - gpu_location: GpuLocation::GpuStore(gpu_address), + gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), render_task: None, clip_task: None, }; @@ -1191,6 +1190,7 @@ impl PrimitiveStore { let cpu_images = &self.cpu_images; let cpu_yuv_images = &self.cpu_yuv_images; let cpu_rectangles = &self.cpu_rectangles; + let cpu_text_runs = &self.cpu_text_runs; let cpu_prim_index = metadata.cpu_prim_index; let prim_kind = metadata.prim_kind; @@ -1226,8 +1226,9 @@ impl PrimitiveStore { let gradient = &cpu_radial_gradients[cpu_prim_index.0]; gradient.write_gpu_blocks(blocks); } - _ => { - unreachable!("Encountered a type not supported by GPU cache!"); + PrimitiveKind::TextRun => { + let text = &cpu_text_runs[cpu_prim_index.0]; + text.write_gpu_blocks(blocks); } } }); @@ -1471,7 +1472,7 @@ macro_rules! define_gpu_block { } define_gpu_block!(GpuBlock16: [f32; 4] = - RectanglePrimitive, InstanceRect, GlyphPrimitive, TextRunPrimitiveGpu + InstanceRect, GlyphPrimitive ); define_gpu_block!(GpuBlock32: [f32; 8] = GradientStopGpu, ClipCorner, ClipRect, ImageMaskData, From 8ab8e3760984bbed646743f5326727517d09a4d9 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Fri, 2 Jun 2017 12:43:17 +1000 Subject: [PATCH 3/3] Remove temporary GpuLocation enum as it's no longer required. --- webrender/src/prim_store.rs | 162 ++++++++++++++++-------------------- 1 file changed, 73 insertions(+), 89 deletions(-) diff --git a/webrender/src/prim_store.rs b/webrender/src/prim_store.rs index dc33c66ca1..d56d7a45fe 100644 --- a/webrender/src/prim_store.rs +++ b/webrender/src/prim_store.rs @@ -111,30 +111,14 @@ pub enum PrimitiveCacheKey { TextShadow(PrimitiveIndex), } -// TODO(gw): This enum is temporary. It allows primitives to use either -// the GPU store or the GPU cache. Once all primitives are -// ported to use the GPU cache, we should remove this enum! -#[derive(Debug)] -pub enum GpuLocation { - GpuCache(GpuCacheHandle), - GpuStore(GpuStoreAddress), -} - -impl GpuLocation { +impl GpuCacheHandle { pub fn as_int(&self, gpu_cache: &GpuCache) -> i32 { - match *self { - GpuLocation::GpuCache(cache_id) => { - let address = gpu_cache.get_address(&cache_id); - - // TODO(gw): Temporarily encode GPU Cache addresses as a single int. - // In the future, we can change the PrimitiveInstance struct - // to use 2x u16 for the vertex attribute instead of an i32. - address.v as i32 * MAX_VERTEX_TEXTURE_WIDTH as i32 + address.u as i32 - } - GpuLocation::GpuStore(address) => { - address.0 - } - } + let address = gpu_cache.get_address(self); + + // TODO(gw): Temporarily encode GPU Cache addresses as a single int. + // In the future, we can change the PrimitiveInstance struct + // to use 2x u16 for the vertex attribute instead of an i32. + address.v as i32 * MAX_VERTEX_TEXTURE_WIDTH as i32 + address.u as i32 } } @@ -146,7 +130,7 @@ pub struct PrimitiveMetadata { pub clip_cache_info: Option, pub prim_kind: PrimitiveKind, pub cpu_prim_index: SpecificPrimitiveIndex, - pub gpu_location: GpuLocation, + pub gpu_location: GpuCacheHandle, // An optional render task that is a dependency of // drawing this primitive. For instance, box shadows // use this to draw a portion of the box shadow to @@ -769,7 +753,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::Rectangle, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_rectangles.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -790,7 +774,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::TextRun, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_text_runs.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -807,7 +791,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::Image, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_images.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -824,7 +808,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::YuvImage, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_yuv_images.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -839,7 +823,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::Border, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_borders.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -860,7 +844,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::AlignedGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_gradients.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -881,7 +865,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::AngleGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_gradients.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -902,7 +886,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::RadialGradient, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_radial_gradients.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: None, clip_task: None, }; @@ -942,7 +926,7 @@ impl PrimitiveStore { clip_cache_info: clip_info, prim_kind: PrimitiveKind::BoxShadow, cpu_prim_index: SpecificPrimitiveIndex(self.cpu_box_shadows.len()), - gpu_location: GpuLocation::GpuCache(GpuCacheHandle::new()), + gpu_location: GpuCacheHandle::new(), render_task: Some(render_task), clip_task: None, }; @@ -1182,57 +1166,57 @@ impl PrimitiveStore { let mut prim_needs_resolve = false; let mut rebuild_bounding_rect = false; - if let GpuLocation::GpuCache(ref mut cache_id) = metadata.gpu_location { - let cpu_borders = &self.cpu_borders; - let cpu_box_shadows = &self.cpu_box_shadows; - let cpu_gradients = &self.cpu_gradients; - let cpu_radial_gradients = &self.cpu_radial_gradients; - let cpu_images = &self.cpu_images; - let cpu_yuv_images = &self.cpu_yuv_images; - let cpu_rectangles = &self.cpu_rectangles; - let cpu_text_runs = &self.cpu_text_runs; - let cpu_prim_index = metadata.cpu_prim_index; - let prim_kind = metadata.prim_kind; - - // Mark this GPU resource as required for this frame. - resource_cache.gpu_cache.request(cache_id, |blocks| { - match prim_kind { - PrimitiveKind::Rectangle => { - let rect = &cpu_rectangles[cpu_prim_index.0]; - rect.write_gpu_blocks(blocks); - } - PrimitiveKind::Border => { - let border = &cpu_borders[cpu_prim_index.0]; - border.write_gpu_blocks(blocks); - } - PrimitiveKind::BoxShadow => { - let box_shadow = &cpu_box_shadows[cpu_prim_index.0]; - box_shadow.write_gpu_blocks(blocks); - } - PrimitiveKind::Image => { - let image = &cpu_images[cpu_prim_index.0]; - image.write_gpu_blocks(blocks); - } - PrimitiveKind::YuvImage => { - let yuv_image = &cpu_yuv_images[cpu_prim_index.0]; - yuv_image.write_gpu_blocks(blocks); - } - PrimitiveKind::AlignedGradient | - PrimitiveKind::AngleGradient => { - let gradient = &cpu_gradients[cpu_prim_index.0]; - gradient.write_gpu_blocks(blocks); - } - PrimitiveKind::RadialGradient => { - let gradient = &cpu_radial_gradients[cpu_prim_index.0]; - gradient.write_gpu_blocks(blocks); - } - PrimitiveKind::TextRun => { - let text = &cpu_text_runs[cpu_prim_index.0]; - text.write_gpu_blocks(blocks); - } + // TODO(gw): Restructure this code so the borrow checker + // doesn't force the locals below! + let cpu_borders = &self.cpu_borders; + let cpu_box_shadows = &self.cpu_box_shadows; + let cpu_gradients = &mut self.cpu_gradients; + let cpu_radial_gradients = &mut self.cpu_radial_gradients; + let cpu_images = &mut self.cpu_images; + let cpu_yuv_images = &mut self.cpu_yuv_images; + let cpu_rectangles = &self.cpu_rectangles; + let cpu_text_runs = &mut self.cpu_text_runs; + let cpu_prim_index = metadata.cpu_prim_index; + let prim_kind = metadata.prim_kind; + + // Mark this GPU resource as required for this frame. + resource_cache.gpu_cache.request(&mut metadata.gpu_location, |blocks| { + match prim_kind { + PrimitiveKind::Rectangle => { + let rect = &cpu_rectangles[cpu_prim_index.0]; + rect.write_gpu_blocks(blocks); } - }); - } + PrimitiveKind::Border => { + let border = &cpu_borders[cpu_prim_index.0]; + border.write_gpu_blocks(blocks); + } + PrimitiveKind::BoxShadow => { + let box_shadow = &cpu_box_shadows[cpu_prim_index.0]; + box_shadow.write_gpu_blocks(blocks); + } + PrimitiveKind::Image => { + let image = &cpu_images[cpu_prim_index.0]; + image.write_gpu_blocks(blocks); + } + PrimitiveKind::YuvImage => { + let yuv_image = &cpu_yuv_images[cpu_prim_index.0]; + yuv_image.write_gpu_blocks(blocks); + } + PrimitiveKind::AlignedGradient | + PrimitiveKind::AngleGradient => { + let gradient = &cpu_gradients[cpu_prim_index.0]; + gradient.write_gpu_blocks(blocks); + } + PrimitiveKind::RadialGradient => { + let gradient = &cpu_radial_gradients[cpu_prim_index.0]; + gradient.write_gpu_blocks(blocks); + } + PrimitiveKind::TextRun => { + let text = &cpu_text_runs[cpu_prim_index.0]; + text.write_gpu_blocks(blocks); + } + } + }); if let Some(ref mut clip_info) = metadata.clip_cache_info { clip_info.update(&metadata.clips, @@ -1267,7 +1251,7 @@ impl PrimitiveStore { metadata.render_task.as_mut().unwrap().location = location; } PrimitiveKind::TextRun => { - let text = &mut self.cpu_text_runs[metadata.cpu_prim_index.0]; + let text = &mut cpu_text_runs[metadata.cpu_prim_index.0]; let font_size_dp = text.logical_font_size.scale_by(device_pixel_ratio); let src_glyphs = display_list.get(text.glyph_range); @@ -1362,7 +1346,7 @@ impl PrimitiveStore { text.glyph_options); } PrimitiveKind::Image => { - let image_cpu = &mut self.cpu_images[metadata.cpu_prim_index.0]; + let image_cpu = &mut cpu_images[metadata.cpu_prim_index.0]; prim_needs_resolve = true; match image_cpu.kind { @@ -1382,7 +1366,7 @@ impl PrimitiveStore { } } PrimitiveKind::YuvImage => { - let image_cpu = &mut self.cpu_yuv_images[metadata.cpu_prim_index.0]; + let image_cpu = &mut cpu_yuv_images[metadata.cpu_prim_index.0]; prim_needs_resolve = true; let channel_num = image_cpu.format.get_plane_num(); @@ -1395,7 +1379,7 @@ impl PrimitiveStore { metadata.is_opaque = true; } PrimitiveKind::AlignedGradient => { - let gradient = &mut self.cpu_gradients[metadata.cpu_prim_index.0]; + let gradient = &mut cpu_gradients[metadata.cpu_prim_index.0]; if gradient.cache_dirty { let src_stops = display_list.get(gradient.stops_range); @@ -1415,7 +1399,7 @@ impl PrimitiveStore { } } PrimitiveKind::AngleGradient => { - let gradient = &mut self.cpu_gradients[metadata.cpu_prim_index.0]; + let gradient = &mut cpu_gradients[metadata.cpu_prim_index.0]; if gradient.cache_dirty { let src_stops = display_list.get(gradient.stops_range); @@ -1425,7 +1409,7 @@ impl PrimitiveStore { } } PrimitiveKind::RadialGradient => { - let gradient = &mut self.cpu_radial_gradients[metadata.cpu_prim_index.0]; + let gradient = &mut cpu_radial_gradients[metadata.cpu_prim_index.0]; if gradient.cache_dirty { let src_stops = display_list.get(gradient.stops_range);