Unify solid tiles and render target tiles.

This commit also removes old shaders from the manifest.
This commit is contained in:
Patrick Walton 2020-03-05 12:22:01 -08:00
parent 9935c9fdff
commit 2548ab853a
45 changed files with 350 additions and 2024 deletions

View File

@ -13,10 +13,10 @@
use crate::concurrent::executor::Executor; use crate::concurrent::executor::Executor;
use crate::gpu::renderer::{BlendModeProgram, MASK_TILES_ACROSS}; use crate::gpu::renderer::{BlendModeProgram, MASK_TILES_ACROSS};
use crate::gpu_data::{AlphaTile, AlphaTileBatch, AlphaTileVertex, FillBatchPrimitive, MaskTile}; use crate::gpu_data::{AlphaTile, AlphaTileBatch, AlphaTileVertex, FillBatchPrimitive, MaskTile};
use crate::gpu_data::{MaskTileVertex, RenderCommand, RenderTargetTile, RenderTargetTileBatch}; use crate::gpu_data::{MaskTileVertex, RenderCommand, SolidTile, SolidTileBatch};
use crate::gpu_data::{RenderTargetTileVertex, SolidTileBatch, TexturePageId, TileObjectPrimitive}; use crate::gpu_data::{TexturePageId, TileObjectPrimitive};
use crate::options::{PreparedBuildOptions, RenderCommandListener}; use crate::options::{PreparedBuildOptions, RenderCommandListener};
use crate::paint::{PaintInfo, PaintMetadata}; use crate::paint::{PaintInfo, PaintMetadata, RenderTargetMetadata};
use crate::scene::{DisplayItem, Scene}; use crate::scene::{DisplayItem, Scene};
use crate::tile_map::DenseTileMap; use crate::tile_map::DenseTileMap;
use crate::tiles::{self, DrawTilingPathInfo, TILE_HEIGHT, TILE_WIDTH, Tiler, TilingPathInfo}; use crate::tiles::{self, DrawTilingPathInfo, TILE_HEIGHT, TILE_WIDTH, Tiler, TilingPathInfo};
@ -63,13 +63,13 @@ struct BuiltDrawPath {
pub(crate) struct BuiltPath { pub(crate) struct BuiltPath {
pub mask_tiles: Vec<MaskTile>, pub mask_tiles: Vec<MaskTile>,
pub alpha_tiles: Vec<AlphaTile>, pub alpha_tiles: Vec<AlphaTile>,
pub solid_tiles: Vec<SolidTile>, pub solid_tiles: Vec<SolidTileInfo>,
pub tiles: DenseTileMap<TileObjectPrimitive>, pub tiles: DenseTileMap<TileObjectPrimitive>,
pub fill_rule: FillRule, pub fill_rule: FillRule,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub(crate) struct SolidTile { pub(crate) struct SolidTileInfo {
pub(crate) coords: Vector2I, pub(crate) coords: Vector2I,
} }
@ -111,7 +111,8 @@ impl<'a> SceneBuilder<'a> {
// Build paint data. // Build paint data.
let PaintInfo { let PaintInfo {
render_commands, render_commands,
metadata: paint_metadata, paint_metadata,
render_target_metadata,
} = self.scene.build_paint_info(); } = self.scene.build_paint_info();
for render_command in render_commands { for render_command in render_commands {
self.listener.send(render_command); self.listener.send(render_command);
@ -132,7 +133,10 @@ impl<'a> SceneBuilder<'a> {
&built_clip_paths) &built_clip_paths)
}); });
self.finish_building(&paint_metadata, built_clip_paths, built_draw_paths); self.finish_building(&paint_metadata,
&render_target_metadata,
built_clip_paths,
built_draw_paths);
let build_time = Instant::now() - start_time; let build_time = Instant::now() - start_time;
self.listener.send(RenderCommand::Finish { build_time }); self.listener.send(RenderCommand::Finish { build_time });
@ -197,13 +201,14 @@ impl<'a> SceneBuilder<'a> {
BuiltDrawPath { BuiltDrawPath {
path: tiler.object_builder.built_path, path: tiler.object_builder.built_path,
blend_mode: path_object.blend_mode(), blend_mode: path_object.blend_mode(),
color_texture_page: paint_metadata.texture_page, color_texture_page: paint_metadata.location.page,
sampling_flags: paint_metadata.sampling_flags, sampling_flags: paint_metadata.sampling_flags,
} }
} }
fn cull_tiles(&self, fn cull_tiles(&self,
paint_metadata: &[PaintMetadata], paint_metadata: &[PaintMetadata],
render_target_metadata: &[RenderTargetMetadata],
built_clip_paths: Vec<BuiltPath>, built_clip_paths: Vec<BuiltPath>,
built_draw_paths: Vec<BuiltDrawPath>) built_draw_paths: Vec<BuiltDrawPath>)
-> CulledTiles { -> CulledTiles {
@ -254,17 +259,28 @@ impl<'a> SceneBuilder<'a> {
let tile_rect = tiles::round_rect_out_to_tile_bounds(effective_view_box); let tile_rect = tiles::round_rect_out_to_tile_bounds(effective_view_box);
let layer_z_buffer = layer_z_buffers_stack.last().unwrap(); let layer_z_buffer = layer_z_buffers_stack.last().unwrap();
let mut tiles = vec![]; let mut tiles = vec![];
let uv_scale = Vector2F::splat(1.0) / tile_rect.lower_right().to_f32();
let metadata = &render_target_metadata[render_target.0 as usize];
for tile_y in tile_rect.min_y()..tile_rect.max_y() { for tile_y in tile_rect.min_y()..tile_rect.max_y() {
for tile_x in tile_rect.min_x()..tile_rect.max_x() { for tile_x in tile_rect.min_x()..tile_rect.max_x() {
let tile_coords = Vector2I::new(tile_x, tile_y); let tile_coords = Vector2I::new(tile_x, tile_y);
if layer_z_buffer.test(tile_coords, current_depth) { if !layer_z_buffer.test(tile_coords, current_depth) {
tiles.push(RenderTargetTile::new(tile_coords)); continue;
}
let uv_rect =
RectI::new(tile_coords, Vector2I::splat(1)).to_f32()
.scale_xy(uv_scale);
tiles.push(SolidTile::from_texture_rect(tile_coords, uv_rect));
} }
} }
} let batch = SolidTileBatch {
let batch = RenderTargetTileBatch { tiles, render_target, effects }; tiles,
culled_tiles.display_list color_texture_page: metadata.location.page,
.push(CulledDisplayItem::DrawRenderTargetTiles(batch)); sampling_flags: TextureSamplingFlags::empty(),
effects,
};
culled_tiles.display_list.push(CulledDisplayItem::DrawSolidTiles(batch));
current_depth += 1; current_depth += 1;
} }
@ -396,9 +412,6 @@ impl<'a> SceneBuilder<'a> {
CulledDisplayItem::DrawAlphaTiles(batch) => { CulledDisplayItem::DrawAlphaTiles(batch) => {
self.listener.send(RenderCommand::DrawAlphaTiles(batch)) self.listener.send(RenderCommand::DrawAlphaTiles(batch))
} }
CulledDisplayItem::DrawRenderTargetTiles(batch) => {
self.listener.send(RenderCommand::DrawRenderTargetTiles(batch))
}
CulledDisplayItem::PushRenderTarget(render_target_id) => { CulledDisplayItem::PushRenderTarget(render_target_id) => {
self.listener.send(RenderCommand::PushRenderTarget(render_target_id)) self.listener.send(RenderCommand::PushRenderTarget(render_target_id))
} }
@ -411,10 +424,14 @@ impl<'a> SceneBuilder<'a> {
fn finish_building(&mut self, fn finish_building(&mut self,
paint_metadata: &[PaintMetadata], paint_metadata: &[PaintMetadata],
render_target_metadata: &[RenderTargetMetadata],
built_clip_paths: Vec<BuiltPath>, built_clip_paths: Vec<BuiltPath>,
built_draw_paths: Vec<BuiltDrawPath>) { built_draw_paths: Vec<BuiltDrawPath>) {
self.listener.send(RenderCommand::FlushFills); self.listener.send(RenderCommand::FlushFills);
let culled_tiles = self.cull_tiles(paint_metadata, built_clip_paths, built_draw_paths); let culled_tiles = self.cull_tiles(paint_metadata,
render_target_metadata,
built_clip_paths,
built_draw_paths);
self.pack_tiles(culled_tiles); self.pack_tiles(culled_tiles);
} }
@ -460,10 +477,10 @@ impl BuiltPath {
} }
} }
impl SolidTile { impl SolidTileInfo {
#[inline] #[inline]
pub(crate) fn new(coords: Vector2I) -> SolidTile { pub(crate) fn new(coords: Vector2I) -> SolidTileInfo {
SolidTile { coords } SolidTileInfo { coords }
} }
} }
@ -476,7 +493,6 @@ struct CulledTiles {
enum CulledDisplayItem { enum CulledDisplayItem {
DrawSolidTiles(SolidTileBatch), DrawSolidTiles(SolidTileBatch),
DrawAlphaTiles(AlphaTileBatch), DrawAlphaTiles(AlphaTileBatch),
DrawRenderTargetTiles(RenderTargetTileBatch),
PushRenderTarget(RenderTargetId), PushRenderTarget(RenderTargetId),
PopRenderTarget, PopRenderTarget,
} }
@ -795,20 +811,3 @@ impl CulledTiles {
} }
} }
} }
impl RenderTargetTile {
fn new(tile_coords: Vector2I) -> RenderTargetTile {
RenderTargetTile {
upper_left: RenderTargetTileVertex::new(tile_coords),
upper_right: RenderTargetTileVertex::new(tile_coords + Vector2I::new(1, 0)),
lower_left: RenderTargetTileVertex::new(tile_coords + Vector2I::new(0, 1)),
lower_right: RenderTargetTileVertex::new(tile_coords + Vector2I::splat(1)),
}
}
}
impl RenderTargetTileVertex {
fn new(tile_coords: Vector2I) -> RenderTargetTileVertex {
RenderTargetTileVertex { tile_x: tile_coords.x() as i16, tile_y: tile_coords.y() as i16 }
}
}

View File

