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