From 3f78bde928e4ad1d854d892178a8c28bc22dd713 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 8 Aug 2021 03:54:23 +0100 Subject: [PATCH] [d3d9] Optimize GetCommonTexture --- src/d3d9/d3d9_texture.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/d3d9/d3d9_texture.h b/src/d3d9/d3d9_texture.h index de1d6615..374dc0b2 100644 --- a/src/d3d9/d3d9_texture.h +++ b/src/d3d9/d3d9_texture.h @@ -196,17 +196,21 @@ namespace dxvk { }; + using D3D9TextureGeneric = D3D9BaseTexture; + + 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 (ptr)->GetCommonTexture(); - else if (type == D3DRTYPE_CUBETEXTURE) - return static_cast(ptr)->GetCommonTexture(); - else //if(type == D3DRTYPE_VOLUMETEXTURE) - return static_cast (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(ptr)->GetCommonTexture(); } inline D3D9CommonTexture* GetCommonTexture(D3D9Surface* ptr) { @@ -224,13 +228,11 @@ namespace dxvk { if (tex == nullptr) return; - D3DRESOURCETYPE type = tex->GetType(); - if (type == D3DRTYPE_TEXTURE) - return CastRefPrivate (tex, AddRef); - else if (type == D3DRTYPE_CUBETEXTURE) - return CastRefPrivate(tex, AddRef); - else //if(type == D3DRTYPE_VOLUMETEXTURE) - return CastRefPrivate (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(tex, AddRef); } inline void TextureChangePrivate(IDirect3DBaseTexture9*& dst, IDirect3DBaseTexture9* src) {