Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11298 from Pokechu22/vertexloader-no-DataReader
VertexLoader: Eliminate use of DataReader
  • Loading branch information
lioncash committed Nov 23, 2022
2 parents 3145825 + e130947 commit cb23215
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 70 deletions.
4 changes: 1 addition & 3 deletions Source/Core/VideoCommon/OpcodeDecoding.cpp
Expand Up @@ -127,10 +127,8 @@ class RunCallback final : public Callback
// load vertices
const u32 size = vertex_size * num_vertices;

// HACK
DataReader src{const_cast<u8*>(vertex_data), const_cast<u8*>(vertex_data) + size};
const u32 bytes =
VertexLoaderManager::RunVertices<is_preprocess>(vat, primitive, num_vertices, src);
VertexLoaderManager::RunVertices<is_preprocess>(vat, primitive, num_vertices, vertex_data);

ASSERT(bytes == size);

Expand Down
11 changes: 5 additions & 6 deletions Source/Core/VideoCommon/VertexLoader.cpp
Expand Up @@ -6,7 +6,6 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"

#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexLoaderUtils.h"
#include "VideoCommon/VertexLoader_Color.h"
Expand All @@ -16,7 +15,7 @@
#include "VideoCommon/VideoCommon.h"

// This pointer is used as the source/dst for all fixed function loader calls
u8* g_video_buffer_read_ptr;
const u8* g_video_buffer_read_ptr;
u8* g_vertex_manager_write_ptr;

static void PosMtx_ReadDirect_UByte(VertexLoader* loader)
Expand Down Expand Up @@ -222,7 +221,7 @@ void VertexLoader::CompileVertexTranslator()
WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right!
break;
}
else if (m_VtxDesc.low.TexMatIdx[i])
else if (m_VtxDesc.low.TexMatIdx[j])
{
has_more = true;
}
Expand All @@ -249,10 +248,10 @@ void VertexLoader::WriteCall(TPipelineFunction func)
m_PipelineStages[m_numPipelineStages++] = func;
}

int VertexLoader::RunVertices(DataReader src, DataReader dst, int count)
int VertexLoader::RunVertices(const u8* src, u8* dst, int count)
{
g_vertex_manager_write_ptr = dst.GetPointer();
g_video_buffer_read_ptr = src.GetPointer();
g_vertex_manager_write_ptr = dst;
g_video_buffer_read_ptr = src;

m_numLoadedVertices += count;
m_skippedVertices = 0;
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/VideoCommon/VertexLoader.h
Expand Up @@ -11,7 +11,6 @@
#include "Common/CommonTypes.h"
#include "VideoCommon/VertexLoaderBase.h"

class DataReader;
class VertexLoader;
typedef void (*TPipelineFunction)(VertexLoader* loader);

Expand All @@ -20,7 +19,7 @@ class VertexLoader : public VertexLoaderBase
public:
VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr);

int RunVertices(DataReader src, DataReader dst, int count) override;
int RunVertices(const u8* src, u8* dst, int count) override;
// They are used for the communication with the loader functions
float m_posScale;
float m_tcScale[8];
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/VideoCommon/VertexLoaderARM64.cpp
Expand Up @@ -7,7 +7,6 @@

#include "Common/CommonTypes.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoaderManager.h"

using namespace Arm64Gen;
Expand Down Expand Up @@ -517,9 +516,8 @@ void VertexLoaderARM64::GenerateVertexLoader()
m_native_vtx_decl.stride = m_dst_ofs;
}

int VertexLoaderARM64::RunVertices(DataReader src, DataReader dst, int count)
int VertexLoaderARM64::RunVertices(const u8* src, u8* dst, int count)
{
m_numLoadedVertices += count;
return ((int (*)(u8 * src, u8 * dst, int count)) region)(src.GetPointer(), dst.GetPointer(),
count - 1);
return ((int (*)(const u8* src, u8* dst, int count))region)(src, dst, count - 1);
}
3 changes: 1 addition & 2 deletions Source/Core/VideoCommon/VertexLoaderARM64.h
Expand Up @@ -9,7 +9,6 @@
#include "Common/CommonTypes.h"
#include "VideoCommon/VertexLoaderBase.h"

class DataReader;
enum class VertexComponentFormat;
enum class ComponentFormat;
enum class ColorFormat;
Expand All @@ -21,7 +20,7 @@ class VertexLoaderARM64 : public VertexLoaderBase, public Arm64Gen::ARM64CodeBlo
VertexLoaderARM64(const TVtxDesc& vtx_desc, const VAT& vtx_att);

protected:
int RunVertices(DataReader src, DataReader dst, int count) override;
int RunVertices(const u8* src, u8* dst, int count) override;

private:
u32 m_src_ofs = 0;
Expand Down
13 changes: 5 additions & 8 deletions Source/Core/VideoCommon/VertexLoaderBase.cpp
Expand Up @@ -17,7 +17,6 @@
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"

