wgpu: Removed some needless copies in command iteration

This commit is contained in:
Nathan Adams 2022-12-23 02:47:33 +01:00
parent 81f4741300
commit 342b9b9007
2 changed files with 17 additions and 19 deletions

View File

@ -278,7 +278,7 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
descriptors: &'global Descriptors, descriptors: &'global Descriptors,
uniform_buffers: &'frame mut UniformBuffer<'global, Transforms>, uniform_buffers: &'frame mut UniformBuffer<'global, Transforms>,
uniform_encoder: &'frame mut wgpu::CommandEncoder, uniform_encoder: &'frame mut wgpu::CommandEncoder,
commands: &CommandList, commands: CommandList,
nearest_layer: &'pass CommandTarget, nearest_layer: &'pass CommandTarget,
clear_color: &mut Option<wgpu::Color>, clear_color: &mut Option<wgpu::Color>,
draw_encoder: &'pass mut wgpu::CommandEncoder, draw_encoder: &'pass mut wgpu::CommandEncoder,
@ -288,7 +288,7 @@ impl<'pass, 'frame: 'pass, 'global: 'frame> CommandRenderer<'pass, 'frame, 'glob
let mut num_masks = 0; let mut num_masks = 0;
let mut mask_state = MaskState::NoMask; let mut mask_state = MaskState::NoMask;
let (chunks, needs_depth) = chunk_blends( let (chunks, needs_depth) = chunk_blends(
&commands.0, commands.0,
descriptors, descriptors,
uniform_buffers, uniform_buffers,
uniform_encoder, uniform_encoder,
@ -734,7 +734,7 @@ pub enum DrawCommand {
/// Every complex blend will be its own item, but every other draw will be chunked together /// Every complex blend will be its own item, but every other draw will be chunked together
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn chunk_blends<'a>( fn chunk_blends<'a>(
commands: &[Command], commands: Vec<Command>,
descriptors: &'a Descriptors, descriptors: &'a Descriptors,
uniform_buffers: &mut UniformBuffer<'a, Transforms>, uniform_buffers: &mut UniformBuffer<'a, Transforms>,
uniform_encoder: &mut wgpu::CommandEncoder, uniform_encoder: &mut wgpu::CommandEncoder,
@ -761,14 +761,14 @@ fn chunk_blends<'a>(
wgpu::TextureFormat::Rgba8Unorm, wgpu::TextureFormat::Rgba8Unorm,
); );
let target = surface.draw_commands( let target = surface.draw_commands(
Some(BlendType::from(*blend_mode).default_color()), Some(BlendType::from(blend_mode).default_color()),
&descriptors, &descriptors,
&meshes, &meshes,
commands, commands,
uniform_buffers, uniform_buffers,
uniform_encoder, uniform_encoder,
draw_encoder, draw_encoder,
if blend_mode == &BlendMode::Layer { if blend_mode == BlendMode::Layer {
None None
} else { } else {
Some(nearest_layer) Some(nearest_layer)
@ -776,7 +776,7 @@ fn chunk_blends<'a>(
texture_pool, texture_pool,
); );
match BlendType::from(*blend_mode) { match BlendType::from(blend_mode) {
BlendType::Trivial(blend_mode) => { BlendType::Trivial(blend_mode) => {
let transform = Transform { let transform = Transform {
matrix: Matrix::scale(target.width() as f32, target.height() as f32), matrix: Matrix::scale(target.width() as f32, target.height() as f32),
@ -811,19 +811,17 @@ fn chunk_blends<'a>(
transform, transform,
smoothing, smoothing,
} => current.push(DrawCommand::RenderBitmap { } => current.push(DrawCommand::RenderBitmap {
bitmap: bitmap.to_owned(), bitmap,
transform: transform.to_owned(), transform,
smoothing: *smoothing, smoothing,
blend_mode: TrivialBlend::Normal, blend_mode: TrivialBlend::Normal,
}), }),
Command::RenderShape { shape, transform } => current.push(DrawCommand::RenderShape { Command::RenderShape { shape, transform } => {
shape: shape.to_owned(), current.push(DrawCommand::RenderShape { shape, transform })
transform: transform.to_owned(), }
}), Command::DrawRect { color, matrix } => {
Command::DrawRect { color, matrix } => current.push(DrawCommand::DrawRect { current.push(DrawCommand::DrawRect { color, matrix })
color: color.to_owned(), }
matrix: matrix.to_owned(),
}),
Command::PushMask => { Command::PushMask => {
needs_depth = true; needs_depth = true;
current.push(DrawCommand::PushMask); current.push(DrawCommand::PushMask);

View File

@ -213,7 +213,7 @@ impl Surface {
clear_color, clear_color,
descriptors, descriptors,
meshes, meshes,
&commands, commands,
&mut uniform_buffer, &mut uniform_buffer,
&mut uniform_encoder, &mut uniform_encoder,
&mut draw_encoder, &mut draw_encoder,
@ -306,7 +306,7 @@ impl Surface {
mut clear_color: Option<wgpu::Color>, mut clear_color: Option<wgpu::Color>,
descriptors: &'global Descriptors, descriptors: &'global Descriptors,
meshes: &'global Vec<Mesh>, meshes: &'global Vec<Mesh>,
commands: &CommandList, commands: CommandList,
uniform_buffers: &'frame mut UniformBuffer<'global, Transforms>, uniform_buffers: &'frame mut UniformBuffer<'global, Transforms>,
uniform_encoder: &'frame mut wgpu::CommandEncoder, uniform_encoder: &'frame mut wgpu::CommandEncoder,
draw_encoder: &'frame mut wgpu::CommandEncoder, draw_encoder: &'frame mut wgpu::CommandEncoder,