Skip to content

Commit

Permalink
More instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
manpat committed Oct 3, 2024
1 parent 1ece306 commit 2235fce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion toybox-gfx/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Command {
_ => None
}
}

pub fn bindings(&self) -> Option<&BindingDescription> {
use Command::*;

Expand Down
11 changes: 8 additions & 3 deletions toybox-gfx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ impl System {
}
}

#[instrument(skip_all, name="gfx start_frame")]
#[instrument(skip_all, name="gfxsys start_frame")]
pub fn start_frame(&mut self) {
self.core.set_debugging_enabled(true);

self.resource_manager.start_frame(&mut self.core);
self.frame_encoder.start_frame();
}

#[instrument(skip_all, name="gfx execute_frame")]
#[instrument(skip_all, name="gfxsys execute_frame")]
pub fn execute_frame(&mut self, vfs: &toybox_vfs::Vfs) {
self.resource_manager.process_requests(&mut self.core, vfs)
.context("Error while processing resource requests")
Expand Down Expand Up @@ -133,6 +133,7 @@ impl System {
self.core.set_debugging_enabled(false);
}

#[instrument(skip_all, name="gfxsys resolve_named_bind_targets")]
fn resolve_named_bind_targets(&mut self) {
for command_group in self.frame_encoder.command_groups.iter_mut() {
for command in command_group.commands.iter_mut() {
Expand All @@ -143,6 +144,7 @@ impl System {
}
}

#[instrument(skip_all, name="gfxsys resolve_staged_buffer_alignments")]
fn resolve_staged_buffer_alignments(&mut self) {
let upload_stage = &mut self.frame_encoder.upload_stage;
let capabilities = self.core.capabilities();
Expand All @@ -158,6 +160,7 @@ impl System {
}
}

#[instrument(skip_all, name="gfxsys resolve_staged_bind_sources")]
fn resolve_staged_bind_sources(&mut self) {
let upload_heap = &mut self.resource_manager.upload_heap;

Expand All @@ -172,6 +175,7 @@ impl System {
}
}

#[instrument(skip_all, name="gfxsys resolve_image_bind_sources")]
fn resolve_image_bind_sources(&mut self) {
for command_group in self.frame_encoder.command_groups.iter_mut() {
for command in command_group.commands.iter_mut() {
Expand All @@ -185,6 +189,7 @@ impl System {
// TODO(pat.m): this sucks. it would be better for commands to 'pull' the bindings they need
// rather than bindings be 'pushed' like this - although a binding tracker may make this less bad.
// its still pretty wasteful though.
#[instrument(skip_all, name="gfxsys merge_bindings")]
fn merge_bindings(&mut self) {
for command_group in self.frame_encoder.command_groups.iter_mut() {
command_group.shared_bindings.merge_unspecified_from(&self.frame_encoder.global_bindings);
Expand All @@ -197,7 +202,7 @@ impl System {
}
}

#[instrument(skip_all, name="gfx dispatch_commands")]
#[instrument(skip_all, name="gfxsys dispatch_commands")]
fn dispatch_commands(&mut self) {
use command::Command::*;

Expand Down
7 changes: 7 additions & 0 deletions toybox-gfx/src/resource_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::hash::Hash;

use std::collections::HashMap;
use anyhow::Context;
use tracing::instrument;

use crate::prelude::*;
use crate::upload_heap::UploadHeap;
Expand Down Expand Up @@ -169,6 +170,7 @@ impl ResourceManager {

/// Make sure all image names that will be invalidated on resize are
/// gone before client code has a chance to ask for them.
#[instrument(skip_all, name="gfx rm handle_resize")]
pub fn handle_resize(&mut self, core: &mut core::Core) {
if let Some(_size) = self.resize_request.take() {
// TODO(pat.m): recreate framebuffers etc
Expand All @@ -180,6 +182,7 @@ impl ResourceManager {
}
}

#[instrument(skip_all, name="gfx rm start_frame")]
pub fn start_frame(&mut self, core: &mut core::Core) {
self.handle_resize(core);

Expand All @@ -195,6 +198,7 @@ impl ResourceManager {
}

/// Attempt to turn requested resources into committed GPU resources.
#[instrument(skip_all, name="gfx rm process_requests")]
pub fn process_requests(&mut self, core: &mut core::Core, vfs: &vfs::Vfs) -> anyhow::Result<()> {
core.push_debug_group("Process Resource Requests");

Expand Down Expand Up @@ -233,6 +237,7 @@ impl ResourceManager {

/// Execution api
impl ResourceManager {
#[instrument(skip_all, name="gfx rm resolve_draw_pipeline")]
pub fn resolve_draw_pipeline(&mut self, core: &mut core::Core,
vertex_shader: shader::ShaderHandle, fragment_shader: impl Into<Option<shader::ShaderHandle>>)
-> core::ShaderPipelineName
Expand Down Expand Up @@ -261,6 +266,7 @@ impl ResourceManager {
pipeline
}

#[instrument(skip_all, name="gfx rm resolve_compute_pipeline")]
pub fn resolve_compute_pipeline(&mut self, core: &mut core::Core, compute_shader: shader::ShaderHandle)
-> core::ShaderPipelineName
{
Expand All @@ -278,6 +284,7 @@ impl ResourceManager {
pipeline
}

#[instrument(skip_all, name="gfx rm resolve_framebuffer")]
pub fn resolve_framebuffer(&mut self, core: &core::Core, desc: impl Into<FramebufferDescription>)
-> Option<core::FramebufferName>
{
Expand Down
4 changes: 4 additions & 0 deletions toybox-gfx/src/resource_manager/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use std::path::{Path, PathBuf};
use tracing::instrument;

use crate::core::*;

Expand Down Expand Up @@ -61,6 +62,7 @@ impl super::Resource for ImageResource {
}

impl ImageResource {
#[instrument(skip_all, name="gfx ImageResource::from_vfs")]
pub fn from_vfs(core: &Core, vfs: &vfs::Vfs, virtual_path: &Path, label: String) -> anyhow::Result<ImageResource> {
// TODO(pat.m): use a BufReader instead so that image can read only what it needs
let data = vfs.load_resource_data(virtual_path)?;
Expand All @@ -84,6 +86,7 @@ impl ImageResource {
})
}

#[instrument(skip_all, name="gfx ImageResource::array_from_vfs")]
pub fn array_from_vfs(core: &Core, vfs: &vfs::Vfs, virtual_paths: &[PathBuf], label: String) -> anyhow::Result<ImageResource> {
if virtual_paths.is_empty() {
anyhow::bail!("Trying to create empty image array")
Expand Down Expand Up @@ -128,6 +131,7 @@ impl ImageResource {
})
}

#[instrument(skip_all, name="gfx ImageResource::from_create_request")]
pub fn from_create_request(core: &Core, req: &CreateImageRequest) -> ImageResource {
let mut image_info = req.image_info.clone();

Expand Down
4 changes: 4 additions & 0 deletions toybox-gfx/src/resource_manager/shader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::prelude::*;
use std::path::Path;
use tracing::instrument;

use crate::core::{
self,
Expand Down Expand Up @@ -36,6 +37,7 @@ impl super::Resource for ShaderResource {
}

impl ShaderResource {
#[instrument(skip_all, name="gfx ShaderResource::from_source")]
pub fn from_source(core: &core::Core, shader_type: ShaderType, data: &str, label: &str) -> anyhow::Result<ShaderResource> {
// TODO(pat.m): ugh
let uses_user_clipping = data.contains("gl_ClipDistance");
Expand Down Expand Up @@ -76,6 +78,7 @@ impl ShaderResource {
})
}

#[instrument(skip_all, name="gfx ShaderResource::from_vfs")]
pub fn from_vfs(core: &core::Core, vfs: &vfs::Vfs, shader_type: ShaderType, virtual_path: &Path, label: &str) -> anyhow::Result<ShaderResource> {
let data = vfs.load_resource_data(virtual_path)?;
let data = String::from_utf8(data)?;
Expand All @@ -86,6 +89,7 @@ impl ShaderResource {


// TODO(pat.m): Could this be in core?
#[instrument(skip_all)]
fn reflect_workgroup_size(core: &core::Core, shader_name: ShaderName) -> Option<Vec3i> {
if shader_name.shader_type != ShaderType::Compute {
return None
Expand Down

0 comments on commit 2235fce

Please sign in to comment.