2 * Copyright 2013 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
21 #include "wined3d_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
24 WINE_DECLARE_DEBUG_CHANNEL(d3d_sync
);
25 WINE_DECLARE_DEBUG_CHANNEL(fps
);
27 #define WINED3D_INITIAL_CS_SIZE 4096
29 struct wined3d_command_list
33 struct wined3d_device
*device
;
38 SIZE_T resource_count
;
39 struct wined3d_resource
**resources
;
41 /* List of command lists queued for execution on this command list. We might
42 * be the only thing holding a pointer to another command list, so we need
43 * to hold a reference here (and in wined3d_deferred_context) as well. */
44 SIZE_T command_list_count
;
45 struct wined3d_command_list
**command_lists
;
48 static void wined3d_command_list_destroy_object(void *object
)
50 struct wined3d_command_list
*list
= object
;
52 TRACE("list %p.\n", list
);
54 heap_free(list
->resources
);
55 heap_free(list
->data
);
59 ULONG CDECL
wined3d_command_list_incref(struct wined3d_command_list
*list
)
61 ULONG refcount
= InterlockedIncrement(&list
->refcount
);
63 TRACE("%p increasing refcount to %u.\n", list
, refcount
);
68 ULONG CDECL
wined3d_command_list_decref(struct wined3d_command_list
*list
)
70 ULONG refcount
= InterlockedDecrement(&list
->refcount
);
71 struct wined3d_device
*device
= list
->device
;
73 TRACE("%p decreasing refcount to %u.\n", list
, refcount
);
79 for (i
= 0; i
< list
->command_list_count
; ++i
)
80 wined3d_command_list_decref(list
->command_lists
[i
]);
81 for (i
= 0; i
< list
->resource_count
; ++i
)
82 wined3d_resource_decref(list
->resources
[i
]);
84 wined3d_cs_destroy_object(device
->cs
, wined3d_command_list_destroy_object
, list
);
93 WINED3D_CS_OP_PRESENT
,
95 WINED3D_CS_OP_DISPATCH
,
98 WINED3D_CS_OP_SET_PREDICATION
,
99 WINED3D_CS_OP_SET_VIEWPORTS
,
100 WINED3D_CS_OP_SET_SCISSOR_RECTS
,
101 WINED3D_CS_OP_SET_RENDERTARGET_VIEW
,
102 WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW
,
103 WINED3D_CS_OP_SET_VERTEX_DECLARATION
,
104 WINED3D_CS_OP_SET_STREAM_SOURCE
,
105 WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ
,
106 WINED3D_CS_OP_SET_STREAM_OUTPUT
,
107 WINED3D_CS_OP_SET_INDEX_BUFFER
,
108 WINED3D_CS_OP_SET_CONSTANT_BUFFER
,
109 WINED3D_CS_OP_SET_TEXTURE
,
110 WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW
,
111 WINED3D_CS_OP_SET_UNORDERED_ACCESS_VIEW
,
112 WINED3D_CS_OP_SET_SAMPLER
,
113 WINED3D_CS_OP_SET_SHADER
,
114 WINED3D_CS_OP_SET_BLEND_STATE
,
115 WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE
,
116 WINED3D_CS_OP_SET_RASTERIZER_STATE
,
117 WINED3D_CS_OP_SET_RENDER_STATE
,
118 WINED3D_CS_OP_SET_TEXTURE_STATE
,
119 WINED3D_CS_OP_SET_SAMPLER_STATE
,
120 WINED3D_CS_OP_SET_TRANSFORM
,
121 WINED3D_CS_OP_SET_CLIP_PLANE
,
122 WINED3D_CS_OP_SET_COLOR_KEY
,
123 WINED3D_CS_OP_SET_MATERIAL
,
124 WINED3D_CS_OP_SET_LIGHT
,
125 WINED3D_CS_OP_SET_LIGHT_ENABLE
,
126 WINED3D_CS_OP_SET_FEATURE_LEVEL
,
127 WINED3D_CS_OP_PUSH_CONSTANTS
,
128 WINED3D_CS_OP_RESET_STATE
,
129 WINED3D_CS_OP_CALLBACK
,
130 WINED3D_CS_OP_QUERY_ISSUE
,
131 WINED3D_CS_OP_PRELOAD_RESOURCE
,
132 WINED3D_CS_OP_UNLOAD_RESOURCE
,
135 WINED3D_CS_OP_BLT_SUB_RESOURCE
,
136 WINED3D_CS_OP_UPDATE_SUB_RESOURCE
,
137 WINED3D_CS_OP_ADD_DIRTY_TEXTURE_REGION
,
138 WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW
,
139 WINED3D_CS_OP_COPY_UAV_COUNTER
,
140 WINED3D_CS_OP_GENERATE_MIPMAPS
,
141 WINED3D_CS_OP_EXECUTE_COMMAND_LIST
,
145 struct wined3d_cs_packet
151 struct wined3d_cs_nop
153 enum wined3d_cs_op opcode
;
156 struct wined3d_cs_present
158 enum wined3d_cs_op opcode
;
159 HWND dst_window_override
;
160 struct wined3d_swapchain
*swapchain
;
163 unsigned int swap_interval
;
167 struct wined3d_cs_clear
169 enum wined3d_cs_op opcode
;
171 unsigned int rt_count
;
172 struct wined3d_fb_state fb
;
174 struct wined3d_color color
;
177 unsigned int rect_count
;
181 struct wined3d_cs_dispatch
183 enum wined3d_cs_op opcode
;
184 struct wined3d_dispatch_parameters parameters
;
187 struct wined3d_cs_draw
189 enum wined3d_cs_op opcode
;
190 enum wined3d_primitive_type primitive_type
;
191 GLint patch_vertex_count
;
192 struct wined3d_draw_parameters parameters
;
195 struct wined3d_cs_flush
197 enum wined3d_cs_op opcode
;
200 struct wined3d_cs_set_predication
202 enum wined3d_cs_op opcode
;
203 struct wined3d_query
*predicate
;
207 struct wined3d_cs_set_viewports
209 enum wined3d_cs_op opcode
;
210 unsigned int viewport_count
;
211 struct wined3d_viewport viewports
[1];
214 struct wined3d_cs_set_scissor_rects
216 enum wined3d_cs_op opcode
;
217 unsigned int rect_count
;
221 struct wined3d_cs_set_rendertarget_view
223 enum wined3d_cs_op opcode
;
224 unsigned int view_idx
;
225 struct wined3d_rendertarget_view
*view
;
228 struct wined3d_cs_set_depth_stencil_view
230 enum wined3d_cs_op opcode
;
231 struct wined3d_rendertarget_view
*view
;
234 struct wined3d_cs_set_vertex_declaration
236 enum wined3d_cs_op opcode
;
237 struct wined3d_vertex_declaration
*declaration
;
240 struct wined3d_cs_set_stream_source
242 enum wined3d_cs_op opcode
;
244 struct wined3d_buffer
*buffer
;
249 struct wined3d_cs_set_stream_source_freq
251 enum wined3d_cs_op opcode
;
257 struct wined3d_cs_set_stream_output
259 enum wined3d_cs_op opcode
;
261 struct wined3d_buffer
*buffer
;
265 struct wined3d_cs_set_index_buffer
267 enum wined3d_cs_op opcode
;
268 struct wined3d_buffer
*buffer
;
269 enum wined3d_format_id format_id
;
273 struct wined3d_cs_set_constant_buffer
275 enum wined3d_cs_op opcode
;
276 enum wined3d_shader_type type
;
278 struct wined3d_buffer
*buffer
;
281 struct wined3d_cs_set_texture
283 enum wined3d_cs_op opcode
;
285 struct wined3d_texture
*texture
;
288 struct wined3d_cs_set_color_key
290 enum wined3d_cs_op opcode
;
291 struct wined3d_texture
*texture
;
294 struct wined3d_color_key color_key
;
297 struct wined3d_cs_set_shader_resource_view
299 enum wined3d_cs_op opcode
;
300 enum wined3d_shader_type type
;
302 struct wined3d_shader_resource_view
*view
;
305 struct wined3d_cs_set_unordered_access_view
307 enum wined3d_cs_op opcode
;
308 enum wined3d_pipeline pipeline
;
309 unsigned int view_idx
;
310 struct wined3d_unordered_access_view
*view
;
311 unsigned int initial_count
;
314 struct wined3d_cs_set_sampler
316 enum wined3d_cs_op opcode
;
317 enum wined3d_shader_type type
;
319 struct wined3d_sampler
*sampler
;
322 struct wined3d_cs_set_shader
324 enum wined3d_cs_op opcode
;
325 enum wined3d_shader_type type
;
326 struct wined3d_shader
*shader
;
329 struct wined3d_cs_set_blend_state
331 enum wined3d_cs_op opcode
;
332 struct wined3d_blend_state
*state
;
333 struct wined3d_color factor
;
334 unsigned int sample_mask
;
337 struct wined3d_cs_set_depth_stencil_state
339 enum wined3d_cs_op opcode
;
340 struct wined3d_depth_stencil_state
*state
;
341 unsigned int stencil_ref
;
344 struct wined3d_cs_set_rasterizer_state
346 enum wined3d_cs_op opcode
;
347 struct wined3d_rasterizer_state
*state
;
350 struct wined3d_cs_set_render_state
352 enum wined3d_cs_op opcode
;
353 enum wined3d_render_state state
;
357 struct wined3d_cs_set_texture_state
359 enum wined3d_cs_op opcode
;
361 enum wined3d_texture_stage_state state
;
365 struct wined3d_cs_set_sampler_state
367 enum wined3d_cs_op opcode
;
369 enum wined3d_sampler_state state
;
373 struct wined3d_cs_set_transform
375 enum wined3d_cs_op opcode
;
376 enum wined3d_transform_state state
;
377 struct wined3d_matrix matrix
;
380 struct wined3d_cs_set_clip_plane
382 enum wined3d_cs_op opcode
;
384 struct wined3d_vec4 plane
;
387 struct wined3d_cs_set_material
389 enum wined3d_cs_op opcode
;
390 struct wined3d_material material
;
393 struct wined3d_cs_set_light
395 enum wined3d_cs_op opcode
;
396 struct wined3d_light_info light
;
399 struct wined3d_cs_set_light_enable
401 enum wined3d_cs_op opcode
;
406 struct wined3d_cs_set_feature_level
408 enum wined3d_cs_op opcode
;
409 enum wined3d_feature_level level
;
412 struct wined3d_cs_push_constants
414 enum wined3d_cs_op opcode
;
415 enum wined3d_push_constants type
;
416 unsigned int start_idx
;
421 struct wined3d_cs_reset_state
423 enum wined3d_cs_op opcode
;
427 struct wined3d_cs_callback
429 enum wined3d_cs_op opcode
;
430 void (*callback
)(void *object
);
434 struct wined3d_cs_query_issue
436 enum wined3d_cs_op opcode
;
437 struct wined3d_query
*query
;
441 struct wined3d_cs_preload_resource
443 enum wined3d_cs_op opcode
;
444 struct wined3d_resource
*resource
;
447 struct wined3d_cs_unload_resource
449 enum wined3d_cs_op opcode
;
450 struct wined3d_resource
*resource
;
453 struct wined3d_cs_map
455 enum wined3d_cs_op opcode
;
456 struct wined3d_resource
*resource
;
457 unsigned int sub_resource_idx
;
459 const struct wined3d_box
*box
;
464 struct wined3d_cs_unmap
466 enum wined3d_cs_op opcode
;
467 struct wined3d_resource
*resource
;
468 unsigned int sub_resource_idx
;
472 struct wined3d_cs_blt_sub_resource
474 enum wined3d_cs_op opcode
;
475 struct wined3d_resource
*dst_resource
;
476 unsigned int dst_sub_resource_idx
;
477 struct wined3d_box dst_box
;
478 struct wined3d_resource
*src_resource
;
479 unsigned int src_sub_resource_idx
;
480 struct wined3d_box src_box
;
482 struct wined3d_blt_fx fx
;
483 enum wined3d_texture_filter_type filter
;
486 struct wined3d_cs_update_sub_resource
488 enum wined3d_cs_op opcode
;
489 struct wined3d_resource
*resource
;
490 unsigned int sub_resource_idx
;
491 struct wined3d_box box
;
492 struct wined3d_sub_resource_data data
;
495 struct wined3d_cs_add_dirty_texture_region
497 enum wined3d_cs_op opcode
;
498 struct wined3d_texture
*texture
;
502 struct wined3d_cs_clear_unordered_access_view
504 enum wined3d_cs_op opcode
;
505 struct wined3d_unordered_access_view
*view
;
506 struct wined3d_uvec4 clear_value
;
510 struct wined3d_cs_copy_uav_counter
512 enum wined3d_cs_op opcode
;
513 struct wined3d_buffer
*buffer
;
515 struct wined3d_unordered_access_view
*view
;
518 struct wined3d_cs_generate_mipmaps
520 enum wined3d_cs_op opcode
;
521 struct wined3d_shader_resource_view
*view
;
524 struct wined3d_cs_execute_command_list
526 enum wined3d_cs_op opcode
;
527 struct wined3d_command_list
*list
;
530 struct wined3d_cs_stop
532 enum wined3d_cs_op opcode
;
535 static inline void *wined3d_device_context_require_space(struct wined3d_device_context
*context
,
536 size_t size
, enum wined3d_cs_queue_id queue_id
)
538 return context
->ops
->require_space(context
, size
, queue_id
);
541 static inline void wined3d_device_context_submit(struct wined3d_device_context
*context
,
542 enum wined3d_cs_queue_id queue_id
)
544 context
->ops
->submit(context
, queue_id
);
547 static inline void wined3d_device_context_finish(struct wined3d_device_context
*context
,
548 enum wined3d_cs_queue_id queue_id
)
550 context
->ops
->finish(context
, queue_id
);
553 static inline void wined3d_device_context_acquire_resource(struct wined3d_device_context
*context
,
554 struct wined3d_resource
*resource
)
556 context
->ops
->acquire_resource(context
, resource
);
559 static struct wined3d_cs
*wined3d_cs_from_context(struct wined3d_device_context
*context
)
561 return CONTAINING_RECORD(context
, struct wined3d_cs
, c
);
564 static const char *debug_cs_op(enum wined3d_cs_op op
)
568 #define WINED3D_TO_STR(type) case type: return #type
569 WINED3D_TO_STR(WINED3D_CS_OP_NOP
);
570 WINED3D_TO_STR(WINED3D_CS_OP_PRESENT
);
571 WINED3D_TO_STR(WINED3D_CS_OP_CLEAR
);
572 WINED3D_TO_STR(WINED3D_CS_OP_DISPATCH
);
573 WINED3D_TO_STR(WINED3D_CS_OP_DRAW
);
574 WINED3D_TO_STR(WINED3D_CS_OP_FLUSH
);
575 WINED3D_TO_STR(WINED3D_CS_OP_SET_PREDICATION
);
576 WINED3D_TO_STR(WINED3D_CS_OP_SET_VIEWPORTS
);
577 WINED3D_TO_STR(WINED3D_CS_OP_SET_SCISSOR_RECTS
);
578 WINED3D_TO_STR(WINED3D_CS_OP_SET_RENDERTARGET_VIEW
);
579 WINED3D_TO_STR(WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW
);
580 WINED3D_TO_STR(WINED3D_CS_OP_SET_VERTEX_DECLARATION
);
581 WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_SOURCE
);
582 WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ
);
583 WINED3D_TO_STR(WINED3D_CS_OP_SET_STREAM_OUTPUT
);
584 WINED3D_TO_STR(WINED3D_CS_OP_SET_INDEX_BUFFER
);
585 WINED3D_TO_STR(WINED3D_CS_OP_SET_CONSTANT_BUFFER
);
586 WINED3D_TO_STR(WINED3D_CS_OP_SET_TEXTURE
);
587 WINED3D_TO_STR(WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW
);
588 WINED3D_TO_STR(WINED3D_CS_OP_SET_UNORDERED_ACCESS_VIEW
);
589 WINED3D_TO_STR(WINED3D_CS_OP_SET_SAMPLER
);
590 WINED3D_TO_STR(WINED3D_CS_OP_SET_SHADER
);
591 WINED3D_TO_STR(WINED3D_CS_OP_SET_BLEND_STATE
);
592 WINED3D_TO_STR(WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE
);
593 WINED3D_TO_STR(WINED3D_CS_OP_SET_RASTERIZER_STATE
);
594 WINED3D_TO_STR(WINED3D_CS_OP_SET_RENDER_STATE
);
595 WINED3D_TO_STR(WINED3D_CS_OP_SET_TEXTURE_STATE
);
596 WINED3D_TO_STR(WINED3D_CS_OP_SET_SAMPLER_STATE
);
597 WINED3D_TO_STR(WINED3D_CS_OP_SET_TRANSFORM
);
598 WINED3D_TO_STR(WINED3D_CS_OP_SET_CLIP_PLANE
);
599 WINED3D_TO_STR(WINED3D_CS_OP_SET_COLOR_KEY
);
600 WINED3D_TO_STR(WINED3D_CS_OP_SET_MATERIAL
);
601 WINED3D_TO_STR(WINED3D_CS_OP_SET_LIGHT
);
602 WINED3D_TO_STR(WINED3D_CS_OP_SET_LIGHT_ENABLE
);
603 WINED3D_TO_STR(WINED3D_CS_OP_SET_FEATURE_LEVEL
);
604 WINED3D_TO_STR(WINED3D_CS_OP_PUSH_CONSTANTS
);
605 WINED3D_TO_STR(WINED3D_CS_OP_RESET_STATE
);
606 WINED3D_TO_STR(WINED3D_CS_OP_CALLBACK
);
607 WINED3D_TO_STR(WINED3D_CS_OP_QUERY_ISSUE
);
608 WINED3D_TO_STR(WINED3D_CS_OP_PRELOAD_RESOURCE
);
609 WINED3D_TO_STR(WINED3D_CS_OP_UNLOAD_RESOURCE
);
610 WINED3D_TO_STR(WINED3D_CS_OP_MAP
);
611 WINED3D_TO_STR(WINED3D_CS_OP_UNMAP
);
612 WINED3D_TO_STR(WINED3D_CS_OP_BLT_SUB_RESOURCE
);
613 WINED3D_TO_STR(WINED3D_CS_OP_UPDATE_SUB_RESOURCE
);
614 WINED3D_TO_STR(WINED3D_CS_OP_ADD_DIRTY_TEXTURE_REGION
);
615 WINED3D_TO_STR(WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW
);
616 WINED3D_TO_STR(WINED3D_CS_OP_COPY_UAV_COUNTER
);
617 WINED3D_TO_STR(WINED3D_CS_OP_GENERATE_MIPMAPS
);
618 WINED3D_TO_STR(WINED3D_CS_OP_EXECUTE_COMMAND_LIST
);
619 WINED3D_TO_STR(WINED3D_CS_OP_STOP
);
620 #undef WINED3D_TO_STR
622 return wine_dbg_sprintf("UNKNOWN_OP(%#x)", op
);
625 static void wined3d_cs_exec_nop(struct wined3d_cs
*cs
, const void *data
)
629 static void wined3d_cs_exec_present(struct wined3d_cs
*cs
, const void *data
)
631 struct wined3d_texture
*logo_texture
, *cursor_texture
, *back_buffer
;
632 struct wined3d_rendertarget_view
*dsv
= cs
->state
.fb
.depth_stencil
;
633 const struct wined3d_cs_present
*op
= data
;
634 const struct wined3d_swapchain_desc
*desc
;
635 struct wined3d_swapchain
*swapchain
;
638 swapchain
= op
->swapchain
;
639 desc
= &swapchain
->state
.desc
;
640 back_buffer
= swapchain
->back_buffers
[0];
641 wined3d_swapchain_set_window(swapchain
, op
->dst_window_override
);
643 if ((logo_texture
= swapchain
->device
->logo_texture
))
645 RECT rect
= {0, 0, logo_texture
->resource
.width
, logo_texture
->resource
.height
};
647 /* Blit the logo into the upper left corner of the back-buffer. */
648 wined3d_device_context_blt(&cs
->c
, back_buffer
, 0, &rect
, logo_texture
, 0,
649 &rect
, WINED3D_BLT_SRC_CKEY
, NULL
, WINED3D_TEXF_POINT
);
652 if ((cursor_texture
= swapchain
->device
->cursor_texture
)
653 && swapchain
->device
->bCursorVisible
&& !swapchain
->device
->hardwareCursor
)
657 swapchain
->device
->xScreenSpace
- swapchain
->device
->xHotSpot
,
658 swapchain
->device
->yScreenSpace
- swapchain
->device
->yHotSpot
,
659 swapchain
->device
->xScreenSpace
+ swapchain
->device
->cursorWidth
- swapchain
->device
->xHotSpot
,
660 swapchain
->device
->yScreenSpace
+ swapchain
->device
->cursorHeight
- swapchain
->device
->yHotSpot
,
664 0, 0, cursor_texture
->resource
.width
, cursor_texture
->resource
.height
666 const RECT clip_rect
= {0, 0, back_buffer
->resource
.width
, back_buffer
->resource
.height
};
668 TRACE("Rendering the software cursor.\n");
671 MapWindowPoints(NULL
, swapchain
->win_handle
, (POINT
*)&dst_rect
, 2);
672 if (wined3d_clip_blit(&clip_rect
, &dst_rect
, &src_rect
))
673 wined3d_device_context_blt(&cs
->c
, back_buffer
, 0, &dst_rect
, cursor_texture
, 0,
674 &src_rect
, WINED3D_BLT_ALPHA_TEST
, NULL
, WINED3D_TEXF_POINT
);
677 swapchain
->swapchain_ops
->swapchain_present(swapchain
, &op
->src_rect
, &op
->dst_rect
, op
->swap_interval
, op
->flags
);
679 /* Discard buffers if the swap effect allows it. */
680 back_buffer
= swapchain
->back_buffers
[desc
->backbuffer_count
- 1];
681 if (desc
->swap_effect
== WINED3D_SWAP_EFFECT_DISCARD
|| desc
->swap_effect
== WINED3D_SWAP_EFFECT_FLIP_DISCARD
)
682 wined3d_texture_validate_location(back_buffer
, 0, WINED3D_LOCATION_DISCARDED
);
684 if (dsv
&& dsv
->resource
->type
!= WINED3D_RTYPE_BUFFER
)
686 struct wined3d_texture
*ds
= texture_from_resource(dsv
->resource
);
688 if ((desc
->flags
& WINED3D_SWAPCHAIN_DISCARD_DEPTHSTENCIL
|| ds
->flags
& WINED3D_TEXTURE_DISCARD
))
689 wined3d_rendertarget_view_validate_location(dsv
, WINED3D_LOCATION_DISCARDED
);
694 DWORD time
= GetTickCount();
697 /* every 1.5 seconds */
698 if (time
- swapchain
->prev_time
> 1500)
700 TRACE_(fps
)("%p @ approx %.2ffps\n",
701 swapchain
, 1000.0 * swapchain
->frames
/ (time
- swapchain
->prev_time
));
702 swapchain
->prev_time
= time
;
703 swapchain
->frames
= 0;
707 wined3d_resource_release(&swapchain
->front_buffer
->resource
);
708 for (i
= 0; i
< desc
->backbuffer_count
; ++i
)
710 wined3d_resource_release(&swapchain
->back_buffers
[i
]->resource
);
713 InterlockedDecrement(&cs
->pending_presents
);
716 void wined3d_cs_emit_present(struct wined3d_cs
*cs
, struct wined3d_swapchain
*swapchain
,
717 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
718 unsigned int swap_interval
, DWORD flags
)
720 struct wined3d_cs_present
*op
;
724 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
725 op
->opcode
= WINED3D_CS_OP_PRESENT
;
726 op
->dst_window_override
= dst_window_override
;
727 op
->swapchain
= swapchain
;
728 op
->src_rect
= *src_rect
;
729 op
->dst_rect
= *dst_rect
;
730 op
->swap_interval
= swap_interval
;
733 pending
= InterlockedIncrement(&cs
->pending_presents
);
735 wined3d_resource_acquire(&swapchain
->front_buffer
->resource
);
736 for (i
= 0; i
< swapchain
->state
.desc
.backbuffer_count
; ++i
)
738 wined3d_resource_acquire(&swapchain
->back_buffers
[i
]->resource
);
741 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
743 /* Limit input latency by limiting the number of presents that we can get
744 * ahead of the worker thread. */
745 while (pending
>= swapchain
->max_frame_latency
)
748 pending
= InterlockedCompareExchange(&cs
->pending_presents
, 0, 0);
752 static void wined3d_cs_exec_clear(struct wined3d_cs
*cs
, const void *data
)
754 struct wined3d_device
*device
= cs
->c
.device
;
755 const struct wined3d_cs_clear
*op
= data
;
758 device
->blitter
->ops
->blitter_clear(device
->blitter
, device
, op
->rt_count
, &op
->fb
,
759 op
->rect_count
, op
->rects
, &op
->draw_rect
, op
->flags
, &op
->color
, op
->depth
, op
->stencil
);
761 if (op
->flags
& WINED3DCLEAR_TARGET
)
763 for (i
= 0; i
< op
->rt_count
; ++i
)
765 if (op
->fb
.render_targets
[i
])
766 wined3d_resource_release(op
->fb
.render_targets
[i
]->resource
);
769 if (op
->flags
& (WINED3DCLEAR_ZBUFFER
| WINED3DCLEAR_STENCIL
))
770 wined3d_resource_release(op
->fb
.depth_stencil
->resource
);
773 void wined3d_cs_emit_clear(struct wined3d_cs
*cs
, DWORD rect_count
, const RECT
*rects
,
774 DWORD flags
, const struct wined3d_color
*color
, float depth
, DWORD stencil
)
776 const struct wined3d_state
*state
= cs
->c
.state
;
777 const struct wined3d_viewport
*vp
= &state
->viewports
[0];
778 struct wined3d_rendertarget_view
*view
;
779 struct wined3d_cs_clear
*op
;
780 unsigned int rt_count
, i
;
782 rt_count
= flags
& WINED3DCLEAR_TARGET
? cs
->c
.device
->adapter
->d3d_info
.limits
.max_rt_count
: 0;
784 op
= wined3d_device_context_require_space(&cs
->c
, FIELD_OFFSET(struct wined3d_cs_clear
, rects
[rect_count
]),
785 WINED3D_CS_QUEUE_DEFAULT
);
786 op
->opcode
= WINED3D_CS_OP_CLEAR
;
787 op
->flags
= flags
& (WINED3DCLEAR_TARGET
| WINED3DCLEAR_ZBUFFER
| WINED3DCLEAR_STENCIL
);
788 op
->rt_count
= rt_count
;
790 SetRect(&op
->draw_rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
791 if (state
->rasterizer_state
&& state
->rasterizer_state
->desc
.scissor
)
792 IntersectRect(&op
->draw_rect
, &op
->draw_rect
, &state
->scissor_rects
[0]);
795 op
->stencil
= stencil
;
796 op
->rect_count
= rect_count
;
797 memcpy(op
->rects
, rects
, sizeof(*rects
) * rect_count
);
799 for (i
= 0; i
< rt_count
; ++i
)
801 if ((view
= state
->fb
.render_targets
[i
]))
802 wined3d_resource_acquire(view
->resource
);
804 if (flags
& (WINED3DCLEAR_ZBUFFER
| WINED3DCLEAR_STENCIL
))
806 view
= state
->fb
.depth_stencil
;
807 wined3d_resource_acquire(view
->resource
);
810 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
813 void wined3d_device_context_emit_clear_rendertarget_view(struct wined3d_device_context
*context
,
814 struct wined3d_rendertarget_view
*view
, const RECT
*rect
, unsigned int flags
,
815 const struct wined3d_color
*color
, float depth
, unsigned int stencil
)
817 struct wined3d_cs_clear
*op
;
820 size
= FIELD_OFFSET(struct wined3d_cs_clear
, rects
[1]);
821 op
= wined3d_device_context_require_space(context
, size
, WINED3D_CS_QUEUE_DEFAULT
);
823 op
->opcode
= WINED3D_CS_OP_CLEAR
;
824 op
->flags
= flags
& (WINED3DCLEAR_TARGET
| WINED3DCLEAR_ZBUFFER
| WINED3DCLEAR_STENCIL
);
825 if (flags
& WINED3DCLEAR_TARGET
)
828 op
->fb
.render_targets
[0] = view
;
829 op
->fb
.depth_stencil
= NULL
;
835 op
->fb
.render_targets
[0] = NULL
;
836 op
->fb
.depth_stencil
= view
;
838 op
->stencil
= stencil
;
840 SetRect(&op
->draw_rect
, 0, 0, view
->width
, view
->height
);
842 op
->rects
[0] = *rect
;
844 wined3d_device_context_acquire_resource(context
, view
->resource
);
846 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
847 if (flags
& WINED3DCLEAR_SYNCHRONOUS
)
848 wined3d_device_context_finish(context
, WINED3D_CS_QUEUE_DEFAULT
);
851 static void acquire_shader_resources(struct wined3d_device_context
*context
, unsigned int shader_mask
)
853 const struct wined3d_state
*state
= context
->state
;
854 struct wined3d_shader_sampler_map_entry
*entry
;
855 struct wined3d_shader_resource_view
*view
;
856 struct wined3d_shader
*shader
;
859 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
861 if (!(shader_mask
& (1u << i
)))
864 if (!(shader
= state
->shader
[i
]))
867 for (j
= 0; j
< WINED3D_MAX_CBS
; ++j
)
870 wined3d_device_context_acquire_resource(context
, &state
->cb
[i
][j
]->resource
);
873 for (j
= 0; j
< shader
->reg_maps
.sampler_map
.count
; ++j
)
875 entry
= &shader
->reg_maps
.sampler_map
.entries
[j
];
877 if (!(view
= state
->shader_resource_view
[i
][entry
->resource_idx
]))
880 wined3d_device_context_acquire_resource(context
, view
->resource
);
885 static void release_shader_resources(const struct wined3d_state
*state
, unsigned int shader_mask
)
887 struct wined3d_shader_sampler_map_entry
*entry
;
888 struct wined3d_shader_resource_view
*view
;
889 struct wined3d_shader
*shader
;
892 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
894 if (!(shader_mask
& (1u << i
)))
897 if (!(shader
= state
->shader
[i
]))
900 for (j
= 0; j
< WINED3D_MAX_CBS
; ++j
)
903 wined3d_resource_release(&state
->cb
[i
][j
]->resource
);
906 for (j
= 0; j
< shader
->reg_maps
.sampler_map
.count
; ++j
)
908 entry
= &shader
->reg_maps
.sampler_map
.entries
[j
];
910 if (!(view
= state
->shader_resource_view
[i
][entry
->resource_idx
]))
913 wined3d_resource_release(view
->resource
);
918 static void acquire_unordered_access_resources(struct wined3d_device_context
*context
,
919 const struct wined3d_shader
*shader
, struct wined3d_unordered_access_view
* const *views
)
926 for (i
= 0; i
< MAX_UNORDERED_ACCESS_VIEWS
; ++i
)
928 if (!shader
->reg_maps
.uav_resource_info
[i
].type
)
934 wined3d_device_context_acquire_resource(context
, views
[i
]->resource
);
938 static void release_unordered_access_resources(const struct wined3d_shader
*shader
,
939 struct wined3d_unordered_access_view
* const *views
)
946 for (i
= 0; i
< MAX_UNORDERED_ACCESS_VIEWS
; ++i
)
948 if (!shader
->reg_maps
.uav_resource_info
[i
].type
)
954 wined3d_resource_release(views
[i
]->resource
);
958 static void wined3d_cs_exec_dispatch(struct wined3d_cs
*cs
, const void *data
)
960 const struct wined3d_cs_dispatch
*op
= data
;
961 struct wined3d_state
*state
= &cs
->state
;
963 if (!state
->shader
[WINED3D_SHADER_TYPE_COMPUTE
])
964 WARN("No compute shader bound, skipping dispatch.\n");
966 cs
->c
.device
->adapter
->adapter_ops
->adapter_dispatch_compute(cs
->c
.device
, state
, &op
->parameters
);
968 if (op
->parameters
.indirect
)
969 wined3d_resource_release(&op
->parameters
.u
.indirect
.buffer
->resource
);
971 release_shader_resources(state
, 1u << WINED3D_SHADER_TYPE_COMPUTE
);
972 release_unordered_access_resources(state
->shader
[WINED3D_SHADER_TYPE_COMPUTE
],
973 state
->unordered_access_view
[WINED3D_PIPELINE_COMPUTE
]);
976 static void acquire_compute_pipeline_resources(struct wined3d_device_context
*context
)
978 const struct wined3d_state
*state
= context
->state
;
980 acquire_shader_resources(context
, 1u << WINED3D_SHADER_TYPE_COMPUTE
);
981 acquire_unordered_access_resources(context
, state
->shader
[WINED3D_SHADER_TYPE_COMPUTE
],
982 state
->unordered_access_view
[WINED3D_PIPELINE_COMPUTE
]);
985 void CDECL
wined3d_device_context_dispatch(struct wined3d_device_context
*context
,
986 unsigned int group_count_x
, unsigned int group_count_y
, unsigned int group_count_z
)
988 struct wined3d_cs_dispatch
*op
;
990 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
991 op
->opcode
= WINED3D_CS_OP_DISPATCH
;
992 op
->parameters
.indirect
= FALSE
;
993 op
->parameters
.u
.direct
.group_count_x
= group_count_x
;
994 op
->parameters
.u
.direct
.group_count_y
= group_count_y
;
995 op
->parameters
.u
.direct
.group_count_z
= group_count_z
;
997 acquire_compute_pipeline_resources(context
);
999 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1002 void CDECL
wined3d_device_context_dispatch_indirect(struct wined3d_device_context
*context
,
1003 struct wined3d_buffer
*buffer
, unsigned int offset
)
1005 struct wined3d_cs_dispatch
*op
;
1007 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1008 op
->opcode
= WINED3D_CS_OP_DISPATCH
;
1009 op
->parameters
.indirect
= TRUE
;
1010 op
->parameters
.u
.indirect
.buffer
= buffer
;
1011 op
->parameters
.u
.indirect
.offset
= offset
;
1013 acquire_compute_pipeline_resources(context
);
1014 wined3d_device_context_acquire_resource(context
, &buffer
->resource
);
1016 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1019 static void wined3d_cs_exec_draw(struct wined3d_cs
*cs
, const void *data
)
1021 const struct wined3d_d3d_info
*d3d_info
= &cs
->c
.device
->adapter
->d3d_info
;
1022 const struct wined3d_shader
*geometry_shader
;
1023 struct wined3d_device
*device
= cs
->c
.device
;
1024 int base_vertex_idx
, load_base_vertex_idx
;
1025 struct wined3d_state
*state
= &cs
->state
;
1026 const struct wined3d_cs_draw
*op
= data
;
1029 base_vertex_idx
= 0;
1030 if (!op
->parameters
.indirect
)
1032 const struct wined3d_direct_draw_parameters
*direct
= &op
->parameters
.u
.direct
;
1034 if (op
->parameters
.indexed
&& d3d_info
->draw_base_vertex_offset
)
1035 base_vertex_idx
= direct
->base_vertex_idx
;
1036 else if (!op
->parameters
.indexed
)
1037 base_vertex_idx
= direct
->start_idx
;
1040 /* ARB_draw_indirect always supports a base vertex offset. */
1041 if (!op
->parameters
.indirect
&& !d3d_info
->draw_base_vertex_offset
)
1042 load_base_vertex_idx
= op
->parameters
.u
.direct
.base_vertex_idx
;
1044 load_base_vertex_idx
= 0;
1046 if (state
->base_vertex_index
!= base_vertex_idx
)
1048 state
->base_vertex_index
= base_vertex_idx
;
1049 for (i
= 0; i
< device
->context_count
; ++i
)
1050 device
->contexts
[i
]->constant_update_mask
|= WINED3D_SHADER_CONST_BASE_VERTEX_ID
;
1053 if (state
->load_base_vertex_index
!= load_base_vertex_idx
)
1055 state
->load_base_vertex_index
= load_base_vertex_idx
;
1056 device_invalidate_state(cs
->c
.device
, STATE_BASEVERTEXINDEX
);
1059 if (state
->primitive_type
!= op
->primitive_type
)
1061 if ((geometry_shader
= state
->shader
[WINED3D_SHADER_TYPE_GEOMETRY
]) && !geometry_shader
->function
)
1062 device_invalidate_state(cs
->c
.device
, STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY
));
1063 if (state
->primitive_type
== WINED3D_PT_POINTLIST
|| op
->primitive_type
== WINED3D_PT_POINTLIST
)
1064 device_invalidate_state(cs
->c
.device
, STATE_POINT_ENABLE
);
1065 state
->primitive_type
= op
->primitive_type
;
1067 state
->patch_vertex_count
= op
->patch_vertex_count
;
1069 cs
->c
.device
->adapter
->adapter_ops
->adapter_draw_primitive(cs
->c
.device
, state
, &op
->parameters
);
1071 if (op
->parameters
.indirect
)
1073 struct wined3d_buffer
*buffer
= op
->parameters
.u
.indirect
.buffer
;
1074 wined3d_resource_release(&buffer
->resource
);
1077 if (op
->parameters
.indexed
)
1078 wined3d_resource_release(&state
->index_buffer
->resource
);
1079 for (i
= 0; i
< ARRAY_SIZE(state
->streams
); ++i
)
1081 if (state
->streams
[i
].buffer
)
1082 wined3d_resource_release(&state
->streams
[i
].buffer
->resource
);
1084 for (i
= 0; i
< ARRAY_SIZE(state
->stream_output
); ++i
)
1086 if (state
->stream_output
[i
].buffer
)
1087 wined3d_resource_release(&state
->stream_output
[i
].buffer
->resource
);
1089 for (i
= 0; i
< ARRAY_SIZE(state
->textures
); ++i
)
1091 if (state
->textures
[i
])
1092 wined3d_resource_release(&state
->textures
[i
]->resource
);
1094 for (i
= 0; i
< d3d_info
->limits
.max_rt_count
; ++i
)
1096 if (state
->fb
.render_targets
[i
])
1097 wined3d_resource_release(state
->fb
.render_targets
[i
]->resource
);
1099 if (state
->fb
.depth_stencil
)
1100 wined3d_resource_release(state
->fb
.depth_stencil
->resource
);
1101 release_shader_resources(state
, ~(1u << WINED3D_SHADER_TYPE_COMPUTE
));
1102 release_unordered_access_resources(state
->shader
[WINED3D_SHADER_TYPE_PIXEL
],
1103 state
->unordered_access_view
[WINED3D_PIPELINE_GRAPHICS
]);
1106 static void acquire_graphics_pipeline_resources(struct wined3d_device_context
*context
,
1107 BOOL indexed
, const struct wined3d_d3d_info
*d3d_info
)
1109 const struct wined3d_state
*state
= context
->state
;
1113 wined3d_device_context_acquire_resource(context
, &state
->index_buffer
->resource
);
1114 for (i
= 0; i
< ARRAY_SIZE(state
->streams
); ++i
)
1116 if (state
->streams
[i
].buffer
)
1117 wined3d_device_context_acquire_resource(context
, &state
->streams
[i
].buffer
->resource
);
1119 for (i
= 0; i
< ARRAY_SIZE(state
->stream_output
); ++i
)
1121 if (state
->stream_output
[i
].buffer
)
1122 wined3d_device_context_acquire_resource(context
, &state
->stream_output
[i
].buffer
->resource
);
1124 for (i
= 0; i
< ARRAY_SIZE(state
->textures
); ++i
)
1126 if (state
->textures
[i
])
1127 wined3d_device_context_acquire_resource(context
, &state
->textures
[i
]->resource
);
1129 for (i
= 0; i
< d3d_info
->limits
.max_rt_count
; ++i
)
1131 if (state
->fb
.render_targets
[i
])
1132 wined3d_device_context_acquire_resource(context
, state
->fb
.render_targets
[i
]->resource
);
1134 if (state
->fb
.depth_stencil
)
1135 wined3d_device_context_acquire_resource(context
, state
->fb
.depth_stencil
->resource
);
1136 acquire_shader_resources(context
, ~(1u << WINED3D_SHADER_TYPE_COMPUTE
));
1137 acquire_unordered_access_resources(context
, state
->shader
[WINED3D_SHADER_TYPE_PIXEL
],
1138 state
->unordered_access_view
[WINED3D_PIPELINE_GRAPHICS
]);
1141 void wined3d_device_context_emit_draw(struct wined3d_device_context
*context
,
1142 enum wined3d_primitive_type primitive_type
, unsigned int patch_vertex_count
, int base_vertex_idx
,
1143 unsigned int start_idx
, unsigned int index_count
, unsigned int start_instance
, unsigned int instance_count
,
1146 const struct wined3d_d3d_info
*d3d_info
= &context
->device
->adapter
->d3d_info
;
1147 struct wined3d_cs_draw
*op
;
1149 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1150 op
->opcode
= WINED3D_CS_OP_DRAW
;
1151 op
->primitive_type
= primitive_type
;
1152 op
->patch_vertex_count
= patch_vertex_count
;
1153 op
->parameters
.indirect
= FALSE
;
1154 op
->parameters
.u
.direct
.base_vertex_idx
= base_vertex_idx
;
1155 op
->parameters
.u
.direct
.start_idx
= start_idx
;
1156 op
->parameters
.u
.direct
.index_count
= index_count
;
1157 op
->parameters
.u
.direct
.start_instance
= start_instance
;
1158 op
->parameters
.u
.direct
.instance_count
= instance_count
;
1159 op
->parameters
.indexed
= indexed
;
1161 acquire_graphics_pipeline_resources(context
, indexed
, d3d_info
);
1163 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1166 void CDECL
wined3d_device_context_draw_indirect(struct wined3d_device_context
*context
,
1167 struct wined3d_buffer
*buffer
, unsigned int offset
, bool indexed
)
1169 const struct wined3d_d3d_info
*d3d_info
= &context
->device
->adapter
->d3d_info
;
1170 const struct wined3d_state
*state
= context
->state
;
1171 struct wined3d_cs_draw
*op
;
1173 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1174 op
->opcode
= WINED3D_CS_OP_DRAW
;
1175 op
->primitive_type
= state
->primitive_type
;
1176 op
->patch_vertex_count
= state
->patch_vertex_count
;
1177 op
->parameters
.indirect
= TRUE
;
1178 op
->parameters
.u
.indirect
.buffer
= buffer
;
1179 op
->parameters
.u
.indirect
.offset
= offset
;
1180 op
->parameters
.indexed
= indexed
;
1182 acquire_graphics_pipeline_resources(context
, indexed
, d3d_info
);
1183 wined3d_device_context_acquire_resource(context
, &buffer
->resource
);
1185 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1188 static void wined3d_cs_exec_flush(struct wined3d_cs
*cs
, const void *data
)
1190 struct wined3d_context
*context
;
1192 context
= context_acquire(cs
->c
.device
, NULL
, 0);
1193 cs
->c
.device
->adapter
->adapter_ops
->adapter_flush_context(context
);
1194 context_release(context
);
1197 static void wined3d_cs_flush(struct wined3d_device_context
*context
)
1199 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
1200 struct wined3d_cs_flush
*op
;
1202 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1203 op
->opcode
= WINED3D_CS_OP_FLUSH
;
1205 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1206 cs
->queries_flushed
= TRUE
;
1209 static void wined3d_cs_exec_set_predication(struct wined3d_cs
*cs
, const void *data
)
1211 const struct wined3d_cs_set_predication
*op
= data
;
1213 cs
->state
.predicate
= op
->predicate
;
1214 cs
->state
.predicate_value
= op
->value
;
1217 void wined3d_device_context_emit_set_predication(struct wined3d_device_context
*context
,
1218 struct wined3d_query
*predicate
, BOOL value
)
1220 struct wined3d_cs_set_predication
*op
;
1222 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1223 op
->opcode
= WINED3D_CS_OP_SET_PREDICATION
;
1224 op
->predicate
= predicate
;
1227 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1230 static void wined3d_cs_exec_set_viewports(struct wined3d_cs
*cs
, const void *data
)
1232 const struct wined3d_cs_set_viewports
*op
= data
;
1234 if (op
->viewport_count
)
1235 memcpy(cs
->state
.viewports
, op
->viewports
, op
->viewport_count
* sizeof(*op
->viewports
));
1237 memset(cs
->state
.viewports
, 0, sizeof(*cs
->state
.viewports
));
1238 cs
->state
.viewport_count
= op
->viewport_count
;
1239 device_invalidate_state(cs
->c
.device
, STATE_VIEWPORT
);
1242 void wined3d_device_context_emit_set_viewports(struct wined3d_device_context
*context
, unsigned int viewport_count
,
1243 const struct wined3d_viewport
*viewports
)
1245 struct wined3d_cs_set_viewports
*op
;
1247 op
= wined3d_device_context_require_space(context
,
1248 FIELD_OFFSET(struct wined3d_cs_set_viewports
,viewports
[viewport_count
]), WINED3D_CS_QUEUE_DEFAULT
);
1249 op
->opcode
= WINED3D_CS_OP_SET_VIEWPORTS
;
1250 memcpy(op
->viewports
, viewports
, viewport_count
* sizeof(*viewports
));
1251 op
->viewport_count
= viewport_count
;
1253 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1256 static void wined3d_cs_exec_set_scissor_rects(struct wined3d_cs
*cs
, const void *data
)
1258 const struct wined3d_cs_set_scissor_rects
*op
= data
;
1261 memcpy(cs
->state
.scissor_rects
, op
->rects
, op
->rect_count
* sizeof(*op
->rects
));
1263 SetRectEmpty(cs
->state
.scissor_rects
);
1264 cs
->state
.scissor_rect_count
= op
->rect_count
;
1265 device_invalidate_state(cs
->c
.device
, STATE_SCISSORRECT
);
1268 void wined3d_device_context_emit_set_scissor_rects(struct wined3d_device_context
*context
,
1269 unsigned int rect_count
, const RECT
*rects
)
1271 struct wined3d_cs_set_scissor_rects
*op
;
1273 op
= wined3d_device_context_require_space(context
, FIELD_OFFSET(struct wined3d_cs_set_scissor_rects
, rects
[rect_count
]),
1274 WINED3D_CS_QUEUE_DEFAULT
);
1275 op
->opcode
= WINED3D_CS_OP_SET_SCISSOR_RECTS
;
1276 memcpy(op
->rects
, rects
, rect_count
* sizeof(*rects
));
1277 op
->rect_count
= rect_count
;
1279 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1282 static void wined3d_cs_exec_set_rendertarget_view(struct wined3d_cs
*cs
, const void *data
)
1284 const struct wined3d_cs_set_rendertarget_view
*op
= data
;
1285 bool prev_alpha_swizzle
, curr_alpha_swizzle
;
1286 struct wined3d_rendertarget_view
*prev
;
1287 bool prev_srgb_write
, curr_srgb_write
;
1288 struct wined3d_device
*device
;
1290 device
= cs
->c
.device
;
1291 prev
= cs
->state
.fb
.render_targets
[op
->view_idx
];
1292 cs
->state
.fb
.render_targets
[op
->view_idx
] = op
->view
;
1293 device_invalidate_state(device
, STATE_FRAMEBUFFER
);
1295 prev_alpha_swizzle
= prev
&& prev
->format
->id
== WINED3DFMT_A8_UNORM
;
1296 curr_alpha_swizzle
= op
->view
&& op
->view
->format
->id
== WINED3DFMT_A8_UNORM
;
1297 if (prev_alpha_swizzle
!= curr_alpha_swizzle
)
1298 device_invalidate_state(device
, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL
));
1300 if (!(device
->adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
)
1301 || cs
->state
.render_states
[WINED3D_RS_SRGBWRITEENABLE
])
1303 prev_srgb_write
= prev
&& prev
->format_flags
& WINED3DFMT_FLAG_SRGB_WRITE
;
1304 curr_srgb_write
= op
->view
&& op
->view
->format_flags
& WINED3DFMT_FLAG_SRGB_WRITE
;
1305 if (prev_srgb_write
!= curr_srgb_write
)
1306 device_invalidate_state(device
, STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE
));
1310 void wined3d_device_context_emit_set_rendertarget_view(struct wined3d_device_context
*context
, unsigned int view_idx
,
1311 struct wined3d_rendertarget_view
*view
)
1313 struct wined3d_cs_set_rendertarget_view
*op
;
1315 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1316 op
->opcode
= WINED3D_CS_OP_SET_RENDERTARGET_VIEW
;
1317 op
->view_idx
= view_idx
;
1320 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1323 static void wined3d_cs_exec_set_depth_stencil_view(struct wined3d_cs
*cs
, const void *data
)
1325 const struct wined3d_cs_set_depth_stencil_view
*op
= data
;
1326 struct wined3d_device
*device
= cs
->c
.device
;
1327 struct wined3d_rendertarget_view
*prev
;
1329 if ((prev
= cs
->state
.fb
.depth_stencil
) && prev
->resource
->type
!= WINED3D_RTYPE_BUFFER
)
1331 struct wined3d_texture
*prev_texture
= texture_from_resource(prev
->resource
);
1333 if (device
->swapchains
[0]->state
.desc
.flags
& WINED3D_SWAPCHAIN_DISCARD_DEPTHSTENCIL
1334 || prev_texture
->flags
& WINED3D_TEXTURE_DISCARD
)
1335 wined3d_texture_validate_location(prev_texture
,
1336 prev
->sub_resource_idx
, WINED3D_LOCATION_DISCARDED
);
1339 cs
->state
.fb
.depth_stencil
= op
->view
;
1341 if (!prev
!= !op
->view
)
1343 /* Swapping NULL / non NULL depth stencil affects the depth and tests */
1344 device_invalidate_state(device
, STATE_DEPTH_STENCIL
);
1345 device_invalidate_state(device
, STATE_STENCIL_REF
);
1346 device_invalidate_state(device
, STATE_RASTERIZER
);
1350 if (prev
->format
->depth_bias_scale
!= op
->view
->format
->depth_bias_scale
)
1351 device_invalidate_state(device
, STATE_RASTERIZER
);
1352 if (prev
->format
->stencil_size
!= op
->view
->format
->stencil_size
)
1353 device_invalidate_state(device
, STATE_STENCIL_REF
);
1356 device_invalidate_state(device
, STATE_FRAMEBUFFER
);
1359 void wined3d_device_context_emit_set_depth_stencil_view(struct wined3d_device_context
*context
,
1360 struct wined3d_rendertarget_view
*view
)
1362 struct wined3d_cs_set_depth_stencil_view
*op
;
1364 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1365 op
->opcode
= WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW
;
1368 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1371 static void wined3d_cs_exec_set_vertex_declaration(struct wined3d_cs
*cs
, const void *data
)
1373 const struct wined3d_cs_set_vertex_declaration
*op
= data
;
1375 cs
->state
.vertex_declaration
= op
->declaration
;
1376 device_invalidate_state(cs
->c
.device
, STATE_VDECL
);
1379 void wined3d_device_context_emit_set_vertex_declaration(struct wined3d_device_context
*context
,
1380 struct wined3d_vertex_declaration
*declaration
)
1382 struct wined3d_cs_set_vertex_declaration
*op
;
1384 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1385 op
->opcode
= WINED3D_CS_OP_SET_VERTEX_DECLARATION
;
1386 op
->declaration
= declaration
;
1388 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1391 static void wined3d_cs_exec_set_stream_source(struct wined3d_cs
*cs
, const void *data
)
1393 const struct wined3d_cs_set_stream_source
*op
= data
;
1394 struct wined3d_stream_state
*stream
;
1395 struct wined3d_buffer
*prev
;
1397 stream
= &cs
->state
.streams
[op
->stream_idx
];
1398 prev
= stream
->buffer
;
1399 stream
->buffer
= op
->buffer
;
1400 stream
->offset
= op
->offset
;
1401 stream
->stride
= op
->stride
;
1404 InterlockedIncrement(&op
->buffer
->resource
.bind_count
);
1406 InterlockedDecrement(&prev
->resource
.bind_count
);
1408 device_invalidate_state(cs
->c
.device
, STATE_STREAMSRC
);
1411 void wined3d_device_context_emit_set_stream_source(struct wined3d_device_context
*context
, unsigned int stream_idx
,
1412 struct wined3d_buffer
*buffer
, unsigned int offset
, unsigned int stride
)
1414 struct wined3d_cs_set_stream_source
*op
;
1416 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1417 op
->opcode
= WINED3D_CS_OP_SET_STREAM_SOURCE
;
1418 op
->stream_idx
= stream_idx
;
1419 op
->buffer
= buffer
;
1420 op
->offset
= offset
;
1421 op
->stride
= stride
;
1423 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1426 static void wined3d_cs_exec_set_stream_source_freq(struct wined3d_cs
*cs
, const void *data
)
1428 const struct wined3d_cs_set_stream_source_freq
*op
= data
;
1429 struct wined3d_stream_state
*stream
;
1431 stream
= &cs
->state
.streams
[op
->stream_idx
];
1432 stream
->frequency
= op
->frequency
;
1433 stream
->flags
= op
->flags
;
1435 device_invalidate_state(cs
->c
.device
, STATE_STREAMSRC
);
1438 void wined3d_cs_emit_set_stream_source_freq(struct wined3d_cs
*cs
, UINT stream_idx
, UINT frequency
, UINT flags
)
1440 struct wined3d_cs_set_stream_source_freq
*op
;
1442 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1443 op
->opcode
= WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ
;
1444 op
->stream_idx
= stream_idx
;
1445 op
->frequency
= frequency
;
1448 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
1451 static void wined3d_cs_exec_set_stream_output(struct wined3d_cs
*cs
, const void *data
)
1453 const struct wined3d_cs_set_stream_output
*op
= data
;
1454 struct wined3d_stream_output
*stream
;
1455 struct wined3d_buffer
*prev
;
1457 stream
= &cs
->state
.stream_output
[op
->stream_idx
];
1458 prev
= stream
->buffer
;
1459 stream
->buffer
= op
->buffer
;
1460 stream
->offset
= op
->offset
;
1463 InterlockedIncrement(&op
->buffer
->resource
.bind_count
);
1465 InterlockedDecrement(&prev
->resource
.bind_count
);
1467 device_invalidate_state(cs
->c
.device
, STATE_STREAM_OUTPUT
);
1470 void wined3d_device_context_emit_set_stream_output(struct wined3d_device_context
*context
, unsigned int stream_idx
,
1471 struct wined3d_buffer
*buffer
, unsigned int offset
)
1473 struct wined3d_cs_set_stream_output
*op
;
1475 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1476 op
->opcode
= WINED3D_CS_OP_SET_STREAM_OUTPUT
;
1477 op
->stream_idx
= stream_idx
;
1478 op
->buffer
= buffer
;
1479 op
->offset
= offset
;
1481 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1484 static void wined3d_cs_exec_set_index_buffer(struct wined3d_cs
*cs
, const void *data
)
1486 const struct wined3d_cs_set_index_buffer
*op
= data
;
1487 struct wined3d_buffer
*prev
;
1489 prev
= cs
->state
.index_buffer
;
1490 cs
->state
.index_buffer
= op
->buffer
;
1491 cs
->state
.index_format
= op
->format_id
;
1492 cs
->state
.index_offset
= op
->offset
;
1495 InterlockedIncrement(&op
->buffer
->resource
.bind_count
);
1497 InterlockedDecrement(&prev
->resource
.bind_count
);
1499 device_invalidate_state(cs
->c
.device
, STATE_INDEXBUFFER
);
1502 void wined3d_device_context_emit_set_index_buffer(struct wined3d_device_context
*context
, struct wined3d_buffer
*buffer
,
1503 enum wined3d_format_id format_id
, unsigned int offset
)
1505 struct wined3d_cs_set_index_buffer
*op
;
1507 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1508 op
->opcode
= WINED3D_CS_OP_SET_INDEX_BUFFER
;
1509 op
->buffer
= buffer
;
1510 op
->format_id
= format_id
;
1511 op
->offset
= offset
;
1513 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1516 static void wined3d_cs_exec_set_constant_buffer(struct wined3d_cs
*cs
, const void *data
)
1518 const struct wined3d_cs_set_constant_buffer
*op
= data
;
1519 struct wined3d_buffer
*prev
;
1521 prev
= cs
->state
.cb
[op
->type
][op
->cb_idx
];
1522 cs
->state
.cb
[op
->type
][op
->cb_idx
] = op
->buffer
;
1525 InterlockedIncrement(&op
->buffer
->resource
.bind_count
);
1527 InterlockedDecrement(&prev
->resource
.bind_count
);
1529 device_invalidate_state(cs
->c
.device
, STATE_CONSTANT_BUFFER(op
->type
));
1532 void wined3d_device_context_emit_set_constant_buffer(struct wined3d_device_context
*context
,
1533 enum wined3d_shader_type type
, UINT cb_idx
, struct wined3d_buffer
*buffer
)
1535 struct wined3d_cs_set_constant_buffer
*op
;
1537 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1538 op
->opcode
= WINED3D_CS_OP_SET_CONSTANT_BUFFER
;
1540 op
->cb_idx
= cb_idx
;
1541 op
->buffer
= buffer
;
1543 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1546 static void wined3d_cs_exec_set_texture(struct wined3d_cs
*cs
, const void *data
)
1548 const struct wined3d_d3d_info
*d3d_info
= &cs
->c
.device
->adapter
->d3d_info
;
1549 const struct wined3d_cs_set_texture
*op
= data
;
1550 struct wined3d_texture
*prev
;
1551 BOOL old_use_color_key
= FALSE
, new_use_color_key
= FALSE
;
1553 prev
= cs
->state
.textures
[op
->stage
];
1554 cs
->state
.textures
[op
->stage
] = op
->texture
;
1558 const struct wined3d_format
*new_format
= op
->texture
->resource
.format
;
1559 const struct wined3d_format
*old_format
= prev
? prev
->resource
.format
: NULL
;
1560 unsigned int old_fmt_flags
= prev
? prev
->resource
.format_flags
: 0;
1561 unsigned int new_fmt_flags
= op
->texture
->resource
.format_flags
;
1563 if (InterlockedIncrement(&op
->texture
->resource
.bind_count
) == 1)
1564 op
->texture
->sampler
= op
->stage
;
1566 if (!prev
|| wined3d_texture_gl(op
->texture
)->target
!= wined3d_texture_gl(prev
)->target
1567 || (!is_same_fixup(new_format
->color_fixup
, old_format
->color_fixup
)
1568 && !(can_use_texture_swizzle(d3d_info
, new_format
) && can_use_texture_swizzle(d3d_info
, old_format
)))
1569 || (new_fmt_flags
& WINED3DFMT_FLAG_SHADOW
) != (old_fmt_flags
& WINED3DFMT_FLAG_SHADOW
))
1570 device_invalidate_state(cs
->c
.device
, STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL
));
1572 if (!prev
&& op
->stage
< d3d_info
->limits
.ffp_blend_stages
)
1574 /* The source arguments for color and alpha ops have different
1575 * meanings when a NULL texture is bound, so the COLOR_OP and
1576 * ALPHA_OP have to be dirtified. */
1577 device_invalidate_state(cs
->c
.device
, STATE_TEXTURESTAGE(op
->stage
, WINED3D_TSS_COLOR_OP
));
1578 device_invalidate_state(cs
->c
.device
, STATE_TEXTURESTAGE(op
->stage
, WINED3D_TSS_ALPHA_OP
));
1581 if (!op
->stage
&& op
->texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
)
1582 new_use_color_key
= TRUE
;
1587 if (InterlockedDecrement(&prev
->resource
.bind_count
) && prev
->sampler
== op
->stage
)
1591 /* Search for other stages the texture is bound to. Shouldn't
1592 * happen if applications bind textures to a single stage only. */
1593 TRACE("Searching for other stages the texture is bound to.\n");
1594 for (i
= 0; i
< WINED3D_MAX_COMBINED_SAMPLERS
; ++i
)
1596 if (cs
->state
.textures
[i
] == prev
)
1598 TRACE("Texture is also bound to stage %u.\n", i
);
1605 if (!op
->texture
&& op
->stage
< d3d_info
->limits
.ffp_blend_stages
)
1607 device_invalidate_state(cs
->c
.device
, STATE_TEXTURESTAGE(op
->stage
, WINED3D_TSS_COLOR_OP
));
1608 device_invalidate_state(cs
->c
.device
, STATE_TEXTURESTAGE(op
->stage
, WINED3D_TSS_ALPHA_OP
));
1611 if (!op
->stage
&& prev
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
)
1612 old_use_color_key
= TRUE
;
1615 device_invalidate_state(cs
->c
.device
, STATE_SAMPLER(op
->stage
));
1617 if (new_use_color_key
!= old_use_color_key
)
1618 device_invalidate_state(cs
->c
.device
, STATE_RENDER(WINED3D_RS_COLORKEYENABLE
));
1620 if (new_use_color_key
)
1621 device_invalidate_state(cs
->c
.device
, STATE_COLOR_KEY
);
1624 void wined3d_device_context_emit_set_texture(struct wined3d_device_context
*context
, unsigned int stage
,
1625 struct wined3d_texture
*texture
)
1627 struct wined3d_cs_set_texture
*op
;
1629 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1630 op
->opcode
= WINED3D_CS_OP_SET_TEXTURE
;
1632 op
->texture
= texture
;
1634 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1637 static void wined3d_cs_exec_set_shader_resource_view(struct wined3d_cs
*cs
, const void *data
)
1639 const struct wined3d_cs_set_shader_resource_view
*op
= data
;
1640 struct wined3d_shader_resource_view
*prev
;
1642 prev
= cs
->state
.shader_resource_view
[op
->type
][op
->view_idx
];
1643 cs
->state
.shader_resource_view
[op
->type
][op
->view_idx
] = op
->view
;
1646 InterlockedIncrement(&op
->view
->resource
->bind_count
);
1648 InterlockedDecrement(&prev
->resource
->bind_count
);
1650 if (op
->type
!= WINED3D_SHADER_TYPE_COMPUTE
)
1651 device_invalidate_state(cs
->c
.device
, STATE_GRAPHICS_SHADER_RESOURCE_BINDING
);
1653 device_invalidate_state(cs
->c
.device
, STATE_COMPUTE_SHADER_RESOURCE_BINDING
);
1656 void wined3d_device_context_emit_set_shader_resource_view(struct wined3d_device_context
*context
,
1657 enum wined3d_shader_type type
, unsigned int view_idx
, struct wined3d_shader_resource_view
*view
)
1659 struct wined3d_cs_set_shader_resource_view
*op
;
1661 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1662 op
->opcode
= WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW
;
1664 op
->view_idx
= view_idx
;
1667 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1670 static void wined3d_cs_exec_set_unordered_access_view(struct wined3d_cs
*cs
, const void *data
)
1672 const struct wined3d_cs_set_unordered_access_view
*op
= data
;
1673 struct wined3d_unordered_access_view
*prev
;
1675 prev
= cs
->state
.unordered_access_view
[op
->pipeline
][op
->view_idx
];
1676 cs
->state
.unordered_access_view
[op
->pipeline
][op
->view_idx
] = op
->view
;
1679 InterlockedIncrement(&op
->view
->resource
->bind_count
);
1681 InterlockedDecrement(&prev
->resource
->bind_count
);
1683 if (op
->view
&& op
->initial_count
!= ~0u)
1684 wined3d_unordered_access_view_set_counter(op
->view
, op
->initial_count
);
1686 device_invalidate_state(cs
->c
.device
, STATE_UNORDERED_ACCESS_VIEW_BINDING(op
->pipeline
));
1689 void wined3d_device_context_emit_set_unordered_access_view(struct wined3d_device_context
*context
,
1690 enum wined3d_pipeline pipeline
, unsigned int view_idx
, struct wined3d_unordered_access_view
*view
,
1691 unsigned int initial_count
)
1693 struct wined3d_cs_set_unordered_access_view
*op
;
1695 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1696 op
->opcode
= WINED3D_CS_OP_SET_UNORDERED_ACCESS_VIEW
;
1697 op
->pipeline
= pipeline
;
1698 op
->view_idx
= view_idx
;
1700 op
->initial_count
= initial_count
;
1702 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1705 static void wined3d_cs_exec_set_sampler(struct wined3d_cs
*cs
, const void *data
)
1707 const struct wined3d_cs_set_sampler
*op
= data
;
1709 cs
->state
.sampler
[op
->type
][op
->sampler_idx
] = op
->sampler
;
1710 if (op
->type
!= WINED3D_SHADER_TYPE_COMPUTE
)
1711 device_invalidate_state(cs
->c
.device
, STATE_GRAPHICS_SHADER_RESOURCE_BINDING
);
1713 device_invalidate_state(cs
->c
.device
, STATE_COMPUTE_SHADER_RESOURCE_BINDING
);
1716 void wined3d_device_context_emit_set_sampler(struct wined3d_device_context
*context
, enum wined3d_shader_type type
,
1717 unsigned int sampler_idx
, struct wined3d_sampler
*sampler
)
1719 struct wined3d_cs_set_sampler
*op
;
1721 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1722 op
->opcode
= WINED3D_CS_OP_SET_SAMPLER
;
1724 op
->sampler_idx
= sampler_idx
;
1725 op
->sampler
= sampler
;
1727 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1730 static void wined3d_cs_exec_set_shader(struct wined3d_cs
*cs
, const void *data
)
1732 const struct wined3d_cs_set_shader
*op
= data
;
1734 cs
->state
.shader
[op
->type
] = op
->shader
;
1735 device_invalidate_state(cs
->c
.device
, STATE_SHADER(op
->type
));
1736 if (op
->type
!= WINED3D_SHADER_TYPE_COMPUTE
)
1737 device_invalidate_state(cs
->c
.device
, STATE_GRAPHICS_SHADER_RESOURCE_BINDING
);
1739 device_invalidate_state(cs
->c
.device
, STATE_COMPUTE_SHADER_RESOURCE_BINDING
);
1742 void wined3d_device_context_emit_set_shader(struct wined3d_device_context
*context
,
1743 enum wined3d_shader_type type
, struct wined3d_shader
*shader
)
1745 struct wined3d_cs_set_shader
*op
;
1747 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1748 op
->opcode
= WINED3D_CS_OP_SET_SHADER
;
1750 op
->shader
= shader
;
1752 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1755 static void wined3d_cs_exec_set_blend_state(struct wined3d_cs
*cs
, const void *data
)
1757 const struct wined3d_cs_set_blend_state
*op
= data
;
1758 struct wined3d_state
*state
= &cs
->state
;
1760 if (state
->blend_state
!= op
->state
)
1762 state
->blend_state
= op
->state
;
1763 device_invalidate_state(cs
->c
.device
, STATE_BLEND
);
1765 state
->blend_factor
= op
->factor
;
1766 device_invalidate_state(cs
->c
.device
, STATE_BLEND_FACTOR
);
1767 state
->sample_mask
= op
->sample_mask
;
1768 device_invalidate_state(cs
->c
.device
, STATE_SAMPLE_MASK
);
1771 void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context
*context
,
1772 struct wined3d_blend_state
*state
, const struct wined3d_color
*blend_factor
, unsigned int sample_mask
)
1774 struct wined3d_cs_set_blend_state
*op
;
1776 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1777 op
->opcode
= WINED3D_CS_OP_SET_BLEND_STATE
;
1779 op
->factor
= *blend_factor
;
1780 op
->sample_mask
= sample_mask
;
1782 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1785 static void wined3d_cs_exec_set_depth_stencil_state(struct wined3d_cs
*cs
, const void *data
)
1787 const struct wined3d_cs_set_depth_stencil_state
*op
= data
;
1788 struct wined3d_state
*state
= &cs
->state
;
1790 if (state
->depth_stencil_state
!= op
->state
)
1792 state
->depth_stencil_state
= op
->state
;
1793 device_invalidate_state(cs
->c
.device
, STATE_DEPTH_STENCIL
);
1795 state
->stencil_ref
= op
->stencil_ref
;
1796 device_invalidate_state(cs
->c
.device
, STATE_STENCIL_REF
);
1799 void wined3d_device_context_emit_set_depth_stencil_state(struct wined3d_device_context
*context
,
1800 struct wined3d_depth_stencil_state
*state
, unsigned int stencil_ref
)
1802 struct wined3d_cs_set_depth_stencil_state
*op
;
1804 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1805 op
->opcode
= WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE
;
1807 op
->stencil_ref
= stencil_ref
;
1809 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1812 static void wined3d_cs_exec_set_rasterizer_state(struct wined3d_cs
*cs
, const void *data
)
1814 const struct wined3d_cs_set_rasterizer_state
*op
= data
;
1816 cs
->state
.rasterizer_state
= op
->state
;
1817 device_invalidate_state(cs
->c
.device
, STATE_RASTERIZER
);
1820 void wined3d_device_context_emit_set_rasterizer_state(struct wined3d_device_context
*context
,
1821 struct wined3d_rasterizer_state
*rasterizer_state
)
1823 struct wined3d_cs_set_rasterizer_state
*op
;
1825 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1826 op
->opcode
= WINED3D_CS_OP_SET_RASTERIZER_STATE
;
1827 op
->state
= rasterizer_state
;
1829 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1832 static void wined3d_cs_exec_set_render_state(struct wined3d_cs
*cs
, const void *data
)
1834 const struct wined3d_cs_set_render_state
*op
= data
;
1836 cs
->state
.render_states
[op
->state
] = op
->value
;
1837 device_invalidate_state(cs
->c
.device
, STATE_RENDER(op
->state
));
1840 void wined3d_device_context_emit_set_render_state(struct wined3d_device_context
*context
,
1841 enum wined3d_render_state state
, unsigned int value
)
1843 struct wined3d_cs_set_render_state
*op
;
1845 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1846 op
->opcode
= WINED3D_CS_OP_SET_RENDER_STATE
;
1850 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1853 static void wined3d_cs_exec_set_texture_state(struct wined3d_cs
*cs
, const void *data
)
1855 const struct wined3d_cs_set_texture_state
*op
= data
;
1857 cs
->state
.texture_states
[op
->stage
][op
->state
] = op
->value
;
1858 device_invalidate_state(cs
->c
.device
, STATE_TEXTURESTAGE(op
->stage
, op
->state
));
1861 void wined3d_device_context_emit_set_texture_state(struct wined3d_device_context
*context
, unsigned int stage
,
1862 enum wined3d_texture_stage_state state
, unsigned int value
)
1864 struct wined3d_cs_set_texture_state
*op
;
1866 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1867 op
->opcode
= WINED3D_CS_OP_SET_TEXTURE_STATE
;
1872 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1875 static void wined3d_cs_exec_set_sampler_state(struct wined3d_cs
*cs
, const void *data
)
1877 const struct wined3d_cs_set_sampler_state
*op
= data
;
1879 cs
->state
.sampler_states
[op
->sampler_idx
][op
->state
] = op
->value
;
1880 device_invalidate_state(cs
->c
.device
, STATE_SAMPLER(op
->sampler_idx
));
1883 void wined3d_device_context_emit_set_sampler_state(struct wined3d_device_context
*context
, unsigned int sampler_idx
,
1884 enum wined3d_sampler_state state
, unsigned int value
)
1886 struct wined3d_cs_set_sampler_state
*op
;
1888 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1889 op
->opcode
= WINED3D_CS_OP_SET_SAMPLER_STATE
;
1890 op
->sampler_idx
= sampler_idx
;
1894 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1897 static void wined3d_cs_exec_set_transform(struct wined3d_cs
*cs
, const void *data
)
1899 const struct wined3d_cs_set_transform
*op
= data
;
1901 cs
->state
.transforms
[op
->state
] = op
->matrix
;
1902 if (op
->state
< WINED3D_TS_WORLD_MATRIX(cs
->c
.device
->adapter
->d3d_info
.limits
.ffp_vertex_blend_matrices
))
1903 device_invalidate_state(cs
->c
.device
, STATE_TRANSFORM(op
->state
));
1906 void wined3d_device_context_emit_set_transform(struct wined3d_device_context
*context
,
1907 enum wined3d_transform_state state
, const struct wined3d_matrix
*matrix
)
1909 struct wined3d_cs_set_transform
*op
;
1911 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1912 op
->opcode
= WINED3D_CS_OP_SET_TRANSFORM
;
1914 op
->matrix
= *matrix
;
1916 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1919 static void wined3d_cs_exec_set_clip_plane(struct wined3d_cs
*cs
, const void *data
)
1921 const struct wined3d_cs_set_clip_plane
*op
= data
;
1923 cs
->state
.clip_planes
[op
->plane_idx
] = op
->plane
;
1924 device_invalidate_state(cs
->c
.device
, STATE_CLIPPLANE(op
->plane_idx
));
1927 void wined3d_device_context_emit_set_clip_plane(struct wined3d_device_context
*context
,
1928 unsigned int plane_idx
, const struct wined3d_vec4
*plane
)
1930 struct wined3d_cs_set_clip_plane
*op
;
1932 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
1933 op
->opcode
= WINED3D_CS_OP_SET_CLIP_PLANE
;
1934 op
->plane_idx
= plane_idx
;
1937 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
1940 static void wined3d_cs_exec_set_color_key(struct wined3d_cs
*cs
, const void *data
)
1942 const struct wined3d_cs_set_color_key
*op
= data
;
1943 struct wined3d_texture
*texture
= op
->texture
;
1949 case WINED3D_CKEY_DST_BLT
:
1950 texture
->async
.dst_blt_color_key
= op
->color_key
;
1951 texture
->async
.color_key_flags
|= WINED3D_CKEY_DST_BLT
;
1954 case WINED3D_CKEY_DST_OVERLAY
:
1955 texture
->async
.dst_overlay_color_key
= op
->color_key
;
1956 texture
->async
.color_key_flags
|= WINED3D_CKEY_DST_OVERLAY
;
1959 case WINED3D_CKEY_SRC_BLT
:
1960 if (texture
== cs
->state
.textures
[0])
1962 device_invalidate_state(cs
->c
.device
, STATE_COLOR_KEY
);
1963 if (!(texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
))
1964 device_invalidate_state(cs
->c
.device
, STATE_RENDER(WINED3D_RS_COLORKEYENABLE
));
1967 texture
->async
.src_blt_color_key
= op
->color_key
;
1968 texture
->async
.color_key_flags
|= WINED3D_CKEY_SRC_BLT
;
1971 case WINED3D_CKEY_SRC_OVERLAY
:
1972 texture
->async
.src_overlay_color_key
= op
->color_key
;
1973 texture
->async
.color_key_flags
|= WINED3D_CKEY_SRC_OVERLAY
;
1981 case WINED3D_CKEY_DST_BLT
:
1982 texture
->async
.color_key_flags
&= ~WINED3D_CKEY_DST_BLT
;
1985 case WINED3D_CKEY_DST_OVERLAY
:
1986 texture
->async
.color_key_flags
&= ~WINED3D_CKEY_DST_OVERLAY
;
1989 case WINED3D_CKEY_SRC_BLT
:
1990 if (texture
== cs
->state
.textures
[0] && texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
)
1991 device_invalidate_state(cs
->c
.device
, STATE_RENDER(WINED3D_RS_COLORKEYENABLE
));
1993 texture
->async
.color_key_flags
&= ~WINED3D_CKEY_SRC_BLT
;
1996 case WINED3D_CKEY_SRC_OVERLAY
:
1997 texture
->async
.color_key_flags
&= ~WINED3D_CKEY_SRC_OVERLAY
;
2003 void wined3d_cs_emit_set_color_key(struct wined3d_cs
*cs
, struct wined3d_texture
*texture
,
2004 WORD flags
, const struct wined3d_color_key
*color_key
)
2006 struct wined3d_cs_set_color_key
*op
;
2008 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2009 op
->opcode
= WINED3D_CS_OP_SET_COLOR_KEY
;
2010 op
->texture
= texture
;
2014 op
->color_key
= *color_key
;
2020 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2023 static void wined3d_cs_exec_set_material(struct wined3d_cs
*cs
, const void *data
)
2025 const struct wined3d_cs_set_material
*op
= data
;
2027 cs
->state
.material
= op
->material
;
2028 device_invalidate_state(cs
->c
.device
, STATE_MATERIAL
);
2031 void wined3d_device_context_emit_set_material(struct wined3d_device_context
*context
,
2032 const struct wined3d_material
*material
)
2034 struct wined3d_cs_set_material
*op
;
2036 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2037 op
->opcode
= WINED3D_CS_OP_SET_MATERIAL
;
2038 op
->material
= *material
;
2040 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2043 static void wined3d_cs_exec_set_light(struct wined3d_cs
*cs
, const void *data
)
2045 const struct wined3d_cs_set_light
*op
= data
;
2046 struct wined3d_light_info
*light_info
;
2047 unsigned int light_idx
, hash_idx
;
2049 light_idx
= op
->light
.OriginalIndex
;
2051 if (!(light_info
= wined3d_light_state_get_light(&cs
->state
.light_state
, light_idx
)))
2053 TRACE("Adding new light.\n");
2054 if (!(light_info
= heap_alloc_zero(sizeof(*light_info
))))
2056 ERR("Failed to allocate light info.\n");
2060 hash_idx
= LIGHTMAP_HASHFUNC(light_idx
);
2061 list_add_head(&cs
->state
.light_state
.light_map
[hash_idx
], &light_info
->entry
);
2062 light_info
->glIndex
= -1;
2063 light_info
->OriginalIndex
= light_idx
;
2066 if (light_info
->glIndex
!= -1)
2068 if (light_info
->OriginalParms
.type
!= op
->light
.OriginalParms
.type
)
2069 device_invalidate_state(cs
->c
.device
, STATE_LIGHT_TYPE
);
2070 device_invalidate_state(cs
->c
.device
, STATE_ACTIVELIGHT(light_info
->glIndex
));
2073 light_info
->OriginalParms
= op
->light
.OriginalParms
;
2074 light_info
->position
= op
->light
.position
;
2075 light_info
->direction
= op
->light
.direction
;
2076 light_info
->exponent
= op
->light
.exponent
;
2077 light_info
->cutoff
= op
->light
.cutoff
;
2080 void wined3d_device_context_emit_set_light(struct wined3d_device_context
*context
,
2081 const struct wined3d_light_info
*light
)
2083 struct wined3d_cs_set_light
*op
;
2085 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2086 op
->opcode
= WINED3D_CS_OP_SET_LIGHT
;
2089 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2092 static void wined3d_cs_exec_set_light_enable(struct wined3d_cs
*cs
, const void *data
)
2094 const struct wined3d_cs_set_light_enable
*op
= data
;
2095 struct wined3d_device
*device
= cs
->c
.device
;
2096 struct wined3d_light_info
*light_info
;
2099 if (!(light_info
= wined3d_light_state_get_light(&cs
->state
.light_state
, op
->idx
)))
2101 ERR("Light doesn't exist.\n");
2105 prev_idx
= light_info
->glIndex
;
2106 wined3d_light_state_enable_light(&cs
->state
.light_state
, &device
->adapter
->d3d_info
, light_info
, op
->enable
);
2107 if (light_info
->glIndex
!= prev_idx
)
2109 device_invalidate_state(device
, STATE_LIGHT_TYPE
);
2110 device_invalidate_state(device
, STATE_ACTIVELIGHT(op
->enable
? light_info
->glIndex
: prev_idx
));
2114 void wined3d_device_context_emit_set_light_enable(struct wined3d_device_context
*context
, unsigned int idx
, BOOL enable
)
2116 struct wined3d_cs_set_light_enable
*op
;
2118 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2119 op
->opcode
= WINED3D_CS_OP_SET_LIGHT_ENABLE
;
2121 op
->enable
= enable
;
2123 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2126 static void wined3d_cs_exec_set_feature_level(struct wined3d_cs
*cs
, const void *data
)
2128 const struct wined3d_cs_set_feature_level
*op
= data
;
2130 cs
->state
.feature_level
= op
->level
;
2133 void wined3d_device_context_emit_set_feature_level(struct wined3d_device_context
*context
,
2134 enum wined3d_feature_level level
)
2136 struct wined3d_cs_set_feature_level
*op
;
2138 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2139 op
->opcode
= WINED3D_CS_OP_SET_FEATURE_LEVEL
;
2142 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2151 wined3d_cs_push_constant_info
[] =
2153 /* WINED3D_PUSH_CONSTANTS_VS_F */
2154 {FIELD_OFFSET(struct wined3d_state
, vs_consts_f
), sizeof(struct wined3d_vec4
), WINED3D_SHADER_CONST_VS_F
},
2155 /* WINED3D_PUSH_CONSTANTS_PS_F */
2156 {FIELD_OFFSET(struct wined3d_state
, ps_consts_f
), sizeof(struct wined3d_vec4
), WINED3D_SHADER_CONST_PS_F
},
2157 /* WINED3D_PUSH_CONSTANTS_VS_I */
2158 {FIELD_OFFSET(struct wined3d_state
, vs_consts_i
), sizeof(struct wined3d_ivec4
), WINED3D_SHADER_CONST_VS_I
},
2159 /* WINED3D_PUSH_CONSTANTS_PS_I */
2160 {FIELD_OFFSET(struct wined3d_state
, ps_consts_i
), sizeof(struct wined3d_ivec4
), WINED3D_SHADER_CONST_PS_I
},
2161 /* WINED3D_PUSH_CONSTANTS_VS_B */
2162 {FIELD_OFFSET(struct wined3d_state
, vs_consts_b
), sizeof(BOOL
), WINED3D_SHADER_CONST_VS_B
},
2163 /* WINED3D_PUSH_CONSTANTS_PS_B */
2164 {FIELD_OFFSET(struct wined3d_state
, ps_consts_b
), sizeof(BOOL
), WINED3D_SHADER_CONST_PS_B
},
2167 static void wined3d_cs_st_push_constants(struct wined3d_device_context
*context
, enum wined3d_push_constants p
,
2168 unsigned int start_idx
, unsigned int count
, const void *constants
)
2170 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2171 struct wined3d_device
*device
= cs
->c
.device
;
2172 unsigned int context_count
;
2176 if (p
== WINED3D_PUSH_CONSTANTS_VS_F
)
2177 device
->shader_backend
->shader_update_float_vertex_constants(device
, start_idx
, count
);
2178 else if (p
== WINED3D_PUSH_CONSTANTS_PS_F
)
2179 device
->shader_backend
->shader_update_float_pixel_constants(device
, start_idx
, count
);
2181 offset
= wined3d_cs_push_constant_info
[p
].offset
+ start_idx
* wined3d_cs_push_constant_info
[p
].size
;
2182 memcpy((BYTE
*)&cs
->state
+ offset
, constants
, count
* wined3d_cs_push_constant_info
[p
].size
);
2183 for (i
= 0, context_count
= device
->context_count
; i
< context_count
; ++i
)
2185 device
->contexts
[i
]->constant_update_mask
|= wined3d_cs_push_constant_info
[p
].mask
;
2189 static void wined3d_cs_exec_push_constants(struct wined3d_cs
*cs
, const void *data
)
2191 const struct wined3d_cs_push_constants
*op
= data
;
2193 wined3d_cs_st_push_constants(&cs
->c
, op
->type
, op
->start_idx
, op
->count
, op
->constants
);
2196 static void wined3d_cs_mt_push_constants(struct wined3d_device_context
*context
, enum wined3d_push_constants p
,
2197 unsigned int start_idx
, unsigned int count
, const void *constants
)
2199 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2200 struct wined3d_cs_push_constants
*op
;
2203 size
= count
* wined3d_cs_push_constant_info
[p
].size
;
2204 op
= wined3d_device_context_require_space(&cs
->c
, FIELD_OFFSET(struct wined3d_cs_push_constants
, constants
[size
]),
2205 WINED3D_CS_QUEUE_DEFAULT
);
2206 op
->opcode
= WINED3D_CS_OP_PUSH_CONSTANTS
;
2208 op
->start_idx
= start_idx
;
2210 memcpy(op
->constants
, constants
, size
);
2212 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2215 static void wined3d_cs_exec_reset_state(struct wined3d_cs
*cs
, const void *data
)
2217 const struct wined3d_device
*device
= cs
->c
.device
;
2218 const struct wined3d_cs_reset_state
*op
= data
;
2219 const struct wined3d_state_entry
*state_table
;
2222 state_cleanup(&cs
->state
);
2223 wined3d_state_reset(&cs
->state
, &device
->adapter
->d3d_info
);
2226 state_table
= device
->state_table
;
2227 for (state
= 0; state
<= STATE_HIGHEST
; ++state
)
2229 if (state_table
[state
].representative
)
2230 device_invalidate_state(device
, state
);
2235 void wined3d_device_context_emit_reset_state(struct wined3d_device_context
*context
, bool invalidate
)
2237 struct wined3d_cs_reset_state
*op
;
2239 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2240 op
->opcode
= WINED3D_CS_OP_RESET_STATE
;
2241 op
->invalidate
= invalidate
;
2243 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2246 static void wined3d_cs_exec_callback(struct wined3d_cs
*cs
, const void *data
)
2248 const struct wined3d_cs_callback
*op
= data
;
2250 op
->callback(op
->object
);
2253 static void wined3d_cs_emit_callback(struct wined3d_cs
*cs
, void (*callback
)(void *object
), void *object
)
2255 struct wined3d_cs_callback
*op
;
2257 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2258 op
->opcode
= WINED3D_CS_OP_CALLBACK
;
2259 op
->callback
= callback
;
2260 op
->object
= object
;
2262 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2265 void wined3d_cs_destroy_object(struct wined3d_cs
*cs
, void (*callback
)(void *object
), void *object
)
2267 wined3d_cs_emit_callback(cs
, callback
, object
);
2270 void wined3d_cs_init_object(struct wined3d_cs
*cs
, void (*callback
)(void *object
), void *object
)
2272 wined3d_cs_emit_callback(cs
, callback
, object
);
2275 static void wined3d_cs_exec_query_issue(struct wined3d_cs
*cs
, const void *data
)
2277 const struct wined3d_cs_query_issue
*op
= data
;
2278 struct wined3d_query
*query
= op
->query
;
2281 poll
= query
->query_ops
->query_issue(query
, op
->flags
);
2286 if (poll
&& list_empty(&query
->poll_list_entry
))
2288 if (query
->buffer_object
)
2289 InterlockedIncrement(&query
->counter_retrieved
);
2291 list_add_tail(&cs
->query_poll_list
, &query
->poll_list_entry
);
2295 /* This can happen if occlusion queries are restarted. This discards the
2296 * old result, since polling it could result in a GL error. */
2297 if ((op
->flags
& WINED3DISSUE_BEGIN
) && !poll
&& !list_empty(&query
->poll_list_entry
))
2299 list_remove(&query
->poll_list_entry
);
2300 list_init(&query
->poll_list_entry
);
2301 InterlockedIncrement(&query
->counter_retrieved
);
2305 /* This can happen when an occlusion query is ended without being started,
2306 * in which case we don't want to poll, but still have to counter-balance
2307 * the increment of the main counter.
2309 * This can also happen if an event query is re-issued before the first
2310 * fence was reached. In this case the query is already in the list and
2311 * the poll function will check the new fence. We have to counter-balance
2312 * the discarded increment. */
2313 if (op
->flags
& WINED3DISSUE_END
)
2314 InterlockedIncrement(&query
->counter_retrieved
);
2317 static void wined3d_cs_issue_query(struct wined3d_device_context
*context
,
2318 struct wined3d_query
*query
, unsigned int flags
)
2320 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2321 struct wined3d_cs_query_issue
*op
;
2323 if (flags
& WINED3DISSUE_END
)
2324 ++query
->counter_main
;
2326 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2327 op
->opcode
= WINED3D_CS_OP_QUERY_ISSUE
;
2331 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2332 cs
->queries_flushed
= FALSE
;
2334 if (flags
& WINED3DISSUE_BEGIN
)
2335 query
->state
= QUERY_BUILDING
;
2337 query
->state
= QUERY_SIGNALLED
;
2340 static void wined3d_cs_execute_command_list(struct wined3d_device_context
*context
,
2341 struct wined3d_command_list
*list
, bool restore_state
)
2343 struct wined3d_cs_execute_command_list
*op
;
2346 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2347 op
->opcode
= WINED3D_CS_OP_EXECUTE_COMMAND_LIST
;
2350 for (i
= 0; i
< list
->resource_count
; ++i
)
2351 wined3d_resource_acquire(list
->resources
[i
]);
2353 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2356 wined3d_device_context_set_state(context
, context
->state
);
2358 wined3d_device_context_reset_state(context
);
2361 static void wined3d_cs_exec_preload_resource(struct wined3d_cs
*cs
, const void *data
)
2363 const struct wined3d_cs_preload_resource
*op
= data
;
2364 struct wined3d_resource
*resource
= op
->resource
;
2366 resource
->resource_ops
->resource_preload(resource
);
2367 wined3d_resource_release(resource
);
2370 void wined3d_cs_emit_preload_resource(struct wined3d_cs
*cs
, struct wined3d_resource
*resource
)
2372 struct wined3d_cs_preload_resource
*op
;
2374 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2375 op
->opcode
= WINED3D_CS_OP_PRELOAD_RESOURCE
;
2376 op
->resource
= resource
;
2378 wined3d_resource_acquire(resource
);
2380 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2383 static void wined3d_cs_exec_unload_resource(struct wined3d_cs
*cs
, const void *data
)
2385 const struct wined3d_cs_unload_resource
*op
= data
;
2386 struct wined3d_resource
*resource
= op
->resource
;
2388 resource
->resource_ops
->resource_unload(resource
);
2389 wined3d_resource_release(resource
);
2392 void wined3d_cs_emit_unload_resource(struct wined3d_cs
*cs
, struct wined3d_resource
*resource
)
2394 struct wined3d_cs_unload_resource
*op
;
2396 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2397 op
->opcode
= WINED3D_CS_OP_UNLOAD_RESOURCE
;
2398 op
->resource
= resource
;
2400 wined3d_resource_acquire(resource
);
2402 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2405 static void wined3d_cs_exec_map(struct wined3d_cs
*cs
, const void *data
)
2407 const struct wined3d_cs_map
*op
= data
;
2408 struct wined3d_resource
*resource
= op
->resource
;
2410 *op
->hr
= resource
->resource_ops
->resource_sub_resource_map(resource
,
2411 op
->sub_resource_idx
, op
->map_ptr
, op
->box
, op
->flags
);
2414 static HRESULT
wined3d_cs_map(struct wined3d_device_context
*context
, struct wined3d_resource
*resource
,
2415 unsigned int sub_resource_idx
, void **map_ptr
, const struct wined3d_box
*box
, unsigned int flags
)
2417 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2418 struct wined3d_cs_map
*op
;
2421 /* Mapping resources from the worker thread isn't an issue by itself, but
2422 * increasing the map count would be visible to applications. */
2423 wined3d_not_from_cs(cs
);
2425 wined3d_resource_wait_idle(resource
);
2427 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_MAP
);
2428 op
->opcode
= WINED3D_CS_OP_MAP
;
2429 op
->resource
= resource
;
2430 op
->sub_resource_idx
= sub_resource_idx
;
2431 op
->map_ptr
= map_ptr
;
2436 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_MAP
);
2437 wined3d_cs_finish(cs
, WINED3D_CS_QUEUE_MAP
);
2442 static void wined3d_cs_exec_unmap(struct wined3d_cs
*cs
, const void *data
)
2444 const struct wined3d_cs_unmap
*op
= data
;
2445 struct wined3d_resource
*resource
= op
->resource
;
2447 *op
->hr
= resource
->resource_ops
->resource_sub_resource_unmap(resource
, op
->sub_resource_idx
);
2450 static HRESULT
wined3d_cs_unmap(struct wined3d_device_context
*context
, struct wined3d_resource
*resource
,
2451 unsigned int sub_resource_idx
)
2453 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2454 struct wined3d_cs_unmap
*op
;
2457 wined3d_not_from_cs(cs
);
2459 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_MAP
);
2460 op
->opcode
= WINED3D_CS_OP_UNMAP
;
2461 op
->resource
= resource
;
2462 op
->sub_resource_idx
= sub_resource_idx
;
2465 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_MAP
);
2466 wined3d_cs_finish(cs
, WINED3D_CS_QUEUE_MAP
);
2471 static void wined3d_cs_exec_blt_sub_resource(struct wined3d_cs
*cs
, const void *data
)
2473 const struct wined3d_cs_blt_sub_resource
*op
= data
;
2475 if (op
->dst_resource
->type
== WINED3D_RTYPE_BUFFER
)
2477 wined3d_buffer_copy(buffer_from_resource(op
->dst_resource
), op
->dst_box
.left
,
2478 buffer_from_resource(op
->src_resource
), op
->src_box
.left
,
2479 op
->src_box
.right
- op
->src_box
.left
);
2481 else if (op
->dst_resource
->type
== WINED3D_RTYPE_TEXTURE_3D
)
2483 struct wined3d_texture
*src_texture
, *dst_texture
;
2484 unsigned int level
, update_w
, update_h
, update_d
;
2485 unsigned int row_pitch
, slice_pitch
;
2486 struct wined3d_context
*context
;
2487 struct wined3d_bo_address addr
;
2489 if (op
->flags
& ~WINED3D_BLT_RAW
)
2491 FIXME("Flags %#x not implemented for %s resources.\n",
2492 op
->flags
, debug_d3dresourcetype(op
->dst_resource
->type
));
2496 if (!(op
->flags
& WINED3D_BLT_RAW
) && op
->src_resource
->format
!= op
->dst_resource
->format
)
2498 FIXME("Format conversion not implemented for %s resources.\n",
2499 debug_d3dresourcetype(op
->dst_resource
->type
));
2503 update_w
= op
->dst_box
.right
- op
->dst_box
.left
;
2504 update_h
= op
->dst_box
.bottom
- op
->dst_box
.top
;
2505 update_d
= op
->dst_box
.back
- op
->dst_box
.front
;
2506 if (op
->src_box
.right
- op
->src_box
.left
!= update_w
2507 || op
->src_box
.bottom
- op
->src_box
.top
!= update_h
2508 || op
->src_box
.back
- op
->src_box
.front
!= update_d
)
2510 FIXME("Stretching not implemented for %s resources.\n",
2511 debug_d3dresourcetype(op
->dst_resource
->type
));
2515 dst_texture
= texture_from_resource(op
->dst_resource
);
2516 src_texture
= texture_from_resource(op
->src_resource
);
2518 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2520 if (!wined3d_texture_load_location(src_texture
, op
->src_sub_resource_idx
,
2521 context
, src_texture
->resource
.map_binding
))
2523 ERR("Failed to load source sub-resource into %s.\n",
2524 wined3d_debug_location(src_texture
->resource
.map_binding
));
2525 context_release(context
);
2529 level
= op
->dst_sub_resource_idx
% dst_texture
->level_count
;
2530 if (update_w
== wined3d_texture_get_level_width(dst_texture
, level
)
2531 && update_h
== wined3d_texture_get_level_height(dst_texture
, level
)
2532 && update_d
== wined3d_texture_get_level_depth(dst_texture
, level
))
2534 wined3d_texture_prepare_location(dst_texture
, op
->dst_sub_resource_idx
,
2535 context
, WINED3D_LOCATION_TEXTURE_RGB
);
2537 else if (!wined3d_texture_load_location(dst_texture
, op
->dst_sub_resource_idx
,
2538 context
, WINED3D_LOCATION_TEXTURE_RGB
))
2540 ERR("Failed to load destination sub-resource.\n");
2541 context_release(context
);
2545 wined3d_texture_get_memory(src_texture
, op
->src_sub_resource_idx
, &addr
, src_texture
->resource
.map_binding
);
2546 wined3d_texture_get_pitch(src_texture
, op
->src_sub_resource_idx
% src_texture
->level_count
,
2547 &row_pitch
, &slice_pitch
);
2549 dst_texture
->texture_ops
->texture_upload_data(context
, wined3d_const_bo_address(&addr
),
2550 dst_texture
->resource
.format
, &op
->src_box
, row_pitch
, slice_pitch
, dst_texture
,
2551 op
->dst_sub_resource_idx
, WINED3D_LOCATION_TEXTURE_RGB
,
2552 op
->dst_box
.left
, op
->dst_box
.top
, op
->dst_box
.front
);
2553 wined3d_texture_validate_location(dst_texture
, op
->dst_sub_resource_idx
, WINED3D_LOCATION_TEXTURE_RGB
);
2554 wined3d_texture_invalidate_location(dst_texture
, op
->dst_sub_resource_idx
, ~WINED3D_LOCATION_TEXTURE_RGB
);
2556 context_release(context
);
2560 if (FAILED(texture2d_blt(texture_from_resource(op
->dst_resource
), op
->dst_sub_resource_idx
,
2561 &op
->dst_box
, texture_from_resource(op
->src_resource
), op
->src_sub_resource_idx
,
2562 &op
->src_box
, op
->flags
, &op
->fx
, op
->filter
)))
2563 FIXME("Blit failed.\n");
2567 if (op
->src_resource
)
2568 wined3d_resource_release(op
->src_resource
);
2569 wined3d_resource_release(op
->dst_resource
);
2572 void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context
*context
,
2573 struct wined3d_resource
*dst_resource
, unsigned int dst_sub_resource_idx
, const struct wined3d_box
*dst_box
,
2574 struct wined3d_resource
*src_resource
, unsigned int src_sub_resource_idx
, const struct wined3d_box
*src_box
,
2575 unsigned int flags
, const struct wined3d_blt_fx
*fx
, enum wined3d_texture_filter_type filter
)
2577 struct wined3d_cs_blt_sub_resource
*op
;
2579 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2580 op
->opcode
= WINED3D_CS_OP_BLT_SUB_RESOURCE
;
2581 op
->dst_resource
= dst_resource
;
2582 op
->dst_sub_resource_idx
= dst_sub_resource_idx
;
2583 op
->dst_box
= *dst_box
;
2584 op
->src_resource
= src_resource
;
2585 op
->src_sub_resource_idx
= src_sub_resource_idx
;
2586 op
->src_box
= *src_box
;
2591 memset(&op
->fx
, 0, sizeof(op
->fx
));
2592 op
->filter
= filter
;
2594 wined3d_device_context_acquire_resource(context
, dst_resource
);
2596 wined3d_device_context_acquire_resource(context
, src_resource
);
2598 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2599 if (flags
& WINED3D_BLT_SYNCHRONOUS
)
2600 wined3d_device_context_finish(context
, WINED3D_CS_QUEUE_DEFAULT
);
2603 static void wined3d_cs_exec_update_sub_resource(struct wined3d_cs
*cs
, const void *data
)
2605 const struct wined3d_cs_update_sub_resource
*op
= data
;
2606 struct wined3d_resource
*resource
= op
->resource
;
2607 const struct wined3d_box
*box
= &op
->box
;
2608 unsigned int width
, height
, depth
, level
;
2609 struct wined3d_const_bo_address addr
;
2610 struct wined3d_context
*context
;
2611 struct wined3d_texture
*texture
;
2612 struct wined3d_box src_box
;
2614 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2616 if (resource
->type
== WINED3D_RTYPE_BUFFER
)
2618 struct wined3d_buffer
*buffer
= buffer_from_resource(resource
);
2620 if (!wined3d_buffer_load_location(buffer
, context
, WINED3D_LOCATION_BUFFER
))
2622 ERR("Failed to load buffer location.\n");
2626 wined3d_buffer_upload_data(buffer
, context
, box
, op
->data
.data
);
2627 wined3d_buffer_invalidate_location(buffer
, ~WINED3D_LOCATION_BUFFER
);
2631 texture
= wined3d_texture_from_resource(resource
);
2633 level
= op
->sub_resource_idx
% texture
->level_count
;
2634 width
= wined3d_texture_get_level_width(texture
, level
);
2635 height
= wined3d_texture_get_level_height(texture
, level
);
2636 depth
= wined3d_texture_get_level_depth(texture
, level
);
2638 addr
.buffer_object
= 0;
2639 addr
.addr
= op
->data
.data
;
2641 /* Only load the sub-resource for partial updates. */
2642 if (!box
->left
&& !box
->top
&& !box
->front
2643 && box
->right
== width
&& box
->bottom
== height
&& box
->back
== depth
)
2644 wined3d_texture_prepare_location(texture
, op
->sub_resource_idx
, context
, WINED3D_LOCATION_TEXTURE_RGB
);
2646 wined3d_texture_load_location(texture
, op
->sub_resource_idx
, context
, WINED3D_LOCATION_TEXTURE_RGB
);
2648 wined3d_box_set(&src_box
, 0, 0, box
->right
- box
->left
, box
->bottom
- box
->top
, 0, box
->back
- box
->front
);
2649 texture
->texture_ops
->texture_upload_data(context
, &addr
, texture
->resource
.format
, &src_box
,
2650 op
->data
.row_pitch
, op
->data
.slice_pitch
, texture
, op
->sub_resource_idx
,
2651 WINED3D_LOCATION_TEXTURE_RGB
, box
->left
, box
->top
, box
->front
);
2653 wined3d_texture_validate_location(texture
, op
->sub_resource_idx
, WINED3D_LOCATION_TEXTURE_RGB
);
2654 wined3d_texture_invalidate_location(texture
, op
->sub_resource_idx
, ~WINED3D_LOCATION_TEXTURE_RGB
);
2657 context_release(context
);
2659 wined3d_resource_release(resource
);
2662 static void wined3d_cs_update_sub_resource(struct wined3d_device_context
*context
,
2663 struct wined3d_resource
*resource
, unsigned int sub_resource_idx
, const struct wined3d_box
*box
,
2664 const void *data
, unsigned int row_pitch
, unsigned int slice_pitch
)
2666 struct wined3d_cs_update_sub_resource
*op
;
2668 wined3d_resource_wait_idle(resource
);
2670 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_MAP
);
2671 op
->opcode
= WINED3D_CS_OP_UPDATE_SUB_RESOURCE
;
2672 op
->resource
= resource
;
2673 op
->sub_resource_idx
= sub_resource_idx
;
2675 op
->data
.row_pitch
= row_pitch
;
2676 op
->data
.slice_pitch
= slice_pitch
;
2677 op
->data
.data
= data
;
2679 wined3d_device_context_acquire_resource(context
, resource
);
2681 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_MAP
);
2682 /* The data pointer may go away, so we need to wait until it is read.
2683 * Copying the data may be faster if it's small. */
2684 wined3d_device_context_finish(context
, WINED3D_CS_QUEUE_MAP
);
2687 static void wined3d_cs_exec_add_dirty_texture_region(struct wined3d_cs
*cs
, const void *data
)
2689 const struct wined3d_cs_add_dirty_texture_region
*op
= data
;
2690 struct wined3d_texture
*texture
= op
->texture
;
2691 unsigned int sub_resource_idx
, i
;
2692 struct wined3d_context
*context
;
2694 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2695 sub_resource_idx
= op
->layer
* texture
->level_count
;
2696 for (i
= 0; i
< texture
->level_count
; ++i
, ++sub_resource_idx
)
2698 if (wined3d_texture_load_location(texture
, sub_resource_idx
, context
, texture
->resource
.map_binding
))
2699 wined3d_texture_invalidate_location(texture
, sub_resource_idx
, ~texture
->resource
.map_binding
);
2701 ERR("Failed to load location %s.\n", wined3d_debug_location(texture
->resource
.map_binding
));
2703 context_release(context
);
2705 wined3d_resource_release(&texture
->resource
);
2708 void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs
*cs
,
2709 struct wined3d_texture
*texture
, unsigned int layer
)
2711 struct wined3d_cs_add_dirty_texture_region
*op
;
2713 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2714 op
->opcode
= WINED3D_CS_OP_ADD_DIRTY_TEXTURE_REGION
;
2715 op
->texture
= texture
;
2718 wined3d_resource_acquire(&texture
->resource
);
2720 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2723 static void wined3d_cs_exec_clear_unordered_access_view(struct wined3d_cs
*cs
, const void *data
)
2725 const struct wined3d_cs_clear_unordered_access_view
*op
= data
;
2726 struct wined3d_unordered_access_view
*view
= op
->view
;
2727 struct wined3d_context
*context
;
2729 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2730 cs
->c
.device
->adapter
->adapter_ops
->adapter_clear_uav(context
, view
, &op
->clear_value
, op
->fp
);
2731 context_release(context
);
2733 wined3d_resource_release(view
->resource
);
2736 void wined3d_device_context_emit_clear_uav(struct wined3d_device_context
*context
,
2737 struct wined3d_unordered_access_view
*view
, const struct wined3d_uvec4
*clear_value
, bool fp
)
2739 struct wined3d_cs_clear_unordered_access_view
*op
;
2741 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2742 op
->opcode
= WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW
;
2744 op
->clear_value
= *clear_value
;
2747 wined3d_device_context_acquire_resource(context
, view
->resource
);
2749 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2752 static void wined3d_cs_exec_copy_uav_counter(struct wined3d_cs
*cs
, const void *data
)
2754 const struct wined3d_cs_copy_uav_counter
*op
= data
;
2755 struct wined3d_unordered_access_view
*view
= op
->view
;
2756 struct wined3d_context
*context
;
2758 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2759 wined3d_unordered_access_view_copy_counter(view
, op
->buffer
, op
->offset
, context
);
2760 context_release(context
);
2762 wined3d_resource_release(&op
->buffer
->resource
);
2765 void wined3d_device_context_emit_copy_uav_counter(struct wined3d_device_context
*context
,
2766 struct wined3d_buffer
*dst_buffer
, unsigned int offset
, struct wined3d_unordered_access_view
*uav
)
2768 struct wined3d_cs_copy_uav_counter
*op
;
2770 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2771 op
->opcode
= WINED3D_CS_OP_COPY_UAV_COUNTER
;
2772 op
->buffer
= dst_buffer
;
2773 op
->offset
= offset
;
2776 wined3d_device_context_acquire_resource(context
, &dst_buffer
->resource
);
2778 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2781 static void wined3d_cs_exec_generate_mipmaps(struct wined3d_cs
*cs
, const void *data
)
2783 const struct wined3d_cs_generate_mipmaps
*op
= data
;
2784 struct wined3d_shader_resource_view
*view
= op
->view
;
2785 struct wined3d_context
*context
;
2787 context
= context_acquire(cs
->c
.device
, NULL
, 0);
2788 cs
->c
.device
->adapter
->adapter_ops
->adapter_generate_mipmap(context
, view
);
2789 context_release(context
);
2791 wined3d_resource_release(view
->resource
);
2794 void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context
*context
,
2795 struct wined3d_shader_resource_view
*view
)
2797 struct wined3d_cs_generate_mipmaps
*op
;
2799 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2800 op
->opcode
= WINED3D_CS_OP_GENERATE_MIPMAPS
;
2803 wined3d_device_context_acquire_resource(context
, view
->resource
);
2805 wined3d_device_context_submit(context
, WINED3D_CS_QUEUE_DEFAULT
);
2808 static void wined3d_cs_emit_stop(struct wined3d_cs
*cs
)
2810 struct wined3d_cs_stop
*op
;
2812 op
= wined3d_device_context_require_space(&cs
->c
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
2813 op
->opcode
= WINED3D_CS_OP_STOP
;
2815 wined3d_device_context_submit(&cs
->c
, WINED3D_CS_QUEUE_DEFAULT
);
2816 wined3d_cs_finish(cs
, WINED3D_CS_QUEUE_DEFAULT
);
2819 static void wined3d_cs_acquire_resource(struct wined3d_device_context
*context
, struct wined3d_resource
*resource
)
2821 wined3d_resource_acquire(resource
);
2824 static void wined3d_cs_exec_execute_command_list(struct wined3d_cs
*cs
, const void *data
);
2826 static void (* const wined3d_cs_op_handlers
[])(struct wined3d_cs
*cs
, const void *data
) =
2828 /* WINED3D_CS_OP_NOP */ wined3d_cs_exec_nop
,
2829 /* WINED3D_CS_OP_PRESENT */ wined3d_cs_exec_present
,
2830 /* WINED3D_CS_OP_CLEAR */ wined3d_cs_exec_clear
,
2831 /* WINED3D_CS_OP_DISPATCH */ wined3d_cs_exec_dispatch
,
2832 /* WINED3D_CS_OP_DRAW */ wined3d_cs_exec_draw
,
2833 /* WINED3D_CS_OP_FLUSH */ wined3d_cs_exec_flush
,
2834 /* WINED3D_CS_OP_SET_PREDICATION */ wined3d_cs_exec_set_predication
,
2835 /* WINED3D_CS_OP_SET_VIEWPORTS */ wined3d_cs_exec_set_viewports
,
2836 /* WINED3D_CS_OP_SET_SCISSOR_RECTS */ wined3d_cs_exec_set_scissor_rects
,
2837 /* WINED3D_CS_OP_SET_RENDERTARGET_VIEW */ wined3d_cs_exec_set_rendertarget_view
,
2838 /* WINED3D_CS_OP_SET_DEPTH_STENCIL_VIEW */ wined3d_cs_exec_set_depth_stencil_view
,
2839 /* WINED3D_CS_OP_SET_VERTEX_DECLARATION */ wined3d_cs_exec_set_vertex_declaration
,
2840 /* WINED3D_CS_OP_SET_STREAM_SOURCE */ wined3d_cs_exec_set_stream_source
,
2841 /* WINED3D_CS_OP_SET_STREAM_SOURCE_FREQ */ wined3d_cs_exec_set_stream_source_freq
,
2842 /* WINED3D_CS_OP_SET_STREAM_OUTPUT */ wined3d_cs_exec_set_stream_output
,
2843 /* WINED3D_CS_OP_SET_INDEX_BUFFER */ wined3d_cs_exec_set_index_buffer
,
2844 /* WINED3D_CS_OP_SET_CONSTANT_BUFFER */ wined3d_cs_exec_set_constant_buffer
,
2845 /* WINED3D_CS_OP_SET_TEXTURE */ wined3d_cs_exec_set_texture
,
2846 /* WINED3D_CS_OP_SET_SHADER_RESOURCE_VIEW */ wined3d_cs_exec_set_shader_resource_view
,
2847 /* WINED3D_CS_OP_SET_UNORDERED_ACCESS_VIEW */ wined3d_cs_exec_set_unordered_access_view
,
2848 /* WINED3D_CS_OP_SET_SAMPLER */ wined3d_cs_exec_set_sampler
,
2849 /* WINED3D_CS_OP_SET_SHADER */ wined3d_cs_exec_set_shader
,
2850 /* WINED3D_CS_OP_SET_BLEND_STATE */ wined3d_cs_exec_set_blend_state
,
2851 /* WINED3D_CS_OP_SET_DEPTH_STENCIL_STATE */ wined3d_cs_exec_set_depth_stencil_state
,
2852 /* WINED3D_CS_OP_SET_RASTERIZER_STATE */ wined3d_cs_exec_set_rasterizer_state
,
2853 /* WINED3D_CS_OP_SET_RENDER_STATE */ wined3d_cs_exec_set_render_state
,
2854 /* WINED3D_CS_OP_SET_TEXTURE_STATE */ wined3d_cs_exec_set_texture_state
,
2855 /* WINED3D_CS_OP_SET_SAMPLER_STATE */ wined3d_cs_exec_set_sampler_state
,
2856 /* WINED3D_CS_OP_SET_TRANSFORM */ wined3d_cs_exec_set_transform
,
2857 /* WINED3D_CS_OP_SET_CLIP_PLANE */ wined3d_cs_exec_set_clip_plane
,
2858 /* WINED3D_CS_OP_SET_COLOR_KEY */ wined3d_cs_exec_set_color_key
,
2859 /* WINED3D_CS_OP_SET_MATERIAL */ wined3d_cs_exec_set_material
,
2860 /* WINED3D_CS_OP_SET_LIGHT */ wined3d_cs_exec_set_light
,
2861 /* WINED3D_CS_OP_SET_LIGHT_ENABLE */ wined3d_cs_exec_set_light_enable
,
2862 /* WINED3D_CS_OP_SET_FEATURE_LEVEL */ wined3d_cs_exec_set_feature_level
,
2863 /* WINED3D_CS_OP_PUSH_CONSTANTS */ wined3d_cs_exec_push_constants
,
2864 /* WINED3D_CS_OP_RESET_STATE */ wined3d_cs_exec_reset_state
,
2865 /* WINED3D_CS_OP_CALLBACK */ wined3d_cs_exec_callback
,
2866 /* WINED3D_CS_OP_QUERY_ISSUE */ wined3d_cs_exec_query_issue
,
2867 /* WINED3D_CS_OP_PRELOAD_RESOURCE */ wined3d_cs_exec_preload_resource
,
2868 /* WINED3D_CS_OP_UNLOAD_RESOURCE */ wined3d_cs_exec_unload_resource
,
2869 /* WINED3D_CS_OP_MAP */ wined3d_cs_exec_map
,
2870 /* WINED3D_CS_OP_UNMAP */ wined3d_cs_exec_unmap
,
2871 /* WINED3D_CS_OP_BLT_SUB_RESOURCE */ wined3d_cs_exec_blt_sub_resource
,
2872 /* WINED3D_CS_OP_UPDATE_SUB_RESOURCE */ wined3d_cs_exec_update_sub_resource
,
2873 /* WINED3D_CS_OP_ADD_DIRTY_TEXTURE_REGION */ wined3d_cs_exec_add_dirty_texture_region
,
2874 /* WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW */ wined3d_cs_exec_clear_unordered_access_view
,
2875 /* WINED3D_CS_OP_COPY_UAV_COUNTER */ wined3d_cs_exec_copy_uav_counter
,
2876 /* WINED3D_CS_OP_GENERATE_MIPMAPS */ wined3d_cs_exec_generate_mipmaps
,
2877 /* WINED3D_CS_OP_EXECUTE_COMMAND_LIST */ wined3d_cs_exec_execute_command_list
,
2880 static void wined3d_cs_exec_execute_command_list(struct wined3d_cs
*cs
, const void *data
)
2882 const struct wined3d_cs_execute_command_list
*op
= data
;
2883 size_t start
= 0, end
= op
->list
->data_size
;
2884 const BYTE
*cs_data
= op
->list
->data
;
2886 TRACE("Executing command list %p.\n", op
->list
);
2890 const struct wined3d_cs_packet
*packet
= (const struct wined3d_cs_packet
*)&cs_data
[start
];
2891 enum wined3d_cs_op opcode
= *(const enum wined3d_cs_op
*)packet
->data
;
2893 if (opcode
>= WINED3D_CS_OP_STOP
)
2894 ERR("Invalid opcode %#x.\n", opcode
);
2896 wined3d_cs_op_handlers
[opcode
](cs
, packet
->data
);
2897 TRACE("%s executed.\n", debug_cs_op(opcode
));
2899 start
+= offsetof(struct wined3d_cs_packet
, data
[packet
->size
]);
2903 static void *wined3d_cs_st_require_space(struct wined3d_device_context
*context
,
2904 size_t size
, enum wined3d_cs_queue_id queue_id
)
2906 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2908 if (size
> (cs
->data_size
- cs
->end
))
2913 new_size
= max(size
, cs
->data_size
* 2);
2915 new_data
= heap_realloc(cs
->data
, new_size
);
2917 new_data
= heap_alloc(new_size
);
2921 cs
->data_size
= new_size
;
2922 cs
->start
= cs
->end
= 0;
2923 cs
->data
= new_data
;
2928 return (BYTE
*)cs
->data
+ cs
->start
;
2931 static void wined3d_cs_st_submit(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
2933 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2934 enum wined3d_cs_op opcode
;
2940 cs
->start
= cs
->end
;
2942 opcode
= *(const enum wined3d_cs_op
*)&data
[start
];
2943 if (opcode
>= WINED3D_CS_OP_STOP
)
2944 ERR("Invalid opcode %#x.\n", opcode
);
2946 wined3d_cs_op_handlers
[opcode
](cs
, &data
[start
]);
2948 if (cs
->data
== data
)
2949 cs
->start
= cs
->end
= start
;
2954 static void wined3d_cs_st_finish(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
2958 static const struct wined3d_device_context_ops wined3d_cs_st_ops
=
2960 wined3d_cs_st_require_space
,
2961 wined3d_cs_st_submit
,
2962 wined3d_cs_st_finish
,
2963 wined3d_cs_st_push_constants
,
2966 wined3d_cs_update_sub_resource
,
2967 wined3d_cs_issue_query
,
2969 wined3d_cs_acquire_resource
,
2970 wined3d_cs_execute_command_list
,
2973 static BOOL
wined3d_cs_queue_is_empty(const struct wined3d_cs
*cs
, const struct wined3d_cs_queue
*queue
)
2975 wined3d_from_cs(cs
);
2976 return *(volatile LONG
*)&queue
->head
== queue
->tail
;
2979 static void wined3d_cs_queue_submit(struct wined3d_cs_queue
*queue
, struct wined3d_cs
*cs
)
2981 struct wined3d_cs_packet
*packet
;
2984 packet
= (struct wined3d_cs_packet
*)&queue
->data
[queue
->head
];
2985 packet_size
= FIELD_OFFSET(struct wined3d_cs_packet
, data
[packet
->size
]);
2986 InterlockedExchange(&queue
->head
, (queue
->head
+ packet_size
) & (WINED3D_CS_QUEUE_SIZE
- 1));
2988 if (InterlockedCompareExchange(&cs
->waiting_for_event
, FALSE
, TRUE
))
2989 SetEvent(cs
->event
);
2992 static void wined3d_cs_mt_submit(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
2994 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
2996 if (cs
->thread_id
== GetCurrentThreadId())
2997 return wined3d_cs_st_submit(context
, queue_id
);
2999 wined3d_cs_queue_submit(&cs
->queue
[queue_id
], cs
);
3002 static void *wined3d_cs_queue_require_space(struct wined3d_cs_queue
*queue
, size_t size
, struct wined3d_cs
*cs
)
3004 size_t queue_size
= ARRAY_SIZE(queue
->data
);
3005 size_t header_size
, packet_size
, remaining
;
3006 struct wined3d_cs_packet
*packet
;
3008 header_size
= FIELD_OFFSET(struct wined3d_cs_packet
, data
[0]);
3009 packet_size
= FIELD_OFFSET(struct wined3d_cs_packet
, data
[size
]);
3010 packet_size
= (packet_size
+ header_size
- 1) & ~(header_size
- 1);
3011 size
= packet_size
- header_size
;
3012 if (packet_size
>= WINED3D_CS_QUEUE_SIZE
)
3014 ERR("Packet size %lu >= queue size %u.\n",
3015 (unsigned long)packet_size
, WINED3D_CS_QUEUE_SIZE
);
3019 remaining
= queue_size
- queue
->head
;
3020 if (remaining
< packet_size
)
3022 size_t nop_size
= remaining
- header_size
;
3023 struct wined3d_cs_nop
*nop
;
3025 TRACE("Inserting a nop for %lu + %lu bytes.\n",
3026 (unsigned long)header_size
, (unsigned long)nop_size
);
3028 nop
= wined3d_cs_queue_require_space(queue
, nop_size
, cs
);
3030 nop
->opcode
= WINED3D_CS_OP_NOP
;
3032 wined3d_cs_queue_submit(queue
, cs
);
3033 assert(!queue
->head
);
3038 LONG tail
= *(volatile LONG
*)&queue
->tail
;
3039 LONG head
= queue
->head
;
3045 new_pos
= (head
+ packet_size
) & (WINED3D_CS_QUEUE_SIZE
- 1);
3046 /* Head ahead of tail. We checked the remaining size above, so we only
3047 * need to make sure we don't make head equal to tail. */
3048 if (head
> tail
&& (new_pos
!= tail
))
3050 /* Tail ahead of head. Make sure the new head is before the tail as
3051 * well. Note that new_pos is 0 when it's at the end of the queue. */
3052 if (new_pos
< tail
&& new_pos
)
3055 TRACE("Waiting for free space. Head %u, tail %u, packet size %lu.\n",
3056 head
, tail
, (unsigned long)packet_size
);
3059 packet
= (struct wined3d_cs_packet
*)&queue
->data
[queue
->head
];
3060 packet
->size
= size
;
3061 return packet
->data
;
3064 static void *wined3d_cs_mt_require_space(struct wined3d_device_context
*context
,
3065 size_t size
, enum wined3d_cs_queue_id queue_id
)
3067 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
3069 if (cs
->thread_id
== GetCurrentThreadId())
3070 return wined3d_cs_st_require_space(context
, size
, queue_id
);
3072 return wined3d_cs_queue_require_space(&cs
->queue
[queue_id
], size
, cs
);
3075 static void wined3d_cs_mt_finish(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
3077 struct wined3d_cs
*cs
= wined3d_cs_from_context(context
);
3079 if (cs
->thread_id
== GetCurrentThreadId())
3080 return wined3d_cs_st_finish(context
, queue_id
);
3082 while (cs
->queue
[queue_id
].head
!= *(volatile LONG
*)&cs
->queue
[queue_id
].tail
)
3086 static const struct wined3d_device_context_ops wined3d_cs_mt_ops
=
3088 wined3d_cs_mt_require_space
,
3089 wined3d_cs_mt_submit
,
3090 wined3d_cs_mt_finish
,
3091 wined3d_cs_mt_push_constants
,
3094 wined3d_cs_update_sub_resource
,
3095 wined3d_cs_issue_query
,
3097 wined3d_cs_acquire_resource
,
3098 wined3d_cs_execute_command_list
,
3101 static void poll_queries(struct wined3d_cs
*cs
)
3103 struct wined3d_query
*query
, *cursor
;
3105 LIST_FOR_EACH_ENTRY_SAFE(query
, cursor
, &cs
->query_poll_list
, struct wined3d_query
, poll_list_entry
)
3107 if (!query
->query_ops
->query_poll(query
, 0))
3110 list_remove(&query
->poll_list_entry
);
3111 list_init(&query
->poll_list_entry
);
3112 InterlockedIncrement(&query
->counter_retrieved
);
3116 static void wined3d_cs_wait_event(struct wined3d_cs
*cs
)
3118 InterlockedExchange(&cs
->waiting_for_event
, TRUE
);
3120 /* The main thread might have enqueued a command and blocked on it after
3121 * the CS thread decided to enter wined3d_cs_wait_event(), but before
3122 * "waiting_for_event" was set.
3124 * Likewise, we can race with the main thread when resetting
3125 * "waiting_for_event", in which case we would need to call
3126 * WaitForSingleObject() because the main thread called SetEvent(). */
3127 if (!(wined3d_cs_queue_is_empty(cs
, &cs
->queue
[WINED3D_CS_QUEUE_DEFAULT
])
3128 && wined3d_cs_queue_is_empty(cs
, &cs
->queue
[WINED3D_CS_QUEUE_MAP
]))
3129 && InterlockedCompareExchange(&cs
->waiting_for_event
, FALSE
, TRUE
))
3132 WaitForSingleObject(cs
->event
, INFINITE
);
3135 static void wined3d_cs_command_lock(const struct wined3d_cs
*cs
)
3137 if (cs
->serialize_commands
)
3138 EnterCriticalSection(&wined3d_command_cs
);
3141 static void wined3d_cs_command_unlock(const struct wined3d_cs
*cs
)
3143 if (cs
->serialize_commands
)
3144 LeaveCriticalSection(&wined3d_command_cs
);
3147 static DWORD WINAPI
wined3d_cs_run(void *ctx
)
3149 struct wined3d_cs_packet
*packet
;
3150 struct wined3d_cs_queue
*queue
;
3151 unsigned int spin_count
= 0;
3152 struct wined3d_cs
*cs
= ctx
;
3153 enum wined3d_cs_op opcode
;
3154 HMODULE wined3d_module
;
3155 unsigned int poll
= 0;
3158 TRACE("Started.\n");
3160 /* Copy the module handle to a local variable to avoid racing with the
3161 * thread freeing "cs" before the FreeLibraryAndExitThread() call. */
3162 wined3d_module
= cs
->wined3d_module
;
3164 list_init(&cs
->query_poll_list
);
3165 cs
->thread_id
= GetCurrentThreadId();
3168 if (++poll
== WINED3D_CS_QUERY_POLL_INTERVAL
)
3170 wined3d_cs_command_lock(cs
);
3172 wined3d_cs_command_unlock(cs
);
3176 queue
= &cs
->queue
[WINED3D_CS_QUEUE_MAP
];
3177 if (wined3d_cs_queue_is_empty(cs
, queue
))
3179 queue
= &cs
->queue
[WINED3D_CS_QUEUE_DEFAULT
];
3180 if (wined3d_cs_queue_is_empty(cs
, queue
))
3182 if (++spin_count
>= WINED3D_CS_SPIN_COUNT
&& list_empty(&cs
->query_poll_list
))
3183 wined3d_cs_wait_event(cs
);
3190 packet
= (struct wined3d_cs_packet
*)&queue
->data
[tail
];
3193 opcode
= *(const enum wined3d_cs_op
*)packet
->data
;
3195 TRACE("Executing %s.\n", debug_cs_op(opcode
));
3196 if (opcode
>= WINED3D_CS_OP_STOP
)
3198 if (opcode
> WINED3D_CS_OP_STOP
)
3199 ERR("Invalid opcode %#x.\n", opcode
);
3203 wined3d_cs_command_lock(cs
);
3204 wined3d_cs_op_handlers
[opcode
](cs
, packet
->data
);
3205 wined3d_cs_command_unlock(cs
);
3206 TRACE("%s executed.\n", debug_cs_op(opcode
));
3209 tail
+= FIELD_OFFSET(struct wined3d_cs_packet
, data
[packet
->size
]);
3210 tail
&= (WINED3D_CS_QUEUE_SIZE
- 1);
3211 InterlockedExchange(&queue
->tail
, tail
);
3214 cs
->queue
[WINED3D_CS_QUEUE_MAP
].tail
= cs
->queue
[WINED3D_CS_QUEUE_MAP
].head
;
3215 cs
->queue
[WINED3D_CS_QUEUE_DEFAULT
].tail
= cs
->queue
[WINED3D_CS_QUEUE_DEFAULT
].head
;
3216 TRACE("Stopped.\n");
3217 FreeLibraryAndExitThread(wined3d_module
, 0);
3220 struct wined3d_cs
*wined3d_cs_create(struct wined3d_device
*device
,
3221 const enum wined3d_feature_level
*levels
, unsigned int level_count
)
3223 const struct wined3d_d3d_info
*d3d_info
= &device
->adapter
->d3d_info
;
3224 struct wined3d_cs
*cs
;
3226 if (!(cs
= heap_alloc_zero(sizeof(*cs
))))
3229 if (FAILED(wined3d_state_create(device
, levels
, level_count
, &cs
->c
.state
)))
3235 cs
->c
.ops
= &wined3d_cs_st_ops
;
3236 cs
->c
.device
= device
;
3237 cs
->serialize_commands
= TRACE_ON(d3d_sync
) || wined3d_settings
.cs_multithreaded
& WINED3D_CSMT_SERIALIZE
;
3239 state_init(&cs
->state
, d3d_info
, WINED3D_STATE_NO_REF
| WINED3D_STATE_INIT_DEFAULT
, cs
->c
.state
->feature_level
);
3241 cs
->data_size
= WINED3D_INITIAL_CS_SIZE
;
3242 if (!(cs
->data
= heap_alloc(cs
->data_size
)))
3245 if (wined3d_settings
.cs_multithreaded
& WINED3D_CSMT_ENABLE
3246 && !RtlIsCriticalSectionLockedByThread(NtCurrentTeb()->Peb
->LoaderLock
))
3248 cs
->c
.ops
= &wined3d_cs_mt_ops
;
3250 if (!(cs
->event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
)))
3252 ERR("Failed to create command stream event.\n");
3253 heap_free(cs
->data
);
3257 if (!(GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
,
3258 (const WCHAR
*)wined3d_cs_run
, &cs
->wined3d_module
)))
3260 ERR("Failed to get wined3d module handle.\n");
3261 CloseHandle(cs
->event
);
3262 heap_free(cs
->data
);
3266 if (!(cs
->thread
= CreateThread(NULL
, 0, wined3d_cs_run
, cs
, 0, NULL
)))
3268 ERR("Failed to create wined3d command stream thread.\n");
3269 FreeLibrary(cs
->wined3d_module
);
3270 CloseHandle(cs
->event
);
3271 heap_free(cs
->data
);
3279 wined3d_state_destroy(cs
->c
.state
);
3280 state_cleanup(&cs
->state
);
3285 void wined3d_cs_destroy(struct wined3d_cs
*cs
)
3289 wined3d_cs_emit_stop(cs
);
3290 CloseHandle(cs
->thread
);
3291 if (!CloseHandle(cs
->event
))
3292 ERR("Closing event failed.\n");
3295 wined3d_state_destroy(cs
->c
.state
);
3296 state_cleanup(&cs
->state
);
3297 heap_free(cs
->data
);
3301 struct wined3d_deferred_context
3303 struct wined3d_device_context c
;
3305 SIZE_T data_size
, data_capacity
;
3308 SIZE_T resource_count
, resources_capacity
;
3309 struct wined3d_resource
**resources
;
3311 /* List of command lists queued for execution on this context. A command
3312 * list can be the only thing holding a pointer to another command list, so
3313 * we need to hold a reference here and in wined3d_command_list as well. */
3314 SIZE_T command_list_count
, command_lists_capacity
;
3315 struct wined3d_command_list
**command_lists
;
3318 static struct wined3d_deferred_context
*wined3d_deferred_context_from_context(struct wined3d_device_context
*context
)
3320 return CONTAINING_RECORD(context
, struct wined3d_deferred_context
, c
);
3323 static void *wined3d_deferred_context_require_space(struct wined3d_device_context
*context
,
3324 size_t size
, enum wined3d_cs_queue_id queue_id
)
3326 struct wined3d_deferred_context
*deferred
= wined3d_deferred_context_from_context(context
);
3327 struct wined3d_cs_packet
*packet
;
3328 size_t header_size
, packet_size
;
3330 assert(queue_id
== WINED3D_CS_QUEUE_DEFAULT
);
3332 header_size
= offsetof(struct wined3d_cs_packet
, data
[0]);
3333 packet_size
= offsetof(struct wined3d_cs_packet
, data
[size
]);
3334 packet_size
= (packet_size
+ header_size
- 1) & ~(header_size
- 1);
3336 if (!wined3d_array_reserve(&deferred
->data
, &deferred
->data_capacity
, deferred
->data_size
+ packet_size
, 1))
3339 packet
= (struct wined3d_cs_packet
*)((BYTE
*)deferred
->data
+ deferred
->data_size
);
3340 TRACE("size was %zu, adding %zu\n", (size_t)deferred
->data_size
, packet_size
);
3341 deferred
->data_size
+= packet_size
;
3342 packet
->size
= packet_size
- header_size
;
3343 return &packet
->data
;
3346 static void wined3d_deferred_context_submit(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
3348 assert(queue_id
== WINED3D_CS_QUEUE_DEFAULT
);
3350 /* Nothing to do. */
3353 static void wined3d_deferred_context_finish(struct wined3d_device_context
*context
, enum wined3d_cs_queue_id queue_id
)
3355 /* This should not happen; we cannot meaningfully finish a deferred context. */
3356 ERR("Ignoring finish() on a deferred context.\n");
3359 static void wined3d_deferred_context_push_constants(struct wined3d_device_context
*context
,
3360 enum wined3d_push_constants p
, unsigned int start_idx
, unsigned int count
, const void *constants
)
3362 FIXME("context %p, p %#x, start_idx %u, count %u, constants %p, stub!\n", context
, p
, start_idx
, count
, constants
);
3365 static HRESULT
wined3d_deferred_context_map(struct wined3d_device_context
*context
, struct wined3d_resource
*resource
,
3366 unsigned int sub_resource_idx
, void **map_ptr
, const struct wined3d_box
*box
, unsigned int flags
)
3368 FIXME("context %p, resource %p, sub_resource_idx %u, map_ptr %p, box %p, flags %#x, stub!\n",
3369 context
, resource
, sub_resource_idx
, map_ptr
, box
, flags
);
3373 static HRESULT
wined3d_deferred_context_unmap(struct wined3d_device_context
*context
,
3374 struct wined3d_resource
*resource
, unsigned int sub_resource_idx
)
3376 FIXME("context %p, resource %p, sub_resource_idx %u, stub!\n", context
, resource
, sub_resource_idx
);
3380 static void wined3d_deferred_context_update_sub_resource(struct wined3d_device_context
*context
,
3381 struct wined3d_resource
*resource
, unsigned int sub_resource_idx
, const struct wined3d_box
*box
,
3382 const void *data
, unsigned int row_pitch
, unsigned int slice_pitch
)
3384 FIXME("context %p, resource %p, sub_resource_idx %u, box %s, data %p, row_pitch %u, slice_pitch %u, stub!\n",
3385 context
, resource
, sub_resource_idx
, debug_box(box
), data
, row_pitch
, slice_pitch
);
3388 static void wined3d_deferred_context_issue_query(struct wined3d_device_context
*context
,
3389 struct wined3d_query
*query
, unsigned int flags
)
3391 FIXME("context %p, query %p, flags %#x, stub!\n", context
, query
, flags
);
3394 static void wined3d_deferred_context_flush(struct wined3d_device_context
*context
)
3396 FIXME("context %p, stub!\n", context
);
3399 static void wined3d_deferred_context_acquire_resource(struct wined3d_device_context
*context
,
3400 struct wined3d_resource
*resource
)
3402 struct wined3d_deferred_context
*deferred
= wined3d_deferred_context_from_context(context
);
3404 if (!wined3d_array_reserve((void **)&deferred
->resources
, &deferred
->resources_capacity
,
3405 deferred
->resource_count
+ 1, sizeof(*deferred
->resources
)))
3408 deferred
->resources
[deferred
->resource_count
++] = resource
;
3409 wined3d_resource_incref(resource
);
3412 static void wined3d_deferred_context_execute_command_list(struct wined3d_device_context
*context
,
3413 struct wined3d_command_list
*list
, bool restore_state
)
3415 struct wined3d_deferred_context
*deferred
= wined3d_deferred_context_from_context(context
);
3416 struct wined3d_cs_execute_command_list
*op
;
3418 op
= wined3d_device_context_require_space(context
, sizeof(*op
), WINED3D_CS_QUEUE_DEFAULT
);
3419 op
->opcode
= WINED3D_CS_OP_EXECUTE_COMMAND_LIST
;
3423 wined3d_device_context_set_state(context
, context
->state
);
3425 wined3d_device_context_reset_state(context
);
3427 /* Grab a reference to the command list. Note that this implicitly prevents
3428 * any dependent command lists or resources from being freed as well. */
3429 if (!wined3d_array_reserve((void **)&deferred
->command_lists
, &deferred
->command_lists_capacity
,
3430 deferred
->command_list_count
+ 1, sizeof(*deferred
->command_lists
)))
3433 wined3d_command_list_incref(deferred
->command_lists
[deferred
->command_list_count
++] = list
);
3436 static const struct wined3d_device_context_ops wined3d_deferred_context_ops
=
3438 wined3d_deferred_context_require_space
,
3439 wined3d_deferred_context_submit
,
3440 wined3d_deferred_context_finish
,
3441 wined3d_deferred_context_push_constants
,
3442 wined3d_deferred_context_map
,
3443 wined3d_deferred_context_unmap
,
3444 wined3d_deferred_context_update_sub_resource
,
3445 wined3d_deferred_context_issue_query
,
3446 wined3d_deferred_context_flush
,
3447 wined3d_deferred_context_acquire_resource
,
3448 wined3d_deferred_context_execute_command_list
,
3451 HRESULT CDECL
wined3d_deferred_context_create(struct wined3d_device
*device
, struct wined3d_device_context
**context
)
3453 struct wined3d_deferred_context
*object
;
3456 TRACE("device %p, context %p.\n", device
, context
);
3458 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3459 return E_OUTOFMEMORY
;
3461 if (FAILED(hr
= wined3d_state_create(device
, &device
->cs
->c
.state
->feature_level
, 1, &object
->c
.state
)))
3467 object
->c
.ops
= &wined3d_deferred_context_ops
;
3468 object
->c
.device
= device
;
3470 TRACE("Created deferred context %p.\n", object
);
3471 *context
= &object
->c
;
3476 void CDECL
wined3d_deferred_context_destroy(struct wined3d_device_context
*context
)
3478 struct wined3d_deferred_context
*deferred
= wined3d_deferred_context_from_context(context
);
3481 TRACE("context %p.\n", context
);
3483 for (i
= 0; i
< deferred
->resource_count
; ++i
)
3484 wined3d_resource_decref(deferred
->resources
[i
]);
3485 heap_free(deferred
->resources
);
3487 wined3d_state_destroy(deferred
->c
.state
);
3488 heap_free(deferred
->data
);
3489 heap_free(deferred
);
3492 HRESULT CDECL
wined3d_deferred_context_record_command_list(struct wined3d_device_context
*context
,
3493 bool restore
, struct wined3d_command_list
**list
)
3495 struct wined3d_deferred_context
*deferred
= wined3d_deferred_context_from_context(context
);
3496 struct wined3d_command_list
*object
;
3498 TRACE("context %p, list %p.\n", context
, list
);
3500 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3501 return E_OUTOFMEMORY
;
3503 object
->refcount
= 1;
3504 object
->device
= deferred
->c
.device
;
3506 if (!(object
->data
= heap_alloc(deferred
->data_size
)))
3509 return E_OUTOFMEMORY
;
3511 object
->data_size
= deferred
->data_size
;
3512 memcpy(object
->data
, deferred
->data
, deferred
->data_size
);
3514 if (!(object
->resources
= heap_alloc(deferred
->resource_count
* sizeof(*object
->resources
))))
3516 heap_free(object
->data
);
3518 return E_OUTOFMEMORY
;
3520 object
->resource_count
= deferred
->resource_count
;
3521 memcpy(object
->resources
, deferred
->resources
, deferred
->resource_count
* sizeof(*object
->resources
));
3522 /* Transfer our references to the resources to the command list. */
3524 if (!(object
->command_lists
= heap_alloc(deferred
->command_list_count
* sizeof(*object
->command_lists
))))
3526 heap_free(object
->resources
);
3527 heap_free(object
->data
);
3529 return E_OUTOFMEMORY
;
3531 object
->command_list_count
= deferred
->command_list_count
;
3532 memcpy(object
->command_lists
, deferred
->command_lists
,
3533 deferred
->command_list_count
* sizeof(*object
->command_lists
));
3534 /* Transfer our references to the command lists to the command list. */
3536 deferred
->data_size
= 0;
3537 deferred
->resource_count
= 0;
3538 deferred
->command_list_count
= 0;
3540 /* This is in fact recorded into a subsequent command list. */
3542 wined3d_device_context_set_state(&deferred
->c
, deferred
->c
.state
);
3544 wined3d_device_context_reset_state(&deferred
->c
);
3546 TRACE("Created command list %p.\n", object
);