mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 02:47:02 +02:00
fix eop/flipping
This commit is contained in:
@@ -29,7 +29,6 @@ struct VulkanSwapchain {
|
||||
std::unique_ptr<VkSemaphore[]> render_complete_semaphores;
|
||||
uint32_t current_index = 0;
|
||||
uint32_t present_frame = 0;
|
||||
std::vector<std::unique_ptr<CommandBuffer>> present_command_buffers;
|
||||
};
|
||||
|
||||
struct VulkanCommandPool {
|
||||
|
||||
@@ -330,7 +330,8 @@ void CommandBuffer::Execute() {
|
||||
queue.mutex->Unlock();
|
||||
}
|
||||
|
||||
m_execute = true;
|
||||
m_execute = true;
|
||||
m_fence_waited = false;
|
||||
m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
@@ -393,7 +394,8 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore signal_semaphore) {
|
||||
queue.mutex->Unlock();
|
||||
}
|
||||
|
||||
m_execute = true;
|
||||
m_execute = true;
|
||||
m_fence_waited = false;
|
||||
m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
@@ -460,7 +462,8 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore,
|
||||
queue.mutex->Unlock();
|
||||
}
|
||||
|
||||
m_execute = true;
|
||||
m_execute = true;
|
||||
m_fence_waited = false;
|
||||
m_submit_seq = g_command_buffer_submit_seq.fetch_add(1, std::memory_order_relaxed) + 1;
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
@@ -474,27 +477,11 @@ void CommandBuffer::ExecuteWithSemaphore(VkSemaphore wait_semaphore,
|
||||
}
|
||||
|
||||
void CommandBuffer::WaitForFence() {
|
||||
EXIT_IF(IsInvalid());
|
||||
|
||||
const bool was_executed = m_execute;
|
||||
if (m_execute) {
|
||||
auto* device = g_render_ctx->GetGraphicCtx()->device;
|
||||
|
||||
auto result = vkWaitForFences(device, 1, &m_pool->fences[m_index], VK_TRUE, UINT64_MAX);
|
||||
if (result != VK_SUCCESS) {
|
||||
LOGF("vkWaitForFences failed: %s (%d), wait=WaitForFence queue=%d index=%u "
|
||||
"submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64
|
||||
" args=%u,%u,%u,%u,0x%016" PRIx64 "\n",
|
||||
string_VkResult(result), static_cast<int>(result), m_queue, m_index, m_submit_seq,
|
||||
m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2,
|
||||
m_debug_arg3, m_debug_arg4);
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS);
|
||||
|
||||
m_execute = false;
|
||||
}
|
||||
|
||||
WaitForFenceOnly();
|
||||
if (was_executed) {
|
||||
m_execute = false;
|
||||
m_fence_waited = false;
|
||||
RecycleDescriptorsAfterFence();
|
||||
m_fence_resources.ReleaseAfterFence();
|
||||
}
|
||||
@@ -505,32 +492,34 @@ void CommandBuffer::WaitForFence() {
|
||||
m_delete_after_fence.clear();
|
||||
}
|
||||
|
||||
void CommandBuffer::WaitForFenceAndReset() {
|
||||
void CommandBuffer::WaitForFenceOnly() {
|
||||
EXIT_IF(IsInvalid());
|
||||
if (!m_execute || m_fence_waited) {
|
||||
return;
|
||||
}
|
||||
auto* device = g_render_ctx->GetGraphicCtx()->device;
|
||||
auto result = vkWaitForFences(device, 1, &m_pool->fences[m_index], VK_TRUE, UINT64_MAX);
|
||||
if (result != VK_SUCCESS) {
|
||||
LOGF("vkWaitForFences failed: %s (%d), queue=%d index=%u submit_seq=%" PRIu64
|
||||
" debug_op=%u debug_submit=%" PRIu64 " args=%u,%u,%u,%u,0x%016" PRIx64 "\n",
|
||||
string_VkResult(result), static_cast<int>(result), m_queue, m_index, m_submit_seq,
|
||||
m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2, m_debug_arg3,
|
||||
m_debug_arg4);
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS);
|
||||
m_fence_waited = true;
|
||||
}
|
||||
|
||||
void CommandBuffer::WaitForFenceAndReset() {
|
||||
const bool was_executed = m_execute;
|
||||
if (m_execute) {
|
||||
auto* device = g_render_ctx->GetGraphicCtx()->device;
|
||||
|
||||
auto result = vkWaitForFences(device, 1, &m_pool->fences[m_index], VK_TRUE, UINT64_MAX);
|
||||
if (result != VK_SUCCESS) {
|
||||
LOGF("vkWaitForFences failed: %s (%d), wait=WaitForFenceAndReset queue=%d index=%u "
|
||||
"submit_seq=%" PRIu64 " debug_op=%u debug_submit=%" PRIu64
|
||||
" args=%u,%u,%u,%u,0x%016" PRIx64 "\n",
|
||||
string_VkResult(result), static_cast<int>(result), m_queue, m_index, m_submit_seq,
|
||||
m_debug_op, m_debug_submit_id, m_debug_arg0, m_debug_arg1, m_debug_arg2,
|
||||
m_debug_arg3, m_debug_arg4);
|
||||
}
|
||||
EXIT_NOT_IMPLEMENTED(result != VK_SUCCESS);
|
||||
|
||||
m_execute = false;
|
||||
|
||||
WaitForFenceOnly();
|
||||
if (was_executed) {
|
||||
m_execute = false;
|
||||
m_fence_waited = false;
|
||||
vkResetCommandBuffer(m_pool->buffers[m_index],
|
||||
VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
|
||||
}
|
||||
|
||||
m_host_stream.Reset();
|
||||
|
||||
if (was_executed) {
|
||||
RecycleDescriptorsAfterFence();
|
||||
m_fence_resources.ReleaseAfterFence();
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
void BeginRenderPass(VulkanFramebuffer* framebuffer, RenderColorInfo* colors,
|
||||
uint32_t color_count, RenderDepthInfo* depth) const;
|
||||
void EndRenderPass() const;
|
||||
void WaitForFenceOnly();
|
||||
void WaitForFence();
|
||||
void WaitForFenceAndReset();
|
||||
void DeleteAfterFence(VulkanBuffer* buffer);
|
||||
@@ -96,6 +97,7 @@ private:
|
||||
uint32_t m_index = static_cast<uint32_t>(-1);
|
||||
int m_queue = -1;
|
||||
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;
|
||||
@@ -150,14 +152,18 @@ void GraphicsRenderWriteAtEndOfPipe32(uint64_t submit_id, CommandBuffer* buffer,
|
||||
void GraphicsRenderWriteAtEndOfPipeGds32(uint64_t submit_id, CommandBuffer* buffer,
|
||||
uint32_t* dst_gpu_addr, uint32_t dw_offset,
|
||||
uint32_t dw_num);
|
||||
uint64_t GraphicsRenderPrepareDisplayBufferFlip(CommandBuffer* buffer, int handle, int index,
|
||||
int flip_mode, int64_t flip_arg);
|
||||
void GraphicsRenderWriteAtEndOfPipeWithInterruptWriteBackFlip32(
|
||||
uint64_t submit_id, CommandBuffer* buffer, uint32_t* dst_gpu_addr, uint32_t value, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg);
|
||||
int index, int flip_mode, int64_t flip_arg, uint64_t request_id);
|
||||
void GraphicsRenderWriteAtEndOfPipeWithFlip32(uint64_t submit_id, CommandBuffer* buffer,
|
||||
uint32_t* dst_gpu_addr, uint32_t value, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg);
|
||||
int index, int flip_mode, int64_t flip_arg,
|
||||
uint64_t request_id);
|
||||
void GraphicsRenderWriteAtEndOfPipeOnlyFlip(uint64_t submit_id, CommandBuffer* buffer, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg);
|
||||
int index, int flip_mode, int64_t flip_arg,
|
||||
uint64_t request_id);
|
||||
void GraphicsRenderWriteAtEndOfPipeWithWriteBack64(uint64_t submit_id, CommandBuffer* buffer,
|
||||
uint64_t* dst_gpu_addr, uint64_t value);
|
||||
void GraphicsRenderWriteAtEndOfPipeWithWriteBack32(uint64_t submit_id, CommandBuffer* buffer,
|
||||
|
||||
@@ -84,30 +84,12 @@ static void PublishImmediateFence(T* dst, T value) {
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
|
||||
static void SubmitDisplayBufferFlip(const uint64_t* args) {
|
||||
if (g_render_ctx == nullptr || args == nullptr) {
|
||||
EXIT("GPU flip submission has invalid state, render_ctx=%p args=%p\n",
|
||||
static_cast<const void*>(g_render_ctx), static_cast<const void*>(args));
|
||||
}
|
||||
const auto handle = static_cast<int>(args[0]);
|
||||
const auto index = static_cast<int>(args[1]);
|
||||
const auto flip_mode = static_cast<int>(args[2]);
|
||||
const auto flip_arg = static_cast<int64_t>(args[3]);
|
||||
const auto result =
|
||||
Presentation::DisplayBufferSubmitFlipFromGpu(handle, index, flip_mode, flip_arg);
|
||||
if (result != 0) {
|
||||
EXIT("GPU flip submission failed, result=%d handle=%d index=%d mode=%d arg=%" PRId64 "\n",
|
||||
result, handle, index, flip_mode, flip_arg);
|
||||
}
|
||||
}
|
||||
|
||||
static bool CompleteDisplayBufferFlip(const uint64_t* args) {
|
||||
if (g_render_ctx == nullptr || args == nullptr) {
|
||||
EXIT("GPU flip completion has invalid state, render_ctx=%p args=%p\n",
|
||||
static_cast<const void*>(g_render_ctx), static_cast<const void*>(args));
|
||||
}
|
||||
Presentation::DisplayBufferCompleteFlipFromGpu(static_cast<int>(args[0]),
|
||||
static_cast<int>(args[1]));
|
||||
Presentation::DisplayBufferCompleteFlipFromGpu(args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -348,9 +330,28 @@ void GraphicsRenderWriteAtEndOfPipeWithInterrupt32(uint64_t submit_id, CommandBu
|
||||
args);
|
||||
}
|
||||
|
||||
uint64_t GraphicsRenderPrepareDisplayBufferFlip(CommandBuffer* buffer, int handle, int index,
|
||||
int flip_mode, int64_t flip_arg) {
|
||||
for (;;) {
|
||||
uint64_t request_id = 0;
|
||||
const auto result = Presentation::DisplayBufferSubmitFlipFromGpu(
|
||||
buffer, handle, index, flip_mode, flip_arg, &request_id);
|
||||
if (result == OK) {
|
||||
EXIT_IF(request_id == 0);
|
||||
return request_id;
|
||||
}
|
||||
if (result != VideoOut::VIDEO_OUT_ERROR_FLIP_QUEUE_FULL) {
|
||||
EXIT("GPU flip submission failed, result=%d handle=%d index=%d mode=%d arg=%" PRId64
|
||||
"\n",
|
||||
result, handle, index, flip_mode, flip_arg);
|
||||
}
|
||||
Presentation::DisplayBufferWaitForFlipQueueSlot();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsRenderWriteAtEndOfPipeWithInterruptWriteBackFlip32(
|
||||
uint64_t submit_id, CommandBuffer* buffer, uint32_t* dst_gpu_addr, uint32_t value, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg) {
|
||||
int index, int flip_mode, int64_t flip_arg, uint64_t request_id) {
|
||||
EXIT_IF(g_render_ctx == nullptr);
|
||||
EXIT_IF(dst_gpu_addr == nullptr);
|
||||
EXIT_IF(buffer == nullptr);
|
||||
@@ -361,11 +362,7 @@ void GraphicsRenderWriteAtEndOfPipeWithInterruptWriteBackFlip32(
|
||||
static_cast<uint32_t>(flip_mode), value, static_cast<uint64_t>(flip_arg));
|
||||
PublishImmediateFence(dst_gpu_addr, value);
|
||||
|
||||
uint64_t args[LABEL_ARGS_MAX] = {static_cast<uint64_t>(handle), static_cast<uint64_t>(index),
|
||||
static_cast<uint64_t>(flip_mode),
|
||||
static_cast<uint64_t>(flip_arg)};
|
||||
|
||||
SubmitDisplayBufferFlip(args);
|
||||
const uint64_t args[LABEL_ARGS_MAX] = {request_id};
|
||||
SubmitLabel32(
|
||||
buffer, nullptr, 0, CompleteDisplayBufferFlip,
|
||||
[](const uint64_t* /*args*/) {
|
||||
@@ -378,7 +375,8 @@ void GraphicsRenderWriteAtEndOfPipeWithInterruptWriteBackFlip32(
|
||||
|
||||
void GraphicsRenderWriteAtEndOfPipeWithFlip32(uint64_t submit_id, CommandBuffer* buffer,
|
||||
uint32_t* dst_gpu_addr, uint32_t value, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg) {
|
||||
int index, int flip_mode, int64_t flip_arg,
|
||||
uint64_t request_id) {
|
||||
EXIT_IF(g_render_ctx == nullptr);
|
||||
EXIT_IF(dst_gpu_addr == nullptr);
|
||||
EXIT_IF(buffer == nullptr);
|
||||
@@ -389,16 +387,13 @@ void GraphicsRenderWriteAtEndOfPipeWithFlip32(uint64_t submit_id, CommandBuffer*
|
||||
static_cast<uint32_t>(flip_mode), value, static_cast<uint64_t>(flip_arg));
|
||||
PublishImmediateFence(dst_gpu_addr, value);
|
||||
|
||||
uint64_t args[LABEL_ARGS_MAX] = {static_cast<uint64_t>(handle), static_cast<uint64_t>(index),
|
||||
static_cast<uint64_t>(flip_mode),
|
||||
static_cast<uint64_t>(flip_arg)};
|
||||
|
||||
SubmitDisplayBufferFlip(args);
|
||||
const uint64_t args[LABEL_ARGS_MAX] = {request_id};
|
||||
SubmitLabel32(buffer, nullptr, 0, CompleteDisplayBufferFlip, nullptr, args);
|
||||
}
|
||||
|
||||
void GraphicsRenderWriteAtEndOfPipeOnlyFlip(uint64_t submit_id, CommandBuffer* buffer, int handle,
|
||||
int index, int flip_mode, int64_t flip_arg) {
|
||||
int index, int flip_mode, int64_t flip_arg,
|
||||
uint64_t request_id) {
|
||||
EXIT_IF(g_render_ctx == nullptr);
|
||||
EXIT_IF(buffer == nullptr);
|
||||
EXIT_IF(buffer->IsInvalid());
|
||||
@@ -407,11 +402,7 @@ void GraphicsRenderWriteAtEndOfPipeOnlyFlip(uint64_t submit_id, CommandBuffer* b
|
||||
static_cast<uint32_t>(handle), static_cast<uint32_t>(index),
|
||||
static_cast<uint32_t>(flip_mode), 0, static_cast<uint64_t>(flip_arg));
|
||||
|
||||
uint64_t args[LABEL_ARGS_MAX] = {static_cast<uint64_t>(handle), static_cast<uint64_t>(index),
|
||||
static_cast<uint64_t>(flip_mode),
|
||||
static_cast<uint64_t>(flip_arg)};
|
||||
|
||||
SubmitDisplayBufferFlip(args);
|
||||
const uint64_t args[LABEL_ARGS_MAX] = {request_id};
|
||||
SubmitLabel32(buffer, nullptr, 0, CompleteDisplayBufferFlip, nullptr, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -863,17 +863,21 @@ void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanI
|
||||
final_layout);
|
||||
}
|
||||
|
||||
void UtilBlitImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchain* dst_swapchain) {
|
||||
void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image,
|
||||
VulkanSwapchain* dst_swapchain) {
|
||||
auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()];
|
||||
if (src_image->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) {
|
||||
EXIT("invalid prepared presentation image, image=%p vk_image=%p layout=%d\n",
|
||||
static_cast<const void*>(src_image),
|
||||
src_image != nullptr ? static_cast<void*>(src_image->image) : nullptr,
|
||||
src_image != nullptr ? static_cast<int>(src_image->layout) : -1);
|
||||
}
|
||||
|
||||
VulkanImage swapchain_image(VulkanImageType::Unknown);
|
||||
|
||||
swapchain_image.image = dst_swapchain->swapchain_images[dst_swapchain->current_index];
|
||||
swapchain_image.layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
|
||||
auto src_layout = src_image->layout;
|
||||
SetImageLayout(vk_buffer, src_image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT, src_layout,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
SetImageLayout(vk_buffer, &swapchain_image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
@@ -902,9 +906,18 @@ void UtilBlitImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchai
|
||||
vkCmdBlitImage(vk_buffer, src_image->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
swapchain_image.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion,
|
||||
VK_FILTER_LINEAR);
|
||||
}
|
||||
|
||||
SetImageLayout(vk_buffer, src_image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
void UtilClearColorImage(CommandBuffer* buffer, VulkanImage* image,
|
||||
const VkClearColorValue& color) {
|
||||
auto* vk_buffer = buffer->GetPool()->buffers[buffer->GetIndex()];
|
||||
SetImageLayout(vk_buffer, image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT, image->layout,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
const VkImageSubresourceRange range {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
vkCmdClearColorImage(vk_buffer, image->image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &color, 1,
|
||||
&range);
|
||||
SetImageLayout(vk_buffer, image, 0, 1, VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
}
|
||||
|
||||
void VulkanCreateBuffer(GraphicContext* gctx, uint64_t size, VulkanBuffer* buffer) {
|
||||
|
||||
@@ -90,7 +90,10 @@ void UtilCopyImageWithBuffer(CommandBuffer* buffer, GraphicContext* ctx, VulkanI
|
||||
VkImageAspectFlags src_aspect, VulkanImage* dst_image,
|
||||
VkImageAspectFlags dst_aspect, uint32_t bytes_per_element,
|
||||
uint64_t dst_layout);
|
||||
void UtilBlitImage(CommandBuffer* buffer, VulkanImage* src_image, VulkanSwapchain* dst_swapchain);
|
||||
void UtilBlitPreparedImage(CommandBuffer* buffer, VulkanImage* src_image,
|
||||
VulkanSwapchain* dst_swapchain);
|
||||
void UtilClearColorImage(CommandBuffer* buffer, VulkanImage* image,
|
||||
const VkClearColorValue& color);
|
||||
void UtilFillImage(GraphicContext* ctx, VulkanImage* dst_image, const void* src_data, uint64_t size,
|
||||
uint32_t src_pitch, uint64_t dst_layout);
|
||||
void UtilFillImage(GraphicContext* ctx, DepthStencilVulkanImage* dst_image, const void* src_data,
|
||||
|
||||
Reference in New Issue
Block a user