2 * Mesa 3-D graphics library
4 * Copyright © 2013 Gregory Hainaut <gregory.hainaut@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * \author Hainaut Gregory <gregory.hainaut@gmail.com>
30 * Implementation of pipeline object related API functions. Based on
31 * GL_ARB_separate_shader_objects extension.
35 #include "main/glheader.h"
36 #include "main/context.h"
37 #include "main/dispatch.h"
38 #include "main/enums.h"
39 #include "main/hash.h"
40 #include "main/mtypes.h"
41 #include "main/pipelineobj.h"
42 #include "main/shaderapi.h"
43 #include "main/shaderobj.h"
44 #include "main/transformfeedback.h"
45 #include "main/uniforms.h"
46 #include "compiler/glsl/glsl_parser_extras.h"
47 #include "compiler/glsl/ir_uniform.h"
48 #include "program/program.h"
49 #include "program/prog_parameter.h"
50 #include "util/ralloc.h"
53 * Delete a pipeline object.
56 _mesa_delete_pipeline_object(struct gl_context
*ctx
,
57 struct gl_pipeline_object
*obj
)
61 _mesa_reference_shader_program(ctx
, &obj
->_CurrentFragmentProgram
, NULL
);
63 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
64 _mesa_reference_shader_program(ctx
, &obj
->CurrentProgram
[i
], NULL
);
66 _mesa_reference_shader_program(ctx
, &obj
->ActiveProgram
, NULL
);
67 mtx_destroy(&obj
->Mutex
);
73 * Allocate and initialize a new pipeline object.
75 static struct gl_pipeline_object
*
76 _mesa_new_pipeline_object(struct gl_context
*ctx
, GLuint name
)
78 struct gl_pipeline_object
*obj
= rzalloc(NULL
, struct gl_pipeline_object
);
81 mtx_init(&obj
->Mutex
, mtx_plain
);
83 obj
->Flags
= _mesa_get_shader_flags();
91 * Initialize pipeline object state for given context.
94 _mesa_init_pipeline(struct gl_context
*ctx
)
96 ctx
->Pipeline
.Objects
= _mesa_NewHashTable();
98 ctx
->Pipeline
.Current
= NULL
;
100 /* Install a default Pipeline */
101 ctx
->Pipeline
.Default
= _mesa_new_pipeline_object(ctx
, 0);
102 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
, ctx
->Pipeline
.Default
);
107 * Callback for deleting a pipeline object. Called by _mesa_HashDeleteAll().
110 delete_pipelineobj_cb(UNUSED GLuint id
, void *data
, void *userData
)
112 struct gl_pipeline_object
*obj
= (struct gl_pipeline_object
*) data
;
113 struct gl_context
*ctx
= (struct gl_context
*) userData
;
114 _mesa_delete_pipeline_object(ctx
, obj
);
119 * Free pipeline state for given context.
122 _mesa_free_pipeline_data(struct gl_context
*ctx
)
124 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
, NULL
);
126 _mesa_HashDeleteAll(ctx
->Pipeline
.Objects
, delete_pipelineobj_cb
, ctx
);
127 _mesa_DeleteHashTable(ctx
->Pipeline
.Objects
);
129 _mesa_delete_pipeline_object(ctx
, ctx
->Pipeline
.Default
);
133 * Look up the pipeline object for the given ID.
136 * Either a pointer to the pipeline object with the specified ID or \c NULL for
137 * a non-existent ID. The spec defines ID 0 as being technically
140 struct gl_pipeline_object
*
141 _mesa_lookup_pipeline_object(struct gl_context
*ctx
, GLuint id
)
146 return (struct gl_pipeline_object
*)
147 _mesa_HashLookup(ctx
->Pipeline
.Objects
, id
);
151 * Add the given pipeline object to the pipeline object pool.
154 save_pipeline_object(struct gl_context
*ctx
, struct gl_pipeline_object
*obj
)
157 _mesa_HashInsert(ctx
->Pipeline
.Objects
, obj
->Name
, obj
);
162 * Remove the given pipeline object from the pipeline object pool.
163 * Do not deallocate the pipeline object though.
166 remove_pipeline_object(struct gl_context
*ctx
, struct gl_pipeline_object
*obj
)
169 _mesa_HashRemove(ctx
->Pipeline
.Objects
, obj
->Name
);
174 * Set ptr to obj w/ reference counting.
175 * Note: this should only be called from the _mesa_reference_pipeline_object()
179 _mesa_reference_pipeline_object_(struct gl_context
*ctx
,
180 struct gl_pipeline_object
**ptr
,
181 struct gl_pipeline_object
*obj
)
186 /* Unreference the old pipeline object */
187 GLboolean deleteFlag
= GL_FALSE
;
188 struct gl_pipeline_object
*oldObj
= *ptr
;
190 mtx_lock(&oldObj
->Mutex
);
191 assert(oldObj
->RefCount
> 0);
193 deleteFlag
= (oldObj
->RefCount
== 0);
194 mtx_unlock(&oldObj
->Mutex
);
197 _mesa_delete_pipeline_object(ctx
, oldObj
);
205 /* reference new pipeline object */
206 mtx_lock(&obj
->Mutex
);
207 if (obj
->RefCount
== 0) {
208 /* this pipeline's being deleted (look just above) */
209 /* Not sure this can ever really happen. Warn if it does. */
210 _mesa_problem(NULL
, "referencing deleted pipeline object");
217 mtx_unlock(&obj
->Mutex
);
222 * Bound program to severals stages of the pipeline
225 _mesa_UseProgramStages(GLuint pipeline
, GLbitfield stages
, GLuint program
)
227 GET_CURRENT_CONTEXT(ctx
);
229 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
230 struct gl_shader_program
*shProg
= NULL
;
231 GLbitfield any_valid_stages
;
233 if (MESA_VERBOSE
& VERBOSE_API
)
234 _mesa_debug(ctx
, "glUseProgramStages(%u, 0x%x, %u)\n",
235 pipeline
, stages
, program
);
238 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUseProgramStages(pipeline)");
242 /* Object is created by any Pipeline call but glGenProgramPipelines,
243 * glIsProgramPipeline and GetProgramPipelineInfoLog
245 pipe
->EverBound
= GL_TRUE
;
247 /* Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec says:
249 * "If stages is not the special value ALL_SHADER_BITS, and has a bit
250 * set that is not recognized, the error INVALID_VALUE is generated."
252 any_valid_stages
= GL_VERTEX_SHADER_BIT
| GL_FRAGMENT_SHADER_BIT
;
253 if (_mesa_has_geometry_shaders(ctx
))
254 any_valid_stages
|= GL_GEOMETRY_SHADER_BIT
;
255 if (_mesa_has_tessellation(ctx
))
256 any_valid_stages
|= GL_TESS_CONTROL_SHADER_BIT
|
257 GL_TESS_EVALUATION_SHADER_BIT
;
258 if (_mesa_has_compute_shaders(ctx
))
259 any_valid_stages
|= GL_COMPUTE_SHADER_BIT
;
261 if (stages
!= GL_ALL_SHADER_BITS
&& (stages
& ~any_valid_stages
) != 0) {
262 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUseProgramStages(Stages)");
266 /* Section 2.17.2 (Transform Feedback Primitive Capture) of the OpenGL 4.1
269 * "The error INVALID_OPERATION is generated:
273 * - by UseProgramStages if the program pipeline object it refers
274 * to is current and the current transform feedback object is
275 * active and not paused;
277 if (ctx
->_Shader
== pipe
) {
278 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
279 _mesa_error(ctx
, GL_INVALID_OPERATION
,
280 "glUseProgramStages(transform feedback active)");
286 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
287 "glUseProgramStages");
291 /* Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec
294 * "If the program object named by program was linked without the
295 * PROGRAM_SEPARABLE parameter set, or was not linked successfully,
296 * the error INVALID_OPERATION is generated and the corresponding
297 * shader stages in the pipeline program pipeline object are not
300 if (!shProg
->LinkStatus
) {
301 _mesa_error(ctx
, GL_INVALID_OPERATION
,
302 "glUseProgramStages(program not linked)");
306 if (!shProg
->SeparateShader
) {
307 _mesa_error(ctx
, GL_INVALID_OPERATION
,
308 "glUseProgramStages(program wasn't linked with the "
309 "PROGRAM_SEPARABLE flag)");
314 /* Enable individual stages from the program as requested by the
315 * application. If there is no shader for a requested stage in the
316 * program, _mesa_use_shader_program will enable fixed-function processing
317 * as dictated by the spec.
319 * Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec
322 * "If UseProgramStages is called with program set to zero or with a
323 * program object that contains no executable code for the given
324 * stages, it is as if the pipeline object has no programmable stage
325 * configured for the indicated shader stages."
327 if ((stages
& GL_VERTEX_SHADER_BIT
) != 0)
328 _mesa_use_shader_program(ctx
, GL_VERTEX_SHADER
, shProg
, pipe
);
330 if ((stages
& GL_FRAGMENT_SHADER_BIT
) != 0)
331 _mesa_use_shader_program(ctx
, GL_FRAGMENT_SHADER
, shProg
, pipe
);
333 if ((stages
& GL_GEOMETRY_SHADER_BIT
) != 0)
334 _mesa_use_shader_program(ctx
, GL_GEOMETRY_SHADER
, shProg
, pipe
);
336 if ((stages
& GL_TESS_CONTROL_SHADER_BIT
) != 0)
337 _mesa_use_shader_program(ctx
, GL_TESS_CONTROL_SHADER
, shProg
, pipe
);
339 if ((stages
& GL_TESS_EVALUATION_SHADER_BIT
) != 0)
340 _mesa_use_shader_program(ctx
, GL_TESS_EVALUATION_SHADER
, shProg
, pipe
);
342 if ((stages
& GL_COMPUTE_SHADER_BIT
) != 0)
343 _mesa_use_shader_program(ctx
, GL_COMPUTE_SHADER
, shProg
, pipe
);
345 pipe
->Validated
= false;
349 * Use the named shader program for subsequent glUniform calls (if pipeline
353 _mesa_ActiveShaderProgram(GLuint pipeline
, GLuint program
)
355 GET_CURRENT_CONTEXT(ctx
);
356 struct gl_shader_program
*shProg
= NULL
;
357 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
359 if (MESA_VERBOSE
& VERBOSE_API
)
360 _mesa_debug(ctx
, "glActiveShaderProgram(%u, %u)\n", pipeline
, program
);
363 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
364 "glActiveShaderProgram(program)");
370 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveShaderProgram(pipeline)");
374 /* Object is created by any Pipeline call but glGenProgramPipelines,
375 * glIsProgramPipeline and GetProgramPipelineInfoLog
377 pipe
->EverBound
= GL_TRUE
;
379 if ((shProg
!= NULL
) && !shProg
->LinkStatus
) {
380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
381 "glActiveShaderProgram(program %u not linked)", shProg
->Name
);
385 _mesa_reference_shader_program(ctx
, &pipe
->ActiveProgram
, shProg
);
389 * Make program of the pipeline current
392 _mesa_BindProgramPipeline(GLuint pipeline
)
394 GET_CURRENT_CONTEXT(ctx
);
395 struct gl_pipeline_object
*newObj
= NULL
;
397 if (MESA_VERBOSE
& VERBOSE_API
)
398 _mesa_debug(ctx
, "glBindProgramPipeline(%u)\n", pipeline
);
400 /* Rebinding the same pipeline object: no change.
402 if (ctx
->_Shader
->Name
== pipeline
)
405 /* Section 2.17.2 (Transform Feedback Primitive Capture) of the OpenGL 4.1
408 * "The error INVALID_OPERATION is generated:
412 * - by BindProgramPipeline if the current transform feedback
413 * object is active and not paused;
415 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
416 _mesa_error(ctx
, GL_INVALID_OPERATION
,
417 "glBindProgramPipeline(transform feedback active)");
421 /* Get pointer to new pipeline object (newObj)
424 /* non-default pipeline object */
425 newObj
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glBindProgramPipeline(non-gen name)");
432 /* Object is created by any Pipeline call but glGenProgramPipelines,
433 * glIsProgramPipeline and GetProgramPipelineInfoLog
435 newObj
->EverBound
= GL_TRUE
;
438 _mesa_bind_pipeline(ctx
, newObj
);
442 _mesa_bind_pipeline(struct gl_context
*ctx
,
443 struct gl_pipeline_object
*pipe
)
446 /* First bind the Pipeline to pipeline binding point */
447 _mesa_reference_pipeline_object(ctx
, &ctx
->Pipeline
.Current
, pipe
);
449 /* Section 2.11.3 (Program Objects) of the OpenGL 4.1 spec says:
451 * "If there is a current program object established by UseProgram,
452 * that program is considered current for all stages. Otherwise, if
453 * there is a bound program pipeline object (see section 2.11.4), the
454 * program bound to the appropriate stage of the pipeline object is
455 * considered current."
457 if (&ctx
->Shader
!= ctx
->_Shader
) {
459 /* Bound the pipeline to the current program and
460 * restore the pipeline state
462 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
, pipe
);
464 /* Unbind the pipeline */
465 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
,
466 ctx
->Pipeline
.Default
);
469 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
471 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
472 _mesa_shader_program_init_subroutine_defaults(ctx
->_Shader
->CurrentProgram
[i
]);
474 if (ctx
->Driver
.UseProgram
)
475 ctx
->Driver
.UseProgram(ctx
, NULL
);
480 * Delete a set of pipeline objects.
482 * \param n Number of pipeline objects to delete.
483 * \param ids pipeline of \c n pipeline object IDs.
486 _mesa_DeleteProgramPipelines(GLsizei n
, const GLuint
*pipelines
)
488 GET_CURRENT_CONTEXT(ctx
);
491 if (MESA_VERBOSE
& VERBOSE_API
)
492 _mesa_debug(ctx
, "glDeleteProgramPipelines(%d, %p)\n", n
, pipelines
);
495 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteProgramPipelines(n<0)");
499 for (i
= 0; i
< n
; i
++) {
500 struct gl_pipeline_object
*obj
=
501 _mesa_lookup_pipeline_object(ctx
, pipelines
[i
]);
504 assert(obj
->Name
== pipelines
[i
]);
506 /* If the pipeline object is currently bound, the spec says "If an
507 * object that is currently bound is deleted, the binding for that
508 * object reverts to zero and no program pipeline object becomes
511 if (obj
== ctx
->Pipeline
.Current
) {
512 _mesa_BindProgramPipeline(0);
515 /* The ID is immediately freed for re-use */
516 remove_pipeline_object(ctx
, obj
);
518 /* Unreference the pipeline object.
519 * If refcount hits zero, the object will be deleted.
521 _mesa_reference_pipeline_object(ctx
, &obj
, NULL
);
527 * Generate a set of unique pipeline object IDs and store them in \c pipelines.
528 * \param n Number of IDs to generate.
529 * \param pipelines pipeline of \c n locations to store the IDs.
532 create_program_pipelines(struct gl_context
*ctx
, GLsizei n
, GLuint
*pipelines
,
539 func
= dsa
? "glCreateProgramPipelines" : "glGenProgramPipelines";
542 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s (n < 0)", func
);
550 first
= _mesa_HashFindFreeKeyBlock(ctx
->Pipeline
.Objects
, n
);
552 for (i
= 0; i
< n
; i
++) {
553 struct gl_pipeline_object
*obj
;
554 GLuint name
= first
+ i
;
556 obj
= _mesa_new_pipeline_object(ctx
, name
);
558 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
563 /* make dsa-allocated objects behave like program objects */
564 obj
->EverBound
= GL_TRUE
;
567 save_pipeline_object(ctx
, obj
);
568 pipelines
[i
] = first
+ i
;
574 _mesa_GenProgramPipelines(GLsizei n
, GLuint
*pipelines
)
576 GET_CURRENT_CONTEXT(ctx
);
578 if (MESA_VERBOSE
& VERBOSE_API
)
579 _mesa_debug(ctx
, "glGenProgramPipelines(%d, %p)\n", n
, pipelines
);
581 create_program_pipelines(ctx
, n
, pipelines
, false);
585 _mesa_CreateProgramPipelines(GLsizei n
, GLuint
*pipelines
)
587 GET_CURRENT_CONTEXT(ctx
);
589 if (MESA_VERBOSE
& VERBOSE_API
)
590 _mesa_debug(ctx
, "glCreateProgramPipelines(%d, %p)\n", n
, pipelines
);
592 create_program_pipelines(ctx
, n
, pipelines
, true);
596 * Determine if ID is the name of an pipeline object.
598 * \param id ID of the potential pipeline object.
599 * \return \c GL_TRUE if \c id is the name of a pipeline object,
600 * \c GL_FALSE otherwise.
603 _mesa_IsProgramPipeline(GLuint pipeline
)
605 GET_CURRENT_CONTEXT(ctx
);
607 if (MESA_VERBOSE
& VERBOSE_API
)
608 _mesa_debug(ctx
, "glIsProgramPipeline(%u)\n", pipeline
);
610 struct gl_pipeline_object
*obj
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
614 return obj
->EverBound
;
618 * glGetProgramPipelineiv() - get pipeline shader state.
621 _mesa_GetProgramPipelineiv(GLuint pipeline
, GLenum pname
, GLint
*params
)
623 GET_CURRENT_CONTEXT(ctx
);
624 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
626 if (MESA_VERBOSE
& VERBOSE_API
)
627 _mesa_debug(ctx
, "glGetProgramPipelineiv(%u, %d, %p)\n",
628 pipeline
, pname
, params
);
630 /* Are geometry shaders available in this context?
632 const bool has_gs
= _mesa_has_geometry_shaders(ctx
);
633 const bool has_tess
= _mesa_has_tessellation(ctx
);
636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
637 "glGetProgramPipelineiv(pipeline)");
641 /* Object is created by any Pipeline call but glGenProgramPipelines,
642 * glIsProgramPipeline and GetProgramPipelineInfoLog
644 pipe
->EverBound
= GL_TRUE
;
647 case GL_ACTIVE_PROGRAM
:
648 *params
= pipe
->ActiveProgram
? pipe
->ActiveProgram
->Name
: 0;
650 case GL_INFO_LOG_LENGTH
:
651 *params
= pipe
->InfoLog
? strlen(pipe
->InfoLog
) + 1 : 0;
653 case GL_VALIDATE_STATUS
:
654 *params
= pipe
->Validated
;
656 case GL_VERTEX_SHADER
:
657 *params
= pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]
658 ? pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]->Name
: 0;
660 case GL_TESS_EVALUATION_SHADER
:
663 *params
= pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
]
664 ? pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
]->Name
: 0;
666 case GL_TESS_CONTROL_SHADER
:
669 *params
= pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
]
670 ? pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
]->Name
: 0;
672 case GL_GEOMETRY_SHADER
:
675 *params
= pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
]
676 ? pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->Name
: 0;
678 case GL_FRAGMENT_SHADER
:
679 *params
= pipe
->CurrentProgram
[MESA_SHADER_FRAGMENT
]
680 ? pipe
->CurrentProgram
[MESA_SHADER_FRAGMENT
]->Name
: 0;
682 case GL_COMPUTE_SHADER
:
683 if (!_mesa_has_compute_shaders(ctx
))
685 *params
= pipe
->CurrentProgram
[MESA_SHADER_COMPUTE
]
686 ? pipe
->CurrentProgram
[MESA_SHADER_COMPUTE
]->Name
: 0;
692 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramPipelineiv(pname=%s)",
693 _mesa_enum_to_string(pname
));
697 * Determines whether every stage in a linked program is active in the
698 * specified pipeline.
701 program_stages_all_active(struct gl_pipeline_object
*pipe
,
702 const struct gl_shader_program
*prog
)
710 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
711 if (prog
->_LinkedShaders
[i
]) {
712 if (pipe
->CurrentProgram
[i
]) {
713 if (prog
->Name
!= pipe
->CurrentProgram
[i
]->Name
) {
723 pipe
->InfoLog
= ralloc_asprintf(pipe
,
724 "Program %d is not active for all "
725 "shaders that was linked",
733 program_stages_interleaved_illegally(const struct gl_pipeline_object
*pipe
)
735 struct gl_shader_program
*prev
= NULL
;
738 /* Look for programs bound to stages: A -> B -> A, with any intervening
739 * sequence of unrelated programs or empty stages.
741 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
742 struct gl_shader_program
*cur
= pipe
->CurrentProgram
[i
];
744 /* Empty stages anywhere in the pipe are OK */
745 if (!cur
|| cur
== prev
)
749 /* We've seen an A -> B transition; look at the rest of the pipe
750 * to see if we ever see A again.
752 for (j
= i
+ 1; j
< MESA_SHADER_STAGES
; j
++) {
753 if (pipe
->CurrentProgram
[j
] == prev
)
765 _mesa_validate_program_pipeline(struct gl_context
* ctx
,
766 struct gl_pipeline_object
*pipe
)
769 bool program_empty
= true;
771 pipe
->Validated
= GL_FALSE
;
773 /* Release and reset the info log.
775 if (pipe
->InfoLog
!= NULL
)
776 ralloc_free(pipe
->InfoLog
);
778 pipe
->InfoLog
= NULL
;
780 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
781 * OpenGL 4.1 spec says:
783 * "[INVALID_OPERATION] is generated by any command that transfers
784 * vertices to the GL if:
786 * - A program object is active for at least one, but not all of
787 * the shader stages that were present when the program was
790 * For each possible program stage, verify that the program bound to that
791 * stage has all of its stages active. In other words, if the program
792 * bound to the vertex stage also has a fragment shader, the fragment
793 * shader must also be bound to the fragment stage.
795 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
796 if (!program_stages_all_active(pipe
, pipe
->CurrentProgram
[i
])) {
801 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
802 * OpenGL 4.1 spec says:
804 * "[INVALID_OPERATION] is generated by any command that transfers
805 * vertices to the GL if:
809 * - One program object is active for at least two shader stages
810 * and a second program is active for a shader stage between two
811 * stages for which the first program was active."
813 if (program_stages_interleaved_illegally(pipe
)) {
816 "Program is active for multiple shader stages with an "
817 "intervening stage provided by another program");
821 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
822 * OpenGL 4.1 spec says:
824 * "[INVALID_OPERATION] is generated by any command that transfers
825 * vertices to the GL if:
829 * - There is an active program for tessellation control,
830 * tessellation evaluation, or geometry stages with corresponding
831 * executable shader, but there is no active program with
832 * executable vertex shader."
834 if (!pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]
835 && (pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
] ||
836 pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
] ||
837 pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
])) {
838 pipe
->InfoLog
= ralloc_strdup(pipe
, "Program lacks a vertex shader");
842 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
843 * OpenGL 4.1 spec says:
845 * "[INVALID_OPERATION] is generated by any command that transfers
846 * vertices to the GL if:
850 * - There is no current program object specified by UseProgram,
851 * there is a current program pipeline object, and the current
852 * program for any shader stage has been relinked since being
853 * applied to the pipeline object via UseProgramStages with the
854 * PROGRAM_SEPARABLE parameter set to FALSE.
856 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
857 if (pipe
->CurrentProgram
[i
] && !pipe
->CurrentProgram
[i
]->SeparateShader
) {
858 pipe
->InfoLog
= ralloc_asprintf(pipe
,
859 "Program %d was relinked without "
860 "PROGRAM_SEPARABLE state",
861 pipe
->CurrentProgram
[i
]->Name
);
866 /* Section 11.1.3.11 (Validation) of the OpenGL 4.5 spec says:
868 * "An INVALID_OPERATION error is generated by any command that trans-
869 * fers vertices to the GL or launches compute work if the current set
870 * of active program objects cannot be executed, for reasons including:
874 * - There is no current program object specified by UseProgram,
875 * there is a current program pipeline object, and that object is
876 * empty (no executable code is installed for any stage).
878 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
879 if (pipe
->CurrentProgram
[i
]) {
880 program_empty
= false;
889 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
890 * OpenGL 4.1 spec says:
892 * "[INVALID_OPERATION] is generated by any command that transfers
893 * vertices to the GL if:
897 * - Any two active samplers in the current program object are of
898 * different types, but refer to the same texture image unit.
900 * - The number of active samplers in the program exceeds the
901 * maximum number of texture image units allowed."
903 if (!_mesa_sampler_uniforms_pipeline_are_valid(pipe
))
906 /* Validate inputs against outputs, this cannot be done during linking
907 * since programs have been linked separately from each other.
909 * Section 11.1.3.11 (Validation) of the OpenGL 4.5 Core Profile spec says:
911 * "Separable program objects may have validation failures that cannot be
912 * detected without the complete program pipeline. Mismatched interfaces,
913 * improper usage of program objects together, and the same
914 * state-dependent failures can result in validation errors for such
917 * OpenGL ES 3.1 specification has the same text.
919 * Section 11.1.3.11 (Validation) of the OpenGL ES spec also says:
921 * An INVALID_OPERATION error is generated by any command that transfers
922 * vertices to the GL or launches compute work if the current set of
923 * active program objects cannot be executed, for reasons including:
925 * * The current program pipeline object contains a shader interface
926 * that doesn't have an exact match (see section 7.4.1)
928 * Based on this, only perform the most-strict checking on ES or when the
929 * application has created a debug context.
931 if ((_mesa_is_gles(ctx
) || (ctx
->Const
.ContextFlags
& GL_CONTEXT_FLAG_DEBUG_BIT
)) &&
932 !_mesa_validate_pipeline_io(pipe
)) {
933 if (_mesa_is_gles(ctx
))
936 static GLuint msg_id
= 0;
938 _mesa_gl_debug(ctx
, &msg_id
,
939 MESA_DEBUG_SOURCE_API
,
940 MESA_DEBUG_TYPE_PORTABILITY
,
941 MESA_DEBUG_SEVERITY_MEDIUM
,
942 "glValidateProgramPipeline: pipeline %u does not meet "
943 "strict OpenGL ES 3.1 requirements and may not be "
944 "portable across desktop hardware\n",
948 pipe
->Validated
= GL_TRUE
;
953 * Check compatibility of pipeline's program
956 _mesa_ValidateProgramPipeline(GLuint pipeline
)
958 GET_CURRENT_CONTEXT(ctx
);
960 if (MESA_VERBOSE
& VERBOSE_API
)
961 _mesa_debug(ctx
, "glValidateProgramPipeline(%u)\n", pipeline
);
963 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
966 _mesa_error(ctx
, GL_INVALID_OPERATION
,
967 "glValidateProgramPipeline(pipeline)");
971 _mesa_validate_program_pipeline(ctx
, pipe
);
975 _mesa_GetProgramPipelineInfoLog(GLuint pipeline
, GLsizei bufSize
,
976 GLsizei
*length
, GLchar
*infoLog
)
978 GET_CURRENT_CONTEXT(ctx
);
980 if (MESA_VERBOSE
& VERBOSE_API
)
981 _mesa_debug(ctx
, "glGetProgramPipelineInfoLog(%u, %d, %p, %p)\n",
982 pipeline
, bufSize
, length
, infoLog
);
984 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
987 _mesa_error(ctx
, GL_INVALID_VALUE
,
988 "glGetProgramPipelineInfoLog(pipeline)");
993 _mesa_error(ctx
, GL_INVALID_VALUE
,
994 "glGetProgramPipelineInfoLog(bufSize)");
998 _mesa_copy_string(infoLog
, bufSize
, length
, pipe
->InfoLog
);