@ -15,12 +15,10 @@ use crate::gpu::shaders::{AlphaTileHSLProgram, AlphaTileOverlayProgram};
use crate::gpu::shaders::{AlphaTileProgram, AlphaTileVertexArray, BlitProgram, BlitVertexArray}; use crate::gpu::shaders::{AlphaTileProgram, AlphaTileVertexArray, BlitProgram, BlitVertexArray};
use crate::gpu::shaders::{CopyTileProgram, CopyTileVertexArray, FillProgram, FillVertexArray}; use crate::gpu::shaders::{CopyTileProgram, CopyTileVertexArray, FillProgram, FillVertexArray};
use crate::gpu::shaders::{MAX_FILLS_PER_BATCH, MaskTileProgram, MaskTileVertexArray}; use crate::gpu::shaders::{MAX_FILLS_PER_BATCH, MaskTileProgram, MaskTileVertexArray};
use crate::gpu::shaders::{ReprojectionProgram, ReprojectionVertexArray, SolidTileProgram}; use crate::gpu::shaders::{ReprojectionProgram, ReprojectionVertexArray, SolidTileBlurFilterProgram, SolidTileProgram, SolidTileTextFilterProgram};
use crate::gpu::shaders::{SolidTileVertexArray, StencilProgram, StencilVertexArray}; use crate::gpu::shaders::{SolidTileVertexArray, StencilProgram, StencilVertexArray};
use crate::gpu::shaders::{TileFilterBasicProgram, TileFilterBlurProgram, TileFilterProgram}; use crate::gpu_data::{AlphaTile, FillBatchPrimitive, MaskTile, RenderCommand, SolidTile};
use crate::gpu::shaders::{TileFilterTextProgram, TileFilterVertexArray}; use crate::gpu_data::{TextureLocation, TexturePageDescriptor, TexturePageId};
use crate::gpu_data::{AlphaTile, FillBatchPrimitive, MaskTile, RenderCommand, RenderTargetTile};
use crate::gpu_data::{SolidTileVertex, TextureLocation, TexturePageDescriptor, TexturePageId};
use crate::options::BoundingQuad; use crate::options::BoundingQuad;
use crate::tiles::{TILE_HEIGHT, TILE_WIDTH}; use crate::tiles::{TILE_HEIGHT, TILE_WIDTH};
use pathfinder_color::{self as color, ColorF, ColorU}; use pathfinder_color::{self as color, ColorF, ColorU};
@ -83,7 +81,6 @@ where
mask_winding_tile_program: MaskTileProgram<D>, mask_winding_tile_program: MaskTileProgram<D>,
mask_evenodd_tile_program: MaskTileProgram<D>, mask_evenodd_tile_program: MaskTileProgram<D>,
copy_tile_program: CopyTileProgram<D>, copy_tile_program: CopyTileProgram<D>,
solid_tile_program: SolidTileProgram<D>,
alpha_tile_program: AlphaTileProgram<D>, alpha_tile_program: AlphaTileProgram<D>,
alpha_tile_overlay_program: AlphaTileOverlayProgram<D>, alpha_tile_overlay_program: AlphaTileOverlayProgram<D>,
alpha_tile_dodgeburn_program: AlphaTileDodgeBurnProgram<D>, alpha_tile_dodgeburn_program: AlphaTileDodgeBurnProgram<D>,
@ -95,7 +92,6 @@ where
mask_winding_tile_vertex_array: MaskTileVertexArray<D>, mask_winding_tile_vertex_array: MaskTileVertexArray<D>,
mask_evenodd_tile_vertex_array: MaskTileVertexArray<D>, mask_evenodd_tile_vertex_array: MaskTileVertexArray<D>,
copy_tile_vertex_array: CopyTileVertexArray<D>, copy_tile_vertex_array: CopyTileVertexArray<D>,
solid_tile_vertex_array: SolidTileVertexArray<D>,
alpha_tile_vertex_array: AlphaTileVertexArray<D>, alpha_tile_vertex_array: AlphaTileVertexArray<D>,
alpha_tile_overlay_vertex_array: AlphaTileVertexArray<D>, alpha_tile_overlay_vertex_array: AlphaTileVertexArray<D>,
alpha_tile_dodgeburn_vertex_array: AlphaTileVertexArray<D>, alpha_tile_dodgeburn_vertex_array: AlphaTileVertexArray<D>,
@ -123,14 +119,14 @@ where
// used, then the transparent black paint would zero out the alpha mask. // used, then the transparent black paint would zero out the alpha mask.
clear_paint_texture: D::Texture, clear_paint_texture: D::Texture,
// Filter shaders // Solid tiles
tile_filter_basic_program: TileFilterBasicProgram<D>, solid_tile_program: SolidTileProgram<D>,
tile_filter_blur_program: TileFilterBlurProgram<D>, solid_tile_blur_filter_program: SolidTileBlurFilterProgram<D>,
tile_filter_text_program: TileFilterTextProgram<D>, solid_tile_text_filter_program: SolidTileTextFilterProgram<D>,
tile_filter_basic_vertex_array: TileFilterVertexArray<D>, solid_tile_vertex_array: SolidTileVertexArray<D>,
tile_filter_blur_vertex_array: TileFilterVertexArray<D>, solid_tile_blur_filter_vertex_array: SolidTileVertexArray<D>,
tile_filter_text_vertex_array: TileFilterVertexArray<D>, solid_tile_text_filter_vertex_array: SolidTileVertexArray<D>,
tile_filter_vertex_buffer: D::Buffer, solid_tile_vertex_buffer: D::Buffer,
gamma_lut_texture: D::Texture, gamma_lut_texture: D::Texture,
// Stencil shader // Stencil shader
@ -175,7 +171,7 @@ where
&device, &device,
resources); resources);
let copy_tile_program = CopyTileProgram::new(&device, resources); let copy_tile_program = CopyTileProgram::new(&device, resources);
let solid_tile_program = SolidTileProgram::new(&device, resources); let solid_tile_program = SolidTileProgram::new(&device, resources, "tile_solid");
let alpha_tile_program = AlphaTileProgram::new(&device, resources); let alpha_tile_program = AlphaTileProgram::new(&device, resources);
let alpha_tile_overlay_program = AlphaTileOverlayProgram::new(&device, resources); let alpha_tile_overlay_program = AlphaTileOverlayProgram::new(&device, resources);
let alpha_tile_dodgeburn_program = AlphaTileDodgeBurnProgram::new(&device, resources); let alpha_tile_dodgeburn_program = AlphaTileDodgeBurnProgram::new(&device, resources);
@ -188,9 +184,8 @@ where
resources, resources,
"tile_alpha_exclusion"); "tile_alpha_exclusion");
let alpha_tile_hsl_program = AlphaTileHSLProgram::new(&device, resources); let alpha_tile_hsl_program = AlphaTileHSLProgram::new(&device, resources);
let tile_filter_basic_program = TileFilterBasicProgram::new(&device, resources); let solid_tile_blur_filter_program = SolidTileBlurFilterProgram::new(&device, resources);
let tile_filter_blur_program = TileFilterBlurProgram::new(&device, resources); let solid_tile_text_filter_program = SolidTileTextFilterProgram::new(&device, resources);
let tile_filter_text_program = TileFilterTextProgram::new(&device, resources);
let stencil_program = StencilProgram::new(&device, resources); let stencil_program = StencilProgram::new(&device, resources);
let reprojection_program = ReprojectionProgram::new(&device, resources); let reprojection_program = ReprojectionProgram::new(&device, resources);
@ -198,7 +193,7 @@ where
let gamma_lut_texture = device.create_texture_from_png(resources, "gamma-lut"); let gamma_lut_texture = device.create_texture_from_png(resources, "gamma-lut");
let alpha_tile_vertex_buffer = device.create_buffer(); let alpha_tile_vertex_buffer = device.create_buffer();
let tile_filter_vertex_buffer = device.create_buffer(); let solid_tile_vertex_buffer = device.create_buffer();
let quad_vertex_positions_buffer = device.create_buffer(); let quad_vertex_positions_buffer = device.create_buffer();
device.allocate_buffer( device.allocate_buffer(
&quad_vertex_positions_buffer, &quad_vertex_positions_buffer,
@ -288,24 +283,19 @@ where
let solid_tile_vertex_array = SolidTileVertexArray::new( let solid_tile_vertex_array = SolidTileVertexArray::new(
&device, &device,
&solid_tile_program, &solid_tile_program,
&solid_tile_vertex_buffer,
&quads_vertex_indices_buffer, &quads_vertex_indices_buffer,
); );
let tile_filter_basic_vertex_array = TileFilterVertexArray::new( let solid_tile_blur_filter_vertex_array = SolidTileVertexArray::new(
&device, &device,
&tile_filter_basic_program.tile_filter_program, &solid_tile_blur_filter_program.solid_tile_program,
&tile_filter_vertex_buffer, &solid_tile_vertex_buffer,
&quads_vertex_indices_buffer, &quads_vertex_indices_buffer,
); );
let tile_filter_blur_vertex_array = TileFilterVertexArray::new( let solid_tile_text_filter_vertex_array = SolidTileVertexArray::new(
&device, &device,
&tile_filter_blur_program.tile_filter_program, &solid_tile_text_filter_program.solid_tile_program,
&tile_filter_vertex_buffer, &solid_tile_vertex_buffer,
&quads_vertex_indices_buffer,
);
let tile_filter_text_vertex_array = TileFilterVertexArray::new(
&device,
&tile_filter_text_program.tile_filter_program,
&tile_filter_vertex_buffer,
&quads_vertex_indices_buffer, &quads_vertex_indices_buffer,
); );
let stencil_vertex_array = StencilVertexArray::new(&device, &stencil_program); let stencil_vertex_array = StencilVertexArray::new(&device, &stencil_program);
@ -363,7 +353,6 @@ where
mask_winding_tile_vertex_array, mask_winding_tile_vertex_array,
mask_evenodd_tile_vertex_array, mask_evenodd_tile_vertex_array,
copy_tile_vertex_array, copy_tile_vertex_array,
solid_tile_vertex_array,
alpha_tile_vertex_array, alpha_tile_vertex_array,
alpha_tile_overlay_vertex_array, alpha_tile_overlay_vertex_array,
alpha_tile_dodgeburn_vertex_array, alpha_tile_dodgeburn_vertex_array,
@ -387,13 +376,12 @@ where
render_target_stack: vec![], render_target_stack: vec![],
clear_paint_texture, clear_paint_texture,
tile_filter_basic_program, solid_tile_vertex_array,
tile_filter_basic_vertex_array, solid_tile_blur_filter_program,
tile_filter_blur_program, solid_tile_blur_filter_vertex_array,
tile_filter_blur_vertex_array, solid_tile_text_filter_program,
tile_filter_text_program, solid_tile_text_filter_vertex_array,
tile_filter_text_vertex_array, solid_tile_vertex_buffer,
tile_filter_vertex_buffer,
gamma_lut_texture, gamma_lut_texture,
stencil_program, stencil_program,
@ -450,18 +438,14 @@ where
self.push_render_target(render_target_id) self.push_render_target(render_target_id)
} }
RenderCommand::PopRenderTarget => self.pop_render_target(), RenderCommand::PopRenderTarget => self.pop_render_target(),
RenderCommand::DrawRenderTargetTiles(ref batch) => {
let count = batch.tiles.len();
self.upload_render_target_tiles(&batch.tiles);
self.draw_render_target_tiles(count as u32, batch.render_target, batch.effects)
}
RenderCommand::DrawSolidTiles(ref batch) => { RenderCommand::DrawSolidTiles(ref batch) => {
let count = batch.vertices.len() / 4; let count = batch.tiles.len();
self.stats.solid_tile_count += count; self.stats.solid_tile_count += count;
self.upload_solid_tiles(&batch.vertices); self.upload_solid_tiles(&batch.tiles);
self.draw_solid_tiles(count as u32, self.draw_solid_tiles(count as u32,
batch.color_texture_page, batch.color_texture_page,
batch.sampling_flags); batch.sampling_flags,
batch.effects);
} }
RenderCommand::DrawAlphaTiles(ref batch) => { RenderCommand::DrawAlphaTiles(ref batch) => {
let count = batch.tiles.len(); let count = batch.tiles.len();
@ -635,14 +619,14 @@ where
self.ensure_index_buffer(mask_tiles.len()); self.ensure_index_buffer(mask_tiles.len());
} }
fn upload_solid_tiles(&mut self, solid_tile_vertices: &[SolidTileVertex]) { fn upload_solid_tiles(&mut self, solid_tiles: &[SolidTile]) {
self.device.allocate_buffer( self.device.allocate_buffer(
&self.solid_tile_vertex_array.vertex_buffer, &self.solid_tile_vertex_buffer,
BufferData::Memory(&solid_tile_vertices), BufferData::Memory(&solid_tiles),
BufferTarget::Vertex, BufferTarget::Vertex,
BufferUploadMode::Dynamic, BufferUploadMode::Dynamic,
); );
self.ensure_index_buffer(solid_tile_vertices.len() / 4); self.ensure_index_buffer(solid_tiles.len());
} }
fn upload_alpha_tiles(&mut self, alpha_tiles: &[AlphaTile]) { fn upload_alpha_tiles(&mut self, alpha_tiles: &[AlphaTile]) {
@ -653,14 +637,6 @@ where
self.ensure_index_buffer(alpha_tiles.len()); self.ensure_index_buffer(alpha_tiles.len());
} }
fn upload_render_target_tiles(&mut self, render_target_tiles: &[RenderTargetTile]) {
self.device.allocate_buffer(&self.tile_filter_vertex_buffer,
BufferData::Memory(&render_target_tiles),
BufferTarget::Vertex,
BufferUploadMode::Dynamic);
self.ensure_index_buffer(render_target_tiles.len());
}
fn ensure_index_buffer(&mut self, mut length: usize) { fn ensure_index_buffer(&mut self, mut length: usize) {
length = length.next_power_of_two(); length = length.next_power_of_two();
if self.quads_vertex_indices_length >= length { if self.quads_vertex_indices_length >= length {
@ -1039,32 +1015,68 @@ where
fn draw_solid_tiles(&mut self, fn draw_solid_tiles(&mut self,
tile_count: u32, tile_count: u32,
color_texture_page: TexturePageId, color_texture_page: TexturePageId,
sampling_flags: TextureSamplingFlags) { sampling_flags: TextureSamplingFlags,
effects: Effects) {
let clear_color = self.clear_color_for_draw_operation(); let clear_color = self.clear_color_for_draw_operation();
let (solid_tile_program, solid_tile_vertex_array) = match effects.filter {
Filter::Composite(_) => {
(&self.solid_tile_program, &self.solid_tile_vertex_array)
}
Filter::Text { .. } => {
(&self.solid_tile_text_filter_program.solid_tile_program,
&self.solid_tile_text_filter_vertex_array)
}
Filter::Blur { .. } => {
(&self.solid_tile_blur_filter_program.solid_tile_program,
&self.solid_tile_blur_filter_vertex_array)
}
};
let mut textures = vec![]; let mut textures = vec![];
let mut uniforms = vec![ let mut uniforms = vec![
(&self.solid_tile_program.transform_uniform, (&solid_tile_program.transform_uniform,
UniformData::Mat4(self.tile_transform().to_columns())), UniformData::Mat4(self.tile_transform().to_columns())),
(&self.solid_tile_program.tile_size_uniform, (&solid_tile_program.tile_size_uniform,
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))), UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
]; ];
let texture_page = self.texture_page(color_texture_page); let texture_page = self.texture_page(color_texture_page);
let texture_size = self.device.texture_size(texture_page);
self.device.set_texture_sampling_mode(texture_page, sampling_flags); self.device.set_texture_sampling_mode(texture_page, sampling_flags);
textures.push(texture_page); textures.push(texture_page);
uniforms.push((&self.solid_tile_program.paint_texture_uniform, uniforms.push((&solid_tile_program.color_texture_uniform, UniformData::TextureUnit(0)));
UniformData::TextureUnit(0)));
let blend_state = match effects.filter {
Filter::Composite(composite_op) => composite_op.to_blend_state(),
Filter::Blur { .. } | Filter::Text { .. } => CompositeOp::SrcOver.to_blend_state(),
};
match effects.filter {
Filter::Composite(_) => {}
Filter::Text { fg_color, bg_color, defringing_kernel, gamma_correction } => {
self.set_uniforms_for_text_filter(&mut textures,
&mut uniforms,
fg_color,
bg_color,
defringing_kernel,
gamma_correction);
}
Filter::Blur { direction, sigma } => {
self.set_uniforms_for_blur_filter(&mut uniforms, texture_size, direction, sigma);
}
}
self.device.draw_elements(6 * tile_count, &RenderState { self.device.draw_elements(6 * tile_count, &RenderState {
target: &self.draw_render_target(), target: &self.draw_render_target(),
program: &self.solid_tile_program.program, program: &solid_tile_program.program,
vertex_array: &self.solid_tile_vertex_array.vertex_array, vertex_array: &solid_tile_vertex_array.vertex_array,
primitive: Primitive::Triangles, primitive: Primitive::Triangles,
textures: &textures, textures: &textures,
uniforms: &uniforms, uniforms: &uniforms,
viewport: self.draw_viewport(), viewport: self.draw_viewport(),
options: RenderOptions { options: RenderOptions {
blend: blend_state,
stencil: self.stencil_state(), stencil: self.stencil_state(),
clear_ops: ClearOps { color: clear_color, ..ClearOps::default() }, clear_ops: ClearOps { color: clear_color, ..ClearOps::default() },
..RenderOptions::default() ..RenderOptions::default()
@ -1182,94 +1194,42 @@ where
self.render_target_stack.pop().expect("Render target stack underflow!"); self.render_target_stack.pop().expect("Render target stack underflow!");
} }
// FIXME(pcwalton): This is inefficient and should eventually go away. fn set_uniforms_for_text_filter<'a>(&'a self,
fn draw_render_target_tiles(&mut self, textures: &mut Vec<&'a D::Texture>,
count: u32, uniforms: &mut Vec<(&'a D::Uniform, UniformData)>,
render_target_id: RenderTargetId,
effects: Effects) {
match effects.filter {
Filter::Composite(composite_op) => {
self.composite_render_target(count, render_target_id, composite_op)
}
Filter::Text { fg_color, bg_color, defringing_kernel, gamma_correction } => {
self.draw_text_render_target(count,
render_target_id,
fg_color,
bg_color,
defringing_kernel,
gamma_correction)
}
Filter::Blur { direction, sigma } => {
self.draw_blur_render_target(count, render_target_id, direction, sigma)
}
}
self.preserve_draw_framebuffer();
}
fn composite_render_target(&mut self,
tile_count: u32,
render_target_id: RenderTargetId,
composite_op: CompositeOp) {
self.finish_drawing_render_target_tiles(&self.tile_filter_basic_program
.tile_filter_program,
&self.tile_filter_basic_vertex_array,
tile_count,
render_target_id,
vec![],
vec![],
composite_op.to_blend_state());
self.preserve_draw_framebuffer();
}
fn draw_text_render_target(&mut self,
tile_count: u32,
render_target_id: RenderTargetId,
fg_color: ColorF, fg_color: ColorF,
bg_color: ColorF, bg_color: ColorF,
defringing_kernel: Option<DefringingKernel>, defringing_kernel: Option<DefringingKernel>,
gamma_correction: bool) { gamma_correction: bool) {
let textures = vec![&self.gamma_lut_texture]; let gamma_lut_texture_unit = textures.len() as u32;
let mut uniforms = vec![ textures.push(&self.gamma_lut_texture);
(&self.tile_filter_text_program.gamma_lut_uniform, UniformData::TextureUnit(0)),
(&self.tile_filter_text_program.fg_color_uniform, UniformData::Vec4(fg_color.0)), uniforms.extend_from_slice(&[
(&self.tile_filter_text_program.bg_color_uniform, UniformData::Vec4(bg_color.0)), (&self.solid_tile_text_filter_program.gamma_lut_uniform,
(&self.tile_filter_text_program.gamma_correction_enabled_uniform, UniformData::TextureUnit(gamma_lut_texture_unit)),
(&self.solid_tile_text_filter_program.fg_color_uniform, UniformData::Vec4(fg_color.0)),
(&self.solid_tile_text_filter_program.bg_color_uniform, UniformData::Vec4(bg_color.0)),
(&self.solid_tile_text_filter_program.gamma_correction_enabled_uniform,
UniformData::Int(gamma_correction as i32)), UniformData::Int(gamma_correction as i32)),
]; ]);
match defringing_kernel { match defringing_kernel {
Some(ref kernel) => { Some(ref kernel) => {
uniforms.push((&self.tile_filter_text_program.kernel_uniform, uniforms.push((&self.solid_tile_text_filter_program.kernel_uniform,
UniformData::Vec4(F32x4::from_slice(&kernel.0)))); UniformData::Vec4(F32x4::from_slice(&kernel.0))));
} }
None => { None => {
uniforms.push((&self.tile_filter_text_program.kernel_uniform, uniforms.push((&self.solid_tile_text_filter_program.kernel_uniform,
UniformData::Vec4(F32x4::default()))); UniformData::Vec4(F32x4::default())));
} }
} }
self.finish_drawing_render_target_tiles(&self.tile_filter_text_program.tile_filter_program,
&self.tile_filter_text_vertex_array,
tile_count,
render_target_id,
uniforms,
textures,
None);
self.preserve_draw_framebuffer();
} }
fn draw_blur_render_target(&mut self, fn set_uniforms_for_blur_filter<'a>(&'a self,
tile_count: u32, uniforms: &mut Vec<(&'a D::Uniform, UniformData)>,
render_target_id: RenderTargetId, src_texture_size: Vector2I,
direction: BlurDirection, direction: BlurDirection,
sigma: f32) { sigma: f32) {
let src_texture_page = self.render_target_location(render_target_id).page;
let src_texture = self.texture_page(src_texture_page);
let src_texture_size = self.device.texture_size(src_texture);
let sigma_inv = 1.0 / sigma; let sigma_inv = 1.0 / sigma;
let gauss_coeff_x = SQRT_2_PI_INV * sigma_inv; let gauss_coeff_x = SQRT_2_PI_INV * sigma_inv;
let gauss_coeff_y = f32::exp(-0.5 * sigma_inv * sigma_inv); let gauss_coeff_y = f32::exp(-0.5 * sigma_inv * sigma_inv);
@ -1281,68 +1241,14 @@ where
}; };
let src_offset_scale = src_offset / src_texture_size.to_f32(); let src_offset_scale = src_offset / src_texture_size.to_f32();
let uniforms = vec![
(&self.tile_filter_blur_program.src_offset_scale_uniform,
UniformData::Vec2(src_offset_scale.0)),
(&self.tile_filter_blur_program.initial_gauss_coeff_uniform,
UniformData::Vec3([gauss_coeff_x, gauss_coeff_y, gauss_coeff_z])),
(&self.tile_filter_blur_program.support_uniform,
UniformData::Int(f32::ceil(1.5 * sigma) as i32 * 2)),
];
self.finish_drawing_render_target_tiles(&self.tile_filter_blur_program.tile_filter_program,
&self.tile_filter_blur_vertex_array,
tile_count,
render_target_id,
uniforms,
vec![],
CompositeOp::SrcOver.to_blend_state());
self.preserve_draw_framebuffer();
}
fn finish_drawing_render_target_tiles<'a>(
&'a self,
tile_filter_program: &'a TileFilterProgram<D>,
tile_filter_vertex_array: &'a TileFilterVertexArray<D>,
tile_count: u32,
render_target_id: RenderTargetId,
mut uniforms: Vec<(&'a D::Uniform, UniformData)>,
mut textures: Vec<&'a D::Texture>,
blend_state: Option<BlendState>) {
let clear_color = self.clear_color_for_draw_operation();
let main_viewport = self.main_viewport();
// TODO(pcwalton): Other viewports.
let src_texture_location = self.render_target_location(render_target_id);
let src_texture = self.texture_page(src_texture_location.page);
let src_texture_size = self.device.texture_size(src_texture);
uniforms.extend_from_slice(&[ uniforms.extend_from_slice(&[
(&tile_filter_program.src_uniform, UniformData::TextureUnit(textures.len() as u32)), (&self.solid_tile_blur_filter_program.src_offset_scale_uniform,
(&tile_filter_program.src_size_uniform, UniformData::Vec2(src_offset_scale.0)),
UniformData::Vec2(src_texture_size.0.to_f32x2())), (&self.solid_tile_blur_filter_program.initial_gauss_coeff_uniform,
(&tile_filter_program.transform_uniform, UniformData::Vec3([gauss_coeff_x, gauss_coeff_y, gauss_coeff_z])),
UniformData::Mat4(self.tile_transform().to_columns())), (&self.solid_tile_blur_filter_program.support_uniform,
(&tile_filter_program.tile_size_uniform, UniformData::Int(f32::ceil(1.5 * sigma) as i32 * 2)),
UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))),
]); ]);
textures.push(src_texture);
self.device.draw_elements(6 * tile_count, &RenderState {
target: &self.draw_render_target(),
program: &tile_filter_program.program,
vertex_array: &tile_filter_vertex_array.vertex_array,
primitive: Primitive::Triangles,
textures: &textures,
uniforms: &uniforms,
viewport: main_viewport,
options: RenderOptions {
clear_ops: ClearOps { color: clear_color, ..ClearOps::default() },
blend: blend_state,
..RenderOptions::default()
},
});
} }
fn blit_intermediate_dest_framebuffer_if_necessary(&mut self) { fn blit_intermediate_dest_framebuffer_if_necessary(&mut self) {

View File

@ -16,9 +16,8 @@ use pathfinder_resources::ResourceLoader;
// TODO(pcwalton): Replace with `mem::size_of` calls? // TODO(pcwalton): Replace with `mem::size_of` calls?
const FILL_INSTANCE_SIZE: usize = 8; const FILL_INSTANCE_SIZE: usize = 8;
const SOLID_TILE_VERTEX_SIZE: usize = 16; const SOLID_TILE_VERTEX_SIZE: usize = 12;
const ALPHA_TILE_VERTEX_SIZE: usize = 20; const ALPHA_TILE_VERTEX_SIZE: usize = 20;
const FILTER_TILE_VERTEX_SIZE: usize = 4;
const MASK_TILE_VERTEX_SIZE: usize = 12; const MASK_TILE_VERTEX_SIZE: usize = 12;
pub const MAX_FILLS_PER_BATCH: usize = 0x4000; pub const MAX_FILLS_PER_BATCH: usize = 0x4000;
@ -273,7 +272,6 @@ where
D: Device, D: Device,
{ {
pub vertex_array: D::VertexArray, pub vertex_array: D::VertexArray,
pub vertex_buffer: D::Buffer,
} }
impl<D> SolidTileVertexArray<D> impl<D> SolidTileVertexArray<D>
@ -283,9 +281,10 @@ where
pub fn new( pub fn new(
device: &D, device: &D,
solid_tile_program: &SolidTileProgram<D>, solid_tile_program: &SolidTileProgram<D>,
solid_tile_vertex_buffer: &D::Buffer,
quads_vertex_indices_buffer: &D::Buffer, quads_vertex_indices_buffer: &D::Buffer,
) -> SolidTileVertexArray<D> { ) -> SolidTileVertexArray<D> {
let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); let vertex_array = device.create_vertex_array();
let tile_position_attr = let tile_position_attr =
device.get_vertex_attr(&solid_tile_program.program, "TilePosition").unwrap(); device.get_vertex_attr(&solid_tile_program.program, "TilePosition").unwrap();
@ -294,7 +293,7 @@ where
// NB: The tile origin must be of type short, not unsigned short, to work around a macOS // NB: The tile origin must be of type short, not unsigned short, to work around a macOS
// Radeon driver bug. // Radeon driver bug.
device.bind_buffer(&vertex_array, &vertex_buffer, BufferTarget::Vertex); device.bind_buffer(&vertex_array, solid_tile_vertex_buffer, BufferTarget::Vertex);
device.configure_vertex_attr(&vertex_array, &tile_position_attr, &VertexAttrDescriptor { device.configure_vertex_attr(&vertex_array, &tile_position_attr, &VertexAttrDescriptor {
size: 2, size: 2,
class: VertexAttrClass::Int, class: VertexAttrClass::Int,
@ -317,7 +316,7 @@ where
}); });
device.bind_buffer(&vertex_array, quads_vertex_indices_buffer, BufferTarget::Index); device.bind_buffer(&vertex_array, quads_vertex_indices_buffer, BufferTarget::Index);
SolidTileVertexArray { vertex_array, vertex_buffer } SolidTileVertexArray { vertex_array }
} }
} }
@ -421,20 +420,24 @@ pub struct SolidTileProgram<D> where D: Device {
pub program: D::Program, pub program: D::Program,
pub transform_uniform: D::Uniform, pub transform_uniform: D::Uniform,
pub tile_size_uniform: D::Uniform, pub tile_size_uniform: D::Uniform,
pub paint_texture_uniform: D::Uniform, pub color_texture_uniform: D::Uniform,
} }
impl<D> SolidTileProgram<D> where D: Device { impl<D> SolidTileProgram<D> where D: Device {
pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileProgram<D> { pub fn new(device: &D, resources: &dyn ResourceLoader, program_name: &str)
let program = device.create_program(resources, "tile_solid"); -> SolidTileProgram<D> {
let program = device.create_program_from_shader_names(resources,
program_name,
"tile_solid",
program_name);
let transform_uniform = device.get_uniform(&program, "Transform"); let transform_uniform = device.get_uniform(&program, "Transform");
let tile_size_uniform = device.get_uniform(&program, "TileSize"); let tile_size_uniform = device.get_uniform(&program, "TileSize");
let paint_texture_uniform = device.get_uniform(&program, "PaintTexture"); let color_texture_uniform = device.get_uniform(&program, "ColorTexture");
SolidTileProgram { SolidTileProgram {
program, program,
transform_uniform, transform_uniform,
tile_size_uniform, tile_size_uniform,
paint_texture_uniform, color_texture_uniform,
} }
} }
} }
@ -566,101 +569,25 @@ impl<D> AlphaTileDodgeBurnProgram<D> where D: Device {
} }
} }
pub struct TileFilterProgram<D> where D: Device { pub struct SolidTileBlurFilterProgram<D> where D: Device {
pub program: D::Program, pub solid_tile_program: SolidTileProgram<D>,
pub transform_uniform: D::Uniform,
pub tile_size_uniform: D::Uniform,
pub src_uniform: D::Uniform,
pub src_size_uniform: D::Uniform,
}
impl<D> TileFilterProgram<D> where D: Device {
pub fn new(device: &D,
resources: &dyn ResourceLoader,
program_name: &str,
fragment_shader_name: &str)
-> TileFilterProgram<D> {
let program = device.create_program_from_shader_names(resources,
program_name,
"tile_filter",
fragment_shader_name);
let transform_uniform = device.get_uniform(&program, "Transform");
let tile_size_uniform = device.get_uniform(&program, "TileSize");
let src_uniform = device.get_uniform(&program, "Src");
let src_size_uniform = device.get_uniform(&program, "SrcSize");
TileFilterProgram {
program,
transform_uniform,
tile_size_uniform,
src_uniform,
src_size_uniform,
}
}
}
pub struct TileFilterBasicProgram<D> where D: Device {
pub tile_filter_program: TileFilterProgram<D>,
}
impl<D> TileFilterBasicProgram<D> where D: Device {
pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterBasicProgram<D> {
TileFilterBasicProgram {
tile_filter_program: TileFilterProgram::new(device, resources, "filter_basic", "blit"),
}
}
}
pub struct TileFilterVertexArray<D> where D: Device {
pub vertex_array: D::VertexArray,
}
impl<D> TileFilterVertexArray<D> where D: Device {
pub fn new(device: &D,
tile_filter_program: &TileFilterProgram<D>,
tile_filter_vertex_buffer: &D::Buffer,
quads_vertex_indices_buffer: &D::Buffer)
-> TileFilterVertexArray<D> {
let vertex_array = device.create_vertex_array();
let tile_position_attr =
device.get_vertex_attr(&tile_filter_program.program, "TilePosition").unwrap();
device.bind_buffer(&vertex_array, tile_filter_vertex_buffer, BufferTarget::Vertex);
device.configure_vertex_attr(&vertex_array, &tile_position_attr, &VertexAttrDescriptor {
size: 2,
class: VertexAttrClass::Int,
attr_type: VertexAttrType::I16,
stride: FILTER_TILE_VERTEX_SIZE,
offset: 0,
divisor: 0,
buffer_index: 0,
});
device.bind_buffer(&vertex_array, quads_vertex_indices_buffer, BufferTarget::Index);
TileFilterVertexArray { vertex_array }
}
}
pub struct TileFilterBlurProgram<D> where D: Device {
pub tile_filter_program: TileFilterProgram<D>,
pub src_offset_scale_uniform: D::Uniform, pub src_offset_scale_uniform: D::Uniform,
pub initial_gauss_coeff_uniform: D::Uniform, pub initial_gauss_coeff_uniform: D::Uniform,
pub support_uniform: D::Uniform, pub support_uniform: D::Uniform,
} }
impl<D> TileFilterBlurProgram<D> where D: Device { impl<D> SolidTileBlurFilterProgram<D> where D: Device {
pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterBlurProgram<D> { pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileBlurFilterProgram<D> {
let tile_filter_program = TileFilterProgram::new(device, let solid_tile_program = SolidTileProgram::new(device,
resources, resources,
"tile_filter_blur", "tile_solid_filter_blur");
"tile_filter_blur"); let src_offset_scale_uniform = device.get_uniform(&solid_tile_program.program,
let src_offset_scale_uniform = device.get_uniform(&tile_filter_program.program,
"SrcOffsetScale"); "SrcOffsetScale");
let initial_gauss_coeff_uniform = device.get_uniform(&tile_filter_program.program, let initial_gauss_coeff_uniform = device.get_uniform(&solid_tile_program.program,
"InitialGaussCoeff"); "InitialGaussCoeff");
let support_uniform = device.get_uniform(&tile_filter_program.program, "Support"); let support_uniform = device.get_uniform(&solid_tile_program.program, "Support");
TileFilterBlurProgram { SolidTileBlurFilterProgram {
tile_filter_program, solid_tile_program,
src_offset_scale_uniform, src_offset_scale_uniform,
initial_gauss_coeff_uniform, initial_gauss_coeff_uniform,
support_uniform, support_uniform,
@ -668,8 +595,8 @@ impl<D> TileFilterBlurProgram<D> where D: Device {
} }
} }
pub struct TileFilterTextProgram<D> where D: Device { pub struct SolidTileTextFilterProgram<D> where D: Device {
pub tile_filter_program: TileFilterProgram<D>, pub solid_tile_program: SolidTileProgram<D>,
pub kernel_uniform: D::Uniform, pub kernel_uniform: D::Uniform,
pub gamma_lut_uniform: D::Uniform, pub gamma_lut_uniform: D::Uniform,
pub gamma_correction_enabled_uniform: D::Uniform, pub gamma_correction_enabled_uniform: D::Uniform,
@ -677,20 +604,19 @@ pub struct TileFilterTextProgram<D> where D: Device {
pub bg_color_uniform: D::Uniform, pub bg_color_uniform: D::Uniform,
} }
impl<D> TileFilterTextProgram<D> where D: Device { impl<D> SolidTileTextFilterProgram<D> where D: Device {
pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterTextProgram<D> { pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileTextFilterProgram<D> {
let tile_filter_program = TileFilterProgram::new(device, let solid_tile_program = SolidTileProgram::new(device,
resources, resources,
"tile_filter_text", "tile_solid_filter_text");
"tile_filter_text"); let kernel_uniform = device.get_uniform(&solid_tile_program.program, "Kernel");
let kernel_uniform = device.get_uniform(&tile_filter_program.program, "Kernel"); let gamma_lut_uniform = device.get_uniform(&solid_tile_program.program, "GammaLUT");
let gamma_lut_uniform = device.get_uniform(&tile_filter_program.program, "GammaLUT"); let gamma_correction_enabled_uniform = device.get_uniform(&solid_tile_program.program,
let gamma_correction_enabled_uniform = device.get_uniform(&tile_filter_program.program,
"GammaCorrectionEnabled"); "GammaCorrectionEnabled");
let fg_color_uniform = device.get_uniform(&tile_filter_program.program, "FGColor"); let fg_color_uniform = device.get_uniform(&solid_tile_program.program, "FGColor");
let bg_color_uniform = device.get_uniform(&tile_filter_program.program, "BGColor"); let bg_color_uniform = device.get_uniform(&solid_tile_program.program, "BGColor");
TileFilterTextProgram { SolidTileTextFilterProgram {
tile_filter_program, solid_tile_program,
kernel_uniform, kernel_uniform,
gamma_lut_uniform, gamma_lut_uniform,
gamma_correction_enabled_uniform, gamma_correction_enabled_uniform,

View File

@ -71,13 +71,6 @@ pub enum RenderCommand {
// Draws a batch of solid tiles to the render target on top of the stack. // Draws a batch of solid tiles to the render target on top of the stack.
DrawSolidTiles(SolidTileBatch), DrawSolidTiles(SolidTileBatch),
// Draws a batch of render target tiles to the render target on top of the stack.
//
// FIXME(pcwalton): We should get rid of this command and transition all uses to
// `DrawAlphaTiles`/`DrawSolidTiles`. The reason it exists is that we don't have logic to
// create tiles for blur bounding regions yet.
DrawRenderTargetTiles(RenderTargetTileBatch),
// Presents a rendered frame. // Presents a rendered frame.
Finish { build_time: Duration }, Finish { build_time: Duration },
} }
@ -106,15 +99,9 @@ pub struct AlphaTileBatch {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SolidTileBatch { pub struct SolidTileBatch {
pub vertices: Vec<SolidTileVertex>, pub tiles: Vec<SolidTile>,
pub color_texture_page: TexturePageId, pub color_texture_page: TexturePageId,
pub sampling_flags: TextureSamplingFlags, pub sampling_flags: TextureSamplingFlags,
}
#[derive(Clone, Debug)]
pub struct RenderTargetTileBatch {
pub tiles: Vec<RenderTargetTile>,
pub render_target: RenderTargetId,
pub effects: Effects, pub effects: Effects,
} }
@ -143,15 +130,13 @@ pub struct FillBatchPrimitive {
pub alpha_tile_index: u16, pub alpha_tile_index: u16,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug, Default)]
#[repr(C)] #[repr(C)]
pub struct SolidTileVertex { pub struct SolidTileVertex {
pub tile_x: i16, pub tile_x: i16,
pub tile_y: i16, pub tile_y: i16,
pub color_u: f32, pub color_u: f32,
pub color_v: f32, pub color_v: f32,
pub object_index: u16,
pub pad: u16,
} }
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
@ -174,11 +159,11 @@ pub struct AlphaTile {
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
#[repr(C)] #[repr(C)]
pub struct RenderTargetTile { pub struct SolidTile {
pub upper_left: RenderTargetTileVertex, pub upper_left: SolidTileVertex,
pub upper_right: RenderTargetTileVertex, pub upper_right: SolidTileVertex,
pub lower_left: RenderTargetTileVertex, pub lower_left: SolidTileVertex,
pub lower_right: RenderTargetTileVertex, pub lower_right: SolidTileVertex,
} }
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug, Default)]
@ -206,13 +191,6 @@ pub struct AlphaTileVertex {
pub pad: u8, pub pad: u8,
} }
#[derive(Clone, Copy, Debug, Default)]
#[repr(C)]
pub struct RenderTargetTileVertex {
pub tile_x: i16,
pub tile_y: i16,
}
impl Debug for RenderCommand { impl Debug for RenderCommand {
fn fmt(&self, formatter: &mut Formatter) -> DebugResult { fn fmt(&self, formatter: &mut Formatter) -> DebugResult {
match *self { match *self {
@ -246,16 +224,10 @@ impl Debug for RenderCommand {
RenderCommand::DrawSolidTiles(ref batch) => { RenderCommand::DrawSolidTiles(ref batch) => {
write!(formatter, write!(formatter,
"DrawSolidTiles(x{}, {:?}, {:?})", "DrawSolidTiles(x{}, {:?}, {:?})",
batch.vertices.len(), batch.tiles.len(),
batch.color_texture_page, batch.color_texture_page,
batch.sampling_flags) batch.sampling_flags)
} }
RenderCommand::DrawRenderTargetTiles(ref batch) => {
write!(formatter,
"DrawRenderTarget(x{}, {:?})",
batch.tiles.len(),
batch.render_target)
}
RenderCommand::Finish { .. } => write!(formatter, "Finish"), RenderCommand::Finish { .. } => write!(formatter, "Finish"),
} }
} }

View File

@ -156,15 +156,17 @@ pub struct PaintInfo {
/// The metadata for each paint. /// The metadata for each paint.
/// ///
/// The indices of this vector are paint IDs. /// The indices of this vector are paint IDs.
pub metadata: Vec<PaintMetadata>, pub paint_metadata: Vec<PaintMetadata>,
/// The metadata for each render target.
///
/// The indices of this vector are render target IDs.
pub render_target_metadata: Vec<RenderTargetMetadata>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct PaintMetadata { pub struct PaintMetadata {
/// The location of the texture. /// The location of the paint.
pub texture_page: TexturePageId, pub location: TextureLocation,
/// The rectangle within the texture atlas.
pub texture_rect: RectI,
/// The transform to apply to screen coordinates to translate them into UVs. /// The transform to apply to screen coordinates to translate them into UVs.
pub texture_transform: Transform2F, pub texture_transform: Transform2F,
/// The sampling mode for the texture. /// The sampling mode for the texture.
@ -173,6 +175,12 @@ pub struct PaintMetadata {
pub is_opaque: bool, pub is_opaque: bool,
} }
#[derive(Debug)]
pub struct RenderTargetMetadata {
/// The location of the render target.
pub location: TextureLocation,
}
impl Palette { impl Palette {
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
pub fn push_paint(&mut self, paint: &Paint) -> PaintId { pub fn push_paint(&mut self, paint: &Paint) -> PaintId {
@ -194,12 +202,13 @@ impl Palette {
pub fn build_paint_info(&self, view_box_size: Vector2I) -> PaintInfo { pub fn build_paint_info(&self, view_box_size: Vector2I) -> PaintInfo {
let mut allocator = TextureAllocator::new(); let mut allocator = TextureAllocator::new();
let mut metadata = vec![]; let (mut paint_metadata, mut render_target_metadata) = (vec![], vec![]);
// Assign render target locations. // Assign render target locations.
let mut render_target_locations = vec![];
for render_target in &self.render_targets { for render_target in &self.render_targets {
render_target_locations.push(allocator.allocate_image(render_target.size())); render_target_metadata.push(RenderTargetMetadata {
location: allocator.allocate_image(render_target.size()),
});
} }
// Assign paint locations. // Assign paint locations.
@ -225,7 +234,7 @@ impl Palette {
match pattern.source { match pattern.source {
PatternSource::RenderTarget(render_target_id) => { PatternSource::RenderTarget(render_target_id) => {
texture_location = texture_location =
render_target_locations[render_target_id.0 as usize]; render_target_metadata[render_target_id.0 as usize].location;
} }
PatternSource::Image(ref image) => { PatternSource::Image(ref image) => {
// TODO(pcwalton): We should be able to use tile cleverness to repeat // TODO(pcwalton): We should be able to use tile cleverness to repeat
@ -254,9 +263,8 @@ impl Palette {
} }
}; };
metadata.push(PaintMetadata { paint_metadata.push(PaintMetadata {
texture_page: texture_location.page, location: texture_location,
texture_rect: texture_location.rect,
texture_transform: Transform2F::default(), texture_transform: Transform2F::default(),
sampling_flags, sampling_flags,
is_opaque: paint.is_opaque(), is_opaque: paint.is_opaque(),
@ -264,23 +272,23 @@ impl Palette {
} }
// Calculate texture transforms. // Calculate texture transforms.
for (paint, metadata) in self.paints.iter().zip(metadata.iter_mut()) { for (paint, metadata) in self.paints.iter().zip(paint_metadata.iter_mut()) {
let texture_scale = allocator.page_scale(metadata.texture_page); let texture_scale = allocator.page_scale(metadata.location.page);
metadata.texture_transform = match paint { metadata.texture_transform = match paint {
Paint::Color(_) => { Paint::Color(_) => {
let vector = rect_to_inset_uv(metadata.texture_rect, texture_scale).origin(); let vector = rect_to_inset_uv(metadata.location.rect, texture_scale).origin();
Transform2F { matrix: Matrix2x2F(F32x4::default()), vector } Transform2F { matrix: Matrix2x2F(F32x4::default()), vector }
} }
Paint::Gradient(_) => { Paint::Gradient(_) => {
let texture_origin_uv = let texture_origin_uv =
rect_to_uv(metadata.texture_rect, texture_scale).origin(); rect_to_uv(metadata.location.rect, texture_scale).origin();
let gradient_tile_scale = texture_scale.scale(GRADIENT_TILE_LENGTH as f32); let gradient_tile_scale = texture_scale.scale(GRADIENT_TILE_LENGTH as f32);
Transform2F::from_translation(texture_origin_uv) * Transform2F::from_translation(texture_origin_uv) *
Transform2F::from_scale(gradient_tile_scale / view_box_size.to_f32()) Transform2F::from_scale(gradient_tile_scale / view_box_size.to_f32())
} }
Paint::Pattern(Pattern { source: PatternSource::Image(_), transform, .. }) => { Paint::Pattern(Pattern { source: PatternSource::Image(_), transform, .. }) => {
let texture_origin_uv = let texture_origin_uv =
rect_to_uv(metadata.texture_rect, texture_scale).origin(); rect_to_uv(metadata.location.rect, texture_scale).origin();
Transform2F::from_translation(texture_origin_uv) * Transform2F::from_translation(texture_origin_uv) *
Transform2F::from_scale(texture_scale) * Transform2F::from_scale(texture_scale) *
transform.inverse() transform.inverse()
@ -291,7 +299,7 @@ impl Palette {
.. ..
}) => { }) => {
// FIXME(pcwalton): Only do this in GL, not Metal! // FIXME(pcwalton): Only do this in GL, not Metal!
let texture_origin_uv = rect_to_uv(metadata.texture_rect, let texture_origin_uv = rect_to_uv(metadata.location.rect,
texture_scale).lower_left(); texture_scale).lower_left();
Transform2F::from_translation(texture_origin_uv) * Transform2F::from_translation(texture_origin_uv) *
Transform2F::from_scale(texture_scale.scale_xy(Vector2F::new(1.0, -1.0))) * Transform2F::from_scale(texture_scale.scale_xy(Vector2F::new(1.0, -1.0))) *
@ -310,24 +318,24 @@ impl Palette {
// Allocate the texels. // Allocate the texels.
// //
// TODO(pcwalton): This is slow. Do more on GPU. // TODO(pcwalton): This is slow. Do more on GPU.
let mut page_texels: Vec<_> = metadata.iter().map(|metadata| { let mut page_texels: Vec<_> = paint_metadata.iter().map(|metadata| {
Texels::new(allocator.page_size(metadata.texture_page)) Texels::new(allocator.page_size(metadata.location.page))
}).collect(); }).collect();
// Draw to texels. // Draw to texels.
// //
// TODO(pcwalton): Do more of this on GPU. // TODO(pcwalton): Do more of this on GPU.
for (paint, metadata) in self.paints.iter().zip(metadata.iter()) { for (paint, metadata) in self.paints.iter().zip(paint_metadata.iter()) {
let texture_page = metadata.texture_page; let texture_page = metadata.location.page;
let texels = &mut page_texels[texture_page.0 as usize]; let texels = &mut page_texels[texture_page.0 as usize];
match paint { match paint {
Paint::Color(color) => { Paint::Color(color) => {
texels.put_texel(metadata.texture_rect.origin(), *color); texels.put_texel(metadata.location.rect.origin(), *color);
} }
Paint::Gradient(ref gradient) => { Paint::Gradient(ref gradient) => {
self.render_gradient(gradient, self.render_gradient(gradient,
metadata.texture_rect, metadata.location.rect,
&metadata.texture_transform, &metadata.texture_transform,
texels); texels);
} }
@ -335,7 +343,7 @@ impl Palette {
match pattern.source { match pattern.source {
PatternSource::RenderTarget(_) => {} PatternSource::RenderTarget(_) => {}
PatternSource::Image(ref image) => { PatternSource::Image(ref image) => {
self.render_image(image, metadata.texture_rect, texels); self.render_image(image, metadata.location.rect, texels);
} }
} }
} }
@ -346,9 +354,12 @@ impl Palette {
let mut render_commands = vec![ let mut render_commands = vec![
RenderCommand::AllocateTexturePages(texture_page_descriptors) RenderCommand::AllocateTexturePages(texture_page_descriptors)
]; ];
for (index, location) in render_target_locations.into_iter().enumerate() { for (index, metadata) in render_target_metadata.iter().enumerate() {
let id = RenderTargetId(index as u32); let id = RenderTargetId(index as u32);
render_commands.push(RenderCommand::DeclareRenderTarget { id, location }); render_commands.push(RenderCommand::DeclareRenderTarget {
id,
location: metadata.location,
});
} }
for (page_index, texels) in page_texels.into_iter().enumerate() { for (page_index, texels) in page_texels.into_iter().enumerate() {
if let Some(texel_data) = texels.data { if let Some(texel_data) = texels.data {
@ -362,7 +373,7 @@ impl Palette {
} }
} }
PaintInfo { render_commands, metadata } PaintInfo { render_commands, paint_metadata, render_target_metadata }
} }
// TODO(pcwalton): This is slow. Do on GPU instead. // TODO(pcwalton): This is slow. Do on GPU instead.

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::builder::{BuiltPath, ObjectBuilder, SceneBuilder, SolidTile}; use crate::builder::{BuiltPath, ObjectBuilder, SceneBuilder, SolidTileInfo};
use crate::gpu_data::TileObjectPrimitive; use crate::gpu_data::TileObjectPrimitive;
use crate::paint::PaintMetadata; use crate::paint::PaintMetadata;
use pathfinder_content::effects::BlendMode; use pathfinder_content::effects::BlendMode;
@ -186,7 +186,10 @@ impl<'a> Tiler<'a> {
if draw_tiling_path_info.paint_metadata.is_opaque && if draw_tiling_path_info.paint_metadata.is_opaque &&
draw_tiling_path_info.blend_mode.occludes_backdrop() && draw_tiling_path_info.blend_mode.occludes_backdrop() &&
draw_tiling_path_info.opacity == !0 { draw_tiling_path_info.opacity == !0 {
self.object_builder.built_path.solid_tiles.push(SolidTile::new(tile_coords)); self.object_builder
.built_path
.solid_tiles
.push(SolidTileInfo::new(tile_coords));
continue; continue;
} }
} }

View File

@ -10,13 +10,14 @@
//! Software occlusion culling. //! Software occlusion culling.
use crate::builder::SolidTile; use crate::builder::SolidTileInfo;
use crate::gpu_data::{SolidTileBatch, SolidTileVertex}; use crate::gpu_data::{SolidTile, SolidTileBatch, SolidTileVertex};
use crate::paint::{PaintId, PaintMetadata}; use crate::paint::{PaintId, PaintMetadata};
use crate::tile_map::DenseTileMap; use crate::tile_map::DenseTileMap;
use crate::tiles; use crate::tiles;
use pathfinder_content::effects::{CompositeOp, Effects, Filter};
use pathfinder_geometry::rect::RectF; use pathfinder_geometry::rect::RectF;
use pathfinder_geometry::vector::Vector2I; use pathfinder_geometry::vector::{Vector2F, Vector2I};
use vec_map::VecMap; use vec_map::VecMap;
pub(crate) struct ZBuffer { pub(crate) struct ZBuffer {
@ -47,7 +48,7 @@ impl ZBuffer {
} }
pub(crate) fn update(&mut self, pub(crate) fn update(&mut self,
solid_tiles: &[SolidTile], solid_tiles: &[SolidTileInfo],
depth: u32, depth: u32,
metadata: DepthMetadata) { metadata: DepthMetadata) {
self.depth_metadata.insert(depth as usize, metadata); self.depth_metadata.insert(depth as usize, metadata);
@ -76,42 +77,76 @@ impl ZBuffer {
// Create a batch if necessary. // Create a batch if necessary.
match solid_tiles.batches.last() { match solid_tiles.batches.last() {
Some(ref batch) if batch.color_texture_page == paint_metadata.texture_page && Some(ref batch) if batch.color_texture_page == paint_metadata.location.page &&
batch.sampling_flags == paint_metadata.sampling_flags => {} batch.sampling_flags == paint_metadata.sampling_flags => {}
_ => { _ => {
// Batch break. // Batch break.
//
// TODO(pcwalton): We could be more aggressive with batching here, since we
// know there are no overlaps.
solid_tiles.batches.push(SolidTileBatch { solid_tiles.batches.push(SolidTileBatch {
color_texture_page: paint_metadata.texture_page, color_texture_page: paint_metadata.location.page,
sampling_flags: paint_metadata.sampling_flags, sampling_flags: paint_metadata.sampling_flags,
vertices: vec![], tiles: vec![],
effects: Effects::new(Filter::Composite(CompositeOp::SrcOver)),
}); });
} }
} }
let batch = solid_tiles.batches.last_mut().unwrap(); let batch = solid_tiles.batches.last_mut().unwrap();
batch.vertices.extend_from_slice(&[ batch.tiles.push(SolidTile::from_paint_metadata(tile_position, paint_metadata));
SolidTileVertex::new(tile_position, paint_metadata),
SolidTileVertex::new(tile_position + Vector2I::new(1, 0), paint_metadata),
SolidTileVertex::new(tile_position + Vector2I::new(0, 1), paint_metadata),
SolidTileVertex::new(tile_position + Vector2I::new(1, 1), paint_metadata),
]);
} }
solid_tiles solid_tiles
} }
} }
impl SolidTile {
pub(crate) fn from_paint_metadata(tile_position: Vector2I, paint_metadata: &PaintMetadata)
-> SolidTile {
SolidTile {
upper_left: SolidTileVertex::from_paint_metadata(tile_position, paint_metadata),
upper_right: SolidTileVertex::from_paint_metadata(tile_position + Vector2I::new(1, 0),
paint_metadata),
lower_left: SolidTileVertex::from_paint_metadata(tile_position + Vector2I::new(0, 1),
paint_metadata),
lower_right: SolidTileVertex::from_paint_metadata(tile_position + Vector2I::new(1, 1),
paint_metadata),
}
}
// The texture rect is in normalized coordinates.
pub(crate) fn from_texture_rect(tile_position: Vector2I, texture_rect: RectF) -> SolidTile {
SolidTile {
upper_left: SolidTileVertex::new(tile_position, texture_rect.origin()),
upper_right: SolidTileVertex::new(tile_position + Vector2I::new(1, 0),
texture_rect.upper_right()),
lower_left: SolidTileVertex::new(tile_position + Vector2I::new(0, 1),
texture_rect.lower_left()),
lower_right: SolidTileVertex::new(tile_position + Vector2I::new(1, 1),
texture_rect.lower_right()),
}
}
}
impl SolidTileVertex { impl SolidTileVertex {
fn new(tile_position: Vector2I, paint_metadata: &PaintMetadata) fn new(tile_position: Vector2I, color_tex_coords: Vector2F) -> SolidTileVertex {
SolidTileVertex {
tile_x: tile_position.x() as i16,
tile_y: tile_position.y() as i16,
color_u: color_tex_coords.x(),
color_v: color_tex_coords.y(),
}
}
fn from_paint_metadata(tile_position: Vector2I, paint_metadata: &PaintMetadata)
-> SolidTileVertex { -> SolidTileVertex {
let color_uv = paint_metadata.calculate_tex_coords(tile_position); let color_uv = paint_metadata.calculate_tex_coords(tile_position);
SolidTileVertex { SolidTileVertex {
tile_x: tile_position.x() as i16, tile_x: tile_position.x() as i16,
tile_y: tile_position.y() as i16, tile_y: tile_position.y() as i16,
object_index: 0,
color_u: color_uv.x(), color_u: color_uv.x(),
color_v: color_uv.y(), color_v: color_uv.y(),
pad: 0,
} }
} }
} }

View File

@ -16,9 +16,6 @@ shaders/gl3/fill.vs.glsl
shaders/gl3/mask.vs.glsl shaders/gl3/mask.vs.glsl
shaders/gl3/mask_evenodd.fs.glsl shaders/gl3/mask_evenodd.fs.glsl
shaders/gl3/mask_winding.fs.glsl shaders/gl3/mask_winding.fs.glsl
shaders/gl3/mask_winding.vs.glsl
shaders/gl3/post.fs.glsl
shaders/gl3/post.vs.glsl
shaders/gl3/reproject.fs.glsl shaders/gl3/reproject.fs.glsl
shaders/gl3/reproject.vs.glsl shaders/gl3/reproject.vs.glsl
shaders/gl3/stencil.fs.glsl shaders/gl3/stencil.fs.glsl
@ -29,19 +26,16 @@ shaders/gl3/tile_alpha_difference.fs.glsl
shaders/gl3/tile_alpha_dodgeburn.fs.glsl shaders/gl3/tile_alpha_dodgeburn.fs.glsl
shaders/gl3/tile_alpha_exclusion.fs.glsl shaders/gl3/tile_alpha_exclusion.fs.glsl
shaders/gl3/tile_alpha_hsl.fs.glsl shaders/gl3/tile_alpha_hsl.fs.glsl
shaders/gl3/tile_alpha_monochrome.vs.glsl
shaders/gl3/tile_alpha_multicolor.vs.glsl
shaders/gl3/tile_alpha_overlay.fs.glsl shaders/gl3/tile_alpha_overlay.fs.glsl
shaders/gl3/tile_alpha_softlight.fs.glsl shaders/gl3/tile_alpha_softlight.fs.glsl
shaders/gl3/tile_copy.fs.glsl shaders/gl3/tile_copy.fs.glsl
shaders/gl3/tile_copy.vs.glsl shaders/gl3/tile_copy.vs.glsl
shaders/gl3/tile_filter.vs.glsl
shaders/gl3/tile_filter_blur.fs.glsl
shaders/gl3/tile_filter_text.fs.glsl
shaders/gl3/tile_solid.fs.glsl shaders/gl3/tile_solid.fs.glsl
shaders/gl3/tile_solid.vs.glsl shaders/gl3/tile_solid.vs.glsl
shaders/gl3/tile_solid_monochrome.vs.glsl shaders/gl3/tile_solid_filter_blur.fs.glsl
shaders/gl3/tile_solid_multicolor.vs.glsl shaders/gl3/tile_solid_filter_text.fs.glsl
shaders/metal/blit.fs.metal
shaders/metal/blit.vs.metal
shaders/metal/debug_solid.fs.metal shaders/metal/debug_solid.fs.metal
shaders/metal/debug_solid.vs.metal shaders/metal/debug_solid.vs.metal
shaders/metal/debug_texture.fs.metal shaders/metal/debug_texture.fs.metal
@ -50,16 +44,9 @@ shaders/metal/demo_ground.fs.metal
shaders/metal/demo_ground.vs.metal shaders/metal/demo_ground.vs.metal
shaders/metal/fill.fs.metal shaders/metal/fill.fs.metal
shaders/metal/fill.vs.metal shaders/metal/fill.vs.metal
shaders/metal/filter.vs.metal
shaders/metal/filter_basic.fs.metal
shaders/metal/filter_blur.fs.metal
shaders/metal/filter_text.fs.metal
shaders/metal/mask.vs.metal shaders/metal/mask.vs.metal
shaders/metal/mask_evenodd.fs.metal shaders/metal/mask_evenodd.fs.metal
shaders/metal/mask_winding.fs.metal shaders/metal/mask_winding.fs.metal
shaders/metal/mask_winding.vs.metal
shaders/metal/post.fs.metal
shaders/metal/post.vs.metal
shaders/metal/reproject.fs.metal shaders/metal/reproject.fs.metal
shaders/metal/reproject.vs.metal shaders/metal/reproject.vs.metal
shaders/metal/stencil.fs.metal shaders/metal/stencil.fs.metal
@ -70,16 +57,14 @@ shaders/metal/tile_alpha_difference.fs.metal
shaders/metal/tile_alpha_dodgeburn.fs.metal shaders/metal/tile_alpha_dodgeburn.fs.metal
shaders/metal/tile_alpha_exclusion.fs.metal shaders/metal/tile_alpha_exclusion.fs.metal
shaders/metal/tile_alpha_hsl.fs.metal shaders/metal/tile_alpha_hsl.fs.metal
shaders/metal/tile_alpha_monochrome.vs.metal
shaders/metal/tile_alpha_multicolor.vs.metal
shaders/metal/tile_alpha_overlay.fs.metal shaders/metal/tile_alpha_overlay.fs.metal
shaders/metal/tile_alpha_softlight.fs.metal shaders/metal/tile_alpha_softlight.fs.metal
shaders/metal/tile_copy.fs.metal shaders/metal/tile_copy.fs.metal
shaders/metal/tile_copy.vs.metal shaders/metal/tile_copy.vs.metal
shaders/metal/tile_solid.fs.metal shaders/metal/tile_solid.fs.metal
shaders/metal/tile_solid.vs.metal shaders/metal/tile_solid.vs.metal
shaders/metal/tile_solid_monochrome.vs.metal shaders/metal/tile_solid_filter_blur.fs.metal
shaders/metal/tile_solid_multicolor.vs.metal shaders/metal/tile_solid_filter_text.fs.metal
textures/area-lut.png textures/area-lut.png
textures/debug-corner-fill.png textures/debug-corner-fill.png
textures/debug-corner-outline.png textures/debug-corner-outline.png

View File

@ -1,31 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
precision highp float;
in ivec2 aPosition;
out vec2 vTexCoord;
void main(){
vec2 position = vec2(aPosition);
vTexCoord = position;
gl_Position = vec4(vec2(position)* 2.0 - 1.0, 0.0, 1.0);
}

View File

@ -1,32 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform sampler2D uSource;
in vec2 vTexCoord;
out vec4 oFragColor;
void main(){
vec4 color = texture(uSource, vTexCoord);
oFragColor = vec4(color . rgb * color . a, color . a);
}

View File

@ -1,127 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform sampler2D uSource;
uniform vec2 uSourceSize;
uniform vec4 uFGColor;
uniform vec4 uBGColor;
uniform int uGammaCorrectionEnabled;
in vec2 vTexCoord;
out vec4 oFragColor;
uniform sampler2D uGammaLUT;
float gammaCorrectChannel(float bgColor, float fgColor){
return texture(uGammaLUT, vec2(fgColor, 1.0 - bgColor)). r;
}
vec3 gammaCorrect(vec3 bgColor, vec3 fgColor){
return vec3(gammaCorrectChannel(bgColor . r, fgColor . r),
gammaCorrectChannel(bgColor . g, fgColor . g),
gammaCorrectChannel(bgColor . b, fgColor . b));
}
uniform vec4 uKernel;
float sample1Tap(float offset);
void sample9Tap(out vec4 outAlphaLeft,
out float outAlphaCenter,
out vec4 outAlphaRight,
float onePixel){
outAlphaLeft = vec4(uKernel . x > 0.0 ? sample1Tap(- 4.0 * onePixel): 0.0,
sample1Tap(- 3.0 * onePixel),
sample1Tap(- 2.0 * onePixel),
sample1Tap(- 1.0 * onePixel));
outAlphaCenter = sample1Tap(0.0);
outAlphaRight = vec4(sample1Tap(1.0 * onePixel),
sample1Tap(2.0 * onePixel),
sample1Tap(3.0 * onePixel),
uKernel . x > 0.0 ? sample1Tap(4.0 * onePixel): 0.0);
}
float convolve7Tap(vec4 alpha0, vec3 alpha1){
return dot(alpha0, uKernel)+ dot(alpha1, uKernel . zyx);
}
float sample1Tap(float offset){
return texture(uSource, vec2(vTexCoord . x + offset, vTexCoord . y)). r;
}
void main(){
vec3 alpha;
if(uKernel . w == 0.0){
alpha = texture(uSource, vTexCoord). rrr;
} else {
vec4 alphaLeft, alphaRight;
float alphaCenter;
sample9Tap(alphaLeft, alphaCenter, alphaRight, 1.0 / uSourceSize . x);
float r = convolve7Tap(alphaLeft, vec3(alphaCenter, alphaRight . xy));
float g = convolve7Tap(vec4(alphaLeft . yzw, alphaCenter), alphaRight . xyz);
float b = convolve7Tap(vec4(alphaLeft . zw, alphaCenter, alphaRight . x), alphaRight . yzw);
alpha = vec3(r, g, b);
}
if(uGammaCorrectionEnabled != 0)
alpha = gammaCorrect(uBGColor . rgb, alpha);
oFragColor = vec4(mix(uBGColor . rgb, uFGColor . rgb, alpha), 1.0);
}

View File

@ -1,34 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
precision highp float;
in vec2 aPosition;
in vec2 aFillTexCoord;
in int aBackdrop;
out vec2 vFillTexCoord;
out float vBackdrop;
void main(){
vec2 position = mix(vec2(- 1.0), vec2(1.0), aPosition);
vFillTexCoord = aFillTexCoord;
vBackdrop = float(aBackdrop);
gl_Position = vec4(position, 0.0, 1.0);
}

View File

@ -1,127 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform sampler2D uSource;
uniform vec2 uSourceSize;
uniform vec4 uFGColor;
uniform vec4 uBGColor;
uniform int uGammaCorrectionEnabled;
in vec2 vTexCoord;
out vec4 oFragColor;
uniform sampler2D uGammaLUT;
float gammaCorrectChannel(float bgColor, float fgColor){
return texture(uGammaLUT, vec2(fgColor, 1.0 - bgColor)). r;
}
vec3 gammaCorrect(vec3 bgColor, vec3 fgColor){
return vec3(gammaCorrectChannel(bgColor . r, fgColor . r),
gammaCorrectChannel(bgColor . g, fgColor . g),
gammaCorrectChannel(bgColor . b, fgColor . b));
}
uniform vec4 uKernel;
float sample1Tap(float offset);
void sample9Tap(out vec4 outAlphaLeft,
out float outAlphaCenter,
out vec4 outAlphaRight,
float onePixel){
outAlphaLeft = vec4(uKernel . x > 0.0 ? sample1Tap(- 4.0 * onePixel): 0.0,
sample1Tap(- 3.0 * onePixel),
sample1Tap(- 2.0 * onePixel),
sample1Tap(- 1.0 * onePixel));
outAlphaCenter = sample1Tap(0.0);
outAlphaRight = vec4(sample1Tap(1.0 * onePixel),
sample1Tap(2.0 * onePixel),
sample1Tap(3.0 * onePixel),
uKernel . x > 0.0 ? sample1Tap(4.0 * onePixel): 0.0);
}
float convolve7Tap(vec4 alpha0, vec3 alpha1){
return dot(alpha0, uKernel)+ dot(alpha1, uKernel . zyx);
}
float sample1Tap(float offset){
return texture(uSource, vec2(vTexCoord . x + offset, vTexCoord . y)). r;
}
void main(){
vec3 alpha;
if(uKernel . w == 0.0){
alpha = texture(uSource, vTexCoord). rrr;
} else {
vec4 alphaLeft, alphaRight;
float alphaCenter;
sample9Tap(alphaLeft, alphaCenter, alphaRight, 1.0 / uSourceSize . x);
float r = convolve7Tap(alphaLeft, vec3(alphaCenter, alphaRight . xy));
float g = convolve7Tap(vec4(alphaLeft . yzw, alphaCenter), alphaRight . xyz);
float b = convolve7Tap(vec4(alphaLeft . zw, alphaCenter, alphaRight . x), alphaRight . yzw);
alpha = vec3(r, g, b);
}
if(uGammaCorrectionEnabled != 0)
alpha = gammaCorrect(uBGColor . rgb, alpha);
oFragColor = vec4(mix(uBGColor . rgb, uFGColor . rgb, alpha), 1.0);
}

View File

@ -1,31 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
precision highp float;
in ivec2 aPosition;
out vec2 vTexCoord;
void main(){
vec2 position = vec2(aPosition);
vTexCoord = position;
gl_Position = vec4(vec2(position)* 2.0 - 1.0, 0.0, 1.0);
}

View File

@ -1,85 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
uniform vec2 uStencilTextureSize;
in uvec2 aTessCoord;
in uvec3 aTileOrigin;
in int aBackdrop;
in int aTileIndex;
out vec2 vTexCoord;
out float vBackdrop;
out vec4 vColor;
vec4 getColor();
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){
uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x);
uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
return vec2(tileOffset)* uTileSize;
}
void computeVaryings(){
vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0;
vec2 position =(origin + vec2(aTessCoord))* uTileSize;
vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize . x);
vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize;
vTexCoord = maskTexCoord / uStencilTextureSize;
vBackdrop = float(aBackdrop);
vColor = getColor();
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}
uniform vec4 uColor;
vec4 getColor(){
return uColor;
}
void main(){
computeVaryings();
}

View File

@ -1,88 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
uniform vec2 uStencilTextureSize;
in uvec2 aTessCoord;
in uvec3 aTileOrigin;
in int aBackdrop;
in int aTileIndex;
out vec2 vTexCoord;
out float vBackdrop;
out vec4 vColor;
vec4 getColor();
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){
uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x);
uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
return vec2(tileOffset)* uTileSize;
}
void computeVaryings(){
vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0;
vec2 position =(origin + vec2(aTessCoord))* uTileSize;
vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize . x);
vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize;
vTexCoord = maskTexCoord / uStencilTextureSize;
vBackdrop = float(aBackdrop);
vColor = getColor();
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}
uniform sampler2D uPaintTexture;
uniform vec2 uPaintTextureSize;
in vec2 aColorTexCoord;
vec4 getColor(){
return texture(uPaintTexture, aColorTexCoord);
}
void main(){
computeVaryings();
}

View File

@ -1,31 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
uniform vec2 uSrcSize;
in ivec2 aTilePosition;
out vec2 vTexCoord;
void main(){
vec2 position = vec2(aTilePosition)* uTileSize;
vTexCoord = position / uSrcSize;
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}

View File

@ -1,69 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform sampler2D uSrc;
uniform vec2 uSrcOffsetScale;
uniform vec3 uInitialGaussCoeff;
uniform int uSupport;
in vec2 vTexCoord;
out vec4 oFragColor;
void main(){
vec3 gaussCoeff = uInitialGaussCoeff;
float gaussSum = gaussCoeff . x;
vec4 color = texture(uSrc, vTexCoord)* gaussCoeff . x;
gaussCoeff . xy *= gaussCoeff . yz;
for(int i = 1;i <= uSupport;i += 2){
float gaussPartialSum = gaussCoeff . x;
gaussCoeff . xy *= gaussCoeff . yz;
gaussPartialSum += gaussCoeff . x;
vec2 srcOffset = uSrcOffsetScale *(float(i)+ gaussCoeff . x / gaussPartialSum);
color +=(texture(uSrc, vTexCoord - srcOffset)+ texture(uSrc, vTexCoord + srcOffset))*
gaussPartialSum;
gaussSum += 2.0 * gaussPartialSum;
gaussCoeff . xy *= gaussCoeff . yz;
}
color /= gaussSum;
color . rgb *= color . a;
oFragColor = color;
}

View File

@ -14,14 +14,14 @@
precision highp float; precision highp float;
uniform sampler2D uPaintTexture; uniform sampler2D uColorTexture;
in vec2 vColorTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
void main(){ void main(){
vec4 color = texture(uPaintTexture, vColorTexCoord); vec4 color = texture(uColorTexture, vColorTexCoord);
oFragColor = vec4(color . rgb * color . a, color . a); oFragColor = vec4(color . rgb * color . a, color . a);
} }

View File

@ -24,12 +24,12 @@
precision highp float; precision highp float;
uniform sampler2D uSrc; uniform sampler2D uColorTexture;
uniform vec2 uSrcOffsetScale; uniform vec2 uSrcOffsetScale;
uniform vec3 uInitialGaussCoeff; uniform vec3 uInitialGaussCoeff;
uniform int uSupport; uniform int uSupport;
in vec2 vTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
@ -37,7 +37,7 @@ void main(){
vec3 gaussCoeff = uInitialGaussCoeff; vec3 gaussCoeff = uInitialGaussCoeff;
float gaussSum = gaussCoeff . x; float gaussSum = gaussCoeff . x;
vec4 color = texture(uSrc, vTexCoord)* gaussCoeff . x; vec4 color = texture(uColorTexture, vColorTexCoord)* gaussCoeff . x;
gaussCoeff . xy *= gaussCoeff . yz; gaussCoeff . xy *= gaussCoeff . yz;
@ -54,8 +54,8 @@ void main(){
gaussPartialSum += gaussCoeff . x; gaussPartialSum += gaussCoeff . x;
vec2 srcOffset = uSrcOffsetScale *(float(i)+ gaussCoeff . x / gaussPartialSum); vec2 srcOffset = uSrcOffsetScale *(float(i)+ gaussCoeff . x / gaussPartialSum);
color +=(texture(uSrc, vTexCoord - srcOffset)+ texture(uSrc, vTexCoord + srcOffset))* color +=(texture(uColorTexture, vColorTexCoord - srcOffset)+
gaussPartialSum; texture(uColorTexture, vColorTexCoord + srcOffset))* gaussPartialSum;
gaussSum += 2.0 * gaussPartialSum; gaussSum += 2.0 * gaussPartialSum;
gaussCoeff . xy *= gaussCoeff . yz; gaussCoeff . xy *= gaussCoeff . yz;

View File

@ -16,13 +16,13 @@
precision highp float; precision highp float;
uniform sampler2D uSrc; uniform sampler2D uColorTexture;
uniform vec2 uSrcSize; uniform vec2 uSrcSize;
uniform vec4 uFGColor; uniform vec4 uFGColor;
uniform vec4 uBGColor; uniform vec4 uBGColor;
uniform int uGammaCorrectionEnabled; uniform int uGammaCorrectionEnabled;
in vec2 vTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
@ -94,14 +94,14 @@ float convolve7Tap(vec4 alpha0, vec3 alpha1){
float sample1Tap(float offset){ float sample1Tap(float offset){
return texture(uSrc, vec2(vTexCoord . x + offset, vTexCoord . y)). r; return texture(uColorTexture, vec2(vColorTexCoord . x + offset, vColorTexCoord . y)). r;
} }
void main(){ void main(){
vec3 alpha; vec3 alpha;
if(uKernel . w == 0.0){ if(uKernel . w == 0.0){
alpha = texture(uSrc, vTexCoord). rrr; alpha = texture(uColorTexture, vColorTexCoord). rrr;
} else { } else {
vec4 alphaLeft, alphaRight; vec4 alphaLeft, alphaRight;
float alphaCenter; float alphaCenter;

View File

@ -1,67 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
in uvec2 aTessCoord;
in ivec2 aTileOrigin;
out vec4 vColor;
vec4 getColor();
void computeVaryings(){
vec2 position = vec2(aTileOrigin + ivec2(aTessCoord))* uTileSize;
vColor = getColor();
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}
uniform vec4 uColor;
vec4 getColor(){
return uColor;
}
void main(){
computeVaryings();
}

View File

@ -1,70 +0,0 @@
#version {{version}}
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#extension GL_GOOGLE_include_directive : enable
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
in uvec2 aTessCoord;
in ivec2 aTileOrigin;
out vec4 vColor;
vec4 getColor();
void computeVaryings(){
vec2 position = vec2(aTileOrigin + ivec2(aTessCoord))* uTileSize;
vColor = getColor();
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}
uniform sampler2D uPaintTexture;
uniform vec2 uPaintTextureSize;
in vec2 aColorTexCoord;
vec4 getColor(){
return texture(uPaintTexture, aColorTexCoord);
}
void main(){
computeVaryings();
}

View File

@ -1,27 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float2 vTexCoord [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
int2 aPosition [[attribute(0)]];
};
vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float2 position = float2(in.aPosition);
out.vTexCoord = position;
position.y = 1.0 - position.y;
out.gl_Position = float4((float2(position) * 2.0) - float2(1.0), 0.0, 1.0);
return out;
}

View File

@ -1,30 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
texture2d<float> uSource [[id(0)]];
sampler uSourceSmplr [[id(1)]];
};
struct main0_out
{
float4 oFragColor [[color(0)]];
};
struct main0_in
{
float2 vTexCoord [[user(locn0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
float4 color = spvDescriptorSet0.uSource.sample(spvDescriptorSet0.uSourceSmplr, in.vTexCoord);
out.oFragColor = float4(color.xyz * color.w, color.w);
return out;
}

View File

@ -1,130 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
texture2d<float> uGammaLUT [[id(0)]];
sampler uGammaLUTSmplr [[id(1)]];
constant float4* uKernel [[id(2)]];
texture2d<float> uSource [[id(3)]];
sampler uSourceSmplr [[id(4)]];
constant float2* uSourceSize [[id(5)]];
constant int* uGammaCorrectionEnabled [[id(6)]];
constant float4* uBGColor [[id(7)]];
constant float4* uFGColor [[id(8)]];
};
struct main0_out
{
float4 oFragColor [[color(0)]];
};
struct main0_in
{
float2 vTexCoord [[user(locn0)]];
};
float sample1Tap(thread const float& offset, thread texture2d<float> uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord)
{
return uSource.sample(uSourceSmplr, float2(vTexCoord.x + offset, vTexCoord.y)).x;
}
void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const float& onePixel, thread float4 uKernel, thread texture2d<float> uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord)
{
float _89;
if (uKernel.x > 0.0)
{
float param = (-4.0) * onePixel;
_89 = sample1Tap(param, uSource, uSourceSmplr, vTexCoord);
}
else
{
_89 = 0.0;
}
float param_1 = (-3.0) * onePixel;
float param_2 = (-2.0) * onePixel;
float param_3 = (-1.0) * onePixel;
outAlphaLeft = float4(_89, sample1Tap(param_1, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_2, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_3, uSource, uSourceSmplr, vTexCoord));
float param_4 = 0.0;
outAlphaCenter = sample1Tap(param_4, uSource, uSourceSmplr, vTexCoord);
float param_5 = 1.0 * onePixel;
float param_6 = 2.0 * onePixel;
float param_7 = 3.0 * onePixel;
float _134;
if (uKernel.x > 0.0)
{
float param_8 = 4.0 * onePixel;
_134 = sample1Tap(param_8, uSource, uSourceSmplr, vTexCoord);
}
else
{
_134 = 0.0;
}
outAlphaRight = float4(sample1Tap(param_5, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_6, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_7, uSource, uSourceSmplr, vTexCoord), _134);
}
float convolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread float4 uKernel)
{
return dot(alpha0, uKernel) + dot(alpha1, uKernel.zyx);
}
float gammaCorrectChannel(thread const float& bgColor, thread const float& fgColor, thread texture2d<float> uGammaLUT, thread const sampler uGammaLUTSmplr)
{
return uGammaLUT.sample(uGammaLUTSmplr, float2(fgColor, 1.0 - bgColor)).x;
}
float3 gammaCorrect(thread const float3& bgColor, thread const float3& fgColor, thread texture2d<float> uGammaLUT, thread const sampler uGammaLUTSmplr)
{
float param = bgColor.x;
float param_1 = fgColor.x;
float param_2 = bgColor.y;
float param_3 = fgColor.y;
float param_4 = bgColor.z;
float param_5 = fgColor.z;
return float3(gammaCorrectChannel(param, param_1, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_2, param_3, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_4, param_5, uGammaLUT, uGammaLUTSmplr));
}
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
float3 alpha;
if ((*spvDescriptorSet0.uKernel).w == 0.0)
{
alpha = spvDescriptorSet0.uSource.sample(spvDescriptorSet0.uSourceSmplr, in.vTexCoord).xxx;
}
else
{
float param_3 = 1.0 / (*spvDescriptorSet0.uSourceSize).x;
float4 param;
float param_1;
float4 param_2;
sample9Tap(param, param_1, param_2, param_3, (*spvDescriptorSet0.uKernel), spvDescriptorSet0.uSource, spvDescriptorSet0.uSourceSmplr, in.vTexCoord);
float4 alphaLeft = param;
float alphaCenter = param_1;
float4 alphaRight = param_2;
float4 param_4 = alphaLeft;
float3 param_5 = float3(alphaCenter, alphaRight.xy);
float r = convolve7Tap(param_4, param_5, (*spvDescriptorSet0.uKernel));
float4 param_6 = float4(alphaLeft.yzw, alphaCenter);
float3 param_7 = alphaRight.xyz;
float g = convolve7Tap(param_6, param_7, (*spvDescriptorSet0.uKernel));
float4 param_8 = float4(alphaLeft.zw, alphaCenter, alphaRight.x);
float3 param_9 = alphaRight.yzw;
float b = convolve7Tap(param_8, param_9, (*spvDescriptorSet0.uKernel));
alpha = float3(r, g, b);
}
if ((*spvDescriptorSet0.uGammaCorrectionEnabled) != 0)
{
float3 param_10 = (*spvDescriptorSet0.uBGColor).xyz;
float3 param_11 = alpha;
alpha = gammaCorrect(param_10, param_11, spvDescriptorSet0.uGammaLUT, spvDescriptorSet0.uGammaLUTSmplr);
}
out.oFragColor = float4(mix((*spvDescriptorSet0.uBGColor).xyz, (*spvDescriptorSet0.uFGColor).xyz, alpha), 1.0);
return out;
}

View File

@ -1,31 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float2 vFillTexCoord [[user(locn0)]];
float vBackdrop [[user(locn1)]];
float4 gl_Position [[position]];
};
struct main0_in
{
float2 aPosition [[attribute(0)]];
float2 aFillTexCoord [[attribute(1)]];
int aBackdrop [[attribute(2)]];
};
vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float2 position = mix(float2(-1.0), float2(1.0), in.aPosition);
position.y = -position.y;
out.vFillTexCoord = in.aFillTexCoord;
out.vBackdrop = float(in.aBackdrop);
out.gl_Position = float4(position, 0.0, 1.0);
return out;
}

View File

@ -1,133 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
texture2d<float> uGammaLUT [[id(0)]];
sampler uGammaLUTSmplr [[id(1)]];
constant float4* uKernel [[id(2)]];
texture2d<float> uSource [[id(3)]];
sampler uSourceSmplr [[id(4)]];
constant float2* uSourceSize [[id(5)]];
constant int* uGammaCorrectionEnabled [[id(6)]];
constant float4* uBGColor [[id(7)]];
constant float4* uFGColor [[id(8)]];
};
struct main0_out
{
float4 oFragColor [[color(0)]];
};
struct main0_in
{
float2 vTexCoord [[user(locn0)]];
};
float sample1Tap(thread const float& offset, thread texture2d<float> uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord)
{
return uSource.sample(uSourceSmplr, float2(vTexCoord.x + offset, vTexCoord.y)).x;
}
void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const float& onePixel, thread float4 uKernel, thread texture2d<float> uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord)
{
float _89;
if (uKernel.x > 0.0)
{
float param = (-4.0) * onePixel;
_89 = sample1Tap(param, uSource, uSourceSmplr, vTexCoord);
}
else
{
_89 = 0.0;
}
float param_1 = (-3.0) * onePixel;
float param_2 = (-2.0) * onePixel;
float param_3 = (-1.0) * onePixel;
outAlphaLeft = float4(_89, sample1Tap(param_1, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_2, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_3, uSource, uSourceSmplr, vTexCoord));
float param_4 = 0.0;
outAlphaCenter = sample1Tap(param_4, uSource, uSourceSmplr, vTexCoord);
float param_5 = 1.0 * onePixel;
float _120 = sample1Tap(param_5, uSource, uSourceSmplr, vTexCoord);
float param_6 = 2.0 * onePixel;
float _125 = sample1Tap(param_6, uSource, uSourceSmplr, vTexCoord);
float param_7 = 3.0 * onePixel;
float _130 = sample1Tap(param_7, uSource, uSourceSmplr, vTexCoord);
float _134;
if (uKernel.x > 0.0)
{
float param_8 = 4.0 * onePixel;
_134 = sample1Tap(param_8, uSource, uSourceSmplr, vTexCoord);
}
else
{
_134 = 0.0;
}
outAlphaRight = float4(_120, _125, _130, _134);
}
float convolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread float4 uKernel)
{
return dot(alpha0, uKernel) + dot(alpha1, uKernel.zyx);
}
float gammaCorrectChannel(thread const float& bgColor, thread const float& fgColor, thread texture2d<float> uGammaLUT, thread const sampler uGammaLUTSmplr)
{
return uGammaLUT.sample(uGammaLUTSmplr, float2(fgColor, 1.0 - bgColor)).x;
}
float3 gammaCorrect(thread const float3& bgColor, thread const float3& fgColor, thread texture2d<float> uGammaLUT, thread const sampler uGammaLUTSmplr)
{
float param = bgColor.x;
float param_1 = fgColor.x;
float param_2 = bgColor.y;
float param_3 = fgColor.y;
float param_4 = bgColor.z;
float param_5 = fgColor.z;
return float3(gammaCorrectChannel(param, param_1, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_2, param_3, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_4, param_5, uGammaLUT, uGammaLUTSmplr));
}
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
float3 alpha;
if ((*spvDescriptorSet0.uKernel).w == 0.0)
{
alpha = spvDescriptorSet0.uSource.sample(spvDescriptorSet0.uSourceSmplr, in.vTexCoord).xxx;
}
else
{
float param_3 = 1.0 / (*spvDescriptorSet0.uSourceSize).x;
float4 param;
float param_1;
float4 param_2;
sample9Tap(param, param_1, param_2, param_3, (*spvDescriptorSet0.uKernel), spvDescriptorSet0.uSource, spvDescriptorSet0.uSourceSmplr, in.vTexCoord);
float4 alphaLeft = param;
float alphaCenter = param_1;
float4 alphaRight = param_2;
float4 param_4 = alphaLeft;
float3 param_5 = float3(alphaCenter, alphaRight.xy);
float r = convolve7Tap(param_4, param_5, (*spvDescriptorSet0.uKernel));
float4 param_6 = float4(alphaLeft.yzw, alphaCenter);
float3 param_7 = alphaRight.xyz;
float g = convolve7Tap(param_6, param_7, (*spvDescriptorSet0.uKernel));
float4 param_8 = float4(alphaLeft.zw, alphaCenter, alphaRight.x);
float3 param_9 = alphaRight.yzw;
float b = convolve7Tap(param_8, param_9, (*spvDescriptorSet0.uKernel));
alpha = float3(r, g, b);
}
if ((*spvDescriptorSet0.uGammaCorrectionEnabled) != 0)
{
float3 param_10 = (*spvDescriptorSet0.uBGColor).xyz;
float3 param_11 = alpha;
alpha = gammaCorrect(param_10, param_11, spvDescriptorSet0.uGammaLUT, spvDescriptorSet0.uGammaLUTSmplr);
}
out.oFragColor = float4(mix((*spvDescriptorSet0.uBGColor).xyz, (*spvDescriptorSet0.uFGColor).xyz, alpha), 1.0);
return out;
}

View File

@ -1,27 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float2 vTexCoord [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
int2 aPosition [[attribute(0)]];
};
vertex main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float2 position = float2(in.aPosition);
out.vTexCoord = position;
position.y = 1.0 - position.y;
out.gl_Position = float4((float2(position) * 2.0) - float2(1.0), 0.0, 1.0);
return out;
}

View File

@ -1,65 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float2* uTileSize [[id(0)]];
constant float2* uStencilTextureSize [[id(1)]];
constant float4x4* uTransform [[id(2)]];
constant float4* uColor [[id(3)]];
};
struct main0_out
{
float2 vTexCoord [[user(locn0)]];
float vBackdrop [[user(locn1)]];
float4 vColor [[user(locn2)]];
float4 gl_Position [[position]];
};
struct main0_in
{
uint2 aTessCoord [[attribute(0)]];
uint3 aTileOrigin [[attribute(1)]];
int aBackdrop [[attribute(2)]];
int aTileIndex [[attribute(3)]];
};
float2 computeTileOffset(thread const uint& tileIndex, thread const float& stencilTextureWidth, thread float2 uTileSize)
{
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
uint2 tileOffset = uint2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
return float2(tileOffset) * uTileSize;
}
float4 getColor(thread float4 uColor)
{
return uColor;
}
void computeVaryings(thread float2 uTileSize, thread uint3& aTileOrigin, thread uint2& aTessCoord, thread int& aTileIndex, thread float2 uStencilTextureSize, thread float2& vTexCoord, thread float& vBackdrop, thread int& aBackdrop, thread float4& vColor, thread float4& gl_Position, thread float4x4 uTransform, thread float4 uColor)
{
float2 origin = float2(aTileOrigin.xy) + (float2(float(aTileOrigin.z & 15u), float(aTileOrigin.z >> 4u)) * 256.0);
float2 position = (origin + float2(aTessCoord)) * uTileSize;
uint param = uint(aTileIndex);
float param_1 = uStencilTextureSize.x;
float2 maskTexCoordOrigin = computeTileOffset(param, param_1, uTileSize);
float2 maskTexCoord = maskTexCoordOrigin + (float2(aTessCoord) * uTileSize);
vTexCoord = maskTexCoord / uStencilTextureSize;
vBackdrop = float(aBackdrop);
vColor = getColor(uColor);
gl_Position = uTransform * float4(position, 0.0, 1.0);
}
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
computeVaryings((*spvDescriptorSet0.uTileSize), in.aTileOrigin, in.aTessCoord, in.aTileIndex, (*spvDescriptorSet0.uStencilTextureSize), out.vTexCoord, out.vBackdrop, in.aBackdrop, out.vColor, out.gl_Position, (*spvDescriptorSet0.uTransform), (*spvDescriptorSet0.uColor));
return out;
}

View File

@ -1,67 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float2* uTileSize [[id(0)]];
constant float2* uStencilTextureSize [[id(1)]];
constant float4x4* uTransform [[id(2)]];
texture2d<float> uPaintTexture [[id(3)]];
sampler uPaintTextureSmplr [[id(4)]];
};
struct main0_out
{
float2 vTexCoord [[user(locn0)]];
float vBackdrop [[user(locn1)]];
float4 vColor [[user(locn2)]];
float4 gl_Position [[position]];
};
struct main0_in
{
uint2 aTessCoord [[attribute(0)]];
uint3 aTileOrigin [[attribute(1)]];
int aBackdrop [[attribute(2)]];
int aTileIndex [[attribute(3)]];
float2 aColorTexCoord [[attribute(4)]];
};
float2 computeTileOffset(thread const uint& tileIndex, thread const float& stencilTextureWidth, thread float2 uTileSize)
{
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
uint2 tileOffset = uint2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
return float2(tileOffset) * uTileSize;
}
float4 getColor(thread texture2d<float> uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord)
{
return uPaintTexture.sample(uPaintTextureSmplr, aColorTexCoord, level(0.0));
}
void computeVaryings(thread float2 uTileSize, thread uint3& aTileOrigin, thread uint2& aTessCoord, thread int& aTileIndex, thread float2 uStencilTextureSize, thread float2& vTexCoord, thread float& vBackdrop, thread int& aBackdrop, thread float4& vColor, thread float4& gl_Position, thread float4x4 uTransform, thread texture2d<float> uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord)
{
float2 origin = float2(aTileOrigin.xy) + (float2(float(aTileOrigin.z & 15u), float(aTileOrigin.z >> 4u)) * 256.0);
float2 position = (origin + float2(aTessCoord)) * uTileSize;
uint param = uint(aTileIndex);
float param_1 = uStencilTextureSize.x;
float2 maskTexCoordOrigin = computeTileOffset(param, param_1, uTileSize);
float2 maskTexCoord = maskTexCoordOrigin + (float2(aTessCoord) * uTileSize);
vTexCoord = maskTexCoord / uStencilTextureSize;
vBackdrop = float(aBackdrop);
vColor = getColor(uPaintTexture, uPaintTextureSmplr, aColorTexCoord);
gl_Position = uTransform * float4(position, 0.0, 1.0);
}
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
computeVaryings((*spvDescriptorSet0.uTileSize), in.aTileOrigin, in.aTessCoord, in.aTileIndex, (*spvDescriptorSet0.uStencilTextureSize), out.vTexCoord, out.vBackdrop, in.aBackdrop, out.vColor, out.gl_Position, (*spvDescriptorSet0.uTransform), spvDescriptorSet0.uPaintTexture, spvDescriptorSet0.uPaintTextureSmplr, in.aColorTexCoord);
return out;
}

View File

@ -1,33 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float2* uTileSize [[id(0)]];
constant float2* uSrcSize [[id(1)]];
constant float4x4* uTransform [[id(2)]];
};
struct main0_out
{
float2 vTexCoord [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
int2 aTilePosition [[attribute(0)]];
};
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
float2 position = float2(in.aTilePosition) * (*spvDescriptorSet0.uTileSize);
out.vTexCoord = position / (*spvDescriptorSet0.uSrcSize);
out.gl_Position = (*spvDescriptorSet0.uTransform) * float4(position, 0.0, 1.0);
return out;
}

View File

@ -1,52 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float3* uInitialGaussCoeff [[id(0)]];
texture2d<float> uSrc [[id(1)]];
sampler uSrcSmplr [[id(2)]];
constant int* uSupport [[id(3)]];
constant float2* uSrcOffsetScale [[id(4)]];
};
struct main0_out
{
float4 oFragColor [[color(0)]];
};
struct main0_in
{
float2 vTexCoord [[user(locn0)]];
};
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
float3 gaussCoeff = (*spvDescriptorSet0.uInitialGaussCoeff);
float gaussSum = gaussCoeff.x;
float4 color = spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, in.vTexCoord) * gaussCoeff.x;
float2 _39 = gaussCoeff.xy * gaussCoeff.yz;
gaussCoeff = float3(_39.x, _39.y, gaussCoeff.z);
for (int i = 1; i <= (*spvDescriptorSet0.uSupport); i += 2)
{
float gaussPartialSum = gaussCoeff.x;
float2 _64 = gaussCoeff.xy * gaussCoeff.yz;
gaussCoeff = float3(_64.x, _64.y, gaussCoeff.z);
gaussPartialSum += gaussCoeff.x;
float2 srcOffset = (*spvDescriptorSet0.uSrcOffsetScale) * (float(i) + (gaussCoeff.x / gaussPartialSum));
color += ((spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, (in.vTexCoord - srcOffset)) + spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, (in.vTexCoord + srcOffset))) * gaussPartialSum);
gaussSum += (2.0 * gaussPartialSum);
float2 _108 = gaussCoeff.xy * gaussCoeff.yz;
gaussCoeff = float3(_108.x, _108.y, gaussCoeff.z);
}
color /= float4(gaussSum);
float3 _123 = color.xyz * color.w;
color = float4(_123.x, _123.y, _123.z, color.w);
out.oFragColor = color;
return out;
}

View File

@ -6,8 +6,8 @@ using namespace metal;
struct spvDescriptorSetBuffer0 struct spvDescriptorSetBuffer0
{ {
texture2d<float> uPaintTexture [[id(0)]]; texture2d<float> uColorTexture [[id(0)]];
sampler uPaintTextureSmplr [[id(1)]]; sampler uColorTextureSmplr [[id(1)]];
}; };
struct main0_out struct main0_out
@ -23,7 +23,7 @@ struct main0_in
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{ {
main0_out out = {}; main0_out out = {};
float4 color = spvDescriptorSet0.uPaintTexture.sample(spvDescriptorSet0.uPaintTextureSmplr, in.vColorTexCoord); float4 color = spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, in.vColorTexCoord);
out.oFragColor = float4(color.xyz * color.w, color.w); out.oFragColor = float4(color.xyz * color.w, color.w);
return out; return out;
} }

View File

@ -7,8 +7,8 @@ using namespace metal;
struct spvDescriptorSetBuffer0 struct spvDescriptorSetBuffer0
{ {
constant float3* uInitialGaussCoeff [[id(0)]]; constant float3* uInitialGaussCoeff [[id(0)]];
texture2d<float> uSrc [[id(1)]]; texture2d<float> uColorTexture [[id(1)]];
sampler uSrcSmplr [[id(2)]]; sampler uColorTextureSmplr [[id(2)]];
constant int* uSupport [[id(3)]]; constant int* uSupport [[id(3)]];
constant float2* uSrcOffsetScale [[id(4)]]; constant float2* uSrcOffsetScale [[id(4)]];
}; };
@ -20,7 +20,7 @@ struct main0_out
struct main0_in struct main0_in
{ {
float2 vTexCoord [[user(locn0)]]; float2 vColorTexCoord [[user(locn0)]];
}; };
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
@ -28,7 +28,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff
main0_out out = {}; main0_out out = {};
float3 gaussCoeff = (*spvDescriptorSet0.uInitialGaussCoeff); float3 gaussCoeff = (*spvDescriptorSet0.uInitialGaussCoeff);
float gaussSum = gaussCoeff.x; float gaussSum = gaussCoeff.x;
float4 color = spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, in.vTexCoord) * gaussCoeff.x; float4 color = spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, in.vColorTexCoord) * gaussCoeff.x;
float2 _39 = gaussCoeff.xy * gaussCoeff.yz; float2 _39 = gaussCoeff.xy * gaussCoeff.yz;
gaussCoeff = float3(_39.x, _39.y, gaussCoeff.z); gaussCoeff = float3(_39.x, _39.y, gaussCoeff.z);
for (int i = 1; i <= (*spvDescriptorSet0.uSupport); i += 2) for (int i = 1; i <= (*spvDescriptorSet0.uSupport); i += 2)
@ -38,7 +38,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff
gaussCoeff = float3(_64.x, _64.y, gaussCoeff.z); gaussCoeff = float3(_64.x, _64.y, gaussCoeff.z);
gaussPartialSum += gaussCoeff.x; gaussPartialSum += gaussCoeff.x;
float2 srcOffset = (*spvDescriptorSet0.uSrcOffsetScale) * (float(i) + (gaussCoeff.x / gaussPartialSum)); float2 srcOffset = (*spvDescriptorSet0.uSrcOffsetScale) * (float(i) + (gaussCoeff.x / gaussPartialSum));
color += ((spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, (in.vTexCoord - srcOffset)) + spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, (in.vTexCoord + srcOffset))) * gaussPartialSum); color += ((spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, (in.vColorTexCoord - srcOffset)) + spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, (in.vColorTexCoord + srcOffset))) * gaussPartialSum);
gaussSum += (2.0 * gaussPartialSum); gaussSum += (2.0 * gaussPartialSum);
float2 _108 = gaussCoeff.xy * gaussCoeff.yz; float2 _108 = gaussCoeff.xy * gaussCoeff.yz;
gaussCoeff = float3(_108.x, _108.y, gaussCoeff.z); gaussCoeff = float3(_108.x, _108.y, gaussCoeff.z);

View File

@ -11,8 +11,8 @@ struct spvDescriptorSetBuffer0
texture2d<float> uGammaLUT [[id(0)]]; texture2d<float> uGammaLUT [[id(0)]];
sampler uGammaLUTSmplr [[id(1)]]; sampler uGammaLUTSmplr [[id(1)]];
constant float4* uKernel [[id(2)]]; constant float4* uKernel [[id(2)]];
texture2d<float> uSrc [[id(3)]]; texture2d<float> uColorTexture [[id(3)]];
sampler uSrcSmplr [[id(4)]]; sampler uColorTextureSmplr [[id(4)]];
constant float2* uSrcSize [[id(5)]]; constant float2* uSrcSize [[id(5)]];
constant int* uGammaCorrectionEnabled [[id(6)]]; constant int* uGammaCorrectionEnabled [[id(6)]];
constant float4* uBGColor [[id(7)]]; constant float4* uBGColor [[id(7)]];
@ -26,21 +26,21 @@ struct main0_out
struct main0_in struct main0_in
{ {
float2 vTexCoord [[user(locn0)]]; float2 vColorTexCoord [[user(locn0)]];
}; };
float sample1Tap(thread const float& offset, thread texture2d<float> uSrc, thread const sampler uSrcSmplr, thread float2& vTexCoord) float sample1Tap(thread const float& offset, thread texture2d<float> uColorTexture, thread const sampler uColorTextureSmplr, thread float2& vColorTexCoord)
{ {
return uSrc.sample(uSrcSmplr, float2(vTexCoord.x + offset, vTexCoord.y)).x; return uColorTexture.sample(uColorTextureSmplr, float2(vColorTexCoord.x + offset, vColorTexCoord.y)).x;
} }
void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const float& onePixel, thread float4 uKernel, thread texture2d<float> uSrc, thread const sampler uSrcSmplr, thread float2& vTexCoord) void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const float& onePixel, thread float4 uKernel, thread texture2d<float> uColorTexture, thread const sampler uColorTextureSmplr, thread float2& vColorTexCoord)
{ {
float _89; float _89;
if (uKernel.x > 0.0) if (uKernel.x > 0.0)
{ {
float param = (-4.0) * onePixel; float param = (-4.0) * onePixel;
_89 = sample1Tap(param, uSrc, uSrcSmplr, vTexCoord); _89 = sample1Tap(param, uColorTexture, uColorTextureSmplr, vColorTexCoord);
} }
else else
{ {
@ -49,9 +49,9 @@ void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, threa
float param_1 = (-3.0) * onePixel; float param_1 = (-3.0) * onePixel;
float param_2 = (-2.0) * onePixel; float param_2 = (-2.0) * onePixel;
float param_3 = (-1.0) * onePixel; float param_3 = (-1.0) * onePixel;
outAlphaLeft = float4(_89, sample1Tap(param_1, uSrc, uSrcSmplr, vTexCoord), sample1Tap(param_2, uSrc, uSrcSmplr, vTexCoord), sample1Tap(param_3, uSrc, uSrcSmplr, vTexCoord)); outAlphaLeft = float4(_89, sample1Tap(param_1, uColorTexture, uColorTextureSmplr, vColorTexCoord), sample1Tap(param_2, uColorTexture, uColorTextureSmplr, vColorTexCoord), sample1Tap(param_3, uColorTexture, uColorTextureSmplr, vColorTexCoord));
float param_4 = 0.0; float param_4 = 0.0;
outAlphaCenter = sample1Tap(param_4, uSrc, uSrcSmplr, vTexCoord); outAlphaCenter = sample1Tap(param_4, uColorTexture, uColorTextureSmplr, vColorTexCoord);
float param_5 = 1.0 * onePixel; float param_5 = 1.0 * onePixel;
float param_6 = 2.0 * onePixel; float param_6 = 2.0 * onePixel;
float param_7 = 3.0 * onePixel; float param_7 = 3.0 * onePixel;
@ -59,13 +59,13 @@ void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, threa
if (uKernel.x > 0.0) if (uKernel.x > 0.0)
{ {
float param_8 = 4.0 * onePixel; float param_8 = 4.0 * onePixel;
_134 = sample1Tap(param_8, uSrc, uSrcSmplr, vTexCoord); _134 = sample1Tap(param_8, uColorTexture, uColorTextureSmplr, vColorTexCoord);
} }
else else
{ {
_134 = 0.0; _134 = 0.0;
} }
outAlphaRight = float4(sample1Tap(param_5, uSrc, uSrcSmplr, vTexCoord), sample1Tap(param_6, uSrc, uSrcSmplr, vTexCoord), sample1Tap(param_7, uSrc, uSrcSmplr, vTexCoord), _134); outAlphaRight = float4(sample1Tap(param_5, uColorTexture, uColorTextureSmplr, vColorTexCoord), sample1Tap(param_6, uColorTexture, uColorTextureSmplr, vColorTexCoord), sample1Tap(param_7, uColorTexture, uColorTextureSmplr, vColorTexCoord), _134);
} }
float convolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread float4 uKernel) float convolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread float4 uKernel)
@ -95,7 +95,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff
float3 alpha; float3 alpha;
if ((*spvDescriptorSet0.uKernel).w == 0.0) if ((*spvDescriptorSet0.uKernel).w == 0.0)
{ {
alpha = spvDescriptorSet0.uSrc.sample(spvDescriptorSet0.uSrcSmplr, in.vTexCoord).xxx; alpha = spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, in.vColorTexCoord).xxx;
} }
else else
{ {
@ -103,7 +103,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff
float4 param; float4 param;
float param_1; float param_1;
float4 param_2; float4 param_2;
sample9Tap(param, param_1, param_2, param_3, (*spvDescriptorSet0.uKernel), spvDescriptorSet0.uSrc, spvDescriptorSet0.uSrcSmplr, in.vTexCoord); sample9Tap(param, param_1, param_2, param_3, (*spvDescriptorSet0.uKernel), spvDescriptorSet0.uColorTexture, spvDescriptorSet0.uColorTextureSmplr, in.vColorTexCoord);
float4 alphaLeft = param; float4 alphaLeft = param;
float alphaCenter = param_1; float alphaCenter = param_1;
float4 alphaRight = param_2; float4 alphaRight = param_2;

View File

@ -1,46 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float2* uTileSize [[id(0)]];
constant float4x4* uTransform [[id(1)]];
constant float4* uColor [[id(2)]];
};
struct main0_out
{
float4 vColor [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
uint2 aTessCoord [[attribute(0)]];
int2 aTileOrigin [[attribute(1)]];
};
float4 getColor(thread float4 uColor)
{
return uColor;
}
void computeVaryings(thread int2& aTileOrigin, thread uint2& aTessCoord, thread float2 uTileSize, thread float4& vColor, thread float4& gl_Position, thread float4x4 uTransform, thread float4 uColor)
{
float2 position = float2(aTileOrigin + int2(aTessCoord)) * uTileSize;
vColor = getColor(uColor);
gl_Position = uTransform * float4(position, 0.0, 1.0);
}
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
computeVaryings(in.aTileOrigin, in.aTessCoord, (*spvDescriptorSet0.uTileSize), out.vColor, out.gl_Position, (*spvDescriptorSet0.uTransform), (*spvDescriptorSet0.uColor));
return out;
}

View File

@ -1,48 +0,0 @@
// Automatically generated from files in pathfinder/shaders/. Do not edit!
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
constant float2* uTileSize [[id(0)]];
constant float4x4* uTransform [[id(1)]];
texture2d<float> uPaintTexture [[id(2)]];
sampler uPaintTextureSmplr [[id(3)]];
};
struct main0_out
{
float4 vColor [[user(locn0)]];
float4 gl_Position [[position]];
};
struct main0_in
{
uint2 aTessCoord [[attribute(0)]];
int2 aTileOrigin [[attribute(1)]];
float2 aColorTexCoord [[attribute(2)]];
};
float4 getColor(thread texture2d<float> uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord)
{
return uPaintTexture.sample(uPaintTextureSmplr, aColorTexCoord, level(0.0));
}
void computeVaryings(thread int2& aTileOrigin, thread uint2& aTessCoord, thread float2 uTileSize, thread float4& vColor, thread float4& gl_Position, thread float4x4 uTransform, thread texture2d<float> uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord)
{
float2 position = float2(aTileOrigin + int2(aTessCoord)) * uTileSize;
vColor = getColor(uPaintTexture, uPaintTextureSmplr, aColorTexCoord);
gl_Position = uTransform * float4(position, 0.0, 1.0);
}
vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
main0_out out = {};
computeVaryings(in.aTileOrigin, in.aTessCoord, (*spvDescriptorSet0.uTileSize), out.vColor, out.gl_Position, (*spvDescriptorSet0.uTransform), spvDescriptorSet0.uPaintTexture, spvDescriptorSet0.uPaintTextureSmplr, in.aColorTexCoord);
return out;
}

