Cache uniform locations and restructure the implementation
This commit is contained in:
parent
bcb5b924fd
commit
17315cee16
@ -885,18 +885,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
|
|||||||
void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
|
void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
|
||||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||||
|
|
||||||
glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(),
|
|
||||||
regs.alpha_test_enabled);
|
|
||||||
glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(),
|
|
||||||
regs.alpha_test_ref);
|
|
||||||
|
|
||||||
u32 func = static_cast<u32>(regs.alpha_test_func);
|
u32 func = static_cast<u32>(regs.alpha_test_func);
|
||||||
// Normalize the gl variants of opCompare to be the same as the normal variants
|
// Normalize the gl variants of opCompare to be the same as the normal variants
|
||||||
if (func >= 0x200) {
|
u32 op = static_cast<u32>(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never);
|
||||||
func = func - 0x200 + 1U;
|
if (func >= op) {
|
||||||
|
func = func - op + 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func);
|
shader->SetAlphaTesting(regs.alpha_test_enabled == 1, regs.alpha_test_ref, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncViewport() {
|
void RasterizerOpenGL::SyncViewport() {
|
||||||
@ -1026,18 +1022,6 @@ void RasterizerOpenGL::SyncLogicOpState() {
|
|||||||
state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
|
state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
void RasterizerOpenGL::SyncAlphaTest() {
|
|
||||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
|
||||||
|
|
||||||
// TODO(Rodrigo): Alpha testing is a legacy OpenGL feature, but it can be
|
|
||||||
// implemented with a test+discard in fragment shaders.
|
|
||||||
if (regs.alpha_test_enabled != 0) {
|
|
||||||
LOG_CRITICAL(Render_OpenGL, "Alpha testing is not implemented");
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RasterizerOpenGL::SyncScissorTest() {
|
void RasterizerOpenGL::SyncScissorTest() {
|
||||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||||
|
|
||||||
@ -1054,8 +1038,6 @@ void RasterizerOpenGL::SyncScissorTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> Remove SyncAlphaTest and clang format
|
|
||||||
void RasterizerOpenGL::SyncTransformFeedback() {
|
void RasterizerOpenGL::SyncTransformFeedback() {
|
||||||
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
|
||||||
|
|
||||||
|
@ -94,6 +94,10 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
|
|||||||
// Store shader's code to lazily build it on draw
|
// Store shader's code to lazily build it on draw
|
||||||
geometry_programs.code = program_result.first;
|
geometry_programs.code = program_result.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (program_type == Maxwell::ShaderProgram::Fragment) {
|
||||||
|
SaveAlphaTestingLocations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
|
GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
|
||||||
@ -134,16 +138,20 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
|
|||||||
return target_program.handle;
|
return target_program.handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
GLint CachedShader::GetAlphaTestingEnableLocation() {
|
void CachedShader::SetAlphaTesting(const bool enable, const float ref, const u32 func) {
|
||||||
return glGetUniformLocation(program.handle, "alpha_testing_enable");
|
if (program_type == Maxwell::ShaderProgram::Fragment) {
|
||||||
|
glProgramUniform1ui(program.handle, alpha_test.enable_loc,
|
||||||
|
(enable ? 1 : 0));
|
||||||
|
glProgramUniform1f(program.handle, alpha_test.ref_loc,
|
||||||
|
ref);
|
||||||
|
glProgramUniform1ui(program.handle, alpha_test.func_loc, func);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLint CachedShader::GetAlphaTestingFuncLocation() {
|
void CachedShader::SaveAlphaTestingLocations() {
|
||||||
return glGetUniformLocation(program.handle, "alpha_testing_func");
|
alpha_test.enable_loc = glGetUniformLocation(program.handle, "alpha_testing_enable");
|
||||||
}
|
alpha_test.ref_loc = glGetUniformLocation(program.handle, "alpha_testing_ref");
|
||||||
|
alpha_test.func_loc = glGetUniformLocation(program.handle, "alpha_testing_func");
|
||||||
GLint CachedShader::GetAlphaTestingRefLocation() {
|
|
||||||
return glGetUniformLocation(program.handle, "alpha_testing_ref");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
|
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
|
||||||
|
@ -73,15 +73,15 @@ public:
|
|||||||
/// Gets the GL uniform location for the specified resource, caching as needed
|
/// Gets the GL uniform location for the specified resource, caching as needed
|
||||||
GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
|
GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
|
||||||
|
|
||||||
GLint GetAlphaTestingEnableLocation();
|
void SetAlphaTesting(const bool enable, const float ref, const u32 func);
|
||||||
GLint GetAlphaTestingFuncLocation();
|
|
||||||
GLint GetAlphaTestingRefLocation();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Generates a geometry shader or returns one that already exists.
|
/// Generates a geometry shader or returns one that already exists.
|
||||||
GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
|
GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
|
||||||
const std::string& debug_name);
|
const std::string& debug_name);
|
||||||
|
|
||||||
|
void SaveAlphaTestingLocations();
|
||||||
|
|
||||||
VAddr addr;
|
VAddr addr;
|
||||||
Maxwell::ShaderProgram program_type;
|
Maxwell::ShaderProgram program_type;
|
||||||
GLShader::ShaderSetup setup;
|
GLShader::ShaderSetup setup;
|
||||||
@ -102,6 +102,12 @@ private:
|
|||||||
OGLProgram triangles_adjacency;
|
OGLProgram triangles_adjacency;
|
||||||
} geometry_programs;
|
} geometry_programs;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
GLint enable_loc;
|
||||||
|
GLint ref_loc;
|
||||||
|
GLint func_loc;
|
||||||
|
} alpha_test;
|
||||||
|
|
||||||
std::map<u32, GLuint> resource_cache;
|
std::map<u32, GLuint> resource_cache;
|
||||||
std::map<u32, GLint> uniform_cache;
|
std::map<u32, GLint> uniform_cache;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user