aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/video_core
diff options
context:
space:
mode:
authorLiam <[email protected]>2024-01-22 12:40:50 -0500
committerLiam <[email protected]>2024-01-31 11:27:21 -0500
commita595e9e8a7a6a742481b1cd05455d3c639095413 (patch)
tree03f8dfaec328171c42b090988e93c51e8d726eda /src/video_core
parent10cf0585180bcf2eab38ebf65dc593fecc4ddf92 (diff)
downloadyuzu-android-a595e9e8a7a6a742481b1cd05455d3c639095413.tar.gz
yuzu-android-a595e9e8a7a6a742481b1cd05455d3c639095413.zip
nvnflinger/gpu: implement layer stack composition
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/framebuffer_config.h3
-rw-r--r--src/video_core/gpu.cpp29
-rw-r--r--src/video_core/gpu.h4
-rw-r--r--src/video_core/gpu_thread.cpp6
-rw-r--r--src/video_core/gpu_thread.h15
-rw-r--r--src/video_core/renderer_base.h2
-rw-r--r--src/video_core/renderer_null/renderer_null.cpp4
-rw-r--r--src/video_core/renderer_null/renderer_null.h2
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp12
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.h4
-rw-r--r--src/video_core/renderer_vulkan/present/util.cpp78
-rw-r--r--src/video_core/renderer_vulkan/present/util.h4
-rw-r--r--src/video_core/renderer_vulkan/renderer_vulkan.cpp167
-rw-r--r--src/video_core/renderer_vulkan/renderer_vulkan.h4
-rw-r--r--src/video_core/renderer_vulkan/vk_blit_screen.cpp2
-rw-r--r--src/video_core/renderer_vulkan/vk_blit_screen.h2
16 files changed, 140 insertions, 198 deletions
diff --git a/src/video_core/framebuffer_config.h b/src/video_core/framebuffer_config.h
index 10ddc75a7..6a18b76fb 100644
--- a/src/video_core/framebuffer_config.h
+++ b/src/video_core/framebuffer_config.h
@@ -7,6 +7,7 @@
#include "common/math_util.h"
#include "core/hle/service/nvnflinger/buffer_transform_flags.h"
#include "core/hle/service/nvnflinger/pixel_format.h"
+#include "core/hle/service/nvnflinger/ui/fence.h"
namespace Tegra {
@@ -21,7 +22,7 @@ struct FramebufferConfig {
u32 stride{};
Service::android::PixelFormat pixel_format{};
Service::android::BufferTransformFlags transform_flags{};
- Common::Rectangle<int> crop_rect;
+ Common::Rectangle<int> crop_rect{};
};
Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width,
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 609704b33..f4a5d831c 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -274,11 +274,6 @@ struct GPU::Impl {
}
}
- /// Swap buffers (render frame)
- void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- gpu_thread.SwapBuffers(framebuffer);
- }
-
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
void FlushRegion(DAddr addr, u64 size) {
gpu_thread.FlushRegion(addr, size);
@@ -313,8 +308,9 @@ struct GPU::Impl {
gpu_thread.FlushAndInvalidateRegion(addr, size);
}
- void RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
- std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences) {
+ void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
+ std::vector<Service::Nvidia::NvFence>&& fences) {
+ size_t num_fences{fences.size()};
size_t current_request_counter{};
{
std::unique_lock<std::mutex> lk(request_swap_mutex);
@@ -328,13 +324,12 @@ struct GPU::Impl {
}
}
const auto wait_fence =
- RequestSyncOperation([this, current_request_counter, framebuffer, fences, num_fences] {
+ RequestSyncOperation([this, current_request_counter, &layers, &fences, num_fences] {
auto& syncpoint_manager = host1x.GetSyncpointManager();
if (num_fences == 0) {
- renderer->SwapBuffers(framebuffer);
+ renderer->Composite(layers);
}
- const auto executer = [this, current_request_counter,
- framebuffer_copy = *framebuffer]() {
+ const auto executer = [this, current_request_counter, layers_copy = layers]() {
{
std::unique_lock<std::mutex> lk(request_swap_mutex);
if (--request_swap_counters[current_request_counter] != 0) {
@@ -342,7 +337,7 @@ struct GPU::Impl {
}
free_swap_counters.push_back(current_request_counter);
}
- renderer->SwapBuffers(&framebuffer_copy);
+ renderer->Composite(layers_copy);
};
for (size_t i = 0; i < num_fences; i++) {
syncpoint_manager.RegisterGuestAction(fences[i].id, fences[i].value, executer);
@@ -505,9 +500,9 @@ const VideoCore::ShaderNotify& GPU::ShaderNotify() const {
return impl->ShaderNotify();
}
-void GPU::RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
- std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences) {
- impl->RequestSwapBuffers(framebuffer, fences, num_fences);
+void GPU::RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
+ std::vector<Service::Nvidia::NvFence>&& fences) {
+ impl->RequestComposite(std::move(layers), std::move(fences));
}
u64 GPU::GetTicks() const {
@@ -554,10 +549,6 @@ void GPU::ClearCdmaInstance(u32 id) {
impl->ClearCdmaInstance(id);
}
-void GPU::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- impl->SwapBuffers(framebuffer);
-}
-
VideoCore::RasterizerDownloadArea GPU::OnCPURead(PAddr addr, u64 size) {
return impl->OnCPURead(addr, size);
}
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index b3c1d15bd..c4602ca37 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -212,8 +212,8 @@ public:
void RendererFrameEndNotify();
- void RequestSwapBuffers(const Tegra::FramebufferConfig* framebuffer,
- std::array<Service::Nvidia::NvFence, 4>& fences, size_t num_fences);
+ void RequestComposite(std::vector<Tegra::FramebufferConfig>&& layers,
+ std::vector<Service::Nvidia::NvFence>&& fences);
/// Performs any additional setup necessary in order to begin GPU emulation.
/// This can be used to launch any necessary threads and register any necessary
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index 788d4f61e..58d8110b8 100644
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -40,8 +40,6 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
}
if (auto* submit_list = std::get_if<SubmitListCommand>(&next.data)) {
scheduler.Push(submit_list->channel, std::move(submit_list->entries));
- } else if (const auto* data = std::get_if<SwapBuffersCommand>(&next.data)) {
- renderer.SwapBuffers(data->framebuffer ? &*data->framebuffer : nullptr);
} else if (std::holds_alternative<GPUTickCommand>(next.data)) {
system.GPU().TickWork();
} else if (const auto* flush = std::get_if<FlushRegionCommand>(&next.data)) {
@@ -78,10 +76,6 @@ void ThreadManager::SubmitList(s32 channel, Tegra::CommandList&& entries) {
PushCommand(SubmitListCommand(channel, std::move(entries)));
}
-void ThreadManager::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- PushCommand(SwapBuffersCommand(framebuffer ? std::make_optional(*framebuffer) : std::nullopt));
-}
-
void ThreadManager::FlushRegion(DAddr addr, u64 size) {
if (!is_async) {
// Always flush with synchronous GPU mode
diff --git a/src/video_core/gpu_thread.h b/src/video_core/gpu_thread.h
index 2de25e9ef..dc0fce9f8 100644
--- a/src/video_core/gpu_thread.h
+++ b/src/video_core/gpu_thread.h
@@ -44,14 +44,6 @@ struct SubmitListCommand final {
Tegra::CommandList entries;
};
-/// Command to signal to the GPU thread that a swap buffers is pending
-struct SwapBuffersCommand final {
- explicit SwapBuffersCommand(std::optional<const Tegra::FramebufferConfig> framebuffer_)
- : framebuffer{std::move(framebuffer_)} {}
-
- std::optional<Tegra::FramebufferConfig> framebuffer;
-};
-
/// Command to signal to the GPU thread to flush a region
struct FlushRegionCommand final {
explicit constexpr FlushRegionCommand(DAddr addr_, u64 size_) : addr{addr_}, size{size_} {}
@@ -81,8 +73,8 @@ struct FlushAndInvalidateRegionCommand final {
struct GPUTickCommand final {};
using CommandData =
- std::variant<std::monostate, SubmitListCommand, SwapBuffersCommand, FlushRegionCommand,
- InvalidateRegionCommand, FlushAndInvalidateRegionCommand, GPUTickCommand>;
+ std::variant<std::monostate, SubmitListCommand, FlushRegionCommand, InvalidateRegionCommand,
+ FlushAndInvalidateRegionCommand, GPUTickCommand>;
struct CommandDataContainer {
CommandDataContainer() = default;
@@ -118,9 +110,6 @@ public:
/// Push GPU command entries to be processed
void SubmitList(s32 channel, Tegra::CommandList&& entries);
- /// Swap buffers (render frame)
- void SwapBuffers(const Tegra::FramebufferConfig* framebuffer);
-
/// Notify rasterizer that any caches of the specified region should be flushed to Switch memory
void FlushRegion(DAddr addr, u64 size);
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h
index 78ea5208b..3ad180f67 100644
--- a/src/video_core/renderer_base.h
+++ b/src/video_core/renderer_base.h
@@ -38,7 +38,7 @@ public:
virtual ~RendererBase();
/// Finalize rendering the guest frame and draw into the presentation texture
- virtual void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) = 0;
+ virtual void Composite(std::span<const Tegra::FramebufferConfig> layers) = 0;
[[nodiscard]] virtual RasterizerInterface* ReadRasterizer() = 0;
diff --git a/src/video_core/renderer_null/renderer_null.cpp b/src/video_core/renderer_null/renderer_null.cpp
index 078feb925..c89daff53 100644
--- a/src/video_core/renderer_null/renderer_null.cpp
+++ b/src/video_core/renderer_null/renderer_null.cpp
@@ -13,8 +13,8 @@ RendererNull::RendererNull(Core::Frontend::EmuWindow& emu_window, Tegra::GPU& gp
RendererNull::~RendererNull() = default;
-void RendererNull::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- if (!framebuffer) {
+void RendererNull::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
+ if (framebuffers.empty()) {
return;
}
diff --git a/src/video_core/renderer_null/renderer_null.h b/src/video_core/renderer_null/renderer_null.h
index 9531b43f6..063b476bb 100644
--- a/src/video_core/renderer_null/renderer_null.h
+++ b/src/video_core/renderer_null/renderer_null.h
@@ -17,7 +17,7 @@ public:
std::unique_ptr<Core::Frontend::GraphicsContext> context);
~RendererNull() override;
- void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override;
+ void Composite(std::span<const Tegra::FramebufferConfig> framebuffer) override;
VideoCore::RasterizerInterface* ReadRasterizer() override {
return &m_rasterizer;
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index 10a9f973c..e33a32592 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -125,15 +125,15 @@ RendererOpenGL::RendererOpenGL(Core::TelemetrySession& telemetry_session_,
RendererOpenGL::~RendererOpenGL() = default;
-void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- if (!framebuffer) {
+void RendererOpenGL::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
+ if (framebuffers.empty()) {
return;
}
- RenderScreenshot(framebuffer);
+ RenderScreenshot(framebuffers);
state_tracker.BindFramebuffer(0);
- blit_screen->DrawScreen(std::span(framebuffer, 1), emu_window.GetFramebufferLayout());
+ blit_screen->DrawScreen(framebuffers, emu_window.GetFramebufferLayout());
++m_current_frame;
@@ -159,7 +159,7 @@ void RendererOpenGL::AddTelemetryFields() {
telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version));
}
-void RendererOpenGL::RenderScreenshot(const Tegra::FramebufferConfig* framebuffer) {
+void RendererOpenGL::RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers) {
if (!renderer_settings.screenshot_requested) {
return;
}
@@ -181,7 +181,7 @@ void RendererOpenGL::RenderScreenshot(const Tegra::FramebufferConfig* framebuffe
glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8, layout.width, layout.height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
- blit_screen->DrawScreen(std::span(framebuffer, 1), layout);
+ blit_screen->DrawScreen(framebuffers, layout);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h
index df76d3d05..c4625c96e 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.h
+++ b/src/video_core/renderer_opengl/renderer_opengl.h
@@ -40,7 +40,7 @@ public:
std::unique_ptr<Core::Frontend::GraphicsContext> context_);
~RendererOpenGL() override;
- void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override;
+ void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override;
VideoCore::RasterizerInterface* ReadRasterizer() override {
return &rasterizer;
@@ -52,7 +52,7 @@ public:
private:
void AddTelemetryFields();
- void RenderScreenshot(const Tegra::FramebufferConfig* framebuffer);
+ void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers);
Core::TelemetrySession& telemetry_session;
Core::Frontend::EmuWindow& emu_window;
diff --git a/src/video_core/renderer_vulkan/present/util.cpp b/src/video_core/renderer_vulkan/present/util.cpp
index 7bff1c436..6ee16595d 100644
--- a/src/video_core/renderer_vulkan/present/util.cpp
+++ b/src/video_core/renderer_vulkan/present/util.cpp
@@ -7,6 +7,20 @@
namespace Vulkan {
+vk::Buffer CreateWrappedBuffer(MemoryAllocator& allocator, VkDeviceSize size, MemoryUsage usage) {
+ const VkBufferCreateInfo dst_buffer_info{
+ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+ .pNext = nullptr,
+ .flags = 0,
+ .size = size,
+ .usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+ .queueFamilyIndexCount = 0,
+ .pQueueFamilyIndices = nullptr,
+ };
+ return allocator.CreateBuffer(dst_buffer_info, usage);
+}
+
vk::Image CreateWrappedImage(MemoryAllocator& allocator, VkExtent2D dimensions, VkFormat format) {
const VkImageCreateInfo image_ci{
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
@@ -96,6 +110,70 @@ void UploadImage(const Device& device, MemoryAllocator& allocator, Scheduler& sc
scheduler.Finish();
}
+void DownloadColorImage(vk::CommandBuffer& cmdbuf, VkImage image, VkBuffer buffer,
+ VkExtent3D extent) {
+ const VkImageMemoryBarrier read_barrier{
+ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ .pNext = nullptr,
+ .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
+ .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
+ .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
+ .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .image = image,
+ .subresourceRange{
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = VK_REMAINING_MIP_LEVELS,
+ .baseArrayLayer = 0,
+ .layerCount = VK_REMAINING_ARRAY_LAYERS,
+ },
+ };
+ const VkImageMemoryBarrier image_write_barrier{
+ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
+ .pNext = nullptr,
+ .srcAccessMask = 0,
+ .dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
+ .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ .newLayout = VK_IMAGE_LAYOUT_GENERAL,
+ .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
+ .image = image,
+ .subresourceRange{
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .baseMipLevel = 0,
+ .levelCount = VK_REMAINING_MIP_LEVELS,
+ .baseArrayLayer = 0,
+ .layerCount = VK_REMAINING_ARRAY_LAYERS,
+ },
+ };
+ static constexpr VkMemoryBarrier memory_write_barrier{
+ .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
+ .pNext = nullptr,
+ .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
+ .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
+ };
+ const VkBufferImageCopy copy{
+ .bufferOffset = 0,
+ .bufferRowLength = 0,
+ .bufferImageHeight = 0,
+ .imageSubresource{
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .mipLevel = 0,
+ .baseArrayLayer = 0,
+ .layerCount = 1,
+ },
+ .imageOffset{.x = 0, .y = 0, .z = 0},
+ .imageExtent{extent},
+ };
+ cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0,
+ read_barrier);
+ cmdbuf.CopyImageToBuffer(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer, copy);
+ cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
+ memory_write_barrier, nullptr, image_write_barrier);
+}
+
vk::ImageView CreateWrappedImageView(const Device& device, vk::Image& image, VkFormat format) {
return device.GetLogical().CreateImageView(VkImageViewCreateInfo{
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
diff --git a/src/video_core/renderer_vulkan/present/util.h b/src/video_core/renderer_vulkan/present/util.h
index fb4e4a8e4..1104aaa15 100644
--- a/src/video_core/renderer_vulkan/present/util.h
+++ b/src/video_core/renderer_vulkan/present/util.h
@@ -11,12 +11,16 @@ namespace Vulkan {
#define ARRAY_TO_SPAN(a) std::span(a, (sizeof(a) / sizeof(a[0])))
+vk::Buffer CreateWrappedBuffer(MemoryAllocator& allocator, VkDeviceSize size, MemoryUsage usage);
+
vk::Image CreateWrappedImage(MemoryAllocator& allocator, VkExtent2D dimensions, VkFormat format);
void TransitionImageLayout(vk::CommandBuffer& cmdbuf, VkImage image, VkImageLayout target_layout,
VkImageLayout source_layout = VK_IMAGE_LAYOUT_GENERAL);
void UploadImage(const Device& device, MemoryAllocator& allocator, Scheduler& scheduler,
vk::Image& image, VkExtent2D dimensions, VkFormat format,
std::span<const u8> initial_contents = {});
+void DownloadColorImage(vk::CommandBuffer& cmdbuf, VkImage image, VkBuffer buffer,
+ VkExtent3D extent);
void ClearColorImage(vk::CommandBuffer& cmdbuf, VkImage image);
vk::ImageView CreateWrappedImageView(const Device& device, vk::Image& image, VkFormat format);
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
index 77837adde..48a105327 100644
--- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp
+++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp
@@ -20,12 +20,14 @@
#include "core/frontend/graphics_context.h"
#include "core/telemetry_session.h"
#include "video_core/gpu.h"
+#include "video_core/renderer_vulkan/present/util.h"
#include "video_core/renderer_vulkan/renderer_vulkan.h"
#include "video_core/renderer_vulkan/vk_blit_screen.h"
#include "video_core/renderer_vulkan/vk_rasterizer.h"
#include "video_core/renderer_vulkan/vk_scheduler.h"
#include "video_core/renderer_vulkan/vk_state_tracker.h"
#include "video_core/renderer_vulkan/vk_swapchain.h"
+#include "video_core/textures/decoders.h"
#include "video_core/vulkan_common/vulkan_debug_callback.h"
#include "video_core/vulkan_common/vulkan_device.h"
#include "video_core/vulkan_common/vulkan_instance.h"
@@ -116,18 +118,20 @@ RendererVulkan::~RendererVulkan() {
void(device.GetLogical().WaitIdle());
}
-void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
- if (!framebuffer) {
+void RendererVulkan::Composite(std::span<const Tegra::FramebufferConfig> framebuffers) {
+ if (framebuffers.empty()) {
return;
}
+
SCOPE_EXIT({ render_window.OnFrameDisplayed(); });
+
if (!render_window.IsShown()) {
return;
}
- RenderScreenshot(framebuffer);
+ RenderScreenshot(framebuffers);
Frame* frame = present_manager.GetRenderFrame();
- blit_swapchain.DrawToFrame(rasterizer, frame, std::span(framebuffer, 1),
+ blit_swapchain.DrawToFrame(rasterizer, frame, framebuffers,
render_window.GetFramebufferLayout(), swapchain.GetImageCount(),
swapchain.GetImageViewFormat());
scheduler.Flush(*frame->render_ready);
@@ -163,156 +167,37 @@ void RendererVulkan::Report() const {
telemetry_session.AddField(field, "GPU_Vulkan_Extensions", extensions);
}
-void Vulkan::RendererVulkan::RenderScreenshot(const Tegra::FramebufferConfig* framebuffer) {
+void Vulkan::RendererVulkan::RenderScreenshot(
+ std::span<const Tegra::FramebufferConfig> framebuffers) {
if (!renderer_settings.screenshot_requested) {
return;
}
+
+ constexpr VkFormat ScreenshotFormat{VK_FORMAT_B8G8R8A8_UNORM};
const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout};
- auto frame = [&]() {
- vk::Image staging_image = memory_allocator.CreateImage(VkImageCreateInfo{
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .pNext = nullptr,
- .flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = VK_FORMAT_B8G8R8A8_UNORM,
- .extent =
- {
- .width = layout.width,
- .height = layout.height,
- .depth = 1,
- },
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = VK_SAMPLE_COUNT_1_BIT,
- .tiling = VK_IMAGE_TILING_OPTIMAL,
- .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
- VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
- .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
- .queueFamilyIndexCount = 0,
- .pQueueFamilyIndices = nullptr,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
- });
- vk::ImageView dst_view = device.GetLogical().CreateImageView(VkImageViewCreateInfo{
- .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
- .pNext = nullptr,
- .flags = 0,
- .image = *staging_image,
- .viewType = VK_IMAGE_VIEW_TYPE_2D,
- .format = VK_FORMAT_B8G8R8A8_UNORM,
- .components{
- .r = VK_COMPONENT_SWIZZLE_IDENTITY,
- .g = VK_COMPONENT_SWIZZLE_IDENTITY,
- .b = VK_COMPONENT_SWIZZLE_IDENTITY,
- .a = VK_COMPONENT_SWIZZLE_IDENTITY,
- },
- .subresourceRange{
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = 1,
- .baseArrayLayer = 0,
- .layerCount = VK_REMAINING_ARRAY_LAYERS,
- },
- });
- vk::Framebuffer screenshot_fb =
- blit_screenshot.CreateFramebuffer(layout, *dst_view, VK_FORMAT_B8G8R8A8_UNORM);
- return Frame{
- .width = layout.width,
- .height = layout.height,
- .image = std::move(staging_image),
- .image_view = std::move(dst_view),
- .framebuffer = std::move(screenshot_fb),
- .cmdbuf{},
- .render_ready{},
- .present_done{},
- };
+ auto frame = [&]() {
+ Frame f{};
+ f.image = CreateWrappedImage(memory_allocator, VkExtent2D{layout.width, layout.height},
+ ScreenshotFormat);
+ f.image_view = CreateWrappedImageView(device, f.image, ScreenshotFormat);
+ f.framebuffer = blit_screenshot.CreateFramebuffer(layout, *f.image_view, ScreenshotFormat);
+ return f;
}();
- blit_screenshot.DrawToFrame(rasterizer, &frame, std::span(framebuffer, 1), layout, 1,
+ blit_screenshot.DrawToFrame(rasterizer, &frame, framebuffers, layout, 1,
VK_FORMAT_B8G8R8A8_UNORM);
- const auto buffer_size = static_cast<VkDeviceSize>(layout.width * layout.height * 4);
- const VkBufferCreateInfo dst_buffer_info{
- .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
- .pNext = nullptr,
- .flags = 0,
- .size = buffer_size,
- .usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT,
- .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
- .queueFamilyIndexCount = 0,
- .pQueueFamilyIndices = nullptr,
- };
- const vk::Buffer dst_buffer =
- memory_allocator.CreateBuffer(dst_buffer_info, MemoryUsage::Download);
+ const auto dst_buffer = CreateWrappedBuffer(
+ memory_allocator, static_cast<VkDeviceSize>(layout.width * layout.height * 4),
+ MemoryUsage::Download);
scheduler.RequestOutsideRenderPassOperationContext();
scheduler.Record([&](vk::CommandBuffer cmdbuf) {
- const VkImageMemoryBarrier read_barrier{
- .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
- .pNext = nullptr,
- .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
- .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT,
- .oldLayout = VK_IMAGE_LAYOUT_GENERAL,
- .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .image = *frame.image,
- .subresourceRange{
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = VK_REMAINING_MIP_LEVELS,
- .baseArrayLayer = 0,
- .layerCount = VK_REMAINING_ARRAY_LAYERS,
- },
- };
- const VkImageMemoryBarrier image_write_barrier{
- .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
- .pNext = nullptr,
- .srcAccessMask = 0,
- .dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
- .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
- .newLayout = VK_IMAGE_LAYOUT_GENERAL,
- .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
- .image = *frame.image,
- .subresourceRange{
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .baseMipLevel = 0,
- .levelCount = VK_REMAINING_MIP_LEVELS,
- .baseArrayLayer = 0,
- .layerCount = VK_REMAINING_ARRAY_LAYERS,
- },
- };
- static constexpr VkMemoryBarrier memory_write_barrier{
- .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER,
- .pNext = nullptr,
- .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
- .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT,
- };
- const VkBufferImageCopy copy{
- .bufferOffset = 0,
- .bufferRowLength = 0,
- .bufferImageHeight = 0,
- .imageSubresource{
- .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
- .mipLevel = 0,
- .baseArrayLayer = 0,
- .layerCount = 1,
- },
- .imageOffset{.x = 0, .y = 0, .z = 0},
- .imageExtent{
- .width = layout.width,
- .height = layout.height,
- .depth = 1,
- },
- };
- cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
- 0, read_barrier);
- cmdbuf.CopyImageToBuffer(*frame.image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *dst_buffer,
- copy);
- cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
- 0, memory_write_barrier, nullptr, image_write_barrier);
+ DownloadColorImage(cmdbuf, *frame.image, *dst_buffer,
+ VkExtent3D{layout.width, layout.height, 1});
});
+
// Ensure the copy is fully completed before saving the screenshot
scheduler.Finish();
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h
index bdeb43a54..c6d8a0f21 100644
--- a/src/video_core/renderer_vulkan/renderer_vulkan.h
+++ b/src/video_core/renderer_vulkan/renderer_vulkan.h
@@ -46,7 +46,7 @@ public:
std::unique_ptr<Core::Frontend::GraphicsContext> context_);
~RendererVulkan() override;
- void SwapBuffers(const Tegra::FramebufferConfig* framebuffer) override;
+ void Composite(std::span<const Tegra::FramebufferConfig> framebuffers) override;
VideoCore::RasterizerInterface* ReadRasterizer() override {
return &rasterizer;
@@ -59,7 +59,7 @@ public:
private:
void Report() const;
- void RenderScreenshot(const Tegra::FramebufferConfig* framebuffer);
+ void RenderScreenshot(std::span<const Tegra::FramebufferConfig> framebuffers);
Core::TelemetrySession& telemetry_session;
Tegra::MaxwellDeviceMemoryManager& device_memory;
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
index b2dcbf80b..2275fcc46 100644
--- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp
+++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp
@@ -115,7 +115,7 @@ void BlitScreen::DrawToFrame(RasterizerVulkan& rasterizer, Frame* frame,
}
vk::Framebuffer BlitScreen::CreateFramebuffer(const Layout::FramebufferLayout& layout,
- const VkImageView& image_view,
+ VkImageView image_view,
VkFormat current_view_format) {
const bool format_updated =
std::exchange(swapchain_view_format, current_view_format) != current_view_format;
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.h b/src/video_core/renderer_vulkan/vk_blit_screen.h
index 9a3476c77..cbdf2d5d0 100644
--- a/src/video_core/renderer_vulkan/vk_blit_screen.h
+++ b/src/video_core/renderer_vulkan/vk_blit_screen.h
@@ -56,7 +56,7 @@ public:
VkFormat current_swapchain_view_format);
[[nodiscard]] vk::Framebuffer CreateFramebuffer(const Layout::FramebufferLayout& layout,
- const VkImageView& image_view,
+ VkImageView image_view,
VkFormat current_view_format);
private: