buildimage: Use "rsvg-convert" as the default RSVG command.
[wine.git] / dlls / wined3d / drawprim.c
blob235f87bfa7d20e9fd62eb2e8ab5fe5bfbea259e0
1 /*
2 * WINED3D draw functions
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2002-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006, 2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "config.h"
28 #include "wine/port.h"
30 #include "wined3d_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d_draw);
33 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
34 WINE_DECLARE_DEBUG_CHANNEL(d3d);
36 #include <stdio.h>
37 #include <math.h>
39 /* Context activation is done by the caller. */
40 static void draw_primitive_arrays(struct wined3d_context *context, const struct wined3d_state *state,
41 const void *idx_data, unsigned int idx_size, int base_vertex_idx, unsigned int start_idx,
42 unsigned int count, unsigned int start_instance, unsigned int instance_count)
44 const struct wined3d_ffp_attrib_ops *ops = &context->d3d_info->ffp_attrib_ops;
45 GLenum idx_type = idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
46 const struct wined3d_stream_info *si = &context->stream_info;
47 unsigned int instanced_elements[ARRAY_SIZE(si->elements)];
48 const struct wined3d_gl_info *gl_info = context->gl_info;
49 unsigned int instanced_element_count = 0;
50 unsigned int i, j;
52 if (!instance_count)
54 if (!idx_size)
56 gl_info->gl_ops.gl.p_glDrawArrays(state->gl_primitive_type, start_idx, count);
57 checkGLcall("glDrawArrays");
58 return;
61 if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
63 GL_EXTCALL(glDrawElementsBaseVertex(state->gl_primitive_type, count, idx_type,
64 (const char *)idx_data + (idx_size * start_idx), base_vertex_idx));
65 checkGLcall("glDrawElementsBaseVertex");
66 return;
69 gl_info->gl_ops.gl.p_glDrawElements(state->gl_primitive_type, count,
70 idx_type, (const char *)idx_data + (idx_size * start_idx));
71 checkGLcall("glDrawElements");
72 return;
75 if (start_instance)
76 FIXME("Start instance (%u) not supported.\n", start_instance);
78 if (gl_info->supported[ARB_INSTANCED_ARRAYS])
80 if (!idx_size)
82 GL_EXTCALL(glDrawArraysInstanced(state->gl_primitive_type, start_idx, count, instance_count));
83 checkGLcall("glDrawArraysInstanced");
84 return;
87 if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
89 GL_EXTCALL(glDrawElementsInstancedBaseVertex(state->gl_primitive_type, count, idx_type,
90 (const char *)idx_data + (idx_size * start_idx), instance_count, base_vertex_idx));
91 checkGLcall("glDrawElementsInstancedBaseVertex");
92 return;
95 GL_EXTCALL(glDrawElementsInstanced(state->gl_primitive_type, count, idx_type,
96 (const char *)idx_data + (idx_size * start_idx), instance_count));
97 checkGLcall("glDrawElementsInstanced");
98 return;
101 /* Instancing emulation by mixing immediate mode and arrays. */
103 /* This is a nasty thing. MSDN says no hardware supports this and
104 * applications have to use software vertex processing. We don't support
105 * this for now.
107 * Shouldn't be too hard to support with OpenGL, in theory just call
108 * glDrawArrays() instead of drawElements(). But the stream fequency value
109 * has a different meaning in that situation. */
110 if (!idx_size)
112 FIXME("Non-indexed instanced drawing is not supported\n");
113 return;
116 for (i = 0; i < ARRAY_SIZE(si->elements); ++i)
118 if (!(si->use_map & (1u << i)))
119 continue;
121 if (state->streams[si->elements[i].stream_idx].flags & WINED3DSTREAMSOURCE_INSTANCEDATA)
122 instanced_elements[instanced_element_count++] = i;
125 for (i = 0; i < instance_count; ++i)
127 /* Specify the instanced attributes using immediate mode calls. */
128 for (j = 0; j < instanced_element_count; ++j)
130 const struct wined3d_stream_info_element *element;
131 unsigned int element_idx;
132 const BYTE *ptr;
134 element_idx = instanced_elements[j];
135 element = &si->elements[element_idx];
136 ptr = element->data.addr + element->stride * i;
137 if (element->data.buffer_object)
138 ptr += (ULONG_PTR)wined3d_buffer_load_sysmem(state->streams[element->stream_idx].buffer, context);
139 ops->generic[element->format->emit_idx](element_idx, ptr);
142 if (gl_info->supported[ARB_DRAW_ELEMENTS_BASE_VERTEX])
144 GL_EXTCALL(glDrawElementsBaseVertex(state->gl_primitive_type, count, idx_type,
145 (const char *)idx_data + (idx_size * start_idx), base_vertex_idx));
146 checkGLcall("glDrawElementsBaseVertex");
148 else
150 gl_info->gl_ops.gl.p_glDrawElements(state->gl_primitive_type, count, idx_type,
151 (const char *)idx_data + (idx_size * start_idx));
152 checkGLcall("glDrawElements");
157 static unsigned int get_stride_idx(const void *idx_data, unsigned int idx_size,
158 unsigned int base_vertex_idx, unsigned int start_idx, unsigned int vertex_idx)
160 if (!idx_data)
161 return start_idx + vertex_idx;
162 if (idx_size == 2)
163 return ((const WORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
164 return ((const DWORD *)idx_data)[start_idx + vertex_idx] + base_vertex_idx;
167 /* Context activation is done by the caller. */
168 static void draw_primitive_immediate_mode(struct wined3d_context *context, const struct wined3d_state *state,
169 const struct wined3d_stream_info *si, const void *idx_data, unsigned int idx_size,
170 int base_vertex_idx, unsigned int start_idx, unsigned int vertex_count, unsigned int instance_count)
172 const BYTE *position = NULL, *normal = NULL, *diffuse = NULL, *specular = NULL;
173 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
174 unsigned int coord_idx, stride_idx, texture_idx, vertex_idx;
175 const struct wined3d_gl_info *gl_info = context->gl_info;
176 const struct wined3d_stream_info_element *element;
177 const BYTE *tex_coords[WINED3DDP_MAXTEXCOORD];
178 unsigned int texture_unit, texture_stages;
179 const struct wined3d_ffp_attrib_ops *ops;
180 unsigned int untracked_material_count;
181 unsigned int tex_mask = 0;
182 BOOL specular_fog = FALSE;
183 BOOL ps = use_ps(state);
184 const void *ptr;
186 static unsigned int once;
188 if (!once++)
189 FIXME_(d3d_perf)("Drawing using immediate mode.\n");
190 else
191 WARN_(d3d_perf)("Drawing using immediate mode.\n");
193 if (!idx_size && idx_data)
194 ERR("Non-NULL idx_data with 0 idx_size, this should never happen.\n");
196 if (instance_count)
197 FIXME("Instancing not implemented.\n");
199 /* Immediate mode drawing can't make use of indices in a VBO - get the
200 * data from the index buffer. */
201 if (idx_size)
202 idx_data = wined3d_buffer_load_sysmem(state->index_buffer, context) + state->index_offset;
204 ops = &d3d_info->ffp_attrib_ops;
206 gl_info->gl_ops.gl.p_glBegin(state->gl_primitive_type);
208 if (use_vs(state) || d3d_info->ffp_generic_attributes)
210 for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
212 unsigned int use_map = si->use_map;
213 unsigned int element_idx;
215 stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
216 for (element_idx = MAX_ATTRIBS - 1; use_map; use_map &= ~(1u << element_idx), --element_idx)
218 if (!(use_map & 1u << element_idx))
219 continue;
221 ptr = si->elements[element_idx].data.addr + si->elements[element_idx].stride * stride_idx;
222 ops->generic[si->elements[element_idx].format->emit_idx](element_idx, ptr);
226 gl_info->gl_ops.gl.p_glEnd();
227 return;
230 if (si->use_map & (1u << WINED3D_FFP_POSITION))
231 position = si->elements[WINED3D_FFP_POSITION].data.addr;
233 if (si->use_map & (1u << WINED3D_FFP_NORMAL))
234 normal = si->elements[WINED3D_FFP_NORMAL].data.addr;
235 else
236 gl_info->gl_ops.gl.p_glNormal3f(0.0f, 0.0f, 0.0f);
238 untracked_material_count = context->num_untracked_materials;
239 if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
241 element = &si->elements[WINED3D_FFP_DIFFUSE];
242 diffuse = element->data.addr;
244 if (untracked_material_count && element->format->id != WINED3DFMT_B8G8R8A8_UNORM)
245 FIXME("Implement diffuse color tracking from %s.\n", debug_d3dformat(element->format->id));
247 else
249 gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
252 if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
254 element = &si->elements[WINED3D_FFP_SPECULAR];
255 specular = element->data.addr;
257 /* Special case where the fog density is stored in the specular alpha channel. */
258 if (state->render_states[WINED3D_RS_FOGENABLE]
259 && (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE
260 || si->elements[WINED3D_FFP_POSITION].format->id == WINED3DFMT_R32G32B32A32_FLOAT)
261 && state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
263 if (gl_info->supported[EXT_FOG_COORD])
265 if (element->format->id == WINED3DFMT_B8G8R8A8_UNORM)
266 specular_fog = TRUE;
267 else
268 FIXME("Implement fog coordinates from %s.\n", debug_d3dformat(element->format->id));
270 else
272 static unsigned int once;
274 if (!once++)
275 FIXME("Implement fog for transformed vertices in software.\n");
279 else if (gl_info->supported[EXT_SECONDARY_COLOR])
281 GL_EXTCALL(glSecondaryColor3fEXT)(0.0f, 0.0f, 0.0f);
284 texture_stages = d3d_info->limits.ffp_blend_stages;
285 for (texture_idx = 0; texture_idx < texture_stages; ++texture_idx)
287 if (!gl_info->supported[ARB_MULTITEXTURE] && texture_idx > 0)
289 FIXME("Program using multiple concurrent textures which this OpenGL implementation doesn't support.\n");
290 continue;
293 if (!ps && !state->textures[texture_idx])
294 continue;
296 texture_unit = context->tex_unit_map[texture_idx];
297 if (texture_unit == WINED3D_UNMAPPED_STAGE)
298 continue;
300 coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
301 if (coord_idx > 7)
303 TRACE("Skipping generated coordinates (%#x) for texture %u.\n", coord_idx, texture_idx);
304 continue;
307 if (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx)))
309 tex_coords[coord_idx] = si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].data.addr;
310 tex_mask |= (1u << texture_idx);
312 else
314 TRACE("Setting default coordinates for texture %u.\n", texture_idx);
315 if (gl_info->supported[ARB_MULTITEXTURE])
316 GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_unit, 0.0f, 0.0f, 0.0f, 1.0f));
317 else
318 gl_info->gl_ops.gl.p_glTexCoord4f(0.0f, 0.0f, 0.0f, 1.0f);
322 /* Blending data and point sizes are not supported by this function. They
323 * are not supported by the fixed function pipeline at all. A FIXME for
324 * them is printed after decoding the vertex declaration. */
325 for (vertex_idx = 0; vertex_idx < vertex_count; ++vertex_idx)
327 unsigned int tmp_tex_mask;
329 stride_idx = get_stride_idx(idx_data, idx_size, base_vertex_idx, start_idx, vertex_idx);
331 if (normal)
333 ptr = normal + stride_idx * si->elements[WINED3D_FFP_NORMAL].stride;
334 ops->normal[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptr);
337 if (diffuse)
339 ptr = diffuse + stride_idx * si->elements[WINED3D_FFP_DIFFUSE].stride;
340 ops->diffuse[si->elements[WINED3D_FFP_DIFFUSE].format->emit_idx](ptr);
342 if (untracked_material_count)
344 struct wined3d_color color;
345 unsigned int i;
347 wined3d_color_from_d3dcolor(&color, *(const DWORD *)ptr);
348 for (i = 0; i < untracked_material_count; ++i)
350 gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, context->untracked_materials[i], &color.r);
355 if (specular)
357 ptr = specular + stride_idx * si->elements[WINED3D_FFP_SPECULAR].stride;
358 ops->specular[si->elements[WINED3D_FFP_SPECULAR].format->emit_idx](ptr);
360 if (specular_fog)
361 GL_EXTCALL(glFogCoordfEXT((float)(*(const DWORD *)ptr >> 24)));
364 tmp_tex_mask = tex_mask;
365 for (texture_idx = 0; tmp_tex_mask; tmp_tex_mask >>= 1, ++texture_idx)
367 if (!(tmp_tex_mask & 1))
368 continue;
370 coord_idx = state->texture_states[texture_idx][WINED3D_TSS_TEXCOORD_INDEX];
371 ptr = tex_coords[coord_idx] + (stride_idx * si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].stride);
372 ops->texcoord[si->elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->emit_idx](
373 GL_TEXTURE0_ARB + context->tex_unit_map[texture_idx], ptr);
376 if (position)
378 ptr = position + stride_idx * si->elements[WINED3D_FFP_POSITION].stride;
379 ops->position[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptr);
383 gl_info->gl_ops.gl.p_glEnd();
384 checkGLcall("glEnd and previous calls");
387 static void remove_vbos(struct wined3d_context *context,
388 const struct wined3d_state *state, struct wined3d_stream_info *s)
390 unsigned int i;
392 for (i = 0; i < ARRAY_SIZE(s->elements); ++i)
394 struct wined3d_stream_info_element *e;
396 if (!(s->use_map & (1u << i)))
397 continue;
399 e = &s->elements[i];
400 if (e->data.buffer_object)
402 struct wined3d_buffer *vb = state->streams[e->stream_idx].buffer;
403 e->data.buffer_object = 0;
404 e->data.addr += (ULONG_PTR)wined3d_buffer_load_sysmem(vb, context);
409 static BOOL use_transform_feedback(const struct wined3d_state *state)
411 const struct wined3d_shader *shader;
412 if (!(shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY]))
413 return FALSE;
414 return shader->u.gs.so_desc.element_count;
417 static void context_pause_transform_feedback(struct wined3d_context *context, BOOL force)
419 const struct wined3d_gl_info *gl_info = context->gl_info;
421 if (!context->transform_feedback_active || context->transform_feedback_paused)
422 return;
424 if (gl_info->supported[ARB_TRANSFORM_FEEDBACK2])
426 GL_EXTCALL(glPauseTransformFeedback());
427 checkGLcall("glPauseTransformFeedback");
428 context->transform_feedback_paused = 1;
429 return;
432 WARN("Cannot pause transform feedback operations.\n");
434 if (force)
435 context_end_transform_feedback(context);
438 static GLenum gl_tfb_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
440 GLenum gl_primitive_type = gl_primitive_type_from_d3d(primitive_type);
441 switch (gl_primitive_type)
443 case GL_POINTS:
444 return GL_POINTS;
446 case GL_LINE_STRIP:
447 case GL_LINE_STRIP_ADJACENCY:
448 case GL_LINES_ADJACENCY:
449 case GL_LINES:
450 return GL_LINES;
452 case GL_TRIANGLE_FAN:
453 case GL_TRIANGLE_STRIP:
454 case GL_TRIANGLE_STRIP_ADJACENCY:
455 case GL_TRIANGLES_ADJACENCY:
456 case GL_TRIANGLES:
457 return GL_TRIANGLES;
459 default:
460 return gl_primitive_type;
464 /* Routine common to the draw primitive and draw indexed primitive routines */
465 void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
466 int base_vertex_idx, unsigned int start_idx, unsigned int index_count,
467 unsigned int start_instance, unsigned int instance_count, BOOL indexed)
469 BOOL emulation = FALSE, rasterizer_discard = FALSE;
470 const struct wined3d_fb_state *fb = state->fb;
471 const struct wined3d_stream_info *stream_info;
472 struct wined3d_rendertarget_view *dsv, *rtv;
473 struct wined3d_stream_info si_emulated;
474 struct wined3d_fence *ib_fence = NULL;
475 const struct wined3d_gl_info *gl_info;
476 struct wined3d_context *context;
477 unsigned int i, idx_size = 0;
478 const void *idx_data = NULL;
480 if (!index_count)
481 return;
483 if (!(rtv = fb->render_targets[0]))
484 rtv = fb->depth_stencil;
485 if (rtv)
486 context = context_acquire(device, wined3d_texture_from_resource(rtv->resource), rtv->sub_resource_idx);
487 else
488 context = context_acquire(device, NULL, 0);
489 if (!context->valid)
491 context_release(context);
492 WARN("Invalid context, skipping draw.\n");
493 return;
495 gl_info = context->gl_info;
497 if (!use_transform_feedback(state))
498 context_pause_transform_feedback(context, TRUE);
500 for (i = 0; i < gl_info->limits.buffers; ++i)
502 if (!(rtv = fb->render_targets[i]) || rtv->format->id == WINED3DFMT_NULL)
503 continue;
505 if (state->render_states[WINED3D_RS_COLORWRITEENABLE])
507 wined3d_rendertarget_view_load_location(rtv, context, rtv->resource->draw_binding);
508 wined3d_rendertarget_view_invalidate_location(rtv, ~rtv->resource->draw_binding);
510 else
512 wined3d_rendertarget_view_prepare_location(rtv, context, rtv->resource->draw_binding);
516 if ((dsv = fb->depth_stencil))
518 /* Note that this depends on the context_acquire() call above to set
519 * context->render_offscreen properly. We don't currently take the
520 * Z-compare function into account, but we could skip loading the
521 * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
522 * that we never copy the stencil data.*/
523 DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
525 if (state->render_states[WINED3D_RS_ZWRITEENABLE] || state->render_states[WINED3D_RS_ZENABLE])
526 wined3d_rendertarget_view_load_location(dsv, context, location);
527 else
528 wined3d_rendertarget_view_prepare_location(dsv, context, location);
531 if (!context_apply_draw_state(context, device, state))
533 context_release(context);
534 WARN("Unable to apply draw state, skipping draw.\n");
535 return;
538 if (dsv && state->render_states[WINED3D_RS_ZWRITEENABLE])
540 DWORD location = context->render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
542 wined3d_rendertarget_view_validate_location(dsv, location);
543 wined3d_rendertarget_view_invalidate_location(dsv, ~location);
546 stream_info = &context->stream_info;
547 if (context->instance_count)
548 instance_count = context->instance_count;
550 if (indexed)
552 struct wined3d_buffer *index_buffer = state->index_buffer;
553 if (!index_buffer->buffer_object || !stream_info->all_vbo)
555 idx_data = index_buffer->resource.heap_memory;
557 else
559 ib_fence = index_buffer->fence;
560 idx_data = NULL;
562 idx_data = (const BYTE *)idx_data + state->index_offset;
564 if (state->index_format == WINED3DFMT_R16_UINT)
565 idx_size = 2;
566 else
567 idx_size = 4;
570 if (!use_vs(state))
572 if (!stream_info->position_transformed && context->num_untracked_materials
573 && state->render_states[WINED3D_RS_LIGHTING])
575 static BOOL warned;
577 if (!warned++)
578 FIXME("Using software emulation because not all material properties could be tracked.\n");
579 else
580 WARN_(d3d_perf)("Using software emulation because not all material properties could be tracked.\n");
581 emulation = TRUE;
583 else if (context->fog_coord && state->render_states[WINED3D_RS_FOGENABLE])
585 static BOOL warned;
587 /* Either write a pipeline replacement shader or convert the
588 * specular alpha from unsigned byte to a float in the vertex
589 * buffer. */
590 if (!warned++)
591 FIXME("Using software emulation because manual fog coordinates are provided.\n");
592 else
593 WARN_(d3d_perf)("Using software emulation because manual fog coordinates are provided.\n");
594 emulation = TRUE;
597 if (emulation)
599 si_emulated = context->stream_info;
600 remove_vbos(context, state, &si_emulated);
601 stream_info = &si_emulated;
605 if (use_transform_feedback(state))
607 const struct wined3d_shader *shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY];
609 if (shader->u.gs.so_desc.rasterizer_stream_idx == WINED3D_NO_RASTERIZER_STREAM)
611 glEnable(GL_RASTERIZER_DISCARD);
612 checkGLcall("enable rasterizer discard");
613 rasterizer_discard = TRUE;
616 if (context->transform_feedback_paused)
618 GL_EXTCALL(glResumeTransformFeedback());
619 checkGLcall("glResumeTransformFeedback");
620 context->transform_feedback_paused = 0;
622 else if (!context->transform_feedback_active)
624 GLenum mode = gl_tfb_primitive_type_from_d3d(shader->u.gs.output_type);
625 GL_EXTCALL(glBeginTransformFeedback(mode));
626 checkGLcall("glBeginTransformFeedback");
627 context->transform_feedback_active = 1;
631 if (state->gl_primitive_type == GL_PATCHES)
633 GL_EXTCALL(glPatchParameteri(GL_PATCH_VERTICES, state->gl_patch_vertices));
634 checkGLcall("glPatchParameteri");
637 if (context->use_immediate_mode_draw || emulation)
638 draw_primitive_immediate_mode(context, state, stream_info, idx_data,
639 idx_size, base_vertex_idx, start_idx, index_count, instance_count);
640 else
641 draw_primitive_arrays(context, state, idx_data, idx_size, base_vertex_idx,
642 start_idx, index_count, start_instance, instance_count);
644 if (context->uses_uavs)
646 GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
647 checkGLcall("glMemoryBarrier");
650 context_pause_transform_feedback(context, FALSE);
652 if (rasterizer_discard)
654 glDisable(GL_RASTERIZER_DISCARD);
655 checkGLcall("disable rasterizer discard");
658 if (ib_fence)
659 wined3d_fence_issue(ib_fence, device);
660 for (i = 0; i < context->buffer_fence_count; ++i)
661 wined3d_fence_issue(context->buffer_fences[i], device);
663 if (wined3d_settings.strict_draw_ordering)
664 gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
666 context_release(context);
668 TRACE("Done all gl drawing.\n");
671 void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
672 const struct wined3d_dispatch_parameters *parameters)
674 const struct wined3d_gl_info *gl_info;
675 struct wined3d_context *context;
677 context = context_acquire(device, NULL, 0);
678 if (!context->valid)
680 context_release(context);
681 WARN("Invalid context, skipping dispatch.\n");
682 return;
684 gl_info = context->gl_info;
686 if (!gl_info->supported[ARB_COMPUTE_SHADER])
688 context_release(context);
689 FIXME("OpenGL implementation does not support compute shaders.\n");
690 return;
693 context_apply_compute_state(context, device, state);
695 if (!state->shader[WINED3D_SHADER_TYPE_COMPUTE])
697 context_release(context);
698 WARN("No compute shader bound, skipping dispatch.\n");
699 return;
702 if (parameters->indirect)
704 const struct wined3d_indirect_dispatch_parameters *indirect = &parameters->u.indirect;
705 struct wined3d_buffer *buffer = indirect->buffer;
707 wined3d_buffer_load(buffer, context, state);
708 GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer->buffer_object));
709 GL_EXTCALL(glDispatchComputeIndirect((GLintptr)indirect->offset));
710 GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0));
712 else
714 const struct wined3d_direct_dispatch_parameters *direct = &parameters->u.direct;
715 GL_EXTCALL(glDispatchCompute(direct->group_count_x, direct->group_count_y, direct->group_count_z));
717 checkGLcall("dispatch compute");
719 GL_EXTCALL(glMemoryBarrier(GL_ALL_BARRIER_BITS));
720 checkGLcall("glMemoryBarrier");
722 if (wined3d_settings.strict_draw_ordering)
723 gl_info->gl_ops.gl.p_glFlush(); /* Flush to ensure ordering across contexts. */
725 context_release(context);