From 2548ab853a46ae53b209c62c1bd60b8af8e573ed Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 5 Mar 2020 12:22:01 -0800 Subject: [PATCH] Unify solid tiles and render target tiles. This commit also removes old shaders from the manifest. --- renderer/src/builder.rs | 75 +++-- renderer/src/gpu/renderer.rs | 310 ++++++------------ renderer/src/gpu/shaders.rs | 154 +++------ renderer/src/gpu_data.rs | 44 +-- renderer/src/paint.rs | 67 ++-- renderer/src/tiles.rs | 7 +- renderer/src/z_buffer.rs | 69 +++- resources/MANIFEST | 27 +- resources/shaders/gl3/filter.vs.glsl | 31 -- resources/shaders/gl3/filter_basic.fs.glsl | 32 -- resources/shaders/gl3/filter_text.fs.glsl | 127 ------- resources/shaders/gl3/mask_winding.vs.glsl | 34 -- resources/shaders/gl3/post.fs.glsl | 127 ------- resources/shaders/gl3/post.vs.glsl | 31 -- .../shaders/gl3/tile_alpha_monochrome.vs.glsl | 85 ----- .../shaders/gl3/tile_alpha_multicolor.vs.glsl | 88 ----- resources/shaders/gl3/tile_filter.vs.glsl | 31 -- .../shaders/gl3/tile_filter_blur.fs.glsl | 69 ---- resources/shaders/gl3/tile_solid.fs.glsl | 4 +- ...fs.glsl => tile_solid_filter_blur.fs.glsl} | 10 +- ...fs.glsl => tile_solid_filter_text.fs.glsl} | 8 +- .../shaders/gl3/tile_solid_monochrome.vs.glsl | 67 ---- .../shaders/gl3/tile_solid_multicolor.vs.glsl | 70 ---- resources/shaders/metal/filter.vs.metal | 27 -- resources/shaders/metal/filter_basic.fs.metal | 30 -- resources/shaders/metal/filter_text.fs.metal | 130 -------- resources/shaders/metal/mask_winding.vs.metal | 31 -- resources/shaders/metal/post.fs.metal | 133 -------- resources/shaders/metal/post.vs.metal | 27 -- .../metal/tile_alpha_monochrome.vs.metal | 65 ---- .../metal/tile_alpha_multicolor.vs.metal | 67 ---- resources/shaders/metal/tile_filter.vs.metal | 33 -- .../shaders/metal/tile_filter_blur.fs.metal | 52 --- resources/shaders/metal/tile_solid.fs.metal | 6 +- ....metal => tile_solid_filter_blur.fs.metal} | 10 +- ....metal => tile_solid_filter_text.fs.metal} | 26 +- .../metal/tile_solid_monochrome.vs.metal | 46 --- .../metal/tile_solid_multicolor.vs.metal | 48 --- shaders/Makefile | 9 +- shaders/tile_filter.vs.glsl | 28 -- shaders/tile_solid.fs.glsl | 4 +- ...fs.glsl => tile_solid_filter_blur.fs.glsl} | 13 +- ...fs.glsl => tile_solid_filter_text.fs.glsl} | 16 +- ... tile_solid_filter_text_convolve.inc.glsl} | 2 +- ..._solid_filter_text_gamma_correct.inc.glsl} | 4 +- 45 files changed, 350 insertions(+), 2024 deletions(-) delete mode 100644 resources/shaders/gl3/filter.vs.glsl delete mode 100644 resources/shaders/gl3/filter_basic.fs.glsl delete mode 100644 resources/shaders/gl3/filter_text.fs.glsl delete mode 100644 resources/shaders/gl3/mask_winding.vs.glsl delete mode 100644 resources/shaders/gl3/post.fs.glsl delete mode 100644 resources/shaders/gl3/post.vs.glsl delete mode 100644 resources/shaders/gl3/tile_alpha_monochrome.vs.glsl delete mode 100644 resources/shaders/gl3/tile_alpha_multicolor.vs.glsl delete mode 100644 resources/shaders/gl3/tile_filter.vs.glsl delete mode 100644 resources/shaders/gl3/tile_filter_blur.fs.glsl rename resources/shaders/gl3/{filter_blur.fs.glsl => tile_solid_filter_blur.fs.glsl} (75%) rename resources/shaders/gl3/{tile_filter_text.fs.glsl => tile_solid_filter_text.fs.glsl} (91%) delete mode 100644 resources/shaders/gl3/tile_solid_monochrome.vs.glsl delete mode 100644 resources/shaders/gl3/tile_solid_multicolor.vs.glsl delete mode 100644 resources/shaders/metal/filter.vs.metal delete mode 100644 resources/shaders/metal/filter_basic.fs.metal delete mode 100644 resources/shaders/metal/filter_text.fs.metal delete mode 100644 resources/shaders/metal/mask_winding.vs.metal delete mode 100644 resources/shaders/metal/post.fs.metal delete mode 100644 resources/shaders/metal/post.vs.metal delete mode 100644 resources/shaders/metal/tile_alpha_monochrome.vs.metal delete mode 100644 resources/shaders/metal/tile_alpha_multicolor.vs.metal delete mode 100644 resources/shaders/metal/tile_filter.vs.metal delete mode 100644 resources/shaders/metal/tile_filter_blur.fs.metal rename resources/shaders/metal/{filter_blur.fs.metal => tile_solid_filter_blur.fs.metal} (73%) rename resources/shaders/metal/{tile_filter_text.fs.metal => tile_solid_filter_text.fs.metal} (72%) delete mode 100644 resources/shaders/metal/tile_solid_monochrome.vs.metal delete mode 100644 resources/shaders/metal/tile_solid_multicolor.vs.metal delete mode 100644 shaders/tile_filter.vs.glsl rename shaders/{tile_filter_blur.fs.glsl => tile_solid_filter_blur.fs.glsl} (86%) rename shaders/{tile_filter_text.fs.glsl => tile_solid_filter_text.fs.glsl} (76%) rename shaders/{tile_filter_text_convolve.inc.glsl => tile_solid_filter_text_convolve.inc.glsl} (95%) rename shaders/{tile_filter_text_gamma_correct.inc.glsl => tile_solid_filter_text_gamma_correct.inc.glsl} (86%) diff --git a/renderer/src/builder.rs b/renderer/src/builder.rs index d06a238e..f1409354 100644 --- a/renderer/src/builder.rs +++ b/renderer/src/builder.rs @@ -13,10 +13,10 @@ use crate::concurrent::executor::Executor; use crate::gpu::renderer::{BlendModeProgram, MASK_TILES_ACROSS}; use crate::gpu_data::{AlphaTile, AlphaTileBatch, AlphaTileVertex, FillBatchPrimitive, MaskTile}; -use crate::gpu_data::{MaskTileVertex, RenderCommand, RenderTargetTile, RenderTargetTileBatch}; -use crate::gpu_data::{RenderTargetTileVertex, SolidTileBatch, TexturePageId, TileObjectPrimitive}; +use crate::gpu_data::{MaskTileVertex, RenderCommand, SolidTile, SolidTileBatch}; +use crate::gpu_data::{TexturePageId, TileObjectPrimitive}; use crate::options::{PreparedBuildOptions, RenderCommandListener}; -use crate::paint::{PaintInfo, PaintMetadata}; +use crate::paint::{PaintInfo, PaintMetadata, RenderTargetMetadata}; use crate::scene::{DisplayItem, Scene}; use crate::tile_map::DenseTileMap; use crate::tiles::{self, DrawTilingPathInfo, TILE_HEIGHT, TILE_WIDTH, Tiler, TilingPathInfo}; @@ -63,13 +63,13 @@ struct BuiltDrawPath { pub(crate) struct BuiltPath { pub mask_tiles: Vec, pub alpha_tiles: Vec, - pub solid_tiles: Vec, + pub solid_tiles: Vec, pub tiles: DenseTileMap, pub fill_rule: FillRule, } #[derive(Clone, Copy, Debug)] -pub(crate) struct SolidTile { +pub(crate) struct SolidTileInfo { pub(crate) coords: Vector2I, } @@ -111,7 +111,8 @@ impl<'a> SceneBuilder<'a> { // Build paint data. let PaintInfo { render_commands, - metadata: paint_metadata, + paint_metadata, + render_target_metadata, } = self.scene.build_paint_info(); for render_command in render_commands { self.listener.send(render_command); @@ -132,7 +133,10 @@ impl<'a> SceneBuilder<'a> { &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; self.listener.send(RenderCommand::Finish { build_time }); @@ -197,13 +201,14 @@ impl<'a> SceneBuilder<'a> { BuiltDrawPath { path: tiler.object_builder.built_path, 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, } } fn cull_tiles(&self, paint_metadata: &[PaintMetadata], + render_target_metadata: &[RenderTargetMetadata], built_clip_paths: Vec, built_draw_paths: Vec) -> CulledTiles { @@ -254,17 +259,28 @@ impl<'a> SceneBuilder<'a> { let tile_rect = tiles::round_rect_out_to_tile_bounds(effective_view_box); let layer_z_buffer = layer_z_buffers_stack.last().unwrap(); 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_x in tile_rect.min_x()..tile_rect.max_x() { let tile_coords = Vector2I::new(tile_x, tile_y); - if layer_z_buffer.test(tile_coords, current_depth) { - tiles.push(RenderTargetTile::new(tile_coords)); + if !layer_z_buffer.test(tile_coords, current_depth) { + 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 = RenderTargetTileBatch { tiles, render_target, effects }; - culled_tiles.display_list - .push(CulledDisplayItem::DrawRenderTargetTiles(batch)); + let batch = SolidTileBatch { + tiles, + color_texture_page: metadata.location.page, + sampling_flags: TextureSamplingFlags::empty(), + effects, + }; + culled_tiles.display_list.push(CulledDisplayItem::DrawSolidTiles(batch)); current_depth += 1; } @@ -396,9 +412,6 @@ impl<'a> SceneBuilder<'a> { CulledDisplayItem::DrawAlphaTiles(batch) => { self.listener.send(RenderCommand::DrawAlphaTiles(batch)) } - CulledDisplayItem::DrawRenderTargetTiles(batch) => { - self.listener.send(RenderCommand::DrawRenderTargetTiles(batch)) - } CulledDisplayItem::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, paint_metadata: &[PaintMetadata], + render_target_metadata: &[RenderTargetMetadata], built_clip_paths: Vec, built_draw_paths: Vec) { 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); } @@ -460,10 +477,10 @@ impl BuiltPath { } } -impl SolidTile { +impl SolidTileInfo { #[inline] - pub(crate) fn new(coords: Vector2I) -> SolidTile { - SolidTile { coords } + pub(crate) fn new(coords: Vector2I) -> SolidTileInfo { + SolidTileInfo { coords } } } @@ -476,7 +493,6 @@ struct CulledTiles { enum CulledDisplayItem { DrawSolidTiles(SolidTileBatch), DrawAlphaTiles(AlphaTileBatch), - DrawRenderTargetTiles(RenderTargetTileBatch), PushRenderTarget(RenderTargetId), 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 } - } -} diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 4bdce8c2..d4cded69 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -15,12 +15,10 @@ use crate::gpu::shaders::{AlphaTileHSLProgram, AlphaTileOverlayProgram}; use crate::gpu::shaders::{AlphaTileProgram, AlphaTileVertexArray, BlitProgram, BlitVertexArray}; use crate::gpu::shaders::{CopyTileProgram, CopyTileVertexArray, FillProgram, FillVertexArray}; 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::{TileFilterBasicProgram, TileFilterBlurProgram, TileFilterProgram}; -use crate::gpu::shaders::{TileFilterTextProgram, TileFilterVertexArray}; -use crate::gpu_data::{AlphaTile, FillBatchPrimitive, MaskTile, RenderCommand, RenderTargetTile}; -use crate::gpu_data::{SolidTileVertex, TextureLocation, TexturePageDescriptor, TexturePageId}; +use crate::gpu_data::{AlphaTile, FillBatchPrimitive, MaskTile, RenderCommand, SolidTile}; +use crate::gpu_data::{TextureLocation, TexturePageDescriptor, TexturePageId}; use crate::options::BoundingQuad; use crate::tiles::{TILE_HEIGHT, TILE_WIDTH}; use pathfinder_color::{self as color, ColorF, ColorU}; @@ -83,7 +81,6 @@ where mask_winding_tile_program: MaskTileProgram, mask_evenodd_tile_program: MaskTileProgram, copy_tile_program: CopyTileProgram, - solid_tile_program: SolidTileProgram, alpha_tile_program: AlphaTileProgram, alpha_tile_overlay_program: AlphaTileOverlayProgram, alpha_tile_dodgeburn_program: AlphaTileDodgeBurnProgram, @@ -95,7 +92,6 @@ where mask_winding_tile_vertex_array: MaskTileVertexArray, mask_evenodd_tile_vertex_array: MaskTileVertexArray, copy_tile_vertex_array: CopyTileVertexArray, - solid_tile_vertex_array: SolidTileVertexArray, alpha_tile_vertex_array: AlphaTileVertexArray, alpha_tile_overlay_vertex_array: AlphaTileVertexArray, alpha_tile_dodgeburn_vertex_array: AlphaTileVertexArray, @@ -123,14 +119,14 @@ where // used, then the transparent black paint would zero out the alpha mask. clear_paint_texture: D::Texture, - // Filter shaders - tile_filter_basic_program: TileFilterBasicProgram, - tile_filter_blur_program: TileFilterBlurProgram, - tile_filter_text_program: TileFilterTextProgram, - tile_filter_basic_vertex_array: TileFilterVertexArray, - tile_filter_blur_vertex_array: TileFilterVertexArray, - tile_filter_text_vertex_array: TileFilterVertexArray, - tile_filter_vertex_buffer: D::Buffer, + // Solid tiles + solid_tile_program: SolidTileProgram, + solid_tile_blur_filter_program: SolidTileBlurFilterProgram, + solid_tile_text_filter_program: SolidTileTextFilterProgram, + solid_tile_vertex_array: SolidTileVertexArray, + solid_tile_blur_filter_vertex_array: SolidTileVertexArray, + solid_tile_text_filter_vertex_array: SolidTileVertexArray, + solid_tile_vertex_buffer: D::Buffer, gamma_lut_texture: D::Texture, // Stencil shader @@ -175,7 +171,7 @@ where &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_overlay_program = AlphaTileOverlayProgram::new(&device, resources); let alpha_tile_dodgeburn_program = AlphaTileDodgeBurnProgram::new(&device, resources); @@ -188,9 +184,8 @@ where resources, "tile_alpha_exclusion"); let alpha_tile_hsl_program = AlphaTileHSLProgram::new(&device, resources); - let tile_filter_basic_program = TileFilterBasicProgram::new(&device, resources); - let tile_filter_blur_program = TileFilterBlurProgram::new(&device, resources); - let tile_filter_text_program = TileFilterTextProgram::new(&device, resources); + let solid_tile_blur_filter_program = SolidTileBlurFilterProgram::new(&device, resources); + let solid_tile_text_filter_program = SolidTileTextFilterProgram::new(&device, resources); let stencil_program = StencilProgram::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 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(); device.allocate_buffer( &quad_vertex_positions_buffer, @@ -288,24 +283,19 @@ where let solid_tile_vertex_array = SolidTileVertexArray::new( &device, &solid_tile_program, + &solid_tile_vertex_buffer, &quads_vertex_indices_buffer, ); - let tile_filter_basic_vertex_array = TileFilterVertexArray::new( + let solid_tile_blur_filter_vertex_array = SolidTileVertexArray::new( &device, - &tile_filter_basic_program.tile_filter_program, - &tile_filter_vertex_buffer, + &solid_tile_blur_filter_program.solid_tile_program, + &solid_tile_vertex_buffer, &quads_vertex_indices_buffer, ); - let tile_filter_blur_vertex_array = TileFilterVertexArray::new( + let solid_tile_text_filter_vertex_array = SolidTileVertexArray::new( &device, - &tile_filter_blur_program.tile_filter_program, - &tile_filter_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, + &solid_tile_text_filter_program.solid_tile_program, + &solid_tile_vertex_buffer, &quads_vertex_indices_buffer, ); let stencil_vertex_array = StencilVertexArray::new(&device, &stencil_program); @@ -363,7 +353,6 @@ where mask_winding_tile_vertex_array, mask_evenodd_tile_vertex_array, copy_tile_vertex_array, - solid_tile_vertex_array, alpha_tile_vertex_array, alpha_tile_overlay_vertex_array, alpha_tile_dodgeburn_vertex_array, @@ -387,13 +376,12 @@ where render_target_stack: vec![], clear_paint_texture, - tile_filter_basic_program, - tile_filter_basic_vertex_array, - tile_filter_blur_program, - tile_filter_blur_vertex_array, - tile_filter_text_program, - tile_filter_text_vertex_array, - tile_filter_vertex_buffer, + solid_tile_vertex_array, + solid_tile_blur_filter_program, + solid_tile_blur_filter_vertex_array, + solid_tile_text_filter_program, + solid_tile_text_filter_vertex_array, + solid_tile_vertex_buffer, gamma_lut_texture, stencil_program, @@ -450,18 +438,14 @@ where self.push_render_target(render_target_id) } 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) => { - let count = batch.vertices.len() / 4; + let count = batch.tiles.len(); 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, batch.color_texture_page, - batch.sampling_flags); + batch.sampling_flags, + batch.effects); } RenderCommand::DrawAlphaTiles(ref batch) => { let count = batch.tiles.len(); @@ -635,14 +619,14 @@ where 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.solid_tile_vertex_array.vertex_buffer, - BufferData::Memory(&solid_tile_vertices), + &self.solid_tile_vertex_buffer, + BufferData::Memory(&solid_tiles), BufferTarget::Vertex, 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]) { @@ -653,14 +637,6 @@ where 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) { length = length.next_power_of_two(); if self.quads_vertex_indices_length >= length { @@ -1039,32 +1015,68 @@ where fn draw_solid_tiles(&mut self, tile_count: u32, color_texture_page: TexturePageId, - sampling_flags: TextureSamplingFlags) { + sampling_flags: TextureSamplingFlags, + effects: Effects) { 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 uniforms = vec![ - (&self.solid_tile_program.transform_uniform, + (&solid_tile_program.transform_uniform, 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))), ]; 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); textures.push(texture_page); - uniforms.push((&self.solid_tile_program.paint_texture_uniform, - UniformData::TextureUnit(0))); + uniforms.push((&solid_tile_program.color_texture_uniform, 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 { target: &self.draw_render_target(), - program: &self.solid_tile_program.program, - vertex_array: &self.solid_tile_vertex_array.vertex_array, + program: &solid_tile_program.program, + vertex_array: &solid_tile_vertex_array.vertex_array, primitive: Primitive::Triangles, textures: &textures, uniforms: &uniforms, viewport: self.draw_viewport(), options: RenderOptions { + blend: blend_state, stencil: self.stencil_state(), clear_ops: ClearOps { color: clear_color, ..ClearOps::default() }, ..RenderOptions::default() @@ -1182,94 +1194,42 @@ where self.render_target_stack.pop().expect("Render target stack underflow!"); } - // FIXME(pcwalton): This is inefficient and should eventually go away. - fn draw_render_target_tiles(&mut self, - count: u32, - 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) - } - } + fn set_uniforms_for_text_filter<'a>(&'a self, + textures: &mut Vec<&'a D::Texture>, + uniforms: &mut Vec<(&'a D::Uniform, UniformData)>, + fg_color: ColorF, + bg_color: ColorF, + defringing_kernel: Option, + gamma_correction: bool) { + let gamma_lut_texture_unit = textures.len() as u32; + textures.push(&self.gamma_lut_texture); - 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, - bg_color: ColorF, - defringing_kernel: Option, - gamma_correction: bool) { - let textures = vec![&self.gamma_lut_texture]; - let mut uniforms = vec![ - (&self.tile_filter_text_program.gamma_lut_uniform, UniformData::TextureUnit(0)), - (&self.tile_filter_text_program.fg_color_uniform, UniformData::Vec4(fg_color.0)), - (&self.tile_filter_text_program.bg_color_uniform, UniformData::Vec4(bg_color.0)), - (&self.tile_filter_text_program.gamma_correction_enabled_uniform, + uniforms.extend_from_slice(&[ + (&self.solid_tile_text_filter_program.gamma_lut_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)), - ]; + ]); match defringing_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)))); } None => { - uniforms.push((&self.tile_filter_text_program.kernel_uniform, + uniforms.push((&self.solid_tile_text_filter_program.kernel_uniform, 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, - tile_count: u32, - render_target_id: RenderTargetId, - direction: BlurDirection, - 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); - + fn set_uniforms_for_blur_filter<'a>(&'a self, + uniforms: &mut Vec<(&'a D::Uniform, UniformData)>, + src_texture_size: Vector2I, + direction: BlurDirection, + sigma: f32) { let sigma_inv = 1.0 / sigma; let gauss_coeff_x = SQRT_2_PI_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 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, - tile_filter_vertex_array: &'a TileFilterVertexArray, - tile_count: u32, - render_target_id: RenderTargetId, - mut uniforms: Vec<(&'a D::Uniform, UniformData)>, - mut textures: Vec<&'a D::Texture>, - blend_state: Option) { - 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(&[ - (&tile_filter_program.src_uniform, UniformData::TextureUnit(textures.len() as u32)), - (&tile_filter_program.src_size_uniform, - UniformData::Vec2(src_texture_size.0.to_f32x2())), - (&tile_filter_program.transform_uniform, - UniformData::Mat4(self.tile_transform().to_columns())), - (&tile_filter_program.tile_size_uniform, - UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))), + (&self.solid_tile_blur_filter_program.src_offset_scale_uniform, + UniformData::Vec2(src_offset_scale.0)), + (&self.solid_tile_blur_filter_program.initial_gauss_coeff_uniform, + UniformData::Vec3([gauss_coeff_x, gauss_coeff_y, gauss_coeff_z])), + (&self.solid_tile_blur_filter_program.support_uniform, + UniformData::Int(f32::ceil(1.5 * sigma) as i32 * 2)), ]); - 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) { diff --git a/renderer/src/gpu/shaders.rs b/renderer/src/gpu/shaders.rs index 6eac750b..7f72a74a 100644 --- a/renderer/src/gpu/shaders.rs +++ b/renderer/src/gpu/shaders.rs @@ -16,9 +16,8 @@ use pathfinder_resources::ResourceLoader; // TODO(pcwalton): Replace with `mem::size_of` calls? 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 FILTER_TILE_VERTEX_SIZE: usize = 4; const MASK_TILE_VERTEX_SIZE: usize = 12; pub const MAX_FILLS_PER_BATCH: usize = 0x4000; @@ -273,7 +272,6 @@ where D: Device, { pub vertex_array: D::VertexArray, - pub vertex_buffer: D::Buffer, } impl SolidTileVertexArray @@ -283,9 +281,10 @@ where pub fn new( device: &D, solid_tile_program: &SolidTileProgram, + solid_tile_vertex_buffer: &D::Buffer, quads_vertex_indices_buffer: &D::Buffer, ) -> SolidTileVertexArray { - let (vertex_array, vertex_buffer) = (device.create_vertex_array(), device.create_buffer()); + let vertex_array = device.create_vertex_array(); let tile_position_attr = 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 // 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 { size: 2, class: VertexAttrClass::Int, @@ -317,7 +316,7 @@ where }); 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 where D: Device { pub program: D::Program, pub transform_uniform: D::Uniform, pub tile_size_uniform: D::Uniform, - pub paint_texture_uniform: D::Uniform, + pub color_texture_uniform: D::Uniform, } impl SolidTileProgram where D: Device { - pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileProgram { - let program = device.create_program(resources, "tile_solid"); + pub fn new(device: &D, resources: &dyn ResourceLoader, program_name: &str) + -> SolidTileProgram { + let program = device.create_program_from_shader_names(resources, + program_name, + "tile_solid", + program_name); let transform_uniform = device.get_uniform(&program, "Transform"); 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 { program, transform_uniform, tile_size_uniform, - paint_texture_uniform, + color_texture_uniform, } } } @@ -566,101 +569,25 @@ impl AlphaTileDodgeBurnProgram where D: Device { } } -pub struct TileFilterProgram where D: Device { - pub program: D::Program, - pub transform_uniform: D::Uniform, - pub tile_size_uniform: D::Uniform, - pub src_uniform: D::Uniform, - pub src_size_uniform: D::Uniform, -} - -impl TileFilterProgram where D: Device { - pub fn new(device: &D, - resources: &dyn ResourceLoader, - program_name: &str, - fragment_shader_name: &str) - -> TileFilterProgram { - 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 where D: Device { - pub tile_filter_program: TileFilterProgram, -} - -impl TileFilterBasicProgram where D: Device { - pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterBasicProgram { - TileFilterBasicProgram { - tile_filter_program: TileFilterProgram::new(device, resources, "filter_basic", "blit"), - } - } -} - -pub struct TileFilterVertexArray where D: Device { - pub vertex_array: D::VertexArray, -} - -impl TileFilterVertexArray where D: Device { - pub fn new(device: &D, - tile_filter_program: &TileFilterProgram, - tile_filter_vertex_buffer: &D::Buffer, - quads_vertex_indices_buffer: &D::Buffer) - -> TileFilterVertexArray { - 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 where D: Device { - pub tile_filter_program: TileFilterProgram, +pub struct SolidTileBlurFilterProgram where D: Device { + pub solid_tile_program: SolidTileProgram, pub src_offset_scale_uniform: D::Uniform, pub initial_gauss_coeff_uniform: D::Uniform, pub support_uniform: D::Uniform, } -impl TileFilterBlurProgram where D: Device { - pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterBlurProgram { - let tile_filter_program = TileFilterProgram::new(device, - resources, - "tile_filter_blur", - "tile_filter_blur"); - let src_offset_scale_uniform = device.get_uniform(&tile_filter_program.program, +impl SolidTileBlurFilterProgram where D: Device { + pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileBlurFilterProgram { + let solid_tile_program = SolidTileProgram::new(device, + resources, + "tile_solid_filter_blur"); + let src_offset_scale_uniform = device.get_uniform(&solid_tile_program.program, "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"); - let support_uniform = device.get_uniform(&tile_filter_program.program, "Support"); - TileFilterBlurProgram { - tile_filter_program, + let support_uniform = device.get_uniform(&solid_tile_program.program, "Support"); + SolidTileBlurFilterProgram { + solid_tile_program, src_offset_scale_uniform, initial_gauss_coeff_uniform, support_uniform, @@ -668,8 +595,8 @@ impl TileFilterBlurProgram where D: Device { } } -pub struct TileFilterTextProgram where D: Device { - pub tile_filter_program: TileFilterProgram, +pub struct SolidTileTextFilterProgram where D: Device { + pub solid_tile_program: SolidTileProgram, pub kernel_uniform: D::Uniform, pub gamma_lut_uniform: D::Uniform, pub gamma_correction_enabled_uniform: D::Uniform, @@ -677,20 +604,19 @@ pub struct TileFilterTextProgram where D: Device { pub bg_color_uniform: D::Uniform, } -impl TileFilterTextProgram where D: Device { - pub fn new(device: &D, resources: &dyn ResourceLoader) -> TileFilterTextProgram { - let tile_filter_program = TileFilterProgram::new(device, - resources, - "tile_filter_text", - "tile_filter_text"); - let kernel_uniform = device.get_uniform(&tile_filter_program.program, "Kernel"); - let gamma_lut_uniform = device.get_uniform(&tile_filter_program.program, "GammaLUT"); - let gamma_correction_enabled_uniform = device.get_uniform(&tile_filter_program.program, +impl SolidTileTextFilterProgram where D: Device { + pub fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileTextFilterProgram { + let solid_tile_program = SolidTileProgram::new(device, + resources, + "tile_solid_filter_text"); + let kernel_uniform = device.get_uniform(&solid_tile_program.program, "Kernel"); + let gamma_lut_uniform = device.get_uniform(&solid_tile_program.program, "GammaLUT"); + let gamma_correction_enabled_uniform = device.get_uniform(&solid_tile_program.program, "GammaCorrectionEnabled"); - let fg_color_uniform = device.get_uniform(&tile_filter_program.program, "FGColor"); - let bg_color_uniform = device.get_uniform(&tile_filter_program.program, "BGColor"); - TileFilterTextProgram { - tile_filter_program, + let fg_color_uniform = device.get_uniform(&solid_tile_program.program, "FGColor"); + let bg_color_uniform = device.get_uniform(&solid_tile_program.program, "BGColor"); + SolidTileTextFilterProgram { + solid_tile_program, kernel_uniform, gamma_lut_uniform, gamma_correction_enabled_uniform, diff --git a/renderer/src/gpu_data.rs b/renderer/src/gpu_data.rs index 571a2c39..793ae45f 100644 --- a/renderer/src/gpu_data.rs +++ b/renderer/src/gpu_data.rs @@ -71,13 +71,6 @@ pub enum RenderCommand { // Draws a batch of solid tiles to the render target on top of the stack. 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. Finish { build_time: Duration }, } @@ -106,15 +99,9 @@ pub struct AlphaTileBatch { #[derive(Clone, Debug)] pub struct SolidTileBatch { - pub vertices: Vec, + pub tiles: Vec, pub color_texture_page: TexturePageId, pub sampling_flags: TextureSamplingFlags, -} - -#[derive(Clone, Debug)] -pub struct RenderTargetTileBatch { - pub tiles: Vec, - pub render_target: RenderTargetId, pub effects: Effects, } @@ -143,15 +130,13 @@ pub struct FillBatchPrimitive { pub alpha_tile_index: u16, } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, Default)] #[repr(C)] pub struct SolidTileVertex { pub tile_x: i16, pub tile_y: i16, pub color_u: f32, pub color_v: f32, - pub object_index: u16, - pub pad: u16, } #[derive(Clone, Copy, Debug, Default)] @@ -174,11 +159,11 @@ pub struct AlphaTile { #[derive(Clone, Copy, Debug, Default)] #[repr(C)] -pub struct RenderTargetTile { - pub upper_left: RenderTargetTileVertex, - pub upper_right: RenderTargetTileVertex, - pub lower_left: RenderTargetTileVertex, - pub lower_right: RenderTargetTileVertex, +pub struct SolidTile { + pub upper_left: SolidTileVertex, + pub upper_right: SolidTileVertex, + pub lower_left: SolidTileVertex, + pub lower_right: SolidTileVertex, } #[derive(Clone, Copy, Debug, Default)] @@ -206,13 +191,6 @@ pub struct AlphaTileVertex { 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 { fn fmt(&self, formatter: &mut Formatter) -> DebugResult { match *self { @@ -246,16 +224,10 @@ impl Debug for RenderCommand { RenderCommand::DrawSolidTiles(ref batch) => { write!(formatter, "DrawSolidTiles(x{}, {:?}, {:?})", - batch.vertices.len(), + batch.tiles.len(), batch.color_texture_page, batch.sampling_flags) } - RenderCommand::DrawRenderTargetTiles(ref batch) => { - write!(formatter, - "DrawRenderTarget(x{}, {:?})", - batch.tiles.len(), - batch.render_target) - } RenderCommand::Finish { .. } => write!(formatter, "Finish"), } } diff --git a/renderer/src/paint.rs b/renderer/src/paint.rs index b18581c5..1b6a60b0 100644 --- a/renderer/src/paint.rs +++ b/renderer/src/paint.rs @@ -156,15 +156,17 @@ pub struct PaintInfo { /// The metadata for each paint. /// /// The indices of this vector are paint IDs. - pub metadata: Vec, + pub paint_metadata: Vec, + /// The metadata for each render target. + /// + /// The indices of this vector are render target IDs. + pub render_target_metadata: Vec, } #[derive(Debug)] pub struct PaintMetadata { - /// The location of the texture. - pub texture_page: TexturePageId, - /// The rectangle within the texture atlas. - pub texture_rect: RectI, + /// The location of the paint. + pub location: TextureLocation, /// The transform to apply to screen coordinates to translate them into UVs. pub texture_transform: Transform2F, /// The sampling mode for the texture. @@ -173,6 +175,12 @@ pub struct PaintMetadata { pub is_opaque: bool, } +#[derive(Debug)] +pub struct RenderTargetMetadata { + /// The location of the render target. + pub location: TextureLocation, +} + impl Palette { #[allow(clippy::trivially_copy_pass_by_ref)] 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 { let mut allocator = TextureAllocator::new(); - let mut metadata = vec![]; + let (mut paint_metadata, mut render_target_metadata) = (vec![], vec![]); // Assign render target locations. - let mut render_target_locations = vec![]; 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. @@ -225,7 +234,7 @@ impl Palette { match pattern.source { PatternSource::RenderTarget(render_target_id) => { 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) => { // TODO(pcwalton): We should be able to use tile cleverness to repeat @@ -254,9 +263,8 @@ impl Palette { } }; - metadata.push(PaintMetadata { - texture_page: texture_location.page, - texture_rect: texture_location.rect, + paint_metadata.push(PaintMetadata { + location: texture_location, texture_transform: Transform2F::default(), sampling_flags, is_opaque: paint.is_opaque(), @@ -264,23 +272,23 @@ impl Palette { } // Calculate texture transforms. - for (paint, metadata) in self.paints.iter().zip(metadata.iter_mut()) { - let texture_scale = allocator.page_scale(metadata.texture_page); + for (paint, metadata) in self.paints.iter().zip(paint_metadata.iter_mut()) { + let texture_scale = allocator.page_scale(metadata.location.page); metadata.texture_transform = match paint { 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 } } Paint::Gradient(_) => { 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); Transform2F::from_translation(texture_origin_uv) * Transform2F::from_scale(gradient_tile_scale / view_box_size.to_f32()) } Paint::Pattern(Pattern { source: PatternSource::Image(_), transform, .. }) => { 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_scale(texture_scale) * transform.inverse() @@ -291,7 +299,7 @@ impl Palette { .. }) => { // 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(); Transform2F::from_translation(texture_origin_uv) * Transform2F::from_scale(texture_scale.scale_xy(Vector2F::new(1.0, -1.0))) * @@ -310,24 +318,24 @@ impl Palette { // Allocate the texels. // // TODO(pcwalton): This is slow. Do more on GPU. - let mut page_texels: Vec<_> = metadata.iter().map(|metadata| { - Texels::new(allocator.page_size(metadata.texture_page)) + let mut page_texels: Vec<_> = paint_metadata.iter().map(|metadata| { + Texels::new(allocator.page_size(metadata.location.page)) }).collect(); // Draw to texels. // // TODO(pcwalton): Do more of this on GPU. - for (paint, metadata) in self.paints.iter().zip(metadata.iter()) { - let texture_page = metadata.texture_page; + for (paint, metadata) in self.paints.iter().zip(paint_metadata.iter()) { + let texture_page = metadata.location.page; let texels = &mut page_texels[texture_page.0 as usize]; match paint { Paint::Color(color) => { - texels.put_texel(metadata.texture_rect.origin(), *color); + texels.put_texel(metadata.location.rect.origin(), *color); } Paint::Gradient(ref gradient) => { self.render_gradient(gradient, - metadata.texture_rect, + metadata.location.rect, &metadata.texture_transform, texels); } @@ -335,7 +343,7 @@ impl Palette { match pattern.source { PatternSource::RenderTarget(_) => {} 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![ 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); - 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() { 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. diff --git a/renderer/src/tiles.rs b/renderer/src/tiles.rs index f718e081..8336c3fa 100644 --- a/renderer/src/tiles.rs +++ b/renderer/src/tiles.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // 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::paint::PaintMetadata; use pathfinder_content::effects::BlendMode; @@ -186,7 +186,10 @@ impl<'a> Tiler<'a> { if draw_tiling_path_info.paint_metadata.is_opaque && draw_tiling_path_info.blend_mode.occludes_backdrop() && 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; } } diff --git a/renderer/src/z_buffer.rs b/renderer/src/z_buffer.rs index 3625f11e..b5ee49e6 100644 --- a/renderer/src/z_buffer.rs +++ b/renderer/src/z_buffer.rs @@ -10,13 +10,14 @@ //! Software occlusion culling. -use crate::builder::SolidTile; -use crate::gpu_data::{SolidTileBatch, SolidTileVertex}; +use crate::builder::SolidTileInfo; +use crate::gpu_data::{SolidTile, SolidTileBatch, SolidTileVertex}; use crate::paint::{PaintId, PaintMetadata}; use crate::tile_map::DenseTileMap; use crate::tiles; +use pathfinder_content::effects::{CompositeOp, Effects, Filter}; use pathfinder_geometry::rect::RectF; -use pathfinder_geometry::vector::Vector2I; +use pathfinder_geometry::vector::{Vector2F, Vector2I}; use vec_map::VecMap; pub(crate) struct ZBuffer { @@ -47,7 +48,7 @@ impl ZBuffer { } pub(crate) fn update(&mut self, - solid_tiles: &[SolidTile], + solid_tiles: &[SolidTileInfo], depth: u32, metadata: DepthMetadata) { self.depth_metadata.insert(depth as usize, metadata); @@ -76,42 +77,76 @@ impl ZBuffer { // Create a batch if necessary. 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 break. + // + // TODO(pcwalton): We could be more aggressive with batching here, since we + // know there are no overlaps. 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, - vertices: vec![], + tiles: vec![], + effects: Effects::new(Filter::Composite(CompositeOp::SrcOver)), }); } } let batch = solid_tiles.batches.last_mut().unwrap(); - batch.vertices.extend_from_slice(&[ - 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), - ]); + batch.tiles.push(SolidTile::from_paint_metadata(tile_position, paint_metadata)); } 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 { - fn new(tile_position: Vector2I, paint_metadata: &PaintMetadata) - -> SolidTileVertex { + 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 { let color_uv = paint_metadata.calculate_tex_coords(tile_position); SolidTileVertex { tile_x: tile_position.x() as i16, tile_y: tile_position.y() as i16, - object_index: 0, color_u: color_uv.x(), color_v: color_uv.y(), - pad: 0, } } } diff --git a/resources/MANIFEST b/resources/MANIFEST index bb285b02..d7bb44ee 100644 --- a/resources/MANIFEST +++ b/resources/MANIFEST @@ -16,9 +16,6 @@ shaders/gl3/fill.vs.glsl shaders/gl3/mask.vs.glsl shaders/gl3/mask_evenodd.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.vs.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_exclusion.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_softlight.fs.glsl shaders/gl3/tile_copy.fs.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.vs.glsl -shaders/gl3/tile_solid_monochrome.vs.glsl -shaders/gl3/tile_solid_multicolor.vs.glsl +shaders/gl3/tile_solid_filter_blur.fs.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.vs.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/fill.fs.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_evenodd.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.vs.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_exclusion.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_softlight.fs.metal shaders/metal/tile_copy.fs.metal shaders/metal/tile_copy.vs.metal shaders/metal/tile_solid.fs.metal shaders/metal/tile_solid.vs.metal -shaders/metal/tile_solid_monochrome.vs.metal -shaders/metal/tile_solid_multicolor.vs.metal +shaders/metal/tile_solid_filter_blur.fs.metal +shaders/metal/tile_solid_filter_text.fs.metal textures/area-lut.png textures/debug-corner-fill.png textures/debug-corner-outline.png diff --git a/resources/shaders/gl3/filter.vs.glsl b/resources/shaders/gl3/filter.vs.glsl deleted file mode 100644 index a1d8effb..00000000 --- a/resources/shaders/gl3/filter.vs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/filter_basic.fs.glsl b/resources/shaders/gl3/filter_basic.fs.glsl deleted file mode 100644 index c0c14856..00000000 --- a/resources/shaders/gl3/filter_basic.fs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/filter_text.fs.glsl b/resources/shaders/gl3/filter_text.fs.glsl deleted file mode 100644 index b9de3d7b..00000000 --- a/resources/shaders/gl3/filter_text.fs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/mask_winding.vs.glsl b/resources/shaders/gl3/mask_winding.vs.glsl deleted file mode 100644 index b5a7a1e1..00000000 --- a/resources/shaders/gl3/mask_winding.vs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/post.fs.glsl b/resources/shaders/gl3/post.fs.glsl deleted file mode 100644 index b9de3d7b..00000000 --- a/resources/shaders/gl3/post.fs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/post.vs.glsl b/resources/shaders/gl3/post.vs.glsl deleted file mode 100644 index a1d8effb..00000000 --- a/resources/shaders/gl3/post.vs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl b/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl deleted file mode 100644 index f36ab4a7..00000000 --- a/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl +++ /dev/null @@ -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(); -} - diff --git a/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl b/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl deleted file mode 100644 index 3994dc28..00000000 --- a/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl +++ /dev/null @@ -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(); -} - diff --git a/resources/shaders/gl3/tile_filter.vs.glsl b/resources/shaders/gl3/tile_filter.vs.glsl deleted file mode 100644 index d3bf9f7c..00000000 --- a/resources/shaders/gl3/tile_filter.vs.glsl +++ /dev/null @@ -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); -} - diff --git a/resources/shaders/gl3/tile_filter_blur.fs.glsl b/resources/shaders/gl3/tile_filter_blur.fs.glsl deleted file mode 100644 index dca9e4d1..00000000 --- a/resources/shaders/gl3/tile_filter_blur.fs.glsl +++ /dev/null @@ -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; -} - diff --git a/resources/shaders/gl3/tile_solid.fs.glsl b/resources/shaders/gl3/tile_solid.fs.glsl index 09dd8db2..e3c9c942 100644 --- a/resources/shaders/gl3/tile_solid.fs.glsl +++ b/resources/shaders/gl3/tile_solid.fs.glsl @@ -14,14 +14,14 @@ precision highp float; -uniform sampler2D uPaintTexture; +uniform sampler2D uColorTexture; in vec2 vColorTexCoord; out vec4 oFragColor; void main(){ - vec4 color = texture(uPaintTexture, vColorTexCoord); + vec4 color = texture(uColorTexture, vColorTexCoord); oFragColor = vec4(color . rgb * color . a, color . a); } diff --git a/resources/shaders/gl3/filter_blur.fs.glsl b/resources/shaders/gl3/tile_solid_filter_blur.fs.glsl similarity index 75% rename from resources/shaders/gl3/filter_blur.fs.glsl rename to resources/shaders/gl3/tile_solid_filter_blur.fs.glsl index dca9e4d1..90418115 100644 --- a/resources/shaders/gl3/filter_blur.fs.glsl +++ b/resources/shaders/gl3/tile_solid_filter_blur.fs.glsl @@ -24,12 +24,12 @@ precision highp float; -uniform sampler2D uSrc; +uniform sampler2D uColorTexture; uniform vec2 uSrcOffsetScale; uniform vec3 uInitialGaussCoeff; uniform int uSupport; -in vec2 vTexCoord; +in vec2 vColorTexCoord; out vec4 oFragColor; @@ -37,7 +37,7 @@ void main(){ vec3 gaussCoeff = uInitialGaussCoeff; float gaussSum = gaussCoeff . x; - vec4 color = texture(uSrc, vTexCoord)* gaussCoeff . x; + vec4 color = texture(uColorTexture, vColorTexCoord)* gaussCoeff . x; gaussCoeff . xy *= gaussCoeff . yz; @@ -54,8 +54,8 @@ void main(){ gaussPartialSum += gaussCoeff . x; vec2 srcOffset = uSrcOffsetScale *(float(i)+ gaussCoeff . x / gaussPartialSum); - color +=(texture(uSrc, vTexCoord - srcOffset)+ texture(uSrc, vTexCoord + srcOffset))* - gaussPartialSum; + color +=(texture(uColorTexture, vColorTexCoord - srcOffset)+ + texture(uColorTexture, vColorTexCoord + srcOffset))* gaussPartialSum; gaussSum += 2.0 * gaussPartialSum; gaussCoeff . xy *= gaussCoeff . yz; diff --git a/resources/shaders/gl3/tile_filter_text.fs.glsl b/resources/shaders/gl3/tile_solid_filter_text.fs.glsl similarity index 91% rename from resources/shaders/gl3/tile_filter_text.fs.glsl rename to resources/shaders/gl3/tile_solid_filter_text.fs.glsl index 88a60f25..a2ecb916 100644 --- a/resources/shaders/gl3/tile_filter_text.fs.glsl +++ b/resources/shaders/gl3/tile_solid_filter_text.fs.glsl @@ -16,13 +16,13 @@ precision highp float; -uniform sampler2D uSrc; +uniform sampler2D uColorTexture; uniform vec2 uSrcSize; uniform vec4 uFGColor; uniform vec4 uBGColor; uniform int uGammaCorrectionEnabled; -in vec2 vTexCoord; +in vec2 vColorTexCoord; out vec4 oFragColor; @@ -94,14 +94,14 @@ float convolve7Tap(vec4 alpha0, vec3 alpha1){ 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(){ vec3 alpha; if(uKernel . w == 0.0){ - alpha = texture(uSrc, vTexCoord). rrr; + alpha = texture(uColorTexture, vColorTexCoord). rrr; } else { vec4 alphaLeft, alphaRight; float alphaCenter; diff --git a/resources/shaders/gl3/tile_solid_monochrome.vs.glsl b/resources/shaders/gl3/tile_solid_monochrome.vs.glsl deleted file mode 100644 index 74437913..00000000 --- a/resources/shaders/gl3/tile_solid_monochrome.vs.glsl +++ /dev/null @@ -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(); -} - diff --git a/resources/shaders/gl3/tile_solid_multicolor.vs.glsl b/resources/shaders/gl3/tile_solid_multicolor.vs.glsl deleted file mode 100644 index fbeeb949..00000000 --- a/resources/shaders/gl3/tile_solid_multicolor.vs.glsl +++ /dev/null @@ -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(); -} - diff --git a/resources/shaders/metal/filter.vs.metal b/resources/shaders/metal/filter.vs.metal deleted file mode 100644 index f7385038..00000000 --- a/resources/shaders/metal/filter.vs.metal +++ /dev/null @@ -1,27 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -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; -} - diff --git a/resources/shaders/metal/filter_basic.fs.metal b/resources/shaders/metal/filter_basic.fs.metal deleted file mode 100644 index 721dcf38..00000000 --- a/resources/shaders/metal/filter_basic.fs.metal +++ /dev/null @@ -1,30 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - texture2d 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; -} - diff --git a/resources/shaders/metal/filter_text.fs.metal b/resources/shaders/metal/filter_text.fs.metal deleted file mode 100644 index e13bec29..00000000 --- a/resources/shaders/metal/filter_text.fs.metal +++ /dev/null @@ -1,130 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - texture2d uGammaLUT [[id(0)]]; - sampler uGammaLUTSmplr [[id(1)]]; - constant float4* uKernel [[id(2)]]; - texture2d 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 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 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 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 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; -} - diff --git a/resources/shaders/metal/mask_winding.vs.metal b/resources/shaders/metal/mask_winding.vs.metal deleted file mode 100644 index b5698991..00000000 --- a/resources/shaders/metal/mask_winding.vs.metal +++ /dev/null @@ -1,31 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -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; -} - diff --git a/resources/shaders/metal/post.fs.metal b/resources/shaders/metal/post.fs.metal deleted file mode 100644 index 3c9502b4..00000000 --- a/resources/shaders/metal/post.fs.metal +++ /dev/null @@ -1,133 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - texture2d uGammaLUT [[id(0)]]; - sampler uGammaLUTSmplr [[id(1)]]; - constant float4* uKernel [[id(2)]]; - texture2d 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 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 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 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 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; -} - diff --git a/resources/shaders/metal/post.vs.metal b/resources/shaders/metal/post.vs.metal deleted file mode 100644 index f7385038..00000000 --- a/resources/shaders/metal/post.vs.metal +++ /dev/null @@ -1,27 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -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; -} - diff --git a/resources/shaders/metal/tile_alpha_monochrome.vs.metal b/resources/shaders/metal/tile_alpha_monochrome.vs.metal deleted file mode 100644 index f2d70fca..00000000 --- a/resources/shaders/metal/tile_alpha_monochrome.vs.metal +++ /dev/null @@ -1,65 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -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; -} - diff --git a/resources/shaders/metal/tile_alpha_multicolor.vs.metal b/resources/shaders/metal/tile_alpha_multicolor.vs.metal deleted file mode 100644 index 5a6cac08..00000000 --- a/resources/shaders/metal/tile_alpha_multicolor.vs.metal +++ /dev/null @@ -1,67 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - constant float2* uTileSize [[id(0)]]; - constant float2* uStencilTextureSize [[id(1)]]; - constant float4x4* uTransform [[id(2)]]; - texture2d 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 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 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; -} - diff --git a/resources/shaders/metal/tile_filter.vs.metal b/resources/shaders/metal/tile_filter.vs.metal deleted file mode 100644 index ba6d6f3b..00000000 --- a/resources/shaders/metal/tile_filter.vs.metal +++ /dev/null @@ -1,33 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -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; -} - diff --git a/resources/shaders/metal/tile_filter_blur.fs.metal b/resources/shaders/metal/tile_filter_blur.fs.metal deleted file mode 100644 index b70ef414..00000000 --- a/resources/shaders/metal/tile_filter_blur.fs.metal +++ /dev/null @@ -1,52 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - constant float3* uInitialGaussCoeff [[id(0)]]; - texture2d 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; -} - diff --git a/resources/shaders/metal/tile_solid.fs.metal b/resources/shaders/metal/tile_solid.fs.metal index f7800819..be2e95f1 100644 --- a/resources/shaders/metal/tile_solid.fs.metal +++ b/resources/shaders/metal/tile_solid.fs.metal @@ -6,8 +6,8 @@ using namespace metal; struct spvDescriptorSetBuffer0 { - texture2d uPaintTexture [[id(0)]]; - sampler uPaintTextureSmplr [[id(1)]]; + texture2d uColorTexture [[id(0)]]; + sampler uColorTextureSmplr [[id(1)]]; }; struct main0_out @@ -23,7 +23,7 @@ struct main0_in fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) { 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); return out; } diff --git a/resources/shaders/metal/filter_blur.fs.metal b/resources/shaders/metal/tile_solid_filter_blur.fs.metal similarity index 73% rename from resources/shaders/metal/filter_blur.fs.metal rename to resources/shaders/metal/tile_solid_filter_blur.fs.metal index b70ef414..27c849c7 100644 --- a/resources/shaders/metal/filter_blur.fs.metal +++ b/resources/shaders/metal/tile_solid_filter_blur.fs.metal @@ -7,8 +7,8 @@ using namespace metal; struct spvDescriptorSetBuffer0 { constant float3* uInitialGaussCoeff [[id(0)]]; - texture2d uSrc [[id(1)]]; - sampler uSrcSmplr [[id(2)]]; + texture2d uColorTexture [[id(1)]]; + sampler uColorTextureSmplr [[id(2)]]; constant int* uSupport [[id(3)]]; constant float2* uSrcOffsetScale [[id(4)]]; }; @@ -20,7 +20,7 @@ struct main0_out 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)]]) @@ -28,7 +28,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff main0_out out = {}; float3 gaussCoeff = (*spvDescriptorSet0.uInitialGaussCoeff); 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; gaussCoeff = float3(_39.x, _39.y, gaussCoeff.z); 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); 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); + color += ((spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, (in.vColorTexCoord - srcOffset)) + spvDescriptorSet0.uColorTexture.sample(spvDescriptorSet0.uColorTextureSmplr, (in.vColorTexCoord + srcOffset))) * gaussPartialSum); gaussSum += (2.0 * gaussPartialSum); float2 _108 = gaussCoeff.xy * gaussCoeff.yz; gaussCoeff = float3(_108.x, _108.y, gaussCoeff.z); diff --git a/resources/shaders/metal/tile_filter_text.fs.metal b/resources/shaders/metal/tile_solid_filter_text.fs.metal similarity index 72% rename from resources/shaders/metal/tile_filter_text.fs.metal rename to resources/shaders/metal/tile_solid_filter_text.fs.metal index 4f56dce1..8e9dc32c 100644 --- a/resources/shaders/metal/tile_filter_text.fs.metal +++ b/resources/shaders/metal/tile_solid_filter_text.fs.metal @@ -11,8 +11,8 @@ struct spvDescriptorSetBuffer0 texture2d uGammaLUT [[id(0)]]; sampler uGammaLUTSmplr [[id(1)]]; constant float4* uKernel [[id(2)]]; - texture2d uSrc [[id(3)]]; - sampler uSrcSmplr [[id(4)]]; + texture2d uColorTexture [[id(3)]]; + sampler uColorTextureSmplr [[id(4)]]; constant float2* uSrcSize [[id(5)]]; constant int* uGammaCorrectionEnabled [[id(6)]]; constant float4* uBGColor [[id(7)]]; @@ -26,21 +26,21 @@ struct main0_out struct main0_in { - float2 vTexCoord [[user(locn0)]]; + float2 vColorTexCoord [[user(locn0)]]; }; -float sample1Tap(thread const float& offset, thread texture2d uSrc, thread const sampler uSrcSmplr, thread float2& vTexCoord) +float sample1Tap(thread const float& offset, thread texture2d 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 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 uColorTexture, thread const sampler uColorTextureSmplr, thread float2& vColorTexCoord) { float _89; if (uKernel.x > 0.0) { float param = (-4.0) * onePixel; - _89 = sample1Tap(param, uSrc, uSrcSmplr, vTexCoord); + _89 = sample1Tap(param, uColorTexture, uColorTextureSmplr, vColorTexCoord); } else { @@ -49,9 +49,9 @@ void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, threa float param_1 = (-3.0) * onePixel; float param_2 = (-2.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; - outAlphaCenter = sample1Tap(param_4, uSrc, uSrcSmplr, vTexCoord); + outAlphaCenter = sample1Tap(param_4, uColorTexture, uColorTextureSmplr, vColorTexCoord); float param_5 = 1.0 * onePixel; float param_6 = 2.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) { float param_8 = 4.0 * onePixel; - _134 = sample1Tap(param_8, uSrc, uSrcSmplr, vTexCoord); + _134 = sample1Tap(param_8, uColorTexture, uColorTextureSmplr, vColorTexCoord); } else { _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) @@ -95,7 +95,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff float3 alpha; 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 { @@ -103,7 +103,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuff float4 param; float param_1; 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; float alphaCenter = param_1; float4 alphaRight = param_2; diff --git a/resources/shaders/metal/tile_solid_monochrome.vs.metal b/resources/shaders/metal/tile_solid_monochrome.vs.metal deleted file mode 100644 index 3a2d625f..00000000 --- a/resources/shaders/metal/tile_solid_monochrome.vs.metal +++ /dev/null @@ -1,46 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -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; -} - diff --git a/resources/shaders/metal/tile_solid_multicolor.vs.metal b/resources/shaders/metal/tile_solid_multicolor.vs.metal deleted file mode 100644 index bbc79172..00000000 --- a/resources/shaders/metal/tile_solid_multicolor.vs.metal +++ /dev/null @@ -1,48 +0,0 @@ -// Automatically generated from files in pathfinder/shaders/. Do not edit! -#pragma clang diagnostic ignored "-Wmissing-prototypes" - -#include -#include - -using namespace metal; - -struct spvDescriptorSetBuffer0 -{ - constant float2* uTileSize [[id(0)]]; - constant float4x4* uTransform [[id(1)]]; - texture2d 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 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 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; -} - diff --git a/shaders/Makefile b/shaders/Makefile index f0b08a38..8c16cdba 100644 --- a/shaders/Makefile +++ b/shaders/Makefile @@ -30,17 +30,16 @@ SHADERS=\ tile_alpha_softlight.fs.glsl \ tile_copy.fs.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.vs.glsl \ + tile_solid_filter_blur.fs.glsl \ + tile_solid_filter_text.fs.glsl \ $(EMPTY) INCLUDES=\ tile_alpha_sample.inc.glsl \ - tile_filter_text_convolve.inc.glsl \ - tile_filter_text_gamma_correct.inc.glsl \ + tile_solid_filter_text_convolve.inc.glsl \ + tile_solid_filter_text_gamma_correct.inc.glsl \ $(EMPTY) OUT=\ diff --git a/shaders/tile_filter.vs.glsl b/shaders/tile_filter.vs.glsl deleted file mode 100644 index aaeee99a..00000000 --- a/shaders/tile_filter.vs.glsl +++ /dev/null @@ -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 or the MIT license -// , 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); -} diff --git a/shaders/tile_solid.fs.glsl b/shaders/tile_solid.fs.glsl index e3e09f35..dcd2c19c 100644 --- a/shaders/tile_solid.fs.glsl +++ b/shaders/tile_solid.fs.glsl @@ -12,13 +12,13 @@ precision highp float; -uniform sampler2D uPaintTexture; +uniform sampler2D uColorTexture; in vec2 vColorTexCoord; out vec4 oFragColor; void main() { - vec4 color = texture(uPaintTexture, vColorTexCoord); + vec4 color = texture(uColorTexture, vColorTexCoord); oFragColor = vec4(color.rgb * color.a, color.a); } diff --git a/shaders/tile_filter_blur.fs.glsl b/shaders/tile_solid_filter_blur.fs.glsl similarity index 86% rename from shaders/tile_filter_blur.fs.glsl rename to shaders/tile_solid_filter_blur.fs.glsl index eb45bf4b..04f8bd3e 100644 --- a/shaders/tile_filter_blur.fs.glsl +++ b/shaders/tile_solid_filter_blur.fs.glsl @@ -1,6 +1,6 @@ #version 330 -// pathfinder/shaders/filter_blur.fs.glsl +// pathfinder/shaders/tile_solid_filter_blur.fs.glsl // // Copyright © 2020 The Pathfinder Project Developers. // @@ -22,12 +22,12 @@ precision highp float; -uniform sampler2D uSrc; +uniform sampler2D uColorTexture; uniform vec2 uSrcOffsetScale; uniform vec3 uInitialGaussCoeff; uniform int uSupport; -in vec2 vTexCoord; +in vec2 vColorTexCoord; out vec4 oFragColor; @@ -35,7 +35,7 @@ void main() { // Set up our incremental calculation. vec3 gaussCoeff = uInitialGaussCoeff; float gaussSum = gaussCoeff.x; - vec4 color = texture(uSrc, vTexCoord) * gaussCoeff.x; + vec4 color = texture(uColorTexture, vColorTexCoord) * gaussCoeff.x; gaussCoeff.xy *= gaussCoeff.yz; // 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; vec2 srcOffset = uSrcOffsetScale * (float(i) + gaussCoeff.x / gaussPartialSum); - color += (texture(uSrc, vTexCoord - srcOffset) + texture(uSrc, vTexCoord + srcOffset)) * - gaussPartialSum; + color += (texture(uColorTexture, vColorTexCoord - srcOffset) + + texture(uColorTexture, vColorTexCoord + srcOffset)) * gaussPartialSum; gaussSum += 2.0 * gaussPartialSum; gaussCoeff.xy *= gaussCoeff.yz; @@ -64,4 +64,3 @@ void main() { color.rgb *= color.a; oFragColor = color; } - diff --git a/shaders/tile_filter_text.fs.glsl b/shaders/tile_solid_filter_text.fs.glsl similarity index 76% rename from shaders/tile_filter_text.fs.glsl rename to shaders/tile_solid_filter_text.fs.glsl index abf5991c..e39d5d67 100644 --- a/shaders/tile_filter_text.fs.glsl +++ b/shaders/tile_solid_filter_text.fs.glsl @@ -1,8 +1,8 @@ #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 or the MIT license @@ -14,29 +14,29 @@ precision highp float; -uniform sampler2D uSrc; +uniform sampler2D uColorTexture; uniform vec2 uSrcSize; uniform vec4 uFGColor; uniform vec4 uBGColor; uniform int uGammaCorrectionEnabled; -in vec2 vTexCoord; +in vec2 vColorTexCoord; out vec4 oFragColor; -#include "tile_filter_text_gamma_correct.inc.glsl" -#include "tile_filter_text_convolve.inc.glsl" +#include "tile_solid_filter_text_gamma_correct.inc.glsl" +#include "tile_solid_filter_text_convolve.inc.glsl" // Convolve horizontally in this pass. 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() { // Apply defringing if necessary. vec3 alpha; if (uKernel.w == 0.0) { - alpha = texture(uSrc, vTexCoord).rrr; + alpha = texture(uColorTexture, vColorTexCoord).rrr; } else { vec4 alphaLeft, alphaRight; float alphaCenter; diff --git a/shaders/tile_filter_text_convolve.inc.glsl b/shaders/tile_solid_filter_text_convolve.inc.glsl similarity index 95% rename from shaders/tile_filter_text_convolve.inc.glsl rename to shaders/tile_solid_filter_text_convolve.inc.glsl index bbfe1d45..220a151f 100644 --- a/shaders/tile_filter_text_convolve.inc.glsl +++ b/shaders/tile_solid_filter_text_convolve.inc.glsl @@ -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. // diff --git a/shaders/tile_filter_text_gamma_correct.inc.glsl b/shaders/tile_solid_filter_text_gamma_correct.inc.glsl similarity index 86% rename from shaders/tile_filter_text_gamma_correct.inc.glsl rename to shaders/tile_solid_filter_text_gamma_correct.inc.glsl index d72ef159..181817bc 100644 --- a/shaders/tile_filter_text_gamma_correct.inc.glsl +++ b/shaders/tile_solid_filter_text_gamma_correct.inc.glsl @@ -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 or the MIT license