Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Sync changes from mozilla-central #3552

Merged
merged 4 commits into from Feb 13, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Bug 1527522 - Add external hooks to WR to allow integration with the …

  • Loading branch information
gw3583 authored and moz-gfx committed Feb 13, 2019
commit 89ea09e9438aff7538d06e033ab40af1fc314708
@@ -28,6 +28,7 @@ bincode = "1.0"
bitflags = "1.0"
byteorder = "1.0"
cfg-if = "0.1.2"
cstr = "0.1.2"
fxhash = "0.2.1"
gleam = "0.6.8"
image = { optional = true, version = "0.21" }
@@ -374,6 +374,8 @@ impl FrameBuilder {
);

{
profile_marker!("UpdateVisibility");

let visibility_context = FrameVisibilityContext {
device_pixel_scale,
clip_scroll_tree,
@@ -439,15 +441,19 @@ impl FrameBuilder {
)
.unwrap();

self.prim_store.prepare_primitives(
&mut prim_list,
&pic_context,
&mut pic_state,
&frame_context,
&mut frame_state,
data_stores,
scratch,
);
{
profile_marker!("PreparePrims");

self.prim_store.prepare_primitives(
&mut prim_list,
&pic_context,
&mut pic_state,
&frame_context,
&mut frame_state,
data_stores,
scratch,
);
}

let pic = &mut self.prim_store.pictures[self.root_pic_index.0];
pic.restore_context(
@@ -500,6 +506,7 @@ impl FrameBuilder {
debug_flags: DebugFlags,
) -> Frame {
profile_scope!("build");
profile_marker!("BuildFrame");
debug_assert!(
DeviceIntRect::new(DeviceIntPoint::zero(), self.window_size)
.contains_rect(&self.screen_rect)
@@ -546,79 +553,86 @@ impl FrameBuilder {
debug_flags,
);

resource_cache.block_until_all_resources_added(gpu_cache,
&mut render_tasks,
texture_cache_profile);
{
profile_marker!("BlockOnResources");

resource_cache.block_until_all_resources_added(gpu_cache,
&mut render_tasks,
texture_cache_profile);
}

let mut passes = vec![];
let mut deferred_resolves = vec![];
let mut has_texture_cache_tasks = false;
let mut prim_headers = PrimitiveHeaders::new();

// Add passes as required for our cached render tasks.
if !render_tasks.cacheable_render_tasks.is_empty() {
passes.push(RenderPass::new_off_screen(screen_size));
for cacheable_render_task in &render_tasks.cacheable_render_tasks {
{
profile_marker!("Batching");

// Add passes as required for our cached render tasks.
if !render_tasks.cacheable_render_tasks.is_empty() {
passes.push(RenderPass::new_off_screen(screen_size));
for cacheable_render_task in &render_tasks.cacheable_render_tasks {
render_tasks.assign_to_passes(
*cacheable_render_task,
0,
screen_size,
&mut passes,
);
}
passes.reverse();
}

if let Some(main_render_task_id) = main_render_task_id {
let passes_start = passes.len();
passes.push(RenderPass::new_main_framebuffer(screen_size));
render_tasks.assign_to_passes(
*cacheable_render_task,
0,
main_render_task_id,
passes_start,
screen_size,
&mut passes,
);
passes[passes_start..].reverse();
}
passes.reverse();
}

if let Some(main_render_task_id) = main_render_task_id {
let passes_start = passes.len();
passes.push(RenderPass::new_main_framebuffer(screen_size));
render_tasks.assign_to_passes(
main_render_task_id,
passes_start,
screen_size,
&mut passes,
);
passes[passes_start..].reverse();
}


let mut deferred_resolves = vec![];
let mut has_texture_cache_tasks = false;
let mut prim_headers = PrimitiveHeaders::new();
// Used to generated a unique z-buffer value per primitive.
let mut z_generator = ZBufferIdGenerator::new();
let use_dual_source_blending = self.config.dual_source_blending_is_enabled &&
self.config.dual_source_blending_is_supported;

for pass in &mut passes {
let mut ctx = RenderTargetContext {
device_pixel_scale,
prim_store: &self.prim_store,
resource_cache,
use_dual_source_blending,
clip_scroll_tree,
data_stores,
surfaces: &surfaces,
scratch,
screen_world_rect,
globals: &self.globals,
};

pass.build(
&mut ctx,
gpu_cache,
&mut render_tasks,
&mut deferred_resolves,
&self.clip_store,
&mut transform_palette,
&mut prim_headers,
&mut z_generator,
);
// Used to generated a unique z-buffer value per primitive.
let mut z_generator = ZBufferIdGenerator::new();
let use_dual_source_blending = self.config.dual_source_blending_is_enabled &&
self.config.dual_source_blending_is_supported;

for pass in &mut passes {
let mut ctx = RenderTargetContext {
device_pixel_scale,
prim_store: &self.prim_store,
resource_cache,
use_dual_source_blending,
clip_scroll_tree,
data_stores,
surfaces: &surfaces,
scratch,
screen_world_rect,
globals: &self.globals,
};

pass.build(
&mut ctx,
gpu_cache,
&mut render_tasks,
&mut deferred_resolves,
&self.clip_store,
&mut transform_palette,
&mut prim_headers,
&mut z_generator,
);

match pass.kind {
RenderPassKind::MainFramebuffer(ref color) => {
has_texture_cache_tasks |= color.must_be_drawn();
}
RenderPassKind::OffScreen { ref texture_cache, ref color, .. } => {
has_texture_cache_tasks |= !texture_cache.is_empty();
has_texture_cache_tasks |= color.must_be_drawn();
match pass.kind {
RenderPassKind::MainFramebuffer(ref color) => {
has_texture_cache_tasks |= color.must_be_drawn();
}
RenderPassKind::OffScreen { ref texture_cache, ref color, .. } => {
has_texture_cache_tasks |= !texture_cache.is_empty();
has_texture_cache_tasks |= color.must_be_drawn();
}
}
}
}
@@ -56,6 +56,8 @@ extern crate bitflags;
#[macro_use]
extern crate cfg_if;
#[macro_use]
extern crate cstr;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
@@ -70,6 +72,9 @@ extern crate thread_profiler;
extern crate wr_malloc_size_of;
use wr_malloc_size_of as malloc_size_of;

#[macro_use]
mod profiler;

mod batch;
mod border;
mod box_shadow;
@@ -103,7 +108,6 @@ mod internal_types;
mod picture;
mod prim_store;
mod print_tree;
mod profiler;
mod record;
mod render_backend;
mod render_task;
@@ -207,6 +211,7 @@ pub use device::{ProgramBinary, ProgramCache, ProgramCacheObserver};
pub use device::Device;
pub use frame_builder::ChasePrimitive;
pub use picture::FRAMES_BEFORE_PICTURE_CACHING;
pub use profiler::{ProfilerHooks, set_profiler_hooks};
pub use renderer::{AsyncPropertySampler, CpuProfile, DebugFlags, OutputImageHandler, RendererKind};
pub use renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource, GpuProfile};
pub use renderer::{GraphicsApi, GraphicsApiInfo, PipelineInfo, Renderer, RendererOptions};
@@ -1646,6 +1646,8 @@ impl<'a> PictureUpdateState<'a> {
clip_store: &ClipStore,
clip_data_store: &ClipDataStore,
) {
profile_marker!("UpdatePictures");

let mut state = PictureUpdateState {
surfaces,
surface_stack: vec![SurfaceIndex(0)],
@@ -7,9 +7,10 @@ use debug_render::DebugRenderer;
use device::query::{GpuSampler, GpuTimer, NamedTag};
use euclid::{Point2D, Rect, Size2D, vec2};
use internal_types::FastHashMap;
use renderer::MAX_VERTEX_TEXTURE_WIDTH;
use renderer::{MAX_VERTEX_TEXTURE_WIDTH, wr_has_been_initialized};
use std::collections::vec_deque::VecDeque;
use std::{f32, mem};
use std::ffi::CStr;
use time::precise_time_ns;

const GRAPH_WIDTH: f32 = 1024.0;
@@ -20,6 +21,68 @@ const PROFILE_PADDING: f32 = 10.0;

const ONE_SECOND_NS: u64 = 1000000000;

/// Defines the interface for hooking up an external profiler to WR.
pub trait ProfilerHooks : Send + Sync {
/// Called at the beginning of a profile scope. The label must
/// be a C string (null terminated).
fn begin_marker(&self, label: &CStr);

/// Called at the end of a profile scope. The label must
/// be a C string (null terminated).
fn end_marker(&self, label: &CStr);
}

/// The current global profiler callbacks, if set by embedder.
static mut PROFILER_HOOKS: Option<&'static ProfilerHooks> = None;

/// Set the profiler callbacks, or None to disable the profiler.
/// This function must only ever be called before any WR instances
/// have been created, or the hooks will not be set.
pub fn set_profiler_hooks(hooks: Option<&'static ProfilerHooks>) {
if !wr_has_been_initialized() {
unsafe {
PROFILER_HOOKS = hooks;
}
}
}

/// A simple RAII style struct to manage a profile scope.
pub struct ProfileScope {
name: &'static CStr,
}

impl ProfileScope {
/// Begin a new profile scope
pub fn new(name: &'static CStr) -> Self {
unsafe {
if let Some(ref hooks) = PROFILER_HOOKS {
hooks.begin_marker(name);
}
}

ProfileScope {
name,
}
}
}

impl Drop for ProfileScope {
fn drop(&mut self) {
unsafe {
if let Some(ref hooks) = PROFILER_HOOKS {
hooks.end_marker(self.name);
}
}
}
}

/// A helper macro to define profile scopes.
macro_rules! profile_marker {
($string:expr) => {
let _scope = $crate::profiler::ProfileScope::new(cstr!($string));
};
}

#[derive(Debug, Clone)]
pub struct GpuProfileTag {
pub label: &'static str,
@@ -84,6 +84,7 @@ use std::os::raw::c_void;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver};
use std::thread;
use std::cell::RefCell;
@@ -106,6 +107,14 @@ cfg_if! {
}
}

/// Is only false if no WR instances have ever been created.
static HAS_BEEN_INITIALIZED: AtomicBool = AtomicBool::new(false);

/// Returns true if a WR instance has ever been initialized in this process.
pub fn wr_has_been_initialized() -> bool {
HAS_BEEN_INITIALIZED.load(Ordering::SeqCst)
}

pub const MAX_VERTEX_TEXTURE_WIDTH: usize = 1024;
/// Enabling this toggle would force the GPU cache scattered texture to
/// be resized every frame, which enables GPU debuggers to see if this
@@ -1629,6 +1638,8 @@ impl Renderer {
mut options: RendererOptions,
shaders: Option<&mut WrShaders>
) -> Result<(Self, RenderApiSender), RendererError> {
HAS_BEEN_INITIALIZED.store(true, Ordering::SeqCst);

let (api_tx, api_rx) = channel::msg_channel()?;
let (payload_tx, payload_rx) = channel::payload_channel()?;
let (result_tx, result_rx) = channel();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.