View File

@ -30,17 +30,16 @@ SHADERS=\
tile_alpha_softlight.fs.glsl \ tile_alpha_softlight.fs.glsl \
tile_copy.fs.glsl \ tile_copy.fs.glsl \
tile_copy.vs.glsl \ tile_copy.vs.glsl \
tile_filter.vs.glsl \
tile_filter_blur.fs.glsl \
tile_filter_text.fs.glsl \
tile_solid.fs.glsl \ tile_solid.fs.glsl \
tile_solid.vs.glsl \ tile_solid.vs.glsl \
tile_solid_filter_blur.fs.glsl \
tile_solid_filter_text.fs.glsl \
$(EMPTY) $(EMPTY)
INCLUDES=\ INCLUDES=\
tile_alpha_sample.inc.glsl \ tile_alpha_sample.inc.glsl \
tile_filter_text_convolve.inc.glsl \ tile_solid_filter_text_convolve.inc.glsl \
tile_filter_text_gamma_correct.inc.glsl \ tile_solid_filter_text_gamma_correct.inc.glsl \
$(EMPTY) $(EMPTY)
OUT=\ OUT=\

View File

@ -1,28 +0,0 @@
#version 330
// pathfinder/shaders/tile_filter.vs.glsl
//
// Copyright © 2020 The Pathfinder Project Developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
precision highp float;
uniform mat4 uTransform;
uniform vec2 uTileSize;
uniform vec2 uSrcSize;
in ivec2 aTilePosition;
out vec2 vTexCoord;
void main() {
vec2 position = vec2(aTilePosition) * uTileSize;
vTexCoord = position / uSrcSize;
gl_Position = uTransform * vec4(position, 0.0, 1.0);
}

