From e00d244e0df7c6844a556e4c3c64bcb95592fa44 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sun, 3 Nov 2024 16:45:13 +0100 Subject: [PATCH] remove unused code --- .../Renderer/Metal/MetalMemoryManager.cpp | 93 ---------- .../Latte/Renderer/Metal/MetalMemoryManager.h | 83 +-------- .../HW/Latte/Renderer/Metal/MetalRenderer.cpp | 159 +----------------- .../HW/Latte/Renderer/Metal/MetalRenderer.h | 29 +--- 4 files changed, 5 insertions(+), 359 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp index cd041c5a..4de12549 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp @@ -5,96 +5,6 @@ #include "Cemu/Logging/CemuLogging.h" #include "Common/precompiled.h" -/* -MetalVertexBufferCache::~MetalVertexBufferCache() -{ -} - -MetalRestridedBufferRange MetalVertexBufferCache::RestrideBufferIfNeeded(MTL::Buffer* bufferCache, uint32 bufferIndex, size_t stride, std::vector& barrierBuffers) -{ - auto vertexBufferRange = m_bufferRanges[bufferIndex]; - auto& restrideInfo = *vertexBufferRange.restrideInfo; - - if (stride % 4 == 0) - { - // No restride needed - return {bufferCache, vertexBufferRange.offset}; - } - - MTL::Buffer* buffer; - if (restrideInfo.memoryInvalidated || stride != restrideInfo.lastStride) - { - size_t newStride = Align(stride, 4); - size_t newSize = vertexBufferRange.size / stride * newStride; - 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; - - //for (size_t elem = 0; elem < vertexBufferRange.size / stride; elem++) - // memcpy(newPtr + elem * newStride, oldPtr + elem * stride, stride); - - if (m_mtlr->GetEncoderType() == MetalEncoderType::Render) - { - auto renderCommandEncoder = static_cast(m_mtlr->GetCommandEncoder()); - - renderCommandEncoder->setRenderPipelineState(m_restrideBufferPipeline->GetRenderPipelineState()); - m_mtlr->GetEncoderState().m_renderPipelineState = m_restrideBufferPipeline->GetRenderPipelineState(); - - m_mtlr->SetBuffer(renderCommandEncoder, METAL_SHADER_TYPE_VERTEX, bufferCache, vertexBufferRange.offset, GET_HELPER_BUFFER_BINDING(0)); - m_mtlr->SetBuffer(renderCommandEncoder, METAL_SHADER_TYPE_VERTEX, buffer, restrideInfo.allocation.offset, GET_HELPER_BUFFER_BINDING(1)); - - struct - { - uint32 oldStride; - uint32 newStride; - } strideData = {static_cast(stride), static_cast(newStride)}; - renderCommandEncoder->setVertexBytes(&strideData, sizeof(strideData), GET_HELPER_BUFFER_BINDING(2)); - m_mtlr->GetEncoderState().m_buffers[METAL_SHADER_TYPE_VERTEX][GET_HELPER_BUFFER_BINDING(2)] = {nullptr}; - - renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangleStrip, NS::UInteger(0), vertexBufferRange.size / stride); - - vectorAppendUnique(barrierBuffers, static_cast(buffer)); - } - else - { - cemu_assert_suspicious(); - } - - restrideInfo.memoryInvalidated = false; - restrideInfo.lastStride = newStride; - - // Debug - m_mtlr->GetPerformanceMonitor().m_vertexBufferRestrides++; - } - else - { - buffer = m_bufferAllocator.GetBuffer(restrideInfo.allocation.bufferIndex); - } - - return {buffer, restrideInfo.allocation.offset}; -} - -void MetalVertexBufferCache::MemoryRangeChanged(size_t offset, size_t size) -{ - for (uint32 i = 0; i < LATTE_MAX_VERTEX_BUFFERS; i++) - { - auto vertexBufferRange = m_bufferRanges[i]; - if (vertexBufferRange.offset != INVALID_OFFSET) - { - if ((offset < vertexBufferRange.offset && (offset + size) < (vertexBufferRange.offset + vertexBufferRange.size)) || - (offset > vertexBufferRange.offset && (offset + size) > (vertexBufferRange.offset + vertexBufferRange.size))) - { - continue; - } - - vertexBufferRange.restrideInfo->memoryInvalidated = true; - } - } -} -*/ - MetalMemoryManager::~MetalMemoryManager() { if (m_bufferCache) @@ -168,9 +78,6 @@ void MetalMemoryManager::UploadToBufferCache(const void* data, size_t offset, si { memcpy((uint8*)m_bufferCache->contents() + offset, data, size); } - - // Notify vertex buffer cache about the change - //m_vertexBufferCache.MemoryRangeChanged(offset, size); } void MetalMemoryManager::CopyBufferCache(size_t srcOffset, size_t dstOffset, size_t size) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h index 6cc4ab1e..ecae3d3e 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.h @@ -4,74 +4,12 @@ #include "GameProfile/GameProfile.h" -/* -struct MetalRestridedBufferRange -{ - MTL::Buffer* buffer; - size_t offset; -}; - -struct MetalVertexBufferRange -{ - size_t offset = INVALID_OFFSET; - size_t size; - MetalRestrideInfo* restrideInfo; -}; - -class MetalVertexBufferCache -{ -public: - friend class MetalMemoryManager; - - MetalVertexBufferCache(class MetalRenderer* metalRenderer, MetalDefaultBufferAllocator& bufferAllocator) : m_mtlr{metalRenderer}, m_bufferAllocator{bufferAllocator} {} - ~MetalVertexBufferCache(); - - void SetRestrideBufferPipeline(class MetalVoidVertexPipeline* restrideBufferPipeline) - { - m_restrideBufferPipeline = restrideBufferPipeline; - } - - void TrackVertexBuffer(uint32 bufferIndex, size_t offset, size_t size, MetalRestrideInfo* restrideInfo) - { - m_bufferRanges[bufferIndex] = MetalVertexBufferRange{offset, size, restrideInfo}; - } - - void UntrackVertexBuffer(uint32 bufferIndex) - { - auto& range = m_bufferRanges[bufferIndex]; - //if (range.restrideInfo->allocation.offset != INVALID_OFFSET) - // m_bufferAllocator.FreeAllocation(range.restrideInfo->allocation); - range.offset = INVALID_OFFSET; - } - - MetalRestridedBufferRange RestrideBufferIfNeeded(MTL::Buffer* bufferCache, uint32 bufferIndex, size_t stride, std::vector& barrierBuffers); - -private: - class MetalRenderer* m_mtlr; - MetalDefaultBufferAllocator& m_bufferAllocator; - - class MetalVoidVertexPipeline* m_restrideBufferPipeline = nullptr; - - MetalVertexBufferRange m_bufferRanges[LATTE_MAX_VERTEX_BUFFERS] = {}; - - 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) {} ~MetalMemoryManager(); - // Pipelines - /* - void SetRestrideBufferPipeline(class MetalVoidVertexPipeline* restrideBufferPipeline) - { - m_vertexBufferCache.SetRestrideBufferPipeline(restrideBufferPipeline); - } - */ - MetalDefaultBufferAllocator& GetBufferAllocator() { return m_bufferAllocator; @@ -99,24 +37,6 @@ public: void UploadToBufferCache(const void* data, size_t offset, size_t size); 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); - } - - void UntrackVertexBuffer(uint32 bufferIndex) - { - m_vertexBufferCache.UntrackVertexBuffer(bufferIndex); - } - - MetalRestridedBufferRange RestrideBufferIfNeeded(uint32 bufferIndex, size_t stride, std::vector& barrierBuffers) - { - return m_vertexBufferCache.RestrideBufferIfNeeded(m_bufferCache, bufferIndex, stride, barrierBuffers); - } - */ - // Getters bool UseHostMemoryForCache() const { @@ -136,7 +56,6 @@ private: MetalDefaultBufferAllocator m_bufferAllocator; MetalDefaultBufferAllocator m_framePersistentBufferAllocator; MetalTemporaryBufferAllocator m_tempBufferAllocator; - //MetalVertexBufferCache m_vertexBufferCache; MTL::Buffer* m_bufferCache = nullptr; BufferCacheType m_bufferCacheType; diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 7c80a0bc..93d3c08d 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -124,54 +124,11 @@ MetalRenderer::MetalRenderer() return; } - // Present pipeline - /* - MTL::Function* fullscreenVertexFunction = utilityLibrary->newFunction(ToNSString("vertexFullscreen")); - MTL::Function* presentFragmentFunction = utilityLibrary->newFunction(ToNSString("fragmentPresent")); - - MTL::RenderPipelineDescriptor* renderPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); - renderPipelineDescriptor->setVertexFunction(fullscreenVertexFunction); - renderPipelineDescriptor->setFragmentFunction(presentFragmentFunction); - fullscreenVertexFunction->release(); - presentFragmentFunction->release(); - - error = nullptr; - renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm); -#ifdef CEMU_DEBUG_ASSERT - renderPipelineDescriptor->setLabel(GetLabel("Present pipeline linear", renderPipelineDescriptor)); -#endif - m_presentPipelineLinear = m_device->newRenderPipelineState(renderPipelineDescriptor, &error); - if (error) - { - debug_printf("failed to create linear present pipeline (error: %s)\n", error->localizedDescription()->utf8String()); - error->release(); - } - - error = nullptr; - renderPipelineDescriptor->colorAttachments()->object(0)->setPixelFormat(MTL::PixelFormatBGRA8Unorm_sRGB); -#ifdef CEMU_DEBUG_ASSERT - renderPipelineDescriptor->setLabel(GetLabel("Present pipeline sRGB", renderPipelineDescriptor)); -#endif - m_presentPipelineSRGB = m_device->newRenderPipelineState(renderPipelineDescriptor, &error); - renderPipelineDescriptor->release(); - if (error) - { - debug_printf("failed to create sRGB present pipeline (error: %s)\n", error->localizedDescription()->utf8String()); - error->release(); - } - */ - - // Copy texture pipelines - auto copyTextureToColorPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init(); - - // Hybrid pipelines + // Void vertex pipelines if (m_isAppleGPU) m_copyBufferToBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyBufferToBuffer"); - //m_copyTextureToTexturePipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexCopyTextureToTexture"); - //m_restrideBufferPipeline = new MetalVoidVertexPipeline(this, utilityLibrary, "vertexRestrideBuffer"); - utilityLibrary->release(); - //m_memoryManager->SetRestrideBufferPipeline(m_restrideBufferPipeline); + utilityLibrary->release(); } MetalRenderer::~MetalRenderer() @@ -741,74 +698,6 @@ void MetalRenderer::surfaceCopy_copySurfaceWithFormatConversion(LatteTexture* so //sourceTexture->GetEffectiveSize(sourceEffectiveWidth, sourceEffectiveHeight, srcMip); texture_copyImageSubData(sourceTexture, srcMip, 0, 0, srcSlice, destinationTexture, dstMip, 0, 0, dstSlice, effectiveCopyWidth, effectiveCopyHeight, 1); - - /* - sint32 texSrcMip = srcMip; - sint32 texSrcSlice = srcSlice; - sint32 texDstMip = dstMip; - sint32 texDstSlice = dstSlice; - - // Create texture views - LatteTextureViewMtl* srcTextureMtl = static_cast(sourceTexture->GetOrCreateView(srcMip, 1, srcSlice, 1)); - LatteTextureViewMtl* dstTextureMtl = static_cast(destinationTexture->GetOrCreateView(dstMip, 1, dstSlice, 1)); - - // check if texture rescale ratios match - // todo - if not, we have to use drawcall based copying - if (!LatteTexture_doesEffectiveRescaleRatioMatch(sourceTexture, texSrcMip, destinationTexture, texDstMip)) - { - cemuLog_logDebug(LogType::Force, "surfaceCopy_copySurfaceWithFormatConversion(): Mismatching dimensions"); - return; - } - - // check if bpp size matches - if (sourceTexture->GetBPP() != destinationTexture->GetBPP()) - { - cemuLog_logDebug(LogType::Force, "surfaceCopy_copySurfaceWithFormatConversion(): Mismatching BPP"); - return; - } - - if (m_encoderType == MetalEncoderType::Render) - { - auto renderCommandEncoder = static_cast(m_commandEncoder); - - renderCommandEncoder->setRenderPipelineState(m_copyTextureToTexturePipeline->GetRenderPipelineState()); - m_state.m_encoderState.m_renderPipelineState = m_copyTextureToTexturePipeline->GetRenderPipelineState(); - - SetTexture(renderCommandEncoder, METAL_SHADER_TYPE_VERTEX, srcTextureMtl->GetRGBAView(), GET_HELPER_TEXTURE_BINDING(0)); - SetTexture(renderCommandEncoder, METAL_SHADER_TYPE_VERTEX, dstTextureMtl->GetRGBAView(), GET_HELPER_TEXTURE_BINDING(1)); - renderCommandEncoder->setVertexBytes(&effectiveCopyWidth, sizeof(effectiveCopyWidth), GET_HELPER_BUFFER_BINDING(0)); - m_state.m_encoderState.m_buffers[METAL_SHADER_TYPE_VERTEX][GET_HELPER_BUFFER_BINDING(0)] = {nullptr}; - - renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(3)); - } - else - { - bool copyingToWholeRegion = ((effectiveCopyWidth == dstTextureMtl->GetMipWidth(dstMip) && effectiveCopyHeight == dstTextureMtl->GetMipHeight(dstMip))); - - auto renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init(); - auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0); - colorAttachment->setTexture(dstTextureMtl->GetTexture()); - // We don't care about previous contents if we are about to overwrite the whole region - colorAttachment->setLoadAction(copyingToWholeRegion ? MTL::LoadActionDontCare : MTL::LoadActionLoad); - colorAttachment->setStoreAction(MTL::StoreActionStore); - colorAttachment->setSlice(dstSlice); - colorAttachment->setLevel(dstMip); - - auto renderCommandEncoder = GetTemporaryRenderCommandEncoder(renderPassDescriptor); - - auto pipeline = (srcTextureMtl->IsDepth() ? m_copyTextureToColorPipeline : m_copyTextureToDepthPipeline); - renderCommandEncoder->setRenderPipelineState(pipeline); - - renderCommandEncoder->setFragmentTexture(srcTextureMtl->GetTexture(), GET_HELPER_TEXTURE_BINDING(0)); - renderCommandEncoder->setFragmentBytes(&effectiveCopyWidth, offsetof(effectiveCopyWidth), GET_HELPER_BUFFER_BINDING(0)); - - renderCommandEncoder->drawPrimitives(MTL::PrimitiveTypeTriangle, NS::UInteger(0), NS::UInteger(3)); - - EndEncoding(); - - debug_printf("surface copy with no render command encoder, skipping copy\n"); - } - */ } void MetalRenderer::bufferCache_init(const sint32 bufferSize) @@ -840,19 +729,6 @@ void MetalRenderer::buffer_bindVertexBuffer(uint32 bufferIndex, uint32 offset, u cemu_assert_debug(bufferIndex < LATTE_MAX_VERTEX_BUFFERS); m_state.m_vertexBufferOffsets[bufferIndex] = offset; - //if (buffer.offset == offset && buffer.size == size) - // return; - - //if (buffer.offset != INVALID_OFFSET) - //{ - // m_memoryManager->UntrackVertexBuffer(bufferIndex); - //} - - //buffer.offset = offset; - //buffer.size = size; - //buffer.restrideInfo = {}; - - //m_memoryManager->TrackVertexBuffer(bufferIndex, offset, size, &buffer.restrideInfo); } void MetalRenderer::buffer_bindUniformBuffer(LatteConst::ShaderType shaderType, uint32 bufferIndex, uint32 offset, uint32 size) @@ -1218,45 +1094,16 @@ void MetalRenderer::draw_execute(uint32 baseVertex, uint32 baseInstance, uint32 // Resources // Vertex buffers - //std::vector barrierBuffers; for (uint8 i = 0; i < MAX_MTL_VERTEX_BUFFERS; i++) { size_t offset = m_state.m_vertexBufferOffsets[i]; if (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; - } - */ - // Bind SetBuffer(renderCommandEncoder, GetMtlShaderType(vertexShader->shaderType, usesGeometryShader), m_memoryManager->GetBufferCache(), offset, GET_MTL_VERTEX_BUFFER_INDEX(i)); } } - //if (!barrierBuffers.empty()) - //{ - // renderCommandEncoder->memoryBarrier(barrierBuffers.data(), barrierBuffers.size(), MTL::RenderStageVertex, MTL::RenderStageVertex); - //} - // Prepare streamout m_state.m_streamoutState.verticesPerInstance = count; LatteStreamout_PrepareDrawcall(count, instanceCount); @@ -1370,8 +1217,6 @@ void MetalRenderer::draw_updateVertexBuffersDirectAccess() uint32 bufferIndex = bufferGroup.attributeBufferIndex; uint32 bufferBaseRegisterIndex = mmSQ_VTX_ATTRIBUTE_BLOCK_START + bufferIndex * 7; MPTR bufferAddress = LatteGPUState.contextRegister[bufferBaseRegisterIndex + 0]; - //uint32 bufferSize = LatteGPUState.contextRegister[bufferBaseRegisterIndex + 1] + 1; - //uint32 bufferStride = (LatteGPUState.contextRegister[bufferBaseRegisterIndex + 2] >> 11) & 0xFFFF; if (bufferAddress == MPTR_NULL) [[unlikely]] bufferAddress = 0x10000000; // TODO: really? diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index 9ddc5e93..de416825 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -20,25 +20,6 @@ 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; -}; -*/ - enum MetalGeneralShaderType { METAL_GENERAL_SHADER_TYPE_VERTEX, @@ -143,7 +124,7 @@ struct MetalState // If the FBO changes, but it's the same FBO as the last one with some omitted attachments, this FBO doesn't change MetalActiveFBOState m_lastUsedFBO; - size_t m_vertexBufferOffsets[MAX_MTL_VERTEX_BUFFERS] = {INVALID_OFFSET}; + size_t m_vertexBufferOffsets[MAX_MTL_VERTEX_BUFFERS]; // TODO: find out what is the max number of bound textures on the Wii U class LatteTextureViewMtl* m_textures[64] = {nullptr}; size_t m_uniformBufferOffsets[METAL_GENERAL_SHADER_TYPE_TOTAL][MAX_MTL_BUFFERS]; @@ -472,14 +453,8 @@ private: class MetalDepthStencilCache* m_depthStencilCache; class MetalSamplerCache* m_samplerCache; - // Pipelines - //MTL::RenderPipelineState* m_presentPipelineLinear; - //MTL::RenderPipelineState* m_presentPipelineSRGB; - - // Hybrid pipelines + // Void vertex pipelines class MetalVoidVertexPipeline* m_copyBufferToBufferPipeline; - //class MetalVoidVertexPipeline* m_copyTextureToTexturePipeline; - //class MetalVoidVertexPipeline* m_restrideBufferPipeline; // Resources MTL::SamplerState* m_nearestSampler;