mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
VertexLoaderManager: Clean up and slightly speed up with templates
This commit is contained in:
@ -42,8 +42,16 @@ NativeVertexFormat* GetOrCreateMatchingFormat(const PortableVertexDeclaration& d
|
||||
NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl);
|
||||
|
||||
// Returns -1 if buf_size is insufficient, else the amount of bytes consumed
|
||||
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, DataReader src,
|
||||
bool is_preprocess);
|
||||
template <bool IsPreprocess = false>
|
||||
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, DataReader src);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This will look for an existing loader in the global hashmap or create a new one if there is none.
|
||||
// It should not be used directly because RefreshLoaders() has another cache for fast lookups.
|
||||
template <bool IsPreprocess = false>
|
||||
VertexLoaderBase* GetOrCreateLoader(int vtx_attr_group);
|
||||
} // namespace detail
|
||||
|
||||
NativeVertexFormat* GetCurrentVertexFormat();
|
||||
|
||||
@ -66,7 +74,31 @@ extern u32 g_current_components;
|
||||
extern BitSet8 g_main_vat_dirty;
|
||||
extern BitSet8 g_preprocess_vat_dirty;
|
||||
extern bool g_bases_dirty; // Main only
|
||||
extern u8 g_current_vat; // Main only
|
||||
extern std::array<VertexLoaderBase*, CP_NUM_VAT_REG> g_main_vertex_loaders;
|
||||
extern std::array<VertexLoaderBase*, CP_NUM_VAT_REG> g_preprocess_vertex_loaders;
|
||||
|
||||
template <bool IsPreprocess = false>
|
||||
VertexLoaderBase* RefreshLoader(int vtx_attr_group)
|
||||
{
|
||||
constexpr const BitSet8& attr_dirty = IsPreprocess ? g_preprocess_vat_dirty : g_main_vat_dirty;
|
||||
constexpr const auto& vertex_loaders =
|
||||
IsPreprocess ? g_preprocess_vertex_loaders : g_main_vertex_loaders;
|
||||
|
||||
VertexLoaderBase* loader;
|
||||
if (!attr_dirty[vtx_attr_group]) [[likely]]
|
||||
{
|
||||
loader = vertex_loaders[vtx_attr_group];
|
||||
}
|
||||
else [[unlikely]]
|
||||
{
|
||||
loader = detail::GetOrCreateLoader<IsPreprocess>(vtx_attr_group);
|
||||
}
|
||||
|
||||
// Lookup pointers for any vertex arrays.
|
||||
if constexpr (!IsPreprocess)
|
||||
UpdateVertexArrayPointers();
|
||||
|
||||
return loader;
|
||||
}
|
||||
|
||||
} // namespace VertexLoaderManager
|
||||
|
Reference in New Issue
Block a user