2014-12-13 00:51:14 +00:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2014-12-13 00:51:14 +00:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2017-03-27 02:12:20 +00:00
|
|
|
#include "VideoCommon/VertexLoaderBase.h"
|
|
|
|
|
|
|
|
#include <array>
|
2015-01-11 15:20:44 +00:00
|
|
|
#include <cinttypes>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include <cstring>
|
2015-12-23 00:59:32 +00:00
|
|
|
#include <memory>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include <string>
|
2014-12-18 22:27:10 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-11-22 22:10:41 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-10-16 18:18:27 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2014-12-13 00:51:14 +00:00
|
|
|
|
2016-01-31 19:51:55 +00:00
|
|
|
#include "VideoCommon/DataReader.h"
|
2014-12-13 00:51:14 +00:00
|
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
|
2015-01-15 00:46:23 +00:00
|
|
|
#ifdef _M_X86_64
|
|
|
|
#include "VideoCommon/VertexLoaderX64.h"
|
2015-02-13 00:52:07 +00:00
|
|
|
#elif defined(_M_ARM_64)
|
|
|
|
#include "VideoCommon/VertexLoaderARM64.h"
|
2015-01-15 00:46:23 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-18 22:27:10 +00:00
|
|
|
// a hacky implementation to compare two vertex loaders
|
|
|
|
class VertexLoaderTester : public VertexLoaderBase
|
|
|
|
{
|
|
|
|
public:
|
2015-12-23 00:59:32 +00:00
|
|
|
VertexLoaderTester(std::unique_ptr<VertexLoaderBase> a_, std::unique_ptr<VertexLoaderBase> b_,
|
|
|
|
const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
|
|
|
: VertexLoaderBase(vtx_desc, vtx_attr), a(std::move(a_)), b(std::move(b_))
|
2014-12-18 22:27:10 +00:00
|
|
|
{
|
|
|
|
m_initialized = a && b && a->IsInitialized() && b->IsInitialized();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-11 15:20:44 +00:00
|
|
|
if (m_initialized)
|
|
|
|
{
|
2015-07-07 22:12:14 +00:00
|
|
|
m_initialized = a->m_VertexSize == b->m_VertexSize &&
|
|
|
|
a->m_native_components == b->m_native_components &&
|
|
|
|
a->m_native_vtx_decl.stride == b->m_native_vtx_decl.stride;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-07-07 22:12:14 +00:00
|
|
|
if (m_initialized)
|
2015-01-11 15:20:44 +00:00
|
|
|
{
|
|
|
|
m_VertexSize = a->m_VertexSize;
|
|
|
|
m_native_components = a->m_native_components;
|
|
|
|
memcpy(&m_native_vtx_decl, &a->m_native_vtx_decl, sizeof(PortableVertexDeclaration));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-14 03:33:26 +00:00
|
|
|
ERROR_LOG_FMT(VIDEO, "Can't compare vertex loaders that expect different vertex formats!");
|
|
|
|
ERROR_LOG_FMT(VIDEO, "a: m_VertexSize {}, m_native_components {:#010x}, stride {}",
|
|
|
|
a->m_VertexSize, a->m_native_components, a->m_native_vtx_decl.stride);
|
|
|
|
ERROR_LOG_FMT(VIDEO, "b: m_VertexSize {}, m_native_components {:#010x}, stride {}",
|
|
|
|
b->m_VertexSize, b->m_native_components, b->m_native_vtx_decl.stride);
|
2015-01-11 15:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-18 22:27:10 +00:00
|
|
|
}
|
2015-01-11 15:20:44 +00:00
|
|
|
~VertexLoaderTester() override {}
|
2015-04-06 09:44:13 +00:00
|
|
|
int RunVertices(DataReader src, DataReader dst, int count) override
|
2014-12-18 22:27:10 +00:00
|
|
|
{
|
2015-01-11 15:20:44 +00:00
|
|
|
buffer_a.resize(count * a->m_native_vtx_decl.stride + 4);
|
|
|
|
buffer_b.resize(count * b->m_native_vtx_decl.stride + 4);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-04-06 09:44:13 +00:00
|
|
|
int count_a =
|
|
|
|
a->RunVertices(src, DataReader(buffer_a.data(), buffer_a.data() + buffer_a.size()), count);
|
|
|
|
int count_b =
|
|
|
|
b->RunVertices(src, DataReader(buffer_b.data(), buffer_b.data() + buffer_b.size()), count);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2014-12-18 22:27:10 +00:00
|
|
|
if (count_a != count_b)
|
2020-11-14 03:33:26 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(
|
|
|
|
VIDEO,
|
|
|
|
"The two vertex loaders have loaded a different amount of vertices (a: {}, b: {}).",
|
|
|
|
count_a, count_b);
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-11 15:20:44 +00:00
|
|
|
if (memcmp(buffer_a.data(), buffer_b.data(),
|
|
|
|
std::min(count_a, count_b) * m_native_vtx_decl.stride))
|
2020-11-14 03:33:26 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(VIDEO,
|
|
|
|
"The two vertex loaders have loaded different data "
|
2021-02-08 23:22:10 +00:00
|
|
|
"(guru meditation {:#010x}, {:#010x}, {:#010x}, {:#010x}, {:#010x}).",
|
2021-03-11 06:15:43 +00:00
|
|
|
m_VtxDesc.low.Hex, m_VtxDesc.high.Hex, m_VtxAttr.g0.Hex, m_VtxAttr.g1.Hex,
|
|
|
|
m_VtxAttr.g2.Hex);
|
2020-11-14 03:33:26 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-01-11 15:20:44 +00:00
|
|
|
memcpy(dst.GetPointer(), buffer_a.data(), count_a * m_native_vtx_decl.stride);
|
|
|
|
m_numLoadedVertices += count;
|
2014-12-18 22:27:10 +00:00
|
|
|
return count_a;
|
|
|
|
}
|
|
|
|
bool IsInitialized() override { return m_initialized; }
|
2018-04-12 12:18:04 +00:00
|
|
|
|
2014-12-18 22:27:10 +00:00
|
|
|
private:
|
|
|
|
bool m_initialized;
|
2015-12-23 00:59:32 +00:00
|
|
|
|
|
|
|
std::unique_ptr<VertexLoaderBase> a;
|
|
|
|
std::unique_ptr<VertexLoaderBase> b;
|
|
|
|
|
|
|
|
std::vector<u8> buffer_a;
|
|
|
|
std::vector<u8> buffer_b;
|
2014-12-18 22:27:10 +00:00
|
|
|
};
|
|
|
|
|
2015-12-23 00:59:32 +00:00
|
|
|
std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc,
|
|
|
|
const VAT& vtx_attr)
|
2014-12-13 00:51:14 +00:00
|
|
|
{
|
2015-12-23 00:59:32 +00:00
|
|
|
std::unique_ptr<VertexLoaderBase> loader;
|
2014-12-13 00:51:14 +00:00
|
|
|
|
2015-01-15 00:46:23 +00:00
|
|
|
//#define COMPARE_VERTEXLOADERS
|
|
|
|
|
|
|
|
#if defined(COMPARE_VERTEXLOADERS) && defined(_M_X86_64)
|
2014-12-18 22:27:10 +00:00
|
|
|
// first try: Any new VertexLoader vs the old one
|
2015-12-23 00:59:32 +00:00
|
|
|
loader = std::make_unique<VertexLoaderTester>(
|
|
|
|
std::make_unique<VertexLoader>(vtx_desc, vtx_attr), // the software one
|
|
|
|
std::make_unique<VertexLoaderX64>(vtx_desc, vtx_attr), // the new one to compare
|
2014-12-18 22:27:10 +00:00
|
|
|
vtx_desc, vtx_attr);
|
|
|
|
if (loader->IsInitialized())
|
|
|
|
return loader;
|
2015-01-15 00:46:23 +00:00
|
|
|
#elif defined(_M_X86_64)
|
2015-12-23 00:59:32 +00:00
|
|
|
loader = std::make_unique<VertexLoaderX64>(vtx_desc, vtx_attr);
|
2015-01-15 00:46:23 +00:00
|
|
|
if (loader->IsInitialized())
|
|
|
|
return loader;
|
2015-02-13 00:52:07 +00:00
|
|
|
#elif defined(_M_ARM_64)
|
2015-12-23 00:59:32 +00:00
|
|
|
loader = std::make_unique<VertexLoaderARM64>(vtx_desc, vtx_attr);
|
2015-02-13 00:52:07 +00:00
|
|
|
if (loader->IsInitialized())
|
|
|
|
return loader;
|
2014-12-18 22:27:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-13 00:51:14 +00:00
|
|
|
// last try: The old VertexLoader
|
2015-12-23 00:59:32 +00:00
|
|
|
loader = std::make_unique<VertexLoader>(vtx_desc, vtx_attr);
|
2014-12-13 00:51:14 +00:00
|
|
|
if (loader->IsInitialized())
|
|
|
|
return loader;
|
|
|
|
|
2020-11-14 03:33:26 +00:00
|
|
|
PanicAlertFmt("No Vertex Loader found.");
|
2014-12-13 00:51:14 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|