glthread: don't insert _mesa_post_marshal_hook into every function
[mesa.git] / src / mesa / main / marshal.c
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 /** \file marshal.c
25 *
26 * Custom functions for marshalling GL calls from the main thread to a worker
27 * thread when automatic code generation isn't appropriate.
28 */
29
30 #include "main/enums.h"
31 #include "main/macros.h"
32 #include "marshal.h"
33 #include "dispatch.h"
34
35 static inline void
36 _mesa_post_marshal_hook(struct gl_context *ctx)
37 {
38 /* This can be enabled for debugging whether a failure is a synchronization
39 * problem between the main thread and the worker thread, or a failure in
40 * how we actually marshal.
41 */
42 if (false)
43 _mesa_glthread_finish(ctx);
44 }
45
46 struct marshal_cmd_Flush
47 {
48 struct marshal_cmd_base cmd_base;
49 };
50
51
52 void
53 _mesa_unmarshal_Flush(struct gl_context *ctx,
54 const struct marshal_cmd_Flush *cmd)
55 {
56 CALL_Flush(ctx->CurrentServerDispatch, ());
57 }
58
59
60 void GLAPIENTRY
61 _mesa_marshal_Flush(void)
62 {
63 GET_CURRENT_CONTEXT(ctx);
64 struct marshal_cmd_Flush *cmd =
65 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_Flush,
66 sizeof(struct marshal_cmd_Flush));
67 (void) cmd;
68 _mesa_post_marshal_hook(ctx);
69
70 /* Flush() needs to be handled specially. In addition to telling the
71 * background thread to flush, we need to ensure that our own buffer is
72 * submitted to the background thread so that it will complete in a finite
73 * amount of time.
74 */
75 _mesa_glthread_flush_batch(ctx);
76 }
77
78 /* Enable: marshalled asynchronously */
79 struct marshal_cmd_Enable
80 {
81 struct marshal_cmd_base cmd_base;
82 GLenum cap;
83 };
84
85 void
86 _mesa_unmarshal_Enable(struct gl_context *ctx,
87 const struct marshal_cmd_Enable *cmd)
88 {
89 const GLenum cap = cmd->cap;
90 CALL_Enable(ctx->CurrentServerDispatch, (cap));
91 }
92
93 void GLAPIENTRY
94 _mesa_marshal_Enable(GLenum cap)
95 {
96 GET_CURRENT_CONTEXT(ctx);
97 struct marshal_cmd_Enable *cmd;
98 debug_print_marshal("Enable");
99
100 if (cap == GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB) {
101 _mesa_glthread_disable(ctx, "Enable(DEBUG_OUTPUT_SYNCHRONOUS)");
102 } else {
103 cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_Enable,
104 sizeof(*cmd));
105 cmd->cap = cap;
106 _mesa_post_marshal_hook(ctx);
107 return;
108 }
109
110 _mesa_glthread_finish(ctx);
111 debug_print_sync_fallback("Enable");
112 CALL_Enable(ctx->CurrentServerDispatch, (cap));
113 }
114
115 struct marshal_cmd_ShaderSource
116 {
117 struct marshal_cmd_base cmd_base;
118 GLuint shader;
119 GLsizei count;
120 /* Followed by GLint length[count], then the contents of all strings,
121 * concatenated.
122 */
123 };
124
125
126 void
127 _mesa_unmarshal_ShaderSource(struct gl_context *ctx,
128 const struct marshal_cmd_ShaderSource *cmd)
129 {
130 const GLint *cmd_length = (const GLint *) (cmd + 1);
131 const GLchar *cmd_strings = (const GLchar *) (cmd_length + cmd->count);
132 /* TODO: how to deal with malloc failure? */
133 const GLchar * *string = malloc(cmd->count * sizeof(const GLchar *));
134 int i;
135
136 for (i = 0; i < cmd->count; ++i) {
137 string[i] = cmd_strings;
138 cmd_strings += cmd_length[i];
139 }
140 CALL_ShaderSource(ctx->CurrentServerDispatch,
141 (cmd->shader, cmd->count, string, cmd_length));
142 free((void *)string);
143 }
144
145
146 static size_t
147 measure_ShaderSource_strings(GLsizei count, const GLchar * const *string,
148 const GLint *length_in, GLint *length_out)
149 {
150 int i;
151 size_t total_string_length = 0;
152
153 for (i = 0; i < count; ++i) {
154 if (length_in == NULL || length_in[i] < 0) {
155 if (string[i])
156 length_out[i] = strlen(string[i]);
157 } else {
158 length_out[i] = length_in[i];
159 }
160 total_string_length += length_out[i];
161 }
162 return total_string_length;
163 }
164
165
166 void GLAPIENTRY
167 _mesa_marshal_ShaderSource(GLuint shader, GLsizei count,
168 const GLchar * const *string, const GLint *length)
169 {
170 /* TODO: how to report an error if count < 0? */
171
172 GET_CURRENT_CONTEXT(ctx);
173 /* TODO: how to deal with malloc failure? */
174 const size_t fixed_cmd_size = sizeof(struct marshal_cmd_ShaderSource);
175 STATIC_ASSERT(sizeof(struct marshal_cmd_ShaderSource) % sizeof(GLint) == 0);
176 size_t length_size = count * sizeof(GLint);
177 GLint *length_tmp = malloc(length_size);
178 size_t total_string_length =
179 measure_ShaderSource_strings(count, string, length, length_tmp);
180 size_t total_cmd_size = fixed_cmd_size + length_size + total_string_length;
181
182 if (total_cmd_size <= MARSHAL_MAX_CMD_SIZE) {
183 struct marshal_cmd_ShaderSource *cmd =
184 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_ShaderSource,
185 total_cmd_size);
186 GLint *cmd_length = (GLint *) (cmd + 1);
187 GLchar *cmd_strings = (GLchar *) (cmd_length + count);
188 int i;
189
190 cmd->shader = shader;
191 cmd->count = count;
192 memcpy(cmd_length, length_tmp, length_size);
193 for (i = 0; i < count; ++i) {
194 memcpy(cmd_strings, string[i], cmd_length[i]);
195 cmd_strings += cmd_length[i];
196 }
197 _mesa_post_marshal_hook(ctx);
198 } else {
199 _mesa_glthread_finish(ctx);
200 CALL_ShaderSource(ctx->CurrentServerDispatch,
201 (shader, count, string, length_tmp));
202 }
203 free(length_tmp);
204 }
205
206
207 /* BindBufferBase: marshalled asynchronously */
208 struct marshal_cmd_BindBufferBase
209 {
210 struct marshal_cmd_base cmd_base;
211 GLenum target;
212 GLuint index;
213 GLuint buffer;
214 };
215
216 /** Tracks the current bindings for the vertex array and index array buffers.
217 *
218 * This is part of what we need to enable glthread on compat-GL contexts that
219 * happen to use VBOs, without also supporting the full tracking of VBO vs
220 * user vertex array bindings per attribute on each vertex array for
221 * determining what to upload at draw call time.
222 *
223 * Note that GL core makes it so that a buffer binding with an invalid handle
224 * in the "buffer" parameter will throw an error, and then a
225 * glVertexAttribPointer() that followsmight not end up pointing at a VBO.
226 * However, in GL core the draw call would throw an error as well, so we don't
227 * really care if our tracking is wrong for this case -- we never need to
228 * marshal user data for draw calls, and the unmarshal will just generate an
229 * error or not as appropriate.
230 *
231 * For compatibility GL, we do need to accurately know whether the draw call
232 * on the unmarshal side will dereference a user pointer or load data from a
233 * VBO per vertex. That would make it seem like we need to track whether a
234 * "buffer" is valid, so that we can know when an error will be generated
235 * instead of updating the binding. However, compat GL has the ridiculous
236 * feature that if you pass a bad name, it just gens a buffer object for you,
237 * so we escape without having to know if things are valid or not.
238 */
239 static void
240 track_vbo_binding(struct gl_context *ctx, GLenum target, GLuint buffer)
241 {
242 struct glthread_state *glthread = ctx->GLThread;
243
244 switch (target) {
245 case GL_ARRAY_BUFFER:
246 glthread->vertex_array_is_vbo = (buffer != 0);
247 break;
248 case GL_ELEMENT_ARRAY_BUFFER:
249 /* The current element array buffer binding is actually tracked in the
250 * vertex array object instead of the context, so this would need to
251 * change on vertex array object updates.
252 */
253 glthread->element_array_is_vbo = (buffer != 0);
254 break;
255 }
256 }
257
258
259 struct marshal_cmd_BindBuffer
260 {
261 struct marshal_cmd_base cmd_base;
262 GLenum target;
263 GLuint buffer;
264 };
265
266 /**
267 * This is just like the code-generated glBindBuffer() support, except that we
268 * call track_vbo_binding().
269 */
270 void
271 _mesa_unmarshal_BindBuffer(struct gl_context *ctx,
272 const struct marshal_cmd_BindBuffer *cmd)
273 {
274 const GLenum target = cmd->target;
275 const GLuint buffer = cmd->buffer;
276 CALL_BindBuffer(ctx->CurrentServerDispatch, (target, buffer));
277 }
278 void GLAPIENTRY
279 _mesa_marshal_BindBuffer(GLenum target, GLuint buffer)
280 {
281 GET_CURRENT_CONTEXT(ctx);
282 size_t cmd_size = sizeof(struct marshal_cmd_BindBuffer);
283 struct marshal_cmd_BindBuffer *cmd;
284 debug_print_marshal("BindBuffer");
285
286 track_vbo_binding(ctx, target, buffer);
287
288 if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {
289 cmd = _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BindBuffer,
290 cmd_size);
291 cmd->target = target;
292 cmd->buffer = buffer;
293 _mesa_post_marshal_hook(ctx);
294 } else {
295 _mesa_glthread_finish(ctx);
296 CALL_BindBuffer(ctx->CurrentServerDispatch, (target, buffer));
297 }
298 }
299
300 /* BufferData: marshalled asynchronously */
301 struct marshal_cmd_BufferData
302 {
303 struct marshal_cmd_base cmd_base;
304 GLenum target;
305 GLsizeiptr size;
306 GLenum usage;
307 bool data_null; /* If set, no data follows for "data" */
308 /* Next size bytes are GLubyte data[size] */
309 };
310
311 void
312 _mesa_unmarshal_BufferData(struct gl_context *ctx,
313 const struct marshal_cmd_BufferData *cmd)
314 {
315 const GLenum target = cmd->target;
316 const GLsizeiptr size = cmd->size;
317 const GLenum usage = cmd->usage;
318 const void *data;
319
320 if (cmd->data_null)
321 data = NULL;
322 else
323 data = (const void *) (cmd + 1);
324
325 CALL_BufferData(ctx->CurrentServerDispatch, (target, size, data, usage));
326 }
327
328 void GLAPIENTRY
329 _mesa_marshal_BufferData(GLenum target, GLsizeiptr size, const GLvoid * data,
330 GLenum usage)
331 {
332 GET_CURRENT_CONTEXT(ctx);
333 size_t cmd_size =
334 sizeof(struct marshal_cmd_BufferData) + (data ? size : 0);
335 debug_print_marshal("BufferData");
336
337 if (unlikely(size < 0)) {
338 _mesa_glthread_finish(ctx);
339 _mesa_error(ctx, GL_INVALID_VALUE, "BufferData(size < 0)");
340 return;
341 }
342
343 if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&
344 cmd_size <= MARSHAL_MAX_CMD_SIZE) {
345 struct marshal_cmd_BufferData *cmd =
346 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BufferData,
347 cmd_size);
348
349 cmd->target = target;
350 cmd->size = size;
351 cmd->usage = usage;
352 cmd->data_null = !data;
353 if (data) {
354 char *variable_data = (char *) (cmd + 1);
355 memcpy(variable_data, data, size);
356 }
357 _mesa_post_marshal_hook(ctx);
358 } else {
359 _mesa_glthread_finish(ctx);
360 CALL_BufferData(ctx->CurrentServerDispatch,
361 (target, size, data, usage));
362 }
363 }
364
365 /* BufferSubData: marshalled asynchronously */
366 struct marshal_cmd_BufferSubData
367 {
368 struct marshal_cmd_base cmd_base;
369 GLenum target;
370 GLintptr offset;
371 GLsizeiptr size;
372 /* Next size bytes are GLubyte data[size] */
373 };
374
375 void
376 _mesa_unmarshal_BufferSubData(struct gl_context *ctx,
377 const struct marshal_cmd_BufferSubData *cmd)
378 {
379 const GLenum target = cmd->target;
380 const GLintptr offset = cmd->offset;
381 const GLsizeiptr size = cmd->size;
382 const void *data = (const void *) (cmd + 1);
383
384 CALL_BufferSubData(ctx->CurrentServerDispatch,
385 (target, offset, size, data));
386 }
387
388 void GLAPIENTRY
389 _mesa_marshal_BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size,
390 const GLvoid * data)
391 {
392 GET_CURRENT_CONTEXT(ctx);
393 size_t cmd_size = sizeof(struct marshal_cmd_BufferSubData) + size;
394
395 debug_print_marshal("BufferSubData");
396 if (unlikely(size < 0)) {
397 _mesa_glthread_finish(ctx);
398 _mesa_error(ctx, GL_INVALID_VALUE, "BufferSubData(size < 0)");
399 return;
400 }
401
402 if (target != GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD &&
403 cmd_size <= MARSHAL_MAX_CMD_SIZE) {
404 struct marshal_cmd_BufferSubData *cmd =
405 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_BufferSubData,
406 cmd_size);
407 cmd->target = target;
408 cmd->offset = offset;
409 cmd->size = size;
410 char *variable_data = (char *) (cmd + 1);
411 memcpy(variable_data, data, size);
412 _mesa_post_marshal_hook(ctx);
413 } else {
414 _mesa_glthread_finish(ctx);
415 CALL_BufferSubData(ctx->CurrentServerDispatch,
416 (target, offset, size, data));
417 }
418 }
419
420 /* NamedBufferData: marshalled asynchronously */
421 struct marshal_cmd_NamedBufferData
422 {
423 struct marshal_cmd_base cmd_base;
424 GLuint name;
425 GLsizei size;
426 GLenum usage;
427 bool data_null; /* If set, no data follows for "data" */
428 /* Next size bytes are GLubyte data[size] */
429 };
430
431 void
432 _mesa_unmarshal_NamedBufferData(struct gl_context *ctx,
433 const struct marshal_cmd_NamedBufferData *cmd)
434 {
435 const GLuint name = cmd->name;
436 const GLsizei size = cmd->size;
437 const GLenum usage = cmd->usage;
438 const void *data;
439
440 if (cmd->data_null)
441 data = NULL;
442 else
443 data = (const void *) (cmd + 1);
444
445 CALL_NamedBufferData(ctx->CurrentServerDispatch,
446 (name, size, data, usage));
447 }
448
449 void GLAPIENTRY
450 _mesa_marshal_NamedBufferData(GLuint buffer, GLsizeiptr size,
451 const GLvoid * data, GLenum usage)
452 {
453 GET_CURRENT_CONTEXT(ctx);
454 size_t cmd_size = sizeof(struct marshal_cmd_NamedBufferData) + (data ? size : 0);
455
456 debug_print_marshal("NamedBufferData");
457 if (unlikely(size < 0)) {
458 _mesa_glthread_finish(ctx);
459 _mesa_error(ctx, GL_INVALID_VALUE, "NamedBufferData(size < 0)");
460 return;
461 }
462
463 if (buffer > 0 && cmd_size <= MARSHAL_MAX_CMD_SIZE) {
464 struct marshal_cmd_NamedBufferData *cmd =
465 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_NamedBufferData,
466 cmd_size);
467 cmd->name = buffer;
468 cmd->size = size;
469 cmd->usage = usage;
470 cmd->data_null = !data;
471 if (data) {
472 char *variable_data = (char *) (cmd + 1);
473 memcpy(variable_data, data, size);
474 }
475 _mesa_post_marshal_hook(ctx);
476 } else {
477 _mesa_glthread_finish(ctx);
478 CALL_NamedBufferData(ctx->CurrentServerDispatch,
479 (buffer, size, data, usage));
480 }
481 }
482
483 /* NamedBufferSubData: marshalled asynchronously */
484 struct marshal_cmd_NamedBufferSubData
485 {
486 struct marshal_cmd_base cmd_base;
487 GLuint name;
488 GLintptr offset;
489 GLsizei size;
490 /* Next size bytes are GLubyte data[size] */
491 };
492
493 void
494 _mesa_unmarshal_NamedBufferSubData(struct gl_context *ctx,
495 const struct marshal_cmd_NamedBufferSubData *cmd)
496 {
497 const GLuint name = cmd->name;
498 const GLintptr offset = cmd->offset;
499 const GLsizei size = cmd->size;
500 const void *data = (const void *) (cmd + 1);
501
502 CALL_NamedBufferSubData(ctx->CurrentServerDispatch,
503 (name, offset, size, data));
504 }
505
506 void GLAPIENTRY
507 _mesa_marshal_NamedBufferSubData(GLuint buffer, GLintptr offset,
508 GLsizeiptr size, const GLvoid * data)
509 {
510 GET_CURRENT_CONTEXT(ctx);
511 size_t cmd_size = sizeof(struct marshal_cmd_NamedBufferSubData) + size;
512
513 debug_print_marshal("NamedBufferSubData");
514 if (unlikely(size < 0)) {
515 _mesa_glthread_finish(ctx);
516 _mesa_error(ctx, GL_INVALID_VALUE, "NamedBufferSubData(size < 0)");
517 return;
518 }
519
520 if (buffer > 0 && cmd_size <= MARSHAL_MAX_CMD_SIZE) {
521 struct marshal_cmd_NamedBufferSubData *cmd =
522 _mesa_glthread_allocate_command(ctx, DISPATCH_CMD_NamedBufferSubData,
523 cmd_size);
524 cmd->name = buffer;
525 cmd->offset = offset;
526 cmd->size = size;
527 char *variable_data = (char *) (cmd + 1);
528 memcpy(variable_data, data, size);
529 _mesa_post_marshal_hook(ctx);
530 } else {
531 _mesa_glthread_finish(ctx);
532 CALL_NamedBufferSubData(ctx->CurrentServerDispatch,
533 (buffer, offset, size, data));
534 }
535 }
536
537 /* ClearBuffer* (all variants): marshalled asynchronously */
538 struct marshal_cmd_ClearBuffer
539 {
540 struct marshal_cmd_base cmd_base;
541 GLenum buffer;
542 GLint drawbuffer;
543 };
544
545 void
546 _mesa_unmarshal_ClearBufferfv(struct gl_context *ctx,
547 const struct marshal_cmd_ClearBuffer *cmd)
548 {
549 const GLenum buffer = cmd->buffer;
550 const GLint drawbuffer = cmd->drawbuffer;
551 const char *variable_data = (const char *) (cmd + 1);
552 const GLfloat *value = (const GLfloat *) variable_data;
553
554 CALL_ClearBufferfv(ctx->CurrentServerDispatch,
555 (buffer, drawbuffer, value));
556 }
557
558 void
559 _mesa_unmarshal_ClearBufferiv(struct gl_context *ctx,
560 const struct marshal_cmd_ClearBuffer *cmd)
561 {
562 const GLenum buffer = cmd->buffer;
563 const GLint drawbuffer = cmd->drawbuffer;
564 const char *variable_data = (const char *) (cmd + 1);
565 const GLint *value = (const GLint *) variable_data;
566
567 CALL_ClearBufferiv(ctx->CurrentServerDispatch,
568 (buffer, drawbuffer, value));
569 }
570
571 void
572 _mesa_unmarshal_ClearBufferuiv(struct gl_context *ctx,
573 const struct marshal_cmd_ClearBuffer *cmd)
574 {
575 const GLenum buffer = cmd->buffer;
576 const GLint drawbuffer = cmd->drawbuffer;
577 const char *variable_data = (const char *) (cmd + 1);
578 const GLuint *value = (const GLuint *) variable_data;
579
580 CALL_ClearBufferuiv(ctx->CurrentServerDispatch,
581 (buffer, drawbuffer, value));
582 }
583
584 void
585 _mesa_unmarshal_ClearBufferfi(struct gl_context *ctx,
586 const struct marshal_cmd_ClearBuffer *cmd)
587 {
588 const GLenum buffer = cmd->buffer;
589 const GLint drawbuffer = cmd->drawbuffer;
590 const char *variable_data = (const char *) (cmd + 1);
591 const GLfloat *depth = (const GLfloat *) variable_data;
592 const GLint *stencil = (const GLint *) (variable_data + 4);
593
594 CALL_ClearBufferfi(ctx->CurrentServerDispatch,
595 (buffer, drawbuffer, *depth, *stencil));
596 }
597
598 static inline size_t buffer_to_size(GLenum buffer)
599 {
600 switch (buffer) {
601 case GL_COLOR:
602 return 4;
603 case GL_DEPTH_STENCIL:
604 return 2;
605 case GL_STENCIL:
606 case GL_DEPTH:
607 return 1;
608 default:
609 return 0;
610 }
611 }
612
613 static inline bool clear_buffer_add_command(struct gl_context *ctx, uint16_t id,
614 GLenum buffer, GLint drawbuffer,
615 const GLuint *value, size_t size)
616 {
617 size_t cmd_size = sizeof(struct marshal_cmd_ClearBuffer) + 4 * size;
618 if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {
619 struct marshal_cmd_ClearBuffer *cmd =
620 _mesa_glthread_allocate_command(ctx, id,
621 cmd_size);
622 cmd->buffer = buffer;
623 cmd->drawbuffer = drawbuffer;
624 GLuint *variable_data = (GLuint *) (cmd + 1);
625 if (size == 4)
626 COPY_4V(variable_data, value);
627 else if (size == 2)
628 COPY_2V(variable_data, value);
629 else
630 *variable_data = *value;
631
632 _mesa_post_marshal_hook(ctx);
633 return true;
634 }
635
636 return false;
637 }
638
639 void GLAPIENTRY
640 _mesa_marshal_ClearBufferfv(GLenum buffer, GLint drawbuffer,
641 const GLfloat *value)
642 {
643 GET_CURRENT_CONTEXT(ctx);
644 debug_print_marshal("ClearBufferfv");
645
646 if (!(buffer == GL_DEPTH || buffer == GL_COLOR)) {
647 _mesa_glthread_finish(ctx);
648
649 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
650 * of the OpenGL 4.5 spec states:
651 *
652 * "An INVALID_ENUM error is generated by ClearBufferfv and
653 * ClearNamedFramebufferfv if buffer is not COLOR or DEPTH."
654 */
655 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfv(buffer=%s)",
656 _mesa_enum_to_string(buffer));
657 }
658
659 size_t size = buffer_to_size(buffer);
660 if (!clear_buffer_add_command(ctx, DISPATCH_CMD_ClearBufferfv, buffer,
661 drawbuffer, (GLuint *)value, size)) {
662 debug_print_sync("ClearBufferfv");
663 _mesa_glthread_finish(ctx);
664 CALL_ClearBufferfv(ctx->CurrentServerDispatch,
665 (buffer, drawbuffer, value));
666 }
667 }
668
669 void GLAPIENTRY
670 _mesa_marshal_ClearBufferiv(GLenum buffer, GLint drawbuffer,
671 const GLint *value)
672 {
673 GET_CURRENT_CONTEXT(ctx);
674 debug_print_marshal("ClearBufferiv");
675
676 if (!(buffer == GL_STENCIL || buffer == GL_COLOR)) {
677 _mesa_glthread_finish(ctx);
678
679 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
680 * of the OpenGL 4.5 spec states:
681 *
682 * "An INVALID_ENUM error is generated by ClearBufferiv and
683 * ClearNamedFramebufferiv if buffer is not COLOR or STENCIL."
684 */
685 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferiv(buffer=%s)",
686 _mesa_enum_to_string(buffer));
687 }
688
689 size_t size = buffer_to_size(buffer);
690 if (!clear_buffer_add_command(ctx, DISPATCH_CMD_ClearBufferiv, buffer,
691 drawbuffer, (GLuint *)value, size)) {
692 debug_print_sync("ClearBufferiv");
693 _mesa_glthread_finish(ctx);
694 CALL_ClearBufferiv(ctx->CurrentServerDispatch,
695 (buffer, drawbuffer, value));
696 }
697 }
698
699 void GLAPIENTRY
700 _mesa_marshal_ClearBufferuiv(GLenum buffer, GLint drawbuffer,
701 const GLuint *value)
702 {
703 GET_CURRENT_CONTEXT(ctx);
704 debug_print_marshal("ClearBufferuiv");
705
706 if (buffer != GL_COLOR) {
707 _mesa_glthread_finish(ctx);
708
709 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
710 * of the OpenGL 4.5 spec states:
711 *
712 * "An INVALID_ENUM error is generated by ClearBufferuiv and
713 * ClearNamedFramebufferuiv if buffer is not COLOR."
714 */
715 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferuiv(buffer=%s)",
716 _mesa_enum_to_string(buffer));
717 }
718
719 if (!clear_buffer_add_command(ctx, DISPATCH_CMD_ClearBufferuiv, buffer,
720 drawbuffer, (GLuint *)value, 4)) {
721 debug_print_sync("ClearBufferuiv");
722 _mesa_glthread_finish(ctx);
723 CALL_ClearBufferuiv(ctx->CurrentServerDispatch,
724 (buffer, drawbuffer, value));
725 }
726 }
727
728 void GLAPIENTRY
729 _mesa_marshal_ClearBufferfi(GLenum buffer, GLint drawbuffer,
730 const GLfloat depth, const GLint stencil)
731 {
732 GET_CURRENT_CONTEXT(ctx);
733 debug_print_marshal("ClearBufferfi");
734
735 if (buffer != GL_DEPTH_STENCIL) {
736 _mesa_glthread_finish(ctx);
737
738 /* Page 498 of the PDF, section '17.4.3.1 Clearing Individual Buffers'
739 * of the OpenGL 4.5 spec states:
740 *
741 * "An INVALID_ENUM error is generated by ClearBufferfi and
742 * ClearNamedFramebufferfi if buffer is not DEPTH_STENCIL."
743 */
744 _mesa_error(ctx, GL_INVALID_ENUM, "glClearBufferfi(buffer=%s)",
745 _mesa_enum_to_string(buffer));
746 }
747
748 fi_type value[2];
749 value[0].f = depth;
750 value[1].i = stencil;
751 if (!clear_buffer_add_command(ctx, DISPATCH_CMD_ClearBufferfi, buffer,
752 drawbuffer, (GLuint *)value, 2)) {
753 debug_print_sync("ClearBufferfi");
754 _mesa_glthread_finish(ctx);
755 CALL_ClearBufferfi(ctx->CurrentServerDispatch,
756 (buffer, drawbuffer, depth, stencil));
757 }
758 }