GeometryShaderGen: Pass the primitive type and always run the generator regardless of stereoscopy.

This commit is contained in:
Jules Blok 2014-12-14 19:41:16 +01:00
parent b406e4e1f2
commit aa4242fd9c
8 changed files with 28 additions and 32 deletions

View File

@ -186,14 +186,14 @@ void GeometryShaderCache::Shutdown()
g_gs_disk_cache.Close();
}
bool GeometryShaderCache::SetShader(u32 components)
bool GeometryShaderCache::SetShader(u32 primitive_type)
{
GeometryShaderUid uid;
GetGeometryShaderUid(uid, components, API_D3D);
GetGeometryShaderUid(uid, primitive_type, API_D3D);
if (g_ActiveConfig.bEnableShaderDebugging)
{
ShaderCode code;
GenerateGeometryShaderCode(code, components, API_D3D);
GenerateGeometryShaderCode(code, primitive_type, API_D3D);
geometry_uid_checker.AddToIndexAndCheck(code, uid, "Geometry", "g");
}
@ -222,7 +222,7 @@ bool GeometryShaderCache::SetShader(u32 components)
// Need to compile a new shader
ShaderCode code;
GenerateGeometryShaderCode(code, components, API_D3D);
GenerateGeometryShaderCode(code, primitive_type, API_D3D);
D3DBlob* pbytecode;
if (!D3D::CompileGeometryShader(code.GetBuffer(), &pbytecode))

View File

@ -18,7 +18,7 @@ public:
static void Init();
static void Clear();
static void Shutdown();
static bool SetShader(u32 components); // TODO: Should be renamed to LoadShader
static bool SetShader(u32 primitive_type); // TODO: Should be renamed to LoadShader
static bool InsertByteCode(const GeometryShaderUid &uid, const void* bytecode, unsigned int bytecodelen);
static ID3D11GeometryShader* GeometryShaderCache::GetClearGeometryShader();

View File

@ -141,7 +141,7 @@ void VertexManager::Draw(u32 stride)
{
D3D::stateman->SetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
D3D::stateman->SetGeometryConstants(GeometryShaderCache::GetConstantBuffer());
D3D::stateman->SetGeometryShader(g_ActiveConfig.iStereoMode > 0 ? GeometryShaderCache::GetActiveShader() : nullptr);
D3D::stateman->SetGeometryShader(GeometryShaderCache::GetActiveShader());
D3D::stateman->Apply();
D3D::context->DrawIndexed(indices, startIndex, baseVertex);
@ -219,13 +219,10 @@ void VertexManager::vFlush(bool useDstAlpha)
return;
}
if (g_ActiveConfig.iStereoMode > 0)
if (!GeometryShaderCache::SetShader(current_primitive_type))
{
if (!GeometryShaderCache::SetShader(components))
{
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
return;
}
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR, true, { printf("Fail to set pixel shader\n"); });
return;
}
if (g_ActiveConfig.backend_info.bSupportsBBox && BoundingBox::active)

View File

@ -171,10 +171,10 @@ GLuint ProgramShaderCache::GetCurrentProgram()
return CurrentProgram;
}
SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type)
{
SHADERUID uid;
GetShaderId(&uid, dstAlphaMode, components);
GetShaderId(&uid, dstAlphaMode, components, primitive_type);
// Check if the shader is already set
if (last_entry)
@ -211,8 +211,7 @@ SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components
ShaderCode gcode;
GenerateVertexShaderCode(vcode, components, API_OPENGL);
GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components);
if (g_ActiveConfig.iStereoMode > 0)
GenerateGeometryShaderCode(gcode, components, API_OPENGL);
GenerateGeometryShaderCode(gcode, primitive_type, API_OPENGL);
if (g_ActiveConfig.bEnableShaderDebugging)
{
@ -395,7 +394,7 @@ GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const char* code)
return result;
}
void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components)
void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type)
{
GetPixelShaderUid(uid->puid, dstAlphaMode, API_OPENGL, components);
GetVertexShaderUid(uid->vuid, components, API_OPENGL);
@ -412,7 +411,7 @@ void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode,
vertex_uid_checker.AddToIndexAndCheck(vcode, uid->vuid, "Vertex", "v");
ShaderCode gcode;
GenerateGeometryShaderCode(gcode, components, API_OPENGL);
GenerateGeometryShaderCode(gcode, primitive_type, API_OPENGL);
geometry_uid_checker.AddToIndexAndCheck(gcode, uid->guid, "Geometry", "g");
}
}

