#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 #include #include #include #include #include #include namespace FrontendCommon { class D3D11HostDisplay final { public: template using ComPtr = Microsoft::WRL::ComPtr; D3D11HostDisplay(); ~D3D11HostDisplay(); ALWAYS_INLINE HostDisplay::RenderAPI GetRenderAPI() const { return HostDisplay::RenderAPI::D3D11; } ALWAYS_INLINE void* GetRenderDevice() const { return m_device.Get(); } ALWAYS_INLINE void* GetRenderContext() const { return m_context.Get(); } bool CreateContextAndSwapChain(const WindowInfo& wi, std::string_view adapter_name, bool use_flip_model, bool debug_device); bool HasContext() const; void DestroyContext(); bool CreateResources(); void DestroyResources(); bool CreateImGuiContext(); void DestroyImGuiContext(); ALWAYS_INLINE u32 GetSwapChainWidth() const { return m_swap_chain_width; } ALWAYS_INLINE u32 GetSwapChainHeight() const { return m_swap_chain_height; } ALWAYS_INLINE bool HasSwapChain() const { return static_cast(m_swap_chain); } bool RecreateSwapChain(const WindowInfo& new_wi, bool use_flip_model); void ResizeSwapChain(u32 new_width, u32 new_height); void DestroySwapChain(); std::unique_ptr CreateTexture(u32 width, u32 height, const void* initial_data, u32 initial_data_stride, bool dynamic); void UpdateTexture(HostDisplayTexture* texture, u32 x, u32 y, u32 width, u32 height, const void* texture_data, u32 texture_data_stride); bool DownloadTexture(const void* texture_handle, u32 x, u32 y, u32 width, u32 height, void* out_data, u32 out_data_stride); void SetVSync(bool enabled); bool BeginRender(); void RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width, u32 texture_height, u32 texture_view_x, u32 texture_view_y, u32 texture_view_width, u32 texture_view_height, bool linear_filter); void RenderImGui(); void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle); void EndRenderAndPresent(); static std::vector EnumerateAdapterNames(); private: static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16; static std::vector EnumerateAdapterNames(IDXGIFactory* dxgi_factory); bool CreateSwapChain(const WindowInfo& new_wi, bool use_flip_model); bool CreateSwapChainRTV(); ComPtr m_dxgi_factory; ComPtr m_device; ComPtr m_context; ComPtr m_swap_chain; ComPtr m_swap_chain_rtv; ComPtr m_display_rasterizer_state; ComPtr m_display_depth_stencil_state; ComPtr m_display_blend_state; ComPtr m_software_cursor_blend_state; ComPtr m_display_vertex_shader; ComPtr m_display_pixel_shader; ComPtr m_point_sampler; ComPtr m_linear_sampler; D3D11::Texture m_display_pixels_texture; D3D11::StreamBuffer m_display_uniform_buffer; D3D11::AutoStagingTexture m_readback_staging_texture; u32 m_swap_chain_width = 0; u32 m_swap_chain_height = 0; bool m_allow_tearing_supported = false; bool m_using_flip_model_swap_chain = true; bool m_using_allow_tearing = false; bool m_vsync = true; }; } // namespace FrontendCommon