1.1 --- a/src/render/metal/SDL_render_metal.m Sun Nov 04 12:31:02 2018 -0400
1.2 +++ b/src/render/metal/SDL_render_metal.m Sun Nov 04 14:31:56 2018 -0400
1.3 @@ -1196,14 +1196,28 @@
1.4 METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
1.5 METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL);
1.6
1.7 - // Commit any current command buffer, and waitUntilCompleted, so any output is ready to be read.
1.8 [data.mtlcmdencoder endEncoding];
1.9 + id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
1.10 +
1.11 +#ifdef __MACOSX__
1.12 + /* on macOS with managed-storage textures, we need to tell the driver to
1.13 + * update the CPU-side copy of the texture data.
1.14 + * NOTE: Currently all of our textures are managed on macOS. We'll need some
1.15 + * extra copying for any private textures. */
1.16 + if (mtltexture.storageMode == MTLStorageModeManaged) {
1.17 + id<MTLBlitCommandEncoder> blit = [data.mtlcmdbuffer blitCommandEncoder];
1.18 + [blit synchronizeResource:mtltexture];
1.19 + [blit endEncoding];
1.20 + }
1.21 +#endif
1.22 +
1.23 + /* Commit the current command buffer and wait until it's completed, to make
1.24 + * sure the GPU has finished rendering to it by the time we read it. */
1.25 [data.mtlcmdbuffer commit];
1.26 [data.mtlcmdbuffer waitUntilCompleted];
1.27 data.mtlcmdencoder = nil;
1.28 data.mtlcmdbuffer = nil;
1.29
1.30 - id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
1.31 MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h);
1.32
1.33 // we only do BGRA8 or RGBA8 at the moment, so 4 will do.