Skip to content

Commit 99ff282

Browse files
committed
implement more primitive types & warn about vertex stride
1 parent 5fc4540 commit 99ff282

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

src/Cafe/HW/Latte/Renderer/Metal/LatteToMtl.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
22
#include "Common/precompiled.h"
33
#include "Metal/MTLDepthStencil.hpp"
4+
#include "Metal/MTLRenderCommandEncoder.hpp"
45
#include "Metal/MTLSampler.hpp"
56

67
std::map<Latte::E_GX2SURFFMT, MtlPixelFormatInfo> MTL_COLOR_FORMAT_TABLE = {
@@ -247,22 +248,38 @@ TextureDecoder* GetMtlTextureDecoder(Latte::E_GX2SURFFMT format, bool isDepth)
247248
}
248249
}
249250

250-
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode)
251+
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode primitiveMode)
251252
{
252-
switch (mode)
253+
switch (primitiveMode)
253254
{
254-
case LattePrimitiveMode::POINTS:
255-
return MTL::PrimitiveTypePoint;
256-
case LattePrimitiveMode::LINES:
257-
return MTL::PrimitiveTypeLine;
258-
case LattePrimitiveMode::TRIANGLES:
259-
return MTL::PrimitiveTypeTriangle;
260-
case LattePrimitiveMode::TRIANGLE_STRIP:
261-
return MTL::PrimitiveTypeTriangleStrip;
262-
default:
263-
// TODO: uncomment
264-
//printf("unimplemented primitive type %u\n", (uint32)mode);
265-
return MTL::PrimitiveTypeTriangle;
255+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::POINTS:
256+
return MTL::PrimitiveTypePoint;
257+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINES:
258+
return MTL::PrimitiveTypeLine;
259+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_STRIP:
260+
return MTL::PrimitiveTypeLineStrip;
261+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_LOOP:
262+
return MTL::PrimitiveTypeLineStrip; // line loops are emulated as line strips with an extra connecting strip at the end
263+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_STRIP_ADJACENT: // Tropical Freeze level 3-6
264+
debug_printf("Metal doesn't support line strip adjacent primitive, using line strip instead\n");
265+
return MTL::PrimitiveTypeLineStrip;
266+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLES:
267+
return MTL::PrimitiveTypeTriangle;
268+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLE_FAN:
269+
debug_printf("Metal doesn't support triangle fan primitive, using triangle strip instead\n");
270+
return MTL::PrimitiveTypeTriangleStrip;
271+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLE_STRIP:
272+
return MTL::PrimitiveTypeTriangleStrip;
273+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::QUADS:
274+
return MTL::PrimitiveTypeTriangle; // quads are emulated as 2 triangles
275+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::QUAD_STRIP:
276+
return MTL::PrimitiveTypeTriangle; // quad strips are emulated as (count-2)/2 triangles
277+
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::RECTS:
278+
return MTL::PrimitiveTypeTriangle; // rects are emulated as 2 triangles
279+
default:
280+
cemuLog_logDebug(LogType::Force, "Metal-Unsupported: Render pipeline with primitive mode {} created", primitiveMode);
281+
cemu_assert_debug(false);
282+
return MTL::PrimitiveTypeTriangle;
266283
}
267284
}
268285

src/Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ size_t GetMtlTextureBytesPerImage(Latte::E_GX2SURFFMT format, bool isDepth, uint
2929

3030
TextureDecoder* GetMtlTextureDecoder(Latte::E_GX2SURFFMT format, bool isDepth);
3131

32-
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode);
32+
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode primitiveMode);
3333

3434
MTL::VertexFormat GetMtlVertexFormat(uint8 format);
3535

src/Cafe/HW/Latte/Renderer/Metal/MetalPipelineCache.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ MTL::RenderPipelineState* MetalPipelineCache::GetPipelineState(const LatteFetchS
6060
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
6161
uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
6262

63+
uint32 strideRemainder = bufferStride % 4;
64+
if (strideRemainder != 0)
65+
{
66+
debug_printf("vertex stride must be a multiple of 4, remainder: %u\n", strideRemainder);
67+
}
68+
6369
auto layout = vertexDescriptor->layouts()->object(GET_MTL_VERTEX_BUFFER_INDEX(bufferIndex));
6470
layout->setStride(bufferStride);
6571
if (!fetchType.has_value() || fetchType == LatteConst::VertexFetchType2::VERTEX_DATA)

0 commit comments

Comments
 (0)