From be9a03b35fbf53e2e7a68d869607d8913dd2a699 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 May 2019 09:29:20 -0400 Subject: VertexLoader_Position: Place helper functions in anonymous namespace --- Source/Core/VideoCommon/VertexLoader_Position.cpp | 123 ++++++---------------- 1 file changed, 33 insertions(+), 90 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Position.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index a21061ac55..1cb38a88c4 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -16,14 +16,16 @@ #include "VideoCommon/VertexLoaderUtils.h" #include "VideoCommon/VideoCommon.h" +namespace +{ template -float PosScale(T val, float scale) +constexpr float PosScale(T val, float scale) { return val * scale; } template <> -float PosScale(float val, float scale) +constexpr float PosScale(float val, [[maybe_unused]] float scale) { return val; } @@ -32,13 +34,13 @@ template void Pos_ReadDirect(VertexLoader* loader) { static_assert(N <= 3, "N > 3 is not sane!"); - auto const scale = loader->m_posScale; + 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) { - float value = PosScale(src.Read(), scale); + const float value = PosScale(src.Read(), scale); if (loader->m_counter < 3) VertexLoaderManager::position_cache[loader->m_counter][i] = value; dst.Write(value); @@ -55,17 +57,17 @@ void Pos_ReadIndex(VertexLoader* loader) static_assert(std::is_unsigned::value, "Only unsigned I is sane!"); static_assert(N <= 3, "N > 3 is not sane!"); - auto const index = DataRead(); + const auto index = DataRead(); loader->m_vertexSkip = index == std::numeric_limits::max(); - auto const data = + const auto data = reinterpret_cast(VertexLoaderManager::cached_arraybases[ARRAY_POSITION] + (index * g_main_cp_state.array_strides[ARRAY_POSITION])); - auto const scale = loader->m_posScale; + const auto scale = loader->m_posScale; DataReader dst(g_vertex_manager_write_ptr, nullptr); for (int i = 0; i < N; ++i) { - float value = PosScale(Common::FromBigEndian(data[i]), scale); + const float value = PosScale(Common::FromBigEndian(data[i]), scale); if (loader->m_counter < 3) VertexLoaderManager::position_cache[loader->m_counter][i] = value; dst.Write(value); @@ -75,7 +77,7 @@ void Pos_ReadIndex(VertexLoader* loader) LOG_VTX(); } -static TPipelineFunction tableReadPosition[4][8][2] = { +TPipelineFunction tableReadPosition[4][8][2] = { { { nullptr, @@ -166,96 +168,37 @@ static TPipelineFunction tableReadPosition[4][8][2] = { }, }; -static int tableReadPositionVertexSize[4][8][2] = { +int tableReadPositionVertexSize[4][8][2] = { { - { - 0, - 0, - }, - { - 0, - 0, - }, - { - 0, - 0, - }, - { - 0, - 0, - }, - { - 0, - 0, - }, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, + {0, 0}, }, { - { - 2, - 3, - }, - { - 2, - 3, - }, - { - 4, - 6, - }, - { - 4, - 6, - }, - { - 8, - 12, - }, + {2, 3}, + {2, 3}, + {4, 6}, + {4, 6}, + {8, 12}, }, { - { - 1, - 1, - }, - { - 1, - 1, - }, - { - 1, - 1, - }, - { - 1, - 1, - }, - { - 1, - 1, - }, + {1, 1}, + {1, 1}, + {1, 1}, + {1, 1}, + {1, 1}, }, { - { - 2, - 2, - }, - { - 2, - 2, - }, - { - 2, - 2, - }, - { - 2, - 2, - }, - { - 2, - 2, - }, + {2, 2}, + {2, 2}, + {2, 2}, + {2, 2}, + {2, 2}, }, }; +} // Anonymous namespace unsigned int VertexLoader_Position::GetSize(u64 _type, unsigned int _format, unsigned int _elements) { -- cgit v1.2.3 From 14e544eef8737634f952c85da4ebac22491f813f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 May 2019 09:30:50 -0400 Subject: VertexLoader_Position: Make lookup tables immutable Allows the compiler to place these arrays within the read-only segment. --- Source/Core/VideoCommon/VertexLoader_Position.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Position.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 1cb38a88c4..d4a816a36c 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -77,7 +77,7 @@ void Pos_ReadIndex(VertexLoader* loader) LOG_VTX(); } -TPipelineFunction tableReadPosition[4][8][2] = { +constexpr TPipelineFunction s_table_read_position[4][8][2] = { { { nullptr, @@ -168,7 +168,7 @@ TPipelineFunction tableReadPosition[4][8][2] = { }, }; -int tableReadPositionVertexSize[4][8][2] = { +constexpr int s_table_read_position_vertex_size[4][8][2] = { { {0, 0}, {0, 0}, @@ -202,11 +202,11 @@ int tableReadPositionVertexSize[4][8][2] = { unsigned int VertexLoader_Position::GetSize(u64 _type, unsigned int _format, unsigned int _elements) { - return tableReadPositionVertexSize[_type][_format][_elements]; + return s_table_read_position_vertex_size[_type][_format][_elements]; } TPipelineFunction VertexLoader_Position::GetFunction(u64 _type, unsigned int _format, unsigned int _elements) { - return tableReadPosition[_type][_format][_elements]; + return s_table_read_position[_type][_format][_elements]; } -- cgit v1.2.3 From 6f656b72199ba95398d5a0b08cab7f7a5db9e876 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 30 May 2019 09:33:43 -0400 Subject: VertexLoader_Position: Tidy up public function definitions We can use u32 instead of unsigned int to shorten up these definitions and make them much nicer to read. While we're at it, change the size array to house u32 elements to match the return value of the function. --- Source/Core/VideoCommon/VertexLoader_Position.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Position.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index d4a816a36c..9808c76e65 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -168,7 +168,7 @@ constexpr TPipelineFunction s_table_read_position[4][8][2] = { }, }; -constexpr int s_table_read_position_vertex_size[4][8][2] = { +constexpr u32 s_table_read_position_vertex_size[4][8][2] = { { {0, 0}, {0, 0}, @@ -200,13 +200,12 @@ constexpr int s_table_read_position_vertex_size[4][8][2] = { }; } // Anonymous namespace -unsigned int VertexLoader_Position::GetSize(u64 _type, unsigned int _format, unsigned int _elements) +u32 VertexLoader_Position::GetSize(u64 type, u32 format, u32 elements) { - return s_table_read_position_vertex_size[_type][_format][_elements]; + return s_table_read_position_vertex_size[type][format][elements]; } -TPipelineFunction VertexLoader_Position::GetFunction(u64 _type, unsigned int _format, - unsigned int _elements) +TPipelineFunction VertexLoader_Position::GetFunction(u64 type, u32 format, u32 elements) { - return s_table_read_position[_type][_format][_elements]; + return s_table_read_position[type][format][elements]; } -- cgit v1.2.3