layer + window pass take device

This commit is contained in:
lizzie 2026-06-10 10:21:41 +00:00 committed by crueter
parent ea91500134
commit 201495db80
5 changed files with 64 additions and 68 deletions

View file

@ -56,13 +56,15 @@ VkFormat GetFormat(const Tegra::FramebufferConfig& framebuffer) {
} // Anonymous namespace
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_)
: device(device_), memory_allocator(memory_allocator_), scheduler(scheduler_),
device_memory(device_memory_), filters(filters_), image_count(image_count_) {
CreateDescriptorPool();
CreateDescriptorSets(layout);
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_)
: memory_allocator(memory_allocator_)
, scheduler(scheduler_)
, device_memory(device_memory_)
, filters(filters_)
, image_count(image_count_)
{
CreateDescriptorPool(device);
CreateDescriptorSets(device, layout);
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr) {
sr_filter.emplace<FSR>(device, memory_allocator, image_count, output_size);
} else if (filters.get_scaling_filter() == Settings::ScalingFilter::Sgsr) {
@ -76,7 +78,7 @@ Layer::~Layer() {
ReleaseRawImages();
}
void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
void Layer::ConfigureDraw(const Device& device, PresentPushConstants* out_push_constants,
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
VkSampler sampler, size_t image_index,
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 bool use_accelerated = texture_info.has_value();
RefreshResources(framebuffer);
SetAntiAliasPass();
RefreshResources(device, framebuffer);
SetAntiAliasPass(device);
// Finish any pending renderpass
scheduler.RequestOutsideRenderPassOperationContext();
@ -127,23 +129,23 @@ void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
crop_rect = {0, 0, 1, 1};
}
SetMatrixData(*out_push_constants, layout);
SetVertexData(*out_push_constants, layout, crop_rect);
SetMatrixData(device, *out_push_constants, layout);
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];
}
void Layer::CreateDescriptorPool() {
void Layer::CreateDescriptorPool(const Device& device) {
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);
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{
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = nullptr,
@ -159,7 +161,7 @@ void Layer::CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer) {
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);
resource_ticks.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 &&
framebuffer.pixel_format == pixel_format && !raw_images.empty()) {
return;
@ -184,11 +186,11 @@ void Layer::RefreshResources(const Tegra::FramebufferConfig& framebuffer) {
anti_alias.emplace<std::monostate>();
ReleaseRawImages();
CreateStagingBuffer(framebuffer);
CreateRawImages(framebuffer);
CreateStagingBuffer(device, 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())
return;
@ -229,20 +231,17 @@ u64 Layer::GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer,
return GetSizeInBytes(framebuffer) * image_index;
}
void Layer::SetMatrixData(PresentPushConstants& data,
const Layout::FramebufferLayout& layout) const {
data.modelview_matrix =
MakeOrthographicMatrix(static_cast<f32>(layout.width), static_cast<f32>(layout.height));
void Layer::SetMatrixData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout) const {
data.modelview_matrix = MakeOrthographicMatrix(f32(layout.width), static_cast<f32>(layout.height));
}
void Layer::SetVertexData(PresentPushConstants& data, const Layout::FramebufferLayout& layout,
const Common::Rectangle<f32>& crop) const {
void Layer::SetVertexData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout, const Common::Rectangle<f32>& crop) const {
// Map the coordinates to the screen.
const auto& screen = layout.screen;
const auto x = static_cast<f32>(screen.left);
const auto y = static_cast<f32>(screen.top);
const auto w = static_cast<f32>(screen.GetWidth());
const auto h = static_cast<f32>(screen.GetHeight());
const auto x = f32(screen.left);
const auto y = f32(screen.top);
const auto w = f32(screen.GetWidth());
const auto h = f32(screen.GetHeight());
data.vertices[0] = ScreenRectVertex(x, y, crop.left, 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);
}
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{
.sampler = sampler,
.imageView = image_view,

View file

@ -52,33 +52,31 @@ public:
const PresentFilters& filters);
~Layer();
void ConfigureDraw(PresentPushConstants* out_push_constants,
void ConfigureDraw(const Device& device, PresentPushConstants* out_push_constants,
VkDescriptorSet* out_descriptor_set, RasterizerVulkan& rasterizer,
VkSampler sampler, size_t image_index,
const Tegra::FramebufferConfig& framebuffer,
const Layout::FramebufferLayout& layout);
private:
void CreateDescriptorPool();
void CreateDescriptorSets(VkDescriptorSetLayout layout);
void CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer);
void CreateRawImages(const Tegra::FramebufferConfig& framebuffer);
void CreateDescriptorPool(const Device& device);
void CreateDescriptorSets(const Device& device, VkDescriptorSetLayout layout);
void CreateStagingBuffer(const Device& device, const Tegra::FramebufferConfig& framebuffer);
void CreateRawImages(const Device& device, const Tegra::FramebufferConfig& framebuffer);
void RefreshResources(const Tegra::FramebufferConfig& framebuffer);
void SetAntiAliasPass();
void RefreshResources(const Device& device, const Tegra::FramebufferConfig& framebuffer);
void SetAntiAliasPass(const Device& device);
void ReleaseRawImages();
u64 CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const;
u64 GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer, size_t image_index) const;
void SetMatrixData(PresentPushConstants& data, const Layout::FramebufferLayout& layout) const;
void SetVertexData(PresentPushConstants& data, const Layout::FramebufferLayout& layout,
const Common::Rectangle<f32>& crop) const;
void UpdateDescriptorSet(VkImageView image_view, VkSampler sampler, size_t image_index);
void SetMatrixData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout) const;
void SetVertexData(const Device& device, PresentPushConstants& data, const Layout::FramebufferLayout& layout, const Common::Rectangle<f32>& crop) const;
void UpdateDescriptorSet(const Device& device, VkImageView image_view, VkSampler sampler, size_t image_index);
void UpdateRawImage(const Tegra::FramebufferConfig& framebuffer, size_t image_index);
private:
const Device& device;
MemoryAllocator& memory_allocator;
Scheduler& scheduler;
Tegra::MaxwellDeviceMemoryManager& device_memory;

