src/render/metal/SDL_render_metal.m
changeset 12394 80f861112154
parent 12393 c7b7abeab424
child 12427 7508e848e7cf
equal deleted inserted replaced
12393:c7b7abeab424 12394:80f861112154
  1194                     Uint32 pixel_format, void * pixels, int pitch)
  1194                     Uint32 pixel_format, void * pixels, int pitch)
  1195 { @autoreleasepool {
  1195 { @autoreleasepool {
  1196     METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
  1196     METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
  1197     METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL);
  1197     METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL);
  1198 
  1198 
  1199     // Commit any current command buffer, and waitUntilCompleted, so any output is ready to be read.
       
  1200     [data.mtlcmdencoder endEncoding];
  1199     [data.mtlcmdencoder endEncoding];
       
  1200     id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
       
  1201 
       
  1202 #ifdef __MACOSX__
       
  1203     /* on macOS with managed-storage textures, we need to tell the driver to
       
  1204      * update the CPU-side copy of the texture data.
       
  1205      * NOTE: Currently all of our textures are managed on macOS. We'll need some
       
  1206      * extra copying for any private textures. */
       
  1207     if (mtltexture.storageMode == MTLStorageModeManaged) {
       
  1208         id<MTLBlitCommandEncoder> blit = [data.mtlcmdbuffer blitCommandEncoder];
       
  1209         [blit synchronizeResource:mtltexture];
       
  1210         [blit endEncoding];
       
  1211     }
       
  1212 #endif
       
  1213 
       
  1214     /* Commit the current command buffer and wait until it's completed, to make
       
  1215      * sure the GPU has finished rendering to it by the time we read it. */
  1201     [data.mtlcmdbuffer commit];
  1216     [data.mtlcmdbuffer commit];
  1202     [data.mtlcmdbuffer waitUntilCompleted];
  1217     [data.mtlcmdbuffer waitUntilCompleted];
  1203     data.mtlcmdencoder = nil;
  1218     data.mtlcmdencoder = nil;
  1204     data.mtlcmdbuffer = nil;
  1219     data.mtlcmdbuffer = nil;
  1205 
  1220 
  1206     id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
       
  1207     MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h);
  1221     MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h);
  1208 
  1222 
  1209     // we only do BGRA8 or RGBA8 at the moment, so 4 will do.
  1223     // we only do BGRA8 or RGBA8 at the moment, so 4 will do.
  1210     const int temp_pitch = rect->w * 4;
  1224     const int temp_pitch = rect->w * 4;
  1211     void *temp_pixels = SDL_malloc(temp_pitch * rect->h);
  1225     void *temp_pixels = SDL_malloc(temp_pitch * rect->h);