wgpu: Hook up wgpu renderer, and wgpu's profiling, to tracy

This commit is contained in:
Nathan Adams 2023-01-06 13:17:12 +01:00
parent f606735720
commit 4d85b6a75b
8 changed files with 54 additions and 17 deletions

25
Cargo.lock generated
View File

@ -3227,6 +3227,20 @@ name = "profiling"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74605f360ce573babfe43964cbe520294dcb081afbf8c108fc6e23036b4da2df"
dependencies = [
"profiling-procmacros",
"tracy-client",
]
[[package]]
name = "profiling-procmacros"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a1e2417ef905b8ad94215f8a607bd2d0f5d13d416d18dca4a530811e8a0674c"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "quick-xml"
@ -3586,13 +3600,14 @@ dependencies = [
"futures",
"gc-arena",
"image",
"log",
"naga-agal",
"once_cell",
"ouroboros",
"profiling",
"raw-window-handle 0.5.0",
"ruffle_render",
"swf",
"tracing",
"typed-arena",
"web-sys",
"wgpu",
@ -4505,9 +4520,9 @@ dependencies = [
[[package]]
name = "tracing-tracy"
version = "0.10.1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74513033e242c0109c2ba9cb6d94117a53dbd6511eb135f5512143136eeba311"
checksum = "ed3ebef1f9f0d00aaa29239537effef65b82c56040c680f540fc6cedfac7b230"
dependencies = [
"tracing-core",
"tracing-subscriber",
@ -4527,9 +4542,9 @@ dependencies = [
[[package]]
name = "tracy-client"
version = "0.15.0"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c615e58172e788a208faee61b74988cd9c4778bc782384bed540b3fa4e5d4436"
checksum = "8b3b9ab635a5b91dd66b7a1591a89f7d52423e6a9143b230bb4c503f41296c0c"
dependencies = [
"loom",
"once_cell",

View File

@ -25,7 +25,9 @@ isahc = "1.7.2"
rfd = "0.10.0"
anyhow = "1.0"
bytemuck = "1.12.3"
tracing-tracy = { version = "0.10.1", optional = true }
# Deliberately held back to match tracy client used by profiling crate
tracing-tracy = { version = "=0.10.0", optional = true }
[target.'cfg(windows)'.dependencies]
winapi = "0.3.9"
@ -40,7 +42,7 @@ default = ["software_video"]
avm_debug = ["ruffle_core/avm_debug"]
lzma = ["ruffle_core/lzma"]
software_video = ["ruffle_video_software"]
tracy = ["tracing-tracy"]
tracy = ["tracing-tracy", "ruffle_render_wgpu/profile-with-tracy"]
# wgpu features
render_debug_labels = ["ruffle_render_wgpu/render_debug_labels"]

View File

@ -9,7 +9,7 @@ version.workspace = true
[dependencies]
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "630c12fe47a7bc0dc9ec6217f3903ec6fd6e3fac", features = ["naga"] }
log = "0.4"
tracing = "0.1.37"
ruffle_render = { path = "..", features = ["tessellator"] }
bytemuck = { version = "1.12.3", features = ["derive"] }
raw-window-handle = "0.5"
@ -24,6 +24,7 @@ once_cell = "1.17.0"
gc-arena = { workspace = true }
naga-agal = { path = "../naga-agal" }
downcast-rs = "1.2.0"
profiling = { version = "1.0", default-features = false, optional = true }
# desktop
[target.'cfg(not(target_family = "wasm"))'.dependencies.futures]
@ -38,3 +39,4 @@ features = ["HtmlCanvasElement"]
render_debug_labels = []
render_trace = ["wgpu/trace"]
webgl = ["wgpu/webgl"]
profile-with-tracy = ["profiling", "profiling/profile-with-tracy"]

View File

@ -22,6 +22,7 @@ use std::num::NonZeroU32;
use std::path::Path;
use std::sync::Arc;
use swf::Color;
use tracing::instrument;
use wgpu::Extent3d;
pub struct WgpuRenderBackend<T: RenderTarget> {
@ -72,7 +73,7 @@ impl WgpuRenderBackend<SwapChainTarget> {
trace_path: Option<&Path>,
) -> Result<Self, Error> {
if wgpu::Backends::SECONDARY.contains(backend) {
log::warn!(
tracing::warn!(
"{} graphics backend support may not be fully supported.",
format_list(&get_backend_names(backend), "and")
);
@ -100,7 +101,7 @@ impl WgpuRenderBackend<crate::target::TextureTarget> {
trace_path: Option<&Path>,
) -> Result<Self, Error> {
if wgpu::Backends::SECONDARY.contains(backend) {
log::warn!(
tracing::warn!(
"{} graphics backend support may not be fully supported.",
format_list(&get_backend_names(backend), "and")
);
@ -298,6 +299,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
)))
}
#[instrument(level = "debug", skip_all)]
fn context3d_present<'gc>(
&mut self,
context: &mut dyn Context3D,
@ -346,6 +348,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
}
}
#[instrument(level = "debug", skip_all)]
fn register_shape(
&mut self,
shape: DistilledShape,
@ -357,6 +360,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
handle
}
#[instrument(level = "debug", skip_all)]
fn replace_shape(
&mut self,
shape: DistilledShape,
@ -367,6 +371,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
self.meshes[handle.0] = mesh;
}
#[instrument(level = "debug", skip_all)]
fn register_glyph_shape(&mut self, glyph: &swf::Glyph) -> ShapeHandle {
let shape = ruffle_render::shape_utils::swf_glyph_to_shape(glyph);
let handle = ShapeHandle(self.meshes.len());
@ -378,11 +383,12 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
handle
}
#[instrument(level = "debug", skip_all)]
fn submit_frame(&mut self, clear: Color, commands: CommandList) {
let frame_output = match self.target.get_next_texture() {
Ok(frame) => frame,
Err(e) => {
log::warn!("Couldn't begin new render frame: {}", e);
tracing::warn!("Couldn't begin new render frame: {}", e);
// Attempt to recreate the swap chain in this case.
self.target.resize(
&self.descriptors.device,
@ -420,6 +426,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
self.offscreen_texture_pool = TexturePool::new();
}
#[instrument(level = "debug", skip_all)]
fn register_bitmap(&mut self, bitmap: Bitmap) -> Result<BitmapHandle, BitmapError> {
if bitmap.width() > self.descriptors.limits.max_texture_dimension_2d
|| bitmap.height() > self.descriptors.limits.max_texture_dimension_2d
@ -479,6 +486,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
Ok(handle)
}
#[instrument(level = "debug", skip_all)]
fn update_texture(
&mut self,
handle: &BitmapHandle,
@ -513,6 +521,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
Ok(())
}
#[instrument(level = "debug", skip_all)]
fn render_offscreen(
&mut self,
handle: BitmapHandle,

View File

@ -174,7 +174,7 @@ impl CurrentPipeline {
Context3DTriangleFace::Back => Some(wgpu::Face::Back),
Context3DTriangleFace::Front => Some(wgpu::Face::Front),
Context3DTriangleFace::FrontAndBack => {
log::error!("FrontAndBack culling not supported!");
tracing::error!("FrontAndBack culling not supported!");
None
}
Context3DTriangleFace::None => None,

View File

@ -225,7 +225,7 @@ impl WgpuContext3D {
mask,
} => {
if *mask != COLOR_MASK | DEPTH_MASK | STENCIL_MASK {
log::warn!(
tracing::warn!(
"Context3D::present: Clear command with mask {:x} not implemeneted",
mask
);
@ -253,12 +253,14 @@ impl WgpuContext3D {
wants_best_resolution_on_browser_zoom: _,
} => {
if *anti_alias != 1 {
log::warn!(
tracing::warn!(
"configureBackBuffer: anti_alias={anti_alias} is not yet implemented"
);
}
if *depth_and_stencil {
log::warn!("configureBackBuffer: depth_and_stencil is not yet implemented");
tracing::warn!(
"configureBackBuffer: depth_and_stencil is not yet implemented"
);
}
let texture_label = create_debug_label!("Render target texture");
@ -358,7 +360,7 @@ impl WgpuContext3D {
);
if !seen_clear_command {
log::warn!("Context3D::present: drawTriangles called without first calling clear()");
tracing::warn!("Context3D::present: drawTriangles called without first calling clear()");
}
if new_pipeline.is_some() || render_pass.is_none() {

View File

@ -11,6 +11,7 @@ use crate::{ColorAdjustments, Descriptors, MaskState, Pipelines, Transforms, Uni
use ruffle_render::commands::CommandList;
use std::sync::Arc;
use target::CommandTarget;
use tracing::instrument;
#[derive(Debug)]
pub struct Surface {
@ -47,6 +48,7 @@ impl Surface {
}
#[allow(clippy::too_many_arguments)]
#[instrument(level = "debug", skip_all)]
pub fn draw_commands_to(
&mut self,
frame_view: &wgpu::TextureView,
@ -165,6 +167,7 @@ impl Surface {
}
#[allow(clippy::too_many_arguments)]
#[instrument(level = "debug", skip_all)]
pub fn draw_commands<'frame, 'global: 'frame>(
&mut self,
clear_color: wgpu::Color,

View File

@ -3,6 +3,7 @@ use crate::Error;
use ruffle_render::utils::unmultiply_alpha_rgba;
use std::fmt::Debug;
use std::sync::Arc;
use tracing::instrument;
pub trait RenderTargetFrame: Debug {
fn into_view(self) -> wgpu::TextureView;
@ -123,6 +124,7 @@ impl RenderTarget for SwapChainTarget {
Ok(SwapChainTargetFrame { texture, view })
}
#[instrument(level = "debug", skip_all)]
fn submit<I: IntoIterator<Item = wgpu::CommandBuffer>>(
&self,
_device: &wgpu::Device,
@ -209,6 +211,7 @@ impl TextureTarget {
/// Captures the current contents of our texture buffer
/// as an `RgbaImage`
#[instrument(level = "debug", skip_all)]
pub fn capture(
&self,
device: &wgpu::Device,
@ -251,7 +254,7 @@ impl TextureTarget {
image
}
Err(e) => {
log::error!("Unknown error reading capture buffer: {:?}", e);
tracing::error!("Unknown error reading capture buffer: {:?}", e);
None
}
}
@ -284,6 +287,7 @@ impl RenderTarget for TextureTarget {
))
}
#[instrument(level = "debug", skip_all)]
fn submit<I: IntoIterator<Item = wgpu::CommandBuffer>>(
&self,
device: &wgpu::Device,