vulkan: Remove orphan new part 2
This commit is contained in:
parent
e196e35669
commit
0021e68aab
|
@ -23,13 +23,12 @@ static void update_func(HLE::Libs::Graphics::GraphicCtx* ctx, const u64* params,
|
||||||
|
|
||||||
if (tiled)
|
if (tiled)
|
||||||
{
|
{
|
||||||
auto* tempbuff = new u08[*size];
|
std::vector<u08> tempbuff(*size);
|
||||||
GPU::convertTileToLinear(tempbuff, reinterpret_cast<void*>(*virtual_addr), width, height, neo);
|
GPU::convertTileToLinear(tempbuff.data(), reinterpret_cast<void*>(*virtual_addr), width, height, neo);
|
||||||
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, tempbuff, *size, pitch, static_cast<uint64_t>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, tempbuff.data(), *size, pitch, static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||||
delete[] tempbuff;
|
|
||||||
} else {
|
} else {
|
||||||
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, reinterpret_cast<void*>(*virtual_addr), *size, pitch,
|
Graphics::Vulkan::vulkanFillImage(ctx, vk_obj, reinterpret_cast<void*>(*virtual_addr), *size, pitch,
|
||||||
static_cast<uint64_t>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
static_cast<u64>(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
#include <vector>
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
@ -9,10 +10,10 @@ namespace HLE::Libs::Graphics {
|
||||||
struct VulkanCommandPool {
|
struct VulkanCommandPool {
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
VkCommandPool pool = nullptr;
|
VkCommandPool pool = nullptr;
|
||||||
VkCommandBuffer* buffers = nullptr;
|
std::vector<VkCommandBuffer> buffers;
|
||||||
VkFence* fences = nullptr;
|
std::vector<VkFence> fences;
|
||||||
VkSemaphore* semaphores = nullptr;
|
std::vector<VkSemaphore> semaphores;
|
||||||
bool* busy = nullptr;
|
std::vector<bool> busy;
|
||||||
u32 buffers_count = 0;
|
u32 buffers_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -130,47 +130,45 @@ void GPU::CommandPool::createPool(int id) {
|
||||||
auto* render_ctx = singleton<RenderCtx>::instance();
|
auto* render_ctx = singleton<RenderCtx>::instance();
|
||||||
auto* ctx = render_ctx->getGraphicCtx();
|
auto* ctx = render_ctx->getGraphicCtx();
|
||||||
|
|
||||||
m_pool[id] = new HLE::Libs::Graphics::VulkanCommandPool;
|
|
||||||
|
|
||||||
VkCommandPoolCreateInfo pool_info{};
|
VkCommandPoolCreateInfo pool_info{};
|
||||||
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
pool_info.pNext = nullptr;
|
pool_info.pNext = nullptr;
|
||||||
pool_info.queueFamilyIndex = ctx->queues[id].family;
|
pool_info.queueFamilyIndex = ctx->queues[id].family;
|
||||||
pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
|
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");
|
fmt::print("pool is nullptr");
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pool[id]->buffers_count = 4;
|
m_pool[id].buffers_count = 4;
|
||||||
m_pool[id]->buffers = new VkCommandBuffer[m_pool[id]->buffers_count];
|
m_pool[id].buffers.resize(m_pool[id].buffers_count);
|
||||||
m_pool[id]->fences = new VkFence[m_pool[id]->buffers_count];
|
m_pool[id].fences.resize(m_pool[id].buffers_count);
|
||||||
m_pool[id]->semaphores = new VkSemaphore[m_pool[id]->buffers_count];
|
m_pool[id].semaphores.resize(m_pool[id].buffers_count);
|
||||||
m_pool[id]->busy = new bool[m_pool[id]->buffers_count];
|
m_pool[id].busy.resize(m_pool[id].buffers_count);
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo alloc_info{};
|
VkCommandBufferAllocateInfo alloc_info{};
|
||||||
alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_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.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");
|
fmt::print("Can't allocate command buffers\n");
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < m_pool[id]->buffers_count; i++) {
|
for (u32 i = 0; i < m_pool[id].buffers_count; i++) {
|
||||||
m_pool[id]->busy[i] = false;
|
m_pool[id].busy[i] = false;
|
||||||
|
|
||||||
VkFenceCreateInfo fence_info{};
|
VkFenceCreateInfo fence_info{};
|
||||||
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
fence_info.pNext = nullptr;
|
fence_info.pNext = nullptr;
|
||||||
fence_info.flags = 0;
|
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");
|
fmt::print("Can't create fence\n");
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
@ -180,7 +178,7 @@ void GPU::CommandPool::createPool(int id) {
|
||||||
semaphore_info.pNext = nullptr;
|
semaphore_info.pNext = nullptr;
|
||||||
semaphore_info.flags = 0;
|
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");
|
fmt::print("Can't create semas\n");
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
@ -192,23 +190,12 @@ void GPU::CommandPool::deleteAllPool() {
|
||||||
auto* ctx = render_ctx->getGraphicCtx();
|
auto* ctx = render_ctx->getGraphicCtx();
|
||||||
|
|
||||||
for (auto& pool : m_pool) {
|
for (auto& pool : m_pool) {
|
||||||
if (pool != nullptr) {
|
if (pool.pool) {
|
||||||
for (uint32_t i = 0; i < pool->buffers_count; i++) {
|
for (u32 i = 0; i < pool.buffers_count; i++) {
|
||||||
vkDestroySemaphore(ctx->m_device, pool->semaphores[i], nullptr);
|
vkDestroySemaphore(ctx->m_device, pool.semaphores[i], nullptr);
|
||||||
vkDestroyFence(ctx->m_device, pool->fences[i], nullptr);
|
vkDestroyFence(ctx->m_device, pool.fences[i], nullptr);
|
||||||
}
|
}
|
||||||
|
vkDestroyCommandPool(ctx->m_device, pool.pool, 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include "graphics_ctx.h"
|
#include "graphics_ctx.h"
|
||||||
|
|
||||||
namespace GPU {
|
namespace GPU {
|
||||||
|
@ -9,17 +11,17 @@ class CommandPool {
|
||||||
~CommandPool() {}
|
~CommandPool() {}
|
||||||
|
|
||||||
HLE::Libs::Graphics::VulkanCommandPool* getPool(int id) {
|
HLE::Libs::Graphics::VulkanCommandPool* getPool(int id) {
|
||||||
if (m_pool[id] == nullptr) {
|
if (!m_pool[id].pool) {
|
||||||
createPool(id);
|
createPool(id);
|
||||||
}
|
}
|
||||||
return m_pool[id];
|
return &m_pool[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createPool(int id);
|
void createPool(int id);
|
||||||
void deleteAllPool();
|
void deleteAllPool();
|
||||||
|
|
||||||
HLE::Libs::Graphics::VulkanCommandPool* m_pool[11] = {};
|
std::array<HLE::Libs::Graphics::VulkanCommandPool, 11> m_pool{};
|
||||||
};
|
};
|
||||||
class CommandBuffer {
|
class CommandBuffer {
|
||||||
public:
|
public:
|
||||||
|
@ -48,14 +50,14 @@ class Framebuffer {
|
||||||
};
|
};
|
||||||
class RenderCtx {
|
class RenderCtx {
|
||||||
public:
|
public:
|
||||||
RenderCtx() : m_framebuffer(new Framebuffer) {}
|
RenderCtx() = default;
|
||||||
|
|
||||||
virtual ~RenderCtx() {}
|
virtual ~RenderCtx() {}
|
||||||
void setGraphicCtx(HLE::Libs::Graphics::GraphicCtx* ctx) { m_graphic_ctx = ctx; }
|
void setGraphicCtx(HLE::Libs::Graphics::GraphicCtx* ctx) { m_graphic_ctx = ctx; }
|
||||||
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { return m_graphic_ctx; }
|
HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { return m_graphic_ctx; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Framebuffer* m_framebuffer = nullptr;
|
Framebuffer m_framebuffer{};
|
||||||
HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr;
|
HLE::Libs::Graphics::GraphicCtx* m_graphic_ctx = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue