mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
metal: Don't try to create a zero-byte vertex buffer.
(Which will cause a crash in Metal, or an assert in the validation layer.)
This commit is contained in:
parent
1ecf4dfc5f
commit
638d624f5a
@ -1052,6 +1052,7 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||||||
{ @autoreleasepool {
|
{ @autoreleasepool {
|
||||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||||
METAL_DrawStateCache statecache;
|
METAL_DrawStateCache statecache;
|
||||||
|
id<MTLBuffer> mtlbufvertex = nil;
|
||||||
|
|
||||||
statecache.pipeline = nil;
|
statecache.pipeline = nil;
|
||||||
statecache.constants_offset = CONSTANTS_OFFSET_INVALID;
|
statecache.constants_offset = CONSTANTS_OFFSET_INVALID;
|
||||||
@ -1063,24 +1064,26 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||||||
statecache.color_offset = 0;
|
statecache.color_offset = 0;
|
||||||
|
|
||||||
// !!! FIXME: have a ring of pre-made MTLBuffers we cycle through? How expensive is creation?
|
// !!! FIXME: have a ring of pre-made MTLBuffers we cycle through? How expensive is creation?
|
||||||
id<MTLBuffer> mtlbufvertexstaging = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared];
|
if (vertsize > 0) {
|
||||||
#if !__has_feature(objc_arc)
|
id<MTLBuffer> mtlbufvertexstaging = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModeShared];
|
||||||
[mtlbufvertexstaging autorelease];
|
#if !__has_feature(objc_arc)
|
||||||
#endif
|
[mtlbufvertexstaging autorelease];
|
||||||
mtlbufvertexstaging.label = @"SDL vertex staging data";
|
#endif
|
||||||
SDL_memcpy([mtlbufvertexstaging contents], vertices, vertsize);
|
mtlbufvertexstaging.label = @"SDL vertex staging data";
|
||||||
|
SDL_memcpy([mtlbufvertexstaging contents], vertices, vertsize);
|
||||||
|
|
||||||
// Move our new vertex buffer from system RAM to GPU memory so any draw calls can use it.
|
// Move our new vertex buffer from system RAM to GPU memory so any draw calls can use it.
|
||||||
id<MTLBuffer> mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModePrivate];
|
mtlbufvertex = [data.mtldevice newBufferWithLength:vertsize options:MTLResourceStorageModePrivate];
|
||||||
#if !__has_feature(objc_arc)
|
#if !__has_feature(objc_arc)
|
||||||
[mtlbufvertex autorelease];
|
[mtlbufvertex autorelease];
|
||||||
#endif
|
#endif
|
||||||
mtlbufvertex.label = @"SDL vertex data";
|
mtlbufvertex.label = @"SDL vertex data";
|
||||||
id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
|
id<MTLCommandBuffer> cmdbuffer = [data.mtlcmdqueue commandBuffer];
|
||||||
id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
|
id<MTLBlitCommandEncoder> blitcmd = [cmdbuffer blitCommandEncoder];
|
||||||
[blitcmd copyFromBuffer:mtlbufvertexstaging sourceOffset:0 toBuffer:mtlbufvertex destinationOffset:0 size:vertsize];
|
[blitcmd copyFromBuffer:mtlbufvertexstaging sourceOffset:0 toBuffer:mtlbufvertex destinationOffset:0 size:vertsize];
|
||||||
[blitcmd endEncoding];
|
[blitcmd endEncoding];
|
||||||
[cmdbuffer commit];
|
[cmdbuffer commit];
|
||||||
|
}
|
||||||
|
|
||||||
// If there's a command buffer here unexpectedly (app requested one?). Commit it so we can start fresh.
|
// If there's a command buffer here unexpectedly (app requested one?). Commit it so we can start fresh.
|
||||||
[data.mtlcmdencoder endEncoding];
|
[data.mtlcmdencoder endEncoding];
|
||||||
|
Loading…
Reference in New Issue
Block a user