ReactOS  0.4.14-dev-49-gfb4591c
wined3d_private.h
Go to the documentation of this file.
1 /*
2  * Direct3D wine internal private include file
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 #ifndef __WINE_WINED3D_PRIVATE_H
26 #define __WINE_WINED3D_PRIVATE_H
27 
28 #ifdef USE_WIN32_OPENGL
29 #define WINE_GLAPI __stdcall
30 #else
31 #define WINE_GLAPI
32 #endif
33 
34 #include <assert.h>
35 #include <stdarg.h>
36 #include <math.h>
37 #include <limits.h>
38 #include "ntstatus.h"
39 #define WIN32_NO_STATUS
40 #define NONAMELESSUNION
41 #define NONAMELESSSTRUCT
42 #define COBJMACROS
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winreg.h"
46 #include "wingdi.h"
47 #include "winuser.h"
48 #include "winternl.h"
49 #include "ddk/d3dkmthk.h"
50 #include "wine/debug.h"
51 #include "wine/heap.h"
52 #include "wine/unicode.h"
53 
54 #include "objbase.h"
55 #include "wine/wined3d.h"
56 #include "wined3d_gl.h"
57 #include "wine/list.h"
58 #include "wine/rbtree.h"
59 #include "wine/wgl_driver.h"
60 
61 #ifndef ARRAY_SIZE
62 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
63 #endif
64 
65 #define MAKEDWORD_VERSION(maj, min) (((maj & 0xffffu) << 16) | (min & 0xffffu))
66 
67 /* Driver quirks */
68 #define WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT 0x00000001
69 #define WINED3D_QUIRK_SET_TEXCOORD_W 0x00000002
70 #define WINED3D_QUIRK_GLSL_CLIP_VARYING 0x00000004
71 #define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA 0x00000008
72 #define WINED3D_QUIRK_NV_CLIP_BROKEN 0x00000010
73 #define WINED3D_QUIRK_FBO_TEX_UPDATE 0x00000020
74 #define WINED3D_QUIRK_BROKEN_RGBA16 0x00000040
75 #define WINED3D_QUIRK_INFO_LOG_SPAM 0x00000080
76 #define WINED3D_QUIRK_LIMITED_TEX_FILTERING 0x00000100
77 #define WINED3D_QUIRK_BROKEN_ARB_FOG 0x00000200
78 
80 {
97 };
98 
100 {
120 };
121 
122 /* Texture format fixups */
123 
125 {
134 };
135 
137 {
144 };
145 
146 #include <pshpack2.h>
148 {
149  unsigned short x_sign_fixup : 1;
150  unsigned short x_source : 3;
151  unsigned short y_sign_fixup : 1;
152  unsigned short y_source : 3;
153  unsigned short z_sign_fixup : 1;
154  unsigned short z_source : 3;
155  unsigned short w_sign_fixup : 1;
156  unsigned short w_source : 3;
157 };
158 #include <poppack.h>
159 
161 {
165  unsigned int varying_count;
166  unsigned int ffp_textures;
167  unsigned int ffp_blend_stages;
169  unsigned int active_light_count;
170 };
171 
172 typedef void (WINE_GLAPI *wined3d_ffp_attrib_func)(const void *data);
175 extern wined3d_ffp_attrib_func specular_func_3ubv DECLSPEC_HIDDEN;
176 
178 {
185 };
186 
188 {
189  struct wined3d_d3d_limits limits;
190  struct wined3d_ffp_attrib_ops ffp_attrib_ops;
200 };
201 
204 
206  int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
207  int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
208 {
209  struct color_fixup_desc fixup =
210  {
211  sign0, src0,
212  sign1, src1,
213  sign2, src2,
214  sign3, src3,
215  };
216  return fixup;
217 }
218 
220 {
221  struct color_fixup_desc fixup =
222  {
227  };
228  return fixup;
229 }
230 
231 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
232 {
233  return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
234 }
235 
236 static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
237 {
239 }
240 
241 static inline BOOL is_scaling_fixup(struct color_fixup_desc fixup)
242 {
243  return fixup.x_sign_fixup || fixup.y_sign_fixup || fixup.z_sign_fixup || fixup.w_sign_fixup;
244 }
245 
247 {
248  return f1.x_sign_fixup == f2.x_sign_fixup && f1.x_source == f2.x_source
249  && f1.y_sign_fixup == f2.y_sign_fixup && f1.y_source == f2.y_source
250  && f1.z_sign_fixup == f2.z_sign_fixup && f1.z_source == f2.z_source
251  && f1.w_sign_fixup == f2.w_sign_fixup && f1.w_source == f2.w_source;
252 }
253 
254 static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
255 {
256  enum complex_fixup complex_fixup = 0;
257  if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 0);
258  if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 1);
259  if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 2);
260  if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 3);
261  return complex_fixup;
262 }
263 
264 /* Device caps */
265 #define MAX_STREAMS 16
266 #define MAX_TEXTURES 8
267 #define MAX_FRAGMENT_SAMPLERS 16
268 #define MAX_VERTEX_SAMPLERS 4
269 #define MAX_COMBINED_SAMPLERS (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
270 #define MAX_ACTIVE_LIGHTS 8
271 #define MAX_CLIP_DISTANCES 8
272 #define MAX_CONSTANT_BUFFERS 15
273 #define MAX_SAMPLER_OBJECTS 16
274 #define MAX_SHADER_RESOURCE_VIEWS 128
275 #define MAX_RENDER_TARGET_VIEWS 8
276 #define MAX_UNORDERED_ACCESS_VIEWS 8
277 #define MAX_TGSM_REGISTERS 8192
278 #define MAX_VERTEX_BLENDS 4
279 #define MAX_VERTEX_INDEX_BLENDS 9
280 #define MAX_MULTISAMPLE_TYPES 8
281 #define MAX_RENDER_TARGETS 8
282 
284 {
286 };
287 
290 
292 
294 {
296  return WINED3D_CMP_ALWAYS;
297  return func;
298 }
299 
301 {
302  return magLookup[mag_filter];
303 }
304 
306  enum wined3d_texture_filter_type mip_filter)
307 {
308  return minMipLookup[min_filter].mip[mip_filter];
309 }
310 
311 /* float_16_to_32() and float_32_to_16() (see implementation in
312  * surface_base.c) convert 16 bit floats in the FLOAT16 data type
313  * to standard C floats and vice versa. They do not depend on the encoding
314  * of the C float, so they are platform independent, but slow. On x86 and
315  * other IEEE 754 compliant platforms the conversion can be accelerated by
316  * bit shifting the exponent and mantissa. There are also some SSE-based
317  * assembly routines out there.
318  *
319  * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
320  */
321 static inline float float_16_to_32(const unsigned short *in)
322 {
323  const unsigned short s = ((*in) & 0x8000u);
324  const unsigned short e = ((*in) & 0x7c00u) >> 10;
325  const unsigned short m = (*in) & 0x3ffu;
326  const float sgn = (s ? -1.0f : 1.0f);
327 
328  if(e == 0) {
329  if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
330  else return sgn * powf(2, -14.0f) * ((float)m / 1024.0f);
331  } else if(e < 31) {
332  return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
333  } else {
334  if(m == 0) return sgn * INFINITY;
335  else return NAN;
336  }
337 }
338 
339 static inline float float_24_to_32(DWORD in)
340 {
341  const float sgn = in & 0x800000u ? -1.0f : 1.0f;
342  const unsigned short e = (in & 0x780000u) >> 19;
343  const unsigned int m = in & 0x7ffffu;
344 
345  if (e == 0)
346  {
347  if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
348  else return sgn * powf(2, -6.0f) * ((float)m / 524288.0f);
349  }
350  else if (e < 15)
351  {
352  return sgn * powf(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
353  }
354  else
355  {
356  if (m == 0) return sgn * INFINITY;
357  else return NAN;
358  }
359 }
360 
361 static inline unsigned int wined3d_popcount(unsigned int x)
362 {
363 #ifdef HAVE___BUILTIN_POPCOUNT
364  return __builtin_popcount(x);
365 #else
366  x -= x >> 1 & 0x55555555;
367  x = (x & 0x33333333) + (x >> 2 & 0x33333333);
368  return ((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
369 #endif
370 }
371 
372 static inline void wined3d_pause(void)
373 {
374 #ifdef __REACTOS__
375  Sleep(0);
376 #else
377 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
378  __asm__ __volatile__( "rep;nop" : : : "memory" );
379 #endif
380 #endif
381 }
382 
383 #define ORM_BACKBUFFER 0
384 #define ORM_FBO 1
385 
386 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
387 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
388 
389 /* NOTE: When adding fields to this structure, make sure to update the default
390  * values in wined3d_main.c as well. */
392 {
393  unsigned int cs_multithreaded;
398  unsigned short pci_vendor_id;
399  unsigned short pci_device_id;
400  /* Memory tracking and object counting. */
402  char *logo;
403  unsigned int multisample_textures;
404  unsigned int sample_count;
407  unsigned int max_sm_vs;
408  unsigned int max_sm_hs;
409  unsigned int max_sm_ds;
410  unsigned int max_sm_gs;
411  unsigned int max_sm_ps;
412  unsigned int max_sm_cs;
414 };
415 
417 
419 {
431 };
432 
433 #define WINED3D_SHADER_CONST_VS_F 0x00000001
434 #define WINED3D_SHADER_CONST_VS_I 0x00000002
435 #define WINED3D_SHADER_CONST_VS_B 0x00000004
436 #define WINED3D_SHADER_CONST_VS_CLIP_PLANES 0x00000008
437 #define WINED3D_SHADER_CONST_VS_POINTSIZE 0x00000010
438 #define WINED3D_SHADER_CONST_POS_FIXUP 0x00000020
439 #define WINED3D_SHADER_CONST_PS_F 0x00000040
440 #define WINED3D_SHADER_CONST_PS_I 0x00000080
441 #define WINED3D_SHADER_CONST_PS_B 0x00000100
442 #define WINED3D_SHADER_CONST_PS_BUMP_ENV 0x00000200
443 #define WINED3D_SHADER_CONST_PS_FOG 0x00000400
444 #define WINED3D_SHADER_CONST_PS_ALPHA_TEST 0x00000800
445 #define WINED3D_SHADER_CONST_PS_Y_CORR 0x00001000
446 #define WINED3D_SHADER_CONST_PS_NP2_FIXUP 0x00002000
447 #define WINED3D_SHADER_CONST_FFP_MODELVIEW 0x00004000
448 #define WINED3D_SHADER_CONST_FFP_PROJ 0x00010000
449 #define WINED3D_SHADER_CONST_FFP_TEXMATRIX 0x00020000
450 #define WINED3D_SHADER_CONST_FFP_MATERIAL 0x00040000
451 #define WINED3D_SHADER_CONST_FFP_LIGHTS 0x00080000
452 #define WINED3D_SHADER_CONST_FFP_PS 0x00100000
453 #define WINED3D_SHADER_CONST_FFP_COLOR_KEY 0x00200000
454 #define WINED3D_SHADER_CONST_FFP_VERTEXBLEND 0xff000000
455 #define WINED3D_SHADER_CONST_FFP_VERTEXBLEND_INDEX(i) (0x01000000 << ((i) - 1))
456 
458 {
509 };
510 
512 {
522 };
523 
525 {
528 };
529 
530 #define WINED3DSP_NOSWIZZLE (0u | (1u << 2) | (2u << 4) | (3u << 6))
531 
533 {
548 };
549 
550 #define WINED3DSP_WRITEMASK_0 0x1u /* .x r */
551 #define WINED3DSP_WRITEMASK_1 0x2u /* .y g */
552 #define WINED3DSP_WRITEMASK_2 0x4u /* .z b */
553 #define WINED3DSP_WRITEMASK_3 0x8u /* .w a */
554 #define WINED3DSP_WRITEMASK_ALL 0xfu /* all */
555 
557 {
562 };
563 
565 {
574 };
575 
576 #define WINED3D_PACKED_INTERPOLATION_SIZE 3
577 #define WINED3D_PACKED_INTERPOLATION_BIT_COUNT 3
578 
580 {
584 };
585 
587 {
590 };
591 
593 {
596 };
597 
599 {
603 };
604 
606 {
611 };
612 
614 {
619 };
620 
621 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
622 #define WINED3DSI_TEXLD_PROJECT 0x1
623 #define WINED3DSI_TEXLD_BIAS 0x2
624 #define WINED3DSI_INDEXED_DYNAMIC 0x4
625 #define WINED3DSI_RESINFO_RCP_FLOAT 0x1
626 #define WINED3DSI_RESINFO_UINT 0x2
627 #define WINED3DSI_SAMPLE_INFO_UINT 0x1
628 #define WINED3DSI_SAMPLER_COMPARISON_MODE 0x1
629 
631 {
638 };
639 
641 {
644 };
645 
646 #define WINED3D_SM1_VS 0xfffeu
647 #define WINED3D_SM1_PS 0xffffu
648 #define WINED3D_SM4_PS 0x0000u
649 #define WINED3D_SM4_VS 0x0001u
650 #define WINED3D_SM4_GS 0x0002u
651 #define WINED3D_SM5_HS 0x0003u
652 #define WINED3D_SM5_DS 0x0004u
653 #define WINED3D_SM5_CS 0x0005u
654 
655 /* Shader version tokens, and shader end tokens */
656 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
657 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
658 
659 /* Shader backends */
660 
661 /* TODO: Make this dynamic, based on shader limits ? */
662 #define MAX_ATTRIBS 16
663 #define MAX_REG_ADDR 1
664 #define MAX_REG_TEXCRD 8
665 #define MAX_REG_INPUT 32
666 #define MAX_REG_OUTPUT 32
667 #define WINED3D_MAX_CBS 15
668 #define WINED3D_MAX_CONSTS_B 16
669 #define WINED3D_MAX_CONSTS_I 16
670 #define WINED3D_MAX_VS_CONSTS_F 256
671 #define WINED3D_MAX_PS_CONSTS_F 224
672 
673 /* FIXME: This needs to go up to 2048 for
674  * Shader model 3 according to msdn (and for software shaders) */
675 #define MAX_LABELS 16
676 
677 #define MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE 4096
678 
680 {
681  struct list entry;
682  char *buffer;
683  unsigned int buffer_size;
684  unsigned int content_size;
685 };
686 
688 {
928 };
929 
931 {
938 
941 };
942 
944 {
948 };
949 
951 {
953  enum wined3d_data_type data_type;
954  unsigned int flags;
955  unsigned int stride;
956 };
957 
958 #define WINED3D_SAMPLER_DEFAULT ~0x0u
959 
961 {
962  unsigned int resource_idx;
963  unsigned int sampler_idx;
964  unsigned int bind_idx;
965 };
966 
968 {
970  size_t size;
971  size_t count;
972 };
973 
975 {
976  unsigned int vec4_count;
978 };
979 
981 {
982  struct list entry;
983  unsigned int register_idx;
984  unsigned int register_size;
985  unsigned int component_count;
986 };
987 
988 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
989 
991 {
992  struct wined3d_shader_version shader_version;
993  BYTE texcoord; /* MAX_REG_TEXCRD, 8 */
994  BYTE address; /* MAX_REG_ADDR, 1 */
995  WORD labels; /* MAX_LABELS, 16 */
996  DWORD temporary; /* 32 */
997  unsigned int temporary_count;
998  DWORD *constf; /* pixel, vertex */
999  struct list indexable_temps;
1001  union
1002  {
1003  DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
1004  BYTE output_registers_mask[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1005  } u;
1006  DWORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 32 */
1007  DWORD output_registers; /* MAX_REG_OUTPUT, 32 */
1008  WORD integer_constants; /* WINED3D_MAX_CONSTS_I, 16 */
1009  WORD boolean_constants; /* WINED3D_MAX_CONSTS_B, 16 */
1010  WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */
1011  WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */
1013 
1015  struct wined3d_shader_sampler_map sampler_map;
1017  BYTE bumpmat; /* MAX_TEXTURES, 8 */
1018  BYTE luminanceparams; /* MAX_TEXTURES, 8 */
1020  DWORD uav_read_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1021  DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1022 
1023  DWORD clip_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */
1024  DWORD cull_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */
1033  DWORD fog : 1;
1042 
1043  DWORD rt_mask; /* Used render targets, 32 max. */
1044 
1045  /* Whether or not loops are used in this shader, and nesting depth */
1046  unsigned int loop_depth;
1047  unsigned int min_rel_offset, max_rel_offset;
1048 
1051  unsigned int tgsm_count;
1052 };
1053 
1054 /* Keeps track of details for TEX_M#x# instructions which need to maintain
1055  * state information between multiple instructions. */
1057 {
1058  unsigned int current_row;
1059  DWORD texcoord_w[2];
1060 };
1061 
1063 {
1064  unsigned int current_loop_depth;
1065  unsigned int current_loop_reg;
1067 };
1068 
1070 {
1071  const struct wined3d_shader *shader;
1072  const struct wined3d_gl_info *gl_info;
1078 };
1079 
1081 {
1083  unsigned int offset;
1084 };
1085 
1087 {
1089  enum wined3d_data_type data_type;
1091  enum wined3d_immconst_type immconst_type;
1092  union
1093  {
1094  DWORD immconst_data[4];
1095  unsigned fp_body_idx;
1096  } u;
1097 };
1098 
1100 {
1105 };
1106 
1108 {
1112 };
1113 
1115 {
1116  struct wined3d_shader_dst_param first_register;
1117  unsigned int last_register;
1118 };
1119 
1121 {
1124  enum wined3d_shader_resource_type resource_type;
1125  enum wined3d_data_type resource_data_type;
1127 };
1128 
1130 {
1153 };
1154 
1156 {
1159 };
1160 
1162 {
1164  unsigned int byte_stride;
1165 };
1166 
1168 {
1169  unsigned int size;
1170  unsigned int stride;
1171 };
1172 
1174 {
1176  unsigned int byte_count;
1177 };
1178 
1180 {
1182  unsigned int byte_stride;
1183  unsigned int structure_count;
1184 };
1185 
1187 {
1188  unsigned int x, y, z;
1189 };
1190 
1192 {
1193  unsigned int index;
1194  unsigned int array_size;
1195  unsigned int body_count;
1196  unsigned int table_count;
1197 };
1198 
1200 {
1201  signed char u, v, w;
1202 };
1203 
1205 {
1207  unsigned int patch_vertex_count;
1208 };
1209 
1211 {
1215  unsigned int dst_count;
1216  unsigned int src_count;
1219  struct wined3d_shader_texel_offset texel_offset;
1222  union
1223  {
1224  struct wined3d_shader_semantic semantic;
1225  struct wined3d_shader_register_semantic register_semantic;
1226  struct wined3d_shader_primitive_type primitive_type;
1229  unsigned int count;
1230  unsigned int index;
1232  struct wined3d_shader_structured_resource structured_resource;
1233  struct wined3d_shader_tgsm_raw tgsm_raw;
1234  struct wined3d_shader_tgsm_structured tgsm_structured;
1235  struct wined3d_shader_thread_group_size thread_group_size;
1236  enum wined3d_tessellator_domain tessellator_domain;
1237  enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1238  enum wined3d_tessellator_partitioning tessellator_partitioning;
1240  struct wined3d_shader_index_range index_range;
1241  struct wined3d_shader_indexable_temp indexable_temp;
1243  } declaration;
1244 };
1245 
1247 {
1248  return ins->texel_offset.u || ins->texel_offset.v || ins->texel_offset.w;
1249 }
1250 
1252 {
1255 };
1256 
1258 {
1259  unsigned int count;
1260  unsigned int start;
1261  int step;
1262 };
1263 
1265 {
1266  void *(*shader_init)(const DWORD *byte_code, size_t byte_code_size,
1267  const struct wined3d_shader_signature *output_signature);
1268  void (*shader_free)(void *data);
1269  void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
1270  void (*shader_read_instruction)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins);
1271  BOOL (*shader_is_end)(void *data, const DWORD **ptr);
1272 };
1273 
1276 
1278 
1279 #define WINED3D_SHADER_CAP_VS_CLIPPING 0x00000001
1280 #define WINED3D_SHADER_CAP_SRGB_WRITE 0x00000002
1281 #define WINED3D_SHADER_CAP_DOUBLE_PRECISION 0x00000004
1282 
1284 {
1285  unsigned int vs_version;
1286  unsigned int hs_version;
1287  unsigned int ds_version;
1288  unsigned int gs_version;
1289  unsigned int ps_version;
1290  unsigned int cs_version;
1291 
1296 
1298 };
1299 
1301 {
1310 };
1311 
1316 };
1317 
1318 #define WINED3D_CONST_NUM_UNUSED ~0U
1319 
1321 {
1326 };
1327 
1328 /* Stateblock dependent parameters which have to be hardcoded
1329  * into the shader code
1330  */
1331 
1332 #define WINED3D_PSARGS_PROJECTED (1u << 3)
1333 #define WINED3D_PSARGS_TEXTRANSFORM_SHIFT 4
1334 #define WINED3D_PSARGS_TEXTRANSFORM_MASK 0xfu
1335 #define WINED3D_PSARGS_TEXTYPE_SHIFT 2
1336 #define WINED3D_PSARGS_TEXTYPE_MASK 0x3u
1337 
1338 /* Used for Shader Model 1 pixel shaders to track the bound texture
1339  * type. 2D and RECT textures are separated through NP2 fixup. */
1341 {
1345 };
1346 
1348 {
1352  WORD tex_transform; /* ps 1.0-1.3, 4 textures */
1353  WORD tex_types; /* ps 1.0 - 1.4, 6 textures */
1355  /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
1356  D3D9 has a limit of 16 samplers and the fixup is superfluous
1357  in D3D10 (unconditional NP2 support mandatory). */
1359  WORD shadow; /* MAX_FRAGMENT_SAMPLERS, 16 */
1360  WORD texcoords_initialized; /* MAX_TEXTURES, 8 */
1367 };
1368 
1370 {
1373 };
1374 
1376 {
1384  WORD swizzle_map; /* MAX_ATTRIBS, 16 */
1387 };
1388 
1390 {
1391  enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1392  enum wined3d_tessellator_partitioning tessellator_partitioning;
1393  unsigned int output_count : 16;
1394  unsigned int next_shader_type : 3;
1395  unsigned int render_offscreen : 1;
1396  unsigned int padding : 12;
1398 };
1399 
1401 {
1402  unsigned int output_count;
1404 };
1405 
1406 struct wined3d_context;
1407 struct wined3d_state;
1408 struct fragment_pipeline;
1410 
1412 {
1413  void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
1414  void (*shader_precompile)(void *shader_priv, struct wined3d_shader *shader);
1415  void (*shader_select)(void *shader_priv, struct wined3d_context *context,
1416  const struct wined3d_state *state);
1417  void (*shader_select_compute)(void *shader_priv, struct wined3d_context *context,
1418  const struct wined3d_state *state);
1419  void (*shader_disable)(void *shader_priv, struct wined3d_context *context);
1420  void (*shader_update_float_vertex_constants)(struct wined3d_device *device, UINT start, UINT count);
1421  void (*shader_update_float_pixel_constants)(struct wined3d_device *device, UINT start, UINT count);
1422  void (*shader_load_constants)(void *shader_priv, struct wined3d_context *context,
1423  const struct wined3d_state *state);
1424  void (*shader_destroy)(struct wined3d_shader *shader);
1425  HRESULT (*shader_alloc_private)(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
1426  const struct fragment_pipeline *fragment_pipe);
1427  void (*shader_free_private)(struct wined3d_device *device);
1428  BOOL (*shader_allocate_context_data)(struct wined3d_context *context);
1429  void (*shader_free_context_data)(struct wined3d_context *context);
1430  void (*shader_init_context_state)(struct wined3d_context *context);
1431  void (*shader_get_caps)(const struct wined3d_gl_info *gl_info, struct shader_caps *caps);
1432  BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
1433  BOOL (*shader_has_ffp_proj_control)(void *shader_priv);
1434 };
1435 
1439 
1440 #define GL_EXTCALL(f) (gl_info->gl_ops.ext.p_##f)
1441 
1442 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xff)
1443 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xff)
1444 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xff)
1445 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xff)
1446 
1447 static inline void wined3d_color_from_d3dcolor(struct wined3d_color *wined3d_color, DWORD d3d_color)
1448 {
1449  wined3d_color->r = D3DCOLOR_B_R(d3d_color) / 255.0f;
1450  wined3d_color->g = D3DCOLOR_B_G(d3d_color) / 255.0f;
1451  wined3d_color->b = D3DCOLOR_B_B(d3d_color) / 255.0f;
1452  wined3d_color->a = D3DCOLOR_B_A(d3d_color) / 255.0f;
1453 }
1454 
1455 #define HIGHEST_TRANSFORMSTATE WINED3D_TS_WORLD_MATRIX(255) /* Highest value in wined3d_transform_state. */
1456 
1457 void wined3d_check_gl_call(const struct wined3d_gl_info *gl_info,
1458  const char *file, unsigned int line, const char *name) DECLSPEC_HIDDEN;
1459 
1460 /* Checking of API calls */
1461 /* --------------------- */
1462 #ifndef WINE_NO_DEBUG_MSGS
1463 #define checkGLcall(A) \
1464 do { \
1465  if (__WINE_IS_DEBUG_ON(_ERR, &__wine_dbch_d3d) \
1466  && !gl_info->supported[ARB_DEBUG_OUTPUT]) \
1467  wined3d_check_gl_call(gl_info, __FILE__, __LINE__, A); \
1468 } while(0)
1469 #else
1470 #define checkGLcall(A) do {} while(0)
1471 #endif
1472 
1474 {
1477 };
1478 
1480 {
1482  const BYTE *addr;
1483 };
1484 
1486 {
1487  return (struct wined3d_const_bo_address *)data;
1488 }
1489 
1491 {
1492  const struct wined3d_format *format;
1495  unsigned int stream_idx;
1496  unsigned int divisor;
1497 };
1498 
1500 {
1504  WORD swizzle_map; /* MAX_ATTRIBS, 16 */
1505  WORD use_map; /* MAX_ATTRIBS, 16 */
1506 };
1507 
1509  const struct wined3d_state *state, const struct wined3d_gl_info *gl_info,
1510  const struct wined3d_d3d_info *d3d_info) DECLSPEC_HIDDEN;
1511 
1513 {
1514  unsigned int group_count_x;
1515  unsigned int group_count_y;
1516  unsigned int group_count_z;
1517 };
1518 
1520 {
1522  unsigned int offset;
1523 };
1524 
1526 {
1528  union
1529  {
1532  } u;
1533 };
1534 
1536 {
1538  unsigned int start_idx;
1539  unsigned int index_count;
1540  unsigned int start_instance;
1541  unsigned int instance_count;
1542 };
1543 
1545 {
1547  unsigned int offset;
1548 };
1549 
1551 {
1553  union
1554  {
1557  } u;
1559 };
1560 
1561 void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
1562  const struct wined3d_draw_parameters *draw_parameters) DECLSPEC_HIDDEN;
1563 void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
1564  const struct wined3d_dispatch_parameters *dispatch_parameters) DECLSPEC_HIDDEN;
1566 
1567 #define eps 1e-8f
1568 
1569 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1570  (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1571 
1573 {
1577 };
1578 
1579 /* Routines and structures related to state management */
1580 
1581 #define STATE_RENDER(a) (a)
1582 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1583 
1584 #define STATE_TEXTURESTAGE(stage, num) \
1585  (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
1586 #define STATE_IS_TEXTURESTAGE(a) \
1587  ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1588 
1589 /* + 1 because samplers start with 0 */
1590 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
1591 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
1592 
1593 #define STATE_GRAPHICS_SHADER(a) (STATE_SAMPLER(MAX_COMBINED_SAMPLERS) + (a))
1594 #define STATE_IS_GRAPHICS_SHADER(a) \
1595  ((a) >= STATE_GRAPHICS_SHADER(0) && (a) < STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1596 
1597 #define STATE_GRAPHICS_CONSTANT_BUFFER(a) (STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT) + (a))
1598 #define STATE_IS_GRAPHICS_CONSTANT_BUFFER(a) \
1599  ((a) >= STATE_GRAPHICS_CONSTANT_BUFFER(0) \
1600  && (a) < STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1601 
1602 #define STATE_GRAPHICS_SHADER_RESOURCE_BINDING (STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1603 #define STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(a) ((a) == STATE_GRAPHICS_SHADER_RESOURCE_BINDING)
1604 
1605 #define STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING (STATE_GRAPHICS_SHADER_RESOURCE_BINDING + 1)
1606 #define STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING)
1607 
1608 #define STATE_TRANSFORM(a) (STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING + (a))
1609 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)))
1610 
1611 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1)
1612 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
1613 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1614 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
1615 
1616 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
1617 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1618 
1619 #define STATE_VIEWPORT (STATE_VDECL + 1)
1620 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1621 
1622 #define STATE_LIGHT_TYPE (STATE_VIEWPORT + 1)
1623 #define STATE_IS_LIGHT_TYPE(a) ((a) == STATE_LIGHT_TYPE)
1624 #define STATE_ACTIVELIGHT(a) (STATE_LIGHT_TYPE + 1 + (a))
1625 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
1626 
1627 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
1628 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1629 
1630 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1631 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIP_DISTANCES - 1))
1632 
1633 #define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIP_DISTANCES))
1634 #define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
1635 
1636 #define STATE_FRONTFACE (STATE_MATERIAL + 1)
1637 #define STATE_IS_FRONTFACE(a) ((a) == STATE_FRONTFACE)
1638 
1639 #define STATE_POINTSPRITECOORDORIGIN (STATE_FRONTFACE + 1)
1640 #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN)
1641 
1642 #define STATE_BASEVERTEXINDEX (STATE_POINTSPRITECOORDORIGIN + 1)
1643 #define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX)
1644 
1645 #define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1)
1646 #define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER)
1647 
1648 #define STATE_POINT_ENABLE (STATE_FRAMEBUFFER + 1)
1649 #define STATE_IS_POINT_ENABLE(a) ((a) == STATE_POINT_ENABLE)
1650 
1651 #define STATE_COLOR_KEY (STATE_POINT_ENABLE + 1)
1652 #define STATE_IS_COLOR_KEY(a) ((a) == STATE_COLOR_KEY)
1653 
1654 #define STATE_STREAM_OUTPUT (STATE_COLOR_KEY + 1)
1655 #define STATE_IS_STREAM_OUTPUT(a) ((a) == STATE_STREAM_OUTPUT)
1656 
1657 #define STATE_BLEND (STATE_STREAM_OUTPUT + 1)
1658 #define STATE_IS_BLEND(a) ((a) == STATE_BLEND)
1659 
1660 #define STATE_COMPUTE_OFFSET (STATE_BLEND + 1)
1661 
1662 #define STATE_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
1663 #define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
1664 
1665 #define STATE_COMPUTE_CONSTANT_BUFFER (STATE_COMPUTE_SHADER + 1)
1666 #define STATE_IS_COMPUTE_CONSTANT_BUFFER(a) ((a) == STATE_COMPUTE_CONSTANT_BUFFER)
1667 
1668 #define STATE_COMPUTE_SHADER_RESOURCE_BINDING (STATE_COMPUTE_CONSTANT_BUFFER + 1)
1669 #define STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(a) ((a) == STATE_COMPUTE_SHADER_RESOURCE_BINDING)
1670 
1671 #define STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING (STATE_COMPUTE_SHADER_RESOURCE_BINDING + 1)
1672 #define STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1673 
1674 #define STATE_COMPUTE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1675 #define STATE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1676 
1677 #define STATE_IS_COMPUTE(a) ((a) >= STATE_COMPUTE_OFFSET && (a) <= STATE_COMPUTE_HIGHEST)
1678 #define STATE_COMPUTE_COUNT (STATE_COMPUTE_HIGHEST - STATE_COMPUTE_OFFSET + 1)
1679 
1680 #define STATE_SHADER(a) ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_SHADER(a) : STATE_COMPUTE_SHADER)
1681 #define STATE_CONSTANT_BUFFER(a) \
1682  ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_CONSTANT_BUFFER(a) : STATE_COMPUTE_CONSTANT_BUFFER)
1683 #define STATE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == WINED3D_PIPELINE_GRAPHICS ? \
1684  STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING : STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
1685 
1690 };
1691 
1693 {
1696 };
1697 
1699 {
1705 };
1706 
1708 {
1709  struct list entry;
1712 };
1713 
1716 void wined3d_fence_issue(struct wined3d_fence *fence, const struct wined3d_device *device) DECLSPEC_HIDDEN;
1717 enum wined3d_fence_result wined3d_fence_wait(const struct wined3d_fence *fence,
1718  const struct wined3d_device *device) DECLSPEC_HIDDEN;
1719 
1720 /* Direct3D terminology with little modifications. We do not have an issued
1721  * state because only the driver knows about it, but we have a created state
1722  * because D3D allows GetData() on a created query, but OpenGL doesn't. */
1724 {
1728 };
1729 
1731 {
1732  BOOL (*query_poll)(struct wined3d_query *query, DWORD flags);
1733  BOOL (*query_issue)(struct wined3d_query *query, DWORD flags);
1734  void (*query_destroy)(struct wined3d_query *query);
1735 };
1736 
1738 {
1740 
1741  void *parent;
1746  const void *data;
1749 
1750  LONG counter_main, counter_retrieved;
1751  struct list poll_list_entry;
1752 };
1753 
1755 {
1757 
1758  struct wined3d_fence fence;
1760 };
1761 
1763 {
1765 
1766  struct list entry;
1771 };
1772 
1774 {
1776 
1777  struct list entry;
1781 };
1782 
1785 
1787 {
1788  GLuint id[2];
1789  struct
1790  {
1793  } query;
1794 };
1795 
1797 {
1799 
1800  struct list entry;
1803  unsigned int stream_idx;
1806 };
1807 
1811 
1813 {
1814  GLuint id[11];
1815  struct
1816  {
1828  } query;
1829 };
1830 
1832 {
1834 
1835  struct list entry;
1840 };
1841 
1845 
1847 {
1850 };
1851 
1853 {
1854  struct wined3d_gl_view gl_view;
1856  unsigned int sub_resource_idx;
1857  unsigned int layer_count;
1858 };
1859 
1860 #define MAX_GL_FRAGMENT_SAMPLERS 32
1861 
1863 {
1864  const struct wined3d_gl_info *gl_info;
1866  const struct StateEntry *state_table;
1867  /* State dirtification
1868  * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
1869  * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
1870  * but with the help of both it is easy to find out if a state is dirty(just check the array index), and for applying dirty states
1871  * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
1872  */
1873  DWORD dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
1875  DWORD isStateDirty[STATE_HIGHEST / (sizeof(DWORD) * CHAR_BIT) + 1]; /* Bitmap to find out quickly if a state is dirty */
1876  unsigned int dirty_compute_states[STATE_COMPUTE_COUNT / (sizeof(unsigned int) * CHAR_BIT) + 1];
1877 
1880  struct
1881  {
1883  unsigned int sub_resource_idx;
1884  } current_rt;
1885  DWORD tid; /* Thread ID which owns this context at the moment */
1886 
1887  /* Stores some information about the context state for optimization */
1889  DWORD last_was_rhw : 1; /* true iff last draw_primitive was in xyzrhw mode */
1890  DWORD last_swizzle_map : 16; /* MAX_ATTRIBS, 16 */
1900  DWORD num_untracked_materials : 2; /* Max value 2 */
1904  DWORD texShaderBumpMap : 8; /* MAX_TEXTURES, 8 */
1905  DWORD lastWasPow2Texture : 8; /* MAX_TEXTURES, 8 */
1906  DWORD fixed_function_usage_map : 8; /* MAX_TEXTURES, 8 */
1907  DWORD lowest_disabled_stage : 4; /* Max MAX_TEXTURES, 8 */
1912  DWORD hdc_has_format : 1; /* only meaningful if hdc_is_private */
1921  DWORD shader_update_mask : 6; /* WINED3D_SHADER_TYPE_COUNT, 6 */
1922  DWORD clip_distance_mask : 8; /* MAX_CLIP_DISTANCES, 8 */
1927  GLenum tracking_parm; /* Which source is tracking current colour */
1928  GLenum untracked_materials[2];
1929  UINT blit_w, blit_h;
1930  enum fogsource fog_source;
1933 
1935 
1936  /* The actual opengl context */
1947 
1950 
1951  /* FBOs */
1953  struct list fbo_list;
1954  struct list fbo_destroy_list;
1959  DWORD draw_buffers_mask; /* Enabled draw buffers, 31 max. */
1960 
1961  /* Queries */
1965  struct list occlusion_queries;
1966 
1969  unsigned int free_fence_count;
1970  struct list fences;
1971 
1975  struct list timestamp_queries;
1976 
1980  struct list so_statistics_queries;
1981 
1985  struct list pipeline_statistics_queries;
1986 
1988 
1989  /* Fences for GL_APPLE_flush_buffer_range */
1990  struct wined3d_fence *buffer_fences[MAX_ATTRIBS];
1991  unsigned int buffer_fence_count;
1992 
1995 
1996  /* Extension emulation */
1999  GLfloat color[4], fogstart, fogend, fogcolor[4];
2001 };
2002 
2004 {
2007 };
2008 
2009 typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
2010 
2012 {
2015 };
2016 
2018 {
2021  enum wined3d_gl_extension extension;
2022 };
2023 
2024 #define WINED3D_FRAGMENT_CAP_PROJ_CONTROL 0x00000001
2025 #define WINED3D_FRAGMENT_CAP_SRGB_WRITE 0x00000002
2026 #define WINED3D_FRAGMENT_CAP_COLOR_KEY 0x00000004
2027 
2029 {
2035 };
2036 
2037 #define GL_EXT_EMUL_ARB_MULTITEXTURE 0x00000001
2038 #define GL_EXT_EMUL_EXT_FOG_COORD 0x00000002
2039 
2041 {
2042  void (*enable_extension)(const struct wined3d_gl_info *gl_info, BOOL enable);
2043  void (*get_caps)(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps);
2044  DWORD (*get_emul_mask)(const struct wined3d_gl_info *gl_info);
2045  void *(*alloc_private)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2046  void (*free_private)(struct wined3d_device *device);
2047  BOOL (*allocate_context_data)(struct wined3d_context *context);
2048  void (*free_context_data)(struct wined3d_context *context);
2049  BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
2051 };
2052 
2054 {
2065 };
2066 
2068 {
2069  void (*vp_enable)(const struct wined3d_gl_info *gl_info, BOOL enable);
2070  void (*vp_get_caps)(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps);
2071  DWORD (*vp_get_emul_mask)(const struct wined3d_gl_info *gl_info);
2072  void *(*vp_alloc)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2073  void (*vp_free)(struct wined3d_device *device);
2075 };
2076 
2085 
2089 
2090 /* "Base" state table */
2091 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
2092  const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
2093  const struct wined3d_vertex_pipe_ops *vertex, const struct fragment_pipeline *fragment,
2094  const struct StateEntryTemplate *misc) DECLSPEC_HIDDEN;
2095 
2096 struct wined3d_surface;
2097 
2099 {
2107 };
2108 
2110 {
2111  const struct wined3d_blitter_ops *ops;
2113 };
2114 
2116 {
2117  void (*blitter_destroy)(struct wined3d_blitter *blitter, struct wined3d_context *context);
2118  void (*blitter_clear)(struct wined3d_blitter *blitter, struct wined3d_device *device,
2119  unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects,
2120  const RECT *draw_rect, DWORD flags, const struct wined3d_color *colour, float depth, DWORD stencil);
2121  DWORD (*blitter_blit)(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context,
2122  struct wined3d_surface *src_surface, DWORD src_location, const RECT *src_rect,
2123  struct wined3d_surface *dst_surface, DWORD dst_location, const RECT *dst_rect,
2125 };
2126 
2128  const struct wined3d_device *device) DECLSPEC_HIDDEN;
2131  const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2133  const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2135  const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2136 
2138 
2140  struct wined3d_texture *texture, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
2146  UINT rt_count, const struct wined3d_fb_state *fb) DECLSPEC_HIDDEN;
2148  struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN;
2149 void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info,
2150  unsigned int unit) DECLSPEC_HIDDEN;
2153  const struct wined3d_context *context) DECLSPEC_HIDDEN;
2157  const struct wined3d_bo_address *dst, GLenum dst_binding,
2158  const struct wined3d_bo_address *src, GLenum src_binding, size_t size) DECLSPEC_HIDDEN;
2159 struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_texture *target,
2160  const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
2161 HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;
2170  const struct wined3d_shader_version *shader_version, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
2173  GLuint name, BOOL rb_namespace) DECLSPEC_HIDDEN;
2177  size_t size, GLenum binding, DWORD flags) DECLSPEC_HIDDEN;
2188  const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2190  const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2193  const struct wined3d_bo_address *data, GLenum binding) DECLSPEC_HIDDEN;
2194 
2195 /*****************************************************************************
2196  * Internal representation of a light
2197  */
2199 {
2200  struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
2204 
2205  /* Converted parms to speed up swapping lights */
2206  struct wined3d_vec4 position;
2207  struct wined3d_vec4 direction;
2208  float exponent;
2209  float cutoff;
2210 
2211  struct list entry;
2212 };
2213 
2214 /* The default light parameters */
2216 
2218 {
2219  int iPixelFormat; /* WGL pixel format */
2220  int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
2221  int redSize, greenSize, blueSize, alphaSize, colorSize;
2222  int depthSize, stencilSize;
2227 };
2228 
2230 {
2232  HW_VENDOR_AMD = 0x1002,
2236 };
2237 
2239 {
2240  CARD_WINE = 0x0000,
2241 
2288 
2304  CARD_NVIDIA_GEFORCE_7300 = 0x01d7, /* GeForce Go 7300 */
2308  CARD_NVIDIA_GEFORCE_8200 = 0x0849, /* Other PCI ID 0x084b */
2395  CARD_NVIDIA_GEFORCE_GTX860M = 0x1392, /* Other PCI ID 0x119a */
2413 
2415 
2426  CARD_INTEL_Q35 = 0x29b2,
2427  CARD_INTEL_G33 = 0x29c2,
2428  CARD_INTEL_Q33 = 0x29d2,
2437  CARD_INTEL_IGD = 0x2e02,
2438  CARD_INTEL_Q45 = 0x2e12,
2439  CARD_INTEL_G45 = 0x2e22,
2440  CARD_INTEL_G41 = 0x2e32,
2441  CARD_INTEL_B43 = 0x2e92,
2450  CARD_INTEL_HWD = 0x0412,
2451  CARD_INTEL_HWM = 0x0416,
2486 };
2487 
2489 {
2490  GLboolean (WINE_GLAPI *glIsRenderbuffer)(GLuint renderbuffer);
2491  void (WINE_GLAPI *glBindRenderbuffer)(GLenum target, GLuint renderbuffer);
2492  void (WINE_GLAPI *glDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers);
2493  void (WINE_GLAPI *glGenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
2494  void (WINE_GLAPI *glRenderbufferStorage)(GLenum target, GLenum internalformat,
2496  void (WINE_GLAPI *glRenderbufferStorageMultisample)(GLenum target, GLsizei samples,
2498  void (WINE_GLAPI *glGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params);
2499  GLboolean (WINE_GLAPI *glIsFramebuffer)(GLuint framebuffer);
2500  void (WINE_GLAPI *glBindFramebuffer)(GLenum target, GLuint framebuffer);
2501  void (WINE_GLAPI *glDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers);
2502  void (WINE_GLAPI *glGenFramebuffers)(GLsizei n, GLuint *framebuffers);
2503  GLenum (WINE_GLAPI *glCheckFramebufferStatus)(GLenum target);
2504  void (WINE_GLAPI *glFramebufferTexture)(GLenum target, GLenum attachment,
2506  void (WINE_GLAPI *glFramebufferTexture1D)(GLenum target, GLenum attachment,
2508  void (WINE_GLAPI *glFramebufferTexture2D)(GLenum target, GLenum attachment,
2510  void (WINE_GLAPI *glFramebufferTexture3D)(GLenum target, GLenum attachment,
2512  void (WINE_GLAPI *glFramebufferTextureLayer)(GLenum target, GLenum attachment,
2514  void (WINE_GLAPI *glFramebufferRenderbuffer)(GLenum target, GLenum attachment,
2516  void (WINE_GLAPI *glGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment,
2517  GLenum pname, GLint *params);
2518  void (WINE_GLAPI *glBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
2520  void (WINE_GLAPI *glGenerateMipmap)(GLenum target);
2521 };
2522 
2524 {
2530  unsigned int uniform_blocks[WINED3D_SHADER_TYPE_COUNT];
2532  unsigned int graphics_samplers;
2533  unsigned int combined_samplers;
2542  float shininess;
2545 
2547 
2548  unsigned int framebuffer_width;
2549  unsigned int framebuffer_height;
2550 
2554 
2564 };
2565 
2566 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits *gl_limits,
2567  enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
2569  enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
2570 
2572 {
2575  struct wined3d_gl_limits limits;
2576  DWORD reserved_glsl_constants, reserved_arb_constants;
2580 
2581  HGLRC (WINAPI *p_wglCreateContextAttribsARB)(HDC dc, HGLRC share, const GLint *attribs);
2582  struct opengl_funcs gl_ops;
2583  struct wined3d_fbo_ops fbo_ops;
2584 
2586  unsigned int format_count;
2587 };
2588 
2590 {
2593  const char *name;
2594  const char *description;
2598 };
2599 
2600 /* The adapter structure */
2602 {
2605  enum wined3d_format_id screen_format;
2606 
2607  struct wined3d_gl_info gl_info;
2608  struct wined3d_d3d_info d3d_info;
2609  struct wined3d_driver_info driver_info;
2610  WCHAR DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
2611  unsigned int cfg_count;
2616 
2620 };
2621 
2623 {
2629 
2630  const struct wined3d_gl_info *gl_info;
2633 };
2634 
2636  struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
2638 
2640 
2642 
2644 {
2648 };
2649 
2651 {
2654 };
2655 
2656 /*****************************************************************************
2657  * Fixed function pipeline replacements
2658  */
2659 #define ARG_UNUSED 0xff
2661 {
2662  unsigned cop : 8;
2663  unsigned carg1 : 8;
2664  unsigned carg2 : 8;
2665  unsigned carg0 : 8;
2666 
2667  unsigned aop : 8;
2668  unsigned aarg1 : 8;
2669  unsigned aarg2 : 8;
2670  unsigned aarg0 : 8;
2671 
2672  struct color_fixup_desc color_fixup;
2673  unsigned tex_type : 3;
2674  unsigned dst : 1;
2675  unsigned projected : 2;
2676  unsigned padding : 10;
2677 };
2678 
2680 {
2683  unsigned char sRGB_write;
2684  unsigned char emul_clipplanes;
2685  unsigned char texcoords_initialized;
2686  unsigned char color_key_enabled : 1;
2687  unsigned char pointsprite : 1;
2688  unsigned char flatshading : 1;
2689  unsigned char alpha_test_func : 3;
2690  unsigned char padding : 2;
2691 };
2692 
2694 {
2697 };
2698 
2701 
2703 
2704 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2705 void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d_state *state,
2706  struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN;
2707 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
2710 void wined3d_ftoa(float value, char *s) DECLSPEC_HIDDEN;
2711 
2712 extern const float wined3d_srgb_const0[] DECLSPEC_HIDDEN;
2713 extern const float wined3d_srgb_const1[] DECLSPEC_HIDDEN;
2714 
2716 {
2721 };
2722 
2723 #define WINED3D_FFP_TCI_SHIFT 16
2724 #define WINED3D_FFP_TCI_MASK 0xffu
2725 
2726 #define WINED3D_FFP_LIGHT_TYPE_SHIFT(idx) (3 * (idx))
2727 #define WINED3D_FFP_LIGHT_TYPE_MASK 0x7u
2728 
2730 {
2746 
2750  DWORD texcoords : 8; /* MAX_TEXTURES */
2753  DWORD swizzle_map : 16; /* MAX_ATTRIBS, 16 */
2756 
2758 };
2759 
2761 {
2764 };
2765 
2768 
2769 struct wined3d
2770 {
2774  struct wined3d_adapter adapters[1];
2775 };
2776 
2780 
2782 {
2785 
2786  void *parent;
2788 
2790 };
2791 
2793 {
2796 
2797  void *parent;
2799 
2801 };
2802 
2804 {
2807 };
2808 
2810 {
2816 };
2817 
2818 #define WINED3D_STATE_NO_REF 0x00000001
2819 #define WINED3D_STATE_INIT_DEFAULT 0x00000002
2820 
2822 {
2824  const struct wined3d_fb_state *fb;
2825 
2828  struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */];
2830  enum wined3d_format_id index_format;
2831  unsigned int index_offset;
2833  int load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
2838 
2844 
2848 
2852 
2856 
2857  struct wined3d_matrix transforms[HIGHEST_TRANSFORMSTATE + 1];
2858  struct wined3d_vec4 clip_planes[MAX_CLIP_DISTANCES];
2859  struct wined3d_material material;
2860  struct wined3d_viewport viewport;
2862 
2863  /* Light hashmap. Collisions are handled using linked lists. */
2864 #define LIGHTMAP_SIZE 43
2865 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE)
2866  struct list light_map[LIGHTMAP_SIZE];
2867  const struct wined3d_light_info *lights[MAX_ACTIVE_LIGHTS];
2868 
2869  DWORD render_states[WINEHIGHEST_RENDER_STATE + 1];
2872 };
2873 
2874 static inline BOOL wined3d_dualblend_enabled(const struct wined3d_state *state, const struct wined3d_gl_info *gl_info)
2875 {
2876  if (!state->fb->render_targets[0]) return FALSE;
2877  if (!state->render_states[WINED3D_RS_ALPHABLENDENABLE]) return FALSE;
2878  if (!gl_info->supported[ARB_BLEND_FUNC_EXTENDED]) return FALSE;
2879 
2880 #define IS_DUAL_SOURCE_BLEND(x) ((x) >= WINED3D_BLEND_SRC1COLOR && (x) <= WINED3D_BLEND_INVSRC1ALPHA)
2881  if (IS_DUAL_SOURCE_BLEND(state->render_states[WINED3D_RS_SRCBLEND])) return TRUE;
2882  if (IS_DUAL_SOURCE_BLEND(state->render_states[WINED3D_RS_DESTBLEND])) return TRUE;
2883  if (IS_DUAL_SOURCE_BLEND(state->render_states[WINED3D_RS_SRCBLENDALPHA])) return TRUE;
2884  if (IS_DUAL_SOURCE_BLEND(state->render_states[WINED3D_RS_DESTBLENDALPHA])) return TRUE;
2885 #undef IS_DUAL_SOURCE_BLEND
2886 
2887  return FALSE;
2888 }
2889 
2891 {
2903 };
2904 
2905 #if defined(STAGING_CSMT)
2906 struct wined3d_gl_bo
2907 {
2908  GLuint name;
2909  GLenum usage;
2910  GLenum type_hint;
2911  UINT size;
2912 };
2913 
2914 #endif /* STAGING_CSMT */
2915 #define WINED3D_UNMAPPED_STAGE ~0u
2916 
2917 /* Multithreaded flag. Removed from the public header to signal that
2918  * wined3d_device_create() ignores it. */
2919 #define WINED3DCREATE_MULTITHREADED 0x00000004
2920 
2922 {
2924 
2925  /* WineD3D Information */
2927  struct wined3d *wined3d;
2929 
2930  /* Window styles to restore when switching fullscreen mode */
2933 
2938  struct StateEntry StateTable[STATE_HIGHEST + 1];
2939  /* Array of functions for states which are handled by more than one pipeline part */
2940  APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
2942 
2943  BYTE vertexBlendUsed : 1; /* To avoid needless setting of the blend matrices */
2946  BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
2947  BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
2950 
2951  unsigned char surface_alignment; /* Line Alignment of surfaces */
2952 
2954 
2958 
2959  /* Internal use fields */
2962 
2966 
2967  struct list resources; /* a linked list to track resources created by the device */
2968  struct list shaders; /* a linked list to track shaders (pixel and vertex) */
2970 
2971  /* Render Target Support */
2972  struct wined3d_fb_state fb;
2974 
2975  /* Cursor management */
2980  UINT cursorWidth, cursorHeight;
2983 
2984  /* The Wine logo texture */
2986 
2987  /* Textures for when no other textures are mapped */
2988  struct wined3d_dummy_textures dummy_textures;
2989 
2990  /* Default sampler used to emulate the direct resource access without using wined3d_sampler */
2993 
2994  /* Command stream */
2995  struct wined3d_cs *cs;
2996 
2997  /* Context management */
3000 };
3001 
3002 void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb,
3003  UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags,
3004  const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
3008  UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags,
3009  BYTE surface_alignment, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN;
3015 #if defined(STAGING_CSMT)
3016 struct wined3d_gl_bo *wined3d_device_get_bo(struct wined3d_device *device, UINT size, GLenum gl_usage,
3017  GLenum type_hint, struct wined3d_context *context) DECLSPEC_HIDDEN;
3018 void wined3d_device_release_bo(struct wined3d_device *device, struct wined3d_gl_bo *bo,
3019  const struct wined3d_context *context) DECLSPEC_HIDDEN;
3020 #endif /* STAGING_CSMT */
3021 
3022 static inline BOOL isStateDirty(const struct wined3d_context *context, DWORD state)
3023 {
3024  DWORD idx = state / (sizeof(*context->isStateDirty) * CHAR_BIT);
3025  BYTE shift = state & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
3026  return context->isStateDirty[idx] & (1u << shift);
3027 }
3028 
3030 
3032 {
3034 }
3035 
3037 {
3038  ULONG (*resource_incref)(struct wined3d_resource *resource);
3039  ULONG (*resource_decref)(struct wined3d_resource *resource);
3040  void (*resource_preload)(struct wined3d_resource *resource);
3042  HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3043  struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags);
3044  HRESULT (*resource_map_info)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
3045  struct wined3d_map_info *info, DWORD flags);
3046  HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
3047 };
3048 
3050 {
3058  const struct wined3d_format *format;
3059  unsigned int format_flags;
3060  enum wined3d_multisample_type multisample_type;
3063  unsigned int access;
3072 
3073  void *parent;
3076 
3077  struct list resource_list_entry;
3078 };
3079 
3081 {
3082  return resource->resource_ops->resource_incref(resource);
3083 }
3084 
3086 {
3087  return resource->resource_ops->resource_decref(resource);
3088 }
3089 
3091 {
3092  InterlockedIncrement(&resource->access_count);
3093 }
3094 
3096 {
3097  InterlockedDecrement(&resource->access_count);
3098 }
3099 
3102  enum wined3d_resource_type type, const struct wined3d_format *format,
3103  enum wined3d_multisample_type multisample_type, unsigned int multisample_quality,
3104  unsigned int usage, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
3105  unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
3106  const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
3114 
3115 /* Tests show that the start address of resources is 32 byte aligned */
3116 #define RESOURCE_ALIGNMENT 16
3117 #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16
3118 
3120 {
3121  struct wined3d_sampler_desc sampler_desc;
3122  unsigned int base_level;
3124 };
3125 
3127 {
3128  void (*texture_upload_data)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3129  const struct wined3d_context *context, const struct wined3d_box *box,
3130  const struct wined3d_const_bo_address *data, unsigned int row_pitch, unsigned int slice_pitch);
3131  BOOL (*texture_load_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
3133  void (*texture_prepare_texture)(struct wined3d_texture *texture,
3134  struct wined3d_context *context, BOOL srgb);
3135  void (*texture_cleanup_sub_resources)(struct wined3d_texture *texture);
3136 };
3137 
3138 #define WINED3D_TEXTURE_COND_NP2 0x00000001
3139 #define WINED3D_TEXTURE_COND_NP2_EMULATED 0x00000002
3140 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000004
3141 #define WINED3D_TEXTURE_IS_SRGB 0x00000008
3142 #define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000010
3143 #define WINED3D_TEXTURE_RGB_VALID 0x00000020
3144 #define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000040
3145 #define WINED3D_TEXTURE_SRGB_VALID 0x00000080
3146 #define WINED3D_TEXTURE_CONVERTED 0x00000100
3147 #define WINED3D_TEXTURE_PIN_SYSMEM 0x00000200
3148 #define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
3149 #define WINED3D_TEXTURE_GET_DC_LENIENT 0x00000800
3150 #define WINED3D_TEXTURE_DC_IN_USE 0x00001000
3151 #define WINED3D_TEXTURE_DISCARD 0x00002000
3152 #define WINED3D_TEXTURE_GET_DC 0x00004000
3153 #define WINED3D_TEXTURE_GENERATE_MIPMAPS 0x00008000
3154 
3155 #define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001
3156 
3158 {
3161  struct gl_texture texture_rgb, texture_srgb;
3163  unsigned int pow2_width;
3164  unsigned int pow2_height;
3167  unsigned int download_count;
3168  unsigned int sysmem_count;
3169  float pow2_matrix[16];
3175 
3178 
3180  unsigned int row_pitch;
3181  unsigned int slice_pitch;
3182 
3183  /* May only be accessed from the command stream worker thread. */
3185  {
3187 
3188  /* Color keys for DDraw */
3189  struct wined3d_color_key dst_blt_color_key;
3190  struct wined3d_color_key src_blt_color_key;
3191  struct wined3d_color_key dst_overlay_color_key;
3192  struct wined3d_color_key src_overlay_color_key;
3193  struct wined3d_color_key gl_color_key;
3195  } async;
3196