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"
|
|
|
|
#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 {
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
class D3D11HostDisplay : public HostDisplay
|
2020-06-19 17:33:34 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<typename T>
|
|
|
|
using ComPtr = Microsoft::WRL::ComPtr<T>;
|
|
|
|
|
|
|
|
D3D11HostDisplay();
|
|
|
|
~D3D11HostDisplay();
|
|
|
|
|
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-19 17:33:34 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool HasRenderDevice() const override;
|
|
|
|
virtual bool HasRenderSurface() const override;
|
2020-06-19 17:33:34 +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-19 17:33:34 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool MakeRenderContextCurrent() override;
|
|
|
|
virtual bool DoneRenderContextCurrent() override;
|
2020-06-19 17:33:34 +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-19 17:33:34 +00:00
|
|
|
|
|
|
|
std::unique_ptr<HostDisplayTexture> CreateTexture(u32 width, u32 height, const void* initial_data,
|
2020-06-29 16:46:57 +00:00
|
|
|
u32 initial_data_stride, bool dynamic) 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-06-19 17:33:34 +00:00
|
|
|
bool DownloadTexture(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, void* out_data,
|
2020-06-29 16:46:57 +00:00
|
|
|
u32 out_data_stride) override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual void SetVSync(bool enabled) override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool Render() override;
|
2020-06-19 17:33:34 +00:00
|
|
|
|
2020-07-10 04:01:48 +00:00
|
|
|
#ifndef LIBRETRO
|
2020-06-19 17:33:49 +00:00
|
|
|
static std::vector<std::string> EnumerateAdapterNames();
|
2020-07-10 04:01:48 +00:00
|
|
|
#endif
|
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;
|
|
|
|
|
2020-06-19 17:33:57 +00:00
|
|
|
static std::vector<std::string> EnumerateAdapterNames(IDXGIFactory* dxgi_factory);
|
|
|
|
|
2020-06-29 16:46:57 +00:00
|
|
|
virtual bool CreateResources();
|
|
|
|
virtual void DestroyResources();
|
|
|
|
|
|
|
|
virtual bool CreateImGuiContext();
|
|
|
|
virtual void DestroyImGuiContext();
|
|
|
|
|
2020-09-01 02:46:58 +00:00
|
|
|
#ifndef LIBRETRO
|
2020-06-29 16:46:57 +00:00
|
|
|
bool CreateSwapChain();
|
2020-06-19 17:33:34 +00:00
|
|
|
bool CreateSwapChainRTV();
|
2020-07-10 04:01:48 +00:00
|
|
|
#endif
|
2020-06-19 17:33:34 +00:00
|
|
|
|
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-06-19 17:33:34 +00:00
|
|
|
ComPtr<ID3D11Device> m_device;
|
|
|
|
ComPtr<ID3D11DeviceContext> m_context;
|
2020-07-10 04:01:48 +00:00
|
|
|
|
|
|
|
#ifndef LIBRETRO
|
|
|
|
ComPtr<IDXGIFactory> m_dxgi_factory;
|
2020-06-19 17:33:34 +00:00
|
|
|
ComPtr<IDXGISwapChain> m_swap_chain;
|
|
|
|
ComPtr<ID3D11RenderTargetView> m_swap_chain_rtv;
|
2020-07-10 04:01:48 +00:00
|
|
|
#endif
|
2020-06-19 17:33:34 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2020-07-10 04:46:44 +00:00
|
|
|
#ifndef LIBRETRO
|
2020-06-19 17:33:34 +00:00
|
|
|
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-07-10 04:01:48 +00:00
|
|
|
#endif
|
2020-06-19 17:33:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FrontendCommon
|