Bug 1728618 - Show shader build times in the wr profiler. r=gfx-reviewers,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D124218
This commit is contained in:
Nicolas Silva 2021-09-07 07:35:34 +00:00
Родитель 774d292c7b
Коммит 715673b09f
4 изменённых файлов: 101 добавлений и 15 удалений

Просмотреть файл

@ -65,7 +65,7 @@ static PROFILER_PRESETS: &'static[(&'static str, &'static str)] = &[
// Timing information for per layout transaction stages.
(&"Transaction times", &"DisplayList,Scene building,Content send,API send"),
// Timing information for per-frame stages.
(&"Frame times", &"Frame CPU total,Frame building,Visibility,Prepare,Batching,Glyph resolve,Texture cache update,Renderer,GPU"),
(&"Frame times", &"Frame CPU total,Frame building,Visibility,Prepare,Batching,Glyph resolve,Texture cache update,Shader build time,Renderer,GPU"),
// Stats about the content of the frame.
(&"Frame stats", &"Primitives,Visible primitives,Draw calls,Vertices,Color passes,Alpha passes,Rendered picture tiles,Rasterized glyphs"),
// Texture cache allocation stats.
@ -229,7 +229,9 @@ pub const INTERNED_POLYGONS: usize = 99;
pub const DEPTH_TARGETS_MEM: usize = 100;
pub const NUM_PROFILER_EVENTS: usize = 101;
pub const SHADER_BUILD_TIME: usize = 101;
pub const NUM_PROFILER_EVENTS: usize = 102;
pub struct Profiler {
counters: Vec<Counter>,
@ -383,6 +385,7 @@ impl Profiler {
int("Interned polygons", "", INTERNED_POLYGONS, Expected::none()),
float("Depth targets mem", "MB", DEPTH_TARGETS_MEM, Expected::none()),
float("Shader build time", "ms", SHADER_BUILD_TIME, Expected::none()),
];
let mut counters = Vec::with_capacity(profile_counters.len());

Просмотреть файл

@ -2579,6 +2579,7 @@ impl Renderer {
&projection,
Some(self.texture_resolver.get_texture_size(source).to_f32()),
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -2607,7 +2608,8 @@ impl Renderer {
&mut self.device,
&projection,
None,
&mut self.renderer_errors
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -2666,6 +2668,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
&[instance],
@ -2747,6 +2750,7 @@ impl Renderer {
.bind(
&mut self.device, projection, None,
&mut self.renderer_errors,
&mut self.profile,
);
let _timer = self.gpu_profiler.start_timer(batch.key.kind.sampler_tag());
@ -2823,6 +2827,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.device.switch_mode(ShaderColorMode::SubpixelWithBgColorPass0 as _);
}
@ -2864,6 +2869,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -2881,6 +2887,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.device.switch_mode(ShaderColorMode::SubpixelWithBgColorPass1 as _);
@ -2898,6 +2905,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.device.switch_mode(ShaderColorMode::SubpixelWithBgColorPass2 as _);
@ -2992,7 +3000,8 @@ impl Renderer {
&mut self.device,
&projection,
None,
&mut self.renderer_errors
&mut self.renderer_errors,
&mut self.profile,
);
let textures = BatchTextures::composite_yuv(
@ -3038,7 +3047,8 @@ impl Renderer {
&mut self.device,
&projection,
None,
&mut self.renderer_errors
&mut self.renderer_errors,
&mut self.profile,
);
let textures = BatchTextures::composite_rgb(plane.texture);
@ -3100,7 +3110,8 @@ impl Renderer {
&mut self.device,
projection,
None,
&mut self.renderer_errors
&mut self.renderer_errors,
&mut self.profile,
);
for item in tiles_iter {
@ -3261,7 +3272,8 @@ impl Renderer {
&mut self.device,
projection,
shader_params.3,
&mut self.renderer_errors
&mut self.renderer_errors,
&mut self.profile,
);
current_shader_params = shader_params;
@ -3528,7 +3540,7 @@ impl Renderer {
self.set_blend(false, framebuffer_kind);
self.shaders.borrow_mut().cs_blur_rgba8
.bind(&mut self.device, projection, None, &mut self.renderer_errors);
.bind(&mut self.device, projection, None, &mut self.renderer_errors, &mut self.profile);
if !target.vertical_blurs.is_empty() {
self.draw_blurs(
@ -3615,6 +3627,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
&list.slow_rectangles,
@ -3630,6 +3643,7 @@ impl Renderer {
projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
&list.fast_rectangles,
@ -3644,7 +3658,7 @@ impl Renderer {
let _gm2 = self.gpu_profiler.start_marker("box-shadows");
let textures = BatchTextures::composite_rgb(*mask_texture_id);
self.shaders.borrow_mut().cs_clip_box_shadow
.bind(&mut self.device, projection, None, &mut self.renderer_errors);
.bind(&mut self.device, projection, None, &mut self.renderer_errors, &mut self.profile);
self.draw_instanced_batch(
items,
VertexArrayKind::ClipBoxShadow,
@ -3677,7 +3691,7 @@ impl Renderer {
}
let textures = BatchTextures::composite_rgb(*mask_texture_id);
self.shaders.borrow_mut().cs_clip_image
.bind(&mut self.device, projection, None, &mut self.renderer_errors);
.bind(&mut self.device, projection, None, &mut self.renderer_errors, &mut self.profile);
self.draw_instanced_batch(
items,
VertexArrayKind::ClipImage,
@ -3762,6 +3776,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
&instances,
@ -3805,7 +3820,7 @@ impl Renderer {
let _timer = self.gpu_profiler.start_timer(GPU_TAG_BLUR);
self.shaders.borrow_mut().cs_blur_a8
.bind(&mut self.device, projection, None, &mut self.renderer_errors);
.bind(&mut self.device, projection, None, &mut self.renderer_errors, &mut self.profile);
if !target.vertical_blurs.is_empty() {
self.draw_blurs(
@ -3917,6 +3932,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
&instances,
@ -3957,6 +3973,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -3973,6 +3990,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -3998,6 +4016,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -4021,6 +4040,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
self.draw_instanced_batch(
@ -4042,6 +4062,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
if let Some(ref texture) = self.dither_matrix_texture {
@ -4067,6 +4088,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
if let Some(ref texture) = self.dither_matrix_texture {
@ -4092,6 +4114,7 @@ impl Renderer {
&projection,
None,
&mut self.renderer_errors,
&mut self.profile,
);
if let Some(ref texture) = self.dither_matrix_texture {
@ -4115,7 +4138,7 @@ impl Renderer {
match target.target_kind {
RenderTargetKind::Alpha => &mut shaders.cs_blur_a8,
RenderTargetKind::Color => &mut shaders.cs_blur_rgba8,
}.bind(&mut self.device, &projection, None, &mut self.renderer_errors);
}.bind(&mut self.device, &projection, None, &mut self.renderer_errors, &mut self.profile);
}
self.draw_blurs(

Просмотреть файл

@ -13,6 +13,7 @@ use crate::renderer::{
BlendMode, DebugFlags, RendererError, RendererOptions,
TextureSampler, VertexArrayKind, ShaderPrecacheFlags,
};
use crate::profiler::{self, TransactionProfile, ns_to_ms};
use gleam::gl::GlType;
use time::precise_time_ns;
@ -96,7 +97,9 @@ impl LazilyCompiledShader {
device: &mut Device,
precache_flags: ShaderPrecacheFlags,
shader_list: &ShaderFeatures,
profile: &mut TransactionProfile,
) -> Result<Self, ShaderError> {
let mut features = unsorted_features.to_vec();
features.sort();
@ -122,7 +125,7 @@ impl LazilyCompiledShader {
if precache_flags.intersects(ShaderPrecacheFlags::ASYNC_COMPILE | ShaderPrecacheFlags::FULL_COMPILE) {
let t0 = precise_time_ns();
shader.get_internal(device, precache_flags)?;
shader.get_internal(device, precache_flags, profile)?;
let t1 = precise_time_ns();
debug!("[C: {:.1} ms ] Precache {} {:?}",
(t1 - t0) as f64 / 1000000.0,
@ -140,9 +143,10 @@ impl LazilyCompiledShader {
projection: &Transform3D<f32>,
texture_size: Option<DeviceSize>,
renderer_errors: &mut Vec<RendererError>,
profile: &mut TransactionProfile,
) {
let update_projection = self.cached_projection != *projection;
let program = match self.get_internal(device, ShaderPrecacheFlags::FULL_COMPILE) {
let program = match self.get_internal(device, ShaderPrecacheFlags::FULL_COMPILE, profile) {
Ok(program) => program,
Err(e) => {
renderer_errors.push(RendererError::from(e));
@ -164,8 +168,10 @@ impl LazilyCompiledShader {
&mut self,
device: &mut Device,
precache_flags: ShaderPrecacheFlags,
profile: &mut TransactionProfile,
) -> Result<&mut Program, ShaderError> {
if self.program.is_none() {
let start_time = precise_time_ns();
let program = match self.kind {
ShaderKind::Primitive | ShaderKind::Brush | ShaderKind::Text | ShaderKind::Resolve | ShaderKind::Clear => {
create_prim_shader(
@ -211,11 +217,16 @@ impl LazilyCompiledShader {
}
};
self.program = Some(program?);
let end_time = precise_time_ns();
profile.add(profiler::SHADER_BUILD_TIME, ns_to_ms(end_time - start_time));
}
let program = self.program.as_mut().unwrap();
if precache_flags.contains(ShaderPrecacheFlags::FULL_COMPILE) && !program.is_initialized() {
let start_time = precise_time_ns();
let vertex_format = match self.kind {
ShaderKind::Primitive |
ShaderKind::Brush |
@ -284,6 +295,9 @@ impl LazilyCompiledShader {
);
}
}
let end_time = precise_time_ns();
profile.add(profiler::SHADER_BUILD_TIME, ns_to_ms(end_time - start_time));
}
Ok(program)
@ -324,6 +338,7 @@ impl BrushShader {
shader_list: &ShaderFeatures,
use_advanced_blend: bool,
use_dual_source: bool,
profile: &mut TransactionProfile,
) -> Result<Self, ShaderError> {
let opaque_features = features.to_vec();
let opaque = LazilyCompiledShader::new(
@ -333,6 +348,7 @@ impl BrushShader {
device,
precache_flags,
&shader_list,
profile,
)?;
let mut alpha_features = opaque_features.to_vec();
@ -345,6 +361,7 @@ impl BrushShader {
device,
precache_flags,
&shader_list,
profile,
)?;
let advanced_blend = if use_advanced_blend {
@ -358,6 +375,7 @@ impl BrushShader {
device,
precache_flags,
&shader_list,
profile,
)?;
Some(shader)
@ -376,6 +394,7 @@ impl BrushShader {
device,
precache_flags,
&shader_list,
profile,
)?;
Some(shader)
@ -393,6 +412,7 @@ impl BrushShader {
device,
precache_flags,
&shader_list,
profile,
)?;
Ok(BrushShader {
@ -462,6 +482,7 @@ impl TextShader {
features: &[&'static str],
precache_flags: ShaderPrecacheFlags,
shader_list: &ShaderFeatures,
profile: &mut TransactionProfile,
) -> Result<Self, ShaderError> {
let mut simple_features = features.to_vec();
simple_features.push("ALPHA_PASS");
@ -474,6 +495,7 @@ impl TextShader {
device,
precache_flags,
&shader_list,
profile,
)?;
let mut glyph_transform_features = features.to_vec();
@ -488,6 +510,7 @@ impl TextShader {
device,
precache_flags,
&shader_list,
profile,
)?;
let mut debug_overdraw_features = features.to_vec();
@ -501,6 +524,7 @@ impl TextShader {
device,
precache_flags,
&shader_list,
profile,
)?;
Ok(TextShader { simple, glyph_transform, debug_overdraw })
@ -623,6 +647,10 @@ impl Shaders {
gl_type: GlType,
options: &RendererOptions,
) -> Result<Self, ShaderError> {
// We have to pass a profile around a bunch but we aren't recording the initialization
// so use a dummy one.
let profile = &mut TransactionProfile::new();
let use_dual_source_blending =
device.get_capabilities().supports_dual_source_blending &&
options.allow_dual_source_blending;
@ -658,6 +686,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let brush_blend = BrushShader::new(
@ -668,6 +697,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let brush_mix_blend = BrushShader::new(
@ -678,6 +708,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let brush_linear_gradient = BrushShader::new(
@ -692,6 +723,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let brush_opacity_aa = BrushShader::new(
@ -702,6 +734,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let brush_opacity = BrushShader::new(
@ -712,6 +745,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
let cs_blur_a8 = LazilyCompiledShader::new(
@ -721,6 +755,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_blur_rgba8 = LazilyCompiledShader::new(
@ -730,6 +765,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_svg_filter = LazilyCompiledShader::new(
@ -739,6 +775,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_clip_rectangle_slow = LazilyCompiledShader::new(
@ -748,6 +785,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_clip_rectangle_fast = LazilyCompiledShader::new(
@ -757,6 +795,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_clip_box_shadow = LazilyCompiledShader::new(
@ -766,6 +805,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_clip_image = LazilyCompiledShader::new(
@ -775,6 +815,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let mut cs_scale = Vec::new();
@ -802,6 +843,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let index = Self::get_compositing_shader_index(
@ -820,6 +862,7 @@ impl Shaders {
&[],
options.precache_flags,
&shader_list,
profile,
)?;
let ps_text_run_dual_source = if use_dual_source_blending {
@ -829,6 +872,7 @@ impl Shaders {
&dual_source_features,
options.precache_flags,
&shader_list,
profile,
)?)
} else {
None
@ -841,6 +885,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let ps_clear = LazilyCompiledShader::new(
@ -850,6 +895,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
// All image configuration.
@ -886,6 +932,7 @@ impl Shaders {
&shader_list,
use_advanced_blend_equation,
use_dual_source_blending,
profile,
)?);
image_features.push("REPETITION");
@ -899,6 +946,7 @@ impl Shaders {
&shader_list,
use_advanced_blend_equation,
use_dual_source_blending,
profile,
)?);
image_features.clear();
@ -950,6 +998,7 @@ impl Shaders {
&shader_list,
false /* advanced blend */,
false /* dual source */,
profile,
)?;
brush_yuv_image[index] = Some(brush_shader);
@ -960,6 +1009,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
composite_yuv[index] = Some(composite_yuv_shader);
}
@ -971,6 +1021,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let composite_rgba_fast_path_shader = LazilyCompiledShader::new(
@ -980,6 +1031,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let index = Self::get_compositing_shader_index(
@ -1001,6 +1053,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_fast_linear_gradient = LazilyCompiledShader::new(
@ -1010,6 +1063,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_linear_gradient = LazilyCompiledShader::new(
@ -1019,6 +1073,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_radial_gradient = LazilyCompiledShader::new(
@ -1028,6 +1083,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_conic_gradient = LazilyCompiledShader::new(
@ -1037,6 +1093,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_border_segment = LazilyCompiledShader::new(
@ -1046,6 +1103,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
let cs_border_solid = LazilyCompiledShader::new(
@ -1055,6 +1113,7 @@ impl Shaders {
device,
options.precache_flags,
&shader_list,
profile,
)?;
Ok(Shaders {

Просмотреть файл

@ -523,7 +523,8 @@ fn copy_from_staging_to_cache_using_draw_calls(
&mut renderer.device,
&projection,
None,
&mut renderer.renderer_errors
&mut renderer.renderer_errors,
&mut renderer.profile,
);
prev_dst = Some(copy.dest_texture_id);