From e7d0fa8f10d0cd124a3c3ef1281506e4aec3bc2b Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 30 May 2020 21:23:49 +0200 Subject: [PATCH] Prevent some redundant state changes from execute buffers --- DDrawCompat/D3dDdi/Device.cpp | 37 ++++++++++++++++++++++++++++++ DDrawCompat/D3dDdi/Device.h | 5 ++++ DDrawCompat/D3dDdi/DeviceFuncs.cpp | 2 ++ 3 files changed, 44 insertions(+) diff --git a/DDrawCompat/D3dDdi/Device.cpp b/DDrawCompat/D3dDdi/Device.cpp index 86e1c19..9d553c2 100644 --- a/DDrawCompat/D3dDdi/Device.cpp +++ b/DDrawCompat/D3dDdi/Device.cpp @@ -24,6 +24,8 @@ namespace D3dDdi , m_renderTarget(nullptr) , m_renderTargetSubResourceIndex(0) , m_sharedPrimary(nullptr) + , m_textures{} + , m_vertexShaderDecl(nullptr) , m_drawPrimitive(*this) { } @@ -218,6 +220,41 @@ namespace D3dDdi return m_drawPrimitive.setStreamSourceUm(*data, umBuffer); } + HRESULT Device::setTexture(UINT stage, HANDLE texture) + { + if (stage < m_textures.size()) + { + if (texture == m_textures[stage]) + { + return S_OK; + } + + HRESULT result = m_origVtable.pfnSetTexture(m_device, stage, texture); + if (SUCCEEDED(result) && stage < m_textures.size()) + { + m_textures[stage] = texture; + } + return result; + } + + return m_origVtable.pfnSetTexture(m_device, stage, texture); + } + + HRESULT Device::setVertexShaderDecl(HANDLE shader) + { + if (shader == m_vertexShaderDecl) + { + return S_OK; + } + + HRESULT result = m_origVtable.pfnSetVertexShaderDecl(m_device, shader); + if (SUCCEEDED(result)) + { + m_vertexShaderDecl = shader; + } + return result; + } + HRESULT Device::unlock(const D3DDDIARG_UNLOCK* data) { auto it = m_resources.find(data->hResource); diff --git a/DDrawCompat/D3dDdi/Device.h b/DDrawCompat/D3dDdi/Device.h index aa4a479..871b9c5 100644 --- a/DDrawCompat/D3dDdi/Device.h +++ b/DDrawCompat/D3dDdi/Device.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -37,6 +38,8 @@ namespace D3dDdi HRESULT setRenderTarget(const D3DDDIARG_SETRENDERTARGET* data); HRESULT setStreamSource(const D3DDDIARG_SETSTREAMSOURCE* data); HRESULT setStreamSourceUm(const D3DDDIARG_SETSTREAMSOURCEUM* data, const void* umBuffer); + HRESULT setTexture(UINT stage, HANDLE texture); + HRESULT setVertexShaderDecl(HANDLE shader); HRESULT unlock(const D3DDDIARG_UNLOCK* data); HRESULT updateWInfo(const D3DDDIARG_WINFO* data); @@ -70,6 +73,8 @@ namespace D3dDdi Resource* m_renderTarget; UINT m_renderTargetSubResourceIndex; HANDLE m_sharedPrimary; + std::array m_textures; + HANDLE m_vertexShaderDecl; DrawPrimitive m_drawPrimitive; static std::map s_devices; diff --git a/DDrawCompat/D3dDdi/DeviceFuncs.cpp b/DDrawCompat/D3dDdi/DeviceFuncs.cpp index 423189a..275ea5b 100644 --- a/DDrawCompat/D3dDdi/DeviceFuncs.cpp +++ b/DDrawCompat/D3dDdi/DeviceFuncs.cpp @@ -45,6 +45,8 @@ namespace D3dDdi vtable.pfnSetRenderTarget = &DEVICE_FUNC(setRenderTarget); vtable.pfnSetStreamSource = &DEVICE_FUNC(setStreamSource); vtable.pfnSetStreamSourceUm = &DEVICE_FUNC(setStreamSourceUm); + vtable.pfnSetTexture = &DEVICE_FUNC(setTexture); + vtable.pfnSetVertexShaderDecl = &DEVICE_FUNC(setVertexShaderDecl); vtable.pfnUnlock = &DEVICE_FUNC(unlock); vtable.pfnUpdateWInfo = &DEVICE_FUNC(updateWInfo); }