implement more primitive types & warn about vertex stride

This commit is contained in:
Samuliak 2024-08-06 16:29:06 +02:00
parent 5fc45407db
commit 99ff282720
3 changed files with 38 additions and 15 deletions

View File

@ -1,6 +1,7 @@
#include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h" #include "Cafe/HW/Latte/Renderer/Metal/LatteToMtl.h"
#include "Common/precompiled.h" #include "Common/precompiled.h"
#include "Metal/MTLDepthStencil.hpp" #include "Metal/MTLDepthStencil.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "Metal/MTLSampler.hpp" #include "Metal/MTLSampler.hpp"
std::map<Latte::E_GX2SURFFMT, MtlPixelFormatInfo> MTL_COLOR_FORMAT_TABLE = { std::map<Latte::E_GX2SURFFMT, MtlPixelFormatInfo> MTL_COLOR_FORMAT_TABLE = {
@ -247,21 +248,37 @@ TextureDecoder* GetMtlTextureDecoder(Latte::E_GX2SURFFMT format, bool isDepth)
} }
} }
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode) MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode primitiveMode)
{ {
switch (mode) switch (primitiveMode)
{ {
case LattePrimitiveMode::POINTS: case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::POINTS:
return MTL::PrimitiveTypePoint; return MTL::PrimitiveTypePoint;
case LattePrimitiveMode::LINES: case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINES:
return MTL::PrimitiveTypeLine; return MTL::PrimitiveTypeLine;
case LattePrimitiveMode::TRIANGLES: case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_STRIP:
return MTL::PrimitiveTypeLineStrip;
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_LOOP:
return MTL::PrimitiveTypeLineStrip; // line loops are emulated as line strips with an extra connecting strip at the end
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::LINE_STRIP_ADJACENT: // Tropical Freeze level 3-6
debug_printf("Metal doesn't support line strip adjacent primitive, using line strip instead\n");
return MTL::PrimitiveTypeLineStrip;
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLES:
return MTL::PrimitiveTypeTriangle; return MTL::PrimitiveTypeTriangle;
case LattePrimitiveMode::TRIANGLE_STRIP: case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLE_FAN:
debug_printf("Metal doesn't support triangle fan primitive, using triangle strip instead\n");
return MTL::PrimitiveTypeTriangleStrip; return MTL::PrimitiveTypeTriangleStrip;
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::TRIANGLE_STRIP:
return MTL::PrimitiveTypeTriangleStrip;
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::QUADS:
return MTL::PrimitiveTypeTriangle; // quads are emulated as 2 triangles
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::QUAD_STRIP:
return MTL::PrimitiveTypeTriangle; // quad strips are emulated as (count-2)/2 triangles
case Latte::LATTE_VGT_PRIMITIVE_TYPE::E_PRIMITIVE_TYPE::RECTS:
return MTL::PrimitiveTypeTriangle; // rects are emulated as 2 triangles
default: default:
// TODO: uncomment cemuLog_logDebug(LogType::Force, "Metal-Unsupported: Render pipeline with primitive mode {} created", primitiveMode);
//printf("unimplemented primitive type %u\n", (uint32)mode); cemu_assert_debug(false);
return MTL::PrimitiveTypeTriangle; return MTL::PrimitiveTypeTriangle;
} }
} }

View File

@ -29,7 +29,7 @@ size_t GetMtlTextureBytesPerImage(Latte::E_GX2SURFFMT format, bool isDepth, uint
TextureDecoder* GetMtlTextureDecoder(Latte::E_GX2SURFFMT format, bool isDepth); TextureDecoder* GetMtlTextureDecoder(Latte::E_GX2SURFFMT format, bool isDepth);
MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode mode); MTL::PrimitiveType GetMtlPrimitiveType(LattePrimitiveMode primitiveMode);
MTL::VertexFormat GetMtlVertexFormat(uint8 format); MTL::VertexFormat GetMtlVertexFormat(uint8 format);

View File

@ -60,6 +60,12 @@ MTL::RenderPipelineState* MetalPipelineCache::GetPipelineState(const LatteFetchS
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7; uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7;
uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF; uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
uint32 strideRemainder = bufferStride % 4;
if (strideRemainder != 0)
{
debug_printf("vertex stride must be a multiple of 4, remainder: %u\n", strideRemainder);
}
auto layout = vertexDescriptor->layouts()->object(GET_MTL_VERTEX_BUFFER_INDEX(bufferIndex)); auto layout = vertexDescriptor->layouts()->object(GET_MTL_VERTEX_BUFFER_INDEX(bufferIndex));
layout->setStride(bufferStride); layout->setStride(bufferStride);
if (!fetchType.has_value() || fetchType == LatteConst::VertexFetchType2::VERTEX_DATA) if (!fetchType.has_value() || fetchType == LatteConst::VertexFetchType2::VERTEX_DATA)