Sfoglia il codice sorgente

gl_rasterizer: Add a simple passthrough shader in lieu of shader generation.

bunnei 8 anni fa
parent
commit
f707c2dac4

+ 56 - 3
src/video_core/renderer_opengl/gl_rasterizer.cpp

@@ -54,6 +54,8 @@ static void SetShaderUniformBlockBindings(GLuint shader) {
 }
 }
 
 
 RasterizerOpenGL::RasterizerOpenGL() {
 RasterizerOpenGL::RasterizerOpenGL() {
+    shader_dirty = true;
+
     has_ARB_buffer_storage = false;
     has_ARB_buffer_storage = false;
     has_ARB_direct_state_access = false;
     has_ARB_direct_state_access = false;
     has_ARB_separate_shader_objects = false;
     has_ARB_separate_shader_objects = false;
@@ -106,8 +108,6 @@ RasterizerOpenGL::RasterizerOpenGL() {
         state.draw.vertex_buffer = stream_buffer->GetHandle();
         state.draw.vertex_buffer = stream_buffer->GetHandle();
 
 
         pipeline.Create();
         pipeline.Create();
-        vs_input_index_min = 0;
-        vs_input_index_max = 0;
         state.draw.program_pipeline = pipeline.handle;
         state.draw.program_pipeline = pipeline.handle;
         state.draw.shader_program = 0;
         state.draw.shader_program = 0;
         state.draw.vertex_array = hw_vao.handle;
         state.draw.vertex_array = hw_vao.handle;
@@ -233,7 +233,60 @@ bool RasterizerOpenGL::AccelerateDisplay(const void* config, PAddr framebuffer_a
 }
 }
 
 
 void RasterizerOpenGL::SetShader() {
 void RasterizerOpenGL::SetShader() {
-    UNIMPLEMENTED();
+    // TODO(bunnei): The below sets up a static test shader for passing untransformed vertices to
+    // OpenGL for rendering. This should be removed/replaced when we start emulating Maxwell
+    // shaders.
+
+    static constexpr char vertex_shader[] = R"(
+#version 150 core
+
+in vec2 vert_position;
+in vec2 vert_tex_coord;
+out vec2 frag_tex_coord;
+
+void main() {
+    // Multiply input position by the rotscale part of the matrix and then manually translate by
+    // the last column. This is equivalent to using a full 3x3 matrix and expanding the vector
+    // to `vec3(vert_position.xy, 1.0)`
+    gl_Position = vec4(mat2(mat3x2(0.0015625f, 0.0, 0.0, -0.0027778, -1.0, 1.0)) * vert_position + mat3x2(0.0015625f, 0.0, 0.0, -0.0027778, -1.0, 1.0)[2], 0.0, 1.0);
+    frag_tex_coord = vert_tex_coord;
+}
+)";
+
+    static constexpr char fragment_shader[] = R"(
+#version 150 core
+
+in vec2 frag_tex_coord;
+out vec4 color;
+
+uniform sampler2D color_texture;
+
+void main() {
+    color = vec4(1.0, 0.0, 0.0, 1.0);
+}
+)";
+
+    if (current_shader) {
+        return;
+    }
+
+    LOG_ERROR(HW_GPU, "Emulated shaders are not supported! Using a passthrough shader.");
+
+    current_shader = &test_shader;
+    if (has_ARB_separate_shader_objects) {
+        test_shader.shader.Create(vertex_shader, nullptr, fragment_shader, {}, true);
+        glActiveShaderProgram(pipeline.handle, test_shader.shader.handle);
+    } else {
+        ASSERT_MSG(false, "Unimplemented");
+    }
+
+    state.draw.shader_program = test_shader.shader.handle;
+    state.Apply();
+
+    if (has_ARB_separate_shader_objects) {
+        state.draw.shader_program = 0;
+        state.Apply();
+    }
 }
 }
 
 
 void RasterizerOpenGL::SyncClipEnabled() {
 void RasterizerOpenGL::SyncClipEnabled() {

+ 12 - 2
src/video_core/renderer_opengl/gl_rasterizer.h

@@ -42,6 +42,12 @@ public:
                            ScreenInfo& screen_info) override;
                            ScreenInfo& screen_info) override;
     bool AccelerateDrawBatch(bool is_indexed) override;
     bool AccelerateDrawBatch(bool is_indexed) override;
 
 
+    /// OpenGL shader generated for a given Maxwell register state
+    struct MaxwellShader {
+        /// OpenGL shader resource
+        OGLShader shader;
+    };
+
     struct VertexShader {
     struct VertexShader {
         OGLShader shader;
         OGLShader shader;
     };
     };
@@ -117,6 +123,12 @@ private:
 
 
     RasterizerCacheOpenGL res_cache;
     RasterizerCacheOpenGL res_cache;
 
 
+    /// Shader used for test renderering - to be removed once we have emulated shaders
+    MaxwellShader test_shader{};
+
+    const MaxwellShader* current_shader{};
+    bool shader_dirty{};
+
     struct {
     struct {
         UniformData data;
         UniformData data;
         bool dirty;
         bool dirty;
@@ -136,8 +148,6 @@ private:
     static constexpr size_t STREAM_BUFFER_SIZE = 4 * 1024 * 1024;
     static constexpr size_t STREAM_BUFFER_SIZE = 4 * 1024 * 1024;
     std::unique_ptr<OGLStreamBuffer> stream_buffer;
     std::unique_ptr<OGLStreamBuffer> stream_buffer;
 
 
-    GLint vs_input_index_min;
-    GLint vs_input_index_max;
     GLsizeiptr vs_input_size;
     GLsizeiptr vs_input_size;
 
 
     void AnalyzeVertexArray(bool is_indexed);
     void AnalyzeVertexArray(bool is_indexed);