diff options
| author | 2022-11-03 22:21:58 -0700 | |
|---|---|---|
| committer | 2022-11-03 22:21:58 -0700 | |
| commit | 38e4382f532d606afbd3969990a9ca3bac70e557 (patch) | |
| tree | b9af6ed0a26285f4b0dcd5c21028601004267607 /src/video_core/renderer_vulkan | |
| parent | Merge pull request #9135 from liamwhite/service-thread-event (diff) | |
| parent | Merge branch 'master' into mipmap (diff) | |
| download | yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.gz yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.tar.xz yuzu-38e4382f532d606afbd3969990a9ca3bac70e557.zip | |
Merge pull request #8858 from vonchenplus/mipmap
video_core: Generate mipmap texture by drawing
Diffstat (limited to 'src/video_core/renderer_vulkan')
4 files changed, 48 insertions, 6 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h index b24f3424a..b7843e995 100644 --- a/src/video_core/renderer_vulkan/pipeline_helper.h +++ b/src/video_core/renderer_vulkan/pipeline_helper.h | |||
| @@ -68,13 +68,15 @@ public: | |||
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { | 70 | vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { |
| 71 | using Shader::Backend::SPIRV::RenderAreaLayout; | ||
| 71 | using Shader::Backend::SPIRV::RescalingLayout; | 72 | using Shader::Backend::SPIRV::RescalingLayout; |
| 72 | const u32 size_offset = is_compute ? sizeof(RescalingLayout::down_factor) : 0u; | 73 | const u32 size_offset = is_compute ? sizeof(RescalingLayout::down_factor) : 0u; |
| 73 | const VkPushConstantRange range{ | 74 | const VkPushConstantRange range{ |
| 74 | .stageFlags = static_cast<VkShaderStageFlags>( | 75 | .stageFlags = static_cast<VkShaderStageFlags>( |
| 75 | is_compute ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_ALL_GRAPHICS), | 76 | is_compute ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_ALL_GRAPHICS), |
| 76 | .offset = 0, | 77 | .offset = 0, |
| 77 | .size = static_cast<u32>(sizeof(RescalingLayout)) - size_offset, | 78 | .size = static_cast<u32>(sizeof(RescalingLayout)) - size_offset + |
| 79 | static_cast<u32>(sizeof(RenderAreaLayout)), | ||
| 78 | }; | 80 | }; |
| 79 | return device->GetLogical().CreatePipelineLayout({ | 81 | return device->GetLogical().CreatePipelineLayout({ |
| 80 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, | 82 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| @@ -167,6 +169,12 @@ private: | |||
| 167 | u32 image_bit{1u}; | 169 | u32 image_bit{1u}; |
| 168 | }; | 170 | }; |
| 169 | 171 | ||
| 172 | class RenderAreaPushConstant { | ||
| 173 | public: | ||
| 174 | bool uses_render_area{}; | ||
| 175 | std::array<f32, 4> words{}; | ||
| 176 | }; | ||
| 177 | |||
| 170 | inline void PushImageDescriptors(TextureCache& texture_cache, | 178 | inline void PushImageDescriptors(TextureCache& texture_cache, |
| 171 | UpdateDescriptorQueue& update_descriptor_queue, | 179 | UpdateDescriptorQueue& update_descriptor_queue, |
| 172 | const Shader::Info& info, RescalingPushConstant& rescaling, | 180 | const Shader::Info& info, RescalingPushConstant& rescaling, |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index c3f66c8a3..b4372a839 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -31,6 +31,7 @@ namespace { | |||
| 31 | using boost::container::small_vector; | 31 | using boost::container::small_vector; |
| 32 | using boost::container::static_vector; | 32 | using boost::container::static_vector; |
| 33 | using Shader::ImageBufferDescriptor; | 33 | using Shader::ImageBufferDescriptor; |
| 34 | using Shader::Backend::SPIRV::RENDERAREA_LAYOUT_OFFSET; | ||
| 34 | using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET; | 35 | using Shader::Backend::SPIRV::RESCALING_LAYOUT_DOWN_FACTOR_OFFSET; |
| 35 | using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET; | 36 | using Shader::Backend::SPIRV::RESCALING_LAYOUT_WORDS_OFFSET; |
| 36 | using Tegra::Texture::TexturePair; | 37 | using Tegra::Texture::TexturePair; |
| @@ -433,12 +434,19 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 433 | update_descriptor_queue.Acquire(); | 434 | update_descriptor_queue.Acquire(); |
| 434 | 435 | ||
| 435 | RescalingPushConstant rescaling; | 436 | RescalingPushConstant rescaling; |
| 437 | RenderAreaPushConstant render_area; | ||
| 436 | const VkSampler* samplers_it{samplers.data()}; | 438 | const VkSampler* samplers_it{samplers.data()}; |
| 437 | const VideoCommon::ImageViewInOut* views_it{views.data()}; | 439 | const VideoCommon::ImageViewInOut* views_it{views.data()}; |
| 438 | const auto prepare_stage{[&](size_t stage) LAMBDA_FORCEINLINE { | 440 | const auto prepare_stage{[&](size_t stage) LAMBDA_FORCEINLINE { |
| 439 | buffer_cache.BindHostStageBuffers(stage); | 441 | buffer_cache.BindHostStageBuffers(stage); |
| 440 | PushImageDescriptors(texture_cache, update_descriptor_queue, stage_infos[stage], rescaling, | 442 | PushImageDescriptors(texture_cache, update_descriptor_queue, stage_infos[stage], rescaling, |
| 441 | samplers_it, views_it); | 443 | samplers_it, views_it); |
| 444 | const auto& info{stage_infos[0]}; | ||
| 445 | if (info.uses_render_area) { | ||
| 446 | render_area.uses_render_area = true; | ||
| 447 | render_area.words = {static_cast<float>(regs.render_area.width), | ||
| 448 | static_cast<float>(regs.render_area.height)}; | ||
| 449 | } | ||
| 442 | }}; | 450 | }}; |
| 443 | if constexpr (Spec::enabled_stages[0]) { | 451 | if constexpr (Spec::enabled_stages[0]) { |
| 444 | prepare_stage(0); | 452 | prepare_stage(0); |
| @@ -455,10 +463,11 @@ void GraphicsPipeline::ConfigureImpl(bool is_indexed) { | |||
| 455 | if constexpr (Spec::enabled_stages[4]) { | 463 | if constexpr (Spec::enabled_stages[4]) { |
| 456 | prepare_stage(4); | 464 | prepare_stage(4); |
| 457 | } | 465 | } |
| 458 | ConfigureDraw(rescaling); | 466 | ConfigureDraw(rescaling, render_area); |
| 459 | } | 467 | } |
| 460 | 468 | ||
| 461 | void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling) { | 469 | void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling, |
| 470 | const RenderAreaPushConstant& render_are) { | ||
| 462 | texture_cache.UpdateRenderTargets(false); | 471 | texture_cache.UpdateRenderTargets(false); |
| 463 | scheduler.RequestRenderpass(texture_cache.GetFramebuffer()); | 472 | scheduler.RequestRenderpass(texture_cache.GetFramebuffer()); |
| 464 | 473 | ||
| @@ -474,7 +483,9 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling) { | |||
| 474 | const bool bind_pipeline{scheduler.UpdateGraphicsPipeline(this)}; | 483 | const bool bind_pipeline{scheduler.UpdateGraphicsPipeline(this)}; |
| 475 | const void* const descriptor_data{update_descriptor_queue.UpdateData()}; | 484 | const void* const descriptor_data{update_descriptor_queue.UpdateData()}; |
| 476 | scheduler.Record([this, descriptor_data, bind_pipeline, rescaling_data = rescaling.Data(), | 485 | scheduler.Record([this, descriptor_data, bind_pipeline, rescaling_data = rescaling.Data(), |
| 477 | is_rescaling, update_rescaling](vk::CommandBuffer cmdbuf) { | 486 | is_rescaling, update_rescaling, |
| 487 | uses_render_area = render_are.uses_render_area, | ||
| 488 | render_area_data = render_are.words](vk::CommandBuffer cmdbuf) { | ||
| 478 | if (bind_pipeline) { | 489 | if (bind_pipeline) { |
| 479 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); | 490 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); |
| 480 | } | 491 | } |
| @@ -483,11 +494,16 @@ void GraphicsPipeline::ConfigureDraw(const RescalingPushConstant& rescaling) { | |||
| 483 | rescaling_data.data()); | 494 | rescaling_data.data()); |
| 484 | if (update_rescaling) { | 495 | if (update_rescaling) { |
| 485 | const f32 config_down_factor{Settings::values.resolution_info.down_factor}; | 496 | const f32 config_down_factor{Settings::values.resolution_info.down_factor}; |
| 486 | const f32 scale_down_factor{is_rescaling ? config_down_factor : 1.0f}; | 497 | const f32 scale_down_factor{is_rescaling ? config_down_factor : 2.0f}; |
| 487 | cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, | 498 | cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, |
| 488 | RESCALING_LAYOUT_DOWN_FACTOR_OFFSET, sizeof(scale_down_factor), | 499 | RESCALING_LAYOUT_DOWN_FACTOR_OFFSET, sizeof(scale_down_factor), |
| 489 | &scale_down_factor); | 500 | &scale_down_factor); |
| 490 | } | 501 | } |
| 502 | if (uses_render_area) { | ||
| 503 | cmdbuf.PushConstants(*pipeline_layout, VK_SHADER_STAGE_ALL_GRAPHICS, | ||
| 504 | RENDERAREA_LAYOUT_OFFSET, sizeof(render_area_data), | ||
| 505 | &render_area_data); | ||
| 506 | } | ||
| 491 | if (!descriptor_set_layout) { | 507 | if (!descriptor_set_layout) { |
| 492 | return; | 508 | return; |
| 493 | } | 509 | } |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h index 85602592b..6bf577d25 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h | |||
| @@ -62,6 +62,7 @@ class Device; | |||
| 62 | class PipelineStatistics; | 62 | class PipelineStatistics; |
| 63 | class RenderPassCache; | 63 | class RenderPassCache; |
| 64 | class RescalingPushConstant; | 64 | class RescalingPushConstant; |
| 65 | class RenderAreaPushConstant; | ||
| 65 | class Scheduler; | 66 | class Scheduler; |
| 66 | class UpdateDescriptorQueue; | 67 | class UpdateDescriptorQueue; |
| 67 | 68 | ||
| @@ -119,7 +120,8 @@ private: | |||
| 119 | template <typename Spec> | 120 | template <typename Spec> |
| 120 | void ConfigureImpl(bool is_indexed); | 121 | void ConfigureImpl(bool is_indexed); |
| 121 | 122 | ||
| 122 | void ConfigureDraw(const RescalingPushConstant& rescaling); | 123 | void ConfigureDraw(const RescalingPushConstant& rescaling, |
| 124 | const RenderAreaPushConstant& render_are); | ||
| 123 | 125 | ||
| 124 | void MakePipeline(VkRenderPass render_pass); | 126 | void MakePipeline(VkRenderPass render_pass); |
| 125 | 127 | ||
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index d94dbf873..5af3c930b 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -683,6 +683,22 @@ void RasterizerVulkan::UpdateViewportsState(Tegra::Engines::Maxwell3D::Regs& reg | |||
| 683 | if (!state_tracker.TouchViewports()) { | 683 | if (!state_tracker.TouchViewports()) { |
| 684 | return; | 684 | return; |
| 685 | } | 685 | } |
| 686 | if (!regs.viewport_transform_enabled) { | ||
| 687 | const auto x = static_cast<float>(regs.render_area.x); | ||
| 688 | const auto y = static_cast<float>(regs.render_area.y); | ||
| 689 | const auto width = static_cast<float>(regs.render_area.width); | ||
| 690 | const auto height = static_cast<float>(regs.render_area.height); | ||
| 691 | VkViewport viewport{ | ||
| 692 | .x = x, | ||
| 693 | .y = y, | ||
| 694 | .width = width != 0.0f ? width : 1.0f, | ||
| 695 | .height = height != 0.0f ? height : 1.0f, | ||
| 696 | .minDepth = 0.0f, | ||
| 697 | .maxDepth = 1.0f, | ||
| 698 | }; | ||
| 699 | scheduler.Record([viewport](vk::CommandBuffer cmdbuf) { cmdbuf.SetViewport(0, viewport); }); | ||
| 700 | return; | ||
| 701 | } | ||
| 686 | const bool is_rescaling{texture_cache.IsRescaling()}; | 702 | const bool is_rescaling{texture_cache.IsRescaling()}; |
| 687 | const float scale = is_rescaling ? Settings::values.resolution_info.up_factor : 1.0f; | 703 | const float scale = is_rescaling ? Settings::values.resolution_info.up_factor : 1.0f; |
| 688 | const std::array viewports{ | 704 | const std::array viewports{ |