Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
[d3d9] Optimize GetCommonTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
misyltoad committed Aug 10, 2021
1 parent 85468a5 commit 3f78bde
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/d3d9/d3d9_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,21 @@ namespace dxvk {

};

using D3D9TextureGeneric = D3D9BaseTexture<D3D9Surface, IDirect3DBaseTexture9>;

static_assert(sizeof(D3D9Texture2D) == sizeof(D3D9Texture3D) &&
sizeof(D3D9Texture2D) == sizeof(D3D9TextureCube) &&
sizeof(D3D9Texture2D) == sizeof(D3D9TextureGeneric));

inline D3D9CommonTexture* GetCommonTexture(IDirect3DBaseTexture9* ptr) {
if (ptr == nullptr)
return nullptr;

D3DRESOURCETYPE type = ptr->GetType();
if (type == D3DRTYPE_TEXTURE)
return static_cast<D3D9Texture2D*> (ptr)->GetCommonTexture();
else if (type == D3DRTYPE_CUBETEXTURE)
return static_cast<D3D9TextureCube*>(ptr)->GetCommonTexture();
else //if(type == D3DRTYPE_VOLUMETEXTURE)
return static_cast<D3D9Texture3D*> (ptr)->GetCommonTexture();
// We can avoid needing to get the type as m_texture has the same offset
// no matter the texture type.
// The compiler is not smart enough to eliminate the call to GetType as it is
// not marked const.
return static_cast<D3D9TextureGeneric*>(ptr)->GetCommonTexture();
}

inline D3D9CommonTexture* GetCommonTexture(D3D9Surface* ptr) {
Expand All @@ -224,13 +228,11 @@ namespace dxvk {
if (tex == nullptr)
return;

D3DRESOURCETYPE type = tex->GetType();
if (type == D3DRTYPE_TEXTURE)
return CastRefPrivate<D3D9Texture2D> (tex, AddRef);
else if (type == D3DRTYPE_CUBETEXTURE)
return CastRefPrivate<D3D9TextureCube>(tex, AddRef);
else //if(type == D3DRTYPE_VOLUMETEXTURE)
return CastRefPrivate<D3D9Texture3D> (tex, AddRef);
// We can avoid needing to get the type as m_refCount has the same offset
// no matter the texture type.
// The compiler is not smart enough to eliminate the call to GetType as it is
// not marked const.
return CastRefPrivate<D3D9TextureGeneric>(tex, AddRef);
}

inline void TextureChangePrivate(IDirect3DBaseTexture9*& dst, IDirect3DBaseTexture9* src) {
Expand Down

0 comments on commit 3f78bde

Please sign in to comment.