diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 15ae3c92002..117035d48e5 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -91,28 +91,4 @@ #include "main/context.h" -void -link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) -{ - prog->data->LinkStatus = LINKING_SUCCESS; /* All error paths will set this to false */ - prog->data->Validated = false; - /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec says: - * - * "Linking can fail for a variety of reasons as specified in the - * OpenGL Shading Language Specification, as well as any of the - * following reasons: - * - * - No shader objects are attached to program." - * - * The Compatibility Profile specification does not list the error. In - * Compatibility Profile missing shader stages are replaced by - * fixed-function. This applies to the case where all stages are - * missing. - */ - if (prog->NumShaders == 0) { - if (ctx->API != API_OPENGL_COMPAT) - linker_error(prog, "no shaders attached to the program\n"); - return; - } -} diff --git a/src/compiler/glsl/linker_util.cpp b/src/compiler/glsl/linker_util.cpp index d24e87086ad..22cccacd242 100644 --- a/src/compiler/glsl/linker_util.cpp +++ b/src/compiler/glsl/linker_util.cpp @@ -54,6 +54,32 @@ linker_warning(gl_shader_program *prog, const char *fmt, ...) } +void +link_shaders_init(struct gl_context *ctx, struct gl_shader_program *prog) +{ + prog->data->LinkStatus = LINKING_SUCCESS; /* All error paths will set this to false */ + prog->data->Validated = false; + + /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec says: + * + * "Linking can fail for a variety of reasons as specified in the + * OpenGL Shading Language Specification, as well as any of the + * following reasons: + * + * - No shader objects are attached to program." + * + * The Compatibility Profile specification does not list the error. In + * Compatibility Profile missing shader stages are replaced by + * fixed-function. This applies to the case where all stages are + * missing. + */ + if (prog->NumShaders == 0) { + if (ctx->API != API_OPENGL_COMPAT) + linker_error(prog, "no shaders attached to the program\n"); + return; + } +} + /** * Given a string identifying a program resource, break it into a base name * and an optional array index in square brackets. diff --git a/src/compiler/glsl/linker_util.h b/src/compiler/glsl/linker_util.h index f7965126700..da0a6cd88e0 100644 --- a/src/compiler/glsl/linker_util.h +++ b/src/compiler/glsl/linker_util.h @@ -28,6 +28,7 @@ #include "util/glheader.h" #include "compiler/glsl/list.h" #include "compiler/glsl_types.h" +#include "main/mtypes.h" #include "main/shader_types.h" struct gl_constants; @@ -84,6 +85,9 @@ struct array_deref_range { unsigned size; }; +void +link_shaders_init(struct gl_context *ctx, struct gl_shader_program *prog); + void linker_error(struct gl_shader_program *prog, const char *fmt, ...); diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index 783f77993dd..b1f14414eea 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -39,6 +39,7 @@ #include "gl_nir_linker.h" #include "glsl_parser_extras.h" #include "builtin_functions.h" +#include "linker_util.h" #include "main/mtypes.h" #include "program/program.h" @@ -427,7 +428,7 @@ standalone_compile_shader(const struct standalone_options *_options, _mesa_clear_shader_program_data(ctx, whole_program); whole_program->data->LinkStatus = LINKING_SUCCESS; - link_shaders(ctx, whole_program); + link_shaders_init(ctx, whole_program); gl_nir_link_glsl(ctx, whole_program); status = (whole_program->data->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/src/compiler/glsl/tests/test_gl_lower_mediump.cpp b/src/compiler/glsl/tests/test_gl_lower_mediump.cpp index 4997b8b1837..bfcf14c6a76 100644 --- a/src/compiler/glsl/tests/test_gl_lower_mediump.cpp +++ b/src/compiler/glsl/tests/test_gl_lower_mediump.cpp @@ -34,6 +34,7 @@ #include "gl_nir.h" #include "gl_nir_linker.h" #include "glsl_to_nir.h" +#include "linker_util.h" #include "nir_builder.h" #include "program.h" @@ -204,7 +205,7 @@ namespace ASSERT_EQ(shader->CompileStatus, COMPILE_SUCCESS); } - link_shaders(ctx, whole_program); + link_shaders_init(ctx, whole_program); gl_nir_link_glsl(ctx, whole_program); if (whole_program->data->LinkStatus != LINKING_SUCCESS) fprintf(stderr, "Linker error: %s", whole_program->data->InfoLog); diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index d70aff22922..e553a222368 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -986,7 +986,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) if (prog->data->LinkStatus) { if (!spirv) { - link_shaders(ctx, prog); + link_shaders_init(ctx, prog); #ifdef ENABLE_SHADER_CACHE shader_cache_read_program_metadata(ctx, prog);