Skip to content

Commit

Permalink
Segregating Locks used for critical Device specific data on Client si…
Browse files Browse the repository at this point in the history
…de from DeviceBridge Queue
  • Loading branch information
lvengesanam committed Sep 22, 2023
1 parent b41ad87 commit c300ed8
Show file tree
Hide file tree
Showing 22 changed files with 668 additions and 662 deletions.
4 changes: 4 additions & 0 deletions src/client/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
using ShadowMap = std::unordered_map<uintptr_t, IUnknown*>;
extern ShadowMap gShadowMap;

extern std::mutex gShadowMapMutex;

enum class D3D9ObjectType: char {
Module,
Device,
Expand Down Expand Up @@ -372,7 +374,9 @@ class D3DBase: public T, public D3DRefCounted, private D3DRefCounted::RefCountTy
}

~D3DBase() override {
gShadowMapMutex.lock();
gShadowMap.erase(m_id);
gShadowMapMutex.unlock();
#ifdef _DEBUG
Logger::debug(format_string("%s object [%p/%p] destroyed",
toD3D9ObjectTypeName<T>(), this, m_id));
Expand Down
39 changes: 23 additions & 16 deletions src/client/d3d9_base_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ class Direct3DBaseTexture9_LSS: public Direct3DContainer9_LSS<Direct3DResource9_
STDMETHOD_(DWORD, SetLOD)(THIS_ DWORD LODNew) {
LogFunctionCall();

DWORD oldLod = m_lod;
m_lod = LODNew;

if (oldLod != LODNew) {
DWORD oldLod;
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
oldLod = m_lod;
m_lod = LODNew;
}
if (oldLod != LODNew) {
ClientMessage c(Commands::IDirect3DBaseTexture9_SetLOD, getId());
c.send_data(LODNew);
}
Expand All @@ -105,6 +107,7 @@ class Direct3DBaseTexture9_LSS: public Direct3DContainer9_LSS<Direct3DResource9_

STDMETHOD_(DWORD, GetLOD)(THIS) {
LogFunctionCall();
BRIDGE_PARENT_DEVICE_LOCKGUARD();
return m_lod;
}

Expand All @@ -125,31 +128,35 @@ class Direct3DBaseTexture9_LSS: public Direct3DContainer9_LSS<Direct3DResource9_
return D3DERR_INVALIDCALL;
}

if (m_mipFilter != FilterType) {
m_mipFilter = FilterType;
UID currentUID = 0;
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
ClientMessage c(Commands::IDirect3DBaseTexture9_SetAutoGenFilterType, getId());
currentUID = c.get_uid();
c.send_data(FilterType);
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
if (m_mipFilter == FilterType) {
return S_OK;
} else {
m_mipFilter = FilterType;
}
WAIT_FOR_OPTIONAL_SERVER_RESPONSE("SetAutoGenFilterType()", D3DERR_INVALIDCALL, currentUID);
}

return S_OK;

UID currentUID = 0;
{
ClientMessage c(Commands::IDirect3DBaseTexture9_SetAutoGenFilterType, getId());
currentUID = c.get_uid();
c.send_data(FilterType);
}
WAIT_FOR_OPTIONAL_SERVER_RESPONSE("SetAutoGenFilterType()", D3DERR_INVALIDCALL, currentUID);
}

STDMETHOD_(D3DTEXTUREFILTERTYPE, GetAutoGenFilterType)(THIS) {
LogFunctionCall();

BRIDGE_PARENT_DEVICE_LOCKGUARD();
return m_mipFilter;
}

STDMETHOD_(void, GenerateMipSubLevels)(THIS) {
LogFunctionCall();

if (m_desc.Usage & D3DUSAGE_AUTOGENMIPMAP) {
BRIDGE_PARENT_DEVICE_LOCKGUARD();
ClientMessage c(Commands::IDirect3DBaseTexture9_GenerateMipSubLevels, getId());
}
}
Expand Down
37 changes: 15 additions & 22 deletions src/client/d3d9_cubetexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ ULONG Direct3DCubeTexture9_LSS::Release() {
}

void Direct3DCubeTexture9_LSS::onDestroy() {
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage { Commands::IDirect3DCubeTexture9_Destroy, getId() };
}
ClientMessage { Commands::IDirect3DCubeTexture9_Destroy, getId() };
}

HRESULT Direct3DCubeTexture9_LSS::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDesc) {
Expand All @@ -83,12 +80,9 @@ HRESULT Direct3DCubeTexture9_LSS::GetLevelDesc(UINT Level, D3DSURFACE_DESC* pDes
*pDesc = getLevelDesc(Level);

if (GlobalOptions::getSendReadOnlyCalls()) {
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage c(Commands::IDirect3DCubeTexture9_GetLevelDesc, getId());
c.send_data(sizeof(D3DSURFACE_DESC), pDesc);
c.send_data(Level);
}
ClientMessage c(Commands::IDirect3DCubeTexture9_GetLevelDesc, getId());
c.send_data(sizeof(D3DSURFACE_DESC), pDesc);
c.send_data(Level);
}
return S_OK;
}
Expand Down Expand Up @@ -125,22 +119,24 @@ HRESULT Direct3DCubeTexture9_LSS::GetCubeMapSurface(D3DCUBEMAP_FACES FaceType, U
return D3D_OK;
}

Direct3DSurface9_LSS* pLssCubeMapSurface = nullptr;
D3DSURFACE_DESC desc;
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
// Insert our own IDirect3DSurface9 interface implementation
D3DSURFACE_DESC desc;

GetLevelDesc(Level, &desc);

auto* const pLssCubeMapSurface = trackWrapper(new Direct3DSurface9_LSS(m_pDevice, this, desc));
pLssCubeMapSurface = trackWrapper(new Direct3DSurface9_LSS(m_pDevice, this, desc));
(*ppCubeMapSurface) = (IDirect3DSurface9*) pLssCubeMapSurface;

setChild(surfaceIndex, pLssCubeMapSurface);
}

{
ClientMessage c(Commands::IDirect3DCubeTexture9_GetCubeMapSurface, getId());
c.send_many(FaceType, Level);
c.send_data(pLssCubeMapSurface->getId());
}
{
ClientMessage c(Commands::IDirect3DCubeTexture9_GetCubeMapSurface, getId());
c.send_many(FaceType, Level);
c.send_data(pLssCubeMapSurface->getId());
}
return S_OK;
}
Expand Down Expand Up @@ -197,11 +193,8 @@ HRESULT Direct3DCubeTexture9_LSS::UnlockRect(D3DCUBEMAP_FACES FaceType, UINT Lev
HRESULT Direct3DCubeTexture9_LSS::AddDirtyRect(D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect) {
LogFunctionCall();
{
BRIDGE_PARENT_DEVICE_LOCKGUARD();
{
ClientMessage c(Commands::IDirect3DCubeTexture9_AddDirtyRect, getId());
c.send_data(sizeof(RECT), (void*) pDirtyRect);
}
ClientMessage c(Commands::IDirect3DCubeTexture9_AddDirtyRect, getId());
c.send_data(sizeof(RECT), (void*) pDirtyRect);
}
return S_OK;
}
Loading

0 comments on commit c300ed8

Please sign in to comment.