blit_image.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  52. void ConvertS8D24ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view);
  53. void ClearColor(const Framebuffer* dst_framebuffer, u8 color_mask,
  54. const std::array<f32, 4>& clear_color, const Region2D& dst_region);
  55. void ClearDepthStencil(const Framebuffer* dst_framebuffer, bool depth_clear, f32 clear_depth,
  56. u8 stencil_mask, u32 stencil_ref, u32 stencil_compare_mask,
  57. const Region2D& dst_region);
  58. private:
  59. void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  60. const ImageView& src_image_view);
  61. void ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  62. ImageView& src_image_view);
  63. [[nodiscard]] VkPipeline FindOrEmplaceColorPipeline(const BlitImagePipelineKey& key);
  64. [[nodiscard]] VkPipeline FindOrEmplaceDepthStencilPipeline(const BlitImagePipelineKey& key);
  65. [[nodiscard]] VkPipeline FindOrEmplaceClearColorPipeline(const BlitImagePipelineKey& key);
  66. [[nodiscard]] VkPipeline FindOrEmplaceClearStencilPipeline(
  67. const BlitDepthStencilPipelineKey& key);
  68. void ConvertPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass, bool is_target_depth);
  69. void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  70. void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  71. void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  72. vk::ShaderModule& module, bool single_texture, bool is_target_depth);
  73. void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  74. vk::ShaderModule& module);
  75. void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
  76. vk::ShaderModule& module);
  77. const Device& device;
  78. Scheduler& scheduler;
  79. StateTracker& state_tracker;
  80. vk::DescriptorSetLayout one_texture_set_layout;
  81. vk::DescriptorSetLayout two_textures_set_layout;
  82. DescriptorAllocator one_texture_descriptor_allocator;
  83. DescriptorAllocator two_textures_descriptor_allocator;
  84. vk::PipelineLayout one_texture_pipeline_layout;
  85. vk::PipelineLayout two_textures_pipeline_layout;
  86. vk::PipelineLayout clear_color_pipeline_layout;
  87. vk::ShaderModule full_screen_vert;
  88. vk::ShaderModule blit_color_to_color_frag;
  89. vk::ShaderModule blit_depth_stencil_frag;
  90. vk::ShaderModule clear_color_vert;
  91. vk::ShaderModule clear_color_frag;
  92. vk::ShaderModule clear_stencil_frag;
  93. vk::ShaderModule convert_depth_to_float_frag;
  94. vk::ShaderModule convert_float_to_depth_frag;
  95. vk::ShaderModule convert_abgr8_to_d24s8_frag;
  96. vk::ShaderModule convert_d24s8_to_abgr8_frag;
  97. vk::ShaderModule convert_s8d24_to_abgr8_frag;
  98. vk::Sampler linear_sampler;
  99. vk::Sampler nearest_sampler;
  100. std::vector<BlitImagePipelineKey> blit_color_keys;
  101. std::vector<vk::Pipeline> blit_color_pipelines;
  102. std::vector<BlitImagePipelineKey> blit_depth_stencil_keys;
  103. std::vector<vk::Pipeline> blit_depth_stencil_pipelines;
  104. std::vector<BlitImagePipelineKey> clear_color_keys;
  105. std::vector<vk::Pipeline> clear_color_pipelines;
  106. std::vector<BlitDepthStencilPipelineKey> clear_stencil_keys;
  107. std::vector<vk::Pipeline> clear_stencil_pipelines;
  108. vk::Pipeline convert_d32_to_r32_pipeline;
  109. vk::Pipeline convert_r32_to_d32_pipeline;
  110. vk::Pipeline convert_d16_to_r16_pipeline;
  111. vk::Pipeline convert_r16_to_d16_pipeline;
  112. vk::Pipeline convert_abgr8_to_d24s8_pipeline;
  113. vk::Pipeline convert_d24s8_to_abgr8_pipeline;
  114. vk::Pipeline convert_s8d24_to_abgr8_pipeline;
  115. };
  116. } // namespace Vulkan