remove vertex restriding code

This commit is contained in:
Samuliak 2024-10-01 18:11:05 +02:00
parent 94e8ed5a46
commit f2096deddd
4 changed files with 56 additions and 28 deletions

View File

@ -2,9 +2,8 @@
#include "Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h"
#include "Cafe/HW/Latte/Renderer/Metal/MetalVoidVertexPipeline.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalVoidVertexPipeline.h"
#include "Common/precompiled.h" #include "Common/precompiled.h"
#include "HW/Latte/Renderer/Metal/MetalRenderer.h"
#include "Metal/MTLResource.hpp"
/*
MetalVertexBufferCache::~MetalVertexBufferCache() MetalVertexBufferCache::~MetalVertexBufferCache()
{ {
} }
@ -28,13 +27,11 @@ MetalRestridedBufferRange MetalVertexBufferCache::RestrideBufferIfNeeded(MTL::Bu
restrideInfo.allocation = m_bufferAllocator.GetBufferAllocation(newSize); restrideInfo.allocation = m_bufferAllocator.GetBufferAllocation(newSize);
buffer = m_bufferAllocator.GetBuffer(restrideInfo.allocation.bufferIndex); buffer = m_bufferAllocator.GetBuffer(restrideInfo.allocation.bufferIndex);
/* //uint8* oldPtr = (uint8*)bufferCache->contents() + vertexBufferRange.offset;
uint8* oldPtr = (uint8*)bufferCache->contents() + vertexBufferRange.offset; //uint8* newPtr = (uint8*)buffer->contents() + restrideInfo.allocation.offset;
uint8* newPtr = (uint8*)buffer->contents() + restrideInfo.allocation.offset;
for (size_t elem = 0; elem < vertexBufferRange.size / stride; elem++) //for (size_t elem = 0; elem < vertexBufferRange.size / stride; elem++)
memcpy(newPtr + elem * newStride, oldPtr + elem * stride, stride); // memcpy(newPtr + elem * newStride, oldPtr + elem * stride, stride);
*/
if (m_mtlr->GetEncoderType() == MetalEncoderType::Render) if (m_mtlr->GetEncoderType() == MetalEncoderType::Render)
{ {
@ -94,6 +91,7 @@ void MetalVertexBufferCache::MemoryRangeChanged(size_t offset, size_t size)
} }
} }
} }
*/
MetalMemoryManager::~MetalMemoryManager() MetalMemoryManager::~MetalMemoryManager()
{ {
@ -144,7 +142,7 @@ void MetalMemoryManager::UploadToBufferCache(const void* data, size_t offset, si
m_tempBufferAllocator.UnlockBuffer(allocation.bufferIndex); m_tempBufferAllocator.UnlockBuffer(allocation.bufferIndex);
// Notify vertex buffer cache about the change // Notify vertex buffer cache about the change
m_vertexBufferCache.MemoryRangeChanged(offset, size); //m_vertexBufferCache.MemoryRangeChanged(offset, size);
} }
void MetalMemoryManager::CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size) void MetalMemoryManager::CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size)

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h" #include "Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h"
#include "Metal/MTLResource.hpp"
/*
struct MetalRestridedBufferRange struct MetalRestridedBufferRange
{ {
MTL::Buffer* buffer; MTL::Buffer* buffer;
@ -54,18 +54,21 @@ private:
void MemoryRangeChanged(size_t offset, size_t size); void MemoryRangeChanged(size_t offset, size_t size);
}; };
*/
class MetalMemoryManager class MetalMemoryManager
{ {
public: public:
MetalMemoryManager(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer}, m_bufferAllocator(metalRenderer, m_mtlr->GetOptimalBufferStorageMode()), m_framePersistentBufferAllocator(metalRenderer, MTL::ResourceStorageModePrivate), m_tempBufferAllocator(metalRenderer), m_vertexBufferCache(metalRenderer, m_framePersistentBufferAllocator) {} MetalMemoryManager(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer}, m_bufferAllocator(metalRenderer, m_mtlr->GetOptimalBufferStorageMode()), m_framePersistentBufferAllocator(metalRenderer, MTL::ResourceStorageModePrivate), m_tempBufferAllocator(metalRenderer)/*, m_vertexBufferCache(metalRenderer, m_framePersistentBufferAllocator)*/ {}
~MetalMemoryManager(); ~MetalMemoryManager();
// Pipelines // Pipelines
/*
void SetRestrideBufferPipeline(class MetalVoidVertexPipeline* restrideBufferPipeline) void SetRestrideBufferPipeline(class MetalVoidVertexPipeline* restrideBufferPipeline)
{ {
m_vertexBufferCache.SetRestrideBufferPipeline(restrideBufferPipeline); m_vertexBufferCache.SetRestrideBufferPipeline(restrideBufferPipeline);
} }
*/
MetalDefaultBufferAllocator& GetBufferAllocator() MetalDefaultBufferAllocator& GetBufferAllocator()
{ {
@ -95,6 +98,7 @@ public:
void CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size); void CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size);
// Vertex buffer cache // Vertex buffer cache
/*
void TrackVertexBuffer(uint32 bufferIndex, size_t offset, size_t size, MetalRestrideInfo* restrideInfo) void TrackVertexBuffer(uint32 bufferIndex, size_t offset, size_t size, MetalRestrideInfo* restrideInfo)
{ {
m_vertexBufferCache.TrackVertexBuffer(bufferIndex, offset, size, restrideInfo); m_vertexBufferCache.TrackVertexBuffer(bufferIndex, offset, size, restrideInfo);
@ -109,6 +113,7 @@ public:
{ {
return m_vertexBufferCache.RestrideBufferIfNeeded(m_bufferCache, bufferIndex, stride, barrierBuffers); return m_vertexBufferCache.RestrideBufferIfNeeded(m_bufferCache, bufferIndex, stride, barrierBuffers);
} }
*/
private: private:
class MetalRenderer* m_mtlr; class MetalRenderer* m_mtlr;
@ -118,7 +123,7 @@ private:
MetalDefaultBufferAllocator m_bufferAllocator; MetalDefaultBufferAllocator m_bufferAllocator;
MetalDefaultBufferAllocator m_framePersistentBufferAllocator; MetalDefaultBufferAllocator m_framePersistentBufferAllocator;
MetalTemporaryBufferAllocator m_tempBufferAllocator; MetalTemporaryBufferAllocator m_tempBufferAllocator;
MetalVertexBufferCache m_vertexBufferCache; //MetalVertexBufferCache m_vertexBufferCache;
MTL::Buffer* m_bufferCache = nullptr; MTL::Buffer* m_bufferCache = nullptr;
}; };

