VideoCore: Split rasterizer regs from Regs struct

This commit is contained in:
Yuri Kunde Schlesner 2017-01-27 20:16:36 -08:00
parent 97e06b0a0d
commit 000e78144c
14 changed files with 219 additions and 188 deletions

View file

@ -197,13 +197,16 @@ void RasterizerOpenGL::DrawTriangles() {
// Sync the viewport
// These registers hold half-width and half-height, so must be multiplied by 2
GLsizei viewport_width = (GLsizei)Pica::float24::FromRaw(regs.viewport_size_x).ToFloat32() * 2;
GLsizei viewport_height = (GLsizei)Pica::float24::FromRaw(regs.viewport_size_y).ToFloat32() * 2;
GLsizei viewport_width =
(GLsizei)Pica::float24::FromRaw(regs.rasterizer.viewport_size_x).ToFloat32() * 2;
GLsizei viewport_height =
(GLsizei)Pica::float24::FromRaw(regs.rasterizer.viewport_size_y).ToFloat32() * 2;
glViewport((GLint)(rect.left + regs.viewport_corner.x * color_surface->res_scale_width),
(GLint)(rect.bottom + regs.viewport_corner.y * color_surface->res_scale_height),
(GLsizei)(viewport_width * color_surface->res_scale_width),
(GLsizei)(viewport_height * color_surface->res_scale_height));
glViewport(
(GLint)(rect.left + regs.rasterizer.viewport_corner.x * color_surface->res_scale_width),
(GLint)(rect.bottom + regs.rasterizer.viewport_corner.y * color_surface->res_scale_height),
(GLsizei)(viewport_width * color_surface->res_scale_width),
(GLsizei)(viewport_height * color_surface->res_scale_height));
if (uniform_block_data.data.framebuffer_scale[0] != color_surface->res_scale_width ||
uniform_block_data.data.framebuffer_scale[1] != color_surface->res_scale_height) {
@ -215,16 +218,16 @@ void RasterizerOpenGL::DrawTriangles() {
// Scissor checks are window-, not viewport-relative, which means that if the cached texture
// sub-rect changes, the scissor bounds also need to be updated.
GLint scissor_x1 =
static_cast<GLint>(rect.left + regs.scissor_test.x1 * color_surface->res_scale_width);
GLint scissor_y1 =
static_cast<GLint>(rect.bottom + regs.scissor_test.y1 * color_surface->res_scale_height);
GLint scissor_x1 = static_cast<GLint>(
rect.left + regs.rasterizer.scissor_test.x1 * color_surface->res_scale_width);
GLint scissor_y1 = static_cast<GLint>(
rect.bottom + regs.rasterizer.scissor_test.y1 * color_surface->res_scale_height);
// x2, y2 have +1 added to cover the entire pixel area, otherwise you might get cracks when
// scaling or doing multisampling.
GLint scissor_x2 =
static_cast<GLint>(rect.left + (regs.scissor_test.x2 + 1) * color_surface->res_scale_width);
GLint scissor_x2 = static_cast<GLint>(
rect.left + (regs.rasterizer.scissor_test.x2 + 1) * color_surface->res_scale_width);
GLint scissor_y2 = static_cast<GLint>(
rect.bottom + (regs.scissor_test.y2 + 1) * color_surface->res_scale_height);
rect.bottom + (regs.rasterizer.scissor_test.y2 + 1) * color_surface->res_scale_height);
if (uniform_block_data.data.scissor_x1 != scissor_x1 ||
uniform_block_data.data.scissor_x2 != scissor_x2 ||
@ -316,20 +319,20 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
switch (id) {
// Culling
case PICA_REG_INDEX(cull_mode):
case PICA_REG_INDEX(rasterizer.cull_mode):
SyncCullMode();
break;
// Depth modifiers
case PICA_REG_INDEX(viewport_depth_range):
case PICA_REG_INDEX(rasterizer.viewport_depth_range):
SyncDepthScale();
break;
case PICA_REG_INDEX(viewport_depth_near_plane):
case PICA_REG_INDEX(rasterizer.viewport_depth_near_plane):
SyncDepthOffset();
break;
// Depth buffering
case PICA_REG_INDEX(depthmap_enable):
case PICA_REG_INDEX(rasterizer.depthmap_enable):
shader_dirty = true;
break;
@ -398,7 +401,7 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
break;
// Scissor test
case PICA_REG_INDEX(scissor_test.mode):
case PICA_REG_INDEX(rasterizer.scissor_test.mode):
shader_dirty = true;
break;
@ -1110,30 +1113,31 @@ void RasterizerOpenGL::SetShader() {
void RasterizerOpenGL::SyncCullMode() {
const auto& regs = Pica::g_state.regs;
switch (regs.cull_mode) {
case Pica::Regs::CullMode::KeepAll:
switch (regs.rasterizer.cull_mode) {
case Pica::RasterizerRegs::CullMode::KeepAll:
state.cull.enabled = false;
break;
case Pica::Regs::CullMode::KeepClockWise:
case Pica::RasterizerRegs::CullMode::KeepClockWise:
state.cull.enabled = true;
state.cull.front_face = GL_CW;
break;
case Pica::Regs::CullMode::KeepCounterClockWise:
case Pica::RasterizerRegs::CullMode::KeepCounterClockWise:
state.cull.enabled = true;
state.cull.front_face = GL_CCW;
break;
default:
LOG_CRITICAL(Render_OpenGL, "Unknown cull mode %d", regs.cull_mode.Value());
LOG_CRITICAL(Render_OpenGL, "Unknown cull mode %d", regs.rasterizer.cull_mode.Value());
UNIMPLEMENTED();
break;
}
}
void RasterizerOpenGL::SyncDepthScale() {
float depth_scale = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_range).ToFloat32();
float depth_scale =
Pica::float24::FromRaw(Pica::g_state.regs.rasterizer.viewport_depth_range).ToFloat32();
if (depth_scale != uniform_block_data.data.depth_scale) {
uniform_block_data.data.depth_scale = depth_scale;
uniform_block_data.dirty = true;
@ -1142,7 +1146,7 @@ void RasterizerOpenGL::SyncDepthScale() {
void RasterizerOpenGL::SyncDepthOffset() {
float depth_offset =
Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_near_plane).ToFloat32();
Pica::float24::FromRaw(Pica::g_state.regs.rasterizer.viewport_depth_near_plane).ToFloat32();
if (depth_offset != uniform_block_data.data.depth_offset) {
uniform_block_data.data.depth_offset = depth_offset;
uniform_block_data.dirty = true;

View file

@ -52,9 +52,9 @@ union PicaShaderConfig {
const auto& regs = Pica::g_state.regs;
state.scissor_test_mode = regs.scissor_test.mode;
state.scissor_test_mode = regs.rasterizer.scissor_test.mode;
state.depthmap_enable = regs.depthmap_enable;
state.depthmap_enable = regs.rasterizer.depthmap_enable;
state.alpha_test_func = regs.output_merger.alpha_test.enable
? regs.output_merger.alpha_test.func.Value()
@ -172,12 +172,12 @@ union PicaShaderConfig {
struct State {
Pica::Regs::CompareFunc alpha_test_func;
Pica::Regs::ScissorMode scissor_test_mode;
Pica::RasterizerRegs::ScissorMode scissor_test_mode;
Pica::Regs::TextureConfig::TextureType texture0_type;
std::array<TevStageConfigRaw, 6> tev_stages;
u8 combiner_buffer_input;
Pica::Regs::DepthBuffering depthmap_enable;
Pica::RasterizerRegs::DepthBuffering depthmap_enable;
Pica::Regs::FogMode fog_mode;
bool fog_flip;

View file

@ -13,6 +13,7 @@
#include "video_core/renderer_opengl/gl_shader_util.h"
using Pica::Regs;
using Pica::RasterizerRegs;
using TevStageConfig = Regs::TevStageConfig;
namespace GLShader {
@ -639,10 +640,10 @@ vec4 secondary_fragment_color = vec4(0.0);
}
// Append the scissor test
if (state.scissor_test_mode != Regs::ScissorMode::Disabled) {
if (state.scissor_test_mode != RasterizerRegs::ScissorMode::Disabled) {
out += "if (";
// Negate the condition if we have to keep only the pixels outside the scissor box
if (state.scissor_test_mode == Regs::ScissorMode::Include)
if (state.scissor_test_mode == RasterizerRegs::ScissorMode::Include)
out += "!";
out += "(gl_FragCoord.x >= scissor_x1 && "
"gl_FragCoord.y >= scissor_y1 && "
@ -652,7 +653,7 @@ vec4 secondary_fragment_color = vec4(0.0);
out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n";
out += "float depth = z_over_w * depth_scale + depth_offset;\n";
if (state.depthmap_enable == Pica::Regs::DepthBuffering::WBuffering) {
if (state.depthmap_enable == Pica::RasterizerRegs::DepthBuffering::WBuffering) {
out += "depth /= gl_FragCoord.w;\n";
}