From e9b133eaa4610e09e5ec35be8ae6e280a7cd61bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Ansel?= Date: Tue, 16 Jul 2019 17:12:06 +0200 Subject: [PATCH 1/4] Misc update --- impl11/ddraw/Direct3DDevice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/impl11/ddraw/Direct3DDevice.cpp b/impl11/ddraw/Direct3DDevice.cpp index 06124507..17b32e7c 100644 --- a/impl11/ddraw/Direct3DDevice.cpp +++ b/impl11/ddraw/Direct3DDevice.cpp @@ -659,7 +659,9 @@ HRESULT Direct3DDevice::Execute( } else { + texture->_refCount++; context->PSSetShaderResources(0, 1, texture->_textureView.GetAddressOf()); + texture->_refCount--; pixelShader = this->_deviceResources->_pixelShaderTexture; } From b5771508f70b22132607bc1fd804c8ddbf5cf322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Ansel?= Date: Tue, 16 Jul 2019 17:14:00 +0200 Subject: [PATCH 2/4] Add an option to disable VSync --- impl11/ddraw/PrimarySurface.cpp | 2 +- impl11/ddraw/config.cpp | 5 +++++ impl11/ddraw/config.h | 1 + impl11/ddraw/ddraw.cfg | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/impl11/ddraw/PrimarySurface.cpp b/impl11/ddraw/PrimarySurface.cpp index f75ce39b..4fafa705 100644 --- a/impl11/ddraw/PrimarySurface.cpp +++ b/impl11/ddraw/PrimarySurface.cpp @@ -531,7 +531,7 @@ HRESULT PrimarySurface::Flip( this->_deviceResources->_d3dDeviceContext->ResolveSubresource(this->_deviceResources->_backBuffer, 0, this->_deviceResources->_offscreenBuffer, 0, DXGI_FORMAT_B8G8R8A8_UNORM); - if (FAILED(hr = this->_deviceResources->_swapChain->Present(1, 0))) + if (FAILED(hr = this->_deviceResources->_swapChain->Present(g_config.VSyncEnabled ? 1 : 0, 0))) { static bool messageShown = false; diff --git a/impl11/ddraw/config.cpp b/impl11/ddraw/config.cpp index 6fdfd091..1fa49bf7 100644 --- a/impl11/ddraw/config.cpp +++ b/impl11/ddraw/config.cpp @@ -18,6 +18,7 @@ Config::Config() this->AspectRatioPreserved = true; this->MultisamplingAntialiasingEnabled = false; this->AnisotropicFilteringEnabled = true; + this->VSyncEnabled = true; this->WireframeFillMode = false; this->Concourse3DScale = 0.6f; @@ -67,6 +68,10 @@ Config::Config() { this->AnisotropicFilteringEnabled = stoi(value) != 0; } + else if (name == "EnableVSync") + { + this->VSyncEnabled = stoi(value) != 0; + } else if (name == "FillWireframe") { this->WireframeFillMode = stoi(value) != 0; diff --git a/impl11/ddraw/config.h b/impl11/ddraw/config.h index 8db2e775..a27f5474 100644 --- a/impl11/ddraw/config.h +++ b/impl11/ddraw/config.h @@ -11,6 +11,7 @@ class Config bool AspectRatioPreserved; bool MultisamplingAntialiasingEnabled; bool AnisotropicFilteringEnabled; + bool VSyncEnabled; bool WireframeFillMode; float Concourse3DScale; diff --git a/impl11/ddraw/ddraw.cfg b/impl11/ddraw/ddraw.cfg index 140f96a2..5c666ddc 100644 --- a/impl11/ddraw/ddraw.cfg +++ b/impl11/ddraw/ddraw.cfg @@ -16,6 +16,9 @@ EnableMultisamplingAntialiasing = 0 ; When set to 1, anisotropic filtering will be used. EnableAnisotropicFiltering = 1 +; EnableVSync = 0 (vsync off) or 1 (vsync on) +EnableVSync = 1 + ; FillWireframe = 0 (solid) or 1 (wireframe) ; When set to 0, fill mode wil be solid. ; When set to 1, fill mode will be wireframe. From fe50cc59e03225bb7e39ae2852e87d305e7c7891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Ansel?= Date: Tue, 16 Jul 2019 17:36:03 +0200 Subject: [PATCH 3/4] Reduce memory usage --- impl11/ddraw/Direct3DTexture.cpp | 5 +++-- impl11/ddraw/MipmapSurface.cpp | 26 ++++++++++++++++++++++++-- impl11/ddraw/MipmapSurface.h | 6 +++++- impl11/ddraw/TextureSurface.cpp | 18 +++++++++++++++++- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/impl11/ddraw/Direct3DTexture.cpp b/impl11/ddraw/Direct3DTexture.cpp index ae6da096..eb431dd4 100644 --- a/impl11/ddraw/Direct3DTexture.cpp +++ b/impl11/ddraw/Direct3DTexture.cpp @@ -227,8 +227,9 @@ HRESULT Direct3DTexture::Load( LogText(str.str()); #endif + d3dTexture->_textureView->AddRef(); *&this->_textureView = d3dTexture->_textureView.Get(); - this->_textureView->AddRef(); + return D3D_OK; } @@ -366,8 +367,8 @@ HRESULT Direct3DTexture::Load( return D3DERR_TEXTURE_LOAD_FAILED; } + d3dTexture->_textureView->AddRef(); *&this->_textureView = d3dTexture->_textureView.Get(); - this->_textureView->AddRef(); return D3D_OK; } diff --git a/impl11/ddraw/MipmapSurface.cpp b/impl11/ddraw/MipmapSurface.cpp index 2644517b..551b1aca 100644 --- a/impl11/ddraw/MipmapSurface.cpp +++ b/impl11/ddraw/MipmapSurface.cpp @@ -4,13 +4,16 @@ #include "common.h" #include "DeviceResources.h" #include "MipmapSurface.h" +#include "TextureSurface.h" #include "Direct3DTexture.h" -MipmapSurface::MipmapSurface(DeviceResources* deviceResources, DWORD width, DWORD height, DDPIXELFORMAT& pixelFormat, DWORD mipmapCount, char* buffer) +MipmapSurface::MipmapSurface(DeviceResources* deviceResources, TextureSurface* surface, DWORD width, DWORD height, DDPIXELFORMAT& pixelFormat, DWORD mipmapCount, char* buffer) { this->_refCount = 1; this->_deviceResources = deviceResources; + this->_surface = surface; + this->_width = width; this->_height = height; this->_pixelFormat = pixelFormat; @@ -21,7 +24,7 @@ MipmapSurface::MipmapSurface(DeviceResources* deviceResources, DWORD width, DWOR if (this->_mipmapCount > 1) { - *this->_mipmap.GetAddressOf() = new MipmapSurface(this->_deviceResources, max(this->_width / 2, 1), max(this->_height / 2, 1), this->_pixelFormat, this->_mipmapCount - 1, this->_buffer + this->_bufferSize); + *this->_mipmap.GetAddressOf() = new MipmapSurface(this->_deviceResources, surface, max(this->_width / 2, 1), max(this->_height / 2, 1), this->_pixelFormat, this->_mipmapCount - 1, this->_buffer + this->_bufferSize); } } @@ -736,6 +739,25 @@ HRESULT MipmapSurface::Unlock( LogText(str.str()); #endif + if (this->_mipmapCount == 1) + { + this->_surface->_d3dTexture->Load(this->_surface->_d3dTexture); + + if (this->_surface->_buffer != nullptr) + { + delete[] this->_surface->_buffer; + this->_surface->_buffer = nullptr; + this->_surface->_bufferSize = 0; + this->_surface->_width = 0; + this->_surface->_height = 0; + + this->_buffer = nullptr; + this->_bufferSize = 0; + this->_width = 0; + this->_height = 0; + } + } + return DD_OK; } diff --git a/impl11/ddraw/MipmapSurface.h b/impl11/ddraw/MipmapSurface.h index 960a500c..6b8f4adf 100644 --- a/impl11/ddraw/MipmapSurface.h +++ b/impl11/ddraw/MipmapSurface.h @@ -3,10 +3,12 @@ #pragma once +class TextureSurface; + class MipmapSurface : public IDirectDrawSurface { public: - MipmapSurface(DeviceResources* deviceResources, DWORD width, DWORD height, DDPIXELFORMAT& pixelFormat, DWORD mipmapCount, char* buffer); + MipmapSurface(DeviceResources* deviceResources, TextureSurface* surface, DWORD width, DWORD height, DDPIXELFORMAT& pixelFormat, DWORD mipmapCount, char* buffer); virtual ~MipmapSurface(); @@ -90,6 +92,8 @@ class MipmapSurface : public IDirectDrawSurface DeviceResources* _deviceResources; + TextureSurface* _surface; + DWORD _width; DWORD _height; DDPIXELFORMAT _pixelFormat; diff --git a/impl11/ddraw/TextureSurface.cpp b/impl11/ddraw/TextureSurface.cpp index f8a34c47..213c7697 100644 --- a/impl11/ddraw/TextureSurface.cpp +++ b/impl11/ddraw/TextureSurface.cpp @@ -32,7 +32,7 @@ TextureSurface::TextureSurface(DeviceResources* deviceResources, bool allocOnLoa if (this->_mipmapCount > 1) { - *this->_mipmap.GetAddressOf() = new MipmapSurface(this->_deviceResources, max(this->_width / 2, 1), max(this->_height / 2, 1), this->_pixelFormat, this->_mipmapCount - 1, this->_buffer + this->_bufferSize / 2); + *this->_mipmap.GetAddressOf() = new MipmapSurface(this->_deviceResources, this, max(this->_width / 2, 1), max(this->_height / 2, 1), this->_pixelFormat, this->_mipmapCount - 1, this->_buffer + this->_bufferSize / 2); } } @@ -44,6 +44,7 @@ TextureSurface::~TextureSurface() if (this->_buffer != nullptr) { delete[] this->_buffer; + this->_buffer = nullptr; } } @@ -780,6 +781,21 @@ HRESULT TextureSurface::Unlock( LogText(str.str()); #endif + // do not free memory for ModelIndex_418_16000_0_ResData_Fonts + if (this->_pixelFormat.dwRGBBitCount == 32 && this->_mipmapCount == 1) + { + this->_d3dTexture->Load(this->_d3dTexture); + + if (this->_buffer != nullptr) + { + delete[] this->_buffer; + this->_buffer = nullptr; + this->_bufferSize = 0; + this->_width = 0; + this->_height = 0; + } + } + return DD_OK; } From 0b6058b26ae03f5061d3c6e65a9f7f565e362182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Ansel?= Date: Tue, 16 Jul 2019 17:38:17 +0200 Subject: [PATCH 4/4] Bump version --- impl11/ddraw/ddraw.rc | Bin 4598 -> 4598 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/impl11/ddraw/ddraw.rc b/impl11/ddraw/ddraw.rc index 2ca70fa593d59427760577fd8f1d8f58ca5f3995..f90fbd96a1ad3c4dae4c84f3236fa9e21c378823 100644 GIT binary patch delta 42 wcmeyS{7rd74F{w7CZO0sZt2Nvd_tSq_&zWL04aqGlK=n! delta 42 wcmeyS{7rd74F{vyCZO0sZt2Nvd_tSq_&zWL04XF4j{pDw