View File

@ -163,10 +163,10 @@ MetalRenderer::MetalRenderer()
if (m_isAppleGPU) if (m_isAppleGPU)
m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer"); m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer");
//m_copyTextureToTexturePipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyTextureToTexture"); //m_copyTextureToTexturePipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyTextureToTexture");
m_restrideBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexRestrideBuffer"); //m_restrideBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexRestrideBuffer");
utilityLibrary->release(); utilityLibrary->release();
m_memoryManager->SetRestrideBufferPipeline(m_restrideBufferPipeline); //m_memoryManager->SetRestrideBufferPipeline(m_restrideBufferPipeline);
} }
MetalRenderer::~MetalRenderer() MetalRenderer::~MetalRenderer()
@ -174,7 +174,7 @@ MetalRenderer::~MetalRenderer()
if (m_isAppleGPU) if (m_isAppleGPU)
delete m_copyBufferToBufferPipeline; delete m_copyBufferToBufferPipeline;
//delete m_copyTextureToTexturePipeline; //delete m_copyTextureToTexturePipeline;
delete m_restrideBufferPipeline; //delete m_restrideBufferPipeline;
//m_presentPipelineLinear->release(); //m_presentPipelineLinear->release();
//m_presentPipelineSRGB->release(); //m_presentPipelineSRGB->release();
@ -831,16 +831,16 @@ void MetalRenderer::buffer_bindVertexBuffer(uint32 bufferIndex, uint32 offset, u
if (buffer.offset == offset && buffer.size == size) if (buffer.offset == offset && buffer.size == size)
return; return;
if (buffer.offset != INVALID_OFFSET) //if (buffer.offset != INVALID_OFFSET)
{ //{
m_memoryManager->UntrackVertexBuffer(bufferIndex); // m_memoryManager->UntrackVertexBuffer(bufferIndex);
} //}
buffer.offset = offset; buffer.offset = offset;
buffer.size = size; buffer.size = size;
buffer.restrideInfo = {}; //buffer.restrideInfo = {};
m_memoryManager->TrackVertexBuffer(bufferIndex, offset, size, &buffer.restrideInfo); //m_memoryManager->TrackVertexBuffer(bufferIndex, offset, size, &buffer.restrideInfo);
} }
void MetalRenderer::buffer_bindUniformBuffer(LatteConst::ShaderType shaderType, uint32 bufferIndex, uint32 offset, uint32 size) void MetalRenderer::buffer_bindUniformBuffer(LatteConst::ShaderType shaderType, uint32 bufferIndex, uint32 offset, uint32 size)
@ -1169,12 +1169,35 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
// Resources // Resources
// Vertex buffers // Vertex buffers
std::vector<MTL::Resource*> barrierBuffers; //std::vector<MTL::Resource*> barrierBuffers;
for (uint8 i = 0; i < MAX_MTL_BUFFERS; i++) for (uint8 i = 0; i < MAX_MTL_BUFFERS; i++)
{ {
auto& vertexBufferRange = m_state.m_vertexBuffers[i]; auto& vertexBufferRange = m_state.m_vertexBuffers[i];
if (vertexBufferRange.offset != INVALID_OFFSET) if (vertexBufferRange.offset != INVALID_OFFSET)
{ {
/*
MTL::Buffer* buffer;
size_t offset;
// Restride
if (usesGeometryShader)
{
// Object shaders don't need restriding, since the attributes are fetched in the shader
buffer = m_memoryManager->GetBufferCache();
offset = m_state.m_vertexBuffers[i].offset;
}
else
{
uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + i * 7;
uint32 bufferStride = (LatteGPUState.contextNew.GetRawView()[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF;
auto restridedBuffer = m_memoryManager->RestrideBufferIfNeeded(i, bufferStride, barrierBuffers);
buffer = restridedBuffer.buffer;
offset = restridedBuffer.offset;
}
*/
MTL::Buffer* buffer = m_memoryManager->GetBufferCache(); MTL::Buffer* buffer = m_memoryManager->GetBufferCache();
size_t offset = m_state.m_vertexBuffers[i].offset; size_t offset = m_state.m_vertexBuffers[i].offset;
@ -1183,10 +1206,10 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
} }
} }
if (!barrierBuffers.empty()) //if (!barrierBuffers.empty())
{ //{
renderCommandEncoder->memoryBarrier(barrierBuffers.data(), barrierBuffers.size(), MTL::RenderStageVertex, MTL::RenderStageVertex); // renderCommandEncoder->memoryBarrier(barrierBuffers.data(), barrierBuffers.size(), MTL::RenderStageVertex, MTL::RenderStageVertex);
} //}
// Render pipeline state // Render pipeline state
MTL::RenderPipelineState* renderPipelineState; MTL::RenderPipelineState* renderPipelineState;

