From 5ef8294375f1931fadea8205a4ab8145f05e1697 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 11 Jul 2022 13:03:54 +0100 Subject: [PATCH] Pass through include paths properly when compiling shaders. Closes #2646 --- renderdoc/driver/gl/gl_initstate.cpp | 13 +++++++++++-- renderdoc/driver/gl/gl_shader_refl.cpp | 14 +++++++------- renderdoc/driver/gl/gl_shader_refl.h | 4 ++-- renderdoc/driver/gl/wrappers/gl_shader_funcs.cpp | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/renderdoc/driver/gl/gl_initstate.cpp b/renderdoc/driver/gl/gl_initstate.cpp index f16db6b49..03786a139 100644 --- a/renderdoc/driver/gl/gl_initstate.cpp +++ b/renderdoc/driver/gl/gl_initstate.cpp @@ -1224,9 +1224,18 @@ bool GLResourceManager::Serialise_InitialState(SerialiserType &ser, ResourceId i for(size_t s = 0; s < shadDetails.sources.size(); s++) srcs[s] = (char *)shadDetails.sources[s].c_str(); drv.glShaderSource(shad, (GLsizei)shadDetails.sources.size(), srcs, NULL); - SAFE_DELETE_ARRAY(srcs); - drv.glCompileShader(shad); + + char **includes = new char *[shadDetails.includepaths.size()]; + for(size_t s = 0; s < shadDetails.includepaths.size(); s++) + includes[s] = (char *)shadDetails.includepaths[s].c_str(); + + if(shadDetails.includepaths.empty()) + drv.glCompileShader(shad); + else + drv.glCompileShaderIncludeARB(shad, (GLsizei)shadDetails.includepaths.size(), includes, + NULL); + SAFE_DELETE_ARRAY(includes); drv.glAttachShader(initProg, shad); drv.glDeleteShader(shad); } diff --git a/renderdoc/driver/gl/gl_shader_refl.cpp b/renderdoc/driver/gl/gl_shader_refl.cpp index 2b53f5471..29755c549 100644 --- a/renderdoc/driver/gl/gl_shader_refl.cpp +++ b/renderdoc/driver/gl/gl_shader_refl.cpp @@ -180,8 +180,8 @@ static bool iswhitespace(char c) return isspacetab(c) || isnewline(c); } -GLuint MakeSeparableShaderProgram(WrappedOpenGL &drv, GLenum type, rdcarray sources, - rdcarray *includepaths) +GLuint MakeSeparableShaderProgram(WrappedOpenGL &drv, GLenum type, const rdcarray &sources, + const rdcarray &includepaths) { // in and out blocks are added separately, in case one is there already const char *blockIdentifiers[2] = {"in gl_PerVertex", "out gl_PerVertex"}; @@ -216,13 +216,13 @@ GLuint MakeSeparableShaderProgram(WrappedOpenGL &drv, GLenum type, rdcarraysize(); + numPaths = (GLsizei)includepaths.size(); - paths = new const char *[includepaths->size()]; - for(size_t i = 0; i < includepaths->size(); i++) - paths[i] = (*includepaths)[i].c_str(); + paths = new const char *[includepaths.size()]; + for(size_t i = 0; i < includepaths.size(); i++) + paths[i] = includepaths[i].c_str(); } GLuint sepProg = CreateSepProgram(drv, type, (GLsizei)sources.size(), strings, numPaths, paths); diff --git a/renderdoc/driver/gl/gl_shader_refl.h b/renderdoc/driver/gl/gl_shader_refl.h index 6929b20da..6651a77f9 100644 --- a/renderdoc/driver/gl/gl_shader_refl.h +++ b/renderdoc/driver/gl/gl_shader_refl.h @@ -56,6 +56,6 @@ struct FixedFunctionVertexOutputs int ParseVersionStatement(const char *version); void MakeShaderReflection(GLenum shadType, GLuint sepProg, ShaderReflection &refl, const FixedFunctionVertexOutputs &outputUsage); -GLuint MakeSeparableShaderProgram(WrappedOpenGL &drv, GLenum type, rdcarray sources, - rdcarray *includepaths); +GLuint MakeSeparableShaderProgram(WrappedOpenGL &drv, GLenum type, const rdcarray &sources, + const rdcarray &includepaths); void CheckVertexOutputUses(const rdcarray &sources, FixedFunctionVertexOutputs &outputUsage); diff --git a/renderdoc/driver/gl/wrappers/gl_shader_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_shader_funcs.cpp index b9f099744..915170c23 100644 --- a/renderdoc/driver/gl/wrappers/gl_shader_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_shader_funcs.cpp @@ -225,7 +225,7 @@ void WrappedOpenGL::ShaderData::ProcessCompilation(WrappedOpenGL &drv, ResourceI // - this may or may not be emulated depending on if ARB_program_interface_query is supported. if(HasExt[ARB_separate_shader_objects]) { - GLuint sepProg = MakeSeparableShaderProgram(drv, type, sources, NULL); + GLuint sepProg = MakeSeparableShaderProgram(drv, type, sources, includepaths); if(sepProg == 0) {