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.
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2017-03-03 12:43:52 -07:00
|
|
|
#include "VideoCommon/VertexLoader_Normal.h"
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
#include <array>
|
2014-11-11 02:48:38 -07:00
|
|
|
#include <type_traits>
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-03-03 12:43:52 -07:00
|
|
|
|
2016-01-17 14:54:31 -07:00
|
|
|
#include "VideoCommon/DataReader.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VertexLoader.h"
|
2015-05-29 06:42:45 -06:00
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
2016-01-17 14:54:31 -07:00
|
|
|
#include "VideoCommon/VertexLoaderUtils.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2013-02-21 03:45:29 -07:00
|
|
|
// warning: mapping buffer should be disabled to use this
|
2016-06-24 02:43:46 -06:00
|
|
|
#define LOG_NORM() // PRIM_LOG("norm: %f %f %f, ", ((float*)g_vertex_manager_write_ptr)[-3],
|
|
|
|
// ((float*)g_vertex_manager_write_ptr)[-2],
|
|
|
|
// ((float*)g_vertex_manager_write_ptr)[-1]);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2013-02-20 21:22:41 -07:00
|
|
|
namespace
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2013-02-20 21:22:41 -07:00
|
|
|
template <typename T>
|
2019-05-29 20:54:21 -06:00
|
|
|
constexpr float FracAdjust(T val)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06: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-19 19:51:12 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// TODO: is this right?
|
2019-05-29 21:58:18 -06:00
|
|
|
return val / float(1u << (sizeof(T) * 8 - std::is_signed_v<T> - 1));
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2013-02-20 21:22:41 -07:00
|
|
|
template <>
|
2019-05-29 20:54:21 -06:00
|
|
|
constexpr float FracAdjust(float val)
|
2013-04-24 07:21:54 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return val;
|
2013-04-24 07:21:54 -06:00
|
|
|
}
|
2009-09-13 15:18:04 -06:00
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
template <typename T, u32 N>
|
|
|
|
void ReadIndirect(const T* data)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
|
|
|
|
DataReader dst(g_vertex_manager_write_ptr, nullptr);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
for (u32 i = 0; i < N; ++i)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
dst.Write(FracAdjust(Common::FromBigEndian(data[i])));
|
|
|
|
}
|
2013-03-19 19:51:12 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
g_vertex_manager_write_ptr = dst.GetPointer();
|
|
|
|
LOG_NORM();
|
2009-09-13 15:18:04 -06:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
template <typename T, u32 N>
|
2013-02-21 12:25:35 -07:00
|
|
|
struct Normal_Direct
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
auto const source = reinterpret_cast<const T*>(DataGetPosition());
|
|
|
|
ReadIndirect<T, N * 3>(source);
|
|
|
|
DataSkip<N * 3 * sizeof(T)>();
|
|
|
|
}
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
static constexpr u32 size = sizeof(T) * N * 3;
|
2013-02-21 12:25:35 -07:00
|
|
|
};
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
template <typename I, typename T, u32 N, u32 Offset>
|
|
|
|
void Normal_Index_Offset()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 21:58:18 -06:00
|
|
|
static_assert(std::is_unsigned_v<I>, "Only unsigned I is sane!");
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
auto const index = DataRead<I>();
|
|
|
|
auto const data = reinterpret_cast<const T*>(
|
|
|
|
VertexLoaderManager::cached_arraybases[ARRAY_NORMAL] +
|
|
|
|
(index * g_main_cp_state.array_strides[ARRAY_NORMAL]) + sizeof(T) * 3 * Offset);
|
|
|
|
ReadIndirect<T, N * 3>(data);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
template <typename I, typename T, u32 N>
|
2013-02-21 12:25:35 -07:00
|
|
|
struct Normal_Index
|
2009-09-13 15:18:04 -06:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader) { Normal_Index_Offset<I, T, N, 0>(); }
|
|
|
|
static constexpr u32 size = sizeof(I);
|
2013-02-21 12:25:35 -07:00
|
|
|
};
|
2009-09-13 15:18:04 -06:00
|
|
|
|
2013-02-20 21:22:41 -07:00
|
|
|
template <typename I, typename T>
|
2013-02-21 12:25:35 -07:00
|
|
|
struct Normal_Index_Indices3
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
static void function([[maybe_unused]] VertexLoader* loader)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
Normal_Index_Offset<I, T, 1, 0>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 1>();
|
|
|
|
Normal_Index_Offset<I, T, 1, 2>();
|
|
|
|
}
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
static constexpr u32 size = sizeof(I) * 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum NormalType
|
|
|
|
{
|
|
|
|
NRM_NOT_PRESENT = 0,
|
|
|
|
NRM_DIRECT = 1,
|
|
|
|
NRM_INDEX8 = 2,
|
|
|
|
NRM_INDEX16 = 3,
|
|
|
|
NUM_NRM_TYPE
|
2013-02-21 12:25:35 -07:00
|
|
|
};
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
enum NormalFormat
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
FORMAT_UBYTE = 0,
|
|
|
|
FORMAT_BYTE = 1,
|
|
|
|
FORMAT_USHORT = 2,
|
|
|
|
FORMAT_SHORT = 3,
|
|
|
|
FORMAT_FLOAT = 4,
|
|
|
|
NUM_NRM_FORMAT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum NormalElements
|
|
|
|
{
|
|
|
|
NRM_NBT = 0,
|
|
|
|
NRM_NBT3 = 1,
|
|
|
|
NUM_NRM_ELEMENTS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum NormalIndices
|
|
|
|
{
|
|
|
|
NRM_INDICES1 = 0,
|
|
|
|
NRM_INDICES3 = 1,
|
|
|
|
NUM_NRM_INDICES
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Set
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
constexpr Set& operator=(const T&)
|
|
|
|
{
|
|
|
|
gc_size = T::size;
|
|
|
|
function = T::function;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 gc_size;
|
|
|
|
TPipelineFunction function;
|
|
|
|
};
|
|
|
|
|
|
|
|
using Formats = std::array<Set, NUM_NRM_FORMAT>;
|
|
|
|
using Elements = std::array<Formats, NUM_NRM_ELEMENTS>;
|
|
|
|
using Indices = std::array<Elements, NUM_NRM_INDICES>;
|
|
|
|
using Types = std::array<Indices, NUM_NRM_TYPE>;
|
|
|
|
|
|
|
|
constexpr Types InitializeTable()
|
|
|
|
{
|
|
|
|
Types table{};
|
|
|
|
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Direct<s16, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Direct<float, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Same as above
|
2019-05-29 20:54:21 -06:00
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Direct<s16, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Direct<float, 1>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
|
|
|
|
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
|
|
|
|
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u8, u8, 3>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u8, s8, 3>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u8, u16, 3>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u8, s16, 3>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u8, float, 3>();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Same as above for NRM_NBT
|
2019-05-29 20:54:21 -06:00
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u8, u8>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u8, s8>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u8, u16>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u8, s16>();
|
|
|
|
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u8, float>();
|
|
|
|
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u16, u8, 3>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u16, s8, 3>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u16, u16, 3>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u16, s16, 3>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u16, float, 3>();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Same as above for NRM_NBT
|
2019-05-29 20:54:21 -06:00
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u16, u8>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u16, s8>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u16, u16>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u16, s16>();
|
|
|
|
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u16, float>();
|
|
|
|
|
|
|
|
return table;
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:54:21 -06:00
|
|
|
constexpr Types s_table = InitializeTable();
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2019-05-29 20:13:18 -06:00
|
|
|
u32 VertexLoader_Normal::GetSize(u64 type, u32 format, u32 elements, u32 index3)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
return s_table[type][index3][elements][format].gc_size;
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:13:18 -06:00
|
|
|
TPipelineFunction VertexLoader_Normal::GetFunction(u64 type, u32 format, u32 elements, u32 index3)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2019-05-29 20:54:21 -06:00
|
|
|
return s_table[type][index3][elements][format].function;
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|