summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/VertexLoaderManager.cpp
diff options
context:
space:
mode:
authordegasus <wickmarkus@web.de>2014-06-05 17:55:21 +0200
committerdegasus <wickmarkus@web.de>2014-07-04 14:39:27 +0200
commitbb2fc8ecbb9fe2e54b0a657ebd24702ab27f7e8c (patch)
treef4281b705a795b4db115243cb9c20683525213f0 /Source/Core/VideoCommon/VertexLoaderManager.cpp
parentbe1fe80bb63ff98dab206b8ac3a7f1924042d814 (diff)
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.
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoaderManager.cpp')
-rw-r--r--Source/Core/VideoCommon/VertexLoaderManager.cpp17
1 files changed, 17 insertions, 0 deletions
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 <algorithm>
+#include <memory>
#include <unordered_map>
#include <vector>
@@ -33,11 +34,13 @@ struct hash<VertexLoaderUID>
}
typedef std::unordered_map<VertexLoaderUID, VertexLoader*> VertexLoaderMap;
+typedef std::map<PortableVertexDeclaration, std::unique_ptr<NativeVertexFormat>> 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<NativeVertexFormat>(raw_pointer);
+ native->m_components = components;
+ native->Initialize(format);
+ }
+ return native.get();
+}
+
} // namespace
void LoadCPReg(u32 sub_cmd, u32 value)