blit_image.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. private:
  40. void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
  41. const ImageView& src_image_view);
  42. [[nodiscard]] VkPipeline FindOrEmplacePipeline(const BlitImagePipelineKey& key);
  43. [[nodiscard]] VkPipeline BlitDepthStencilPipeline(VkRenderPass renderpass);
  44. void ConvertDepthToColorPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  45. void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
  46. const Device& device;
  47. VKScheduler& scheduler;
  48. StateTracker& state_tracker;
  49. vk::DescriptorSetLayout one_texture_set_layout;
  50. vk::DescriptorSetLayout two_textures_set_layout;
  51. DescriptorAllocator one_texture_descriptor_allocator;
  52. DescriptorAllocator two_textures_descriptor_allocator;
  53. vk::PipelineLayout one_texture_pipeline_layout;
  54. vk::PipelineLayout two_textures_pipeline_layout;
  55. vk::ShaderModule full_screen_vert;
  56. vk::ShaderModule blit_color_to_color_frag;
  57. vk::ShaderModule blit_depth_stencil_frag;
  58. vk::ShaderModule convert_depth_to_float_frag;
  59. vk::ShaderModule convert_float_to_depth_frag;
  60. vk::Sampler linear_sampler;
  61. vk::Sampler nearest_sampler;
  62. std::vector<BlitImagePipelineKey> blit_color_keys;
  63. std::vector<vk::Pipeline> blit_color_pipelines;
  64. vk::Pipeline blit_depth_stencil_pipeline;
  65. vk::Pipeline convert_d32_to_r32_pipeline;
  66. vk::Pipeline convert_r32_to_d32_pipeline;
  67. vk::Pipeline convert_d16_to_r16_pipeline;
  68. vk::Pipeline convert_r16_to_d16_pipeline;
  69. };
  70. } // namespace Vulkan