1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright © 2012 Intel Corporation
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker *
11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker * Software.
14*61046927SAndroid Build Coastguard Worker *
15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*61046927SAndroid Build Coastguard Worker * IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker */
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard Worker #include "glthread_marshal.h"
25*61046927SAndroid Build Coastguard Worker #include "dispatch.h"
26*61046927SAndroid Build Coastguard Worker #include "uniforms.h"
27*61046927SAndroid Build Coastguard Worker #include "api_exec_decl.h"
28*61046927SAndroid Build Coastguard Worker
29*61046927SAndroid Build Coastguard Worker void
_mesa_glthread_ProgramChanged(struct gl_context * ctx)30*61046927SAndroid Build Coastguard Worker _mesa_glthread_ProgramChanged(struct gl_context *ctx)
31*61046927SAndroid Build Coastguard Worker {
32*61046927SAndroid Build Coastguard Worker struct glthread_state *glthread = &ctx->GLThread;
33*61046927SAndroid Build Coastguard Worker
34*61046927SAndroid Build Coastguard Worker /* Track the last change to shader programs. */
35*61046927SAndroid Build Coastguard Worker _mesa_glthread_fence_call(ctx, &glthread->LastProgramChangeBatch);
36*61046927SAndroid Build Coastguard Worker }
37*61046927SAndroid Build Coastguard Worker
38*61046927SAndroid Build Coastguard Worker uint32_t
_mesa_unmarshal_GetActiveUniform(struct gl_context * ctx,const struct marshal_cmd_GetActiveUniform * restrict cmd)39*61046927SAndroid Build Coastguard Worker _mesa_unmarshal_GetActiveUniform(struct gl_context *ctx,
40*61046927SAndroid Build Coastguard Worker const struct marshal_cmd_GetActiveUniform *restrict cmd)
41*61046927SAndroid Build Coastguard Worker {
42*61046927SAndroid Build Coastguard Worker unreachable("never executed");
43*61046927SAndroid Build Coastguard Worker return 0;
44*61046927SAndroid Build Coastguard Worker }
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard Worker static void
wait_for_glLinkProgram(struct gl_context * ctx)47*61046927SAndroid Build Coastguard Worker wait_for_glLinkProgram(struct gl_context *ctx)
48*61046927SAndroid Build Coastguard Worker {
49*61046927SAndroid Build Coastguard Worker /* Wait for the last glLinkProgram call. */
50*61046927SAndroid Build Coastguard Worker _mesa_glthread_wait_for_call(ctx, &ctx->GLThread.LastProgramChangeBatch);
51*61046927SAndroid Build Coastguard Worker }
52*61046927SAndroid Build Coastguard Worker
53*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_marshal_GetActiveUniform(GLuint program,GLuint index,GLsizei bufSize,GLsizei * length,GLint * size,GLenum * type,GLchar * name)54*61046927SAndroid Build Coastguard Worker _mesa_marshal_GetActiveUniform(GLuint program, GLuint index, GLsizei bufSize,
55*61046927SAndroid Build Coastguard Worker GLsizei *length, GLint *size, GLenum *type,
56*61046927SAndroid Build Coastguard Worker GLchar * name)
57*61046927SAndroid Build Coastguard Worker {
58*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
59*61046927SAndroid Build Coastguard Worker
60*61046927SAndroid Build Coastguard Worker /* This will generate GL_INVALID_OPERATION, as it should. */
61*61046927SAndroid Build Coastguard Worker if (ctx->GLThread.inside_begin_end) {
62*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish_before(ctx, "GetActiveUniform");
63*61046927SAndroid Build Coastguard Worker CALL_GetActiveUniform(ctx->Dispatch.Current,
64*61046927SAndroid Build Coastguard Worker (program, index, bufSize, length, size, type,
65*61046927SAndroid Build Coastguard Worker name));
66*61046927SAndroid Build Coastguard Worker return;
67*61046927SAndroid Build Coastguard Worker }
68*61046927SAndroid Build Coastguard Worker
69*61046927SAndroid Build Coastguard Worker wait_for_glLinkProgram(ctx);
70*61046927SAndroid Build Coastguard Worker
71*61046927SAndroid Build Coastguard Worker /* We can execute glGetActiveUniform without syncing if we are sync'd to
72*61046927SAndroid Build Coastguard Worker * the last calls of glLinkProgram and glDeleteProgram because shader
73*61046927SAndroid Build Coastguard Worker * object IDs and their contents are immutable after those calls and
74*61046927SAndroid Build Coastguard Worker * also thread-safe because they are shared between contexts.
75*61046927SAndroid Build Coastguard Worker * glCreateShaderProgram calls glLinkProgram internally and it always
76*61046927SAndroid Build Coastguard Worker * syncs, so it doesn't need any handling.
77*61046927SAndroid Build Coastguard Worker */
78*61046927SAndroid Build Coastguard Worker _mesa_GetActiveUniform_impl(program, index, bufSize, length, size, type,
79*61046927SAndroid Build Coastguard Worker name, true);
80*61046927SAndroid Build Coastguard Worker }
81*61046927SAndroid Build Coastguard Worker
82*61046927SAndroid Build Coastguard Worker uint32_t
_mesa_unmarshal_GetUniformLocation(struct gl_context * ctx,const struct marshal_cmd_GetUniformLocation * restrict cmd)83*61046927SAndroid Build Coastguard Worker _mesa_unmarshal_GetUniformLocation(struct gl_context *ctx,
84*61046927SAndroid Build Coastguard Worker const struct marshal_cmd_GetUniformLocation *restrict cmd)
85*61046927SAndroid Build Coastguard Worker {
86*61046927SAndroid Build Coastguard Worker unreachable("never executed");
87*61046927SAndroid Build Coastguard Worker return 0;
88*61046927SAndroid Build Coastguard Worker }
89*61046927SAndroid Build Coastguard Worker
90*61046927SAndroid Build Coastguard Worker GLint GLAPIENTRY
_mesa_marshal_GetUniformLocation(GLuint program,const GLchar * name)91*61046927SAndroid Build Coastguard Worker _mesa_marshal_GetUniformLocation(GLuint program, const GLchar *name)
92*61046927SAndroid Build Coastguard Worker {
93*61046927SAndroid Build Coastguard Worker GET_CURRENT_CONTEXT(ctx);
94*61046927SAndroid Build Coastguard Worker
95*61046927SAndroid Build Coastguard Worker /* This will generate GL_INVALID_OPERATION, as it should. */
96*61046927SAndroid Build Coastguard Worker if (ctx->GLThread.inside_begin_end) {
97*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish_before(ctx, "GetUniformLocation");
98*61046927SAndroid Build Coastguard Worker return CALL_GetUniformLocation(ctx->Dispatch.Current, (program, name));
99*61046927SAndroid Build Coastguard Worker }
100*61046927SAndroid Build Coastguard Worker
101*61046927SAndroid Build Coastguard Worker wait_for_glLinkProgram(ctx);
102*61046927SAndroid Build Coastguard Worker
103*61046927SAndroid Build Coastguard Worker /* This is thread-safe. See the comment in _mesa_marshal_GetActiveUniform. */
104*61046927SAndroid Build Coastguard Worker return _mesa_GetUniformLocation_impl(program, name, true);
105*61046927SAndroid Build Coastguard Worker }
106