From d7e4cf18b56ab4fa2e1cda034268c765fd50442d Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 9 Nov 2024 13:44:41 +0200 Subject: [PATCH] Metal: IWYU fixes --- include/renderer_mtl/mtl_blit_pipeline_cache.hpp | 1 + include/renderer_mtl/mtl_draw_pipeline_cache.hpp | 1 + include/renderer_mtl/mtl_texture.hpp | 1 - include/renderer_mtl/mtl_vertex_buffer_cache.hpp | 15 ++++++++++----- include/renderer_mtl/pica_to_mtl.hpp | 12 +++++------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/renderer_mtl/mtl_blit_pipeline_cache.hpp b/include/renderer_mtl/mtl_blit_pipeline_cache.hpp index 02e075b2..1fa47f42 100644 --- a/include/renderer_mtl/mtl_blit_pipeline_cache.hpp +++ b/include/renderer_mtl/mtl_blit_pipeline_cache.hpp @@ -2,6 +2,7 @@ #include +#include "objc_helper.hpp" #include "pica_to_mtl.hpp" using namespace PICA; diff --git a/include/renderer_mtl/mtl_draw_pipeline_cache.hpp b/include/renderer_mtl/mtl_draw_pipeline_cache.hpp index 47ea5314..7178785e 100644 --- a/include/renderer_mtl/mtl_draw_pipeline_cache.hpp +++ b/include/renderer_mtl/mtl_draw_pipeline_cache.hpp @@ -2,6 +2,7 @@ #include +#include "objc_helper.hpp" #include "pica_to_mtl.hpp" using namespace PICA; diff --git a/include/renderer_mtl/mtl_texture.hpp b/include/renderer_mtl/mtl_texture.hpp index 51cb4c4b..93103091 100644 --- a/include/renderer_mtl/mtl_texture.hpp +++ b/include/renderer_mtl/mtl_texture.hpp @@ -11,7 +11,6 @@ #include "opengl.hpp" #include "renderer_mtl/pica_to_mtl.hpp" - template using Interval = boost::icl::right_open_interval; diff --git a/include/renderer_mtl/mtl_vertex_buffer_cache.hpp b/include/renderer_mtl/mtl_vertex_buffer_cache.hpp index d53af283..b392389c 100644 --- a/include/renderer_mtl/mtl_vertex_buffer_cache.hpp +++ b/include/renderer_mtl/mtl_vertex_buffer_cache.hpp @@ -1,13 +1,17 @@ #pragma once +#include + +#include "helpers.hpp" #include "pica_to_mtl.hpp" + using namespace PICA; namespace Metal { struct BufferHandle { MTL::Buffer* buffer; - size_t offset; + usize offset; }; class VertexBufferCache { @@ -35,7 +39,7 @@ namespace Metal { additionalAllocations.clear(); } - BufferHandle get(const void* data, size_t size) { + BufferHandle get(const void* data, usize size) { // If the vertex buffer is too large, just create a new one if (ptr + size > CACHE_BUFFER_SIZE) { MTL::Buffer* newBuffer = device->newBuffer(data, size, MTL::ResourceStorageModeShared); @@ -47,9 +51,9 @@ namespace Metal { } // Copy the data into the buffer - memcpy((char*)buffer->contents() + ptr, data, size); + std::memcpy((char*)buffer->contents() + ptr, data, size); - size_t oldPtr = ptr; + auto oldPtr = ptr; ptr += size; return BufferHandle{buffer, oldPtr}; @@ -57,6 +61,7 @@ namespace Metal { void reset() { endFrame(); + if (buffer) { buffer->release(); create(); @@ -65,7 +70,7 @@ namespace Metal { private: MTL::Buffer* buffer = nullptr; - size_t ptr = 0; + usize ptr = 0; std::vector additionalAllocations; MTL::Device* device; diff --git a/include/renderer_mtl/pica_to_mtl.hpp b/include/renderer_mtl/pica_to_mtl.hpp index 9234c748..715088b4 100644 --- a/include/renderer_mtl/pica_to_mtl.hpp +++ b/include/renderer_mtl/pica_to_mtl.hpp @@ -4,7 +4,6 @@ #include "PICA/regs.hpp" - namespace PICA { struct PixelFormatInfo { MTL::PixelFormat pixelFormat; @@ -61,7 +60,7 @@ namespace PICA { case 5: return MTL::CompareFunctionLessEqual; case 6: return MTL::CompareFunctionGreater; case 7: return MTL::CompareFunctionGreaterEqual; - default: panic("Unknown compare function %u", func); + default: Helpers::panic("Unknown compare function %u", func); } return MTL::CompareFunctionAlways; @@ -77,7 +76,7 @@ namespace PICA { case 5: return MTL::BlendOperationAdd; // Unused (same as 0) case 6: return MTL::BlendOperationAdd; // Unused (same as 0) case 7: return MTL::BlendOperationAdd; // Unused (same as 0) - default: panic("Unknown blend operation %u", op); + default: Helpers::panic("Unknown blend operation %u", op); } return MTL::BlendOperationAdd; @@ -101,7 +100,7 @@ namespace PICA { case 13: return MTL::BlendFactorOneMinusBlendAlpha; case 14: return MTL::BlendFactorSourceAlphaSaturated; case 15: return MTL::BlendFactorOne; // Undocumented - default: panic("Unknown blend factor %u", factor); + default: Helpers::panic("Unknown blend factor %u", factor); } return MTL::BlendFactorOne; @@ -117,7 +116,7 @@ namespace PICA { case 5: return MTL::StencilOperationInvert; case 6: return MTL::StencilOperationIncrementWrap; case 7: return MTL::StencilOperationDecrementWrap; - default: panic("Unknown stencil operation %u", op); + default: Helpers::panic("Unknown stencil operation %u", op); } return MTL::StencilOperationKeep; @@ -131,7 +130,6 @@ namespace PICA { Helpers::warn("Triangle fans are not supported on Metal, using triangles instead"); return MTL::PrimitiveTypeTriangle; case PrimType::GeometryPrimitive: - // Helpers::warn("Geometry primitives are not yet, using triangles instead"); return MTL::PrimitiveTypeTriangle; } } @@ -146,7 +144,7 @@ namespace PICA { case 5: return MTL::SamplerAddressModeClampToBorderColor; case 6: return MTL::SamplerAddressModeRepeat; case 7: return MTL::SamplerAddressModeRepeat; - default: panic("Unknown sampler address mode %u", addrMode); + default: Helpers::panic("Unknown sampler address mode %u", addrMode); } return MTL::SamplerAddressModeClampToEdge;