2020-06-18 14:18:19 +00:00
|
|
|
#pragma once
|
2022-10-13 07:42:15 +00:00
|
|
|
#include "common/timer.h"
|
2022-07-08 11:49:27 +00:00
|
|
|
#include "common/vulkan/loader.h"
|
2020-09-12 15:19:57 +00:00
|
|
|
#include "common/vulkan/stream_buffer.h"
|
2020-06-18 14:18:19 +00:00
|
|
|
#include "common/vulkan/swap_chain.h"
|
|
|
|
#include "common/window_info.h"
|
|
|
|
#include "core/host_display.h"
|
2020-12-26 14:11:31 +00:00
|
|
|
#include "postprocessing_chain.h"
|
2020-06-18 14:18:19 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
class StreamBuffer;
|
|
|
|
class SwapChain;
|
|
|
|
} // namespace Vulkan
|
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
class VulkanHostDisplay final : public HostDisplay
|
2020-06-18 14:18:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
VulkanHostDisplay();
|
2021-05-22 06:09:14 +00:00
|
|
|
~VulkanHostDisplay();
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
RenderAPI GetRenderAPI() const override;
|
|
|
|
void* GetRenderDevice() const override;
|
|
|
|
void* GetRenderContext() const override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool HasRenderDevice() const override;
|
|
|
|
bool HasRenderSurface() const override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device,
|
2022-07-08 11:49:27 +00:00
|
|
|
bool threaded_presentation) override;
|
2021-05-22 06:09:14 +00:00
|
|
|
bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device,
|
2022-07-08 11:49:27 +00:00
|
|
|
bool threaded_presentation) override;
|
2022-10-03 06:44:34 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool MakeRenderContextCurrent() override;
|
|
|
|
bool DoneRenderContextCurrent() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool ChangeRenderWindow(const WindowInfo& new_wi) override;
|
|
|
|
void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) override;
|
|
|
|
bool SupportsFullscreen() const override;
|
|
|
|
bool IsFullscreen() override;
|
|
|
|
bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override;
|
|
|
|
AdapterAndModeList GetAdapterAndModeList() override;
|
|
|
|
void DestroyRenderSurface() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool SetPostProcessingChain(const std::string_view& config) override;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2022-10-03 06:44:34 +00:00
|
|
|
std::unique_ptr<GPUTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
|
|
|
|
GPUTexture::Format format, const void* data, u32 data_stride,
|
|
|
|
bool dynamic = false) override;
|
|
|
|
bool BeginTextureUpdate(GPUTexture* texture, u32 width, u32 height, void** out_buffer, u32* out_pitch) override;
|
|
|
|
void EndTextureUpdate(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height) override;
|
|
|
|
bool UpdateTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch) override;
|
|
|
|
bool DownloadTexture(GPUTexture* texture, u32 x, u32 y, u32 width, u32 height, void* out_data,
|
|
|
|
u32 out_data_stride) override;
|
|
|
|
bool SupportsTextureFormat(GPUTexture::Format format) const override;
|
2020-10-21 15:25:33 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
void SetVSync(bool enabled) override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2022-08-18 13:51:43 +00:00
|
|
|
bool Render(bool skip_present) override;
|
2021-05-22 06:09:14 +00:00
|
|
|
bool RenderScreenshot(u32 width, u32 height, std::vector<u32>* out_pixels, u32* out_stride,
|
2022-10-03 06:44:34 +00:00
|
|
|
GPUTexture::Format* out_format) override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2022-09-03 04:15:15 +00:00
|
|
|
bool SetGPUTimingEnabled(bool enabled) override;
|
|
|
|
float GetAndResetAccumulatedGPUTime() override;
|
|
|
|
|
2021-02-15 16:57:35 +00:00
|
|
|
static AdapterAndModeList StaticGetAdapterAndModeList(const WindowInfo* wi);
|
2020-06-19 17:33:49 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
protected:
|
2020-06-18 14:18:19 +00:00
|
|
|
struct PushConstants
|
|
|
|
{
|
|
|
|
float src_rect_left;
|
|
|
|
float src_rect_top;
|
|
|
|
float src_rect_width;
|
|
|
|
float src_rect_height;
|
|
|
|
};
|
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
struct PostProcessingStage
|
|
|
|
{
|
|
|
|
PostProcessingStage() = default;
|
|
|
|
PostProcessingStage(PostProcessingStage&& move);
|
|
|
|
~PostProcessingStage();
|
|
|
|
|
|
|
|
VkPipeline pipeline = VK_NULL_HANDLE;
|
|
|
|
VkFramebuffer output_framebuffer = VK_NULL_HANDLE;
|
|
|
|
Vulkan::Texture output_texture;
|
|
|
|
u32 uniforms_size = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CheckPostProcessingRenderTargets(u32 target_width, u32 target_height);
|
2021-03-05 16:11:17 +00:00
|
|
|
void ApplyPostProcessingChain(VkFramebuffer target_fb, s32 final_left, s32 final_top, s32 final_width,
|
2022-10-03 06:44:34 +00:00
|
|
|
s32 final_height, Vulkan::Texture* texture, s32 texture_view_x, s32 texture_view_y,
|
|
|
|
s32 texture_view_width, s32 texture_view_height, u32 target_width, u32 target_height);
|
2020-09-12 15:19:57 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
VkRenderPass GetRenderPassForDisplay() const;
|
2020-07-04 10:06:04 +00:00
|
|
|
|
2022-09-26 10:44:23 +00:00
|
|
|
bool CheckStagingBufferSize(u32 required_size);
|
|
|
|
void DestroyStagingBuffer();
|
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool CreateResources() override;
|
|
|
|
void DestroyResources() override;
|
2020-06-29 16:46:57 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool CreateImGuiContext() override;
|
|
|
|
void DestroyImGuiContext() override;
|
|
|
|
bool UpdateImGuiFontTexture() override;
|
2020-06-29 16:46:57 +00:00
|
|
|
|
2021-03-05 16:11:17 +00:00
|
|
|
void BeginSwapChainRenderPass(VkFramebuffer framebuffer, u32 width, u32 height);
|
2020-06-29 16:46:57 +00:00
|
|
|
void RenderDisplay();
|
|
|
|
void RenderImGui();
|
|
|
|
void RenderSoftwareCursor();
|
|
|
|
|
2022-10-03 06:44:34 +00:00
|
|
|
void RenderDisplay(s32 left, s32 top, s32 width, s32 height, Vulkan::Texture* texture, s32 texture_view_x,
|
|
|
|
s32 texture_view_y, s32 texture_view_width, s32 texture_view_height, bool linear_filter);
|
|
|
|
void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, GPUTexture* texture_handle);
|
2020-06-29 16:46:57 +00:00
|
|
|
|
2020-06-18 14:18:19 +00:00
|
|
|
std::unique_ptr<Vulkan::SwapChain> m_swap_chain;
|
|
|
|
|
|
|
|
VkDescriptorSetLayout m_descriptor_set_layout = VK_NULL_HANDLE;
|
|
|
|
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
|
2020-06-30 15:56:28 +00:00
|
|
|
VkPipeline m_cursor_pipeline = VK_NULL_HANDLE;
|
2020-06-18 14:18:19 +00:00
|
|
|
VkPipeline m_display_pipeline = VK_NULL_HANDLE;
|
|
|
|
VkSampler m_point_sampler = VK_NULL_HANDLE;
|
|
|
|
VkSampler m_linear_sampler = VK_NULL_HANDLE;
|
2022-10-13 12:53:09 +00:00
|
|
|
VkSampler m_border_sampler = VK_NULL_HANDLE;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2022-09-26 10:44:23 +00:00
|
|
|
VmaAllocation m_readback_staging_allocation = VK_NULL_HANDLE;
|
|
|
|
VkBuffer m_readback_staging_buffer = VK_NULL_HANDLE;
|
|
|
|
u8* m_readback_staging_buffer_map = nullptr;
|
|
|
|
u32 m_readback_staging_buffer_size = 0;
|
2022-10-03 03:13:35 +00:00
|
|
|
bool m_is_adreno = false;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
|
|
|
VkDescriptorSetLayout m_post_process_descriptor_set_layout = VK_NULL_HANDLE;
|
|
|
|
VkDescriptorSetLayout m_post_process_ubo_descriptor_set_layout = VK_NULL_HANDLE;
|
|
|
|
VkPipelineLayout m_post_process_pipeline_layout = VK_NULL_HANDLE;
|
|
|
|
VkPipelineLayout m_post_process_ubo_pipeline_layout = VK_NULL_HANDLE;
|
|
|
|
|
2022-09-26 10:44:23 +00:00
|
|
|
FrontendCommon::PostProcessingChain m_post_processing_chain;
|
2020-09-12 15:19:57 +00:00
|
|
|
Vulkan::Texture m_post_processing_input_texture;
|
|
|
|
VkFramebuffer m_post_processing_input_framebuffer = VK_NULL_HANDLE;
|
|
|
|
Vulkan::StreamBuffer m_post_processing_ubo;
|
|
|
|
std::vector<PostProcessingStage> m_post_processing_stages;
|
2022-10-13 07:42:15 +00:00
|
|
|
Common::Timer m_post_processing_timer;
|
2020-06-18 14:18:19 +00:00
|
|
|
};
|