src/render/metal/SDL_render_metal.m
changeset 12384 b1f5162fd621
parent 12382 03d0bddca61b
child 12385 45038f8422c9
equal deleted inserted replaced
12383:f6430feceeda 12384:b1f5162fd621
    59 static const size_t CONSTANTS_OFFSET_IDENTITY = 0;
    59 static const size_t CONSTANTS_OFFSET_IDENTITY = 0;
    60 static const size_t CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM = ALIGN_CONSTANTS(CONSTANTS_OFFSET_IDENTITY + sizeof(float) * 16);
    60 static const size_t CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM = ALIGN_CONSTANTS(CONSTANTS_OFFSET_IDENTITY + sizeof(float) * 16);
    61 static const size_t CONSTANTS_OFFSET_DECODE_JPEG = ALIGN_CONSTANTS(CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM + sizeof(float) * 16);
    61 static const size_t CONSTANTS_OFFSET_DECODE_JPEG = ALIGN_CONSTANTS(CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM + sizeof(float) * 16);
    62 static const size_t CONSTANTS_OFFSET_DECODE_BT601 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_JPEG + sizeof(float) * 4 * 4);
    62 static const size_t CONSTANTS_OFFSET_DECODE_BT601 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_JPEG + sizeof(float) * 4 * 4);
    63 static const size_t CONSTANTS_OFFSET_DECODE_BT709 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT601 + sizeof(float) * 4 * 4);
    63 static const size_t CONSTANTS_OFFSET_DECODE_BT709 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT601 + sizeof(float) * 4 * 4);
    64 static const size_t CONSTANTS_OFFSET_CLEAR_VERTS = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT709 + sizeof(float) * 4 * 4);
    64 static const size_t CONSTANTS_LENGTH = CONSTANTS_OFFSET_DECODE_BT709 + sizeof(float) * 6;
    65 static const size_t CONSTANTS_LENGTH = CONSTANTS_OFFSET_CLEAR_VERTS + sizeof(float) * 6;
       
    66 
    65 
    67 typedef enum SDL_MetalVertexFunction
    66 typedef enum SDL_MetalVertexFunction
    68 {
    67 {
    69     SDL_METAL_VERTEX_SOLID,
    68     SDL_METAL_VERTEX_SOLID,
    70     SDL_METAL_VERTEX_COPY,
    69     SDL_METAL_VERTEX_COPY,
  1410         1.0000,  0.0000,  1.4020, 0.0,        /* Rcoeff */
  1409         1.0000,  0.0000,  1.4020, 0.0,        /* Rcoeff */
  1411         1.0000, -0.3441, -0.7141, 0.0,        /* Gcoeff */
  1410         1.0000, -0.3441, -0.7141, 0.0,        /* Gcoeff */
  1412         1.0000,  1.7720,  0.0000, 0.0,        /* Bcoeff */
  1411         1.0000,  1.7720,  0.0000, 0.0,        /* Bcoeff */
  1413     };
  1412     };
  1414 
  1413 
  1415     float clearverts[6] = {0.0f, 0.0f,  0.0f, 2.0f,  2.0f, 0.0f};
       
  1416 
       
  1417     id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared];
  1414     id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared];
  1418     #if !__has_feature(objc_arc)
  1415     #if !__has_feature(objc_arc)
  1419     [mtlbufconstantstaging autorelease];
  1416     [mtlbufconstantstaging autorelease];
  1420     #endif
  1417     #endif
  1421     mtlbufconstantstaging.label = @"SDL constant staging data";
  1418     mtlbufconstantstaging.label = @"SDL constant staging data";
  1428     SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
  1425     SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
  1429     SDL_memcpy(constantdata + CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, halfpixeltransform, sizeof(halfpixeltransform));
  1426     SDL_memcpy(constantdata + CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, halfpixeltransform, sizeof(halfpixeltransform));
  1430     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_JPEG, decodetransformJPEG, sizeof(decodetransformJPEG));
  1427     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_JPEG, decodetransformJPEG, sizeof(decodetransformJPEG));
  1431     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601, decodetransformBT601, sizeof(decodetransformBT601));
  1428     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT601, decodetransformBT601, sizeof(decodetransformBT601));
  1432     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709, decodetransformBT709, sizeof(decodetransformBT709));
  1429     SDL_memcpy(constantdata + CONSTANTS_OFFSET_DECODE_BT709, decodetransformBT709, sizeof(decodetransformBT709));
  1433     SDL_memcpy(constantdata + CONSTANTS_OFFSET_CLEAR_VERTS, clearverts, sizeof(clearverts));
       
  1434 
  1430 
  1435     id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
  1431     id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
  1436     id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
  1432     id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
  1437 
  1433 
  1438     [blitcmd copyFromBuffer:mtlbufconstantstaging sourceOffset:0 toBuffer:data.mtlbufconstants destinationOffset:0 size:CONSTANTS_LENGTH];
  1434     [blitcmd copyFromBuffer:mtlbufconstantstaging sourceOffset:0 toBuffer:data.mtlbufconstants destinationOffset:0 size:CONSTANTS_LENGTH];