mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-06-24 20:09:28 -04:00
layer + window pass take device
This commit is contained in:
parent
0000941304
commit
676d663e56
5 changed files with 64 additions and 68 deletions
|
|
@ -56,13 +56,15 @@ VkFormat GetFormat(const Tegra::FramebufferConfig& framebuffer) {
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
Layer::Layer(const Device& device_, MemoryAllocator& memory_allocator_, Scheduler& scheduler_,
|
Layer::Layer(const Device& device, MemoryAllocator& memory_allocator_, Scheduler& scheduler_, Tegra::MaxwellDeviceMemoryManager& device_memory_, size_t image_count_, VkExtent2D output_size, VkDescriptorSetLayout layout, const PresentFilters& filters_)
|
||||||
Tegra::MaxwellDeviceMemoryManager& device_memory_, size_t image_count_,
|
: memory_allocator(memory_allocator_)
|
||||||
VkExtent2D output_size, VkDescriptorSetLayout layout, const PresentFilters& filters_)
|
, scheduler(scheduler_)
|
||||||
: device(device_), memory_allocator(memory_allocator_), scheduler(scheduler_),
|
, device_memory(device_memory_)
|
||||||
device_memory(device_memory_), filters(filters_), image_count(image_count_) {
|
, filters(filters_)
|
||||||
CreateDescriptorPool();
|
, image_count(image_count_)
|
||||||
CreateDescriptorSets(layout);
|
{
|
||||||
|
CreateDescriptorPool(device);
|
||||||
|
CreateDescriptorSets(device, layout);
|
||||||
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr) {
|
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr) {
|
||||||
sr_filter.emplace<FSR>(device, memory_allocator, image_count, output_size);
|
sr_filter.emplace<FSR>(device, memory_allocator, image_count, output_size);
|
||||||
} else if (filters.get_scaling_filter() == Settings::ScalingFilter::Sgsr) {
|
} else if (filters.get_scaling_filter() == Settings::ScalingFilter::Sgsr) {
|
||||||
|
|
@ -76,7 +78,7 @@ Layer::~Layer() {
|
||||||
ReleaseRawImages();
|
ReleaseRawImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
|
void Layer::ConfigureDraw(const Device& device, PresentPushConstants* out_push_constants,
|
||||||
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
|
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
|
||||||
VkSampler sampler, size_t image_index,
|
VkSampler sampler, size_t image_index,
|
||||||
const Tegra::FramebufferConfig& framebuffer,
|
const Tegra::FramebufferConfig& framebuffer,
|
||||||
|
|
@ -89,8 +91,8 @@ void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
|
||||||
const u32 scaled_height = texture_info ? texture_info->scaled_height : texture_height;
|
const u32 scaled_height = texture_info ? texture_info->scaled_height : texture_height;
|
||||||
const bool use_accelerated = texture_info.has_value();
|
const bool use_accelerated = texture_info.has_value();
|
||||||
|
|
||||||
RefreshResources(framebuffer);
|
RefreshResources(device, framebuffer);
|
||||||
SetAntiAliasPass();
|
SetAntiAliasPass(device);
|
||||||
|
|
||||||
// Finish any pending renderpass
|
// Finish any pending renderpass
|
||||||
scheduler.RequestOutsideRenderPassOperationContext();
|
scheduler.RequestOutsideRenderPassOperationContext();
|
||||||
|
|
@ -127,23 +129,23 @@ void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
|
||||||
crop_rect = {0, 0, 1, 1};
|
crop_rect = {0, 0, 1, 1};
|
||||||
}
|
}
|
||||||
|
|
||||||
SetMatrixData(*out_push_constants, layout);
|
SetMatrixData(device, *out_push_constants, layout);
|
||||||
SetVertexData(*out_push_constants, layout, crop_rect);
|
SetVertexData(device, *out_push_constants, layout, crop_rect);
|
||||||
|
|
||||||
UpdateDescriptorSet(source_image_view, sampler, image_index);
|
UpdateDescriptorSet(device, source_image_view, sampler, image_index);
|
||||||
*out_descriptor_set = descriptor_sets[image_index];
|
*out_descriptor_set = descriptor_sets[image_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::CreateDescriptorPool() {
|
void Layer::CreateDescriptorPool(const Device& device) {
|
||||||
descriptor_pool = CreateWrappedDescriptorPool(device, image_count, image_count);
|
descriptor_pool = CreateWrappedDescriptorPool(device, image_count, image_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::CreateDescriptorSets(VkDescriptorSetLayout layout) {
|
void Layer::CreateDescriptorSets(const Device& device, VkDescriptorSetLayout layout) {
|
||||||
const std::vector layouts(image_count, layout);
|
const std::vector layouts(image_count, layout);
|
||||||
descriptor_sets = CreateWrappedDescriptorSets(descriptor_pool, layouts);
|
descriptor_sets = CreateWrappedDescriptorSets(descriptor_pool, layouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) {
|
void Layer::CreateStagingBuffer(const Device& device, 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,
|
||||||
|
|
@ -159,7 +161,7 @@ void Layer::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) {
|
||||||
buffer = memory_allocator.CreateBuffer(ci, MemoryUsage::Upload);
|
buffer = memory_allocator.CreateBuffer(ci, MemoryUsage::Upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) {
|
void Layer::CreateRawImages(const Device& device, const Tegra::FramebufferConfig& framebuffer) {
|
||||||
const auto format = GetFormat(framebuffer);
|
const auto format = GetFormat(framebuffer);
|
||||||
resource_ticks.resize(image_count);
|
resource_ticks.resize(image_count);
|
||||||
raw_images.resize(image_count);
|
raw_images.resize(image_count);
|
||||||
|
|
@ -172,7 +174,7 @@ void Layer::CreateRawImages(const Tegra::FramebufferConfig& framebuffer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::RefreshResources(const Tegra::FramebufferConfig& framebuffer) {
|
void Layer::RefreshResources(const Device& device, const Tegra::FramebufferConfig& framebuffer) {
|
||||||
if (framebuffer.width == raw_width && framebuffer.height == raw_height &&
|
if (framebuffer.width == raw_width && framebuffer.height == raw_height &&
|
||||||
framebuffer.pixel_format == pixel_format && !raw_images.empty()) {
|
framebuffer.pixel_format == pixel_format && !raw_images.empty()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -184,11 +186,11 @@ void Layer::RefreshResources(const Tegra::FramebufferConfig& framebuffer) {
|
||||||
anti_alias.emplace<std::monostate>();
|
anti_alias.emplace<std::monostate>();
|
||||||
|
|
||||||
ReleaseRawImages();
|
ReleaseRawImages();
|
||||||
CreateStagingBuffer(framebuffer);
|
CreateStagingBuffer(device, framebuffer);
|
||||||
CreateRawImages(framebuffer);
|
CreateRawImages(device, framebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::SetAntiAliasPass() {
|
void Layer::SetAntiAliasPass(const Device& device) {
|
||||||
if (!std::holds_alternative<std::monostate>(anti_alias) && anti_alias_setting == filters.get_anti_aliasing())
|
if (!std::holds_alternative<std::monostate>(anti_alias) && anti_alias_setting == filters.get_anti_aliasing())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -229,20 +231,17 @@ u64 Layer::GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer,
|
||||||
return GetSizeInBytes(framebuffer) * image_index;
|
return GetSizeInBytes(framebuffer) * image_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::SetMatrixData(PresentPushConstants& data,
|
void Layer::SetMatrixData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout) const {
|
||||||
const Layout::FramebufferLayout& layout) const {
|
data.modelview_matrix = MakeOrthographicMatrix(f32(layout.width), static_cast<f32>(layout.height));
|
||||||
data.modelview_matrix =
|
|
||||||
MakeOrthographicMatrix(static_cast<f32>(layout.width), static_cast<f32>(layout.height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::SetVertexData(PresentPushConstants& data, const Layout::FramebufferLayout& layout,
|
void Layer::SetVertexData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout, const Common::Rectangle<f32>& crop) const {
|
||||||
const Common::Rectangle<f32>& crop) const {
|
|
||||||
// Map the coordinates to the screen.
|
// Map the coordinates to the screen.
|
||||||
const auto& screen = layout.screen;
|
const auto& screen = layout.screen;
|
||||||
const auto x = static_cast<f32>(screen.left);
|
const auto x = f32(screen.left);
|
||||||
const auto y = static_cast<f32>(screen.top);
|
const auto y = f32(screen.top);
|
||||||
const auto w = static_cast<f32>(screen.GetWidth());
|
const auto w = f32(screen.GetWidth());
|
||||||
const auto h = static_cast<f32>(screen.GetHeight());
|
const auto h = f32(screen.GetHeight());
|
||||||
|
|
||||||
data.vertices[0] = ScreenRectVertex(x, y, crop.left, crop.top);
|
data.vertices[0] = ScreenRectVertex(x, y, crop.left, crop.top);
|
||||||
data.vertices[1] = ScreenRectVertex(x + w, y, crop.right, crop.top);
|
data.vertices[1] = ScreenRectVertex(x + w, y, crop.right, crop.top);
|
||||||
|
|
@ -250,7 +249,7 @@ void Layer::SetVertexData(PresentPushConstants& data, const Layout::FramebufferL
|
||||||
data.vertices[3] = ScreenRectVertex(x + w, y + h, crop.right, crop.bottom);
|
data.vertices[3] = ScreenRectVertex(x + w, y + h, crop.right, crop.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::UpdateDescriptorSet(VkImageView image_view, VkSampler sampler, size_t image_index) {
|
void Layer::UpdateDescriptorSet(const Device& device, VkImageView image_view, VkSampler sampler, size_t image_index) {
|
||||||
const VkDescriptorImageInfo image_info{
|
const VkDescriptorImageInfo image_info{
|
||||||
.sampler = sampler,
|
.sampler = sampler,
|
||||||
.imageView = image_view,
|
.imageView = image_view,
|
||||||
|
|
|
||||||
|
|
@ -52,33 +52,31 @@ public:
|
||||||
const PresentFilters& filters);
|
const PresentFilters& filters);
|
||||||
~Layer();
|
~Layer();
|
||||||
|
|
||||||
void ConfigureDraw(PresentPushConstants* out_push_constants,
|
void ConfigureDraw(const Device& device, PresentPushConstants* out_push_constants,
|
||||||
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
|
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
|
||||||
VkSampler sampler, size_t image_index,
|
VkSampler sampler, size_t image_index,
|
||||||
const Tegra::FramebufferConfig& framebuffer,
|
const Tegra::FramebufferConfig& framebuffer,
|
||||||
const Layout::FramebufferLayout& layout);
|
const Layout::FramebufferLayout& layout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateDescriptorPool();
|
void CreateDescriptorPool(const Device& device);
|
||||||
void CreateDescriptorSets(VkDescriptorSetLayout layout);
|
void CreateDescriptorSets(const Device& device, VkDescriptorSetLayout layout);
|
||||||
void CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer);
|
void CreateStagingBuffer(const Device& device, const Tegra::FramebufferConfig& framebuffer);
|
||||||
void CreateRawImages(const Tegra::FramebufferConfig& framebuffer);
|
void CreateRawImages(const Device& device, const Tegra::FramebufferConfig& framebuffer);
|
||||||
|
|
||||||
void RefreshResources(const Tegra::FramebufferConfig& framebuffer);
|
void RefreshResources(const Device& device, const Tegra::FramebufferConfig& framebuffer);
|
||||||
void SetAntiAliasPass();
|
void SetAntiAliasPass(const Device& device);
|
||||||
void ReleaseRawImages();
|
void ReleaseRawImages();
|
||||||
|
|
||||||
u64 CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const;
|
u64 CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const;
|
||||||
u64 GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer, size_t image_index) const;
|
u64 GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer, size_t image_index) const;
|
||||||
|
|
||||||
void SetMatrixData(PresentPushConstants& data, const Layout::FramebufferLayout& layout) const;
|
void SetMatrixData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout) const;
|
||||||
void SetVertexData(PresentPushConstants& data, const Layout::FramebufferLayout& layout,
|
void SetVertexData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout, const Common::Rectangle<f32>& crop) const;
|
||||||
const Common::Rectangle<f32>& crop) const;
|
void UpdateDescriptorSet(const Device& device, VkImageView image_view, VkSampler sampler, size_t image_index);
|
||||||
void UpdateDescriptorSet(VkImageView image_view, VkSampler sampler, size_t image_index);
|
|
||||||
void UpdateRawImage(const Tegra::FramebufferConfig& framebuffer, size_t image_index);
|
void UpdateRawImage(const Tegra::FramebufferConfig& framebuffer, size_t image_index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Device& device;
|
|
||||||
MemoryAllocator& memory_allocator;
|
MemoryAllocator& memory_allocator;
|
||||||
Scheduler& scheduler;
|
Scheduler& scheduler;
|
||||||
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
Tegra::MaxwellDeviceMemoryManager& device_memory;
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,20 @@
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
WindowAdaptPass::WindowAdaptPass(const Device& device_, VkFormat frame_format,
|
WindowAdaptPass::WindowAdaptPass(const Device& device, VkFormat frame_format, vk::Sampler&& sampler_, vk::ShaderModule&& fragment_shader_)
|
||||||
vk::Sampler&& sampler_, vk::ShaderModule&& fragment_shader_)
|
: sampler(std::move(sampler_))
|
||||||
: device(device_), sampler(std::move(sampler_)), fragment_shader(std::move(fragment_shader_)) {
|
, fragment_shader(std::move(fragment_shader_))
|
||||||
CreateDescriptorSetLayout();
|
{
|
||||||
CreatePipelineLayout();
|
CreateDescriptorSetLayout(device);
|
||||||
CreateVertexShader();
|
CreatePipelineLayout(device);
|
||||||
CreateRenderPass(frame_format);
|
CreateVertexShader(device);
|
||||||
CreatePipelines();
|
CreateRenderPass(device, frame_format);
|
||||||
|
CreatePipelines(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowAdaptPass::~WindowAdaptPass() = default;
|
WindowAdaptPass::~WindowAdaptPass() = default;
|
||||||
|
|
||||||
void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, size_t image_index,
|
void WindowAdaptPass::Draw(const Device& device, RasterizerVulkan& rasterizer, Scheduler& scheduler, size_t image_index,
|
||||||
std::list<Layer>& layers,
|
std::list<Layer>& layers,
|
||||||
std::span<const Tegra::FramebufferConfig> configs,
|
std::span<const Tegra::FramebufferConfig> configs,
|
||||||
const Layout::FramebufferLayout& layout, Frame* dst) {
|
const Layout::FramebufferLayout& layout, Frame* dst) {
|
||||||
|
|
@ -60,7 +61,7 @@ void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, s
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
layer_it->ConfigureDraw(&push_constants[i], &descriptor_sets[i], rasterizer, *sampler,
|
layer_it->ConfigureDraw(device, &push_constants[i], &descriptor_sets[i], rasterizer, *sampler,
|
||||||
image_index, configs[i], layout);
|
image_index, configs[i], layout);
|
||||||
layer_it++;
|
layer_it++;
|
||||||
}
|
}
|
||||||
|
|
@ -111,12 +112,12 @@ VkRenderPass WindowAdaptPass::GetRenderPass() {
|
||||||
return *render_pass;
|
return *render_pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowAdaptPass::CreateDescriptorSetLayout() {
|
void WindowAdaptPass::CreateDescriptorSetLayout(const Device& device) {
|
||||||
descriptor_set_layout =
|
descriptor_set_layout =
|
||||||
CreateWrappedDescriptorSetLayout(device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER});
|
CreateWrappedDescriptorSetLayout(device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowAdaptPass::CreatePipelineLayout() {
|
void WindowAdaptPass::CreatePipelineLayout(const Device& device) {
|
||||||
const VkPushConstantRange range{
|
const VkPushConstantRange range{
|
||||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
|
|
@ -134,15 +135,15 @@ void WindowAdaptPass::CreatePipelineLayout() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowAdaptPass::CreateVertexShader() {
|
void WindowAdaptPass::CreateVertexShader(const Device& device) {
|
||||||
vertex_shader = BuildShader(device, VULKAN_PRESENT_VERT_SPV);
|
vertex_shader = BuildShader(device, VULKAN_PRESENT_VERT_SPV);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowAdaptPass::CreateRenderPass(VkFormat frame_format) {
|
void WindowAdaptPass::CreateRenderPass(const Device& device, VkFormat frame_format) {
|
||||||
render_pass = CreateWrappedRenderPass(device, frame_format, VK_IMAGE_LAYOUT_UNDEFINED);
|
render_pass = CreateWrappedRenderPass(device, frame_format, VK_IMAGE_LAYOUT_UNDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowAdaptPass::CreatePipelines() {
|
void WindowAdaptPass::CreatePipelines(const Device& device) {
|
||||||
opaque_pipeline = CreateWrappedPipeline(device, render_pass, pipeline_layout,
|
opaque_pipeline = CreateWrappedPipeline(device, render_pass, pipeline_layout,
|
||||||
std::tie(vertex_shader, fragment_shader));
|
std::tie(vertex_shader, fragment_shader));
|
||||||
premultiplied_pipeline = CreateWrappedPremultipliedBlendingPipeline(
|
premultiplied_pipeline = CreateWrappedPremultipliedBlendingPipeline(
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public:
|
||||||
vk::ShaderModule&& fragment_shader);
|
vk::ShaderModule&& fragment_shader);
|
||||||
~WindowAdaptPass();
|
~WindowAdaptPass();
|
||||||
|
|
||||||
void Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, size_t image_index,
|
void Draw(const Device& device, RasterizerVulkan& rasterizer, Scheduler& scheduler, size_t image_index,
|
||||||
std::list<Layer>& layers, std::span<const Tegra::FramebufferConfig> configs,
|
std::list<Layer>& layers, std::span<const Tegra::FramebufferConfig> configs,
|
||||||
const Layout::FramebufferLayout& layout, Frame* dst);
|
const Layout::FramebufferLayout& layout, Frame* dst);
|
||||||
|
|
||||||
|
|
@ -38,14 +38,12 @@ public:
|
||||||
VkRenderPass GetRenderPass();
|
VkRenderPass GetRenderPass();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void CreateDescriptorSetLayout();
|
void CreateDescriptorSetLayout(const Device& device);
|
||||||
void CreatePipelineLayout();
|
void CreatePipelineLayout(const Device& device);
|
||||||
void CreateVertexShader();
|
void CreateVertexShader(const Device& device);
|
||||||
void CreateRenderPass(VkFormat frame_format);
|
void CreateRenderPass(const Device& device, VkFormat frame_format);
|
||||||
void CreatePipelines();
|
void CreatePipelines(const Device& device);
|
||||||
|
|
||||||
private:
|
|
||||||
const Device& device;
|
|
||||||
vk::DescriptorSetLayout descriptor_set_layout;
|
vk::DescriptorSetLayout descriptor_set_layout;
|
||||||
vk::PipelineLayout pipeline_layout;
|
vk::PipelineLayout pipeline_layout;
|
||||||
vk::Sampler sampler;
|
vk::Sampler sampler;
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ void BlitScreen::DrawToFrame(RasterizerVulkan& rasterizer, Frame* frame,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window_adapt->Draw(rasterizer, scheduler, image_index, layers, framebuffers, layout, frame);
|
window_adapt->Draw(device, rasterizer, scheduler, image_index, layers, framebuffers, layout, frame);
|
||||||
|
|
||||||
if (++image_index >= image_count) {
|
if (++image_index >= image_count) {
|
||||||
image_index = 0;
|
image_index = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue