2019-12-11 00:51:42 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "GpWindows.h"
|
|
|
|
|
#include "GpRingBuffer.h"
|
|
|
|
|
|
|
|
|
|
#include "IGpDisplayDriver.h"
|
2020-07-03 02:46:43 -04:00
|
|
|
#include "IGpPrefsHandler.h"
|
2019-12-11 00:51:42 -05:00
|
|
|
#include "GpCoreDefs.h"
|
|
|
|
|
#include "GpDisplayDriverProperties.h"
|
2019-12-21 18:40:17 -05:00
|
|
|
#include "GpComPtr.h"
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2019-12-23 17:43:10 -05:00
|
|
|
#include "GpPixelFormat.h"
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2020-07-03 02:46:43 -04:00
|
|
|
#include "IGpPrefsHandler.h"
|
|
|
|
|
|
2019-12-22 00:35:30 -05:00
|
|
|
struct GpWindowsGlobals;
|
2020-02-23 20:21:04 -05:00
|
|
|
struct IGpCursor_Win32;
|
|
|
|
|
struct IGpCursor;
|
2019-12-23 17:43:10 -05:00
|
|
|
struct IGpFiber;
|
2019-12-22 00:35:30 -05:00
|
|
|
|
2019-12-11 00:51:42 -05:00
|
|
|
struct IDXGISwapChain1;
|
2019-12-21 18:40:17 -05:00
|
|
|
struct ID3D11Buffer;
|
|
|
|
|
struct ID3D11DepthStencilState;
|
|
|
|
|
struct ID3D11Device;
|
|
|
|
|
struct ID3D11DeviceContext;
|
|
|
|
|
struct ID3D11InputLayout;
|
|
|
|
|
struct ID3D11PixelShader;
|
|
|
|
|
struct ID3D11RenderTargetView;
|
|
|
|
|
struct ID3D11SamplerState;
|
|
|
|
|
struct ID3D11ShaderResourceView;
|
|
|
|
|
struct ID3D11Texture1D;
|
|
|
|
|
struct ID3D11Texture2D;
|
|
|
|
|
struct ID3D11VertexShader;
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2020-05-18 02:03:17 -04:00
|
|
|
|
2020-07-03 02:46:43 -04:00
|
|
|
class GpDisplayDriverD3D11 : public IGpDisplayDriver, public IGpPrefsHandler
|
2019-12-11 00:51:42 -05:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void Run() override;
|
|
|
|
|
void Shutdown() override;
|
|
|
|
|
|
2020-06-13 04:33:41 -04:00
|
|
|
void GetDisplayResolution(unsigned int *width, unsigned int *height) override;
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2019-12-23 17:43:10 -05:00
|
|
|
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, GpPixelFormat_t pixelFormat) override;
|
2020-05-18 02:03:17 -04:00
|
|
|
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
|
2019-12-21 18:40:17 -05:00
|
|
|
|
2020-02-23 20:21:04 -05:00
|
|
|
IGpCursor *LoadCursor(bool isColor, int cursorID) override;
|
|
|
|
|
void SetCursor(IGpCursor *cursor) override;
|
2019-12-22 00:35:30 -05:00
|
|
|
void SetStandardCursor(EGpStandardCursor_t standardCursor) override;
|
|
|
|
|
|
2019-12-21 18:40:17 -05:00
|
|
|
void UpdatePalette(const void *paletteData) override;
|
|
|
|
|
|
2020-04-05 02:15:49 -04:00
|
|
|
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
2020-06-20 02:08:22 -04:00
|
|
|
void SetBackgroundDarkenEffect(bool isDark) override;
|
2020-04-05 02:15:49 -04:00
|
|
|
|
2020-07-03 13:53:10 -04:00
|
|
|
void SetUseICCProfile(bool useICCProfile) override;
|
|
|
|
|
|
2020-04-18 00:18:20 -04:00
|
|
|
void RequestToggleFullScreen(uint32_t timestamp) override;
|
2020-06-20 01:33:26 -04:00
|
|
|
void RequestResetVirtualResolution() override;
|
2020-04-18 00:18:20 -04:00
|
|
|
|
2020-06-13 04:33:41 -04:00
|
|
|
const GpDisplayDriverProperties &GetProperties() const override;
|
2020-07-03 02:46:43 -04:00
|
|
|
IGpPrefsHandler *GetPrefsHandler() const override;
|
|
|
|
|
|
|
|
|
|
void ApplyPrefs(const void *identifier, size_t identifierSize, const void *contents, size_t contentsSize, uint32_t version) override;
|
|
|
|
|
bool SavePrefs(void *context, IGpPrefsHandler::WritePrefsFunc_t writeFunc) override;
|
2020-06-13 04:33:41 -04:00
|
|
|
|
2019-12-11 00:51:42 -05:00
|
|
|
static GpDisplayDriverD3D11 *Create(const GpDisplayDriverProperties &properties);
|
|
|
|
|
|
|
|
|
|
private:
|
2019-12-21 18:40:17 -05:00
|
|
|
struct DrawQuadVertexConstants
|
|
|
|
|
{
|
|
|
|
|
float m_ndcOriginX;
|
|
|
|
|
float m_ndcOriginY;
|
|
|
|
|
float m_ndcWidth;
|
|
|
|
|
float m_ndcHeight;
|
|
|
|
|
|
|
|
|
|
float m_surfaceDimensionX;
|
|
|
|
|
float m_surfaceDimensionY;
|
2020-05-18 02:03:17 -04:00
|
|
|
|
2019-12-21 18:40:17 -05:00
|
|
|
float m_unused[2];
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-18 02:03:17 -04:00
|
|
|
struct DrawQuadPixelConstants
|
|
|
|
|
{
|
|
|
|
|
float m_modulation[4];
|
2020-05-18 03:30:25 -04:00
|
|
|
|
|
|
|
|
int32_t m_flickerAxis[2];
|
|
|
|
|
int32_t m_flickerStart;
|
|
|
|
|
int32_t m_flickerEnd;
|
2020-05-22 21:14:43 -04:00
|
|
|
|
|
|
|
|
float m_desaturation;
|
|
|
|
|
float m_unused[3];
|
2020-05-18 02:03:17 -04:00
|
|
|
};
|
|
|
|
|
|
2020-04-25 18:54:56 -04:00
|
|
|
struct ScaleQuadPixelConstants
|
|
|
|
|
{
|
|
|
|
|
float m_dx;
|
|
|
|
|
float m_dy;
|
|
|
|
|
float m_unused[2];
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-22 00:35:30 -05:00
|
|
|
struct CompactedPresentHistoryItem
|
|
|
|
|
{
|
|
|
|
|
LARGE_INTEGER m_timestamp;
|
|
|
|
|
unsigned int m_numFrames;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-11 00:51:42 -05:00
|
|
|
GpDisplayDriverD3D11(const GpDisplayDriverProperties &properties);
|
2019-12-21 18:40:17 -05:00
|
|
|
~GpDisplayDriverD3D11();
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2020-04-01 14:53:44 -04:00
|
|
|
bool DetachSwapChain();
|
2020-04-25 16:35:34 -04:00
|
|
|
bool InitBackBuffer(uint32_t virtualWidth, uint32_t virtualHeight);
|
|
|
|
|
bool InitResources(uint32_t virtualWidth, uint32_t virtualHeight);
|
2019-12-31 05:20:07 -05:00
|
|
|
GpDisplayDriverTickStatus_t PresentFrameAndSync();
|
2020-04-25 16:35:34 -04:00
|
|
|
void ScaleVirtualScreen();
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2019-12-22 00:35:30 -05:00
|
|
|
void SynchronizeCursors();
|
|
|
|
|
void ChangeToCursor(HCURSOR cursor);
|
|
|
|
|
void ChangeToStandardCursor(EGpStandardCursor_t cursor);
|
|
|
|
|
|
2020-04-18 00:18:20 -04:00
|
|
|
void BecomeFullScreen(LONG &windowStyle);
|
|
|
|
|
void BecomeWindowed(LONG &windowStyle);
|
|
|
|
|
|
2019-12-21 18:40:17 -05:00
|
|
|
GpComPtr<IDXGISwapChain1> m_swapChain;
|
|
|
|
|
GpComPtr<ID3D11Device> m_device;
|
|
|
|
|
GpComPtr<ID3D11DeviceContext> m_deviceContext;
|
|
|
|
|
GpComPtr<ID3D11Buffer> m_quadIndexBuffer;
|
|
|
|
|
GpComPtr<ID3D11Buffer> m_quadVertexBuffer;
|
|
|
|
|
GpComPtr<ID3D11InputLayout> m_drawQuadInputLayout;
|
|
|
|
|
GpComPtr<ID3D11VertexShader> m_drawQuadVertexShader;
|
|
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuadPalettePixelShader;
|
|
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuad15BitPixelShader;
|
|
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuadRGBPixelShader;
|
2020-07-03 13:53:10 -04:00
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuadPaletteICCPixelShader;
|
|
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuad15BitICCPixelShader;
|
|
|
|
|
GpComPtr<ID3D11PixelShader> m_drawQuadRGBICCPixelShader;
|
2020-04-25 16:35:34 -04:00
|
|
|
GpComPtr<ID3D11PixelShader> m_scaleQuadPixelShader;
|
2019-12-21 18:40:17 -05:00
|
|
|
GpComPtr<ID3D11Buffer> m_drawQuadVertexConstantBuffer;
|
2020-05-18 02:03:17 -04:00
|
|
|
GpComPtr<ID3D11Buffer> m_drawQuadPixelConstantBuffer;
|
2020-04-25 18:54:56 -04:00
|
|
|
GpComPtr<ID3D11Buffer> m_scaleQuadPixelConstantBuffer;
|
2019-12-21 18:40:17 -05:00
|
|
|
GpComPtr<ID3D11DepthStencilState> m_drawQuadDepthStencilState;
|
|
|
|
|
GpComPtr<ID3D11SamplerState> m_nearestNeighborSamplerState;
|
|
|
|
|
GpComPtr<ID3D11Texture1D> m_paletteTexture;
|
|
|
|
|
GpComPtr<ID3D11ShaderResourceView> m_paletteTextureSRV;
|
|
|
|
|
|
|
|
|
|
GpComPtr<ID3D11Texture2D> m_backBufferTexture;
|
|
|
|
|
GpComPtr<ID3D11RenderTargetView> m_backBufferRTV;
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2020-04-25 16:35:34 -04:00
|
|
|
GpComPtr<ID3D11Texture2D> m_virtualScreenTexture;
|
|
|
|
|
GpComPtr<ID3D11RenderTargetView> m_virtualScreenTextureRTV;
|
|
|
|
|
GpComPtr<ID3D11ShaderResourceView> m_virtualScreenTextureSRV;
|
|
|
|
|
|
2019-12-11 00:51:42 -05:00
|
|
|
GpRingBuffer<CompactedPresentHistoryItem, 60> m_presentHistory;
|
|
|
|
|
GpDisplayDriverProperties m_properties;
|
|
|
|
|
|
|
|
|
|
LARGE_INTEGER m_syncTimeBase;
|
|
|
|
|
LARGE_INTEGER m_QPFrequency;
|
|
|
|
|
UINT m_expectedSyncDelta;
|
|
|
|
|
bool m_isResettingSwapChain;
|
|
|
|
|
|
2020-04-18 00:18:20 -04:00
|
|
|
bool m_isFullScreen;
|
|
|
|
|
bool m_isFullScreenDesired;
|
2020-06-20 01:33:26 -04:00
|
|
|
bool m_isResolutionResetDesired;
|
2020-04-18 00:18:20 -04:00
|
|
|
RECT m_windowModeRevertRect;
|
|
|
|
|
uint32_t m_lastFullScreenToggleTimeStamp;
|
|
|
|
|
|
2019-12-11 00:51:42 -05:00
|
|
|
LONGLONG m_frameTimeAccumulated;
|
|
|
|
|
LONGLONG m_frameTimeSliceSize;
|
|
|
|
|
|
2020-04-18 00:18:20 -04:00
|
|
|
DWORD m_windowWidthPhysical; // Physical resolution is the resolution of the actual window
|
|
|
|
|
DWORD m_windowHeightPhysical;
|
2020-06-20 01:33:26 -04:00
|
|
|
DWORD m_windowWidthVirtual; // Virtual resolution is the resolution reported to the game
|
2020-04-18 00:18:20 -04:00
|
|
|
DWORD m_windowHeightVirtual;
|
|
|
|
|
float m_pixelScaleX;
|
|
|
|
|
float m_pixelScaleY;
|
2019-12-11 00:51:42 -05:00
|
|
|
|
2020-02-23 20:21:04 -05:00
|
|
|
IGpCursor_Win32 *m_activeCursor;
|
|
|
|
|
IGpCursor_Win32 *m_pendingCursor;
|
2019-12-22 00:35:30 -05:00
|
|
|
EGpStandardCursor_t m_currentStandardCursor;
|
|
|
|
|
EGpStandardCursor_t m_pendingStandardCursor;
|
|
|
|
|
bool m_mouseIsInClientArea;
|
|
|
|
|
|
2019-12-23 17:43:10 -05:00
|
|
|
IGpFiber *m_vosFiber;
|
2019-12-22 00:35:30 -05:00
|
|
|
GpWindowsGlobals *m_osGlobals;
|
|
|
|
|
|
|
|
|
|
HCURSOR m_arrowCursor;
|
2020-02-23 20:21:04 -05:00
|
|
|
HCURSOR m_waitCursor;
|
|
|
|
|
HCURSOR m_ibeamCursor;
|
2020-04-05 02:15:49 -04:00
|
|
|
|
|
|
|
|
float m_bgColor[4];
|
2020-06-20 02:08:22 -04:00
|
|
|
bool m_bgIsDark;
|
2020-07-03 13:53:10 -04:00
|
|
|
|
|
|
|
|
bool m_useICCProfile;
|
2019-12-11 00:51:42 -05:00
|
|
|
};
|