From 8aeff9cf8e84c27ab83cea8df1a94ce8082efc78 Mon Sep 17 00:00:00 2001
From: bunnei <bunneidev@gmail.com>
Date: Thu, 12 Jul 2018 22:57:57 -0400
Subject: [PATCH] gl_rasterizer: Fix check for if a shader stage is enabled.

---
 src/video_core/engines/maxwell_3d.cpp         | 21 -------------------
 src/video_core/engines/maxwell_3d.h           | 11 +++++++---
 .../renderer_opengl/gl_rasterizer.cpp         | 14 +++----------
 3 files changed, 11 insertions(+), 35 deletions(-)

diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 3bca16364e..dfbf80abdb 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -398,27 +398,6 @@ u32 Maxwell3D::GetRegisterValue(u32 method) const {
     return regs.reg_array[method];
 }
 
-bool Maxwell3D::IsShaderStageEnabled(Regs::ShaderStage stage) const {
-    // The Vertex stage is always enabled.
-    if (stage == Regs::ShaderStage::Vertex)
-        return true;
-
-    switch (stage) {
-    case Regs::ShaderStage::TesselationControl:
-        return regs.shader_config[static_cast<size_t>(Regs::ShaderProgram::TesselationControl)]
-                   .enable != 0;
-    case Regs::ShaderStage::TesselationEval:
-        return regs.shader_config[static_cast<size_t>(Regs::ShaderProgram::TesselationEval)]
-                   .enable != 0;
-    case Regs::ShaderStage::Geometry:
-        return regs.shader_config[static_cast<size_t>(Regs::ShaderProgram::Geometry)].enable != 0;
-    case Regs::ShaderStage::Fragment:
-        return regs.shader_config[static_cast<size_t>(Regs::ShaderProgram::Fragment)].enable != 0;
-    }
-
-    UNREACHABLE();
-}
-
 void Maxwell3D::ProcessClearBuffers() {
     ASSERT(regs.clear_buffers.R == regs.clear_buffers.G &&
            regs.clear_buffers.R == regs.clear_buffers.B &&
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 5a7cf01072..6f0170ff7c 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -379,6 +379,14 @@ public:
             }
         };
 
+        bool IsShaderConfigEnabled(size_t index) const {
+            // The VertexB is always enabled.
+            if (index == static_cast<size_t>(Regs::ShaderProgram::VertexB)) {
+                return true;
+            }
+            return shader_config[index].enable != 0;
+        }
+
         union {
             struct {
                 INSERT_PADDING_WORDS(0x45);
@@ -780,9 +788,6 @@ public:
     /// Returns the texture information for a specific texture in a specific shader stage.
     Texture::FullTextureInfo GetStageTexture(Regs::ShaderStage stage, size_t offset) const;
 
-    /// Returns whether the specified shader stage is enabled or not.
-    bool IsShaderStageEnabled(Regs::ShaderStage stage) const;
-
 private:
     std::unordered_map<u32, std::vector<u32>> uploaded_macros;
 
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 02ffd9bde3..4072a12b44 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -216,15 +216,13 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset) {
         auto& shader_config = gpu.regs.shader_config[index];
         const Maxwell::ShaderProgram program{static_cast<Maxwell::ShaderProgram>(index)};
 
-        const size_t stage{index == 0 ? 0 : index - 1}; // Stage indices are 0 - 5
-
-        const bool is_enabled = gpu.IsShaderStageEnabled(static_cast<Maxwell::ShaderStage>(stage));
-
         // Skip stages that are not enabled
-        if (!is_enabled) {
+        if (!gpu.regs.IsShaderConfigEnabled(index)) {
             continue;
         }
 
+        const size_t stage{index == 0 ? 0 : index - 1}; // Stage indices are 0 - 5
+
         GLShader::MaxwellUniformData ubo{};
         ubo.SetFromRegs(gpu.state.shader_stages[stage]);
         std::memcpy(buffer_ptr, &ubo, sizeof(ubo));
@@ -628,9 +626,6 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr
     auto& gpu = Core::System::GetInstance().GPU();
     auto& maxwell3d = gpu.Get3DEngine();
 
-    ASSERT_MSG(maxwell3d.IsShaderStageEnabled(stage),
-               "Attempted to upload constbuffer of disabled shader stage");
-
     // Reset all buffer draw state for this stage.
     for (auto& buffer : state.draw.const_buffers[static_cast<size_t>(stage)]) {
         buffer.bindpoint = 0;
@@ -697,9 +692,6 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, GLuint program,
     auto& gpu = Core::System::GetInstance().GPU();
     auto& maxwell3d = gpu.Get3DEngine();
 
-    ASSERT_MSG(maxwell3d.IsShaderStageEnabled(stage),
-               "Attempted to upload textures of disabled shader stage");
-
     ASSERT_MSG(current_unit + entries.size() <= std::size(state.texture_units),
                "Exceeded the number of active textures.");
 
-- 
GitLab