[Commits] SDL: metal: use a private instead of managed buffer for the rend...

libsdl.org revision control commits-owner at libsdl.org
Thu Jan 4 18:17:02 PST 2018


details:   https://hg.libsdl.org/SDL/rev/4f3cdd0a5768
changeset: 11818:4f3cdd0a5768
user:      Alex Szpakowski <slime73 at gmail.com>
date:      Thu Jan 04 22:16:42 2018 -0400
description:
metal: use a private instead of managed buffer for the renderer's non-changing constant data.

Recommended by Xcode's Metal frame capture analysis.

diffstat:

 src/render/metal/SDL_render_metal.m |  21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diffs (38 lines):

diff -r 5724c41db8fd -r 4f3cdd0a5768 src/render/metal/SDL_render_metal.m
--- a/src/render/metal/SDL_render_metal.m	Thu Jan 04 19:29:33 2018 -0400
+++ b/src/render/metal/SDL_render_metal.m	Thu Jan 04 22:16:42 2018 -0400
@@ -487,22 +487,25 @@
 
     float clearverts[6] = {0.0f, 0.0f,  0.0f, 2.0f,  2.0f, 0.0f};
 
-    MTLResourceOptions constantsopts = 0;
-#ifdef __MACOSX__
-    constantsopts |= MTLResourceStorageModeManaged;
-#endif
+    id<MTLBuffer> mtlbufconstantstaging = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModeShared];
+    mtlbufconstantstaging.label = @"SDL constant staging data";
 
-    id<MTLBuffer> mtlbufconstants = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:constantsopts];
+    id<MTLBuffer> mtlbufconstants = [data.mtldevice newBufferWithLength:CONSTANTS_LENGTH options:MTLResourceStorageModePrivate];
     data.mtlbufconstants = mtlbufconstants;
     data.mtlbufconstants.label = @"SDL constant data";
 
-    char *constantdata = [data.mtlbufconstants contents];
+    char *constantdata = [mtlbufconstantstaging contents];
     SDL_memcpy(constantdata + CONSTANTS_OFFSET_IDENTITY, identitytransform, sizeof(identitytransform));
     SDL_memcpy(constantdata + CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, halfpixeltransform, sizeof(halfpixeltransform));
     SDL_memcpy(constantdata + CONSTANTS_OFFSET_CLEAR_VERTS, clearverts, sizeof(clearverts));
-#ifdef __MACOSX__
-    [data.mtlbufconstants didModifyRange:NSMakeRange(0, CONSTANTS_LENGTH)];
-#endif
+
+    id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
+    id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
+
+    [blitcmd copyFromBuffer:mtlbufconstantstaging sourceOffset:0 toBuffer:data.mtlbufconstants destinationOffset:0 size:CONSTANTS_LENGTH];
+
+    [blitcmd endEncoding];
+    [cmdbuffer commit];
 
     // !!! FIXME: force more clears here so all the drawables are sane to start, and our static buffers are definitely flushed.
 


More information about the commits mailing list