View File

@ -12,13 +12,13 @@
precision highp float; precision highp float;
uniform sampler2D uPaintTexture; uniform sampler2D uColorTexture;
in vec2 vColorTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
void main() { void main() {
vec4 color = texture(uPaintTexture, vColorTexCoord); vec4 color = texture(uColorTexture, vColorTexCoord);
oFragColor = vec4(color.rgb * color.a, color.a); oFragColor = vec4(color.rgb * color.a, color.a);
} }

View File

@ -1,6 +1,6 @@
#version 330 #version 330
// pathfinder/shaders/filter_blur.fs.glsl // pathfinder/shaders/tile_solid_filter_blur.fs.glsl
// //
// Copyright © 2020 The Pathfinder Project Developers. // Copyright © 2020 The Pathfinder Project Developers.
// //
@ -22,12 +22,12 @@
precision highp float; precision highp float;
uniform sampler2D uSrc; uniform sampler2D uColorTexture;
uniform vec2 uSrcOffsetScale; uniform vec2 uSrcOffsetScale;
uniform vec3 uInitialGaussCoeff; uniform vec3 uInitialGaussCoeff;
uniform int uSupport; uniform int uSupport;
in vec2 vTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
@ -35,7 +35,7 @@ void main() {
// Set up our incremental calculation. // Set up our incremental calculation.
vec3 gaussCoeff = uInitialGaussCoeff; vec3 gaussCoeff = uInitialGaussCoeff;
float gaussSum = gaussCoeff.x; float gaussSum = gaussCoeff.x;
vec4 color = texture(uSrc, vTexCoord) * gaussCoeff.x; vec4 color = texture(uColorTexture, vColorTexCoord) * gaussCoeff.x;
gaussCoeff.xy *= gaussCoeff.yz; gaussCoeff.xy *= gaussCoeff.yz;
// This is a common trick that lets us use the texture filtering hardware to evaluate two // This is a common trick that lets us use the texture filtering hardware to evaluate two
@ -52,8 +52,8 @@ void main() {
gaussPartialSum += gaussCoeff.x; gaussPartialSum += gaussCoeff.x;
vec2 srcOffset = uSrcOffsetScale * (float(i) + gaussCoeff.x / gaussPartialSum); vec2 srcOffset = uSrcOffsetScale * (float(i) + gaussCoeff.x / gaussPartialSum);
color += (texture(uSrc, vTexCoord - srcOffset) + texture(uSrc, vTexCoord + srcOffset)) * color += (texture(uColorTexture, vColorTexCoord - srcOffset) +
gaussPartialSum; texture(uColorTexture, vColorTexCoord + srcOffset)) * gaussPartialSum;
gaussSum += 2.0 * gaussPartialSum; gaussSum += 2.0 * gaussPartialSum;
gaussCoeff.xy *= gaussCoeff.yz; gaussCoeff.xy *= gaussCoeff.yz;
@ -64,4 +64,3 @@ void main() {
color.rgb *= color.a; color.rgb *= color.a;
oFragColor = color; oFragColor = color;
} }

View File

@ -1,8 +1,8 @@
#version 330 #version 330
// pathfinder/shaders/tile_filter_text.fs.glsl // pathfinder/shaders/tile_solid_filter_text.fs.glsl
// //
// Copyright © 2019 The Pathfinder Project Developers. // Copyright © 2020 The Pathfinder Project Developers.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
@ -14,29 +14,29 @@
precision highp float; precision highp float;
uniform sampler2D uSrc; uniform sampler2D uColorTexture;
uniform vec2 uSrcSize; uniform vec2 uSrcSize;
uniform vec4 uFGColor; uniform vec4 uFGColor;
uniform vec4 uBGColor; uniform vec4 uBGColor;
uniform int uGammaCorrectionEnabled; uniform int uGammaCorrectionEnabled;
in vec2 vTexCoord; in vec2 vColorTexCoord;
out vec4 oFragColor; out vec4 oFragColor;
#include "tile_filter_text_gamma_correct.inc.glsl" #include "tile_solid_filter_text_gamma_correct.inc.glsl"
#include "tile_filter_text_convolve.inc.glsl" #include "tile_solid_filter_text_convolve.inc.glsl"
// Convolve horizontally in this pass. // Convolve horizontally in this pass.
float sample1Tap(float offset) { float sample1Tap(float offset) {
return texture(uSrc, vec2(vTexCoord.x + offset, vTexCoord.y)).r; return texture(uColorTexture, vec2(vColorTexCoord.x + offset, vColorTexCoord.y)).r;
} }
void main() { void main() {
// Apply defringing if necessary. // Apply defringing if necessary.
vec3 alpha; vec3 alpha;
if (uKernel.w == 0.0) { if (uKernel.w == 0.0) {
alpha = texture(uSrc, vTexCoord).rrr; alpha = texture(uColorTexture, vColorTexCoord).rrr;
} else { } else {
vec4 alphaLeft, alphaRight; vec4 alphaLeft, alphaRight;
float alphaCenter; float alphaCenter;

View File

@ -1,4 +1,4 @@
// pathfinder/shaders/tile_filter_text_convolve.inc.glsl // pathfinder/shaders/tile_solid_filter_text_convolve.inc.glsl
// //
// Copyright © 2020 The Pathfinder Project Developers. // Copyright © 2020 The Pathfinder Project Developers.
// //

View File

@ -1,6 +1,6 @@
// pathfinder/shaders/filter_text_gamma_correct.inc.glsl // pathfinder/shaders/tile_solid_filter_text_gamma_correct.inc.glsl
// //
// Copyright © 2019 The Pathfinder Project Developers. // Copyright © 2020 The Pathfinder Project Developers.
// //
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license