Skip to content

Commit d6b8b93

Browse files
committed
[mtl] avoid heap allocation and an extra autorelease pool at begin_render_pass
1 parent a275491 commit d6b8b93

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/backend/metal/src/command.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,11 @@ impl CommandSink {
821821
) where
822822
I: Iterator<Item = soft::RenderCommand<&'a soft::Own>>,
823823
{
824+
//assert!(AutoReleasePool::is_active());
824825
self.stop_encoding();
825826

826827
match *self {
827828
CommandSink::Immediate { ref cmd_buffer, ref mut encoder_state, .. } => {
828-
let _ap = AutoreleasePool::new();
829829
let encoder = cmd_buffer.new_render_command_encoder(descriptor);
830830
for command in init_commands {
831831
exec_render(encoder, command);
@@ -1446,7 +1446,7 @@ impl pool::RawCommandPool<Backend> for CommandPool {
14461446
framebuffer_inner: native::FramebufferInner {
14471447
extent: Extent::default(),
14481448
aspects: Aspects::empty(),
1449-
colors: Vec::new(),
1449+
colors: SmallVec::new(),
14501450
depth_stencil: None,
14511451
}
14521452
},
@@ -1653,6 +1653,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
16531653
T: IntoIterator,
16541654
T::Item: Borrow<SubresourceRange>,
16551655
{
1656+
let _ap = AutoreleasePool::new();
1657+
16561658
let CommandBufferInner {
16571659
ref mut retained_textures,
16581660
ref mut sink,
@@ -2017,6 +2019,8 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
20172019
T: IntoIterator,
20182020
T::Item: Borrow<com::ImageBlit>
20192021
{
2022+
let _ap = AutoreleasePool::new();
2023+
20202024
let vertices = &mut self.temp.blit_vertices;
20212025
vertices.clear();
20222026

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

2223-
inner.sink().begin_render_pass(false, &descriptor, commands);
2227+
inner
2228+
.sink()
2229+
.begin_render_pass(false, &descriptor, commands);
22242230
}
22252231
}
22262232

src/backend/metal/src/device.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use metal::{self,
2727
MTLVertexStepFunction, MTLSamplerBorderColor, MTLSamplerMipFilter, MTLTextureType,
2828
CaptureManager
2929
};
30+
use smallvec::SmallVec;
3031
use spirv_cross::{msl, spirv, ErrorCode as SpirvErrorCode};
3132
use foreign_types::ForeignType;
3233

@@ -1124,7 +1125,7 @@ impl hal::Device<Backend> for Device {
11241125
let mut inner = n::FramebufferInner {
11251126
extent,
11261127
aspects: format::Aspects::empty(),
1127-
colors: Vec::new(),
1128+
colors: SmallVec::new(),
11281129
depth_stencil: None,
11291130
};
11301131

src/backend/metal/src/native.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use hal::format::{Aspects, Format, FormatDesc};
1313

1414
use cocoa::foundation::{NSUInteger};
1515
use metal;
16+
use smallvec::SmallVec;
1617
use spirv_cross::{msl, spirv};
1718
use foreign_types::ForeignType;
1819

@@ -51,7 +52,7 @@ pub struct ColorAttachment {
5152
pub struct FramebufferInner {
5253
pub extent: image::Extent,
5354
pub aspects: Aspects,
54-
pub colors: Vec<ColorAttachment>,
55+
pub colors: SmallVec<[ColorAttachment; 4]>,
5556
pub depth_stencil: Option<metal::MTLPixelFormat>,
5657
}
5758

0 commit comments

Comments
 (0)