Merge pull request #619 from Subv/flip_cull

GPU: Flip the triangle front face winding if the GPU is configured to not flip the triangles.
This commit is contained in:
bunnei 2018-07-04 12:13:38 -04:00 committed by GitHub
commit 2355460d7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -478,7 +478,9 @@ public:
u32 depth_write_enabled; u32 depth_write_enabled;
INSERT_PADDING_WORDS(0x8); INSERT_PADDING_WORDS(0x7);
u32 d3d_cull_mode;
BitField<0, 3, ComparisonOp> depth_test_func; BitField<0, 3, ComparisonOp> depth_test_func;
@ -498,7 +500,13 @@ public:
u32 enable[NumRenderTargets]; u32 enable[NumRenderTargets];
} blend; } blend;
INSERT_PADDING_WORDS(0x2D); INSERT_PADDING_WORDS(0xB);
union {
BitField<4, 1, u32> triangle_rast_flip;
} screen_y_control;
INSERT_PADDING_WORDS(0x21);
u32 vb_element_base; u32 vb_element_base;
@ -528,7 +536,12 @@ public:
} }
} tic; } tic;
INSERT_PADDING_WORDS(0x22); INSERT_PADDING_WORDS(0x21);
union {
BitField<2, 1, u32> coord_origin;
BitField<3, 10, u32> enable;
} point_coord_replace;
struct { struct {
u32 code_address_high; u32 code_address_high;
@ -818,11 +831,14 @@ ASSERT_REG_POSITION(rt_control, 0x487);
ASSERT_REG_POSITION(depth_test_enable, 0x4B3); ASSERT_REG_POSITION(depth_test_enable, 0x4B3);
ASSERT_REG_POSITION(independent_blend_enable, 0x4B9); ASSERT_REG_POSITION(independent_blend_enable, 0x4B9);
ASSERT_REG_POSITION(depth_write_enabled, 0x4BA); ASSERT_REG_POSITION(depth_write_enabled, 0x4BA);
ASSERT_REG_POSITION(d3d_cull_mode, 0x4C2);
ASSERT_REG_POSITION(depth_test_func, 0x4C3); ASSERT_REG_POSITION(depth_test_func, 0x4C3);
ASSERT_REG_POSITION(blend, 0x4CF); ASSERT_REG_POSITION(blend, 0x4CF);
ASSERT_REG_POSITION(screen_y_control, 0x4EB);
ASSERT_REG_POSITION(vb_element_base, 0x50D); ASSERT_REG_POSITION(vb_element_base, 0x50D);
ASSERT_REG_POSITION(tsc, 0x557); ASSERT_REG_POSITION(tsc, 0x557);
ASSERT_REG_POSITION(tic, 0x55D); ASSERT_REG_POSITION(tic, 0x55D);
ASSERT_REG_POSITION(point_coord_replace, 0x581);
ASSERT_REG_POSITION(code_address, 0x582); ASSERT_REG_POSITION(code_address, 0x582);
ASSERT_REG_POSITION(draw, 0x585); ASSERT_REG_POSITION(draw, 0x585);
ASSERT_REG_POSITION(index_array, 0x5F2); ASSERT_REG_POSITION(index_array, 0x5F2);

View File

@ -771,6 +771,16 @@ void RasterizerOpenGL::SyncCullMode() {
if (state.cull.enabled) { if (state.cull.enabled) {
state.cull.front_face = MaxwellToGL::FrontFace(regs.cull.front_face); state.cull.front_face = MaxwellToGL::FrontFace(regs.cull.front_face);
state.cull.mode = MaxwellToGL::CullFace(regs.cull.cull_face); state.cull.mode = MaxwellToGL::CullFace(regs.cull.cull_face);
// If the GPU is configured to flip the rasterized triangles, then we need to flip the
// notion of front and back. Note: We flip the triangles when the value of the register is 0
// because OpenGL already does it for us.
if (regs.screen_y_control.triangle_rast_flip == 0) {
if (state.cull.front_face == GL_CCW)
state.cull.front_face = GL_CW;
else if (state.cull.front_face == GL_CW)
state.cull.front_face = GL_CCW;
}
} }
} }