use templates for primitive restart
This commit is contained in:
parent
4dca133745
commit
b0108631f6
|
@ -35,6 +35,30 @@ u32 IndexGenerator::index;
|
||||||
|
|
||||||
static const u16 s_primitive_restart = -1;
|
static const u16 s_primitive_restart = -1;
|
||||||
|
|
||||||
|
static void (*primitive_table[8])(u32);
|
||||||
|
|
||||||
|
void IndexGenerator::Init()
|
||||||
|
{
|
||||||
|
if(g_Config.backend_info.bSupportsPrimitiveRestart)
|
||||||
|
{
|
||||||
|
primitive_table[0] = IndexGenerator::AddQuads<true>;
|
||||||
|
primitive_table[2] = IndexGenerator::AddList<true>;
|
||||||
|
primitive_table[3] = IndexGenerator::AddStrip<true>;
|
||||||
|
primitive_table[4] = IndexGenerator::AddFan<true>;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
primitive_table[0] = IndexGenerator::AddQuads<false>;
|
||||||
|
primitive_table[2] = IndexGenerator::AddList<false>;
|
||||||
|
primitive_table[3] = IndexGenerator::AddStrip<false>;
|
||||||
|
primitive_table[4] = IndexGenerator::AddFan<false>;
|
||||||
|
}
|
||||||
|
primitive_table[1] = NULL;
|
||||||
|
primitive_table[5] = &IndexGenerator::AddLineList;
|
||||||
|
primitive_table[6] = &IndexGenerator::AddLineStrip;
|
||||||
|
primitive_table[7] = &IndexGenerator::AddPoints;
|
||||||
|
}
|
||||||
|
|
||||||
void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr)
|
void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr)
|
||||||
{
|
{
|
||||||
Tptr = Triangleptr;
|
Tptr = Triangleptr;
|
||||||
|
@ -51,57 +75,34 @@ void IndexGenerator::Start(u16* Triangleptr, u16* Lineptr, u16* Pointptr)
|
||||||
|
|
||||||
void IndexGenerator::AddIndices(int primitive, u32 numVerts)
|
void IndexGenerator::AddIndices(int primitive, u32 numVerts)
|
||||||
{
|
{
|
||||||
//switch (primitive)
|
|
||||||
//{
|
|
||||||
//case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVerts); break;
|
|
||||||
//case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVerts); break;
|
|
||||||
//case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVerts); break;
|
|
||||||
//case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVerts); break;
|
|
||||||
//case GX_DRAW_LINES: IndexGenerator::AddLineList(numVerts); break;
|
|
||||||
//case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVerts); break;
|
|
||||||
//case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVerts); break;
|
|
||||||
//}
|
|
||||||
|
|
||||||
static void (*const primitive_table[])(u32) =
|
|
||||||
{
|
|
||||||
IndexGenerator::AddQuads,
|
|
||||||
NULL,
|
|
||||||
IndexGenerator::AddList,
|
|
||||||
IndexGenerator::AddStrip,
|
|
||||||
IndexGenerator::AddFan,
|
|
||||||
IndexGenerator::AddLineList,
|
|
||||||
IndexGenerator::AddLineStrip,
|
|
||||||
IndexGenerator::AddPoints,
|
|
||||||
};
|
|
||||||
|
|
||||||
primitive_table[primitive](numVerts);
|
primitive_table[primitive](numVerts);
|
||||||
index += numVerts;
|
index += numVerts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triangles
|
// Triangles
|
||||||
__forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3)
|
template <bool pr> __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3)
|
||||||
{
|
{
|
||||||
*Tptr++ = index1;
|
*Tptr++ = index1;
|
||||||
*Tptr++ = index2;
|
*Tptr++ = index2;
|
||||||
*Tptr++ = index3;
|
*Tptr++ = index3;
|
||||||
if(g_Config.backend_info.bSupportsPrimitiveRestart)
|
if(pr)
|
||||||
*Tptr++ = s_primitive_restart;
|
*Tptr++ = s_primitive_restart;
|
||||||
|
|
||||||
++numT;
|
++numT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator::AddList(u32 const numVerts)
|
template <bool pr> void IndexGenerator::AddList(u32 const numVerts)
|
||||||
{
|
{
|
||||||
auto const numTris = numVerts / 3;
|
auto const numTris = numVerts / 3;
|
||||||
for (u32 i = 0; i != numTris; ++i)
|
for (u32 i = 0; i != numTris; ++i)
|
||||||
{
|
{
|
||||||
WriteTriangle(index + i * 3, index + i * 3 + 1, index + i * 3 + 2);
|
WriteTriangle<pr>(index + i * 3, index + i * 3 + 1, index + i * 3 + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndexGenerator::AddStrip(u32 const numVerts)
|
template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts)
|
||||||
{
|
{
|
||||||
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
if(pr) {
|
||||||
for (u32 i = 0; i < numVerts; ++i)
|
for (u32 i = 0; i < numVerts; ++i)
|
||||||
{
|
{
|
||||||
*Tptr++ = index + i;
|
*Tptr++ = index + i;
|
||||||
|
@ -113,7 +114,7 @@ void IndexGenerator::AddStrip(u32 const numVerts)
|
||||||
bool wind = false;
|
bool wind = false;
|
||||||
for (u32 i = 2; i < numVerts; ++i)
|
for (u32 i = 2; i < numVerts; ++i)
|
||||||
{
|
{
|
||||||
WriteTriangle(
|
WriteTriangle<pr>(
|
||||||
index + i - 2,
|
index + i - 2,
|
||||||
index + i - !wind,
|
index + i - !wind,
|
||||||
index + i - wind);
|
index + i - wind);
|
||||||
|
@ -142,11 +143,11 @@ void IndexGenerator::AddStrip(u32 const numVerts)
|
||||||
* so we use 6 indices for 3 triangles
|
* so we use 6 indices for 3 triangles
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void IndexGenerator::AddFan(u32 numVerts)
|
template <bool pr> void IndexGenerator::AddFan(u32 numVerts)
|
||||||
{
|
{
|
||||||
u32 i = 2;
|
u32 i = 2;
|
||||||
|
|
||||||
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
if(pr) {
|
||||||
for(; i<=numVerts-3; i+=3) {
|
for(; i<=numVerts-3; i+=3) {
|
||||||
*Tptr++ = index + i - 1;
|
*Tptr++ = index + i - 1;
|
||||||
*Tptr++ = index + i + 0;
|
*Tptr++ = index + i + 0;
|
||||||
|
@ -169,7 +170,7 @@ void IndexGenerator::AddFan(u32 numVerts)
|
||||||
|
|
||||||
for (; i < numVerts; ++i)
|
for (; i < numVerts; ++i)
|
||||||
{
|
{
|
||||||
WriteTriangle(index, index + i - 1, index + i);
|
WriteTriangle<pr>(index, index + i - 1, index + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,12 +187,12 @@ void IndexGenerator::AddFan(u32 numVerts)
|
||||||
* or 120,302, 564,746
|
* or 120,302, 564,746
|
||||||
* or as strip: 1203, 5647
|
* or as strip: 1203, 5647
|
||||||
*/
|
*/
|
||||||
void IndexGenerator::AddQuads(u32 numVerts)
|
template <bool pr> void IndexGenerator::AddQuads(u32 numVerts)
|
||||||
{
|
{
|
||||||
auto const numQuads = numVerts / 4;
|
auto const numQuads = numVerts / 4;
|
||||||
for (u32 i = 0; i != numQuads; ++i)
|
for (u32 i = 0; i != numQuads; ++i)
|
||||||
{
|
{
|
||||||
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
if(pr) {
|
||||||
*Tptr++ = index + i * 4 + 1;
|
*Tptr++ = index + i * 4 + 1;
|
||||||
*Tptr++ = index + i * 4 + 2;
|
*Tptr++ = index + i * 4 + 2;
|
||||||
*Tptr++ = index + i * 4 + 0;
|
*Tptr++ = index + i * 4 + 0;
|
||||||
|
@ -199,8 +200,8 @@ void IndexGenerator::AddQuads(u32 numVerts)
|
||||||
*Tptr++ = s_primitive_restart;
|
*Tptr++ = s_primitive_restart;
|
||||||
numT += 2;
|
numT += 2;
|
||||||
} else {
|
} else {
|
||||||
WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2);
|
WriteTriangle<pr>(index + i * 4, index + i * 4 + 1, index + i * 4 + 2);
|
||||||
WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3);
|
WriteTriangle<pr>(index + i * 4, index + i * 4 + 2, index + i * 4 + 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class IndexGenerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Init
|
// Init
|
||||||
|
static void Init();
|
||||||
static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr);
|
static void Start(u16 *Triangleptr,u16 *Lineptr,u16 *Pointptr);
|
||||||
|
|
||||||
static void AddIndices(int primitive, u32 numVertices);
|
static void AddIndices(int primitive, u32 numVertices);
|
||||||
|
@ -54,10 +55,10 @@ public:
|
||||||
*/
|
*/
|
||||||
private:
|
private:
|
||||||
// Triangles
|
// Triangles
|
||||||
static void AddList(u32 numVerts);
|
template <bool pr> static void AddList(u32 numVerts);
|
||||||
static void AddStrip(u32 numVerts);
|
template <bool pr> static void AddStrip(u32 numVerts);
|
||||||
static void AddFan(u32 numVerts);
|
template <bool pr> static void AddFan(u32 numVerts);
|
||||||
static void AddQuads(u32 numVerts);
|
template <bool pr> static void AddQuads(u32 numVerts);
|
||||||
|
|
||||||
// Lines
|
// Lines
|
||||||
static void AddLineList(u32 numVerts);
|
static void AddLineList(u32 numVerts);
|
||||||
|
@ -66,7 +67,7 @@ private:
|
||||||
// Points
|
// Points
|
||||||
static void AddPoints(u32 numVerts);
|
static void AddPoints(u32 numVerts);
|
||||||
|
|
||||||
static void WriteTriangle(u32 index1, u32 index2, u32 index3);
|
template <bool pr> static void WriteTriangle(u32 index1, u32 index2, u32 index3);
|
||||||
|
|
||||||
static u16 *Tptr;
|
static u16 *Tptr;
|
||||||
static u16 *BASETptr;
|
static u16 *BASETptr;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "Debugger/DebuggerPanel.h"
|
#include "Debugger/DebuggerPanel.h"
|
||||||
#include "DLCache.h"
|
#include "DLCache.h"
|
||||||
#include "EmuWindow.h"
|
#include "EmuWindow.h"
|
||||||
|
#include "IndexGenerator.h"
|
||||||
#include "FileUtil.h"
|
#include "FileUtil.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
|
@ -193,6 +194,7 @@ void VideoBackend::Video_Prepare()
|
||||||
// VideoCommon
|
// VideoCommon
|
||||||
BPInit();
|
BPInit();
|
||||||
Fifo_Init();
|
Fifo_Init();
|
||||||
|
IndexGenerator::Init();
|
||||||
VertexLoaderManager::Init();
|
VertexLoaderManager::Init();
|
||||||
OpcodeDecoder_Init();
|
OpcodeDecoder_Init();
|
||||||
VertexShaderManager::Init();
|
VertexShaderManager::Init();
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#include "VideoState.h"
|
#include "VideoState.h"
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
#include "DLCache.h"
|
#include "DLCache.h"
|
||||||
|
#include "IndexGenerator.h"
|
||||||
#include "IniFile.h"
|
#include "IniFile.h"
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
#include "Host.h"
|
#include "Host.h"
|
||||||
|
@ -184,6 +185,7 @@ void VideoBackend::Video_Prepare()
|
||||||
// VideoCommon
|
// VideoCommon
|
||||||
BPInit();
|
BPInit();
|
||||||
Fifo_Init();
|
Fifo_Init();
|
||||||
|
IndexGenerator::Init();
|
||||||
VertexLoaderManager::Init();
|
VertexLoaderManager::Init();
|
||||||
OpcodeDecoder_Init();
|
OpcodeDecoder_Init();
|
||||||
VertexShaderManager::Init();
|
VertexShaderManager::Init();
|
||||||
|
|
|
@ -338,7 +338,7 @@ Renderer::Renderer()
|
||||||
|
|
||||||
g_Config.backend_info.bSupportsDualSourceBlend = GLEW_ARB_blend_func_extended;
|
g_Config.backend_info.bSupportsDualSourceBlend = GLEW_ARB_blend_func_extended;
|
||||||
g_Config.backend_info.bSupportsGLSLUBO = GLEW_ARB_uniform_buffer_object;
|
g_Config.backend_info.bSupportsGLSLUBO = GLEW_ARB_uniform_buffer_object;
|
||||||
g_Config.backend_info.bSupportsPrimitiveRestart = false; //GLEW_VERSION_3_1;
|
g_Config.backend_info.bSupportsPrimitiveRestart = GLEW_VERSION_3_1;
|
||||||
|
|
||||||
g_ogl_config.bSupportsGLSLCache = GLEW_ARB_get_program_binary;
|
g_ogl_config.bSupportsGLSLCache = GLEW_ARB_get_program_binary;
|
||||||
g_ogl_config.bSupportsGLPinnedMemory = GLEW_AMD_pinned_memory;
|
g_ogl_config.bSupportsGLPinnedMemory = GLEW_AMD_pinned_memory;
|
||||||
|
|
|
@ -96,6 +96,7 @@ Make AA apply instantly during gameplay if possible
|
||||||
#include "PerfQuery.h"
|
#include "PerfQuery.h"
|
||||||
|
|
||||||
#include "VideoState.h"
|
#include "VideoState.h"
|
||||||
|
#include "IndexGenerator.h"
|
||||||
#include "VideoBackend.h"
|
#include "VideoBackend.h"
|
||||||
#include "ConfigManager.h"
|
#include "ConfigManager.h"
|
||||||
|
|
||||||
|
@ -199,6 +200,7 @@ void VideoBackend::Video_Prepare()
|
||||||
g_perf_query = new PerfQuery;
|
g_perf_query = new PerfQuery;
|
||||||
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
||||||
OpcodeDecoder_Init();
|
OpcodeDecoder_Init();
|
||||||
|
IndexGenerator::Init();
|
||||||
VertexShaderManager::Init();
|
VertexShaderManager::Init();
|
||||||
PixelShaderManager::Init();
|
PixelShaderManager::Init();
|
||||||
ProgramShaderCache::Init();
|
ProgramShaderCache::Init();
|
||||||
|
|
Loading…
Reference in New Issue