2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2009-03-07 01:35:01 -07:00
|
|
|
|
2019-06-01 05:55:09 -06:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
|
2010-03-05 19:07:48 -07:00
|
|
|
#include <algorithm>
|
2019-06-01 05:55:09 -06:00
|
|
|
#include <iterator>
|
2014-06-05 09:55:21 -06:00
|
|
|
#include <memory>
|
2014-08-24 21:53:28 -06:00
|
|
|
#include <mutex>
|
2016-01-17 14:54:31 -07:00
|
|
|
#include <string>
|
2012-12-09 23:40:28 -07:00
|
|
|
#include <unordered_map>
|
2014-08-15 08:17:06 -06:00
|
|
|
#include <utility>
|
2009-03-07 01:35:01 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2016-01-17 14:54:31 -07:00
|
|
|
#include "Common/Assert.h"
|
|
|
|
#include "Common/CommonTypes.h"
|
2021-02-28 14:53:32 -07:00
|
|
|
#include "Common/Logging/Log.h"
|
2021-03-07 16:42:10 -07:00
|
|
|
|
|
|
|
#include "Core/DolphinAnalytics.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/HW/Memmap.h"
|
2009-03-07 01:35:01 -07:00
|
|
|
|
2014-08-04 20:51:42 -06:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
2021-02-28 14:53:32 -07:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
2019-05-31 00:46:17 -06:00
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
2016-01-31 12:51:55 -07:00
|
|
|
#include "VideoCommon/DataReader.h"
|
2014-08-02 00:42:15 -06:00
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
2016-01-17 14:54:31 -07:00
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
2019-02-14 18:59:50 -07:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/Statistics.h"
|
2014-12-12 17:51:14 -07:00
|
|
|
#include "VideoCommon/VertexLoaderBase.h"
|
2014-07-25 17:10:44 -06:00
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
2010-03-05 19:07:48 -07:00
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
namespace VertexLoaderManager
|
|
|
|
{
|
2015-06-01 11:58:27 -06:00
|
|
|
float position_cache[3][4];
|
2016-05-07 01:35:40 -06:00
|
|
|
|
|
|
|
// The counter added to the address of the array is 1, 2, or 3, but never zero.
|
|
|
|
// So only index 1 - 3 are used.
|
|
|
|
u32 position_matrix_index[4];
|
2015-06-01 11:58:27 -06:00
|
|
|
|
2014-12-12 00:53:48 -07:00
|
|
|
static NativeVertexFormatMap s_native_vertex_map;
|
|
|
|
static NativeVertexFormat* s_current_vtx_fmt;
|
2015-11-01 14:39:31 -07:00
|
|
|
u32 g_current_components;
|
2014-12-12 00:53:48 -07:00
|
|
|
|
2014-12-12 17:51:14 -07:00
|
|
|
typedef std::unordered_map<VertexLoaderUID, std::unique_ptr<VertexLoaderBase>> VertexLoaderMap;
|
2014-08-24 21:53:28 -06:00
|
|
|
static std::mutex s_vertex_loader_map_lock;
|
|
|
|
static VertexLoaderMap s_vertex_loader_map;
|
2009-03-07 01:35:01 -07:00
|
|
|
// TODO - change into array of pointers. Keep a map of all seen so far.
|
|
|
|
|
2021-03-26 16:46:37 -06:00
|
|
|
u8* cached_arraybases[NUM_VERTEX_COMPONENT_ARRAYS];
|
2015-05-29 06:42:45 -06:00
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
MarkAllDirty();
|
2014-08-27 11:38:00 -06:00
|
|
|
for (auto& map_entry : g_main_cp_state.vertex_loaders)
|
|
|
|
map_entry = nullptr;
|
|
|
|
for (auto& map_entry : g_preprocess_cp_state.vertex_loaders)
|
2014-08-24 21:53:28 -06:00
|
|
|
map_entry = nullptr;
|
2019-07-10 21:34:50 -06:00
|
|
|
SETSTAT(g_stats.num_vertex_loaders, 0);
|
2009-03-07 01:35:01 -07:00
|
|
|
}
|
|
|
|
|
2016-01-13 13:14:20 -07:00
|
|
|
void Clear()
|
2009-03-07 01:35:01 -07:00
|
|
|
{
|
2014-08-24 21:53:28 -06:00
|
|
|
std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
|
|
|
|
s_vertex_loader_map.clear();
|
2014-12-12 00:53:48 -07:00
|
|
|
s_native_vertex_map.clear();
|
2009-03-07 01:35:01 -07:00
|
|
|
}
|
|
|
|
|
2015-05-29 06:42:45 -06:00
|
|
|
void UpdateVertexArrayPointers()
|
|
|
|
{
|
2015-05-29 09:58:27 -06:00
|
|
|
// Anything to update?
|
|
|
|
if (!g_main_cp_state.bases_dirty)
|
|
|
|
return;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-05-29 06:42:45 -06:00
|
|
|
// Some games such as Burnout 2 can put invalid addresses into
|
|
|
|
// the array base registers. (see issue 8591)
|
|
|
|
// But the vertex arrays with invalid addresses aren't actually enabled.
|
|
|
|
// Note: Only array bases 0 through 11 are used by the Vertex loaders.
|
|
|
|
// 12 through 15 are used for loading data into xfmem.
|
2021-02-08 16:22:10 -07:00
|
|
|
// We also only update the array base if the vertex description states we are going to use it.
|
|
|
|
if (IsIndexed(g_main_cp_state.vtx_desc.low.Position))
|
|
|
|
cached_arraybases[ARRAY_POSITION] =
|
|
|
|
Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_POSITION]);
|
|
|
|
|
|
|
|
if (IsIndexed(g_main_cp_state.vtx_desc.low.Normal))
|
|
|
|
cached_arraybases[ARRAY_NORMAL] = Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_NORMAL]);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < g_main_cp_state.vtx_desc.low.Color.Size(); i++)
|
|
|
|
{
|
|
|
|
if (IsIndexed(g_main_cp_state.vtx_desc.low.Color[i]))
|
2021-03-26 16:46:37 -06:00
|
|
|
cached_arraybases[ARRAY_COLOR0 + i] =
|
|
|
|
Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_COLOR0 + i]);
|
2021-02-08 16:22:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < g_main_cp_state.vtx_desc.high.TexCoord.Size(); i++)
|
2015-05-29 06:42:45 -06:00
|
|
|
{
|
2021-02-08 16:22:10 -07:00
|
|
|
if (IsIndexed(g_main_cp_state.vtx_desc.high.TexCoord[i]))
|
|
|
|
cached_arraybases[ARRAY_TEXCOORD0 + i] =
|
|
|
|
Memory::GetPointer(g_main_cp_state.array_bases[ARRAY_TEXCOORD0 + i]);
|
2015-05-29 06:42:45 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-05-29 09:58:27 -06:00
|
|
|
g_main_cp_state.bases_dirty = false;
|
2015-05-29 06:42:45 -06:00
|
|
|
}
|
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct entry
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
u64 num_verts;
|
|
|
|
bool operator<(const entry& other) const { return num_verts > other.num_verts; }
|
|
|
|
};
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace
|
2009-03-07 01:35:01 -07:00
|
|
|
|
|
|
|
void MarkAllDirty()
|
|
|
|
{
|
2014-10-21 18:42:55 -06:00
|
|
|
g_main_cp_state.attr_dirty = BitSet32::AllTrue(8);
|
|
|
|
g_preprocess_cp_state.attr_dirty = BitSet32::AllTrue(8);
|
2009-03-07 01:35:01 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 03:43:47 -06:00
|
|
|
NativeVertexFormat* GetOrCreateMatchingFormat(const PortableVertexDeclaration& decl)
|
|
|
|
{
|
|
|
|
auto iter = s_native_vertex_map.find(decl);
|
|
|
|
if (iter == s_native_vertex_map.end())
|
|
|
|
{
|
2019-02-14 18:59:50 -07:00
|
|
|
std::unique_ptr<NativeVertexFormat> fmt = g_renderer->CreateNativeVertexFormat(decl);
|
2017-07-03 03:43:47 -06:00
|
|
|
auto ipair = s_native_vertex_map.emplace(decl, std::move(fmt));
|
|
|
|
iter = ipair.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter->second.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl)
|
|
|
|
{
|
|
|
|
// The padding in the structs can cause the memcmp() in the map to create duplicates.
|
|
|
|
// Avoid this by initializing the padding to zero.
|
|
|
|
PortableVertexDeclaration new_decl;
|
|
|
|
std::memset(&new_decl, 0, sizeof(new_decl));
|
|
|
|
new_decl.stride = decl.stride;
|
|
|
|
|
|
|
|
auto MakeDummyAttribute = [](AttributeFormat& attr, VarType type, int components, bool integer) {
|
|
|
|
attr.type = type;
|
|
|
|
attr.components = components;
|
|
|
|
attr.offset = 0;
|
|
|
|
attr.enable = true;
|
|
|
|
attr.integer = integer;
|
|
|
|
};
|
|
|
|
auto CopyAttribute = [](AttributeFormat& attr, const AttributeFormat& src) {
|
|
|
|
attr.type = src.type;
|
|
|
|
attr.components = src.components;
|
|
|
|
attr.offset = src.offset;
|
|
|
|
attr.enable = src.enable;
|
|
|
|
attr.integer = src.integer;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (decl.position.enable)
|
|
|
|
CopyAttribute(new_decl.position, decl.position);
|
|
|
|
else
|
|
|
|
MakeDummyAttribute(new_decl.position, VAR_FLOAT, 1, false);
|
2019-06-01 05:55:09 -06:00
|
|
|
for (size_t i = 0; i < std::size(new_decl.normals); i++)
|
2017-07-03 03:43:47 -06:00
|
|
|
{
|
|
|
|
if (decl.normals[i].enable)
|
|
|
|
CopyAttribute(new_decl.normals[i], decl.normals[i]);
|
|
|
|
else
|
|
|
|
MakeDummyAttribute(new_decl.normals[i], VAR_FLOAT, 1, false);
|
|
|
|
}
|
2019-06-01 05:55:09 -06:00
|
|
|
for (size_t i = 0; i < std::size(new_decl.colors); i++)
|
2017-07-03 03:43:47 -06:00
|
|
|
{
|
|
|
|
if (decl.colors[i].enable)
|
|
|
|
CopyAttribute(new_decl.colors[i], decl.colors[i]);
|
|
|
|
else
|
|
|
|
MakeDummyAttribute(new_decl.colors[i], VAR_UNSIGNED_BYTE, 4, false);
|
|
|
|
}
|
2019-06-01 05:55:09 -06:00
|
|
|
for (size_t i = 0; i < std::size(new_decl.texcoords); i++)
|
2017-07-03 03:43:47 -06:00
|
|
|
{
|
|
|
|
if (decl.texcoords[i].enable)
|
|
|
|
CopyAttribute(new_decl.texcoords[i], decl.texcoords[i]);
|
|
|
|
else
|
|
|
|
MakeDummyAttribute(new_decl.texcoords[i], VAR_FLOAT, 1, false);
|
|
|
|
}
|
|
|
|
if (decl.posmtx.enable)
|
|
|
|
CopyAttribute(new_decl.posmtx, decl.posmtx);
|
|
|
|
else
|
|
|
|
MakeDummyAttribute(new_decl.posmtx, VAR_UNSIGNED_BYTE, 1, true);
|
|
|
|
|
|
|
|
return GetOrCreateMatchingFormat(new_decl);
|
|
|
|
}
|
|
|
|
|
2015-01-02 13:05:36 -07:00
|
|
|
static VertexLoaderBase* RefreshLoader(int vtx_attr_group, bool preprocess = false)
|
2014-08-15 08:17:06 -06:00
|
|
|
{
|
2015-01-02 13:05:36 -07:00
|
|
|
CPState* state = preprocess ? &g_preprocess_cp_state : &g_main_cp_state;
|
2015-10-09 12:50:36 -06:00
|
|
|
state->last_id = vtx_attr_group;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2014-12-12 17:51:14 -07:00
|
|
|
VertexLoaderBase* loader;
|
2014-10-21 18:42:55 -06:00
|
|
|
if (state->attr_dirty[vtx_attr_group])
|
2014-08-15 08:17:06 -06:00
|
|
|
{
|
2015-01-02 13:05:36 -07:00
|
|
|
// We are not allowed to create a native vertex format on preprocessing as this is on the wrong
|
|
|
|
// thread
|
|
|
|
bool check_for_native_format = !preprocess;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2014-08-27 11:38:00 -06:00
|
|
|
VertexLoaderUID uid(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
|
2014-08-24 21:53:28 -06:00
|
|
|
std::lock_guard<std::mutex> lk(s_vertex_loader_map_lock);
|
|
|
|
VertexLoaderMap::iterator iter = s_vertex_loader_map.find(uid);
|
|
|
|
if (iter != s_vertex_loader_map.end())
|
2014-08-15 08:17:06 -06:00
|
|
|
{
|
2014-08-24 21:53:28 -06:00
|
|
|
loader = iter->second.get();
|
2015-01-02 13:05:36 -07:00
|
|
|
check_for_native_format &= !loader->m_native_vertex_format;
|
2014-08-15 08:17:06 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-22 17:59:32 -07:00
|
|
|
s_vertex_loader_map[uid] =
|
|
|
|
VertexLoaderBase::CreateVertexLoader(state->vtx_desc, state->vtx_attr[vtx_attr_group]);
|
|
|
|
loader = s_vertex_loader_map[uid].get();
|
2019-07-10 21:34:50 -06:00
|
|
|
INCSTAT(g_stats.num_vertex_loaders);
|
2015-01-02 13:05:36 -07:00
|
|
|
}
|
|
|
|
if (check_for_native_format)
|
|
|
|
{
|
2014-12-12 00:53:48 -07:00
|
|
|
// search for a cached native vertex format
|
2014-12-12 16:23:54 -07:00
|
|
|
const PortableVertexDeclaration& format = loader->m_native_vtx_decl;
|
2015-01-08 02:44:16 -07:00
|
|
|
std::unique_ptr<NativeVertexFormat>& native = s_native_vertex_map[format];
|
2014-12-12 00:53:48 -07:00
|
|
|
if (!native)
|
2019-02-14 18:59:50 -07:00
|
|
|
native = g_renderer->CreateNativeVertexFormat(format);
|
2014-12-12 00:53:48 -07:00
|
|
|
loader->m_native_vertex_format = native.get();
|
2014-08-15 08:17:06 -06:00
|
|
|
}
|
2014-08-27 11:38:00 -06:00
|
|
|
state->vertex_loaders[vtx_attr_group] = loader;
|
2014-10-21 18:42:55 -06:00
|
|
|
state->attr_dirty[vtx_attr_group] = false;
|
2014-08-24 21:53:28 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 11:38:00 -06:00
|
|
|
loader = state->vertex_loaders[vtx_attr_group];
|
2014-08-15 08:17:06 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-05-29 00:25:19 -06:00
|
|
|
// Lookup pointers for any vertex arrays.
|
|
|
|
if (!preprocess)
|
2015-05-29 06:42:45 -06:00
|
|
|
UpdateVertexArrayPointers();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2014-08-24 21:53:28 -06:00
|
|
|
return loader;
|
2014-08-15 08:17:06 -06:00
|
|
|
}
|
|
|
|
|
2016-10-07 20:55:47 -06:00
|
|
|
int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool is_preprocess)
|
2009-03-07 01:35:01 -07:00
|
|
|
{
|
|
|
|
if (!count)
|
2014-12-09 00:35:04 -07:00
|
|
|
return 0;
|
2014-08-27 11:38:00 -06:00
|
|
|
|
2015-01-31 01:23:50 -07:00
|
|
|
VertexLoaderBase* loader = RefreshLoader(vtx_attr_group, is_preprocess);
|
2014-07-25 17:10:44 -06:00
|
|
|
|
2021-03-11 13:55:25 -07:00
|
|
|
int size = count * loader->m_vertex_size;
|
2014-12-09 00:35:04 -07:00
|
|
|
if ((int)src.size() < size)
|
|
|
|
return -1;
|
Refactor opcode decoding a bit to kill FifoCommandRunnable.
Separated out from my gpu-determinism branch by request. It's not a big
commit; I just like to write long commit messages.
The main reason to kill it is hopefully a slight performance improvement
from avoiding the double switch (especially in single core mode);
however, this also improves cycle calculation, as described below.
- FifoCommandRunnable is removed; in its stead, Decode returns the
number of cycles (which only matters for "sync" GPU mode), or 0 if there
was not enough data, and is also responsible for unknown opcode alerts.
Decode and DecodeSemiNop are almost identical, so the latter is replaced
with a skipped_frame parameter to Decode. Doesn't mean we can't improve
skipped_frame mode to do less work; if, at such a point, branching on it
has too much overhead (it certainly won't now), it can always be changed
to a template parameter.
- FifoCommandRunnable used a fixed, large cycle count for display lists,
regardless of the contents. Presumably the actual hardware's processing
time is mostly the processing time of whatever commands are in the list,
and with this change InterpretDisplayList can just return the list's
cycle count to be added to the total. (Since the calculation for this
is part of Decode, it didn't seem easy to split this change up.)
To facilitate this, Decode also gains an explicit 'end' parameter in
lieu of FifoCommandRunnable's call to GetVideoBufferEndPtr, which can
point to there or to the end of a display list (or elsewhere in
gpu-determinism, but that's another story). Also, as a small
optimization, InterpretDisplayList now calls OpcodeDecoder_Run rather
than having its own Decode loop, to allow Decode to be inlined (haven't
checked whether this actually happens though).
skipped_frame mode still does not traverse display lists and uses the
old fake value of 45 cycles. degasus has suggested that this hack is
not essential for performance and can be removed, but I want to separate
any potential performance impact of that from this commit.
2014-08-31 23:11:32 -06:00
|
|
|
|
2016-10-07 20:55:47 -06:00
|
|
|
if (is_preprocess)
|
2014-12-09 00:35:04 -07:00
|
|
|
return size;
|
2014-08-04 20:51:42 -06:00
|
|
|
|
2014-07-25 17:10:44 -06:00
|
|
|
// If the native vertex format changed, force a flush.
|
2015-11-01 14:39:31 -07:00
|
|
|
if (loader->m_native_vertex_format != s_current_vtx_fmt ||
|
|
|
|
loader->m_native_components != g_current_components)
|
|
|
|
{
|
2016-08-21 21:02:37 -06:00
|
|
|
g_vertex_manager->Flush();
|
2015-11-01 14:39:31 -07:00
|
|
|
}
|
2014-12-12 00:53:48 -07:00
|
|
|
s_current_vtx_fmt = loader->m_native_vertex_format;
|
2015-11-01 14:39:31 -07:00
|
|
|
g_current_components = loader->m_native_components;
|
2017-07-19 23:25:27 -06:00
|
|
|
VertexShaderManager::SetVertexFormat(loader->m_native_components);
|
2014-07-25 17:10:44 -06:00
|
|
|
|
2015-01-23 18:37:20 -07:00
|
|
|
// if cull mode is CULL_ALL, tell VertexManager to skip triangles and quads.
|
|
|
|
// They still need to go through vertex loading, because we need to calculate a zfreeze refrence
|
|
|
|
// slope.
|
2021-02-10 19:11:31 -07:00
|
|
|
bool cullall = (bpmem.genMode.cullmode == CullMode::All && primitive < 5);
|
2015-01-23 18:37:20 -07:00
|
|
|
|
2016-08-21 21:02:37 -06:00
|
|
|
DataReader dst = g_vertex_manager->PrepareForAdditionalData(
|
2015-01-23 18:37:20 -07:00
|
|
|
primitive, count, loader->m_native_vtx_decl.stride, cullall);
|
2014-08-02 00:42:15 -06:00
|
|
|
|
2015-04-06 03:44:13 -06:00
|
|
|
count = loader->RunVertices(src, dst, count);
|
2014-08-02 00:42:15 -06:00
|
|
|
|
2019-12-05 08:01:33 -07:00
|
|
|
g_vertex_manager->AddIndices(primitive, count);
|
2016-08-21 21:02:37 -06:00
|
|
|
g_vertex_manager->FlushData(count, loader->m_native_vtx_decl.stride);
|
2014-12-09 00:35:04 -07:00
|
|
|
|
2019-07-10 21:34:50 -06:00
|
|
|
ADDSTAT(g_stats.this_frame.num_prims, count);
|
|
|
|
INCSTAT(g_stats.this_frame.num_primitive_joins);
|
2014-12-09 00:35:04 -07:00
|
|
|
return size;
|
2014-01-30 06:48:23 -07:00
|
|
|
}
|
2009-08-07 19:39:56 -06:00
|
|
|
|
2014-07-25 17:10:44 -06:00
|
|
|
NativeVertexFormat* GetCurrentVertexFormat()
|
2014-06-05 09:55:21 -06:00
|
|
|
{
|
2014-07-25 17:10:44 -06:00
|
|
|
return s_current_vtx_fmt;
|
2014-06-05 09:55:21 -06:00
|
|
|
}
|
|
|
|
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace VertexLoaderManager
|
2009-03-07 01:35:01 -07:00
|
|
|
|
2014-08-27 11:38:00 -06:00
|
|
|
void LoadCPReg(u32 sub_cmd, u32 value, bool is_preprocess)
|
2009-03-07 01:35:01 -07:00
|
|
|
{
|
2014-08-27 11:38:00 -06:00
|
|
|
bool update_global_state = !is_preprocess;
|
|
|
|
CPState* state = is_preprocess ? &g_preprocess_cp_state : &g_main_cp_state;
|
2021-02-28 14:53:32 -07:00
|
|
|
switch (sub_cmd & CP_COMMAND_MASK)
|
2009-03-07 01:35:01 -07:00
|
|
|
{
|
2021-03-26 20:37:51 -06:00
|
|
|
case UNKNOWN_00:
|
|
|
|
case UNKNOWN_10:
|
|
|
|
case UNKNOWN_20:
|
|
|
|
if (!(sub_cmd == UNKNOWN_20 && value == 0))
|
|
|
|
{
|
|
|
|
// All titles using libogc or the official SDK issue 0x20 with value=0 on startup
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_CP_PERF_COMMAND);
|
|
|
|
DEBUG_LOG_FMT(VIDEO, "Unknown CP command possibly relating to perf queries used: {:02x}",
|
|
|
|
sub_cmd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case MATINDEX_A:
|
2021-03-07 16:42:10 -07:00
|
|
|
if (sub_cmd != MATINDEX_A)
|
2021-03-26 20:29:55 -06:00
|
|
|
{
|
2021-03-07 16:42:10 -07:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-03-26 20:29:55 -06:00
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP MATINDEX_A: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
|
|
|
MATINDEX_A, sub_cmd);
|
|
|
|
}
|
2021-03-07 16:42:10 -07:00
|
|
|
|
2014-08-27 11:38:00 -06:00
|
|
|
if (update_global_state)
|
|
|
|
VertexShaderManager::SetTexMatrixChangedA(value);
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case MATINDEX_B:
|
2021-03-07 16:42:10 -07:00
|
|
|
if (sub_cmd != MATINDEX_B)
|
2021-03-26 20:29:55 -06:00
|
|
|
{
|
2021-03-07 16:42:10 -07:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-03-26 20:29:55 -06:00
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP MATINDEX_B: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
|
|
|
MATINDEX_B, sub_cmd);
|
|
|
|
}
|
2021-03-07 16:42:10 -07:00
|
|
|
|
2014-08-27 11:38:00 -06:00
|
|
|
if (update_global_state)
|
|
|
|
VertexShaderManager::SetTexMatrixChangedB(value);
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case VCD_LO:
|
2021-03-07 16:42:10 -07:00
|
|
|
if (sub_cmd != VCD_LO) // Stricter than YAGCD
|
2021-03-26 20:29:55 -06:00
|
|
|
{
|
2021-03-07 16:42:10 -07:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-03-26 20:29:55 -06:00
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP VCD_LO: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
|
|
|
VCD_LO, sub_cmd);
|
|
|
|
}
|
2021-03-07 16:42:10 -07:00
|
|
|
|
2021-02-08 16:22:10 -07:00
|
|
|
state->vtx_desc.low.Hex = value;
|
2021-02-28 14:53:32 -07:00
|
|
|
state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG);
|
2015-05-29 09:58:27 -06:00
|
|
|
state->bases_dirty = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case VCD_HI:
|
2021-03-07 16:42:10 -07:00
|
|
|
if (sub_cmd != VCD_HI) // Stricter than YAGCD
|
2021-03-26 20:29:55 -06:00
|
|
|
{
|
2021-03-07 16:42:10 -07:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-03-26 20:29:55 -06:00
|
|
|
WARN_LOG_FMT(VIDEO,
|
|
|
|
"CP VCD_HI: an exact value of {:02x} was expected "
|
|
|
|
"but instead a value of {:02x} was seen",
|
|
|
|
VCD_HI, sub_cmd);
|
|
|
|
}
|
2021-03-07 16:42:10 -07:00
|
|
|
|
2021-02-08 16:22:10 -07:00
|
|
|
state->vtx_desc.high.Hex = value;
|
2021-02-28 14:53:32 -07:00
|
|
|
state->attr_dirty = BitSet32::AllTrue(CP_NUM_VAT_REG);
|
2015-05-29 09:58:27 -06:00
|
|
|
state->bases_dirty = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case CP_VAT_REG_A:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_A) >= CP_NUM_VAT_REG)
|
2021-03-07 16:42:10 -07:00
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-02-28 14:53:32 -07:00
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_A: Invalid VAT {}", sub_cmd - CP_VAT_REG_A);
|
2021-03-07 16:42:10 -07:00
|
|
|
}
|
2021-02-28 14:53:32 -07:00
|
|
|
state->vtx_attr[sub_cmd & CP_VAT_MASK].g0.Hex = value;
|
|
|
|
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case CP_VAT_REG_B:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_B) >= CP_NUM_VAT_REG)
|
2021-03-07 16:42:10 -07:00
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-02-28 14:53:32 -07:00
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_B: Invalid VAT {}", sub_cmd - CP_VAT_REG_B);
|
2021-03-07 16:42:10 -07:00
|
|
|
}
|
2021-02-28 14:53:32 -07:00
|
|
|
state->vtx_attr[sub_cmd & CP_VAT_MASK].g1.Hex = value;
|
|
|
|
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case CP_VAT_REG_C:
|
|
|
|
if ((sub_cmd - CP_VAT_REG_C) >= CP_NUM_VAT_REG)
|
2021-03-07 16:42:10 -07:00
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_MAYBE_INVALID_CP_COMMAND);
|
2021-02-28 14:53:32 -07:00
|
|
|
WARN_LOG_FMT(VIDEO, "CP_VAT_REG_C: Invalid VAT {}", sub_cmd - CP_VAT_REG_C);
|
2021-03-07 16:42:10 -07:00
|
|
|
}
|
2021-02-28 14:53:32 -07:00
|
|
|
state->vtx_attr[sub_cmd & CP_VAT_MASK].g2.Hex = value;
|
|
|
|
state->attr_dirty[sub_cmd & CP_VAT_MASK] = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2009-03-07 01:35:01 -07:00
|
|
|
// Pointers to vertex arrays in GC RAM
|
2021-02-28 14:53:32 -07:00
|
|
|
case ARRAY_BASE:
|
|
|
|
state->array_bases[sub_cmd & CP_ARRAY_MASK] =
|
|
|
|
value & CommandProcessor::GetPhysicalAddressMask();
|
2015-05-29 09:58:27 -06:00
|
|
|
state->bases_dirty = true;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
case ARRAY_STRIDE:
|
|
|
|
state->array_strides[sub_cmd & CP_ARRAY_MASK] = value & 0xFF;
|
2009-03-07 01:35:01 -07:00
|
|
|
break;
|
2021-02-28 14:53:32 -07:00
|
|
|
|
|
|
|
default:
|
2021-03-07 16:42:10 -07:00
|
|
|
DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_UNKNOWN_CP_COMMAND);
|
2021-02-28 14:53:32 -07:00
|
|
|
WARN_LOG_FMT(VIDEO, "Unknown CP register {:02x} set to {:08x}", sub_cmd, value);
|
2009-03-07 01:35:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-26 20:55:08 -06:00
|
|
|
void FillCPMemoryArray(u32* memory)
|
|
|
|
{
|
2021-02-28 14:53:32 -07:00
|
|
|
memory[MATINDEX_A] = g_main_cp_state.matrix_index_a.Hex;
|
|
|
|
memory[MATINDEX_B] = g_main_cp_state.matrix_index_b.Hex;
|
2021-02-08 16:22:10 -07:00
|
|
|
memory[VCD_LO] = g_main_cp_state.vtx_desc.low.Hex;
|
|
|
|
memory[VCD_HI] = g_main_cp_state.vtx_desc.high.Hex;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
for (int i = 0; i < CP_NUM_VAT_REG; ++i)
|
2011-03-26 20:55:08 -06:00
|
|
|
{
|
2021-02-28 14:53:32 -07:00
|
|
|
memory[CP_VAT_REG_A + i] = g_main_cp_state.vtx_attr[i].g0.Hex;
|
|
|
|
memory[CP_VAT_REG_B + i] = g_main_cp_state.vtx_attr[i].g1.Hex;
|
|
|
|
memory[CP_VAT_REG_C + i] = g_main_cp_state.vtx_attr[i].g2.Hex;
|
2011-03-26 20:55:08 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-28 14:53:32 -07:00
|
|
|
for (int i = 0; i < CP_NUM_ARRAYS; ++i)
|
2011-03-26 20:55:08 -06:00
|
|
|
{
|
2021-02-28 14:53:32 -07:00
|
|
|
memory[ARRAY_BASE + i] = g_main_cp_state.array_bases[i];
|
|
|
|
memory[ARRAY_STRIDE + i] = g_main_cp_state.array_strides[i];
|
2011-03-26 20:55:08 -06:00
|
|
|
}
|
|
|
|
}
|