#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h"
#include "VideoCommon/VertexLoader_Color.h"
#include "VideoCommon/VertexLoader_Normal.h"
Expand Down Expand Up @@ -57,15 +56,13 @@ class VertexLoaderTester : public VertexLoaderBase
b->m_vertex_size, b->m_native_components, b->m_native_vtx_decl.stride);
}
}
int RunVertices(DataReader src, DataReader dst, int count) override
int RunVertices(const u8* src, u8* dst, int count) override
{
buffer_a.resize(count * a->m_native_vtx_decl.stride + 4);
buffer_b.resize(count * b->m_native_vtx_decl.stride + 4);

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);
int count_a = a->RunVertices(src, buffer_a.data(), count);
int count_b = b->RunVertices(src, buffer_b.data(), count);

if (count_a != count_b)
{
Expand All @@ -84,7 +81,7 @@ class VertexLoaderTester : public VertexLoaderBase
m_VtxDesc, m_VtxAttr);
}

memcpy(dst.GetPointer(), buffer_a.data(), count_a * m_native_vtx_decl.stride);
memcpy(dst, buffer_a.data(), count_a * m_native_vtx_decl.stride);
m_numLoadedVertices += count;
return count_a;
}
Expand Down Expand Up @@ -162,7 +159,7 @@ std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVt
{
std::unique_ptr<VertexLoaderBase> loader = nullptr;

//#define COMPARE_VERTEXLOADERS
// #define COMPARE_VERTEXLOADERS

#if defined(_M_X86_64)
loader = std::make_unique<VertexLoaderX64>(vtx_desc, vtx_attr);
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/VideoCommon/VertexLoaderBase.h
Expand Up @@ -12,8 +12,6 @@
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/NativeVertexFormat.h"

class DataReader;

class VertexLoaderUID
{
std::array<u32, 5> vid{};
Expand Down Expand Up @@ -65,7 +63,7 @@ class VertexLoaderBase
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
const VAT& vtx_attr);
virtual ~VertexLoaderBase() {}
virtual int RunVertices(DataReader src, DataReader dst, int count) = 0;
virtual int RunVertices(const u8* src, u8* dst, int count) = 0;

// per loader public state
PortableVertexDeclaration m_native_vtx_decl{};
Expand Down
10 changes: 4 additions & 6 deletions Source/Core/VideoCommon/VertexLoaderManager.cpp
Expand Up @@ -332,7 +332,7 @@ static void CheckCPConfiguration(int vtx_attr_group)
}

template <bool IsPreprocess>
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, DataReader src)
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, const u8* src)
{
if (count == 0) [[unlikely]]
return 0;
Expand All @@ -341,8 +341,6 @@ int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int coun
VertexLoaderBase* loader = RefreshLoader<IsPreprocess>(vtx_attr_group);

int size = count * loader->m_vertex_size;
if ((int)src.size() < size) [[unlikely]]
return -1;

if constexpr (!IsPreprocess)
{
Expand Down Expand Up @@ -371,7 +369,7 @@ int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int coun
DataReader dst = g_vertex_manager->PrepareForAdditionalData(
primitive, count, loader->m_native_vtx_decl.stride, cullall);

count = loader->RunVertices(src, dst, count);
count = loader->RunVertices(src, dst.GetPointer(), count);

g_vertex_manager->AddIndices(primitive, count);
g_vertex_manager->FlushData(count, loader->m_native_vtx_decl.stride);
Expand All @@ -383,9 +381,9 @@ int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int coun
}

template int RunVertices<false>(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count,
DataReader src);
const u8* src);
template int RunVertices<true>(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count,
DataReader src);
const u8* src);

NativeVertexFormat* GetCurrentVertexFormat()
{
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/VideoCommon/VertexLoaderManager.h
Expand Up @@ -12,7 +12,6 @@
#include "Common/EnumMap.h"
#include "VideoCommon/CPMemory.h"

class DataReader;
class NativeVertexFormat;
struct PortableVertexDeclaration;

Expand Down Expand Up @@ -43,7 +42,7 @@ NativeVertexFormat* GetUberVertexFormat(const PortableVertexDeclaration& decl);

// Returns -1 if buf_size is insufficient, else the amount of bytes consumed
template <bool IsPreprocess = false>
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, DataReader src);
int RunVertices(int vtx_attr_group, OpcodeDecoder::Primitive primitive, int count, const u8* src);

namespace detail
{
Expand Down
9 changes: 5 additions & 4 deletions Source/Core/VideoCommon/VertexLoaderUtils.h
Expand Up @@ -7,8 +7,9 @@

#include "Common/CommonTypes.h"
#include "Common/Inline.h"
#include "Common/Swap.h"

extern u8* g_video_buffer_read_ptr;
extern const u8* g_video_buffer_read_ptr;
extern u8* g_vertex_manager_write_ptr;

DOLPHIN_FORCE_INLINE void DataSkip(u32 skip)
Expand All @@ -24,15 +25,15 @@ DOLPHIN_FORCE_INLINE void DataSkip()
}

template <typename T>
DOLPHIN_FORCE_INLINE T DataPeek(int _uOffset, u8* bufp = g_video_buffer_read_ptr)
DOLPHIN_FORCE_INLINE T DataPeek(int _uOffset, const u8* bufp = g_video_buffer_read_ptr)
{
T result;
std::memcpy(&result, &bufp[_uOffset], sizeof(T));
return Common::FromBigEndian(result);
}

