blit_image.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. struct BlitDepthStencilPipelineKey {
  23. constexpr auto operator<=>(const BlitDepthStencilPipelineKey&) const noexcept = default;
  24. VkRenderPass renderpass;
  25. bool depth_clear;
  26. u8 stencil_mask;
  27. u32 stencil_compare_mask;
  28. u32 stencil_ref;
  29. };
  30. class BlitImageHelper {
  31. public:
  32. explicit BlitImageHelper(const Device& device, Scheduler& scheduler,
  33. StateTracker& state_tracker, DescriptorPool& descriptor_pool);
  34. ~BlitImageHelper();
  35. void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
  36. const Region2D& dst_region, const Region2D& src_region,
  37. Tegra::Engines::Fermi2D::Filter filter,
  38. Tegra::Engines::Fermi2D::Operation operation);
  39. void BlitColor(const Framebuffer* dst_framebuffer, VkImageView src_image_view,
  40. VkImage src_image, VkSampler src_sampler, const Region2D& dst_region,
  41. const Region2D& src_region, const Extent3D& src_size);
  42. void BlitDepthStencil(const Framebuffer* dst_framebuffer, VkImageView src_depth_view,
  43. VkImageView src_stencil_view, const Region2D& dst_region,
  44. const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
  45. Tegra::Engines::Fermi2D::Operation operation);
  46. void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  47. void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  48. void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  49. void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  50. void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  51. void ConvertABGR8ToD32F(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
  52. void ConvertD32FToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  53. void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  54. void ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  55. void ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
  56. const std::array<f32, 4>& clear_color, const Region2D& dst_region);
  57. void ClearDepthStencil(const Framebuffer* dst_framebuffer, bool depth_clear, f32 clear_depth,
  58. u8 stencil_mask, u32 stencil_ref, u32 stencil_compare_mask,
  59. const Region2D& dst_region);
  60. private:
  61. void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  62. const ImageView& src_image_view);
  63. void ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  64. ImageView& src_image_view);
  65. [[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key);
  66. [[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key);
  67. [[nodiscard]] VkPipeline FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key);
  68. [[nodiscard]] VkPipeline FindOrEmplaceClearStencilPipeline(
  69. const BlitDepthStencilPipelineKey& key);
  70. void ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass, bool is_target_depth);
  71. void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  72. void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  73. void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  74. vk::ShaderModule& module, bool single_texture, bool is_target_depth);
  75. void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  76. vk::ShaderModule& module);
  77. void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  78. vk::ShaderModule& module);
  79. const Device& device;
  80. Scheduler& scheduler;
  81. StateTracker& state_tracker;
  82. vk::DescriptorSetLayout one_texture_set_layout;
  83. vk::DescriptorSetLayout two_textures_set_layout;
  84. DescriptorAllocator one_texture_descriptor_allocator;
  85. DescriptorAllocator two_textures_descriptor_allocator;
  86. vk::PipelineLayout one_texture_pipeline_layout;
  87. vk::PipelineLayout two_textures_pipeline_layout;
  88. vk::PipelineLayout clear_color_pipeline_layout;
  89. vk::ShaderModule full_screen_vert;
  90. vk::ShaderModule blit_color_to_color_frag;
  91. vk::ShaderModule blit_depth_stencil_frag;
  92. vk::ShaderModule clear_color_vert;
  93. vk::ShaderModule clear_color_frag;
  94. vk::ShaderModule clear_stencil_frag;
  95. vk::ShaderModule convert_depth_to_float_frag;
  96. vk::ShaderModule convert_float_to_depth_frag;
  97. vk::ShaderModule convert_abgr8_to_d24s8_frag;
  98. vk::ShaderModule convert_abgr8_to_d32f_frag;
  99. vk::ShaderModule convert_d32f_to_abgr8_frag;
  100. vk::ShaderModule convert_d24s8_to_abgr8_frag;
  101. vk::ShaderModule convert_s8d24_to_abgr8_frag;
  102. vk::Sampler linear_sampler;
  103. vk::Sampler nearest_sampler;
  104. std::vector<BlitImagePipelineKey> blit_color_keys;
  105. std::vector<vk::Pipeline> blit_color_pipelines;
  106. std::vector<BlitImagePipelineKey> blit_depth_stencil_keys;
  107. std::vector<vk::Pipeline> blit_depth_stencil_pipelines;
  108. std::vector<BlitImagePipelineKey> clear_color_keys;
  109. std::vector<vk::Pipeline> clear_color_pipelines;
  110. std::vector<BlitDepthStencilPipelineKey> clear_stencil_keys;
  111. std::vector<vk::Pipeline> clear_stencil_pipelines;
  112. vk::Pipeline convert_d32_to_r32_pipeline;
  113. vk::Pipeline convert_r32_to_d32_pipeline;
  114. vk::Pipeline convert_d16_to_r16_pipeline;
  115. vk::Pipeline convert_r16_to_d16_pipeline;
  116. vk::Pipeline convert_abgr8_to_d24s8_pipeline;
  117. vk::Pipeline convert_abgr8_to_d32f_pipeline;
  118. vk::Pipeline convert_d32f_to_abgr8_pipeline;
  119. vk::Pipeline convert_d24s8_to_abgr8_pipeline;
  120. vk::Pipeline convert_s8d24_to_abgr8_pipeline;
  121. };
  122. } // namespace Vulkan