bkaradzic/bgfx

Metal creates useless blit encoders after each and every view/renderpass

EvilTrev opened this issue · 1 comments

Describe the bug
During FrameBufferMtl::resolve() a call is made to s_renderMtl->getBlitCommandEncoder() regardless of if the encoder is actually required or not. This creates a lot of extra encoders, complicates gpu captures and issues perf warnings. The simplest fix seems to be to rearrange this code slightly as:

void FrameBufferMtl::resolve()
{
	BlitCommandEncoder bce = nil;
	for (uint32_t ii = 0; ii < m_num; ++ii)
	{
		if (0 != (m_colorAttachment[ii].resolve & BGFX_RESOLVE_AUTO_GEN_MIPS))
		{
			const TextureMtl& texture = s_renderMtl->m_textures[m_colorHandle[ii].idx];
			const bool isRenderTarget = (texture.m_flags & BGFX_TEXTURE_RT_MASK);
			const bool fmtSupport = 0 != (g_caps.formats[texture.m_textureFormat] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN);
			if (isRenderTarget
				&& fmtSupport
				&& texture.m_numMips > 1)
			{
				if ( !bce ) bce = s_renderMtl->getBlitCommandEncoder();
				bce.generateMipmapsForTexture(texture.m_ptr);
			}
		}
	}

	s_renderMtl->endEncoding();
}