Skip to content

Commit d8f85be

Browse files
committed
Add reporting for texture memory.
1 parent 489d67c commit d8f85be

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

webrender/src/device/gl.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,17 @@ impl Texture {
487487
self.last_frame_used == frame_id
488488
}
489489

490+
/// Returns the number of bytes (generally in GPU memory) that this texture
491+
/// consumes.
492+
pub fn size_in_bytes(&self) -> usize {
493+
assert!(self.layer_count > 0 || self.width + self.height == 0);
494+
let bpp = self.format.bytes_per_pixel() as usize;
495+
let w = self.width as usize;
496+
let h = self.height as usize;
497+
let count = self.layer_count as usize;
498+
bpp * w * h * count
499+
}
500+
490501
#[cfg(feature = "replay")]
491502
pub fn into_external(mut self) -> ExternalTexture {
492503
let ext = ExternalTexture {

webrender/src/renderer.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,21 @@ impl SourceTextureResolver {
896896
}
897897
}
898898
}
899+
900+
fn report_memory(&self) -> MemoryReport {
901+
let mut report = MemoryReport::default();
902+
903+
// We're reporting GPU memory rather than heap-allocations, so we don't
904+
// use size_of_op.
905+
for t in self.cache_texture_map.iter() {
906+
report.texture_cache_textures += t.size_in_bytes();
907+
}
908+
for t in self.render_target_pool.iter() {
909+
report.render_target_textures += t.size_in_bytes();
910+
}
911+
912+
report
913+
}
899914
}
900915

901916
#[derive(Debug, Copy, Clone, PartialEq)]
@@ -4176,15 +4191,30 @@ impl Renderer {
41764191
/// Collects a memory report.
41774192
pub fn report_memory(&self) -> MemoryReport {
41784193
let mut report = MemoryReport::default();
4194+
4195+
// GPU cache CPU memory.
41794196
if let CacheBus::PixelBuffer{ref cpu_blocks, ..} = self.gpu_cache_texture.bus {
41804197
report.gpu_cache_cpu_mirror += self.size_of(cpu_blocks.as_ptr());
41814198
}
41824199

4200+
// GPU cache GPU memory.
4201+
report.gpu_cache_textures += self.gpu_cache_texture.texture.size_in_bytes();
4202+
4203+
// Render task CPU memory.
41834204
for (_id, doc) in &self.active_documents {
41844205
report.render_tasks += self.size_of(doc.frame.render_tasks.tasks.as_ptr());
41854206
report.render_tasks += self.size_of(doc.frame.render_tasks.task_data.as_ptr());
41864207
}
41874208

4209+
// Vertex data GPU memory.
4210+
report.vertex_data_textures += self.prim_header_f_texture.texture.size_in_bytes();
4211+
report.vertex_data_textures += self.prim_header_i_texture.texture.size_in_bytes();
4212+
report.vertex_data_textures += self.transforms_texture.texture.size_in_bytes();
4213+
report.vertex_data_textures += self.render_task_texture.texture.size_in_bytes();
4214+
4215+
// Texture cache and render target GPU memory.
4216+
report += self.texture_resolver.report_memory();
4217+
41884218
report
41894219
}
41904220

webrender_api/src/api.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ impl PipelineId {
751751
#[repr(C)]
752752
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
753753
pub struct MemoryReport {
754+
//
755+
// CPU Memory.
756+
//
754757
pub primitive_stores: usize,
755758
pub clip_stores: usize,
756759
pub gpu_cache_metadata: usize,
@@ -760,6 +763,13 @@ pub struct MemoryReport {
760763
pub fonts: usize,
761764
pub images: usize,
762765
pub rasterized_blobs: usize,
766+
//
767+
// GPU memory.
768+
//
769+
pub gpu_cache_textures: usize,
770+
pub vertex_data_textures: usize,
771+
pub render_target_textures: usize,
772+
pub texture_cache_textures: usize,
763773
}
764774

765775
impl ::std::ops::AddAssign for MemoryReport {
@@ -773,6 +783,10 @@ impl ::std::ops::AddAssign for MemoryReport {
773783
self.fonts += other.fonts;
774784
self.images += other.images;
775785
self.rasterized_blobs += other.rasterized_blobs;
786+
self.gpu_cache_textures += other.gpu_cache_textures;
787+
self.vertex_data_textures += other.vertex_data_textures;
788+
self.render_target_textures += other.render_target_textures;
789+
self.texture_cache_textures += other.texture_cache_textures;
776790
}
777791
}
778792

0 commit comments

Comments
 (0)