2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2021-05-13 23:05:31 +00:00
|
|
|
#include <array>
|
2016-02-26 19:55:34 +00:00
|
|
|
#include <memory>
|
2009-08-10 06:18:10 +00:00
|
|
|
#include <string>
|
2016-01-08 03:38:00 +00:00
|
|
|
#include <unordered_map>
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2021-06-20 20:47:57 +00:00
|
|
|
#include "Common/EnumMap.h"
|
2021-03-26 22:46:37 +00:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
|
|
|
|
class NativeVertexFormat;
|
2016-01-08 03:38:00 +00:00
|
|
|
struct PortableVertexDeclaration;
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2021-04-30 21:57:12 +00:00
|
|
|
namespace OpcodeDecoder
|
|
|
|
{
|
|
|
|
enum class Primitive : u8;
|
2024-08-18 13:08:44 +00:00
|
|
|
}
|
2021-04-30 21:57:12 +00:00
|
|
|
|
2008-10-25 12:35:55 +00:00
|
|
|
namespace VertexLoaderManager
|
|
|
|
{
|
2016-01-08 03:38:00 +00:00
|
|
|
using NativeVertexFormatMap =
|
|
|
|
std::unordered_map<PortableVertexDeclaration, std::unique_ptr<NativeVertexFormat>>;
|
|
|
|
|
2008-12-25 21:44:56 +00:00
|
|
|
void Init();
|
2016-01-13 20:14:20 +00:00
|
|
|
void Clear();
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-10-25 15:53:43 +00:00
|
|
|
void MarkAllDirty();
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2017-07-03 09:43:47 +00:00
|
|
|
// Creates or obtains a pointer to a VertexFormat representing decl.
|
|
|
|
// If this results in a VertexFormat being created, if the game later uses a matching vertex
|
|
|
|
// declaration, the one that was previously created will be used.
|
|
|
|
NativeVertexFormat* GetOrCreateMatchingFormat(const PortableVertexDeclaration& decl);
|
|
|
|
|
|
|
|
// For vertex ubershaders, all attributes need to be present, even when the vertex
|
|
|
|
// format does not contain them. This function returns a vertex format with dummy
|
|
|
|
// offsets set to the unused attributes.
|
|
|
|
NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl);
|
|
|
|
|
2014-12-09 07:35:04 +00:00
|
|
|
// Returns -1 if buf_size is insufficient, else the amount of bytes consumed
|
2022-09-15 21:38:57 +00:00
|
|
|
template <bool IsPreprocess = false>
|
2022-11-23 00:54:05 +00:00
|
|
|
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, const u8* src);
|
2022-09-15 21:38:57 +00:00
|
|
|
|
|
|
|
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
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-07-25 23:10:44 +00:00
|
|
|
NativeVertexFormat* GetCurrentVertexFormat();
|
2015-05-29 12:42:45 +00:00
|
|
|
|
|
|
|
// Resolved pointers to array bases. Used by vertex loaders.
|
2021-06-20 20:47:57 +00:00
|
|
|
extern Common::EnumMap<u8*, CPArray::TexCoord7> cached_arraybases;
|
2015-05-29 12:42:45 +00:00
|
|
|
void UpdateVertexArrayPointers();
|
2015-06-01 17:58:27 +00:00
|
|
|
|
|
|
|
// Position cache for zfreeze (3 vertices, 4 floats each to allow SIMD overwrite).
|
|
|
|
// These arrays are in reverse order.
|
2022-04-13 23:12:53 +00:00
|
|
|
extern std::array<std::array<float, 4>, 3> position_cache;
|
2022-04-14 19:01:57 +00:00
|
|
|
extern std::array<u32, 3> position_matrix_index_cache;
|
Cache normals in addition to binormals and tangents
Fixes LIT (https://bugs.dolphin-emu.org/issues/13635). The text does not include normals, but has lighting enabled. With the previous default of (0, 0, 0), lighting was always black (as dot(X, (0, 0, 0)) is always 0). It seems like the normal from the map in the background (0, 0, 1) is re-used.
LIT also has the vertex color enabled while vertex color is not specified, the same as SMS's debug cubes; the default MissingColorValue GameINI value of solid white seems to work correctly in this case.
2024-09-25 06:46:45 +00:00
|
|
|
// Needed for the game "LIT", which has text that has lighting enabled, but doesn't have normal
|
|
|
|
// vectors. The normals from the last drawn object are used instead.
|
|
|
|
// See https://bugs.dolphin-emu.org/issues/13635
|
|
|
|
extern std::array<float, 4> normal_cache;
|
2022-04-14 05:03:34 +00:00
|
|
|
// Store the tangent and binormal vectors for games that use emboss texgens when the vertex format
|
|
|
|
// doesn't include them (e.g. RS2 and RS3). These too are 4 floats each for SIMD overwrites.
|
|
|
|
extern std::array<float, 4> tangent_cache;
|
|
|
|
extern std::array<float, 4> binormal_cache;
|
2015-11-01 21:39:31 +00:00
|
|
|
|
|
|
|
// VB_HAS_X. Bitmask telling what vertex components are present.
|
|
|
|
extern u32 g_current_components;
|
2021-05-13 23:05:31 +00:00
|
|
|
|
|
|
|
extern BitSet8 g_main_vat_dirty;
|
|
|
|
extern BitSet8 g_preprocess_vat_dirty;
|
|
|
|
extern bool g_bases_dirty; // 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;
|
2022-11-16 13:39:29 +00:00
|
|
|
extern bool g_needs_cp_xf_consistency_check;
|
2022-09-15 21:38:57 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace VertexLoaderManager
|