Skip pass-thru tev stages, upper_bound calc once

This commit is contained in:
tfarley 2015-05-17 15:12:27 -07:00
parent dfc807daf9
commit 863edeefe0
4 changed files with 61 additions and 45 deletions

View File

@ -43,6 +43,7 @@ void RasterizerOpenGL::InitObjects() {
auto& uniform_tev = uniform_tev_cfgs[i]; auto& uniform_tev = uniform_tev_cfgs[i];
std::string tev_ref_str = "tev_cfgs[" + std::to_string(i) + "]"; std::string tev_ref_str = "tev_cfgs[" + std::to_string(i) + "]";
uniform_tev.enabled = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".enabled").c_str());
uniform_tev.color_sources = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".color_sources").c_str()); uniform_tev.color_sources = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".color_sources").c_str());
uniform_tev.alpha_sources = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".alpha_sources").c_str()); uniform_tev.alpha_sources = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".alpha_sources").c_str());
uniform_tev.color_modifiers = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".color_modifiers").c_str()); uniform_tev.color_modifiers = glGetUniformLocation(shader.GetHandle(), (tev_ref_str + ".color_modifiers").c_str());
@ -479,6 +480,17 @@ void RasterizerOpenGL::SyncDrawState() {
const auto& stage = tev_stages[tev_stage_idx]; const auto& stage = tev_stages[tev_stage_idx];
const auto& uniform_tev_cfg = uniform_tev_cfgs[tev_stage_idx]; const auto& uniform_tev_cfg = uniform_tev_cfgs[tev_stage_idx];
// No need to process the tev stage if it simply passes the previous stage results through
if (stage.color_op == Pica::Regs::TevStageConfig::Operation::Replace &&
stage.alpha_op == Pica::Regs::TevStageConfig::Operation::Replace &&
stage.color_source1 == Pica::Regs::TevStageConfig::Source::Previous &&
stage.alpha_source1 == Pica::Regs::TevStageConfig::Source::Previous &&
stage.color_modifier1 == Pica::Regs::TevStageConfig::ColorModifier::SourceColor &&
stage.alpha_modifier1 == Pica::Regs::TevStageConfig::AlphaModifier::SourceAlpha &&
stage.GetColorMultiplier() == 1 &&
stage.GetAlphaMultiplier() == 1) {
glUniform1i(uniform_tev_cfg.enabled, 0);
} else {
GLint color_srcs[3] = { (GLint)stage.color_source1.Value(), (GLint)stage.color_source2.Value(), (GLint)stage.color_source3.Value() }; GLint color_srcs[3] = { (GLint)stage.color_source1.Value(), (GLint)stage.color_source2.Value(), (GLint)stage.color_source3.Value() };
GLint alpha_srcs[3] = { (GLint)stage.alpha_source1.Value(), (GLint)stage.alpha_source2.Value(), (GLint)stage.alpha_source3.Value() }; GLint alpha_srcs[3] = { (GLint)stage.alpha_source1.Value(), (GLint)stage.alpha_source2.Value(), (GLint)stage.alpha_source3.Value() };
GLint color_mods[3] = { (GLint)stage.color_modifier1.Value(), (GLint)stage.color_modifier2.Value(), (GLint)stage.color_modifier3.Value() }; GLint color_mods[3] = { (GLint)stage.color_modifier1.Value(), (GLint)stage.color_modifier2.Value(), (GLint)stage.color_modifier3.Value() };
@ -488,6 +500,7 @@ void RasterizerOpenGL::SyncDrawState() {
stage.const_b / 255.0f, stage.const_b / 255.0f,
stage.const_a / 255.0f }; stage.const_a / 255.0f };
glUniform1i(uniform_tev_cfg.enabled, 1);
glUniform3iv(uniform_tev_cfg.color_sources, 1, color_srcs); glUniform3iv(uniform_tev_cfg.color_sources, 1, color_srcs);
glUniform3iv(uniform_tev_cfg.alpha_sources, 1, alpha_srcs); glUniform3iv(uniform_tev_cfg.alpha_sources, 1, alpha_srcs);
glUniform3iv(uniform_tev_cfg.color_modifiers, 1, color_mods); glUniform3iv(uniform_tev_cfg.color_modifiers, 1, color_mods);
@ -499,6 +512,7 @@ void RasterizerOpenGL::SyncDrawState() {
Pica::registers.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferColor(tev_stage_idx), Pica::registers.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferColor(tev_stage_idx),
Pica::registers.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferAlpha(tev_stage_idx)); Pica::registers.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferAlpha(tev_stage_idx));
} }
}
// Sync alpha testing to hw shader // Sync alpha testing to hw shader
if (Pica::registers.output_merger.alpha_test.enable) { if (Pica::registers.output_merger.alpha_test.enable) {

View File

@ -35,6 +35,7 @@ public:
private: private:
/// Structure used for managing texture environment states /// Structure used for managing texture environment states
struct TEVConfigUniforms { struct TEVConfigUniforms {
GLuint enabled;
GLuint color_sources; GLuint color_sources;
GLuint alpha_sources; GLuint alpha_sources;
GLuint color_modifiers; GLuint color_modifiers;

View File

@ -60,7 +60,9 @@ void RasterizerCacheOpenGL::LoadAndBindTexture(OpenGLState &state, int texture_u
void RasterizerCacheOpenGL::NotifyFlush(PAddr addr, u32 size) { void RasterizerCacheOpenGL::NotifyFlush(PAddr addr, u32 size) {
// Flush any texture that falls in the flushed region // Flush any texture that falls in the flushed region
for (auto it = texture_cache.begin(); it != texture_cache.upper_bound(addr + size);) { // TODO: Optimize by also inserting upper bound (addr + size) of each texture into the same map and also narrow using lower_bound
auto cache_upper_bound = texture_cache.upper_bound(addr + size);
for (auto it = texture_cache.begin(); it != cache_upper_bound;) {
PAddr max_low_addr_bound = std::max(addr, it->first); PAddr max_low_addr_bound = std::max(addr, it->first);
PAddr min_hi_addr_bound = std::min(addr + size, it->first + it->second->size); PAddr min_hi_addr_bound = std::min(addr + size, it->first + it->second->size);

View File

@ -144,6 +144,7 @@ uniform vec4 tev_combiner_buffer_color;
struct TEVConfig struct TEVConfig
{ {
bool enabled;
ivec3 color_sources; ivec3 color_sources;
ivec3 alpha_sources; ivec3 alpha_sources;
ivec3 color_modifiers; ivec3 color_modifiers;
@ -286,7 +287,11 @@ float AlphaCombine(int op, float alpha[3]) {
return 0.0; return 0.0;
} }
void ProcessTexEnv(int tex_env_idx) { void main(void) {
g_combiner_buffer = tev_combiner_buffer_color;
for (int tex_env_idx = 0; tex_env_idx < NUM_TEV_STAGES; ++tex_env_idx) {
if (tev_cfgs[tex_env_idx].enabled) {
g_const_color = tev_cfgs[tex_env_idx].const_color; g_const_color = tev_cfgs[tex_env_idx].const_color;
vec3 color_results[3] = vec3[3](GetColorModifier(tev_cfgs[tex_env_idx].color_modifiers.x, GetSource(tev_cfgs[tex_env_idx].color_sources.x)), vec3 color_results[3] = vec3[3](GetColorModifier(tev_cfgs[tex_env_idx].color_modifiers.x, GetSource(tev_cfgs[tex_env_idx].color_sources.x)),
@ -300,6 +305,7 @@ void ProcessTexEnv(int tex_env_idx) {
float alpha_output = AlphaCombine(tev_cfgs[tex_env_idx].color_alpha_op.y, alpha_results); float alpha_output = AlphaCombine(tev_cfgs[tex_env_idx].color_alpha_op.y, alpha_results);
g_last_tex_env_out = vec4(min(color_output * tev_cfgs[tex_env_idx].color_alpha_multiplier.x, 1.0), min(alpha_output * tev_cfgs[tex_env_idx].color_alpha_multiplier.y, 1.0)); g_last_tex_env_out = vec4(min(color_output * tev_cfgs[tex_env_idx].color_alpha_multiplier.x, 1.0), min(alpha_output * tev_cfgs[tex_env_idx].color_alpha_multiplier.y, 1.0));
}
if (tev_cfgs[tex_env_idx].updates_combiner_buffer_color_alpha.x) { if (tev_cfgs[tex_env_idx].updates_combiner_buffer_color_alpha.x) {
g_combiner_buffer.rgb = g_last_tex_env_out.rgb; g_combiner_buffer.rgb = g_last_tex_env_out.rgb;
@ -308,13 +314,6 @@ void ProcessTexEnv(int tex_env_idx) {
if (tev_cfgs[tex_env_idx].updates_combiner_buffer_color_alpha.y) { if (tev_cfgs[tex_env_idx].updates_combiner_buffer_color_alpha.y) {
g_combiner_buffer.a = g_last_tex_env_out.a; g_combiner_buffer.a = g_last_tex_env_out.a;
} }
}
void main(void) {
g_combiner_buffer = tev_combiner_buffer_color;
for (int i = 0; i < NUM_TEV_STAGES; ++i) {
ProcessTexEnv(i);
} }
if (alphatest_func == COMPAREFUNC_NEVER) { if (alphatest_func == COMPAREFUNC_NEVER) {