Skip to content

Commit 49e3455

Browse files
committed
Vk: allow to record overlays
1 parent 6530326 commit 49e3455

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

rpcs3/Emu/RSX/VK/VKFramebuffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace vk
2929
vk::framebuffer_holder* get_framebuffer(VkDevice dev, u16 width, u16 height, VkBool32 has_input_attachments, VkRenderPass renderpass, const std::vector<vk::image*>& image_list)
3030
{
3131
framebuffer_storage_key key(width, height, has_input_attachments);
32-
auto &queue = g_framebuffers_cache[key.encoded];
32+
auto& queue = g_framebuffers_cache[key.encoded];
3333

34-
for (auto &fbo : queue)
34+
for (const auto& fbo : queue)
3535
{
3636
if (fbo->matches(image_list, width, height))
3737
{
@@ -42,7 +42,7 @@ namespace vk
4242
std::vector<std::unique_ptr<vk::image_view>> image_views;
4343
image_views.reserve(image_list.size());
4444

45-
for (auto &e : image_list)
45+
for (const auto& e : image_list)
4646
{
4747
const VkImageSubresourceRange subres = { e->aspect(), 0, 1, 0, 1 };
4848
image_views.push_back(std::make_unique<vk::image_view>(dev, e, VK_IMAGE_VIEW_TYPE_2D, vk::default_component_map, subres));
@@ -58,9 +58,9 @@ namespace vk
5858
vk::framebuffer_holder* get_framebuffer(VkDevice dev, u16 width, u16 height, VkBool32 has_input_attachments, VkRenderPass renderpass, VkFormat format, VkImage attachment)
5959
{
6060
framebuffer_storage_key key(width, height, has_input_attachments);
61-
auto &queue = g_framebuffers_cache[key.encoded];
61+
auto& queue = g_framebuffers_cache[key.encoded];
6262

63-
for (const auto &e : queue)
63+
for (const auto& e : queue)
6464
{
6565
if (e->attachments[0]->info.image == attachment)
6666
{

rpcs3/Emu/RSX/VK/VKPresent.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,21 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
658658
}
659659
}
660660

661+
const bool has_overlay = (m_overlay_manager && m_overlay_manager->has_visible());
662+
const auto render_overlays = [&](vk::framebuffer_holder* fbo, const areau& area)
663+
{
664+
if (!has_overlay) return;
665+
666+
// Lock to avoid modification during run-update chain
667+
auto ui_renderer = vk::get_overlay_pass<vk::ui_overlay_renderer>();
668+
std::lock_guard lock(*m_overlay_manager);
669+
670+
for (const auto& view : m_overlay_manager->get_views())
671+
{
672+
ui_renderer->run(*m_current_command_buffer, area, fbo, single_target_pass, m_texture_upload_buffer_ring_info, *view.get());
673+
}
674+
};
675+
661676
if (image_to_flip)
662677
{
663678
const bool use_full_rgb_range_output = g_cfg.video.full_rgb_range_output.get();
@@ -744,17 +759,42 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
744759
copy_info.imageExtent.height = buffer_height;
745760
copy_info.imageExtent.depth = 1;
746761

747-
image_to_flip->push_layout(*m_current_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
748-
vk::copy_image_to_buffer(*m_current_command_buffer, image_to_flip, &sshot_vkbuf, copy_info);
749-
image_to_flip->pop_layout(*m_current_command_buffer);
762+
std::unique_ptr<vk::image> tmp_tex;
763+
vk::image* image_to_copy = image_to_flip;
764+
765+
if (g_cfg.video.record_with_overlays && has_overlay)
766+
{
767+
const auto key = vk::get_renderpass_key(m_swapchain->get_surface_format());
768+
single_target_pass = vk::get_renderpass(*m_device, key);
769+
ensure(single_target_pass != VK_NULL_HANDLE);
770+
771+
tmp_tex = std::make_unique<vk::image>(*m_device, m_device->get_memory_mapping().device_local, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
772+
image_to_flip->type(), image_to_flip->format(), image_to_flip->width(), image_to_flip->height(), 1, 1, image_to_flip->layers(), VK_SAMPLE_COUNT_1_BIT, image_to_flip->current_layout,
773+
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
774+
0, VMM_ALLOCATION_POOL_UNDEFINED);
775+
776+
const areai rect = areai(0, 0, buffer_width, buffer_height);
777+
vk::copy_image(*m_current_command_buffer, image_to_flip, tmp_tex.get(), rect, rect, 1);
778+
779+
vk::framebuffer_holder* sshot_fbo = vk::get_framebuffer(*m_device, buffer_width, buffer_height, VK_FALSE, single_target_pass, { tmp_tex.get() });
780+
sshot_fbo->add_ref();
781+
render_overlays(sshot_fbo, areau(rect));
782+
sshot_fbo->release();
783+
784+
image_to_copy = tmp_tex.get();
785+
}
786+
787+
image_to_copy->push_layout(*m_current_command_buffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
788+
vk::copy_image_to_buffer(*m_current_command_buffer, image_to_copy, &sshot_vkbuf, copy_info);
789+
image_to_copy->pop_layout(*m_current_command_buffer);
750790

751791
flush_command_queue(true);
752792
const auto src = sshot_vkbuf.map(0, sshot_size);
753793
std::vector<u8> sshot_frame(sshot_size);
754794
memcpy(sshot_frame.data(), src, sshot_size);
755795
sshot_vkbuf.unmap();
756796

757-
const bool is_bgra = image_to_flip->format() == VK_FORMAT_B8G8R8A8_UNORM;
797+
const bool is_bgra = image_to_copy->format() == VK_FORMAT_B8G8R8A8_UNORM;
758798

759799
if (g_user_asked_for_screenshot.exchange(false))
760800
{
@@ -767,7 +807,6 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
767807
}
768808
}
769809

770-
const bool has_overlay = (m_overlay_manager && m_overlay_manager->has_visible());
771810
if (g_cfg.video.debug_overlay || has_overlay)
772811
{
773812
if (target_layout != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
@@ -799,17 +838,7 @@ void VKGSRender::flip(const rsx::display_flip_info_t& info)
799838

800839
direct_fbo->add_ref();
801840

802-
if (has_overlay)
803-
{
804-
// Lock to avoid modification during run-update chain
805-
auto ui_renderer = vk::get_overlay_pass<vk::ui_overlay_renderer>();
806-
std::lock_guard lock(*m_overlay_manager);
807-
808-
for (const auto& view : m_overlay_manager->get_views())
809-
{
810-
ui_renderer->run(*m_current_command_buffer, areau(aspect_ratio), direct_fbo, single_target_pass, m_texture_upload_buffer_ring_info, *view.get());
811-
}
812-
}
841+
render_overlays(direct_fbo, areau(aspect_ratio));
813842

814843
if (g_cfg.video.debug_overlay)
815844
{

rpcs3/Emu/RSX/VK/vkutils/framebuffer_object.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,35 @@ namespace vk
4747
vkDestroyFramebuffer(m_device, value, nullptr);
4848
}
4949

50-
u32 width()
50+
u32 width() const
5151
{
5252
return m_width;
5353
}
5454

55-
u32 height()
55+
u32 height() const
5656
{
5757
return m_height;
5858
}
5959

60-
u8 samples()
60+
u8 samples() const
6161
{
6262
ensure(!attachments.empty());
6363
return attachments[0]->image()->samples();
6464
}
6565

66-
VkFormat format()
66+
VkFormat format() const
6767
{
6868
ensure(!attachments.empty());
6969
return attachments[0]->image()->format();
7070
}
7171

72-
VkFormat depth_format()
72+
VkFormat depth_format() const
7373
{
7474
ensure(!attachments.empty());
7575
return attachments.back()->image()->format();
7676
}
7777

78-
bool matches(const std::vector<vk::image*>& fbo_images, u32 width, u32 height)
78+
bool matches(const std::vector<vk::image*>& fbo_images, u32 width, u32 height) const
7979
{
8080
if (m_width != width || m_height != height)
8181
return false;

0 commit comments

Comments
 (0)