2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

Cache uniform locations and restructure the implementation

This commit is contained in:
FernandoS27 2018-10-10 15:06:32 -04:00
parent bcb5b924fd
commit 17315cee16
3 changed files with 29 additions and 33 deletions

View file

@ -885,18 +885,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
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);
// Normalize the gl variants of opCompare to be the same as the normal variants
if (func >= 0x200) {
func = func - 0x200 + 1U;
u32 op = static_cast<u32>(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never);
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() {
@ -1026,18 +1022,6 @@ void RasterizerOpenGL::SyncLogicOpState() {
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() {
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
@ -1054,8 +1038,6 @@ void RasterizerOpenGL::SyncScissorTest() {
}
}
=======
>>>>>>> Remove SyncAlphaTest and clang format
void RasterizerOpenGL::SyncTransformFeedback() {
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;

View file

@ -94,6 +94,10 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
// Store shader's code to lazily build it on draw
geometry_programs.code = program_result.first;
}
if (program_type == Maxwell::ShaderProgram::Fragment) {
SaveAlphaTestingLocations();
}
}
GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
@ -134,16 +138,20 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
return target_program.handle;
};
GLint CachedShader::GetAlphaTestingEnableLocation() {
return glGetUniformLocation(program.handle, "alpha_testing_enable");
void CachedShader::SetAlphaTesting(const bool enable, const float ref, const u32 func) {
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() {
return glGetUniformLocation(program.handle, "alpha_testing_func");
}
GLint CachedShader::GetAlphaTestingRefLocation() {
return glGetUniformLocation(program.handle, "alpha_testing_ref");
void CachedShader::SaveAlphaTestingLocations() {
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");
}
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {

View file

@ -73,15 +73,15 @@ public:
/// Gets the GL uniform location for the specified resource, caching as needed
GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
GLint GetAlphaTestingEnableLocation();
GLint GetAlphaTestingFuncLocation();
GLint GetAlphaTestingRefLocation();
void SetAlphaTesting(const bool enable, const float ref, const u32 func);
private:
/// Generates a geometry shader or returns one that already exists.
GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
const std::string& debug_name);
void SaveAlphaTestingLocations();
VAddr addr;
Maxwell::ShaderProgram program_type;
GLShader::ShaderSetup setup;
@ -102,6 +102,12 @@ private:
OGLProgram triangles_adjacency;
} geometry_programs;
struct {
GLint enable_loc;
GLint ref_loc;
GLint func_loc;
} alpha_test;
std::map<u32, GLuint> resource_cache;
std::map<u32, GLint> uniform_cache;
};