2020-06-18 14:18:19 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common/vulkan/staging_texture.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"
|
|
|
|
#include "vulkan_loader.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
class StreamBuffer;
|
|
|
|
class SwapChain;
|
|
|
|
} // namespace Vulkan
|
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
#ifndef LIBRETRO
|
|
|
|
#include "postprocessing_chain.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-18 14:18:19 +00:00
|
|
|
namespace FrontendCommon {
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
class VulkanHostDisplay : public HostDisplay
|
2020-06-18 14:18:19 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
VulkanHostDisplay();
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual ~VulkanHostDisplay();
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual RenderAPI GetRenderAPI() const override;
|
|
|
|
virtual void* GetRenderDevice() const override;
|
|
|
|
virtual void* GetRenderContext() const override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool HasRenderDevice() const override;
|
|
|
|
virtual bool HasRenderSurface() const override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device) override;
|
|
|
|
virtual bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) override;
|
|
|
|
virtual void DestroyRenderDevice() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool MakeRenderContextCurrent() override;
|
|
|
|
virtual bool DoneRenderContextCurrent() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool ChangeRenderWindow(const WindowInfo& new_wi) override;
|
|
|
|
virtual void ResizeRenderWindow(s32 new_window_width, s32 new_window_height) override;
|
|
|
|
virtual void DestroyRenderSurface() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
virtual bool SetPostProcessingChain(const std::string_view& config) override;
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* initial_data,
|
|
|
|
u32 initial_data_stride, bool dynamic) override;
|
|
|
|
void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* texture_data,
|
|
|
|
u32 texture_data_stride) override;
|
|
|
|
bool DownloadTexture(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, void* out_data,
|
|
|
|
u32 out_data_stride) override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual void SetVSync(bool enabled) override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool Render() override;
|
2020-06-18 14:18:19 +00:00
|
|
|
|
2020-06-19 17:33:49 +00:00
|
|
|
static std::vector<std::string> EnumerateAdapterNames();
|
|
|
|
|
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
|
|
|
#ifndef LIBRETRO
|
|
|
|
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);
|
|
|
|
void ApplyPostProcessingChain(s32 final_left, s32 final_top, s32 final_width, s32 final_height, void* texture_handle,
|
|
|
|
u32 texture_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y,
|
|
|
|
s32 texture_view_width, s32 texture_view_height);
|
|
|
|
#endif
|
|
|
|
|
2020-07-04 10:06:04 +00:00
|
|
|
// Can be overridden by frontends.
|
|
|
|
virtual VkRenderPass GetRenderPassForDisplay() const;
|
|
|
|
|
2020-09-13 01:54:51 +00:00
|
|
|
virtual bool CreateResources() override;
|
|
|
|
virtual void DestroyResources() override;
|
2020-06-29 16:46:57 +00:00
|
|
|
|
|
|
|
virtual bool CreateImGuiContext();
|
|
|
|
virtual void DestroyImGuiContext();
|
|
|
|
|
2020-09-12 15:19:57 +00:00
|
|
|
void BeginSwapChainRenderPass(VkFramebuffer framebuffer);
|
2020-06-29 16:46:57 +00:00
|
|
|
void RenderDisplay();
|
|
|
|
void RenderImGui();
|
|
|
|
void RenderSoftwareCursor();
|
|
|
|
|
|
|
|
void RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width,
|
|
|
|
s32 texture_height, 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, HostDisplayTexture* texture_handle);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
Vulkan::StagingTexture m_upload_staging_texture;
|
|
|
|
Vulkan::StagingTexture m_readback_staging_texture;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
|
|
|
#ifndef LIBRETRO
|
|
|
|
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;
|
|
|
|
|
|
|
|
PostProcessingChain m_post_processing_chain;
|
|
|
|
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;
|
|
|
|
#endif
|
2020-06-18 14:18:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FrontendCommon
|