blit_image.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "video_core/engines/fermi_2d.h"
  5. #include "video_core/renderer_vulkan/vk_descriptor_pool.h"
  6. #include "video_core/texture_cache/types.h"
  7. #include "video_core/vulkan_common/vulkan_wrapper.h"
  8. namespace Vulkan {
  9. using VideoCommon::Extent3D;
  10. using VideoCommon::Offset2D;
  11. using VideoCommon::Region2D;
  12. class Device;
  13. class Framebuffer;
  14. class ImageView;
  15. class StateTracker;
  16. class Scheduler;
  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, Scheduler& 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 BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
  32. VkImage src_image, VkSampler src_sampler, const Region2D& dst_region,
  33. const Region2D& src_region, const Extent3D& src_size);
  34. void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,
  35. VkImageView src_stencil_view, const Region2D& dst_region,
  36. const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
  37. Tegra::Engines::Fermi2D::Operation operation);
  38. void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  39. void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  40. void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  41. void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  42. void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  43. void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  44. void ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  45. void ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
  46. const std::array<f32, 4>& clear_color, const Region2D& dst_region);
  47. private:
  48. void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  49. const ImageView& src_image_view);
  50. void ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  51. ImageView& src_image_view);
  52. [[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key);
  53. [[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key);
  54. [[nodiscard]] VkPipeline FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key);
  55. void ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass, bool is_target_depth);
  56. void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  57. void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  58. void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  59. vk::ShaderModule& module, bool single_texture, bool is_target_depth);
  60. void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  61. vk::ShaderModule& module);
  62. void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  63. vk::ShaderModule& module);
  64. const Device& device;
  65. Scheduler& scheduler;
  66. StateTracker& state_tracker;
  67. vk::DescriptorSetLayout one_texture_set_layout;
  68. vk::DescriptorSetLayout two_textures_set_layout;
  69. DescriptorAllocator one_texture_descriptor_allocator;
  70. DescriptorAllocator two_textures_descriptor_allocator;
  71. vk::PipelineLayout one_texture_pipeline_layout;
  72. vk::PipelineLayout two_textures_pipeline_layout;
  73. vk::PipelineLayout clear_color_pipeline_layout;
  74. vk::ShaderModule full_screen_vert;
  75. vk::ShaderModule blit_color_to_color_frag;
  76. vk::ShaderModule blit_depth_stencil_frag;
  77. vk::ShaderModule clear_color_vert;
  78. vk::ShaderModule clear_color_frag;
  79. vk::ShaderModule convert_depth_to_float_frag;
  80. vk::ShaderModule convert_float_to_depth_frag;
  81. vk::ShaderModule convert_abgr8_to_d24s8_frag;
  82. vk::ShaderModule convert_d24s8_to_abgr8_frag;
  83. vk::ShaderModule convert_s8d24_to_abgr8_frag;
  84. vk::Sampler linear_sampler;
  85. vk::Sampler nearest_sampler;
  86. std::vector<BlitImagePipelineKey> blit_color_keys;
  87. std::vector<vk::Pipeline> blit_color_pipelines;
  88. std::vector<BlitImagePipelineKey> blit_depth_stencil_keys;
  89. std::vector<vk::Pipeline> blit_depth_stencil_pipelines;
  90. std::vector<BlitImagePipelineKey> clear_color_keys;
  91. std::vector<vk::Pipeline> clear_color_pipelines;
  92. vk::Pipeline convert_d32_to_r32_pipeline;
  93. vk::Pipeline convert_r32_to_d32_pipeline;
  94. vk::Pipeline convert_d16_to_r16_pipeline;
  95. vk::Pipeline convert_r16_to_d16_pipeline;
  96. vk::Pipeline convert_abgr8_to_d24s8_pipeline;
  97. vk::Pipeline convert_d24s8_to_abgr8_pipeline;
  98. vk::Pipeline convert_s8d24_to_abgr8_pipeline;
  99. };
  100. } // namespace Vulkan