vk_rasterizer.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <boost/container/static_vector.hpp>
  6. #include "common/common_types.h"
  7. #include "video_core/control/channel_state_cache.h"
  8. #include "video_core/engines/maxwell_dma.h"
  9. #include "video_core/rasterizer_accelerated.h"
  10. #include "video_core/rasterizer_interface.h"
  11. #include "video_core/renderer_vulkan/blit_image.h"
  12. #include "video_core/renderer_vulkan/vk_buffer_cache.h"
  13. #include "video_core/renderer_vulkan/vk_descriptor_pool.h"
  14. #include "video_core/renderer_vulkan/vk_fence_manager.h"
  15. #include "video_core/renderer_vulkan/vk_pipeline_cache.h"
  16. #include "video_core/renderer_vulkan/vk_query_cache.h"
  17. #include "video_core/renderer_vulkan/vk_render_pass_cache.h"
  18. #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
  19. #include "video_core/renderer_vulkan/vk_texture_cache.h"
  20. #include "video_core/renderer_vulkan/vk_update_descriptor.h"
  21. #include "video_core/vulkan_common/vulkan_memory_allocator.h"
  22. #include "video_core/vulkan_common/vulkan_wrapper.h"
  23. namespace Core {
  24. class System;
  25. }
  26. namespace Core::Frontend {
  27. class EmuWindow;
  28. }
  29. namespace Tegra::Engines {
  30. class Maxwell3D;
  31. }
  32. namespace Vulkan {
  33. struct ScreenInfo;
  34. class StateTracker;
  35. class AccelerateDMA : public Tegra::Engines::AccelerateDMAInterface {
  36. public:
  37. explicit AccelerateDMA(BufferCache& buffer_cache);
  38. bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override;
  39. bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override;
  40. private:
  41. BufferCache& buffer_cache;
  42. };
  43. class RasterizerVulkan final : public VideoCore::RasterizerAccelerated,
  44. protected VideoCommon::ChannelSetupCaches<VideoCommon::ChannelInfo> {
  45. public:
  46. explicit RasterizerVulkan(Core::Frontend::EmuWindow& emu_window_, Tegra::GPU& gpu_,
  47. Core::Memory::Memory& cpu_memory_, ScreenInfo& screen_info_,
  48. const Device& device_, MemoryAllocator& memory_allocator_,
  49. StateTracker& state_tracker_, Scheduler& scheduler_);
  50. ~RasterizerVulkan() override;
  51. void Draw(bool is_indexed, u32 instance_count) override;
  52. void Clear(u32 layer_count) override;
  53. void DispatchCompute() override;
  54. void ResetCounter(VideoCore::QueryType type) override;
  55. void Query(GPUVAddr gpu_addr, VideoCore::QueryType type, std::optional<u64> timestamp) override;
  56. void BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) override;
  57. void DisableGraphicsUniformBuffer(size_t stage, u32 index) override;
  58. void FlushAll() override;
  59. void FlushRegion(VAddr addr, u64 size) override;
  60. bool MustFlushRegion(VAddr addr, u64 size) override;
  61. void InvalidateRegion(VAddr addr, u64 size) override;
  62. void OnCPUWrite(VAddr addr, u64 size) override;
  63. void InvalidateGPUCache() override;
  64. void UnmapMemory(VAddr addr, u64 size) override;
  65. void ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) override;
  66. void SignalFence(std::function<void()>&& func) override;
  67. void SyncOperation(std::function<void()>&& func) override;
  68. void SignalSyncPoint(u32 value) override;
  69. void SignalReference() override;
  70. void ReleaseFences() override;
  71. void FlushAndInvalidateRegion(VAddr addr, u64 size) override;
  72. void WaitForIdle() override;
  73. void FragmentBarrier() override;
  74. void TiledCacheBarrier() override;
  75. void FlushCommands() override;
  76. void TickFrame() override;
  77. bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Surface& src,
  78. const Tegra::Engines::Fermi2D::Surface& dst,
  79. const Tegra::Engines::Fermi2D::Config& copy_config) override;
  80. Tegra::Engines::AccelerateDMAInterface& AccessAccelerateDMA() override;
  81. void AccelerateInlineToMemory(GPUVAddr address, size_t copy_size,
  82. std::span<const u8> memory) override;
  83. bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
  84. u32 pixel_stride) override;
  85. void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
  86. const VideoCore::DiskResourceLoadCallback& callback) override;
  87. void InitializeChannel(Tegra::Control::ChannelState& channel) override;
  88. void BindChannel(Tegra::Control::ChannelState& channel) override;
  89. void ReleaseChannel(s32 channel_id) override;
  90. private:
  91. static constexpr size_t MAX_TEXTURES = 192;
  92. static constexpr size_t MAX_IMAGES = 48;
  93. static constexpr size_t MAX_IMAGE_VIEWS = MAX_TEXTURES + MAX_IMAGES;
  94. static constexpr VkDeviceSize DEFAULT_BUFFER_SIZE = 4 * sizeof(float);
  95. void FlushWork();
  96. void UpdateDynamicStates();
  97. void BeginTransformFeedback();
  98. void EndTransformFeedback();
  99. void UpdateViewportsState(Tegra::Engines::Maxwell3D::Regs& regs);
  100. void UpdateScissorsState(Tegra::Engines::Maxwell3D::Regs& regs);
  101. void UpdateDepthBias(Tegra::Engines::Maxwell3D::Regs& regs);
  102. void UpdateBlendConstants(Tegra::Engines::Maxwell3D::Regs& regs);
  103. void UpdateDepthBounds(Tegra::Engines::Maxwell3D::Regs& regs);
  104. void UpdateStencilFaces(Tegra::Engines::Maxwell3D::Regs& regs);
  105. void UpdateLineWidth(Tegra::Engines::Maxwell3D::Regs& regs);
  106. void UpdateCullMode(Tegra::Engines::Maxwell3D::Regs& regs);
  107. void UpdateDepthBoundsTestEnable(Tegra::Engines::Maxwell3D::Regs& regs);
  108. void UpdateDepthTestEnable(Tegra::Engines::Maxwell3D::Regs& regs);
  109. void UpdateDepthWriteEnable(Tegra::Engines::Maxwell3D::Regs& regs);
  110. void UpdateDepthCompareOp(Tegra::Engines::Maxwell3D::Regs& regs);
  111. void UpdateFrontFace(Tegra::Engines::Maxwell3D::Regs& regs);
  112. void UpdateStencilOp(Tegra::Engines::Maxwell3D::Regs& regs);
  113. void UpdateStencilTestEnable(Tegra::Engines::Maxwell3D::Regs& regs);
  114. void UpdateVertexInput(Tegra::Engines::Maxwell3D::Regs& regs);
  115. void BindInlineIndexBuffer();
  116. Tegra::GPU& gpu;
  117. ScreenInfo& screen_info;
  118. const Device& device;
  119. MemoryAllocator& memory_allocator;
  120. StateTracker& state_tracker;
  121. Scheduler& scheduler;
  122. StagingBufferPool staging_pool;
  123. DescriptorPool descriptor_pool;
  124. UpdateDescriptorQueue update_descriptor_queue;
  125. BlitImageHelper blit_image;
  126. RenderPassCache render_pass_cache;
  127. TextureCacheRuntime texture_cache_runtime;
  128. TextureCache texture_cache;
  129. BufferCacheRuntime buffer_cache_runtime;
  130. BufferCache buffer_cache;
  131. PipelineCache pipeline_cache;
  132. QueryCache query_cache;
  133. AccelerateDMA accelerate_dma;
  134. FenceManager fence_manager;
  135. vk::Event wfi_event;
  136. boost::container::static_vector<u32, MAX_IMAGE_VIEWS> image_view_indices;
  137. std::array<VideoCommon::ImageViewId, MAX_IMAGE_VIEWS> image_view_ids;
  138. boost::container::static_vector<VkSampler, MAX_TEXTURES> sampler_handles;
  139. u32 draw_counter = 0;
  140. };
  141. } // namespace Vulkan