first try of primitive restart index generator
Convert all quads+triangles into trangle_strip and uses primitive restart to split them. Speed up triangle_strip, but slows down all others primitive formats. Only implemented in ogl.
This commit is contained in:
parent
c743e75d92
commit
ca8554e7d1
|
@ -18,6 +18,7 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "VideoConfig.h"
|
||||||
#include "IndexGenerator.h"
|
#include "IndexGenerator.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -90,7 +91,9 @@ __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 ind
|
||||||
*Tptr++ = index1;
|
*Tptr++ = index1;
|
||||||
*Tptr++ = index2;
|
*Tptr++ = index2;
|
||||||
*Tptr++ = index3;
|
*Tptr++ = index3;
|
||||||
|
if(g_Config.backend_info.bSupportsPrimitiveRestart)
|
||||||
|
*Tptr++ = 65535;
|
||||||
|
|
||||||
++numT;
|
++numT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,15 +108,25 @@ void IndexGenerator::AddList(u32 const numVerts)
|
||||||
|
|
||||||
void IndexGenerator::AddStrip(u32 const numVerts)
|
void IndexGenerator::AddStrip(u32 const numVerts)
|
||||||
{
|
{
|
||||||
bool wind = false;
|
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
||||||
for (u32 i = 2; i < numVerts; ++i)
|
for (u32 i = 0; i < numVerts; ++i)
|
||||||
{
|
{
|
||||||
WriteTriangle(
|
*Tptr++ = index + i;
|
||||||
index + i - 2,
|
}
|
||||||
index + i - !wind,
|
*Tptr++ = 65535;
|
||||||
index + i - wind);
|
numT += numVerts - 2;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
bool wind = false;
|
||||||
|
for (u32 i = 2; i < numVerts; ++i)
|
||||||
|
{
|
||||||
|
WriteTriangle(
|
||||||
|
index + i - 2,
|
||||||
|
index + i - !wind,
|
||||||
|
index + i - wind);
|
||||||
|
|
||||||
wind ^= true;
|
wind ^= true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +143,17 @@ 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)
|
||||||
{
|
{
|
||||||
WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2);
|
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
||||||
WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3);
|
*Tptr++ = index + i * 4 + 0;
|
||||||
|
*Tptr++ = index + i * 4 + 1;
|
||||||
|
*Tptr++ = index + i * 4 + 3;
|
||||||
|
*Tptr++ = index + i * 4 + 2;
|
||||||
|
*Tptr++ = 65535;
|
||||||
|
numT += 2;
|
||||||
|
} else {
|
||||||
|
WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2);
|
||||||
|
WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -659,6 +659,10 @@ void VertexLoader::SetVAT(u32 _group0, u32 _group1, u32 _group2)
|
||||||
m_VtxAttr.texCoord[7].Elements = vat.g2.Tex7CoordElements;
|
m_VtxAttr.texCoord[7].Elements = vat.g2.Tex7CoordElements;
|
||||||
m_VtxAttr.texCoord[7].Format = vat.g2.Tex7CoordFormat;
|
m_VtxAttr.texCoord[7].Format = vat.g2.Tex7CoordFormat;
|
||||||
m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac;
|
m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac;
|
||||||
|
|
||||||
|
if(!m_VtxAttr.ByteDequant) {
|
||||||
|
ERROR_LOG(VIDEO, "ByteDequant is set to zero");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void VertexLoader::AppendToString(std::string *dest) const
|
void VertexLoader::AppendToString(std::string *dest) const
|
||||||
|
|
|
@ -74,28 +74,54 @@ bool VertexManager::IsFlushed() const
|
||||||
|
|
||||||
u32 VertexManager::GetRemainingIndices(int primitive)
|
u32 VertexManager::GetRemainingIndices(int primitive)
|
||||||
{
|
{
|
||||||
switch (primitive)
|
|
||||||
{
|
if(g_Config.backend_info.bSupportsPrimitiveRestart) {
|
||||||
case GX_DRAW_QUADS:
|
switch (primitive)
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4;
|
{
|
||||||
case GX_DRAW_TRIANGLES:
|
case GX_DRAW_QUADS:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen());
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 5 * 4;
|
||||||
case GX_DRAW_TRIANGLE_STRIP:
|
case GX_DRAW_TRIANGLES:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2;
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 4 * 3;
|
||||||
case GX_DRAW_TRIANGLE_FAN:
|
case GX_DRAW_TRIANGLE_STRIP:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2;
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 1 - 1;
|
||||||
|
case GX_DRAW_TRIANGLE_FAN:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 4 + 2;
|
||||||
|
|
||||||
case GX_DRAW_LINES:
|
case GX_DRAW_LINES:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen());
|
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen());
|
||||||
case GX_DRAW_LINE_STRIP:
|
case GX_DRAW_LINE_STRIP:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1;
|
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1;
|
||||||
|
|
||||||
case GX_DRAW_POINTS:
|
case GX_DRAW_POINTS:
|
||||||
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
|
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch (primitive)
|
||||||
|
{
|
||||||
|
case GX_DRAW_QUADS:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 6 * 4;
|
||||||
|
case GX_DRAW_TRIANGLES:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen());
|
||||||
|
case GX_DRAW_TRIANGLE_STRIP:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2;
|
||||||
|
case GX_DRAW_TRIANGLE_FAN:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3 + 2;
|
||||||
|
|
||||||
|
case GX_DRAW_LINES:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen());
|
||||||
|
case GX_DRAW_LINE_STRIP:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2 + 1;
|
||||||
|
|
||||||
|
case GX_DRAW_POINTS:
|
||||||
|
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexManager::AddVertices(int primitive, u32 numVertices)
|
void VertexManager::AddVertices(int primitive, u32 numVertices)
|
||||||
|
|
|
@ -153,6 +153,7 @@ struct VideoConfig
|
||||||
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
||||||
bool bSupportsFormatReinterpretation;
|
bool bSupportsFormatReinterpretation;
|
||||||
bool bSupportsPixelLighting;
|
bool bSupportsPixelLighting;
|
||||||
|
bool bSupportsPrimitiveRestart;
|
||||||
|
|
||||||
bool bSupportsGLSLUBO; // needed by pixelShaderGen, so must stay in videoCommon
|
bool bSupportsGLSLUBO; // needed by pixelShaderGen, so must stay in videoCommon
|
||||||
} backend_info;
|
} backend_info;
|
||||||
|
|
|
@ -96,6 +96,7 @@ void InitBackendInfo()
|
||||||
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
||||||
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
g_Config.backend_info.bSupportsFormatReinterpretation = true;
|
||||||
g_Config.backend_info.bSupportsPixelLighting = true;
|
g_Config.backend_info.bSupportsPixelLighting = true;
|
||||||
|
g_Config.backend_info.bSupportsPrimitiveRestart = false; // TODO: dx11 does support it, but it isn't implemented
|
||||||
|
|
||||||
IDXGIFactory* factory;
|
IDXGIFactory* factory;
|
||||||
IDXGIAdapter* ad;
|
IDXGIAdapter* ad;
|
||||||
|
|
|
@ -101,6 +101,7 @@ void InitBackendInfo()
|
||||||
g_Config.backend_info.bUseRGBATextures = false;
|
g_Config.backend_info.bUseRGBATextures = false;
|
||||||
g_Config.backend_info.bUseMinimalMipCount = true;
|
g_Config.backend_info.bUseMinimalMipCount = true;
|
||||||
g_Config.backend_info.bSupports3DVision = true;
|
g_Config.backend_info.bSupports3DVision = true;
|
||||||
|
g_Config.backend_info.bSupportsPrimitiveRestart = false; // TODO: figure out if it does
|
||||||
OSVERSIONINFO info;
|
OSVERSIONINFO info;
|
||||||
ZeroMemory(&info, sizeof(OSVERSIONINFO));
|
ZeroMemory(&info, sizeof(OSVERSIONINFO));
|
||||||
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||||
|
|
|
@ -293,6 +293,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_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;
|
||||||
|
@ -328,9 +329,10 @@ Renderer::Renderer()
|
||||||
g_ogl_config.gl_renderer,
|
g_ogl_config.gl_renderer,
|
||||||
g_ogl_config.gl_version).c_str(), 5000);
|
g_ogl_config.gl_version).c_str(), 5000);
|
||||||
|
|
||||||
OSD::AddMessage(StringFromFormat("Missing Extensions: %s%s%s%s%s%s%s%s",
|
OSD::AddMessage(StringFromFormat("Missing Extensions: %s%s%s%s%s%s%s%s%s",
|
||||||
g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ",
|
g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ",
|
||||||
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "UniformBuffer ",
|
g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "" : "UniformBuffer ",
|
||||||
|
g_ActiveConfig.backend_info.bSupportsPrimitiveRestart ? "" : "PrimitiveRestart ",
|
||||||
g_ogl_config.bSupportsGLPinnedMemory ? "" : "PinnedMemory ",
|
g_ogl_config.bSupportsGLPinnedMemory ? "" : "PinnedMemory ",
|
||||||
g_ogl_config.bSupportsGLSLCache ? "" : "ShaderCache ",
|
g_ogl_config.bSupportsGLSLCache ? "" : "ShaderCache ",
|
||||||
g_ogl_config.bSupportsGLBaseVertex ? "" : "BaseVertex ",
|
g_ogl_config.bSupportsGLBaseVertex ? "" : "BaseVertex ",
|
||||||
|
@ -1391,6 +1393,12 @@ void Renderer::ResetAPIState()
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
if(g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
|
||||||
|
{
|
||||||
|
glDisable(GL_PRIMITIVE_RESTART);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::RestoreAPIState()
|
void Renderer::RestoreAPIState()
|
||||||
|
@ -1411,6 +1419,12 @@ void Renderer::RestoreAPIState()
|
||||||
vm->m_last_vao = 0;
|
vm->m_last_vao = 0;
|
||||||
|
|
||||||
TextureCache::SetStage();
|
TextureCache::SetStage();
|
||||||
|
|
||||||
|
if(g_ActiveConfig.backend_info.bSupportsPrimitiveRestart)
|
||||||
|
{
|
||||||
|
glEnable(GL_PRIMITIVE_RESTART);
|
||||||
|
glPrimitiveRestartIndex(65535);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SetGenerationMode()
|
void Renderer::SetGenerationMode()
|
||||||
|
|
|
@ -127,7 +127,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
if(g_ogl_config.bSupportsGLBaseVertex) {
|
if(g_ogl_config.bSupportsGLBaseVertex) {
|
||||||
if (triangle_index_size > 0)
|
if (triangle_index_size > 0)
|
||||||
{
|
{
|
||||||
glDrawElementsBaseVertex(GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (u8*)NULL+s_offset[0], s_baseVertex);
|
glDrawElementsBaseVertex(g_ActiveConfig.backend_info.bSupportsPrimitiveRestart?GL_TRIANGLE_STRIP:GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (u8*)NULL+s_offset[0], s_baseVertex);
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (line_index_size > 0)
|
if (line_index_size > 0)
|
||||||
|
@ -143,7 +143,7 @@ void VertexManager::Draw(u32 stride)
|
||||||
} else {
|
} else {
|
||||||
if (triangle_index_size > 0)
|
if (triangle_index_size > 0)
|
||||||
{
|
{
|
||||||
glDrawElements(GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (u8*)NULL+s_offset[0]);
|
glDrawElements(g_ActiveConfig.backend_info.bSupportsPrimitiveRestart?GL_TRIANGLE_STRIP:GL_TRIANGLES, triangle_index_size, GL_UNSIGNED_SHORT, (u8*)NULL+s_offset[0]);
|
||||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||||
}
|
}
|
||||||
if (line_index_size > 0)
|
if (line_index_size > 0)
|
||||||
|
|
Loading…
Reference in New Issue