#pragma once #include "../dxvk/dxvk_device.h" #include "../dxvk/dxvk_surface.h" #include "../dxvk/dxvk_swapchain.h" #include "../dxvk/hud/dxvk_hud.h" #include "../spirv/spirv_module.h" #include "dxgi_options.h" namespace dxvk { constexpr uint32_t DXGI_VK_GAMMA_CP_COUNT = 1024; /** * \brief Gamma control point * * Control points are stored as normalized * 16-bit unsigned integer values that will * be converted back to floats in the shader. */ struct DXGI_VK_GAMMA_CP { uint16_t R, G, B, A; }; /** * \brief Gamma curve * * A collection of control points that * will be uploaded to the gamma texture. */ struct DXGI_VK_GAMMA_CURVE { DXGI_VK_GAMMA_CP ControlPoints[DXGI_VK_GAMMA_CP_COUNT]; }; /** * \brief Maps color value to normalized integer * * \param [in] x Input value, as floating point * \returns Corresponding normalized integer */ inline uint16_t MapGammaControlPoint(float x) { if (x < 0.0f) x = 0.0f; if (x > 1.0f) x = 1.0f; return uint16_t(65535.0f * x); } /** * \brief Computes gamma control point location * * \param [in] CpIndex Control point ID * \returns Location of the control point */ inline float GammaControlPointLocation(uint32_t CpIndex) { return float(CpIndex) / float(DXGI_VK_GAMMA_CP_COUNT - 1); } /** * \brief DXGI presenter * * Renders the back buffer from the * \ref DxgiSwapChain to the Vulkan * swap chain. */ class DxgiVkPresenter : public RcObject { public: DxgiVkPresenter( const Rc& device, HWND window); ~DxgiVkPresenter(); /** * \brief Initializes back buffer image * \param [in] image Back buffer image */ void InitBackBuffer(const Rc& Image); /** * \brief Renders back buffer to the screen * \param [in] SyncInterval Vsync interval */ void PresentImage(UINT SyncInterval); /** * \brief Sets new back buffer * * Recreates internal structures when * the back buffer image was replaced. * \param [in] image Back buffer image */ void UpdateBackBuffer(const Rc& Image); /** * \brief Recreats Vulkan swap chain * * Only actually recreates the swap chain object * if any of the properties have changed. If no * properties have changed, this is a no-op. * \param [in] Format New surface format * \param [in] PresentMode Present mode * \param [in] WindowSize Window size */ void RecreateSwapchain( DXGI_FORMAT Format, VkPresentModeKHR PresentMode, VkExtent2D WindowSize); /** * \brief Sets gamma curve * * Updates the gamma lookup texture. * \param [in] pGammaControl Input parameters * \param [in] pGammaCurve Gamma curve */ void SetGammaControl( const DXGI_VK_GAMMA_CURVE* pGammaCurve); private: enum BindingIds : uint32_t { Sampler = 0, Texture = 1, GammaSmp = 2, GammaTex = 3, }; HWND m_window; Rc m_device; Rc m_context; Rc m_surface; Rc m_swapchain; Rc m_vertShader; Rc m_fragShader; Rc m_samplerFitting; Rc m_samplerScaling; Rc m_backBuffer; Rc m_backBufferResolve; Rc m_backBufferView; Rc m_gammaSampler; Rc m_gammaTexture; Rc m_gammaTextureView; Rc m_hud; DxvkInputAssemblyState m_iaState; DxvkRasterizerState m_rsState; DxvkMultisampleState m_msState; DxvkDepthStencilState m_dsState; DxvkLogicOpState m_loState; DxvkBlendMode m_blendMode; DxvkSwapchainProperties m_options; VkSurfaceFormatKHR PickSurfaceFormat(DXGI_FORMAT Fmt) const; VkPresentModeKHR PickPresentMode(VkPresentModeKHR Preferred) const; Rc CreateSurface(); Rc CreateSampler( VkFilter Filter, VkSamplerAddressMode AddressMode); Rc CreateGammaTexture(); Rc CreateGammaTextureView(); Rc CreateVertexShader(); Rc CreateFragmentShader(); }; }