From bb2fc8ecbb9fe2e54b0a657ebd24702ab27f7e8c Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 5 Jun 2014 17:55:21 +0200 Subject: VideoCommon: Cache native vertex formats We are used to have a 1:1 mapping of GX vertex formats and the native (OGL + D3D) ones, but there are by far more GX ones. This new cache maps them directly so that we don't flush on GX vertex format changes as long as the native one doesn't change. The idea is stolen from galop1n. --- Source/Core/VideoCommon/VertexLoaderManager.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp') diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index b39577dd26..dd1196a48e 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -33,11 +34,13 @@ struct hash } typedef std::unordered_map VertexLoaderMap; +typedef std::map> NativeVertexLoaderMap; namespace VertexLoaderManager { static VertexLoaderMap g_VertexLoaderMap; +static NativeVertexLoaderMap s_native_vertex_map; // TODO - change into array of pointers. Keep a map of all seen so far. void Init() @@ -55,6 +58,7 @@ void Shutdown() delete p.second; } g_VertexLoaderMap.clear(); + s_native_vertex_map.clear(); } namespace @@ -131,6 +135,19 @@ int GetVertexSize(int vtx_attr_group) return RefreshLoader(vtx_attr_group)->GetVertexSize(); } +NativeVertexFormat* GetNativeVertexFormat(const PortableVertexDeclaration& format, u32 components) +{ + auto& native = s_native_vertex_map[format]; + if (!native) + { + auto raw_pointer = g_vertex_manager->CreateNativeVertexFormat(); + native = std::unique_ptr(raw_pointer); + native->m_components = components; + native->Initialize(format); + } + return native.get(); +} + } // namespace void LoadCPReg(u32 sub_cmd, u32 value) -- cgit v1.2.3