2020-06-19 17:33:34 +00:00
|
|
|
#pragma once
|
|
|
|
#include "common/d3d11/staging_texture.h"
|
|
|
|
#include "common/d3d11/stream_buffer.h"
|
|
|
|
#include "common/d3d11/texture.h"
|
|
|
|
#include "common/window_info.h"
|
|
|
|
#include "common/windows_headers.h"
|
|
|
|
#include "core/host_display.h"
|
2020-12-26 14:11:31 +00:00
|
|
|
#include "frontend-common/postprocessing_chain.h"
|
2020-06-19 17:33:34 +00:00
|
|
|
#include <d3d11.h>
|
|
|
|
#include <dxgi.h>
|
|
|
|
#include <memory>
|
2020-06-19 17:33:49 +00:00
|
|
|
#include <string>
|
2020-06-19 17:33:57 +00:00
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
#include <wrl/client.h>
|
2020-06-19 17:33:34 +00:00
|
|
|
|
|
|
|
namespace FrontendCommon {
|
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
class D3D11HostDisplay final : public HostDisplay
|
2020-06-19 17:33:34 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
using ComPtr = Microsoft::WRL::ComPtr<T>;
|
|
|
|
|
|
|
|
D3D11HostDisplay();
|
|
|
|
~D3D11HostDisplay();
|
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
RenderAPI GetRenderAPI() const override;
|
|
|
|
void* GetRenderDevice() const override;
|
|
|
|
void* GetRenderContext() const override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool HasRenderDevice() const override;
|
|
|
|
bool HasRenderSurface() const override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device,
|
|
|
|
bool threaded_presentation) override;
|
|
|
|
bool InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device,
|
|
|
|
bool threaded_presentation) override;
|
|
|
|
void DestroyRenderDevice() override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool MakeRenderContextCurrent() override;
|
|
|
|
bool DoneRenderContextCurrent() override;
|
2020-06-19 17:33:34 +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-19 17:33:34 +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
|
|
|
|
2021-01-23 08:05:33 +00:00
|
|
|
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
|
|
|
|
HostDisplayPixelFormat format, const void* data, u32 data_stride,
|
|
|
|
bool dynamic = false) override;
|
2020-06-19 17:33:34 +00:00
|
|
|
void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* texture_data,
|
2020-06-29 16:46:57 +00:00
|
|
|
u32 texture_data_stride) override;
|
2020-12-17 15:59:32 +00:00
|
|
|
bool DownloadTexture(const void* texture_handle, HostDisplayPixelFormat texture_format, u32 x, u32 y, u32 width,
|
|
|
|
u32 height, void* out_data, u32 out_data_stride) override;
|
2020-10-21 15:25:33 +00:00
|
|
|
bool SupportsDisplayPixelFormat(HostDisplayPixelFormat format) const override;
|
|
|
|
bool BeginSetDisplayPixels(HostDisplayPixelFormat format, u32 width, u32 height, void** out_buffer,
|
|
|
|
u32* out_pitch) override;
|
|
|
|
void EndSetDisplayPixels() override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-01-10 17:50:10 +00:00
|
|
|
bool GetHostRefreshRate(float* refresh_rate) override;
|
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
void SetVSync(bool enabled) override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-05-22 06:09:14 +00:00
|
|
|
bool Render() override;
|
|
|
|
bool RenderScreenshot(u32 width, u32 height, std::vector<u32>* out_pixels, u32* out_stride,
|
|
|
|
HostDisplayPixelFormat* out_format) override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2021-02-13 14:33:35 +00:00
|
|
|
static AdapterAndModeList StaticGetAdapterAndModeList();
|
2020-06-19 17:33:49 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
protected:
|
2020-06-19 17:33:34 +00:00
|
|
|
static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16;
|
|
|
|
|
2021-02-13 14:33:35 +00:00
|
|
|
static AdapterAndModeList GetAdapterAndModeList(IDXGIFactory* dxgi_factory);
|
2020-06-19 17:33:57 +00:00
|
|
|
|
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
|
|
|
|
2020-11-01 14:38:54 +00:00
|
|
|
bool CreateSwapChain(const DXGI_MODE_DESC* fullscreen_mode);
|
2020-06-19 17:33:34 +00:00
|
|
|
bool CreateSwapChainRTV();
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
void RenderDisplay();
|
|
|
|
void RenderSoftwareCursor();
|
2020-07-10 04:01:48 +00:00
|
|
|
void RenderImGui();
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
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-09-12 15:19:57 +00:00
|
|
|
struct PostProcessingStage
|
|
|
|
{
|
|
|
|
ComPtr<ID3D11VertexShader> vertex_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> pixel_shader;
|
|
|
|
D3D11::Texture output_texture;
|
|
|
|
u32 uniforms_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool CheckPostProcessingRenderTargets(u32 target_width, u32 target_height);
|
|
|
|
void ApplyPostProcessingChain(ID3D11RenderTargetView* final_target, s32 final_left, s32 final_top, s32 final_width,
|
|
|
|
s32 final_height, void* texture_handle, u32 texture_width, s32 texture_height,
|
2021-05-22 06:09:14 +00:00
|
|
|
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
|
|
|
|
2020-06-19 17:33:34 +00:00
|
|
|
ComPtr<ID3D11Device> m_device;
|
|
|
|
ComPtr<ID3D11DeviceContext> m_context;
|
2020-07-10 04:01:48 +00:00
|
|
|
|
|
|
|
ComPtr<IDXGIFactory> m_dxgi_factory;
|
2020-06-19 17:33:34 +00:00
|
|
|
ComPtr<IDXGISwapChain> m_swap_chain;
|
|
|
|
ComPtr<ID3D11RenderTargetView> m_swap_chain_rtv;
|
|
|
|
|
|
|
|
ComPtr<ID3D11RasterizerState> m_display_rasterizer_state;
|
|
|
|
ComPtr<ID3D11DepthStencilState> m_display_depth_stencil_state;
|
|
|
|
ComPtr<ID3D11BlendState> m_display_blend_state;
|
|
|
|
ComPtr<ID3D11BlendState> m_software_cursor_blend_state;
|
|
|
|
ComPtr<ID3D11VertexShader> m_display_vertex_shader;
|
|
|
|
ComPtr<ID3D11PixelShader> m_display_pixel_shader;
|
2021-05-07 16:11:02 +00:00
|
|
|
ComPtr<ID3D11PixelShader> m_display_alpha_pixel_shader;
|
2020-06-19 17:33:34 +00:00
|
|
|
ComPtr<ID3D11SamplerState> m_point_sampler;
|
|
|
|
ComPtr<ID3D11SamplerState> m_linear_sampler;
|
|
|
|
|
|
|
|
D3D11::Texture m_display_pixels_texture;
|
|
|
|
D3D11::StreamBuffer m_display_uniform_buffer;
|
|
|
|
D3D11::AutoStagingTexture m_readback_staging_texture;
|
|
|
|
|
|
|
|
bool m_allow_tearing_supported = false;
|
|
|
|
bool m_using_flip_model_swap_chain = true;
|
|
|
|
bool m_using_allow_tearing = false;
|
|
|
|
bool m_vsync = true;
|
2020-09-12 15:19:57 +00:00
|
|
|
|
|
|
|
PostProcessingChain m_post_processing_chain;
|
|
|
|
D3D11::Texture m_post_processing_input_texture;
|
|
|
|
std::vector<PostProcessingStage> m_post_processing_stages;
|
2020-06-19 17:33:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FrontendCommon
|