From d6b8b934b59e1d37b23cd6a5a1f406a6ce5947cb Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 27 Jun 2018 18:54:59 -0400 Subject: [PATCH] [mtl] avoid heap allocation and an extra autorelease pool at begin_render_pass --- src/backend/metal/src/command.rs | 12 +++++++++--- src/backend/metal/src/device.rs | 3 ++- src/backend/metal/src/native.rs | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/backend/metal/src/command.rs b/src/backend/metal/src/command.rs index 8188a05d7c0..358c7a238a7 100644 --- a/src/backend/metal/src/command.rs +++ b/src/backend/metal/src/command.rs @@ -821,11 +821,11 @@ impl CommandSink { ) where I: Iterator>, { + //assert!(AutoReleasePool::is_active()); self.stop_encoding(); match *self { CommandSink::Immediate { ref cmd_buffer, ref mut encoder_state, .. } => { - let _ap = AutoreleasePool::new(); let encoder = cmd_buffer.new_render_command_encoder(descriptor); for command in init_commands { exec_render(encoder, command); @@ -1446,7 +1446,7 @@ impl pool::RawCommandPool for CommandPool { framebuffer_inner: native::FramebufferInner { extent: Extent::default(), aspects: Aspects::empty(), - colors: Vec::new(), + colors: SmallVec::new(), depth_stencil: None, } }, @@ -1653,6 +1653,8 @@ impl com::RawCommandBuffer for CommandBuffer { T: IntoIterator, T::Item: Borrow, { + let _ap = AutoreleasePool::new(); + let CommandBufferInner { ref mut retained_textures, ref mut sink, @@ -2017,6 +2019,8 @@ impl com::RawCommandBuffer for CommandBuffer { T: IntoIterator, T::Item: Borrow { + let _ap = AutoreleasePool::new(); + let vertices = &mut self.temp.blit_vertices; vertices.clear(); @@ -2220,7 +2224,9 @@ impl com::RawCommandBuffer for CommandBuffer { .chain(&extra) .cloned(); - inner.sink().begin_render_pass(false, &descriptor, commands); + inner + .sink() + .begin_render_pass(false, &descriptor, commands); } } diff --git a/src/backend/metal/src/device.rs b/src/backend/metal/src/device.rs index a8db0c2e9fb..48f69ebe41b 100644 --- a/src/backend/metal/src/device.rs +++ b/src/backend/metal/src/device.rs @@ -27,6 +27,7 @@ use metal::{self, MTLVertexStepFunction, MTLSamplerBorderColor, MTLSamplerMipFilter, MTLTextureType, CaptureManager }; +use smallvec::SmallVec; use spirv_cross::{msl, spirv, ErrorCode as SpirvErrorCode}; use foreign_types::ForeignType; @@ -1124,7 +1125,7 @@ impl hal::Device for Device { let mut inner = n::FramebufferInner { extent, aspects: format::Aspects::empty(), - colors: Vec::new(), + colors: SmallVec::new(), depth_stencil: None, }; diff --git a/src/backend/metal/src/native.rs b/src/backend/metal/src/native.rs index e7313cc02ae..948edd42633 100644 --- a/src/backend/metal/src/native.rs +++ b/src/backend/metal/src/native.rs @@ -13,6 +13,7 @@ use hal::format::{Aspects, Format, FormatDesc}; use cocoa::foundation::{NSUInteger}; use metal; +use smallvec::SmallVec; use spirv_cross::{msl, spirv}; use foreign_types::ForeignType; @@ -51,7 +52,7 @@ pub struct ColorAttachment { pub struct FramebufferInner { pub extent: image::Extent, pub aspects: Aspects, - pub colors: Vec, + pub colors: SmallVec<[ColorAttachment; 4]>, pub depth_stencil: Option, }