From 409eac9d209efcdc3e8c2e7a950a044595f97a18 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sun, 19 Apr 2020 01:11:11 +0100 Subject: [PATCH] [d3d9] Use if/else in GetCommonTexture and TextureRefPrivate These are the only things it can be, and they all end up calling what the compiler will optimize to the same function so we can avoid a branch here. --- src/d3d9/d3d9_texture.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/d3d9/d3d9_texture.h b/src/d3d9/d3d9_texture.h index abad69f3b..be19d3273 100644 --- a/src/d3d9/d3d9_texture.h +++ b/src/d3d9/d3d9_texture.h @@ -189,15 +189,13 @@ namespace dxvk { if (ptr == nullptr) return nullptr; - switch (ptr->GetType()) { - case D3DRTYPE_TEXTURE: return static_cast (ptr)->GetCommonTexture(); - case D3DRTYPE_CUBETEXTURE: return static_cast(ptr)->GetCommonTexture(); - case D3DRTYPE_VOLUMETEXTURE: return static_cast (ptr)->GetCommonTexture(); - default: - Logger::warn("Unknown texture resource type."); break; - } - - 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(); } inline D3D9CommonTexture* GetCommonTexture(D3D9Surface* ptr) { @@ -215,13 +213,13 @@ namespace dxvk { if (tex == nullptr) return; - switch (tex->GetType()) { - case D3DRTYPE_TEXTURE: CastRefPrivate (tex, AddRef); break; - case D3DRTYPE_CUBETEXTURE: CastRefPrivate(tex, AddRef); break; - case D3DRTYPE_VOLUMETEXTURE: CastRefPrivate (tex, AddRef); break; - default: - Logger::warn("Unknown texture resource type."); break; - } + 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); } inline void TextureChangePrivate(IDirect3DBaseTexture9*& dst, IDirect3DBaseTexture9* src) {