Browse Source

metal: synchronize textures with READ flag (#870)

* metal: synchronize textures with READ flag

* Only necessary for desktop
Stuart Carnie 9 years ago
parent
commit
6cff1b2fb7
2 changed files with 17 additions and 0 deletions
  1. 10 0
      src/renderer_mtl.h
  2. 7 0
      src/renderer_mtl.mm

+ 10 - 0
src/renderer_mtl.h

@@ -87,6 +87,16 @@ namespace bgfx { namespace mtl
 				 destinationSlice:_destinationSlice destinationLevel:_destinationLevel destinationOrigin:_destinationOrigin];
 		}
 
+		void synchronizeTexture(id<MTLTexture> _texture, NSUInteger _slice, NSUInteger _level)
+		{
+			[m_obj synchronizeTexture:_texture slice:_slice level:_level];
+		}
+
+		void synchronizeResource(id<MTLResource> _resource)
+		{
+			[m_obj synchronizeResource:_resource];
+		}
+
 		void endEncoding()
 		{
 			[m_obj endEncoding];

+ 7 - 0
src/renderer_mtl.mm

@@ -3023,16 +3023,23 @@ namespace bgfx { namespace mtl
 						uint32_t width     = bx::uint32_min(srcWidth,  dstWidth);
 						uint32_t height    = bx::uint32_min(srcHeight, dstHeight);
 						uint32_t depth     = bx::uint32_min(srcDepth,  dstDepth);
+						bool     readBack  = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK);
 
 						if ( MTLTextureType3D == src.m_ptr.textureType())
 						{
 							m_blitCommandEncoder.copyFromTexture(src.m_ptr, 0, 0, MTLOriginMake(blit.m_srcX, blit.m_srcY, blit.m_srcZ), MTLSizeMake(width, height, bx::uint32_imax(depth, 1)),
 																 dst.m_ptr, 0, 0, MTLOriginMake(blit.m_dstX, blit.m_dstY, blit.m_dstZ));
+							if (m_macOS11Runtime &&readBack) {
+								m_blitCommandEncoder.synchronizeResource(dst.m_ptr);
+							}
 						}
 						else
 						{
 							m_blitCommandEncoder.copyFromTexture(src.m_ptr, blit.m_srcZ, blit.m_srcMip, MTLOriginMake(blit.m_srcX, blit.m_srcY, 0), MTLSizeMake(width, height, 1),
 																 dst.m_ptr, blit.m_dstZ, blit.m_dstMip, MTLOriginMake(blit.m_dstX, blit.m_dstY, 0));
+							if (m_macOS11Runtime && readBack) {
+								m_blitCommandEncoder.synchronizeTexture(dst.m_ptr, 0, blit.m_dstMip);
+							}
 						}
 					}