summaryrefslogtreecommitdiff
path: root/src/video_core/rasterizer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/rasterizer.cpp')
-rw-r--r--src/video_core/rasterizer.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp
index b83798b0f..000b4542b 100644
--- a/src/video_core/rasterizer.cpp
+++ b/src/video_core/rasterizer.cpp
@@ -215,14 +215,25 @@ static void SetStencil(int x, int y, u8 value) {
215 } 215 }
216} 216}
217 217
218// TODO: Should the stencil mask be applied to the "dest" or "ref" operands? Most likely not! 218// TODO: Should the stencil mask be applied to the "old_stencil" or "ref" operands? Most likely not!
219static u8 PerformStencilAction(Regs::StencilAction action, u8 dest, u8 ref) { 219static u8 PerformStencilAction(Regs::StencilAction action, u8 old_stencil, u8 ref) {
220 switch (action) { 220 switch (action) {
221 case Regs::StencilAction::Keep: 221 case Regs::StencilAction::Keep:
222 return dest; 222 return old_stencil;
223 223
224 case Regs::StencilAction::Xor: 224 case Regs::StencilAction::Replace:
225 return dest ^ ref; 225 return ref;
226
227 case Regs::StencilAction::Increment:
228 // Saturated increment
229 return std::min<u8>(old_stencil, 254) + 1;
230
231 case Regs::StencilAction::Decrement:
232 // Saturated decrement
233 return std::max<u8>(old_stencil, 1) - 1;
234
235 case Regs::StencilAction::Invert:
236 return ~old_stencil;
226 237
227 default: 238 default:
228 LOG_CRITICAL(HW_GPU, "Unknown stencil action %x", (int)action); 239 LOG_CRITICAL(HW_GPU, "Unknown stencil action %x", (int)action);
@@ -782,8 +793,8 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0,
782 u8 old_stencil = 0; 793 u8 old_stencil = 0;
783 if (stencil_action_enable) { 794 if (stencil_action_enable) {
784 old_stencil = GetStencil(x >> 4, y >> 4); 795 old_stencil = GetStencil(x >> 4, y >> 4);
785 u8 dest = old_stencil & stencil_test.mask; 796 u8 dest = old_stencil & stencil_test.input_mask;
786 u8 ref = stencil_test.reference_value & stencil_test.mask; 797 u8 ref = stencil_test.reference_value & stencil_test.input_mask;
787 798
788 bool pass = false; 799 bool pass = false;
789 switch (stencil_test.func) { 800 switch (stencil_test.func) {
@@ -821,8 +832,8 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0,
821 } 832 }
822 833
823 if (!pass) { 834 if (!pass) {
824 u8 new_stencil = PerformStencilAction(stencil_test.action_stencil_fail, old_stencil, stencil_test.replacement_value); 835 u8 new_stencil = PerformStencilAction(stencil_test.action_stencil_fail, old_stencil, stencil_test.reference_value);
825 SetStencil(x >> 4, y >> 4, new_stencil); 836 SetStencil(x >> 4, y >> 4, (new_stencil & stencil_test.write_mask) | (old_stencil & ~stencil_test.write_mask));
826 continue; 837 continue;
827 } 838 }
828 } 839 }
@@ -873,8 +884,8 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0,
873 884
874 if (!pass) { 885 if (!pass) {
875 if (stencil_action_enable) { 886 if (stencil_action_enable) {
876 u8 new_stencil = PerformStencilAction(stencil_test.action_depth_fail, old_stencil, stencil_test.replacement_value); 887 u8 new_stencil = PerformStencilAction(stencil_test.action_depth_fail, old_stencil, stencil_test.reference_value);
877 SetStencil(x >> 4, y >> 4, new_stencil); 888 SetStencil(x >> 4, y >> 4, (new_stencil & stencil_test.write_mask) | (old_stencil & ~stencil_test.write_mask));
878 } 889 }
879 continue; 890 continue;
880 } 891 }
@@ -884,8 +895,8 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0,
884 895
885 if (stencil_action_enable) { 896 if (stencil_action_enable) {
886 // TODO: What happens if stencil testing is enabled, but depth testing is not? Will stencil get updated anyway? 897 // TODO: What happens if stencil testing is enabled, but depth testing is not? Will stencil get updated anyway?
887 u8 new_stencil = PerformStencilAction(stencil_test.action_depth_pass, old_stencil, stencil_test.replacement_value); 898 u8 new_stencil = PerformStencilAction(stencil_test.action_depth_pass, old_stencil, stencil_test.reference_value);
888 SetStencil(x >> 4, y >> 4, new_stencil); 899 SetStencil(x >> 4, y >> 4, (new_stencil & stencil_test.write_mask) | (old_stencil & ~stencil_test.write_mask));
889 } 900 }
890 } 901 }
891 902