yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

video_core: Replace VKBlitScreen with BlitScreen

This commit is contained in:
german77 2022-06-25 23:33:35 -05:00
parent fca5752690
commit a262dc02b5
3 changed files with 51 additions and 51 deletions

View File

@ -72,7 +72,7 @@ private:
StateTracker state_tracker; StateTracker state_tracker;
VKScheduler scheduler; VKScheduler scheduler;
VKSwapchain swapchain; VKSwapchain swapchain;
VKBlitScreen blit_screen; BlitScreen blit_screen;
RasterizerVulkan rasterizer; RasterizerVulkan rasterizer;
}; };

View File

@ -108,7 +108,7 @@ VkFormat GetFormat(const Tegra::FramebufferConfig& framebuffer) {
} // Anonymous namespace } // Anonymous namespace
struct VKBlitScreen::BufferData { struct BlitScreen::BufferData {
struct { struct {
std::array<f32, 4 * 4> modelview_matrix; std::array<f32, 4 * 4> modelview_matrix;
} uniform; } uniform;
@ -118,10 +118,10 @@ struct VKBlitScreen::BufferData {
// Unaligned image data goes here // Unaligned image data goes here
}; };
VKBlitScreen::VKBlitScreen(Core::Memory::Memory& cpu_memory_, BlitScreen::BlitScreen(Core::Memory::Memory& cpu_memory_, Core::Frontend::EmuWindow& render_window_,
Core::Frontend::EmuWindow& render_window_, const Device& device_, const Device& device_, MemoryAllocator& memory_allocator_,
MemoryAllocator& memory_allocator_, VKSwapchain& swapchain_, VKSwapchain& swapchain_, VKScheduler& scheduler_,
VKScheduler& scheduler_, const VKScreenInfo& screen_info_) const VKScreenInfo& screen_info_)
: cpu_memory{cpu_memory_}, render_window{render_window_}, device{device_}, : cpu_memory{cpu_memory_}, render_window{render_window_}, device{device_},
memory_allocator{memory_allocator_}, swapchain{swapchain_}, scheduler{scheduler_}, memory_allocator{memory_allocator_}, swapchain{swapchain_}, scheduler{scheduler_},
image_count{swapchain.GetImageCount()}, screen_info{screen_info_} { image_count{swapchain.GetImageCount()}, screen_info{screen_info_} {
@ -131,16 +131,16 @@ VKBlitScreen::VKBlitScreen(Core::Memory::Memory& cpu_memory_,
CreateDynamicResources(); CreateDynamicResources();
} }
VKBlitScreen::~VKBlitScreen() = default; BlitScreen::~BlitScreen() = default;
void VKBlitScreen::Recreate() { void BlitScreen::Recreate() {
CreateDynamicResources(); CreateDynamicResources();
} }
VkSemaphore VKBlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer, VkSemaphore BlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer,
const VkFramebuffer& host_framebuffer, const VkFramebuffer& host_framebuffer,
const Layout::FramebufferLayout layout, VkExtent2D render_area, const Layout::FramebufferLayout layout, VkExtent2D render_area,
bool use_accelerated) { bool use_accelerated) {
RefreshResources(framebuffer); RefreshResources(framebuffer);
// Finish any pending renderpass // Finish any pending renderpass
@ -419,20 +419,20 @@ VkSemaphore VKBlitScreen::Draw(const Tegra::FramebufferConfig& framebuffer,
return *semaphores[image_index]; return *semaphores[image_index];
} }
VkSemaphore VKBlitScreen::DrawToSwapchain(const Tegra::FramebufferConfig& framebuffer, VkSemaphore BlitScreen::DrawToSwapchain(const Tegra::FramebufferConfig& framebuffer,
bool use_accelerated) { bool use_accelerated) {
const std::size_t image_index = swapchain.GetImageIndex(); const std::size_t image_index = swapchain.GetImageIndex();
const VkExtent2D render_area = swapchain.GetSize(); const VkExtent2D render_area = swapchain.GetSize();
const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout(); const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout();
return Draw(framebuffer, *framebuffers[image_index], layout, render_area, use_accelerated); return Draw(framebuffer, *framebuffers[image_index], layout, render_area, use_accelerated);
} }
vk::Framebuffer VKBlitScreen::CreateFramebuffer(const VkImageView& image_view, VkExtent2D extent) { vk::Framebuffer BlitScreen::CreateFramebuffer(const VkImageView& image_view, VkExtent2D extent) {
return CreateFramebuffer(image_view, extent, renderpass); return CreateFramebuffer(image_view, extent, renderpass);
} }
vk::Framebuffer VKBlitScreen::CreateFramebuffer(const VkImageView& image_view, VkExtent2D extent, vk::Framebuffer BlitScreen::CreateFramebuffer(const VkImageView& image_view, VkExtent2D extent,
vk::RenderPass& rd) { vk::RenderPass& rd) {
return device.GetLogical().CreateFramebuffer(VkFramebufferCreateInfo{ return device.GetLogical().CreateFramebuffer(VkFramebufferCreateInfo{
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@ -446,7 +446,7 @@ vk::Framebuffer VKBlitScreen::CreateFramebuffer(const VkImageView& image_view, V
}); });
} }
void VKBlitScreen::CreateStaticResources() { void BlitScreen::CreateStaticResources() {
CreateShaders(); CreateShaders();
CreateSemaphores(); CreateSemaphores();
CreateDescriptorPool(); CreateDescriptorPool();
@ -456,7 +456,7 @@ void VKBlitScreen::CreateStaticResources() {
CreateSampler(); CreateSampler();
} }
void VKBlitScreen::CreateDynamicResources() { void BlitScreen::CreateDynamicResources() {
CreateRenderPass(); CreateRenderPass();
CreateFramebuffers(); CreateFramebuffers();
CreateGraphicsPipeline(); CreateGraphicsPipeline();
@ -466,7 +466,7 @@ void VKBlitScreen::CreateDynamicResources() {
} }
} }
void VKBlitScreen::RefreshResources(const Tegra::FramebufferConfig& framebuffer) { void BlitScreen::RefreshResources(const Tegra::FramebufferConfig& framebuffer) {
if (Settings::values.scaling_filter.GetValue() == Settings::ScalingFilter::Fsr) { if (Settings::values.scaling_filter.GetValue() == Settings::ScalingFilter::Fsr) {
if (!fsr) { if (!fsr) {
CreateFSR(); CreateFSR();
@ -486,7 +486,7 @@ void VKBlitScreen::RefreshResources(const Tegra::FramebufferConfig& framebuffer)
CreateRawImages(framebuffer); CreateRawImages(framebuffer);
} }
void VKBlitScreen::CreateShaders() { void BlitScreen::CreateShaders() {
vertex_shader = BuildShader(device, VULKAN_PRESENT_VERT_SPV); vertex_shader = BuildShader(device, VULKAN_PRESENT_VERT_SPV);
fxaa_vertex_shader = BuildShader(device, FXAA_VERT_SPV); fxaa_vertex_shader = BuildShader(device, FXAA_VERT_SPV);
fxaa_fragment_shader = BuildShader(device, FXAA_FRAG_SPV); fxaa_fragment_shader = BuildShader(device, FXAA_FRAG_SPV);
@ -500,12 +500,12 @@ void VKBlitScreen::CreateShaders() {
} }
} }
void VKBlitScreen::CreateSemaphores() { void BlitScreen::CreateSemaphores() {
semaphores.resize(image_count); semaphores.resize(image_count);
std::ranges::generate(semaphores, [this] { return device.GetLogical().CreateSemaphore(); }); std::ranges::generate(semaphores, [this] { return device.GetLogical().CreateSemaphore(); });
} }
void VKBlitScreen::CreateDescriptorPool() { void BlitScreen::CreateDescriptorPool() {
const std::array<VkDescriptorPoolSize, 2> pool_sizes{{ const std::array<VkDescriptorPoolSize, 2> pool_sizes{{
{ {
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
@ -545,11 +545,11 @@ void VKBlitScreen::CreateDescriptorPool() {
aa_descriptor_pool = device.GetLogical().CreateDescriptorPool(ci_aa); aa_descriptor_pool = device.GetLogical().CreateDescriptorPool(ci_aa);
} }
void VKBlitScreen::CreateRenderPass() { void BlitScreen::CreateRenderPass() {
renderpass = CreateRenderPassImpl(swapchain.GetImageViewFormat()); renderpass = CreateRenderPassImpl(swapchain.GetImageViewFormat());
} }
vk::RenderPass VKBlitScreen::CreateRenderPassImpl(VkFormat format, bool is_present) { vk::RenderPass BlitScreen::CreateRenderPassImpl(VkFormat format, bool is_present) {
const VkAttachmentDescription color_attachment{ const VkAttachmentDescription color_attachment{
.flags = 0, .flags = 0,
.format = format, .format = format,
@ -605,7 +605,7 @@ vk::RenderPass VKBlitScreen::CreateRenderPassImpl(VkFormat format, bool is_prese
return device.GetLogical().CreateRenderPass(renderpass_ci); return device.GetLogical().CreateRenderPass(renderpass_ci);
} }
void VKBlitScreen::CreateDescriptorSetLayout() { void BlitScreen::CreateDescriptorSetLayout() {
const std::array<VkDescriptorSetLayoutBinding, 2> layout_bindings{{ const std::array<VkDescriptorSetLayoutBinding, 2> layout_bindings{{
{ {
.binding = 0, .binding = 0,
@ -660,7 +660,7 @@ void VKBlitScreen::CreateDescriptorSetLayout() {
aa_descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(ci_aa); aa_descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(ci_aa);
} }
void VKBlitScreen::CreateDescriptorSets() { void BlitScreen::CreateDescriptorSets() {
const std::vector layouts(image_count, *descriptor_set_layout); const std::vector layouts(image_count, *descriptor_set_layout);
const std::vector layouts_aa(image_count, *aa_descriptor_set_layout); const std::vector layouts_aa(image_count, *aa_descriptor_set_layout);
@ -684,7 +684,7 @@ void VKBlitScreen::CreateDescriptorSets() {
aa_descriptor_sets = aa_descriptor_pool.Allocate(ai_aa); aa_descriptor_sets = aa_descriptor_pool.Allocate(ai_aa);
} }
void VKBlitScreen::CreatePipelineLayout() { void BlitScreen::CreatePipelineLayout() {
const VkPipelineLayoutCreateInfo ci{ const VkPipelineLayoutCreateInfo ci{
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@ -707,7 +707,7 @@ void VKBlitScreen::CreatePipelineLayout() {
aa_pipeline_layout = device.GetLogical().CreatePipelineLayout(ci_aa); aa_pipeline_layout = device.GetLogical().CreatePipelineLayout(ci_aa);
} }
void VKBlitScreen::CreateGraphicsPipeline() { void BlitScreen::CreateGraphicsPipeline() {
const std::array<VkPipelineShaderStageCreateInfo, 2> bilinear_shader_stages{{ const std::array<VkPipelineShaderStageCreateInfo, 2> bilinear_shader_stages{{
{ {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
@ -980,7 +980,7 @@ void VKBlitScreen::CreateGraphicsPipeline() {
scaleforce_pipeline = device.GetLogical().CreateGraphicsPipeline(scaleforce_pipeline_ci); scaleforce_pipeline = device.GetLogical().CreateGraphicsPipeline(scaleforce_pipeline_ci);
} }
void VKBlitScreen::CreateSampler() { void BlitScreen::CreateSampler() {
const VkSamplerCreateInfo ci{ const VkSamplerCreateInfo ci{
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@ -1027,7 +1027,7 @@ void VKBlitScreen::CreateSampler() {
nn_sampler = device.GetLogical().CreateSampler(ci_nn); nn_sampler = device.GetLogical().CreateSampler(ci_nn);
} }
void VKBlitScreen::CreateFramebuffers() { void BlitScreen::CreateFramebuffers() {
const VkExtent2D size{swapchain.GetSize()}; const VkExtent2D size{swapchain.GetSize()};
framebuffers.resize(image_count); framebuffers.resize(image_count);
@ -1037,7 +1037,7 @@ void VKBlitScreen::CreateFramebuffers() {
} }
} }
void VKBlitScreen::ReleaseRawImages() { void BlitScreen::ReleaseRawImages() {
for (const u64 tick : resource_ticks) { for (const u64 tick : resource_ticks) {
scheduler.Wait(tick); scheduler.Wait(tick);
} }
@ -1052,7 +1052,7 @@ void VKBlitScreen::ReleaseRawImages() {
buffer_commit = MemoryCommit{}; buffer_commit = MemoryCommit{};
} }
void VKBlitScreen::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) { void BlitScreen::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) {
const VkBufferCreateInfo ci{ const VkBufferCreateInfo ci{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@ -1069,7 +1069,7 @@ void VKBlitScreen::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuff
buffer_commit = memory_allocator.Commit(buffer, MemoryUsage::Upload); buffer_commit = memory_allocator.Commit(buffer, MemoryUsage::Upload);
} }
void VKBlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) { void BlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) {
raw_images.resize(image_count); raw_images.resize(image_count);
raw_image_views.resize(image_count); raw_image_views.resize(image_count);
raw_buffer_commits.resize(image_count); raw_buffer_commits.resize(image_count);
@ -1294,8 +1294,8 @@ void VKBlitScreen::CreateRawImages(const Tegra::FramebufferConfig& framebuffer)
aa_pipeline = device.GetLogical().CreateGraphicsPipeline(fxaa_pipeline_ci); aa_pipeline = device.GetLogical().CreateGraphicsPipeline(fxaa_pipeline_ci);
} }
void VKBlitScreen::UpdateAADescriptorSet(std::size_t image_index, VkImageView image_view, void BlitScreen::UpdateAADescriptorSet(std::size_t image_index, VkImageView image_view,
bool nn) const { bool nn) const {
const VkDescriptorImageInfo image_info{ const VkDescriptorImageInfo image_info{
.sampler = nn ? *nn_sampler : *sampler, .sampler = nn ? *nn_sampler : *sampler,
.imageView = image_view, .imageView = image_view,
@ -1331,8 +1331,8 @@ void VKBlitScreen::UpdateAADescriptorSet(std::size_t image_index, VkImageView im
device.GetLogical().UpdateDescriptorSets(std::array{sampler_write, sampler_write_2}, {}); device.GetLogical().UpdateDescriptorSets(std::array{sampler_write, sampler_write_2}, {});
} }
void VKBlitScreen::UpdateDescriptorSet(std::size_t image_index, VkImageView image_view, void BlitScreen::UpdateDescriptorSet(std::size_t image_index, VkImageView image_view,
bool nn) const { bool nn) const {
const VkDescriptorBufferInfo buffer_info{ const VkDescriptorBufferInfo buffer_info{
.buffer = *buffer, .buffer = *buffer,
.offset = offsetof(BufferData, uniform), .offset = offsetof(BufferData, uniform),
@ -1374,13 +1374,13 @@ void VKBlitScreen::UpdateDescriptorSet(std::size_t image_index, VkImageView imag
device.GetLogical().UpdateDescriptorSets(std::array{ubo_write, sampler_write}, {}); device.GetLogical().UpdateDescriptorSets(std::array{ubo_write, sampler_write}, {});
} }
void VKBlitScreen::SetUniformData(BufferData& data, const Layout::FramebufferLayout layout) const { void BlitScreen::SetUniformData(BufferData& data, const Layout::FramebufferLayout layout) const {
data.uniform.modelview_matrix = data.uniform.modelview_matrix =
MakeOrthographicMatrix(static_cast<f32>(layout.width), static_cast<f32>(layout.height)); MakeOrthographicMatrix(static_cast<f32>(layout.width), static_cast<f32>(layout.height));
} }
void VKBlitScreen::SetVertexData(BufferData& data, const Tegra::FramebufferConfig& framebuffer, void BlitScreen::SetVertexData(BufferData& data, const Tegra::FramebufferConfig& framebuffer,
const Layout::FramebufferLayout layout) const { const Layout::FramebufferLayout layout) const {
const auto& framebuffer_transform_flags = framebuffer.transform_flags; const auto& framebuffer_transform_flags = framebuffer.transform_flags;
const auto& framebuffer_crop_rect = framebuffer.crop_rect; const auto& framebuffer_crop_rect = framebuffer.crop_rect;
@ -1432,7 +1432,7 @@ void VKBlitScreen::SetVertexData(BufferData& data, const Tegra::FramebufferConfi
data.vertices[3] = ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v); data.vertices[3] = ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v);
} }
void VKBlitScreen::CreateFSR() { void BlitScreen::CreateFSR() {
const auto& layout = render_window.GetFramebufferLayout(); const auto& layout = render_window.GetFramebufferLayout();
const VkExtent2D fsr_size{ const VkExtent2D fsr_size{
.width = layout.screen.GetWidth(), .width = layout.screen.GetWidth(),
@ -1441,12 +1441,12 @@ void VKBlitScreen::CreateFSR() {
fsr = std::make_unique<FSR>(device, memory_allocator, image_count, fsr_size); fsr = std::make_unique<FSR>(device, memory_allocator, image_count, fsr_size);
} }
u64 VKBlitScreen::CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const { u64 BlitScreen::CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const {
return sizeof(BufferData) + GetSizeInBytes(framebuffer) * image_count; return sizeof(BufferData) + GetSizeInBytes(framebuffer) * image_count;
} }
u64 VKBlitScreen::GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer, u64 BlitScreen::GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer,
std::size_t image_index) const { std::size_t image_index) const {
constexpr auto first_image_offset = static_cast<u64>(sizeof(BufferData)); constexpr auto first_image_offset = static_cast<u64>(sizeof(BufferData));
return first_image_offset + GetSizeInBytes(framebuffer) * image_index; return first_image_offset + GetSizeInBytes(framebuffer) * image_index;
} }

View File

@ -45,13 +45,13 @@ struct VKScreenInfo {
bool is_srgb{}; bool is_srgb{};
}; };
class VKBlitScreen { class BlitScreen {
public: public:
explicit VKBlitScreen(Core::Memory::Memory& cpu_memory, explicit BlitScreen(Core::Memory::Memory& cpu_memory, Core::Frontend::EmuWindow& render_window,
Core::Frontend::EmuWindow& render_window, const Device& device, const Device& device, MemoryAllocator& memory_manager,
MemoryAllocator& memory_manager, VKSwapchain& swapchain, VKSwapchain& swapchain, VKScheduler& scheduler,
VKScheduler& scheduler, const VKScreenInfo& screen_info); const VKScreenInfo& screen_info);
~VKBlitScreen(); ~BlitScreen();
void Recreate(); void Recreate();