Browse Source
[video_core] Add SSAA antialiasing
[video_core] Add SSAA antialiasing
Signed-off-by: lizzie <lizzie@eden-emu.dev>lizzie/ssaa-what-the-fuck
13 changed files with 225 additions and 4 deletions
-
2src/android/app/src/main/res/values-fa/strings.xml
-
1src/android/app/src/main/res/values/arrays.xml
-
1src/android/app/src/main/res/values/strings.xml
-
2src/common/settings_enums.h
-
1src/qt_common/config/shared_translation.cpp
-
1src/qt_common/config/shared_translation.h
-
2src/video_core/CMakeLists.txt
-
1src/video_core/host_shaders/CMakeLists.txt
-
19src/video_core/host_shaders/ssaa.frag
-
2src/video_core/renderer_vulkan/present/layer.cpp
-
3src/video_core/renderer_vulkan/present/layer.h
-
131src/video_core/renderer_vulkan/present/ssaa.cpp
-
63src/video_core/renderer_vulkan/present/ssaa.h
@ -0,0 +1,19 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
||||
|
// SPDX-License-Identifier: GPL-2.0-or-later |
||||
|
|
||||
|
#version 460 |
||||
|
#extension GL_ARB_sample_shading : enable |
||||
|
|
||||
|
#ifdef VULKAN |
||||
|
#define BINDING_COLOR_TEXTURE 1 |
||||
|
#else // ^^^ Vulkan ^^^ // vvv OpenGL vvv |
||||
|
#define BINDING_COLOR_TEXTURE 0 |
||||
|
#endif |
||||
|
|
||||
|
layout (location = 0) in vec4 posPos; |
||||
|
layout (location = 0) out vec4 frag_color; |
||||
|
layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D input_texture; |
||||
|
|
||||
|
void main() { |
||||
|
frag_color = texelFetch(input_texture, ivec2(posPos.xy * textureSize(input_texture)), gl_SampleID); |
||||
|
} |
||||
@ -0,0 +1,131 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
|
||||
|
#include "common/common_types.h"
|
||||
|
|
||||
|
#include "video_core/host_shaders/ssaa_frag_spv.h"
|
||||
|
#include "video_core/host_shaders/full_screen_triangle_vert_spv.h"
|
||||
|
#include "video_core/renderer_vulkan/present/ssaa.h"
|
||||
|
#include "video_core/renderer_vulkan/present/util.h"
|
||||
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
|
#include "video_core/renderer_vulkan/vk_shader_util.h"
|
||||
|
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
|
|
||||
|
namespace Vulkan { |
||||
|
|
||||
|
SSAA::SSAA(const Device& device, MemoryAllocator& allocator, size_t image_count, VkExtent2D extent) |
||||
|
: m_device(device), m_allocator(allocator), m_extent(extent) |
||||
|
, m_image_count(u32(image_count)) |
||||
|
{ |
||||
|
CreateImages(); |
||||
|
CreateRenderPasses(); |
||||
|
CreateSampler(); |
||||
|
CreateShaders(); |
||||
|
CreateDescriptorPool(); |
||||
|
CreateDescriptorSetLayouts(); |
||||
|
CreateDescriptorSets(); |
||||
|
CreatePipelineLayouts(); |
||||
|
CreatePipelines(); |
||||
|
} |
||||
|
|
||||
|
SSAA::~SSAA() = default; |
||||
|
|
||||
|
void SSAA::CreateImages() { |
||||
|
for (u32 i = 0; i < m_image_count; i++) { |
||||
|
Image& image = m_dynamic_images.emplace_back(); |
||||
|
image.image = CreateWrappedImage(m_allocator, m_extent, VK_FORMAT_R16G16B16A16_SFLOAT); |
||||
|
image.image_view = CreateWrappedImageView(m_device, image.image, VK_FORMAT_R16G16B16A16_SFLOAT); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateRenderPasses() { |
||||
|
m_renderpass = CreateWrappedRenderPass(m_device, VK_FORMAT_R16G16B16A16_SFLOAT); |
||||
|
for (auto& image : m_dynamic_images) { |
||||
|
image.framebuffer = CreateWrappedFramebuffer(m_device, m_renderpass, image.image_view, m_extent); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateSampler() { |
||||
|
m_sampler = CreateWrappedSampler(m_device); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateShaders() { |
||||
|
m_vertex_shader = CreateWrappedShaderModule(m_device, FULL_SCREEN_TRIANGLE_VERT_SPV); |
||||
|
m_fragment_shader = CreateWrappedShaderModule(m_device, SSAA_FRAG_SPV); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateDescriptorPool() { |
||||
|
// 2 descriptors, 1 descriptor set per image
|
||||
|
m_descriptor_pool = CreateWrappedDescriptorPool(m_device, 2 * m_image_count, m_image_count); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateDescriptorSetLayouts() { |
||||
|
m_descriptor_set_layout = CreateWrappedDescriptorSetLayout(m_device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreateDescriptorSets() { |
||||
|
VkDescriptorSetLayout layout = *m_descriptor_set_layout; |
||||
|
for (auto& images : m_dynamic_images) |
||||
|
images.descriptor_sets = CreateWrappedDescriptorSets(m_descriptor_pool, {layout}); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreatePipelineLayouts() { |
||||
|
m_pipeline_layout = CreateWrappedPipelineLayout(m_device, m_descriptor_set_layout); |
||||
|
} |
||||
|
|
||||
|
void SSAA::CreatePipelines() { |
||||
|
m_pipeline = CreateWrappedPipeline(m_device, m_renderpass, m_pipeline_layout, std::tie(m_vertex_shader, m_fragment_shader)); |
||||
|
} |
||||
|
|
||||
|
void SSAA::UpdateDescriptorSets(VkImageView image_view, size_t image_index) { |
||||
|
Image& image = m_dynamic_images[image_index]; |
||||
|
std::vector<VkDescriptorImageInfo> image_infos; |
||||
|
std::vector<VkWriteDescriptorSet> updates; |
||||
|
image_infos.reserve(2); |
||||
|
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, image_view, image.descriptor_sets[0], 0)); |
||||
|
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, image_view, image.descriptor_sets[0], 1)); |
||||
|
m_device.GetLogical().UpdateDescriptorSets(updates, {}); |
||||
|
} |
||||
|
|
||||
|
void SSAA::UploadImages(Scheduler& scheduler) { |
||||
|
if (!m_images_ready) { |
||||
|
m_images_ready = true; |
||||
|
scheduler.Record([&](vk::CommandBuffer cmdbuf) { |
||||
|
for (auto& image : m_dynamic_images) |
||||
|
ClearColorImage(cmdbuf, *image.image); |
||||
|
}); |
||||
|
scheduler.Finish(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void SSAA::Draw(Scheduler& scheduler, size_t image_index, VkImage* inout_image, VkImageView* inout_image_view) { |
||||
|
const Image& image{m_dynamic_images[image_index]}; |
||||
|
const VkImage input_image{*inout_image}; |
||||
|
const VkImage output_image{*image.image}; |
||||
|
const VkDescriptorSet descriptor_set{image.descriptor_sets[0]}; |
||||
|
const VkFramebuffer framebuffer{*image.framebuffer}; |
||||
|
const VkRenderPass renderpass{*m_renderpass}; |
||||
|
const VkPipeline pipeline{*m_pipeline}; |
||||
|
const VkPipelineLayout layout{*m_pipeline_layout}; |
||||
|
const VkExtent2D extent{m_extent}; |
||||
|
|
||||
|
UploadImages(scheduler); |
||||
|
UpdateDescriptorSets(*inout_image_view, image_index); |
||||
|
|
||||
|
scheduler.RequestOutsideRenderPassOperationContext(); |
||||
|
scheduler.Record([=](vk::CommandBuffer cmdbuf) { |
||||
|
TransitionImageLayout(cmdbuf, input_image, VK_IMAGE_LAYOUT_GENERAL); |
||||
|
TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL); |
||||
|
BeginRenderPass(cmdbuf, renderpass, framebuffer, extent); |
||||
|
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); |
||||
|
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, {}); |
||||
|
cmdbuf.Draw(3, 1, 0, 0); |
||||
|
cmdbuf.EndRenderPass(); |
||||
|
TransitionImageLayout(cmdbuf, output_image, VK_IMAGE_LAYOUT_GENERAL); |
||||
|
}); |
||||
|
|
||||
|
*inout_image = *image.image; |
||||
|
*inout_image_view = *image.image_view; |
||||
|
} |
||||
|
|
||||
|
} // namespace Vulkan
|
||||
@ -0,0 +1,63 @@ |
|||||
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project |
||||
|
// SPDX-License-Identifier: GPL-2.0-or-later |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "video_core/renderer_vulkan/present/anti_alias_pass.h" |
||||
|
#include "video_core/vulkan_common/vulkan_memory_allocator.h" |
||||
|
#include "video_core/vulkan_common/vulkan_wrapper.h" |
||||
|
|
||||
|
namespace Vulkan { |
||||
|
|
||||
|
class Device; |
||||
|
class Scheduler; |
||||
|
class StagingBufferPool; |
||||
|
|
||||
|
class SSAA final : public AntiAliasPass { |
||||
|
public: |
||||
|
explicit SSAA(const Device& device, MemoryAllocator& allocator, size_t image_count, |
||||
|
VkExtent2D extent); |
||||
|
~SSAA() override; |
||||
|
|
||||
|
void Draw(Scheduler& scheduler, size_t image_index, VkImage* inout_image, |
||||
|
VkImageView* inout_image_view) override; |
||||
|
|
||||
|
private: |
||||
|
void CreateImages(); |
||||
|
void CreateRenderPasses(); |
||||
|
void CreateSampler(); |
||||
|
void CreateShaders(); |
||||
|
void CreateDescriptorPool(); |
||||
|
void CreateDescriptorSetLayouts(); |
||||
|
void CreateDescriptorSets(); |
||||
|
void CreatePipelineLayouts(); |
||||
|
void CreatePipelines(); |
||||
|
void UpdateDescriptorSets(VkImageView image_view, size_t image_index); |
||||
|
void UploadImages(Scheduler& scheduler); |
||||
|
|
||||
|
const Device& m_device; |
||||
|
MemoryAllocator& m_allocator; |
||||
|
const VkExtent2D m_extent; |
||||
|
const u32 m_image_count; |
||||
|
|
||||
|
vk::ShaderModule m_vertex_shader{}; |
||||
|
vk::ShaderModule m_fragment_shader{}; |
||||
|
vk::DescriptorPool m_descriptor_pool{}; |
||||
|
vk::DescriptorSetLayout m_descriptor_set_layout{}; |
||||
|
vk::PipelineLayout m_pipeline_layout{}; |
||||
|
vk::Pipeline m_pipeline{}; |
||||
|
vk::RenderPass m_renderpass{}; |
||||
|
|
||||
|
struct Image { |
||||
|
vk::DescriptorSets descriptor_sets{}; |
||||
|
vk::Framebuffer framebuffer{}; |
||||
|
vk::Image image{}; |
||||
|
vk::ImageView image_view{}; |
||||
|
}; |
||||
|
std::vector<Image> m_dynamic_images{}; |
||||
|
bool m_images_ready{}; |
||||
|
|
||||
|
vk::Sampler m_sampler{}; |
||||
|
}; |
||||
|
|
||||
|
} // namespace Vulkan |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue