diff --git a/src/Core/PS4/GPU/video_out_buffer.cpp b/src/Core/PS4/GPU/video_out_buffer.cpp index 21d825b9..339b5960 100644 --- a/src/Core/PS4/GPU/video_out_buffer.cpp +++ b/src/Core/PS4/GPU/video_out_buffer.cpp @@ -23,13 +23,12 @@ static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params, if (tiled) { - auto* tempbuff = new u08[*size]; - GPU::convertTileToLinear(tempbuff, reinterpret_cast(*virtual_addr), width, height, neo); - Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, tempbuff, *size, pitch, static_cast(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)); - delete[] tempbuff; + std::vector tempbuff(*size); + GPU::convertTileToLinear(tempbuff.data(), reinterpret_cast(*virtual_addr), width, height, neo); + Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, tempbuff.data(), *size, pitch, static_cast(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)); } else { Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, reinterpret_cast(*virtual_addr), *size, pitch, - static_cast(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)); + static_cast(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)); } } diff --git a/src/Core/PS4/HLE/Graphics/graphics_ctx.h b/src/Core/PS4/HLE/Graphics/graphics_ctx.h index 4496b5ea..1196d0b0 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_ctx.h +++ b/src/Core/PS4/HLE/Graphics/graphics_ctx.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -9,10 +10,10 @@ namespace HLE::Libs::Graphics { struct VulkanCommandPool { std::mutex mutex; VkCommandPool pool = nullptr; - VkCommandBuffer* buffers = nullptr; - VkFence* fences = nullptr; - VkSemaphore* semaphores = nullptr; - bool* busy = nullptr; + std::vector buffers; + std::vector fences; + std::vector semaphores; + std::vector busy; u32 buffers_count = 0; }; diff --git a/src/Core/PS4/HLE/Graphics/graphics_render.cpp b/src/Core/PS4/HLE/Graphics/graphics_render.cpp index 22829e7c..63e68f3a 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_render.cpp +++ b/src/Core/PS4/HLE/Graphics/graphics_render.cpp @@ -130,47 +130,45 @@ void GPU::CommandPool::createPool(int id) { auto* render_ctx = singleton::instance(); auto* ctx = render_ctx->getGraphicCtx(); - m_pool[id] = new HLE::Libs::Graphics::VulkanCommandPool; - VkCommandPoolCreateInfo pool_info{}; pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; pool_info.pNext = nullptr; pool_info.queueFamilyIndex = ctx->queues[id].family; pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - vkCreateCommandPool(ctx->m_device, &pool_info, nullptr, &m_pool[id]->pool); + vkCreateCommandPool(ctx->m_device, &pool_info, nullptr, &m_pool[id].pool); - if (m_pool[id]->pool == nullptr) { + if (!m_pool[id].pool) { fmt::print("pool is nullptr"); std::exit(0); } - m_pool[id]->buffers_count = 4; - m_pool[id]->buffers = new VkCommandBuffer[m_pool[id]->buffers_count]; - m_pool[id]->fences = new VkFence[m_pool[id]->buffers_count]; - m_pool[id]->semaphores = new VkSemaphore[m_pool[id]->buffers_count]; - m_pool[id]->busy = new bool[m_pool[id]->buffers_count]; + m_pool[id].buffers_count = 4; + m_pool[id].buffers.resize(m_pool[id].buffers_count); + m_pool[id].fences.resize(m_pool[id].buffers_count); + m_pool[id].semaphores.resize(m_pool[id].buffers_count); + m_pool[id].busy.resize(m_pool[id].buffers_count); VkCommandBufferAllocateInfo alloc_info{}; alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - alloc_info.commandPool = m_pool[id]->pool; + alloc_info.commandPool = m_pool[id].pool; alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - alloc_info.commandBufferCount = m_pool[id]->buffers_count; + alloc_info.commandBufferCount = m_pool[id].buffers_count; - if (vkAllocateCommandBuffers(ctx->m_device, &alloc_info, m_pool[id]->buffers) != VK_SUCCESS) { + if (vkAllocateCommandBuffers(ctx->m_device, &alloc_info, m_pool[id].buffers.data()) != VK_SUCCESS) { fmt::print("Can't allocate command buffers\n"); std::exit(0); } - for (uint32_t i = 0; i < m_pool[id]->buffers_count; i++) { - m_pool[id]->busy[i] = false; + for (u32 i = 0; i < m_pool[id].buffers_count; i++) { + m_pool[id].busy[i] = false; VkFenceCreateInfo fence_info{}; fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fence_info.pNext = nullptr; fence_info.flags = 0; - if (vkCreateFence(ctx->m_device, &fence_info, nullptr, &m_pool[id]->fences[i]) != VK_SUCCESS) { + if (vkCreateFence(ctx->m_device, &fence_info, nullptr, &m_pool[id].fences[i]) != VK_SUCCESS) { fmt::print("Can't create fence\n"); std::exit(0); } @@ -180,7 +178,7 @@ void GPU::CommandPool::createPool(int id) { semaphore_info.pNext = nullptr; semaphore_info.flags = 0; - if (vkCreateSemaphore(ctx->m_device, &semaphore_info, nullptr, &m_pool[id]->semaphores[i]) != VK_SUCCESS) { + if (vkCreateSemaphore(ctx->m_device, &semaphore_info, nullptr, &m_pool[id].semaphores[i]) != VK_SUCCESS) { fmt::print("Can't create semas\n"); std::exit(0); } @@ -192,23 +190,12 @@ void GPU::CommandPool::deleteAllPool() { auto* ctx = render_ctx->getGraphicCtx(); for (auto& pool : m_pool) { - if (pool != nullptr) { - for (uint32_t i = 0; i < pool->buffers_count; i++) { - vkDestroySemaphore(ctx->m_device, pool->semaphores[i], nullptr); - vkDestroyFence(ctx->m_device, pool->fences[i], nullptr); + if (pool.pool) { + for (u32 i = 0; i < pool.buffers_count; i++) { + vkDestroySemaphore(ctx->m_device, pool.semaphores[i], nullptr); + vkDestroyFence(ctx->m_device, pool.fences[i], nullptr); } - - vkFreeCommandBuffers(ctx->m_device, pool->pool, pool->buffers_count, pool->buffers); - - vkDestroyCommandPool(ctx->m_device, pool->pool, nullptr); - - delete[] pool->semaphores; - delete[] pool->fences; - delete[] pool->buffers; - delete[] pool->busy; - - delete pool; - pool = nullptr; + vkDestroyCommandPool(ctx->m_device, pool.pool, nullptr); } } } diff --git a/src/Core/PS4/HLE/Graphics/graphics_render.h b/src/Core/PS4/HLE/Graphics/graphics_render.h index b98197de..c85f3948 100644 --- a/src/Core/PS4/HLE/Graphics/graphics_render.h +++ b/src/Core/PS4/HLE/Graphics/graphics_render.h @@ -1,4 +1,6 @@ #pragma once + +#include #include "graphics_ctx.h" namespace GPU { @@ -9,17 +11,17 @@ class CommandPool { ~CommandPool() {} HLE::Libs::Graphics::VulkanCommandPool* getPool(int id) { - if (m_pool[id] == nullptr) { + if (!m_pool[id].pool) { createPool(id); } - return m_pool[id]; + return &m_pool[id]; } private: void createPool(int id); void deleteAllPool(); - HLE::Libs::Graphics::VulkanCommandPool* m_pool[11] = {}; + std::array m_pool{}; }; class CommandBuffer { public: @@ -48,16 +50,16 @@ class Framebuffer { }; class RenderCtx { public: - RenderCtx() : m_framebuffer(new Framebuffer) {} + RenderCtx() = default; virtual ~RenderCtx() {} void setGraphicCtx(HLE::Libs::Graphics::GraphicCtx* ctx) { m_graphic_ctx = ctx; } HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { return m_graphic_ctx; } private: - Framebuffer* m_framebuffer = nullptr; + Framebuffer m_framebuffer{}; HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr; }; void renderCreateCtx(); -}; // namespace GPU \ No newline at end of file +}; // namespace GPU