View File

@ -88,8 +88,8 @@ public:
static PCacheEntry GetShaderProgram();
static GLuint GetCurrentProgram();
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type);
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode, const char* gcode = nullptr);
static GLuint CompileSingleShader(GLuint type, const char *code);

View File

@ -142,11 +142,11 @@ void VertexManager::vFlush(bool useDstAlpha)
// the same pass as regular rendering.
if (useDstAlpha && dualSourcePossible)
{
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, nativeVertexFmt->m_components);
ProgramShaderCache::SetShader(DSTALPHA_DUAL_SOURCE_BLEND, nativeVertexFmt->m_components, current_primitive_type);
}
else
{
ProgramShaderCache::SetShader(DSTALPHA_NONE, nativeVertexFmt->m_components);
ProgramShaderCache::SetShader(DSTALPHA_NONE, nativeVertexFmt->m_components, current_primitive_type);
}
// upload global constants
@ -160,7 +160,7 @@ void VertexManager::vFlush(bool useDstAlpha)
// run through vertex groups again to set alpha
if (useDstAlpha && !dualSourcePossible)
{
ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS, nativeVertexFmt->m_components);
ProgramShaderCache::SetShader(DSTALPHA_ALPHA_PASS, nativeVertexFmt->m_components, current_primitive_type);
// only update alpha
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);

View File

@ -12,7 +12,7 @@
static char text[16384];
template<class T>
static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiType)
static inline void GenerateGeometryShader(T& out, u32 primitive_type, API_TYPE ApiType)
{
// Non-uid template parameters will write to the dummy data (=> gets optimized out)
geometry_shader_uid_data dummy_data;
@ -26,8 +26,7 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
if (is_writing_shadercode)
text[sizeof(text) - 1] = 0x7C; // canary
out.Write("//Geometry Shader for 3D stereoscopy\n");
uid_data->primitive_type = primitive_type;
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
if (ApiType == API_OPENGL)
{
@ -156,12 +155,12 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
}
}
void GetGeometryShaderUid(GeometryShaderUid& object, u32 components, API_TYPE ApiType)
void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType)
{
GenerateGeometryShader<GeometryShaderUid>(object, components, ApiType);
GenerateGeometryShader<GeometryShaderUid>(object, primitive_type, ApiType);
}
void GenerateGeometryShaderCode(ShaderCode& object, u32 components, API_TYPE ApiType)
void GenerateGeometryShaderCode(ShaderCode& object, u32 primitive_type, API_TYPE ApiType)
{
GenerateGeometryShader<ShaderCode>(object, components, ApiType);
GenerateGeometryShader<ShaderCode>(object, primitive_type, ApiType);
}

View File

@ -16,11 +16,12 @@ struct geometry_shader_uid_data
u32 stereo : 1;
u32 numTexGens : 4;
u32 pixel_lighting : 1;
u32 primitive_type : 2;
};
#pragma pack()
typedef ShaderUid<geometry_shader_uid_data> GeometryShaderUid;
void GenerateGeometryShaderCode(ShaderCode& object, u32 components, API_TYPE ApiType);
void GetGeometryShaderUid(GeometryShaderUid& object, u32 components, API_TYPE ApiType);
void GenerateGeometryShaderCode(ShaderCode& object, u32 primitive_type, API_TYPE ApiType);
void GetGeometryShaderUid(GeometryShaderUid& object, u32 primitive_type, API_TYPE ApiType);