graphics: fix initialization

This commit is contained in:
nmzik
2026-07-21 07:33:01 +02:00
parent 0a5f78c727
commit 8a4600c5e9
16 changed files with 39 additions and 170 deletions
-1
View File
@@ -277,7 +277,6 @@ void TileCompute::Init() {
if (resources.pipeline_layout != nullptr) {
return;
}
EXIT_IF(graphics.device == nullptr || graphics.allocator == nullptr);
std::array<vk::DescriptorSetLayoutBinding, 2> bindings {};
for (uint32_t i = 0; i < bindings.size(); i++) {
bindings[i] = {i, vk::DescriptorType::eStorageBuffer, 1, vk::ShaderStageFlagBits::eCompute,
+4 -35
View File
@@ -16,18 +16,14 @@
#include "graphics/host_gpu/transfer.h"
#include "graphics/host_gpu/vma.h"
#include "graphics/host_gpu/vulkanCommon.h"
#include "graphics/presentation/window.h"
#include <algorithm>
#include <array>
#include <atomic>
#include <cstring>
#include <memory>
#include <mutex>
namespace Libs::Graphics {
static std::atomic<uint64_t> g_command_buffer_submit_seq = 0;
static bool g_render_initialized = false;
static std::mutex g_render_init_mutex;
static void RequireValidQueueId(int queue_id) {
EXIT_IF(queue_id < 0 || queue_id >= GraphicContext::QUEUES_NUM);
@@ -71,12 +67,7 @@ private:
static RenderContext* g_render_ctx = nullptr;
static thread_local CommandPool g_command_pool;
bool HasRenderContext() noexcept {
return g_render_ctx != nullptr;
}
RenderContext& GetRenderContext() {
EXIT_IF(g_render_ctx == nullptr);
RenderContext& GetRenderContext() noexcept {
return *g_render_ctx;
}
@@ -101,30 +92,12 @@ void FenceResourceRetainer::ReleaseAfterFence() noexcept {
m_resources.clear();
}
void GraphicsRenderInit() {
std::scoped_lock lock(g_render_init_mutex);
EXIT_IF(g_render_initialized || g_render_ctx != nullptr);
g_render_initialized = true;
void GraphicsRenderInit(GraphicContext& graphics) {
g_render_ctx = new RenderContext(graphics);
}
void GraphicsRenderReleaseThreadCommandPools() {
if (g_render_ctx != nullptr) {
g_command_pool.DeleteAll();
}
}
void GraphicsRenderCreateContext() {
std::scoped_lock lock(g_render_init_mutex);
EXIT_IF(!g_render_initialized);
if (g_render_ctx == nullptr) {
g_render_ctx = new RenderContext(WindowGetGraphicContext());
}
}
void GraphicsRenderSetContext(RenderContext& context) {
std::scoped_lock lock(g_render_init_mutex);
EXIT_IF(!g_render_initialized || g_render_ctx != nullptr);
g_render_ctx = &context;
g_command_pool.DeleteAll();
}
CommandBuffer::CommandBuffer(int queue)
@@ -139,7 +112,6 @@ void CommandPool::Create(int queue_id) {
auto*& pool = m_pools[queue_id];
EXIT_IF(pool != nullptr);
EXIT_IF(graphics.device == nullptr);
EXIT_IF(graphics.queues[queue_id].family == static_cast<uint32_t>(-1));
pool = new VulkanCommandPool;
@@ -204,8 +176,6 @@ void CommandPool::DeleteAll() {
for (auto& pool: m_pools) {
if (pool != nullptr) {
EXIT_IF(graphics.device == nullptr);
for (uint32_t i = 0; i < pool->buffers_count; i++) {
graphics.device.destroySemaphore(pool->semaphores[i], nullptr);
graphics.device.destroyFence(pool->fences[i], nullptr);
@@ -369,7 +339,6 @@ void CommandBuffer::Submit(vk::Semaphore wait_semaphore, vk::PipelineStageFlags
submit_info.pSignalSemaphores = has_signal ? &signal_semaphore : nullptr;
auto& graphics = GetRenderContext().GetGraphics();
EXIT_IF(graphics.device == nullptr);
const auto& queue = graphics.queues[m_queue];
auto result = graphics.device.resetFences(1, &fence);
+1 -4
View File
@@ -33,7 +33,6 @@ struct VulkanFramebuffer;
struct RenderDepthInfo;
struct RenderColorInfo;
class BufferCache;
class RenderContext;
struct HtileClearTarget {
uint64_t address = 0;
@@ -162,9 +161,7 @@ void RenderDrawIndexAuto(uint64_t submit_id, RenderCommandBuffer& buffer, uint32
void RenderDispatchDirect(uint64_t submit_id, RenderCommandBuffer& buffer, uint32_t thread_group_x,
uint32_t thread_group_y, uint32_t thread_group_z, uint32_t mode);
void GraphicsRenderInit();
void GraphicsRenderCreateContext();
void GraphicsRenderSetContext(RenderContext& context);
void GraphicsRenderInit(GraphicContext& graphics);
void GraphicsRenderReleaseThreadCommandPools();
[[nodiscard]] bool ResolveComputeImageClear(const ShaderComputeInputInfo& input, uint32_t group_x,
@@ -63,8 +63,7 @@ private:
std::vector<EopEqRegistration> m_eop_eqs;
};
[[nodiscard]] bool HasRenderContext() noexcept;
[[nodiscard]] RenderContext& GetRenderContext();
[[nodiscard]] RenderContext& GetRenderContext() noexcept;
} // namespace Libs::Graphics
@@ -303,12 +303,9 @@ static void LogDrawInputState(const RenderColorInfo& color,
}
}
static void VulkanCmdSetColorWriteEnableEXT(const RenderCommandBuffer& buffer,
vk::CommandBuffer command_buffer,
static void VulkanCmdSetColorWriteEnableEXT(vk::CommandBuffer command_buffer,
uint32_t attachment_count,
const vk::Bool32* p_color_write_enables) {
EXIT_IF(buffer.GetGraphics().device == nullptr);
if (VULKAN_HPP_DEFAULT_DISPATCHER.vkCmdSetColorWriteEnableEXT == nullptr) {
EXIT("vkCmdSetColorWriteEnableEXT not present\n");
}
@@ -413,7 +410,7 @@ static void SetDynamicParams(const RenderCommandBuffer& buffer, vk::CommandBuffe
for (uint32_t i = 0; i < dynamic_params.color_write_count; i++) {
enable[i] = (dynamic_params.color_write_enable[i] ? VK_TRUE : VK_FALSE);
}
VulkanCmdSetColorWriteEnableEXT(buffer, vk_buffer, dynamic_params.color_write_count, enable);
VulkanCmdSetColorWriteEnableEXT(vk_buffer, dynamic_params.color_write_count, enable);
}
static bool DrawHasValidVertexShader(const HW::Shader& sh_ctx) {
+10 -10
View File
@@ -52,20 +52,20 @@ struct ImageImageCopy {
explicit ImageImageCopy(VulkanImage& source): src_image(source) {}
VulkanImage& src_image;
uint32_t src_level;
uint32_t dst_level;
uint32_t width;
uint32_t height;
uint32_t src_level = 0;
uint32_t dst_level = 0;
uint32_t width = 0;
uint32_t height = 0;
uint32_t src_layer = 0;
uint32_t dst_layer = 0;
vk::ImageAspectFlags src_aspect = vk::ImageAspectFlagBits::eColor;
vk::ImageAspectFlags dst_aspect = vk::ImageAspectFlagBits::eColor;
int src_x;
int src_y;
int src_z = 0;
int dst_x;
int dst_y;
int dst_z = 0;
int src_x = 0;
int src_y = 0;
int src_z = 0;
int dst_x = 0;
int dst_y = 0;
int dst_z = 0;
};
namespace Transfer {