blit_image.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <compare>
  6. #include "video_core/engines/fermi_2d.h"
  7. #include "video_core/renderer_vulkan/vk_descriptor_pool.h"
  8. #include "video_core/texture_cache/types.h"
  9. #include "video_core/vulkan_common/vulkan_wrapper.h"
  10. namespace Vulkan {
  11. using VideoCommon::Region2D;
  12. class Device;
  13. class Framebuffer;
  14. class ImageView;
  15. class StateTracker;
  16. class VKScheduler;
  17. struct BlitImagePipelineKey {
  18. constexpr auto operator<=>(const BlitImagePipelineKey&) const noexcept = default;
  19. VkRenderPass renderpass;
  20. Tegra::Engines::Fermi2D::Operation operation;
  21. };
  22. class BlitImageHelper {
  23. public:
  24. explicit BlitImageHelper(const Device& device, VKScheduler& scheduler,
  25. StateTracker& state_tracker, DescriptorPool& descriptor_pool);
  26. ~BlitImageHelper();
  27. void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
  28. const Region2D& dst_region, const Region2D& src_region,
  29. Tegra::Engines::Fermi2D::Filter filter,
  30. Tegra::Engines::Fermi2D::Operation operation);
  31. void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,
  32. VkImageView src_stencil_view, const Region2D& dst_region,
  33. const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
  34. Tegra::Engines::Fermi2D::Operation operation);
  35. void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  36. void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  37. void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  38. void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  39. void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  40. void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  41. private:
  42. void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  43. const ImageView& src_image_view);
  44. void ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  45. ImageView& src_image_view);
  46. [[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key);
  47. [[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key);
  48. void ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass, bool is_target_depth);
  49. void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  50. void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  51. void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  52. vk::ShaderModule& module, bool single_texture, bool is_target_depth);
  53. void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  54. vk::ShaderModule& module);
  55. void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  56. vk::ShaderModule& module);
  57. const Device& device;
  58. VKScheduler& scheduler;
  59. StateTracker& state_tracker;
  60. vk::DescriptorSetLayout one_texture_set_layout;
  61. vk::DescriptorSetLayout two_textures_set_layout;
  62. DescriptorAllocator one_texture_descriptor_allocator;
  63. DescriptorAllocator two_textures_descriptor_allocator;
  64. vk::PipelineLayout one_texture_pipeline_layout;
  65. vk::PipelineLayout two_textures_pipeline_layout;
  66. vk::ShaderModule full_screen_vert;
  67. vk::ShaderModule blit_color_to_color_frag;
  68. vk::ShaderModule blit_depth_stencil_frag;
  69. vk::ShaderModule convert_depth_to_float_frag;
  70. vk::ShaderModule convert_float_to_depth_frag;
  71. vk::ShaderModule convert_abgr8_to_d24s8_frag;
  72. vk::ShaderModule convert_d24s8_to_abgr8_frag;
  73. vk::Sampler linear_sampler;
  74. vk::Sampler nearest_sampler;
  75. std::vector<BlitImagePipelineKey> blit_color_keys;
  76. std::vector<vk::Pipeline> blit_color_pipelines;
  77. std::vector<BlitImagePipelineKey> blit_depth_stencil_keys;
  78. std::vector<vk::Pipeline> blit_depth_stencil_pipelines;
  79. vk::Pipeline convert_d32_to_r32_pipeline;
  80. vk::Pipeline convert_r32_to_d32_pipeline;
  81. vk::Pipeline convert_d16_to_r16_pipeline;
  82. vk::Pipeline convert_r16_to_d16_pipeline;
  83. vk::Pipeline convert_abgr8_to_d24s8_pipeline;
  84. vk::Pipeline convert_d24s8_to_abgr8_pipeline;
  85. };
  86. } // namespace Vulkan