From bbc7844021dc34e26285a495ed86bad088b87279 Mon Sep 17 00:00:00 2001
From: Yuri Kunde Schlesner <yuriks@yuriks.net>
Date: Sun, 18 Dec 2016 15:39:56 -0800
Subject: [PATCH] VideoCore: Change misleading register names

A few registers had names such as "count" or "number" when they actually
contained the maximum (that is, count - 1). This can easily lead to hard
to notice off by one errors.
---
 src/video_core/command_processor.cpp             | 5 +++--
 src/video_core/pica.h                            | 8 ++++----
 src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 +-
 src/video_core/renderer_opengl/gl_rasterizer.h   | 2 +-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index eb79974a8..9c0ed79c7 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -138,7 +138,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
 
                 immediate_input.attr[immediate_attribute_id++] = attribute;
 
-                if (immediate_attribute_id >= regs.vs.num_input_attributes + 1) {
+                if (immediate_attribute_id >= regs.vs.max_input_attribute_index + 1) {
                     MICROPROFILE_SCOPE(GPU_Drawing);
                     immediate_attribute_id = 0;
 
@@ -150,7 +150,8 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
                         g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation,
                                                  static_cast<void*>(&immediate_input));
                     Shader::UnitState shader_unit;
-                    shader_unit.LoadInputVertex(immediate_input, regs.vs.num_input_attributes + 1);
+                    shader_unit.LoadInputVertex(immediate_input,
+                                                regs.vs.max_input_attribute_index + 1);
                     shader_engine->Run(g_state.vs, shader_unit);
                     auto output_vertex = Shader::OutputVertex::FromRegisters(
                         shader_unit.registers.output, regs, regs.vs.output_mask);
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index b2db609ec..5afc9d5dd 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -868,7 +868,7 @@ struct Regs {
         LightSrc light[8];
         LightColor global_ambient; // Emission + (material.ambient * lighting.ambient)
         INSERT_PADDING_WORDS(0x1);
-        BitField<0, 3, u32> num_lights; // Number of enabled lights - 1
+        BitField<0, 3, u32> max_light_index; // Number of enabled lights - 1
 
         union {
             BitField<2, 2, LightingFresnelSelector> fresnel_selector;
@@ -1045,7 +1045,7 @@ struct Regs {
             BitField<48, 12, u64> attribute_mask;
 
             // number of total attributes minus 1
-            BitField<60, 4, u64> num_extra_attributes;
+            BitField<60, 4, u64> max_attribute_index;
         };
 
         inline VertexAttributeFormat GetFormat(int n) const {
@@ -1076,7 +1076,7 @@ struct Regs {
         }
 
         inline int GetNumTotalAttributes() const {
-            return (int)num_extra_attributes + 1;
+            return (int)max_attribute_index + 1;
         }
 
         // Attribute loaders map the source vertex data to input attributes
@@ -1214,7 +1214,7 @@ struct Regs {
 
         union {
             // Number of input attributes to shader unit - 1
-            BitField<0, 4, u32> num_input_attributes;
+            BitField<0, 4, u32> max_input_attribute_index;
         };
 
         // Offset to shader program entry point (in words)
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 2d2f4edc1..9dd9ae0fb 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -467,7 +467,7 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
 
     // Fragment lighting switches
     case PICA_REG_INDEX(lighting.disable):
-    case PICA_REG_INDEX(lighting.num_lights):
+    case PICA_REG_INDEX(lighting.max_light_index):
     case PICA_REG_INDEX(lighting.config0):
     case PICA_REG_INDEX(lighting.config1):
     case PICA_REG_INDEX(lighting.abs_lut_input):
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index cc3e4bed5..a1aa07074 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -84,7 +84,7 @@ union PicaShaderConfig {
         // Fragment lighting
 
         state.lighting.enable = !regs.lighting.disable;
-        state.lighting.src_num = regs.lighting.num_lights + 1;
+        state.lighting.src_num = regs.lighting.max_light_index + 1;
 
         for (unsigned light_index = 0; light_index < state.lighting.src_num; ++light_index) {
             unsigned num = regs.lighting.light_enable.GetNum(light_index);