wined3d: Move struct wined3d_swapchain_gl to wined3d_gl.h.
[wine.git] / dlls / wined3d / wined3d_private.h
blobc81327832236d355ab024e269c2e534c7523eb47
1 /*
2 * Direct3D wine internal private include file
4 * Copyright 2002-2003 The wine-d3d team
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2002-2003, 2004 Jason Edmeades
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006-2011, 2013 Stefan Dösinger for CodeWeavers
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #ifndef __WINE_WINED3D_PRIVATE_H
26 #define __WINE_WINED3D_PRIVATE_H
28 #include <assert.h>
29 #include <stdarg.h>
30 #include <stdbool.h>
31 #include <sys/types.h>
32 #include <math.h>
33 #include <limits.h>
34 #include <float.h>
35 #define LIBVKD3D_SHADER_SOURCE
36 #include <vkd3d_shader.h>
37 #include "ntstatus.h"
38 #define WIN32_NO_STATUS
39 #define COBJMACROS
40 #include "windef.h"
41 #include "winbase.h"
42 #include "winreg.h"
43 #include "wingdi.h"
44 #include "winuser.h"
45 #include "winternl.h"
46 #include "ddk/d3dkmthk.h"
47 #include "wine/debug.h"
48 #include "wine/heap.h"
50 #include "objbase.h"
51 #include "wine/wined3d.h"
52 #include "wine/list.h"
53 #include "wine/rbtree.h"
55 static inline size_t align(size_t addr, size_t alignment)
57 return (addr + (alignment - 1)) & ~(alignment - 1);
60 static inline float int_to_float(uint32_t i)
62 union
64 uint32_t u;
65 float f;
66 } u;
68 u.u = i;
69 return u.f;
72 static inline const char *wined3d_get_line(const char **ptr, const char *end)
74 const char *p, *q;
76 if ((p = *ptr) >= end)
77 return NULL;
79 if (!(q = memchr(p, '\n', end - p)))
80 *ptr = end;
81 else
82 *ptr = q + 1;
83 return p;
86 #define MAKEDWORD_VERSION(maj, min) (((maj & 0xffffu) << 16) | (min & 0xffffu))
88 #define WINED3D_MAX_DIRTY_REGION_COUNT 7
90 #define WINED3D_ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A','2','M','1')
91 #define WINED3D_ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A','2','M','0')
93 #define WINED3D_BITMAP_SIZE(x) (((x) + 31) >> 5)
95 struct wined3d_fragment_pipe_ops;
96 struct wined3d_adapter;
97 struct wined3d_context;
98 struct wined3d_gl_info;
99 struct wined3d_state;
100 struct wined3d_vertex_pipe_ops;
102 enum wined3d_ffp_idx
104 WINED3D_FFP_POSITION = 0,
105 WINED3D_FFP_BLENDWEIGHT = 1,
106 WINED3D_FFP_BLENDINDICES = 2,
107 WINED3D_FFP_NORMAL = 3,
108 WINED3D_FFP_PSIZE = 4,
109 WINED3D_FFP_DIFFUSE = 5,
110 WINED3D_FFP_SPECULAR = 6,
111 WINED3D_FFP_TEXCOORD0 = 7,
112 WINED3D_FFP_TEXCOORD1 = 8,
113 WINED3D_FFP_TEXCOORD2 = 9,
114 WINED3D_FFP_TEXCOORD3 = 10,
115 WINED3D_FFP_TEXCOORD4 = 11,
116 WINED3D_FFP_TEXCOORD5 = 12,
117 WINED3D_FFP_TEXCOORD6 = 13,
118 WINED3D_FFP_TEXCOORD7 = 14,
119 WINED3D_FFP_ATTRIBS_COUNT = 15,
122 enum wined3d_ffp_emit_idx
124 WINED3D_FFP_EMIT_FLOAT1,
125 WINED3D_FFP_EMIT_FLOAT2,
126 WINED3D_FFP_EMIT_FLOAT3,
127 WINED3D_FFP_EMIT_FLOAT4,
128 WINED3D_FFP_EMIT_D3DCOLOR,
129 WINED3D_FFP_EMIT_UBYTE4,
130 WINED3D_FFP_EMIT_SHORT2,
131 WINED3D_FFP_EMIT_SHORT4,
132 WINED3D_FFP_EMIT_UBYTE4N,
133 WINED3D_FFP_EMIT_SHORT2N,
134 WINED3D_FFP_EMIT_SHORT4N,
135 WINED3D_FFP_EMIT_USHORT2N,
136 WINED3D_FFP_EMIT_USHORT4N,
137 WINED3D_FFP_EMIT_UDEC3,
138 WINED3D_FFP_EMIT_DEC3N,
139 WINED3D_FFP_EMIT_FLOAT16_2,
140 WINED3D_FFP_EMIT_FLOAT16_4,
141 WINED3D_FFP_EMIT_INVALID,
142 WINED3D_FFP_EMIT_COUNT,
145 /* Texture format fixups */
147 enum fixup_channel_source
149 CHANNEL_SOURCE_ZERO = 0,
150 CHANNEL_SOURCE_ONE = 1,
151 CHANNEL_SOURCE_X = 2,
152 CHANNEL_SOURCE_Y = 3,
153 CHANNEL_SOURCE_Z = 4,
154 CHANNEL_SOURCE_W = 5,
155 CHANNEL_SOURCE_COMPLEX0 = 6,
156 CHANNEL_SOURCE_COMPLEX1 = 7,
159 enum complex_fixup
161 COMPLEX_FIXUP_NONE = 0,
162 COMPLEX_FIXUP_YUY2 = 1,
163 COMPLEX_FIXUP_UYVY = 2,
164 COMPLEX_FIXUP_YV12 = 3,
165 COMPLEX_FIXUP_P8 = 4,
166 COMPLEX_FIXUP_NV12 = 5,
167 COMPLEX_FIXUP_YUV = 6,
170 #include <pshpack2.h>
171 struct color_fixup_desc
173 unsigned short x_sign_fixup : 1;
174 unsigned short x_source : 3;
175 unsigned short y_sign_fixup : 1;
176 unsigned short y_source : 3;
177 unsigned short z_sign_fixup : 1;
178 unsigned short z_source : 3;
179 unsigned short w_sign_fixup : 1;
180 unsigned short w_source : 3;
182 #include <poppack.h>
184 struct wined3d_d3d_limits
186 unsigned int vs_version, hs_version, ds_version, gs_version, ps_version, cs_version;
187 DWORD vs_uniform_count;
188 DWORD ps_uniform_count;
189 unsigned int varying_count;
190 unsigned int ffp_textures;
191 unsigned int ffp_blend_stages;
192 unsigned int ffp_vertex_blend_matrices;
193 unsigned int active_light_count;
195 unsigned int max_rt_count;
196 unsigned int max_clip_distances;
197 unsigned int texture_size;
198 unsigned int sample_count;
199 float pointsize_max;
202 struct wined3d_d3d_info
204 struct wined3d_d3d_limits limits;
205 uint32_t wined3d_creation_flags;
206 uint32_t xyzrhw : 1;
207 uint32_t emulated_flatshading : 1;
208 uint32_t ffp_generic_attributes : 1;
209 uint32_t ffp_alpha_test : 1;
210 uint32_t vs_clipping : 1;
211 uint32_t shader_color_key : 1;
212 uint32_t shader_double_precision : 1;
213 uint32_t shader_output_interpolation : 1;
214 uint32_t frag_coord_correction : 1;
215 uint32_t viewport_array_index_any_shader : 1;
216 uint32_t texture_npot : 1;
217 uint32_t texture_npot_conditional : 1;
218 uint32_t normalized_texrect : 1;
219 uint32_t draw_base_vertex_offset : 1;
220 uint32_t vertex_bgra : 1;
221 uint32_t texture_swizzle : 1;
222 uint32_t srgb_read_control : 1;
223 uint32_t srgb_write_control : 1;
224 uint32_t clip_control : 1;
225 uint32_t full_ffp_varyings : 1;
226 uint32_t scaled_resolve : 1;
227 uint32_t pbo : 1;
228 uint32_t subpixel_viewport : 1;
229 uint32_t fences : 1;
230 uint32_t persistent_map : 1;
231 enum wined3d_feature_level feature_level;
233 DWORD multisample_draw_location;
235 float filling_convention_offset;
238 static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
239 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
241 static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
243 struct color_fixup_desc fixup =
245 0u, complex_fixup & (1u << 0) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
246 0u, complex_fixup & (1u << 1) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
247 0u, complex_fixup & (1u << 2) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
248 0u, complex_fixup & (1u << 3) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
250 return fixup;
253 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
255 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
258 static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
260 return fixup.x_source == CHANNEL_SOURCE_COMPLEX0 || fixup.x_source == CHANNEL_SOURCE_COMPLEX1;
263 static inline BOOL is_scaling_fixup(struct color_fixup_desc fixup)
265 return fixup.x_sign_fixup || fixup.y_sign_fixup || fixup.z_sign_fixup || fixup.w_sign_fixup;
268 static inline BOOL is_same_fixup(struct color_fixup_desc f1, struct color_fixup_desc f2)
270 return f1.x_sign_fixup == f2.x_sign_fixup && f1.x_source == f2.x_source
271 && f1.y_sign_fixup == f2.y_sign_fixup && f1.y_source == f2.y_source
272 && f1.z_sign_fixup == f2.z_sign_fixup && f1.z_source == f2.z_source
273 && f1.w_sign_fixup == f2.w_sign_fixup && f1.w_source == f2.w_source;
276 static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
278 enum complex_fixup complex_fixup = 0;
279 if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 0);
280 if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 1);
281 if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 2);
282 if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 3);
283 return complex_fixup;
286 /* Device caps */
287 #define WINED3D_MAX_ACTIVE_LIGHTS 8
288 #define WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS 32
289 #define MAX_CONSTANT_BUFFERS 15
290 #define MAX_SAMPLER_OBJECTS 16
291 #define MAX_SHADER_RESOURCE_VIEWS 128
292 #define MAX_UNORDERED_ACCESS_VIEWS 8
293 #define MAX_TGSM_REGISTERS 8192
294 #define MAX_VERTEX_BLENDS 4
296 static const uint32_t WINED3D_READ_ONLY_BIND_MASK = WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER
297 | WINED3D_BIND_CONSTANT_BUFFER | WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_INDIRECT_BUFFER;
299 static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func)
301 if (func < WINED3D_CMP_NEVER || func > WINED3D_CMP_ALWAYS)
302 return WINED3D_CMP_ALWAYS;
303 return func;
306 /* float_16_to_32() and float_32_to_16() convert 16 bit floats in the
307 * FLOAT16 data type to standard C floats and vice versa. They do not
308 * depend on the encoding of the C float, so they are platform independent,
309 * but slow. On x86 and other IEEE 754 compliant platforms the conversion
310 * can be accelerated by bit shifting the exponent and mantissa. There are
311 * also some SSE-based assembly routines out there.
313 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
315 static inline float float_16_to_32(const unsigned short *in)
317 const unsigned short s = ((*in) & 0x8000u);
318 const unsigned short e = ((*in) & 0x7c00u) >> 10;
319 const unsigned short m = (*in) & 0x3ffu;
320 const float sgn = (s ? -1.0f : 1.0f);
322 if(e == 0) {
323 if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
324 else return sgn * powf(2, -14.0f) * ((float)m / 1024.0f);
325 } else if(e < 31) {
326 return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
327 } else {
328 if(m == 0) return sgn * INFINITY;
329 else return NAN;
333 static inline float float_24_to_32(DWORD in)
335 const float sgn = in & 0x800000u ? -1.0f : 1.0f;
336 const unsigned short e = (in & 0x780000u) >> 19;
337 const unsigned int m = in & 0x7ffffu;
339 if (e == 0)
341 if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
342 else return sgn * powf(2, -6.0f) * ((float)m / 524288.0f);
344 else if (e < 15)
346 return sgn * powf(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
348 else
350 if (m == 0) return sgn * INFINITY;
351 else return NAN;
355 static inline unsigned short float_32_to_16(const float *in)
357 int exp = 0;
358 float tmp = fabsf(*in);
359 unsigned int mantissa;
360 unsigned short ret;
362 /* Deal with special numbers */
363 if (*in == 0.0f)
364 return 0x0000;
365 if (isnan(*in))
366 return 0x7c01;
367 if (isinf(*in))
368 return (*in < 0.0f ? 0xfc00 : 0x7c00);
370 if (tmp < (float)(1u << 10))
374 tmp = tmp * 2.0f;
375 exp--;
376 } while (tmp < (float)(1u << 10));
378 else if (tmp >= (float)(1u << 11))
382 tmp /= 2.0f;
383 exp++;
384 } while (tmp >= (float)(1u << 11));
387 mantissa = (unsigned int)tmp;
388 if (tmp - mantissa >= 0.5f)
389 ++mantissa; /* Round to nearest, away from zero. */
391 exp += 10; /* Normalize the mantissa. */
392 exp += 15; /* Exponent is encoded with excess 15. */
394 if (exp > 30) /* too big */
396 ret = 0x7c00; /* INF */
398 else if (exp <= 0)
400 /* exp == 0: Non-normalized mantissa. Returns 0x0000 (=0.0) for too small numbers. */
401 while (exp <= 0)
403 mantissa = mantissa >> 1;
404 ++exp;
406 ret = mantissa & 0x3ff;
408 else
410 ret = (exp << 10) | (mantissa & 0x3ff);
413 ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
414 return ret;
417 static inline unsigned int wined3d_popcount(unsigned int x)
419 #if defined(__MINGW32__)
420 return __builtin_popcount(x);
421 #else
422 x -= x >> 1 & 0x55555555;
423 x = (x & 0x33333333) + (x >> 2 & 0x33333333);
424 return ((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
425 #endif
428 static inline int wined3d_uint32_compare(uint32_t x, uint32_t y)
430 return (x > y) - (x < y);
433 static inline int wined3d_uint64_compare(uint64_t x, uint64_t y)
435 return (x > y) - (x < y);
438 #define ORM_BACKBUFFER 0
439 #define ORM_FBO 1
441 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
442 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
444 enum wined3d_shader_backend
446 WINED3D_SHADER_BACKEND_AUTO,
447 WINED3D_SHADER_BACKEND_GLSL,
448 WINED3D_SHADER_BACKEND_ARB,
449 WINED3D_SHADER_BACKEND_NONE,
452 #define WINED3D_CSMT_ENABLE 0x00000001
453 #define WINED3D_CSMT_SERIALIZE 0x00000002
455 /* NOTE: When adding fields to this structure, make sure to update the default
456 * values in wined3d_main.c as well. */
457 struct wined3d_settings
459 unsigned int cs_multithreaded;
460 unsigned int max_gl_version;
461 int offscreen_rendering_mode;
462 unsigned short pci_vendor_id;
463 unsigned short pci_device_id;
464 /* Memory tracking and object counting. */
465 UINT64 emulated_textureram;
466 char *logo;
467 unsigned int multisample_textures;
468 unsigned int sample_count;
469 BOOL check_float_constants;
470 unsigned int strict_shader_math;
471 unsigned int max_sm_vs;
472 unsigned int max_sm_hs;
473 unsigned int max_sm_ds;
474 unsigned int max_sm_gs;
475 unsigned int max_sm_ps;
476 unsigned int max_sm_cs;
477 enum wined3d_renderer renderer;
478 enum wined3d_shader_backend shader_backend;
479 BOOL cb_access_map_w;
482 extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
484 enum wined3d_shader_resource_type
486 WINED3D_SHADER_RESOURCE_NONE,
487 WINED3D_SHADER_RESOURCE_BUFFER,
488 WINED3D_SHADER_RESOURCE_TEXTURE_1D,
489 WINED3D_SHADER_RESOURCE_TEXTURE_2D,
490 WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
491 WINED3D_SHADER_RESOURCE_TEXTURE_3D,
492 WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
493 WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
494 WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
495 WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
496 WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY,
499 #define WINED3D_SHADER_CONST_VS_F 0x00000001
500 #define WINED3D_SHADER_CONST_VS_I 0x00000002
501 #define WINED3D_SHADER_CONST_VS_B 0x00000004
502 #define WINED3D_SHADER_CONST_VS_CLIP_PLANES 0x00000008
503 #define WINED3D_SHADER_CONST_VS_POINTSIZE 0x00000010
504 #define WINED3D_SHADER_CONST_POS_FIXUP 0x00000020
505 #define WINED3D_SHADER_CONST_PS_F 0x00000040
506 #define WINED3D_SHADER_CONST_PS_I 0x00000080
507 #define WINED3D_SHADER_CONST_PS_B 0x00000100
508 #define WINED3D_SHADER_CONST_PS_BUMP_ENV 0x00000200
509 #define WINED3D_SHADER_CONST_PS_FOG 0x00000400
510 #define WINED3D_SHADER_CONST_PS_ALPHA_TEST 0x00000800
511 #define WINED3D_SHADER_CONST_PS_Y_CORR 0x00001000
512 #define WINED3D_SHADER_CONST_PS_NP2_FIXUP 0x00002000
513 #define WINED3D_SHADER_CONST_FFP_MODELVIEW 0x00004000
514 #define WINED3D_SHADER_CONST_FFP_VERTEXBLEND 0x00008000
515 #define WINED3D_SHADER_CONST_FFP_PROJ 0x00010000
516 #define WINED3D_SHADER_CONST_FFP_TEXMATRIX 0x00020000
517 #define WINED3D_SHADER_CONST_FFP_MATERIAL 0x00040000
518 #define WINED3D_SHADER_CONST_FFP_LIGHTS 0x00080000
519 #define WINED3D_SHADER_CONST_FFP_PS 0x00100000
520 #define WINED3D_SHADER_CONST_FFP_COLOR_KEY 0x00200000
521 #define WINED3D_SHADER_CONST_BASE_VERTEX_ID 0x00400000
523 enum wined3d_shader_register_type
525 WINED3DSPR_TEMP = 0,
526 WINED3DSPR_INPUT = 1,
527 WINED3DSPR_CONST = 2,
528 WINED3DSPR_ADDR = 3,
529 WINED3DSPR_TEXTURE = 3,
530 WINED3DSPR_RASTOUT = 4,
531 WINED3DSPR_ATTROUT = 5,
532 WINED3DSPR_TEXCRDOUT = 6,
533 WINED3DSPR_OUTPUT = 6,
534 WINED3DSPR_CONSTINT = 7,
535 WINED3DSPR_COLOROUT = 8,
536 WINED3DSPR_DEPTHOUT = 9,
537 WINED3DSPR_SAMPLER = 10,
538 WINED3DSPR_CONST2 = 11,
539 WINED3DSPR_CONST3 = 12,
540 WINED3DSPR_CONST4 = 13,
541 WINED3DSPR_CONSTBOOL = 14,
542 WINED3DSPR_LOOP = 15,
543 WINED3DSPR_TEMPFLOAT16 = 16,
544 WINED3DSPR_MISCTYPE = 17,
545 WINED3DSPR_LABEL = 18,
546 WINED3DSPR_PREDICATE = 19,
547 WINED3DSPR_IMMCONST,
548 WINED3DSPR_CONSTBUFFER,
549 WINED3DSPR_IMMCONSTBUFFER,
550 WINED3DSPR_PRIMID,
551 WINED3DSPR_NULL,
552 WINED3DSPR_RESOURCE,
553 WINED3DSPR_UAV,
554 WINED3DSPR_OUTPOINTID,
555 WINED3DSPR_FORKINSTID,
556 WINED3DSPR_JOININSTID,
557 WINED3DSPR_INCONTROLPOINT,
558 WINED3DSPR_OUTCONTROLPOINT,
559 WINED3DSPR_PATCHCONST,
560 WINED3DSPR_TESSCOORD,
561 WINED3DSPR_GROUPSHAREDMEM,
562 WINED3DSPR_THREADID,
563 WINED3DSPR_THREADGROUPID,
564 WINED3DSPR_LOCALTHREADID,
565 WINED3DSPR_LOCALTHREADINDEX,
566 WINED3DSPR_IDXTEMP,
567 WINED3DSPR_STREAM,
568 WINED3DSPR_FUNCTIONBODY,
569 WINED3DSPR_FUNCTIONPOINTER,
570 WINED3DSPR_COVERAGE,
571 WINED3DSPR_SAMPLEMASK,
572 WINED3DSPR_GSINSTID,
573 WINED3DSPR_DEPTHOUTGE,
574 WINED3DSPR_DEPTHOUTLE,
575 WINED3DSPR_RASTERIZER,
578 enum wined3d_data_type
580 WINED3D_DATA_FLOAT,
581 WINED3D_DATA_INT,
582 WINED3D_DATA_RESOURCE,
583 WINED3D_DATA_SAMPLER,
584 WINED3D_DATA_UAV,
585 WINED3D_DATA_UINT,
586 WINED3D_DATA_UNORM,
587 WINED3D_DATA_SNORM,
588 WINED3D_DATA_OPAQUE,
591 enum wined3d_immconst_type
593 WINED3D_IMMCONST_SCALAR,
594 WINED3D_IMMCONST_VEC4,
597 #define WINED3DSP_NOSWIZZLE (0u | (1u << 2) | (2u << 4) | (3u << 6))
599 enum wined3d_shader_src_modifier
601 WINED3DSPSM_NONE = 0,
602 WINED3DSPSM_NEG = 1,
603 WINED3DSPSM_BIAS = 2,
604 WINED3DSPSM_BIASNEG = 3,
605 WINED3DSPSM_SIGN = 4,
606 WINED3DSPSM_SIGNNEG = 5,
607 WINED3DSPSM_COMP = 6,
608 WINED3DSPSM_X2 = 7,
609 WINED3DSPSM_X2NEG = 8,
610 WINED3DSPSM_DZ = 9,
611 WINED3DSPSM_DW = 10,
612 WINED3DSPSM_ABS = 11,
613 WINED3DSPSM_ABSNEG = 12,
614 WINED3DSPSM_NOT = 13,
617 #define WINED3DSP_WRITEMASK_0 0x1u /* .x r */
618 #define WINED3DSP_WRITEMASK_1 0x2u /* .y g */
619 #define WINED3DSP_WRITEMASK_2 0x4u /* .z b */
620 #define WINED3DSP_WRITEMASK_3 0x8u /* .w a */
621 #define WINED3DSP_WRITEMASK_ALL 0xfu /* all */
623 enum wined3d_shader_dst_modifier
625 WINED3DSPDM_NONE = 0,
626 WINED3DSPDM_SATURATE = 1,
627 WINED3DSPDM_PARTIALPRECISION = 2,
628 WINED3DSPDM_MSAMPCENTROID = 4,
631 enum wined3d_shader_interpolation_mode
633 WINED3DSIM_NONE = 0,
634 WINED3DSIM_CONSTANT = 1,
635 WINED3DSIM_LINEAR = 2,
636 WINED3DSIM_LINEAR_CENTROID = 3,
637 WINED3DSIM_LINEAR_NOPERSPECTIVE = 4,
638 WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID = 5,
639 WINED3DSIM_LINEAR_SAMPLE = 6,
640 WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
643 #define WINED3D_PACKED_INTERPOLATION_SIZE 3
644 #define WINED3D_PACKED_INTERPOLATION_BIT_COUNT 3
646 enum wined3d_shader_global_flags
648 WINED3DSGF_REFACTORING_ALLOWED = 0x1,
649 WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL = 0x4,
650 WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS = 0x8,
653 enum wined3d_shader_sync_flags
655 WINED3DSSF_THREAD_GROUP = 0x1,
656 WINED3DSSF_GROUP_SHARED_MEMORY = 0x2,
657 WINED3DSSF_GLOBAL_UAV = 0x8,
660 enum wined3d_shader_uav_flags
662 WINED3DSUF_GLOBALLY_COHERENT = 0x2,
663 WINED3DSUF_ORDER_PRESERVING_COUNTER = 0x100,
666 enum wined3d_tessellator_domain
668 WINED3D_TESSELLATOR_DOMAIN_LINE = 1,
669 WINED3D_TESSELLATOR_DOMAIN_TRIANGLE = 2,
670 WINED3D_TESSELLATOR_DOMAIN_QUAD = 3,
673 enum wined3d_tessellator_output_primitive
675 WINED3D_TESSELLATOR_OUTPUT_POINT = 1,
676 WINED3D_TESSELLATOR_OUTPUT_LINE = 2,
677 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
678 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4,
681 enum wined3d_tessellator_partitioning
683 WINED3D_TESSELLATOR_PARTITIONING_INTEGER = 1,
684 WINED3D_TESSELLATOR_PARTITIONING_POW2 = 2,
685 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
686 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4,
689 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
690 #define WINED3DSI_TEXLD_PROJECT 0x1
691 #define WINED3DSI_TEXLD_BIAS 0x2
692 #define WINED3DSI_INDEXED_DYNAMIC 0x4
693 #define WINED3DSI_RESINFO_RCP_FLOAT 0x1
694 #define WINED3DSI_RESINFO_UINT 0x2
695 #define WINED3DSI_SAMPLE_INFO_UINT 0x1
696 #define WINED3DSI_SAMPLER_COMPARISON_MODE 0x1
698 #define WINED3DSI_PRECISE_X 0x100
699 #define WINED3DSI_PRECISE_Y 0x200
700 #define WINED3DSI_PRECISE_Z 0x400
701 #define WINED3DSI_PRECISE_W 0x800
702 #define WINED3DSI_PRECISE_XYZW (WINED3DSI_PRECISE_X | WINED3DSI_PRECISE_Y \
703 | WINED3DSI_PRECISE_Z | WINED3DSI_PRECISE_W)
704 #define WINED3DSI_PRECISE_SHIFT 8
706 enum wined3d_shader_rel_op
708 WINED3D_SHADER_REL_OP_GT = 1,
709 WINED3D_SHADER_REL_OP_EQ = 2,
710 WINED3D_SHADER_REL_OP_GE = 3,
711 WINED3D_SHADER_REL_OP_LT = 4,
712 WINED3D_SHADER_REL_OP_NE = 5,
713 WINED3D_SHADER_REL_OP_LE = 6,
716 enum wined3d_shader_conditional_op
718 WINED3D_SHADER_CONDITIONAL_OP_NZ = 0,
719 WINED3D_SHADER_CONDITIONAL_OP_Z = 1
722 enum wined3d_sysval_semantic
724 WINED3D_SV_POSITION = 0x01,
725 WINED3D_SV_CLIP_DISTANCE = 0x02,
726 WINED3D_SV_CULL_DISTANCE = 0x03,
727 WINED3D_SV_RENDER_TARGET_ARRAY_INDEX = 0x04,
728 WINED3D_SV_VIEWPORT_ARRAY_INDEX = 0x05,
729 WINED3D_SV_VERTEX_ID = 0x06,
730 WINED3D_SV_PRIMITIVE_ID = 0x07,
731 WINED3D_SV_INSTANCE_ID = 0x08,
732 WINED3D_SV_IS_FRONT_FACE = 0x09,
733 WINED3D_SV_SAMPLE_INDEX = 0x0a,
734 WINED3D_SV_TESS_FACTOR_QUADEDGE = 0x0b,
735 WINED3D_SV_TESS_FACTOR_QUADINT = 0x0c,
736 WINED3D_SV_TESS_FACTOR_TRIEDGE = 0x0d,
737 WINED3D_SV_TESS_FACTOR_TRIINT = 0x0e,
738 WINED3D_SV_TESS_FACTOR_LINEDET = 0x0f,
739 WINED3D_SV_TESS_FACTOR_LINEDEN = 0x10,
742 enum wined3d_component_type
744 WINED3D_TYPE_UNKNOWN = 0x0,
745 WINED3D_TYPE_UINT = 0x1,
746 WINED3D_TYPE_INT = 0x2,
747 WINED3D_TYPE_FLOAT = 0x3,
750 struct wined3d_shader_signature_element
752 const char *semantic_name;
753 unsigned int semantic_idx;
754 unsigned int stream_idx;
755 enum wined3d_sysval_semantic sysval_semantic;
756 enum wined3d_component_type component_type;
757 unsigned int register_idx;
758 uint32_t mask;
759 unsigned int min_precision;
762 struct wined3d_shader_signature
764 unsigned int element_count;
765 struct wined3d_shader_signature_element *elements;
768 #define WINED3D_SM1_VS 0xfffeu
769 #define WINED3D_SM1_PS 0xffffu
770 #define WINED3D_SM4_PS 0x0000u
771 #define WINED3D_SM4_VS 0x0001u
772 #define WINED3D_SM4_GS 0x0002u
773 #define WINED3D_SM5_HS 0x0003u
774 #define WINED3D_SM5_DS 0x0004u
775 #define WINED3D_SM5_CS 0x0005u
777 /* Shader version tokens, and shader end tokens */
778 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
779 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
781 /* Shader backends */
783 #define MAX_ATTRIBS 32
784 #define MAX_REG_ADDR 1
785 #define MAX_REG_TEXCRD 8
786 #define MAX_REG_INPUT 32
787 #define MAX_REG_OUTPUT 32
788 #define WINED3D_MAX_CBS 15
790 /* FIXME: This needs to go up to 2048 for
791 * Shader model 3 according to msdn (and for software shaders) */
792 #define MAX_LABELS 16
794 #define MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE 4096
796 struct wined3d_string_buffer
798 struct list entry;
799 char *buffer;
800 unsigned int buffer_size;
801 unsigned int content_size;
804 enum WINED3D_SHADER_INSTRUCTION_HANDLER
806 WINED3DSIH_ABS,
807 WINED3DSIH_ADD,
808 WINED3DSIH_AND,
809 WINED3DSIH_ATOMIC_AND,
810 WINED3DSIH_ATOMIC_CMP_STORE,
811 WINED3DSIH_ATOMIC_IADD,
812 WINED3DSIH_ATOMIC_IMAX,
813 WINED3DSIH_ATOMIC_IMIN,
814 WINED3DSIH_ATOMIC_OR,
815 WINED3DSIH_ATOMIC_UMAX,
816 WINED3DSIH_ATOMIC_UMIN,
817 WINED3DSIH_ATOMIC_XOR,
818 WINED3DSIH_BEM,
819 WINED3DSIH_BFI,
820 WINED3DSIH_BFREV,
821 WINED3DSIH_BREAK,
822 WINED3DSIH_BREAKC,
823 WINED3DSIH_BREAKP,
824 WINED3DSIH_BUFINFO,
825 WINED3DSIH_CALL,
826 WINED3DSIH_CALLNZ,
827 WINED3DSIH_CASE,
828 WINED3DSIH_CMP,
829 WINED3DSIH_CND,
830 WINED3DSIH_CONTINUE,
831 WINED3DSIH_CONTINUEP,
832 WINED3DSIH_COUNTBITS,
833 WINED3DSIH_CRS,
834 WINED3DSIH_CUT,
835 WINED3DSIH_CUT_STREAM,
836 WINED3DSIH_DCL,
837 WINED3DSIH_DCL_CONSTANT_BUFFER,
838 WINED3DSIH_DCL_FUNCTION_BODY,
839 WINED3DSIH_DCL_FUNCTION_TABLE,
840 WINED3DSIH_DCL_GLOBAL_FLAGS,
841 WINED3DSIH_DCL_GS_INSTANCES,
842 WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT,
843 WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT,
844 WINED3DSIH_DCL_HS_MAX_TESSFACTOR,
845 WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER,
846 WINED3DSIH_DCL_INDEX_RANGE,
847 WINED3DSIH_DCL_INDEXABLE_TEMP,
848 WINED3DSIH_DCL_INPUT,
849 WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT,
850 WINED3DSIH_DCL_INPUT_PRIMITIVE,
851 WINED3DSIH_DCL_INPUT_PS,
852 WINED3DSIH_DCL_INPUT_PS_SGV,
853 WINED3DSIH_DCL_INPUT_PS_SIV,
854 WINED3DSIH_DCL_INPUT_SGV,
855 WINED3DSIH_DCL_INPUT_SIV,
856 WINED3DSIH_DCL_INTERFACE,
857 WINED3DSIH_DCL_OUTPUT,
858 WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT,
859 WINED3DSIH_DCL_OUTPUT_SIV,
860 WINED3DSIH_DCL_OUTPUT_TOPOLOGY,
861 WINED3DSIH_DCL_RESOURCE_RAW,
862 WINED3DSIH_DCL_RESOURCE_STRUCTURED,
863 WINED3DSIH_DCL_SAMPLER,
864 WINED3DSIH_DCL_STREAM,
865 WINED3DSIH_DCL_TEMPS,
866 WINED3DSIH_DCL_TESSELLATOR_DOMAIN,
867 WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE,
868 WINED3DSIH_DCL_TESSELLATOR_PARTITIONING,
869 WINED3DSIH_DCL_TGSM_RAW,
870 WINED3DSIH_DCL_TGSM_STRUCTURED,
871 WINED3DSIH_DCL_THREAD_GROUP,
872 WINED3DSIH_DCL_UAV_RAW,
873 WINED3DSIH_DCL_UAV_STRUCTURED,
874 WINED3DSIH_DCL_UAV_TYPED,
875 WINED3DSIH_DCL_VERTICES_OUT,
876 WINED3DSIH_DEF,
877 WINED3DSIH_DEFAULT,
878 WINED3DSIH_DEFB,
879 WINED3DSIH_DEFI,
880 WINED3DSIH_DIV,
881 WINED3DSIH_DP2,
882 WINED3DSIH_DP2ADD,
883 WINED3DSIH_DP3,
884 WINED3DSIH_DP4,
885 WINED3DSIH_DST,
886 WINED3DSIH_DSX,
887 WINED3DSIH_DSX_COARSE,
888 WINED3DSIH_DSX_FINE,
889 WINED3DSIH_DSY,
890 WINED3DSIH_DSY_COARSE,
891 WINED3DSIH_DSY_FINE,
892 WINED3DSIH_ELSE,
893 WINED3DSIH_EMIT,
894 WINED3DSIH_EMIT_STREAM,
895 WINED3DSIH_ENDIF,
896 WINED3DSIH_ENDLOOP,
897 WINED3DSIH_ENDREP,
898 WINED3DSIH_ENDSWITCH,
899 WINED3DSIH_EQ,
900 WINED3DSIH_EVAL_CENTROID,
901 WINED3DSIH_EVAL_SAMPLE_INDEX,
902 WINED3DSIH_EXP,
903 WINED3DSIH_EXPP,
904 WINED3DSIH_F16TOF32,
905 WINED3DSIH_F32TOF16,
906 WINED3DSIH_FCALL,
907 WINED3DSIH_FIRSTBIT_HI,
908 WINED3DSIH_FIRSTBIT_LO,
909 WINED3DSIH_FIRSTBIT_SHI,
910 WINED3DSIH_FRC,
911 WINED3DSIH_FTOI,
912 WINED3DSIH_FTOU,
913 WINED3DSIH_GATHER4,
914 WINED3DSIH_GATHER4_C,
915 WINED3DSIH_GATHER4_PO,
916 WINED3DSIH_GATHER4_PO_C,
917 WINED3DSIH_GE,
918 WINED3DSIH_HS_CONTROL_POINT_PHASE,
919 WINED3DSIH_HS_DECLS,
920 WINED3DSIH_HS_FORK_PHASE,
921 WINED3DSIH_HS_JOIN_PHASE,
922 WINED3DSIH_IADD,
923 WINED3DSIH_IBFE,
924 WINED3DSIH_IEQ,
925 WINED3DSIH_IF,
926 WINED3DSIH_IFC,
927 WINED3DSIH_IGE,
928 WINED3DSIH_ILT,
929 WINED3DSIH_IMAD,
930 WINED3DSIH_IMAX,
931 WINED3DSIH_IMIN,
932 WINED3DSIH_IMM_ATOMIC_ALLOC,
933 WINED3DSIH_IMM_ATOMIC_AND,
934 WINED3DSIH_IMM_ATOMIC_CMP_EXCH,
935 WINED3DSIH_IMM_ATOMIC_CONSUME,
936 WINED3DSIH_IMM_ATOMIC_EXCH,
937 WINED3DSIH_IMM_ATOMIC_IADD,
938 WINED3DSIH_IMM_ATOMIC_IMAX,
939 WINED3DSIH_IMM_ATOMIC_IMIN,
940 WINED3DSIH_IMM_ATOMIC_OR,
941 WINED3DSIH_IMM_ATOMIC_UMAX,
942 WINED3DSIH_IMM_ATOMIC_UMIN,
943 WINED3DSIH_IMM_ATOMIC_XOR,
944 WINED3DSIH_IMUL,
945 WINED3DSIH_INE,
946 WINED3DSIH_INEG,
947 WINED3DSIH_ISHL,
948 WINED3DSIH_ISHR,
949 WINED3DSIH_ITOF,
950 WINED3DSIH_LABEL,
951 WINED3DSIH_LD,
952 WINED3DSIH_LD2DMS,
953 WINED3DSIH_LD_RAW,
954 WINED3DSIH_LD_STRUCTURED,
955 WINED3DSIH_LD_UAV_TYPED,
956 WINED3DSIH_LIT,
957 WINED3DSIH_LOD,
958 WINED3DSIH_LOG,
959 WINED3DSIH_LOGP,
960 WINED3DSIH_LOOP,
961 WINED3DSIH_LRP,
962 WINED3DSIH_LT,
963 WINED3DSIH_M3x2,
964 WINED3DSIH_M3x3,
965 WINED3DSIH_M3x4,
966 WINED3DSIH_M4x3,
967 WINED3DSIH_M4x4,
968 WINED3DSIH_MAD,
969 WINED3DSIH_MAX,
970 WINED3DSIH_MIN,
971 WINED3DSIH_MOV,
972 WINED3DSIH_MOVA,
973 WINED3DSIH_MOVC,
974 WINED3DSIH_MUL,
975 WINED3DSIH_NE,
976 WINED3DSIH_NOP,
977 WINED3DSIH_NOT,
978 WINED3DSIH_NRM,
979 WINED3DSIH_OR,
980 WINED3DSIH_PHASE,
981 WINED3DSIH_POW,
982 WINED3DSIH_RCP,
983 WINED3DSIH_REP,
984 WINED3DSIH_RESINFO,
985 WINED3DSIH_RET,
986 WINED3DSIH_RETP,
987 WINED3DSIH_ROUND_NE,
988 WINED3DSIH_ROUND_NI,
989 WINED3DSIH_ROUND_PI,
990 WINED3DSIH_ROUND_Z,
991 WINED3DSIH_RSQ,
992 WINED3DSIH_SAMPLE,
993 WINED3DSIH_SAMPLE_B,
994 WINED3DSIH_SAMPLE_C,
995 WINED3DSIH_SAMPLE_C_LZ,
996 WINED3DSIH_SAMPLE_GRAD,
997 WINED3DSIH_SAMPLE_INFO,
998 WINED3DSIH_SAMPLE_LOD,
999 WINED3DSIH_SAMPLE_POS,
1000 WINED3DSIH_SETP,
1001 WINED3DSIH_SGE,
1002 WINED3DSIH_SGN,
1003 WINED3DSIH_SINCOS,
1004 WINED3DSIH_SLT,
1005 WINED3DSIH_SQRT,
1006 WINED3DSIH_STORE_RAW,
1007 WINED3DSIH_STORE_STRUCTURED,
1008 WINED3DSIH_STORE_UAV_TYPED,
1009 WINED3DSIH_SUB,
1010 WINED3DSIH_SWAPC,
1011 WINED3DSIH_SWITCH,
1012 WINED3DSIH_SYNC,
1013 WINED3DSIH_TEX,
1014 WINED3DSIH_TEXBEM,
1015 WINED3DSIH_TEXBEML,
1016 WINED3DSIH_TEXCOORD,
1017 WINED3DSIH_TEXDEPTH,
1018 WINED3DSIH_TEXDP3,
1019 WINED3DSIH_TEXDP3TEX,
1020 WINED3DSIH_TEXKILL,
1021 WINED3DSIH_TEXLDD,
1022 WINED3DSIH_TEXLDL,
1023 WINED3DSIH_TEXM3x2DEPTH,
1024 WINED3DSIH_TEXM3x2PAD,
1025 WINED3DSIH_TEXM3x2TEX,
1026 WINED3DSIH_TEXM3x3,
1027 WINED3DSIH_TEXM3x3DIFF,
1028 WINED3DSIH_TEXM3x3PAD,
1029 WINED3DSIH_TEXM3x3SPEC,
1030 WINED3DSIH_TEXM3x3TEX,
1031 WINED3DSIH_TEXM3x3VSPEC,
1032 WINED3DSIH_TEXREG2AR,
1033 WINED3DSIH_TEXREG2GB,
1034 WINED3DSIH_TEXREG2RGB,
1035 WINED3DSIH_UBFE,
1036 WINED3DSIH_UDIV,
1037 WINED3DSIH_UGE,
1038 WINED3DSIH_ULT,
1039 WINED3DSIH_UMAX,
1040 WINED3DSIH_UMIN,
1041 WINED3DSIH_UMUL,
1042 WINED3DSIH_USHR,
1043 WINED3DSIH_UTOF,
1044 WINED3DSIH_XOR,
1045 WINED3DSIH_TABLE_SIZE
1048 struct wined3d_shader_version
1050 enum wined3d_shader_type type;
1051 BYTE major;
1052 BYTE minor;
1055 struct wined3d_shader_resource_info
1057 enum wined3d_shader_resource_type type;
1058 enum wined3d_data_type data_type;
1059 unsigned int flags;
1060 unsigned int stride;
1063 #define WINED3D_SAMPLER_DEFAULT ~0x0u
1065 struct wined3d_shader_sampler_map_entry
1067 unsigned int resource_idx;
1068 unsigned int sampler_idx;
1069 unsigned int bind_idx;
1072 struct wined3d_shader_sampler_map
1074 struct wined3d_shader_sampler_map_entry *entries;
1075 size_t size;
1076 size_t count;
1079 struct wined3d_shader_immediate_constant_buffer
1081 unsigned int vec4_count;
1082 uint32_t data[MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE];
1085 struct wined3d_shader_indexable_temp
1087 struct list entry;
1088 unsigned int register_idx;
1089 unsigned int register_size;
1090 unsigned int component_count;
1093 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
1095 struct wined3d_shader_reg_maps
1097 struct wined3d_shader_version shader_version;
1098 BYTE texcoord; /* MAX_REG_TEXCRD, 8 */
1099 BYTE address; /* MAX_REG_ADDR, 1 */
1100 WORD labels; /* MAX_LABELS, 16 */
1101 DWORD temporary; /* 32 */
1102 unsigned int temporary_count;
1103 uint32_t *constf; /* pixel, vertex */
1104 struct list indexable_temps;
1105 const struct wined3d_shader_immediate_constant_buffer *icb;
1106 union
1108 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
1109 BYTE output_registers_mask[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1110 } u;
1111 DWORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 32 */
1112 DWORD output_registers; /* MAX_REG_OUTPUT, 32 */
1113 WORD integer_constants; /* WINED3D_MAX_CONSTS_I, 16 */
1114 WORD boolean_constants; /* WINED3D_MAX_CONSTS_B, 16 */
1115 WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */
1116 WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */
1117 UINT cb_sizes[WINED3D_MAX_CBS];
1118 uint32_t cb_map; /* WINED3D_MAX_CBS, 15 */
1120 struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS];
1121 uint32_t resource_map[WINED3D_BITMAP_SIZE(MAX_SHADER_RESOURCE_VIEWS)];
1122 struct wined3d_shader_sampler_map sampler_map;
1123 DWORD sampler_comparison_mode;
1124 BYTE bumpmat; /* WINED3D_MAX_TEXTURES, 8 */
1125 BYTE luminanceparams; /* WINED3D_MAX_TEXTURES, 8 */
1126 struct wined3d_shader_resource_info uav_resource_info[MAX_UNORDERED_ACCESS_VIEWS];
1127 DWORD uav_read_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1128 DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1130 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1131 DWORD cull_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1132 DWORD usesnrm : 1;
1133 DWORD vpos : 1;
1134 DWORD usesdsx : 1;
1135 DWORD usesdsy : 1;
1136 DWORD usestexldd : 1;
1137 DWORD usesmova : 1;
1138 DWORD usesfacing : 1;
1139 DWORD usesrelconstF : 1;
1140 DWORD fog : 1;
1141 DWORD usestexldl : 1;
1142 DWORD usesifc : 1;
1143 DWORD usescall : 1;
1144 DWORD usespow : 1;
1145 DWORD point_size : 1;
1146 DWORD vocp : 1;
1147 DWORD input_rel_addressing : 1;
1148 DWORD viewport_array : 1;
1149 DWORD sample_mask : 1;
1150 DWORD padding : 14;
1152 DWORD rt_mask; /* Used render targets, 32 max. */
1154 /* Whether or not loops are used in this shader, and nesting depth */
1155 unsigned int loop_depth;
1156 unsigned int min_rel_offset, max_rel_offset;
1158 struct wined3d_shader_tgsm *tgsm;
1159 SIZE_T tgsm_capacity;
1160 unsigned int tgsm_count;
1163 /* Keeps track of details for TEX_M#x# instructions which need to maintain
1164 * state information between multiple instructions. */
1165 struct wined3d_shader_tex_mx
1167 unsigned int current_row;
1168 unsigned int texcoord_w[2];
1171 struct wined3d_shader_parser_state
1173 unsigned int current_loop_depth;
1174 unsigned int current_loop_reg;
1175 BOOL in_subroutine;
1178 struct wined3d_shader_context
1180 const struct wined3d_shader *shader;
1181 const struct wined3d_shader_reg_maps *reg_maps;
1182 struct wined3d_string_buffer *buffer;
1183 struct wined3d_shader_tex_mx *tex_mx;
1184 struct wined3d_shader_parser_state *state;
1185 void *backend_data;
1188 struct wined3d_shader_register_index
1190 const struct wined3d_shader_src_param *rel_addr;
1191 unsigned int offset;
1194 struct wined3d_shader_register
1196 enum wined3d_shader_register_type type;
1197 enum wined3d_data_type data_type;
1198 struct wined3d_shader_register_index idx[2];
1199 enum wined3d_immconst_type immconst_type;
1200 union
1202 unsigned int immconst_data[4];
1203 unsigned fp_body_idx;
1204 } u;
1207 struct wined3d_shader_dst_param
1209 struct wined3d_shader_register reg;
1210 uint32_t write_mask;
1211 uint32_t modifiers;
1212 unsigned int shift;
1215 struct wined3d_shader_src_param
1217 struct wined3d_shader_register reg;
1218 DWORD swizzle;
1219 enum wined3d_shader_src_modifier modifiers;
1222 struct wined3d_shader_index_range
1224 struct wined3d_shader_dst_param first_register;
1225 unsigned int last_register;
1228 struct wined3d_shader_semantic
1230 enum wined3d_decl_usage usage;
1231 UINT usage_idx;
1232 enum wined3d_shader_resource_type resource_type;
1233 unsigned int sample_count;
1234 enum wined3d_data_type resource_data_type;
1235 struct wined3d_shader_dst_param reg;
1238 enum wined3d_shader_input_sysval_semantic
1240 WINED3D_SIV_POSITION = 1,
1241 WINED3D_SIV_CLIP_DISTANCE = 2,
1242 WINED3D_SIV_CULL_DISTANCE = 3,
1243 WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX = 4,
1244 WINED3D_SIV_VIEWPORT_ARRAY_INDEX = 5,
1245 WINED3D_SIV_VERTEX_ID = 6,
1246 WINED3D_SIV_PRIMITIVE_ID = 7,
1247 WINED3D_SIV_INSTANCE_ID = 8,
1248 WINED3D_SIV_IS_FRONT_FACE = 9,
1249 WINED3D_SIV_SAMPLE_INDEX = 10,
1250 WINED3D_SIV_QUAD_U0_TESS_FACTOR = 11,
1251 WINED3D_SIV_QUAD_V0_TESS_FACTOR = 12,
1252 WINED3D_SIV_QUAD_U1_TESS_FACTOR = 13,
1253 WINED3D_SIV_QUAD_V1_TESS_FACTOR = 14,
1254 WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR = 15,
1255 WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR = 16,
1256 WINED3D_SIV_TRIANGLE_U_TESS_FACTOR = 17,
1257 WINED3D_SIV_TRIANGLE_V_TESS_FACTOR = 18,
1258 WINED3D_SIV_TRIANGLE_W_TESS_FACTOR = 19,
1259 WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR = 20,
1260 WINED3D_SIV_LINE_DETAIL_TESS_FACTOR = 21,
1261 WINED3D_SIV_LINE_DENSITY_TESS_FACTOR = 22,
1264 struct wined3d_shader_register_semantic
1266 struct wined3d_shader_dst_param reg;
1267 enum wined3d_shader_input_sysval_semantic sysval_semantic;
1270 struct wined3d_shader_structured_resource
1272 struct wined3d_shader_dst_param reg;
1273 unsigned int byte_stride;
1276 struct wined3d_shader_tgsm
1278 unsigned int size;
1279 unsigned int stride;
1282 struct wined3d_shader_tgsm_raw
1284 struct wined3d_shader_dst_param reg;
1285 unsigned int byte_count;
1288 struct wined3d_shader_tgsm_structured
1290 struct wined3d_shader_dst_param reg;
1291 unsigned int byte_stride;
1292 unsigned int structure_count;
1295 struct wined3d_shader_thread_group_size
1297 unsigned int x, y, z;
1300 struct wined3d_shader_function_table_pointer
1302 unsigned int index;
1303 unsigned int array_size;
1304 unsigned int body_count;
1305 unsigned int table_count;
1308 struct wined3d_shader_texel_offset
1310 signed char u, v, w;
1313 struct wined3d_shader_primitive_type
1315 enum wined3d_primitive_type type;
1316 unsigned int patch_vertex_count;
1319 struct wined3d_shader_instruction
1321 const struct wined3d_shader_context *ctx;
1322 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
1323 uint32_t flags;
1324 unsigned int dst_count;
1325 unsigned int src_count;
1326 const struct wined3d_shader_dst_param *dst;
1327 const struct wined3d_shader_src_param *src;
1328 struct wined3d_shader_texel_offset texel_offset;
1329 enum wined3d_shader_resource_type resource_type;
1330 enum wined3d_data_type resource_data_type;
1331 BOOL coissue;
1332 const struct wined3d_shader_src_param *predicate;
1333 union
1335 struct wined3d_shader_semantic semantic;
1336 struct wined3d_shader_register_semantic register_semantic;
1337 struct wined3d_shader_primitive_type primitive_type;
1338 struct wined3d_shader_dst_param dst;
1339 struct wined3d_shader_src_param src;
1340 unsigned int count;
1341 unsigned int index;
1342 const struct wined3d_shader_immediate_constant_buffer *icb;
1343 struct wined3d_shader_structured_resource structured_resource;
1344 struct wined3d_shader_tgsm_raw tgsm_raw;
1345 struct wined3d_shader_tgsm_structured tgsm_structured;
1346 struct wined3d_shader_thread_group_size thread_group_size;
1347 enum wined3d_tessellator_domain tessellator_domain;
1348 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1349 enum wined3d_tessellator_partitioning tessellator_partitioning;
1350 float max_tessellation_factor;
1351 struct wined3d_shader_index_range index_range;
1352 struct wined3d_shader_indexable_temp indexable_temp;
1353 struct wined3d_shader_function_table_pointer fp;
1354 } declaration;
1357 static inline BOOL wined3d_shader_instruction_has_texel_offset(const struct wined3d_shader_instruction *ins)
1359 return ins->texel_offset.u || ins->texel_offset.v || ins->texel_offset.w;
1362 struct wined3d_shader_attribute
1364 enum wined3d_decl_usage usage;
1365 UINT usage_idx;
1368 struct wined3d_shader_loop_control
1370 unsigned int count;
1371 unsigned int start;
1372 int step;
1375 struct wined3d_shader_frontend
1377 void *(*shader_init)(const DWORD *byte_code, size_t byte_code_size,
1378 const struct wined3d_shader_signature *output_signature);
1379 void (*shader_free)(void *data);
1380 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
1381 void (*shader_read_instruction)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins);
1382 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
1385 extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
1386 extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
1388 HRESULT wined3d_shader_extract_from_dxbc(struct wined3d_shader *shader,
1389 unsigned int max_shader_version, enum vkd3d_shader_source_type *source_type) DECLSPEC_HIDDEN;
1390 BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader,
1391 const struct wined3d_stream_output_element *so_element, unsigned int *register_idx,
1392 unsigned int *component_idx) DECLSPEC_HIDDEN;
1394 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
1396 #define WINED3D_SHADER_CAP_VS_CLIPPING 0x00000001u
1397 #define WINED3D_SHADER_CAP_SRGB_WRITE 0x00000002u
1398 #define WINED3D_SHADER_CAP_DOUBLE_PRECISION 0x00000004u
1399 #define WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION 0x00000008u
1400 #define WINED3D_SHADER_CAP_FULL_FFP_VARYINGS 0x00000010u
1402 struct shader_caps
1404 unsigned int vs_version;
1405 unsigned int hs_version;
1406 unsigned int ds_version;
1407 unsigned int gs_version;
1408 unsigned int ps_version;
1409 unsigned int cs_version;
1411 unsigned int vs_uniform_count;
1412 unsigned int ps_uniform_count;
1413 float ps_1x_max_value;
1414 unsigned int varying_count;
1416 DWORD wined3d_caps;
1419 enum wined3d_gl_resource_type
1421 WINED3D_GL_RES_TYPE_TEX_1D = 0,
1422 WINED3D_GL_RES_TYPE_TEX_2D = 1,
1423 WINED3D_GL_RES_TYPE_TEX_3D = 2,
1424 WINED3D_GL_RES_TYPE_TEX_CUBE = 3,
1425 WINED3D_GL_RES_TYPE_TEX_RECT = 4,
1426 WINED3D_GL_RES_TYPE_BUFFER = 5,
1427 WINED3D_GL_RES_TYPE_RB = 6,
1428 WINED3D_GL_RES_TYPE_COUNT = 7,
1431 enum wined3d_vertex_processing_mode
1433 WINED3D_VP_MODE_FF,
1434 WINED3D_VP_MODE_SHADER,
1435 WINED3D_VP_MODE_NONE,
1438 #define WINED3D_CONST_NUM_UNUSED ~0U
1440 enum wined3d_ffp_ps_fog_mode
1442 WINED3D_FFP_PS_FOG_OFF,
1443 WINED3D_FFP_PS_FOG_LINEAR,
1444 WINED3D_FFP_PS_FOG_EXP,
1445 WINED3D_FFP_PS_FOG_EXP2,
1448 /* Stateblock dependent parameters which have to be hardcoded
1449 * into the shader code
1452 #define WINED3D_PSARGS_PROJECTED (1u << 3)
1453 #define WINED3D_PSARGS_TEXTRANSFORM_SHIFT 4
1454 #define WINED3D_PSARGS_TEXTRANSFORM_MASK 0xfu
1455 #define WINED3D_PSARGS_TEXTYPE_SHIFT 2
1456 #define WINED3D_PSARGS_TEXTYPE_MASK 0x3u
1458 /* Used for Shader Model 1 pixel shaders to track the bound texture
1459 * type. 2D and RECT textures are separated through NP2 fixup. */
1460 enum wined3d_shader_tex_types
1462 WINED3D_SHADER_TEX_2D = 0,
1463 WINED3D_SHADER_TEX_3D = 1,
1464 WINED3D_SHADER_TEX_CUBE = 2,
1465 WINED3D_SHADER_TEX_ERR = 3,
1468 struct ps_compile_args
1470 struct color_fixup_desc color_fixup[WINED3D_MAX_FRAGMENT_SAMPLERS];
1471 enum wined3d_vertex_processing_mode vp_mode;
1472 enum wined3d_ffp_ps_fog_mode fog;
1473 DWORD tex_types; /* ps 1 - 3, 16 textures */
1474 WORD tex_transform; /* ps 1.0-1.3, 4 textures */
1475 WORD srgb_correction;
1476 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
1477 D3D9 has a limit of 16 samplers and the fixup is superfluous
1478 in D3D10 (unconditional NP2 support mandatory). */
1479 WORD np2_fixup;
1480 WORD shadow; /* WINED3D_MAX_FRAGMENT_SAMPLERS, 16 */
1481 WORD texcoords_initialized; /* WINED3D_MAX_TEXTURES, 8 */
1482 WORD padding_to_dword;
1483 DWORD pointsprite : 1;
1484 DWORD flatshading : 1;
1485 DWORD alpha_test_func : 3;
1486 DWORD y_correction : 1;
1487 DWORD rt_alpha_swizzle : 8; /* WINED3D_MAX_RENDER_TARGETS, 8 */
1488 DWORD dual_source_blend : 1;
1489 DWORD padding : 17;
1492 enum fog_src_type
1494 VS_FOG_Z = 0,
1495 VS_FOG_COORD = 1
1498 struct vs_compile_args
1500 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1501 unsigned int next_shader_input_count;
1502 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1503 BYTE fog_src;
1504 BYTE clip_enabled : 1;
1505 BYTE point_size : 1;
1506 BYTE per_vertex_point_size : 1;
1507 BYTE flatshading : 1;
1508 BYTE next_shader_type : 3;
1509 BYTE padding : 1;
1512 struct ds_compile_args
1514 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1515 enum wined3d_tessellator_partitioning tessellator_partitioning;
1516 unsigned int output_count : 16;
1517 unsigned int next_shader_type : 3;
1518 unsigned int render_offscreen : 1;
1519 unsigned int padding : 12;
1520 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1523 struct gs_compile_args
1525 unsigned int output_count;
1526 enum wined3d_primitive_type primitive_type;
1527 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1530 struct wined3d_shader_backend_ops
1532 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
1533 void (*shader_precompile)(void *shader_priv, struct wined3d_shader *shader);
1534 void (*shader_select)(void *shader_priv, struct wined3d_context *context,
1535 const struct wined3d_state *state);
1536 void (*shader_select_compute)(void *shader_priv, struct wined3d_context *context,
1537 const struct wined3d_state *state);
1538 void (*shader_disable)(void *shader_priv, struct wined3d_context *context);
1539 void (*shader_update_float_vertex_constants)(struct wined3d_device *device, UINT start, UINT count);
1540 void (*shader_update_float_pixel_constants)(struct wined3d_device *device, UINT start, UINT count);
1541 void (*shader_load_constants)(void *shader_priv, struct wined3d_context *context,
1542 const struct wined3d_state *state);
1543 void (*shader_destroy)(struct wined3d_shader *shader);
1544 HRESULT (*shader_alloc_private)(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
1545 const struct wined3d_fragment_pipe_ops *fragment_pipe);
1546 void (*shader_free_private)(struct wined3d_device *device, struct wined3d_context *context);
1547 BOOL (*shader_allocate_context_data)(struct wined3d_context *context);
1548 void (*shader_free_context_data)(struct wined3d_context *context);
1549 void (*shader_init_context_state)(struct wined3d_context *context);
1550 void (*shader_get_caps)(const struct wined3d_adapter *adapter, struct shader_caps *caps);
1551 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
1552 BOOL (*shader_has_ffp_proj_control)(void *shader_priv);
1553 uint64_t (*shader_compile)(struct wined3d_context *context, const struct wined3d_shader_desc *shader_desc,
1554 enum wined3d_shader_type shader_type);
1557 extern const struct wined3d_shader_backend_ops glsl_shader_backend DECLSPEC_HIDDEN;
1558 extern const struct wined3d_shader_backend_ops arb_program_shader_backend DECLSPEC_HIDDEN;
1559 extern const struct wined3d_shader_backend_ops none_shader_backend DECLSPEC_HIDDEN;
1561 const struct wined3d_shader_backend_ops *wined3d_spirv_shader_backend_init_vk(void) DECLSPEC_HIDDEN;
1563 #define GL_EXTCALL(f) (gl_info->gl_ops.ext.p_##f)
1565 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xff)
1566 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xff)
1567 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xff)
1568 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xff)
1570 static inline void wined3d_color_from_d3dcolor(struct wined3d_color *wined3d_color, DWORD d3d_color)
1572 wined3d_color->r = D3DCOLOR_B_R(d3d_color) / 255.0f;
1573 wined3d_color->g = D3DCOLOR_B_G(d3d_color) / 255.0f;
1574 wined3d_color->b = D3DCOLOR_B_B(d3d_color) / 255.0f;
1575 wined3d_color->a = D3DCOLOR_B_A(d3d_color) / 255.0f;
1578 extern const struct wined3d_vec4 wined3d_srgb_const[] DECLSPEC_HIDDEN;
1580 static inline float wined3d_srgb_from_linear(float colour)
1582 if (colour < 0.0f)
1583 return 0.0f;
1584 if (colour < wined3d_srgb_const[1].x)
1585 return colour * wined3d_srgb_const[0].w;
1586 if (colour < 1.0f)
1587 return wined3d_srgb_const[0].y * powf(colour, wined3d_srgb_const[0].x) - wined3d_srgb_const[0].z;
1588 return 1.0f;
1591 static inline void wined3d_colour_srgb_from_linear(struct wined3d_color *colour_srgb,
1592 const struct wined3d_color *colour)
1594 colour_srgb->r = wined3d_srgb_from_linear(colour->r);
1595 colour_srgb->g = wined3d_srgb_from_linear(colour->g);
1596 colour_srgb->b = wined3d_srgb_from_linear(colour->b);
1597 colour_srgb->a = colour->a;
1600 struct wined3d_bo
1602 /* client_map_count and map_ptr are accessed from both the client and CS
1603 * threads, and protected by wined3d_device.bo_map_lock. */
1604 struct list users;
1605 void *map_ptr;
1606 size_t buffer_offset;
1607 size_t memory_offset;
1608 unsigned int client_map_count;
1609 bool coherent;
1610 /* Number of resources referencing this BO, used for COW tracking.
1611 * If a resource has this BO as a location and wants to write to it, it
1612 * needs to make a copy unless it's the only owner (refcount == 1).
1613 * Deferred contexts may also hold a reference. */
1614 uint8_t refcount;
1617 struct wined3d_bo_user
1619 struct list entry;
1620 bool valid;
1623 struct wined3d_bo_address
1625 struct wined3d_bo *buffer_object;
1626 BYTE *addr;
1629 struct wined3d_const_bo_address
1631 struct wined3d_bo *buffer_object;
1632 const BYTE *addr;
1635 static inline struct wined3d_const_bo_address *wined3d_const_bo_address(const struct wined3d_bo_address *data)
1637 return (struct wined3d_const_bo_address *)data;
1640 struct wined3d_stream_info_element
1642 const struct wined3d_format *format;
1643 struct wined3d_bo_address data;
1644 unsigned int stride;
1645 unsigned int stream_idx;
1646 unsigned int divisor;
1647 bool instanced;
1650 struct wined3d_stream_info
1652 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
1653 DWORD position_transformed : 1;
1654 DWORD all_vbo : 1;
1655 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1656 DWORD use_map; /* MAX_ATTRIBS, 32 */
1659 void wined3d_stream_info_from_declaration(struct wined3d_stream_info *stream_info,
1660 const struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info) DECLSPEC_HIDDEN;
1662 struct wined3d_direct_dispatch_parameters
1664 unsigned int group_count_x;
1665 unsigned int group_count_y;
1666 unsigned int group_count_z;
1669 struct wined3d_indirect_dispatch_parameters
1671 struct wined3d_buffer *buffer;
1672 unsigned int offset;
1675 struct wined3d_dispatch_parameters
1677 BOOL indirect;
1678 union
1680 struct wined3d_direct_dispatch_parameters direct;
1681 struct wined3d_indirect_dispatch_parameters indirect;
1682 } u;
1685 struct wined3d_direct_draw_parameters
1687 int base_vertex_idx;
1688 unsigned int start_idx;
1689 unsigned int index_count;
1690 unsigned int start_instance;
1691 unsigned int instance_count;
1694 struct wined3d_indirect_draw_parameters
1696 struct wined3d_buffer *buffer;
1697 unsigned int offset;
1700 struct wined3d_draw_parameters
1702 BOOL indirect;
1703 union
1705 struct wined3d_direct_draw_parameters direct;
1706 struct wined3d_indirect_draw_parameters indirect;
1707 } u;
1708 BOOL indexed;
1711 void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
1712 const struct wined3d_draw_parameters *draw_parameters) DECLSPEC_HIDDEN;
1713 void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
1714 const struct wined3d_dispatch_parameters *dispatch_parameters) DECLSPEC_HIDDEN;
1716 #define eps 1e-8f
1718 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1719 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1721 /* Routines and structures related to state management */
1723 #define STATE_RENDER(a) (a)
1724 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1726 #define STATE_TEXTURESTAGE(stage, num) \
1727 (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
1728 #define STATE_IS_TEXTURESTAGE(a) \
1729 ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1731 /* + 1 because samplers start with 0 */
1732 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
1733 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS - 1))
1735 #define STATE_GRAPHICS_SHADER(a) (STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS) + (a))
1736 #define STATE_IS_GRAPHICS_SHADER(a) \
1737 ((a) >= STATE_GRAPHICS_SHADER(0) && (a) < STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1739 #define STATE_GRAPHICS_CONSTANT_BUFFER(a) (STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT) + (a))
1740 #define STATE_IS_GRAPHICS_CONSTANT_BUFFER(a) \
1741 ((a) >= STATE_GRAPHICS_CONSTANT_BUFFER(0) \
1742 && (a) < STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1744 #define STATE_GRAPHICS_SHADER_RESOURCE_BINDING (STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1745 #define STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(a) ((a) == STATE_GRAPHICS_SHADER_RESOURCE_BINDING)
1747 #define STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING (STATE_GRAPHICS_SHADER_RESOURCE_BINDING + 1)
1748 #define STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING)
1750 #define STATE_TRANSFORM(a) (STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING + (a))
1751 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)))
1753 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1)
1754 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
1755 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1756 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
1758 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
1759 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1761 #define STATE_VIEWPORT (STATE_VDECL + 1)
1762 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1764 #define STATE_LIGHT_TYPE (STATE_VIEWPORT + 1)
1765 #define STATE_IS_LIGHT_TYPE(a) ((a) == STATE_LIGHT_TYPE)
1766 #define STATE_ACTIVELIGHT(a) (STATE_LIGHT_TYPE + 1 + (a))
1767 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS))
1769 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS - 1) + 1)
1770 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1772 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1773 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES - 1))
1775 #define STATE_MATERIAL (STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES))
1776 #define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
1778 #define STATE_RASTERIZER (STATE_MATERIAL + 1)
1779 #define STATE_IS_RASTERIZER(a) ((a) == STATE_RASTERIZER)
1781 #define STATE_DEPTH_BOUNDS (STATE_RASTERIZER + 1)
1782 #define STATE_IS_DEPTH_BOUNDS(a) ((a) == STATE_DEPTH_BOUNDS)
1784 #define STATE_POINTSPRITECOORDORIGIN (STATE_DEPTH_BOUNDS + 1)
1785 #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN)
1787 #define STATE_BASEVERTEXINDEX (STATE_POINTSPRITECOORDORIGIN + 1)
1788 #define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX)
1790 #define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1)
1791 #define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER)
1793 #define STATE_POINT_ENABLE (STATE_FRAMEBUFFER + 1)
1794 #define STATE_IS_POINT_ENABLE(a) ((a) == STATE_POINT_ENABLE)
1796 #define STATE_COLOR_KEY (STATE_POINT_ENABLE + 1)
1797 #define STATE_IS_COLOR_KEY(a) ((a) == STATE_COLOR_KEY)
1799 #define STATE_STREAM_OUTPUT (STATE_COLOR_KEY + 1)
1800 #define STATE_IS_STREAM_OUTPUT(a) ((a) == STATE_STREAM_OUTPUT)
1802 #define STATE_BLEND (STATE_STREAM_OUTPUT + 1)
1803 #define STATE_IS_BLEND(a) ((a) == STATE_BLEND)
1805 #define STATE_BLEND_FACTOR (STATE_BLEND + 1)
1806 #define STATE_IS_BLEND_FACTOR(a) ((a) == STATE_BLEND_FACTOR)
1808 #define STATE_SAMPLE_MASK (STATE_BLEND_FACTOR + 1)
1809 #define STATE_IS_SAMPLE_MASK(a) ((a) == STATE_SAMPLE_MASK)
1811 #define STATE_DEPTH_STENCIL (STATE_SAMPLE_MASK + 1)
1812 #define STATE_IS_DEPTH_STENCIL(a) ((a) == STATE_DEPTH_STENCIL)
1814 #define STATE_STENCIL_REF (STATE_DEPTH_STENCIL + 1)
1815 #define STATE_IS_STENCIL_REF(a) ((a) == STATE_STENCIL_REF)
1817 #define STATE_COMPUTE_OFFSET (STATE_STENCIL_REF + 1)
1819 #define STATE_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
1820 #define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
1822 #define STATE_COMPUTE_CONSTANT_BUFFER (STATE_COMPUTE_SHADER + 1)
1823 #define STATE_IS_COMPUTE_CONSTANT_BUFFER(a) ((a) == STATE_COMPUTE_CONSTANT_BUFFER)
1825 #define STATE_COMPUTE_SHADER_RESOURCE_BINDING (STATE_COMPUTE_CONSTANT_BUFFER + 1)
1826 #define STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(a) ((a) == STATE_COMPUTE_SHADER_RESOURCE_BINDING)
1828 #define STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING (STATE_COMPUTE_SHADER_RESOURCE_BINDING + 1)
1829 #define STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1831 #define STATE_COMPUTE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1832 #define STATE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1834 #define STATE_IS_COMPUTE(a) ((a) >= STATE_COMPUTE_OFFSET && (a) <= STATE_COMPUTE_HIGHEST)
1835 #define STATE_COMPUTE_COUNT (STATE_COMPUTE_HIGHEST - STATE_COMPUTE_OFFSET + 1)
1837 #define STATE_SHADER(a) ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_SHADER(a) : STATE_COMPUTE_SHADER)
1838 #define STATE_CONSTANT_BUFFER(a) \
1839 ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_CONSTANT_BUFFER(a) : STATE_COMPUTE_CONSTANT_BUFFER)
1840 #define STATE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == WINED3D_PIPELINE_GRAPHICS ? \
1841 STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING : STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1843 enum fogsource {
1844 FOGSOURCE_FFP,
1845 FOGSOURCE_VS,
1846 FOGSOURCE_COORD,
1849 /* Direct3D terminology with little modifications. We do not have an issued
1850 * state because only the driver knows about it, but we have a created state
1851 * because D3D allows GetData() on a created query, but OpenGL doesn't. */
1852 enum wined3d_query_state
1854 QUERY_CREATED,
1855 QUERY_SIGNALLED,
1856 QUERY_BUILDING
1859 struct wined3d_query_ops
1861 BOOL (*query_poll)(struct wined3d_query *query, uint32_t flags);
1862 BOOL (*query_issue)(struct wined3d_query *query, uint32_t flags);
1863 void (*query_destroy)(struct wined3d_query *query);
1866 struct wined3d_query
1868 LONG ref;
1870 void *parent;
1871 const struct wined3d_parent_ops *parent_ops;
1872 struct wined3d_device *device;
1873 enum wined3d_query_state state;
1874 enum wined3d_query_type type;
1875 const void *data;
1876 DWORD data_size;
1877 const struct wined3d_query_ops *query_ops;
1879 LONG counter_main, counter_retrieved;
1880 struct list poll_list_entry;
1882 /* FIXME: This is GL-specific. */
1883 unsigned int buffer_object;
1884 UINT64 *map_ptr;
1885 bool poll_in_cs;
1888 #define WINED3D_QUERY_POOL_SIZE 256
1890 struct wined3d_range
1892 unsigned int offset;
1893 unsigned int size;
1896 struct wined3d_fb_state
1898 struct wined3d_rendertarget_view *render_targets[WINED3D_MAX_RENDER_TARGETS];
1899 struct wined3d_rendertarget_view *depth_stencil;
1902 struct wined3d_context
1904 const struct wined3d_d3d_info *d3d_info;
1905 const struct wined3d_state_entry *state_table;
1906 uint32_t dirty_graphics_states[WINED3D_BITMAP_SIZE(STATE_HIGHEST)];
1907 uint32_t dirty_compute_states[WINED3D_BITMAP_SIZE(STATE_COMPUTE_COUNT)];
1909 struct wined3d_device *device;
1910 struct wined3d_swapchain *swapchain;
1911 struct
1913 struct wined3d_texture *texture;
1914 unsigned int sub_resource_idx;
1915 } current_rt;
1917 /* Stores some information about the context state for optimization */
1918 DWORD last_swizzle_map; /* MAX_ATTRIBS, 32 */
1920 DWORD shader_update_mask : 6; /* WINED3D_SHADER_TYPE_COUNT, 6 */
1921 DWORD update_shader_resource_bindings : 1;
1922 DWORD update_compute_shader_resource_bindings : 1;
1923 DWORD update_unordered_access_view_bindings : 1;
1924 DWORD update_compute_unordered_access_view_bindings : 1;
1925 DWORD last_was_rhw : 1; /* True iff last draw_primitive was in xyzrhw mode. */
1926 DWORD last_was_pshader : 1;
1927 DWORD last_was_vshader : 1;
1928 DWORD last_was_diffuse : 1;
1929 DWORD last_was_specular : 1;
1930 DWORD last_was_normal : 1;
1931 DWORD last_was_ffp_blit : 1;
1932 DWORD last_was_blit : 1;
1933 DWORD last_was_ckey : 1;
1934 DWORD last_was_dual_source_blend : 1;
1935 DWORD texShaderBumpMap : 8; /* WINED3D_MAX_TEXTURES, 8 */
1936 DWORD lowest_disabled_stage : 4; /* Max WINED3D_MAX_TEXTURES, 8 */
1938 DWORD lastWasPow2Texture : 8; /* WINED3D_MAX_TEXTURES, 8 */
1939 DWORD fixed_function_usage_map : 8; /* WINED3D_MAX_TEXTURES, 8 */
1940 DWORD use_immediate_mode_draw : 1;
1941 DWORD uses_uavs : 1;
1942 DWORD uses_fbo_attached_resources : 1;
1943 DWORD transform_feedback_active : 1;
1944 DWORD transform_feedback_paused : 1;
1945 DWORD fog_coord : 1;
1946 DWORD render_offscreen : 1;
1947 DWORD current : 1;
1948 DWORD destroyed : 1;
1949 DWORD destroy_delayed : 1;
1950 DWORD namedArraysLoaded : 1;
1951 DWORD padding : 5;
1953 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1955 DWORD constant_update_mask;
1956 DWORD numbered_array_mask;
1957 enum fogsource fog_source;
1960 void *shader_backend_data;
1961 void *fragment_pipe_data;
1963 struct wined3d_stream_info stream_info;
1965 unsigned int viewport_count;
1966 unsigned int scissor_rect_count;
1969 void wined3d_context_cleanup(struct wined3d_context *context) DECLSPEC_HIDDEN;
1970 void wined3d_context_init(struct wined3d_context *context, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
1971 void context_preload_textures(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
1972 void context_update_stream_info(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
1974 HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d,
1975 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
1977 typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
1979 struct wined3d_state_entry
1981 unsigned int representative;
1982 APPLYSTATEFUNC apply;
1985 struct wined3d_state_entry_template
1987 unsigned int state;
1988 struct wined3d_state_entry content;
1989 unsigned int extension;
1992 #define WINED3D_FRAGMENT_CAP_PROJ_CONTROL 0x00000001
1993 #define WINED3D_FRAGMENT_CAP_SRGB_WRITE 0x00000002
1994 #define WINED3D_FRAGMENT_CAP_COLOR_KEY 0x00000004
1996 struct fragment_caps
1998 DWORD wined3d_caps;
1999 DWORD PrimitiveMiscCaps;
2000 DWORD TextureOpCaps;
2001 DWORD MaxTextureBlendStages;
2002 DWORD MaxSimultaneousTextures;
2005 #define GL_EXT_EMUL_ARB_MULTITEXTURE 0x00000001
2006 #define GL_EXT_EMUL_EXT_FOG_COORD 0x00000002
2008 struct wined3d_fragment_pipe_ops
2010 void (*fp_enable)(const struct wined3d_context *context, BOOL enable);
2011 void (*get_caps)(const struct wined3d_adapter *adapter, struct fragment_caps *caps);
2012 unsigned int (*get_emul_mask)(const struct wined3d_adapter *adapter);
2013 void *(*alloc_private)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2014 void (*free_private)(struct wined3d_device *device, struct wined3d_context *context);
2015 BOOL (*allocate_context_data)(struct wined3d_context *context);
2016 void (*free_context_data)(struct wined3d_context *context);
2017 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
2018 const struct wined3d_state_entry_template *states;
2021 struct wined3d_vertex_caps
2023 BOOL xyzrhw;
2024 BOOL emulated_flatshading;
2025 BOOL ffp_generic_attributes;
2026 DWORD max_active_lights;
2027 DWORD max_vertex_blend_matrices;
2028 DWORD max_vertex_blend_matrix_index;
2029 DWORD vertex_processing_caps;
2030 DWORD fvf_caps;
2031 DWORD max_user_clip_planes;
2032 DWORD raster_caps;
2035 struct wined3d_vertex_pipe_ops
2037 void (*vp_enable)(const struct wined3d_context *context, BOOL enable);
2038 void (*vp_get_caps)(const struct wined3d_adapter *adapter, struct wined3d_vertex_caps *caps);
2039 unsigned int (*vp_get_emul_mask)(const struct wined3d_adapter *adapter);
2040 void *(*vp_alloc)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2041 void (*vp_free)(struct wined3d_device *device, struct wined3d_context *context);
2042 const struct wined3d_state_entry_template *vp_states;
2045 extern const struct wined3d_state_entry_template misc_state_template_gl[] DECLSPEC_HIDDEN;
2046 extern const struct wined3d_fragment_pipe_ops none_fragment_pipe DECLSPEC_HIDDEN;
2047 extern const struct wined3d_fragment_pipe_ops ffp_fragment_pipeline DECLSPEC_HIDDEN;
2048 extern const struct wined3d_fragment_pipe_ops atifs_fragment_pipeline DECLSPEC_HIDDEN;
2049 extern const struct wined3d_fragment_pipe_ops arbfp_fragment_pipeline DECLSPEC_HIDDEN;
2050 extern const struct wined3d_fragment_pipe_ops nvts_fragment_pipeline DECLSPEC_HIDDEN;
2051 extern const struct wined3d_fragment_pipe_ops nvrc_fragment_pipeline DECLSPEC_HIDDEN;
2052 extern const struct wined3d_fragment_pipe_ops glsl_fragment_pipe DECLSPEC_HIDDEN;
2054 const struct wined3d_fragment_pipe_ops *wined3d_spirv_fragment_pipe_init_vk(void) DECLSPEC_HIDDEN;
2056 extern const struct wined3d_vertex_pipe_ops none_vertex_pipe DECLSPEC_HIDDEN;
2057 extern const struct wined3d_vertex_pipe_ops ffp_vertex_pipe DECLSPEC_HIDDEN;
2058 extern const struct wined3d_vertex_pipe_ops glsl_vertex_pipe DECLSPEC_HIDDEN;
2060 const struct wined3d_vertex_pipe_ops *wined3d_spirv_vertex_pipe_init_vk(void) DECLSPEC_HIDDEN;
2062 /* "Base" state table */
2063 HRESULT compile_state_table(struct wined3d_state_entry *state_table, APPLYSTATEFUNC **dev_multistate_funcs,
2064 const struct wined3d_d3d_info *d3d_info, const BOOL *supported_extensions,
2065 const struct wined3d_vertex_pipe_ops *vertex, const struct wined3d_fragment_pipe_ops *fragment,
2066 const struct wined3d_state_entry_template *misc) DECLSPEC_HIDDEN;
2068 enum wined3d_blit_op
2070 WINED3D_BLIT_OP_COLOR_BLIT,
2071 WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST,
2072 WINED3D_BLIT_OP_COLOR_BLIT_CKEY,
2073 WINED3D_BLIT_OP_DEPTH_BLIT,
2074 WINED3D_BLIT_OP_RAW_BLIT,
2077 struct wined3d_blitter
2079 const struct wined3d_blitter_ops *ops;
2080 struct wined3d_blitter *next;
2083 struct wined3d_blitter_ops
2085 void (*blitter_destroy)(struct wined3d_blitter *blitter, struct wined3d_context *context);
2086 void (*blitter_clear)(struct wined3d_blitter *blitter, struct wined3d_device *device,
2087 unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects,
2088 const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil);
2089 DWORD (*blitter_blit)(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context,
2090 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location,
2091 const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
2092 DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key,
2093 enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format);
2096 struct wined3d_blitter *wined3d_cpu_blitter_create(void) DECLSPEC_HIDDEN;
2097 void wined3d_vk_blitter_create(struct wined3d_blitter **next) DECLSPEC_HIDDEN;
2099 BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other) DECLSPEC_HIDDEN;
2101 void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id) DECLSPEC_HIDDEN;
2102 void context_invalidate_state(struct wined3d_context *context, unsigned int state_id) DECLSPEC_HIDDEN;
2103 void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
2104 void context_restore(struct wined3d_context *context, struct wined3d_texture *texture,
2105 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
2106 void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
2107 void context_state_drawbuf(struct wined3d_context *context,
2108 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2109 void context_state_fb(struct wined3d_context *context,
2110 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2112 /*****************************************************************************
2113 * Internal representation of a light
2115 struct wined3d_light_info
2117 struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
2118 unsigned int OriginalIndex;
2119 LONG glIndex;
2120 BOOL enabled;
2122 /* Converted parms to speed up swapping lights */
2123 struct wined3d_vec4 position;
2124 struct wined3d_vec4 direction;
2125 float exponent;
2126 float cutoff;
2128 struct rb_entry entry;
2129 struct list changed_entry;
2130 bool changed;
2133 /* The default light parameters */
2134 extern const struct wined3d_light WINED3D_default_light DECLSPEC_HIDDEN;
2136 struct wined3d_pixel_format
2138 int iPixelFormat; /* WGL pixel format */
2139 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
2140 int redSize, greenSize, blueSize, alphaSize, colorSize;
2141 int depthSize, stencilSize;
2142 BOOL windowDrawable;
2143 BOOL doubleBuffer;
2144 int auxBuffers;
2145 int numSamples;
2146 int swap_method;
2149 enum wined3d_pci_vendor
2151 HW_VENDOR_SOFTWARE = 0x0000,
2152 HW_VENDOR_AMD = 0x1002,
2153 HW_VENDOR_NVIDIA = 0x10de,
2154 HW_VENDOR_VMWARE = 0x15ad,
2155 HW_VENDOR_REDHAT = 0x1af4,
2156 HW_VENDOR_INTEL = 0x8086,
2159 enum wined3d_pci_device
2161 CARD_WINE = 0x0000,
2163 CARD_AMD_RAGE_128PRO = 0x5246,
2164 CARD_AMD_RADEON_7200 = 0x5144,
2165 CARD_AMD_RADEON_8500 = 0x514c,
2166 CARD_AMD_RADEON_9500 = 0x4144,
2167 CARD_AMD_RADEON_XPRESS_200M = 0x5955,
2168 CARD_AMD_RADEON_X700 = 0x5e4c,
2169 CARD_AMD_RADEON_X1600 = 0x71c2,
2170 CARD_AMD_RADEON_HD2350 = 0x94c7,
2171 CARD_AMD_RADEON_HD2600 = 0x9581,
2172 CARD_AMD_RADEON_HD2900 = 0x9400,
2173 CARD_AMD_RADEON_HD3200 = 0x9620,
2174 CARD_AMD_RADEON_HD3850 = 0x9515,
2175 CARD_AMD_RADEON_HD4200M = 0x9712,
2176 CARD_AMD_RADEON_HD4350 = 0x954f,
2177 CARD_AMD_RADEON_HD4600 = 0x9495,
2178 CARD_AMD_RADEON_HD4700 = 0x944e,
2179 CARD_AMD_RADEON_HD4800 = 0x944c,
2180 CARD_AMD_RADEON_HD5400 = 0x68f9,
2181 CARD_AMD_RADEON_HD5600 = 0x68d8,
2182 CARD_AMD_RADEON_HD5700 = 0x68be,
2183 CARD_AMD_RADEON_HD5800 = 0x6898,
2184 CARD_AMD_RADEON_HD5900 = 0x689c,
2185 CARD_AMD_RADEON_HD6300 = 0x9803,
2186 CARD_AMD_RADEON_HD6400 = 0x6770,
2187 CARD_AMD_RADEON_HD6490M = 0x6760,
2188 CARD_AMD_RADEON_HD6410D = 0x9644,
2189 CARD_AMD_RADEON_HD6480G = 0x9648,
2190 CARD_AMD_RADEON_HD6550D = 0x9640,
2191 CARD_AMD_RADEON_HD6600 = 0x6758,
2192 CARD_AMD_RADEON_HD6600M = 0x6741,
2193 CARD_AMD_RADEON_HD6700 = 0x68ba,
2194 CARD_AMD_RADEON_HD6800 = 0x6739,
2195 CARD_AMD_RADEON_HD6900 = 0x6719,
2196 CARD_AMD_RADEON_HD7660D = 0x9901,
2197 CARD_AMD_RADEON_HD7700 = 0x683d,
2198 CARD_AMD_RADEON_HD7800 = 0x6819,
2199 CARD_AMD_RADEON_HD7870 = 0x6818,
2200 CARD_AMD_RADEON_HD7900 = 0x679a,
2201 CARD_AMD_RADEON_HD8600M = 0x6660,
2202 CARD_AMD_RADEON_HD8670 = 0x6610,
2203 CARD_AMD_RADEON_HD8770 = 0x665c,
2204 CARD_AMD_RADEON_R3 = 0x9830,
2205 CARD_AMD_RADEON_R7 = 0x130f,
2206 CARD_AMD_RADEON_R9_285 = 0x6939,
2207 CARD_AMD_RADEON_R9_290 = 0x67b1,
2208 CARD_AMD_RADEON_R9_290X = 0x67b0,
2209 CARD_AMD_RADEON_R9_FURY = 0x7300,
2210 CARD_AMD_RADEON_R9_M370X = 0x6821,
2211 CARD_AMD_RADEON_R9_M380 = 0x6647,
2212 CARD_AMD_RADEON_R9_M395X = 0x6920,
2213 CARD_AMD_RADEON_RX_460 = 0x67ef,
2214 CARD_AMD_RADEON_RX_480 = 0x67df,
2215 CARD_AMD_RADEON_RX_VEGA_10 = 0x687f,
2216 CARD_AMD_RADEON_RX_VEGA_12 = 0x69af,
2217 CARD_AMD_RADEON_RAVEN = 0x15dd,
2218 CARD_AMD_RADEON_RX_VEGA_20 = 0x66af,
2219 CARD_AMD_RADEON_RX_NAVI_10 = 0x731f,
2220 CARD_AMD_RADEON_RX_NAVI_14 = 0x7340,
2221 CARD_AMD_RADEON_RX_NAVI_21 = 0x73bf,
2222 CARD_AMD_RADEON_PRO_V620 = 0x73a1,
2223 CARD_AMD_RADEON_PRO_V620_VF = 0x73ae,
2224 CARD_AMD_VANGOGH = 0x163f,
2225 CARD_AMD_RAPHAEL = 0x164e,
2227 CARD_NVIDIA_RIVA_128 = 0x0018,
2228 CARD_NVIDIA_RIVA_TNT = 0x0020,
2229 CARD_NVIDIA_RIVA_TNT2 = 0x0028,
2230 CARD_NVIDIA_GEFORCE = 0x0100,
2231 CARD_NVIDIA_GEFORCE2_MX = 0x0110,
2232 CARD_NVIDIA_GEFORCE2 = 0x0150,
2233 CARD_NVIDIA_GEFORCE3 = 0x0200,
2234 CARD_NVIDIA_GEFORCE4_MX = 0x0170,
2235 CARD_NVIDIA_GEFORCE4_TI4200 = 0x0253,
2236 CARD_NVIDIA_GEFORCEFX_5200 = 0x0320,
2237 CARD_NVIDIA_GEFORCEFX_5600 = 0x0312,
2238 CARD_NVIDIA_GEFORCEFX_5800 = 0x0302,
2239 CARD_NVIDIA_GEFORCE_6200 = 0x014f,
2240 CARD_NVIDIA_GEFORCE_6600GT = 0x0140,
2241 CARD_NVIDIA_GEFORCE_6800 = 0x0041,
2242 CARD_NVIDIA_GEFORCE_7300 = 0x01d7, /* GeForce Go 7300 */
2243 CARD_NVIDIA_GEFORCE_7400 = 0x01d8,
2244 CARD_NVIDIA_GEFORCE_7600 = 0x0391,
2245 CARD_NVIDIA_GEFORCE_7800GT = 0x0092,
2246 CARD_NVIDIA_GEFORCE_8200 = 0x0849, /* Other PCI ID 0x084b */
2247 CARD_NVIDIA_GEFORCE_8300GS = 0x0423,
2248 CARD_NVIDIA_GEFORCE_8400GS = 0x0404,
2249 CARD_NVIDIA_GEFORCE_8500GT = 0x0421,
2250 CARD_NVIDIA_GEFORCE_8600GT = 0x0402,
2251 CARD_NVIDIA_GEFORCE_8600MGT = 0x0407,
2252 CARD_NVIDIA_GEFORCE_8800GTS = 0x0193,
2253 CARD_NVIDIA_GEFORCE_8800GTX = 0x0191,
2254 CARD_NVIDIA_GEFORCE_9200 = 0x086d,
2255 CARD_NVIDIA_GEFORCE_9300 = 0x086c,
2256 CARD_NVIDIA_GEFORCE_9400M = 0x0863,
2257 CARD_NVIDIA_GEFORCE_9400GT = 0x042c,
2258 CARD_NVIDIA_GEFORCE_9500GT = 0x0640,
2259 CARD_NVIDIA_GEFORCE_9600GT = 0x0622,
2260 CARD_NVIDIA_GEFORCE_9700MGT = 0x064a,
2261 CARD_NVIDIA_GEFORCE_9800GT = 0x0614,
2262 CARD_NVIDIA_GEFORCE_210 = 0x0a23,
2263 CARD_NVIDIA_GEFORCE_GT220 = 0x0a20,
2264 CARD_NVIDIA_GEFORCE_GT240 = 0x0ca3,
2265 CARD_NVIDIA_GEFORCE_GTS250 = 0x0615,
2266 CARD_NVIDIA_GEFORCE_GTX260 = 0x05e2,
2267 CARD_NVIDIA_GEFORCE_GTX275 = 0x05e6,
2268 CARD_NVIDIA_GEFORCE_GTX280 = 0x05e1,
2269 CARD_NVIDIA_GEFORCE_315M = 0x0a7a,
2270 CARD_NVIDIA_GEFORCE_320M = 0x08a3,
2271 CARD_NVIDIA_GEFORCE_GT320M = 0x0a2d,
2272 CARD_NVIDIA_GEFORCE_GT325M = 0x0a35,
2273 CARD_NVIDIA_GEFORCE_GT330 = 0x0ca0,
2274 CARD_NVIDIA_GEFORCE_GTS350M = 0x0cb0,
2275 CARD_NVIDIA_GEFORCE_410M = 0x1055,
2276 CARD_NVIDIA_GEFORCE_GT420 = 0x0de2,
2277 CARD_NVIDIA_GEFORCE_GT425M = 0x0df0,
2278 CARD_NVIDIA_GEFORCE_GT430 = 0x0de1,
2279 CARD_NVIDIA_GEFORCE_GT440 = 0x0de0,
2280 CARD_NVIDIA_GEFORCE_GTS450 = 0x0dc4,
2281 CARD_NVIDIA_GEFORCE_GTX460 = 0x0e22,
2282 CARD_NVIDIA_GEFORCE_GTX460M = 0x0dd1,
2283 CARD_NVIDIA_GEFORCE_GTX465 = 0x06c4,
2284 CARD_NVIDIA_GEFORCE_GTX470 = 0x06cd,
2285 CARD_NVIDIA_GEFORCE_GTX480 = 0x06c0,
2286 CARD_NVIDIA_GEFORCE_GT520 = 0x1040,
2287 CARD_NVIDIA_GEFORCE_GT525M = 0x0dec,
2288 CARD_NVIDIA_GEFORCE_GT540M = 0x0df4,
2289 CARD_NVIDIA_GEFORCE_GTX550 = 0x1244,
2290 CARD_NVIDIA_GEFORCE_GT555M = 0x04b8,
2291 CARD_NVIDIA_GEFORCE_GTX560TI = 0x1200,
2292 CARD_NVIDIA_GEFORCE_GTX560M = 0x1251,
2293 CARD_NVIDIA_GEFORCE_GTX560 = 0x1201,
2294 CARD_NVIDIA_GEFORCE_GTX570 = 0x1081,
2295 CARD_NVIDIA_GEFORCE_GTX580 = 0x1080,
2296 CARD_NVIDIA_GEFORCE_GT610 = 0x104a,
2297 CARD_NVIDIA_GEFORCE_GT630 = 0x0f00,
2298 CARD_NVIDIA_GEFORCE_GT630M = 0x0de9,
2299 CARD_NVIDIA_GEFORCE_GT640 = 0x0fc1,
2300 CARD_NVIDIA_GEFORCE_GT640M = 0x0fd2,
2301 CARD_NVIDIA_GEFORCE_GT650M = 0x0fd1,
2302 CARD_NVIDIA_GEFORCE_GTX650 = 0x0fc6,
2303 CARD_NVIDIA_GEFORCE_GTX650TI = 0x11c6,
2304 CARD_NVIDIA_GEFORCE_GTX660 = 0x11c0,
2305 CARD_NVIDIA_GEFORCE_GTX660M = 0x0fd4,
2306 CARD_NVIDIA_GEFORCE_GTX660TI = 0x1183,
2307 CARD_NVIDIA_GEFORCE_GTX670 = 0x1189,
2308 CARD_NVIDIA_GEFORCE_GTX670MX = 0x11a1,
2309 CARD_NVIDIA_GEFORCE_GTX675MX_1 = 0x11a7,
2310 CARD_NVIDIA_GEFORCE_GTX675MX_2 = 0x11a2,
2311 CARD_NVIDIA_GEFORCE_GTX680 = 0x1180,
2312 CARD_NVIDIA_GEFORCE_GTX690 = 0x1188,
2313 CARD_NVIDIA_GEFORCE_GT720 = 0x128b,
2314 CARD_NVIDIA_GEFORCE_GT730 = 0x1287,
2315 CARD_NVIDIA_GEFORCE_GT730M = 0x0fe1,
2316 CARD_NVIDIA_GEFORCE_GT740M = 0x1292,
2317 CARD_NVIDIA_GEFORCE_GT750M = 0x0fe9,
2318 CARD_NVIDIA_GEFORCE_GT755M = 0x0fcd,
2319 CARD_NVIDIA_GEFORCE_GTX750 = 0x1381,
2320 CARD_NVIDIA_GEFORCE_GTX750TI = 0x1380,
2321 CARD_NVIDIA_GEFORCE_GTX760 = 0x1187,
2322 CARD_NVIDIA_GEFORCE_GTX760TI = 0x1193,
2323 CARD_NVIDIA_GEFORCE_GTX765M = 0x11e2,
2324 CARD_NVIDIA_GEFORCE_GTX770M = 0x11e0,
2325 CARD_NVIDIA_GEFORCE_GTX770 = 0x1184,
2326 CARD_NVIDIA_GEFORCE_GTX775M = 0x119d,
2327 CARD_NVIDIA_GEFORCE_GTX780 = 0x1004,
2328 CARD_NVIDIA_GEFORCE_GTX780M = 0x119e,
2329 CARD_NVIDIA_GEFORCE_GTX780TI = 0x100a,
2330 CARD_NVIDIA_GEFORCE_GTXTITAN = 0x1005,
2331 CARD_NVIDIA_GEFORCE_GTXTITANB = 0x100c,
2332 CARD_NVIDIA_GEFORCE_GTXTITANX = 0x17c2,
2333 CARD_NVIDIA_GEFORCE_GTXTITANZ = 0x1001,
2334 CARD_NVIDIA_GEFORCE_820M = 0x0fed,
2335 CARD_NVIDIA_GEFORCE_830M = 0x1340,
2336 CARD_NVIDIA_GEFORCE_840M = 0x1341,
2337 CARD_NVIDIA_GEFORCE_845M = 0x1344,
2338 CARD_NVIDIA_GEFORCE_GTX850M = 0x1391,
2339 CARD_NVIDIA_GEFORCE_GTX860M = 0x1392, /* Other PCI ID 0x119a */
2340 CARD_NVIDIA_GEFORCE_GTX870M = 0x1199,
2341 CARD_NVIDIA_GEFORCE_GTX880M = 0x1198,
2342 CARD_NVIDIA_GEFORCE_940M = 0x1347,
2343 CARD_NVIDIA_GEFORCE_GTX950 = 0x1402,
2344 CARD_NVIDIA_GEFORCE_GTX950M = 0x139a,
2345 CARD_NVIDIA_GEFORCE_GTX960 = 0x1401,
2346 CARD_NVIDIA_GEFORCE_GTX960M = 0x139b,
2347 CARD_NVIDIA_GEFORCE_GTX970 = 0x13c2,
2348 CARD_NVIDIA_GEFORCE_GTX970M = 0x13d8,
2349 CARD_NVIDIA_GEFORCE_GTX980 = 0x13c0,
2350 CARD_NVIDIA_GEFORCE_GTX980TI = 0x17c8,
2351 CARD_NVIDIA_GEFORCE_GT1030 = 0x1d01,
2352 CARD_NVIDIA_GEFORCE_GTX1050 = 0x1c81,
2353 CARD_NVIDIA_GEFORCE_GTX1050TI = 0x1c82,
2354 CARD_NVIDIA_GEFORCE_GTX1060_3GB = 0x1c02,
2355 CARD_NVIDIA_GEFORCE_GTX1060 = 0x1c03,
2356 CARD_NVIDIA_GEFORCE_GTX1060M = 0x1c20,
2357 CARD_NVIDIA_GEFORCE_GTX1070 = 0x1b81,
2358 CARD_NVIDIA_GEFORCE_GTX1080 = 0x1b80,
2359 CARD_NVIDIA_GEFORCE_GTX1080M = 0x1be0,
2360 CARD_NVIDIA_GEFORCE_GTX1080TI = 0x1b06,
2361 CARD_NVIDIA_TITANX_PASCAL = 0x1b00,
2362 CARD_NVIDIA_TITANV = 0x1d81,
2363 CARD_NVIDIA_GEFORCE_GTX1650SUPER= 0x2187,
2364 CARD_NVIDIA_GEFORCE_GTX1660SUPER= 0x21c4,
2365 CARD_NVIDIA_GEFORCE_GTX1660TI = 0x2182,
2366 CARD_NVIDIA_GEFORCE_RTX2060 = 0x1f08,
2367 CARD_NVIDIA_GEFORCE_RTX2070 = 0x1f07,
2368 CARD_NVIDIA_GEFORCE_RTX2080 = 0x1e87,
2369 CARD_NVIDIA_GEFORCE_RTX2080TI = 0x1e07,
2370 CARD_NVIDIA_TESLA_T4 = 0x1eb8,
2371 CARD_NVIDIA_AMPERE_A10 = 0x2236,
2373 CARD_REDHAT_VIRGL = 0x1010,
2375 CARD_VMWARE_SVGA3D = 0x0405,
2377 CARD_INTEL_830M = 0x3577,
2378 CARD_INTEL_855GM = 0x3582,
2379 CARD_INTEL_845G = 0x2562,
2380 CARD_INTEL_865G = 0x2572,
2381 CARD_INTEL_915G = 0x2582,
2382 CARD_INTEL_E7221G = 0x258a,
2383 CARD_INTEL_915GM = 0x2592,
2384 CARD_INTEL_945G = 0x2772,
2385 CARD_INTEL_945GM = 0x27a2,
2386 CARD_INTEL_945GME = 0x27ae,
2387 CARD_INTEL_Q35 = 0x29b2,
2388 CARD_INTEL_G33 = 0x29c2,
2389 CARD_INTEL_Q33 = 0x29d2,
2390 CARD_INTEL_PNVG = 0xa001,
2391 CARD_INTEL_PNVM = 0xa011,
2392 CARD_INTEL_965Q = 0x2992,
2393 CARD_INTEL_965G = 0x2982,
2394 CARD_INTEL_946GZ = 0x2972,
2395 CARD_INTEL_965GM = 0x2a02,
2396 CARD_INTEL_965GME = 0x2a12,
2397 CARD_INTEL_GM45 = 0x2a42,
2398 CARD_INTEL_IGD = 0x2e02,
2399 CARD_INTEL_Q45 = 0x2e12,
2400 CARD_INTEL_G45 = 0x2e22,
2401 CARD_INTEL_G41 = 0x2e32,
2402 CARD_INTEL_B43 = 0x2e92,
2403 CARD_INTEL_ILKD = 0x0042,
2404 CARD_INTEL_ILKM = 0x0046,
2405 CARD_INTEL_SNBD = 0x0122,
2406 CARD_INTEL_SNBM = 0x0126,
2407 CARD_INTEL_SNBS = 0x010a,
2408 CARD_INTEL_IVBD = 0x0162,
2409 CARD_INTEL_IVBM = 0x0166,
2410 CARD_INTEL_IVBS = 0x015a,
2411 CARD_INTEL_HWD = 0x0412,
2412 CARD_INTEL_HWM = 0x0416,
2413 CARD_INTEL_HD5000_1 = 0x0a26,
2414 CARD_INTEL_HD5000_2 = 0x0422,
2415 CARD_INTEL_I5100_1 = 0x0a22,
2416 CARD_INTEL_I5100_2 = 0x0a2a,
2417 CARD_INTEL_I5100_3 = 0x0a2b,
2418 CARD_INTEL_I5100_4 = 0x0a2e,
2419 CARD_INTEL_IP5200_1 = 0x0d22,
2420 CARD_INTEL_IP5200_2 = 0x0d26,
2421 CARD_INTEL_IP5200_3 = 0x0d2a,
2422 CARD_INTEL_IP5200_4 = 0x0d2b,
2423 CARD_INTEL_IP5200_5 = 0x0d2e,
2424 CARD_INTEL_IP5200_6 = 0x0c22,
2425 CARD_INTEL_HD5300 = 0x161e,
2426 CARD_INTEL_HD5500 = 0x1616,
2427 CARD_INTEL_HD5600 = 0x1612,
2428 CARD_INTEL_HD6000 = 0x1626,
2429 CARD_INTEL_I6100 = 0x162b,
2430 CARD_INTEL_IP6200 = 0x1622,
2431 CARD_INTEL_IPP6300 = 0x162a,
2432 CARD_INTEL_HD510_1 = 0x1902,
2433 CARD_INTEL_HD510_2 = 0x1906,
2434 CARD_INTEL_HD510_3 = 0x190b,
2435 CARD_INTEL_HD515 = 0x191e,
2436 CARD_INTEL_HD520_1 = 0x1916,
2437 CARD_INTEL_HD520_2 = 0x1921,
2438 CARD_INTEL_HD530_1 = 0x1912,
2439 CARD_INTEL_HD530_2 = 0x191b,
2440 CARD_INTEL_HDP530 = 0x191d,
2441 CARD_INTEL_I540 = 0x1926,
2442 CARD_INTEL_I550 = 0x1927,
2443 CARD_INTEL_I555 = 0x192b,
2444 CARD_INTEL_IP555 = 0x192d,
2445 CARD_INTEL_IP580_1 = 0x1932,
2446 CARD_INTEL_IP580_2 = 0x193b,
2447 CARD_INTEL_IPP580_1 = 0x193a,
2448 CARD_INTEL_IPP580_2 = 0x193d,
2449 CARD_INTEL_UHD617 = 0x87c0,
2450 CARD_INTEL_UHD620 = 0x3ea0,
2451 CARD_INTEL_HD615 = 0x591e,
2452 CARD_INTEL_HD620 = 0x5916,
2453 CARD_INTEL_HD630_1 = 0x5912,
2454 CARD_INTEL_HD630_2 = 0x591b,
2455 CARD_INTEL_UHD630_1 = 0x3e9b,
2456 CARD_INTEL_UHD630_2 = 0x3e91,
2459 /* The driver names reflect the lowest GPU supported
2460 * by a certain driver, so DRIVER_AMD_R300 supports
2461 * R3xx, R4xx and R5xx GPUs. */
2462 enum wined3d_display_driver
2464 DRIVER_AMD_RAGE_128PRO,
2465 DRIVER_AMD_R100,
2466 DRIVER_AMD_R300,
2467 DRIVER_AMD_R600,
2468 DRIVER_AMD_RX,
2469 DRIVER_INTEL_GMA800,
2470 DRIVER_INTEL_GMA900,
2471 DRIVER_INTEL_GMA950,
2472 DRIVER_INTEL_GMA3000,
2473 DRIVER_INTEL_HD4000,
2474 DRIVER_NVIDIA_TNT,
2475 DRIVER_NVIDIA_GEFORCE2MX,
2476 DRIVER_NVIDIA_GEFORCEFX,
2477 DRIVER_NVIDIA_GEFORCE6,
2478 DRIVER_NVIDIA_GEFORCE8,
2479 DRIVER_NVIDIA_FERMI,
2480 DRIVER_NVIDIA_KEPLER,
2481 DRIVER_REDHAT_VIRGL,
2482 DRIVER_VMWARE,
2483 DRIVER_WINE,
2484 DRIVER_UNKNOWN,
2487 struct wined3d_gpu_description
2489 enum wined3d_pci_vendor vendor;
2490 enum wined3d_pci_device device;
2491 const char *description;
2492 enum wined3d_display_driver driver;
2493 unsigned int vidmem;
2496 const struct wined3d_gpu_description *wined3d_get_gpu_description(enum wined3d_pci_vendor vendor,
2497 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
2498 const struct wined3d_gpu_description *wined3d_get_user_override_gpu_description(enum wined3d_pci_vendor vendor,
2499 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
2500 enum wined3d_pci_device wined3d_gpu_from_feature_level(enum wined3d_pci_vendor *vendor,
2501 enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
2503 /* 512 in Direct3D 8/9, 128 in DXGI. */
2504 #define WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH 512
2506 struct wined3d_driver_info
2508 enum wined3d_pci_vendor vendor;
2509 enum wined3d_pci_device device;
2510 const char *name;
2511 char description[WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH];
2512 UINT64 vram_bytes;
2513 UINT64 sysmem_bytes;
2514 unsigned int version_high;
2515 unsigned int version_low;
2518 bool wined3d_driver_info_init(struct wined3d_driver_info *driver_info,
2519 const struct wined3d_gpu_description *gpu_description, enum wined3d_feature_level feature_level,
2520 UINT64 vram_bytes, UINT64 sysmem_bytes) DECLSPEC_HIDDEN;
2522 #define UPLOAD_BO_UPLOAD_ON_UNMAP 0x1
2523 #define UPLOAD_BO_RENAME_ON_UNMAP 0x2
2524 #define UPLOAD_BO_FREE_ON_UNMAP 0x4
2526 struct upload_bo
2528 struct wined3d_const_bo_address addr;
2529 uint32_t flags;
2532 struct wined3d_adapter_ops
2534 void (*adapter_destroy)(struct wined3d_adapter *adapter);
2535 HRESULT (*adapter_create_device)(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
2536 enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
2537 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
2538 struct wined3d_device_parent *device_parent, struct wined3d_device **device);
2539 void (*adapter_destroy_device)(struct wined3d_device *device);
2540 struct wined3d_context *(*adapter_acquire_context)(struct wined3d_device *device,
2541 struct wined3d_texture *texture, unsigned int sub_resource_idx);
2542 void (*adapter_release_context)(struct wined3d_context *context);
2543 void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps);
2544 BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
2545 const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
2546 const struct wined3d_format *ds_format);
2547 HRESULT (*adapter_init_3d)(struct wined3d_device *device);
2548 void (*adapter_uninit_3d)(struct wined3d_device *device);
2549 void *(*adapter_map_bo_address)(struct wined3d_context *context,
2550 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags);
2551 void (*adapter_unmap_bo_address)(struct wined3d_context *context, const struct wined3d_bo_address *data,
2552 unsigned int range_count, const struct wined3d_range *ranges);
2553 void (*adapter_copy_bo_address)(struct wined3d_context *context,
2554 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
2555 unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags);
2556 void (*adapter_flush_bo_address)(struct wined3d_context *context,
2557 const struct wined3d_const_bo_address *data, size_t size);
2558 bool (*adapter_alloc_bo)(struct wined3d_device *device, struct wined3d_resource *resource,
2559 unsigned int sub_resource_idx, struct wined3d_bo_address *addr);
2560 void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo);
2561 HRESULT (*adapter_create_swapchain)(struct wined3d_device *device,
2562 const struct wined3d_swapchain_desc *desc,
2563 struct wined3d_swapchain_state_parent *state_parent, void *parent,
2564 const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain);
2565 void (*adapter_destroy_swapchain)(struct wined3d_swapchain *swapchain);
2566 HRESULT (*adapter_create_buffer)(struct wined3d_device *device, const struct wined3d_buffer_desc *desc,
2567 const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops,
2568 struct wined3d_buffer **buffer);
2569 void (*adapter_destroy_buffer)(struct wined3d_buffer *buffer);
2570 HRESULT (*adapter_create_texture)(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
2571 unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent,
2572 const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
2573 void (*adapter_destroy_texture)(struct wined3d_texture *texture);
2574 HRESULT (*adapter_create_rendertarget_view)(const struct wined3d_view_desc *desc,
2575 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2576 struct wined3d_rendertarget_view **view);
2577 void (*adapter_destroy_rendertarget_view)(struct wined3d_rendertarget_view *view);
2578 HRESULT (*adapter_create_shader_resource_view)(const struct wined3d_view_desc *desc,
2579 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2580 struct wined3d_shader_resource_view **view);
2581 void (*adapter_destroy_shader_resource_view)(struct wined3d_shader_resource_view *view);
2582 HRESULT (*adapter_create_unordered_access_view)(const struct wined3d_view_desc *desc,
2583 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2584 struct wined3d_unordered_access_view **view);
2585 void (*adapter_destroy_unordered_access_view)(struct wined3d_unordered_access_view *view);
2586 HRESULT (*adapter_create_sampler)(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
2587 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler);
2588 void (*adapter_destroy_sampler)(struct wined3d_sampler *sampler);
2589 HRESULT (*adapter_create_query)(struct wined3d_device *device, enum wined3d_query_type type,
2590 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query);
2591 void (*adapter_destroy_query)(struct wined3d_query *query);
2592 void (*adapter_flush_context)(struct wined3d_context *context);
2593 void (*adapter_draw_primitive)(struct wined3d_device *device, const struct wined3d_state *state,
2594 const struct wined3d_draw_parameters *parameters);
2595 void (*adapter_dispatch_compute)(struct wined3d_device *device, const struct wined3d_state *state,
2596 const struct wined3d_dispatch_parameters *parameters);
2597 void (*adapter_clear_uav)(struct wined3d_context *context,
2598 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp);
2599 void (*adapter_generate_mipmap)(struct wined3d_context *context, struct wined3d_shader_resource_view *view);
2602 struct wined3d_output
2604 unsigned int ordinal;
2605 WCHAR device_name[CCHDEVICENAME];
2606 struct wined3d_adapter *adapter;
2607 enum wined3d_format_id screen_format;
2609 D3DKMT_HANDLE kmt_device;
2610 D3DDDI_VIDEO_PRESENT_SOURCE_ID vidpn_source_id;
2612 struct wined3d_display_mode *modes;
2613 SIZE_T mode_count, modes_size;
2614 bool modes_valid;
2617 HRESULT wined3d_output_get_gamma_ramp(struct wined3d_output *output, struct wined3d_gamma_ramp *ramp) DECLSPEC_HIDDEN;
2619 #ifdef _WIN64
2620 #define MAX_PERSISTENT_MAPPED_BYTES I64_MAX
2621 #else
2622 #define MAX_PERSISTENT_MAPPED_BYTES (128 * 1024 * 1024)
2623 #endif
2625 /* The adapter structure */
2626 struct wined3d_adapter
2628 unsigned int ordinal;
2630 struct wined3d_d3d_info d3d_info;
2631 struct wined3d_driver_info driver_info;
2632 struct wined3d_output *outputs;
2633 SIZE_T output_count, outputs_size;
2634 D3DKMT_HANDLE kmt_adapter;
2635 UINT64 vram_bytes_used;
2636 GUID driver_uuid;
2637 GUID device_uuid;
2638 LUID luid;
2640 void *formats;
2641 size_t format_size;
2643 ssize_t mapped_size;
2645 const struct wined3d_vertex_pipe_ops *vertex_pipe;
2646 const struct wined3d_fragment_pipe_ops *fragment_pipe;
2647 const struct wined3d_state_entry_template *misc_state_template;
2648 const struct wined3d_shader_backend_ops *shader_backend;
2649 const struct wined3d_adapter_ops *adapter_ops;
2652 BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
2653 const struct wined3d_adapter_ops *adapter_ops) DECLSPEC_HIDDEN;
2654 void wined3d_adapter_cleanup(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
2655 BOOL wined3d_get_primary_adapter_luid(LUID *luid) DECLSPEC_HIDDEN;
2657 struct wined3d_adapter *wined3d_adapter_vk_create(unsigned int ordinal,
2658 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
2660 struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal,
2661 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
2663 BOOL wined3d_adapter_no3d_init_format_info(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
2664 ssize_t adapter_adjust_mapped_memory(struct wined3d_adapter *adapter, ssize_t size) DECLSPEC_HIDDEN;
2665 UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount) DECLSPEC_HIDDEN;
2667 enum wined3d_projection_type
2669 WINED3D_PROJECTION_NONE = 0,
2670 WINED3D_PROJECTION_COUNT3 = 1,
2671 WINED3D_PROJECTION_COUNT4 = 2
2674 /*****************************************************************************
2675 * Fixed function pipeline replacements
2677 #define ARG_UNUSED 0xff
2678 struct texture_stage_op
2680 unsigned cop : 8;
2681 unsigned carg1 : 8;
2682 unsigned carg2 : 8;
2683 unsigned carg0 : 8;
2685 unsigned aop : 8;
2686 unsigned aarg1 : 8;
2687 unsigned aarg2 : 8;
2688 unsigned aarg0 : 8;
2690 struct color_fixup_desc color_fixup;
2691 unsigned tex_type : 3;
2692 unsigned tmp_dst : 1;
2693 unsigned projected : 2;
2694 unsigned padding : 10;
2697 struct ffp_frag_settings
2699 struct texture_stage_op op[WINED3D_MAX_TEXTURES];
2700 enum wined3d_ffp_ps_fog_mode fog;
2701 unsigned char sRGB_write;
2702 unsigned char emul_clipplanes;
2703 unsigned char texcoords_initialized;
2704 unsigned char color_key_enabled : 1;
2705 unsigned char pointsprite : 1;
2706 unsigned char flatshading : 1;
2707 unsigned char alpha_test_func : 3;
2708 unsigned char padding : 2;
2711 struct ffp_frag_desc
2713 struct wine_rb_entry entry;
2714 struct ffp_frag_settings settings;
2717 int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
2718 int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
2720 extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
2722 void wined3d_ffp_get_fs_settings(const struct wined3d_context *context, const struct wined3d_state *state,
2723 struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN;
2724 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
2725 const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
2726 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
2727 void wined3d_ftoa(float value, char *s) DECLSPEC_HIDDEN;
2729 enum wined3d_ffp_vs_fog_mode
2731 WINED3D_FFP_VS_FOG_OFF = 0,
2732 WINED3D_FFP_VS_FOG_FOGCOORD = 1,
2733 WINED3D_FFP_VS_FOG_DEPTH = 2,
2734 WINED3D_FFP_VS_FOG_RANGE = 3,
2737 #define WINED3D_FFP_TCI_SHIFT 16
2738 #define WINED3D_FFP_TCI_MASK 0xffu
2740 #define WINED3D_FFP_LIGHT_TYPE_SHIFT(idx) (3 * (idx))
2741 #define WINED3D_FFP_LIGHT_TYPE_MASK 0x7u
2743 struct wined3d_ffp_vs_settings
2745 DWORD point_light_count : 4;
2746 DWORD spot_light_count : 4;
2747 DWORD directional_light_count : 4;
2748 DWORD parallel_point_light_count : 4;
2749 DWORD diffuse_source : 2;
2750 DWORD emissive_source : 2;
2751 DWORD ambient_source : 2;
2752 DWORD specular_source : 2;
2753 DWORD transformed : 1;
2754 DWORD vertexblends : 2;
2755 DWORD clipping : 1;
2756 DWORD normal : 1;
2757 DWORD normalize : 1;
2758 DWORD lighting : 1;
2759 DWORD localviewer : 1;
2761 DWORD point_size : 1;
2762 DWORD per_vertex_point_size : 1;
2763 DWORD fog_mode : 2;
2764 DWORD texcoords : 8; /* WINED3D_MAX_TEXTURES */
2765 DWORD ortho_fog : 1;
2766 DWORD flatshading : 1;
2767 DWORD padding : 18;
2769 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
2771 unsigned int texgen[WINED3D_MAX_TEXTURES];
2774 struct wined3d_ffp_vs_desc
2776 struct wine_rb_entry entry;
2777 struct wined3d_ffp_vs_settings settings;
2780 void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
2781 const struct wined3d_state *state, struct wined3d_ffp_vs_settings *settings) DECLSPEC_HIDDEN;
2783 struct wined3d
2785 LONG ref;
2786 unsigned int flags;
2787 unsigned int adapter_count;
2788 struct wined3d_adapter *adapters[1];
2791 BOOL wined3d_filter_messages(HWND window, BOOL filter) DECLSPEC_HIDDEN;
2792 HRESULT wined3d_init(struct wined3d *wined3d, uint32_t flags) DECLSPEC_HIDDEN;
2793 void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
2795 BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size) DECLSPEC_HIDDEN;
2797 enum wined3d_push_constants
2799 WINED3D_PUSH_CONSTANTS_VS_F,
2800 WINED3D_PUSH_CONSTANTS_PS_F,
2801 WINED3D_PUSH_CONSTANTS_VS_I,
2802 WINED3D_PUSH_CONSTANTS_PS_I,
2803 WINED3D_PUSH_CONSTANTS_VS_B,
2804 WINED3D_PUSH_CONSTANTS_PS_B,
2805 WINED3D_PUSH_CONSTANTS_COUNT,
2808 struct wined3d_blend_state
2810 LONG refcount;
2811 struct wined3d_blend_state_desc desc;
2812 BOOL dual_source;
2814 void *parent;
2815 const struct wined3d_parent_ops *parent_ops;
2817 struct wined3d_device *device;
2818 struct wine_rb_entry entry;
2821 static inline unsigned int wined3d_blend_state_get_writemask(const struct wined3d_blend_state *state,
2822 unsigned int index)
2824 if (!state)
2825 return 0xf;
2826 if (!state->desc.independent)
2827 index = 0;
2828 return state->desc.rt[index].writemask;
2831 struct wined3d_depth_stencil_state
2833 LONG refcount;
2834 struct wined3d_depth_stencil_state_desc desc;
2836 bool writes_ds;
2838 void *parent;
2839 const struct wined3d_parent_ops *parent_ops;
2841 struct wined3d_device *device;
2842 struct wine_rb_entry entry;
2845 struct wined3d_rasterizer_state
2847 LONG refcount;
2848 struct wined3d_rasterizer_state_desc desc;
2850 void *parent;
2851 const struct wined3d_parent_ops *parent_ops;
2853 struct wined3d_device *device;
2854 struct wine_rb_entry entry;
2857 struct wined3d_light_state
2859 struct rb_tree lights_tree;
2860 const struct wined3d_light_info *lights[WINED3D_MAX_ACTIVE_LIGHTS];
2863 #define WINED3D_STATE_NO_REF 0x00000001
2864 #define WINED3D_STATE_INIT_DEFAULT 0x00000002
2866 struct wined3d_state
2868 enum wined3d_feature_level feature_level;
2869 uint32_t flags;
2870 struct wined3d_fb_state fb;
2872 struct wined3d_vertex_declaration *vertex_declaration;
2873 struct wined3d_stream_output stream_output[WINED3D_MAX_STREAM_OUTPUT_BUFFERS];
2874 struct wined3d_stream_state streams[WINED3D_MAX_STREAMS];
2875 struct wined3d_buffer *index_buffer;
2876 enum wined3d_format_id index_format;
2877 unsigned int index_offset;
2878 int base_vertex_index;
2879 int load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
2880 enum wined3d_primitive_type primitive_type;
2881 unsigned int patch_vertex_count;
2882 struct wined3d_query *predicate;
2883 BOOL predicate_value;
2885 struct wined3d_shader *shader[WINED3D_SHADER_TYPE_COUNT];
2886 struct wined3d_constant_buffer_state cb[WINED3D_SHADER_TYPE_COUNT][MAX_CONSTANT_BUFFERS];
2887 struct wined3d_sampler *sampler[WINED3D_SHADER_TYPE_COUNT][MAX_SAMPLER_OBJECTS];
2888 struct wined3d_shader_resource_view *shader_resource_view[WINED3D_SHADER_TYPE_COUNT][MAX_SHADER_RESOURCE_VIEWS];
2889 struct wined3d_unordered_access_view *unordered_access_view[WINED3D_PIPELINE_COUNT][MAX_UNORDERED_ACCESS_VIEWS];
2891 struct wined3d_texture *textures[WINED3D_MAX_COMBINED_SAMPLERS];
2892 uint32_t sampler_states[WINED3D_MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
2893 uint32_t texture_states[WINED3D_MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
2895 struct wined3d_matrix transforms[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
2896 struct wined3d_vec4 clip_planes[WINED3D_MAX_CLIP_DISTANCES];
2897 struct wined3d_material material;
2898 struct wined3d_viewport viewports[WINED3D_MAX_VIEWPORTS];
2899 unsigned int viewport_count;
2900 RECT scissor_rects[WINED3D_MAX_VIEWPORTS];
2901 unsigned int scissor_rect_count;
2903 struct wined3d_light_state light_state;
2905 unsigned int render_states[WINEHIGHEST_RENDER_STATE + 1];
2906 struct wined3d_blend_state *blend_state;
2907 struct wined3d_color blend_factor;
2908 unsigned int sample_mask;
2909 struct wined3d_depth_stencil_state *depth_stencil_state;
2910 unsigned int stencil_ref;
2911 bool depth_bounds_enable;
2912 float depth_bounds_min, depth_bounds_max;
2913 struct wined3d_rasterizer_state *rasterizer_state;
2916 void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
2917 void state_init(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info,
2918 uint32_t flags, enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
2919 void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN;
2921 static inline void wined3d_state_reset(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info)
2923 enum wined3d_feature_level feature_level = state->feature_level;
2924 uint32_t flags = state->flags;
2926 memset(state, 0, sizeof(*state));
2927 state_init(state, d3d_info, flags, feature_level);
2930 static inline bool wined3d_state_uses_depth_buffer(const struct wined3d_state *state)
2932 if (!state->depth_stencil_state)
2933 return true;
2934 return state->depth_stencil_state->desc.depth || state->depth_stencil_state->desc.depth_write
2935 || state->depth_stencil_state->desc.stencil;
2938 #define WINED3D_UNMAPPED_STAGE ~0u
2940 /* Multithreaded flag. Removed from the public header to signal that
2941 * wined3d_device_create() ignores it. */
2942 #define WINED3DCREATE_MULTITHREADED 0x00000004
2944 struct wined3d_so_desc_entry
2946 struct wine_rb_entry entry;
2947 struct wined3d_stream_output_desc desc;
2948 struct wined3d_stream_output_element elements[1];
2951 struct wined3d_device
2953 LONG ref;
2955 /* WineD3D Information */
2956 struct wined3d_device_parent *device_parent;
2957 struct wined3d *wined3d;
2958 struct wined3d_adapter *adapter;
2960 const struct wined3d_shader_backend_ops *shader_backend;
2961 void *shader_priv;
2962 void *fragment_priv;
2963 void *vertex_priv;
2964 struct wined3d_state_entry state_table[STATE_HIGHEST + 1];
2965 /* Array of functions for states which are handled by more than one pipeline part */
2966 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
2967 struct wined3d_blitter *blitter;
2969 BYTE bCursorVisible : 1;
2970 BYTE d3d_initialized : 1;
2971 BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
2972 BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
2973 BYTE restore_screensaver : 1;
2974 BYTE padding : 3;
2976 unsigned char surface_alignment; /* Line Alignment of surfaces */
2978 WORD padding2 : 16;
2980 /* Internal use fields */
2981 struct wined3d_device_creation_parameters create_parms;
2982 HWND focus_window;
2984 struct wined3d_rendertarget_view *back_buffer_view;
2985 struct wined3d_swapchain **swapchains;
2986 UINT swapchain_count;
2987 unsigned int max_frame_latency;
2989 struct list resources; /* a linked list to track resources created by the device */
2990 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
2991 struct wine_rb_tree so_descs;
2992 struct wine_rb_tree samplers, rasterizer_states, blend_states, depth_stencil_states;
2994 /* Render Target Support */
2995 struct wined3d_rendertarget_view *auto_depth_stencil_view;
2997 /* Cursor management */
2998 UINT xHotSpot;
2999 UINT yHotSpot;
3000 UINT xScreenSpace;
3001 UINT yScreenSpace;
3002 UINT cursorWidth, cursorHeight;
3003 struct wined3d_texture *cursor_texture;
3004 HCURSOR hardwareCursor;
3006 /* The Wine logo texture */
3007 struct wined3d_texture *logo_texture;
3009 /* Default sampler used to emulate the direct resource access without using wined3d_sampler */
3010 struct wined3d_sampler *default_sampler;
3011 struct wined3d_sampler *null_sampler;
3013 /* Command stream */
3014 struct wined3d_cs *cs;
3016 struct wined3d_buffer *push_constants[WINED3D_PUSH_CONSTANTS_COUNT];
3018 /* Context management */
3019 struct wined3d_context **contexts;
3020 UINT context_count;
3022 CRITICAL_SECTION bo_map_lock;
3025 void wined3d_device_cleanup(struct wined3d_device *device) DECLSPEC_HIDDEN;
3026 BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
3027 void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
3028 void wined3d_device_create_default_samplers(struct wined3d_device *device,
3029 struct wined3d_context *context) DECLSPEC_HIDDEN;
3030 void wined3d_device_destroy_default_samplers(struct wined3d_device *device) DECLSPEC_HIDDEN;
3031 HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
3032 unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
3033 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
3034 const BOOL *supported_extensions, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN;
3035 LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
3036 UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
3037 void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3038 void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3039 void device_invalidate_state(const struct wined3d_device *device, unsigned int state) DECLSPEC_HIDDEN;
3040 HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device,
3041 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
3042 void wined3d_device_uninit_3d(struct wined3d_device *device) DECLSPEC_HIDDEN;
3044 static inline void wined3d_device_bo_map_lock(struct wined3d_device *device)
3046 EnterCriticalSection(&device->bo_map_lock);
3049 static inline void wined3d_device_bo_map_unlock(struct wined3d_device *device)
3051 LeaveCriticalSection(&device->bo_map_lock);
3054 struct wined3d_device_no3d
3056 struct wined3d_device d;
3058 struct wined3d_context context_no3d;
3061 static inline struct wined3d_device_no3d *wined3d_device_no3d(struct wined3d_device *device)
3063 return CONTAINING_RECORD(device, struct wined3d_device_no3d, d);
3066 #define WINED3D_ALLOCATOR_CHUNK_SIZE (64 * 1024 * 1024)
3067 #define WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT 15
3068 #define WINED3D_ALLOCATOR_MIN_BLOCK_SIZE (WINED3D_ALLOCATOR_CHUNK_SIZE >> (WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT - 1))
3069 #define WINED3D_SLAB_BO_MIN_OBJECT_ALIGN 16
3070 #define WINED3D_RETIRED_BO_SIZE_THRESHOLD (64 * 1024 * 1024)
3072 struct wined3d_allocator_chunk
3074 struct list entry;
3075 struct list available[WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT];
3076 struct wined3d_allocator *allocator;
3077 unsigned int map_count;
3078 void *map_ptr;
3081 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk *chunk) DECLSPEC_HIDDEN;
3082 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk *chunk,
3083 struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
3085 struct wined3d_allocator_block
3087 struct list entry;
3088 struct wined3d_allocator_chunk *chunk;
3089 struct wined3d_allocator_block *parent, *sibling;
3090 unsigned int order;
3091 size_t offset;
3092 bool free;
3095 void wined3d_allocator_block_free(struct wined3d_allocator_block *block) DECLSPEC_HIDDEN;
3097 struct wined3d_allocator_pool
3099 struct list chunks;
3102 struct wined3d_allocator_ops
3104 struct wined3d_allocator_chunk *(*allocator_create_chunk)(struct wined3d_allocator *allocator,
3105 struct wined3d_context *context, unsigned int memory_type, size_t chunk_size);
3106 void (*allocator_destroy_chunk)(struct wined3d_allocator_chunk *chunk);
3109 struct wined3d_allocator
3111 const struct wined3d_allocator_ops *ops;
3112 struct wined3d_allocator_pool *pools;
3113 size_t pool_count;
3114 struct wined3d_allocator_block *free;
3117 struct wined3d_allocator_block *wined3d_allocator_allocate(struct wined3d_allocator *allocator,
3118 struct wined3d_context *context, unsigned int memory_type, size_t size) DECLSPEC_HIDDEN;
3119 void wined3d_allocator_cleanup(struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
3120 bool wined3d_allocator_init(struct wined3d_allocator *allocator,
3121 size_t pool_count, const struct wined3d_allocator_ops *allocator_ops) DECLSPEC_HIDDEN;
3123 static inline float wined3d_alpha_ref(const struct wined3d_state *state)
3125 return (state->render_states[WINED3D_RS_ALPHAREF] & 0xff) / 255.0f;
3128 const char *wined3d_debug_resource_access(uint32_t access) DECLSPEC_HIDDEN;
3129 const char *wined3d_debug_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
3130 const char *wined3d_debug_view_desc(const struct wined3d_view_desc *d,
3131 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3133 static inline ULONG wined3d_atomic_decrement_mutex_lock(volatile LONG *refcount)
3135 ULONG count, old_count = *refcount;
3138 if ((count = old_count) == 1)
3140 wined3d_mutex_lock();
3141 count = InterlockedDecrement(refcount);
3142 if (count) wined3d_mutex_unlock();
3143 return count;
3146 old_count = InterlockedCompareExchange(refcount, count - 1, count);
3148 while (old_count != count);
3150 return count - 1;
3153 #define CLIENT_BO_DISCARDED ((struct wined3d_bo *)~(UINT_PTR)0)
3155 struct wined3d_client_resource
3157 /* The resource's persistently mapped address, which we may use to perform
3158 * NOOVERWRITE maps from the client thread. */
3159 struct wined3d_bo_address addr;
3161 /* The currently mapped upload BO, if applicable, and box. */
3162 struct upload_bo mapped_upload;
3163 struct wined3d_box mapped_box;
3166 static inline BOOL wined3d_resource_access_is_managed(unsigned int access)
3168 return !(~access & (WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU));
3171 struct wined3d_resource_ops
3173 ULONG (*resource_incref)(struct wined3d_resource *resource);
3174 ULONG (*resource_decref)(struct wined3d_resource *resource);
3175 void (*resource_preload)(struct wined3d_resource *resource);
3176 void (*resource_unload)(struct wined3d_resource *resource);
3177 HRESULT (*resource_sub_resource_get_desc)(struct wined3d_resource *resource,
3178 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc);
3179 void (*resource_sub_resource_get_map_pitch)(struct wined3d_resource *resource,
3180 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch);
3181 HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3182 void **map_ptr, const struct wined3d_box *box, uint32_t flags);
3183 HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
3186 struct wined3d_resource
3188 LONG ref;
3189 LONG bind_count;
3190 LONG map_count;
3191 ULONG access_time;
3192 struct wined3d_device *device;
3193 enum wined3d_resource_type type;
3194 enum wined3d_gl_resource_type gl_type;
3195 const struct wined3d_format *format;
3196 unsigned int format_attrs;
3197 unsigned int format_caps;
3198 enum wined3d_multisample_type multisample_type;
3199 UINT multisample_quality;
3200 uint32_t usage;
3201 unsigned int bind_flags;
3202 unsigned int access;
3203 WORD draw_binding;
3204 WORD map_binding;
3205 UINT width;
3206 UINT height;
3207 UINT depth;
3208 UINT size;
3209 unsigned int priority;
3210 void *heap_memory;
3212 uint32_t pin_sysmem : 1;
3214 struct wined3d_client_resource client;
3216 void *parent;
3217 const struct wined3d_parent_ops *parent_ops;
3218 const struct wined3d_resource_ops *resource_ops;
3220 struct list resource_list_entry;
3222 LONG srv_bind_count_device;
3223 LONG rtv_bind_count_device;
3226 static inline ULONG wined3d_resource_incref(struct wined3d_resource *resource)
3228 return resource->resource_ops->resource_incref(resource);
3231 static inline ULONG wined3d_resource_decref(struct wined3d_resource *resource)
3233 return resource->resource_ops->resource_decref(resource);
3236 static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_resource *resource,
3237 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
3239 return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc);
3242 static inline void wined3d_resource_get_sub_resource_map_pitch(struct wined3d_resource *resource,
3243 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
3245 resource->resource_ops->resource_sub_resource_get_map_pitch(resource, sub_resource_idx, row_pitch, slice_pitch);
3248 void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3249 HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
3250 enum wined3d_resource_type type, const struct wined3d_format *format,
3251 enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, unsigned int usage,
3252 unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
3253 unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
3254 const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
3255 void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3256 uint8_t *base_memory, const struct wined3d_box *box) DECLSPEC_HIDDEN;
3257 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3258 HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource,
3259 unsigned int sub_resource_idx, const struct wined3d_box *box) DECLSPEC_HIDDEN;
3260 void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3261 const struct wined3d_format *wined3d_resource_get_decompress_format(
3262 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3263 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3264 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3265 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3266 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3267 void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
3268 const struct wined3d_map_desc *map, const struct wined3d_color *colour,
3269 const struct wined3d_box *box, bool full_subresource) DECLSPEC_HIDDEN;
3271 /* Tests show that the start address of resources is 32 byte aligned */
3272 #define RESOURCE_ALIGNMENT 16
3273 #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16
3275 #define WINED3D_LOCATION_DISCARDED 0x00000001
3276 #define WINED3D_LOCATION_SYSMEM 0x00000002
3277 #define WINED3D_LOCATION_CLEARED 0x00000004
3278 #define WINED3D_LOCATION_BUFFER 0x00000008
3279 #define WINED3D_LOCATION_TEXTURE_RGB 0x00000010
3280 #define WINED3D_LOCATION_TEXTURE_SRGB 0x00000020
3281 #define WINED3D_LOCATION_DRAWABLE 0x00000040
3282 #define WINED3D_LOCATION_RB_MULTISAMPLE 0x00000080
3283 #define WINED3D_LOCATION_RB_RESOLVED 0x00000100
3285 const char *wined3d_debug_location(uint32_t location) DECLSPEC_HIDDEN;
3287 struct wined3d_texture_ops
3289 BOOL (*texture_prepare_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3290 struct wined3d_context *context, unsigned int location);
3291 BOOL (*texture_load_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3292 struct wined3d_context *context, unsigned int location);
3293 void (*texture_unload_location)(struct wined3d_texture *texture,
3294 struct wined3d_context *context, unsigned int location);
3295 void (*texture_upload_data)(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr,
3296 const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch,
3297 unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3298 unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z);
3299 void (*texture_download_data)(struct wined3d_context *context, struct wined3d_texture *src_texture,
3300 unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box,
3301 const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format,
3302 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z,
3303 unsigned int dst_row_pitch, unsigned int dst_slice_pitch);
3306 #define WINED3D_TEXTURE_COND_NP2 0x00000001
3307 #define WINED3D_TEXTURE_COND_NP2_EMULATED 0x00000002
3308 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000004
3309 #define WINED3D_TEXTURE_IS_SRGB 0x00000008
3310 #define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000010
3311 #define WINED3D_TEXTURE_RGB_VALID 0x00000020
3312 #define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000040
3313 #define WINED3D_TEXTURE_SRGB_VALID 0x00000080
3314 #define WINED3D_TEXTURE_CONVERTED 0x00000100
3315 #define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
3316 #define WINED3D_TEXTURE_GET_DC_LENIENT 0x00000800
3317 #define WINED3D_TEXTURE_DC_IN_USE 0x00001000
3318 #define WINED3D_TEXTURE_DISCARD 0x00002000
3319 #define WINED3D_TEXTURE_GET_DC 0x00004000
3320 #define WINED3D_TEXTURE_GENERATE_MIPMAPS 0x00008000
3321 #define WINED3D_TEXTURE_DOWNLOADABLE 0x00010000
3323 #define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001
3325 struct wined3d_texture
3327 struct wined3d_resource resource;
3328 const struct wined3d_texture_ops *texture_ops;
3329 struct wined3d_swapchain *swapchain;
3330 unsigned int pow2_width;
3331 unsigned int pow2_height;
3332 UINT layer_count;
3333 unsigned int level_count;
3334 unsigned int download_count;
3335 unsigned int sysmem_count;
3336 float pow2_matrix[16];
3337 unsigned int lod;
3338 DWORD sampler;
3339 uint32_t flags;
3340 DWORD update_map_binding;
3342 unsigned int row_pitch;
3343 unsigned int slice_pitch;
3345 /* May only be accessed from the command stream worker thread. */
3346 struct wined3d_texture_async
3348 uint32_t flags;
3350 /* Color keys for DDraw */
3351 struct wined3d_color_key dst_blt_color_key;
3352 struct wined3d_color_key src_blt_color_key;
3353 struct wined3d_color_key dst_overlay_color_key;
3354 struct wined3d_color_key src_overlay_color_key;
3355 struct wined3d_color_key gl_color_key;
3356 DWORD color_key_flags;
3357 } async;
3359 struct wined3d_dirty_regions
3361 struct wined3d_box *boxes;
3362 SIZE_T boxes_size;
3363 unsigned int box_count;
3364 } *dirty_regions;
3366 struct wined3d_overlay_info
3368 struct list entry;
3369 struct list overlays;
3370 struct wined3d_texture *dst_texture;
3371 unsigned int dst_sub_resource_idx;
3372 RECT src_rect;
3373 RECT dst_rect;
3374 } *overlay_info;
3376 struct wined3d_dc_info
3378 HBITMAP bitmap;
3379 HDC dc;
3380 } *dc_info;
3382 struct wined3d_texture_sub_resource
3384 void *parent;
3385 const struct wined3d_parent_ops *parent_ops;
3387 unsigned int offset;
3388 unsigned int size;
3390 unsigned int map_count;
3391 uint32_t map_flags;
3392 DWORD locations;
3393 struct wined3d_bo *bo;
3394 union
3396 struct wined3d_color colour;
3397 struct
3399 float depth;
3400 unsigned int stencil;
3402 } clear_value;
3404 void *user_memory;
3405 } *sub_resources;
3408 static inline void *wined3d_texture_allocate_object_memory(SIZE_T s, SIZE_T level_count, SIZE_T layer_count)
3410 struct wined3d_texture *t;
3412 if (level_count > ((~(SIZE_T)0 - s) / sizeof(*t->sub_resources)) / layer_count)
3413 return NULL;
3415 return heap_alloc_zero(s + level_count * layer_count * sizeof(*t->sub_resources));
3418 static inline struct wined3d_texture *texture_from_resource(struct wined3d_resource *resource)
3420 return CONTAINING_RECORD(resource, struct wined3d_texture, resource);
3423 static inline unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture,
3424 unsigned int level)
3426 return max(1, texture->resource.width >> level);
3429 static inline unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture,
3430 unsigned int level)
3432 return max(1, texture->resource.height >> level);
3435 static inline unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture,
3436 unsigned int level)
3438 return max(1, texture->resource.depth >> level);
3441 static inline unsigned int wined3d_texture_get_level_pow2_width(const struct wined3d_texture *texture,
3442 unsigned int level)
3444 return max(1, texture->pow2_width >> level);
3447 static inline unsigned int wined3d_texture_get_level_pow2_height(const struct wined3d_texture *texture,
3448 unsigned int level)
3450 return max(1, texture->pow2_height >> level);
3453 static inline void wined3d_texture_get_level_box(const struct wined3d_texture *texture,
3454 unsigned int level, struct wined3d_box *box)
3456 wined3d_box_set(box, 0, 0,
3457 wined3d_texture_get_level_width(texture, level),
3458 wined3d_texture_get_level_height(texture, level),
3459 0, wined3d_texture_get_level_depth(texture, level));
3462 static inline bool wined3d_texture_is_full_rect(const struct wined3d_texture *texture,
3463 unsigned int level, const RECT *r)
3465 unsigned int t;
3467 t = wined3d_texture_get_level_width(texture, level);
3468 if ((r->left && r->right) || abs(r->right - r->left) != t)
3469 return false;
3470 t = wined3d_texture_get_level_height(texture, level);
3471 if ((r->top && r->bottom) || abs(r->bottom - r->top) != t)
3472 return false;
3473 return true;
3476 HRESULT texture2d_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3477 const struct wined3d_box *dst_box, struct wined3d_texture *src_texture,
3478 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, uint32_t flags,
3479 const struct wined3d_blt_fx *blt_fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
3481 void wined3d_texture_cleanup(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3482 void wined3d_texture_download_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3483 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx) DECLSPEC_HIDDEN;
3484 void wined3d_texture_get_bo_address(const struct wined3d_texture *texture,
3485 unsigned int sub_resource_idx, struct wined3d_bo_address *data, uint32_t location) DECLSPEC_HIDDEN;
3486 void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
3487 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
3488 void wined3d_texture_load(struct wined3d_texture *texture,
3489 struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
3490 BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
3491 unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3492 BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3493 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3494 void wined3d_texture_set_swapchain(struct wined3d_texture *texture,
3495 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
3496 BOOL wined3d_texture_can_use_pbo(const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
3497 DECLSPEC_HIDDEN;
3498 void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3499 void wined3d_texture_translate_drawable_coords(const struct wined3d_texture *texture,
3500 HWND window, RECT *rect) DECLSPEC_HIDDEN;
3501 void wined3d_texture_update_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3502 struct wined3d_context *context, const struct upload_bo *upload_bo, const struct wined3d_box *box,
3503 unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
3504 void wined3d_texture_upload_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3505 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, struct wined3d_texture *src_texture,
3506 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box) DECLSPEC_HIDDEN;
3507 void wined3d_texture_validate_location(struct wined3d_texture *texture,
3508 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
3509 bool wined3d_texture_validate_sub_resource_idx(const struct wined3d_texture *texture,
3510 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
3511 void wined3d_texture_clear_dirty_regions(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3513 HRESULT wined3d_texture_no3d_init(struct wined3d_texture *texture_no3d, struct wined3d_device *device,
3514 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
3515 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3517 struct wined3d_sampler
3519 struct wine_rb_entry entry;
3520 LONG refcount;
3521 struct wined3d_device *device;
3522 void *parent;
3523 const struct wined3d_parent_ops *parent_ops;
3524 struct wined3d_sampler_desc desc;
3527 struct wined3d_vertex_declaration_element
3529 const struct wined3d_format *format;
3530 BOOL ffp_valid;
3531 unsigned int input_slot;
3532 unsigned int offset;
3533 unsigned int output_slot;
3534 enum wined3d_input_classification input_slot_class;
3535 unsigned int instance_data_step_rate;
3536 BYTE method;
3537 BYTE usage;
3538 BYTE usage_idx;
3541 struct wined3d_vertex_declaration
3543 LONG ref;
3544 void *parent;
3545 const struct wined3d_parent_ops *parent_ops;
3546 struct wined3d_device *device;
3548 struct wined3d_vertex_declaration_element *elements;
3549 unsigned int element_count;
3551 BOOL position_transformed;
3554 struct wined3d_saved_states
3556 uint32_t vs_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_VS_CONSTS_F)];
3557 WORD vertexShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
3558 WORD vertexShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
3559 uint32_t ps_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_PS_CONSTS_F)];
3560 WORD pixelShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
3561 WORD pixelShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
3562 uint32_t transform[WINED3D_BITMAP_SIZE(WINED3D_HIGHEST_TRANSFORM_STATE + 1)];
3563 WORD streamSource; /* WINED3D_MAX_STREAMS, 16 */
3564 WORD streamFreq; /* WINED3D_MAX_STREAMS, 16 */
3565 uint32_t renderState[WINED3D_BITMAP_SIZE(WINEHIGHEST_RENDER_STATE + 1)];
3566 DWORD textureState[WINED3D_MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
3567 WORD samplerState[WINED3D_MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
3568 DWORD clipplane; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
3569 DWORD textures : 20; /* WINED3D_MAX_COMBINED_SAMPLERS, 20 */
3570 DWORD indices : 1;
3571 DWORD material : 1;
3572 DWORD viewport : 1;
3573 DWORD vertexDecl : 1;
3574 DWORD pixelShader : 1;
3575 DWORD vertexShader : 1;
3576 DWORD scissorRect : 1;
3577 DWORD store_stream_offset : 1;
3578 DWORD alpha_to_coverage : 1;
3579 DWORD lights : 1;
3580 DWORD transforms : 1;
3581 DWORD padding : 1;
3583 struct list changed_lights;
3586 struct StageState {
3587 DWORD stage;
3588 DWORD state;
3591 struct wined3d_stateblock
3593 LONG ref; /* Note: Ref counting not required */
3594 struct wined3d_device *device;
3596 /* Array indicating whether things have been set or changed */
3597 struct wined3d_saved_states changed;
3599 struct wined3d_stateblock_state stateblock_state;
3600 struct wined3d_light_state light_state;
3602 /* Contained state management */
3603 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
3604 unsigned int num_contained_render_states;
3605 DWORD contained_transform_states[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
3606 unsigned int num_contained_transform_states;
3607 struct StageState contained_tss_states[WINED3D_MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
3608 unsigned int num_contained_tss_states;
3609 struct StageState contained_sampler_states[WINED3D_MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
3610 unsigned int num_contained_sampler_states;
3613 void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state,
3614 const struct wined3d_device *device, uint32_t flags) DECLSPEC_HIDDEN;
3615 void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) DECLSPEC_HIDDEN;
3617 bool wined3d_light_state_enable_light(struct wined3d_light_state *state, const struct wined3d_d3d_info *d3d_info,
3618 struct wined3d_light_info *light_info, BOOL enable) DECLSPEC_HIDDEN;
3619 struct wined3d_light_info *wined3d_light_state_get_light(const struct wined3d_light_state *state,
3620 unsigned int idx) DECLSPEC_HIDDEN;
3621 HRESULT wined3d_light_state_set_light(struct wined3d_light_state *state, DWORD light_idx,
3622 const struct wined3d_light *params, struct wined3d_light_info **light_info) DECLSPEC_HIDDEN;
3624 enum wined3d_cs_queue_id
3626 WINED3D_CS_QUEUE_DEFAULT = 0,
3627 WINED3D_CS_QUEUE_MAP,
3628 WINED3D_CS_QUEUE_COUNT,
3631 #define WINED3D_CS_QUERY_POLL_INTERVAL 10u
3632 #if defined(_WIN64)
3633 #define WINED3D_CS_QUEUE_SIZE 0x1000000u
3634 #else
3635 #define WINED3D_CS_QUEUE_SIZE 0x400000u
3636 #endif
3637 #define WINED3D_CS_SPIN_COUNT 2000u
3638 #define WINED3D_CS_QUEUE_MASK (WINED3D_CS_QUEUE_SIZE - 1)
3640 C_ASSERT(!(WINED3D_CS_QUEUE_SIZE & (WINED3D_CS_QUEUE_SIZE - 1)));
3642 struct wined3d_cs_queue
3644 ULONG head, tail;
3645 BYTE data[WINED3D_CS_QUEUE_SIZE];
3648 struct wined3d_device_context_ops
3650 void *(*require_space)(struct wined3d_device_context *context, size_t size, enum wined3d_cs_queue_id queue_id);
3651 void (*submit)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
3652 void (*finish)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
3653 bool (*map_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
3654 unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
3655 const struct wined3d_box *box, uint32_t flags);
3656 bool (*unmap_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
3657 unsigned int sub_resource_idx, struct wined3d_box *box, struct upload_bo *upload_bo);
3658 void (*issue_query)(struct wined3d_device_context *context, struct wined3d_query *query, unsigned int flags);
3659 void (*flush)(struct wined3d_device_context *context);
3660 void (*reference_resource)(struct wined3d_device_context *context, struct wined3d_resource *resource);
3661 void (*reference_command_list)(struct wined3d_device_context *context, struct wined3d_command_list *list);
3664 struct wined3d_device_context
3666 const struct wined3d_device_context_ops *ops;
3667 struct wined3d_device *device;
3668 struct wined3d_state *state;
3671 struct wined3d_cs
3673 struct wined3d_device_context c;
3675 struct wined3d_state state;
3676 HMODULE wined3d_module;
3677 HANDLE thread;
3678 DWORD thread_id;
3679 BOOL serialize_commands;
3681 struct wined3d_cs_queue queue[WINED3D_CS_QUEUE_COUNT];
3682 size_t data_size, start, end;
3683 void *data;
3684 struct list query_poll_list;
3685 BOOL queries_flushed;
3687 HANDLE event, present_event;
3688 LONG waiting_for_event;
3689 LONG waiting_for_present;
3690 LONG pending_presents;
3693 static inline void wined3d_device_context_lock(struct wined3d_device_context *context)
3695 if (context == &context->device->cs->c)
3696 wined3d_mutex_lock();
3699 static inline void wined3d_device_context_unlock(struct wined3d_device_context *context)
3701 if (context == &context->device->cs->c)
3702 wined3d_mutex_unlock();
3705 struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
3706 const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN;
3707 void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
3708 void wined3d_cs_destroy_object(struct wined3d_cs *cs,
3709 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
3710 void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs *cs,
3711 struct wined3d_texture *texture, unsigned int layer) DECLSPEC_HIDDEN;
3712 void wined3d_cs_emit_clear(struct wined3d_cs *cs, DWORD rect_count, const RECT *rects,
3713 uint32_t flags, const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
3714 void wined3d_device_context_emit_clear_uav(struct wined3d_device_context *context,
3715 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp) DECLSPEC_HIDDEN;
3716 void wined3d_cs_emit_preload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3717 void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *swapchain, const RECT *src_rect,
3718 const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags) DECLSPEC_HIDDEN;
3719 void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture *texture,
3720 WORD flags, const struct wined3d_color_key *color_key) DECLSPEC_HIDDEN;
3721 void wined3d_cs_emit_set_render_state(struct wined3d_cs *cs,
3722 enum wined3d_render_state state, DWORD value) DECLSPEC_HIDDEN;
3723 void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3724 void wined3d_cs_init_object(struct wined3d_cs *cs,
3725 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
3726 void wined3d_cs_map_bo_address(struct wined3d_cs *cs,
3727 struct wined3d_bo_address *addr, size_t size, unsigned int flags) DECLSPEC_HIDDEN;
3728 void wined3d_device_context_set_depth_bounds(struct wined3d_device_context *context,
3729 bool enable, float min_depth, float max_depth);
3731 static inline void wined3d_cs_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
3733 cs->c.ops->finish(&cs->c, queue_id);
3736 void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context *context,
3737 struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, const struct wined3d_box *dst_box,
3738 struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box,
3739 unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
3740 void wined3d_device_context_emit_clear_rendertarget_view(struct wined3d_device_context *context,
3741 struct wined3d_rendertarget_view *view, const RECT *rect, unsigned int flags,
3742 const struct wined3d_color *color, float depth, unsigned int stencil) DECLSPEC_HIDDEN;
3743 void wined3d_device_context_emit_copy_uav_counter(struct wined3d_device_context *context,
3744 struct wined3d_buffer *dst_buffer, unsigned int offset,
3745 struct wined3d_unordered_access_view *uav) DECLSPEC_HIDDEN;
3746 void wined3d_device_context_emit_draw(struct wined3d_device_context *context,
3747 enum wined3d_primitive_type primitive_type, unsigned int patch_vertex_count, int base_vertex_idx,
3748 unsigned int start_idx, unsigned int index_count, unsigned int start_instance, unsigned int instance_count,
3749 bool indexed) DECLSPEC_HIDDEN;
3750 void wined3d_device_context_emit_execute_command_list(struct wined3d_device_context *context,
3751 struct wined3d_command_list *list, bool restore_state) DECLSPEC_HIDDEN;
3752 void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context *context,
3753 struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
3754 HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
3755 struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
3756 const struct wined3d_box *box, unsigned int flags) DECLSPEC_HIDDEN;
3757 void wined3d_device_context_emit_reset_state(struct wined3d_device_context *context, bool invalidate) DECLSPEC_HIDDEN;
3758 void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context *context,
3759 struct wined3d_blend_state *state, const struct wined3d_color *blend_factor,
3760 unsigned int sample_mask) DECLSPEC_HIDDEN;
3761 void wined3d_device_context_emit_set_clip_plane(struct wined3d_device_context *context, unsigned int plane_idx,
3762 const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN;
3763 void wined3d_device_context_emit_set_constant_buffers(struct wined3d_device_context *context,
3764 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
3765 const struct wined3d_constant_buffer_state *buffers) DECLSPEC_HIDDEN;
3766 void wined3d_device_context_emit_set_depth_stencil_state(struct wined3d_device_context *context,
3767 struct wined3d_depth_stencil_state *state, unsigned int stencil_ref) DECLSPEC_HIDDEN;
3768 void wined3d_device_context_emit_set_depth_stencil_view(struct wined3d_device_context *context,
3769 struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
3770 void wined3d_device_context_emit_set_feature_level(struct wined3d_device_context *context,
3771 enum wined3d_feature_level level) DECLSPEC_HIDDEN;
3772 void wined3d_device_context_emit_set_index_buffer(struct wined3d_device_context *context, struct wined3d_buffer *buffer,
3773 enum wined3d_format_id format_id, unsigned int offset) DECLSPEC_HIDDEN;
3774 void wined3d_device_context_emit_set_light(struct wined3d_device_context *context,
3775 const struct wined3d_light_info *light) DECLSPEC_HIDDEN;
3776 void wined3d_device_context_emit_set_light_enable(struct wined3d_device_context *context, unsigned int idx,
3777 BOOL enable) DECLSPEC_HIDDEN;
3778 void wined3d_device_context_emit_set_material(struct wined3d_device_context *context,
3779 const struct wined3d_material *material) DECLSPEC_HIDDEN;
3780 void wined3d_device_context_emit_set_predication(struct wined3d_device_context *context,
3781 struct wined3d_query *predicate, BOOL value) DECLSPEC_HIDDEN;
3782 void wined3d_device_context_emit_set_rasterizer_state(struct wined3d_device_context *context,
3783 struct wined3d_rasterizer_state *rasterizer_state) DECLSPEC_HIDDEN;
3784 void wined3d_device_context_emit_set_render_state(struct wined3d_device_context *context,
3785 enum wined3d_render_state state, unsigned int value) DECLSPEC_HIDDEN;
3786 void wined3d_device_context_emit_set_rendertarget_views(struct wined3d_device_context *context, unsigned int start_idx,
3787 unsigned int count, struct wined3d_rendertarget_view *const *views) DECLSPEC_HIDDEN;
3788 void wined3d_device_context_emit_set_samplers(struct wined3d_device_context *context, enum wined3d_shader_type type,
3789 unsigned int start_idx, unsigned int count, struct wined3d_sampler *const *samplers) DECLSPEC_HIDDEN;
3790 void wined3d_device_context_emit_set_sampler_state(struct wined3d_device_context *context, unsigned int sampler_idx,
3791 enum wined3d_sampler_state state, unsigned int value) DECLSPEC_HIDDEN;
3792 void wined3d_device_context_emit_set_scissor_rects(struct wined3d_device_context *context,
3793 unsigned int rect_count, const RECT *rects) DECLSPEC_HIDDEN;
3794 void wined3d_device_context_emit_set_shader(struct wined3d_device_context *context, enum wined3d_shader_type type,
3795 struct wined3d_shader *shader) DECLSPEC_HIDDEN;
3796 void wined3d_device_context_emit_set_shader_resource_views(struct wined3d_device_context *context,
3797 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
3798 struct wined3d_shader_resource_view *const *views) DECLSPEC_HIDDEN;
3799 void wined3d_device_context_emit_set_stream_outputs(struct wined3d_device_context *context,
3800 const struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]) DECLSPEC_HIDDEN;
3801 void wined3d_device_context_emit_set_stream_sources(struct wined3d_device_context *context,
3802 unsigned int start_idx, unsigned int count, const struct wined3d_stream_state *streams) DECLSPEC_HIDDEN;
3803 void wined3d_device_context_emit_set_texture(struct wined3d_device_context *context, unsigned int stage,
3804 struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3805 void wined3d_device_context_emit_set_texture_state(struct wined3d_device_context *context, unsigned int stage,
3806 enum wined3d_texture_stage_state state, unsigned int value) DECLSPEC_HIDDEN;
3807 void wined3d_device_context_emit_set_transform(struct wined3d_device_context *context,
3808 enum wined3d_transform_state state, const struct wined3d_matrix *matrix) DECLSPEC_HIDDEN;
3809 void wined3d_device_context_emit_set_unordered_access_views(struct wined3d_device_context *context,
3810 enum wined3d_pipeline pipeline, unsigned int start_idx, unsigned int count,
3811 struct wined3d_unordered_access_view *const *views, const unsigned int *initial_count) DECLSPEC_HIDDEN;
3812 void wined3d_device_context_emit_set_vertex_declaration(struct wined3d_device_context *context,
3813 struct wined3d_vertex_declaration *declaration) DECLSPEC_HIDDEN;
3814 void wined3d_device_context_emit_set_viewports(struct wined3d_device_context *context, unsigned int viewport_count,
3815 const struct wined3d_viewport *viewports) DECLSPEC_HIDDEN;
3816 void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context,
3817 struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box,
3818 const void *data, unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
3819 HRESULT wined3d_device_context_emit_unmap(struct wined3d_device_context *context,
3820 struct wined3d_resource *resource, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
3821 void wined3d_device_context_push_constants(struct wined3d_device_context *context,
3822 enum wined3d_push_constants type, unsigned int start_idx,
3823 unsigned int count, const void *constants) DECLSPEC_HIDDEN;
3825 static inline void wined3d_resource_reference(struct wined3d_resource *resource)
3827 const struct wined3d_cs *cs = resource->device->cs;
3828 resource->access_time = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
3831 static inline BOOL wined3d_ge_wrap(ULONG x, ULONG y)
3833 return (x - y) < UINT_MAX / 2;
3835 C_ASSERT(WINED3D_CS_QUEUE_SIZE < UINT_MAX / 4);
3837 static inline void wined3d_resource_wait_idle(const struct wined3d_resource *resource)
3839 const struct wined3d_cs *cs = resource->device->cs;
3840 ULONG access_time, tail, head;
3842 if (!cs->thread || cs->thread_id == GetCurrentThreadId())
3843 return;
3845 access_time = resource->access_time;
3846 head = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
3848 /* The basic idea is that a resource is busy if tail < access_time <= head.
3849 * But we have to be careful about wrap-around of the head and tail. The
3850 * wined3d_ge_wrap function considers x >= y if x - y is smaller than half the
3851 * UINT range. Head is at most WINED3D_CS_QUEUE_SIZE ahead of tail, because
3852 * otherwise the queue memory is considered full and queue_require_space
3853 * stalls. Thus wined3d_ge_wrap(head, tail) is always true. The C_ASSERT above
3854 * ensures this in case we decide to grow the queue size in the future.
3856 * It is possible that a resource has not been used for a long time and is idle, but the head and
3857 * tail wrapped around in such a way that the previously set access time falls between head and tail.
3858 * In this case we will incorrectly wait for the resource. Because we use the entire 32 bits of the
3859 * counters and not just the bits needed to address the actual queue memory, this should happen rarely.
3860 * If it turns out to be a problem we can switch to 64 bit counters or attempt to somehow mark the
3861 * access time of resources invalid. CS packets are at least 4 byte aligned, so we could use the lower
3862 * 2 bits in access_time for such a marker.
3864 * Note that the access time is set before the command is submitted, so we have to wait until the
3865 * tail is bigger than access_time, not equal. */
3867 if (!wined3d_ge_wrap(head, access_time))
3868 return;
3870 for (;;)
3872 tail = *(volatile ULONG *)&cs->queue[WINED3D_CS_QUEUE_DEFAULT].tail;
3873 if (head == tail) /* Queue empty. */
3874 break;
3876 if (!wined3d_ge_wrap(access_time, tail) && access_time != tail)
3877 break;
3879 YieldProcessor();
3883 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
3884 * fixed function semantics as D3DCOLOR or FLOAT16 */
3885 enum wined3d_buffer_conversion_type
3887 CONV_NONE,
3888 CONV_D3DCOLOR,
3889 CONV_POSITIONT,
3892 struct wined3d_buffer
3894 struct wined3d_resource resource;
3895 const struct wined3d_buffer_ops *buffer_ops;
3897 unsigned int structure_byte_stride;
3898 uint32_t flags;
3899 DWORD locations;
3900 void *map_ptr;
3901 struct wined3d_bo *buffer_object;
3902 struct wined3d_bo_user bo_user;
3904 struct wined3d_range *maps;
3905 SIZE_T maps_size, modified_areas;
3907 /* conversion stuff */
3908 UINT decl_change_count, full_conversion_count;
3909 UINT draw_count;
3910 UINT stride; /* 0 if no conversion */
3911 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
3912 UINT conversion_stride; /* 0 if no shifted conversion */
3915 static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resource *resource)
3917 return CONTAINING_RECORD(resource, struct wined3d_buffer, resource);
3920 static inline void wined3d_buffer_validate_user(struct wined3d_buffer *buffer)
3922 if (buffer->bo_user.valid)
3923 return;
3924 buffer->bo_user.valid = true;
3925 list_add_head(&buffer->buffer_object->users, &buffer->bo_user.entry);
3928 void wined3d_buffer_acquire_bo_for_write(struct wined3d_buffer *buffer,
3929 struct wined3d_context *context) DECLSPEC_HIDDEN;
3930 void wined3d_buffer_cleanup(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
3931 void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset,
3932 struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size) DECLSPEC_HIDDEN;
3933 void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wined3d_context *context,
3934 unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size) DECLSPEC_HIDDEN;
3935 DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context,
3936 struct wined3d_bo_address *data) DECLSPEC_HIDDEN;
3937 void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, uint32_t location) DECLSPEC_HIDDEN;
3938 void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context,
3939 const struct wined3d_state *state) DECLSPEC_HIDDEN;
3940 BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer,
3941 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3942 void *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN;
3943 BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer,
3944 struct wined3d_context *context, unsigned int location) DECLSPEC_HIDDEN;
3945 void wined3d_buffer_update_sub_resource(struct wined3d_buffer *buffer, struct wined3d_context *context,
3946 const struct upload_bo *upload_bo, unsigned int offset, unsigned int size) DECLSPEC_HIDDEN;
3947 void wined3d_buffer_validate_location(struct wined3d_buffer *buffer, uint32_t location) DECLSPEC_HIDDEN;
3949 HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device,
3950 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
3951 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3953 struct wined3d_rendertarget_view
3955 LONG refcount;
3957 struct wined3d_resource *resource;
3958 void *parent;
3959 const struct wined3d_parent_ops *parent_ops;
3961 const struct wined3d_format *format;
3962 unsigned int format_attrs;
3963 unsigned int format_caps;
3964 unsigned int sub_resource_idx;
3965 unsigned int layer_count;
3967 unsigned int width;
3968 unsigned int height;
3970 struct wined3d_view_desc desc;
3973 void wined3d_rendertarget_view_cleanup(struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
3974 void wined3d_rendertarget_view_get_drawable_size(const struct wined3d_rendertarget_view *view,
3975 const struct wined3d_context *context, unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
3976 void wined3d_rendertarget_view_get_box(struct wined3d_rendertarget_view *view,
3977 struct wined3d_box *box) DECLSPEC_HIDDEN;
3978 void wined3d_rendertarget_view_invalidate_location(struct wined3d_rendertarget_view *view,
3979 uint32_t location) DECLSPEC_HIDDEN;
3980 void wined3d_rendertarget_view_load_location(struct wined3d_rendertarget_view *view,
3981 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3982 void wined3d_rendertarget_view_prepare_location(struct wined3d_rendertarget_view *view,
3983 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3984 void wined3d_rendertarget_view_validate_location(struct wined3d_rendertarget_view *view,
3985 uint32_t location) DECLSPEC_HIDDEN;
3986 DWORD wined3d_rendertarget_view_get_locations(const struct wined3d_rendertarget_view *view)
3987 DECLSPEC_HIDDEN;
3989 HRESULT wined3d_rendertarget_view_no3d_init(struct wined3d_rendertarget_view *view_no3d,
3990 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
3991 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3993 struct wined3d_shader_resource_view
3995 LONG refcount;
3997 struct wined3d_resource *resource;
3998 void *parent;
3999 const struct wined3d_parent_ops *parent_ops;
4001 const struct wined3d_format *format;
4003 struct wined3d_view_desc desc;
4006 void wined3d_shader_resource_view_cleanup(struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
4008 struct wined3d_unordered_access_view
4010 LONG refcount;
4012 struct wined3d_resource *resource;
4013 void *parent;
4014 const struct wined3d_parent_ops *parent_ops;
4016 const struct wined3d_format *format;
4018 struct wined3d_view_desc desc;
4019 struct wined3d_bo *counter_bo;
4022 void wined3d_unordered_access_view_cleanup(struct wined3d_unordered_access_view *view) DECLSPEC_HIDDEN;
4023 void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_view *view,
4024 struct wined3d_buffer *buffer, unsigned int offset, struct wined3d_context *context) DECLSPEC_HIDDEN;
4025 void wined3d_unordered_access_view_invalidate_location(struct wined3d_unordered_access_view *view,
4026 uint32_t location) DECLSPEC_HIDDEN;
4027 void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_view *view,
4028 unsigned int value) DECLSPEC_HIDDEN;
4030 struct wined3d_swapchain_state
4032 struct wined3d *wined3d;
4033 struct wined3d_swapchain_desc desc;
4034 struct wined3d_swapchain_state_parent *parent;
4036 struct wined3d_display_mode original_mode, d3d_mode;
4037 RECT original_window_rect;
4039 /* Window styles to restore when switching fullscreen mode. */
4040 LONG style;
4041 LONG exstyle;
4042 HWND device_window;
4045 void wined3d_swapchain_state_cleanup(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
4046 void wined3d_swapchain_state_register(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
4047 void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state,
4048 HWND window, const RECT *window_rect) DECLSPEC_HIDDEN;
4049 HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
4050 HWND window, int x, int y, int width, int height) DECLSPEC_HIDDEN;
4052 struct wined3d_swapchain_ops
4054 void (*swapchain_present)(struct wined3d_swapchain *swapchain,
4055 const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags);
4056 void (*swapchain_frontbuffer_updated)(struct wined3d_swapchain *swapchain);
4059 struct wined3d_swapchain
4061 LONG ref;
4062 void *parent;
4063 const struct wined3d_parent_ops *parent_ops;
4064 const struct wined3d_swapchain_ops *swapchain_ops;
4065 struct wined3d_device *device;
4067 struct wined3d_texture **back_buffers;
4068 struct wined3d_texture *front_buffer;
4069 struct wined3d_gamma_ramp orig_gamma;
4070 bool reapply_mode;
4071 const struct wined3d_format *ds_format;
4072 struct wined3d_palette *palette;
4073 RECT front_buffer_update;
4074 unsigned int swap_interval;
4075 unsigned int max_frame_latency;
4077 LONG prev_time, frames; /* Performance tracking */
4079 struct wined3d_swapchain_state state;
4080 HWND win_handle;
4083 void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activate) DECLSPEC_HIDDEN;
4084 void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4085 struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4086 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4087 void swapchain_set_max_frame_latency(struct wined3d_swapchain *swapchain,
4088 const struct wined3d_device *device) DECLSPEC_HIDDEN;
4090 HRESULT wined3d_swapchain_no3d_init(struct wined3d_swapchain *swapchain_no3d,
4091 struct wined3d_device *device, const struct wined3d_swapchain_desc *desc,
4092 struct wined3d_swapchain_state_parent *state_parent, void *parent,
4093 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4095 #include "wined3d_gl.h"
4097 /*****************************************************************************
4098 * Utility function prototypes
4101 /* Trace routines */
4102 const char *debug_bo_address(const struct wined3d_bo_address *address) DECLSPEC_HIDDEN;
4103 const char *debug_box(const struct wined3d_box *box) DECLSPEC_HIDDEN;
4104 const char *debug_color(const struct wined3d_color *color) DECLSPEC_HIDDEN;
4105 const char *debug_const_bo_address(const struct wined3d_const_bo_address *address) DECLSPEC_HIDDEN;
4106 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx) DECLSPEC_HIDDEN;
4107 const char *debug_d3dformat(enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
4108 const char *debug_d3ddevicetype(enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
4109 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) DECLSPEC_HIDDEN;
4110 const char *debug_d3dusage(uint32_t usage) DECLSPEC_HIDDEN;
4111 const char *debug_d3ddeclmethod(enum wined3d_decl_method method) DECLSPEC_HIDDEN;
4112 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
4113 const char *debug_d3dinput_classification(enum wined3d_input_classification classification) DECLSPEC_HIDDEN;
4114 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) DECLSPEC_HIDDEN;
4115 const char *debug_d3drenderstate(enum wined3d_render_state state) DECLSPEC_HIDDEN;
4116 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) DECLSPEC_HIDDEN;
4117 const char *debug_d3dstate(uint32_t state) DECLSPEC_HIDDEN;
4118 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) DECLSPEC_HIDDEN;
4119 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) DECLSPEC_HIDDEN;
4120 const char *debug_d3dtop(enum wined3d_texture_op d3dtop) DECLSPEC_HIDDEN;
4121 const char *debug_d3dtstype(enum wined3d_transform_state tstype) DECLSPEC_HIDDEN;
4122 const char *debug_ivec4(const struct wined3d_ivec4 *v) DECLSPEC_HIDDEN;
4123 const char *debug_uvec4(const struct wined3d_uvec4 *v) DECLSPEC_HIDDEN;
4124 const char *debug_shader_type(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN;
4125 const char *debug_vec4(const struct wined3d_vec4 *v) DECLSPEC_HIDDEN;
4126 const char *wined3d_debug_feature_level(enum wined3d_feature_level level) DECLSPEC_HIDDEN;
4127 void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
4129 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
4130 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
4131 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
4132 BOOL is_alpha, int stage, enum wined3d_texture_op op, uint32_t arg1, uint32_t arg2, uint32_t arg3,
4133 INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
4134 void texture_activate_dimensions(struct wined3d_texture *texture,
4135 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
4136 void sampler_texdim(struct wined3d_context *context,
4137 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4138 void tex_alphaop(struct wined3d_context *context,
4139 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4140 void apply_pixelshader(struct wined3d_context *context,
4141 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4142 void state_alpha_test(struct wined3d_context *context,
4143 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4144 void state_fogcolor(struct wined3d_context *context,
4145 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4146 void state_fogdensity(struct wined3d_context *context,
4147 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4148 void state_fogstartend(struct wined3d_context *context,
4149 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4150 void state_fog_fragpart(struct wined3d_context *context,
4151 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4152 void state_nop(struct wined3d_context *context,
4153 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4154 void state_srgbwrite(struct wined3d_context *context,
4155 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4157 void state_clipping(struct wined3d_context *context,
4158 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4159 void clipplane(struct wined3d_context *context,
4160 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4161 void state_pointsprite_w(struct wined3d_context *context,
4162 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4163 void state_pointsprite(struct wined3d_context *context,
4164 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4165 void state_shademode(struct wined3d_context *context,
4166 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4168 /* Math utils */
4169 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
4170 const struct wined3d_matrix *src2) DECLSPEC_HIDDEN;
4172 void wined3d_release_dc(HWND window, HDC dc) DECLSPEC_HIDDEN;
4174 struct wined3d_shader_lconst
4176 struct list entry;
4177 unsigned int idx;
4178 unsigned int value[4];
4181 struct wined3d_shader_limits
4183 unsigned int sampler;
4184 unsigned int constant_int;
4185 unsigned int constant_float;
4186 unsigned int constant_bool;
4187 unsigned int packed_output;
4188 unsigned int packed_input;
4191 #define wined3d_lock_init(lock, name) wined3d_lock_init_(lock, __FILE__ ": " name)
4192 static inline void wined3d_lock_init_(CRITICAL_SECTION *lock, const char *name)
4194 InitializeCriticalSection(lock);
4195 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
4196 lock->DebugInfo->Spare[0] = (DWORD_PTR)name;
4199 static inline void wined3d_lock_cleanup(CRITICAL_SECTION *lock)
4201 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
4202 lock->DebugInfo->Spare[0] = 0;
4203 DeleteCriticalSection(lock);
4206 #ifdef __GNUC__
4207 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
4208 #else
4209 #define PRINTF_ATTR(fmt,args)
4210 #endif
4212 struct wined3d_string_buffer_list
4214 struct list list;
4217 struct wined3d_string_buffer *string_buffer_get(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4218 void string_buffer_sprintf(struct wined3d_string_buffer *buffer, const char *format, ...) PRINTF_ATTR(2, 3) DECLSPEC_HIDDEN;
4219 void string_buffer_release(struct wined3d_string_buffer_list *list, struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4220 void string_buffer_list_init(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4221 void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4223 int shader_addline(struct wined3d_string_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
4224 BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc) DECLSPEC_HIDDEN;
4225 int shader_vaddline(struct wined3d_string_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
4227 struct wined3d_shader_phase
4229 const DWORD *start;
4230 const DWORD *end;
4231 unsigned int instance_count;
4232 unsigned int temporary_count;
4235 struct wined3d_vertex_shader
4237 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
4240 struct wined3d_hull_shader
4242 struct
4244 struct wined3d_shader_phase *control_point;
4245 unsigned int fork_count;
4246 unsigned int join_count;
4247 struct wined3d_shader_phase *fork;
4248 SIZE_T fork_size;
4249 struct wined3d_shader_phase *join;
4250 SIZE_T join_size;
4251 } phases;
4252 unsigned int output_vertex_count;
4253 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
4254 enum wined3d_tessellator_partitioning tessellator_partitioning;
4257 struct wined3d_domain_shader
4259 enum wined3d_tessellator_domain tessellator_domain;
4262 struct wined3d_geometry_shader
4264 enum wined3d_primitive_type input_type;
4265 enum wined3d_primitive_type output_type;
4266 unsigned int vertices_out;
4267 unsigned int instance_count;
4269 const struct wined3d_stream_output_desc *so_desc;
4272 struct wined3d_pixel_shader
4274 /* Pixel shader input semantics */
4275 unsigned int input_reg_map[MAX_REG_INPUT];
4276 DWORD input_reg_used; /* MAX_REG_INPUT, 32 */
4277 unsigned int declared_in_count;
4279 /* Some information about the shader behavior */
4280 BOOL color0_mov;
4281 unsigned int color0_reg;
4283 BOOL force_early_depth_stencil;
4284 enum wined3d_shader_register_type depth_output;
4285 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
4288 struct wined3d_compute_shader
4290 struct wined3d_shader_thread_group_size thread_group_size;
4293 struct wined3d_shader
4295 LONG ref;
4296 const struct wined3d_shader_limits *limits;
4297 const DWORD *function;
4298 unsigned int functionLength;
4299 void *byte_code;
4300 unsigned int byte_code_size;
4301 BOOL load_local_constsF;
4302 const struct wined3d_shader_frontend *frontend;
4303 void *frontend_data;
4304 void *backend_data;
4306 void *parent;
4307 const struct wined3d_parent_ops *parent_ops;
4309 /* Programs this shader is linked with */
4310 struct list linked_programs;
4312 /* Immediate constants (override global ones) */
4313 struct list constantsB;
4314 struct list constantsF;
4315 struct list constantsI;
4316 struct wined3d_shader_reg_maps reg_maps;
4317 BOOL lconst_inf_or_nan;
4319 struct wined3d_shader_signature input_signature;
4320 struct wined3d_shader_signature output_signature;
4321 struct wined3d_shader_signature patch_constant_signature;
4323 /* Pointer to the parent device */
4324 struct wined3d_device *device;
4325 struct list shader_list_entry;
4327 union
4329 struct wined3d_vertex_shader vs;
4330 struct wined3d_hull_shader hs;
4331 struct wined3d_domain_shader ds;
4332 struct wined3d_geometry_shader gs;
4333 struct wined3d_pixel_shader ps;
4334 struct wined3d_compute_shader cs;
4335 } u;
4338 enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps,
4339 unsigned int resource_idx, DWORD tex_types) DECLSPEC_HIDDEN;
4340 void find_ps_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4341 BOOL position_transformed, struct ps_compile_args *args,
4342 const struct wined3d_context *context) DECLSPEC_HIDDEN;
4344 bool vshader_get_input(const struct wined3d_shader *shader,
4345 uint8_t usage_req, uint8_t usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
4346 void find_vs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4347 struct vs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4349 void find_ds_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4350 struct ds_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4352 void find_gs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4353 struct gs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4355 void string_buffer_clear(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4356 BOOL string_buffer_init(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4357 void string_buffer_free(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4358 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps,
4359 unsigned int max) DECLSPEC_HIDDEN;
4360 HRESULT shader_generate_code(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer,
4361 const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx,
4362 const DWORD *start, const DWORD *end) DECLSPEC_HIDDEN;
4363 BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
4365 static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
4367 switch (reg->type)
4369 case WINED3DSPR_RASTOUT:
4370 /* oFog & oPts */
4371 if (reg->idx[0].offset)
4372 return TRUE;
4373 /* oPos */
4374 return FALSE;
4376 case WINED3DSPR_CONSTBOOL: /* b# */
4377 case WINED3DSPR_DEPTHOUT: /* oDepth */
4378 case WINED3DSPR_DEPTHOUTGE:
4379 case WINED3DSPR_DEPTHOUTLE:
4380 case WINED3DSPR_LOOP: /* aL */
4381 case WINED3DSPR_OUTPOINTID:
4382 case WINED3DSPR_PREDICATE: /* p0 */
4383 case WINED3DSPR_PRIMID: /* primID */
4384 case WINED3DSPR_COVERAGE: /* vCoverage */
4385 case WINED3DSPR_SAMPLEMASK: /* oMask */
4386 return TRUE;
4388 case WINED3DSPR_MISCTYPE:
4389 switch (reg->idx[0].offset)
4391 case 0: /* vPos */
4392 return FALSE;
4393 case 1: /* vFace */
4394 return TRUE;
4395 default:
4396 return FALSE;
4399 case WINED3DSPR_IMMCONST:
4400 return reg->immconst_type == WINED3D_IMMCONST_SCALAR;
4402 default:
4403 return FALSE;
4407 static inline void shader_get_position_fixup(const struct wined3d_context *context,
4408 const struct wined3d_state *state, unsigned int fixup_count, float *position_fixup)
4410 float center_offset, x = 0.0f, y = 0.0f;
4411 unsigned int i;
4413 /* See get_projection_matrix() in utils.c for a discussion of the position fixup.
4414 * This function here also applies to d3d10+ which does not need adjustment for
4415 * integer pixel centers, but it may need the filling convention offset. */
4416 if (context->d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
4417 center_offset = 1.0f;
4418 else
4419 center_offset = 0.0f;
4421 center_offset += context->d3d_info->filling_convention_offset;
4423 for (i = 0; i < fixup_count; ++i)
4425 position_fixup[4 * i ] = 1.0f;
4426 position_fixup[4 * i + 1] = 1.0f;
4427 if (!context->d3d_info->subpixel_viewport)
4429 double dummy;
4430 x = modf(state->viewports[i].x, &dummy) * 2.0f;
4431 y = modf(state->viewports[i].y, &dummy) * 2.0f;
4433 position_fixup[4 * i + 2] = (center_offset + x) / state->viewports[i].width;
4434 position_fixup[4 * i + 3] = -(center_offset + y) / state->viewports[i].height;
4436 if (context->render_offscreen)
4438 position_fixup[4 * i + 1] *= -1.0f;
4439 position_fixup[4 * i + 3] *= -1.0f;
4444 static inline BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg)
4446 struct wined3d_shader_lconst *lconst;
4448 if (shader->load_local_constsF)
4449 return FALSE;
4451 LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
4453 if (lconst->idx == reg)
4454 return TRUE;
4457 return FALSE;
4460 void get_identity_matrix(struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4461 void get_modelview_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4462 unsigned int index, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4463 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4464 struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4465 void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4466 unsigned int tex, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4467 void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state,
4468 float *out_min, float *out_max) DECLSPEC_HIDDEN;
4469 void get_pointsize(const struct wined3d_context *context, const struct wined3d_state *state,
4470 float *out_pointsize, float *out_att) DECLSPEC_HIDDEN;
4471 void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state,
4472 float *start, float *end) DECLSPEC_HIDDEN;
4474 /* Using additional shader constants (uniforms in GLSL / program environment
4475 * or local parameters in ARB) is costly:
4476 * ARB only knows float4 parameters and GLSL compiler are not really smart
4477 * when it comes to efficiently pack float2 uniforms, so no space is wasted
4478 * (in fact most compilers map a float2 to a full float4 uniform).
4480 * For NP2 texcoord fixup we only need 2 floats (width and height) for each
4481 * 2D texture used in the shader. We therefore pack fixup info for 2 textures
4482 * into a single shader constant (uniform / program parameter).
4484 * This structure is shared between the GLSL and the ARB backend.*/
4485 struct ps_np2fixup_info {
4486 unsigned char idx[WINED3D_MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
4487 WORD active; /* bitfield indicating if we can apply the fixup */
4488 WORD num_consts;
4491 struct wined3d_palette
4493 LONG ref;
4494 struct wined3d_device *device;
4496 unsigned int size;
4497 RGBQUAD colors[256];
4498 uint32_t flags;
4501 /* DirectDraw utility functions */
4502 extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
4504 /*****************************************************************************
4505 * Pixel format management
4508 /* Pixel format attributes */
4509 #define WINED3D_FORMAT_ATTR_FLOAT 0x00000001
4510 #define WINED3D_FORMAT_ATTR_INTEGER 0x00000002
4511 #define WINED3D_FORMAT_ATTR_NORMALISED 0x00000004
4512 #define WINED3D_FORMAT_ATTR_BUMPMAP 0x00000008
4513 #define WINED3D_FORMAT_ATTR_EXTENSION 0x00000010
4514 #define WINED3D_FORMAT_ATTR_BLOCKS 0x00000020
4515 #define WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY 0x00000040
4516 #define WINED3D_FORMAT_ATTR_COMPRESSED 0x00000080
4517 #define WINED3D_FORMAT_ATTR_BROKEN_PITCH 0x00000100
4518 #define WINED3D_FORMAT_ATTR_HEIGHT_SCALE 0x00000200
4519 #define WINED3D_FORMAT_ATTR_MAPPABLE 0x00000400
4520 #define WINED3D_FORMAT_ATTR_CAST_TO_BLOCK 0x00000800
4522 /* Pixel format capabilities */
4523 #define WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING 0x00000001
4524 #define WINED3D_FORMAT_CAP_FILTERING 0x00000002
4525 #define WINED3D_FORMAT_CAP_UNORDERED_ACCESS 0x00000004
4526 #define WINED3D_FORMAT_CAP_DEPTH_STENCIL 0x00000008
4527 #define WINED3D_FORMAT_CAP_RENDERTARGET 0x00000010
4528 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE 0x00000020
4529 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB 0x00000040
4530 #define WINED3D_FORMAT_CAP_DECOMPRESS 0x00000080
4531 #define WINED3D_FORMAT_CAP_SRGB_READ 0x00000100
4532 #define WINED3D_FORMAT_CAP_SRGB_WRITE 0x00000200
4533 #define WINED3D_FORMAT_CAP_VTF 0x00000400
4534 #define WINED3D_FORMAT_CAP_SHADOW 0x00000800
4535 #define WINED3D_FORMAT_CAP_TEXTURE 0x00001000
4536 #define WINED3D_FORMAT_CAP_GEN_MIPMAP 0x00002000
4537 #define WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE 0x00004000
4538 #define WINED3D_FORMAT_CAP_BLIT 0x00008000
4539 #define WINED3D_FORMAT_CAP_INDEX_BUFFER 0x00010000
4541 struct wined3d_rational
4543 UINT numerator;
4544 UINT denominator;
4547 struct wined3d_color_key_conversion
4549 enum wined3d_format_id dst_format;
4550 void (*convert)(const BYTE *src, unsigned int src_pitch, BYTE *dst, unsigned int dst_pitch,
4551 unsigned int width, unsigned int height, const struct wined3d_color_key *colour_key);
4554 enum wined3d_channel_type
4556 WINED3D_CHANNEL_TYPE_NONE,
4557 WINED3D_CHANNEL_TYPE_UNORM,
4558 WINED3D_CHANNEL_TYPE_SNORM,
4559 WINED3D_CHANNEL_TYPE_UINT,
4560 WINED3D_CHANNEL_TYPE_SINT,
4561 WINED3D_CHANNEL_TYPE_FLOAT,
4562 WINED3D_CHANNEL_TYPE_DEPTH,
4563 WINED3D_CHANNEL_TYPE_STENCIL,
4564 WINED3D_CHANNEL_TYPE_UNUSED,
4567 struct wined3d_format
4569 enum wined3d_format_id id;
4571 D3DDDIFORMAT ddi_format;
4572 unsigned int component_count;
4573 DWORD red_size;
4574 DWORD green_size;
4575 DWORD blue_size;
4576 DWORD alpha_size;
4577 DWORD red_offset;
4578 DWORD green_offset;
4579 DWORD blue_offset;
4580 DWORD alpha_offset;
4581 UINT byte_count;
4582 BYTE depth_size;
4583 BYTE stencil_size;
4585 UINT block_width;
4586 UINT block_height;
4587 UINT block_byte_count;
4589 enum wined3d_ffp_emit_idx emit_idx;
4591 UINT conv_byte_count;
4592 DWORD multisample_types;
4593 unsigned int attrs;
4594 unsigned int caps[WINED3D_GL_RES_TYPE_COUNT];
4595 float depth_bias_scale;
4596 struct wined3d_rational height_scale;
4597 struct color_fixup_desc color_fixup;
4598 void (*upload)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4599 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4600 unsigned int width, unsigned int height, unsigned int depth);
4601 void (*download)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4602 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4603 unsigned int width, unsigned int height, unsigned int depth);
4604 void (*decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4605 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4606 unsigned int width, unsigned int height, unsigned int depth);
4608 enum wined3d_format_id typeless_id;
4611 const struct wined3d_format *wined3d_get_format(const struct wined3d_adapter *adapter,
4612 enum wined3d_format_id format_id, unsigned int bind_flags) DECLSPEC_HIDDEN;
4613 enum wined3d_format_id wined3d_get_typed_format_id(const struct wined3d_adapter *adapter,
4614 const struct wined3d_format *format, enum wined3d_channel_type channel_type) DECLSPEC_HIDDEN;
4615 void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
4616 unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) DECLSPEC_HIDDEN;
4617 UINT wined3d_format_calculate_size(const struct wined3d_format *format,
4618 UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
4619 void wined3d_format_convert_from_float(const struct wined3d_format *format,
4620 const struct wined3d_color *color, void *ret) DECLSPEC_HIDDEN;
4621 void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src,
4622 unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
4623 unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d) DECLSPEC_HIDDEN;
4624 void wined3d_format_get_float_color_key(const struct wined3d_format *format,
4625 const struct wined3d_color_key *key, struct wined3d_color *float_colors) DECLSPEC_HIDDEN;
4626 BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id,
4627 enum wined3d_format_id view_format_id) DECLSPEC_HIDDEN;
4628 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
4629 const struct wined3d_texture *texture, BOOL need_alpha_ck) DECLSPEC_HIDDEN;
4630 uint32_t wined3d_format_pack(const struct wined3d_format *format, const struct wined3d_uvec4 *value) DECLSPEC_HIDDEN;
4631 BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1,
4632 enum wined3d_format_id format2) DECLSPEC_HIDDEN;
4634 struct wined3d_format_gl
4636 struct wined3d_format f;
4638 GLenum vtx_type;
4639 GLint vtx_format;
4641 GLint internal;
4642 GLint srgb_internal;
4643 GLint rt_internal;
4644 GLint format;
4645 GLint type;
4647 GLenum view_class;
4650 static inline const struct wined3d_format_gl *wined3d_format_gl(const struct wined3d_format *format)
4652 return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
4655 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
4657 static inline BOOL wined3d_format_is_typeless(const struct wined3d_format *format)
4659 return format->id == format->typeless_id && format->id != WINED3DFMT_UNKNOWN;
4662 static inline BOOL use_vs(const struct wined3d_state *state)
4664 /* Check state->vertex_declaration to allow this to be used before the
4665 * stream info is validated, for example in device_update_tex_unit_map(). */
4666 return state->shader[WINED3D_SHADER_TYPE_VERTEX]
4667 && (!state->vertex_declaration || !state->vertex_declaration->position_transformed);
4670 static inline BOOL use_ps(const struct wined3d_state *state)
4672 return !!state->shader[WINED3D_SHADER_TYPE_PIXEL];
4675 static inline BOOL use_transform_feedback(const struct wined3d_state *state)
4677 const struct wined3d_shader *shader;
4679 if (!(shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY]))
4680 return FALSE;
4681 return !!shader->u.gs.so_desc;
4684 static inline void context_apply_state(struct wined3d_context *context,
4685 const struct wined3d_state *state, DWORD state_id)
4687 const struct wined3d_state_entry *state_table = context->state_table;
4688 unsigned int rep = state_table[state_id].representative;
4689 state_table[rep].apply(context, state, rep);
4692 static inline BOOL is_srgb_enabled(const uint32_t *sampler_states)
4694 /* Only use the LSB of the WINED3D_SAMP_SRGB_TEXTURE value. This matches
4695 * the behaviour of the AMD Windows driver.
4697 * Might & Magic: Heroes VI - Shades of Darkness sets
4698 * WINED3D_SAMP_SRGB_TEXTURE to a large value that looks like a
4699 * pointer—presumably by accident—and expects sRGB decoding to be
4700 * disabled. */
4701 return sampler_states[WINED3D_SAMP_SRGB_TEXTURE] & 0x1;
4704 static inline BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context,
4705 const struct wined3d_texture *texture)
4707 if (!(context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
4708 return FALSE;
4710 if (!context->d3d_info->srgb_read_control
4711 && (texture->resource.bind_flags & WINED3D_BIND_SHADER_RESOURCE)
4712 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_READ))
4713 return TRUE;
4715 if (!context->d3d_info->srgb_write_control
4716 && (texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET)
4717 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE))
4718 return TRUE;
4720 return FALSE;
4723 static inline BOOL needs_srgb_write(const struct wined3d_d3d_info *d3d_info,
4724 const struct wined3d_state *state, const struct wined3d_fb_state *fb)
4726 return (!(d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
4727 || state->render_states[WINED3D_RS_SRGBWRITEENABLE])
4728 && fb->render_targets[0] && fb->render_targets[0]->format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE;
4731 static inline GLuint wined3d_texture_gl_get_texture_name(const struct wined3d_texture_gl *texture_gl,
4732 const struct wined3d_context *context, BOOL srgb)
4734 return srgb && needs_separate_srgb_gl_texture(context, &texture_gl->t)
4735 ? texture_gl->texture_srgb.name : texture_gl->texture_rgb.name;
4738 static inline GLuint wined3d_gl_get_internal_format(struct wined3d_resource *resource,
4739 const struct wined3d_format_gl *format_gl, bool srgb)
4741 if (srgb)
4742 return format_gl->srgb_internal;
4743 else if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET && wined3d_resource_is_offscreen(resource))
4744 return format_gl->rt_internal;
4745 else
4746 return format_gl->internal;
4749 static inline BOOL can_use_texture_swizzle(const struct wined3d_d3d_info *d3d_info, const struct wined3d_format *format)
4751 return d3d_info->texture_swizzle && !is_complex_fixup(format->color_fixup) && !is_scaling_fixup(format->color_fixup);
4754 static inline BOOL is_rasterization_disabled(const struct wined3d_shader *geometry_shader)
4756 return geometry_shader && geometry_shader->u.gs.so_desc
4757 && geometry_shader->u.gs.so_desc->rasterizer_stream_idx == WINED3D_NO_RASTERIZER_STREAM;
4760 static inline uint32_t wined3d_mask_from_size(unsigned int size)
4762 return size < 32 ? (1u << size) - 1 : ~0u;
4765 static inline DWORD wined3d_extract_bits(const uint32_t *bitstream,
4766 unsigned int offset, unsigned int count)
4768 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
4769 const unsigned int idx = offset / word_bit_count;
4770 const unsigned int shift = offset % word_bit_count;
4771 DWORD mask = (1u << count) - 1;
4772 DWORD ret;
4774 ret = (bitstream[idx] >> shift) & mask;
4775 if (shift + count > word_bit_count)
4777 const unsigned int extracted_bit_count = word_bit_count - shift;
4778 const unsigned int remaining_bit_count = count - extracted_bit_count;
4779 mask = (1u << remaining_bit_count) - 1;
4780 ret |= (bitstream[idx + 1] & mask) << extracted_bit_count;
4782 return ret;
4785 static inline void wined3d_insert_bits(uint32_t *bitstream,
4786 unsigned int offset, unsigned int count, DWORD bits)
4788 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
4789 const unsigned int idx = offset / word_bit_count;
4790 const unsigned int shift = offset % word_bit_count;
4791 DWORD mask = (1u << count) - 1;
4793 bitstream[idx] |= (bits & mask) << shift;
4794 if (shift + count > word_bit_count)
4796 const unsigned int inserted_bit_count = word_bit_count - shift;
4797 const unsigned int remaining_bit_count = count - inserted_bit_count;
4798 mask = (1u << remaining_bit_count) - 1;
4799 bitstream[idx + 1] |= (bits >> inserted_bit_count) & mask;
4803 static inline void wined3d_from_cs(const struct wined3d_cs *cs)
4805 if (cs->thread)
4806 assert(cs->thread_id == GetCurrentThreadId());
4809 static inline void wined3d_not_from_cs(const struct wined3d_cs *cs)
4811 assert(cs->thread_id != GetCurrentThreadId());
4814 static inline enum wined3d_material_color_source validate_material_colour_source(WORD use_map,
4815 enum wined3d_material_color_source source)
4817 if (source == WINED3D_MCS_COLOR1 && use_map & (1u << WINED3D_FFP_DIFFUSE))
4818 return source;
4819 if (source == WINED3D_MCS_COLOR2 && use_map & (1u << WINED3D_FFP_SPECULAR))
4820 return source;
4821 return WINED3D_MCS_MATERIAL;
4824 static inline void wined3d_get_material_colour_source(enum wined3d_material_color_source *diffuse,
4825 enum wined3d_material_color_source *emissive, enum wined3d_material_color_source *ambient,
4826 enum wined3d_material_color_source *specular, const struct wined3d_state *state,
4827 const struct wined3d_stream_info *si)
4829 if (!state->render_states[WINED3D_RS_LIGHTING])
4831 *diffuse = WINED3D_MCS_COLOR1;
4832 *specular = WINED3D_MCS_COLOR2;
4833 *emissive = *ambient = WINED3D_MCS_MATERIAL;
4835 return;
4838 if (!state->render_states[WINED3D_RS_COLORVERTEX])
4840 *diffuse = *emissive = *ambient = *specular = WINED3D_MCS_MATERIAL;
4842 return;
4845 *diffuse = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE]);
4846 *emissive = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE]);
4847 *ambient = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE]);
4848 *specular = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
4851 static inline void wined3d_vec4_transform(struct wined3d_vec4 *dst,
4852 const struct wined3d_vec4 *v, const struct wined3d_matrix *m)
4854 struct wined3d_vec4 tmp;
4856 tmp.x = v->x * m->_11 + v->y * m->_21 + v->z * m->_31 + v->w * m->_41;
4857 tmp.y = v->x * m->_12 + v->y * m->_22 + v->z * m->_32 + v->w * m->_42;
4858 tmp.z = v->x * m->_13 + v->y * m->_23 + v->z * m->_33 + v->w * m->_43;
4859 tmp.w = v->x * m->_14 + v->y * m->_24 + v->z * m->_34 + v->w * m->_44;
4861 *dst = tmp;
4864 BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m) DECLSPEC_HIDDEN;
4866 void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting,
4867 const struct wined3d_matrix *modelview) DECLSPEC_HIDDEN;
4869 static inline struct wined3d_context *context_acquire(struct wined3d_device *device,
4870 struct wined3d_texture *texture, unsigned int sub_resource_idx)
4872 wined3d_from_cs(device->cs);
4874 return device->adapter->adapter_ops->adapter_acquire_context(device, texture, sub_resource_idx);
4877 static inline void context_release(struct wined3d_context *context)
4879 context->device->adapter->adapter_ops->adapter_release_context(context);
4882 static inline float wined3d_get_float_state(const struct wined3d_state *state, enum wined3d_render_state rs)
4884 union
4886 DWORD d;
4887 float f;
4889 tmpvalue;
4891 tmpvalue.d = state->render_states[rs];
4892 return tmpvalue.f;
4895 static inline void *wined3d_context_map_bo_address(struct wined3d_context *context,
4896 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
4898 return context->device->adapter->adapter_ops->adapter_map_bo_address(context, data, size, map_flags);
4901 static inline void wined3d_context_unmap_bo_address(struct wined3d_context *context,
4902 const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
4904 context->device->adapter->adapter_ops->adapter_unmap_bo_address(context, data, range_count, ranges);
4907 static inline void wined3d_context_copy_bo_address(struct wined3d_context *context,
4908 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
4909 unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags)
4911 context->device->adapter->adapter_ops->adapter_copy_bo_address(context, dst, src, range_count, ranges, map_flags);
4914 static inline void wined3d_context_flush_bo_address(struct wined3d_context *context,
4915 const struct wined3d_const_bo_address *data, size_t size)
4917 context->device->adapter->adapter_ops->adapter_flush_bo_address(context, data, size);
4920 static inline void wined3d_context_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)
4922 context->device->adapter->adapter_ops->adapter_destroy_bo(context, bo);
4925 static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_view *dsv,
4926 const struct wined3d_format *srv_format)
4928 return !srv_format || (srv_format->red_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_DEPTH))
4929 || (srv_format->green_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_STENCIL));
4932 static inline unsigned int wined3d_bind_layer_count(const struct wined3d_texture *texture)
4934 return texture->resource.type == WINED3D_RTYPE_TEXTURE_3D ? texture->resource.depth : texture->layer_count;
4937 static inline bool wined3d_srv_all_subresources(const struct wined3d_shader_resource_view *srv)
4939 struct wined3d_texture *texture;
4941 if (srv->resource->type == WINED3D_RTYPE_BUFFER)
4942 return TRUE;
4944 if (srv->desc.u.texture.layer_idx || srv->desc.u.texture.level_idx)
4945 return FALSE;
4947 texture = texture_from_resource(srv->resource);
4948 return srv->desc.u.texture.level_count == texture->level_count
4949 && srv->desc.u.texture.layer_count == wined3d_bind_layer_count(texture);
4952 static inline bool wined3d_rtv_all_subresources(const struct wined3d_rendertarget_view *rtv)
4954 struct wined3d_texture *texture;
4956 if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
4957 return TRUE;
4959 if (rtv->sub_resource_idx)
4960 return FALSE;
4962 texture = texture_from_resource(rtv->resource);
4963 return texture->level_count == 1 && rtv->layer_count == wined3d_bind_layer_count(texture);
4966 static inline void wined3d_srv_bind_count_inc(struct wined3d_shader_resource_view *srv)
4968 InterlockedIncrement(&srv->resource->srv_bind_count_device);
4971 static inline void wined3d_srv_bind_count_dec(struct wined3d_shader_resource_view *srv)
4973 InterlockedDecrement(&srv->resource->srv_bind_count_device);
4976 static inline void wined3d_rtv_bind_count_inc(struct wined3d_rendertarget_view *rtv)
4978 InterlockedIncrement(&rtv->resource->rtv_bind_count_device);
4981 static inline void wined3d_rtv_bind_count_dec(struct wined3d_rendertarget_view *rtv)
4983 InterlockedDecrement(&rtv->resource->rtv_bind_count_device);
4986 static inline bool wined3d_rtv_overlaps_srv(const struct wined3d_rendertarget_view *rtv,
4987 const struct wined3d_shader_resource_view *srv)
4989 if (rtv->resource != srv->resource)
4990 return false;
4992 if (wined3d_srv_all_subresources(srv) || wined3d_rtv_all_subresources(rtv))
4993 return true;
4995 return rtv->sub_resource_idx >= srv->desc.u.texture.level_idx
4996 && rtv->sub_resource_idx < srv->desc.u.texture.level_idx + srv->desc.u.texture.level_count
4997 && rtv->layer_count >= srv->desc.u.texture.layer_idx;
5000 static inline bool wined3d_is_srv_rtv_bound(const struct wined3d_state *state,
5001 const struct wined3d_shader_resource_view *srv)
5003 unsigned int i;
5005 if (!srv->resource->rtv_bind_count_device)
5006 return false;
5008 for (i = 0; i < ARRAY_SIZE(state->fb.render_targets); ++i)
5010 const struct wined3d_rendertarget_view *rtv;
5012 if ((rtv = state->fb.render_targets[i]) && wined3d_rtv_overlaps_srv(rtv, srv))
5013 return true;
5016 return false;
5019 static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)
5021 *min_z = vp->min_z;
5023 /* The magic constant is derived from tests. */
5024 *max_z = max(vp->max_z, vp->min_z + 0.001f);
5027 static inline BOOL wined3d_bitmap_clear(uint32_t *map, unsigned int idx)
5029 return map[idx >> 5] &= ~(1u << (idx & 0x1f));
5032 static inline BOOL wined3d_bitmap_set(uint32_t *map, unsigned int idx)
5034 return map[idx >> 5] |= (1u << (idx & 0x1f));
5037 static inline BOOL wined3d_bitmap_is_set(const uint32_t *map, unsigned int idx)
5039 return map[idx >> 5] & (1u << (idx & 0x1f));
5042 static inline unsigned int wined3d_bitmap_ffs_xor(const uint32_t *bitmap, unsigned int bit_count,
5043 unsigned int start, uint32_t xor_mask)
5045 const unsigned int word_bit_count = sizeof(*bitmap) * CHAR_BIT;
5046 const uint32_t *ptr, *end_ptr;
5047 uint32_t map, mask;
5049 assert(bit_count < word_bit_count || !(bit_count % word_bit_count));
5051 ptr = bitmap + start / word_bit_count;
5052 end_ptr = bitmap + (bit_count + word_bit_count - 1) / word_bit_count;
5054 if (ptr >= end_ptr)
5055 return ~0u;
5057 mask = ~0u << start % word_bit_count;
5058 map = (*ptr ^ xor_mask) & mask;
5059 while (!map)
5061 if (++ptr == end_ptr)
5062 return ~0u;
5063 map = *ptr ^ xor_mask;
5065 return (ptr - bitmap) * word_bit_count + wined3d_bit_scan(&map);
5068 static inline unsigned int wined3d_bitmap_ffs(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
5070 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, 0);
5073 static inline unsigned int wined3d_bitmap_ffz(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
5075 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, ~0u);
5078 static inline BOOL wined3d_bitmap_get_range(const uint32_t *bitmap, unsigned int bit_count,
5079 unsigned int start, struct wined3d_range *range)
5081 unsigned int range_start, range_end;
5083 range_start = wined3d_bitmap_ffs(bitmap, bit_count, start);
5084 if (range_start == ~0u)
5085 return FALSE;
5087 range_end = wined3d_bitmap_ffz(bitmap, bit_count, range_start + 1);
5088 if (range_end == ~0u)
5089 range_end = bit_count;
5091 range->offset = range_start;
5092 range->size = range_end - range_start;
5093 return TRUE;
5096 static inline bool wined3d_context_is_graphics_state_dirty(const struct wined3d_context *context, unsigned int state_id)
5098 return wined3d_bitmap_is_set(context->dirty_graphics_states, state_id);
5101 static inline bool wined3d_context_is_compute_state_dirty(const struct wined3d_context *context, unsigned int state_id)
5103 return wined3d_bitmap_is_set(context->dirty_compute_states, state_id - STATE_COMPUTE_OFFSET);
5106 static inline bool isStateDirty(const struct wined3d_context *context, unsigned int state_id)
5108 return wined3d_context_is_graphics_state_dirty(context, state_id);
5111 static inline bool wined3d_primitive_type_is_list(enum wined3d_primitive_type t)
5113 return t == WINED3D_PT_POINTLIST
5114 || t == WINED3D_PT_LINELIST
5115 || t == WINED3D_PT_TRIANGLELIST
5116 || t == WINED3D_PT_LINELIST_ADJ
5117 || t == WINED3D_PT_TRIANGLELIST_ADJ
5118 || t == WINED3D_PT_PATCH;
5121 static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo_gl)
5123 struct wined3d_device_gl *device_gl = wined3d_device_gl(context_gl->c.device);
5125 bo_gl->command_fence_id = device_gl->current_fence_id;
5128 static inline void wined3d_context_gl_reference_buffer(struct wined3d_context_gl *context_gl,
5129 struct wined3d_buffer *buffer)
5131 if (buffer->buffer_object)
5132 wined3d_context_gl_reference_bo(context_gl, wined3d_bo_gl(buffer->buffer_object));
5135 static inline bool wined3d_map_persistent(void)
5137 return sizeof(void *) >= sizeof(uint64_t);
5140 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
5141 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
5143 extern CRITICAL_SECTION wined3d_command_cs;
5145 #endif