mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 10:56:58 +02:00
graphics: cleanup
This commit is contained in:
@@ -100,6 +100,10 @@ CommandBuffer::CommandBuffer()
|
||||
: m_graphics(GetRenderContext().GetGraphics()), m_slot(g_command_pool.Allocate()),
|
||||
m_host_stream(m_graphics) {}
|
||||
|
||||
CommandBuffer::~CommandBuffer() {
|
||||
Release();
|
||||
}
|
||||
|
||||
void ThreadCommandPool::Create() {
|
||||
auto& graphics = GetRenderContext().GetGraphics();
|
||||
EXIT_IF(m_pool != nullptr || graphics.queue_family == static_cast<uint32_t>(-1));
|
||||
@@ -200,8 +204,11 @@ void CommandBuffer::Release() {
|
||||
EXIT_NOT_IMPLEMENTED(!IsInvalid());
|
||||
}
|
||||
|
||||
void CommandBuffer::DeleteAfterFence(VulkanBuffer& buffer) {
|
||||
m_delete_after_fence.push_back(&buffer);
|
||||
void CommandBuffer::RetireBufferAfterFence(std::unique_ptr<VulkanBuffer> buffer) {
|
||||
if (IsInvalid() || m_execute || buffer == nullptr || buffer->buffer == nullptr) {
|
||||
EXIT("cannot retire a buffer on an invalid or submitted command buffer\n");
|
||||
}
|
||||
m_retired_buffers.push_back(std::move(buffer));
|
||||
}
|
||||
|
||||
void CommandBuffer::RetainResourceUntilFence(std::shared_ptr<void> resource) {
|
||||
@@ -375,11 +382,10 @@ void CommandBuffer::ReleaseResourcesAfterFence() {
|
||||
}
|
||||
|
||||
void CommandBuffer::DeleteBuffersAfterFence() {
|
||||
for (auto* buffer: m_delete_after_fence) {
|
||||
for (const auto& buffer: m_retired_buffers) {
|
||||
GetRenderContext().GetGraphics().DeleteBuffer(*buffer);
|
||||
delete buffer;
|
||||
}
|
||||
m_delete_after_fence.clear();
|
||||
m_retired_buffers.clear();
|
||||
}
|
||||
|
||||
void CommandBuffer::BeginRenderPass(VulkanFramebuffer& framebuffer, RenderColorInfo* colors,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "graphics/guest_gpu/hardwareContext.h"
|
||||
#include "graphics/host_gpu/renderer/render.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cmath>
|
||||
#include <fmt/format.h>
|
||||
@@ -100,8 +101,6 @@ void sh_print(const char* func, const HW::Shader& /*uc*/) {
|
||||
LOGF("%s\n", func);
|
||||
}
|
||||
|
||||
void sh_check(const HW::Shader& /*uc*/) {}
|
||||
|
||||
std::vector<std::string> rt_print(const char* func, const HW::RenderTarget& rt) {
|
||||
std::vector<std::string> dst;
|
||||
dst.reserve(53);
|
||||
@@ -1135,10 +1134,10 @@ static ScissorRect ScissorRectClamp(ScissorRect r, uint32_t width, uint32_t heig
|
||||
int max_right = static_cast<int>(width);
|
||||
int max_bottom = static_cast<int>(height);
|
||||
|
||||
r.left = (r.left < 0 ? 0 : (r.left > max_right ? max_right : r.left));
|
||||
r.right = (r.right < 0 ? 0 : (r.right > max_right ? max_right : r.right));
|
||||
r.top = (r.top < 0 ? 0 : (r.top > max_bottom ? max_bottom : r.top));
|
||||
r.bottom = (r.bottom < 0 ? 0 : (r.bottom > max_bottom ? max_bottom : r.bottom));
|
||||
r.left = std::clamp(r.left, 0, max_right);
|
||||
r.right = std::clamp(r.right, 0, max_right);
|
||||
r.top = std::clamp(r.top, 0, max_bottom);
|
||||
r.bottom = std::clamp(r.bottom, 0, max_bottom);
|
||||
|
||||
if (!ScissorRectValid(r)) {
|
||||
r.right = r.left;
|
||||
|
||||
@@ -33,7 +33,6 @@ bool graphics_debug_dump_enabled();
|
||||
void uc_print(const char* func, const HW::UserConfig& uc);
|
||||
void uc_check(const HW::UserConfig& uc);
|
||||
void sh_print(const char* func, const HW::Shader& uc);
|
||||
void sh_check(const HW::Shader& uc);
|
||||
std::vector<std::string> rt_print(const char* func, const HW::RenderTarget& rt);
|
||||
bool RenderIsColorTileModeLinear(uint32_t tile_mode);
|
||||
void hw_print(const RenderCommandBuffer& buffer);
|
||||
|
||||
@@ -69,7 +69,7 @@ private:
|
||||
class CommandBuffer {
|
||||
public:
|
||||
CommandBuffer();
|
||||
~CommandBuffer() { Release(); }
|
||||
~CommandBuffer();
|
||||
|
||||
KYTY_CLASS_NO_COPY(CommandBuffer);
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
void WaitForFenceOnly();
|
||||
void WaitForFence();
|
||||
void WaitForFenceAndReset();
|
||||
void DeleteAfterFence(VulkanBuffer& buffer);
|
||||
void RetireBufferAfterFence(std::unique_ptr<VulkanBuffer> buffer);
|
||||
void RetainResourceUntilFence(std::shared_ptr<void> resource);
|
||||
void RecycleDescriptorAfterFence(VulkanDescriptorSet& set);
|
||||
|
||||
@@ -107,22 +107,22 @@ private:
|
||||
void DeleteBuffersAfterFence();
|
||||
void RecycleDescriptorsAfterFence();
|
||||
|
||||
GraphicContext& m_graphics;
|
||||
CommandSlot* m_slot = nullptr;
|
||||
bool m_execute = false;
|
||||
bool m_fence_waited = false;
|
||||
uint64_t m_submit_seq = 0;
|
||||
uint32_t m_debug_op = 0;
|
||||
uint64_t m_debug_submit_id = 0;
|
||||
uint32_t m_debug_arg0 = 0;
|
||||
uint32_t m_debug_arg1 = 0;
|
||||
uint32_t m_debug_arg2 = 0;
|
||||
uint32_t m_debug_arg3 = 0;
|
||||
uint64_t m_debug_arg4 = 0;
|
||||
std::vector<VulkanBuffer*> m_delete_after_fence;
|
||||
FenceResourceRetainer m_fence_resources;
|
||||
std::vector<VulkanDescriptorSet*> m_descriptor_sets_after_fence;
|
||||
HostStreamBuffer m_host_stream;
|
||||
GraphicContext& m_graphics;
|
||||
CommandSlot* m_slot = nullptr;
|
||||
bool m_execute = false;
|
||||
bool m_fence_waited = false;
|
||||
uint64_t m_submit_seq = 0;
|
||||
uint32_t m_debug_op = 0;
|
||||
uint64_t m_debug_submit_id = 0;
|
||||
uint32_t m_debug_arg0 = 0;
|
||||
uint32_t m_debug_arg1 = 0;
|
||||
uint32_t m_debug_arg2 = 0;
|
||||
uint32_t m_debug_arg3 = 0;
|
||||
uint64_t m_debug_arg4 = 0;
|
||||
std::vector<std::unique_ptr<VulkanBuffer>> m_retired_buffers;
|
||||
FenceResourceRetainer m_fence_resources;
|
||||
std::vector<VulkanDescriptorSet*> m_descriptor_sets_after_fence;
|
||||
HostStreamBuffer m_host_stream;
|
||||
};
|
||||
|
||||
class RenderCommandBuffer final: public CommandBuffer {
|
||||
|
||||
@@ -1120,7 +1120,6 @@ void RenderDrawIndex(uint64_t submit_id, RenderCommandBuffer& buffer, uint32_t i
|
||||
instance_count, render_target_slice_offset, static_cast<uint32_t>(vertex_offset_add),
|
||||
first_instance);
|
||||
}
|
||||
sh_check(sh_ctx);
|
||||
|
||||
uc_check(ucfg);
|
||||
|
||||
@@ -1248,7 +1247,6 @@ void RenderDrawIndexAuto(uint64_t submit_id, RenderCommandBuffer& buffer, uint32
|
||||
index_count, flags, render_target_slice_offset, instance_count, first_vertex,
|
||||
first_instance);
|
||||
}
|
||||
sh_check(sh_ctx);
|
||||
|
||||
uc_check(ucfg);
|
||||
|
||||
|
||||
@@ -620,10 +620,13 @@ void CreatePipelineInternal(PipelineCache::GraphicsPipeline& pipeline, vk::Rende
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
auto swizzle = vs_input_info.resources[index].DstSelXYZ();
|
||||
auto expected =
|
||||
(attr_size == 1 ? DstSel(4, 0, 0)
|
||||
: (attr_size == 2 ? DstSel(4, 5, 0) : DstSel(4, 5, 6)));
|
||||
auto swizzle = vs_input_info.resources[index].DstSelXYZ();
|
||||
auto expected = DstSel(4, 5, 6);
|
||||
switch (attr_size) {
|
||||
case 1: expected = DstSel(4, 0, 0); break;
|
||||
case 2: expected = DstSel(4, 5, 0); break;
|
||||
default: break;
|
||||
}
|
||||
if (swizzle != expected) {
|
||||
log_unsupported_vertex_swizzle(swizzle, expected);
|
||||
}
|
||||
|
||||
@@ -774,14 +774,16 @@ void CopyImage(CommandBuffer& buffer, std::span<const ImageImageCopy> regions,
|
||||
compressed_copy_size =
|
||||
std::max(compressed_copy_size, CompressedImageCopyBufferSize(r, dst_image));
|
||||
}
|
||||
VulkanBuffer* compressed_copy_buffer = nullptr;
|
||||
std::unique_ptr<VulkanBuffer> compressed_copy_owner;
|
||||
VulkanBuffer* compressed_copy_buffer = nullptr;
|
||||
if (compressed_copy_size != 0) {
|
||||
compressed_copy_buffer = new VulkanBuffer;
|
||||
compressed_copy_owner = std::make_unique<VulkanBuffer>();
|
||||
compressed_copy_buffer = compressed_copy_owner.get();
|
||||
compressed_copy_buffer->usage =
|
||||
vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst;
|
||||
compressed_copy_buffer->memory.property = {};
|
||||
buffer.GetGraphics().CreateBuffer(compressed_copy_size, *compressed_copy_buffer);
|
||||
buffer.DeleteAfterFence(*compressed_copy_buffer);
|
||||
buffer.RetireBufferAfterFence(std::move(compressed_copy_owner));
|
||||
}
|
||||
|
||||
for (const auto& r: regions) {
|
||||
@@ -850,13 +852,14 @@ void CopyImageViaBuffer(CommandBuffer& buffer, VulkanImage& src_image,
|
||||
std::min<uint64_t>(src_image.extent.height, MAX_COPY_BUFFER_SIZE / row_bytes));
|
||||
const auto copy_buffer_size = row_bytes * rows_per_chunk;
|
||||
|
||||
auto& graphics = buffer.GetGraphics();
|
||||
auto* copy_buffer = new VulkanBuffer;
|
||||
auto& graphics = buffer.GetGraphics();
|
||||
auto copy_buffer_owner = std::make_unique<VulkanBuffer>();
|
||||
auto* copy_buffer = copy_buffer_owner.get();
|
||||
copy_buffer->usage =
|
||||
vk::BufferUsageFlagBits::eTransferSrc | vk::BufferUsageFlagBits::eTransferDst;
|
||||
copy_buffer->memory.property = vk::MemoryPropertyFlagBits::eDeviceLocal;
|
||||
graphics.CreateBuffer(copy_buffer_size, *copy_buffer);
|
||||
buffer.DeleteAfterFence(*copy_buffer);
|
||||
buffer.RetireBufferAfterFence(std::move(copy_buffer_owner));
|
||||
|
||||
auto vk_buffer = buffer.Handle();
|
||||
const auto src_layout = src_image.layout;
|
||||
|
||||
Reference in New Issue
Block a user