Skip to content

Commit

Permalink
[mtl] avoid heap allocation and an extra autorelease pool at begin_re…
Browse files Browse the repository at this point in the history
…nder_pass
  • Loading branch information
kvark committed Jun 28, 2018
1 parent a275491 commit d6b8b93
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/backend/metal/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ impl CommandSink {
) where
I: Iterator<Item = soft::RenderCommand<&'a soft::Own>>,
{
//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);
Expand Down Expand Up @@ -1446,7 +1446,7 @@ impl pool::RawCommandPool<Backend> for CommandPool {
framebuffer_inner: native::FramebufferInner {
extent: Extent::default(),
aspects: Aspects::empty(),
colors: Vec::new(),
colors: SmallVec::new(),
depth_stencil: None,
}
},
Expand Down Expand Up @@ -1653,6 +1653,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
T: IntoIterator,
T::Item: Borrow<SubresourceRange>,
{
let _ap = AutoreleasePool::new();

let CommandBufferInner {
ref mut retained_textures,
ref mut sink,
Expand Down Expand Up @@ -2017,6 +2019,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
T: IntoIterator,
T::Item: Borrow<com::ImageBlit>
{
let _ap = AutoreleasePool::new();

let vertices = &mut self.temp.blit_vertices;
vertices.clear();

Expand Down Expand Up @@ -2220,7 +2224,9 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
.chain(&extra)
.cloned();

inner.sink().begin_render_pass(false, &descriptor, commands);
inner
.sink()
.begin_render_pass(false, &descriptor, commands);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/backend/metal/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1124,7 +1125,7 @@ impl hal::Device<Backend> for Device {
let mut inner = n::FramebufferInner {
extent,
aspects: format::Aspects::empty(),
colors: Vec::new(),
colors: SmallVec::new(),
depth_stencil: None,
};

Expand Down
3 changes: 2 additions & 1 deletion src/backend/metal/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,7 +52,7 @@ pub struct ColorAttachment {
pub struct FramebufferInner {
pub extent: image::Extent,
pub aspects: Aspects,
pub colors: Vec<ColorAttachment>,
pub colors: SmallVec<[ColorAttachment; 4]>,
pub depth_stencil: Option<metal::MTLPixelFormat>,
}

Expand Down

0 comments on commit d6b8b93

Please sign in to comment.