X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fshaderapi.c;h=f7080847cc1828ef9d66cdccff9662a1a17059e5;hb=a96e946d25d4518d1c73c5d9d0f3d147f42bc416;hp=b681534ddbf29cd0c373aee15def70e033d0d75f;hpb=9045ddcfe4ed2ecc6220db69dc33d6049956b99b;p=mesa.git diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index b681534ddbf..f7080847cc1 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -38,15 +38,18 @@ #include +#include #include "main/glheader.h" #include "main/context.h" -#include "main/dispatch.h" #include "main/enums.h" +#include "main/glspirv.h" #include "main/hash.h" #include "main/mtypes.h" #include "main/pipelineobj.h" +#include "main/program_binary.h" #include "main/shaderapi.h" #include "main/shaderobj.h" +#include "main/state.h" #include "main/transformfeedback.h" #include "main/uniforms.h" #include "compiler/glsl/glsl_parser_extras.h" @@ -59,11 +62,7 @@ #include "util/ralloc.h" #include "util/hash_table.h" #include "util/mesa-sha1.h" - -#ifdef _MSC_VER -#include -#define PATH_MAX _MAX_PATH -#endif +#include "util/crc32.h" /** * Return mask of GLSL_x flags by examining the MESA_GLSL env var. @@ -81,14 +80,14 @@ _mesa_get_shader_flags(void) flags |= GLSL_DUMP; if (strstr(env, "log")) flags |= GLSL_LOG; + if (strstr(env, "cache_fb")) + flags |= GLSL_CACHE_FALLBACK; + if (strstr(env, "cache_info")) + flags |= GLSL_CACHE_INFO; if (strstr(env, "nopvert")) flags |= GLSL_NOP_VERT; if (strstr(env, "nopfrag")) flags |= GLSL_NOP_FRAG; - if (strstr(env, "nopt")) - flags |= GLSL_NO_OPT; - else if (strstr(env, "opt")) - flags |= GLSL_OPT; if (strstr(env, "uniform")) flags |= GLSL_UNIFORMS; if (strstr(env, "useprog")) @@ -112,13 +111,6 @@ _mesa_get_shader_capture_path(void) if (!read_env_var) { path = getenv("MESA_SHADER_CAPTURE_PATH"); read_env_var = true; - if (path && - strlen(path) > PATH_MAX - strlen("/fp-4294967295.shader_test")) { - GET_CURRENT_CONTEXT(ctx); - _mesa_warning(ctx, "MESA_SHADER_CAPTURE_PATH too long; ignoring " - "request to capture shaders"); - path = NULL; - } } return path; @@ -151,8 +143,6 @@ _mesa_init_shader_state(struct gl_context *ctx) /* Extended for ARB_separate_shader_objects */ ctx->Shader.RefCount = 1; - mtx_init(&ctx->Shader.Mutex, mtx_plain); - ctx->TessCtrlProgram.patch_vertices = 3; for (i = 0; i < 4; ++i) ctx->TessCtrlProgram.patch_default_outer_level[i] = 1.0; @@ -167,20 +157,18 @@ _mesa_init_shader_state(struct gl_context *ctx) void _mesa_free_shader_state(struct gl_context *ctx) { - int i; - for (i = 0; i < MESA_SHADER_STAGES; i++) { - _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentProgram[i], + for (int i = 0; i < MESA_SHADER_STAGES; i++) { + _mesa_reference_program(ctx, &ctx->Shader.CurrentProgram[i], NULL); + _mesa_reference_shader_program(ctx, + &ctx->Shader.ReferencedPrograms[i], NULL); } - _mesa_reference_shader_program(ctx, &ctx->Shader._CurrentFragmentProgram, - NULL); _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL); /* Extended for ARB_separate_shader_objects */ _mesa_reference_pipeline_object(ctx, &ctx->_Shader, NULL); assert(ctx->Shader.RefCount == 1); - mtx_destroy(&ctx->Shader.Mutex); } @@ -262,7 +250,27 @@ is_shader(struct gl_context *ctx, GLuint name) * Attach shader to a shader program. */ static void -attach_shader(struct gl_context *ctx, GLuint program, GLuint shader) +attach_shader(struct gl_context *ctx, struct gl_shader_program *shProg, + struct gl_shader *sh) +{ + GLuint n = shProg->NumShaders; + + shProg->Shaders = realloc(shProg->Shaders, + (n + 1) * sizeof(struct gl_shader *)); + if (!shProg->Shaders) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader"); + return; + } + + /* append */ + shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */ + _mesa_reference_shader(ctx, &shProg->Shaders[n], sh); + shProg->NumShaders++; +} + +static void +attach_shader_err(struct gl_context *ctx, GLuint program, GLuint shader, + const char *caller) { struct gl_shader_program *shProg; struct gl_shader *sh; @@ -270,11 +278,11 @@ attach_shader(struct gl_context *ctx, GLuint program, GLuint shader) const bool same_type_disallowed = _mesa_is_gles(ctx); - shProg = _mesa_lookup_shader_program_err(ctx, program, "glAttachShader"); + shProg = _mesa_lookup_shader_program_err(ctx, program, caller); if (!shProg) return; - sh = _mesa_lookup_shader_err(ctx, shader, "glAttachShader"); + sh = _mesa_lookup_shader_err(ctx, shader, caller); if (!sh) { return; } @@ -288,7 +296,7 @@ attach_shader(struct gl_context *ctx, GLuint program, GLuint shader) * "The error INVALID_OPERATION is generated by AttachObjectARB * if is already attached to ." */ - _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader"); + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); return; } else if (same_type_disallowed && shProg->Shaders[i]->Stage == sh->Stage) { @@ -300,25 +308,25 @@ attach_shader(struct gl_context *ctx, GLuint program, GLuint shader) * is generated if [...] another shader object of the same type * as shader is already attached to program." */ - _mesa_error(ctx, GL_INVALID_OPERATION, "glAttachShader"); + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); return; } } - /* grow list */ - shProg->Shaders = realloc(shProg->Shaders, - (n + 1) * sizeof(struct gl_shader *)); - if (!shProg->Shaders) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader"); - return; - } - - /* append */ - shProg->Shaders[n] = NULL; /* since realloc() didn't zero the new space */ - _mesa_reference_shader(ctx, &shProg->Shaders[n], sh); - shProg->NumShaders++; + attach_shader(ctx, shProg, sh); } +static void +attach_shader_no_error(struct gl_context *ctx, GLuint program, GLuint shader) +{ + struct gl_shader_program *shProg; + struct gl_shader *sh; + + shProg = _mesa_lookup_shader_program(ctx, program); + sh = _mesa_lookup_shader(ctx, shader); + + attach_shader(ctx, shProg, sh); +} static GLuint create_shader(struct gl_context *ctx, GLenum type) @@ -326,12 +334,6 @@ create_shader(struct gl_context *ctx, GLenum type) struct gl_shader *sh; GLuint name; - if (!_mesa_validate_shader_target(ctx, type)) { - _mesa_error(ctx, GL_INVALID_ENUM, "CreateShader(%s)", - _mesa_enum_to_string(type)); - return 0; - } - _mesa_HashLockMutex(ctx->Shared->ShaderObjects); name = _mesa_HashFindFreeKeyBlock(ctx->Shared->ShaderObjects, 1); sh = _mesa_new_shader(name, _mesa_shader_enum_to_shader_stage(type)); @@ -343,6 +345,19 @@ create_shader(struct gl_context *ctx, GLenum type) } +static GLuint +create_shader_err(struct gl_context *ctx, GLenum type, const char *caller) +{ + if (!_mesa_validate_shader_target(ctx, type)) { + _mesa_error(ctx, GL_INVALID_ENUM, "%s(%s)", + caller, _mesa_enum_to_string(type)); + return 0; + } + + return create_shader(ctx, type); +} + + static GLuint create_shader_program(struct gl_context *ctx) { @@ -414,16 +429,21 @@ delete_shader(struct gl_context *ctx, GLuint shader) } -static void -detach_shader(struct gl_context *ctx, GLuint program, GLuint shader) +static ALWAYS_INLINE void +detach_shader(struct gl_context *ctx, GLuint program, GLuint shader, + bool no_error) { struct gl_shader_program *shProg; GLuint n; GLuint i, j; - shProg = _mesa_lookup_shader_program_err(ctx, program, "glDetachShader"); - if (!shProg) - return; + if (!no_error) { + shProg = _mesa_lookup_shader_program_err(ctx, program, "glDetachShader"); + if (!shProg) + return; + } else { + shProg = _mesa_lookup_shader_program(ctx, program); + } n = shProg->NumShaders; @@ -471,7 +491,7 @@ detach_shader(struct gl_context *ctx, GLuint program, GLuint shader) } /* not found */ - { + if (!no_error) { GLenum err; if (is_shader(ctx, shader) || is_program(ctx, shader)) err = GL_INVALID_OPERATION; @@ -483,12 +503,28 @@ detach_shader(struct gl_context *ctx, GLuint program, GLuint shader) } +static void +detach_shader_error(struct gl_context *ctx, GLuint program, GLuint shader) +{ + detach_shader(ctx, program, shader, false); +} + + +static void +detach_shader_no_error(struct gl_context *ctx, GLuint program, GLuint shader) +{ + detach_shader(ctx, program, shader, true); +} + + /** * Return list of shaders attached to shader program. + * \param objOut returns GLuint ids + * \param handleOut returns GLhandleARB handles */ static void get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount, - GLsizei *count, GLuint *obj) + GLsizei *countOut, GLuint *objOut, GLhandleARB *handleOut) { struct gl_shader_program *shProg; @@ -503,14 +539,20 @@ get_attached_shaders(struct gl_context *ctx, GLuint program, GLsizei maxCount, if (shProg) { GLuint i; for (i = 0; i < (GLuint) maxCount && i < shProg->NumShaders; i++) { - obj[i] = shProg->Shaders[i]->Name; + if (objOut) { + objOut[i] = shProg->Shaders[i]->Name; + } + + if (handleOut) { + handleOut[i] = (GLhandleARB) shProg->Shaders[i]->Name; + } + } + if (countOut) { + *countOut = i; } - if (count) - *count = i; } } - /** * glGetHandleARB() - return ID/name of currently bound shader program. */ @@ -544,7 +586,7 @@ get_handle(struct gl_context *ctx, GLenum pname) static bool check_gs_query(struct gl_context *ctx, const struct gl_shader_program *shProg) { - if (shProg->LinkStatus && + if (shProg->data->LinkStatus && shProg->_LinkedShaders[MESA_SHADER_GEOMETRY] != NULL) { return true; } @@ -569,7 +611,7 @@ check_gs_query(struct gl_context *ctx, const struct gl_shader_program *shProg) static bool check_tcs_query(struct gl_context *ctx, const struct gl_shader_program *shProg) { - if (shProg->LinkStatus && + if (shProg->data->LinkStatus && shProg->_LinkedShaders[MESA_SHADER_TESS_CTRL] != NULL) { return true; } @@ -595,7 +637,7 @@ check_tcs_query(struct gl_context *ctx, const struct gl_shader_program *shProg) static bool check_tes_query(struct gl_context *ctx, const struct gl_shader_program *shProg) { - if (shProg->LinkStatus && + if (shProg->data->LinkStatus && shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL] != NULL) { return true; } @@ -628,7 +670,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, /* True if geometry shaders (of the form that was adopted into GLSL 1.50 * and GL 3.2) are available in this context */ - const bool has_core_gs = _mesa_has_geometry_shaders(ctx); + const bool has_gs = _mesa_has_geometry_shaders(ctx); const bool has_tess = _mesa_has_tessellation(ctx); /* Are uniform buffer objects available in this context? @@ -648,13 +690,14 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, *params = shProg->DeletePending; return; case GL_LINK_STATUS: - *params = shProg->LinkStatus; + *params = shProg->data->LinkStatus ? GL_TRUE : GL_FALSE; return; case GL_VALIDATE_STATUS: - *params = shProg->Validated; + *params = shProg->data->Validated; return; case GL_INFO_LOG_LENGTH: - *params = shProg->InfoLog ? strlen(shProg->InfoLog) + 1 : 0; + *params = (shProg->data->InfoLog && shProg->data->InfoLog[0] != '\0') ? + strlen(shProg->data->InfoLog) + 1 : 0; return; case GL_ATTACHED_SHADERS: *params = shProg->NumShaders; @@ -668,9 +711,9 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, case GL_ACTIVE_UNIFORMS: { unsigned i; const unsigned num_uniforms = - shProg->NumUniformStorage - shProg->NumHiddenUniforms; + shProg->data->NumUniformStorage - shProg->data->NumHiddenUniforms; for (*params = 0, i = 0; i < num_uniforms; i++) { - if (!shProg->UniformStorage[i].is_shader_storage) + if (!shProg->data->UniformStorage[i].is_shader_storage) (*params)++; } return; @@ -679,17 +722,17 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, unsigned i; GLint max_len = 0; const unsigned num_uniforms = - shProg->NumUniformStorage - shProg->NumHiddenUniforms; + shProg->data->NumUniformStorage - shProg->data->NumHiddenUniforms; for (i = 0; i < num_uniforms; i++) { - if (shProg->UniformStorage[i].is_shader_storage) + if (shProg->data->UniformStorage[i].is_shader_storage) continue; /* Add one for the terminating NUL character for a non-array, and * 4 for the "[0]" and the NUL for an array. */ - const GLint len = strlen(shProg->UniformStorage[i].name) + 1 + - ((shProg->UniformStorage[i].array_elements != 0) ? 3 : 0); + const GLint len = strlen(shProg->data->UniformStorage[i].name) + 1 + + ((shProg->data->UniformStorage[i].array_elements != 0) ? 3 : 0); if (len > max_len) max_len = len; @@ -728,35 +771,35 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, *params = shProg->TransformFeedback.BufferMode; return; case GL_GEOMETRY_VERTICES_OUT: - if (!has_core_gs) + if (!has_gs) break; if (check_gs_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]-> - info.Geom.VerticesOut; + Program->info.gs.vertices_out; } return; case GL_GEOMETRY_SHADER_INVOCATIONS: - if (!has_core_gs || !ctx->Extensions.ARB_gpu_shader5) + if (!has_gs || !ctx->Extensions.ARB_gpu_shader5) break; if (check_gs_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]-> - info.Geom.Invocations; + Program->info.gs.invocations; } return; case GL_GEOMETRY_INPUT_TYPE: - if (!has_core_gs) + if (!has_gs) break; if (check_gs_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]-> - info.Geom.InputType; + Program->info.gs.input_primitive; } return; case GL_GEOMETRY_OUTPUT_TYPE: - if (!has_core_gs) + if (!has_gs) break; if (check_gs_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]-> - info.Geom.OutputType; + Program->info.gs.output_primitive; } return; case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: { @@ -766,10 +809,10 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, if (!has_ubo) break; - for (i = 0; i < shProg->NumUniformBlocks; i++) { + for (i = 0; i < shProg->data->NumUniformBlocks; i++) { /* Add one for the terminating NUL character. */ - const GLint len = strlen(shProg->UniformBlocks[i].Name) + 1; + const GLint len = strlen(shProg->data->UniformBlocks[i].Name) + 1; if (len > max_len) max_len = len; @@ -782,7 +825,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, if (!has_ubo) break; - *params = shProg->NumUniformBlocks; + *params = shProg->data->NumUniformBlocks; return; case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: /* This enum isn't part of the OES extension for OpenGL ES 2.0. It is @@ -797,19 +840,23 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, *params = shProg->BinaryRetreivableHint; return; case GL_PROGRAM_BINARY_LENGTH: - *params = 0; + if (ctx->Const.NumProgramBinaryFormats == 0 || !shProg->data->LinkStatus) { + *params = 0; + } else { + _mesa_get_program_binary_length(ctx, shProg, params); + } return; case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: if (!ctx->Extensions.ARB_shader_atomic_counters) break; - *params = shProg->NumAtomicBuffers; + *params = shProg->data->NumAtomicBuffers; return; case GL_COMPUTE_WORK_GROUP_SIZE: { int i; if (!_mesa_has_compute_shaders(ctx)) break; - if (!shProg->LinkStatus) { + if (!shProg->data->LinkStatus) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramiv(program not " "linked)"); return; @@ -820,12 +867,13 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, return; } for (i = 0; i < 3; i++) - params[i] = shProg->Comp.LocalSize[i]; + params[i] = shProg->_LinkedShaders[MESA_SHADER_COMPUTE]-> + Program->info.cs.local_size[i]; return; } case GL_PROGRAM_SEPARABLE: /* If the program has not been linked, return initial value 0. */ - *params = (shProg->LinkStatus == GL_FALSE) ? 0 : shProg->SeparateShader; + *params = (shProg->data->LinkStatus == LINKING_FAILURE) ? 0 : shProg->SeparateShader; return; /* ARB_tessellation_shader */ @@ -834,7 +882,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, break; if (check_tcs_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_TESS_CTRL]-> - info.TessCtrl.VerticesOut; + Program->info.tess.tcs_vertices_out; } return; case GL_TESS_GEN_MODE: @@ -842,15 +890,29 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, break; if (check_tes_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]-> - info.TessEval.PrimitiveMode; + Program->info.tess.primitive_mode; } return; case GL_TESS_GEN_SPACING: if (!has_tess) break; if (check_tes_query(ctx, shProg)) { - *params = shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]-> - info.TessEval.Spacing; + const struct gl_linked_shader *tes = + shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]; + switch (tes->Program->info.tess.spacing) { + case TESS_SPACING_EQUAL: + *params = GL_EQUAL; + break; + case TESS_SPACING_FRACTIONAL_ODD: + *params = GL_FRACTIONAL_ODD; + break; + case TESS_SPACING_FRACTIONAL_EVEN: + *params = GL_FRACTIONAL_EVEN; + break; + case TESS_SPACING_UNSPECIFIED: + *params = 0; + break; + } } return; case GL_TESS_GEN_VERTEX_ORDER: @@ -858,7 +920,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, break; if (check_tes_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]-> - info.TessEval.VertexOrder; + Program->info.tess.ccw ? GL_CCW : GL_CW; } return; case GL_TESS_GEN_POINT_MODE: @@ -866,7 +928,7 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, break; if (check_tes_query(ctx, shProg)) { *params = shProg->_LinkedShaders[MESA_SHADER_TESS_EVAL]-> - info.TessEval.PointMode; + Program->info.tess.point_mode ? GL_TRUE : GL_FALSE; } return; default: @@ -899,14 +961,18 @@ get_shaderiv(struct gl_context *ctx, GLuint name, GLenum pname, GLint *params) *params = shader->DeletePending; break; case GL_COMPILE_STATUS: - *params = shader->CompileStatus; + *params = shader->CompileStatus ? GL_TRUE : GL_FALSE; break; case GL_INFO_LOG_LENGTH: - *params = shader->InfoLog ? strlen(shader->InfoLog) + 1 : 0; + *params = (shader->InfoLog && shader->InfoLog[0] != '\0') ? + strlen(shader->InfoLog) + 1 : 0; break; case GL_SHADER_SOURCE_LENGTH: *params = shader->Source ? strlen((char *) shader->Source) + 1 : 0; break; + case GL_SPIR_V_BINARY_ARB: + *params = (shader->spirv_data != NULL); + break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glGetShaderiv(pname)"); return; @@ -937,7 +1003,7 @@ get_program_info_log(struct gl_context *ctx, GLuint program, GLsizei bufSize, return; } - _mesa_copy_string(infoLog, bufSize, length, shProg->InfoLog); + _mesa_copy_string(infoLog, bufSize, length, shProg->data->InfoLog); } @@ -994,15 +1060,34 @@ get_shader_source(struct gl_context *ctx, GLuint shader, GLsizei maxLength, * glShaderSource[ARB]. */ static void -shader_source(struct gl_shader *sh, const GLchar *source) +set_shader_source(struct gl_shader *sh, const GLchar *source) { assert(sh); - /* free old shader source string and install new one */ - free((void *)sh->Source); - sh->Source = source; + /* The GL_ARB_gl_spirv spec adds the following to the end of the description + * of ShaderSource: + * + * "If was previously associated with a SPIR-V module (via the + * ShaderBinary command), that association is broken. Upon successful + * completion of this command the SPIR_V_BINARY_ARB state of + * is set to FALSE." + */ + _mesa_shader_spirv_data_reference(&sh->spirv_data, NULL); + + if (sh->CompileStatus == COMPILE_SKIPPED && !sh->FallbackSource) { + /* If shader was previously compiled back-up the source in case of cache + * fallback. + */ + sh->FallbackSource = sh->Source; + sh->Source = source; + } else { + /* free old shader source string and install new one */ + free((void *)sh->Source); + sh->Source = source; + } + #ifdef DEBUG - sh->SourceChecksum = _mesa_str_checksum(sh->Source); + sh->SourceChecksum = util_hash_crc32(sh->Source, strlen(sh->Source)); #endif } @@ -1016,11 +1101,23 @@ _mesa_compile_shader(struct gl_context *ctx, struct gl_shader *sh) if (!sh) return; + /* The GL_ARB_gl_spirv spec says: + * + * "Add a new error for the CompileShader command: + * + * An INVALID_OPERATION error is generated if the SPIR_V_BINARY_ARB + * state of is TRUE." + */ + if (sh->spirv_data) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glCompileShader(SPIR-V)"); + return; + } + if (!sh->Source) { /* If the user called glCompileShader without first calling * glShaderSource, we should fail to compile, but not raise a GL_ERROR. */ - sh->CompileStatus = GL_FALSE; + sh->CompileStatus = COMPILE_FAILURE; } else { if (ctx->_Shader->Flags & GLSL_DUMP) { _mesa_log("GLSL source for %s shader %d:\n", @@ -1031,7 +1128,7 @@ _mesa_compile_shader(struct gl_context *ctx, struct gl_shader *sh) /* this call will set the shader->CompileStatus field to indicate if * compilation was successful. */ - _mesa_glsl_compile_shader(ctx, sh, false, false); + _mesa_glsl_compile_shader(ctx, sh, false, false, false); if (ctx->_Shader->Flags & GLSL_LOG) { _mesa_write_shader_to_file(sh); @@ -1076,41 +1173,71 @@ _mesa_compile_shader(struct gl_context *ctx, struct gl_shader *sh) /** * Link a program's shaders. */ -void -_mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg) +static ALWAYS_INLINE void +link_program(struct gl_context *ctx, struct gl_shader_program *shProg, + bool no_error) { if (!shProg) return; - /* From the ARB_transform_feedback2 specification: - * "The error INVALID_OPERATION is generated by LinkProgram if is - * the name of a program being used by one or more transform feedback - * objects, even if the objects are not currently bound or are paused." - */ - if (_mesa_transform_feedback_is_using_program(ctx, shProg)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glLinkProgram(transform feedback is using the program)"); - return; + if (!no_error) { + /* From the ARB_transform_feedback2 specification: + * "The error INVALID_OPERATION is generated by LinkProgram if + * is the name of a program being used by one or more transform feedback + * objects, even if the objects are not currently bound or are paused." + */ + if (_mesa_transform_feedback_is_using_program(ctx, shProg)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glLinkProgram(transform feedback is using the program)"); + return; + } } - FLUSH_VERTICES(ctx, _NEW_PROGRAM); + unsigned programs_in_use = 0; + if (ctx->_Shader) + for (unsigned stage = 0; stage < MESA_SHADER_STAGES; stage++) { + if (ctx->_Shader->CurrentProgram[stage] && + ctx->_Shader->CurrentProgram[stage]->Id == shProg->Name) { + programs_in_use |= 1 << stage; + } + } + FLUSH_VERTICES(ctx, 0); _mesa_glsl_link_shader(ctx, shProg); + /* From section 7.3 (Program Objects) of the OpenGL 4.5 spec: + * + * "If LinkProgram or ProgramBinary successfully re-links a program + * object that is active for any shader stage, then the newly generated + * executable code will be installed as part of the current rendering + * state for all shader stages where the program is active. + * Additionally, the newly generated executable code is made part of + * the state of any program pipeline for all stages where the program + * is attached." + */ + if (shProg->data->LinkStatus && programs_in_use) { + while (programs_in_use) { + const int stage = u_bit_scan(&programs_in_use); + + struct gl_program *prog = NULL; + if (shProg->_LinkedShaders[stage]) + prog = shProg->_LinkedShaders[stage]->Program; + + _mesa_use_program(ctx, stage, shProg, prog, ctx->_Shader); + } + } + /* Capture .shader_test files. */ const char *capture_path = _mesa_get_shader_capture_path(); if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) { FILE *file; - char filename[PATH_MAX]; - - _mesa_snprintf(filename, sizeof(filename), "%s/%u.shader_test", - capture_path, shProg->Name); - + char *filename = ralloc_asprintf(NULL, "%s/%u.shader_test", + capture_path, shProg->Name); file = fopen(filename, "w"); if (file) { fprintf(file, "[require]\nGLSL%s >= %u.%02u\n", shProg->IsES ? " ES" : "", - shProg->Version / 100, shProg->Version % 100); + shProg->data->Version / 100, shProg->data->Version % 100); if (shProg->SeparateShader) fprintf(file, "GL_ARB_separate_shader_objects\nSSO ENABLED\n"); fprintf(file, "\n"); @@ -1124,21 +1251,25 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg) } else { _mesa_warning(ctx, "Failed to open %s", filename); } + + ralloc_free(filename); } - if (shProg->LinkStatus == GL_FALSE && + if (shProg->data->LinkStatus == LINKING_FAILURE && (ctx->_Shader->Flags & GLSL_REPORT_ERRORS)) { _mesa_debug(ctx, "Error linking program %u:\n%s\n", - shProg->Name, shProg->InfoLog); + shProg->Name, shProg->data->InfoLog); } + _mesa_update_vertex_processing_mode(ctx); + /* debug code */ if (0) { GLuint i; printf("Link %u shaders in program %u: %s\n", shProg->NumShaders, shProg->Name, - shProg->LinkStatus ? "Success" : "Failed"); + shProg->data->LinkStatus ? "Success" : "Failed"); for (i = 0; i < shProg->NumShaders; i++) { printf(" shader %u, stage %u\n", @@ -1149,6 +1280,27 @@ _mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg) } +static void +link_program_error(struct gl_context *ctx, struct gl_shader_program *shProg) +{ + link_program(ctx, shProg, false); +} + + +static void +link_program_no_error(struct gl_context *ctx, struct gl_shader_program *shProg) +{ + link_program(ctx, shProg, true); +} + + +void +_mesa_link_program(struct gl_context *ctx, struct gl_shader_program *shProg) +{ + link_program_error(ctx, shProg); +} + + /** * Print basic shader info (for debug). */ @@ -1159,10 +1311,16 @@ print_shader_info(const struct gl_shader_program *shProg) printf("Mesa: glUseProgram(%u)\n", shProg->Name); for (i = 0; i < shProg->NumShaders; i++) { +#ifdef DEBUG printf(" %s shader %u, checksum %u\n", _mesa_shader_stage_to_string(shProg->Shaders[i]->Stage), shProg->Shaders[i]->Name, shProg->Shaders[i]->SourceChecksum); +#else + printf(" %s shader %u\n", + _mesa_shader_stage_to_string(shProg->Shaders[i]->Stage), + shProg->Shaders[i]->Name); +#endif } if (shProg->_LinkedShaders[MESA_SHADER_VERTEX]) printf(" vert prog %u\n", @@ -1189,7 +1347,7 @@ void _mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg, const char *caller) { - if ((shProg != NULL) && !shProg->LinkStatus) { + if ((shProg != NULL) && !shProg->data->LinkStatus) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program %u not linked)", caller, shProg->Name); return; @@ -1201,62 +1359,19 @@ _mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg, } -static void -use_shader_program(struct gl_context *ctx, gl_shader_stage stage, - struct gl_shader_program *shProg, - struct gl_pipeline_object *shTarget) -{ - struct gl_shader_program **target; - - target = &shTarget->CurrentProgram[stage]; - if ((shProg != NULL) && (shProg->_LinkedShaders[stage] == NULL)) - shProg = NULL; - - if (shProg) - _mesa_shader_program_init_subroutine_defaults(ctx, shProg); - - if (*target != shProg) { - /* Program is current, flush it */ - if (shTarget == ctx->_Shader) { - FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS); - } - - /* If the shader is also bound as the current rendering shader, unbind - * it from that binding point as well. This ensures that the correct - * semantics of glDeleteProgram are maintained. - */ - switch (stage) { - case MESA_SHADER_VERTEX: - case MESA_SHADER_TESS_CTRL: - case MESA_SHADER_TESS_EVAL: - case MESA_SHADER_GEOMETRY: - case MESA_SHADER_COMPUTE: - /* Empty for now. */ - break; - case MESA_SHADER_FRAGMENT: - if (*target == ctx->_Shader->_CurrentFragmentProgram) { - _mesa_reference_shader_program(ctx, - &ctx->_Shader->_CurrentFragmentProgram, - NULL); - } - break; - } - - _mesa_reference_shader_program(ctx, target, shProg); - return; - } -} - - /** * Use the named shader program for subsequent rendering. */ void -_mesa_use_program(struct gl_context *ctx, struct gl_shader_program *shProg) +_mesa_use_shader_program(struct gl_context *ctx, + struct gl_shader_program *shProg) { - int i; - for (i = 0; i < MESA_SHADER_STAGES; i++) - use_shader_program(ctx, i, shProg, &ctx->Shader); + for (int i = 0; i < MESA_SHADER_STAGES; i++) { + struct gl_program *new_prog = NULL; + if (shProg && shProg->_LinkedShaders[i]) + new_prog = shProg->_LinkedShaders[i]->Program; + _mesa_use_program(ctx, i, shProg, new_prog, &ctx->Shader); + } _mesa_active_program(ctx, shProg, "glUseProgram"); } @@ -1270,7 +1385,7 @@ static GLboolean validate_shader_program(const struct gl_shader_program *shProg, char *errMsg) { - if (!shProg->LinkStatus) { + if (!shProg->data->LinkStatus) { return GL_FALSE; } @@ -1314,23 +1429,38 @@ validate_program(struct gl_context *ctx, GLuint program) return; } - shProg->Validated = validate_shader_program(shProg, errMsg); - if (!shProg->Validated) { + shProg->data->Validated = validate_shader_program(shProg, errMsg); + if (!shProg->data->Validated) { /* update info log */ - if (shProg->InfoLog) { - ralloc_free(shProg->InfoLog); + if (shProg->data->InfoLog) { + ralloc_free(shProg->data->InfoLog); } - shProg->InfoLog = ralloc_strdup(shProg, errMsg); + shProg->data->InfoLog = ralloc_strdup(shProg->data, errMsg); } } +void GLAPIENTRY +_mesa_AttachObjectARB_no_error(GLhandleARB program, GLhandleARB shader) +{ + GET_CURRENT_CONTEXT(ctx); + attach_shader_no_error(ctx, program, shader); +} + void GLAPIENTRY _mesa_AttachObjectARB(GLhandleARB program, GLhandleARB shader) { GET_CURRENT_CONTEXT(ctx); - attach_shader(ctx, program, shader); + attach_shader_err(ctx, program, shader, "glAttachObjectARB"); +} + + +void GLAPIENTRY +_mesa_AttachShader_no_error(GLuint program, GLuint shader) +{ + GET_CURRENT_CONTEXT(ctx); + attach_shader_no_error(ctx, program, shader); } @@ -1338,7 +1468,7 @@ void GLAPIENTRY _mesa_AttachShader(GLuint program, GLuint shader) { GET_CURRENT_CONTEXT(ctx); - attach_shader(ctx, program, shader); + attach_shader_err(ctx, program, shader, "glAttachShader"); } @@ -1353,12 +1483,30 @@ _mesa_CompileShader(GLuint shaderObj) } +GLuint GLAPIENTRY +_mesa_CreateShader_no_error(GLenum type) +{ + GET_CURRENT_CONTEXT(ctx); + return create_shader(ctx, type); +} + + GLuint GLAPIENTRY _mesa_CreateShader(GLenum type) { GET_CURRENT_CONTEXT(ctx); + if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glCreateShader %s\n", _mesa_enum_to_string(type)); + + return create_shader_err(ctx, type, "glCreateShader"); +} + + +GLhandleARB GLAPIENTRY +_mesa_CreateShaderObjectARB_no_error(GLenum type) +{ + GET_CURRENT_CONTEXT(ctx); return create_shader(ctx, type); } @@ -1367,7 +1515,7 @@ GLhandleARB GLAPIENTRY _mesa_CreateShaderObjectARB(GLenum type) { GET_CURRENT_CONTEXT(ctx); - return create_shader(ctx, type); + return create_shader_err(ctx, type, "glCreateShaderObjectARB"); } @@ -1435,11 +1583,27 @@ _mesa_DeleteShader(GLuint name) } +void GLAPIENTRY +_mesa_DetachObjectARB_no_error(GLhandleARB program, GLhandleARB shader) +{ + GET_CURRENT_CONTEXT(ctx); + detach_shader_no_error(ctx, program, shader); +} + + void GLAPIENTRY _mesa_DetachObjectARB(GLhandleARB program, GLhandleARB shader) { GET_CURRENT_CONTEXT(ctx); - detach_shader(ctx, program, shader); + detach_shader_error(ctx, program, shader); +} + + +void GLAPIENTRY +_mesa_DetachShader_no_error(GLuint program, GLuint shader) +{ + GET_CURRENT_CONTEXT(ctx); + detach_shader_no_error(ctx, program, shader); } @@ -1447,7 +1611,7 @@ void GLAPIENTRY _mesa_DetachShader(GLuint program, GLuint shader) { GET_CURRENT_CONTEXT(ctx); - detach_shader(ctx, program, shader); + detach_shader_error(ctx, program, shader); } @@ -1456,7 +1620,7 @@ _mesa_GetAttachedObjectsARB(GLhandleARB container, GLsizei maxCount, GLsizei * count, GLhandleARB * obj) { GET_CURRENT_CONTEXT(ctx); - get_attached_shaders(ctx, container, maxCount, count, obj); + get_attached_shaders(ctx, (GLuint)container, maxCount, count, NULL, obj); } @@ -1465,7 +1629,7 @@ _mesa_GetAttachedShaders(GLuint program, GLsizei maxCount, GLsizei *count, GLuint *obj) { GET_CURRENT_CONTEXT(ctx); - get_attached_shaders(ctx, program, maxCount, count, obj); + get_attached_shaders(ctx, program, maxCount, count, obj, NULL); } @@ -1590,17 +1754,31 @@ _mesa_IsShader(GLuint name) } +void GLAPIENTRY +_mesa_LinkProgram_no_error(GLuint programObj) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_shader_program *shProg = + _mesa_lookup_shader_program(ctx, programObj); + link_program_no_error(ctx, shProg); +} + + void GLAPIENTRY _mesa_LinkProgram(GLuint programObj) { GET_CURRENT_CONTEXT(ctx); + if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glLinkProgram %u\n", programObj); - _mesa_link_program(ctx, _mesa_lookup_shader_program_err(ctx, programObj, - "glLinkProgram")); + + struct gl_shader_program *shProg = + _mesa_lookup_shader_program_err(ctx, programObj, "glLinkProgram"); + link_program_error(ctx, shProg); } -#if defined(HAVE_SHA1) +#ifdef ENABLE_SHADER_CACHE /** * Generate a SHA-1 hash value string for given source string. */ @@ -1618,9 +1796,9 @@ generate_sha1(const char *source, char sha_str[64]) * * /_.glsl */ -static void +static char * construct_name(const gl_shader_stage stage, const char *source, - const char *path, char *name, unsigned length) + const char *path) { char sha[64]; static const char *types[] = { @@ -1628,8 +1806,7 @@ construct_name(const gl_shader_stage stage, const char *source, }; generate_sha1(source, sha); - _mesa_snprintf(name, length, "%s/%s_%s.glsl", path, types[stage], - sha); + return ralloc_asprintf(NULL, "%s/%s_%s.glsl", path, types[stage], sha); } /** @@ -1638,7 +1815,6 @@ construct_name(const gl_shader_stage stage, const char *source, static void dump_shader(const gl_shader_stage stage, const char *source) { - char name[PATH_MAX]; static bool path_exists = true; char *dump_path; FILE *f; @@ -1652,7 +1828,7 @@ dump_shader(const gl_shader_stage stage, const char *source) return; } - construct_name(stage, source, dump_path, name, PATH_MAX); + char *name = construct_name(stage, source, dump_path); f = fopen(name, "w"); if (f) { @@ -1663,6 +1839,7 @@ dump_shader(const gl_shader_stage stage, const char *source) _mesa_warning(ctx, "could not open %s for dumping shader (%s)", name, strerror(errno)); } + ralloc_free(name); } /** @@ -1672,7 +1849,6 @@ dump_shader(const gl_shader_stage stage, const char *source) static GLcharARB * read_shader(const gl_shader_stage stage, const char *source) { - char name[PATH_MAX]; char *read_path; static bool path_exists = true; int len, shader_size = 0; @@ -1688,9 +1864,9 @@ read_shader(const gl_shader_stage stage, const char *source) return NULL; } - construct_name(stage, source, read_path, name, PATH_MAX); - + char *name = construct_name(stage, source, read_path); f = fopen(name, "r"); + ralloc_free(name); if (!f) return NULL; @@ -1713,34 +1889,34 @@ read_shader(const gl_shader_stage stage, const char *source) return buffer; } -#endif /* HAVE_SHA1 */ + +#endif /* ENABLE_SHADER_CACHE */ /** * Called via glShaderSource() and glShaderSourceARB() API functions. * Basically, concatenate the source code strings into one long string * and pass it to _mesa_shader_source(). */ -void GLAPIENTRY -_mesa_ShaderSource(GLuint shaderObj, GLsizei count, - const GLchar * const * string, const GLint * length) +static ALWAYS_INLINE void +shader_source(struct gl_context *ctx, GLuint shaderObj, GLsizei count, + const GLchar *const *string, const GLint *length, bool no_error) { - GET_CURRENT_CONTEXT(ctx); GLint *offsets; GLsizei i, totalLength; GLcharARB *source; struct gl_shader *sh; -#if defined(HAVE_SHA1) - GLcharARB *replacement; -#endif /* HAVE_SHA1 */ - - sh = _mesa_lookup_shader_err(ctx, shaderObj, "glShaderSourceARB"); - if (!sh) - return; + if (!no_error) { + sh = _mesa_lookup_shader_err(ctx, shaderObj, "glShaderSourceARB"); + if (!sh) + return; - if (string == NULL) { - _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB"); - return; + if (string == NULL) { + _mesa_error(ctx, GL_INVALID_VALUE, "glShaderSourceARB"); + return; + } + } else { + sh = _mesa_lookup_shader(ctx, shaderObj); } /* @@ -1754,7 +1930,7 @@ _mesa_ShaderSource(GLuint shaderObj, GLsizei count, } for (i = 0; i < count; i++) { - if (string[i] == NULL) { + if (!no_error && string[i] == NULL) { free((GLvoid *) offsets); _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderSourceARB(null string)"); @@ -1789,7 +1965,9 @@ _mesa_ShaderSource(GLuint shaderObj, GLsizei count, source[totalLength - 1] = '\0'; source[totalLength - 2] = '\0'; -#if defined(HAVE_SHA1) +#ifdef ENABLE_SHADER_CACHE + GLcharARB *replacement; + /* Dump original shader source to MESA_SHADER_DUMP_PATH and replace * if corresponding entry found from MESA_SHADER_READ_PATH. */ @@ -1800,48 +1978,70 @@ _mesa_ShaderSource(GLuint shaderObj, GLsizei count, free(source); source = replacement; } -#endif /* HAVE_SHA1 */ +#endif /* ENABLE_SHADER_CACHE */ - shader_source(sh, source); + set_shader_source(sh, source); free(offsets); } void GLAPIENTRY -_mesa_UseProgram(GLuint program) +_mesa_ShaderSource_no_error(GLuint shaderObj, GLsizei count, + const GLchar *const *string, const GLint *length) { GET_CURRENT_CONTEXT(ctx); - struct gl_shader_program *shProg; + shader_source(ctx, shaderObj, count, string, length, true); +} + + +void GLAPIENTRY +_mesa_ShaderSource(GLuint shaderObj, GLsizei count, + const GLchar *const *string, const GLint *length) +{ + GET_CURRENT_CONTEXT(ctx); + shader_source(ctx, shaderObj, count, string, length, false); +} + + +static ALWAYS_INLINE void +use_program(GLuint program, bool no_error) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_shader_program *shProg = NULL; if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glUseProgram %u\n", program); - if (_mesa_is_xfb_active_and_unpaused(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glUseProgram(transform feedback active)"); - return; - } - - if (program) { - shProg = _mesa_lookup_shader_program_err(ctx, program, "glUseProgram"); - if (!shProg) { - return; + if (no_error) { + if (program) { + shProg = _mesa_lookup_shader_program(ctx, program); } - if (!shProg->LinkStatus) { + } else { + if (_mesa_is_xfb_active_and_unpaused(ctx)) { _mesa_error(ctx, GL_INVALID_OPERATION, - "glUseProgram(program %u not linked)", program); + "glUseProgram(transform feedback active)"); return; } - /* debug code */ - if (ctx->_Shader->Flags & GLSL_USE_PROG) { - print_shader_info(shProg); + if (program) { + shProg = + _mesa_lookup_shader_program_err(ctx, program, "glUseProgram"); + if (!shProg) + return; + + if (!shProg->data->LinkStatus) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glUseProgram(program %u not linked)", program); + return; + } + + /* debug code */ + if (ctx->_Shader->Flags & GLSL_USE_PROG) { + print_shader_info(shProg); + } } } - else { - shProg = NULL; - } /* The ARB_separate_shader_object spec says: * @@ -1852,21 +2052,41 @@ _mesa_UseProgram(GLuint program) * object (section 2.14.PPO), the program bound to the appropriate * stage of the pipeline object is considered current." */ - if (program) { + if (shProg) { /* Attach shader state to the binding point */ _mesa_reference_pipeline_object(ctx, &ctx->_Shader, &ctx->Shader); /* Update the program */ - _mesa_use_program(ctx, shProg); + _mesa_use_shader_program(ctx, shProg); } else { /* Must be done first: detach the progam */ - _mesa_use_program(ctx, shProg); + _mesa_use_shader_program(ctx, shProg); /* Unattach shader_state binding point */ - _mesa_reference_pipeline_object(ctx, &ctx->_Shader, ctx->Pipeline.Default); + _mesa_reference_pipeline_object(ctx, &ctx->_Shader, + ctx->Pipeline.Default); /* If a pipeline was bound, rebind it */ if (ctx->Pipeline.Current) { - _mesa_BindProgramPipeline(ctx->Pipeline.Current->Name); + if (no_error) + _mesa_BindProgramPipeline_no_error(ctx->Pipeline.Current->Name); + else + _mesa_BindProgramPipeline(ctx->Pipeline.Current->Name); } } + + _mesa_update_vertex_processing_mode(ctx); +} + + +void GLAPIENTRY +_mesa_UseProgram_no_error(GLuint program) +{ + use_program(program, true); +} + + +void GLAPIENTRY +_mesa_UseProgram(GLuint program) +{ + use_program(program, false); } @@ -1951,9 +2171,7 @@ _mesa_ShaderBinary(GLint n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLint length) { GET_CURRENT_CONTEXT(ctx); - (void) shaders; - (void) binaryformat; - (void) binary; + struct gl_shader **sh; /* Page 68, section 7.2 'Shader Binaries" of the of the OpenGL ES 3.1, and * page 88 of the OpenGL 4.5 specs state: @@ -1967,6 +2185,37 @@ _mesa_ShaderBinary(GLint n, const GLuint* shaders, GLenum binaryformat, return; } + /* Get all shader objects at once so we can make the operation + * all-or-nothing. + */ + if (n > SIZE_MAX / sizeof(*sh)) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary(count)"); + return; + } + + sh = alloca(sizeof(*sh) * (size_t)n); + if (!sh) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary"); + return; + } + + for (int i = 0; i < n; ++i) { + sh[i] = _mesa_lookup_shader_err(ctx, shaders[i], "glShaderBinary"); + if (!sh[i]) + return; + } + + if (binaryformat == GL_SHADER_BINARY_FORMAT_SPIR_V_ARB) { + if (!ctx->Extensions.ARB_gl_spirv) { + _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderBinary(SPIR-V)"); + } else if (n > 0) { + _mesa_spirv_shader_binary(ctx, (unsigned) n, sh, binary, + (size_t) length); + } + + return; + } + _mesa_error(ctx, GL_INVALID_ENUM, "glShaderBinary(format)"); } @@ -2005,7 +2254,7 @@ _mesa_GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei *length, * length is zero, and a call to GetProgramBinary will generate an * INVALID_OPERATION error. */ - if (!shProg->LinkStatus) { + if (!shProg->data->LinkStatus) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramBinary(program %u not linked)", shProg->Name); @@ -2013,12 +2262,15 @@ _mesa_GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei *length, return; } - *length = 0; - _mesa_error(ctx, GL_INVALID_OPERATION, - "glGetProgramBinary(driver supports zero binary formats)"); - - (void) binaryFormat; - (void) binary; + if (ctx->Const.NumProgramBinaryFormats == 0) { + *length = 0; + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetProgramBinary(driver supports zero binary formats)"); + } else { + _mesa_get_program_binary(ctx, shProg, bufSize, length, binaryFormat, + binary); + assert(*length == 0 || *binaryFormat == GL_PROGRAM_BINARY_FORMAT_MESA); + } } void GLAPIENTRY @@ -2032,8 +2284,8 @@ _mesa_ProgramBinary(GLuint program, GLenum binaryFormat, if (!shProg) return; - (void) binaryFormat; - (void) binary; + _mesa_clear_shader_program_data(ctx, shProg); + shProg->data = _mesa_create_shader_program_data(); /* Section 2.3.1 (Errors) of the OpenGL 4.5 spec says: * @@ -2045,34 +2297,32 @@ _mesa_ProgramBinary(GLuint program, GLenum binaryFormat, return; } - /* The ARB_get_program_binary spec says: - * - * " and must be those returned by a previous - * call to GetProgramBinary, and must be the length of the - * program binary as returned by GetProgramBinary or GetProgramiv with - * PROGRAM_BINARY_LENGTH. Loading the program binary will fail, - * setting the LINK_STATUS of to FALSE, if these conditions - * are not met." - * - * Since any value of binaryFormat passed "is not one of those specified as - * allowable for [this] command, an INVALID_ENUM error is generated." - */ - shProg->LinkStatus = GL_FALSE; - _mesa_error(ctx, GL_INVALID_ENUM, "glProgramBinary"); + if (ctx->Const.NumProgramBinaryFormats == 0 || + binaryFormat != GL_PROGRAM_BINARY_FORMAT_MESA) { + /* The ARB_get_program_binary spec says: + * + * " and must be those returned by a previous + * call to GetProgramBinary, and must be the length of the + * program binary as returned by GetProgramBinary or GetProgramiv with + * PROGRAM_BINARY_LENGTH. Loading the program binary will fail, + * setting the LINK_STATUS of to FALSE, if these conditions + * are not met." + * + * Since any value of binaryFormat passed "is not one of those specified as + * allowable for [this] command, an INVALID_ENUM error is generated." + */ + shProg->data->LinkStatus = LINKING_FAILURE; + _mesa_error(ctx, GL_INVALID_ENUM, "glProgramBinary"); + } else { + _mesa_program_binary(ctx, shProg, binaryFormat, binary, length); + } } -void GLAPIENTRY -_mesa_ProgramParameteri(GLuint program, GLenum pname, GLint value) +static ALWAYS_INLINE void +program_parameteri(struct gl_context *ctx, struct gl_shader_program *shProg, + GLuint pname, GLint value, bool no_error) { - struct gl_shader_program *shProg; - GET_CURRENT_CONTEXT(ctx); - - shProg = _mesa_lookup_shader_program_err(ctx, program, - "glProgramParameteri"); - if (!shProg) - return; - switch (pname) { case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: /* This enum isn't part of the OES extension for OpenGL ES 2.0, but it @@ -2088,7 +2338,7 @@ _mesa_ProgramParameteri(GLuint program, GLenum pname, GLint value) * "An INVALID_VALUE error is generated if the argument to * ProgramParameteri is not TRUE or FALSE." */ - if (value != GL_TRUE && value != GL_FALSE) { + if (!no_error && value != GL_TRUE && value != GL_FALSE) { goto invalid_value; } @@ -2119,15 +2369,17 @@ _mesa_ProgramParameteri(GLuint program, GLenum pname, GLint value) /* Spec imply that the behavior is the same as ARB_get_program_binary * Chapter 7.3 Program Objects */ - if (value != GL_TRUE && value != GL_FALSE) { + if (!no_error && value != GL_TRUE && value != GL_FALSE) { goto invalid_value; } shProg->SeparateShader = value; return; default: - _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteri(pname=%s)", - _mesa_enum_to_string(pname)); + if (!no_error) { + _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameteri(pname=%s)", + _mesa_enum_to_string(pname)); + } return; } @@ -2140,13 +2392,58 @@ invalid_value: } +void GLAPIENTRY +_mesa_ProgramParameteri_no_error(GLuint program, GLenum pname, GLint value) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); + program_parameteri(ctx, shProg, pname, value, true); +} + + +void GLAPIENTRY +_mesa_ProgramParameteri(GLuint program, GLenum pname, GLint value) +{ + struct gl_shader_program *shProg; + GET_CURRENT_CONTEXT(ctx); + + shProg = _mesa_lookup_shader_program_err(ctx, program, + "glProgramParameteri"); + if (!shProg) + return; + + program_parameteri(ctx, shProg, pname, value, false); +} + + void -_mesa_use_shader_program(struct gl_context *ctx, GLenum type, - struct gl_shader_program *shProg, - struct gl_pipeline_object *shTarget) +_mesa_use_program(struct gl_context *ctx, gl_shader_stage stage, + struct gl_shader_program *shProg, struct gl_program *prog, + struct gl_pipeline_object *shTarget) { - gl_shader_stage stage = _mesa_shader_enum_to_shader_stage(type); - use_shader_program(ctx, stage, shProg, shTarget); + struct gl_program **target; + + target = &shTarget->CurrentProgram[stage]; + if (prog) { + _mesa_program_init_subroutine_defaults(ctx, prog); + } + + if (*target != prog) { + /* Program is current, flush it */ + if (shTarget == ctx->_Shader) { + FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS); + } + + _mesa_reference_shader_program(ctx, + &shTarget->ReferencedPrograms[stage], + shProg); + _mesa_reference_program(ctx, target, prog); + if (stage == MESA_SHADER_VERTEX) + _mesa_update_vertex_processing_mode(ctx); + return; + } + } @@ -2165,54 +2462,26 @@ _mesa_copy_linked_program_data(const struct gl_shader_program *src, struct gl_program *dst = dst_sh->Program; + dst->info.separate_shader = src->SeparateShader; + switch (dst_sh->Stage) { - case MESA_SHADER_VERTEX: - dst->ClipDistanceArraySize = src->Vert.ClipDistanceArraySize; - dst->CullDistanceArraySize = src->Vert.CullDistanceArraySize; - break; - case MESA_SHADER_TESS_CTRL: { - dst->info.tcs.vertices_out = dst_sh->info.TessCtrl.VerticesOut; - break; - } - case MESA_SHADER_TESS_EVAL: { - dst->info.tes.primitive_mode = dst_sh->info.TessEval.PrimitiveMode; - dst->info.tes.spacing = dst_sh->info.TessEval.Spacing; - dst->info.tes.vertex_order = dst_sh->info.TessEval.VertexOrder; - dst->info.tes.point_mode = dst_sh->info.TessEval.PointMode; - dst->ClipDistanceArraySize = src->TessEval.ClipDistanceArraySize; - dst->CullDistanceArraySize = src->TessEval.CullDistanceArraySize; - break; - } case MESA_SHADER_GEOMETRY: { dst->info.gs.vertices_in = src->Geom.VerticesIn; - dst->info.gs.vertices_out = dst_sh->info.Geom.VerticesOut; - dst->info.gs.invocations = dst_sh->info.Geom.Invocations; - dst->info.gs.input_primitive = dst_sh->info.Geom.InputType; - dst->info.gs.output_primitive = dst_sh->info.Geom.OutputType; - dst->ClipDistanceArraySize = src->Geom.ClipDistanceArraySize; - dst->CullDistanceArraySize = src->Geom.CullDistanceArraySize; dst->info.gs.uses_end_primitive = src->Geom.UsesEndPrimitive; dst->info.gs.uses_streams = src->Geom.UsesStreams; break; } case MESA_SHADER_FRAGMENT: { - struct gl_fragment_program *dst_fp = (struct gl_fragment_program *) dst; - dst_fp->FragDepthLayout = src->FragDepthLayout; + dst->info.fs.depth_layout = src->FragDepthLayout; break; } case MESA_SHADER_COMPUTE: { - struct gl_compute_program *dst_cp = (struct gl_compute_program *) dst; - int i; - for (i = 0; i < 3; i++) - dst_cp->LocalSize[i] = src->Comp.LocalSize[i]; - dst_cp->SharedSize = src->Comp.SharedSize; + dst->info.cs.shared_size = src->Comp.SharedSize; break; } default: break; } - - copy_shader_info(src, dst_sh); } /** @@ -2224,7 +2493,7 @@ _mesa_CreateShaderProgramv(GLenum type, GLsizei count, { GET_CURRENT_CONTEXT(ctx); - const GLuint shader = create_shader(ctx, type); + const GLuint shader = create_shader_err(ctx, type, "glCreateShaderProgramv"); GLuint program = 0; /* @@ -2253,20 +2522,20 @@ _mesa_CreateShaderProgramv(GLenum type, GLsizei count, get_shaderiv(ctx, shader, GL_COMPILE_STATUS, &compiled); if (compiled) { - attach_shader(ctx, program, shader); + attach_shader_err(ctx, program, shader, "glCreateShaderProgramv"); _mesa_link_program(ctx, shProg); - detach_shader(ctx, program, shader); + detach_shader_error(ctx, program, shader); #if 0 /* Possibly... */ if (active-user-defined-varyings-in-linked-program) { append-error-to-info-log; - shProg->LinkStatus = GL_FALSE; + shProg->data->LinkStatus = LINKING_FAILURE; } #endif } if (sh->InfoLog) - ralloc_strcat(&shProg->InfoLog, sh->InfoLog); + ralloc_strcat(&shProg->data->InfoLog, sh->InfoLog); } delete_shader(ctx, shader); @@ -2279,6 +2548,14 @@ _mesa_CreateShaderProgramv(GLenum type, GLsizei count, /** * For GL_ARB_tessellation_shader */ +void GLAPIENTRY +_mesa_PatchParameteri_no_error(GLenum pname, GLint value) +{ + GET_CURRENT_CONTEXT(ctx); + ctx->TessCtrlProgram.patch_vertices = value; +} + + extern void GLAPIENTRY _mesa_PatchParameteri(GLenum pname, GLint value) { @@ -2345,11 +2622,6 @@ _mesa_GetSubroutineUniformLocation(GLuint program, GLenum shadertype, GLenum resource_type; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return -1; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return -1; @@ -2380,11 +2652,6 @@ _mesa_GetSubroutineIndex(GLuint program, GLenum shadertype, GLenum resource_type; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return -1; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return -1; @@ -2424,11 +2691,6 @@ _mesa_GetActiveSubroutineUniformiv(GLuint program, GLenum shadertype, GLenum resource_type; int count, i, j; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; @@ -2447,7 +2709,8 @@ _mesa_GetActiveSubroutineUniformiv(GLuint program, GLenum shadertype, return; } - if (index >= sh->NumSubroutineUniforms) { + struct gl_program *p = shProg->_LinkedShaders[stage]->Program; + if (index >= p->sh.NumSubroutineUniforms) { _mesa_error(ctx, GL_INVALID_VALUE, "%s: invalid index greater than GL_ACTIVE_SUBROUTINE_UNIFORMS", api_name); return; } @@ -2466,8 +2729,8 @@ _mesa_GetActiveSubroutineUniformiv(GLuint program, GLenum shadertype, if (res) { uni = res->Data; count = 0; - for (i = 0; i < sh->NumSubroutineFunctions; i++) { - struct gl_subroutine_function *fn = &sh->SubroutineFunctions[i]; + for (i = 0; i < p->sh.NumSubroutineFunctions; i++) { + struct gl_subroutine_function *fn = &p->sh.SubroutineFunctions[i]; for (j = 0; j < fn->num_compat_types; j++) { if (fn->types[j] == uni->type) { values[count++] = i; @@ -2510,11 +2773,6 @@ _mesa_GetActiveSubroutineUniformName(GLuint program, GLenum shadertype, GLenum resource_type; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; @@ -2549,11 +2807,6 @@ _mesa_GetActiveSubroutineName(GLuint program, GLenum shadertype, GLenum resource_type; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; @@ -2580,60 +2833,53 @@ _mesa_UniformSubroutinesuiv(GLenum shadertype, GLsizei count, { GET_CURRENT_CONTEXT(ctx); const char *api_name = "glUniformSubroutinesuiv"; - struct gl_shader_program *shProg; - struct gl_linked_shader *sh; gl_shader_stage stage; int i; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; } stage = _mesa_shader_enum_to_shader_stage(shadertype); - shProg = ctx->_Shader->CurrentProgram[stage]; - if (!shProg) { + struct gl_program *p = ctx->_Shader->CurrentProgram[stage]; + if (!p) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; } - sh = shProg->_LinkedShaders[stage]; - if (!sh) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - - if (count != sh->NumSubroutineUniformRemapTable) { + if (count != p->sh.NumSubroutineUniformRemapTable) { _mesa_error(ctx, GL_INVALID_VALUE, "%s", api_name); return; } i = 0; + bool flushed = false; do { - struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i]; + struct gl_uniform_storage *uni = p->sh.SubroutineUniformRemapTable[i]; if (uni == NULL) { i++; continue; } + if (!flushed) { + _mesa_flush_vertices_for_uniforms(ctx, uni); + flushed = true; + } + int uni_count = uni->array_elements ? uni->array_elements : 1; int j, k, f; for (j = i; j < i + uni_count; j++) { struct gl_subroutine_function *subfn = NULL; - if (indices[j] > sh->MaxSubroutineFunctionIndex) { + if (indices[j] > p->sh.MaxSubroutineFunctionIndex) { _mesa_error(ctx, GL_INVALID_VALUE, "%s", api_name); return; } - for (f = 0; f < sh->NumSubroutineFunctions; f++) { - if (sh->SubroutineFunctions[f].index == indices[j]) - subfn = &sh->SubroutineFunctions[f]; + for (f = 0; f < p->sh.NumSubroutineFunctions; f++) { + if (p->sh.SubroutineFunctions[f].index == indices[j]) + subfn = &p->sh.SubroutineFunctions[f]; } if (!subfn) { @@ -2649,12 +2895,10 @@ _mesa_UniformSubroutinesuiv(GLenum shadertype, GLsizei count, return; } - ctx->SubroutineIndex[sh->Stage].IndexPtr[j] = indices[j]; + ctx->SubroutineIndex[p->info.stage].IndexPtr[j] = indices[j]; } i += uni_count; } while(i < count); - - FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS); } @@ -2664,39 +2908,26 @@ _mesa_GetUniformSubroutineuiv(GLenum shadertype, GLint location, { GET_CURRENT_CONTEXT(ctx); const char *api_name = "glGetUniformSubroutineuiv"; - struct gl_shader_program *shProg; - struct gl_linked_shader *sh; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; } stage = _mesa_shader_enum_to_shader_stage(shadertype); - shProg = ctx->_Shader->CurrentProgram[stage]; - if (!shProg) { + struct gl_program *p = ctx->_Shader->CurrentProgram[stage]; + if (!p) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; } - sh = shProg->_LinkedShaders[stage]; - if (!sh) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - - if (location >= sh->NumSubroutineUniformRemapTable) { + if (location >= p->sh.NumSubroutineUniformRemapTable) { _mesa_error(ctx, GL_INVALID_VALUE, "%s", api_name); return; } - *params = ctx->SubroutineIndex[sh->Stage].IndexPtr[location]; + *params = ctx->SubroutineIndex[p->info.stage].IndexPtr[location]; } @@ -2710,11 +2941,6 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, struct gl_linked_shader *sh; gl_shader_stage stage; - if (!_mesa_has_ARB_shader_subroutine(ctx)) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); - return; - } - if (!_mesa_validate_shader_target(ctx, shadertype)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name); return; @@ -2748,15 +2974,16 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, return; } + struct gl_program *p = sh->Program; switch (pname) { case GL_ACTIVE_SUBROUTINES: - values[0] = sh->NumSubroutineFunctions; + values[0] = p->sh.NumSubroutineFunctions; break; case GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS: - values[0] = sh->NumSubroutineUniformRemapTable; + values[0] = p->sh.NumSubroutineUniformRemapTable; break; case GL_ACTIVE_SUBROUTINE_UNIFORMS: - values[0] = sh->NumSubroutineUniforms; + values[0] = p->sh.NumSubroutineUniforms; break; case GL_ACTIVE_SUBROUTINE_MAX_LENGTH: { @@ -2766,7 +2993,7 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, struct gl_program_resource *res; resource_type = _mesa_shader_stage_to_subroutine(stage); - for (i = 0; i < sh->NumSubroutineFunctions; i++) { + for (i = 0; i < p->sh.NumSubroutineFunctions; i++) { res = _mesa_program_resource_find_index(shProg, resource_type, i); if (res) { const GLint len = strlen(_mesa_program_resource_name(res)) + 1; @@ -2785,7 +3012,7 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, struct gl_program_resource *res; resource_type = _mesa_shader_stage_to_subroutine_uniform(stage); - for (i = 0; i < sh->NumSubroutineUniformRemapTable; i++) { + for (i = 0; i < p->sh.NumSubroutineUniformRemapTable; i++) { res = _mesa_program_resource_find_index(shProg, resource_type, i); if (res) { const GLint len = strlen(_mesa_program_resource_name(res)) + 1 @@ -2806,13 +3033,12 @@ _mesa_GetProgramStageiv(GLuint program, GLenum shadertype, } static int -find_compat_subroutine(struct gl_linked_shader *sh, - const struct glsl_type *type) +find_compat_subroutine(struct gl_program *p, const struct glsl_type *type) { int i, j; - for (i = 0; i < sh->NumSubroutineFunctions; i++) { - struct gl_subroutine_function *fn = &sh->SubroutineFunctions[i]; + for (i = 0; i < p->sh.NumSubroutineFunctions; i++) { + struct gl_subroutine_function *fn = &p->sh.SubroutineFunctions[i]; for (j = 0; j < fn->num_compat_types; j++) { if (fn->types[j] == type) return i; @@ -2823,16 +3049,16 @@ find_compat_subroutine(struct gl_linked_shader *sh, static void _mesa_shader_write_subroutine_index(struct gl_context *ctx, - struct gl_linked_shader *sh) + struct gl_program *p) { int i, j; - if (sh->NumSubroutineUniformRemapTable == 0) + if (p->sh.NumSubroutineUniformRemapTable == 0) return; i = 0; do { - struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i]; + struct gl_uniform_storage *uni = p->sh.SubroutineUniformRemapTable[i]; int uni_count; int val; @@ -2843,60 +3069,43 @@ _mesa_shader_write_subroutine_index(struct gl_context *ctx, uni_count = uni->array_elements ? uni->array_elements : 1; for (j = 0; j < uni_count; j++) { - val = ctx->SubroutineIndex[sh->Stage].IndexPtr[i + j]; + val = ctx->SubroutineIndex[p->info.stage].IndexPtr[i + j]; memcpy(&uni->storage[j], &val, sizeof(int)); } _mesa_propagate_uniforms_to_driver_storage(uni, 0, uni_count); i += uni_count; - } while(i < sh->NumSubroutineUniformRemapTable); + } while(i < p->sh.NumSubroutineUniformRemapTable); } void _mesa_shader_write_subroutine_indices(struct gl_context *ctx, gl_shader_stage stage) { - if (ctx->_Shader->CurrentProgram[stage] && - ctx->_Shader->CurrentProgram[stage]->_LinkedShaders[stage]) + if (ctx->_Shader->CurrentProgram[stage]) _mesa_shader_write_subroutine_index(ctx, - ctx->_Shader->CurrentProgram[stage]->_LinkedShaders[stage]); + ctx->_Shader->CurrentProgram[stage]); } -static void -_mesa_shader_init_subroutine_defaults(struct gl_context *ctx, - struct gl_linked_shader *sh) +void +_mesa_program_init_subroutine_defaults(struct gl_context *ctx, + struct gl_program *p) { - int i; - struct gl_subroutine_index_binding *binding = &ctx->SubroutineIndex[sh->Stage]; - if (binding->NumIndex != sh->NumSubroutineUniformRemapTable) { + assert(p); + + struct gl_subroutine_index_binding *binding = &ctx->SubroutineIndex[p->info.stage]; + if (binding->NumIndex != p->sh.NumSubroutineUniformRemapTable) { binding->IndexPtr = realloc(binding->IndexPtr, - sh->NumSubroutineUniformRemapTable * (sizeof(GLuint))); - binding->NumIndex = sh->NumSubroutineUniformRemapTable; + p->sh.NumSubroutineUniformRemapTable * (sizeof(GLuint))); + binding->NumIndex = p->sh.NumSubroutineUniformRemapTable; } - for (i = 0; i < sh->NumSubroutineUniformRemapTable; i++) { - struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i]; + for (int i = 0; i < p->sh.NumSubroutineUniformRemapTable; i++) { + struct gl_uniform_storage *uni = p->sh.SubroutineUniformRemapTable[i]; if (!uni) continue; - binding->IndexPtr[i] = find_compat_subroutine(sh, uni->type); - } -} - -void -_mesa_shader_program_init_subroutine_defaults(struct gl_context *ctx, - struct gl_shader_program *shProg) -{ - int i; - - if (!shProg) - return; - - for (i = 0; i < MESA_SHADER_STAGES; i++) { - if (!shProg->_LinkedShaders[i]) - continue; - - _mesa_shader_init_subroutine_defaults(ctx, shProg->_LinkedShaders[i]); + binding->IndexPtr[i] = find_compat_subroutine(p, uni->type); } }