View File

@ -19,19 +19,21 @@ struct MetalBufferAllocation
} }
}; };
/*
struct MetalRestrideInfo struct MetalRestrideInfo
{ {
bool memoryInvalidated = true; bool memoryInvalidated = true;
size_t lastStride = 0; size_t lastStride = 0;
MetalBufferAllocation allocation{}; MetalBufferAllocation allocation{};
}; };
*/
struct MetalBoundBuffer struct MetalBoundBuffer
{ {
size_t offset = INVALID_OFFSET; size_t offset = INVALID_OFFSET;
size_t size = 0; size_t size = 0;
// Memory manager will write restride info to this variable // Memory manager will write restride info to this variable
MetalRestrideInfo restrideInfo; //MetalRestrideInfo restrideInfo;
}; };
enum MetalGeneralShaderType enum MetalGeneralShaderType
@ -473,7 +475,7 @@ private:
// Hybrid pipelines // Hybrid pipelines
class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline; class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline;
//class MetalVoidVertexPipeline* m_copyTextureToTexturePipeline; //class MetalVoidVertexPipeline* m_copyTextureToTexturePipeline;
class MetalVoidVertexPipeline* m_restrideBufferPipeline; //class MetalVoidVertexPipeline* m_restrideBufferPipeline;
// Resources // Resources
MTL::SamplerState* m_nearestSampler; MTL::SamplerState* m_nearestSampler;