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 05:25:12 +00:00
|
|
|
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "VideoCommon/VertexLoader_Normal.h"
|
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
#include <array>
|
2014-11-11 09:48:38 +00:00
|
|
|
#include <type_traits>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2021-04-25 23:04:13 +00:00
|
|
|
#include "Common/EnumMap.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/DataReader.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VertexLoader.h"
|
2015-05-29 12:42:45 +00:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "VideoCommon/VertexLoaderUtils.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2013-02-21 10:45:29 +00:00
|
|
|
// warning: mapping buffer should be disabled to use this
|
2020-11-14 03:33:26 +00:00
|
|
|
#define LOG_NORM() // PRIM_LOG("norm: {} {} {}, ", ((float*)g_vertex_manager_write_ptr)[-3],
|
2014-12-09 07:30:38 +00:00
|
|
|
// ((float*)g_vertex_manager_write_ptr)[-2],
|
|
|
|
// ((float*)g_vertex_manager_write_ptr)[-1]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
namespace
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename T>
|
2019-05-30 02:54:21 +00:00
|
|
|
constexpr float FracAdjust(T val)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
// auto const S8FRAC = 1.f / (1u << 6);
|
|
|
|
// auto const U8FRAC = 1.f / (1u << 7);
|
|
|
|
// auto const S16FRAC = 1.f / (1u << 14);
|
|
|
|
// auto const U16FRAC = 1.f / (1u << 15);
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 06:49:47 +00:00
|
|
|
// TODO: is this right?
|
2019-05-30 03:58:18 +00:00
|
|
|
return val / float(1u << (sizeof(T) * 8 - std::is_signed_v<T> - 1));
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <>
|
2019-05-30 02:54:21 +00:00
|
|
|
constexpr float FracAdjust(float val)
|
2013-02-21 04:22:41 +00:00
|
|
|
{
|
|
|
|
return val;
|
|
|
|
}
|
2009-09-13 21:18:04 +00:00
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
template <typename T, u32 N>
|
|
|
|
void ReadIndirect(const T* data)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
|
2014-12-09 07:30:38 +00:00
|
|
|
DataReader dst(g_vertex_manager_write_ptr, nullptr);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
for (u32 i = 0; i < N; ++i)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-01-21 22:44:51 +00:00
|
|
|
dst.Write(FracAdjust(Common::FromBigEndian(data[i])));
|
2013-02-21 04:22:41 +00:00
|
|
|
}
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2015-01-06 16:49:27 +00:00
|
|
|
g_vertex_manager_write_ptr = dst.GetPointer();
|
2013-02-21 12:45:48 +00:00
|
|
|
LOG_NORM();
|
2009-09-13 21:18:04 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
template <typename T, u32 N>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Direct
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2019-05-30 02:54:21 +00:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader)
|
2013-02-21 19:25:35 +00:00
|
|
|
{
|
2021-06-20 20:47:57 +00:00
|
|
|
const auto source = reinterpret_cast<const T*>(DataGetPosition());
|
2013-02-21 19:25:35 +00:00
|
|
|
ReadIndirect<T, N * 3>(source);
|
|
|
|
DataSkip<N * 3 * sizeof(T)>();
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
static constexpr u32 size = sizeof(T) * N * 3;
|
2013-02-21 19:25:35 +00:00
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
template <typename I, typename T, u32 N, u32 Offset>
|
|
|
|
void Normal_Index_Offset()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2019-05-30 03:58:18 +00:00
|
|
|
static_assert(std::is_unsigned_v<I>, "Only unsigned I is sane!");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2021-06-20 20:47:57 +00:00
|
|
|
const auto index = DataRead<I>();
|
|
|
|
const auto data = reinterpret_cast<const T*>(
|
|
|
|
VertexLoaderManager::cached_arraybases[CPArray::Normal] +
|
|
|
|
(index * g_main_cp_state.array_strides[CPArray::Normal]) + sizeof(T) * 3 * Offset);
|
2013-02-21 04:22:41 +00:00
|
|
|
ReadIndirect<T, N * 3>(data);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
template <typename I, typename T, u32 N>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Index
|
2009-09-13 21:18:04 +00:00
|
|
|
{
|
2019-05-30 02:54:21 +00:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader) { Normal_Index_Offset<I, T, N, 0>(); }
|
|
|
|
static constexpr u32 size = sizeof(I);
|
2013-02-21 19:25:35 +00:00
|
|
|
};
|
2009-09-13 21:18:04 +00:00
|
|
|
|
2013-02-21 04:22:41 +00:00
|
|
|
template <typename I, typename T>
|
2013-02-21 19:25:35 +00:00
|
|
|
struct Normal_Index_Indices3
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2019-05-30 02:54:21 +00:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader)
|
2013-02-21 19:25:35 +00:00
|
|
|
{
|
|
|
|
Normal_Index_Offset<I, T, 1, 0>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 1>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 2>();
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
static constexpr u32 size = sizeof(I) * 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Set
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
constexpr Set& operator=(const T&)
|
|
|
|
{
|
|
|
|
gc_size = T::size;
|
|
|
|
function = T::function;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 gc_size;
|
|
|
|
TPipelineFunction function;
|
|
|
|
};
|
|
|
|
|
2021-04-25 23:04:13 +00:00
|
|
|
using Common::EnumMap;
|
|
|
|
using Formats = EnumMap<Set, ComponentFormat::Float>;
|
|
|
|
using Elements = EnumMap<Formats, NormalComponentCount::NBT>;
|
|
|
|
using Indices = std::array<Elements, 2>;
|
|
|
|
using Types = EnumMap<Indices, VertexComponentFormat::Index16>;
|
2019-05-30 02:54:21 +00:00
|
|
|
|
|
|
|
constexpr Types InitializeTable()
|
|
|
|
{
|
|
|
|
Types table{};
|
|
|
|
|
2021-04-25 23:04:13 +00:00
|
|
|
using VCF = VertexComponentFormat;
|
|
|
|
using NCC = NormalComponentCount;
|
|
|
|
using FMT = ComponentFormat;
|
|
|
|
|
|
|
|
table[VCF::Direct][false][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
|
|
|
|
table[VCF::Direct][false][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
|
|
|
|
table[VCF::Direct][false][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
|
|
|
|
table[VCF::Direct][false][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
|
|
|
|
table[VCF::Direct][false][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
|
|
|
|
table[VCF::Direct][false][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
|
|
|
|
table[VCF::Direct][false][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
|
|
|
|
table[VCF::Direct][false][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 3>();
|
|
|
|
table[VCF::Direct][false][NCC::NBT][FMT::Short] = Normal_Direct<s16, 3>();
|
|
|
|
table[VCF::Direct][false][NCC::NBT][FMT::Float] = Normal_Direct<float, 3>();
|
|
|
|
|
|
|
|
// Same as above, since there are no indices
|
|
|
|
table[VCF::Direct][true][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
|
|
|
|
table[VCF::Direct][true][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
|
|
|
|
table[VCF::Direct][true][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
|
|
|
|
table[VCF::Direct][true][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
|
|
|
|
table[VCF::Direct][true][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
|
|
|
|
table[VCF::Direct][true][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
|
|
|
|
table[VCF::Direct][true][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
|
|
|
|
table[VCF::Direct][true][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 3>();
|
|
|
|
table[VCF::Direct][true][NCC::NBT][FMT::Short] = Normal_Direct<s16, 3>();
|
|
|
|
table[VCF::Direct][true][NCC::NBT][FMT::Float] = Normal_Direct<float, 3>();
|
|
|
|
|
|
|
|
table[VCF::Index8][false][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
|
|
|
|
table[VCF::Index8][false][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
|
|
|
|
table[VCF::Index8][false][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
|
|
|
|
table[VCF::Index8][false][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
|
|
|
|
table[VCF::Index8][false][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
|
|
|
|
table[VCF::Index8][false][NCC::NBT][FMT::UByte] = Normal_Index<u8, u8, 3>();
|
|
|
|
table[VCF::Index8][false][NCC::NBT][FMT::Byte] = Normal_Index<u8, s8, 3>();
|
|
|
|
table[VCF::Index8][false][NCC::NBT][FMT::UShort] = Normal_Index<u8, u16, 3>();
|
|
|
|
table[VCF::Index8][false][NCC::NBT][FMT::Short] = Normal_Index<u8, s16, 3>();
|
|
|
|
table[VCF::Index8][false][NCC::NBT][FMT::Float] = Normal_Index<u8, float, 3>();
|
|
|
|
|
|
|
|
// Same for NormalComponentCount::N; differs for NBT
|
|
|
|
table[VCF::Index8][true][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
|
|
|
|
table[VCF::Index8][true][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
|
|
|
|
table[VCF::Index8][true][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
|
|
|
|
table[VCF::Index8][true][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
|
|
|
|
table[VCF::Index8][true][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
|
|
|
|
table[VCF::Index8][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3<u8, u8>();
|
|
|
|
table[VCF::Index8][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3<u8, s8>();
|
|
|
|
table[VCF::Index8][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3<u8, u16>();
|
|
|
|
table[VCF::Index8][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3<u8, s16>();
|
|
|
|
table[VCF::Index8][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3<u8, float>();
|
|
|
|
|
|
|
|
table[VCF::Index16][false][NCC::N][FMT::UByte] = Normal_Index<u16, u8, 1>();
|
|
|
|
table[VCF::Index16][false][NCC::N][FMT::Byte] = Normal_Index<u16, s8, 1>();
|
|
|
|
table[VCF::Index16][false][NCC::N][FMT::UShort] = Normal_Index<u16, u16, 1>();
|
|
|
|
table[VCF::Index16][false][NCC::N][FMT::Short] = Normal_Index<u16, s16, 1>();
|
|
|
|
table[VCF::Index16][false][NCC::N][FMT::Float] = Normal_Index<u16, float, 1>();
|
|
|
|
table[VCF::Index16][false][NCC::NBT][FMT::UByte] = Normal_Index<u16, u8, 3>();
|
|
|
|
table[VCF::Index16][false][NCC::NBT][FMT::Byte] = Normal_Index<u16, s8, 3>();
|
|
|
|
table[VCF::Index16][false][NCC::NBT][FMT::UShort] = Normal_Index<u16, u16, 3>();
|
|
|
|
table[VCF::Index16][false][NCC::NBT][FMT::Short] = Normal_Index<u16, s16, 3>();
|
|
|
|
table[VCF::Index16][false][NCC::NBT][FMT::Float] = Normal_Index<u16, float, 3>();
|
|
|
|
|
|
|
|
// Same for NormalComponentCount::N; differs for NBT
|
|
|
|
table[VCF::Index16][true][NCC::N][FMT::UByte] = Normal_Index<u16, u8, 1>();
|
|
|
|
table[VCF::Index16][true][NCC::N][FMT::Byte] = Normal_Index<u16, s8, 1>();
|
|
|
|
table[VCF::Index16][true][NCC::N][FMT::UShort] = Normal_Index<u16, u16, 1>();
|
|
|
|
table[VCF::Index16][true][NCC::N][FMT::Short] = Normal_Index<u16, s16, 1>();
|
|
|
|
table[VCF::Index16][true][NCC::N][FMT::Float] = Normal_Index<u16, float, 1>();
|
|
|
|
table[VCF::Index16][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3<u16, u8>();
|
|
|
|
table[VCF::Index16][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3<u16, s8>();
|
|
|
|
table[VCF::Index16][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3<u16, u16>();
|
|
|
|
table[VCF::Index16][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3<u16, s16>();
|
|
|
|
table[VCF::Index16][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3<u16, float>();
|
2019-05-30 02:54:21 +00:00
|
|
|
|
|
|
|
return table;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 02:54:21 +00:00
|
|
|
constexpr Types s_table = InitializeTable();
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
u32 VertexLoader_Normal::GetSize(VertexComponentFormat type, ComponentFormat format,
|
2021-04-25 23:04:13 +00:00
|
|
|
NormalComponentCount elements, bool index3)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2021-04-25 23:04:13 +00:00
|
|
|
return s_table[type][index3][elements][format].gc_size;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 23:22:10 +00:00
|
|
|
TPipelineFunction VertexLoader_Normal::GetFunction(VertexComponentFormat type,
|
|
|
|
ComponentFormat format,
|
2021-04-25 23:04:13 +00:00
|
|
|
NormalComponentCount elements, bool index3)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2021-04-25 23:04:13 +00:00
|
|
|
return s_table[type][index3][elements][format].function;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|