Skip to content

Commit

Permalink
[Metal] Fix missing baseInstance while still supporting older version…
Browse files Browse the repository at this point in the history
…s of Metal (fixes #130).

The baseInstance versions of drawPrimitives and drawIndexedPrimitives in Metal are only supported in iOS 9.0 or later,
while the other versions are supported since iOS 8.0 and later.
If a non-zero value of baseInstance is specified, we have to use those draw functions regardless of the instanceCount value.
  • Loading branch information
LukasBanana committed Aug 16, 2024
1 parent 5887e46 commit 5bb7ffe
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sources/Renderer/Metal/Command/MTCommandExecutor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@
else
{
id<MTLRenderCommandEncoder> renderEncoder = context.FlushAndGetRenderEncoder();
if (cmd->instanceCount != 1)
const bool hasBaseInstance = (cmd->baseInstance != 0);
if (cmd->instanceCount != 1 || hasBaseInstance)
{
if (cmd->baseInstance != 0)
if (hasBaseInstance)
{
/* Suppored since iOS 9.0 */
[renderEncoder
drawPrimitives: context.GetPrimitiveType()
vertexStart: cmd->vertexStart
Expand All @@ -318,6 +320,7 @@
}
else
{
/* Suppored since iOS 8.0 */
[renderEncoder
drawPrimitives: context.GetPrimitiveType()
vertexStart: cmd->vertexStart
Expand All @@ -328,6 +331,7 @@
}
else
{
/* Suppored since iOS 8.0 */
[renderEncoder
drawPrimitives: context.GetPrimitiveType()
vertexStart: cmd->vertexStart
Expand Down Expand Up @@ -362,10 +366,12 @@
else
{
id<MTLRenderCommandEncoder> renderEncoder = context.FlushAndGetRenderEncoder();
if (cmd->instanceCount != 1)
const bool hasBaseVertexOrInstance = (cmd->baseVertex != 0 || cmd->baseInstance != 0);
if (cmd->instanceCount != 1 || hasBaseVertexOrInstance)
{
if (cmd->baseVertex != 0 || cmd->baseInstance != 0)
if (hasBaseVertexOrInstance)
{
/* Suppored since iOS 9.0 */
[renderEncoder
drawIndexedPrimitives: context.GetPrimitiveType()
indexCount: cmd->indexCount
Expand All @@ -379,6 +385,7 @@
}
else
{
/* Suppored since iOS 8.0 */
[renderEncoder
drawIndexedPrimitives: context.GetPrimitiveType()
indexCount: cmd->indexCount
Expand All @@ -391,6 +398,7 @@
}
else
{
/* Suppored since iOS 8.0 */
[renderEncoder
drawIndexedPrimitives: context.GetPrimitiveType()
indexCount: cmd->indexCount
Expand Down

0 comments on commit 5bb7ffe

Please sign in to comment.