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_program(ctx
, &obj
->_CurrentFragmentProgram
, NULL
);
63 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
64 _mesa_reference_program(ctx
, &obj
->CurrentProgram
[i
], NULL
);
65 _mesa_reference_shader_program(ctx
, &obj
->ReferencedPrograms
[i
], NULL
);
68 _mesa_reference_shader_program(ctx
, &obj
->ActiveProgram
, NULL
);
74 * Allocate and initialize a new pipeline object.
76 static struct gl_pipeline_object
*
77 _mesa_new_pipeline_object(struct gl_context
*ctx
, GLuint name
)
79 struct gl_pipeline_object
*obj
= rzalloc(NULL
, struct gl_pipeline_object
);
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_HashLookupLocked(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_HashInsertLocked(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_HashRemoveLocked(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 struct gl_pipeline_object
*oldObj
= *ptr
;
189 assert(oldObj
->RefCount
> 0);
192 if (oldObj
->RefCount
== 0) {
193 _mesa_delete_pipeline_object(ctx
, oldObj
);
201 /* reference new pipeline object */
202 assert(obj
->RefCount
> 0);
210 use_program_stage(struct gl_context
*ctx
, GLenum type
,
211 struct gl_shader_program
*shProg
,
212 struct gl_pipeline_object
*pipe
) {
213 gl_shader_stage stage
= _mesa_shader_enum_to_shader_stage(type
);
214 struct gl_program
*prog
= NULL
;
215 if (shProg
&& shProg
->_LinkedShaders
[stage
])
216 prog
= shProg
->_LinkedShaders
[stage
]->Program
;
218 _mesa_use_program(ctx
, stage
, shProg
, prog
, pipe
);
222 use_program_stages(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
223 GLbitfield stages
, struct gl_pipeline_object
*pipe
) {
225 /* Enable individual stages from the program as requested by the
226 * application. If there is no shader for a requested stage in the
227 * program, _mesa_use_shader_program will enable fixed-function processing
228 * as dictated by the spec.
230 * Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec
233 * "If UseProgramStages is called with program set to zero or with a
234 * program object that contains no executable code for the given
235 * stages, it is as if the pipeline object has no programmable stage
236 * configured for the indicated shader stages."
238 if ((stages
& GL_VERTEX_SHADER_BIT
) != 0)
239 use_program_stage(ctx
, GL_VERTEX_SHADER
, shProg
, pipe
);
241 if ((stages
& GL_FRAGMENT_SHADER_BIT
) != 0)
242 use_program_stage(ctx
, GL_FRAGMENT_SHADER
, shProg
, pipe
);
244 if ((stages
& GL_GEOMETRY_SHADER_BIT
) != 0)
245 use_program_stage(ctx
, GL_GEOMETRY_SHADER
, shProg
, pipe
);
247 if ((stages
& GL_TESS_CONTROL_SHADER_BIT
) != 0)
248 use_program_stage(ctx
, GL_TESS_CONTROL_SHADER
, shProg
, pipe
);
250 if ((stages
& GL_TESS_EVALUATION_SHADER_BIT
) != 0)
251 use_program_stage(ctx
, GL_TESS_EVALUATION_SHADER
, shProg
, pipe
);
253 if ((stages
& GL_COMPUTE_SHADER_BIT
) != 0)
254 use_program_stage(ctx
, GL_COMPUTE_SHADER
, shProg
, pipe
);
256 pipe
->Validated
= false;
260 _mesa_UseProgramStages_no_error(GLuint pipeline
, GLbitfield stages
,
263 GET_CURRENT_CONTEXT(ctx
);
265 struct gl_pipeline_object
*pipe
=
266 _mesa_lookup_pipeline_object(ctx
, pipeline
);
267 struct gl_shader_program
*shProg
= NULL
;
270 _mesa_lookup_shader_program(ctx
, prog
);
272 /* Object is created by any Pipeline call but glGenProgramPipelines,
273 * glIsProgramPipeline and GetProgramPipelineInfoLog
275 pipe
->EverBound
= GL_TRUE
;
277 use_program_stages(ctx
, shProg
, stages
, pipe
);
281 * Bound program to severals stages of the pipeline
284 _mesa_UseProgramStages(GLuint pipeline
, GLbitfield stages
, GLuint program
)
286 GET_CURRENT_CONTEXT(ctx
);
288 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
289 struct gl_shader_program
*shProg
= NULL
;
290 GLbitfield any_valid_stages
;
292 if (MESA_VERBOSE
& VERBOSE_API
)
293 _mesa_debug(ctx
, "glUseProgramStages(%u, 0x%x, %u)\n",
294 pipeline
, stages
, program
);
297 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUseProgramStages(pipeline)");
301 /* Object is created by any Pipeline call but glGenProgramPipelines,
302 * glIsProgramPipeline and GetProgramPipelineInfoLog
304 pipe
->EverBound
= GL_TRUE
;
306 /* Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec says:
308 * "If stages is not the special value ALL_SHADER_BITS, and has a bit
309 * set that is not recognized, the error INVALID_VALUE is generated."
311 any_valid_stages
= GL_VERTEX_SHADER_BIT
| GL_FRAGMENT_SHADER_BIT
;
312 if (_mesa_has_geometry_shaders(ctx
))
313 any_valid_stages
|= GL_GEOMETRY_SHADER_BIT
;
314 if (_mesa_has_tessellation(ctx
))
315 any_valid_stages
|= GL_TESS_CONTROL_SHADER_BIT
|
316 GL_TESS_EVALUATION_SHADER_BIT
;
317 if (_mesa_has_compute_shaders(ctx
))
318 any_valid_stages
|= GL_COMPUTE_SHADER_BIT
;
320 if (stages
!= GL_ALL_SHADER_BITS
&& (stages
& ~any_valid_stages
) != 0) {
321 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUseProgramStages(Stages)");
325 /* Section 2.17.2 (Transform Feedback Primitive Capture) of the OpenGL 4.1
328 * "The error INVALID_OPERATION is generated:
332 * - by UseProgramStages if the program pipeline object it refers
333 * to is current and the current transform feedback object is
334 * active and not paused;
336 if (ctx
->_Shader
== pipe
) {
337 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
339 "glUseProgramStages(transform feedback active)");
345 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
346 "glUseProgramStages");
350 /* Section 2.11.4 (Program Pipeline Objects) of the OpenGL 4.1 spec
353 * "If the program object named by program was linked without the
354 * PROGRAM_SEPARABLE parameter set, or was not linked successfully,
355 * the error INVALID_OPERATION is generated and the corresponding
356 * shader stages in the pipeline program pipeline object are not
359 if (!shProg
->data
->LinkStatus
) {
360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
361 "glUseProgramStages(program not linked)");
365 if (!shProg
->SeparateShader
) {
366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
367 "glUseProgramStages(program wasn't linked with the "
368 "PROGRAM_SEPARABLE flag)");
373 use_program_stages(ctx
, shProg
, stages
, pipe
);
377 * Use the named shader program for subsequent glUniform calls (if pipeline
381 _mesa_ActiveShaderProgram(GLuint pipeline
, GLuint program
)
383 GET_CURRENT_CONTEXT(ctx
);
384 struct gl_shader_program
*shProg
= NULL
;
385 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
387 if (MESA_VERBOSE
& VERBOSE_API
)
388 _mesa_debug(ctx
, "glActiveShaderProgram(%u, %u)\n", pipeline
, program
);
391 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
392 "glActiveShaderProgram(program)");
398 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glActiveShaderProgram(pipeline)");
402 /* Object is created by any Pipeline call but glGenProgramPipelines,
403 * glIsProgramPipeline and GetProgramPipelineInfoLog
405 pipe
->EverBound
= GL_TRUE
;
407 if ((shProg
!= NULL
) && !shProg
->data
->LinkStatus
) {
408 _mesa_error(ctx
, GL_INVALID_OPERATION
,
409 "glActiveShaderProgram(program %u not linked)", shProg
->Name
);
413 _mesa_reference_shader_program(ctx
, &pipe
->ActiveProgram
, shProg
);
417 * Make program of the pipeline current
420 _mesa_BindProgramPipeline(GLuint pipeline
)
422 GET_CURRENT_CONTEXT(ctx
);
423 struct gl_pipeline_object
*newObj
= NULL
;
425 if (MESA_VERBOSE
& VERBOSE_API
)
426 _mesa_debug(ctx
, "glBindProgramPipeline(%u)\n", pipeline
);
428 /* Rebinding the same pipeline object: no change.
430 if (ctx
->_Shader
->Name
== pipeline
)
433 /* Section 2.17.2 (Transform Feedback Primitive Capture) of the OpenGL 4.1
436 * "The error INVALID_OPERATION is generated:
440 * - by BindProgramPipeline if the current transform feedback
441 * object is active and not paused;
443 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
444 _mesa_error(ctx
, GL_INVALID_OPERATION
,
445 "glBindProgramPipeline(transform feedback active)");
449 /* Get pointer to new pipeline object (newObj)
452 /* non-default pipeline object */
453 newObj
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
455 _mesa_error(ctx
, GL_INVALID_OPERATION
,
456 "glBindProgramPipeline(non-gen name)");
460 /* Object is created by any Pipeline call but glGenProgramPipelines,
461 * glIsProgramPipeline and GetProgramPipelineInfoLog
463 newObj
->EverBound
= GL_TRUE
;
466 _mesa_bind_pipeline(ctx
, newObj
);
470 _mesa_bind_pipeline(struct gl_context
*ctx
,
471 struct gl_pipeline_object
*pipe
)
474 /* First bind the Pipeline to pipeline binding point */
475 _mesa_reference_pipeline_object(ctx
, &ctx
->Pipeline
.Current
, pipe
);
477 /* Section 2.11.3 (Program Objects) of the OpenGL 4.1 spec says:
479 * "If there is a current program object established by UseProgram,
480 * that program is considered current for all stages. Otherwise, if
481 * there is a bound program pipeline object (see section 2.11.4), the
482 * program bound to the appropriate stage of the pipeline object is
483 * considered current."
485 if (&ctx
->Shader
!= ctx
->_Shader
) {
487 /* Bound the pipeline to the current program and
488 * restore the pipeline state
490 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
, pipe
);
492 /* Unbind the pipeline */
493 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
,
494 ctx
->Pipeline
.Default
);
497 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
499 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
500 struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[i
];
502 _mesa_program_init_subroutine_defaults(ctx
, prog
);
509 * Delete a set of pipeline objects.
511 * \param n Number of pipeline objects to delete.
512 * \param ids pipeline of \c n pipeline object IDs.
515 _mesa_DeleteProgramPipelines(GLsizei n
, const GLuint
*pipelines
)
517 GET_CURRENT_CONTEXT(ctx
);
520 if (MESA_VERBOSE
& VERBOSE_API
)
521 _mesa_debug(ctx
, "glDeleteProgramPipelines(%d, %p)\n", n
, pipelines
);
524 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteProgramPipelines(n<0)");
528 for (i
= 0; i
< n
; i
++) {
529 struct gl_pipeline_object
*obj
=
530 _mesa_lookup_pipeline_object(ctx
, pipelines
[i
]);
533 assert(obj
->Name
== pipelines
[i
]);
535 /* If the pipeline object is currently bound, the spec says "If an
536 * object that is currently bound is deleted, the binding for that
537 * object reverts to zero and no program pipeline object becomes
540 if (obj
== ctx
->Pipeline
.Current
) {
541 _mesa_BindProgramPipeline(0);
544 /* The ID is immediately freed for re-use */
545 remove_pipeline_object(ctx
, obj
);
547 /* Unreference the pipeline object.
548 * If refcount hits zero, the object will be deleted.
550 _mesa_reference_pipeline_object(ctx
, &obj
, NULL
);
556 * Generate a set of unique pipeline object IDs and store them in \c pipelines.
557 * \param n Number of IDs to generate.
558 * \param pipelines pipeline of \c n locations to store the IDs.
561 create_program_pipelines(struct gl_context
*ctx
, GLsizei n
, GLuint
*pipelines
,
568 func
= dsa
? "glCreateProgramPipelines" : "glGenProgramPipelines";
571 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s (n < 0)", func
);
579 first
= _mesa_HashFindFreeKeyBlock(ctx
->Pipeline
.Objects
, n
);
581 for (i
= 0; i
< n
; i
++) {
582 struct gl_pipeline_object
*obj
;
583 GLuint name
= first
+ i
;
585 obj
= _mesa_new_pipeline_object(ctx
, name
);
587 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
592 /* make dsa-allocated objects behave like program objects */
593 obj
->EverBound
= GL_TRUE
;
596 save_pipeline_object(ctx
, obj
);
597 pipelines
[i
] = first
+ i
;
603 _mesa_GenProgramPipelines(GLsizei n
, GLuint
*pipelines
)
605 GET_CURRENT_CONTEXT(ctx
);
607 if (MESA_VERBOSE
& VERBOSE_API
)
608 _mesa_debug(ctx
, "glGenProgramPipelines(%d, %p)\n", n
, pipelines
);
610 create_program_pipelines(ctx
, n
, pipelines
, false);
614 _mesa_CreateProgramPipelines(GLsizei n
, GLuint
*pipelines
)
616 GET_CURRENT_CONTEXT(ctx
);
618 if (MESA_VERBOSE
& VERBOSE_API
)
619 _mesa_debug(ctx
, "glCreateProgramPipelines(%d, %p)\n", n
, pipelines
);
621 create_program_pipelines(ctx
, n
, pipelines
, true);
625 * Determine if ID is the name of an pipeline object.
627 * \param id ID of the potential pipeline object.
628 * \return \c GL_TRUE if \c id is the name of a pipeline object,
629 * \c GL_FALSE otherwise.
632 _mesa_IsProgramPipeline(GLuint pipeline
)
634 GET_CURRENT_CONTEXT(ctx
);
636 if (MESA_VERBOSE
& VERBOSE_API
)
637 _mesa_debug(ctx
, "glIsProgramPipeline(%u)\n", pipeline
);
639 struct gl_pipeline_object
*obj
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
643 return obj
->EverBound
;
647 * glGetProgramPipelineiv() - get pipeline shader state.
650 _mesa_GetProgramPipelineiv(GLuint pipeline
, GLenum pname
, GLint
*params
)
652 GET_CURRENT_CONTEXT(ctx
);
653 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
655 if (MESA_VERBOSE
& VERBOSE_API
)
656 _mesa_debug(ctx
, "glGetProgramPipelineiv(%u, %d, %p)\n",
657 pipeline
, pname
, params
);
659 /* Are geometry shaders available in this context?
661 const bool has_gs
= _mesa_has_geometry_shaders(ctx
);
662 const bool has_tess
= _mesa_has_tessellation(ctx
);
665 _mesa_error(ctx
, GL_INVALID_OPERATION
,
666 "glGetProgramPipelineiv(pipeline)");
670 /* Object is created by any Pipeline call but glGenProgramPipelines,
671 * glIsProgramPipeline and GetProgramPipelineInfoLog
673 pipe
->EverBound
= GL_TRUE
;
676 case GL_ACTIVE_PROGRAM
:
677 *params
= pipe
->ActiveProgram
? pipe
->ActiveProgram
->Name
: 0;
679 case GL_INFO_LOG_LENGTH
:
680 *params
= (pipe
->InfoLog
&& pipe
->InfoLog
[0] != '\0') ?
681 strlen(pipe
->InfoLog
) + 1 : 0;
683 case GL_VALIDATE_STATUS
:
684 *params
= pipe
->Validated
;
686 case GL_VERTEX_SHADER
:
687 *params
= pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]
688 ? pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]->Id
: 0;
690 case GL_TESS_EVALUATION_SHADER
:
693 *params
= pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
]
694 ? pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
]->Id
: 0;
696 case GL_TESS_CONTROL_SHADER
:
699 *params
= pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
]
700 ? pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
]->Id
: 0;
702 case GL_GEOMETRY_SHADER
:
705 *params
= pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
]
706 ? pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->Id
: 0;
708 case GL_FRAGMENT_SHADER
:
709 *params
= pipe
->CurrentProgram
[MESA_SHADER_FRAGMENT
]
710 ? pipe
->CurrentProgram
[MESA_SHADER_FRAGMENT
]->Id
: 0;
712 case GL_COMPUTE_SHADER
:
713 if (!_mesa_has_compute_shaders(ctx
))
715 *params
= pipe
->CurrentProgram
[MESA_SHADER_COMPUTE
]
716 ? pipe
->CurrentProgram
[MESA_SHADER_COMPUTE
]->Id
: 0;
722 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramPipelineiv(pname=%s)",
723 _mesa_enum_to_string(pname
));
727 * Determines whether every stage in a linked program is active in the
728 * specified pipeline.
731 program_stages_all_active(struct gl_pipeline_object
*pipe
,
732 const struct gl_program
*prog
)
739 unsigned mask
= prog
->sh
.data
->linked_stages
;
741 const int i
= u_bit_scan(&mask
);
742 if (pipe
->CurrentProgram
[i
]) {
743 if (prog
->Id
!= pipe
->CurrentProgram
[i
]->Id
) {
752 pipe
->InfoLog
= ralloc_asprintf(pipe
,
753 "Program %d is not active for all "
754 "shaders that was linked",
762 program_stages_interleaved_illegally(const struct gl_pipeline_object
*pipe
)
764 unsigned prev_linked_stages
= 0;
766 /* Look for programs bound to stages: A -> B -> A, with any intervening
767 * sequence of unrelated programs or empty stages.
769 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
770 struct gl_program
*cur
= pipe
->CurrentProgram
[i
];
772 /* Empty stages anywhere in the pipe are OK. Also we can be confident
773 * that if the linked_stages mask matches we are looking at the same
774 * linked program because a previous validation call to
775 * program_stages_all_active() will have already failed if two different
776 * programs with the sames stages linked are not active for all linked
779 if (!cur
|| cur
->sh
.data
->linked_stages
== prev_linked_stages
)
782 if (prev_linked_stages
) {
783 /* We've seen an A -> B transition; look at the rest of the pipe
784 * to see if we ever see A again.
786 if (prev_linked_stages
>> (i
+ 1))
790 prev_linked_stages
= cur
->sh
.data
->linked_stages
;
797 _mesa_validate_program_pipeline(struct gl_context
* ctx
,
798 struct gl_pipeline_object
*pipe
)
801 bool program_empty
= true;
803 pipe
->Validated
= GL_FALSE
;
805 /* Release and reset the info log.
807 if (pipe
->InfoLog
!= NULL
)
808 ralloc_free(pipe
->InfoLog
);
810 pipe
->InfoLog
= NULL
;
812 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
813 * OpenGL 4.1 spec says:
815 * "[INVALID_OPERATION] is generated by any command that transfers
816 * vertices to the GL if:
818 * - A program object is active for at least one, but not all of
819 * the shader stages that were present when the program was
822 * For each possible program stage, verify that the program bound to that
823 * stage has all of its stages active. In other words, if the program
824 * bound to the vertex stage also has a fragment shader, the fragment
825 * shader must also be bound to the fragment stage.
827 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
828 if (!program_stages_all_active(pipe
, pipe
->CurrentProgram
[i
])) {
833 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
834 * OpenGL 4.1 spec says:
836 * "[INVALID_OPERATION] is generated by any command that transfers
837 * vertices to the GL if:
841 * - One program object is active for at least two shader stages
842 * and a second program is active for a shader stage between two
843 * stages for which the first program was active."
845 if (program_stages_interleaved_illegally(pipe
)) {
848 "Program is active for multiple shader stages with an "
849 "intervening stage provided by another program");
853 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
854 * OpenGL 4.1 spec says:
856 * "[INVALID_OPERATION] is generated by any command that transfers
857 * vertices to the GL if:
861 * - There is an active program for tessellation control,
862 * tessellation evaluation, or geometry stages with corresponding
863 * executable shader, but there is no active program with
864 * executable vertex shader."
866 if (!pipe
->CurrentProgram
[MESA_SHADER_VERTEX
]
867 && (pipe
->CurrentProgram
[MESA_SHADER_GEOMETRY
] ||
868 pipe
->CurrentProgram
[MESA_SHADER_TESS_CTRL
] ||
869 pipe
->CurrentProgram
[MESA_SHADER_TESS_EVAL
])) {
870 pipe
->InfoLog
= ralloc_strdup(pipe
, "Program lacks a vertex shader");
874 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
875 * OpenGL 4.1 spec says:
877 * "[INVALID_OPERATION] is generated by any command that transfers
878 * vertices to the GL if:
882 * - There is no current program object specified by UseProgram,
883 * there is a current program pipeline object, and the current
884 * program for any shader stage has been relinked since being
885 * applied to the pipeline object via UseProgramStages with the
886 * PROGRAM_SEPARABLE parameter set to FALSE.
888 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
889 if (pipe
->CurrentProgram
[i
] &&
890 !pipe
->CurrentProgram
[i
]->info
.separate_shader
) {
891 pipe
->InfoLog
= ralloc_asprintf(pipe
,
892 "Program %d was relinked without "
893 "PROGRAM_SEPARABLE state",
894 pipe
->CurrentProgram
[i
]->Id
);
899 /* Section 11.1.3.11 (Validation) of the OpenGL 4.5 spec says:
901 * "An INVALID_OPERATION error is generated by any command that trans-
902 * fers vertices to the GL or launches compute work if the current set
903 * of active program objects cannot be executed, for reasons including:
907 * - There is no current program object specified by UseProgram,
908 * there is a current program pipeline object, and that object is
909 * empty (no executable code is installed for any stage).
911 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
912 if (pipe
->CurrentProgram
[i
]) {
913 program_empty
= false;
922 /* Section 2.11.11 (Shader Execution), subheading "Validation," of the
923 * OpenGL 4.1 spec says:
925 * "[INVALID_OPERATION] is generated by any command that transfers
926 * vertices to the GL if:
930 * - Any two active samplers in the current program object are of
931 * different types, but refer to the same texture image unit.
933 * - The number of active samplers in the program exceeds the
934 * maximum number of texture image units allowed."
936 if (!_mesa_sampler_uniforms_pipeline_are_valid(pipe
))
939 /* Validate inputs against outputs, this cannot be done during linking
940 * since programs have been linked separately from each other.
942 * Section 11.1.3.11 (Validation) of the OpenGL 4.5 Core Profile spec says:
944 * "Separable program objects may have validation failures that cannot be
945 * detected without the complete program pipeline. Mismatched interfaces,
946 * improper usage of program objects together, and the same
947 * state-dependent failures can result in validation errors for such
950 * OpenGL ES 3.1 specification has the same text.
952 * Section 11.1.3.11 (Validation) of the OpenGL ES spec also says:
954 * An INVALID_OPERATION error is generated by any command that transfers
955 * vertices to the GL or launches compute work if the current set of
956 * active program objects cannot be executed, for reasons including:
958 * * The current program pipeline object contains a shader interface
959 * that doesn't have an exact match (see section 7.4.1)
961 * Based on this, only perform the most-strict checking on ES or when the
962 * application has created a debug context.
964 if ((_mesa_is_gles(ctx
) || (ctx
->Const
.ContextFlags
& GL_CONTEXT_FLAG_DEBUG_BIT
)) &&
965 !_mesa_validate_pipeline_io(pipe
)) {
966 if (_mesa_is_gles(ctx
))
969 static GLuint msg_id
= 0;
971 _mesa_gl_debug(ctx
, &msg_id
,
972 MESA_DEBUG_SOURCE_API
,
973 MESA_DEBUG_TYPE_PORTABILITY
,
974 MESA_DEBUG_SEVERITY_MEDIUM
,
975 "glValidateProgramPipeline: pipeline %u does not meet "
976 "strict OpenGL ES 3.1 requirements and may not be "
977 "portable across desktop hardware\n",
981 pipe
->Validated
= GL_TRUE
;
986 * Check compatibility of pipeline's program
989 _mesa_ValidateProgramPipeline(GLuint pipeline
)
991 GET_CURRENT_CONTEXT(ctx
);
993 if (MESA_VERBOSE
& VERBOSE_API
)
994 _mesa_debug(ctx
, "glValidateProgramPipeline(%u)\n", pipeline
);
996 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1000 "glValidateProgramPipeline(pipeline)");
1004 _mesa_validate_program_pipeline(ctx
, pipe
);
1008 _mesa_GetProgramPipelineInfoLog(GLuint pipeline
, GLsizei bufSize
,
1009 GLsizei
*length
, GLchar
*infoLog
)
1011 GET_CURRENT_CONTEXT(ctx
);
1013 if (MESA_VERBOSE
& VERBOSE_API
)
1014 _mesa_debug(ctx
, "glGetProgramPipelineInfoLog(%u, %d, %p, %p)\n",
1015 pipeline
, bufSize
, length
, infoLog
);
1017 struct gl_pipeline_object
*pipe
= _mesa_lookup_pipeline_object(ctx
, pipeline
);
1020 _mesa_error(ctx
, GL_INVALID_VALUE
,
1021 "glGetProgramPipelineInfoLog(pipeline)");
1026 _mesa_error(ctx
, GL_INVALID_VALUE
,
1027 "glGetProgramPipelineInfoLog(bufSize)");
1031 _mesa_copy_string(infoLog
, bufSize
, length
, pipe
->InfoLog
);