From 79680c50c085f45bd5a4ce01f52565d9a2c175d8 Mon Sep 17 00:00:00 2001 From: Vladislav Mikhalin Date: Wed, 21 Aug 2024 23:54:23 +0300 Subject: [PATCH] Misc fixes (#517) * Misc fixes * Removed the skip for draw calls without RTs * Remove Srgb image stores to rework later --- .../libraries/avplayer/avplayer_source.cpp | 3 ++ src/core/libraries/system/msgdialog.cpp | 21 ++++++++++++-- src/video_core/amdgpu/liverpool.h | 1 + .../renderer_vulkan/liverpool_to_vk.cpp | 28 +++++++++++-------- .../renderer_vulkan/vk_graphics_pipeline.cpp | 3 +- .../renderer_vulkan/vk_graphics_pipeline.h | 1 + .../renderer_vulkan/vk_pipeline_cache.cpp | 17 ++++++++++- .../renderer_vulkan/vk_rasterizer.cpp | 15 +++++++--- .../renderer_vulkan/vk_scheduler.cpp | 13 +++++++-- src/video_core/texture_cache/image.cpp | 14 ++++++++-- 10 files changed, 89 insertions(+), 27 deletions(-) diff --git a/src/core/libraries/avplayer/avplayer_source.cpp b/src/core/libraries/avplayer/avplayer_source.cpp index e05a2cdf..f5479870 100644 --- a/src/core/libraries/avplayer/avplayer_source.cpp +++ b/src/core/libraries/avplayer/avplayer_source.cpp @@ -366,6 +366,9 @@ bool AvPlayerSource::GetAudioData(SceAvPlayerFrameInfo& audio_info) { } u64 AvPlayerSource::CurrentTime() { + if (!IsActive()) { + return 0; + } using namespace std::chrono; return duration_cast(high_resolution_clock::now() - m_start_time).count(); } diff --git a/src/core/libraries/system/msgdialog.cpp b/src/core/libraries/system/msgdialog.cpp index 1c8653f5..452feec9 100644 --- a/src/core/libraries/system/msgdialog.cpp +++ b/src/core/libraries/system/msgdialog.cpp @@ -6,6 +6,8 @@ #include "core/libraries/libs.h" #include "core/libraries/system/msgdialog.h" +#include + namespace Libraries::MsgDialog { int PS4_SYSV_ABI sceMsgDialogClose() { @@ -30,9 +32,22 @@ int PS4_SYSV_ABI sceMsgDialogInitialize() { s32 PS4_SYSV_ABI sceMsgDialogOpen(const OrbisMsgDialogParam* param) { LOG_ERROR(Lib_MsgDlg, "(STUBBED) called"); - OrbisMsgDialogUserMessageParam* userMsgParam = param->userMsgParam; - const char* msg = userMsgParam->msg; - printf("sceMsgDialogOpen msg : %s", msg); + switch (param->mode) { + case ORBIS_MSG_DIALOG_MODE_USER_MSG: + LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen userMsg type = %s msg = %s", + magic_enum::enum_name(param->userMsgParam->buttonType), param->userMsgParam->msg); + break; + case ORBIS_MSG_DIALOG_MODE_PROGRESS_BAR: + LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen progressBar type = %s msg = %s", + magic_enum::enum_name(param->progBarParam->barType), param->progBarParam->msg); + break; + case ORBIS_MSG_DIALOG_MODE_SYSTEM_MSG: + LOG_INFO(Lib_MsgDlg, "sceMsgDialogOpen systemMsg type: %s", + magic_enum::enum_name(param->sysMsgParam->sysMsgType)); + break; + default: + break; + } return ORBIS_OK; } diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index 896927df..595c98f5 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -848,6 +848,7 @@ struct Liverpool { u32 raw; BitField<0, 1, u32> depth_clear_enable; BitField<1, 1, u32> stencil_clear_enable; + BitField<5, 1, u32> stencil_compress_disable; BitField<6, 1, u32> depth_compress_disable; }; diff --git a/src/video_core/renderer_vulkan/liverpool_to_vk.cpp b/src/video_core/renderer_vulkan/liverpool_to_vk.cpp index e86d0652..daf64a4d 100644 --- a/src/video_core/renderer_vulkan/liverpool_to_vk.cpp +++ b/src/video_core/renderer_vulkan/liverpool_to_vk.cpp @@ -5,6 +5,8 @@ #include "video_core/amdgpu/pixel_format.h" #include "video_core/renderer_vulkan/liverpool_to_vk.h" +#include + namespace Vulkan::LiverpoolToVK { using DepthBuffer = Liverpool::DepthBuffer; @@ -588,6 +590,8 @@ vk::Format AdjustColorBufferFormat(vk::Format base_format, return is_vo_surface ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb; case vk::Format::eB8G8R8A8Srgb: return is_vo_surface ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb; + default: + break; } } else { if (is_vo_surface && base_format == vk::Format::eR8G8B8A8Srgb) { @@ -601,27 +605,29 @@ vk::Format AdjustColorBufferFormat(vk::Format base_format, } vk::Format DepthFormat(DepthBuffer::ZFormat z_format, DepthBuffer::StencilFormat stencil_format) { - if (z_format == DepthBuffer::ZFormat::Z32Float && - stencil_format == DepthBuffer::StencilFormat::Stencil8) { + using ZFormat = DepthBuffer::ZFormat; + using StencilFormat = DepthBuffer::StencilFormat; + + if (z_format == ZFormat::Z32Float && stencil_format == StencilFormat::Stencil8) { return vk::Format::eD32SfloatS8Uint; } - if (z_format == DepthBuffer::ZFormat::Z32Float && - stencil_format == DepthBuffer::StencilFormat::Invalid) { + if (z_format == ZFormat::Z32Float && stencil_format == StencilFormat::Invalid) { return vk::Format::eD32Sfloat; } - if (z_format == DepthBuffer::ZFormat::Z16 && - stencil_format == DepthBuffer::StencilFormat::Invalid) { + if (z_format == ZFormat::Z16 && stencil_format == StencilFormat::Invalid) { return vk::Format::eD16Unorm; } - if (z_format == DepthBuffer::ZFormat::Z16 && - stencil_format == DepthBuffer::StencilFormat::Stencil8) { + if (z_format == ZFormat::Z16 && stencil_format == StencilFormat::Stencil8) { return vk::Format::eD16UnormS8Uint; } - if (z_format == DepthBuffer::ZFormat::Invalid && - stencil_format == DepthBuffer::StencilFormat::Invalid) { + if (z_format == ZFormat::Invalid && stencil_format == StencilFormat::Stencil8) { + return vk::Format::eD32SfloatS8Uint; + } + if (z_format == ZFormat::Invalid && stencil_format == StencilFormat::Invalid) { return vk::Format::eUndefined; } - UNREACHABLE(); + UNREACHABLE_MSG("Unsupported depth/stencil format. depth = {} stencil = {}", + magic_enum::enum_name(z_format), magic_enum::enum_name(stencil_format)); } void EmitQuadToTriangleListIndices(u8* out_ptr, u32 num_vertices) { diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index 887a6d87..c2649b96 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -214,8 +214,7 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul .colorAttachmentCount = num_color_formats, .pColorAttachmentFormats = key.color_formats.data(), .depthAttachmentFormat = key.depth_format, - .stencilAttachmentFormat = - key.depth.stencil_enable ? key.depth_format : vk::Format::eUndefined, + .stencilAttachmentFormat = key.stencil_format, }; std::array attachments; diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h index f7ea32d9..548e7d45 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h @@ -26,6 +26,7 @@ struct GraphicsPipelineKey { std::array stage_hashes; std::array color_formats; vk::Format depth_format; + vk::Format stencil_format; Liverpool::DepthControl depth; float depth_bounds_min; diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 617a7812..55f04bac 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -180,11 +180,26 @@ void PipelineCache::RefreshGraphicsKey() { key.num_samples = regs.aa_config.NumSamples(); const auto& db = regs.depth_buffer; - key.depth_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format); + const auto ds_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format); + + if (db.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid) { + key.depth_format = ds_format; + } else { + key.depth_format = vk::Format::eUndefined; + } if (key.depth.depth_enable) { key.depth.depth_enable.Assign(key.depth_format != vk::Format::eUndefined); } + if (db.stencil_info.format != AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid) { + key.stencil_format = key.depth_format; + } else { + key.stencil_format = vk::Format::eUndefined; + } + if (key.depth.stencil_enable) { + key.depth.stencil_enable.Assign(key.stencil_format != vk::Format::eUndefined); + } + const auto skip_cb_binding = regs.color_control.mode == AmdGpu::Liverpool::ColorControl::OperationMode::Disable; diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 9ec8fe21..6cd80393 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -10,6 +10,7 @@ #include "video_core/renderer_vulkan/vk_scheduler.h" #include "video_core/texture_cache/image_view.h" #include "video_core/texture_cache/texture_cache.h" +#include "vk_rasterizer.h" namespace Vulkan { @@ -129,8 +130,12 @@ void Rasterizer::BeginRendering() { texture_cache.TouchMeta(col_buf.CmaskAddress(), false); } - if (regs.depth_buffer.z_info.format != Liverpool::DepthBuffer::ZFormat::Invalid && - regs.depth_buffer.Address() != 0) { + using ZFormat = AmdGpu::Liverpool::DepthBuffer::ZFormat; + using StencilFormat = AmdGpu::Liverpool::DepthBuffer::StencilFormat; + if (regs.depth_buffer.Address() != 0 && + ((regs.depth_control.depth_enable && regs.depth_buffer.z_info.format != ZFormat::Invalid) || + regs.depth_control.stencil_enable && + regs.depth_buffer.stencil_info.format != StencilFormat::Invalid)) { const auto htile_address = regs.depth_htile_data_base.GetAddress(); const bool is_clear = regs.depth_render_control.depth_clear_enable || texture_cache.IsMetaCleared(htile_address); @@ -152,8 +157,10 @@ void Rasterizer::BeginRendering() { .stencil = regs.stencil_clear}}, }; texture_cache.TouchMeta(htile_address, false); - state.has_depth = true; - state.has_stencil = regs.depth_control.stencil_enable; + state.has_depth = + regs.depth_buffer.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid; + state.has_stencil = regs.depth_buffer.stencil_info.format != + AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid; } scheduler.BeginRendering(state); } diff --git a/src/video_core/renderer_vulkan/vk_scheduler.cpp b/src/video_core/renderer_vulkan/vk_scheduler.cpp index 10ee6ea6..ef0307ef 100644 --- a/src/video_core/renderer_vulkan/vk_scheduler.cpp +++ b/src/video_core/renderer_vulkan/vk_scheduler.cpp @@ -29,15 +29,22 @@ void Scheduler::BeginRendering(const RenderState& new_state) { is_rendering = true; render_state = new_state; + const auto witdh = + render_state.width != std::numeric_limits::max() ? render_state.width : 1; + const auto height = + render_state.height != std::numeric_limits::max() ? render_state.height : 1; + const vk::RenderingInfo rendering_info = { .renderArea = { .offset = {0, 0}, - .extent = {render_state.width, render_state.height}, + .extent = {witdh, height}, }, .layerCount = 1, .colorAttachmentCount = render_state.num_color_attachments, - .pColorAttachments = render_state.color_attachments.data(), + .pColorAttachments = render_state.num_color_attachments > 0 + ? render_state.color_attachments.data() + : nullptr, .pDepthAttachment = render_state.has_depth ? &render_state.depth_attachment : nullptr, .pStencilAttachment = render_state.has_stencil ? &render_state.depth_attachment : nullptr, }; @@ -72,7 +79,7 @@ void Scheduler::EndRendering() { }, }); } - if (render_state.has_depth) { + if (render_state.has_depth || render_state.has_stencil) { barriers.push_back(vk::ImageMemoryBarrier{ .srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite, .dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, diff --git a/src/video_core/texture_cache/image.cpp b/src/video_core/texture_cache/image.cpp index bae4b89d..528dda55 100644 --- a/src/video_core/texture_cache/image.cpp +++ b/src/video_core/texture_cache/image.cpp @@ -131,11 +131,19 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_, usage = ImageUsageFlags(info); - if (info.pixel_format == vk::Format::eD32Sfloat) { + switch (info.pixel_format) { + case vk::Format::eD16Unorm: + case vk::Format::eD32Sfloat: + case vk::Format::eX8D24UnormPack32: aspect_mask = vk::ImageAspectFlagBits::eDepth; - } - if (info.pixel_format == vk::Format::eD32SfloatS8Uint) { + break; + case vk::Format::eD16UnormS8Uint: + case vk::Format::eD24UnormS8Uint: + case vk::Format::eD32SfloatS8Uint: aspect_mask = vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil; + break; + default: + break; } const vk::ImageCreateInfo image_ci = {