View file

@ -15,19 +15,20 @@
namespace Vulkan {
WindowAdaptPass::WindowAdaptPass(const Device& device_, VkFormat frame_format,
vk::Sampler&& sampler_, vk::ShaderModule&& fragment_shader_)
: device(device_), sampler(std::move(sampler_)), fragment_shader(std::move(fragment_shader_)) {
CreateDescriptorSetLayout();
CreatePipelineLayout();
CreateVertexShader();
CreateRenderPass(frame_format);
CreatePipelines();
WindowAdaptPass::WindowAdaptPass(const Device& device, VkFormat frame_format, vk::Sampler&& sampler_, vk::ShaderModule&& fragment_shader_)
: sampler(std::move(sampler_))
, fragment_shader(std::move(fragment_shader_))
{
CreateDescriptorSetLayout(device);
CreatePipelineLayout(device);
CreateVertexShader(device);
CreateRenderPass(device, frame_format);
CreatePipelines(device);
}
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::span<const Tegra::FramebufferConfig> configs,
const Layout::FramebufferLayout& layout, Frame* dst) {
@ -60,7 +61,7 @@ void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, s
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);
layer_it++;
}
@ -111,12 +112,12 @@ VkRenderPass WindowAdaptPass::GetRenderPass() {
return *render_pass;
}
void WindowAdaptPass::CreateDescriptorSetLayout() {
void WindowAdaptPass::CreateDescriptorSetLayout(const Device& device) {
descriptor_set_layout =
CreateWrappedDescriptorSetLayout(device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER});
}
void WindowAdaptPass::CreatePipelineLayout() {
void WindowAdaptPass::CreatePipelineLayout(const Device& device) {
const VkPushConstantRange range{
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.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);
}
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);
}
void WindowAdaptPass::CreatePipelines() {
void WindowAdaptPass::CreatePipelines(const Device& device) {
opaque_pipeline = CreateWrappedPipeline(device, render_pass, pipeline_layout,
std::tie(vertex_shader, fragment_shader));
premultiplied_pipeline = CreateWrappedPremultipliedBlendingPipeline(

View file

@ -30,7 +30,7 @@ public:
vk::ShaderModule&& fragment_shader);
~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,
const Layout::FramebufferLayout& layout, Frame* dst);
@ -38,14 +38,12 @@ public:
VkRenderPass GetRenderPass();
private:
void CreateDescriptorSetLayout();
void CreatePipelineLayout();
void CreateVertexShader();
void CreateRenderPass(VkFormat frame_format);
void CreatePipelines();
void CreateDescriptorSetLayout(const Device& device);
void CreatePipelineLayout(const Device& device);
void CreateVertexShader(const Device& device);
void CreateRenderPass(const Device& device, VkFormat frame_format);
void CreatePipelines(const Device& device);
private:
const Device& device;
vk::DescriptorSetLayout descriptor_set_layout;
vk::PipelineLayout pipeline_layout;
vk::Sampler sampler;

View file

@ -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) {
image_index = 0;