summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sebastian Valle2018-05-20 12:57:32 -0500
committerGravatar GitHub2018-05-20 12:57:32 -0500
commit03388c3071bdece3cfb2fe65bdaeeef5eab0b2b9 (patch)
tree3a1ef76916ed44ddb052c20075e22ba87b30c215
parentMerge pull request #443 from ogniK5377/ipc-500 (diff)
parentGLRenderer: Log the shader source code when program linking fails. (diff)
downloadyuzu-03388c3071bdece3cfb2fe65bdaeeef5eab0b2b9.tar.gz
yuzu-03388c3071bdece3cfb2fe65bdaeeef5eab0b2b9.tar.xz
yuzu-03388c3071bdece3cfb2fe65bdaeeef5eab0b2b9.zip
Merge pull request #450 from Subv/shader_link_error
GLRenderer: Log the shader source code when program linking fails.
-rw-r--r--src/video_core/renderer_opengl/gl_shader_util.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h
index a1fa9e814..2036a06a9 100644
--- a/src/video_core/renderer_opengl/gl_shader_util.h
+++ b/src/video_core/renderer_opengl/gl_shader_util.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <string>
7#include <vector> 8#include <vector>
8#include <glad/glad.h> 9#include <glad/glad.h>
9#include "common/assert.h" 10#include "common/assert.h"
@@ -12,6 +13,27 @@
12namespace GLShader { 13namespace GLShader {
13 14
14/** 15/**
16 * Utility function to log the source code of a list of shaders.
17 * @param shaders The OpenGL shaders whose source we will print.
18 */
19template <typename... T>
20void LogShaderSource(T... shaders) {
21 auto shader_list = {shaders...};
22
23 for (const auto& shader : shader_list) {
24 if (shader == 0)
25 continue;
26
27 GLint source_length;
28 glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &source_length);
29
30 std::string source(source_length, ' ');
31 glGetShaderSource(shader, source_length, nullptr, &source[0]);
32 NGLOG_INFO(Render_OpenGL, "Shader source {}", source);
33 }
34}
35
36/**
15 * Utility function to create and compile an OpenGL GLSL shader 37 * Utility function to create and compile an OpenGL GLSL shader
16 * @param source String of the GLSL shader program 38 * @param source String of the GLSL shader program
17 * @param type Type of the shader (GL_VERTEX_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER) 39 * @param type Type of the shader (GL_VERTEX_SHADER, GL_GEOMETRY_SHADER or GL_FRAGMENT_SHADER)
@@ -55,6 +77,11 @@ GLuint LoadProgram(bool separable_program, T... shaders) {
55 } 77 }
56 } 78 }
57 79
80 if (result == GL_FALSE) {
81 // There was a problem linking the shader, print the source for debugging purposes.
82 LogShaderSource(shaders...);
83 }
84
58 ASSERT_MSG(result == GL_TRUE, "Shader not linked"); 85 ASSERT_MSG(result == GL_TRUE, "Shader not linked");
59 86
60 ((shaders == 0 ? (void)0 : glDetachShader(program_id, shaders)), ...); 87 ((shaders == 0 ? (void)0 : glDetachShader(program_id, shaders)), ...);