summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_util.cpp
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-07-14 08:48:30 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:40 +0200
commite1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5 (patch)
treeac6ddd37fd94fd2ccd693b4da0443ff28b75008d /src/video_core/renderer_opengl/gl_shader_util.cpp
parentshader: Implement ISETP.X (diff)
downloadyuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar.gz
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar.bz2
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar.lz
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar.xz
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.tar.zst
yuzu-e1ed218b418cd1ed94f6f25ccd0db86b63bd6bb5.zip
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_util.cpp')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_util.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_util.cpp b/src/video_core/renderer_opengl/gl_shader_util.cpp
index 5109985f1..d432072ad 100644
--- a/src/video_core/renderer_opengl/gl_shader_util.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_util.cpp
@@ -13,6 +13,33 @@
namespace OpenGL {
+static OGLProgram LinkSeparableProgram(GLuint shader) {
+ OGLProgram program;
+ program.handle = glCreateProgram();
+ glProgramParameteri(program.handle, GL_PROGRAM_SEPARABLE, GL_TRUE);
+ glAttachShader(program.handle, shader);
+ glLinkProgram(program.handle);
+ if (!Settings::values.renderer_debug) {
+ return program;
+ }
+ GLint link_status{};
+ glGetProgramiv(program.handle, GL_LINK_STATUS, &link_status);
+
+ GLint log_length{};
+ glGetProgramiv(program.handle, GL_INFO_LOG_LENGTH, &log_length);
+ if (log_length == 0) {
+ return program;
+ }
+ std::string log(log_length, 0);
+ glGetProgramInfoLog(program.handle, log_length, nullptr, log.data());
+ if (link_status == GL_FALSE) {
+ LOG_ERROR(Render_OpenGL, "{}", log);
+ } else {
+ LOG_WARNING(Render_OpenGL, "{}", log);
+ }
+ return program;
+}
+
static void LogShader(GLuint shader, std::string_view code = {}) {
GLint shader_status{};
glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_status);
@@ -36,7 +63,7 @@ static void LogShader(GLuint shader, std::string_view code = {}) {
}
}
-void AttachShader(GLenum stage, GLuint program, std::string_view code) {
+OGLProgram CreateProgram(std::string_view code, GLenum stage) {
OGLShader shader;
shader.handle = glCreateShader(stage);
@@ -44,45 +71,23 @@ void AttachShader(GLenum stage, GLuint program, std::string_view code) {
const GLchar* const code_ptr = code.data();
glShaderSource(shader.handle, 1, &code_ptr, &length);
glCompileShader(shader.handle);
- glAttachShader(program, shader.handle);
if (Settings::values.renderer_debug) {
LogShader(shader.handle, code);
}
+ return LinkSeparableProgram(shader.handle);
}
-void AttachShader(GLenum stage, GLuint program, std::span<const u32> code) {
+OGLProgram CreateProgram(std::span<const u32> code, GLenum stage) {
OGLShader shader;
shader.handle = glCreateShader(stage);
glShaderBinary(1, &shader.handle, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, code.data(),
static_cast<GLsizei>(code.size_bytes()));
glSpecializeShader(shader.handle, "main", 0, nullptr, nullptr);
- glAttachShader(program, shader.handle);
if (Settings::values.renderer_debug) {
LogShader(shader.handle);
}
-}
-
-void LinkProgram(GLuint program) {
- glLinkProgram(program);
- if (!Settings::values.renderer_debug) {
- return;
- }
- GLint link_status{};
- glGetProgramiv(program, GL_LINK_STATUS, &link_status);
-
- GLint log_length{};
- glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_length);
- if (log_length == 0) {
- return;
- }
- std::string log(log_length, 0);
- glGetProgramInfoLog(program, log_length, nullptr, log.data());
- if (link_status == GL_FALSE) {
- LOG_ERROR(Render_OpenGL, "{}", log);
- } else {
- LOG_WARNING(Render_OpenGL, "{}", log);
- }
+ return LinkSeparableProgram(shader.handle);
}
OGLAssemblyProgram CompileProgram(std::string_view code, GLenum target) {