2019-01-14 17:20:36 -05:00
|
|
|
// pathfinder/renderer/src/gpu_data.rs
|
|
|
|
//
|
2020-02-20 17:22:07 -05:00
|
|
|
// Copyright © 2020 The Pathfinder Project Developers.
|
2019-01-14 17:20:36 -05:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Packed data ready to be sent to the GPU.
|
|
|
|
|
2019-04-30 22:13:28 -04:00
|
|
|
use crate::options::BoundingQuad;
|
2020-02-11 20:20:21 -05:00
|
|
|
use pathfinder_color::ColorU;
|
2020-02-20 18:52:40 -05:00
|
|
|
use pathfinder_content::effects::{BlendMode, Effects};
|
2020-02-17 17:44:48 -05:00
|
|
|
use pathfinder_content::fill::FillRule;
|
2020-03-03 18:50:48 -05:00
|
|
|
use pathfinder_content::render_target::RenderTargetId;
|
2019-06-21 13:06:19 -04:00
|
|
|
use pathfinder_geometry::line_segment::{LineSegmentU4, LineSegmentU8};
|
2020-03-04 18:49:38 -05:00
|
|
|
use pathfinder_geometry::rect::RectI;
|
2020-02-04 01:24:34 -05:00
|
|
|
use pathfinder_geometry::vector::Vector2I;
|
2020-02-26 17:56:05 -05:00
|
|
|
use pathfinder_gpu::TextureSamplingFlags;
|
2019-03-29 22:11:38 -04:00
|
|
|
use std::fmt::{Debug, Formatter, Result as DebugResult};
|
2020-04-01 16:00:23 -04:00
|
|
|
use std::sync::Arc;
|
2019-04-30 22:13:28 -04:00
|
|
|
use std::time::Duration;
|
2019-01-14 17:20:36 -05:00
|
|
|
|
2019-03-29 22:11:38 -04:00
|
|
|
pub enum RenderCommand {
|
2020-02-22 00:42:15 -05:00
|
|
|
// Starts rendering a frame.
|
2020-02-22 17:39:03 -05:00
|
|
|
Start {
|
|
|
|
/// The number of paths that will be rendered.
|
|
|
|
path_count: usize,
|
|
|
|
|
|
|
|
/// A bounding quad for the scene.
|
|
|
|
bounding_quad: BoundingQuad,
|
|
|
|
|
|
|
|
/// Whether the framebuffer we're rendering to must be readable.
|
|
|
|
///
|
|
|
|
/// This is needed if a path that renders directly to the output framebuffer (i.e. not to a
|
|
|
|
/// render target) uses one of the more exotic blend modes.
|
|
|
|
needs_readable_framebuffer: bool,
|
|
|
|
},
|
2020-02-22 00:42:15 -05:00
|
|
|
|
2020-03-04 18:49:38 -05:00
|
|
|
// Allocates texture pages for the frame.
|
|
|
|
AllocateTexturePages(Vec<TexturePageDescriptor>),
|
|
|
|
|
|
|
|
// Uploads data to a texture page.
|
2020-04-01 16:00:23 -04:00
|
|
|
UploadTexelData { texels: Arc<Vec<ColorU>>, location: TextureLocation },
|
2020-03-04 18:49:38 -05:00
|
|
|
|
|
|
|
// Associates a render target with a texture page.
|
|
|
|
//
|
|
|
|
// TODO(pcwalton): Add a rect to this so we can render to subrects of a page.
|
2020-03-04 22:41:24 -05:00
|
|
|
DeclareRenderTarget { id: RenderTargetId, location: TextureLocation },
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Adds fills to the queue.
|
2019-04-15 16:21:24 -04:00
|
|
|
AddFills(Vec<FillBatchPrimitive>),
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Flushes the queue of fills.
|
2019-04-15 16:21:24 -04:00
|
|
|
FlushFills,
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Pushes a render target onto the stack. Draw commands go to the render target on top of the
|
|
|
|
// stack.
|
|
|
|
PushRenderTarget(RenderTargetId),
|
|
|
|
|
|
|
|
// Pops a render target from the stack.
|
|
|
|
PopRenderTarget,
|
|
|
|
|
2020-03-19 19:44:45 -04:00
|
|
|
// Draws a batch of tiles to the render target on top of the stack.
|
|
|
|
DrawTiles(TileBatch),
|
2020-02-22 00:42:15 -05:00
|
|
|
|
|
|
|
// Presents a rendered frame.
|
2019-04-30 22:13:28 -04:00
|
|
|
Finish { build_time: Duration },
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2020-02-22 00:42:15 -05:00
|
|
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
2020-03-04 15:09:08 -05:00
|
|
|
pub struct TexturePageId(pub u32);
|
2020-02-22 00:42:15 -05:00
|
|
|
|
2020-02-21 17:46:10 -05:00
|
|
|
#[derive(Clone, Debug)]
|
2020-03-04 18:49:38 -05:00
|
|
|
pub struct TexturePageDescriptor {
|
2019-06-03 15:39:29 -04:00
|
|
|
pub size: Vector2I,
|
2019-05-14 14:33:52 -04:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:41:24 -05:00
|
|
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
|
|
|
pub struct TextureLocation {
|
|
|
|
pub page: TexturePageId,
|
|
|
|
pub rect: RectI,
|
|
|
|
}
|
|
|
|
|
2020-02-26 17:56:05 -05:00
|
|
|
#[derive(Clone, Debug)]
|
2020-03-19 19:44:45 -04:00
|
|
|
pub struct TileBatch {
|
|
|
|
pub tiles: Vec<Tile>,
|
|
|
|
pub color_texture_0: Option<TileBatchTexture>,
|
|
|
|
pub color_texture_1: Option<TileBatchTexture>,
|
|
|
|
pub mask_0_fill_rule: Option<FillRule>,
|
|
|
|
pub mask_1_fill_rule: Option<FillRule>,
|
2020-02-26 17:56:05 -05:00
|
|
|
pub blend_mode: BlendMode,
|
2020-03-19 19:44:45 -04:00
|
|
|
pub effects: Effects,
|
2020-02-26 17:56:05 -05:00
|
|
|
}
|
|
|
|
|
2020-03-19 19:44:45 -04:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
|
|
pub struct TileBatchTexture {
|
|
|
|
pub page: TexturePageId,
|
2020-02-26 17:56:05 -05:00
|
|
|
pub sampling_flags: TextureSamplingFlags,
|
2020-03-02 23:04:09 -05:00
|
|
|
}
|
|
|
|
|
2019-01-14 17:20:36 -05:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
pub struct FillObjectPrimitive {
|
|
|
|
pub px: LineSegmentU4,
|
|
|
|
pub subpx: LineSegmentU8,
|
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
2019-04-15 16:21:24 -04:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct TileObjectPrimitive {
|
|
|
|
/// If `u16::MAX`, then this is a solid tile.
|
|
|
|
pub alpha_tile_index: u16,
|
|
|
|
pub backdrop: i8,
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(pcwalton): Move `subpx` before `px` and remove `repr(packed)`.
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
2019-01-15 13:52:37 -05:00
|
|
|
#[repr(packed)]
|
2019-01-14 17:20:36 -05:00
|
|
|
pub struct FillBatchPrimitive {
|
|
|
|
pub px: LineSegmentU4,
|
|
|
|
pub subpx: LineSegmentU8,
|
2019-03-22 17:28:18 -04:00
|
|
|
pub alpha_tile_index: u16,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2020-03-05 15:22:01 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
2019-01-14 22:32:53 -05:00
|
|
|
#[repr(C)]
|
2020-03-19 19:44:45 -04:00
|
|
|
pub struct Tile {
|
|
|
|
pub upper_left: TileVertex,
|
|
|
|
pub upper_right: TileVertex,
|
|
|
|
pub lower_left: TileVertex,
|
|
|
|
pub lower_right: TileVertex,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2020-02-15 00:55:37 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
#[repr(C)]
|
2020-03-19 19:44:45 -04:00
|
|
|
pub struct TileVertex {
|
2020-02-07 14:46:20 -05:00
|
|
|
pub tile_x: i16,
|
|
|
|
pub tile_y: i16,
|
2020-03-19 19:44:45 -04:00
|
|
|
pub color_0_u: f32,
|
|
|
|
pub color_0_v: f32,
|
|
|
|
pub color_1_u: f32,
|
|
|
|
pub color_1_v: f32,
|
|
|
|
pub mask_0_u: f32,
|
|
|
|
pub mask_0_v: f32,
|
|
|
|
pub mask_1_u: f32,
|
|
|
|
pub mask_1_v: f32,
|
|
|
|
pub mask_0_backdrop: i16,
|
|
|
|
pub mask_1_backdrop: i16,
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
|
2019-03-29 22:11:38 -04:00
|
|
|
impl Debug for RenderCommand {
|
|
|
|
fn fmt(&self, formatter: &mut Formatter) -> DebugResult {
|
|
|
|
match *self {
|
2019-04-30 22:13:28 -04:00
|
|
|
RenderCommand::Start { .. } => write!(formatter, "Start"),
|
2020-03-04 18:49:38 -05:00
|
|
|
RenderCommand::AllocateTexturePages(ref pages) => {
|
|
|
|
write!(formatter, "AllocateTexturePages(x{})", pages.len())
|
|
|
|
}
|
2020-03-04 22:41:24 -05:00
|
|
|
RenderCommand::UploadTexelData { ref texels, location } => {
|
2020-03-19 19:44:45 -04:00
|
|
|
write!(formatter, "UploadTexelData(x{:?}, {:?})", texels.len(), location)
|
2020-03-04 18:49:38 -05:00
|
|
|
}
|
2020-03-04 22:41:24 -05:00
|
|
|
RenderCommand::DeclareRenderTarget { id, location } => {
|
|
|
|
write!(formatter, "DeclareRenderTarget({:?}, {:?})", id, location)
|
2019-04-30 22:13:28 -04:00
|
|
|
}
|
2019-04-15 16:21:24 -04:00
|
|
|
RenderCommand::AddFills(ref fills) => write!(formatter, "AddFills(x{})", fills.len()),
|
|
|
|
RenderCommand::FlushFills => write!(formatter, "FlushFills"),
|
2020-02-22 00:42:15 -05:00
|
|
|
RenderCommand::PushRenderTarget(render_target_id) => {
|
|
|
|
write!(formatter, "PushRenderTarget({:?})", render_target_id)
|
|
|
|
}
|
|
|
|
RenderCommand::PopRenderTarget => write!(formatter, "PopRenderTarget"),
|
2020-03-19 19:44:45 -04:00
|
|
|
RenderCommand::DrawTiles(ref batch) => {
|
2020-02-21 17:46:10 -05:00
|
|
|
write!(formatter,
|
2020-03-19 19:44:45 -04:00
|
|
|
"DrawTiles(x{}, C0 {:?}, C1 {:?}, M0 {:?}, {:?})",
|
2020-03-05 15:22:01 -05:00
|
|
|
batch.tiles.len(),
|
2020-03-19 19:44:45 -04:00
|
|
|
batch.color_texture_0,
|
|
|
|
batch.color_texture_1,
|
|
|
|
batch.mask_0_fill_rule,
|
|
|
|
batch.blend_mode)
|
2019-05-03 21:51:36 -04:00
|
|
|
}
|
2019-04-30 22:13:28 -04:00
|
|
|
RenderCommand::Finish { .. } => write!(formatter, "Finish"),
|
2019-01-14 17:20:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|