wined3d: Move GL-specific blitter create function declarations to wined3d_gl.h.
[wine.git] / dlls / wined3d / wined3d_private.h
blobf63a4afdd7d984815db37ea4b95c9a2296bb281a
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_swapchain_gl;
101 struct wined3d_texture_gl;
102 struct wined3d_vertex_pipe_ops;
104 enum wined3d_ffp_idx
106 WINED3D_FFP_POSITION = 0,
107 WINED3D_FFP_BLENDWEIGHT = 1,
108 WINED3D_FFP_BLENDINDICES = 2,
109 WINED3D_FFP_NORMAL = 3,
110 WINED3D_FFP_PSIZE = 4,
111 WINED3D_FFP_DIFFUSE = 5,
112 WINED3D_FFP_SPECULAR = 6,
113 WINED3D_FFP_TEXCOORD0 = 7,
114 WINED3D_FFP_TEXCOORD1 = 8,
115 WINED3D_FFP_TEXCOORD2 = 9,
116 WINED3D_FFP_TEXCOORD3 = 10,
117 WINED3D_FFP_TEXCOORD4 = 11,
118 WINED3D_FFP_TEXCOORD5 = 12,
119 WINED3D_FFP_TEXCOORD6 = 13,
120 WINED3D_FFP_TEXCOORD7 = 14,
121 WINED3D_FFP_ATTRIBS_COUNT = 15,
124 enum wined3d_ffp_emit_idx
126 WINED3D_FFP_EMIT_FLOAT1,
127 WINED3D_FFP_EMIT_FLOAT2,
128 WINED3D_FFP_EMIT_FLOAT3,
129 WINED3D_FFP_EMIT_FLOAT4,
130 WINED3D_FFP_EMIT_D3DCOLOR,
131 WINED3D_FFP_EMIT_UBYTE4,
132 WINED3D_FFP_EMIT_SHORT2,
133 WINED3D_FFP_EMIT_SHORT4,
134 WINED3D_FFP_EMIT_UBYTE4N,
135 WINED3D_FFP_EMIT_SHORT2N,
136 WINED3D_FFP_EMIT_SHORT4N,
137 WINED3D_FFP_EMIT_USHORT2N,
138 WINED3D_FFP_EMIT_USHORT4N,
139 WINED3D_FFP_EMIT_UDEC3,
140 WINED3D_FFP_EMIT_DEC3N,
141 WINED3D_FFP_EMIT_FLOAT16_2,
142 WINED3D_FFP_EMIT_FLOAT16_4,
143 WINED3D_FFP_EMIT_INVALID,
144 WINED3D_FFP_EMIT_COUNT,
147 /* Texture format fixups */
149 enum fixup_channel_source
151 CHANNEL_SOURCE_ZERO = 0,
152 CHANNEL_SOURCE_ONE = 1,
153 CHANNEL_SOURCE_X = 2,
154 CHANNEL_SOURCE_Y = 3,
155 CHANNEL_SOURCE_Z = 4,
156 CHANNEL_SOURCE_W = 5,
157 CHANNEL_SOURCE_COMPLEX0 = 6,
158 CHANNEL_SOURCE_COMPLEX1 = 7,
161 enum complex_fixup
163 COMPLEX_FIXUP_NONE = 0,
164 COMPLEX_FIXUP_YUY2 = 1,
165 COMPLEX_FIXUP_UYVY = 2,
166 COMPLEX_FIXUP_YV12 = 3,
167 COMPLEX_FIXUP_P8 = 4,
168 COMPLEX_FIXUP_NV12 = 5,
169 COMPLEX_FIXUP_YUV = 6,
172 #include <pshpack2.h>
173 struct color_fixup_desc
175 unsigned short x_sign_fixup : 1;
176 unsigned short x_source : 3;
177 unsigned short y_sign_fixup : 1;
178 unsigned short y_source : 3;
179 unsigned short z_sign_fixup : 1;
180 unsigned short z_source : 3;
181 unsigned short w_sign_fixup : 1;
182 unsigned short w_source : 3;
184 #include <poppack.h>
186 struct wined3d_d3d_limits
188 unsigned int vs_version, hs_version, ds_version, gs_version, ps_version, cs_version;
189 DWORD vs_uniform_count;
190 DWORD ps_uniform_count;
191 unsigned int varying_count;
192 unsigned int ffp_textures;
193 unsigned int ffp_blend_stages;
194 unsigned int ffp_vertex_blend_matrices;
195 unsigned int active_light_count;
197 unsigned int max_rt_count;
198 unsigned int max_clip_distances;
199 unsigned int texture_size;
200 unsigned int sample_count;
201 float pointsize_max;
204 struct wined3d_d3d_info
206 struct wined3d_d3d_limits limits;
207 uint32_t wined3d_creation_flags;
208 uint32_t xyzrhw : 1;
209 uint32_t emulated_flatshading : 1;
210 uint32_t ffp_generic_attributes : 1;
211 uint32_t ffp_alpha_test : 1;
212 uint32_t vs_clipping : 1;
213 uint32_t shader_color_key : 1;
214 uint32_t shader_double_precision : 1;
215 uint32_t shader_output_interpolation : 1;
216 uint32_t frag_coord_correction : 1;
217 uint32_t viewport_array_index_any_shader : 1;
218 uint32_t texture_npot : 1;
219 uint32_t texture_npot_conditional : 1;
220 uint32_t normalized_texrect : 1;
221 uint32_t draw_base_vertex_offset : 1;
222 uint32_t vertex_bgra : 1;
223 uint32_t texture_swizzle : 1;
224 uint32_t srgb_read_control : 1;
225 uint32_t srgb_write_control : 1;
226 uint32_t clip_control : 1;
227 uint32_t full_ffp_varyings : 1;
228 uint32_t scaled_resolve : 1;
229 uint32_t pbo : 1;
230 uint32_t subpixel_viewport : 1;
231 uint32_t fences : 1;
232 uint32_t persistent_map : 1;
233 enum wined3d_feature_level feature_level;
235 DWORD multisample_draw_location;
237 float filling_convention_offset;
240 static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
241 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
243 static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
245 struct color_fixup_desc fixup =
247 0u, complex_fixup & (1u << 0) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
248 0u, complex_fixup & (1u << 1) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
249 0u, complex_fixup & (1u << 2) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
250 0u, complex_fixup & (1u << 3) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
252 return fixup;
255 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
257 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
260 static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
262 return fixup.x_source == CHANNEL_SOURCE_COMPLEX0 || fixup.x_source == CHANNEL_SOURCE_COMPLEX1;
265 static inline BOOL is_scaling_fixup(struct color_fixup_desc fixup)
267 return fixup.x_sign_fixup || fixup.y_sign_fixup || fixup.z_sign_fixup || fixup.w_sign_fixup;
270 static inline BOOL is_same_fixup(struct color_fixup_desc f1, struct color_fixup_desc f2)
272 return f1.x_sign_fixup == f2.x_sign_fixup && f1.x_source == f2.x_source
273 && f1.y_sign_fixup == f2.y_sign_fixup && f1.y_source == f2.y_source
274 && f1.z_sign_fixup == f2.z_sign_fixup && f1.z_source == f2.z_source
275 && f1.w_sign_fixup == f2.w_sign_fixup && f1.w_source == f2.w_source;
278 static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
280 enum complex_fixup complex_fixup = 0;
281 if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 0);
282 if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 1);
283 if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 2);
284 if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 3);
285 return complex_fixup;
288 /* Device caps */
289 #define WINED3D_MAX_ACTIVE_LIGHTS 8
290 #define WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS 32
291 #define MAX_CONSTANT_BUFFERS 15
292 #define MAX_SAMPLER_OBJECTS 16
293 #define MAX_SHADER_RESOURCE_VIEWS 128
294 #define MAX_UNORDERED_ACCESS_VIEWS 8
295 #define MAX_TGSM_REGISTERS 8192
296 #define MAX_VERTEX_BLENDS 4
298 static const uint32_t WINED3D_READ_ONLY_BIND_MASK = WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER
299 | WINED3D_BIND_CONSTANT_BUFFER | WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_INDIRECT_BUFFER;
301 static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func)
303 if (func < WINED3D_CMP_NEVER || func > WINED3D_CMP_ALWAYS)
304 return WINED3D_CMP_ALWAYS;
305 return func;
308 /* float_16_to_32() and float_32_to_16() convert 16 bit floats in the
309 * FLOAT16 data type to standard C floats and vice versa. They do not
310 * depend on the encoding of the C float, so they are platform independent,
311 * but slow. On x86 and other IEEE 754 compliant platforms the conversion
312 * can be accelerated by bit shifting the exponent and mantissa. There are
313 * also some SSE-based assembly routines out there.
315 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
317 static inline float float_16_to_32(const unsigned short *in)
319 const unsigned short s = ((*in) & 0x8000u);
320 const unsigned short e = ((*in) & 0x7c00u) >> 10;
321 const unsigned short m = (*in) & 0x3ffu;
322 const float sgn = (s ? -1.0f : 1.0f);
324 if(e == 0) {
325 if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
326 else return sgn * powf(2, -14.0f) * ((float)m / 1024.0f);
327 } else if(e < 31) {
328 return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
329 } else {
330 if(m == 0) return sgn * INFINITY;
331 else return NAN;
335 static inline float float_24_to_32(DWORD in)
337 const float sgn = in & 0x800000u ? -1.0f : 1.0f;
338 const unsigned short e = (in & 0x780000u) >> 19;
339 const unsigned int m = in & 0x7ffffu;
341 if (e == 0)
343 if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
344 else return sgn * powf(2, -6.0f) * ((float)m / 524288.0f);
346 else if (e < 15)
348 return sgn * powf(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
350 else
352 if (m == 0) return sgn * INFINITY;
353 else return NAN;
357 static inline unsigned short float_32_to_16(const float *in)
359 int exp = 0;
360 float tmp = fabsf(*in);
361 unsigned int mantissa;
362 unsigned short ret;
364 /* Deal with special numbers */
365 if (*in == 0.0f)
366 return 0x0000;
367 if (isnan(*in))
368 return 0x7c01;
369 if (isinf(*in))
370 return (*in < 0.0f ? 0xfc00 : 0x7c00);
372 if (tmp < (float)(1u << 10))
376 tmp = tmp * 2.0f;
377 exp--;
378 } while (tmp < (float)(1u << 10));
380 else if (tmp >= (float)(1u << 11))
384 tmp /= 2.0f;
385 exp++;
386 } while (tmp >= (float)(1u << 11));
389 mantissa = (unsigned int)tmp;
390 if (tmp - mantissa >= 0.5f)
391 ++mantissa; /* Round to nearest, away from zero. */
393 exp += 10; /* Normalize the mantissa. */
394 exp += 15; /* Exponent is encoded with excess 15. */
396 if (exp > 30) /* too big */
398 ret = 0x7c00; /* INF */
400 else if (exp <= 0)
402 /* exp == 0: Non-normalized mantissa. Returns 0x0000 (=0.0) for too small numbers. */
403 while (exp <= 0)
405 mantissa = mantissa >> 1;
406 ++exp;
408 ret = mantissa & 0x3ff;
410 else
412 ret = (exp << 10) | (mantissa & 0x3ff);
415 ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
416 return ret;
419 static inline unsigned int wined3d_popcount(unsigned int x)
421 #if defined(__MINGW32__)
422 return __builtin_popcount(x);
423 #else
424 x -= x >> 1 & 0x55555555;
425 x = (x & 0x33333333) + (x >> 2 & 0x33333333);
426 return ((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
427 #endif
430 static inline int wined3d_uint32_compare(uint32_t x, uint32_t y)
432 return (x > y) - (x < y);
435 static inline int wined3d_uint64_compare(uint64_t x, uint64_t y)
437 return (x > y) - (x < y);
440 #define ORM_BACKBUFFER 0
441 #define ORM_FBO 1
443 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
444 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
446 enum wined3d_shader_backend
448 WINED3D_SHADER_BACKEND_AUTO,
449 WINED3D_SHADER_BACKEND_GLSL,
450 WINED3D_SHADER_BACKEND_ARB,
451 WINED3D_SHADER_BACKEND_NONE,
454 #define WINED3D_CSMT_ENABLE 0x00000001
455 #define WINED3D_CSMT_SERIALIZE 0x00000002
457 /* NOTE: When adding fields to this structure, make sure to update the default
458 * values in wined3d_main.c as well. */
459 struct wined3d_settings
461 unsigned int cs_multithreaded;
462 unsigned int max_gl_version;
463 int offscreen_rendering_mode;
464 unsigned short pci_vendor_id;
465 unsigned short pci_device_id;
466 /* Memory tracking and object counting. */
467 UINT64 emulated_textureram;
468 char *logo;
469 unsigned int multisample_textures;
470 unsigned int sample_count;
471 BOOL check_float_constants;
472 unsigned int strict_shader_math;
473 unsigned int max_sm_vs;
474 unsigned int max_sm_hs;
475 unsigned int max_sm_ds;
476 unsigned int max_sm_gs;
477 unsigned int max_sm_ps;
478 unsigned int max_sm_cs;
479 enum wined3d_renderer renderer;
480 enum wined3d_shader_backend shader_backend;
481 BOOL cb_access_map_w;
484 extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
486 enum wined3d_shader_resource_type
488 WINED3D_SHADER_RESOURCE_NONE,
489 WINED3D_SHADER_RESOURCE_BUFFER,
490 WINED3D_SHADER_RESOURCE_TEXTURE_1D,
491 WINED3D_SHADER_RESOURCE_TEXTURE_2D,
492 WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
493 WINED3D_SHADER_RESOURCE_TEXTURE_3D,
494 WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
495 WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
496 WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
497 WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
498 WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY,
501 #define WINED3D_SHADER_CONST_VS_F 0x00000001
502 #define WINED3D_SHADER_CONST_VS_I 0x00000002
503 #define WINED3D_SHADER_CONST_VS_B 0x00000004
504 #define WINED3D_SHADER_CONST_VS_CLIP_PLANES 0x00000008
505 #define WINED3D_SHADER_CONST_VS_POINTSIZE 0x00000010
506 #define WINED3D_SHADER_CONST_POS_FIXUP 0x00000020
507 #define WINED3D_SHADER_CONST_PS_F 0x00000040
508 #define WINED3D_SHADER_CONST_PS_I 0x00000080
509 #define WINED3D_SHADER_CONST_PS_B 0x00000100
510 #define WINED3D_SHADER_CONST_PS_BUMP_ENV 0x00000200
511 #define WINED3D_SHADER_CONST_PS_FOG 0x00000400
512 #define WINED3D_SHADER_CONST_PS_ALPHA_TEST 0x00000800
513 #define WINED3D_SHADER_CONST_PS_Y_CORR 0x00001000
514 #define WINED3D_SHADER_CONST_PS_NP2_FIXUP 0x00002000
515 #define WINED3D_SHADER_CONST_FFP_MODELVIEW 0x00004000
516 #define WINED3D_SHADER_CONST_FFP_VERTEXBLEND 0x00008000
517 #define WINED3D_SHADER_CONST_FFP_PROJ 0x00010000
518 #define WINED3D_SHADER_CONST_FFP_TEXMATRIX 0x00020000
519 #define WINED3D_SHADER_CONST_FFP_MATERIAL 0x00040000
520 #define WINED3D_SHADER_CONST_FFP_LIGHTS 0x00080000
521 #define WINED3D_SHADER_CONST_FFP_PS 0x00100000
522 #define WINED3D_SHADER_CONST_FFP_COLOR_KEY 0x00200000
523 #define WINED3D_SHADER_CONST_BASE_VERTEX_ID 0x00400000
525 enum wined3d_shader_register_type
527 WINED3DSPR_TEMP = 0,
528 WINED3DSPR_INPUT = 1,
529 WINED3DSPR_CONST = 2,
530 WINED3DSPR_ADDR = 3,
531 WINED3DSPR_TEXTURE = 3,
532 WINED3DSPR_RASTOUT = 4,
533 WINED3DSPR_ATTROUT = 5,
534 WINED3DSPR_TEXCRDOUT = 6,
535 WINED3DSPR_OUTPUT = 6,
536 WINED3DSPR_CONSTINT = 7,
537 WINED3DSPR_COLOROUT = 8,
538 WINED3DSPR_DEPTHOUT = 9,
539 WINED3DSPR_SAMPLER = 10,
540 WINED3DSPR_CONST2 = 11,
541 WINED3DSPR_CONST3 = 12,
542 WINED3DSPR_CONST4 = 13,
543 WINED3DSPR_CONSTBOOL = 14,
544 WINED3DSPR_LOOP = 15,
545 WINED3DSPR_TEMPFLOAT16 = 16,
546 WINED3DSPR_MISCTYPE = 17,
547 WINED3DSPR_LABEL = 18,
548 WINED3DSPR_PREDICATE = 19,
549 WINED3DSPR_IMMCONST,
550 WINED3DSPR_CONSTBUFFER,
551 WINED3DSPR_IMMCONSTBUFFER,
552 WINED3DSPR_PRIMID,
553 WINED3DSPR_NULL,
554 WINED3DSPR_RESOURCE,
555 WINED3DSPR_UAV,
556 WINED3DSPR_OUTPOINTID,
557 WINED3DSPR_FORKINSTID,
558 WINED3DSPR_JOININSTID,
559 WINED3DSPR_INCONTROLPOINT,
560 WINED3DSPR_OUTCONTROLPOINT,
561 WINED3DSPR_PATCHCONST,
562 WINED3DSPR_TESSCOORD,
563 WINED3DSPR_GROUPSHAREDMEM,
564 WINED3DSPR_THREADID,
565 WINED3DSPR_THREADGROUPID,
566 WINED3DSPR_LOCALTHREADID,
567 WINED3DSPR_LOCALTHREADINDEX,
568 WINED3DSPR_IDXTEMP,
569 WINED3DSPR_STREAM,
570 WINED3DSPR_FUNCTIONBODY,
571 WINED3DSPR_FUNCTIONPOINTER,
572 WINED3DSPR_COVERAGE,
573 WINED3DSPR_SAMPLEMASK,
574 WINED3DSPR_GSINSTID,
575 WINED3DSPR_DEPTHOUTGE,
576 WINED3DSPR_DEPTHOUTLE,
577 WINED3DSPR_RASTERIZER,
580 enum wined3d_data_type
582 WINED3D_DATA_FLOAT,
583 WINED3D_DATA_INT,
584 WINED3D_DATA_RESOURCE,
585 WINED3D_DATA_SAMPLER,
586 WINED3D_DATA_UAV,
587 WINED3D_DATA_UINT,
588 WINED3D_DATA_UNORM,
589 WINED3D_DATA_SNORM,
590 WINED3D_DATA_OPAQUE,
593 enum wined3d_immconst_type
595 WINED3D_IMMCONST_SCALAR,
596 WINED3D_IMMCONST_VEC4,
599 #define WINED3DSP_NOSWIZZLE (0u | (1u << 2) | (2u << 4) | (3u << 6))
601 enum wined3d_shader_src_modifier
603 WINED3DSPSM_NONE = 0,
604 WINED3DSPSM_NEG = 1,
605 WINED3DSPSM_BIAS = 2,
606 WINED3DSPSM_BIASNEG = 3,
607 WINED3DSPSM_SIGN = 4,
608 WINED3DSPSM_SIGNNEG = 5,
609 WINED3DSPSM_COMP = 6,
610 WINED3DSPSM_X2 = 7,
611 WINED3DSPSM_X2NEG = 8,
612 WINED3DSPSM_DZ = 9,
613 WINED3DSPSM_DW = 10,
614 WINED3DSPSM_ABS = 11,
615 WINED3DSPSM_ABSNEG = 12,
616 WINED3DSPSM_NOT = 13,
619 #define WINED3DSP_WRITEMASK_0 0x1u /* .x r */
620 #define WINED3DSP_WRITEMASK_1 0x2u /* .y g */
621 #define WINED3DSP_WRITEMASK_2 0x4u /* .z b */
622 #define WINED3DSP_WRITEMASK_3 0x8u /* .w a */
623 #define WINED3DSP_WRITEMASK_ALL 0xfu /* all */
625 enum wined3d_shader_dst_modifier
627 WINED3DSPDM_NONE = 0,
628 WINED3DSPDM_SATURATE = 1,
629 WINED3DSPDM_PARTIALPRECISION = 2,
630 WINED3DSPDM_MSAMPCENTROID = 4,
633 enum wined3d_shader_interpolation_mode
635 WINED3DSIM_NONE = 0,
636 WINED3DSIM_CONSTANT = 1,
637 WINED3DSIM_LINEAR = 2,
638 WINED3DSIM_LINEAR_CENTROID = 3,
639 WINED3DSIM_LINEAR_NOPERSPECTIVE = 4,
640 WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID = 5,
641 WINED3DSIM_LINEAR_SAMPLE = 6,
642 WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
645 #define WINED3D_PACKED_INTERPOLATION_SIZE 3
646 #define WINED3D_PACKED_INTERPOLATION_BIT_COUNT 3
648 enum wined3d_shader_global_flags
650 WINED3DSGF_REFACTORING_ALLOWED = 0x1,
651 WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL = 0x4,
652 WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS = 0x8,
655 enum wined3d_shader_sync_flags
657 WINED3DSSF_THREAD_GROUP = 0x1,
658 WINED3DSSF_GROUP_SHARED_MEMORY = 0x2,
659 WINED3DSSF_GLOBAL_UAV = 0x8,
662 enum wined3d_shader_uav_flags
664 WINED3DSUF_GLOBALLY_COHERENT = 0x2,
665 WINED3DSUF_ORDER_PRESERVING_COUNTER = 0x100,
668 enum wined3d_tessellator_domain
670 WINED3D_TESSELLATOR_DOMAIN_LINE = 1,
671 WINED3D_TESSELLATOR_DOMAIN_TRIANGLE = 2,
672 WINED3D_TESSELLATOR_DOMAIN_QUAD = 3,
675 enum wined3d_tessellator_output_primitive
677 WINED3D_TESSELLATOR_OUTPUT_POINT = 1,
678 WINED3D_TESSELLATOR_OUTPUT_LINE = 2,
679 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
680 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4,
683 enum wined3d_tessellator_partitioning
685 WINED3D_TESSELLATOR_PARTITIONING_INTEGER = 1,
686 WINED3D_TESSELLATOR_PARTITIONING_POW2 = 2,
687 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
688 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4,
691 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
692 #define WINED3DSI_TEXLD_PROJECT 0x1
693 #define WINED3DSI_TEXLD_BIAS 0x2
694 #define WINED3DSI_INDEXED_DYNAMIC 0x4
695 #define WINED3DSI_RESINFO_RCP_FLOAT 0x1
696 #define WINED3DSI_RESINFO_UINT 0x2
697 #define WINED3DSI_SAMPLE_INFO_UINT 0x1
698 #define WINED3DSI_SAMPLER_COMPARISON_MODE 0x1
700 #define WINED3DSI_PRECISE_X 0x100
701 #define WINED3DSI_PRECISE_Y 0x200
702 #define WINED3DSI_PRECISE_Z 0x400
703 #define WINED3DSI_PRECISE_W 0x800
704 #define WINED3DSI_PRECISE_XYZW (WINED3DSI_PRECISE_X | WINED3DSI_PRECISE_Y \
705 | WINED3DSI_PRECISE_Z | WINED3DSI_PRECISE_W)
706 #define WINED3DSI_PRECISE_SHIFT 8
708 enum wined3d_shader_rel_op
710 WINED3D_SHADER_REL_OP_GT = 1,
711 WINED3D_SHADER_REL_OP_EQ = 2,
712 WINED3D_SHADER_REL_OP_GE = 3,
713 WINED3D_SHADER_REL_OP_LT = 4,
714 WINED3D_SHADER_REL_OP_NE = 5,
715 WINED3D_SHADER_REL_OP_LE = 6,
718 enum wined3d_shader_conditional_op
720 WINED3D_SHADER_CONDITIONAL_OP_NZ = 0,
721 WINED3D_SHADER_CONDITIONAL_OP_Z = 1
724 enum wined3d_sysval_semantic
726 WINED3D_SV_POSITION = 0x01,
727 WINED3D_SV_CLIP_DISTANCE = 0x02,
728 WINED3D_SV_CULL_DISTANCE = 0x03,
729 WINED3D_SV_RENDER_TARGET_ARRAY_INDEX = 0x04,
730 WINED3D_SV_VIEWPORT_ARRAY_INDEX = 0x05,
731 WINED3D_SV_VERTEX_ID = 0x06,
732 WINED3D_SV_PRIMITIVE_ID = 0x07,
733 WINED3D_SV_INSTANCE_ID = 0x08,
734 WINED3D_SV_IS_FRONT_FACE = 0x09,
735 WINED3D_SV_SAMPLE_INDEX = 0x0a,
736 WINED3D_SV_TESS_FACTOR_QUADEDGE = 0x0b,
737 WINED3D_SV_TESS_FACTOR_QUADINT = 0x0c,
738 WINED3D_SV_TESS_FACTOR_TRIEDGE = 0x0d,
739 WINED3D_SV_TESS_FACTOR_TRIINT = 0x0e,
740 WINED3D_SV_TESS_FACTOR_LINEDET = 0x0f,
741 WINED3D_SV_TESS_FACTOR_LINEDEN = 0x10,
744 enum wined3d_component_type
746 WINED3D_TYPE_UNKNOWN = 0x0,
747 WINED3D_TYPE_UINT = 0x1,
748 WINED3D_TYPE_INT = 0x2,
749 WINED3D_TYPE_FLOAT = 0x3,
752 struct wined3d_shader_signature_element
754 const char *semantic_name;
755 unsigned int semantic_idx;
756 unsigned int stream_idx;
757 enum wined3d_sysval_semantic sysval_semantic;
758 enum wined3d_component_type component_type;
759 unsigned int register_idx;
760 uint32_t mask;
761 unsigned int min_precision;
764 struct wined3d_shader_signature
766 unsigned int element_count;
767 struct wined3d_shader_signature_element *elements;
770 #define WINED3D_SM1_VS 0xfffeu
771 #define WINED3D_SM1_PS 0xffffu
772 #define WINED3D_SM4_PS 0x0000u
773 #define WINED3D_SM4_VS 0x0001u
774 #define WINED3D_SM4_GS 0x0002u
775 #define WINED3D_SM5_HS 0x0003u
776 #define WINED3D_SM5_DS 0x0004u
777 #define WINED3D_SM5_CS 0x0005u
779 /* Shader version tokens, and shader end tokens */
780 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
781 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
783 /* Shader backends */
785 #define MAX_ATTRIBS 32
786 #define MAX_REG_ADDR 1
787 #define MAX_REG_TEXCRD 8
788 #define MAX_REG_INPUT 32
789 #define MAX_REG_OUTPUT 32
790 #define WINED3D_MAX_CBS 15
792 /* FIXME: This needs to go up to 2048 for
793 * Shader model 3 according to msdn (and for software shaders) */
794 #define MAX_LABELS 16
796 #define MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE 4096
798 struct wined3d_string_buffer
800 struct list entry;
801 char *buffer;
802 unsigned int buffer_size;
803 unsigned int content_size;
806 enum WINED3D_SHADER_INSTRUCTION_HANDLER
808 WINED3DSIH_ABS,
809 WINED3DSIH_ADD,
810 WINED3DSIH_AND,
811 WINED3DSIH_ATOMIC_AND,
812 WINED3DSIH_ATOMIC_CMP_STORE,
813 WINED3DSIH_ATOMIC_IADD,
814 WINED3DSIH_ATOMIC_IMAX,
815 WINED3DSIH_ATOMIC_IMIN,
816 WINED3DSIH_ATOMIC_OR,
817 WINED3DSIH_ATOMIC_UMAX,
818 WINED3DSIH_ATOMIC_UMIN,
819 WINED3DSIH_ATOMIC_XOR,
820 WINED3DSIH_BEM,
821 WINED3DSIH_BFI,
822 WINED3DSIH_BFREV,
823 WINED3DSIH_BREAK,
824 WINED3DSIH_BREAKC,
825 WINED3DSIH_BREAKP,
826 WINED3DSIH_BUFINFO,
827 WINED3DSIH_CALL,
828 WINED3DSIH_CALLNZ,
829 WINED3DSIH_CASE,
830 WINED3DSIH_CMP,
831 WINED3DSIH_CND,
832 WINED3DSIH_CONTINUE,
833 WINED3DSIH_CONTINUEP,
834 WINED3DSIH_COUNTBITS,
835 WINED3DSIH_CRS,
836 WINED3DSIH_CUT,
837 WINED3DSIH_CUT_STREAM,
838 WINED3DSIH_DCL,
839 WINED3DSIH_DCL_CONSTANT_BUFFER,
840 WINED3DSIH_DCL_FUNCTION_BODY,
841 WINED3DSIH_DCL_FUNCTION_TABLE,
842 WINED3DSIH_DCL_GLOBAL_FLAGS,
843 WINED3DSIH_DCL_GS_INSTANCES,
844 WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT,
845 WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT,
846 WINED3DSIH_DCL_HS_MAX_TESSFACTOR,
847 WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER,
848 WINED3DSIH_DCL_INDEX_RANGE,
849 WINED3DSIH_DCL_INDEXABLE_TEMP,
850 WINED3DSIH_DCL_INPUT,
851 WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT,
852 WINED3DSIH_DCL_INPUT_PRIMITIVE,
853 WINED3DSIH_DCL_INPUT_PS,
854 WINED3DSIH_DCL_INPUT_PS_SGV,
855 WINED3DSIH_DCL_INPUT_PS_SIV,
856 WINED3DSIH_DCL_INPUT_SGV,
857 WINED3DSIH_DCL_INPUT_SIV,
858 WINED3DSIH_DCL_INTERFACE,
859 WINED3DSIH_DCL_OUTPUT,
860 WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT,
861 WINED3DSIH_DCL_OUTPUT_SIV,
862 WINED3DSIH_DCL_OUTPUT_TOPOLOGY,
863 WINED3DSIH_DCL_RESOURCE_RAW,
864 WINED3DSIH_DCL_RESOURCE_STRUCTURED,
865 WINED3DSIH_DCL_SAMPLER,
866 WINED3DSIH_DCL_STREAM,
867 WINED3DSIH_DCL_TEMPS,
868 WINED3DSIH_DCL_TESSELLATOR_DOMAIN,
869 WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE,
870 WINED3DSIH_DCL_TESSELLATOR_PARTITIONING,
871 WINED3DSIH_DCL_TGSM_RAW,
872 WINED3DSIH_DCL_TGSM_STRUCTURED,
873 WINED3DSIH_DCL_THREAD_GROUP,
874 WINED3DSIH_DCL_UAV_RAW,
875 WINED3DSIH_DCL_UAV_STRUCTURED,
876 WINED3DSIH_DCL_UAV_TYPED,
877 WINED3DSIH_DCL_VERTICES_OUT,
878 WINED3DSIH_DEF,
879 WINED3DSIH_DEFAULT,
880 WINED3DSIH_DEFB,
881 WINED3DSIH_DEFI,
882 WINED3DSIH_DIV,
883 WINED3DSIH_DP2,
884 WINED3DSIH_DP2ADD,
885 WINED3DSIH_DP3,
886 WINED3DSIH_DP4,
887 WINED3DSIH_DST,
888 WINED3DSIH_DSX,
889 WINED3DSIH_DSX_COARSE,
890 WINED3DSIH_DSX_FINE,
891 WINED3DSIH_DSY,
892 WINED3DSIH_DSY_COARSE,
893 WINED3DSIH_DSY_FINE,
894 WINED3DSIH_ELSE,
895 WINED3DSIH_EMIT,
896 WINED3DSIH_EMIT_STREAM,
897 WINED3DSIH_ENDIF,
898 WINED3DSIH_ENDLOOP,
899 WINED3DSIH_ENDREP,
900 WINED3DSIH_ENDSWITCH,
901 WINED3DSIH_EQ,
902 WINED3DSIH_EVAL_CENTROID,
903 WINED3DSIH_EVAL_SAMPLE_INDEX,
904 WINED3DSIH_EXP,
905 WINED3DSIH_EXPP,
906 WINED3DSIH_F16TOF32,
907 WINED3DSIH_F32TOF16,
908 WINED3DSIH_FCALL,
909 WINED3DSIH_FIRSTBIT_HI,
910 WINED3DSIH_FIRSTBIT_LO,
911 WINED3DSIH_FIRSTBIT_SHI,
912 WINED3DSIH_FRC,
913 WINED3DSIH_FTOI,
914 WINED3DSIH_FTOU,
915 WINED3DSIH_GATHER4,
916 WINED3DSIH_GATHER4_C,
917 WINED3DSIH_GATHER4_PO,
918 WINED3DSIH_GATHER4_PO_C,
919 WINED3DSIH_GE,
920 WINED3DSIH_HS_CONTROL_POINT_PHASE,
921 WINED3DSIH_HS_DECLS,
922 WINED3DSIH_HS_FORK_PHASE,
923 WINED3DSIH_HS_JOIN_PHASE,
924 WINED3DSIH_IADD,
925 WINED3DSIH_IBFE,
926 WINED3DSIH_IEQ,
927 WINED3DSIH_IF,
928 WINED3DSIH_IFC,
929 WINED3DSIH_IGE,
930 WINED3DSIH_ILT,
931 WINED3DSIH_IMAD,
932 WINED3DSIH_IMAX,
933 WINED3DSIH_IMIN,
934 WINED3DSIH_IMM_ATOMIC_ALLOC,
935 WINED3DSIH_IMM_ATOMIC_AND,
936 WINED3DSIH_IMM_ATOMIC_CMP_EXCH,
937 WINED3DSIH_IMM_ATOMIC_CONSUME,
938 WINED3DSIH_IMM_ATOMIC_EXCH,
939 WINED3DSIH_IMM_ATOMIC_IADD,
940 WINED3DSIH_IMM_ATOMIC_IMAX,
941 WINED3DSIH_IMM_ATOMIC_IMIN,
942 WINED3DSIH_IMM_ATOMIC_OR,
943 WINED3DSIH_IMM_ATOMIC_UMAX,
944 WINED3DSIH_IMM_ATOMIC_UMIN,
945 WINED3DSIH_IMM_ATOMIC_XOR,
946 WINED3DSIH_IMUL,
947 WINED3DSIH_INE,
948 WINED3DSIH_INEG,
949 WINED3DSIH_ISHL,
950 WINED3DSIH_ISHR,
951 WINED3DSIH_ITOF,
952 WINED3DSIH_LABEL,
953 WINED3DSIH_LD,
954 WINED3DSIH_LD2DMS,
955 WINED3DSIH_LD_RAW,
956 WINED3DSIH_LD_STRUCTURED,
957 WINED3DSIH_LD_UAV_TYPED,
958 WINED3DSIH_LIT,
959 WINED3DSIH_LOD,
960 WINED3DSIH_LOG,
961 WINED3DSIH_LOGP,
962 WINED3DSIH_LOOP,
963 WINED3DSIH_LRP,
964 WINED3DSIH_LT,
965 WINED3DSIH_M3x2,
966 WINED3DSIH_M3x3,
967 WINED3DSIH_M3x4,
968 WINED3DSIH_M4x3,
969 WINED3DSIH_M4x4,
970 WINED3DSIH_MAD,
971 WINED3DSIH_MAX,
972 WINED3DSIH_MIN,
973 WINED3DSIH_MOV,
974 WINED3DSIH_MOVA,
975 WINED3DSIH_MOVC,
976 WINED3DSIH_MUL,
977 WINED3DSIH_NE,
978 WINED3DSIH_NOP,
979 WINED3DSIH_NOT,
980 WINED3DSIH_NRM,
981 WINED3DSIH_OR,
982 WINED3DSIH_PHASE,
983 WINED3DSIH_POW,
984 WINED3DSIH_RCP,
985 WINED3DSIH_REP,
986 WINED3DSIH_RESINFO,
987 WINED3DSIH_RET,
988 WINED3DSIH_RETP,
989 WINED3DSIH_ROUND_NE,
990 WINED3DSIH_ROUND_NI,
991 WINED3DSIH_ROUND_PI,
992 WINED3DSIH_ROUND_Z,
993 WINED3DSIH_RSQ,
994 WINED3DSIH_SAMPLE,
995 WINED3DSIH_SAMPLE_B,
996 WINED3DSIH_SAMPLE_C,
997 WINED3DSIH_SAMPLE_C_LZ,
998 WINED3DSIH_SAMPLE_GRAD,
999 WINED3DSIH_SAMPLE_INFO,
1000 WINED3DSIH_SAMPLE_LOD,
1001 WINED3DSIH_SAMPLE_POS,
1002 WINED3DSIH_SETP,
1003 WINED3DSIH_SGE,
1004 WINED3DSIH_SGN,
1005 WINED3DSIH_SINCOS,
1006 WINED3DSIH_SLT,
1007 WINED3DSIH_SQRT,
1008 WINED3DSIH_STORE_RAW,
1009 WINED3DSIH_STORE_STRUCTURED,
1010 WINED3DSIH_STORE_UAV_TYPED,
1011 WINED3DSIH_SUB,
1012 WINED3DSIH_SWAPC,
1013 WINED3DSIH_SWITCH,
1014 WINED3DSIH_SYNC,
1015 WINED3DSIH_TEX,
1016 WINED3DSIH_TEXBEM,
1017 WINED3DSIH_TEXBEML,
1018 WINED3DSIH_TEXCOORD,
1019 WINED3DSIH_TEXDEPTH,
1020 WINED3DSIH_TEXDP3,
1021 WINED3DSIH_TEXDP3TEX,
1022 WINED3DSIH_TEXKILL,
1023 WINED3DSIH_TEXLDD,
1024 WINED3DSIH_TEXLDL,
1025 WINED3DSIH_TEXM3x2DEPTH,
1026 WINED3DSIH_TEXM3x2PAD,
1027 WINED3DSIH_TEXM3x2TEX,
1028 WINED3DSIH_TEXM3x3,
1029 WINED3DSIH_TEXM3x3DIFF,
1030 WINED3DSIH_TEXM3x3PAD,
1031 WINED3DSIH_TEXM3x3SPEC,
1032 WINED3DSIH_TEXM3x3TEX,
1033 WINED3DSIH_TEXM3x3VSPEC,
1034 WINED3DSIH_TEXREG2AR,
1035 WINED3DSIH_TEXREG2GB,
1036 WINED3DSIH_TEXREG2RGB,
1037 WINED3DSIH_UBFE,
1038 WINED3DSIH_UDIV,
1039 WINED3DSIH_UGE,
1040 WINED3DSIH_ULT,
1041 WINED3DSIH_UMAX,
1042 WINED3DSIH_UMIN,
1043 WINED3DSIH_UMUL,
1044 WINED3DSIH_USHR,
1045 WINED3DSIH_UTOF,
1046 WINED3DSIH_XOR,
1047 WINED3DSIH_TABLE_SIZE
1050 struct wined3d_shader_version
1052 enum wined3d_shader_type type;
1053 BYTE major;
1054 BYTE minor;
1057 struct wined3d_shader_resource_info
1059 enum wined3d_shader_resource_type type;
1060 enum wined3d_data_type data_type;
1061 unsigned int flags;
1062 unsigned int stride;
1065 #define WINED3D_SAMPLER_DEFAULT ~0x0u
1067 struct wined3d_shader_sampler_map_entry
1069 unsigned int resource_idx;
1070 unsigned int sampler_idx;
1071 unsigned int bind_idx;
1074 struct wined3d_shader_sampler_map
1076 struct wined3d_shader_sampler_map_entry *entries;
1077 size_t size;
1078 size_t count;
1081 struct wined3d_shader_immediate_constant_buffer
1083 unsigned int vec4_count;
1084 uint32_t data[MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE];
1087 struct wined3d_shader_indexable_temp
1089 struct list entry;
1090 unsigned int register_idx;
1091 unsigned int register_size;
1092 unsigned int component_count;
1095 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
1097 struct wined3d_shader_reg_maps
1099 struct wined3d_shader_version shader_version;
1100 BYTE texcoord; /* MAX_REG_TEXCRD, 8 */
1101 BYTE address; /* MAX_REG_ADDR, 1 */
1102 WORD labels; /* MAX_LABELS, 16 */
1103 DWORD temporary; /* 32 */
1104 unsigned int temporary_count;
1105 uint32_t *constf; /* pixel, vertex */
1106 struct list indexable_temps;
1107 const struct wined3d_shader_immediate_constant_buffer *icb;
1108 union
1110 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
1111 BYTE output_registers_mask[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1112 } u;
1113 DWORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 32 */
1114 DWORD output_registers; /* MAX_REG_OUTPUT, 32 */
1115 WORD integer_constants; /* WINED3D_MAX_CONSTS_I, 16 */
1116 WORD boolean_constants; /* WINED3D_MAX_CONSTS_B, 16 */
1117 WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */
1118 WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */
1119 UINT cb_sizes[WINED3D_MAX_CBS];
1120 uint32_t cb_map; /* WINED3D_MAX_CBS, 15 */
1122 struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS];
1123 uint32_t resource_map[WINED3D_BITMAP_SIZE(MAX_SHADER_RESOURCE_VIEWS)];
1124 struct wined3d_shader_sampler_map sampler_map;
1125 DWORD sampler_comparison_mode;
1126 BYTE bumpmat; /* WINED3D_MAX_TEXTURES, 8 */
1127 BYTE luminanceparams; /* WINED3D_MAX_TEXTURES, 8 */
1128 struct wined3d_shader_resource_info uav_resource_info[MAX_UNORDERED_ACCESS_VIEWS];
1129 DWORD uav_read_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1130 DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1132 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1133 DWORD cull_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1134 DWORD usesnrm : 1;
1135 DWORD vpos : 1;
1136 DWORD usesdsx : 1;
1137 DWORD usesdsy : 1;
1138 DWORD usestexldd : 1;
1139 DWORD usesmova : 1;
1140 DWORD usesfacing : 1;
1141 DWORD usesrelconstF : 1;
1142 DWORD fog : 1;
1143 DWORD usestexldl : 1;
1144 DWORD usesifc : 1;
1145 DWORD usescall : 1;
1146 DWORD usespow : 1;
1147 DWORD point_size : 1;
1148 DWORD vocp : 1;
1149 DWORD input_rel_addressing : 1;
1150 DWORD viewport_array : 1;
1151 DWORD sample_mask : 1;
1152 DWORD padding : 14;
1154 DWORD rt_mask; /* Used render targets, 32 max. */
1156 /* Whether or not loops are used in this shader, and nesting depth */
1157 unsigned int loop_depth;
1158 unsigned int min_rel_offset, max_rel_offset;
1160 struct wined3d_shader_tgsm *tgsm;
1161 SIZE_T tgsm_capacity;
1162 unsigned int tgsm_count;
1165 /* Keeps track of details for TEX_M#x# instructions which need to maintain
1166 * state information between multiple instructions. */
1167 struct wined3d_shader_tex_mx
1169 unsigned int current_row;
1170 unsigned int texcoord_w[2];
1173 struct wined3d_shader_parser_state
1175 unsigned int current_loop_depth;
1176 unsigned int current_loop_reg;
1177 BOOL in_subroutine;
1180 struct wined3d_shader_context
1182 const struct wined3d_shader *shader;
1183 const struct wined3d_shader_reg_maps *reg_maps;
1184 struct wined3d_string_buffer *buffer;
1185 struct wined3d_shader_tex_mx *tex_mx;
1186 struct wined3d_shader_parser_state *state;
1187 void *backend_data;
1190 struct wined3d_shader_register_index
1192 const struct wined3d_shader_src_param *rel_addr;
1193 unsigned int offset;
1196 struct wined3d_shader_register
1198 enum wined3d_shader_register_type type;
1199 enum wined3d_data_type data_type;
1200 struct wined3d_shader_register_index idx[2];
1201 enum wined3d_immconst_type immconst_type;
1202 union
1204 unsigned int immconst_data[4];
1205 unsigned fp_body_idx;
1206 } u;
1209 struct wined3d_shader_dst_param
1211 struct wined3d_shader_register reg;
1212 uint32_t write_mask;
1213 uint32_t modifiers;
1214 unsigned int shift;
1217 struct wined3d_shader_src_param
1219 struct wined3d_shader_register reg;
1220 DWORD swizzle;
1221 enum wined3d_shader_src_modifier modifiers;
1224 struct wined3d_shader_index_range
1226 struct wined3d_shader_dst_param first_register;
1227 unsigned int last_register;
1230 struct wined3d_shader_semantic
1232 enum wined3d_decl_usage usage;
1233 UINT usage_idx;
1234 enum wined3d_shader_resource_type resource_type;
1235 unsigned int sample_count;
1236 enum wined3d_data_type resource_data_type;
1237 struct wined3d_shader_dst_param reg;
1240 enum wined3d_shader_input_sysval_semantic
1242 WINED3D_SIV_POSITION = 1,
1243 WINED3D_SIV_CLIP_DISTANCE = 2,
1244 WINED3D_SIV_CULL_DISTANCE = 3,
1245 WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX = 4,
1246 WINED3D_SIV_VIEWPORT_ARRAY_INDEX = 5,
1247 WINED3D_SIV_VERTEX_ID = 6,
1248 WINED3D_SIV_PRIMITIVE_ID = 7,
1249 WINED3D_SIV_INSTANCE_ID = 8,
1250 WINED3D_SIV_IS_FRONT_FACE = 9,
1251 WINED3D_SIV_SAMPLE_INDEX = 10,
1252 WINED3D_SIV_QUAD_U0_TESS_FACTOR = 11,
1253 WINED3D_SIV_QUAD_V0_TESS_FACTOR = 12,
1254 WINED3D_SIV_QUAD_U1_TESS_FACTOR = 13,
1255 WINED3D_SIV_QUAD_V1_TESS_FACTOR = 14,
1256 WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR = 15,
1257 WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR = 16,
1258 WINED3D_SIV_TRIANGLE_U_TESS_FACTOR = 17,
1259 WINED3D_SIV_TRIANGLE_V_TESS_FACTOR = 18,
1260 WINED3D_SIV_TRIANGLE_W_TESS_FACTOR = 19,
1261 WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR = 20,
1262 WINED3D_SIV_LINE_DETAIL_TESS_FACTOR = 21,
1263 WINED3D_SIV_LINE_DENSITY_TESS_FACTOR = 22,
1266 struct wined3d_shader_register_semantic
1268 struct wined3d_shader_dst_param reg;
1269 enum wined3d_shader_input_sysval_semantic sysval_semantic;
1272 struct wined3d_shader_structured_resource
1274 struct wined3d_shader_dst_param reg;
1275 unsigned int byte_stride;
1278 struct wined3d_shader_tgsm
1280 unsigned int size;
1281 unsigned int stride;
1284 struct wined3d_shader_tgsm_raw
1286 struct wined3d_shader_dst_param reg;
1287 unsigned int byte_count;
1290 struct wined3d_shader_tgsm_structured
1292 struct wined3d_shader_dst_param reg;
1293 unsigned int byte_stride;
1294 unsigned int structure_count;
1297 struct wined3d_shader_thread_group_size
1299 unsigned int x, y, z;
1302 struct wined3d_shader_function_table_pointer
1304 unsigned int index;
1305 unsigned int array_size;
1306 unsigned int body_count;
1307 unsigned int table_count;
1310 struct wined3d_shader_texel_offset
1312 signed char u, v, w;
1315 struct wined3d_shader_primitive_type
1317 enum wined3d_primitive_type type;
1318 unsigned int patch_vertex_count;
1321 struct wined3d_shader_instruction
1323 const struct wined3d_shader_context *ctx;
1324 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
1325 uint32_t flags;
1326 unsigned int dst_count;
1327 unsigned int src_count;
1328 const struct wined3d_shader_dst_param *dst;
1329 const struct wined3d_shader_src_param *src;
1330 struct wined3d_shader_texel_offset texel_offset;
1331 enum wined3d_shader_resource_type resource_type;
1332 enum wined3d_data_type resource_data_type;
1333 BOOL coissue;
1334 const struct wined3d_shader_src_param *predicate;
1335 union
1337 struct wined3d_shader_semantic semantic;
1338 struct wined3d_shader_register_semantic register_semantic;
1339 struct wined3d_shader_primitive_type primitive_type;
1340 struct wined3d_shader_dst_param dst;
1341 struct wined3d_shader_src_param src;
1342 unsigned int count;
1343 unsigned int index;
1344 const struct wined3d_shader_immediate_constant_buffer *icb;
1345 struct wined3d_shader_structured_resource structured_resource;
1346 struct wined3d_shader_tgsm_raw tgsm_raw;
1347 struct wined3d_shader_tgsm_structured tgsm_structured;
1348 struct wined3d_shader_thread_group_size thread_group_size;
1349 enum wined3d_tessellator_domain tessellator_domain;
1350 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1351 enum wined3d_tessellator_partitioning tessellator_partitioning;
1352 float max_tessellation_factor;
1353 struct wined3d_shader_index_range index_range;
1354 struct wined3d_shader_indexable_temp indexable_temp;
1355 struct wined3d_shader_function_table_pointer fp;
1356 } declaration;
1359 static inline BOOL wined3d_shader_instruction_has_texel_offset(const struct wined3d_shader_instruction *ins)
1361 return ins->texel_offset.u || ins->texel_offset.v || ins->texel_offset.w;
1364 struct wined3d_shader_attribute
1366 enum wined3d_decl_usage usage;
1367 UINT usage_idx;
1370 struct wined3d_shader_loop_control
1372 unsigned int count;
1373 unsigned int start;
1374 int step;
1377 struct wined3d_shader_frontend
1379 void *(*shader_init)(const DWORD *byte_code, size_t byte_code_size,
1380 const struct wined3d_shader_signature *output_signature);
1381 void (*shader_free)(void *data);
1382 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
1383 void (*shader_read_instruction)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins);
1384 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
1387 extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
1388 extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
1390 HRESULT wined3d_shader_extract_from_dxbc(struct wined3d_shader *shader,
1391 unsigned int max_shader_version, enum vkd3d_shader_source_type *source_type) DECLSPEC_HIDDEN;
1392 BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader,
1393 const struct wined3d_stream_output_element *so_element, unsigned int *register_idx,
1394 unsigned int *component_idx) DECLSPEC_HIDDEN;
1396 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
1398 #define WINED3D_SHADER_CAP_VS_CLIPPING 0x00000001u
1399 #define WINED3D_SHADER_CAP_SRGB_WRITE 0x00000002u
1400 #define WINED3D_SHADER_CAP_DOUBLE_PRECISION 0x00000004u
1401 #define WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION 0x00000008u
1402 #define WINED3D_SHADER_CAP_FULL_FFP_VARYINGS 0x00000010u
1404 struct shader_caps
1406 unsigned int vs_version;
1407 unsigned int hs_version;
1408 unsigned int ds_version;
1409 unsigned int gs_version;
1410 unsigned int ps_version;
1411 unsigned int cs_version;
1413 unsigned int vs_uniform_count;
1414 unsigned int ps_uniform_count;
1415 float ps_1x_max_value;
1416 unsigned int varying_count;
1418 DWORD wined3d_caps;
1421 enum wined3d_gl_resource_type
1423 WINED3D_GL_RES_TYPE_TEX_1D = 0,
1424 WINED3D_GL_RES_TYPE_TEX_2D = 1,
1425 WINED3D_GL_RES_TYPE_TEX_3D = 2,
1426 WINED3D_GL_RES_TYPE_TEX_CUBE = 3,
1427 WINED3D_GL_RES_TYPE_TEX_RECT = 4,
1428 WINED3D_GL_RES_TYPE_BUFFER = 5,
1429 WINED3D_GL_RES_TYPE_RB = 6,
1430 WINED3D_GL_RES_TYPE_COUNT = 7,
1433 enum wined3d_vertex_processing_mode
1435 WINED3D_VP_MODE_FF,
1436 WINED3D_VP_MODE_SHADER,
1437 WINED3D_VP_MODE_NONE,
1440 #define WINED3D_CONST_NUM_UNUSED ~0U
1442 enum wined3d_ffp_ps_fog_mode
1444 WINED3D_FFP_PS_FOG_OFF,
1445 WINED3D_FFP_PS_FOG_LINEAR,
1446 WINED3D_FFP_PS_FOG_EXP,
1447 WINED3D_FFP_PS_FOG_EXP2,
1450 /* Stateblock dependent parameters which have to be hardcoded
1451 * into the shader code
1454 #define WINED3D_PSARGS_PROJECTED (1u << 3)
1455 #define WINED3D_PSARGS_TEXTRANSFORM_SHIFT 4
1456 #define WINED3D_PSARGS_TEXTRANSFORM_MASK 0xfu
1457 #define WINED3D_PSARGS_TEXTYPE_SHIFT 2
1458 #define WINED3D_PSARGS_TEXTYPE_MASK 0x3u
1460 /* Used for Shader Model 1 pixel shaders to track the bound texture
1461 * type. 2D and RECT textures are separated through NP2 fixup. */
1462 enum wined3d_shader_tex_types
1464 WINED3D_SHADER_TEX_2D = 0,
1465 WINED3D_SHADER_TEX_3D = 1,
1466 WINED3D_SHADER_TEX_CUBE = 2,
1467 WINED3D_SHADER_TEX_ERR = 3,
1470 struct ps_compile_args
1472 struct color_fixup_desc color_fixup[WINED3D_MAX_FRAGMENT_SAMPLERS];
1473 enum wined3d_vertex_processing_mode vp_mode;
1474 enum wined3d_ffp_ps_fog_mode fog;
1475 DWORD tex_types; /* ps 1 - 3, 16 textures */
1476 WORD tex_transform; /* ps 1.0-1.3, 4 textures */
1477 WORD srgb_correction;
1478 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
1479 D3D9 has a limit of 16 samplers and the fixup is superfluous
1480 in D3D10 (unconditional NP2 support mandatory). */
1481 WORD np2_fixup;
1482 WORD shadow; /* WINED3D_MAX_FRAGMENT_SAMPLERS, 16 */
1483 WORD texcoords_initialized; /* WINED3D_MAX_TEXTURES, 8 */
1484 WORD padding_to_dword;
1485 DWORD pointsprite : 1;
1486 DWORD flatshading : 1;
1487 DWORD alpha_test_func : 3;
1488 DWORD y_correction : 1;
1489 DWORD rt_alpha_swizzle : 8; /* WINED3D_MAX_RENDER_TARGETS, 8 */
1490 DWORD dual_source_blend : 1;
1491 DWORD padding : 17;
1494 enum fog_src_type
1496 VS_FOG_Z = 0,
1497 VS_FOG_COORD = 1
1500 struct vs_compile_args
1502 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1503 unsigned int next_shader_input_count;
1504 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1505 BYTE fog_src;
1506 BYTE clip_enabled : 1;
1507 BYTE point_size : 1;
1508 BYTE per_vertex_point_size : 1;
1509 BYTE flatshading : 1;
1510 BYTE next_shader_type : 3;
1511 BYTE padding : 1;
1514 struct ds_compile_args
1516 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1517 enum wined3d_tessellator_partitioning tessellator_partitioning;
1518 unsigned int output_count : 16;
1519 unsigned int next_shader_type : 3;
1520 unsigned int render_offscreen : 1;
1521 unsigned int padding : 12;
1522 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1525 struct gs_compile_args
1527 unsigned int output_count;
1528 enum wined3d_primitive_type primitive_type;
1529 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1532 struct wined3d_shader_backend_ops
1534 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
1535 void (*shader_precompile)(void *shader_priv, struct wined3d_shader *shader);
1536 void (*shader_select)(void *shader_priv, struct wined3d_context *context,
1537 const struct wined3d_state *state);
1538 void (*shader_select_compute)(void *shader_priv, struct wined3d_context *context,
1539 const struct wined3d_state *state);
1540 void (*shader_disable)(void *shader_priv, struct wined3d_context *context);
1541 void (*shader_update_float_vertex_constants)(struct wined3d_device *device, UINT start, UINT count);
1542 void (*shader_update_float_pixel_constants)(struct wined3d_device *device, UINT start, UINT count);
1543 void (*shader_load_constants)(void *shader_priv, struct wined3d_context *context,
1544 const struct wined3d_state *state);
1545 void (*shader_destroy)(struct wined3d_shader *shader);
1546 HRESULT (*shader_alloc_private)(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
1547 const struct wined3d_fragment_pipe_ops *fragment_pipe);
1548 void (*shader_free_private)(struct wined3d_device *device, struct wined3d_context *context);
1549 BOOL (*shader_allocate_context_data)(struct wined3d_context *context);
1550 void (*shader_free_context_data)(struct wined3d_context *context);
1551 void (*shader_init_context_state)(struct wined3d_context *context);
1552 void (*shader_get_caps)(const struct wined3d_adapter *adapter, struct shader_caps *caps);
1553 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
1554 BOOL (*shader_has_ffp_proj_control)(void *shader_priv);
1555 uint64_t (*shader_compile)(struct wined3d_context *context, const struct wined3d_shader_desc *shader_desc,
1556 enum wined3d_shader_type shader_type);
1559 extern const struct wined3d_shader_backend_ops glsl_shader_backend DECLSPEC_HIDDEN;
1560 extern const struct wined3d_shader_backend_ops arb_program_shader_backend DECLSPEC_HIDDEN;
1561 extern const struct wined3d_shader_backend_ops none_shader_backend DECLSPEC_HIDDEN;
1563 const struct wined3d_shader_backend_ops *wined3d_spirv_shader_backend_init_vk(void) DECLSPEC_HIDDEN;
1565 #define GL_EXTCALL(f) (gl_info->gl_ops.ext.p_##f)
1567 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xff)
1568 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xff)
1569 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xff)
1570 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xff)
1572 static inline void wined3d_color_from_d3dcolor(struct wined3d_color *wined3d_color, DWORD d3d_color)
1574 wined3d_color->r = D3DCOLOR_B_R(d3d_color) / 255.0f;
1575 wined3d_color->g = D3DCOLOR_B_G(d3d_color) / 255.0f;
1576 wined3d_color->b = D3DCOLOR_B_B(d3d_color) / 255.0f;
1577 wined3d_color->a = D3DCOLOR_B_A(d3d_color) / 255.0f;
1580 extern const struct wined3d_vec4 wined3d_srgb_const[] DECLSPEC_HIDDEN;
1582 static inline float wined3d_srgb_from_linear(float colour)
1584 if (colour < 0.0f)
1585 return 0.0f;
1586 if (colour < wined3d_srgb_const[1].x)
1587 return colour * wined3d_srgb_const[0].w;
1588 if (colour < 1.0f)
1589 return wined3d_srgb_const[0].y * powf(colour, wined3d_srgb_const[0].x) - wined3d_srgb_const[0].z;
1590 return 1.0f;
1593 static inline void wined3d_colour_srgb_from_linear(struct wined3d_color *colour_srgb,
1594 const struct wined3d_color *colour)
1596 colour_srgb->r = wined3d_srgb_from_linear(colour->r);
1597 colour_srgb->g = wined3d_srgb_from_linear(colour->g);
1598 colour_srgb->b = wined3d_srgb_from_linear(colour->b);
1599 colour_srgb->a = colour->a;
1602 struct wined3d_bo
1604 /* client_map_count and map_ptr are accessed from both the client and CS
1605 * threads, and protected by wined3d_device.bo_map_lock. */
1606 struct list users;
1607 void *map_ptr;
1608 size_t buffer_offset;
1609 size_t memory_offset;
1610 unsigned int client_map_count;
1611 bool coherent;
1612 /* Number of resources referencing this BO, used for COW tracking.
1613 * If a resource has this BO as a location and wants to write to it, it
1614 * needs to make a copy unless it's the only owner (refcount == 1).
1615 * Deferred contexts may also hold a reference. */
1616 uint8_t refcount;
1619 struct wined3d_bo_user
1621 struct list entry;
1622 bool valid;
1625 struct wined3d_bo_address
1627 struct wined3d_bo *buffer_object;
1628 BYTE *addr;
1631 struct wined3d_const_bo_address
1633 struct wined3d_bo *buffer_object;
1634 const BYTE *addr;
1637 static inline struct wined3d_const_bo_address *wined3d_const_bo_address(const struct wined3d_bo_address *data)
1639 return (struct wined3d_const_bo_address *)data;
1642 struct wined3d_stream_info_element
1644 const struct wined3d_format *format;
1645 struct wined3d_bo_address data;
1646 unsigned int stride;
1647 unsigned int stream_idx;
1648 unsigned int divisor;
1649 bool instanced;
1652 struct wined3d_stream_info
1654 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
1655 DWORD position_transformed : 1;
1656 DWORD all_vbo : 1;
1657 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1658 DWORD use_map; /* MAX_ATTRIBS, 32 */
1661 void wined3d_stream_info_from_declaration(struct wined3d_stream_info *stream_info,
1662 const struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info) DECLSPEC_HIDDEN;
1664 struct wined3d_direct_dispatch_parameters
1666 unsigned int group_count_x;
1667 unsigned int group_count_y;
1668 unsigned int group_count_z;
1671 struct wined3d_indirect_dispatch_parameters
1673 struct wined3d_buffer *buffer;
1674 unsigned int offset;
1677 struct wined3d_dispatch_parameters
1679 BOOL indirect;
1680 union
1682 struct wined3d_direct_dispatch_parameters direct;
1683 struct wined3d_indirect_dispatch_parameters indirect;
1684 } u;
1687 struct wined3d_direct_draw_parameters
1689 int base_vertex_idx;
1690 unsigned int start_idx;
1691 unsigned int index_count;
1692 unsigned int start_instance;
1693 unsigned int instance_count;
1696 struct wined3d_indirect_draw_parameters
1698 struct wined3d_buffer *buffer;
1699 unsigned int offset;
1702 struct wined3d_draw_parameters
1704 BOOL indirect;
1705 union
1707 struct wined3d_direct_draw_parameters direct;
1708 struct wined3d_indirect_draw_parameters indirect;
1709 } u;
1710 BOOL indexed;
1713 void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
1714 const struct wined3d_draw_parameters *draw_parameters) DECLSPEC_HIDDEN;
1715 void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
1716 const struct wined3d_dispatch_parameters *dispatch_parameters) DECLSPEC_HIDDEN;
1718 #define eps 1e-8f
1720 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1721 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1723 /* Routines and structures related to state management */
1725 #define STATE_RENDER(a) (a)
1726 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1728 #define STATE_TEXTURESTAGE(stage, num) \
1729 (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
1730 #define STATE_IS_TEXTURESTAGE(a) \
1731 ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1733 /* + 1 because samplers start with 0 */
1734 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
1735 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS - 1))
1737 #define STATE_GRAPHICS_SHADER(a) (STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS) + (a))
1738 #define STATE_IS_GRAPHICS_SHADER(a) \
1739 ((a) >= STATE_GRAPHICS_SHADER(0) && (a) < STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1741 #define STATE_GRAPHICS_CONSTANT_BUFFER(a) (STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT) + (a))
1742 #define STATE_IS_GRAPHICS_CONSTANT_BUFFER(a) \
1743 ((a) >= STATE_GRAPHICS_CONSTANT_BUFFER(0) \
1744 && (a) < STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1746 #define STATE_GRAPHICS_SHADER_RESOURCE_BINDING (STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1747 #define STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(a) ((a) == STATE_GRAPHICS_SHADER_RESOURCE_BINDING)
1749 #define STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING (STATE_GRAPHICS_SHADER_RESOURCE_BINDING + 1)
1750 #define STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING)
1752 #define STATE_TRANSFORM(a) (STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING + (a))
1753 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)))
1755 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1)
1756 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
1757 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1758 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
1760 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
1761 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1763 #define STATE_VIEWPORT (STATE_VDECL + 1)
1764 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1766 #define STATE_LIGHT_TYPE (STATE_VIEWPORT + 1)
1767 #define STATE_IS_LIGHT_TYPE(a) ((a) == STATE_LIGHT_TYPE)
1768 #define STATE_ACTIVELIGHT(a) (STATE_LIGHT_TYPE + 1 + (a))
1769 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS))
1771 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS - 1) + 1)
1772 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1774 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1775 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES - 1))
1777 #define STATE_MATERIAL (STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES))
1778 #define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
1780 #define STATE_RASTERIZER (STATE_MATERIAL + 1)
1781 #define STATE_IS_RASTERIZER(a) ((a) == STATE_RASTERIZER)
1783 #define STATE_DEPTH_BOUNDS (STATE_RASTERIZER + 1)
1784 #define STATE_IS_DEPTH_BOUNDS(a) ((a) == STATE_DEPTH_BOUNDS)
1786 #define STATE_POINTSPRITECOORDORIGIN (STATE_DEPTH_BOUNDS + 1)
1787 #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN)
1789 #define STATE_BASEVERTEXINDEX (STATE_POINTSPRITECOORDORIGIN + 1)
1790 #define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX)
1792 #define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1)
1793 #define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER)
1795 #define STATE_POINT_ENABLE (STATE_FRAMEBUFFER + 1)
1796 #define STATE_IS_POINT_ENABLE(a) ((a) == STATE_POINT_ENABLE)
1798 #define STATE_COLOR_KEY (STATE_POINT_ENABLE + 1)
1799 #define STATE_IS_COLOR_KEY(a) ((a) == STATE_COLOR_KEY)
1801 #define STATE_STREAM_OUTPUT (STATE_COLOR_KEY + 1)
1802 #define STATE_IS_STREAM_OUTPUT(a) ((a) == STATE_STREAM_OUTPUT)
1804 #define STATE_BLEND (STATE_STREAM_OUTPUT + 1)
1805 #define STATE_IS_BLEND(a) ((a) == STATE_BLEND)
1807 #define STATE_BLEND_FACTOR (STATE_BLEND + 1)
1808 #define STATE_IS_BLEND_FACTOR(a) ((a) == STATE_BLEND_FACTOR)
1810 #define STATE_SAMPLE_MASK (STATE_BLEND_FACTOR + 1)
1811 #define STATE_IS_SAMPLE_MASK(a) ((a) == STATE_SAMPLE_MASK)
1813 #define STATE_DEPTH_STENCIL (STATE_SAMPLE_MASK + 1)
1814 #define STATE_IS_DEPTH_STENCIL(a) ((a) == STATE_DEPTH_STENCIL)
1816 #define STATE_STENCIL_REF (STATE_DEPTH_STENCIL + 1)
1817 #define STATE_IS_STENCIL_REF(a) ((a) == STATE_STENCIL_REF)
1819 #define STATE_COMPUTE_OFFSET (STATE_STENCIL_REF + 1)
1821 #define STATE_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
1822 #define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
1824 #define STATE_COMPUTE_CONSTANT_BUFFER (STATE_COMPUTE_SHADER + 1)
1825 #define STATE_IS_COMPUTE_CONSTANT_BUFFER(a) ((a) == STATE_COMPUTE_CONSTANT_BUFFER)
1827 #define STATE_COMPUTE_SHADER_RESOURCE_BINDING (STATE_COMPUTE_CONSTANT_BUFFER + 1)
1828 #define STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(a) ((a) == STATE_COMPUTE_SHADER_RESOURCE_BINDING)
1830 #define STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING (STATE_COMPUTE_SHADER_RESOURCE_BINDING + 1)
1831 #define STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1833 #define STATE_COMPUTE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1834 #define STATE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1836 #define STATE_IS_COMPUTE(a) ((a) >= STATE_COMPUTE_OFFSET && (a) <= STATE_COMPUTE_HIGHEST)
1837 #define STATE_COMPUTE_COUNT (STATE_COMPUTE_HIGHEST - STATE_COMPUTE_OFFSET + 1)
1839 #define STATE_SHADER(a) ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_SHADER(a) : STATE_COMPUTE_SHADER)
1840 #define STATE_CONSTANT_BUFFER(a) \
1841 ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_CONSTANT_BUFFER(a) : STATE_COMPUTE_CONSTANT_BUFFER)
1842 #define STATE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == WINED3D_PIPELINE_GRAPHICS ? \
1843 STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING : STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1845 enum fogsource {
1846 FOGSOURCE_FFP,
1847 FOGSOURCE_VS,
1848 FOGSOURCE_COORD,
1851 /* Direct3D terminology with little modifications. We do not have an issued
1852 * state because only the driver knows about it, but we have a created state
1853 * because D3D allows GetData() on a created query, but OpenGL doesn't. */
1854 enum wined3d_query_state
1856 QUERY_CREATED,
1857 QUERY_SIGNALLED,
1858 QUERY_BUILDING
1861 struct wined3d_query_ops
1863 BOOL (*query_poll)(struct wined3d_query *query, uint32_t flags);
1864 BOOL (*query_issue)(struct wined3d_query *query, uint32_t flags);
1865 void (*query_destroy)(struct wined3d_query *query);
1868 struct wined3d_query
1870 LONG ref;
1872 void *parent;
1873 const struct wined3d_parent_ops *parent_ops;
1874 struct wined3d_device *device;
1875 enum wined3d_query_state state;
1876 enum wined3d_query_type type;
1877 const void *data;
1878 DWORD data_size;
1879 const struct wined3d_query_ops *query_ops;
1881 LONG counter_main, counter_retrieved;
1882 struct list poll_list_entry;
1884 /* FIXME: This is GL-specific. */
1885 unsigned int buffer_object;
1886 UINT64 *map_ptr;
1887 bool poll_in_cs;
1890 #define WINED3D_QUERY_POOL_SIZE 256
1892 struct wined3d_range
1894 unsigned int offset;
1895 unsigned int size;
1898 struct wined3d_fb_state
1900 struct wined3d_rendertarget_view *render_targets[WINED3D_MAX_RENDER_TARGETS];
1901 struct wined3d_rendertarget_view *depth_stencil;
1904 struct wined3d_context
1906 const struct wined3d_d3d_info *d3d_info;
1907 const struct wined3d_state_entry *state_table;
1908 uint32_t dirty_graphics_states[WINED3D_BITMAP_SIZE(STATE_HIGHEST)];
1909 uint32_t dirty_compute_states[WINED3D_BITMAP_SIZE(STATE_COMPUTE_COUNT)];
1911 struct wined3d_device *device;
1912 struct wined3d_swapchain *swapchain;
1913 struct
1915 struct wined3d_texture *texture;
1916 unsigned int sub_resource_idx;
1917 } current_rt;
1919 /* Stores some information about the context state for optimization */
1920 DWORD last_swizzle_map; /* MAX_ATTRIBS, 32 */
1922 DWORD shader_update_mask : 6; /* WINED3D_SHADER_TYPE_COUNT, 6 */
1923 DWORD update_shader_resource_bindings : 1;
1924 DWORD update_compute_shader_resource_bindings : 1;
1925 DWORD update_unordered_access_view_bindings : 1;
1926 DWORD update_compute_unordered_access_view_bindings : 1;
1927 DWORD last_was_rhw : 1; /* True iff last draw_primitive was in xyzrhw mode. */
1928 DWORD last_was_pshader : 1;
1929 DWORD last_was_vshader : 1;
1930 DWORD last_was_diffuse : 1;
1931 DWORD last_was_specular : 1;
1932 DWORD last_was_normal : 1;
1933 DWORD last_was_ffp_blit : 1;
1934 DWORD last_was_blit : 1;
1935 DWORD last_was_ckey : 1;
1936 DWORD last_was_dual_source_blend : 1;
1937 DWORD texShaderBumpMap : 8; /* WINED3D_MAX_TEXTURES, 8 */
1938 DWORD lowest_disabled_stage : 4; /* Max WINED3D_MAX_TEXTURES, 8 */
1940 DWORD lastWasPow2Texture : 8; /* WINED3D_MAX_TEXTURES, 8 */
1941 DWORD fixed_function_usage_map : 8; /* WINED3D_MAX_TEXTURES, 8 */
1942 DWORD use_immediate_mode_draw : 1;
1943 DWORD uses_uavs : 1;
1944 DWORD uses_fbo_attached_resources : 1;
1945 DWORD transform_feedback_active : 1;
1946 DWORD transform_feedback_paused : 1;
1947 DWORD fog_coord : 1;
1948 DWORD render_offscreen : 1;
1949 DWORD current : 1;
1950 DWORD destroyed : 1;
1951 DWORD destroy_delayed : 1;
1952 DWORD namedArraysLoaded : 1;
1953 DWORD padding : 5;
1955 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1957 DWORD constant_update_mask;
1958 DWORD numbered_array_mask;
1959 enum fogsource fog_source;
1962 void *shader_backend_data;
1963 void *fragment_pipe_data;
1965 struct wined3d_stream_info stream_info;
1967 unsigned int viewport_count;
1968 unsigned int scissor_rect_count;
1971 void wined3d_context_cleanup(struct wined3d_context *context) DECLSPEC_HIDDEN;
1972 void wined3d_context_init(struct wined3d_context *context, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
1973 void context_preload_textures(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
1974 void context_update_stream_info(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
1976 HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d,
1977 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
1979 typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
1981 struct wined3d_state_entry
1983 unsigned int representative;
1984 APPLYSTATEFUNC apply;
1987 struct wined3d_state_entry_template
1989 unsigned int state;
1990 struct wined3d_state_entry content;
1991 unsigned int extension;
1994 #define WINED3D_FRAGMENT_CAP_PROJ_CONTROL 0x00000001
1995 #define WINED3D_FRAGMENT_CAP_SRGB_WRITE 0x00000002
1996 #define WINED3D_FRAGMENT_CAP_COLOR_KEY 0x00000004
1998 struct fragment_caps
2000 DWORD wined3d_caps;
2001 DWORD PrimitiveMiscCaps;
2002 DWORD TextureOpCaps;
2003 DWORD MaxTextureBlendStages;
2004 DWORD MaxSimultaneousTextures;
2007 #define GL_EXT_EMUL_ARB_MULTITEXTURE 0x00000001
2008 #define GL_EXT_EMUL_EXT_FOG_COORD 0x00000002
2010 struct wined3d_fragment_pipe_ops
2012 void (*fp_enable)(const struct wined3d_context *context, BOOL enable);
2013 void (*get_caps)(const struct wined3d_adapter *adapter, struct fragment_caps *caps);
2014 unsigned int (*get_emul_mask)(const struct wined3d_adapter *adapter);
2015 void *(*alloc_private)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2016 void (*free_private)(struct wined3d_device *device, struct wined3d_context *context);
2017 BOOL (*allocate_context_data)(struct wined3d_context *context);
2018 void (*free_context_data)(struct wined3d_context *context);
2019 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
2020 const struct wined3d_state_entry_template *states;
2023 struct wined3d_vertex_caps
2025 BOOL xyzrhw;
2026 BOOL emulated_flatshading;
2027 BOOL ffp_generic_attributes;
2028 DWORD max_active_lights;
2029 DWORD max_vertex_blend_matrices;
2030 DWORD max_vertex_blend_matrix_index;
2031 DWORD vertex_processing_caps;
2032 DWORD fvf_caps;
2033 DWORD max_user_clip_planes;
2034 DWORD raster_caps;
2037 struct wined3d_vertex_pipe_ops
2039 void (*vp_enable)(const struct wined3d_context *context, BOOL enable);
2040 void (*vp_get_caps)(const struct wined3d_adapter *adapter, struct wined3d_vertex_caps *caps);
2041 unsigned int (*vp_get_emul_mask)(const struct wined3d_adapter *adapter);
2042 void *(*vp_alloc)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2043 void (*vp_free)(struct wined3d_device *device, struct wined3d_context *context);
2044 const struct wined3d_state_entry_template *vp_states;
2047 extern const struct wined3d_state_entry_template misc_state_template_gl[] DECLSPEC_HIDDEN;
2048 extern const struct wined3d_fragment_pipe_ops none_fragment_pipe DECLSPEC_HIDDEN;
2049 extern const struct wined3d_fragment_pipe_ops ffp_fragment_pipeline DECLSPEC_HIDDEN;
2050 extern const struct wined3d_fragment_pipe_ops atifs_fragment_pipeline DECLSPEC_HIDDEN;
2051 extern const struct wined3d_fragment_pipe_ops arbfp_fragment_pipeline DECLSPEC_HIDDEN;
2052 extern const struct wined3d_fragment_pipe_ops nvts_fragment_pipeline DECLSPEC_HIDDEN;
2053 extern const struct wined3d_fragment_pipe_ops nvrc_fragment_pipeline DECLSPEC_HIDDEN;
2054 extern const struct wined3d_fragment_pipe_ops glsl_fragment_pipe DECLSPEC_HIDDEN;
2056 const struct wined3d_fragment_pipe_ops *wined3d_spirv_fragment_pipe_init_vk(void) DECLSPEC_HIDDEN;
2058 extern const struct wined3d_vertex_pipe_ops none_vertex_pipe DECLSPEC_HIDDEN;
2059 extern const struct wined3d_vertex_pipe_ops ffp_vertex_pipe DECLSPEC_HIDDEN;
2060 extern const struct wined3d_vertex_pipe_ops glsl_vertex_pipe DECLSPEC_HIDDEN;
2062 const struct wined3d_vertex_pipe_ops *wined3d_spirv_vertex_pipe_init_vk(void) DECLSPEC_HIDDEN;
2064 /* "Base" state table */
2065 HRESULT compile_state_table(struct wined3d_state_entry *state_table, APPLYSTATEFUNC **dev_multistate_funcs,
2066 const struct wined3d_d3d_info *d3d_info, const BOOL *supported_extensions,
2067 const struct wined3d_vertex_pipe_ops *vertex, const struct wined3d_fragment_pipe_ops *fragment,
2068 const struct wined3d_state_entry_template *misc) DECLSPEC_HIDDEN;
2070 enum wined3d_blit_op
2072 WINED3D_BLIT_OP_COLOR_BLIT,
2073 WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST,
2074 WINED3D_BLIT_OP_COLOR_BLIT_CKEY,
2075 WINED3D_BLIT_OP_DEPTH_BLIT,
2076 WINED3D_BLIT_OP_RAW_BLIT,
2079 struct wined3d_blitter
2081 const struct wined3d_blitter_ops *ops;
2082 struct wined3d_blitter *next;
2085 struct wined3d_blitter_ops
2087 void (*blitter_destroy)(struct wined3d_blitter *blitter, struct wined3d_context *context);
2088 void (*blitter_clear)(struct wined3d_blitter *blitter, struct wined3d_device *device,
2089 unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects,
2090 const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil);
2091 DWORD (*blitter_blit)(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context,
2092 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location,
2093 const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
2094 DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key,
2095 enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format);
2098 #include "wined3d_gl.h"
2100 struct wined3d_blitter *wined3d_cpu_blitter_create(void) DECLSPEC_HIDDEN;
2101 void wined3d_vk_blitter_create(struct wined3d_blitter **next) DECLSPEC_HIDDEN;
2103 BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other) DECLSPEC_HIDDEN;
2105 void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id) DECLSPEC_HIDDEN;
2106 void context_invalidate_state(struct wined3d_context *context, unsigned int state_id) DECLSPEC_HIDDEN;
2107 void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
2108 void context_restore(struct wined3d_context *context, struct wined3d_texture *texture,
2109 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
2110 void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
2111 void context_state_drawbuf(struct wined3d_context *context,
2112 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2113 void context_state_fb(struct wined3d_context *context,
2114 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2116 /*****************************************************************************
2117 * Internal representation of a light
2119 struct wined3d_light_info
2121 struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
2122 unsigned int OriginalIndex;
2123 LONG glIndex;
2124 BOOL enabled;
2126 /* Converted parms to speed up swapping lights */
2127 struct wined3d_vec4 position;
2128 struct wined3d_vec4 direction;
2129 float exponent;
2130 float cutoff;
2132 struct rb_entry entry;
2133 struct list changed_entry;
2134 bool changed;
2137 /* The default light parameters */
2138 extern const struct wined3d_light WINED3D_default_light DECLSPEC_HIDDEN;
2140 struct wined3d_pixel_format
2142 int iPixelFormat; /* WGL pixel format */
2143 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
2144 int redSize, greenSize, blueSize, alphaSize, colorSize;
2145 int depthSize, stencilSize;
2146 BOOL windowDrawable;
2147 BOOL doubleBuffer;
2148 int auxBuffers;
2149 int numSamples;
2150 int swap_method;
2153 enum wined3d_pci_vendor
2155 HW_VENDOR_SOFTWARE = 0x0000,
2156 HW_VENDOR_AMD = 0x1002,
2157 HW_VENDOR_NVIDIA = 0x10de,
2158 HW_VENDOR_VMWARE = 0x15ad,
2159 HW_VENDOR_REDHAT = 0x1af4,
2160 HW_VENDOR_INTEL = 0x8086,
2163 enum wined3d_pci_device
2165 CARD_WINE = 0x0000,
2167 CARD_AMD_RAGE_128PRO = 0x5246,
2168 CARD_AMD_RADEON_7200 = 0x5144,
2169 CARD_AMD_RADEON_8500 = 0x514c,
2170 CARD_AMD_RADEON_9500 = 0x4144,
2171 CARD_AMD_RADEON_XPRESS_200M = 0x5955,
2172 CARD_AMD_RADEON_X700 = 0x5e4c,
2173 CARD_AMD_RADEON_X1600 = 0x71c2,
2174 CARD_AMD_RADEON_HD2350 = 0x94c7,
2175 CARD_AMD_RADEON_HD2600 = 0x9581,
2176 CARD_AMD_RADEON_HD2900 = 0x9400,
2177 CARD_AMD_RADEON_HD3200 = 0x9620,
2178 CARD_AMD_RADEON_HD3850 = 0x9515,
2179 CARD_AMD_RADEON_HD4200M = 0x9712,
2180 CARD_AMD_RADEON_HD4350 = 0x954f,
2181 CARD_AMD_RADEON_HD4600 = 0x9495,
2182 CARD_AMD_RADEON_HD4700 = 0x944e,
2183 CARD_AMD_RADEON_HD4800 = 0x944c,
2184 CARD_AMD_RADEON_HD5400 = 0x68f9,
2185 CARD_AMD_RADEON_HD5600 = 0x68d8,
2186 CARD_AMD_RADEON_HD5700 = 0x68be,
2187 CARD_AMD_RADEON_HD5800 = 0x6898,
2188 CARD_AMD_RADEON_HD5900 = 0x689c,
2189 CARD_AMD_RADEON_HD6300 = 0x9803,
2190 CARD_AMD_RADEON_HD6400 = 0x6770,
2191 CARD_AMD_RADEON_HD6490M = 0x6760,
2192 CARD_AMD_RADEON_HD6410D = 0x9644,
2193 CARD_AMD_RADEON_HD6480G = 0x9648,
2194 CARD_AMD_RADEON_HD6550D = 0x9640,
2195 CARD_AMD_RADEON_HD6600 = 0x6758,
2196 CARD_AMD_RADEON_HD6600M = 0x6741,
2197 CARD_AMD_RADEON_HD6700 = 0x68ba,
2198 CARD_AMD_RADEON_HD6800 = 0x6739,
2199 CARD_AMD_RADEON_HD6900 = 0x6719,
2200 CARD_AMD_RADEON_HD7660D = 0x9901,
2201 CARD_AMD_RADEON_HD7700 = 0x683d,
2202 CARD_AMD_RADEON_HD7800 = 0x6819,
2203 CARD_AMD_RADEON_HD7870 = 0x6818,
2204 CARD_AMD_RADEON_HD7900 = 0x679a,
2205 CARD_AMD_RADEON_HD8600M = 0x6660,
2206 CARD_AMD_RADEON_HD8670 = 0x6610,
2207 CARD_AMD_RADEON_HD8770 = 0x665c,
2208 CARD_AMD_RADEON_R3 = 0x9830,
2209 CARD_AMD_RADEON_R7 = 0x130f,
2210 CARD_AMD_RADEON_R9_285 = 0x6939,
2211 CARD_AMD_RADEON_R9_290 = 0x67b1,
2212 CARD_AMD_RADEON_R9_290X = 0x67b0,
2213 CARD_AMD_RADEON_R9_FURY = 0x7300,
2214 CARD_AMD_RADEON_R9_M370X = 0x6821,
2215 CARD_AMD_RADEON_R9_M380 = 0x6647,
2216 CARD_AMD_RADEON_R9_M395X = 0x6920,
2217 CARD_AMD_RADEON_RX_460 = 0x67ef,
2218 CARD_AMD_RADEON_RX_480 = 0x67df,
2219 CARD_AMD_RADEON_RX_VEGA_10 = 0x687f,
2220 CARD_AMD_RADEON_RX_VEGA_12 = 0x69af,
2221 CARD_AMD_RADEON_RAVEN = 0x15dd,
2222 CARD_AMD_RADEON_RX_VEGA_20 = 0x66af,
2223 CARD_AMD_RADEON_RX_NAVI_10 = 0x731f,
2224 CARD_AMD_RADEON_RX_NAVI_14 = 0x7340,
2225 CARD_AMD_RADEON_RX_NAVI_21 = 0x73bf,
2226 CARD_AMD_RADEON_PRO_V620 = 0x73a1,
2227 CARD_AMD_RADEON_PRO_V620_VF = 0x73ae,
2228 CARD_AMD_VANGOGH = 0x163f,
2229 CARD_AMD_RAPHAEL = 0x164e,
2231 CARD_NVIDIA_RIVA_128 = 0x0018,
2232 CARD_NVIDIA_RIVA_TNT = 0x0020,
2233 CARD_NVIDIA_RIVA_TNT2 = 0x0028,
2234 CARD_NVIDIA_GEFORCE = 0x0100,
2235 CARD_NVIDIA_GEFORCE2_MX = 0x0110,
2236 CARD_NVIDIA_GEFORCE2 = 0x0150,
2237 CARD_NVIDIA_GEFORCE3 = 0x0200,
2238 CARD_NVIDIA_GEFORCE4_MX = 0x0170,
2239 CARD_NVIDIA_GEFORCE4_TI4200 = 0x0253,
2240 CARD_NVIDIA_GEFORCEFX_5200 = 0x0320,
2241 CARD_NVIDIA_GEFORCEFX_5600 = 0x0312,
2242 CARD_NVIDIA_GEFORCEFX_5800 = 0x0302,
2243 CARD_NVIDIA_GEFORCE_6200 = 0x014f,
2244 CARD_NVIDIA_GEFORCE_6600GT = 0x0140,
2245 CARD_NVIDIA_GEFORCE_6800 = 0x0041,
2246 CARD_NVIDIA_GEFORCE_7300 = 0x01d7, /* GeForce Go 7300 */
2247 CARD_NVIDIA_GEFORCE_7400 = 0x01d8,
2248 CARD_NVIDIA_GEFORCE_7600 = 0x0391,
2249 CARD_NVIDIA_GEFORCE_7800GT = 0x0092,
2250 CARD_NVIDIA_GEFORCE_8200 = 0x0849, /* Other PCI ID 0x084b */
2251 CARD_NVIDIA_GEFORCE_8300GS = 0x0423,
2252 CARD_NVIDIA_GEFORCE_8400GS = 0x0404,
2253 CARD_NVIDIA_GEFORCE_8500GT = 0x0421,
2254 CARD_NVIDIA_GEFORCE_8600GT = 0x0402,
2255 CARD_NVIDIA_GEFORCE_8600MGT = 0x0407,
2256 CARD_NVIDIA_GEFORCE_8800GTS = 0x0193,
2257 CARD_NVIDIA_GEFORCE_8800GTX = 0x0191,
2258 CARD_NVIDIA_GEFORCE_9200 = 0x086d,
2259 CARD_NVIDIA_GEFORCE_9300 = 0x086c,
2260 CARD_NVIDIA_GEFORCE_9400M = 0x0863,
2261 CARD_NVIDIA_GEFORCE_9400GT = 0x042c,
2262 CARD_NVIDIA_GEFORCE_9500GT = 0x0640,
2263 CARD_NVIDIA_GEFORCE_9600GT = 0x0622,
2264 CARD_NVIDIA_GEFORCE_9700MGT = 0x064a,
2265 CARD_NVIDIA_GEFORCE_9800GT = 0x0614,
2266 CARD_NVIDIA_GEFORCE_210 = 0x0a23,
2267 CARD_NVIDIA_GEFORCE_GT220 = 0x0a20,
2268 CARD_NVIDIA_GEFORCE_GT240 = 0x0ca3,
2269 CARD_NVIDIA_GEFORCE_GTS250 = 0x0615,
2270 CARD_NVIDIA_GEFORCE_GTX260 = 0x05e2,
2271 CARD_NVIDIA_GEFORCE_GTX275 = 0x05e6,
2272 CARD_NVIDIA_GEFORCE_GTX280 = 0x05e1,
2273 CARD_NVIDIA_GEFORCE_315M = 0x0a7a,
2274 CARD_NVIDIA_GEFORCE_320M = 0x08a3,
2275 CARD_NVIDIA_GEFORCE_GT320M = 0x0a2d,
2276 CARD_NVIDIA_GEFORCE_GT325M = 0x0a35,
2277 CARD_NVIDIA_GEFORCE_GT330 = 0x0ca0,
2278 CARD_NVIDIA_GEFORCE_GTS350M = 0x0cb0,
2279 CARD_NVIDIA_GEFORCE_410M = 0x1055,
2280 CARD_NVIDIA_GEFORCE_GT420 = 0x0de2,
2281 CARD_NVIDIA_GEFORCE_GT425M = 0x0df0,
2282 CARD_NVIDIA_GEFORCE_GT430 = 0x0de1,
2283 CARD_NVIDIA_GEFORCE_GT440 = 0x0de0,
2284 CARD_NVIDIA_GEFORCE_GTS450 = 0x0dc4,
2285 CARD_NVIDIA_GEFORCE_GTX460 = 0x0e22,
2286 CARD_NVIDIA_GEFORCE_GTX460M = 0x0dd1,
2287 CARD_NVIDIA_GEFORCE_GTX465 = 0x06c4,
2288 CARD_NVIDIA_GEFORCE_GTX470 = 0x06cd,
2289 CARD_NVIDIA_GEFORCE_GTX480 = 0x06c0,
2290 CARD_NVIDIA_GEFORCE_GT520 = 0x1040,
2291 CARD_NVIDIA_GEFORCE_GT525M = 0x0dec,
2292 CARD_NVIDIA_GEFORCE_GT540M = 0x0df4,
2293 CARD_NVIDIA_GEFORCE_GTX550 = 0x1244,
2294 CARD_NVIDIA_GEFORCE_GT555M = 0x04b8,
2295 CARD_NVIDIA_GEFORCE_GTX560TI = 0x1200,
2296 CARD_NVIDIA_GEFORCE_GTX560M = 0x1251,
2297 CARD_NVIDIA_GEFORCE_GTX560 = 0x1201,
2298 CARD_NVIDIA_GEFORCE_GTX570 = 0x1081,
2299 CARD_NVIDIA_GEFORCE_GTX580 = 0x1080,
2300 CARD_NVIDIA_GEFORCE_GT610 = 0x104a,
2301 CARD_NVIDIA_GEFORCE_GT630 = 0x0f00,
2302 CARD_NVIDIA_GEFORCE_GT630M = 0x0de9,
2303 CARD_NVIDIA_GEFORCE_GT640 = 0x0fc1,
2304 CARD_NVIDIA_GEFORCE_GT640M = 0x0fd2,
2305 CARD_NVIDIA_GEFORCE_GT650M = 0x0fd1,
2306 CARD_NVIDIA_GEFORCE_GTX650 = 0x0fc6,
2307 CARD_NVIDIA_GEFORCE_GTX650TI = 0x11c6,
2308 CARD_NVIDIA_GEFORCE_GTX660 = 0x11c0,
2309 CARD_NVIDIA_GEFORCE_GTX660M = 0x0fd4,
2310 CARD_NVIDIA_GEFORCE_GTX660TI = 0x1183,
2311 CARD_NVIDIA_GEFORCE_GTX670 = 0x1189,
2312 CARD_NVIDIA_GEFORCE_GTX670MX = 0x11a1,
2313 CARD_NVIDIA_GEFORCE_GTX675MX_1 = 0x11a7,
2314 CARD_NVIDIA_GEFORCE_GTX675MX_2 = 0x11a2,
2315 CARD_NVIDIA_GEFORCE_GTX680 = 0x1180,
2316 CARD_NVIDIA_GEFORCE_GTX690 = 0x1188,
2317 CARD_NVIDIA_GEFORCE_GT720 = 0x128b,
2318 CARD_NVIDIA_GEFORCE_GT730 = 0x1287,
2319 CARD_NVIDIA_GEFORCE_GT730M = 0x0fe1,
2320 CARD_NVIDIA_GEFORCE_GT740M = 0x1292,
2321 CARD_NVIDIA_GEFORCE_GT750M = 0x0fe9,
2322 CARD_NVIDIA_GEFORCE_GT755M = 0x0fcd,
2323 CARD_NVIDIA_GEFORCE_GTX750 = 0x1381,
2324 CARD_NVIDIA_GEFORCE_GTX750TI = 0x1380,
2325 CARD_NVIDIA_GEFORCE_GTX760 = 0x1187,
2326 CARD_NVIDIA_GEFORCE_GTX760TI = 0x1193,
2327 CARD_NVIDIA_GEFORCE_GTX765M = 0x11e2,
2328 CARD_NVIDIA_GEFORCE_GTX770M = 0x11e0,
2329 CARD_NVIDIA_GEFORCE_GTX770 = 0x1184,
2330 CARD_NVIDIA_GEFORCE_GTX775M = 0x119d,
2331 CARD_NVIDIA_GEFORCE_GTX780 = 0x1004,
2332 CARD_NVIDIA_GEFORCE_GTX780M = 0x119e,
2333 CARD_NVIDIA_GEFORCE_GTX780TI = 0x100a,
2334 CARD_NVIDIA_GEFORCE_GTXTITAN = 0x1005,
2335 CARD_NVIDIA_GEFORCE_GTXTITANB = 0x100c,
2336 CARD_NVIDIA_GEFORCE_GTXTITANX = 0x17c2,
2337 CARD_NVIDIA_GEFORCE_GTXTITANZ = 0x1001,
2338 CARD_NVIDIA_GEFORCE_820M = 0x0fed,
2339 CARD_NVIDIA_GEFORCE_830M = 0x1340,
2340 CARD_NVIDIA_GEFORCE_840M = 0x1341,
2341 CARD_NVIDIA_GEFORCE_845M = 0x1344,
2342 CARD_NVIDIA_GEFORCE_GTX850M = 0x1391,
2343 CARD_NVIDIA_GEFORCE_GTX860M = 0x1392, /* Other PCI ID 0x119a */
2344 CARD_NVIDIA_GEFORCE_GTX870M = 0x1199,
2345 CARD_NVIDIA_GEFORCE_GTX880M = 0x1198,
2346 CARD_NVIDIA_GEFORCE_940M = 0x1347,
2347 CARD_NVIDIA_GEFORCE_GTX950 = 0x1402,
2348 CARD_NVIDIA_GEFORCE_GTX950M = 0x139a,
2349 CARD_NVIDIA_GEFORCE_GTX960 = 0x1401,
2350 CARD_NVIDIA_GEFORCE_GTX960M = 0x139b,
2351 CARD_NVIDIA_GEFORCE_GTX970 = 0x13c2,
2352 CARD_NVIDIA_GEFORCE_GTX970M = 0x13d8,
2353 CARD_NVIDIA_GEFORCE_GTX980 = 0x13c0,
2354 CARD_NVIDIA_GEFORCE_GTX980TI = 0x17c8,
2355 CARD_NVIDIA_GEFORCE_GT1030 = 0x1d01,
2356 CARD_NVIDIA_GEFORCE_GTX1050 = 0x1c81,
2357 CARD_NVIDIA_GEFORCE_GTX1050TI = 0x1c82,
2358 CARD_NVIDIA_GEFORCE_GTX1060_3GB = 0x1c02,
2359 CARD_NVIDIA_GEFORCE_GTX1060 = 0x1c03,
2360 CARD_NVIDIA_GEFORCE_GTX1060M = 0x1c20,
2361 CARD_NVIDIA_GEFORCE_GTX1070 = 0x1b81,
2362 CARD_NVIDIA_GEFORCE_GTX1080 = 0x1b80,
2363 CARD_NVIDIA_GEFORCE_GTX1080M = 0x1be0,
2364 CARD_NVIDIA_GEFORCE_GTX1080TI = 0x1b06,
2365 CARD_NVIDIA_TITANX_PASCAL = 0x1b00,
2366 CARD_NVIDIA_TITANV = 0x1d81,
2367 CARD_NVIDIA_GEFORCE_GTX1650SUPER= 0x2187,
2368 CARD_NVIDIA_GEFORCE_GTX1660SUPER= 0x21c4,
2369 CARD_NVIDIA_GEFORCE_GTX1660TI = 0x2182,
2370 CARD_NVIDIA_GEFORCE_RTX2060 = 0x1f08,
2371 CARD_NVIDIA_GEFORCE_RTX2070 = 0x1f07,
2372 CARD_NVIDIA_GEFORCE_RTX2080 = 0x1e87,
2373 CARD_NVIDIA_GEFORCE_RTX2080TI = 0x1e07,
2374 CARD_NVIDIA_TESLA_T4 = 0x1eb8,
2375 CARD_NVIDIA_AMPERE_A10 = 0x2236,
2377 CARD_REDHAT_VIRGL = 0x1010,
2379 CARD_VMWARE_SVGA3D = 0x0405,
2381 CARD_INTEL_830M = 0x3577,
2382 CARD_INTEL_855GM = 0x3582,
2383 CARD_INTEL_845G = 0x2562,
2384 CARD_INTEL_865G = 0x2572,
2385 CARD_INTEL_915G = 0x2582,
2386 CARD_INTEL_E7221G = 0x258a,
2387 CARD_INTEL_915GM = 0x2592,
2388 CARD_INTEL_945G = 0x2772,
2389 CARD_INTEL_945GM = 0x27a2,
2390 CARD_INTEL_945GME = 0x27ae,
2391 CARD_INTEL_Q35 = 0x29b2,
2392 CARD_INTEL_G33 = 0x29c2,
2393 CARD_INTEL_Q33 = 0x29d2,
2394 CARD_INTEL_PNVG = 0xa001,
2395 CARD_INTEL_PNVM = 0xa011,
2396 CARD_INTEL_965Q = 0x2992,
2397 CARD_INTEL_965G = 0x2982,
2398 CARD_INTEL_946GZ = 0x2972,
2399 CARD_INTEL_965GM = 0x2a02,
2400 CARD_INTEL_965GME = 0x2a12,
2401 CARD_INTEL_GM45 = 0x2a42,
2402 CARD_INTEL_IGD = 0x2e02,
2403 CARD_INTEL_Q45 = 0x2e12,
2404 CARD_INTEL_G45 = 0x2e22,
2405 CARD_INTEL_G41 = 0x2e32,
2406 CARD_INTEL_B43 = 0x2e92,
2407 CARD_INTEL_ILKD = 0x0042,
2408 CARD_INTEL_ILKM = 0x0046,
2409 CARD_INTEL_SNBD = 0x0122,
2410 CARD_INTEL_SNBM = 0x0126,
2411 CARD_INTEL_SNBS = 0x010a,
2412 CARD_INTEL_IVBD = 0x0162,
2413 CARD_INTEL_IVBM = 0x0166,
2414 CARD_INTEL_IVBS = 0x015a,
2415 CARD_INTEL_HWD = 0x0412,
2416 CARD_INTEL_HWM = 0x0416,
2417 CARD_INTEL_HD5000_1 = 0x0a26,
2418 CARD_INTEL_HD5000_2 = 0x0422,
2419 CARD_INTEL_I5100_1 = 0x0a22,
2420 CARD_INTEL_I5100_2 = 0x0a2a,
2421 CARD_INTEL_I5100_3 = 0x0a2b,
2422 CARD_INTEL_I5100_4 = 0x0a2e,
2423 CARD_INTEL_IP5200_1 = 0x0d22,
2424 CARD_INTEL_IP5200_2 = 0x0d26,
2425 CARD_INTEL_IP5200_3 = 0x0d2a,
2426 CARD_INTEL_IP5200_4 = 0x0d2b,
2427 CARD_INTEL_IP5200_5 = 0x0d2e,
2428 CARD_INTEL_IP5200_6 = 0x0c22,
2429 CARD_INTEL_HD5300 = 0x161e,
2430 CARD_INTEL_HD5500 = 0x1616,
2431 CARD_INTEL_HD5600 = 0x1612,
2432 CARD_INTEL_HD6000 = 0x1626,
2433 CARD_INTEL_I6100 = 0x162b,
2434 CARD_INTEL_IP6200 = 0x1622,
2435 CARD_INTEL_IPP6300 = 0x162a,
2436 CARD_INTEL_HD510_1 = 0x1902,
2437 CARD_INTEL_HD510_2 = 0x1906,
2438 CARD_INTEL_HD510_3 = 0x190b,
2439 CARD_INTEL_HD515 = 0x191e,
2440 CARD_INTEL_HD520_1 = 0x1916,
2441 CARD_INTEL_HD520_2 = 0x1921,
2442 CARD_INTEL_HD530_1 = 0x1912,
2443 CARD_INTEL_HD530_2 = 0x191b,
2444 CARD_INTEL_HDP530 = 0x191d,
2445 CARD_INTEL_I540 = 0x1926,
2446 CARD_INTEL_I550 = 0x1927,
2447 CARD_INTEL_I555 = 0x192b,
2448 CARD_INTEL_IP555 = 0x192d,
2449 CARD_INTEL_IP580_1 = 0x1932,
2450 CARD_INTEL_IP580_2 = 0x193b,
2451 CARD_INTEL_IPP580_1 = 0x193a,
2452 CARD_INTEL_IPP580_2 = 0x193d,
2453 CARD_INTEL_UHD617 = 0x87c0,
2454 CARD_INTEL_UHD620 = 0x3ea0,
2455 CARD_INTEL_HD615 = 0x591e,
2456 CARD_INTEL_HD620 = 0x5916,
2457 CARD_INTEL_HD630_1 = 0x5912,
2458 CARD_INTEL_HD630_2 = 0x591b,
2459 CARD_INTEL_UHD630_1 = 0x3e9b,
2460 CARD_INTEL_UHD630_2 = 0x3e91,
2463 /* The driver names reflect the lowest GPU supported
2464 * by a certain driver, so DRIVER_AMD_R300 supports
2465 * R3xx, R4xx and R5xx GPUs. */
2466 enum wined3d_display_driver
2468 DRIVER_AMD_RAGE_128PRO,
2469 DRIVER_AMD_R100,
2470 DRIVER_AMD_R300,
2471 DRIVER_AMD_R600,
2472 DRIVER_AMD_RX,
2473 DRIVER_INTEL_GMA800,
2474 DRIVER_INTEL_GMA900,
2475 DRIVER_INTEL_GMA950,
2476 DRIVER_INTEL_GMA3000,
2477 DRIVER_INTEL_HD4000,
2478 DRIVER_NVIDIA_TNT,
2479 DRIVER_NVIDIA_GEFORCE2MX,
2480 DRIVER_NVIDIA_GEFORCEFX,
2481 DRIVER_NVIDIA_GEFORCE6,
2482 DRIVER_NVIDIA_GEFORCE8,
2483 DRIVER_NVIDIA_FERMI,
2484 DRIVER_NVIDIA_KEPLER,
2485 DRIVER_REDHAT_VIRGL,
2486 DRIVER_VMWARE,
2487 DRIVER_WINE,
2488 DRIVER_UNKNOWN,
2491 struct wined3d_gpu_description
2493 enum wined3d_pci_vendor vendor;
2494 enum wined3d_pci_device device;
2495 const char *description;
2496 enum wined3d_display_driver driver;
2497 unsigned int vidmem;
2500 const struct wined3d_gpu_description *wined3d_get_gpu_description(enum wined3d_pci_vendor vendor,
2501 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
2502 const struct wined3d_gpu_description *wined3d_get_user_override_gpu_description(enum wined3d_pci_vendor vendor,
2503 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
2504 enum wined3d_pci_device wined3d_gpu_from_feature_level(enum wined3d_pci_vendor *vendor,
2505 enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
2507 /* 512 in Direct3D 8/9, 128 in DXGI. */
2508 #define WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH 512
2510 struct wined3d_driver_info
2512 enum wined3d_pci_vendor vendor;
2513 enum wined3d_pci_device device;
2514 const char *name;
2515 char description[WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH];
2516 UINT64 vram_bytes;
2517 UINT64 sysmem_bytes;
2518 unsigned int version_high;
2519 unsigned int version_low;
2522 bool wined3d_driver_info_init(struct wined3d_driver_info *driver_info,
2523 const struct wined3d_gpu_description *gpu_description, enum wined3d_feature_level feature_level,
2524 UINT64 vram_bytes, UINT64 sysmem_bytes) DECLSPEC_HIDDEN;
2526 #define UPLOAD_BO_UPLOAD_ON_UNMAP 0x1
2527 #define UPLOAD_BO_RENAME_ON_UNMAP 0x2
2528 #define UPLOAD_BO_FREE_ON_UNMAP 0x4
2530 struct upload_bo
2532 struct wined3d_const_bo_address addr;
2533 uint32_t flags;
2536 struct wined3d_adapter_ops
2538 void (*adapter_destroy)(struct wined3d_adapter *adapter);
2539 HRESULT (*adapter_create_device)(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
2540 enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
2541 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
2542 struct wined3d_device_parent *device_parent, struct wined3d_device **device);
2543 void (*adapter_destroy_device)(struct wined3d_device *device);
2544 struct wined3d_context *(*adapter_acquire_context)(struct wined3d_device *device,
2545 struct wined3d_texture *texture, unsigned int sub_resource_idx);
2546 void (*adapter_release_context)(struct wined3d_context *context);
2547 void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps);
2548 BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
2549 const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
2550 const struct wined3d_format *ds_format);
2551 HRESULT (*adapter_init_3d)(struct wined3d_device *device);
2552 void (*adapter_uninit_3d)(struct wined3d_device *device);
2553 void *(*adapter_map_bo_address)(struct wined3d_context *context,
2554 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags);
2555 void (*adapter_unmap_bo_address)(struct wined3d_context *context, const struct wined3d_bo_address *data,
2556 unsigned int range_count, const struct wined3d_range *ranges);
2557 void (*adapter_copy_bo_address)(struct wined3d_context *context,
2558 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
2559 unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags);
2560 void (*adapter_flush_bo_address)(struct wined3d_context *context,
2561 const struct wined3d_const_bo_address *data, size_t size);
2562 bool (*adapter_alloc_bo)(struct wined3d_device *device, struct wined3d_resource *resource,
2563 unsigned int sub_resource_idx, struct wined3d_bo_address *addr);
2564 void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo);
2565 HRESULT (*adapter_create_swapchain)(struct wined3d_device *device,
2566 struct wined3d_swapchain_desc *desc,
2567 struct wined3d_swapchain_state_parent *state_parent, void *parent,
2568 const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain);
2569 void (*adapter_destroy_swapchain)(struct wined3d_swapchain *swapchain);
2570 HRESULT (*adapter_create_buffer)(struct wined3d_device *device, const struct wined3d_buffer_desc *desc,
2571 const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops,
2572 struct wined3d_buffer **buffer);
2573 void (*adapter_destroy_buffer)(struct wined3d_buffer *buffer);
2574 HRESULT (*adapter_create_texture)(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
2575 unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent,
2576 const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
2577 void (*adapter_destroy_texture)(struct wined3d_texture *texture);
2578 HRESULT (*adapter_create_rendertarget_view)(const struct wined3d_view_desc *desc,
2579 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2580 struct wined3d_rendertarget_view **view);
2581 void (*adapter_destroy_rendertarget_view)(struct wined3d_rendertarget_view *view);
2582 HRESULT (*adapter_create_shader_resource_view)(const struct wined3d_view_desc *desc,
2583 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2584 struct wined3d_shader_resource_view **view);
2585 void (*adapter_destroy_shader_resource_view)(struct wined3d_shader_resource_view *view);
2586 HRESULT (*adapter_create_unordered_access_view)(const struct wined3d_view_desc *desc,
2587 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
2588 struct wined3d_unordered_access_view **view);
2589 void (*adapter_destroy_unordered_access_view)(struct wined3d_unordered_access_view *view);
2590 HRESULT (*adapter_create_sampler)(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
2591 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler);
2592 void (*adapter_destroy_sampler)(struct wined3d_sampler *sampler);
2593 HRESULT (*adapter_create_query)(struct wined3d_device *device, enum wined3d_query_type type,
2594 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query);
2595 void (*adapter_destroy_query)(struct wined3d_query *query);
2596 void (*adapter_flush_context)(struct wined3d_context *context);
2597 void (*adapter_draw_primitive)(struct wined3d_device *device, const struct wined3d_state *state,
2598 const struct wined3d_draw_parameters *parameters);
2599 void (*adapter_dispatch_compute)(struct wined3d_device *device, const struct wined3d_state *state,
2600 const struct wined3d_dispatch_parameters *parameters);
2601 void (*adapter_clear_uav)(struct wined3d_context *context,
2602 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp);
2603 void (*adapter_generate_mipmap)(struct wined3d_context *context, struct wined3d_shader_resource_view *view);
2606 struct wined3d_output
2608 unsigned int ordinal;
2609 WCHAR device_name[CCHDEVICENAME];
2610 struct wined3d_adapter *adapter;
2611 enum wined3d_format_id screen_format;
2613 D3DKMT_HANDLE kmt_device;
2614 D3DDDI_VIDEO_PRESENT_SOURCE_ID vidpn_source_id;
2616 struct wined3d_display_mode *modes;
2617 SIZE_T mode_count, modes_size;
2618 bool modes_valid;
2621 HRESULT wined3d_output_get_gamma_ramp(struct wined3d_output *output, struct wined3d_gamma_ramp *ramp) DECLSPEC_HIDDEN;
2623 #ifdef _WIN64
2624 #define MAX_PERSISTENT_MAPPED_BYTES I64_MAX
2625 #else
2626 #define MAX_PERSISTENT_MAPPED_BYTES (128 * 1024 * 1024)
2627 #endif
2629 /* The adapter structure */
2630 struct wined3d_adapter
2632 unsigned int ordinal;
2634 struct wined3d_d3d_info d3d_info;
2635 struct wined3d_driver_info driver_info;
2636 struct wined3d_output *outputs;
2637 SIZE_T output_count, outputs_size;
2638 D3DKMT_HANDLE kmt_adapter;
2639 UINT64 vram_bytes_used;
2640 GUID driver_uuid;
2641 GUID device_uuid;
2642 LUID luid;
2644 void *formats;
2645 size_t format_size;
2647 ssize_t mapped_size;
2649 const struct wined3d_vertex_pipe_ops *vertex_pipe;
2650 const struct wined3d_fragment_pipe_ops *fragment_pipe;
2651 const struct wined3d_state_entry_template *misc_state_template;
2652 const struct wined3d_shader_backend_ops *shader_backend;
2653 const struct wined3d_adapter_ops *adapter_ops;
2656 BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
2657 const struct wined3d_adapter_ops *adapter_ops) DECLSPEC_HIDDEN;
2658 void wined3d_adapter_cleanup(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
2659 BOOL wined3d_get_primary_adapter_luid(LUID *luid) DECLSPEC_HIDDEN;
2661 struct wined3d_adapter *wined3d_adapter_vk_create(unsigned int ordinal,
2662 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
2664 struct wined3d_adapter_gl
2666 struct wined3d_adapter a;
2668 struct wined3d_gl_info gl_info;
2670 struct wined3d_pixel_format *pixel_formats;
2671 unsigned int pixel_format_count;
2674 static inline struct wined3d_adapter_gl *wined3d_adapter_gl(struct wined3d_adapter *adapter)
2676 return CONTAINING_RECORD(adapter, struct wined3d_adapter_gl, a);
2679 static inline const struct wined3d_adapter_gl *wined3d_adapter_gl_const(const struct wined3d_adapter *adapter)
2681 return CONTAINING_RECORD(adapter, struct wined3d_adapter_gl, a);
2684 struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal,
2685 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
2687 struct wined3d_caps_gl_ctx
2689 HDC dc;
2690 HWND wnd;
2691 HGLRC gl_ctx;
2692 HDC restore_dc;
2693 HGLRC restore_gl_ctx;
2695 const struct wined3d_gl_info *gl_info;
2696 GLuint test_vbo;
2697 GLuint test_program_id;
2699 const struct wined3d_gpu_description *gpu_description;
2700 UINT64 vram_bytes;
2703 BOOL wined3d_adapter_gl_init_format_info(struct wined3d_adapter *adapter,
2704 struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
2705 BOOL wined3d_adapter_no3d_init_format_info(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
2706 ssize_t adapter_adjust_mapped_memory(struct wined3d_adapter *adapter, ssize_t size) DECLSPEC_HIDDEN;
2707 UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount) DECLSPEC_HIDDEN;
2709 BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
2710 bool wined3d_caps_gl_ctx_test_filling_convention(struct wined3d_caps_gl_ctx *ctx, float offset) DECLSPEC_HIDDEN;
2712 enum wined3d_projection_type
2714 WINED3D_PROJECTION_NONE = 0,
2715 WINED3D_PROJECTION_COUNT3 = 1,
2716 WINED3D_PROJECTION_COUNT4 = 2
2719 /*****************************************************************************
2720 * Fixed function pipeline replacements
2722 #define ARG_UNUSED 0xff
2723 struct texture_stage_op
2725 unsigned cop : 8;
2726 unsigned carg1 : 8;
2727 unsigned carg2 : 8;
2728 unsigned carg0 : 8;
2730 unsigned aop : 8;
2731 unsigned aarg1 : 8;
2732 unsigned aarg2 : 8;
2733 unsigned aarg0 : 8;
2735 struct color_fixup_desc color_fixup;
2736 unsigned tex_type : 3;
2737 unsigned tmp_dst : 1;
2738 unsigned projected : 2;
2739 unsigned padding : 10;
2742 struct ffp_frag_settings
2744 struct texture_stage_op op[WINED3D_MAX_TEXTURES];
2745 enum wined3d_ffp_ps_fog_mode fog;
2746 unsigned char sRGB_write;
2747 unsigned char emul_clipplanes;
2748 unsigned char texcoords_initialized;
2749 unsigned char color_key_enabled : 1;
2750 unsigned char pointsprite : 1;
2751 unsigned char flatshading : 1;
2752 unsigned char alpha_test_func : 3;
2753 unsigned char padding : 2;
2756 struct ffp_frag_desc
2758 struct wine_rb_entry entry;
2759 struct ffp_frag_settings settings;
2762 int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
2763 int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
2765 extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
2767 void wined3d_ffp_get_fs_settings(const struct wined3d_context *context, const struct wined3d_state *state,
2768 struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN;
2769 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
2770 const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
2771 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
2772 void wined3d_ftoa(float value, char *s) DECLSPEC_HIDDEN;
2774 enum wined3d_ffp_vs_fog_mode
2776 WINED3D_FFP_VS_FOG_OFF = 0,
2777 WINED3D_FFP_VS_FOG_FOGCOORD = 1,
2778 WINED3D_FFP_VS_FOG_DEPTH = 2,
2779 WINED3D_FFP_VS_FOG_RANGE = 3,
2782 #define WINED3D_FFP_TCI_SHIFT 16
2783 #define WINED3D_FFP_TCI_MASK 0xffu
2785 #define WINED3D_FFP_LIGHT_TYPE_SHIFT(idx) (3 * (idx))
2786 #define WINED3D_FFP_LIGHT_TYPE_MASK 0x7u
2788 struct wined3d_ffp_vs_settings
2790 DWORD point_light_count : 4;
2791 DWORD spot_light_count : 4;
2792 DWORD directional_light_count : 4;
2793 DWORD parallel_point_light_count : 4;
2794 DWORD diffuse_source : 2;
2795 DWORD emissive_source : 2;
2796 DWORD ambient_source : 2;
2797 DWORD specular_source : 2;
2798 DWORD transformed : 1;
2799 DWORD vertexblends : 2;
2800 DWORD clipping : 1;
2801 DWORD normal : 1;
2802 DWORD normalize : 1;
2803 DWORD lighting : 1;
2804 DWORD localviewer : 1;
2806 DWORD point_size : 1;
2807 DWORD per_vertex_point_size : 1;
2808 DWORD fog_mode : 2;
2809 DWORD texcoords : 8; /* WINED3D_MAX_TEXTURES */
2810 DWORD ortho_fog : 1;
2811 DWORD flatshading : 1;
2812 DWORD padding : 18;
2814 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
2816 unsigned int texgen[WINED3D_MAX_TEXTURES];
2819 struct wined3d_ffp_vs_desc
2821 struct wine_rb_entry entry;
2822 struct wined3d_ffp_vs_settings settings;
2825 void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
2826 const struct wined3d_state *state, struct wined3d_ffp_vs_settings *settings) DECLSPEC_HIDDEN;
2828 struct wined3d
2830 LONG ref;
2831 unsigned int flags;
2832 unsigned int adapter_count;
2833 struct wined3d_adapter *adapters[1];
2836 BOOL wined3d_filter_messages(HWND window, BOOL filter) DECLSPEC_HIDDEN;
2837 HRESULT wined3d_init(struct wined3d *wined3d, uint32_t flags) DECLSPEC_HIDDEN;
2838 void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
2840 BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size) DECLSPEC_HIDDEN;
2842 enum wined3d_push_constants
2844 WINED3D_PUSH_CONSTANTS_VS_F,
2845 WINED3D_PUSH_CONSTANTS_PS_F,
2846 WINED3D_PUSH_CONSTANTS_VS_I,
2847 WINED3D_PUSH_CONSTANTS_PS_I,
2848 WINED3D_PUSH_CONSTANTS_VS_B,
2849 WINED3D_PUSH_CONSTANTS_PS_B,
2850 WINED3D_PUSH_CONSTANTS_COUNT,
2853 struct wined3d_blend_state
2855 LONG refcount;
2856 struct wined3d_blend_state_desc desc;
2857 BOOL dual_source;
2859 void *parent;
2860 const struct wined3d_parent_ops *parent_ops;
2862 struct wined3d_device *device;
2863 struct wine_rb_entry entry;
2866 static inline unsigned int wined3d_blend_state_get_writemask(const struct wined3d_blend_state *state,
2867 unsigned int index)
2869 if (!state)
2870 return 0xf;
2871 if (!state->desc.independent)
2872 index = 0;
2873 return state->desc.rt[index].writemask;
2876 struct wined3d_depth_stencil_state
2878 LONG refcount;
2879 struct wined3d_depth_stencil_state_desc desc;
2881 bool writes_ds;
2883 void *parent;
2884 const struct wined3d_parent_ops *parent_ops;
2886 struct wined3d_device *device;
2887 struct wine_rb_entry entry;
2890 struct wined3d_rasterizer_state
2892 LONG refcount;
2893 struct wined3d_rasterizer_state_desc desc;
2895 void *parent;
2896 const struct wined3d_parent_ops *parent_ops;
2898 struct wined3d_device *device;
2899 struct wine_rb_entry entry;
2902 struct wined3d_light_state
2904 struct rb_tree lights_tree;
2905 const struct wined3d_light_info *lights[WINED3D_MAX_ACTIVE_LIGHTS];
2908 #define WINED3D_STATE_NO_REF 0x00000001
2909 #define WINED3D_STATE_INIT_DEFAULT 0x00000002
2911 struct wined3d_state
2913 enum wined3d_feature_level feature_level;
2914 uint32_t flags;
2915 struct wined3d_fb_state fb;
2917 struct wined3d_vertex_declaration *vertex_declaration;
2918 struct wined3d_stream_output stream_output[WINED3D_MAX_STREAM_OUTPUT_BUFFERS];
2919 struct wined3d_stream_state streams[WINED3D_MAX_STREAMS];
2920 struct wined3d_buffer *index_buffer;
2921 enum wined3d_format_id index_format;
2922 unsigned int index_offset;
2923 int base_vertex_index;
2924 int load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
2925 enum wined3d_primitive_type primitive_type;
2926 unsigned int patch_vertex_count;
2927 struct wined3d_query *predicate;
2928 BOOL predicate_value;
2930 struct wined3d_shader *shader[WINED3D_SHADER_TYPE_COUNT];
2931 struct wined3d_constant_buffer_state cb[WINED3D_SHADER_TYPE_COUNT][MAX_CONSTANT_BUFFERS];
2932 struct wined3d_sampler *sampler[WINED3D_SHADER_TYPE_COUNT][MAX_SAMPLER_OBJECTS];
2933 struct wined3d_shader_resource_view *shader_resource_view[WINED3D_SHADER_TYPE_COUNT][MAX_SHADER_RESOURCE_VIEWS];
2934 struct wined3d_unordered_access_view *unordered_access_view[WINED3D_PIPELINE_COUNT][MAX_UNORDERED_ACCESS_VIEWS];
2936 struct wined3d_texture *textures[WINED3D_MAX_COMBINED_SAMPLERS];
2937 uint32_t sampler_states[WINED3D_MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
2938 uint32_t texture_states[WINED3D_MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
2940 struct wined3d_matrix transforms[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
2941 struct wined3d_vec4 clip_planes[WINED3D_MAX_CLIP_DISTANCES];
2942 struct wined3d_material material;
2943 struct wined3d_viewport viewports[WINED3D_MAX_VIEWPORTS];
2944 unsigned int viewport_count;
2945 RECT scissor_rects[WINED3D_MAX_VIEWPORTS];
2946 unsigned int scissor_rect_count;
2948 struct wined3d_light_state light_state;
2950 unsigned int render_states[WINEHIGHEST_RENDER_STATE + 1];
2951 struct wined3d_blend_state *blend_state;
2952 struct wined3d_color blend_factor;
2953 unsigned int sample_mask;
2954 struct wined3d_depth_stencil_state *depth_stencil_state;
2955 unsigned int stencil_ref;
2956 bool depth_bounds_enable;
2957 float depth_bounds_min, depth_bounds_max;
2958 struct wined3d_rasterizer_state *rasterizer_state;
2961 void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
2962 void state_init(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info,
2963 uint32_t flags, enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
2964 void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN;
2966 static inline void wined3d_state_reset(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info)
2968 enum wined3d_feature_level feature_level = state->feature_level;
2969 uint32_t flags = state->flags;
2971 memset(state, 0, sizeof(*state));
2972 state_init(state, d3d_info, flags, feature_level);
2975 static inline bool wined3d_state_uses_depth_buffer(const struct wined3d_state *state)
2977 if (!state->depth_stencil_state)
2978 return true;
2979 return state->depth_stencil_state->desc.depth || state->depth_stencil_state->desc.depth_write
2980 || state->depth_stencil_state->desc.stencil;
2983 struct wined3d_dummy_textures
2985 GLuint tex_1d;
2986 GLuint tex_2d;
2987 GLuint tex_rect;
2988 GLuint tex_3d;
2989 GLuint tex_cube;
2990 GLuint tex_cube_array;
2991 GLuint tex_1d_array;
2992 GLuint tex_2d_array;
2993 GLuint tex_buffer;
2994 GLuint tex_2d_ms;
2995 GLuint tex_2d_ms_array;
2998 #define WINED3D_UNMAPPED_STAGE ~0u
3000 /* Multithreaded flag. Removed from the public header to signal that
3001 * wined3d_device_create() ignores it. */
3002 #define WINED3DCREATE_MULTITHREADED 0x00000004
3004 struct wined3d_so_desc_entry
3006 struct wine_rb_entry entry;
3007 struct wined3d_stream_output_desc desc;
3008 struct wined3d_stream_output_element elements[1];
3011 struct wined3d_device
3013 LONG ref;
3015 /* WineD3D Information */
3016 struct wined3d_device_parent *device_parent;
3017 struct wined3d *wined3d;
3018 struct wined3d_adapter *adapter;
3020 const struct wined3d_shader_backend_ops *shader_backend;
3021 void *shader_priv;
3022 void *fragment_priv;
3023 void *vertex_priv;
3024 struct wined3d_state_entry state_table[STATE_HIGHEST + 1];
3025 /* Array of functions for states which are handled by more than one pipeline part */
3026 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
3027 struct wined3d_blitter *blitter;
3029 BYTE bCursorVisible : 1;
3030 BYTE d3d_initialized : 1;
3031 BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
3032 BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
3033 BYTE restore_screensaver : 1;
3034 BYTE padding : 3;
3036 unsigned char surface_alignment; /* Line Alignment of surfaces */
3038 WORD padding2 : 16;
3040 /* Internal use fields */
3041 struct wined3d_device_creation_parameters create_parms;
3042 HWND focus_window;
3044 struct wined3d_rendertarget_view *back_buffer_view;
3045 struct wined3d_swapchain **swapchains;
3046 UINT swapchain_count;
3047 unsigned int max_frame_latency;
3049 struct list resources; /* a linked list to track resources created by the device */
3050 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
3051 struct wine_rb_tree so_descs;
3052 struct wine_rb_tree samplers, rasterizer_states, blend_states, depth_stencil_states;
3054 /* Render Target Support */
3055 struct wined3d_rendertarget_view *auto_depth_stencil_view;
3057 /* Cursor management */
3058 UINT xHotSpot;
3059 UINT yHotSpot;
3060 UINT xScreenSpace;
3061 UINT yScreenSpace;
3062 UINT cursorWidth, cursorHeight;
3063 struct wined3d_texture *cursor_texture;
3064 HCURSOR hardwareCursor;
3066 /* The Wine logo texture */
3067 struct wined3d_texture *logo_texture;
3069 /* Default sampler used to emulate the direct resource access without using wined3d_sampler */
3070 struct wined3d_sampler *default_sampler;
3071 struct wined3d_sampler *null_sampler;
3073 /* Command stream */
3074 struct wined3d_cs *cs;
3076 struct wined3d_buffer *push_constants[WINED3D_PUSH_CONSTANTS_COUNT];
3078 /* Context management */
3079 struct wined3d_context **contexts;
3080 UINT context_count;
3082 CRITICAL_SECTION bo_map_lock;
3085 void wined3d_device_cleanup(struct wined3d_device *device) DECLSPEC_HIDDEN;
3086 BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
3087 void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
3088 void wined3d_device_create_default_samplers(struct wined3d_device *device,
3089 struct wined3d_context *context) DECLSPEC_HIDDEN;
3090 void wined3d_device_destroy_default_samplers(struct wined3d_device *device) DECLSPEC_HIDDEN;
3091 HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
3092 unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
3093 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
3094 const BOOL *supported_extensions, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN;
3095 LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
3096 UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
3097 void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3098 void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3099 void device_invalidate_state(const struct wined3d_device *device, unsigned int state) DECLSPEC_HIDDEN;
3100 HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device,
3101 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
3102 void wined3d_device_uninit_3d(struct wined3d_device *device) DECLSPEC_HIDDEN;
3104 static inline void wined3d_device_bo_map_lock(struct wined3d_device *device)
3106 EnterCriticalSection(&device->bo_map_lock);
3109 static inline void wined3d_device_bo_map_unlock(struct wined3d_device *device)
3111 LeaveCriticalSection(&device->bo_map_lock);
3114 struct wined3d_device_no3d
3116 struct wined3d_device d;
3118 struct wined3d_context context_no3d;
3121 static inline struct wined3d_device_no3d *wined3d_device_no3d(struct wined3d_device *device)
3123 return CONTAINING_RECORD(device, struct wined3d_device_no3d, d);
3126 #define WINED3D_ALLOCATOR_CHUNK_SIZE (64 * 1024 * 1024)
3127 #define WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT 15
3128 #define WINED3D_ALLOCATOR_MIN_BLOCK_SIZE (WINED3D_ALLOCATOR_CHUNK_SIZE >> (WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT - 1))
3129 #define WINED3D_SLAB_BO_MIN_OBJECT_ALIGN 16
3130 #define WINED3D_RETIRED_BO_SIZE_THRESHOLD (64 * 1024 * 1024)
3132 struct wined3d_allocator_chunk
3134 struct list entry;
3135 struct list available[WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT];
3136 struct wined3d_allocator *allocator;
3137 unsigned int map_count;
3138 void *map_ptr;
3141 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk *chunk) DECLSPEC_HIDDEN;
3142 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk *chunk,
3143 struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
3145 struct wined3d_allocator_chunk_gl
3147 struct wined3d_allocator_chunk c;
3148 unsigned int memory_type;
3149 GLuint gl_buffer;
3152 static inline struct wined3d_allocator_chunk_gl *wined3d_allocator_chunk_gl(struct wined3d_allocator_chunk *chunk)
3154 return CONTAINING_RECORD(chunk, struct wined3d_allocator_chunk_gl, c);
3157 struct wined3d_allocator_block
3159 struct list entry;
3160 struct wined3d_allocator_chunk *chunk;
3161 struct wined3d_allocator_block *parent, *sibling;
3162 unsigned int order;
3163 size_t offset;
3164 bool free;
3167 void wined3d_allocator_block_free(struct wined3d_allocator_block *block) DECLSPEC_HIDDEN;
3169 struct wined3d_allocator_pool
3171 struct list chunks;
3174 struct wined3d_allocator_ops
3176 struct wined3d_allocator_chunk *(*allocator_create_chunk)(struct wined3d_allocator *allocator,
3177 struct wined3d_context *context, unsigned int memory_type, size_t chunk_size);
3178 void (*allocator_destroy_chunk)(struct wined3d_allocator_chunk *chunk);
3181 struct wined3d_allocator
3183 const struct wined3d_allocator_ops *ops;
3184 struct wined3d_allocator_pool *pools;
3185 size_t pool_count;
3186 struct wined3d_allocator_block *free;
3189 struct wined3d_allocator_block *wined3d_allocator_allocate(struct wined3d_allocator *allocator,
3190 struct wined3d_context *context, unsigned int memory_type, size_t size) DECLSPEC_HIDDEN;
3191 void wined3d_allocator_cleanup(struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
3192 bool wined3d_allocator_init(struct wined3d_allocator *allocator,
3193 size_t pool_count, const struct wined3d_allocator_ops *allocator_ops) DECLSPEC_HIDDEN;
3195 struct wined3d_device_gl
3197 struct wined3d_device d;
3199 /* Textures for when no other textures are bound. */
3200 struct wined3d_dummy_textures dummy_textures;
3202 CRITICAL_SECTION allocator_cs;
3203 struct wined3d_allocator allocator;
3204 uint64_t completed_fence_id;
3205 uint64_t current_fence_id;
3206 uint64_t retired_bo_size;
3208 struct wined3d_retired_block_gl
3210 struct wined3d_allocator_block *block;
3211 uint64_t fence_id;
3212 } *retired_blocks;
3213 SIZE_T retired_blocks_size;
3214 SIZE_T retired_block_count;
3216 HWND backup_wnd;
3217 HDC backup_dc;
3220 static inline struct wined3d_device_gl *wined3d_device_gl(struct wined3d_device *device)
3222 return CONTAINING_RECORD(device, struct wined3d_device_gl, d);
3225 static inline struct wined3d_device_gl *wined3d_device_gl_from_allocator(struct wined3d_allocator *allocator)
3227 return CONTAINING_RECORD(allocator, struct wined3d_device_gl, allocator);
3230 static inline void wined3d_device_gl_allocator_lock(struct wined3d_device_gl *device_gl)
3232 EnterCriticalSection(&device_gl->allocator_cs);
3235 static inline void wined3d_device_gl_allocator_unlock(struct wined3d_device_gl *device_gl)
3237 LeaveCriticalSection(&device_gl->allocator_cs);
3240 static inline void wined3d_allocator_chunk_gl_lock(struct wined3d_allocator_chunk_gl *chunk_gl)
3242 wined3d_device_gl_allocator_lock(wined3d_device_gl_from_allocator(chunk_gl->c.allocator));
3245 static inline void wined3d_allocator_chunk_gl_unlock(struct wined3d_allocator_chunk_gl *chunk_gl)
3247 wined3d_device_gl_allocator_unlock(wined3d_device_gl_from_allocator(chunk_gl->c.allocator));
3250 bool wined3d_device_gl_create_bo(struct wined3d_device_gl *device_gl,
3251 struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding,
3252 GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
3253 void wined3d_device_gl_create_primary_opengl_context_cs(void *object) DECLSPEC_HIDDEN;
3254 void wined3d_device_gl_delete_opengl_contexts_cs(void *object) DECLSPEC_HIDDEN;
3255 HDC wined3d_device_gl_get_backup_dc(struct wined3d_device_gl *device_gl) DECLSPEC_HIDDEN;
3256 GLbitfield wined3d_device_gl_get_memory_type_flags(unsigned int memory_type_idx) DECLSPEC_HIDDEN;
3258 static inline float wined3d_alpha_ref(const struct wined3d_state *state)
3260 return (state->render_states[WINED3D_RS_ALPHAREF] & 0xff) / 255.0f;
3263 const char *wined3d_debug_resource_access(uint32_t access) DECLSPEC_HIDDEN;
3264 const char *wined3d_debug_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
3265 const char *wined3d_debug_view_desc(const struct wined3d_view_desc *d,
3266 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3268 static inline ULONG wined3d_atomic_decrement_mutex_lock(volatile LONG *refcount)
3270 ULONG count, old_count = *refcount;
3273 if ((count = old_count) == 1)
3275 wined3d_mutex_lock();
3276 count = InterlockedDecrement(refcount);
3277 if (count) wined3d_mutex_unlock();
3278 return count;
3281 old_count = InterlockedCompareExchange(refcount, count - 1, count);
3283 while (old_count != count);
3285 return count - 1;
3288 #define CLIENT_BO_DISCARDED ((struct wined3d_bo *)~(UINT_PTR)0)
3290 struct wined3d_client_resource
3292 /* The resource's persistently mapped address, which we may use to perform
3293 * NOOVERWRITE maps from the client thread. */
3294 struct wined3d_bo_address addr;
3296 /* The currently mapped upload BO, if applicable, and box. */
3297 struct upload_bo mapped_upload;
3298 struct wined3d_box mapped_box;
3301 static inline BOOL wined3d_resource_access_is_managed(unsigned int access)
3303 return !(~access & (WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU));
3306 struct wined3d_resource_ops
3308 ULONG (*resource_incref)(struct wined3d_resource *resource);
3309 ULONG (*resource_decref)(struct wined3d_resource *resource);
3310 void (*resource_preload)(struct wined3d_resource *resource);
3311 void (*resource_unload)(struct wined3d_resource *resource);
3312 HRESULT (*resource_sub_resource_get_desc)(struct wined3d_resource *resource,
3313 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc);
3314 void (*resource_sub_resource_get_map_pitch)(struct wined3d_resource *resource,
3315 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch);
3316 HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3317 void **map_ptr, const struct wined3d_box *box, uint32_t flags);
3318 HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
3321 struct wined3d_resource
3323 LONG ref;
3324 LONG bind_count;
3325 LONG map_count;
3326 ULONG access_time;
3327 struct wined3d_device *device;
3328 enum wined3d_resource_type type;
3329 enum wined3d_gl_resource_type gl_type;
3330 const struct wined3d_format *format;
3331 unsigned int format_attrs;
3332 unsigned int format_caps;
3333 enum wined3d_multisample_type multisample_type;
3334 UINT multisample_quality;
3335 uint32_t usage;
3336 unsigned int bind_flags;
3337 unsigned int access;
3338 WORD draw_binding;
3339 WORD map_binding;
3340 UINT width;
3341 UINT height;
3342 UINT depth;
3343 UINT size;
3344 unsigned int priority;
3345 void *heap_memory;
3347 uint32_t pin_sysmem : 1;
3349 struct wined3d_client_resource client;
3351 void *parent;
3352 const struct wined3d_parent_ops *parent_ops;
3353 const struct wined3d_resource_ops *resource_ops;
3355 struct list resource_list_entry;
3357 LONG srv_bind_count_device;
3358 LONG rtv_bind_count_device;
3361 static inline ULONG wined3d_resource_incref(struct wined3d_resource *resource)
3363 return resource->resource_ops->resource_incref(resource);
3366 static inline ULONG wined3d_resource_decref(struct wined3d_resource *resource)
3368 return resource->resource_ops->resource_decref(resource);
3371 static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_resource *resource,
3372 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
3374 return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc);
3377 static inline void wined3d_resource_get_sub_resource_map_pitch(struct wined3d_resource *resource,
3378 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
3380 resource->resource_ops->resource_sub_resource_get_map_pitch(resource, sub_resource_idx, row_pitch, slice_pitch);
3383 void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3384 HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
3385 enum wined3d_resource_type type, const struct wined3d_format *format,
3386 enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, unsigned int usage,
3387 unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
3388 unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
3389 const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
3390 void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3391 uint8_t *base_memory, const struct wined3d_box *box) DECLSPEC_HIDDEN;
3392 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3393 HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource,
3394 unsigned int sub_resource_idx, const struct wined3d_box *box) DECLSPEC_HIDDEN;
3395 void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3396 const struct wined3d_format *wined3d_resource_get_decompress_format(
3397 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3398 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3399 GLbitfield wined3d_resource_gl_map_flags(const struct wined3d_bo_gl *bo, DWORD d3d_flags) DECLSPEC_HIDDEN;
3400 GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
3401 GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3402 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3403 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3404 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3405 void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
3406 const struct wined3d_map_desc *map, const struct wined3d_color *colour,
3407 const struct wined3d_box *box, bool full_subresource) DECLSPEC_HIDDEN;
3409 /* Tests show that the start address of resources is 32 byte aligned */
3410 #define RESOURCE_ALIGNMENT 16
3411 #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16
3413 #define WINED3D_LOCATION_DISCARDED 0x00000001
3414 #define WINED3D_LOCATION_SYSMEM 0x00000002
3415 #define WINED3D_LOCATION_CLEARED 0x00000004
3416 #define WINED3D_LOCATION_BUFFER 0x00000008
3417 #define WINED3D_LOCATION_TEXTURE_RGB 0x00000010
3418 #define WINED3D_LOCATION_TEXTURE_SRGB 0x00000020
3419 #define WINED3D_LOCATION_DRAWABLE 0x00000040
3420 #define WINED3D_LOCATION_RB_MULTISAMPLE 0x00000080
3421 #define WINED3D_LOCATION_RB_RESOLVED 0x00000100
3423 const char *wined3d_debug_location(uint32_t location) DECLSPEC_HIDDEN;
3425 struct wined3d_blt_info
3427 GLenum bind_target;
3428 struct wined3d_vec3 texcoords[4];
3431 struct wined3d_texture_ops
3433 BOOL (*texture_prepare_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3434 struct wined3d_context *context, unsigned int location);
3435 BOOL (*texture_load_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3436 struct wined3d_context *context, unsigned int location);
3437 void (*texture_unload_location)(struct wined3d_texture *texture,
3438 struct wined3d_context *context, unsigned int location);
3439 void (*texture_upload_data)(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr,
3440 const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch,
3441 unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3442 unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z);
3443 void (*texture_download_data)(struct wined3d_context *context, struct wined3d_texture *src_texture,
3444 unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box,
3445 const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format,
3446 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z,
3447 unsigned int dst_row_pitch, unsigned int dst_slice_pitch);
3450 #define WINED3D_TEXTURE_COND_NP2 0x00000001
3451 #define WINED3D_TEXTURE_COND_NP2_EMULATED 0x00000002
3452 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000004
3453 #define WINED3D_TEXTURE_IS_SRGB 0x00000008
3454 #define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000010
3455 #define WINED3D_TEXTURE_RGB_VALID 0x00000020
3456 #define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000040
3457 #define WINED3D_TEXTURE_SRGB_VALID 0x00000080
3458 #define WINED3D_TEXTURE_CONVERTED 0x00000100
3459 #define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
3460 #define WINED3D_TEXTURE_GET_DC_LENIENT 0x00000800
3461 #define WINED3D_TEXTURE_DC_IN_USE 0x00001000
3462 #define WINED3D_TEXTURE_DISCARD 0x00002000
3463 #define WINED3D_TEXTURE_GET_DC 0x00004000
3464 #define WINED3D_TEXTURE_GENERATE_MIPMAPS 0x00008000
3465 #define WINED3D_TEXTURE_DOWNLOADABLE 0x00010000
3467 #define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001
3469 struct wined3d_texture
3471 struct wined3d_resource resource;
3472 const struct wined3d_texture_ops *texture_ops;
3473 struct wined3d_swapchain *swapchain;
3474 unsigned int pow2_width;
3475 unsigned int pow2_height;
3476 UINT layer_count;
3477 unsigned int level_count;
3478 unsigned int download_count;
3479 unsigned int sysmem_count;
3480 float pow2_matrix[16];
3481 unsigned int lod;
3482 DWORD sampler;
3483 uint32_t flags;
3484 DWORD update_map_binding;
3486 unsigned int row_pitch;
3487 unsigned int slice_pitch;
3489 /* May only be accessed from the command stream worker thread. */
3490 struct wined3d_texture_async
3492 uint32_t flags;
3494 /* Color keys for DDraw */
3495 struct wined3d_color_key dst_blt_color_key;
3496 struct wined3d_color_key src_blt_color_key;
3497 struct wined3d_color_key dst_overlay_color_key;
3498 struct wined3d_color_key src_overlay_color_key;
3499 struct wined3d_color_key gl_color_key;
3500 DWORD color_key_flags;
3501 } async;
3503 struct wined3d_dirty_regions
3505 struct wined3d_box *boxes;
3506 SIZE_T boxes_size;
3507 unsigned int box_count;
3508 } *dirty_regions;
3510 struct wined3d_overlay_info
3512 struct list entry;
3513 struct list overlays;
3514 struct wined3d_texture *dst_texture;
3515 unsigned int dst_sub_resource_idx;
3516 RECT src_rect;
3517 RECT dst_rect;
3518 } *overlay_info;
3520 struct wined3d_dc_info
3522 HBITMAP bitmap;
3523 HDC dc;
3524 } *dc_info;
3526 struct wined3d_texture_sub_resource
3528 void *parent;
3529 const struct wined3d_parent_ops *parent_ops;
3531 unsigned int offset;
3532 unsigned int size;
3534 unsigned int map_count;
3535 uint32_t map_flags;
3536 DWORD locations;
3537 struct wined3d_bo *bo;
3538 union
3540 struct wined3d_color colour;
3541 struct
3543 float depth;
3544 unsigned int stencil;
3546 } clear_value;
3548 void *user_memory;
3549 } *sub_resources;
3552 static inline void *wined3d_texture_allocate_object_memory(SIZE_T s, SIZE_T level_count, SIZE_T layer_count)
3554 struct wined3d_texture *t;
3556 if (level_count > ((~(SIZE_T)0 - s) / sizeof(*t->sub_resources)) / layer_count)
3557 return NULL;
3559 return heap_alloc_zero(s + level_count * layer_count * sizeof(*t->sub_resources));
3562 static inline struct wined3d_texture *texture_from_resource(struct wined3d_resource *resource)
3564 return CONTAINING_RECORD(resource, struct wined3d_texture, resource);
3567 static inline unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture,
3568 unsigned int level)
3570 return max(1, texture->resource.width >> level);
3573 static inline unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture,
3574 unsigned int level)
3576 return max(1, texture->resource.height >> level);
3579 static inline unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture,
3580 unsigned int level)
3582 return max(1, texture->resource.depth >> level);
3585 static inline unsigned int wined3d_texture_get_level_pow2_width(const struct wined3d_texture *texture,
3586 unsigned int level)
3588 return max(1, texture->pow2_width >> level);
3591 static inline unsigned int wined3d_texture_get_level_pow2_height(const struct wined3d_texture *texture,
3592 unsigned int level)
3594 return max(1, texture->pow2_height >> level);
3597 static inline void wined3d_texture_get_level_box(const struct wined3d_texture *texture,
3598 unsigned int level, struct wined3d_box *box)
3600 wined3d_box_set(box, 0, 0,
3601 wined3d_texture_get_level_width(texture, level),
3602 wined3d_texture_get_level_height(texture, level),
3603 0, wined3d_texture_get_level_depth(texture, level));
3606 static inline bool wined3d_texture_is_full_rect(const struct wined3d_texture *texture,
3607 unsigned int level, const RECT *r)
3609 unsigned int t;
3611 t = wined3d_texture_get_level_width(texture, level);
3612 if ((r->left && r->right) || abs(r->right - r->left) != t)
3613 return false;
3614 t = wined3d_texture_get_level_height(texture, level);
3615 if ((r->top && r->bottom) || abs(r->bottom - r->top) != t)
3616 return false;
3617 return true;
3620 HRESULT texture2d_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3621 const struct wined3d_box *dst_box, struct wined3d_texture *src_texture,
3622 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, uint32_t flags,
3623 const struct wined3d_blt_fx *blt_fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
3624 void texture2d_get_blt_info(const struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
3625 const RECT *rect, struct wined3d_blt_info *info) DECLSPEC_HIDDEN;
3626 void texture2d_load_fb_texture(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
3627 BOOL srgb, struct wined3d_context *context) DECLSPEC_HIDDEN;
3628 void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3629 struct wined3d_context *context, DWORD src_location, DWORD dst_location) DECLSPEC_HIDDEN;
3631 void wined3d_texture_cleanup(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3632 void wined3d_texture_download_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3633 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx) DECLSPEC_HIDDEN;
3634 void wined3d_texture_get_bo_address(const struct wined3d_texture *texture,
3635 unsigned int sub_resource_idx, struct wined3d_bo_address *data, uint32_t location) DECLSPEC_HIDDEN;
3636 GLenum wined3d_texture_get_gl_buffer(const struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3637 void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
3638 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
3639 void wined3d_texture_load(struct wined3d_texture *texture,
3640 struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
3641 BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
3642 unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3643 BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3644 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
3645 void wined3d_texture_set_swapchain(struct wined3d_texture *texture,
3646 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
3647 BOOL wined3d_texture_can_use_pbo(const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
3648 DECLSPEC_HIDDEN;
3649 void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3650 void wined3d_texture_translate_drawable_coords(const struct wined3d_texture *texture,
3651 HWND window, RECT *rect) DECLSPEC_HIDDEN;
3652 void wined3d_texture_update_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3653 struct wined3d_context *context, const struct upload_bo *upload_bo, const struct wined3d_box *box,
3654 unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
3655 void wined3d_texture_upload_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
3656 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, struct wined3d_texture *src_texture,
3657 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box) DECLSPEC_HIDDEN;
3658 void wined3d_texture_validate_location(struct wined3d_texture *texture,
3659 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
3660 bool wined3d_texture_validate_sub_resource_idx(const struct wined3d_texture *texture,
3661 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
3662 void wined3d_texture_clear_dirty_regions(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
3664 HRESULT wined3d_texture_no3d_init(struct wined3d_texture *texture_no3d, struct wined3d_device *device,
3665 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
3666 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3668 void wined3d_gl_texture_swizzle_from_color_fixup(GLint swizzle[4], struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
3670 struct gl_texture
3672 struct wined3d_sampler_desc sampler_desc;
3673 unsigned int base_level;
3674 GLuint name;
3677 struct wined3d_texture_gl
3679 struct wined3d_texture t;
3681 struct gl_texture texture_rgb, texture_srgb;
3683 GLenum target;
3685 GLuint rb_multisample;
3686 GLuint rb_resolved;
3688 struct list renderbuffers;
3689 const struct wined3d_renderbuffer_entry *current_renderbuffer;
3692 static inline struct wined3d_texture_gl *wined3d_texture_gl(struct wined3d_texture *texture)
3694 return CONTAINING_RECORD(texture, struct wined3d_texture_gl, t);
3697 static inline struct gl_texture *wined3d_texture_gl_get_gl_texture(struct wined3d_texture_gl *texture_gl,
3698 BOOL srgb)
3700 return srgb ? &texture_gl->texture_srgb : &texture_gl->texture_rgb;
3703 static inline GLenum wined3d_texture_gl_get_sub_resource_target(const struct wined3d_texture_gl *texture_gl,
3704 unsigned int sub_resource_idx)
3706 static const GLenum cube_targets[] =
3708 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
3709 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
3710 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
3711 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
3712 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
3713 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
3716 return texture_gl->t.resource.usage & WINED3DUSAGE_LEGACY_CUBEMAP
3717 ? cube_targets[sub_resource_idx / texture_gl->t.level_count] : texture_gl->target;
3720 static inline BOOL wined3d_texture_gl_is_multisample_location(const struct wined3d_texture_gl *texture_gl,
3721 uint32_t location)
3723 if (location == WINED3D_LOCATION_RB_MULTISAMPLE)
3724 return TRUE;
3725 if (location != WINED3D_LOCATION_TEXTURE_RGB && location != WINED3D_LOCATION_TEXTURE_SRGB)
3726 return FALSE;
3727 return texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE || texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
3730 void wined3d_texture_gl_apply_sampler_desc(struct wined3d_texture_gl *texture_gl,
3731 const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
3732 void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl,
3733 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
3734 void wined3d_texture_gl_bind_and_dirtify(struct wined3d_texture_gl *texture_gl,
3735 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
3736 HRESULT wined3d_texture_gl_init(struct wined3d_texture_gl *texture_gl, struct wined3d_device *device,
3737 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
3738 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3739 void wined3d_texture_gl_prepare_texture(struct wined3d_texture_gl *texture_gl,
3740 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
3741 void wined3d_texture_gl_set_compatible_renderbuffer(struct wined3d_texture_gl *texture_gl,
3742 struct wined3d_context_gl *context_gl, unsigned int level,
3743 const struct wined3d_rendertarget_info *rt) DECLSPEC_HIDDEN;
3745 struct wined3d_renderbuffer_entry
3747 struct list entry;
3748 GLuint id;
3749 UINT width;
3750 UINT height;
3753 struct wined3d_fbo_resource
3755 GLuint object;
3756 GLenum target;
3757 GLuint level, layer;
3760 #define WINED3D_FBO_ENTRY_FLAG_ATTACHED 0x1
3761 #define WINED3D_FBO_ENTRY_FLAG_DEPTH 0x2
3762 #define WINED3D_FBO_ENTRY_FLAG_STENCIL 0x4
3764 struct fbo_entry
3766 struct list entry;
3767 uint32_t flags;
3768 uint32_t rt_mask;
3769 GLuint id;
3770 struct wined3d_fbo_entry_key
3772 DWORD rb_namespace;
3773 struct wined3d_fbo_resource objects[WINED3D_MAX_RENDER_TARGETS + 1];
3774 } key;
3777 struct wined3d_sampler
3779 struct wine_rb_entry entry;
3780 LONG refcount;
3781 struct wined3d_device *device;
3782 void *parent;
3783 const struct wined3d_parent_ops *parent_ops;
3784 struct wined3d_sampler_desc desc;
3787 struct wined3d_sampler_gl
3789 struct wined3d_sampler s;
3791 GLuint name;
3794 static inline struct wined3d_sampler_gl *wined3d_sampler_gl(struct wined3d_sampler *sampler)
3796 return CONTAINING_RECORD(sampler, struct wined3d_sampler_gl, s);
3799 void wined3d_sampler_gl_bind(struct wined3d_sampler_gl *sampler_gl, unsigned int unit,
3800 struct wined3d_texture_gl *texture_gl, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
3801 void wined3d_sampler_gl_init(struct wined3d_sampler_gl *sampler_gl,
3802 struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
3803 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
3805 struct wined3d_vertex_declaration_element
3807 const struct wined3d_format *format;
3808 BOOL ffp_valid;
3809 unsigned int input_slot;
3810 unsigned int offset;
3811 unsigned int output_slot;
3812 enum wined3d_input_classification input_slot_class;
3813 unsigned int instance_data_step_rate;
3814 BYTE method;
3815 BYTE usage;
3816 BYTE usage_idx;
3819 struct wined3d_vertex_declaration
3821 LONG ref;
3822 void *parent;
3823 const struct wined3d_parent_ops *parent_ops;
3824 struct wined3d_device *device;
3826 struct wined3d_vertex_declaration_element *elements;
3827 unsigned int element_count;
3829 BOOL position_transformed;
3832 struct wined3d_saved_states
3834 uint32_t vs_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_VS_CONSTS_F)];
3835 WORD vertexShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
3836 WORD vertexShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
3837 uint32_t ps_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_PS_CONSTS_F)];
3838 WORD pixelShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
3839 WORD pixelShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
3840 uint32_t transform[WINED3D_BITMAP_SIZE(WINED3D_HIGHEST_TRANSFORM_STATE + 1)];
3841 WORD streamSource; /* WINED3D_MAX_STREAMS, 16 */
3842 WORD streamFreq; /* WINED3D_MAX_STREAMS, 16 */
3843 uint32_t renderState[WINED3D_BITMAP_SIZE(WINEHIGHEST_RENDER_STATE + 1)];
3844 DWORD textureState[WINED3D_MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
3845 WORD samplerState[WINED3D_MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
3846 DWORD clipplane; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
3847 DWORD textures : 20; /* WINED3D_MAX_COMBINED_SAMPLERS, 20 */
3848 DWORD indices : 1;
3849 DWORD material : 1;
3850 DWORD viewport : 1;
3851 DWORD vertexDecl : 1;
3852 DWORD pixelShader : 1;
3853 DWORD vertexShader : 1;
3854 DWORD scissorRect : 1;
3855 DWORD store_stream_offset : 1;
3856 DWORD alpha_to_coverage : 1;
3857 DWORD lights : 1;
3858 DWORD transforms : 1;
3859 DWORD padding : 1;
3861 struct list changed_lights;
3864 struct StageState {
3865 DWORD stage;
3866 DWORD state;
3869 struct wined3d_stateblock
3871 LONG ref; /* Note: Ref counting not required */
3872 struct wined3d_device *device;
3874 /* Array indicating whether things have been set or changed */
3875 struct wined3d_saved_states changed;
3877 struct wined3d_stateblock_state stateblock_state;
3878 struct wined3d_light_state light_state;
3880 /* Contained state management */
3881 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
3882 unsigned int num_contained_render_states;
3883 DWORD contained_transform_states[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
3884 unsigned int num_contained_transform_states;
3885 struct StageState contained_tss_states[WINED3D_MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
3886 unsigned int num_contained_tss_states;
3887 struct StageState contained_sampler_states[WINED3D_MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
3888 unsigned int num_contained_sampler_states;
3891 void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state,
3892 const struct wined3d_device *device, uint32_t flags) DECLSPEC_HIDDEN;
3893 void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) DECLSPEC_HIDDEN;
3895 bool wined3d_light_state_enable_light(struct wined3d_light_state *state, const struct wined3d_d3d_info *d3d_info,
3896 struct wined3d_light_info *light_info, BOOL enable) DECLSPEC_HIDDEN;
3897 struct wined3d_light_info *wined3d_light_state_get_light(const struct wined3d_light_state *state,
3898 unsigned int idx) DECLSPEC_HIDDEN;
3899 HRESULT wined3d_light_state_set_light(struct wined3d_light_state *state, DWORD light_idx,
3900 const struct wined3d_light *params, struct wined3d_light_info **light_info) DECLSPEC_HIDDEN;
3902 enum wined3d_cs_queue_id
3904 WINED3D_CS_QUEUE_DEFAULT = 0,
3905 WINED3D_CS_QUEUE_MAP,
3906 WINED3D_CS_QUEUE_COUNT,
3909 #define WINED3D_CS_QUERY_POLL_INTERVAL 10u
3910 #if defined(_WIN64)
3911 #define WINED3D_CS_QUEUE_SIZE 0x1000000u
3912 #else
3913 #define WINED3D_CS_QUEUE_SIZE 0x400000u
3914 #endif
3915 #define WINED3D_CS_SPIN_COUNT 2000u
3916 #define WINED3D_CS_QUEUE_MASK (WINED3D_CS_QUEUE_SIZE - 1)
3918 C_ASSERT(!(WINED3D_CS_QUEUE_SIZE & (WINED3D_CS_QUEUE_SIZE - 1)));
3920 struct wined3d_cs_queue
3922 ULONG head, tail;
3923 BYTE data[WINED3D_CS_QUEUE_SIZE];
3926 struct wined3d_device_context_ops
3928 void *(*require_space)(struct wined3d_device_context *context, size_t size, enum wined3d_cs_queue_id queue_id);
3929 void (*submit)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
3930 void (*finish)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
3931 bool (*map_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
3932 unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
3933 const struct wined3d_box *box, uint32_t flags);
3934 bool (*unmap_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
3935 unsigned int sub_resource_idx, struct wined3d_box *box, struct upload_bo *upload_bo);
3936 void (*issue_query)(struct wined3d_device_context *context, struct wined3d_query *query, unsigned int flags);
3937 void (*flush)(struct wined3d_device_context *context);
3938 void (*reference_resource)(struct wined3d_device_context *context, struct wined3d_resource *resource);
3939 void (*reference_command_list)(struct wined3d_device_context *context, struct wined3d_command_list *list);
3942 struct wined3d_device_context
3944 const struct wined3d_device_context_ops *ops;
3945 struct wined3d_device *device;
3946 struct wined3d_state *state;
3949 struct wined3d_cs
3951 struct wined3d_device_context c;
3953 struct wined3d_state state;
3954 HMODULE wined3d_module;
3955 HANDLE thread;
3956 DWORD thread_id;
3957 BOOL serialize_commands;
3959 struct wined3d_cs_queue queue[WINED3D_CS_QUEUE_COUNT];
3960 size_t data_size, start, end;
3961 void *data;
3962 struct list query_poll_list;
3963 BOOL queries_flushed;
3965 HANDLE event, present_event;
3966 LONG waiting_for_event;
3967 LONG waiting_for_present;
3968 LONG pending_presents;
3971 static inline void wined3d_device_context_lock(struct wined3d_device_context *context)
3973 if (context == &context->device->cs->c)
3974 wined3d_mutex_lock();
3977 static inline void wined3d_device_context_unlock(struct wined3d_device_context *context)
3979 if (context == &context->device->cs->c)
3980 wined3d_mutex_unlock();
3983 struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
3984 const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN;
3985 void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
3986 void wined3d_cs_destroy_object(struct wined3d_cs *cs,
3987 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
3988 void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs *cs,
3989 struct wined3d_texture *texture, unsigned int layer) DECLSPEC_HIDDEN;
3990 void wined3d_cs_emit_clear(struct wined3d_cs *cs, DWORD rect_count, const RECT *rects,
3991 uint32_t flags, const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
3992 void wined3d_device_context_emit_clear_uav(struct wined3d_device_context *context,
3993 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp) DECLSPEC_HIDDEN;
3994 void wined3d_cs_emit_preload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
3995 void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *swapchain, const RECT *src_rect,
3996 const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags) DECLSPEC_HIDDEN;
3997 void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture *texture,
3998 WORD flags, const struct wined3d_color_key *color_key) DECLSPEC_HIDDEN;
3999 void wined3d_cs_emit_set_render_state(struct wined3d_cs *cs,
4000 enum wined3d_render_state state, DWORD value) DECLSPEC_HIDDEN;
4001 void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4002 void wined3d_cs_init_object(struct wined3d_cs *cs,
4003 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
4004 void wined3d_cs_map_bo_address(struct wined3d_cs *cs,
4005 struct wined3d_bo_address *addr, size_t size, unsigned int flags) DECLSPEC_HIDDEN;
4006 void wined3d_device_context_set_depth_bounds(struct wined3d_device_context *context,
4007 bool enable, float min_depth, float max_depth);
4009 static inline void wined3d_cs_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
4011 cs->c.ops->finish(&cs->c, queue_id);
4014 void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context *context,
4015 struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, const struct wined3d_box *dst_box,
4016 struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box,
4017 unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
4018 void wined3d_device_context_emit_clear_rendertarget_view(struct wined3d_device_context *context,
4019 struct wined3d_rendertarget_view *view, const RECT *rect, unsigned int flags,
4020 const struct wined3d_color *color, float depth, unsigned int stencil) DECLSPEC_HIDDEN;
4021 void wined3d_device_context_emit_copy_uav_counter(struct wined3d_device_context *context,
4022 struct wined3d_buffer *dst_buffer, unsigned int offset,
4023 struct wined3d_unordered_access_view *uav) DECLSPEC_HIDDEN;
4024 void wined3d_device_context_emit_draw(struct wined3d_device_context *context,
4025 enum wined3d_primitive_type primitive_type, unsigned int patch_vertex_count, int base_vertex_idx,
4026 unsigned int start_idx, unsigned int index_count, unsigned int start_instance, unsigned int instance_count,
4027 bool indexed) DECLSPEC_HIDDEN;
4028 void wined3d_device_context_emit_execute_command_list(struct wined3d_device_context *context,
4029 struct wined3d_command_list *list, bool restore_state) DECLSPEC_HIDDEN;
4030 void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context *context,
4031 struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
4032 HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
4033 struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
4034 const struct wined3d_box *box, unsigned int flags) DECLSPEC_HIDDEN;
4035 void wined3d_device_context_emit_reset_state(struct wined3d_device_context *context, bool invalidate) DECLSPEC_HIDDEN;
4036 void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context *context,
4037 struct wined3d_blend_state *state, const struct wined3d_color *blend_factor,
4038 unsigned int sample_mask) DECLSPEC_HIDDEN;
4039 void wined3d_device_context_emit_set_clip_plane(struct wined3d_device_context *context, unsigned int plane_idx,
4040 const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN;
4041 void wined3d_device_context_emit_set_constant_buffers(struct wined3d_device_context *context,
4042 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
4043 const struct wined3d_constant_buffer_state *buffers) DECLSPEC_HIDDEN;
4044 void wined3d_device_context_emit_set_depth_stencil_state(struct wined3d_device_context *context,
4045 struct wined3d_depth_stencil_state *state, unsigned int stencil_ref) DECLSPEC_HIDDEN;
4046 void wined3d_device_context_emit_set_depth_stencil_view(struct wined3d_device_context *context,
4047 struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
4048 void wined3d_device_context_emit_set_feature_level(struct wined3d_device_context *context,
4049 enum wined3d_feature_level level) DECLSPEC_HIDDEN;
4050 void wined3d_device_context_emit_set_index_buffer(struct wined3d_device_context *context, struct wined3d_buffer *buffer,
4051 enum wined3d_format_id format_id, unsigned int offset) DECLSPEC_HIDDEN;
4052 void wined3d_device_context_emit_set_light(struct wined3d_device_context *context,
4053 const struct wined3d_light_info *light) DECLSPEC_HIDDEN;
4054 void wined3d_device_context_emit_set_light_enable(struct wined3d_device_context *context, unsigned int idx,
4055 BOOL enable) DECLSPEC_HIDDEN;
4056 void wined3d_device_context_emit_set_material(struct wined3d_device_context *context,
4057 const struct wined3d_material *material) DECLSPEC_HIDDEN;
4058 void wined3d_device_context_emit_set_predication(struct wined3d_device_context *context,
4059 struct wined3d_query *predicate, BOOL value) DECLSPEC_HIDDEN;
4060 void wined3d_device_context_emit_set_rasterizer_state(struct wined3d_device_context *context,
4061 struct wined3d_rasterizer_state *rasterizer_state) DECLSPEC_HIDDEN;
4062 void wined3d_device_context_emit_set_render_state(struct wined3d_device_context *context,
4063 enum wined3d_render_state state, unsigned int value) DECLSPEC_HIDDEN;
4064 void wined3d_device_context_emit_set_rendertarget_views(struct wined3d_device_context *context, unsigned int start_idx,
4065 unsigned int count, struct wined3d_rendertarget_view *const *views) DECLSPEC_HIDDEN;
4066 void wined3d_device_context_emit_set_samplers(struct wined3d_device_context *context, enum wined3d_shader_type type,
4067 unsigned int start_idx, unsigned int count, struct wined3d_sampler *const *samplers) DECLSPEC_HIDDEN;
4068 void wined3d_device_context_emit_set_sampler_state(struct wined3d_device_context *context, unsigned int sampler_idx,
4069 enum wined3d_sampler_state state, unsigned int value) DECLSPEC_HIDDEN;
4070 void wined3d_device_context_emit_set_scissor_rects(struct wined3d_device_context *context,
4071 unsigned int rect_count, const RECT *rects) DECLSPEC_HIDDEN;
4072 void wined3d_device_context_emit_set_shader(struct wined3d_device_context *context, enum wined3d_shader_type type,
4073 struct wined3d_shader *shader) DECLSPEC_HIDDEN;
4074 void wined3d_device_context_emit_set_shader_resource_views(struct wined3d_device_context *context,
4075 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
4076 struct wined3d_shader_resource_view *const *views) DECLSPEC_HIDDEN;
4077 void wined3d_device_context_emit_set_stream_outputs(struct wined3d_device_context *context,
4078 const struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]) DECLSPEC_HIDDEN;
4079 void wined3d_device_context_emit_set_stream_sources(struct wined3d_device_context *context,
4080 unsigned int start_idx, unsigned int count, const struct wined3d_stream_state *streams) DECLSPEC_HIDDEN;
4081 void wined3d_device_context_emit_set_texture(struct wined3d_device_context *context, unsigned int stage,
4082 struct wined3d_texture *texture) DECLSPEC_HIDDEN;
4083 void wined3d_device_context_emit_set_texture_state(struct wined3d_device_context *context, unsigned int stage,
4084 enum wined3d_texture_stage_state state, unsigned int value) DECLSPEC_HIDDEN;
4085 void wined3d_device_context_emit_set_transform(struct wined3d_device_context *context,
4086 enum wined3d_transform_state state, const struct wined3d_matrix *matrix) DECLSPEC_HIDDEN;
4087 void wined3d_device_context_emit_set_unordered_access_views(struct wined3d_device_context *context,
4088 enum wined3d_pipeline pipeline, unsigned int start_idx, unsigned int count,
4089 struct wined3d_unordered_access_view *const *views, const unsigned int *initial_count) DECLSPEC_HIDDEN;
4090 void wined3d_device_context_emit_set_vertex_declaration(struct wined3d_device_context *context,
4091 struct wined3d_vertex_declaration *declaration) DECLSPEC_HIDDEN;
4092 void wined3d_device_context_emit_set_viewports(struct wined3d_device_context *context, unsigned int viewport_count,
4093 const struct wined3d_viewport *viewports) DECLSPEC_HIDDEN;
4094 void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context,
4095 struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box,
4096 const void *data, unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
4097 HRESULT wined3d_device_context_emit_unmap(struct wined3d_device_context *context,
4098 struct wined3d_resource *resource, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
4099 void wined3d_device_context_push_constants(struct wined3d_device_context *context,
4100 enum wined3d_push_constants type, unsigned int start_idx,
4101 unsigned int count, const void *constants) DECLSPEC_HIDDEN;
4103 static inline void wined3d_resource_reference(struct wined3d_resource *resource)
4105 const struct wined3d_cs *cs = resource->device->cs;
4106 resource->access_time = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
4109 static inline BOOL wined3d_ge_wrap(ULONG x, ULONG y)
4111 return (x - y) < UINT_MAX / 2;
4113 C_ASSERT(WINED3D_CS_QUEUE_SIZE < UINT_MAX / 4);
4115 static inline void wined3d_resource_wait_idle(const struct wined3d_resource *resource)
4117 const struct wined3d_cs *cs = resource->device->cs;
4118 ULONG access_time, tail, head;
4120 if (!cs->thread || cs->thread_id == GetCurrentThreadId())
4121 return;
4123 access_time = resource->access_time;
4124 head = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
4126 /* The basic idea is that a resource is busy if tail < access_time <= head.
4127 * But we have to be careful about wrap-around of the head and tail. The
4128 * wined3d_ge_wrap function considers x >= y if x - y is smaller than half the
4129 * UINT range. Head is at most WINED3D_CS_QUEUE_SIZE ahead of tail, because
4130 * otherwise the queue memory is considered full and queue_require_space
4131 * stalls. Thus wined3d_ge_wrap(head, tail) is always true. The C_ASSERT above
4132 * ensures this in case we decide to grow the queue size in the future.
4134 * It is possible that a resource has not been used for a long time and is idle, but the head and
4135 * tail wrapped around in such a way that the previously set access time falls between head and tail.
4136 * In this case we will incorrectly wait for the resource. Because we use the entire 32 bits of the
4137 * counters and not just the bits needed to address the actual queue memory, this should happen rarely.
4138 * If it turns out to be a problem we can switch to 64 bit counters or attempt to somehow mark the
4139 * access time of resources invalid. CS packets are at least 4 byte aligned, so we could use the lower
4140 * 2 bits in access_time for such a marker.
4142 * Note that the access time is set before the command is submitted, so we have to wait until the
4143 * tail is bigger than access_time, not equal. */
4145 if (!wined3d_ge_wrap(head, access_time))
4146 return;
4148 for (;;)
4150 tail = *(volatile ULONG *)&cs->queue[WINED3D_CS_QUEUE_DEFAULT].tail;
4151 if (head == tail) /* Queue empty. */
4152 break;
4154 if (!wined3d_ge_wrap(access_time, tail) && access_time != tail)
4155 break;
4157 YieldProcessor();
4161 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
4162 * fixed function semantics as D3DCOLOR or FLOAT16 */
4163 enum wined3d_buffer_conversion_type
4165 CONV_NONE,
4166 CONV_D3DCOLOR,
4167 CONV_POSITIONT,
4170 struct wined3d_buffer
4172 struct wined3d_resource resource;
4173 const struct wined3d_buffer_ops *buffer_ops;
4175 unsigned int structure_byte_stride;
4176 uint32_t flags;
4177 DWORD locations;
4178 void *map_ptr;
4179 struct wined3d_bo *buffer_object;
4180 struct wined3d_bo_user bo_user;
4182 struct wined3d_range *maps;
4183 SIZE_T maps_size, modified_areas;
4185 /* conversion stuff */
4186 UINT decl_change_count, full_conversion_count;
4187 UINT draw_count;
4188 UINT stride; /* 0 if no conversion */
4189 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
4190 UINT conversion_stride; /* 0 if no shifted conversion */
4193 static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resource *resource)
4195 return CONTAINING_RECORD(resource, struct wined3d_buffer, resource);
4198 static inline void wined3d_buffer_validate_user(struct wined3d_buffer *buffer)
4200 if (buffer->bo_user.valid)
4201 return;
4202 buffer->bo_user.valid = true;
4203 list_add_head(&buffer->buffer_object->users, &buffer->bo_user.entry);
4206 void wined3d_buffer_acquire_bo_for_write(struct wined3d_buffer *buffer,
4207 struct wined3d_context *context) DECLSPEC_HIDDEN;
4208 void wined3d_buffer_cleanup(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
4209 void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset,
4210 struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size) DECLSPEC_HIDDEN;
4211 void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wined3d_context *context,
4212 unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size) DECLSPEC_HIDDEN;
4213 DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context,
4214 struct wined3d_bo_address *data) DECLSPEC_HIDDEN;
4215 void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, uint32_t location) DECLSPEC_HIDDEN;
4216 void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context,
4217 const struct wined3d_state *state) DECLSPEC_HIDDEN;
4218 BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer,
4219 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
4220 void *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN;
4221 BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer,
4222 struct wined3d_context *context, unsigned int location) DECLSPEC_HIDDEN;
4223 void wined3d_buffer_update_sub_resource(struct wined3d_buffer *buffer, struct wined3d_context *context,
4224 const struct upload_bo *upload_bo, unsigned int offset, unsigned int size) DECLSPEC_HIDDEN;
4225 void wined3d_buffer_validate_location(struct wined3d_buffer *buffer, uint32_t location) DECLSPEC_HIDDEN;
4227 HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device,
4228 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
4229 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4231 struct wined3d_buffer_gl
4233 struct wined3d_buffer b;
4236 static inline struct wined3d_buffer_gl *wined3d_buffer_gl(struct wined3d_buffer *buffer)
4238 return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
4241 static inline const struct wined3d_buffer_gl *wined3d_buffer_gl_const(const struct wined3d_buffer *buffer)
4243 return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
4246 HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device,
4247 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
4248 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4250 struct wined3d_rendertarget_view
4252 LONG refcount;
4254 struct wined3d_resource *resource;
4255 void *parent;
4256 const struct wined3d_parent_ops *parent_ops;
4258 const struct wined3d_format *format;
4259 unsigned int format_attrs;
4260 unsigned int format_caps;
4261 unsigned int sub_resource_idx;
4262 unsigned int layer_count;
4264 unsigned int width;
4265 unsigned int height;
4267 struct wined3d_view_desc desc;
4270 void wined3d_rendertarget_view_cleanup(struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
4271 void wined3d_rendertarget_view_get_drawable_size(const struct wined3d_rendertarget_view *view,
4272 const struct wined3d_context *context, unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
4273 void wined3d_rendertarget_view_get_box(struct wined3d_rendertarget_view *view,
4274 struct wined3d_box *box) DECLSPEC_HIDDEN;
4275 void wined3d_rendertarget_view_invalidate_location(struct wined3d_rendertarget_view *view,
4276 uint32_t location) DECLSPEC_HIDDEN;
4277 void wined3d_rendertarget_view_load_location(struct wined3d_rendertarget_view *view,
4278 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
4279 void wined3d_rendertarget_view_prepare_location(struct wined3d_rendertarget_view *view,
4280 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
4281 void wined3d_rendertarget_view_validate_location(struct wined3d_rendertarget_view *view,
4282 uint32_t location) DECLSPEC_HIDDEN;
4283 DWORD wined3d_rendertarget_view_get_locations(const struct wined3d_rendertarget_view *view)
4284 DECLSPEC_HIDDEN;
4286 HRESULT wined3d_rendertarget_view_no3d_init(struct wined3d_rendertarget_view *view_no3d,
4287 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
4288 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4290 struct wined3d_rendertarget_view_gl
4292 struct wined3d_rendertarget_view v;
4293 struct wined3d_gl_view gl_view;
4296 static inline struct wined3d_rendertarget_view_gl *wined3d_rendertarget_view_gl(
4297 struct wined3d_rendertarget_view *view)
4299 return CONTAINING_RECORD(view, struct wined3d_rendertarget_view_gl, v);
4302 HRESULT wined3d_rendertarget_view_gl_init(struct wined3d_rendertarget_view_gl *view_gl,
4303 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
4304 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4306 struct wined3d_shader_resource_view
4308 LONG refcount;
4310 struct wined3d_resource *resource;
4311 void *parent;
4312 const struct wined3d_parent_ops *parent_ops;
4314 const struct wined3d_format *format;
4316 struct wined3d_view_desc desc;
4319 void wined3d_shader_resource_view_cleanup(struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
4321 struct wined3d_shader_resource_view_gl
4323 struct wined3d_shader_resource_view v;
4324 struct wined3d_bo_user bo_user;
4325 struct wined3d_gl_view gl_view;
4328 static inline struct wined3d_shader_resource_view_gl *wined3d_shader_resource_view_gl(
4329 struct wined3d_shader_resource_view *view)
4331 return CONTAINING_RECORD(view, struct wined3d_shader_resource_view_gl, v);
4334 void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl *view_gl, unsigned int unit,
4335 struct wined3d_sampler_gl *sampler_gl, struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4336 void wined3d_shader_resource_view_gl_generate_mipmap(struct wined3d_shader_resource_view_gl *srv_gl,
4337 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4338 HRESULT wined3d_shader_resource_view_gl_init(struct wined3d_shader_resource_view_gl *view_gl,
4339 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
4340 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4341 void wined3d_shader_resource_view_gl_update(struct wined3d_shader_resource_view_gl *srv_gl,
4342 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4344 struct wined3d_unordered_access_view
4346 LONG refcount;
4348 struct wined3d_resource *resource;
4349 void *parent;
4350 const struct wined3d_parent_ops *parent_ops;
4352 const struct wined3d_format *format;
4354 struct wined3d_view_desc desc;
4355 struct wined3d_bo *counter_bo;
4358 void wined3d_unordered_access_view_cleanup(struct wined3d_unordered_access_view *view) DECLSPEC_HIDDEN;
4359 void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_view *view,
4360 struct wined3d_buffer *buffer, unsigned int offset, struct wined3d_context *context) DECLSPEC_HIDDEN;
4361 void wined3d_unordered_access_view_invalidate_location(struct wined3d_unordered_access_view *view,
4362 uint32_t location) DECLSPEC_HIDDEN;
4363 void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_view *view,
4364 unsigned int value) DECLSPEC_HIDDEN;
4366 struct wined3d_unordered_access_view_gl
4368 struct wined3d_unordered_access_view v;
4369 struct wined3d_bo_user bo_user;
4370 struct wined3d_gl_view gl_view;
4371 struct wined3d_bo_gl counter_bo;
4374 static inline struct wined3d_unordered_access_view_gl *wined3d_unordered_access_view_gl(
4375 struct wined3d_unordered_access_view *view)
4377 return CONTAINING_RECORD(view, struct wined3d_unordered_access_view_gl, v);
4380 void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view_gl *view_gl,
4381 const struct wined3d_uvec4 *clear_value, struct wined3d_context_gl *context_gl, bool fp) DECLSPEC_HIDDEN;
4382 HRESULT wined3d_unordered_access_view_gl_init(struct wined3d_unordered_access_view_gl *view_gl,
4383 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
4384 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4385 void wined3d_unordered_access_view_gl_update(struct wined3d_unordered_access_view_gl *uav_gl,
4386 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4388 struct wined3d_swapchain_state
4390 struct wined3d *wined3d;
4391 struct wined3d_swapchain_desc desc;
4392 struct wined3d_swapchain_state_parent *parent;
4394 struct wined3d_display_mode original_mode, d3d_mode;
4395 RECT original_window_rect;
4397 /* Window styles to restore when switching fullscreen mode. */
4398 LONG style;
4399 LONG exstyle;
4400 HWND device_window;
4403 void wined3d_swapchain_state_cleanup(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
4404 void wined3d_swapchain_state_register(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
4405 void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state,
4406 HWND window, const RECT *window_rect) DECLSPEC_HIDDEN;
4407 HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
4408 HWND window, int x, int y, int width, int height) DECLSPEC_HIDDEN;
4410 struct wined3d_swapchain_ops
4412 void (*swapchain_present)(struct wined3d_swapchain *swapchain,
4413 const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags);
4414 void (*swapchain_frontbuffer_updated)(struct wined3d_swapchain *swapchain);
4417 struct wined3d_swapchain
4419 LONG ref;
4420 void *parent;
4421 const struct wined3d_parent_ops *parent_ops;
4422 const struct wined3d_swapchain_ops *swapchain_ops;
4423 struct wined3d_device *device;
4425 struct wined3d_texture **back_buffers;
4426 struct wined3d_texture *front_buffer;
4427 struct wined3d_gamma_ramp orig_gamma;
4428 bool reapply_mode;
4429 const struct wined3d_format *ds_format;
4430 struct wined3d_palette *palette;
4431 RECT front_buffer_update;
4432 unsigned int swap_interval;
4433 unsigned int max_frame_latency;
4435 LONG prev_time, frames; /* Performance tracking */
4437 struct wined3d_swapchain_state state;
4438 HWND win_handle;
4441 void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activate) DECLSPEC_HIDDEN;
4442 void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4443 struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4444 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4445 void swapchain_set_max_frame_latency(struct wined3d_swapchain *swapchain,
4446 const struct wined3d_device *device) DECLSPEC_HIDDEN;
4448 HRESULT wined3d_swapchain_no3d_init(struct wined3d_swapchain *swapchain_no3d,
4449 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
4450 struct wined3d_swapchain_state_parent *state_parent, void *parent,
4451 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4453 struct wined3d_swapchain_gl
4455 struct wined3d_swapchain s;
4458 static inline struct wined3d_swapchain_gl *wined3d_swapchain_gl(struct wined3d_swapchain *swapchain)
4460 return CONTAINING_RECORD(swapchain, struct wined3d_swapchain_gl, s);
4463 void wined3d_swapchain_gl_cleanup(struct wined3d_swapchain_gl *swapchain_gl) DECLSPEC_HIDDEN;
4464 struct wined3d_context_gl *wined3d_swapchain_gl_get_context(struct wined3d_swapchain_gl *swapchain_gl) DECLSPEC_HIDDEN;
4465 HRESULT wined3d_swapchain_gl_init(struct wined3d_swapchain_gl *swapchain_gl,
4466 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
4467 struct wined3d_swapchain_state_parent *state_parent, void *parent,
4468 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4470 /*****************************************************************************
4471 * Utility function prototypes
4474 /* Trace routines */
4475 const char *debug_bo_address(const struct wined3d_bo_address *address) DECLSPEC_HIDDEN;
4476 const char *debug_box(const struct wined3d_box *box) DECLSPEC_HIDDEN;
4477 const char *debug_color(const struct wined3d_color *color) DECLSPEC_HIDDEN;
4478 const char *debug_const_bo_address(const struct wined3d_const_bo_address *address) DECLSPEC_HIDDEN;
4479 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx) DECLSPEC_HIDDEN;
4480 const char *debug_d3dformat(enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
4481 const char *debug_d3ddevicetype(enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
4482 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) DECLSPEC_HIDDEN;
4483 const char *debug_d3dusage(uint32_t usage) DECLSPEC_HIDDEN;
4484 const char *debug_d3ddeclmethod(enum wined3d_decl_method method) DECLSPEC_HIDDEN;
4485 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
4486 const char *debug_d3dinput_classification(enum wined3d_input_classification classification) DECLSPEC_HIDDEN;
4487 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) DECLSPEC_HIDDEN;
4488 const char *debug_d3drenderstate(enum wined3d_render_state state) DECLSPEC_HIDDEN;
4489 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) DECLSPEC_HIDDEN;
4490 const char *debug_d3dstate(uint32_t state) DECLSPEC_HIDDEN;
4491 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) DECLSPEC_HIDDEN;
4492 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) DECLSPEC_HIDDEN;
4493 const char *debug_d3dtop(enum wined3d_texture_op d3dtop) DECLSPEC_HIDDEN;
4494 const char *debug_d3dtstype(enum wined3d_transform_state tstype) DECLSPEC_HIDDEN;
4495 const char *debug_ivec4(const struct wined3d_ivec4 *v) DECLSPEC_HIDDEN;
4496 const char *debug_uvec4(const struct wined3d_uvec4 *v) DECLSPEC_HIDDEN;
4497 const char *debug_shader_type(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN;
4498 const char *debug_vec4(const struct wined3d_vec4 *v) DECLSPEC_HIDDEN;
4499 const char *wined3d_debug_feature_level(enum wined3d_feature_level level) DECLSPEC_HIDDEN;
4500 void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
4502 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
4503 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
4504 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
4505 BOOL is_alpha, int stage, enum wined3d_texture_op op, uint32_t arg1, uint32_t arg2, uint32_t arg3,
4506 INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
4507 void texture_activate_dimensions(struct wined3d_texture *texture,
4508 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
4509 void sampler_texdim(struct wined3d_context *context,
4510 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4511 void tex_alphaop(struct wined3d_context *context,
4512 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4513 void apply_pixelshader(struct wined3d_context *context,
4514 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4515 void state_alpha_test(struct wined3d_context *context,
4516 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4517 void state_fogcolor(struct wined3d_context *context,
4518 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4519 void state_fogdensity(struct wined3d_context *context,
4520 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4521 void state_fogstartend(struct wined3d_context *context,
4522 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4523 void state_fog_fragpart(struct wined3d_context *context,
4524 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4525 void state_nop(struct wined3d_context *context,
4526 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4527 void state_srgbwrite(struct wined3d_context *context,
4528 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4530 void state_clipping(struct wined3d_context *context,
4531 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4532 void clipplane(struct wined3d_context *context,
4533 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4534 void state_pointsprite_w(struct wined3d_context *context,
4535 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4536 void state_pointsprite(struct wined3d_context *context,
4537 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4538 void state_shademode(struct wined3d_context *context,
4539 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
4541 /* Math utils */
4542 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
4543 const struct wined3d_matrix *src2) DECLSPEC_HIDDEN;
4545 void wined3d_release_dc(HWND window, HDC dc) DECLSPEC_HIDDEN;
4547 struct wined3d_shader_lconst
4549 struct list entry;
4550 unsigned int idx;
4551 unsigned int value[4];
4554 struct wined3d_shader_limits
4556 unsigned int sampler;
4557 unsigned int constant_int;
4558 unsigned int constant_float;
4559 unsigned int constant_bool;
4560 unsigned int packed_output;
4561 unsigned int packed_input;
4564 #define wined3d_lock_init(lock, name) wined3d_lock_init_(lock, __FILE__ ": " name)
4565 static inline void wined3d_lock_init_(CRITICAL_SECTION *lock, const char *name)
4567 InitializeCriticalSection(lock);
4568 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
4569 lock->DebugInfo->Spare[0] = (DWORD_PTR)name;
4572 static inline void wined3d_lock_cleanup(CRITICAL_SECTION *lock)
4574 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
4575 lock->DebugInfo->Spare[0] = 0;
4576 DeleteCriticalSection(lock);
4579 #ifdef __GNUC__
4580 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
4581 #else
4582 #define PRINTF_ATTR(fmt,args)
4583 #endif
4585 struct wined3d_string_buffer_list
4587 struct list list;
4590 struct wined3d_string_buffer *string_buffer_get(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4591 void string_buffer_sprintf(struct wined3d_string_buffer *buffer, const char *format, ...) PRINTF_ATTR(2, 3) DECLSPEC_HIDDEN;
4592 void string_buffer_release(struct wined3d_string_buffer_list *list, struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4593 void string_buffer_list_init(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4594 void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
4596 int shader_addline(struct wined3d_string_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
4597 BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc) DECLSPEC_HIDDEN;
4598 int shader_vaddline(struct wined3d_string_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
4600 struct wined3d_shader_phase
4602 const DWORD *start;
4603 const DWORD *end;
4604 unsigned int instance_count;
4605 unsigned int temporary_count;
4608 struct wined3d_vertex_shader
4610 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
4613 struct wined3d_hull_shader
4615 struct
4617 struct wined3d_shader_phase *control_point;
4618 unsigned int fork_count;
4619 unsigned int join_count;
4620 struct wined3d_shader_phase *fork;
4621 SIZE_T fork_size;
4622 struct wined3d_shader_phase *join;
4623 SIZE_T join_size;
4624 } phases;
4625 unsigned int output_vertex_count;
4626 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
4627 enum wined3d_tessellator_partitioning tessellator_partitioning;
4630 struct wined3d_domain_shader
4632 enum wined3d_tessellator_domain tessellator_domain;
4635 struct wined3d_geometry_shader
4637 enum wined3d_primitive_type input_type;
4638 enum wined3d_primitive_type output_type;
4639 unsigned int vertices_out;
4640 unsigned int instance_count;
4642 const struct wined3d_stream_output_desc *so_desc;
4645 struct wined3d_pixel_shader
4647 /* Pixel shader input semantics */
4648 unsigned int input_reg_map[MAX_REG_INPUT];
4649 DWORD input_reg_used; /* MAX_REG_INPUT, 32 */
4650 unsigned int declared_in_count;
4652 /* Some information about the shader behavior */
4653 BOOL color0_mov;
4654 unsigned int color0_reg;
4656 BOOL force_early_depth_stencil;
4657 enum wined3d_shader_register_type depth_output;
4658 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
4661 struct wined3d_compute_shader
4663 struct wined3d_shader_thread_group_size thread_group_size;
4666 struct wined3d_shader
4668 LONG ref;
4669 const struct wined3d_shader_limits *limits;
4670 const DWORD *function;
4671 unsigned int functionLength;
4672 void *byte_code;
4673 unsigned int byte_code_size;
4674 BOOL load_local_constsF;
4675 const struct wined3d_shader_frontend *frontend;
4676 void *frontend_data;
4677 void *backend_data;
4679 void *parent;
4680 const struct wined3d_parent_ops *parent_ops;
4682 /* Programs this shader is linked with */
4683 struct list linked_programs;
4685 /* Immediate constants (override global ones) */
4686 struct list constantsB;
4687 struct list constantsF;
4688 struct list constantsI;
4689 struct wined3d_shader_reg_maps reg_maps;
4690 BOOL lconst_inf_or_nan;
4692 struct wined3d_shader_signature input_signature;
4693 struct wined3d_shader_signature output_signature;
4694 struct wined3d_shader_signature patch_constant_signature;
4696 /* Pointer to the parent device */
4697 struct wined3d_device *device;
4698 struct list shader_list_entry;
4700 union
4702 struct wined3d_vertex_shader vs;
4703 struct wined3d_hull_shader hs;
4704 struct wined3d_domain_shader ds;
4705 struct wined3d_geometry_shader gs;
4706 struct wined3d_pixel_shader ps;
4707 struct wined3d_compute_shader cs;
4708 } u;
4711 enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps,
4712 unsigned int resource_idx, DWORD tex_types) DECLSPEC_HIDDEN;
4713 void find_ps_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4714 BOOL position_transformed, struct ps_compile_args *args,
4715 const struct wined3d_context *context) DECLSPEC_HIDDEN;
4717 bool vshader_get_input(const struct wined3d_shader *shader,
4718 uint8_t usage_req, uint8_t usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
4719 void find_vs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4720 struct vs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4722 void find_ds_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4723 struct ds_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4725 void find_gs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
4726 struct gs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
4728 void string_buffer_clear(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4729 BOOL string_buffer_init(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4730 void string_buffer_free(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
4731 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps,
4732 unsigned int max) DECLSPEC_HIDDEN;
4733 HRESULT shader_generate_code(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer,
4734 const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx,
4735 const DWORD *start, const DWORD *end) DECLSPEC_HIDDEN;
4736 BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
4738 static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
4740 switch (reg->type)
4742 case WINED3DSPR_RASTOUT:
4743 /* oFog & oPts */
4744 if (reg->idx[0].offset)
4745 return TRUE;
4746 /* oPos */
4747 return FALSE;
4749 case WINED3DSPR_CONSTBOOL: /* b# */
4750 case WINED3DSPR_DEPTHOUT: /* oDepth */
4751 case WINED3DSPR_DEPTHOUTGE:
4752 case WINED3DSPR_DEPTHOUTLE:
4753 case WINED3DSPR_LOOP: /* aL */
4754 case WINED3DSPR_OUTPOINTID:
4755 case WINED3DSPR_PREDICATE: /* p0 */
4756 case WINED3DSPR_PRIMID: /* primID */
4757 case WINED3DSPR_COVERAGE: /* vCoverage */
4758 case WINED3DSPR_SAMPLEMASK: /* oMask */
4759 return TRUE;
4761 case WINED3DSPR_MISCTYPE:
4762 switch (reg->idx[0].offset)
4764 case 0: /* vPos */
4765 return FALSE;
4766 case 1: /* vFace */
4767 return TRUE;
4768 default:
4769 return FALSE;
4772 case WINED3DSPR_IMMCONST:
4773 return reg->immconst_type == WINED3D_IMMCONST_SCALAR;
4775 default:
4776 return FALSE;
4780 static inline void shader_get_position_fixup(const struct wined3d_context *context,
4781 const struct wined3d_state *state, unsigned int fixup_count, float *position_fixup)
4783 float center_offset, x = 0.0f, y = 0.0f;
4784 unsigned int i;
4786 /* See get_projection_matrix() in utils.c for a discussion of the position fixup.
4787 * This function here also applies to d3d10+ which does not need adjustment for
4788 * integer pixel centers, but it may need the filling convention offset. */
4789 if (context->d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
4790 center_offset = 1.0f;
4791 else
4792 center_offset = 0.0f;
4794 center_offset += context->d3d_info->filling_convention_offset;
4796 for (i = 0; i < fixup_count; ++i)
4798 position_fixup[4 * i ] = 1.0f;
4799 position_fixup[4 * i + 1] = 1.0f;
4800 if (!context->d3d_info->subpixel_viewport)
4802 double dummy;
4803 x = modf(state->viewports[i].x, &dummy) * 2.0f;
4804 y = modf(state->viewports[i].y, &dummy) * 2.0f;
4806 position_fixup[4 * i + 2] = (center_offset + x) / state->viewports[i].width;
4807 position_fixup[4 * i + 3] = -(center_offset + y) / state->viewports[i].height;
4809 if (context->render_offscreen)
4811 position_fixup[4 * i + 1] *= -1.0f;
4812 position_fixup[4 * i + 3] *= -1.0f;
4817 static inline BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg)
4819 struct wined3d_shader_lconst *lconst;
4821 if (shader->load_local_constsF)
4822 return FALSE;
4824 LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
4826 if (lconst->idx == reg)
4827 return TRUE;
4830 return FALSE;
4833 void get_identity_matrix(struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4834 void get_modelview_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4835 unsigned int index, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4836 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4837 struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4838 void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4839 unsigned int tex, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
4840 void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state,
4841 float *out_min, float *out_max) DECLSPEC_HIDDEN;
4842 void get_pointsize(const struct wined3d_context *context, const struct wined3d_state *state,
4843 float *out_pointsize, float *out_att) DECLSPEC_HIDDEN;
4844 void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state,
4845 float *start, float *end) DECLSPEC_HIDDEN;
4847 /* Using additional shader constants (uniforms in GLSL / program environment
4848 * or local parameters in ARB) is costly:
4849 * ARB only knows float4 parameters and GLSL compiler are not really smart
4850 * when it comes to efficiently pack float2 uniforms, so no space is wasted
4851 * (in fact most compilers map a float2 to a full float4 uniform).
4853 * For NP2 texcoord fixup we only need 2 floats (width and height) for each
4854 * 2D texture used in the shader. We therefore pack fixup info for 2 textures
4855 * into a single shader constant (uniform / program parameter).
4857 * This structure is shared between the GLSL and the ARB backend.*/
4858 struct ps_np2fixup_info {
4859 unsigned char idx[WINED3D_MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
4860 WORD active; /* bitfield indicating if we can apply the fixup */
4861 WORD num_consts;
4864 struct wined3d_palette
4866 LONG ref;
4867 struct wined3d_device *device;
4869 unsigned int size;
4870 RGBQUAD colors[256];
4871 uint32_t flags;
4874 /* DirectDraw utility functions */
4875 extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
4877 /*****************************************************************************
4878 * Pixel format management
4881 /* Pixel format attributes */
4882 #define WINED3D_FORMAT_ATTR_FLOAT 0x00000001
4883 #define WINED3D_FORMAT_ATTR_INTEGER 0x00000002
4884 #define WINED3D_FORMAT_ATTR_NORMALISED 0x00000004
4885 #define WINED3D_FORMAT_ATTR_BUMPMAP 0x00000008
4886 #define WINED3D_FORMAT_ATTR_EXTENSION 0x00000010
4887 #define WINED3D_FORMAT_ATTR_BLOCKS 0x00000020
4888 #define WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY 0x00000040
4889 #define WINED3D_FORMAT_ATTR_COMPRESSED 0x00000080
4890 #define WINED3D_FORMAT_ATTR_BROKEN_PITCH 0x00000100
4891 #define WINED3D_FORMAT_ATTR_HEIGHT_SCALE 0x00000200
4892 #define WINED3D_FORMAT_ATTR_MAPPABLE 0x00000400
4893 #define WINED3D_FORMAT_ATTR_CAST_TO_BLOCK 0x00000800
4895 /* Pixel format capabilities */
4896 #define WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING 0x00000001
4897 #define WINED3D_FORMAT_CAP_FILTERING 0x00000002
4898 #define WINED3D_FORMAT_CAP_UNORDERED_ACCESS 0x00000004
4899 #define WINED3D_FORMAT_CAP_DEPTH_STENCIL 0x00000008
4900 #define WINED3D_FORMAT_CAP_RENDERTARGET 0x00000010
4901 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE 0x00000020
4902 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB 0x00000040
4903 #define WINED3D_FORMAT_CAP_DECOMPRESS 0x00000080
4904 #define WINED3D_FORMAT_CAP_SRGB_READ 0x00000100
4905 #define WINED3D_FORMAT_CAP_SRGB_WRITE 0x00000200
4906 #define WINED3D_FORMAT_CAP_VTF 0x00000400
4907 #define WINED3D_FORMAT_CAP_SHADOW 0x00000800
4908 #define WINED3D_FORMAT_CAP_TEXTURE 0x00001000
4909 #define WINED3D_FORMAT_CAP_GEN_MIPMAP 0x00002000
4910 #define WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE 0x00004000
4911 #define WINED3D_FORMAT_CAP_BLIT 0x00008000
4912 #define WINED3D_FORMAT_CAP_INDEX_BUFFER 0x00010000
4914 struct wined3d_rational
4916 UINT numerator;
4917 UINT denominator;
4920 struct wined3d_color_key_conversion
4922 enum wined3d_format_id dst_format;
4923 void (*convert)(const BYTE *src, unsigned int src_pitch, BYTE *dst, unsigned int dst_pitch,
4924 unsigned int width, unsigned int height, const struct wined3d_color_key *colour_key);
4927 enum wined3d_channel_type
4929 WINED3D_CHANNEL_TYPE_NONE,
4930 WINED3D_CHANNEL_TYPE_UNORM,
4931 WINED3D_CHANNEL_TYPE_SNORM,
4932 WINED3D_CHANNEL_TYPE_UINT,
4933 WINED3D_CHANNEL_TYPE_SINT,
4934 WINED3D_CHANNEL_TYPE_FLOAT,
4935 WINED3D_CHANNEL_TYPE_DEPTH,
4936 WINED3D_CHANNEL_TYPE_STENCIL,
4937 WINED3D_CHANNEL_TYPE_UNUSED,
4940 struct wined3d_format
4942 enum wined3d_format_id id;
4944 D3DDDIFORMAT ddi_format;
4945 unsigned int component_count;
4946 DWORD red_size;
4947 DWORD green_size;
4948 DWORD blue_size;
4949 DWORD alpha_size;
4950 DWORD red_offset;
4951 DWORD green_offset;
4952 DWORD blue_offset;
4953 DWORD alpha_offset;
4954 UINT byte_count;
4955 BYTE depth_size;
4956 BYTE stencil_size;
4958 UINT block_width;
4959 UINT block_height;
4960 UINT block_byte_count;
4962 enum wined3d_ffp_emit_idx emit_idx;
4964 UINT conv_byte_count;
4965 DWORD multisample_types;
4966 unsigned int attrs;
4967 unsigned int caps[WINED3D_GL_RES_TYPE_COUNT];
4968 float depth_bias_scale;
4969 struct wined3d_rational height_scale;
4970 struct color_fixup_desc color_fixup;
4971 void (*upload)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4972 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4973 unsigned int width, unsigned int height, unsigned int depth);
4974 void (*download)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4975 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4976 unsigned int width, unsigned int height, unsigned int depth);
4977 void (*decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
4978 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
4979 unsigned int width, unsigned int height, unsigned int depth);
4981 enum wined3d_format_id typeless_id;
4984 const struct wined3d_format *wined3d_get_format(const struct wined3d_adapter *adapter,
4985 enum wined3d_format_id format_id, unsigned int bind_flags) DECLSPEC_HIDDEN;
4986 enum wined3d_format_id wined3d_get_typed_format_id(const struct wined3d_adapter *adapter,
4987 const struct wined3d_format *format, enum wined3d_channel_type channel_type) DECLSPEC_HIDDEN;
4988 void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
4989 unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) DECLSPEC_HIDDEN;
4990 UINT wined3d_format_calculate_size(const struct wined3d_format *format,
4991 UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
4992 void wined3d_format_convert_from_float(const struct wined3d_format *format,
4993 const struct wined3d_color *color, void *ret) DECLSPEC_HIDDEN;
4994 void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src,
4995 unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
4996 unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d) DECLSPEC_HIDDEN;
4997 void wined3d_format_get_float_color_key(const struct wined3d_format *format,
4998 const struct wined3d_color_key *key, struct wined3d_color *float_colors) DECLSPEC_HIDDEN;
4999 BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id,
5000 enum wined3d_format_id view_format_id) DECLSPEC_HIDDEN;
5001 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
5002 const struct wined3d_texture *texture, BOOL need_alpha_ck) DECLSPEC_HIDDEN;
5003 uint32_t wined3d_format_pack(const struct wined3d_format *format, const struct wined3d_uvec4 *value) DECLSPEC_HIDDEN;
5004 BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1,
5005 enum wined3d_format_id format2) DECLSPEC_HIDDEN;
5007 struct wined3d_format_gl
5009 struct wined3d_format f;
5011 GLenum vtx_type;
5012 GLint vtx_format;
5014 GLint internal;
5015 GLint srgb_internal;
5016 GLint rt_internal;
5017 GLint format;
5018 GLint type;
5020 GLenum view_class;
5023 static inline const struct wined3d_format_gl *wined3d_format_gl(const struct wined3d_format *format)
5025 return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
5028 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
5030 static inline BOOL wined3d_format_is_typeless(const struct wined3d_format *format)
5032 return format->id == format->typeless_id && format->id != WINED3DFMT_UNKNOWN;
5035 static inline BOOL use_vs(const struct wined3d_state *state)
5037 /* Check state->vertex_declaration to allow this to be used before the
5038 * stream info is validated, for example in device_update_tex_unit_map(). */
5039 return state->shader[WINED3D_SHADER_TYPE_VERTEX]
5040 && (!state->vertex_declaration || !state->vertex_declaration->position_transformed);
5043 static inline BOOL use_ps(const struct wined3d_state *state)
5045 return !!state->shader[WINED3D_SHADER_TYPE_PIXEL];
5048 static inline BOOL use_transform_feedback(const struct wined3d_state *state)
5050 const struct wined3d_shader *shader;
5052 if (!(shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY]))
5053 return FALSE;
5054 return !!shader->u.gs.so_desc;
5057 static inline void context_apply_state(struct wined3d_context *context,
5058 const struct wined3d_state *state, DWORD state_id)
5060 const struct wined3d_state_entry *state_table = context->state_table;
5061 unsigned int rep = state_table[state_id].representative;
5062 state_table[rep].apply(context, state, rep);
5065 static inline BOOL is_srgb_enabled(const uint32_t *sampler_states)
5067 /* Only use the LSB of the WINED3D_SAMP_SRGB_TEXTURE value. This matches
5068 * the behaviour of the AMD Windows driver.
5070 * Might & Magic: Heroes VI - Shades of Darkness sets
5071 * WINED3D_SAMP_SRGB_TEXTURE to a large value that looks like a
5072 * pointer—presumably by accident—and expects sRGB decoding to be
5073 * disabled. */
5074 return sampler_states[WINED3D_SAMP_SRGB_TEXTURE] & 0x1;
5077 static inline BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context,
5078 const struct wined3d_texture *texture)
5080 if (!(context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
5081 return FALSE;
5083 if (!context->d3d_info->srgb_read_control
5084 && (texture->resource.bind_flags & WINED3D_BIND_SHADER_RESOURCE)
5085 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_READ))
5086 return TRUE;
5088 if (!context->d3d_info->srgb_write_control
5089 && (texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET)
5090 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE))
5091 return TRUE;
5093 return FALSE;
5096 static inline BOOL needs_srgb_write(const struct wined3d_d3d_info *d3d_info,
5097 const struct wined3d_state *state, const struct wined3d_fb_state *fb)
5099 return (!(d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
5100 || state->render_states[WINED3D_RS_SRGBWRITEENABLE])
5101 && fb->render_targets[0] && fb->render_targets[0]->format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE;
5104 static inline GLuint wined3d_texture_gl_get_texture_name(const struct wined3d_texture_gl *texture_gl,
5105 const struct wined3d_context *context, BOOL srgb)
5107 return srgb && needs_separate_srgb_gl_texture(context, &texture_gl->t)
5108 ? texture_gl->texture_srgb.name : texture_gl->texture_rgb.name;
5111 static inline GLuint wined3d_gl_get_internal_format(struct wined3d_resource *resource,
5112 const struct wined3d_format_gl *format_gl, bool srgb)
5114 if (srgb)
5115 return format_gl->srgb_internal;
5116 else if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET && wined3d_resource_is_offscreen(resource))
5117 return format_gl->rt_internal;
5118 else
5119 return format_gl->internal;
5122 static inline BOOL can_use_texture_swizzle(const struct wined3d_d3d_info *d3d_info, const struct wined3d_format *format)
5124 return d3d_info->texture_swizzle && !is_complex_fixup(format->color_fixup) && !is_scaling_fixup(format->color_fixup);
5127 static inline BOOL is_rasterization_disabled(const struct wined3d_shader *geometry_shader)
5129 return geometry_shader && geometry_shader->u.gs.so_desc
5130 && geometry_shader->u.gs.so_desc->rasterizer_stream_idx == WINED3D_NO_RASTERIZER_STREAM;
5133 static inline uint32_t wined3d_mask_from_size(unsigned int size)
5135 return size < 32 ? (1u << size) - 1 : ~0u;
5138 static inline DWORD wined3d_extract_bits(const uint32_t *bitstream,
5139 unsigned int offset, unsigned int count)
5141 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
5142 const unsigned int idx = offset / word_bit_count;
5143 const unsigned int shift = offset % word_bit_count;
5144 DWORD mask = (1u << count) - 1;
5145 DWORD ret;
5147 ret = (bitstream[idx] >> shift) & mask;
5148 if (shift + count > word_bit_count)
5150 const unsigned int extracted_bit_count = word_bit_count - shift;
5151 const unsigned int remaining_bit_count = count - extracted_bit_count;
5152 mask = (1u << remaining_bit_count) - 1;
5153 ret |= (bitstream[idx + 1] & mask) << extracted_bit_count;
5155 return ret;
5158 static inline void wined3d_insert_bits(uint32_t *bitstream,
5159 unsigned int offset, unsigned int count, DWORD bits)
5161 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
5162 const unsigned int idx = offset / word_bit_count;
5163 const unsigned int shift = offset % word_bit_count;
5164 DWORD mask = (1u << count) - 1;
5166 bitstream[idx] |= (bits & mask) << shift;
5167 if (shift + count > word_bit_count)
5169 const unsigned int inserted_bit_count = word_bit_count - shift;
5170 const unsigned int remaining_bit_count = count - inserted_bit_count;
5171 mask = (1u << remaining_bit_count) - 1;
5172 bitstream[idx + 1] |= (bits >> inserted_bit_count) & mask;
5176 static inline void wined3d_from_cs(const struct wined3d_cs *cs)
5178 if (cs->thread)
5179 assert(cs->thread_id == GetCurrentThreadId());
5182 static inline void wined3d_not_from_cs(const struct wined3d_cs *cs)
5184 assert(cs->thread_id != GetCurrentThreadId());
5187 static inline enum wined3d_material_color_source validate_material_colour_source(WORD use_map,
5188 enum wined3d_material_color_source source)
5190 if (source == WINED3D_MCS_COLOR1 && use_map & (1u << WINED3D_FFP_DIFFUSE))
5191 return source;
5192 if (source == WINED3D_MCS_COLOR2 && use_map & (1u << WINED3D_FFP_SPECULAR))
5193 return source;
5194 return WINED3D_MCS_MATERIAL;
5197 static inline void wined3d_get_material_colour_source(enum wined3d_material_color_source *diffuse,
5198 enum wined3d_material_color_source *emissive, enum wined3d_material_color_source *ambient,
5199 enum wined3d_material_color_source *specular, const struct wined3d_state *state,
5200 const struct wined3d_stream_info *si)
5202 if (!state->render_states[WINED3D_RS_LIGHTING])
5204 *diffuse = WINED3D_MCS_COLOR1;
5205 *specular = WINED3D_MCS_COLOR2;
5206 *emissive = *ambient = WINED3D_MCS_MATERIAL;
5208 return;
5211 if (!state->render_states[WINED3D_RS_COLORVERTEX])
5213 *diffuse = *emissive = *ambient = *specular = WINED3D_MCS_MATERIAL;
5215 return;
5218 *diffuse = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE]);
5219 *emissive = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE]);
5220 *ambient = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE]);
5221 *specular = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
5224 static inline void wined3d_vec4_transform(struct wined3d_vec4 *dst,
5225 const struct wined3d_vec4 *v, const struct wined3d_matrix *m)
5227 struct wined3d_vec4 tmp;
5229 tmp.x = v->x * m->_11 + v->y * m->_21 + v->z * m->_31 + v->w * m->_41;
5230 tmp.y = v->x * m->_12 + v->y * m->_22 + v->z * m->_32 + v->w * m->_42;
5231 tmp.z = v->x * m->_13 + v->y * m->_23 + v->z * m->_33 + v->w * m->_43;
5232 tmp.w = v->x * m->_14 + v->y * m->_24 + v->z * m->_34 + v->w * m->_44;
5234 *dst = tmp;
5237 BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m) DECLSPEC_HIDDEN;
5239 void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting,
5240 const struct wined3d_matrix *modelview) DECLSPEC_HIDDEN;
5242 static inline struct wined3d_context *context_acquire(struct wined3d_device *device,
5243 struct wined3d_texture *texture, unsigned int sub_resource_idx)
5245 wined3d_from_cs(device->cs);
5247 return device->adapter->adapter_ops->adapter_acquire_context(device, texture, sub_resource_idx);
5250 static inline void context_release(struct wined3d_context *context)
5252 context->device->adapter->adapter_ops->adapter_release_context(context);
5255 static inline float wined3d_get_float_state(const struct wined3d_state *state, enum wined3d_render_state rs)
5257 union
5259 DWORD d;
5260 float f;
5262 tmpvalue;
5264 tmpvalue.d = state->render_states[rs];
5265 return tmpvalue.f;
5268 static inline void *wined3d_context_map_bo_address(struct wined3d_context *context,
5269 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
5271 return context->device->adapter->adapter_ops->adapter_map_bo_address(context, data, size, map_flags);
5274 static inline void wined3d_context_unmap_bo_address(struct wined3d_context *context,
5275 const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
5277 context->device->adapter->adapter_ops->adapter_unmap_bo_address(context, data, range_count, ranges);
5280 static inline void wined3d_context_copy_bo_address(struct wined3d_context *context,
5281 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
5282 unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags)
5284 context->device->adapter->adapter_ops->adapter_copy_bo_address(context, dst, src, range_count, ranges, map_flags);
5287 static inline void wined3d_context_flush_bo_address(struct wined3d_context *context,
5288 const struct wined3d_const_bo_address *data, size_t size)
5290 context->device->adapter->adapter_ops->adapter_flush_bo_address(context, data, size);
5293 static inline void wined3d_context_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)
5295 context->device->adapter->adapter_ops->adapter_destroy_bo(context, bo);
5298 static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_view *dsv,
5299 const struct wined3d_format *srv_format)
5301 return !srv_format || (srv_format->red_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_DEPTH))
5302 || (srv_format->green_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_STENCIL));
5305 static inline unsigned int wined3d_bind_layer_count(const struct wined3d_texture *texture)
5307 return texture->resource.type == WINED3D_RTYPE_TEXTURE_3D ? texture->resource.depth : texture->layer_count;
5310 static inline bool wined3d_srv_all_subresources(const struct wined3d_shader_resource_view *srv)
5312 struct wined3d_texture *texture;
5314 if (srv->resource->type == WINED3D_RTYPE_BUFFER)
5315 return TRUE;
5317 if (srv->desc.u.texture.layer_idx || srv->desc.u.texture.level_idx)
5318 return FALSE;
5320 texture = texture_from_resource(srv->resource);
5321 return srv->desc.u.texture.level_count == texture->level_count
5322 && srv->desc.u.texture.layer_count == wined3d_bind_layer_count(texture);
5325 static inline bool wined3d_rtv_all_subresources(const struct wined3d_rendertarget_view *rtv)
5327 struct wined3d_texture *texture;
5329 if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
5330 return TRUE;
5332 if (rtv->sub_resource_idx)
5333 return FALSE;
5335 texture = texture_from_resource(rtv->resource);
5336 return texture->level_count == 1 && rtv->layer_count == wined3d_bind_layer_count(texture);
5339 static inline void wined3d_srv_bind_count_inc(struct wined3d_shader_resource_view *srv)
5341 InterlockedIncrement(&srv->resource->srv_bind_count_device);
5344 static inline void wined3d_srv_bind_count_dec(struct wined3d_shader_resource_view *srv)
5346 InterlockedDecrement(&srv->resource->srv_bind_count_device);
5349 static inline void wined3d_rtv_bind_count_inc(struct wined3d_rendertarget_view *rtv)
5351 InterlockedIncrement(&rtv->resource->rtv_bind_count_device);
5354 static inline void wined3d_rtv_bind_count_dec(struct wined3d_rendertarget_view *rtv)
5356 InterlockedDecrement(&rtv->resource->rtv_bind_count_device);
5359 static inline bool wined3d_rtv_overlaps_srv(const struct wined3d_rendertarget_view *rtv,
5360 const struct wined3d_shader_resource_view *srv)
5362 if (rtv->resource != srv->resource)
5363 return false;
5365 if (wined3d_srv_all_subresources(srv) || wined3d_rtv_all_subresources(rtv))
5366 return true;
5368 return rtv->sub_resource_idx >= srv->desc.u.texture.level_idx
5369 && rtv->sub_resource_idx < srv->desc.u.texture.level_idx + srv->desc.u.texture.level_count
5370 && rtv->layer_count >= srv->desc.u.texture.layer_idx;
5373 static inline bool wined3d_is_srv_rtv_bound(const struct wined3d_state *state,
5374 const struct wined3d_shader_resource_view *srv)
5376 unsigned int i;
5378 if (!srv->resource->rtv_bind_count_device)
5379 return false;
5381 for (i = 0; i < ARRAY_SIZE(state->fb.render_targets); ++i)
5383 const struct wined3d_rendertarget_view *rtv;
5385 if ((rtv = state->fb.render_targets[i]) && wined3d_rtv_overlaps_srv(rtv, srv))
5386 return true;
5389 return false;
5392 static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)
5394 *min_z = vp->min_z;
5396 /* The magic constant is derived from tests. */
5397 *max_z = max(vp->max_z, vp->min_z + 0.001f);
5400 static inline BOOL wined3d_bitmap_clear(uint32_t *map, unsigned int idx)
5402 return map[idx >> 5] &= ~(1u << (idx & 0x1f));
5405 static inline BOOL wined3d_bitmap_set(uint32_t *map, unsigned int idx)
5407 return map[idx >> 5] |= (1u << (idx & 0x1f));
5410 static inline BOOL wined3d_bitmap_is_set(const uint32_t *map, unsigned int idx)
5412 return map[idx >> 5] & (1u << (idx & 0x1f));
5415 static inline unsigned int wined3d_bitmap_ffs_xor(const uint32_t *bitmap, unsigned int bit_count,
5416 unsigned int start, uint32_t xor_mask)
5418 const unsigned int word_bit_count = sizeof(*bitmap) * CHAR_BIT;
5419 const uint32_t *ptr, *end_ptr;
5420 uint32_t map, mask;
5422 assert(bit_count < word_bit_count || !(bit_count % word_bit_count));
5424 ptr = bitmap + start / word_bit_count;
5425 end_ptr = bitmap + (bit_count + word_bit_count - 1) / word_bit_count;
5427 if (ptr >= end_ptr)
5428 return ~0u;
5430 mask = ~0u << start % word_bit_count;
5431 map = (*ptr ^ xor_mask) & mask;
5432 while (!map)
5434 if (++ptr == end_ptr)
5435 return ~0u;
5436 map = *ptr ^ xor_mask;
5438 return (ptr - bitmap) * word_bit_count + wined3d_bit_scan(&map);
5441 static inline unsigned int wined3d_bitmap_ffs(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
5443 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, 0);
5446 static inline unsigned int wined3d_bitmap_ffz(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
5448 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, ~0u);
5451 static inline BOOL wined3d_bitmap_get_range(const uint32_t *bitmap, unsigned int bit_count,
5452 unsigned int start, struct wined3d_range *range)
5454 unsigned int range_start, range_end;
5456 range_start = wined3d_bitmap_ffs(bitmap, bit_count, start);
5457 if (range_start == ~0u)
5458 return FALSE;
5460 range_end = wined3d_bitmap_ffz(bitmap, bit_count, range_start + 1);
5461 if (range_end == ~0u)
5462 range_end = bit_count;
5464 range->offset = range_start;
5465 range->size = range_end - range_start;
5466 return TRUE;
5469 static inline bool wined3d_context_is_graphics_state_dirty(const struct wined3d_context *context, unsigned int state_id)
5471 return wined3d_bitmap_is_set(context->dirty_graphics_states, state_id);
5474 static inline bool wined3d_context_is_compute_state_dirty(const struct wined3d_context *context, unsigned int state_id)
5476 return wined3d_bitmap_is_set(context->dirty_compute_states, state_id - STATE_COMPUTE_OFFSET);
5479 static inline bool isStateDirty(const struct wined3d_context *context, unsigned int state_id)
5481 return wined3d_context_is_graphics_state_dirty(context, state_id);
5484 static inline bool wined3d_primitive_type_is_list(enum wined3d_primitive_type t)
5486 return t == WINED3D_PT_POINTLIST
5487 || t == WINED3D_PT_LINELIST
5488 || t == WINED3D_PT_TRIANGLELIST
5489 || t == WINED3D_PT_LINELIST_ADJ
5490 || t == WINED3D_PT_TRIANGLELIST_ADJ
5491 || t == WINED3D_PT_PATCH;
5494 static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo_gl)
5496 struct wined3d_device_gl *device_gl = wined3d_device_gl(context_gl->c.device);
5498 bo_gl->command_fence_id = device_gl->current_fence_id;
5501 static inline void wined3d_context_gl_reference_buffer(struct wined3d_context_gl *context_gl,
5502 struct wined3d_buffer *buffer)
5504 if (buffer->buffer_object)
5505 wined3d_context_gl_reference_bo(context_gl, wined3d_bo_gl(buffer->buffer_object));
5508 static inline bool wined3d_map_persistent(void)
5510 return sizeof(void *) >= sizeof(uint64_t);
5513 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
5514 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
5516 extern CRITICAL_SECTION wined3d_command_cs;
5518 #endif