template <typename T>
DOLPHIN_FORCE_INLINE T DataRead(u8** bufp = &g_video_buffer_read_ptr)
DOLPHIN_FORCE_INLINE T DataRead(const u8** bufp = &g_video_buffer_read_ptr)
{
auto const result = DataPeek<T>(0, *bufp);
*bufp += sizeof(T);
Expand All @@ -47,7 +48,7 @@ DOLPHIN_FORCE_INLINE u32 DataReadU32Unswapped()
return result;
}

DOLPHIN_FORCE_INLINE u8* DataGetPosition()
DOLPHIN_FORCE_INLINE const u8* DataGetPosition()
{
return g_video_buffer_read_ptr;
}
Expand Down
7 changes: 3 additions & 4 deletions Source/Core/VideoCommon/VertexLoaderX64.cpp
Expand Up @@ -16,7 +16,6 @@
#include "Common/x64ABI.h"
#include "Common/x64Emitter.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoaderManager.h"

using namespace Gen;
Expand Down Expand Up @@ -582,9 +581,9 @@ void VertexLoaderX64::GenerateVertexLoader()
m_native_vtx_decl.stride = m_dst_ofs;
}

int VertexLoaderX64::RunVertices(DataReader src, DataReader dst, int count)
int VertexLoaderX64::RunVertices(const u8* src, u8* dst, int count)
{
m_numLoadedVertices += count;
return ((int (*)(u8*, u8*, int, const void*))region)(src.GetPointer(), dst.GetPointer(), count,
memory_base_ptr);
return ((int (*)(const u8* src, u8* dst, int count, const void* base))region)(src, dst, count,
memory_base_ptr);
}
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/VertexLoaderX64.h
Expand Up @@ -18,7 +18,7 @@ class VertexLoaderX64 : public VertexLoaderBase, public Gen::X64CodeBlock
VertexLoaderX64(const TVtxDesc& vtx_desc, const VAT& vtx_att);

protected:
int RunVertices(DataReader src, DataReader dst, int count) override;
int RunVertices(const u8* src, u8* dst, int count) override;

private:
u32 m_src_ofs = 0;
Expand Down
5 changes: 1 addition & 4 deletions Source/Core/VideoCommon/VertexLoader_Normal.cpp
Expand Up @@ -9,7 +9,6 @@
#include "Common/CommonTypes.h"
#include "Common/EnumMap.h"

#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexLoaderUtils.h"
Expand Down Expand Up @@ -43,7 +42,6 @@ template <typename T, u32 N>
void ReadIndirect(VertexLoader* loader, const T* data)
{
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
DataReader dst(g_vertex_manager_write_ptr, nullptr);

for (u32 i = 0; i < N; ++i)
{
Expand All @@ -55,10 +53,9 @@ void ReadIndirect(VertexLoader* loader, const T* data)
else if (i >= 6 && i < 9)
VertexLoaderManager::binormal_cache[i - 6] = value;
}
dst.Write(value);
DataWrite(value);
}

g_vertex_manager_write_ptr = dst.GetPointer();
LOG_NORM();
}

Expand Down
13 changes: 3 additions & 10 deletions Source/Core/VideoCommon/VertexLoader_Position.cpp
Expand Up @@ -10,7 +10,6 @@
#include "Common/EnumMap.h"
#include "Common/Swap.h"

#include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexLoaderUtils.h"
Expand All @@ -35,19 +34,15 @@ void Pos_ReadDirect(VertexLoader* loader)
{
static_assert(N <= 3, "N > 3 is not sane!");
const auto scale = loader->m_posScale;
DataReader dst(g_vertex_manager_write_ptr, nullptr);
DataReader src(g_video_buffer_read_ptr, nullptr);

for (int i = 0; i < N; ++i)
{
const float value = PosScale(src.Read<T>(), scale);
const float value = PosScale(DataRead<T>(), scale);
if (loader->m_remaining < 3)
VertexLoaderManager::position_cache[loader->m_remaining][i] = value;
dst.Write(value);
DataWrite(value);
}

g_vertex_manager_write_ptr = dst.GetPointer();
g_video_buffer_read_ptr = src.GetPointer();
LOG_VTX();
}

Expand All @@ -63,17 +58,15 @@ void Pos_ReadIndex(VertexLoader* loader)
reinterpret_cast<const T*>(VertexLoaderManager::cached_arraybases[CPArray::Position] +
(index * g_main_cp_state.array_strides[CPArray::Position]));
const auto scale = loader->m_posScale;
DataReader dst(g_vertex_manager_write_ptr, nullptr);

for (int i = 0; i < N; ++i)
{
const float value = PosScale(Common::FromBigEndian(data[i]), scale);
if (loader->m_remaining < 3)
VertexLoaderManager::position_cache[loader->m_remaining][i] = value;
dst.Write(value);
DataWrite(value);
}

g_vertex_manager_write_ptr = dst.GetPointer();
LOG_VTX();
}

Expand Down

0 comments on commit cb23215

Please sign in to comment.