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

View File

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

View File

@ -163,10 +163,10 @@ MetalRenderer::MetalRenderer()
if (m_isAppleGPU)
m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer");
//m_copyTextureToTexturePipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyTextureToTexture");
m_restrideBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexRestrideBuffer");
//m_restrideBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexRestrideBuffer");
utilityLibrary->release();
m_memoryManager->SetRestrideBufferPipeline(m_restrideBufferPipeline);
//m_memoryManager->SetRestrideBufferPipeline(m_restrideBufferPipeline);
}
MetalRenderer::~MetalRenderer()
@ -174,7 +174,7 @@ MetalRenderer::~MetalRenderer()
if (m_isAppleGPU)
delete m_copyBufferToBufferPipeline;
//delete m_copyTextureToTexturePipeline;
delete m_restrideBufferPipeline;
//delete m_restrideBufferPipeline;
//m_presentPipelineLinear->release();
//m_presentPipelineSRGB->release();
@ -831,16 +831,16 @@ void MetalRenderer::buffer_bindVertexBuffer(uint32 bufferIndex, uint32 offset, u
if (buffer.offset == offset && buffer.size == size)
return;
if (buffer.offset != INVALID_OFFSET)
{
m_memoryManager->UntrackVertexBuffer(bufferIndex);
}
//if (buffer.offset != INVALID_OFFSET)
//{
// m_memoryManager->UntrackVertexBuffer(bufferIndex);
//}
buffer.offset = offset;
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)
@ -1169,12 +1169,35 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32
// Resources
// Vertex buffers
std::vector<MTL::Resource*> barrierBuffers;
//std::vector<MTL::Resource*> barrierBuffers;
for (uint8 i = 0; i < MAX_MTL_BUFFERS; i++)
{
auto& vertexBufferRange = m_state.m_vertexBuffers[i];
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();
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())
{
renderCommandEncoder->memoryBarrier(barrierBuffers.data(), barrierBuffers.size(), MTL::RenderStageVertex, MTL::RenderStageVertex);
}
//if (!barrierBuffers.empty())
//{
// renderCommandEncoder->memoryBarrier(barrierBuffers.data(), barrierBuffers.size(), MTL::RenderStageVertex, MTL::RenderStageVertex);
//}
// Render pipeline state
MTL::RenderPipelineState* renderPipelineState;

View File

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