mf/tests: Test input type for WMA decoder DMO.
[wine.git] / dlls / wined3d / wined3d_private.h
bloba586d6847bf8df19a314f11a1b4579441daeb8cd
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 #define WINE_GLAPI __stdcall
30 #include <assert.h>
31 #include <stdarg.h>
32 #include <stdbool.h>
33 #include <sys/types.h>
34 #include <math.h>
35 #include <limits.h>
36 #include <float.h>
37 #define LIBVKD3D_SHADER_SOURCE
38 #include <vkd3d_shader.h>
39 #include "ntstatus.h"
40 #define WIN32_NO_STATUS
41 #define NONAMELESSUNION
42 #define NONAMELESSSTRUCT
43 #define COBJMACROS
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winreg.h"
47 #include "wingdi.h"
48 #include "winuser.h"
49 #include "winternl.h"
50 #include "ddk/d3dkmthk.h"
51 #include "wine/debug.h"
52 #include "wine/heap.h"
54 #include "objbase.h"
55 #include "wine/wined3d.h"
56 #include "wined3d_gl.h"
57 #include "wined3d_vk.h"
58 #include "wine/list.h"
59 #include "wine/rbtree.h"
60 #include "wine/wgl_driver.h"
62 static inline size_t align(size_t addr, size_t alignment)
64 return (addr + (alignment - 1)) & ~(alignment - 1);
67 static inline float int_to_float(uint32_t i)
69 union
71 uint32_t u;
72 float f;
73 } u;
75 u.u = i;
76 return u.f;
79 static inline const char *wined3d_get_line(const char **ptr, const char *end)
81 const char *p, *q;
83 if ((p = *ptr) >= end)
84 return NULL;
86 if (!(q = memchr(p, '\n', end - p)))
87 *ptr = end;
88 else
89 *ptr = q + 1;
90 return p;
93 #define MAKEDWORD_VERSION(maj, min) (((maj & 0xffffu) << 16) | (min & 0xffffu))
95 /* Driver quirks */
96 #define WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT 0x00000001
97 #define WINED3D_QUIRK_GLSL_CLIP_VARYING 0x00000004
98 #define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA 0x00000008
99 #define WINED3D_QUIRK_NV_CLIP_BROKEN 0x00000010
100 #define WINED3D_QUIRK_FBO_TEX_UPDATE 0x00000020
101 #define WINED3D_QUIRK_BROKEN_RGBA16 0x00000040
102 #define WINED3D_QUIRK_INFO_LOG_SPAM 0x00000080
103 #define WINED3D_QUIRK_LIMITED_TEX_FILTERING 0x00000100
104 #define WINED3D_QUIRK_BROKEN_ARB_FOG 0x00000200
105 #define WINED3D_QUIRK_NO_INDEPENDENT_BIT_DEPTHS 0x00000400
107 #define WINED3D_MAX_DIRTY_REGION_COUNT 7
109 #define WINED3D_ALPHA_TO_COVERAGE_ENABLE MAKEFOURCC('A','2','M','1')
110 #define WINED3D_ALPHA_TO_COVERAGE_DISABLE MAKEFOURCC('A','2','M','0')
112 #define WINED3D_BITMAP_SIZE(x) (((x) + 31) >> 5)
114 struct wined3d_fragment_pipe_ops;
115 struct wined3d_adapter;
116 struct wined3d_buffer_vk;
117 struct wined3d_context;
118 struct wined3d_context_vk;
119 struct wined3d_gl_info;
120 struct wined3d_state;
121 struct wined3d_swapchain_gl;
122 struct wined3d_texture_gl;
123 struct wined3d_vertex_pipe_ops;
125 enum wined3d_ffp_idx
127 WINED3D_FFP_POSITION = 0,
128 WINED3D_FFP_BLENDWEIGHT = 1,
129 WINED3D_FFP_BLENDINDICES = 2,
130 WINED3D_FFP_NORMAL = 3,
131 WINED3D_FFP_PSIZE = 4,
132 WINED3D_FFP_DIFFUSE = 5,
133 WINED3D_FFP_SPECULAR = 6,
134 WINED3D_FFP_TEXCOORD0 = 7,
135 WINED3D_FFP_TEXCOORD1 = 8,
136 WINED3D_FFP_TEXCOORD2 = 9,
137 WINED3D_FFP_TEXCOORD3 = 10,
138 WINED3D_FFP_TEXCOORD4 = 11,
139 WINED3D_FFP_TEXCOORD5 = 12,
140 WINED3D_FFP_TEXCOORD6 = 13,
141 WINED3D_FFP_TEXCOORD7 = 14,
142 WINED3D_FFP_ATTRIBS_COUNT = 15,
145 enum wined3d_ffp_emit_idx
147 WINED3D_FFP_EMIT_FLOAT1,
148 WINED3D_FFP_EMIT_FLOAT2,
149 WINED3D_FFP_EMIT_FLOAT3,
150 WINED3D_FFP_EMIT_FLOAT4,
151 WINED3D_FFP_EMIT_D3DCOLOR,
152 WINED3D_FFP_EMIT_UBYTE4,
153 WINED3D_FFP_EMIT_SHORT2,
154 WINED3D_FFP_EMIT_SHORT4,
155 WINED3D_FFP_EMIT_UBYTE4N,
156 WINED3D_FFP_EMIT_SHORT2N,
157 WINED3D_FFP_EMIT_SHORT4N,
158 WINED3D_FFP_EMIT_USHORT2N,
159 WINED3D_FFP_EMIT_USHORT4N,
160 WINED3D_FFP_EMIT_UDEC3,
161 WINED3D_FFP_EMIT_DEC3N,
162 WINED3D_FFP_EMIT_FLOAT16_2,
163 WINED3D_FFP_EMIT_FLOAT16_4,
164 WINED3D_FFP_EMIT_INVALID,
165 WINED3D_FFP_EMIT_COUNT,
168 /* Texture format fixups */
170 enum fixup_channel_source
172 CHANNEL_SOURCE_ZERO = 0,
173 CHANNEL_SOURCE_ONE = 1,
174 CHANNEL_SOURCE_X = 2,
175 CHANNEL_SOURCE_Y = 3,
176 CHANNEL_SOURCE_Z = 4,
177 CHANNEL_SOURCE_W = 5,
178 CHANNEL_SOURCE_COMPLEX0 = 6,
179 CHANNEL_SOURCE_COMPLEX1 = 7,
182 enum complex_fixup
184 COMPLEX_FIXUP_NONE = 0,
185 COMPLEX_FIXUP_YUY2 = 1,
186 COMPLEX_FIXUP_UYVY = 2,
187 COMPLEX_FIXUP_YV12 = 3,
188 COMPLEX_FIXUP_P8 = 4,
189 COMPLEX_FIXUP_NV12 = 5,
190 COMPLEX_FIXUP_YUV = 6,
193 #include <pshpack2.h>
194 struct color_fixup_desc
196 unsigned short x_sign_fixup : 1;
197 unsigned short x_source : 3;
198 unsigned short y_sign_fixup : 1;
199 unsigned short y_source : 3;
200 unsigned short z_sign_fixup : 1;
201 unsigned short z_source : 3;
202 unsigned short w_sign_fixup : 1;
203 unsigned short w_source : 3;
205 #include <poppack.h>
207 struct wined3d_d3d_limits
209 unsigned int vs_version, hs_version, ds_version, gs_version, ps_version, cs_version;
210 DWORD vs_uniform_count;
211 DWORD ps_uniform_count;
212 unsigned int varying_count;
213 unsigned int ffp_textures;
214 unsigned int ffp_blend_stages;
215 unsigned int ffp_vertex_blend_matrices;
216 unsigned int active_light_count;
218 unsigned int max_rt_count;
219 unsigned int max_clip_distances;
220 unsigned int texture_size;
221 float pointsize_max;
224 typedef void (WINE_GLAPI *wined3d_ffp_attrib_func)(const void *data);
225 typedef void (WINE_GLAPI *wined3d_ffp_texcoord_func)(GLenum unit, const void *data);
226 typedef void (WINE_GLAPI *wined3d_generic_attrib_func)(GLuint idx, const void *data);
227 extern wined3d_ffp_attrib_func specular_func_3ubv DECLSPEC_HIDDEN;
229 struct wined3d_ffp_attrib_ops
231 wined3d_ffp_attrib_func position[WINED3D_FFP_EMIT_COUNT];
232 wined3d_ffp_attrib_func diffuse[WINED3D_FFP_EMIT_COUNT];
233 wined3d_ffp_attrib_func specular[WINED3D_FFP_EMIT_COUNT];
234 wined3d_ffp_attrib_func normal[WINED3D_FFP_EMIT_COUNT];
235 wined3d_ffp_texcoord_func texcoord[WINED3D_FFP_EMIT_COUNT];
236 wined3d_generic_attrib_func generic[WINED3D_FFP_EMIT_COUNT];
239 struct wined3d_d3d_info
241 struct wined3d_d3d_limits limits;
242 struct wined3d_ffp_attrib_ops ffp_attrib_ops;
243 uint32_t wined3d_creation_flags;
244 uint32_t xyzrhw : 1;
245 uint32_t emulated_flatshading : 1;
246 uint32_t ffp_generic_attributes : 1;
247 uint32_t ffp_alpha_test : 1;
248 uint32_t vs_clipping : 1;
249 uint32_t shader_color_key : 1;
250 uint32_t shader_double_precision : 1;
251 uint32_t shader_output_interpolation : 1;
252 uint32_t frag_coord_correction : 1;
253 uint32_t viewport_array_index_any_shader : 1;
254 uint32_t texture_npot : 1;
255 uint32_t texture_npot_conditional : 1;
256 uint32_t draw_base_vertex_offset : 1;
257 uint32_t vertex_bgra : 1;
258 uint32_t texture_swizzle : 1;
259 uint32_t srgb_read_control : 1;
260 uint32_t srgb_write_control : 1;
261 uint32_t clip_control : 1;
262 uint32_t full_ffp_varyings : 1;
263 uint32_t scaled_resolve : 1;
264 uint32_t pbo : 1;
265 uint32_t subpixel_viewport : 1;
266 uint32_t fences : 1;
267 uint32_t persistent_map : 1;
268 enum wined3d_feature_level feature_level;
270 DWORD multisample_draw_location;
272 float filling_convention_offset;
275 static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
276 {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
278 static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
280 struct color_fixup_desc fixup =
282 0u, complex_fixup & (1u << 0) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
283 0u, complex_fixup & (1u << 1) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
284 0u, complex_fixup & (1u << 2) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
285 0u, complex_fixup & (1u << 3) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
287 return fixup;
290 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
292 return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
295 static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
297 return fixup.x_source == CHANNEL_SOURCE_COMPLEX0 || fixup.x_source == CHANNEL_SOURCE_COMPLEX1;
300 static inline BOOL is_scaling_fixup(struct color_fixup_desc fixup)
302 return fixup.x_sign_fixup || fixup.y_sign_fixup || fixup.z_sign_fixup || fixup.w_sign_fixup;
305 static inline BOOL is_same_fixup(struct color_fixup_desc f1, struct color_fixup_desc f2)
307 return f1.x_sign_fixup == f2.x_sign_fixup && f1.x_source == f2.x_source
308 && f1.y_sign_fixup == f2.y_sign_fixup && f1.y_source == f2.y_source
309 && f1.z_sign_fixup == f2.z_sign_fixup && f1.z_source == f2.z_source
310 && f1.w_sign_fixup == f2.w_sign_fixup && f1.w_source == f2.w_source;
313 static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
315 enum complex_fixup complex_fixup = 0;
316 if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 0);
317 if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 1);
318 if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 2);
319 if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1u << 3);
320 return complex_fixup;
323 /* Device caps */
324 #define WINED3D_MAX_ACTIVE_LIGHTS 8
325 #define WINED3D_MAX_SOFTWARE_ACTIVE_LIGHTS 32
326 #define MAX_CONSTANT_BUFFERS 15
327 #define MAX_SAMPLER_OBJECTS 16
328 #define MAX_SHADER_RESOURCE_VIEWS 128
329 #define MAX_UNORDERED_ACCESS_VIEWS 8
330 #define MAX_TGSM_REGISTERS 8192
331 #define MAX_VERTEX_BLENDS 4
333 struct min_lookup
335 GLenum mip[WINED3D_TEXF_LINEAR + 1];
338 extern const struct min_lookup minMipLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
339 extern const GLenum magLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
341 static const uint32_t WINED3D_READ_ONLY_BIND_MASK = WINED3D_BIND_VERTEX_BUFFER | WINED3D_BIND_INDEX_BUFFER
342 | WINED3D_BIND_CONSTANT_BUFFER | WINED3D_BIND_SHADER_RESOURCE | WINED3D_BIND_INDIRECT_BUFFER;
344 static const VkAccessFlags WINED3D_READ_ONLY_ACCESS_FLAGS = VK_ACCESS_INDIRECT_COMMAND_READ_BIT
345 | VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_UNIFORM_READ_BIT
346 | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
347 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_HOST_READ_BIT
348 | VK_ACCESS_MEMORY_READ_BIT;
350 GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f) DECLSPEC_HIDDEN;
351 VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
352 VkCompareOp vk_compare_op_from_wined3d(enum wined3d_cmp_func op) DECLSPEC_HIDDEN;
353 VkImageViewType vk_image_view_type_from_wined3d(enum wined3d_resource_type type, uint32_t flags) DECLSPEC_HIDDEN;
354 VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
355 VkShaderStageFlagBits vk_shader_stage_from_wined3d(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN;
356 VkAccessFlags vk_access_mask_from_buffer_usage(VkBufferUsageFlags usage) DECLSPEC_HIDDEN;
357 VkPipelineStageFlags vk_pipeline_stage_mask_from_buffer_usage(VkBufferUsageFlags usage) DECLSPEC_HIDDEN;
358 VkBufferUsageFlags vk_buffer_usage_from_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
359 VkMemoryPropertyFlags vk_memory_type_from_access_flags(uint32_t access, uint32_t usage) DECLSPEC_HIDDEN;
361 static inline enum wined3d_cmp_func wined3d_sanitize_cmp_func(enum wined3d_cmp_func func)
363 if (func < WINED3D_CMP_NEVER || func > WINED3D_CMP_ALWAYS)
364 return WINED3D_CMP_ALWAYS;
365 return func;
368 static inline GLenum wined3d_gl_mag_filter(enum wined3d_texture_filter_type mag_filter)
370 return magLookup[mag_filter];
373 static inline GLenum wined3d_gl_min_mip_filter(enum wined3d_texture_filter_type min_filter,
374 enum wined3d_texture_filter_type mip_filter)
376 return minMipLookup[min_filter].mip[mip_filter];
379 /* float_16_to_32() and float_32_to_16() convert 16 bit floats in the
380 * FLOAT16 data type to standard C floats and vice versa. They do not
381 * depend on the encoding of the C float, so they are platform independent,
382 * but slow. On x86 and other IEEE 754 compliant platforms the conversion
383 * can be accelerated by bit shifting the exponent and mantissa. There are
384 * also some SSE-based assembly routines out there.
386 * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
388 static inline float float_16_to_32(const unsigned short *in)
390 const unsigned short s = ((*in) & 0x8000u);
391 const unsigned short e = ((*in) & 0x7c00u) >> 10;
392 const unsigned short m = (*in) & 0x3ffu;
393 const float sgn = (s ? -1.0f : 1.0f);
395 if(e == 0) {
396 if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
397 else return sgn * powf(2, -14.0f) * ((float)m / 1024.0f);
398 } else if(e < 31) {
399 return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
400 } else {
401 if(m == 0) return sgn * INFINITY;
402 else return NAN;
406 static inline float float_24_to_32(DWORD in)
408 const float sgn = in & 0x800000u ? -1.0f : 1.0f;
409 const unsigned short e = (in & 0x780000u) >> 19;
410 const unsigned int m = in & 0x7ffffu;
412 if (e == 0)
414 if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
415 else return sgn * powf(2, -6.0f) * ((float)m / 524288.0f);
417 else if (e < 15)
419 return sgn * powf(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
421 else
423 if (m == 0) return sgn * INFINITY;
424 else return NAN;
428 static inline unsigned short float_32_to_16(const float *in)
430 int exp = 0;
431 float tmp = fabsf(*in);
432 unsigned int mantissa;
433 unsigned short ret;
435 /* Deal with special numbers */
436 if (*in == 0.0f)
437 return 0x0000;
438 if (isnan(*in))
439 return 0x7c01;
440 if (isinf(*in))
441 return (*in < 0.0f ? 0xfc00 : 0x7c00);
443 if (tmp < (float)(1u << 10))
447 tmp = tmp * 2.0f;
448 exp--;
449 } while (tmp < (float)(1u << 10));
451 else if (tmp >= (float)(1u << 11))
455 tmp /= 2.0f;
456 exp++;
457 } while (tmp >= (float)(1u << 11));
460 mantissa = (unsigned int)tmp;
461 if (tmp - mantissa >= 0.5f)
462 ++mantissa; /* Round to nearest, away from zero. */
464 exp += 10; /* Normalize the mantissa. */
465 exp += 15; /* Exponent is encoded with excess 15. */
467 if (exp > 30) /* too big */
469 ret = 0x7c00; /* INF */
471 else if (exp <= 0)
473 /* exp == 0: Non-normalized mantissa. Returns 0x0000 (=0.0) for too small numbers. */
474 while (exp <= 0)
476 mantissa = mantissa >> 1;
477 ++exp;
479 ret = mantissa & 0x3ff;
481 else
483 ret = (exp << 10) | (mantissa & 0x3ff);
486 ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
487 return ret;
490 static inline unsigned int wined3d_popcount(unsigned int x)
492 #if defined(__MINGW32__)
493 return __builtin_popcount(x);
494 #else
495 x -= x >> 1 & 0x55555555;
496 x = (x & 0x33333333) + (x >> 2 & 0x33333333);
497 return ((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101 >> 24;
498 #endif
501 static inline int wined3d_uint32_compare(uint32_t x, uint32_t y)
503 return (x > y) - (x < y);
506 static inline int wined3d_uint64_compare(uint64_t x, uint64_t y)
508 return (x > y) - (x < y);
511 #define ORM_BACKBUFFER 0
512 #define ORM_FBO 1
514 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
515 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
517 enum wined3d_renderer
519 WINED3D_RENDERER_AUTO,
520 WINED3D_RENDERER_VULKAN,
521 WINED3D_RENDERER_OPENGL,
522 WINED3D_RENDERER_NO3D,
525 enum wined3d_shader_backend
527 WINED3D_SHADER_BACKEND_AUTO,
528 WINED3D_SHADER_BACKEND_GLSL,
529 WINED3D_SHADER_BACKEND_ARB,
530 WINED3D_SHADER_BACKEND_NONE,
533 #define WINED3D_CSMT_ENABLE 0x00000001
534 #define WINED3D_CSMT_SERIALIZE 0x00000002
536 /* NOTE: When adding fields to this structure, make sure to update the default
537 * values in wined3d_main.c as well. */
538 struct wined3d_settings
540 unsigned int cs_multithreaded;
541 unsigned int max_gl_version;
542 int offscreen_rendering_mode;
543 unsigned short pci_vendor_id;
544 unsigned short pci_device_id;
545 /* Memory tracking and object counting. */
546 UINT64 emulated_textureram;
547 char *logo;
548 unsigned int multisample_textures;
549 unsigned int sample_count;
550 BOOL check_float_constants;
551 unsigned int strict_shader_math;
552 unsigned int max_sm_vs;
553 unsigned int max_sm_hs;
554 unsigned int max_sm_ds;
555 unsigned int max_sm_gs;
556 unsigned int max_sm_ps;
557 unsigned int max_sm_cs;
558 enum wined3d_renderer renderer;
559 enum wined3d_shader_backend shader_backend;
560 BOOL cb_access_map_w;
563 extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
565 enum wined3d_shader_resource_type
567 WINED3D_SHADER_RESOURCE_NONE,
568 WINED3D_SHADER_RESOURCE_BUFFER,
569 WINED3D_SHADER_RESOURCE_TEXTURE_1D,
570 WINED3D_SHADER_RESOURCE_TEXTURE_2D,
571 WINED3D_SHADER_RESOURCE_TEXTURE_2DMS,
572 WINED3D_SHADER_RESOURCE_TEXTURE_3D,
573 WINED3D_SHADER_RESOURCE_TEXTURE_CUBE,
574 WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY,
575 WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY,
576 WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY,
577 WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY,
580 #define WINED3D_SHADER_CONST_VS_F 0x00000001
581 #define WINED3D_SHADER_CONST_VS_I 0x00000002
582 #define WINED3D_SHADER_CONST_VS_B 0x00000004
583 #define WINED3D_SHADER_CONST_VS_CLIP_PLANES 0x00000008
584 #define WINED3D_SHADER_CONST_VS_POINTSIZE 0x00000010
585 #define WINED3D_SHADER_CONST_POS_FIXUP 0x00000020
586 #define WINED3D_SHADER_CONST_PS_F 0x00000040
587 #define WINED3D_SHADER_CONST_PS_I 0x00000080
588 #define WINED3D_SHADER_CONST_PS_B 0x00000100
589 #define WINED3D_SHADER_CONST_PS_BUMP_ENV 0x00000200
590 #define WINED3D_SHADER_CONST_PS_FOG 0x00000400
591 #define WINED3D_SHADER_CONST_PS_ALPHA_TEST 0x00000800
592 #define WINED3D_SHADER_CONST_PS_Y_CORR 0x00001000
593 #define WINED3D_SHADER_CONST_PS_NP2_FIXUP 0x00002000
594 #define WINED3D_SHADER_CONST_FFP_MODELVIEW 0x00004000
595 #define WINED3D_SHADER_CONST_FFP_VERTEXBLEND 0x00008000
596 #define WINED3D_SHADER_CONST_FFP_PROJ 0x00010000
597 #define WINED3D_SHADER_CONST_FFP_TEXMATRIX 0x00020000
598 #define WINED3D_SHADER_CONST_FFP_MATERIAL 0x00040000
599 #define WINED3D_SHADER_CONST_FFP_LIGHTS 0x00080000
600 #define WINED3D_SHADER_CONST_FFP_PS 0x00100000
601 #define WINED3D_SHADER_CONST_FFP_COLOR_KEY 0x00200000
602 #define WINED3D_SHADER_CONST_BASE_VERTEX_ID 0x00400000
604 enum wined3d_shader_register_type
606 WINED3DSPR_TEMP = 0,
607 WINED3DSPR_INPUT = 1,
608 WINED3DSPR_CONST = 2,
609 WINED3DSPR_ADDR = 3,
610 WINED3DSPR_TEXTURE = 3,
611 WINED3DSPR_RASTOUT = 4,
612 WINED3DSPR_ATTROUT = 5,
613 WINED3DSPR_TEXCRDOUT = 6,
614 WINED3DSPR_OUTPUT = 6,
615 WINED3DSPR_CONSTINT = 7,
616 WINED3DSPR_COLOROUT = 8,
617 WINED3DSPR_DEPTHOUT = 9,
618 WINED3DSPR_SAMPLER = 10,
619 WINED3DSPR_CONST2 = 11,
620 WINED3DSPR_CONST3 = 12,
621 WINED3DSPR_CONST4 = 13,
622 WINED3DSPR_CONSTBOOL = 14,
623 WINED3DSPR_LOOP = 15,
624 WINED3DSPR_TEMPFLOAT16 = 16,
625 WINED3DSPR_MISCTYPE = 17,
626 WINED3DSPR_LABEL = 18,
627 WINED3DSPR_PREDICATE = 19,
628 WINED3DSPR_IMMCONST,
629 WINED3DSPR_CONSTBUFFER,
630 WINED3DSPR_IMMCONSTBUFFER,
631 WINED3DSPR_PRIMID,
632 WINED3DSPR_NULL,
633 WINED3DSPR_RESOURCE,
634 WINED3DSPR_UAV,
635 WINED3DSPR_OUTPOINTID,
636 WINED3DSPR_FORKINSTID,
637 WINED3DSPR_JOININSTID,
638 WINED3DSPR_INCONTROLPOINT,
639 WINED3DSPR_OUTCONTROLPOINT,
640 WINED3DSPR_PATCHCONST,
641 WINED3DSPR_TESSCOORD,
642 WINED3DSPR_GROUPSHAREDMEM,
643 WINED3DSPR_THREADID,
644 WINED3DSPR_THREADGROUPID,
645 WINED3DSPR_LOCALTHREADID,
646 WINED3DSPR_LOCALTHREADINDEX,
647 WINED3DSPR_IDXTEMP,
648 WINED3DSPR_STREAM,
649 WINED3DSPR_FUNCTIONBODY,
650 WINED3DSPR_FUNCTIONPOINTER,
651 WINED3DSPR_COVERAGE,
652 WINED3DSPR_SAMPLEMASK,
653 WINED3DSPR_GSINSTID,
654 WINED3DSPR_DEPTHOUTGE,
655 WINED3DSPR_DEPTHOUTLE,
656 WINED3DSPR_RASTERIZER,
659 enum wined3d_data_type
661 WINED3D_DATA_FLOAT,
662 WINED3D_DATA_INT,
663 WINED3D_DATA_RESOURCE,
664 WINED3D_DATA_SAMPLER,
665 WINED3D_DATA_UAV,
666 WINED3D_DATA_UINT,
667 WINED3D_DATA_UNORM,
668 WINED3D_DATA_SNORM,
669 WINED3D_DATA_OPAQUE,
672 enum wined3d_immconst_type
674 WINED3D_IMMCONST_SCALAR,
675 WINED3D_IMMCONST_VEC4,
678 #define WINED3DSP_NOSWIZZLE (0u | (1u << 2) | (2u << 4) | (3u << 6))
680 enum wined3d_shader_src_modifier
682 WINED3DSPSM_NONE = 0,
683 WINED3DSPSM_NEG = 1,
684 WINED3DSPSM_BIAS = 2,
685 WINED3DSPSM_BIASNEG = 3,
686 WINED3DSPSM_SIGN = 4,
687 WINED3DSPSM_SIGNNEG = 5,
688 WINED3DSPSM_COMP = 6,
689 WINED3DSPSM_X2 = 7,
690 WINED3DSPSM_X2NEG = 8,
691 WINED3DSPSM_DZ = 9,
692 WINED3DSPSM_DW = 10,
693 WINED3DSPSM_ABS = 11,
694 WINED3DSPSM_ABSNEG = 12,
695 WINED3DSPSM_NOT = 13,
698 #define WINED3DSP_WRITEMASK_0 0x1u /* .x r */
699 #define WINED3DSP_WRITEMASK_1 0x2u /* .y g */
700 #define WINED3DSP_WRITEMASK_2 0x4u /* .z b */
701 #define WINED3DSP_WRITEMASK_3 0x8u /* .w a */
702 #define WINED3DSP_WRITEMASK_ALL 0xfu /* all */
704 enum wined3d_shader_dst_modifier
706 WINED3DSPDM_NONE = 0,
707 WINED3DSPDM_SATURATE = 1,
708 WINED3DSPDM_PARTIALPRECISION = 2,
709 WINED3DSPDM_MSAMPCENTROID = 4,
712 enum wined3d_shader_interpolation_mode
714 WINED3DSIM_NONE = 0,
715 WINED3DSIM_CONSTANT = 1,
716 WINED3DSIM_LINEAR = 2,
717 WINED3DSIM_LINEAR_CENTROID = 3,
718 WINED3DSIM_LINEAR_NOPERSPECTIVE = 4,
719 WINED3DSIM_LINEAR_NOPERSPECTIVE_CENTROID = 5,
720 WINED3DSIM_LINEAR_SAMPLE = 6,
721 WINED3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
724 #define WINED3D_PACKED_INTERPOLATION_SIZE 3
725 #define WINED3D_PACKED_INTERPOLATION_BIT_COUNT 3
727 enum wined3d_shader_global_flags
729 WINED3DSGF_REFACTORING_ALLOWED = 0x1,
730 WINED3DSGF_FORCE_EARLY_DEPTH_STENCIL = 0x4,
731 WINED3DSGF_ENABLE_RAW_AND_STRUCTURED_BUFFERS = 0x8,
734 enum wined3d_shader_sync_flags
736 WINED3DSSF_THREAD_GROUP = 0x1,
737 WINED3DSSF_GROUP_SHARED_MEMORY = 0x2,
738 WINED3DSSF_GLOBAL_UAV = 0x8,
741 enum wined3d_shader_uav_flags
743 WINED3DSUF_GLOBALLY_COHERENT = 0x2,
744 WINED3DSUF_ORDER_PRESERVING_COUNTER = 0x100,
747 enum wined3d_tessellator_domain
749 WINED3D_TESSELLATOR_DOMAIN_LINE = 1,
750 WINED3D_TESSELLATOR_DOMAIN_TRIANGLE = 2,
751 WINED3D_TESSELLATOR_DOMAIN_QUAD = 3,
754 enum wined3d_tessellator_output_primitive
756 WINED3D_TESSELLATOR_OUTPUT_POINT = 1,
757 WINED3D_TESSELLATOR_OUTPUT_LINE = 2,
758 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3,
759 WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4,
762 enum wined3d_tessellator_partitioning
764 WINED3D_TESSELLATOR_PARTITIONING_INTEGER = 1,
765 WINED3D_TESSELLATOR_PARTITIONING_POW2 = 2,
766 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3,
767 WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4,
770 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
771 #define WINED3DSI_TEXLD_PROJECT 0x1
772 #define WINED3DSI_TEXLD_BIAS 0x2
773 #define WINED3DSI_INDEXED_DYNAMIC 0x4
774 #define WINED3DSI_RESINFO_RCP_FLOAT 0x1
775 #define WINED3DSI_RESINFO_UINT 0x2
776 #define WINED3DSI_SAMPLE_INFO_UINT 0x1
777 #define WINED3DSI_SAMPLER_COMPARISON_MODE 0x1
779 #define WINED3DSI_PRECISE_X 0x100
780 #define WINED3DSI_PRECISE_Y 0x200
781 #define WINED3DSI_PRECISE_Z 0x400
782 #define WINED3DSI_PRECISE_W 0x800
783 #define WINED3DSI_PRECISE_XYZW (WINED3DSI_PRECISE_X | WINED3DSI_PRECISE_Y \
784 | WINED3DSI_PRECISE_Z | WINED3DSI_PRECISE_W)
785 #define WINED3DSI_PRECISE_SHIFT 8
787 enum wined3d_shader_rel_op
789 WINED3D_SHADER_REL_OP_GT = 1,
790 WINED3D_SHADER_REL_OP_EQ = 2,
791 WINED3D_SHADER_REL_OP_GE = 3,
792 WINED3D_SHADER_REL_OP_LT = 4,
793 WINED3D_SHADER_REL_OP_NE = 5,
794 WINED3D_SHADER_REL_OP_LE = 6,
797 enum wined3d_shader_conditional_op
799 WINED3D_SHADER_CONDITIONAL_OP_NZ = 0,
800 WINED3D_SHADER_CONDITIONAL_OP_Z = 1
803 enum wined3d_sysval_semantic
805 WINED3D_SV_POSITION = 0x01,
806 WINED3D_SV_CLIP_DISTANCE = 0x02,
807 WINED3D_SV_CULL_DISTANCE = 0x03,
808 WINED3D_SV_RENDER_TARGET_ARRAY_INDEX = 0x04,
809 WINED3D_SV_VIEWPORT_ARRAY_INDEX = 0x05,
810 WINED3D_SV_VERTEX_ID = 0x06,
811 WINED3D_SV_PRIMITIVE_ID = 0x07,
812 WINED3D_SV_INSTANCE_ID = 0x08,
813 WINED3D_SV_IS_FRONT_FACE = 0x09,
814 WINED3D_SV_SAMPLE_INDEX = 0x0a,
815 WINED3D_SV_TESS_FACTOR_QUADEDGE = 0x0b,
816 WINED3D_SV_TESS_FACTOR_QUADINT = 0x0c,
817 WINED3D_SV_TESS_FACTOR_TRIEDGE = 0x0d,
818 WINED3D_SV_TESS_FACTOR_TRIINT = 0x0e,
819 WINED3D_SV_TESS_FACTOR_LINEDET = 0x0f,
820 WINED3D_SV_TESS_FACTOR_LINEDEN = 0x10,
823 enum wined3d_component_type
825 WINED3D_TYPE_UNKNOWN = 0x0,
826 WINED3D_TYPE_UINT = 0x1,
827 WINED3D_TYPE_INT = 0x2,
828 WINED3D_TYPE_FLOAT = 0x3,
831 struct wined3d_shader_signature_element
833 const char *semantic_name;
834 unsigned int semantic_idx;
835 unsigned int stream_idx;
836 enum wined3d_sysval_semantic sysval_semantic;
837 enum wined3d_component_type component_type;
838 unsigned int register_idx;
839 uint32_t mask;
840 unsigned int min_precision;
843 struct wined3d_shader_signature
845 unsigned int element_count;
846 struct wined3d_shader_signature_element *elements;
849 #define WINED3D_SM1_VS 0xfffeu
850 #define WINED3D_SM1_PS 0xffffu
851 #define WINED3D_SM4_PS 0x0000u
852 #define WINED3D_SM4_VS 0x0001u
853 #define WINED3D_SM4_GS 0x0002u
854 #define WINED3D_SM5_HS 0x0003u
855 #define WINED3D_SM5_DS 0x0004u
856 #define WINED3D_SM5_CS 0x0005u
858 /* Shader version tokens, and shader end tokens */
859 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
860 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
862 /* Shader backends */
864 #define MAX_ATTRIBS 32
865 #define MAX_REG_ADDR 1
866 #define MAX_REG_TEXCRD 8
867 #define MAX_REG_INPUT 32
868 #define MAX_REG_OUTPUT 32
869 #define WINED3D_MAX_CBS 15
871 /* FIXME: This needs to go up to 2048 for
872 * Shader model 3 according to msdn (and for software shaders) */
873 #define MAX_LABELS 16
875 #define MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE 4096
877 struct wined3d_string_buffer
879 struct list entry;
880 char *buffer;
881 unsigned int buffer_size;
882 unsigned int content_size;
885 enum WINED3D_SHADER_INSTRUCTION_HANDLER
887 WINED3DSIH_ABS,
888 WINED3DSIH_ADD,
889 WINED3DSIH_AND,
890 WINED3DSIH_ATOMIC_AND,
891 WINED3DSIH_ATOMIC_CMP_STORE,
892 WINED3DSIH_ATOMIC_IADD,
893 WINED3DSIH_ATOMIC_IMAX,
894 WINED3DSIH_ATOMIC_IMIN,
895 WINED3DSIH_ATOMIC_OR,
896 WINED3DSIH_ATOMIC_UMAX,
897 WINED3DSIH_ATOMIC_UMIN,
898 WINED3DSIH_ATOMIC_XOR,
899 WINED3DSIH_BEM,
900 WINED3DSIH_BFI,
901 WINED3DSIH_BFREV,
902 WINED3DSIH_BREAK,
903 WINED3DSIH_BREAKC,
904 WINED3DSIH_BREAKP,
905 WINED3DSIH_BUFINFO,
906 WINED3DSIH_CALL,
907 WINED3DSIH_CALLNZ,
908 WINED3DSIH_CASE,
909 WINED3DSIH_CMP,
910 WINED3DSIH_CND,
911 WINED3DSIH_CONTINUE,
912 WINED3DSIH_CONTINUEP,
913 WINED3DSIH_COUNTBITS,
914 WINED3DSIH_CRS,
915 WINED3DSIH_CUT,
916 WINED3DSIH_CUT_STREAM,
917 WINED3DSIH_DCL,
918 WINED3DSIH_DCL_CONSTANT_BUFFER,
919 WINED3DSIH_DCL_FUNCTION_BODY,
920 WINED3DSIH_DCL_FUNCTION_TABLE,
921 WINED3DSIH_DCL_GLOBAL_FLAGS,
922 WINED3DSIH_DCL_GS_INSTANCES,
923 WINED3DSIH_DCL_HS_FORK_PHASE_INSTANCE_COUNT,
924 WINED3DSIH_DCL_HS_JOIN_PHASE_INSTANCE_COUNT,
925 WINED3DSIH_DCL_HS_MAX_TESSFACTOR,
926 WINED3DSIH_DCL_IMMEDIATE_CONSTANT_BUFFER,
927 WINED3DSIH_DCL_INDEX_RANGE,
928 WINED3DSIH_DCL_INDEXABLE_TEMP,
929 WINED3DSIH_DCL_INPUT,
930 WINED3DSIH_DCL_INPUT_CONTROL_POINT_COUNT,
931 WINED3DSIH_DCL_INPUT_PRIMITIVE,
932 WINED3DSIH_DCL_INPUT_PS,
933 WINED3DSIH_DCL_INPUT_PS_SGV,
934 WINED3DSIH_DCL_INPUT_PS_SIV,
935 WINED3DSIH_DCL_INPUT_SGV,
936 WINED3DSIH_DCL_INPUT_SIV,
937 WINED3DSIH_DCL_INTERFACE,
938 WINED3DSIH_DCL_OUTPUT,
939 WINED3DSIH_DCL_OUTPUT_CONTROL_POINT_COUNT,
940 WINED3DSIH_DCL_OUTPUT_SIV,
941 WINED3DSIH_DCL_OUTPUT_TOPOLOGY,
942 WINED3DSIH_DCL_RESOURCE_RAW,
943 WINED3DSIH_DCL_RESOURCE_STRUCTURED,
944 WINED3DSIH_DCL_SAMPLER,
945 WINED3DSIH_DCL_STREAM,
946 WINED3DSIH_DCL_TEMPS,
947 WINED3DSIH_DCL_TESSELLATOR_DOMAIN,
948 WINED3DSIH_DCL_TESSELLATOR_OUTPUT_PRIMITIVE,
949 WINED3DSIH_DCL_TESSELLATOR_PARTITIONING,
950 WINED3DSIH_DCL_TGSM_RAW,
951 WINED3DSIH_DCL_TGSM_STRUCTURED,
952 WINED3DSIH_DCL_THREAD_GROUP,
953 WINED3DSIH_DCL_UAV_RAW,
954 WINED3DSIH_DCL_UAV_STRUCTURED,
955 WINED3DSIH_DCL_UAV_TYPED,
956 WINED3DSIH_DCL_VERTICES_OUT,
957 WINED3DSIH_DEF,
958 WINED3DSIH_DEFAULT,
959 WINED3DSIH_DEFB,
960 WINED3DSIH_DEFI,
961 WINED3DSIH_DIV,
962 WINED3DSIH_DP2,
963 WINED3DSIH_DP2ADD,
964 WINED3DSIH_DP3,
965 WINED3DSIH_DP4,
966 WINED3DSIH_DST,
967 WINED3DSIH_DSX,
968 WINED3DSIH_DSX_COARSE,
969 WINED3DSIH_DSX_FINE,
970 WINED3DSIH_DSY,
971 WINED3DSIH_DSY_COARSE,
972 WINED3DSIH_DSY_FINE,
973 WINED3DSIH_ELSE,
974 WINED3DSIH_EMIT,
975 WINED3DSIH_EMIT_STREAM,
976 WINED3DSIH_ENDIF,
977 WINED3DSIH_ENDLOOP,
978 WINED3DSIH_ENDREP,
979 WINED3DSIH_ENDSWITCH,
980 WINED3DSIH_EQ,
981 WINED3DSIH_EVAL_CENTROID,
982 WINED3DSIH_EVAL_SAMPLE_INDEX,
983 WINED3DSIH_EXP,
984 WINED3DSIH_EXPP,
985 WINED3DSIH_F16TOF32,
986 WINED3DSIH_F32TOF16,
987 WINED3DSIH_FCALL,
988 WINED3DSIH_FIRSTBIT_HI,
989 WINED3DSIH_FIRSTBIT_LO,
990 WINED3DSIH_FIRSTBIT_SHI,
991 WINED3DSIH_FRC,
992 WINED3DSIH_FTOI,
993 WINED3DSIH_FTOU,
994 WINED3DSIH_GATHER4,
995 WINED3DSIH_GATHER4_C,
996 WINED3DSIH_GATHER4_PO,
997 WINED3DSIH_GATHER4_PO_C,
998 WINED3DSIH_GE,
999 WINED3DSIH_HS_CONTROL_POINT_PHASE,
1000 WINED3DSIH_HS_DECLS,
1001 WINED3DSIH_HS_FORK_PHASE,
1002 WINED3DSIH_HS_JOIN_PHASE,
1003 WINED3DSIH_IADD,
1004 WINED3DSIH_IBFE,
1005 WINED3DSIH_IEQ,
1006 WINED3DSIH_IF,
1007 WINED3DSIH_IFC,
1008 WINED3DSIH_IGE,
1009 WINED3DSIH_ILT,
1010 WINED3DSIH_IMAD,
1011 WINED3DSIH_IMAX,
1012 WINED3DSIH_IMIN,
1013 WINED3DSIH_IMM_ATOMIC_ALLOC,
1014 WINED3DSIH_IMM_ATOMIC_AND,
1015 WINED3DSIH_IMM_ATOMIC_CMP_EXCH,
1016 WINED3DSIH_IMM_ATOMIC_CONSUME,
1017 WINED3DSIH_IMM_ATOMIC_EXCH,
1018 WINED3DSIH_IMM_ATOMIC_IADD,
1019 WINED3DSIH_IMM_ATOMIC_IMAX,
1020 WINED3DSIH_IMM_ATOMIC_IMIN,
1021 WINED3DSIH_IMM_ATOMIC_OR,
1022 WINED3DSIH_IMM_ATOMIC_UMAX,
1023 WINED3DSIH_IMM_ATOMIC_UMIN,
1024 WINED3DSIH_IMM_ATOMIC_XOR,
1025 WINED3DSIH_IMUL,
1026 WINED3DSIH_INE,
1027 WINED3DSIH_INEG,
1028 WINED3DSIH_ISHL,
1029 WINED3DSIH_ISHR,
1030 WINED3DSIH_ITOF,
1031 WINED3DSIH_LABEL,
1032 WINED3DSIH_LD,
1033 WINED3DSIH_LD2DMS,
1034 WINED3DSIH_LD_RAW,
1035 WINED3DSIH_LD_STRUCTURED,
1036 WINED3DSIH_LD_UAV_TYPED,
1037 WINED3DSIH_LIT,
1038 WINED3DSIH_LOD,
1039 WINED3DSIH_LOG,
1040 WINED3DSIH_LOGP,
1041 WINED3DSIH_LOOP,
1042 WINED3DSIH_LRP,
1043 WINED3DSIH_LT,
1044 WINED3DSIH_M3x2,
1045 WINED3DSIH_M3x3,
1046 WINED3DSIH_M3x4,
1047 WINED3DSIH_M4x3,
1048 WINED3DSIH_M4x4,
1049 WINED3DSIH_MAD,
1050 WINED3DSIH_MAX,
1051 WINED3DSIH_MIN,
1052 WINED3DSIH_MOV,
1053 WINED3DSIH_MOVA,
1054 WINED3DSIH_MOVC,
1055 WINED3DSIH_MUL,
1056 WINED3DSIH_NE,
1057 WINED3DSIH_NOP,
1058 WINED3DSIH_NOT,
1059 WINED3DSIH_NRM,
1060 WINED3DSIH_OR,
1061 WINED3DSIH_PHASE,
1062 WINED3DSIH_POW,
1063 WINED3DSIH_RCP,
1064 WINED3DSIH_REP,
1065 WINED3DSIH_RESINFO,
1066 WINED3DSIH_RET,
1067 WINED3DSIH_RETP,
1068 WINED3DSIH_ROUND_NE,
1069 WINED3DSIH_ROUND_NI,
1070 WINED3DSIH_ROUND_PI,
1071 WINED3DSIH_ROUND_Z,
1072 WINED3DSIH_RSQ,
1073 WINED3DSIH_SAMPLE,
1074 WINED3DSIH_SAMPLE_B,
1075 WINED3DSIH_SAMPLE_C,
1076 WINED3DSIH_SAMPLE_C_LZ,
1077 WINED3DSIH_SAMPLE_GRAD,
1078 WINED3DSIH_SAMPLE_INFO,
1079 WINED3DSIH_SAMPLE_LOD,
1080 WINED3DSIH_SAMPLE_POS,
1081 WINED3DSIH_SETP,
1082 WINED3DSIH_SGE,
1083 WINED3DSIH_SGN,
1084 WINED3DSIH_SINCOS,
1085 WINED3DSIH_SLT,
1086 WINED3DSIH_SQRT,
1087 WINED3DSIH_STORE_RAW,
1088 WINED3DSIH_STORE_STRUCTURED,
1089 WINED3DSIH_STORE_UAV_TYPED,
1090 WINED3DSIH_SUB,
1091 WINED3DSIH_SWAPC,
1092 WINED3DSIH_SWITCH,
1093 WINED3DSIH_SYNC,
1094 WINED3DSIH_TEX,
1095 WINED3DSIH_TEXBEM,
1096 WINED3DSIH_TEXBEML,
1097 WINED3DSIH_TEXCOORD,
1098 WINED3DSIH_TEXDEPTH,
1099 WINED3DSIH_TEXDP3,
1100 WINED3DSIH_TEXDP3TEX,
1101 WINED3DSIH_TEXKILL,
1102 WINED3DSIH_TEXLDD,
1103 WINED3DSIH_TEXLDL,
1104 WINED3DSIH_TEXM3x2DEPTH,
1105 WINED3DSIH_TEXM3x2PAD,
1106 WINED3DSIH_TEXM3x2TEX,
1107 WINED3DSIH_TEXM3x3,
1108 WINED3DSIH_TEXM3x3DIFF,
1109 WINED3DSIH_TEXM3x3PAD,
1110 WINED3DSIH_TEXM3x3SPEC,
1111 WINED3DSIH_TEXM3x3TEX,
1112 WINED3DSIH_TEXM3x3VSPEC,
1113 WINED3DSIH_TEXREG2AR,
1114 WINED3DSIH_TEXREG2GB,
1115 WINED3DSIH_TEXREG2RGB,
1116 WINED3DSIH_UBFE,
1117 WINED3DSIH_UDIV,
1118 WINED3DSIH_UGE,
1119 WINED3DSIH_ULT,
1120 WINED3DSIH_UMAX,
1121 WINED3DSIH_UMIN,
1122 WINED3DSIH_UMUL,
1123 WINED3DSIH_USHR,
1124 WINED3DSIH_UTOF,
1125 WINED3DSIH_XOR,
1126 WINED3DSIH_TABLE_SIZE
1129 struct wined3d_shader_version
1131 enum wined3d_shader_type type;
1132 BYTE major;
1133 BYTE minor;
1136 struct wined3d_shader_resource_info
1138 enum wined3d_shader_resource_type type;
1139 enum wined3d_data_type data_type;
1140 unsigned int flags;
1141 unsigned int stride;
1144 #define WINED3D_SAMPLER_DEFAULT ~0x0u
1146 struct wined3d_shader_sampler_map_entry
1148 unsigned int resource_idx;
1149 unsigned int sampler_idx;
1150 unsigned int bind_idx;
1153 struct wined3d_shader_sampler_map
1155 struct wined3d_shader_sampler_map_entry *entries;
1156 size_t size;
1157 size_t count;
1160 struct wined3d_shader_immediate_constant_buffer
1162 unsigned int vec4_count;
1163 uint32_t data[MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE];
1166 struct wined3d_shader_indexable_temp
1168 struct list entry;
1169 unsigned int register_idx;
1170 unsigned int register_size;
1171 unsigned int component_count;
1174 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
1176 struct wined3d_shader_reg_maps
1178 struct wined3d_shader_version shader_version;
1179 BYTE texcoord; /* MAX_REG_TEXCRD, 8 */
1180 BYTE address; /* MAX_REG_ADDR, 1 */
1181 WORD labels; /* MAX_LABELS, 16 */
1182 DWORD temporary; /* 32 */
1183 unsigned int temporary_count;
1184 uint32_t *constf; /* pixel, vertex */
1185 struct list indexable_temps;
1186 const struct wined3d_shader_immediate_constant_buffer *icb;
1187 union
1189 DWORD texcoord_mask[MAX_REG_TEXCRD]; /* vertex < 3.0 */
1190 BYTE output_registers_mask[MAX_REG_OUTPUT]; /* vertex >= 3.0 */
1191 } u;
1192 DWORD input_registers; /* max(MAX_REG_INPUT, MAX_ATTRIBS), 32 */
1193 DWORD output_registers; /* MAX_REG_OUTPUT, 32 */
1194 WORD integer_constants; /* WINED3D_MAX_CONSTS_I, 16 */
1195 WORD boolean_constants; /* WINED3D_MAX_CONSTS_B, 16 */
1196 WORD local_int_consts; /* WINED3D_MAX_CONSTS_I, 16 */
1197 WORD local_bool_consts; /* WINED3D_MAX_CONSTS_B, 16 */
1198 UINT cb_sizes[WINED3D_MAX_CBS];
1199 uint32_t cb_map; /* WINED3D_MAX_CBS, 15 */
1201 struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS];
1202 uint32_t resource_map[WINED3D_BITMAP_SIZE(MAX_SHADER_RESOURCE_VIEWS)];
1203 struct wined3d_shader_sampler_map sampler_map;
1204 DWORD sampler_comparison_mode;
1205 BYTE bumpmat; /* WINED3D_MAX_TEXTURES, 8 */
1206 BYTE luminanceparams; /* WINED3D_MAX_TEXTURES, 8 */
1207 struct wined3d_shader_resource_info uav_resource_info[MAX_UNORDERED_ACCESS_VIEWS];
1208 DWORD uav_read_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1209 DWORD uav_counter_mask : 8; /* MAX_UNORDERED_ACCESS_VIEWS, 8 */
1211 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1212 DWORD cull_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
1213 DWORD usesnrm : 1;
1214 DWORD vpos : 1;
1215 DWORD usesdsx : 1;
1216 DWORD usesdsy : 1;
1217 DWORD usestexldd : 1;
1218 DWORD usesmova : 1;
1219 DWORD usesfacing : 1;
1220 DWORD usesrelconstF : 1;
1221 DWORD fog : 1;
1222 DWORD usestexldl : 1;
1223 DWORD usesifc : 1;
1224 DWORD usescall : 1;
1225 DWORD usespow : 1;
1226 DWORD point_size : 1;
1227 DWORD vocp : 1;
1228 DWORD input_rel_addressing : 1;
1229 DWORD viewport_array : 1;
1230 DWORD sample_mask : 1;
1231 DWORD padding : 14;
1233 DWORD rt_mask; /* Used render targets, 32 max. */
1235 /* Whether or not loops are used in this shader, and nesting depth */
1236 unsigned int loop_depth;
1237 unsigned int min_rel_offset, max_rel_offset;
1239 struct wined3d_shader_tgsm *tgsm;
1240 SIZE_T tgsm_capacity;
1241 unsigned int tgsm_count;
1244 /* Keeps track of details for TEX_M#x# instructions which need to maintain
1245 * state information between multiple instructions. */
1246 struct wined3d_shader_tex_mx
1248 unsigned int current_row;
1249 unsigned int texcoord_w[2];
1252 struct wined3d_shader_parser_state
1254 unsigned int current_loop_depth;
1255 unsigned int current_loop_reg;
1256 BOOL in_subroutine;
1259 struct wined3d_shader_context
1261 const struct wined3d_shader *shader;
1262 const struct wined3d_shader_reg_maps *reg_maps;
1263 struct wined3d_string_buffer *buffer;
1264 struct wined3d_shader_tex_mx *tex_mx;
1265 struct wined3d_shader_parser_state *state;
1266 void *backend_data;
1269 struct wined3d_shader_register_index
1271 const struct wined3d_shader_src_param *rel_addr;
1272 unsigned int offset;
1275 struct wined3d_shader_register
1277 enum wined3d_shader_register_type type;
1278 enum wined3d_data_type data_type;
1279 struct wined3d_shader_register_index idx[2];
1280 enum wined3d_immconst_type immconst_type;
1281 union
1283 unsigned int immconst_data[4];
1284 unsigned fp_body_idx;
1285 } u;
1288 struct wined3d_shader_dst_param
1290 struct wined3d_shader_register reg;
1291 uint32_t write_mask;
1292 uint32_t modifiers;
1293 unsigned int shift;
1296 struct wined3d_shader_src_param
1298 struct wined3d_shader_register reg;
1299 DWORD swizzle;
1300 enum wined3d_shader_src_modifier modifiers;
1303 struct wined3d_shader_index_range
1305 struct wined3d_shader_dst_param first_register;
1306 unsigned int last_register;
1309 struct wined3d_shader_semantic
1311 enum wined3d_decl_usage usage;
1312 UINT usage_idx;
1313 enum wined3d_shader_resource_type resource_type;
1314 unsigned int sample_count;
1315 enum wined3d_data_type resource_data_type;
1316 struct wined3d_shader_dst_param reg;
1319 enum wined3d_shader_input_sysval_semantic
1321 WINED3D_SIV_POSITION = 1,
1322 WINED3D_SIV_CLIP_DISTANCE = 2,
1323 WINED3D_SIV_CULL_DISTANCE = 3,
1324 WINED3D_SIV_RENDER_TARGET_ARRAY_INDEX = 4,
1325 WINED3D_SIV_VIEWPORT_ARRAY_INDEX = 5,
1326 WINED3D_SIV_VERTEX_ID = 6,
1327 WINED3D_SIV_PRIMITIVE_ID = 7,
1328 WINED3D_SIV_INSTANCE_ID = 8,
1329 WINED3D_SIV_IS_FRONT_FACE = 9,
1330 WINED3D_SIV_SAMPLE_INDEX = 10,
1331 WINED3D_SIV_QUAD_U0_TESS_FACTOR = 11,
1332 WINED3D_SIV_QUAD_V0_TESS_FACTOR = 12,
1333 WINED3D_SIV_QUAD_U1_TESS_FACTOR = 13,
1334 WINED3D_SIV_QUAD_V1_TESS_FACTOR = 14,
1335 WINED3D_SIV_QUAD_U_INNER_TESS_FACTOR = 15,
1336 WINED3D_SIV_QUAD_V_INNER_TESS_FACTOR = 16,
1337 WINED3D_SIV_TRIANGLE_U_TESS_FACTOR = 17,
1338 WINED3D_SIV_TRIANGLE_V_TESS_FACTOR = 18,
1339 WINED3D_SIV_TRIANGLE_W_TESS_FACTOR = 19,
1340 WINED3D_SIV_TRIANGLE_INNER_TESS_FACTOR = 20,
1341 WINED3D_SIV_LINE_DETAIL_TESS_FACTOR = 21,
1342 WINED3D_SIV_LINE_DENSITY_TESS_FACTOR = 22,
1345 struct wined3d_shader_register_semantic
1347 struct wined3d_shader_dst_param reg;
1348 enum wined3d_shader_input_sysval_semantic sysval_semantic;
1351 struct wined3d_shader_structured_resource
1353 struct wined3d_shader_dst_param reg;
1354 unsigned int byte_stride;
1357 struct wined3d_shader_tgsm
1359 unsigned int size;
1360 unsigned int stride;
1363 struct wined3d_shader_tgsm_raw
1365 struct wined3d_shader_dst_param reg;
1366 unsigned int byte_count;
1369 struct wined3d_shader_tgsm_structured
1371 struct wined3d_shader_dst_param reg;
1372 unsigned int byte_stride;
1373 unsigned int structure_count;
1376 struct wined3d_shader_thread_group_size
1378 unsigned int x, y, z;
1381 struct wined3d_shader_function_table_pointer
1383 unsigned int index;
1384 unsigned int array_size;
1385 unsigned int body_count;
1386 unsigned int table_count;
1389 struct wined3d_shader_texel_offset
1391 signed char u, v, w;
1394 struct wined3d_shader_primitive_type
1396 enum wined3d_primitive_type type;
1397 unsigned int patch_vertex_count;
1400 struct wined3d_shader_instruction
1402 const struct wined3d_shader_context *ctx;
1403 enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
1404 uint32_t flags;
1405 unsigned int dst_count;
1406 unsigned int src_count;
1407 const struct wined3d_shader_dst_param *dst;
1408 const struct wined3d_shader_src_param *src;
1409 struct wined3d_shader_texel_offset texel_offset;
1410 enum wined3d_shader_resource_type resource_type;
1411 enum wined3d_data_type resource_data_type;
1412 BOOL coissue;
1413 const struct wined3d_shader_src_param *predicate;
1414 union
1416 struct wined3d_shader_semantic semantic;
1417 struct wined3d_shader_register_semantic register_semantic;
1418 struct wined3d_shader_primitive_type primitive_type;
1419 struct wined3d_shader_dst_param dst;
1420 struct wined3d_shader_src_param src;
1421 unsigned int count;
1422 unsigned int index;
1423 const struct wined3d_shader_immediate_constant_buffer *icb;
1424 struct wined3d_shader_structured_resource structured_resource;
1425 struct wined3d_shader_tgsm_raw tgsm_raw;
1426 struct wined3d_shader_tgsm_structured tgsm_structured;
1427 struct wined3d_shader_thread_group_size thread_group_size;
1428 enum wined3d_tessellator_domain tessellator_domain;
1429 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1430 enum wined3d_tessellator_partitioning tessellator_partitioning;
1431 float max_tessellation_factor;
1432 struct wined3d_shader_index_range index_range;
1433 struct wined3d_shader_indexable_temp indexable_temp;
1434 struct wined3d_shader_function_table_pointer fp;
1435 } declaration;
1438 static inline BOOL wined3d_shader_instruction_has_texel_offset(const struct wined3d_shader_instruction *ins)
1440 return ins->texel_offset.u || ins->texel_offset.v || ins->texel_offset.w;
1443 struct wined3d_shader_attribute
1445 enum wined3d_decl_usage usage;
1446 UINT usage_idx;
1449 struct wined3d_shader_loop_control
1451 unsigned int count;
1452 unsigned int start;
1453 int step;
1456 struct wined3d_shader_frontend
1458 void *(*shader_init)(const DWORD *byte_code, size_t byte_code_size,
1459 const struct wined3d_shader_signature *output_signature);
1460 void (*shader_free)(void *data);
1461 void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
1462 void (*shader_read_instruction)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins);
1463 BOOL (*shader_is_end)(void *data, const DWORD **ptr);
1466 extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
1467 extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
1469 HRESULT shader_extract_from_dxbc(struct wined3d_shader *shader,
1470 unsigned int max_shader_version, enum vkd3d_shader_source_type *source_type) DECLSPEC_HIDDEN;
1471 BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader,
1472 const struct wined3d_stream_output_element *so_element, unsigned int *register_idx,
1473 unsigned int *component_idx) DECLSPEC_HIDDEN;
1475 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
1477 #define WINED3D_SHADER_CAP_VS_CLIPPING 0x00000001u
1478 #define WINED3D_SHADER_CAP_SRGB_WRITE 0x00000002u
1479 #define WINED3D_SHADER_CAP_DOUBLE_PRECISION 0x00000004u
1480 #define WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION 0x00000008u
1481 #define WINED3D_SHADER_CAP_FULL_FFP_VARYINGS 0x00000010u
1483 struct shader_caps
1485 unsigned int vs_version;
1486 unsigned int hs_version;
1487 unsigned int ds_version;
1488 unsigned int gs_version;
1489 unsigned int ps_version;
1490 unsigned int cs_version;
1492 unsigned int vs_uniform_count;
1493 unsigned int ps_uniform_count;
1494 float ps_1x_max_value;
1495 unsigned int varying_count;
1497 DWORD wined3d_caps;
1500 enum wined3d_gl_resource_type
1502 WINED3D_GL_RES_TYPE_TEX_1D = 0,
1503 WINED3D_GL_RES_TYPE_TEX_2D = 1,
1504 WINED3D_GL_RES_TYPE_TEX_3D = 2,
1505 WINED3D_GL_RES_TYPE_TEX_CUBE = 3,
1506 WINED3D_GL_RES_TYPE_TEX_RECT = 4,
1507 WINED3D_GL_RES_TYPE_BUFFER = 5,
1508 WINED3D_GL_RES_TYPE_RB = 6,
1509 WINED3D_GL_RES_TYPE_COUNT = 7,
1512 enum wined3d_vertex_processing_mode
1514 WINED3D_VP_MODE_FF,
1515 WINED3D_VP_MODE_SHADER,
1516 WINED3D_VP_MODE_NONE,
1519 #define WINED3D_CONST_NUM_UNUSED ~0U
1521 enum wined3d_ffp_ps_fog_mode
1523 WINED3D_FFP_PS_FOG_OFF,
1524 WINED3D_FFP_PS_FOG_LINEAR,
1525 WINED3D_FFP_PS_FOG_EXP,
1526 WINED3D_FFP_PS_FOG_EXP2,
1529 /* Stateblock dependent parameters which have to be hardcoded
1530 * into the shader code
1533 #define WINED3D_PSARGS_PROJECTED (1u << 3)
1534 #define WINED3D_PSARGS_TEXTRANSFORM_SHIFT 4
1535 #define WINED3D_PSARGS_TEXTRANSFORM_MASK 0xfu
1536 #define WINED3D_PSARGS_TEXTYPE_SHIFT 2
1537 #define WINED3D_PSARGS_TEXTYPE_MASK 0x3u
1539 /* Used for Shader Model 1 pixel shaders to track the bound texture
1540 * type. 2D and RECT textures are separated through NP2 fixup. */
1541 enum wined3d_shader_tex_types
1543 WINED3D_SHADER_TEX_2D = 0,
1544 WINED3D_SHADER_TEX_3D = 1,
1545 WINED3D_SHADER_TEX_CUBE = 2,
1546 WINED3D_SHADER_TEX_ERR = 3,
1549 struct ps_compile_args
1551 struct color_fixup_desc color_fixup[WINED3D_MAX_FRAGMENT_SAMPLERS];
1552 enum wined3d_vertex_processing_mode vp_mode;
1553 enum wined3d_ffp_ps_fog_mode fog;
1554 DWORD tex_types; /* ps 1 - 3, 16 textures */
1555 WORD tex_transform; /* ps 1.0-1.3, 4 textures */
1556 WORD srgb_correction;
1557 /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
1558 D3D9 has a limit of 16 samplers and the fixup is superfluous
1559 in D3D10 (unconditional NP2 support mandatory). */
1560 WORD np2_fixup;
1561 WORD shadow; /* WINED3D_MAX_FRAGMENT_SAMPLERS, 16 */
1562 WORD texcoords_initialized; /* WINED3D_MAX_TEXTURES, 8 */
1563 WORD padding_to_dword;
1564 DWORD pointsprite : 1;
1565 DWORD flatshading : 1;
1566 DWORD alpha_test_func : 3;
1567 DWORD y_correction : 1;
1568 DWORD rt_alpha_swizzle : 8; /* WINED3D_MAX_RENDER_TARGETS, 8 */
1569 DWORD dual_source_blend : 1;
1570 DWORD padding : 17;
1573 enum fog_src_type
1575 VS_FOG_Z = 0,
1576 VS_FOG_COORD = 1
1579 struct vs_compile_args
1581 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1582 unsigned int next_shader_input_count;
1583 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1584 BYTE fog_src;
1585 BYTE clip_enabled : 1;
1586 BYTE point_size : 1;
1587 BYTE per_vertex_point_size : 1;
1588 BYTE flatshading : 1;
1589 BYTE next_shader_type : 3;
1590 BYTE padding : 1;
1593 struct ds_compile_args
1595 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
1596 enum wined3d_tessellator_partitioning tessellator_partitioning;
1597 unsigned int output_count : 16;
1598 unsigned int next_shader_type : 3;
1599 unsigned int render_offscreen : 1;
1600 unsigned int padding : 12;
1601 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1604 struct gs_compile_args
1606 unsigned int output_count;
1607 enum wined3d_primitive_type primitive_type;
1608 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
1611 struct wined3d_shader_backend_ops
1613 void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
1614 void (*shader_precompile)(void *shader_priv, struct wined3d_shader *shader);
1615 void (*shader_select)(void *shader_priv, struct wined3d_context *context,
1616 const struct wined3d_state *state);
1617 void (*shader_select_compute)(void *shader_priv, struct wined3d_context *context,
1618 const struct wined3d_state *state);
1619 void (*shader_disable)(void *shader_priv, struct wined3d_context *context);
1620 void (*shader_update_float_vertex_constants)(struct wined3d_device *device, UINT start, UINT count);
1621 void (*shader_update_float_pixel_constants)(struct wined3d_device *device, UINT start, UINT count);
1622 void (*shader_load_constants)(void *shader_priv, struct wined3d_context *context,
1623 const struct wined3d_state *state);
1624 void (*shader_destroy)(struct wined3d_shader *shader);
1625 HRESULT (*shader_alloc_private)(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
1626 const struct wined3d_fragment_pipe_ops *fragment_pipe);
1627 void (*shader_free_private)(struct wined3d_device *device, struct wined3d_context *context);
1628 BOOL (*shader_allocate_context_data)(struct wined3d_context *context);
1629 void (*shader_free_context_data)(struct wined3d_context *context);
1630 void (*shader_init_context_state)(struct wined3d_context *context);
1631 void (*shader_get_caps)(const struct wined3d_adapter *adapter, struct shader_caps *caps);
1632 BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
1633 BOOL (*shader_has_ffp_proj_control)(void *shader_priv);
1634 uint64_t (*shader_compile)(struct wined3d_context *context, const struct wined3d_shader_desc *shader_desc,
1635 enum wined3d_shader_type shader_type);
1638 extern const struct wined3d_shader_backend_ops glsl_shader_backend DECLSPEC_HIDDEN;
1639 extern const struct wined3d_shader_backend_ops arb_program_shader_backend DECLSPEC_HIDDEN;
1640 extern const struct wined3d_shader_backend_ops none_shader_backend DECLSPEC_HIDDEN;
1642 const struct wined3d_shader_backend_ops *wined3d_spirv_shader_backend_init_vk(void) DECLSPEC_HIDDEN;
1644 #define GL_EXTCALL(f) (gl_info->gl_ops.ext.p_##f)
1646 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xff)
1647 #define D3DCOLOR_B_G(dw) (((dw) >> 8) & 0xff)
1648 #define D3DCOLOR_B_B(dw) (((dw) >> 0) & 0xff)
1649 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xff)
1651 static inline void wined3d_color_from_d3dcolor(struct wined3d_color *wined3d_color, DWORD d3d_color)
1653 wined3d_color->r = D3DCOLOR_B_R(d3d_color) / 255.0f;
1654 wined3d_color->g = D3DCOLOR_B_G(d3d_color) / 255.0f;
1655 wined3d_color->b = D3DCOLOR_B_B(d3d_color) / 255.0f;
1656 wined3d_color->a = D3DCOLOR_B_A(d3d_color) / 255.0f;
1659 extern const struct wined3d_vec4 wined3d_srgb_const[] DECLSPEC_HIDDEN;
1661 static inline float wined3d_srgb_from_linear(float colour)
1663 if (colour < 0.0f)
1664 return 0.0f;
1665 if (colour < wined3d_srgb_const[1].x)
1666 return colour * wined3d_srgb_const[0].w;
1667 if (colour < 1.0f)
1668 return wined3d_srgb_const[0].y * powf(colour, wined3d_srgb_const[0].x) - wined3d_srgb_const[0].z;
1669 return 1.0f;
1672 static inline void wined3d_colour_srgb_from_linear(struct wined3d_color *colour_srgb,
1673 const struct wined3d_color *colour)
1675 colour_srgb->r = wined3d_srgb_from_linear(colour->r);
1676 colour_srgb->g = wined3d_srgb_from_linear(colour->g);
1677 colour_srgb->b = wined3d_srgb_from_linear(colour->b);
1678 colour_srgb->a = colour->a;
1681 void wined3d_check_gl_call(const struct wined3d_gl_info *gl_info,
1682 const char *file, unsigned int line, const char *name) DECLSPEC_HIDDEN;
1684 /* Checking of API calls */
1685 /* --------------------- */
1686 #ifndef WINE_NO_DEBUG_MSGS
1687 #define checkGLcall(A) \
1688 do { \
1689 if (__WINE_IS_DEBUG_ON(_ERR, &__wine_dbch_d3d) \
1690 && !gl_info->supported[ARB_DEBUG_OUTPUT]) \
1691 wined3d_check_gl_call(gl_info, __FILE__, __LINE__, A); \
1692 } while(0)
1693 #else
1694 #define checkGLcall(A) do {} while(0)
1695 #endif
1697 struct wined3d_bo
1699 /* client_map_count and map_ptr are accessed from both the client and CS
1700 * threads, and protected by wined3d_device.bo_map_lock. */
1701 struct list users;
1702 void *map_ptr;
1703 size_t buffer_offset;
1704 size_t memory_offset;
1705 unsigned int client_map_count;
1706 bool coherent;
1709 struct wined3d_bo_gl
1711 struct wined3d_bo b;
1713 GLuint id;
1715 struct wined3d_allocator_block *memory;
1717 GLsizeiptr size;
1718 GLenum binding;
1719 GLenum usage;
1721 GLbitfield flags;
1722 uint64_t command_fence_id;
1725 static inline struct wined3d_bo_gl *wined3d_bo_gl(struct wined3d_bo *bo)
1727 return CONTAINING_RECORD(bo, struct wined3d_bo_gl, b);
1730 static inline GLuint wined3d_bo_gl_id(struct wined3d_bo *bo)
1732 return bo ? wined3d_bo_gl(bo)->id : 0;
1735 struct wined3d_bo_user
1737 struct list entry;
1738 bool valid;
1741 struct wined3d_bo_vk
1743 struct wined3d_bo b;
1745 VkBuffer vk_buffer;
1746 struct wined3d_allocator_block *memory;
1747 struct wined3d_bo_slab_vk *slab;
1749 VkDeviceMemory vk_memory;
1751 VkDeviceSize size;
1752 VkBufferUsageFlags usage;
1753 VkMemoryPropertyFlags memory_type;
1755 uint64_t command_buffer_id;
1756 bool host_synced;
1759 static inline struct wined3d_bo_vk *wined3d_bo_vk(struct wined3d_bo *bo)
1761 return CONTAINING_RECORD(bo, struct wined3d_bo_vk, b);
1764 struct wined3d_bo_slab_vk_key
1766 VkMemoryPropertyFlags memory_type;
1767 VkBufferUsageFlags usage;
1768 VkDeviceSize size;
1771 struct wined3d_bo_slab_vk
1773 struct wine_rb_entry entry;
1774 struct wined3d_bo_slab_vk *next;
1775 VkMemoryPropertyFlags requested_memory_type;
1776 struct wined3d_bo_vk bo;
1777 unsigned int map_count;
1778 void *map_ptr;
1779 uint32_t map;
1782 void *wined3d_bo_slab_vk_map(struct wined3d_bo_slab_vk *slab_vk,
1783 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
1784 void wined3d_bo_slab_vk_unmap(struct wined3d_bo_slab_vk *slab_vk,
1785 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
1787 struct wined3d_bo_address
1789 struct wined3d_bo *buffer_object;
1790 BYTE *addr;
1793 struct wined3d_const_bo_address
1795 struct wined3d_bo *buffer_object;
1796 const BYTE *addr;
1799 static inline struct wined3d_const_bo_address *wined3d_const_bo_address(const struct wined3d_bo_address *data)
1801 return (struct wined3d_const_bo_address *)data;
1804 struct wined3d_image_vk
1806 VkImage vk_image;
1807 struct wined3d_allocator_block *memory;
1808 VkDeviceMemory vk_memory;
1809 uint64_t command_buffer_id;
1812 struct wined3d_stream_info_element
1814 const struct wined3d_format *format;
1815 struct wined3d_bo_address data;
1816 GLsizei stride;
1817 unsigned int stream_idx;
1818 unsigned int divisor;
1819 bool instanced;
1822 struct wined3d_stream_info
1824 struct wined3d_stream_info_element elements[MAX_ATTRIBS];
1825 DWORD position_transformed : 1;
1826 DWORD all_vbo : 1;
1827 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
1828 DWORD use_map; /* MAX_ATTRIBS, 32 */
1831 void wined3d_stream_info_from_declaration(struct wined3d_stream_info *stream_info,
1832 const struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info) DECLSPEC_HIDDEN;
1834 struct wined3d_direct_dispatch_parameters
1836 unsigned int group_count_x;
1837 unsigned int group_count_y;
1838 unsigned int group_count_z;
1841 struct wined3d_indirect_dispatch_parameters
1843 struct wined3d_buffer *buffer;
1844 unsigned int offset;
1847 struct wined3d_dispatch_parameters
1849 BOOL indirect;
1850 union
1852 struct wined3d_direct_dispatch_parameters direct;
1853 struct wined3d_indirect_dispatch_parameters indirect;
1854 } u;
1857 struct wined3d_direct_draw_parameters
1859 int base_vertex_idx;
1860 unsigned int start_idx;
1861 unsigned int index_count;
1862 unsigned int start_instance;
1863 unsigned int instance_count;
1866 struct wined3d_indirect_draw_parameters
1868 struct wined3d_buffer *buffer;
1869 unsigned int offset;
1872 struct wined3d_draw_parameters
1874 BOOL indirect;
1875 union
1877 struct wined3d_direct_draw_parameters direct;
1878 struct wined3d_indirect_draw_parameters indirect;
1879 } u;
1880 BOOL indexed;
1883 void draw_primitive(struct wined3d_device *device, const struct wined3d_state *state,
1884 const struct wined3d_draw_parameters *draw_parameters) DECLSPEC_HIDDEN;
1885 void dispatch_compute(struct wined3d_device *device, const struct wined3d_state *state,
1886 const struct wined3d_dispatch_parameters *dispatch_parameters) DECLSPEC_HIDDEN;
1888 #define eps 1e-8f
1890 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
1891 (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
1893 /* Routines and structures related to state management */
1895 #define STATE_RENDER(a) (a)
1896 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
1898 #define STATE_TEXTURESTAGE(stage, num) \
1899 (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
1900 #define STATE_IS_TEXTURESTAGE(a) \
1901 ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
1903 /* + 1 because samplers start with 0 */
1904 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(WINED3D_MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
1905 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS - 1))
1907 #define STATE_GRAPHICS_SHADER(a) (STATE_SAMPLER(WINED3D_MAX_COMBINED_SAMPLERS) + (a))
1908 #define STATE_IS_GRAPHICS_SHADER(a) \
1909 ((a) >= STATE_GRAPHICS_SHADER(0) && (a) < STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1911 #define STATE_GRAPHICS_CONSTANT_BUFFER(a) (STATE_GRAPHICS_SHADER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT) + (a))
1912 #define STATE_IS_GRAPHICS_CONSTANT_BUFFER(a) \
1913 ((a) >= STATE_GRAPHICS_CONSTANT_BUFFER(0) \
1914 && (a) < STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1916 #define STATE_GRAPHICS_SHADER_RESOURCE_BINDING (STATE_GRAPHICS_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GRAPHICS_COUNT))
1917 #define STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(a) ((a) == STATE_GRAPHICS_SHADER_RESOURCE_BINDING)
1919 #define STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING (STATE_GRAPHICS_SHADER_RESOURCE_BINDING + 1)
1920 #define STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING)
1922 #define STATE_TRANSFORM(a) (STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING + (a))
1923 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)))
1925 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1)
1926 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
1927 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
1928 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
1930 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
1931 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
1933 #define STATE_VIEWPORT (STATE_VDECL + 1)
1934 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
1936 #define STATE_LIGHT_TYPE (STATE_VIEWPORT + 1)
1937 #define STATE_IS_LIGHT_TYPE(a) ((a) == STATE_LIGHT_TYPE)
1938 #define STATE_ACTIVELIGHT(a) (STATE_LIGHT_TYPE + 1 + (a))
1939 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS))
1941 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(WINED3D_MAX_ACTIVE_LIGHTS - 1) + 1)
1942 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
1944 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
1945 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES - 1))
1947 #define STATE_MATERIAL (STATE_CLIPPLANE(WINED3D_MAX_CLIP_DISTANCES))
1948 #define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
1950 #define STATE_RASTERIZER (STATE_MATERIAL + 1)
1951 #define STATE_IS_RASTERIZER(a) ((a) == STATE_RASTERIZER)
1953 #define STATE_DEPTH_BOUNDS (STATE_RASTERIZER + 1)
1954 #define STATE_IS_DEPTH_BOUNDS(a) ((a) == STATE_DEPTH_BOUNDS)
1956 #define STATE_POINTSPRITECOORDORIGIN (STATE_DEPTH_BOUNDS + 1)
1957 #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN)
1959 #define STATE_BASEVERTEXINDEX (STATE_POINTSPRITECOORDORIGIN + 1)
1960 #define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX)
1962 #define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1)
1963 #define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER)
1965 #define STATE_POINT_ENABLE (STATE_FRAMEBUFFER + 1)
1966 #define STATE_IS_POINT_ENABLE(a) ((a) == STATE_POINT_ENABLE)
1968 #define STATE_COLOR_KEY (STATE_POINT_ENABLE + 1)
1969 #define STATE_IS_COLOR_KEY(a) ((a) == STATE_COLOR_KEY)
1971 #define STATE_STREAM_OUTPUT (STATE_COLOR_KEY + 1)
1972 #define STATE_IS_STREAM_OUTPUT(a) ((a) == STATE_STREAM_OUTPUT)
1974 #define STATE_BLEND (STATE_STREAM_OUTPUT + 1)
1975 #define STATE_IS_BLEND(a) ((a) == STATE_BLEND)
1977 #define STATE_BLEND_FACTOR (STATE_BLEND + 1)
1978 #define STATE_IS_BLEND_FACTOR(a) ((a) == STATE_BLEND_FACTOR)
1980 #define STATE_SAMPLE_MASK (STATE_BLEND_FACTOR + 1)
1981 #define STATE_IS_SAMPLE_MASK(a) ((a) == STATE_SAMPLE_MASK)
1983 #define STATE_DEPTH_STENCIL (STATE_SAMPLE_MASK + 1)
1984 #define STATE_IS_DEPTH_STENCIL(a) ((a) == STATE_DEPTH_STENCIL)
1986 #define STATE_STENCIL_REF (STATE_DEPTH_STENCIL + 1)
1987 #define STATE_IS_STENCIL_REF(a) ((a) == STATE_STENCIL_REF)
1989 #define STATE_COMPUTE_OFFSET (STATE_STENCIL_REF + 1)
1991 #define STATE_COMPUTE_SHADER (STATE_COMPUTE_OFFSET)
1992 #define STATE_IS_COMPUTE_SHADER(a) ((a) == STATE_COMPUTE_SHADER)
1994 #define STATE_COMPUTE_CONSTANT_BUFFER (STATE_COMPUTE_SHADER + 1)
1995 #define STATE_IS_COMPUTE_CONSTANT_BUFFER(a) ((a) == STATE_COMPUTE_CONSTANT_BUFFER)
1997 #define STATE_COMPUTE_SHADER_RESOURCE_BINDING (STATE_COMPUTE_CONSTANT_BUFFER + 1)
1998 #define STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(a) ((a) == STATE_COMPUTE_SHADER_RESOURCE_BINDING)
2000 #define STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING (STATE_COMPUTE_SHADER_RESOURCE_BINDING + 1)
2001 #define STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
2003 #define STATE_COMPUTE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
2004 #define STATE_HIGHEST (STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
2006 #define STATE_IS_COMPUTE(a) ((a) >= STATE_COMPUTE_OFFSET && (a) <= STATE_COMPUTE_HIGHEST)
2007 #define STATE_COMPUTE_COUNT (STATE_COMPUTE_HIGHEST - STATE_COMPUTE_OFFSET + 1)
2009 #define STATE_SHADER(a) ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_SHADER(a) : STATE_COMPUTE_SHADER)
2010 #define STATE_CONSTANT_BUFFER(a) \
2011 ((a) != WINED3D_SHADER_TYPE_COMPUTE ? STATE_GRAPHICS_CONSTANT_BUFFER(a) : STATE_COMPUTE_CONSTANT_BUFFER)
2012 #define STATE_UNORDERED_ACCESS_VIEW_BINDING(a) ((a) == WINED3D_PIPELINE_GRAPHICS ? \
2013 STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING : STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING)
2015 enum fogsource {
2016 FOGSOURCE_FFP,
2017 FOGSOURCE_VS,
2018 FOGSOURCE_COORD,
2021 union wined3d_gl_fence_object
2023 GLuint id;
2024 GLsync sync;
2027 enum wined3d_fence_result
2029 WINED3D_FENCE_OK,
2030 WINED3D_FENCE_WAITING,
2031 WINED3D_FENCE_NOT_STARTED,
2032 WINED3D_FENCE_WRONG_THREAD,
2033 WINED3D_FENCE_ERROR,
2036 struct wined3d_fence
2038 struct list entry;
2039 union wined3d_gl_fence_object object;
2040 struct wined3d_context_gl *context_gl;
2043 HRESULT wined3d_fence_create(struct wined3d_device *device, struct wined3d_fence **fence) DECLSPEC_HIDDEN;
2044 void wined3d_fence_destroy(struct wined3d_fence *fence) DECLSPEC_HIDDEN;
2045 void wined3d_fence_issue(struct wined3d_fence *fence, struct wined3d_device *device) DECLSPEC_HIDDEN;
2046 enum wined3d_fence_result wined3d_fence_wait(const struct wined3d_fence *fence,
2047 struct wined3d_device *device) DECLSPEC_HIDDEN;
2048 enum wined3d_fence_result wined3d_fence_test(const struct wined3d_fence *fence,
2049 struct wined3d_device *device, uint32_t flags) DECLSPEC_HIDDEN;
2051 /* Direct3D terminology with little modifications. We do not have an issued
2052 * state because only the driver knows about it, but we have a created state
2053 * because D3D allows GetData() on a created query, but OpenGL doesn't. */
2054 enum wined3d_query_state
2056 QUERY_CREATED,
2057 QUERY_SIGNALLED,
2058 QUERY_BUILDING
2061 struct wined3d_query_ops
2063 BOOL (*query_poll)(struct wined3d_query *query, uint32_t flags);
2064 BOOL (*query_issue)(struct wined3d_query *query, uint32_t flags);
2065 void (*query_destroy)(struct wined3d_query *query);
2068 struct wined3d_query
2070 LONG ref;
2072 void *parent;
2073 const struct wined3d_parent_ops *parent_ops;
2074 struct wined3d_device *device;
2075 enum wined3d_query_state state;
2076 enum wined3d_query_type type;
2077 const void *data;
2078 DWORD data_size;
2079 const struct wined3d_query_ops *query_ops;
2081 LONG counter_main, counter_retrieved;
2082 struct list poll_list_entry;
2084 GLuint buffer_object;
2085 UINT64 *map_ptr;
2086 bool poll_in_cs;
2089 HRESULT wined3d_query_gl_create(struct wined3d_device *device, enum wined3d_query_type type, void *parent,
2090 const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query) DECLSPEC_HIDDEN;
2091 void wined3d_query_gl_destroy_buffer_object(struct wined3d_context_gl *context_gl,
2092 struct wined3d_query *query) DECLSPEC_HIDDEN;
2094 struct wined3d_event_query
2096 struct wined3d_query query;
2098 struct wined3d_fence fence;
2099 BOOL signalled;
2102 struct wined3d_occlusion_query
2104 struct wined3d_query query;
2106 struct list entry;
2107 GLuint id;
2108 struct wined3d_context_gl *context_gl;
2109 UINT64 samples;
2110 BOOL started;
2113 struct wined3d_timestamp_query
2115 struct wined3d_query query;
2117 struct list entry;
2118 GLuint id;
2119 struct wined3d_context_gl *context_gl;
2120 UINT64 timestamp;
2123 union wined3d_gl_so_statistics_query
2125 GLuint id[2];
2126 struct
2128 GLuint written;
2129 GLuint generated;
2130 } query;
2133 struct wined3d_so_statistics_query
2135 struct wined3d_query query;
2137 struct list entry;
2138 union wined3d_gl_so_statistics_query u;
2139 struct wined3d_context_gl *context_gl;
2140 unsigned int stream_idx;
2141 struct wined3d_query_data_so_statistics statistics;
2142 BOOL started;
2145 union wined3d_gl_pipeline_statistics_query
2147 GLuint id[11];
2148 struct
2150 GLuint vertices;
2151 GLuint primitives;
2152 GLuint vertex_shader;
2153 GLuint tess_control_shader;
2154 GLuint tess_eval_shader;
2155 GLuint geometry_shader;
2156 GLuint geometry_primitives;
2157 GLuint fragment_shader;
2158 GLuint compute_shader;
2159 GLuint clipping_input;
2160 GLuint clipping_output;
2161 } query;
2164 struct wined3d_pipeline_statistics_query
2166 struct wined3d_query query;
2168 struct list entry;
2169 union wined3d_gl_pipeline_statistics_query u;
2170 struct wined3d_context_gl *context_gl;
2171 struct wined3d_query_data_pipeline_statistics statistics;
2172 BOOL started;
2175 #define WINED3D_QUERY_POOL_SIZE 256
2177 struct wined3d_query_pool_vk
2179 struct list entry;
2180 struct list completed_entry;
2182 struct list *free_list;
2183 VkQueryPool vk_query_pool;
2184 VkEvent vk_event;
2186 uint32_t allocated[WINED3D_BITMAP_SIZE(WINED3D_QUERY_POOL_SIZE)];
2187 uint32_t completed[WINED3D_BITMAP_SIZE(WINED3D_QUERY_POOL_SIZE)];
2190 bool wined3d_query_pool_vk_allocate_query(struct wined3d_query_pool_vk *pool_vk, size_t *idx) DECLSPEC_HIDDEN;
2191 void wined3d_query_pool_vk_mark_free(struct wined3d_context_vk *context_vk, struct wined3d_query_pool_vk *pool_vk,
2192 uint32_t start, uint32_t count) DECLSPEC_HIDDEN;
2193 void wined3d_query_pool_vk_cleanup(struct wined3d_query_pool_vk *pool_vk,
2194 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2195 bool wined3d_query_pool_vk_init(struct wined3d_query_pool_vk *pool_vk, struct wined3d_context_vk *context_vk,
2196 enum wined3d_query_type type, struct list *free_pools) DECLSPEC_HIDDEN;
2198 struct wined3d_query_pool_idx_vk
2200 struct wined3d_query_pool_vk *pool_vk;
2201 size_t idx;
2204 #define WINED3D_QUERY_VK_FLAG_ACTIVE 0x00000001
2205 #define WINED3D_QUERY_VK_FLAG_STARTED 0x00000002
2206 #define WINED3D_QUERY_VK_FLAG_RENDER_PASS 0x00000004
2208 struct wined3d_query_vk
2210 struct wined3d_query q;
2212 struct list entry;
2213 struct wined3d_query_pool_idx_vk pool_idx;
2214 uint8_t flags;
2215 uint64_t command_buffer_id;
2216 uint32_t control_flags;
2217 VkEvent vk_event;
2218 SIZE_T pending_count, pending_size;
2219 struct wined3d_query_pool_idx_vk *pending;
2222 static inline struct wined3d_query_vk *wined3d_query_vk(struct wined3d_query *query)
2224 return CONTAINING_RECORD(query, struct wined3d_query_vk, q);
2227 struct wined3d_device_vk;
2229 bool wined3d_query_vk_accumulate_data(struct wined3d_query_vk *query_vk, struct wined3d_device_vk *device_vk,
2230 const struct wined3d_query_pool_idx_vk *pool_idx) DECLSPEC_HIDDEN;
2231 HRESULT wined3d_query_vk_create(struct wined3d_device *device, enum wined3d_query_type type, void *parent,
2232 const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query) DECLSPEC_HIDDEN;
2233 void wined3d_query_vk_resume(struct wined3d_query_vk *query_vk, struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2234 void wined3d_query_vk_suspend(struct wined3d_query_vk *query_vk, struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2236 struct wined3d_gl_view
2238 GLenum target;
2239 GLuint name;
2242 struct wined3d_range
2244 unsigned int offset;
2245 unsigned int size;
2248 struct wined3d_rendertarget_info
2250 struct wined3d_gl_view gl_view;
2251 struct wined3d_resource *resource;
2252 unsigned int sub_resource_idx;
2253 unsigned int layer_count;
2256 struct wined3d_fb_state
2258 struct wined3d_rendertarget_view *render_targets[WINED3D_MAX_RENDER_TARGETS];
2259 struct wined3d_rendertarget_view *depth_stencil;
2262 #define MAX_GL_FRAGMENT_SAMPLERS 32
2264 struct wined3d_context
2266 const struct wined3d_d3d_info *d3d_info;
2267 const struct wined3d_state_entry *state_table;
2268 uint32_t dirty_graphics_states[WINED3D_BITMAP_SIZE(STATE_HIGHEST)];
2269 uint32_t dirty_compute_states[WINED3D_BITMAP_SIZE(STATE_COMPUTE_COUNT)];
2271 struct wined3d_device *device;
2272 struct wined3d_swapchain *swapchain;
2273 struct
2275 struct wined3d_texture *texture;
2276 unsigned int sub_resource_idx;
2277 } current_rt;
2279 /* Stores some information about the context state for optimization */
2280 DWORD last_swizzle_map; /* MAX_ATTRIBS, 32 */
2282 DWORD shader_update_mask : 6; /* WINED3D_SHADER_TYPE_COUNT, 6 */
2283 DWORD update_shader_resource_bindings : 1;
2284 DWORD update_compute_shader_resource_bindings : 1;
2285 DWORD update_unordered_access_view_bindings : 1;
2286 DWORD update_compute_unordered_access_view_bindings : 1;
2287 DWORD last_was_rhw : 1; /* True iff last draw_primitive was in xyzrhw mode. */
2288 DWORD last_was_pshader : 1;
2289 DWORD last_was_vshader : 1;
2290 DWORD last_was_diffuse : 1;
2291 DWORD last_was_specular : 1;
2292 DWORD last_was_normal : 1;
2293 DWORD last_was_ffp_blit : 1;
2294 DWORD last_was_blit : 1;
2295 DWORD last_was_ckey : 1;
2296 DWORD last_was_dual_source_blend : 1;
2297 DWORD texShaderBumpMap : 8; /* WINED3D_MAX_TEXTURES, 8 */
2298 DWORD lowest_disabled_stage : 4; /* Max WINED3D_MAX_TEXTURES, 8 */
2300 DWORD lastWasPow2Texture : 8; /* WINED3D_MAX_TEXTURES, 8 */
2301 DWORD fixed_function_usage_map : 8; /* WINED3D_MAX_TEXTURES, 8 */
2302 DWORD use_immediate_mode_draw : 1;
2303 DWORD uses_uavs : 1;
2304 DWORD uses_fbo_attached_resources : 1;
2305 DWORD transform_feedback_active : 1;
2306 DWORD transform_feedback_paused : 1;
2307 DWORD fog_coord : 1;
2308 DWORD render_offscreen : 1;
2309 DWORD current : 1;
2310 DWORD destroyed : 1;
2311 DWORD destroy_delayed : 1;
2312 DWORD namedArraysLoaded : 1;
2313 DWORD padding : 5;
2315 DWORD clip_distance_mask : 8; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
2317 DWORD constant_update_mask;
2318 DWORD numbered_array_mask;
2319 enum fogsource fog_source;
2322 void *shader_backend_data;
2323 void *fragment_pipe_data;
2325 struct wined3d_stream_info stream_info;
2327 unsigned int viewport_count;
2328 unsigned int scissor_rect_count;
2331 void wined3d_context_cleanup(struct wined3d_context *context) DECLSPEC_HIDDEN;
2332 void wined3d_context_init(struct wined3d_context *context, struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
2333 void context_preload_textures(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
2334 void context_update_stream_info(struct wined3d_context *context, const struct wined3d_state *state) DECLSPEC_HIDDEN;
2336 HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d,
2337 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
2339 struct wined3d_command_fence_gl
2341 uint64_t id;
2342 struct wined3d_fence *fence;
2345 struct wined3d_context_gl
2347 struct wined3d_context c;
2349 const struct wined3d_gl_info *gl_info;
2351 DWORD tid; /* Thread ID which owns this context at the moment. */
2353 uint32_t dc_is_private : 1;
2354 uint32_t dc_has_format : 1; /* Only meaningful for private DCs. */
2355 uint32_t fog_enabled : 1;
2356 uint32_t diffuse_attrib_to_1 : 1;
2357 uint32_t rebind_fbo : 1;
2358 uint32_t untracked_material_count : 2; /* Max value 2 */
2359 uint32_t needs_set : 1;
2360 uint32_t internal_format_set : 1;
2361 uint32_t valid : 1;
2362 uint32_t padding : 22;
2364 uint32_t default_attrib_value_set;
2366 GLenum tracking_parm; /* Which source is tracking current colour. */
2367 GLenum untracked_materials[2];
2368 SIZE blit_size;
2369 unsigned int active_texture;
2371 GLenum *texture_type;
2373 /* The WGL context. */
2374 unsigned int level;
2375 HGLRC restore_ctx;
2376 HDC restore_dc;
2377 int restore_pf;
2378 HWND restore_pf_win;
2379 HGLRC gl_ctx;
2380 HDC dc;
2381 int pixel_format;
2382 HWND window;
2383 GLint aux_buffers;
2385 /* FBOs. */
2386 unsigned int fbo_entry_count;
2387 struct list fbo_list;
2388 struct list fbo_destroy_list;
2389 struct fbo_entry *current_fbo;
2390 GLuint fbo_read_binding;
2391 GLuint fbo_draw_binding;
2392 struct wined3d_rendertarget_info blit_targets[WINED3D_MAX_RENDER_TARGETS];
2393 uint32_t draw_buffers_mask; /* Enabled draw buffers, 31 max. */
2395 /* Queries. */
2396 struct list occlusion_queries;
2397 struct list fences;
2398 struct list timestamp_queries;
2399 struct list so_statistics_queries;
2400 struct list pipeline_statistics_queries;
2402 GLuint *free_occlusion_queries;
2403 SIZE_T free_occlusion_query_size;
2404 unsigned int free_occlusion_query_count;
2406 union wined3d_gl_fence_object *free_fences;
2407 SIZE_T free_fence_size;
2408 unsigned int free_fence_count;
2410 GLuint *free_timestamp_queries;
2411 SIZE_T free_timestamp_query_size;
2412 unsigned int free_timestamp_query_count;
2414 union wined3d_gl_so_statistics_query *free_so_statistics_queries;
2415 SIZE_T free_so_statistics_query_size;
2416 unsigned int free_so_statistics_query_count;
2418 union wined3d_gl_pipeline_statistics_query *free_pipeline_statistics_queries;
2419 SIZE_T free_pipeline_statistics_query_size;
2420 unsigned int free_pipeline_statistics_query_count;
2422 GLuint blit_vbo;
2424 unsigned int tex_unit_map[WINED3D_MAX_COMBINED_SAMPLERS];
2425 unsigned int rev_tex_unit_map[MAX_GL_FRAGMENT_SAMPLERS + WINED3D_MAX_VERTEX_SAMPLERS];
2427 /* Extension emulation. */
2428 GLint gl_fog_source;
2429 GLfloat fog_coord_value;
2430 GLfloat colour[4], fog_start, fog_end, fog_colour[4];
2432 GLuint dummy_arbfp_prog;
2434 struct
2436 struct wined3d_command_fence_gl *fences;
2437 SIZE_T fences_size;
2438 SIZE_T fence_count;
2439 } submitted;
2442 static inline struct wined3d_context_gl *wined3d_context_gl(struct wined3d_context *context)
2444 return CONTAINING_RECORD(context, struct wined3d_context_gl, c);
2447 static inline const struct wined3d_context_gl *wined3d_context_gl_const(const struct wined3d_context *context)
2449 return CONTAINING_RECORD(context, struct wined3d_context_gl, c);
2452 struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device *device,
2453 struct wined3d_texture *texture, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
2454 void wined3d_context_gl_active_texture(struct wined3d_context_gl *context_gl,
2455 const struct wined3d_gl_info *gl_info, unsigned int unit) DECLSPEC_HIDDEN;
2456 void wined3d_context_gl_alloc_fence(struct wined3d_context_gl *context_gl,
2457 struct wined3d_fence *fence) DECLSPEC_HIDDEN;
2458 void wined3d_context_gl_alloc_occlusion_query(struct wined3d_context_gl *context_gl,
2459 struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
2460 void wined3d_context_gl_alloc_pipeline_statistics_query(struct wined3d_context_gl *context_gl,
2461 struct wined3d_pipeline_statistics_query *query) DECLSPEC_HIDDEN;
2462 void wined3d_context_gl_alloc_so_statistics_query(struct wined3d_context_gl *context_gl,
2463 struct wined3d_so_statistics_query *query) DECLSPEC_HIDDEN;
2464 void wined3d_context_gl_alloc_timestamp_query(struct wined3d_context_gl *context_gl,
2465 struct wined3d_timestamp_query *query) DECLSPEC_HIDDEN;
2466 GLuint wined3d_context_gl_allocate_vram_chunk_buffer(struct wined3d_context_gl *context_gl,
2467 unsigned int pool, size_t size) DECLSPEC_HIDDEN;
2468 void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl,
2469 const struct wined3d_device *device) DECLSPEC_HIDDEN;
2470 BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl, const struct wined3d_state *state,
2471 unsigned int rt_count, const struct wined3d_fb_state *fb) DECLSPEC_HIDDEN;
2472 void wined3d_context_gl_apply_fbo_state_blit(struct wined3d_context_gl *context_gl, GLenum target,
2473 struct wined3d_resource *rt, unsigned int rt_sub_resource_idx,
2474 struct wined3d_resource *ds, unsigned int ds_sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
2475 void wined3d_context_gl_apply_ffp_blit_state(struct wined3d_context_gl *context_gl,
2476 const struct wined3d_device *device) DECLSPEC_HIDDEN;
2477 void wined3d_context_gl_bind_bo(struct wined3d_context_gl *context_gl, GLenum binding, GLuint name) DECLSPEC_HIDDEN;
2478 void wined3d_context_gl_bind_dummy_textures(const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2479 void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl,
2480 GLenum target, GLuint name) DECLSPEC_HIDDEN;
2481 void wined3d_context_gl_check_fbo_status(const struct wined3d_context_gl *context_gl, GLenum target) DECLSPEC_HIDDEN;
2482 void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
2483 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
2484 unsigned int range_count, const struct wined3d_range *ranges) DECLSPEC_HIDDEN;
2485 void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2486 void wined3d_context_gl_destroy_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
2487 void wined3d_context_gl_draw_shaded_quad(struct wined3d_context_gl *context_gl, struct wined3d_texture_gl *texture_gl,
2488 unsigned int sub_resource_idx, const RECT *src_rect, const RECT *dst_rect,
2489 enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
2490 void wined3d_context_gl_draw_textured_quad(struct wined3d_context_gl *context_gl,
2491 struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
2492 const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
2493 void wined3d_context_gl_enable_clip_distances(struct wined3d_context_gl *context_gl, uint32_t mask) DECLSPEC_HIDDEN;
2494 void wined3d_context_gl_end_transform_feedback(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2495 void wined3d_context_gl_flush_bo_address(struct wined3d_context_gl *context_gl,
2496 const struct wined3d_const_bo_address *data, size_t size) DECLSPEC_HIDDEN;
2497 void wined3d_context_gl_free_fence(struct wined3d_fence *fence) DECLSPEC_HIDDEN;
2498 void wined3d_context_gl_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
2499 void wined3d_context_gl_free_pipeline_statistics_query(struct wined3d_pipeline_statistics_query *query) DECLSPEC_HIDDEN;
2500 void wined3d_context_gl_free_so_statistics_query(struct wined3d_so_statistics_query *query) DECLSPEC_HIDDEN;
2501 void wined3d_context_gl_free_timestamp_query(struct wined3d_timestamp_query *query) DECLSPEC_HIDDEN;
2502 struct wined3d_context_gl *wined3d_context_gl_get_current(void) DECLSPEC_HIDDEN;
2503 GLenum wined3d_context_gl_get_offscreen_gl_buffer(const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2504 const unsigned int *wined3d_context_gl_get_tex_unit_mapping(const struct wined3d_context_gl *context_gl,
2505 const struct wined3d_shader_version *shader_version, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
2506 HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl,
2507 struct wined3d_swapchain_gl *swapchain_gl) DECLSPEC_HIDDEN;
2508 void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context_gl,
2509 const struct wined3d_stream_info *si, GLuint *current_bo, const struct wined3d_state *state) DECLSPEC_HIDDEN;
2510 void *wined3d_context_gl_map_bo_address(struct wined3d_context_gl *context_gl,
2511 const struct wined3d_bo_address *data, size_t size, uint32_t flags) DECLSPEC_HIDDEN;
2512 struct wined3d_context_gl *wined3d_context_gl_reacquire(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2513 void wined3d_context_gl_release(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2514 BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2515 void wined3d_context_gl_submit_command_fence(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2516 void wined3d_context_gl_texture_update(struct wined3d_context_gl *context_gl,
2517 const struct wined3d_texture_gl *texture_gl) DECLSPEC_HIDDEN;
2518 void wined3d_context_gl_unload_tex_coords(const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
2519 void wined3d_context_gl_unmap_bo_address(struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data,
2520 unsigned int range_count, const struct wined3d_range *ranges) DECLSPEC_HIDDEN;
2521 void wined3d_context_gl_update_stream_sources(struct wined3d_context_gl *context_gl,
2522 const struct wined3d_state *state) DECLSPEC_HIDDEN;
2523 void wined3d_context_gl_wait_command_fence(struct wined3d_context_gl *context_gl, uint64_t id) DECLSPEC_HIDDEN;
2525 struct wined3d_command_buffer_vk
2527 uint64_t id;
2528 VkCommandBuffer vk_command_buffer;
2529 VkFence vk_fence;
2532 enum wined3d_retired_object_type_vk
2534 WINED3D_RETIRED_FREE_VK,
2535 WINED3D_RETIRED_FRAMEBUFFER_VK,
2536 WINED3D_RETIRED_DESCRIPTOR_POOL_VK,
2537 WINED3D_RETIRED_MEMORY_VK,
2538 WINED3D_RETIRED_ALLOCATOR_BLOCK_VK,
2539 WINED3D_RETIRED_BO_SLAB_SLICE_VK,
2540 WINED3D_RETIRED_BUFFER_VK,
2541 WINED3D_RETIRED_IMAGE_VK,
2542 WINED3D_RETIRED_BUFFER_VIEW_VK,
2543 WINED3D_RETIRED_IMAGE_VIEW_VK,
2544 WINED3D_RETIRED_SAMPLER_VK,
2545 WINED3D_RETIRED_QUERY_POOL_VK,
2546 WINED3D_RETIRED_EVENT_VK,
2547 WINED3D_RETIRED_PIPELINE_VK,
2550 struct wined3d_retired_object_vk
2552 enum wined3d_retired_object_type_vk type;
2553 union
2555 struct wined3d_retired_object_vk *next;
2556 VkFramebuffer vk_framebuffer;
2557 VkDescriptorPool vk_descriptor_pool;
2558 VkDeviceMemory vk_memory;
2559 struct wined3d_allocator_block *block;
2560 struct
2562 struct wined3d_bo_slab_vk *slab;
2563 size_t idx;
2564 } slice;
2565 VkBuffer vk_buffer;
2566 VkImage vk_image;
2567 VkBufferView vk_buffer_view;
2568 VkImageView vk_image_view;
2569 VkSampler vk_sampler;
2570 VkEvent vk_event;
2571 VkPipeline vk_pipeline;
2572 struct
2574 struct wined3d_query_pool_vk *pool_vk;
2575 uint32_t start;
2576 uint32_t count;
2577 } queries;
2578 } u;
2579 uint64_t command_buffer_id;
2582 struct wined3d_retired_objects_vk
2584 struct wined3d_retired_object_vk *objects;
2585 struct wined3d_retired_object_vk *free;
2586 SIZE_T size;
2587 SIZE_T count;
2590 #define WINED3D_FB_ATTACHMENT_FLAG_DISCARDED 1
2591 #define WINED3D_FB_ATTACHMENT_FLAG_CLEAR_C 2
2592 #define WINED3D_FB_ATTACHMENT_FLAG_CLEAR_S 4
2593 #define WINED3D_FB_ATTACHMENT_FLAG_CLEAR_Z 8
2595 struct wined3d_render_pass_attachment_vk
2597 VkFormat vk_format;
2598 VkSampleCountFlagBits vk_samples;
2599 VkImageLayout vk_layout;
2600 uint32_t flags;
2603 struct wined3d_render_pass_key_vk
2605 struct wined3d_render_pass_attachment_vk rt[WINED3D_MAX_RENDER_TARGETS];
2606 struct wined3d_render_pass_attachment_vk ds;
2607 uint32_t rt_mask;
2610 struct wined3d_render_pass_vk
2612 struct wine_rb_entry entry;
2613 struct wined3d_render_pass_key_vk key;
2614 VkRenderPass vk_render_pass;
2617 struct wined3d_pipeline_layout_key_vk
2619 VkDescriptorSetLayoutBinding *bindings;
2620 SIZE_T binding_count;
2623 struct wined3d_pipeline_layout_vk
2625 struct wine_rb_entry entry;
2626 struct wined3d_pipeline_layout_key_vk key;
2627 VkPipelineLayout vk_pipeline_layout;
2628 VkDescriptorSetLayout vk_set_layout;
2631 struct wined3d_graphics_pipeline_key_vk
2633 VkPipelineShaderStageCreateInfo stages[WINED3D_SHADER_TYPE_GRAPHICS_COUNT];
2634 VkVertexInputBindingDivisorDescriptionEXT divisors[MAX_ATTRIBS];
2635 VkVertexInputAttributeDescription attributes[MAX_ATTRIBS];
2636 VkVertexInputBindingDescription bindings[MAX_ATTRIBS];
2637 VkViewport viewports[WINED3D_MAX_VIEWPORTS];
2638 VkRect2D scissors[WINED3D_MAX_VIEWPORTS];
2639 VkSampleMask sample_mask;
2640 VkPipelineColorBlendAttachmentState blend_attachments[WINED3D_MAX_RENDER_TARGETS];
2642 VkPipelineVertexInputDivisorStateCreateInfoEXT divisor_desc;
2643 VkPipelineVertexInputStateCreateInfo input_desc;
2644 VkPipelineInputAssemblyStateCreateInfo ia_desc;
2645 VkPipelineTessellationStateCreateInfo ts_desc;
2646 VkPipelineViewportStateCreateInfo vp_desc;
2647 VkPipelineRasterizationStateCreateInfo rs_desc;
2648 VkPipelineMultisampleStateCreateInfo ms_desc;
2649 VkPipelineDepthStencilStateCreateInfo ds_desc;
2650 VkPipelineColorBlendStateCreateInfo blend_desc;
2651 VkPipelineDynamicStateCreateInfo dynamic_desc;
2653 VkGraphicsPipelineCreateInfo pipeline_desc;
2656 struct wined3d_graphics_pipeline_vk
2658 struct wine_rb_entry entry;
2659 struct wined3d_graphics_pipeline_key_vk key;
2660 VkPipeline vk_pipeline;
2663 enum wined3d_shader_descriptor_type
2665 WINED3D_SHADER_DESCRIPTOR_TYPE_CBV,
2666 WINED3D_SHADER_DESCRIPTOR_TYPE_SRV,
2667 WINED3D_SHADER_DESCRIPTOR_TYPE_UAV,
2668 WINED3D_SHADER_DESCRIPTOR_TYPE_UAV_COUNTER,
2669 WINED3D_SHADER_DESCRIPTOR_TYPE_SAMPLER,
2672 struct wined3d_shader_resource_binding
2674 enum wined3d_shader_type shader_type;
2675 enum wined3d_shader_descriptor_type shader_descriptor_type;
2676 size_t resource_idx;
2677 enum wined3d_shader_resource_type resource_type;
2678 enum wined3d_data_type resource_data_type;
2679 size_t binding_idx;
2682 struct wined3d_shader_resource_bindings
2684 struct wined3d_shader_resource_binding *bindings;
2685 SIZE_T size, count;
2688 struct wined3d_shader_descriptor_writes_vk
2690 VkWriteDescriptorSet *writes;
2691 SIZE_T size, count;
2694 struct wined3d_context_vk
2696 struct wined3d_context c;
2698 const struct wined3d_vk_info *vk_info;
2700 uint32_t update_compute_pipeline : 1;
2701 uint32_t update_stream_output : 1;
2702 uint32_t padding : 30;
2704 struct
2706 VkShaderModule vk_modules[WINED3D_SHADER_TYPE_GRAPHICS_COUNT];
2707 struct wined3d_graphics_pipeline_key_vk pipeline_key_vk;
2708 VkPipeline vk_pipeline;
2709 VkPipelineLayout vk_pipeline_layout;
2710 VkDescriptorSetLayout vk_set_layout;
2711 struct wined3d_shader_resource_bindings bindings;
2712 } graphics;
2714 struct
2716 VkPipeline vk_pipeline;
2717 VkPipelineLayout vk_pipeline_layout;
2718 VkDescriptorSetLayout vk_set_layout;
2719 struct wined3d_shader_resource_bindings bindings;
2720 } compute;
2722 VkCommandPool vk_command_pool;
2723 struct wined3d_command_buffer_vk current_command_buffer;
2724 uint64_t completed_command_buffer_id;
2725 VkDeviceSize retired_bo_size;
2727 struct
2729 struct wined3d_command_buffer_vk *buffers;
2730 SIZE_T buffers_size;
2731 SIZE_T buffer_count;
2732 } submitted;
2734 struct wined3d_shader_descriptor_writes_vk descriptor_writes;
2736 VkFramebuffer vk_framebuffer;
2737 VkRenderPass vk_render_pass;
2739 SIZE_T vk_descriptor_pools_size;
2740 SIZE_T vk_descriptor_pool_count;
2741 VkDescriptorPool *vk_descriptor_pools;
2743 VkSampleCountFlagBits sample_count;
2744 unsigned int rt_count;
2746 VkBuffer vk_so_counters[WINED3D_MAX_STREAM_OUTPUT_BUFFERS];
2747 VkDeviceSize vk_so_offsets[WINED3D_MAX_STREAM_OUTPUT_BUFFERS];
2748 struct wined3d_bo_vk vk_so_counter_bo;
2750 struct list render_pass_queries;
2751 struct list active_queries;
2752 struct list completed_query_pools;
2753 struct list free_occlusion_query_pools;
2754 struct list free_timestamp_query_pools;
2755 struct list free_pipeline_statistics_query_pools;
2756 struct list free_stream_output_statistics_query_pools;
2758 struct wined3d_retired_objects_vk retired;
2759 struct wine_rb_tree render_passes;
2760 struct wine_rb_tree pipeline_layouts;
2761 struct wine_rb_tree graphics_pipelines;
2762 struct wine_rb_tree bo_slab_available;
2765 static inline struct wined3d_context_vk *wined3d_context_vk(struct wined3d_context *context)
2767 return CONTAINING_RECORD(context, struct wined3d_context_vk, c);
2770 bool wined3d_context_vk_allocate_query(struct wined3d_context_vk *context_vk,
2771 enum wined3d_query_type type, struct wined3d_query_pool_idx_vk *pool_idx) DECLSPEC_HIDDEN;
2772 VkDeviceMemory wined3d_context_vk_allocate_vram_chunk_memory(struct wined3d_context_vk *context_vk,
2773 unsigned int pool, size_t size) DECLSPEC_HIDDEN;
2774 VkCommandBuffer wined3d_context_vk_apply_compute_state(struct wined3d_context_vk *context_vk,
2775 const struct wined3d_state *state, struct wined3d_buffer_vk *indirect_vk) DECLSPEC_HIDDEN;
2776 VkCommandBuffer wined3d_context_vk_apply_draw_state(struct wined3d_context_vk *context_vk,
2777 const struct wined3d_state *state, struct wined3d_buffer_vk *indirect_vk, bool indexed) DECLSPEC_HIDDEN;
2778 void wined3d_context_vk_cleanup(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2779 BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDeviceSize size,
2780 VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo) DECLSPEC_HIDDEN;
2781 BOOL wined3d_context_vk_create_image(struct wined3d_context_vk *context_vk, VkImageType vk_image_type,
2782 VkImageUsageFlags usage, VkFormat vk_format, unsigned int width, unsigned int height, unsigned int depth,
2783 unsigned int sample_count, unsigned int mip_levels, unsigned int layer_count, unsigned int flags,
2784 struct wined3d_image_vk *image) DECLSPEC_HIDDEN;
2785 void wined3d_context_vk_destroy_allocator_block(struct wined3d_context_vk *context_vk,
2786 struct wined3d_allocator_block *block, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2787 void wined3d_context_vk_destroy_bo(struct wined3d_context_vk *context_vk,
2788 const struct wined3d_bo_vk *bo) DECLSPEC_HIDDEN;
2789 void wined3d_context_vk_destroy_image(struct wined3d_context_vk *context_vk,
2790 struct wined3d_image_vk *image_vk) DECLSPEC_HIDDEN;
2791 void wined3d_context_vk_destroy_vk_buffer_view(struct wined3d_context_vk *context_vk,
2792 VkBufferView vk_view, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2793 void wined3d_context_vk_destroy_vk_framebuffer(struct wined3d_context_vk *context_vk,
2794 VkFramebuffer vk_framebuffer, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2795 void wined3d_context_vk_destroy_vk_image(struct wined3d_context_vk *context_vk,
2796 VkImage vk_image, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2797 void wined3d_context_vk_destroy_vk_image_view(struct wined3d_context_vk *context_vk,
2798 VkImageView vk_view, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2799 void wined3d_context_vk_destroy_vk_memory(struct wined3d_context_vk *context_vk,
2800 VkDeviceMemory vk_memory, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2801 void wined3d_context_vk_destroy_vk_sampler(struct wined3d_context_vk *context_vk,
2802 VkSampler vk_sampler, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2803 void wined3d_context_vk_destroy_vk_event(struct wined3d_context_vk *context_vk,
2804 VkEvent vk_event, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2805 void wined3d_context_vk_destroy_vk_pipeline(struct wined3d_context_vk *context_vk,
2806 VkPipeline vk_pipeline, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
2807 void wined3d_context_vk_end_current_render_pass(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2808 VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
2809 struct wined3d_pipeline_layout_vk *wined3d_context_vk_get_pipeline_layout(struct wined3d_context_vk *context_vk,
2810 VkDescriptorSetLayoutBinding *bindings, SIZE_T binding_count) DECLSPEC_HIDDEN;
2811 VkRenderPass wined3d_context_vk_get_render_pass(struct wined3d_context_vk *context_vk,
2812 const struct wined3d_fb_state *fb, unsigned int rt_count,
2813 bool depth_stencil, uint32_t clear_flags) DECLSPEC_HIDDEN;
2814 void wined3d_context_vk_image_barrier(struct wined3d_context_vk *context_vk,
2815 VkCommandBuffer vk_command_buffer, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask,
2816 VkAccessFlags src_access_mask, VkAccessFlags dst_access_mask, VkImageLayout old_layout,
2817 VkImageLayout new_layout, VkImage image, const VkImageSubresourceRange *range) DECLSPEC_HIDDEN;
2818 HRESULT wined3d_context_vk_init(struct wined3d_context_vk *context_vk,
2819 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
2820 void wined3d_context_vk_submit_command_buffer(struct wined3d_context_vk *context_vk,
2821 unsigned int wait_semaphore_count, const VkSemaphore *wait_semaphores, const VkPipelineStageFlags *wait_stages,
2822 unsigned int signal_semaphore_count, const VkSemaphore *signal_semaphores) DECLSPEC_HIDDEN;
2823 void wined3d_context_vk_wait_command_buffer(struct wined3d_context_vk *context_vk, uint64_t id) DECLSPEC_HIDDEN;
2824 VkDescriptorSet wined3d_context_vk_create_vk_descriptor_set(struct wined3d_context_vk *context_vk,
2825 VkDescriptorSetLayout vk_set_layout) DECLSPEC_HIDDEN;
2827 typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
2829 struct wined3d_state_entry
2831 unsigned int representative;
2832 APPLYSTATEFUNC apply;
2835 struct wined3d_state_entry_template
2837 unsigned int state;
2838 struct wined3d_state_entry content;
2839 unsigned int extension;
2842 #define WINED3D_FRAGMENT_CAP_PROJ_CONTROL 0x00000001
2843 #define WINED3D_FRAGMENT_CAP_SRGB_WRITE 0x00000002
2844 #define WINED3D_FRAGMENT_CAP_COLOR_KEY 0x00000004
2846 struct fragment_caps
2848 DWORD wined3d_caps;
2849 DWORD PrimitiveMiscCaps;
2850 DWORD TextureOpCaps;
2851 DWORD MaxTextureBlendStages;
2852 DWORD MaxSimultaneousTextures;
2855 #define GL_EXT_EMUL_ARB_MULTITEXTURE 0x00000001
2856 #define GL_EXT_EMUL_EXT_FOG_COORD 0x00000002
2858 struct wined3d_fragment_pipe_ops
2860 void (*fp_enable)(const struct wined3d_context *context, BOOL enable);
2861 void (*get_caps)(const struct wined3d_adapter *adapter, struct fragment_caps *caps);
2862 unsigned int (*get_emul_mask)(const struct wined3d_gl_info *gl_info);
2863 void *(*alloc_private)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2864 void (*free_private)(struct wined3d_device *device, struct wined3d_context *context);
2865 BOOL (*allocate_context_data)(struct wined3d_context *context);
2866 void (*free_context_data)(struct wined3d_context *context);
2867 BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
2868 const struct wined3d_state_entry_template *states;
2871 struct wined3d_vertex_caps
2873 BOOL xyzrhw;
2874 BOOL emulated_flatshading;
2875 BOOL ffp_generic_attributes;
2876 DWORD max_active_lights;
2877 DWORD max_vertex_blend_matrices;
2878 DWORD max_vertex_blend_matrix_index;
2879 DWORD vertex_processing_caps;
2880 DWORD fvf_caps;
2881 DWORD max_user_clip_planes;
2882 DWORD raster_caps;
2885 struct wined3d_vertex_pipe_ops
2887 void (*vp_enable)(const struct wined3d_context *context, BOOL enable);
2888 void (*vp_get_caps)(const struct wined3d_adapter *adapter, struct wined3d_vertex_caps *caps);
2889 unsigned int (*vp_get_emul_mask)(const struct wined3d_gl_info *gl_info);
2890 void *(*vp_alloc)(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv);
2891 void (*vp_free)(struct wined3d_device *device, struct wined3d_context *context);
2892 const struct wined3d_state_entry_template *vp_states;
2895 extern const struct wined3d_state_entry_template misc_state_template_gl[] DECLSPEC_HIDDEN;
2896 extern const struct wined3d_fragment_pipe_ops none_fragment_pipe DECLSPEC_HIDDEN;
2897 extern const struct wined3d_fragment_pipe_ops ffp_fragment_pipeline DECLSPEC_HIDDEN;
2898 extern const struct wined3d_fragment_pipe_ops atifs_fragment_pipeline DECLSPEC_HIDDEN;
2899 extern const struct wined3d_fragment_pipe_ops arbfp_fragment_pipeline DECLSPEC_HIDDEN;
2900 extern const struct wined3d_fragment_pipe_ops nvts_fragment_pipeline DECLSPEC_HIDDEN;
2901 extern const struct wined3d_fragment_pipe_ops nvrc_fragment_pipeline DECLSPEC_HIDDEN;
2902 extern const struct wined3d_fragment_pipe_ops glsl_fragment_pipe DECLSPEC_HIDDEN;
2904 const struct wined3d_fragment_pipe_ops *wined3d_spirv_fragment_pipe_init_vk(void) DECLSPEC_HIDDEN;
2906 extern const struct wined3d_vertex_pipe_ops none_vertex_pipe DECLSPEC_HIDDEN;
2907 extern const struct wined3d_vertex_pipe_ops ffp_vertex_pipe DECLSPEC_HIDDEN;
2908 extern const struct wined3d_vertex_pipe_ops glsl_vertex_pipe DECLSPEC_HIDDEN;
2910 const struct wined3d_vertex_pipe_ops *wined3d_spirv_vertex_pipe_init_vk(void) DECLSPEC_HIDDEN;
2912 /* "Base" state table */
2913 HRESULT compile_state_table(struct wined3d_state_entry *state_table, APPLYSTATEFUNC **dev_multistate_funcs,
2914 const struct wined3d_d3d_info *d3d_info, const BOOL *supported_extensions,
2915 const struct wined3d_vertex_pipe_ops *vertex, const struct wined3d_fragment_pipe_ops *fragment,
2916 const struct wined3d_state_entry_template *misc) DECLSPEC_HIDDEN;
2918 enum wined3d_blit_op
2920 WINED3D_BLIT_OP_COLOR_BLIT,
2921 WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST,
2922 WINED3D_BLIT_OP_COLOR_BLIT_CKEY,
2923 WINED3D_BLIT_OP_DEPTH_BLIT,
2924 WINED3D_BLIT_OP_RAW_BLIT,
2927 struct wined3d_blitter
2929 const struct wined3d_blitter_ops *ops;
2930 struct wined3d_blitter *next;
2933 struct wined3d_blitter_ops
2935 void (*blitter_destroy)(struct wined3d_blitter *blitter, struct wined3d_context *context);
2936 void (*blitter_clear)(struct wined3d_blitter *blitter, struct wined3d_device *device,
2937 unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects,
2938 const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil);
2939 DWORD (*blitter_blit)(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context,
2940 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location,
2941 const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
2942 DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key,
2943 enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format);
2946 void wined3d_arbfp_blitter_create(struct wined3d_blitter **next,
2947 const struct wined3d_device *device) DECLSPEC_HIDDEN;
2948 struct wined3d_blitter *wined3d_cpu_blitter_create(void) DECLSPEC_HIDDEN;
2949 void wined3d_fbo_blitter_create(struct wined3d_blitter **next,
2950 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2951 void wined3d_ffp_blitter_create(struct wined3d_blitter **next,
2952 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2953 struct wined3d_blitter *wined3d_glsl_blitter_create(struct wined3d_blitter **next,
2954 const struct wined3d_device *device) DECLSPEC_HIDDEN;
2955 void wined3d_raw_blitter_create(struct wined3d_blitter **next,
2956 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
2957 void wined3d_vk_blitter_create(struct wined3d_blitter **next) DECLSPEC_HIDDEN;
2959 BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other) DECLSPEC_HIDDEN;
2961 HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;
2962 DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
2963 void context_gl_apply_texture_draw_state(struct wined3d_context_gl *context_gl,
2964 struct wined3d_texture *texture, unsigned int sub_resource_idx, unsigned int location);
2965 void context_gl_resource_released(struct wined3d_device *device,
2966 GLuint name, BOOL rb_namespace) DECLSPEC_HIDDEN;
2967 void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id) DECLSPEC_HIDDEN;
2968 void context_invalidate_state(struct wined3d_context *context, unsigned int state_id) DECLSPEC_HIDDEN;
2969 void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
2970 void context_restore(struct wined3d_context *context, struct wined3d_texture *texture,
2971 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
2972 void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
2973 void context_state_drawbuf(struct wined3d_context *context,
2974 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2975 void context_state_fb(struct wined3d_context *context,
2976 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
2978 /*****************************************************************************
2979 * Internal representation of a light
2981 struct wined3d_light_info
2983 struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
2984 unsigned int OriginalIndex;
2985 LONG glIndex;
2986 BOOL enabled;
2988 /* Converted parms to speed up swapping lights */
2989 struct wined3d_vec4 position;
2990 struct wined3d_vec4 direction;
2991 float exponent;
2992 float cutoff;
2994 struct rb_entry entry;
2995 struct list changed_entry;
2996 bool changed;
2999 /* The default light parameters */
3000 extern const struct wined3d_light WINED3D_default_light DECLSPEC_HIDDEN;
3002 struct wined3d_pixel_format
3004 int iPixelFormat; /* WGL pixel format */
3005 int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
3006 int redSize, greenSize, blueSize, alphaSize, colorSize;
3007 int depthSize, stencilSize;
3008 BOOL windowDrawable;
3009 BOOL doubleBuffer;
3010 int auxBuffers;
3011 int numSamples;
3012 int swap_method;
3015 enum wined3d_pci_vendor
3017 HW_VENDOR_SOFTWARE = 0x0000,
3018 HW_VENDOR_AMD = 0x1002,
3019 HW_VENDOR_NVIDIA = 0x10de,
3020 HW_VENDOR_VMWARE = 0x15ad,
3021 HW_VENDOR_REDHAT = 0x1af4,
3022 HW_VENDOR_INTEL = 0x8086,
3025 enum wined3d_pci_device
3027 CARD_WINE = 0x0000,
3029 CARD_AMD_RAGE_128PRO = 0x5246,
3030 CARD_AMD_RADEON_7200 = 0x5144,
3031 CARD_AMD_RADEON_8500 = 0x514c,
3032 CARD_AMD_RADEON_9500 = 0x4144,
3033 CARD_AMD_RADEON_XPRESS_200M = 0x5955,
3034 CARD_AMD_RADEON_X700 = 0x5e4c,
3035 CARD_AMD_RADEON_X1600 = 0x71c2,
3036 CARD_AMD_RADEON_HD2350 = 0x94c7,
3037 CARD_AMD_RADEON_HD2600 = 0x9581,
3038 CARD_AMD_RADEON_HD2900 = 0x9400,
3039 CARD_AMD_RADEON_HD3200 = 0x9620,
3040 CARD_AMD_RADEON_HD3850 = 0x9515,
3041 CARD_AMD_RADEON_HD4200M = 0x9712,
3042 CARD_AMD_RADEON_HD4350 = 0x954f,
3043 CARD_AMD_RADEON_HD4600 = 0x9495,
3044 CARD_AMD_RADEON_HD4700 = 0x944e,
3045 CARD_AMD_RADEON_HD4800 = 0x944c,
3046 CARD_AMD_RADEON_HD5400 = 0x68f9,
3047 CARD_AMD_RADEON_HD5600 = 0x68d8,
3048 CARD_AMD_RADEON_HD5700 = 0x68be,
3049 CARD_AMD_RADEON_HD5800 = 0x6898,
3050 CARD_AMD_RADEON_HD5900 = 0x689c,
3051 CARD_AMD_RADEON_HD6300 = 0x9803,
3052 CARD_AMD_RADEON_HD6400 = 0x6770,
3053 CARD_AMD_RADEON_HD6490M = 0x6760,
3054 CARD_AMD_RADEON_HD6410D = 0x9644,
3055 CARD_AMD_RADEON_HD6480G = 0x9648,
3056 CARD_AMD_RADEON_HD6550D = 0x9640,
3057 CARD_AMD_RADEON_HD6600 = 0x6758,
3058 CARD_AMD_RADEON_HD6600M = 0x6741,
3059 CARD_AMD_RADEON_HD6700 = 0x68ba,
3060 CARD_AMD_RADEON_HD6800 = 0x6739,
3061 CARD_AMD_RADEON_HD6900 = 0x6719,
3062 CARD_AMD_RADEON_HD7660D = 0x9901,
3063 CARD_AMD_RADEON_HD7700 = 0x683d,
3064 CARD_AMD_RADEON_HD7800 = 0x6819,
3065 CARD_AMD_RADEON_HD7870 = 0x6818,
3066 CARD_AMD_RADEON_HD7900 = 0x679a,
3067 CARD_AMD_RADEON_HD8600M = 0x6660,
3068 CARD_AMD_RADEON_HD8670 = 0x6610,
3069 CARD_AMD_RADEON_HD8770 = 0x665c,
3070 CARD_AMD_RADEON_R3 = 0x9830,
3071 CARD_AMD_RADEON_R7 = 0x130f,
3072 CARD_AMD_RADEON_R9_285 = 0x6939,
3073 CARD_AMD_RADEON_R9_290 = 0x67b1,
3074 CARD_AMD_RADEON_R9_290X = 0x67b0,
3075 CARD_AMD_RADEON_R9_FURY = 0x7300,
3076 CARD_AMD_RADEON_R9_M370X = 0x6821,
3077 CARD_AMD_RADEON_R9_M380 = 0x6647,
3078 CARD_AMD_RADEON_R9_M395X = 0x6920,
3079 CARD_AMD_RADEON_RX_460 = 0x67ef,
3080 CARD_AMD_RADEON_RX_480 = 0x67df,
3081 CARD_AMD_RADEON_RX_VEGA_10 = 0x687f,
3082 CARD_AMD_RADEON_RX_VEGA_12 = 0x69af,
3083 CARD_AMD_RADEON_RAVEN = 0x15dd,
3084 CARD_AMD_RADEON_RX_VEGA_20 = 0x66af,
3085 CARD_AMD_RADEON_RX_NAVI_10 = 0x731f,
3086 CARD_AMD_RADEON_RX_NAVI_14 = 0x7340,
3087 CARD_AMD_RADEON_RX_NAVI_21 = 0x73bf,
3088 CARD_AMD_RADEON_PRO_V620 = 0x73a1,
3089 CARD_AMD_RADEON_PRO_V620_VF = 0x73ae,
3090 CARD_AMD_VANGOGH = 0x163f,
3091 CARD_AMD_RAPHAEL = 0x164e,
3093 CARD_NVIDIA_RIVA_128 = 0x0018,
3094 CARD_NVIDIA_RIVA_TNT = 0x0020,
3095 CARD_NVIDIA_RIVA_TNT2 = 0x0028,
3096 CARD_NVIDIA_GEFORCE = 0x0100,
3097 CARD_NVIDIA_GEFORCE2_MX = 0x0110,
3098 CARD_NVIDIA_GEFORCE2 = 0x0150,
3099 CARD_NVIDIA_GEFORCE3 = 0x0200,
3100 CARD_NVIDIA_GEFORCE4_MX = 0x0170,
3101 CARD_NVIDIA_GEFORCE4_TI4200 = 0x0253,
3102 CARD_NVIDIA_GEFORCEFX_5200 = 0x0320,
3103 CARD_NVIDIA_GEFORCEFX_5600 = 0x0312,
3104 CARD_NVIDIA_GEFORCEFX_5800 = 0x0302,
3105 CARD_NVIDIA_GEFORCE_6200 = 0x014f,
3106 CARD_NVIDIA_GEFORCE_6600GT = 0x0140,
3107 CARD_NVIDIA_GEFORCE_6800 = 0x0041,
3108 CARD_NVIDIA_GEFORCE_7300 = 0x01d7, /* GeForce Go 7300 */
3109 CARD_NVIDIA_GEFORCE_7400 = 0x01d8,
3110 CARD_NVIDIA_GEFORCE_7600 = 0x0391,
3111 CARD_NVIDIA_GEFORCE_7800GT = 0x0092,
3112 CARD_NVIDIA_GEFORCE_8200 = 0x0849, /* Other PCI ID 0x084b */
3113 CARD_NVIDIA_GEFORCE_8300GS = 0x0423,
3114 CARD_NVIDIA_GEFORCE_8400GS = 0x0404,
3115 CARD_NVIDIA_GEFORCE_8500GT = 0x0421,
3116 CARD_NVIDIA_GEFORCE_8600GT = 0x0402,
3117 CARD_NVIDIA_GEFORCE_8600MGT = 0x0407,
3118 CARD_NVIDIA_GEFORCE_8800GTS = 0x0193,
3119 CARD_NVIDIA_GEFORCE_8800GTX = 0x0191,
3120 CARD_NVIDIA_GEFORCE_9200 = 0x086d,
3121 CARD_NVIDIA_GEFORCE_9300 = 0x086c,
3122 CARD_NVIDIA_GEFORCE_9400M = 0x0863,
3123 CARD_NVIDIA_GEFORCE_9400GT = 0x042c,
3124 CARD_NVIDIA_GEFORCE_9500GT = 0x0640,
3125 CARD_NVIDIA_GEFORCE_9600GT = 0x0622,
3126 CARD_NVIDIA_GEFORCE_9700MGT = 0x064a,
3127 CARD_NVIDIA_GEFORCE_9800GT = 0x0614,
3128 CARD_NVIDIA_GEFORCE_210 = 0x0a23,
3129 CARD_NVIDIA_GEFORCE_GT220 = 0x0a20,
3130 CARD_NVIDIA_GEFORCE_GT240 = 0x0ca3,
3131 CARD_NVIDIA_GEFORCE_GTS250 = 0x0615,
3132 CARD_NVIDIA_GEFORCE_GTX260 = 0x05e2,
3133 CARD_NVIDIA_GEFORCE_GTX275 = 0x05e6,
3134 CARD_NVIDIA_GEFORCE_GTX280 = 0x05e1,
3135 CARD_NVIDIA_GEFORCE_315M = 0x0a7a,
3136 CARD_NVIDIA_GEFORCE_320M = 0x08a3,
3137 CARD_NVIDIA_GEFORCE_GT320M = 0x0a2d,
3138 CARD_NVIDIA_GEFORCE_GT325M = 0x0a35,
3139 CARD_NVIDIA_GEFORCE_GT330 = 0x0ca0,
3140 CARD_NVIDIA_GEFORCE_GTS350M = 0x0cb0,
3141 CARD_NVIDIA_GEFORCE_410M = 0x1055,
3142 CARD_NVIDIA_GEFORCE_GT420 = 0x0de2,
3143 CARD_NVIDIA_GEFORCE_GT425M = 0x0df0,
3144 CARD_NVIDIA_GEFORCE_GT430 = 0x0de1,
3145 CARD_NVIDIA_GEFORCE_GT440 = 0x0de0,
3146 CARD_NVIDIA_GEFORCE_GTS450 = 0x0dc4,
3147 CARD_NVIDIA_GEFORCE_GTX460 = 0x0e22,
3148 CARD_NVIDIA_GEFORCE_GTX460M = 0x0dd1,
3149 CARD_NVIDIA_GEFORCE_GTX465 = 0x06c4,
3150 CARD_NVIDIA_GEFORCE_GTX470 = 0x06cd,
3151 CARD_NVIDIA_GEFORCE_GTX480 = 0x06c0,
3152 CARD_NVIDIA_GEFORCE_GT520 = 0x1040,
3153 CARD_NVIDIA_GEFORCE_GT525M = 0x0dec,
3154 CARD_NVIDIA_GEFORCE_GT540M = 0x0df4,
3155 CARD_NVIDIA_GEFORCE_GTX550 = 0x1244,
3156 CARD_NVIDIA_GEFORCE_GT555M = 0x04b8,
3157 CARD_NVIDIA_GEFORCE_GTX560TI = 0x1200,
3158 CARD_NVIDIA_GEFORCE_GTX560M = 0x1251,
3159 CARD_NVIDIA_GEFORCE_GTX560 = 0x1201,
3160 CARD_NVIDIA_GEFORCE_GTX570 = 0x1081,
3161 CARD_NVIDIA_GEFORCE_GTX580 = 0x1080,
3162 CARD_NVIDIA_GEFORCE_GT610 = 0x104a,
3163 CARD_NVIDIA_GEFORCE_GT630 = 0x0f00,
3164 CARD_NVIDIA_GEFORCE_GT630M = 0x0de9,
3165 CARD_NVIDIA_GEFORCE_GT640 = 0x0fc1,
3166 CARD_NVIDIA_GEFORCE_GT640M = 0x0fd2,
3167 CARD_NVIDIA_GEFORCE_GT650M = 0x0fd1,
3168 CARD_NVIDIA_GEFORCE_GTX650 = 0x0fc6,
3169 CARD_NVIDIA_GEFORCE_GTX650TI = 0x11c6,
3170 CARD_NVIDIA_GEFORCE_GTX660 = 0x11c0,
3171 CARD_NVIDIA_GEFORCE_GTX660M = 0x0fd4,
3172 CARD_NVIDIA_GEFORCE_GTX660TI = 0x1183,
3173 CARD_NVIDIA_GEFORCE_GTX670 = 0x1189,
3174 CARD_NVIDIA_GEFORCE_GTX670MX = 0x11a1,
3175 CARD_NVIDIA_GEFORCE_GTX675MX_1 = 0x11a7,
3176 CARD_NVIDIA_GEFORCE_GTX675MX_2 = 0x11a2,
3177 CARD_NVIDIA_GEFORCE_GTX680 = 0x1180,
3178 CARD_NVIDIA_GEFORCE_GTX690 = 0x1188,
3179 CARD_NVIDIA_GEFORCE_GT720 = 0x128b,
3180 CARD_NVIDIA_GEFORCE_GT730 = 0x1287,
3181 CARD_NVIDIA_GEFORCE_GT730M = 0x0fe1,
3182 CARD_NVIDIA_GEFORCE_GT740M = 0x1292,
3183 CARD_NVIDIA_GEFORCE_GT750M = 0x0fe9,
3184 CARD_NVIDIA_GEFORCE_GT755M = 0x0fcd,
3185 CARD_NVIDIA_GEFORCE_GTX750 = 0x1381,
3186 CARD_NVIDIA_GEFORCE_GTX750TI = 0x1380,
3187 CARD_NVIDIA_GEFORCE_GTX760 = 0x1187,
3188 CARD_NVIDIA_GEFORCE_GTX760TI = 0x1193,
3189 CARD_NVIDIA_GEFORCE_GTX765M = 0x11e2,
3190 CARD_NVIDIA_GEFORCE_GTX770M = 0x11e0,
3191 CARD_NVIDIA_GEFORCE_GTX770 = 0x1184,
3192 CARD_NVIDIA_GEFORCE_GTX775M = 0x119d,
3193 CARD_NVIDIA_GEFORCE_GTX780 = 0x1004,
3194 CARD_NVIDIA_GEFORCE_GTX780M = 0x119e,
3195 CARD_NVIDIA_GEFORCE_GTX780TI = 0x100a,
3196 CARD_NVIDIA_GEFORCE_GTXTITAN = 0x1005,
3197 CARD_NVIDIA_GEFORCE_GTXTITANB = 0x100c,
3198 CARD_NVIDIA_GEFORCE_GTXTITANX = 0x17c2,
3199 CARD_NVIDIA_GEFORCE_GTXTITANZ = 0x1001,
3200 CARD_NVIDIA_GEFORCE_820M = 0x0fed,
3201 CARD_NVIDIA_GEFORCE_830M = 0x1340,
3202 CARD_NVIDIA_GEFORCE_840M = 0x1341,
3203 CARD_NVIDIA_GEFORCE_845M = 0x1344,
3204 CARD_NVIDIA_GEFORCE_GTX850M = 0x1391,
3205 CARD_NVIDIA_GEFORCE_GTX860M = 0x1392, /* Other PCI ID 0x119a */
3206 CARD_NVIDIA_GEFORCE_GTX870M = 0x1199,
3207 CARD_NVIDIA_GEFORCE_GTX880M = 0x1198,
3208 CARD_NVIDIA_GEFORCE_940M = 0x1347,
3209 CARD_NVIDIA_GEFORCE_GTX950 = 0x1402,
3210 CARD_NVIDIA_GEFORCE_GTX950M = 0x139a,
3211 CARD_NVIDIA_GEFORCE_GTX960 = 0x1401,
3212 CARD_NVIDIA_GEFORCE_GTX960M = 0x139b,
3213 CARD_NVIDIA_GEFORCE_GTX970 = 0x13c2,
3214 CARD_NVIDIA_GEFORCE_GTX970M = 0x13d8,
3215 CARD_NVIDIA_GEFORCE_GTX980 = 0x13c0,
3216 CARD_NVIDIA_GEFORCE_GTX980TI = 0x17c8,
3217 CARD_NVIDIA_GEFORCE_GT1030 = 0x1d01,
3218 CARD_NVIDIA_GEFORCE_GTX1050 = 0x1c81,
3219 CARD_NVIDIA_GEFORCE_GTX1050TI = 0x1c82,
3220 CARD_NVIDIA_GEFORCE_GTX1060_3GB = 0x1c02,
3221 CARD_NVIDIA_GEFORCE_GTX1060 = 0x1c03,
3222 CARD_NVIDIA_GEFORCE_GTX1060M = 0x1c20,
3223 CARD_NVIDIA_GEFORCE_GTX1070 = 0x1b81,
3224 CARD_NVIDIA_GEFORCE_GTX1080 = 0x1b80,
3225 CARD_NVIDIA_GEFORCE_GTX1080M = 0x1be0,
3226 CARD_NVIDIA_GEFORCE_GTX1080TI = 0x1b06,
3227 CARD_NVIDIA_TITANX_PASCAL = 0x1b00,
3228 CARD_NVIDIA_TITANV = 0x1d81,
3229 CARD_NVIDIA_GEFORCE_GTX1650SUPER= 0x2187,
3230 CARD_NVIDIA_GEFORCE_GTX1660SUPER= 0x21c4,
3231 CARD_NVIDIA_GEFORCE_GTX1660TI = 0x2182,
3232 CARD_NVIDIA_GEFORCE_RTX2060 = 0x1f08,
3233 CARD_NVIDIA_GEFORCE_RTX2070 = 0x1f07,
3234 CARD_NVIDIA_GEFORCE_RTX2080 = 0x1e87,
3235 CARD_NVIDIA_GEFORCE_RTX2080TI = 0x1e07,
3236 CARD_NVIDIA_TESLA_T4 = 0x1eb8,
3237 CARD_NVIDIA_AMPERE_A10 = 0x2236,
3239 CARD_REDHAT_VIRGL = 0x1010,
3241 CARD_VMWARE_SVGA3D = 0x0405,
3243 CARD_INTEL_830M = 0x3577,
3244 CARD_INTEL_855GM = 0x3582,
3245 CARD_INTEL_845G = 0x2562,
3246 CARD_INTEL_865G = 0x2572,
3247 CARD_INTEL_915G = 0x2582,
3248 CARD_INTEL_E7221G = 0x258a,
3249 CARD_INTEL_915GM = 0x2592,
3250 CARD_INTEL_945G = 0x2772,
3251 CARD_INTEL_945GM = 0x27a2,
3252 CARD_INTEL_945GME = 0x27ae,
3253 CARD_INTEL_Q35 = 0x29b2,
3254 CARD_INTEL_G33 = 0x29c2,
3255 CARD_INTEL_Q33 = 0x29d2,
3256 CARD_INTEL_PNVG = 0xa001,
3257 CARD_INTEL_PNVM = 0xa011,
3258 CARD_INTEL_965Q = 0x2992,
3259 CARD_INTEL_965G = 0x2982,
3260 CARD_INTEL_946GZ = 0x2972,
3261 CARD_INTEL_965GM = 0x2a02,
3262 CARD_INTEL_965GME = 0x2a12,
3263 CARD_INTEL_GM45 = 0x2a42,
3264 CARD_INTEL_IGD = 0x2e02,
3265 CARD_INTEL_Q45 = 0x2e12,
3266 CARD_INTEL_G45 = 0x2e22,
3267 CARD_INTEL_G41 = 0x2e32,
3268 CARD_INTEL_B43 = 0x2e92,
3269 CARD_INTEL_ILKD = 0x0042,
3270 CARD_INTEL_ILKM = 0x0046,
3271 CARD_INTEL_SNBD = 0x0122,
3272 CARD_INTEL_SNBM = 0x0126,
3273 CARD_INTEL_SNBS = 0x010a,
3274 CARD_INTEL_IVBD = 0x0162,
3275 CARD_INTEL_IVBM = 0x0166,
3276 CARD_INTEL_IVBS = 0x015a,
3277 CARD_INTEL_HWD = 0x0412,
3278 CARD_INTEL_HWM = 0x0416,
3279 CARD_INTEL_HD5000_1 = 0x0a26,
3280 CARD_INTEL_HD5000_2 = 0x0422,
3281 CARD_INTEL_I5100_1 = 0x0a22,
3282 CARD_INTEL_I5100_2 = 0x0a2a,
3283 CARD_INTEL_I5100_3 = 0x0a2b,
3284 CARD_INTEL_I5100_4 = 0x0a2e,
3285 CARD_INTEL_IP5200_1 = 0x0d22,
3286 CARD_INTEL_IP5200_2 = 0x0d26,
3287 CARD_INTEL_IP5200_3 = 0x0d2a,
3288 CARD_INTEL_IP5200_4 = 0x0d2b,
3289 CARD_INTEL_IP5200_5 = 0x0d2e,
3290 CARD_INTEL_IP5200_6 = 0x0c22,
3291 CARD_INTEL_HD5300 = 0x161e,
3292 CARD_INTEL_HD5500 = 0x1616,
3293 CARD_INTEL_HD5600 = 0x1612,
3294 CARD_INTEL_HD6000 = 0x1626,
3295 CARD_INTEL_I6100 = 0x162b,
3296 CARD_INTEL_IP6200 = 0x1622,
3297 CARD_INTEL_IPP6300 = 0x162a,
3298 CARD_INTEL_HD510_1 = 0x1902,
3299 CARD_INTEL_HD510_2 = 0x1906,
3300 CARD_INTEL_HD510_3 = 0x190b,
3301 CARD_INTEL_HD515 = 0x191e,
3302 CARD_INTEL_HD520_1 = 0x1916,
3303 CARD_INTEL_HD520_2 = 0x1921,
3304 CARD_INTEL_HD530_1 = 0x1912,
3305 CARD_INTEL_HD530_2 = 0x191b,
3306 CARD_INTEL_HDP530 = 0x191d,
3307 CARD_INTEL_I540 = 0x1926,
3308 CARD_INTEL_I550 = 0x1927,
3309 CARD_INTEL_I555 = 0x192b,
3310 CARD_INTEL_IP555 = 0x192d,
3311 CARD_INTEL_IP580_1 = 0x1932,
3312 CARD_INTEL_IP580_2 = 0x193b,
3313 CARD_INTEL_IPP580_1 = 0x193a,
3314 CARD_INTEL_IPP580_2 = 0x193d,
3315 CARD_INTEL_UHD617 = 0x87c0,
3316 CARD_INTEL_UHD620 = 0x3ea0,
3317 CARD_INTEL_HD615 = 0x591e,
3318 CARD_INTEL_HD620 = 0x5916,
3319 CARD_INTEL_HD630_1 = 0x5912,
3320 CARD_INTEL_HD630_2 = 0x591b,
3321 CARD_INTEL_UHD630_1 = 0x3e9b,
3322 CARD_INTEL_UHD630_2 = 0x3e91,
3325 struct wined3d_fbo_ops
3327 GLboolean (WINE_GLAPI *glIsRenderbuffer)(GLuint renderbuffer);
3328 void (WINE_GLAPI *glBindRenderbuffer)(GLenum target, GLuint renderbuffer);
3329 void (WINE_GLAPI *glDeleteRenderbuffers)(GLsizei n, const GLuint *renderbuffers);
3330 void (WINE_GLAPI *glGenRenderbuffers)(GLsizei n, GLuint *renderbuffers);
3331 void (WINE_GLAPI *glRenderbufferStorage)(GLenum target, GLenum internalformat,
3332 GLsizei width, GLsizei height);
3333 void (WINE_GLAPI *glRenderbufferStorageMultisample)(GLenum target, GLsizei samples,
3334 GLenum internalformat, GLsizei width, GLsizei height);
3335 void (WINE_GLAPI *glGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint *params);
3336 GLboolean (WINE_GLAPI *glIsFramebuffer)(GLuint framebuffer);
3337 void (WINE_GLAPI *glBindFramebuffer)(GLenum target, GLuint framebuffer);
3338 void (WINE_GLAPI *glDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers);
3339 void (WINE_GLAPI *glGenFramebuffers)(GLsizei n, GLuint *framebuffers);
3340 GLenum (WINE_GLAPI *glCheckFramebufferStatus)(GLenum target);
3341 void (WINE_GLAPI *glFramebufferTexture)(GLenum target, GLenum attachment,
3342 GLuint texture, GLint level);
3343 void (WINE_GLAPI *glFramebufferTexture1D)(GLenum target, GLenum attachment,
3344 GLenum textarget, GLuint texture, GLint level);
3345 void (WINE_GLAPI *glFramebufferTexture2D)(GLenum target, GLenum attachment,
3346 GLenum textarget, GLuint texture, GLint level);
3347 void (WINE_GLAPI *glFramebufferTexture3D)(GLenum target, GLenum attachment,
3348 GLenum textarget, GLuint texture, GLint level, GLint layer);
3349 void (WINE_GLAPI *glFramebufferTextureLayer)(GLenum target, GLenum attachment,
3350 GLuint texture, GLint level, GLint layer);
3351 void (WINE_GLAPI *glFramebufferRenderbuffer)(GLenum target, GLenum attachment,
3352 GLenum renderbuffertarget, GLuint renderbuffer);
3353 void (WINE_GLAPI *glGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment,
3354 GLenum pname, GLint *params);
3355 void (WINE_GLAPI *glBlitFramebuffer)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
3356 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
3357 void (WINE_GLAPI *glGenerateMipmap)(GLenum target);
3360 struct wined3d_gl_limits
3362 UINT buffers;
3363 UINT lights;
3364 UINT textures;
3365 UINT texture_coords;
3366 unsigned int uniform_blocks[WINED3D_SHADER_TYPE_COUNT];
3367 unsigned int samplers[WINED3D_SHADER_TYPE_COUNT];
3368 unsigned int graphics_samplers;
3369 unsigned int combined_samplers;
3370 UINT general_combiners;
3371 UINT user_clip_distances;
3372 unsigned int texture_size;
3373 UINT texture3d_size;
3374 UINT anisotropy;
3375 float shininess;
3376 UINT samples;
3377 UINT vertex_attribs;
3379 unsigned int texture_buffer_offset_alignment;
3381 unsigned int framebuffer_width;
3382 unsigned int framebuffer_height;
3383 unsigned int viewport_subpixel_bits;
3385 UINT glsl_varyings;
3386 UINT glsl_vs_float_constants;
3387 UINT glsl_ps_float_constants;
3389 UINT arb_vs_float_constants;
3390 UINT arb_vs_native_constants;
3391 UINT arb_vs_instructions;
3392 UINT arb_vs_temps;
3393 UINT arb_ps_float_constants;
3394 UINT arb_ps_local_constants;
3395 UINT arb_ps_native_constants;
3396 UINT arb_ps_instructions;
3397 UINT arb_ps_temps;
3400 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits *gl_limits,
3401 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
3402 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits *gl_limits,
3403 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
3405 struct wined3d_gl_info
3407 unsigned int selected_gl_version;
3408 unsigned int glsl_version;
3409 struct wined3d_gl_limits limits;
3410 DWORD reserved_glsl_constants, reserved_arb_constants;
3411 DWORD quirks;
3412 BOOL supported[WINED3D_GL_EXT_COUNT];
3413 GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP + 1];
3414 float filling_convention_offset;
3416 HGLRC (WINAPI *p_wglCreateContextAttribsARB)(HDC dc, HGLRC share, const GLint *attribs);
3417 struct opengl_funcs gl_ops;
3418 struct wined3d_fbo_ops fbo_ops;
3420 void (WINE_GLAPI *p_glDisableWINE)(GLenum cap);
3421 void (WINE_GLAPI *p_glEnableWINE)(GLenum cap);
3424 static inline BOOL wined3d_fence_supported(const struct wined3d_gl_info *gl_info)
3426 return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE];
3429 /* The driver names reflect the lowest GPU supported
3430 * by a certain driver, so DRIVER_AMD_R300 supports
3431 * R3xx, R4xx and R5xx GPUs. */
3432 enum wined3d_display_driver
3434 DRIVER_AMD_RAGE_128PRO,
3435 DRIVER_AMD_R100,
3436 DRIVER_AMD_R300,
3437 DRIVER_AMD_R600,
3438 DRIVER_AMD_RX,
3439 DRIVER_INTEL_GMA800,
3440 DRIVER_INTEL_GMA900,
3441 DRIVER_INTEL_GMA950,
3442 DRIVER_INTEL_GMA3000,
3443 DRIVER_INTEL_HD4000,
3444 DRIVER_NVIDIA_TNT,
3445 DRIVER_NVIDIA_GEFORCE2MX,
3446 DRIVER_NVIDIA_GEFORCEFX,
3447 DRIVER_NVIDIA_GEFORCE6,
3448 DRIVER_NVIDIA_GEFORCE8,
3449 DRIVER_NVIDIA_FERMI,
3450 DRIVER_NVIDIA_KEPLER,
3451 DRIVER_REDHAT_VIRGL,
3452 DRIVER_VMWARE,
3453 DRIVER_WINE,
3454 DRIVER_UNKNOWN,
3457 struct wined3d_gpu_description
3459 enum wined3d_pci_vendor vendor;
3460 enum wined3d_pci_device device;
3461 const char *description;
3462 enum wined3d_display_driver driver;
3463 unsigned int vidmem;
3466 const struct wined3d_gpu_description *wined3d_get_gpu_description(enum wined3d_pci_vendor vendor,
3467 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
3468 const struct wined3d_gpu_description *wined3d_get_user_override_gpu_description(enum wined3d_pci_vendor vendor,
3469 enum wined3d_pci_device device) DECLSPEC_HIDDEN;
3470 enum wined3d_pci_device wined3d_gpu_from_feature_level(enum wined3d_pci_vendor *vendor,
3471 enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
3473 /* 512 in Direct3D 8/9, 128 in DXGI. */
3474 #define WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH 512
3476 struct wined3d_driver_info
3478 enum wined3d_pci_vendor vendor;
3479 enum wined3d_pci_device device;
3480 const char *name;
3481 char description[WINED3D_MAX_DEVICE_IDENTIFIER_LENGTH];
3482 UINT64 vram_bytes;
3483 UINT64 sysmem_bytes;
3484 unsigned int version_high;
3485 unsigned int version_low;
3488 bool wined3d_driver_info_init(struct wined3d_driver_info *driver_info,
3489 const struct wined3d_gpu_description *gpu_description, enum wined3d_feature_level feature_level,
3490 UINT64 vram_bytes, UINT64 sysmem_bytes) DECLSPEC_HIDDEN;
3492 #define UPLOAD_BO_UPLOAD_ON_UNMAP 0x1
3493 #define UPLOAD_BO_RENAME_ON_UNMAP 0x2
3494 #define UPLOAD_BO_FREE_ON_UNMAP 0x4
3496 struct upload_bo
3498 struct wined3d_const_bo_address addr;
3499 uint32_t flags;
3502 struct wined3d_adapter_ops
3504 void (*adapter_destroy)(struct wined3d_adapter *adapter);
3505 HRESULT (*adapter_create_device)(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
3506 enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
3507 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
3508 struct wined3d_device_parent *device_parent, struct wined3d_device **device);
3509 void (*adapter_destroy_device)(struct wined3d_device *device);
3510 struct wined3d_context *(*adapter_acquire_context)(struct wined3d_device *device,
3511 struct wined3d_texture *texture, unsigned int sub_resource_idx);
3512 void (*adapter_release_context)(struct wined3d_context *context);
3513 void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps);
3514 BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
3515 const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
3516 const struct wined3d_format *ds_format);
3517 HRESULT (*adapter_init_3d)(struct wined3d_device *device);
3518 void (*adapter_uninit_3d)(struct wined3d_device *device);
3519 void *(*adapter_map_bo_address)(struct wined3d_context *context,
3520 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags);
3521 void (*adapter_unmap_bo_address)(struct wined3d_context *context, const struct wined3d_bo_address *data,
3522 unsigned int range_count, const struct wined3d_range *ranges);
3523 void (*adapter_copy_bo_address)(struct wined3d_context *context,
3524 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
3525 unsigned int range_count, const struct wined3d_range *ranges);
3526 void (*adapter_flush_bo_address)(struct wined3d_context *context,
3527 const struct wined3d_const_bo_address *data, size_t size);
3528 bool (*adapter_alloc_bo)(struct wined3d_device *device, struct wined3d_resource *resource,
3529 unsigned int sub_resource_idx, struct wined3d_bo_address *addr);
3530 void (*adapter_destroy_bo)(struct wined3d_context *context, struct wined3d_bo *bo);
3531 HRESULT (*adapter_create_swapchain)(struct wined3d_device *device,
3532 struct wined3d_swapchain_desc *desc,
3533 struct wined3d_swapchain_state_parent *state_parent, void *parent,
3534 const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain);
3535 void (*adapter_destroy_swapchain)(struct wined3d_swapchain *swapchain);
3536 HRESULT (*adapter_create_buffer)(struct wined3d_device *device, const struct wined3d_buffer_desc *desc,
3537 const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops,
3538 struct wined3d_buffer **buffer);
3539 void (*adapter_destroy_buffer)(struct wined3d_buffer *buffer);
3540 HRESULT (*adapter_create_texture)(struct wined3d_device *device, const struct wined3d_resource_desc *desc,
3541 unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent,
3542 const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture);
3543 void (*adapter_destroy_texture)(struct wined3d_texture *texture);
3544 HRESULT (*adapter_create_rendertarget_view)(const struct wined3d_view_desc *desc,
3545 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3546 struct wined3d_rendertarget_view **view);
3547 void (*adapter_destroy_rendertarget_view)(struct wined3d_rendertarget_view *view);
3548 HRESULT (*adapter_create_shader_resource_view)(const struct wined3d_view_desc *desc,
3549 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3550 struct wined3d_shader_resource_view **view);
3551 void (*adapter_destroy_shader_resource_view)(struct wined3d_shader_resource_view *view);
3552 HRESULT (*adapter_create_unordered_access_view)(const struct wined3d_view_desc *desc,
3553 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3554 struct wined3d_unordered_access_view **view);
3555 void (*adapter_destroy_unordered_access_view)(struct wined3d_unordered_access_view *view);
3556 HRESULT (*adapter_create_sampler)(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
3557 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler);
3558 void (*adapter_destroy_sampler)(struct wined3d_sampler *sampler);
3559 HRESULT (*adapter_create_query)(struct wined3d_device *device, enum wined3d_query_type type,
3560 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query);
3561 void (*adapter_destroy_query)(struct wined3d_query *query);
3562 void (*adapter_flush_context)(struct wined3d_context *context);
3563 void (*adapter_draw_primitive)(struct wined3d_device *device, const struct wined3d_state *state,
3564 const struct wined3d_draw_parameters *parameters);
3565 void (*adapter_dispatch_compute)(struct wined3d_device *device, const struct wined3d_state *state,
3566 const struct wined3d_dispatch_parameters *parameters);
3567 void (*adapter_clear_uav)(struct wined3d_context *context,
3568 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp);
3569 void (*adapter_generate_mipmap)(struct wined3d_context *context, struct wined3d_shader_resource_view *view);
3572 struct wined3d_output
3574 unsigned int ordinal;
3575 WCHAR device_name[CCHDEVICENAME];
3576 struct wined3d_adapter *adapter;
3577 enum wined3d_format_id screen_format;
3579 D3DKMT_HANDLE kmt_device;
3580 D3DDDI_VIDEO_PRESENT_SOURCE_ID vidpn_source_id;
3582 struct wined3d_display_mode *modes;
3583 SIZE_T mode_count, modes_size;
3584 bool modes_valid;
3587 HRESULT wined3d_output_get_gamma_ramp(struct wined3d_output *output, struct wined3d_gamma_ramp *ramp) DECLSPEC_HIDDEN;
3589 #ifdef _WIN64
3590 #define MAX_PERSISTENT_MAPPED_BYTES I64_MAX
3591 #else
3592 #define MAX_PERSISTENT_MAPPED_BYTES (128 * 1024 * 1024)
3593 #endif
3595 /* The adapter structure */
3596 struct wined3d_adapter
3598 unsigned int ordinal;
3600 struct wined3d_gl_info gl_info;
3601 struct wined3d_d3d_info d3d_info;
3602 struct wined3d_driver_info driver_info;
3603 struct wined3d_output *outputs;
3604 SIZE_T output_count, outputs_size;
3605 D3DKMT_HANDLE kmt_adapter;
3606 UINT64 vram_bytes_used;
3607 GUID driver_uuid;
3608 GUID device_uuid;
3609 LUID luid;
3611 void *formats;
3612 size_t format_size;
3614 ssize_t mapped_size;
3616 const struct wined3d_vertex_pipe_ops *vertex_pipe;
3617 const struct wined3d_fragment_pipe_ops *fragment_pipe;
3618 const struct wined3d_state_entry_template *misc_state_template;
3619 const struct wined3d_shader_backend_ops *shader_backend;
3620 const struct wined3d_adapter_ops *adapter_ops;
3623 BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
3624 const struct wined3d_adapter_ops *adapter_ops) DECLSPEC_HIDDEN;
3625 void wined3d_adapter_cleanup(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
3626 BOOL wined3d_get_primary_adapter_luid(LUID *luid) DECLSPEC_HIDDEN;
3628 struct wined3d_adapter_gl
3630 struct wined3d_adapter a;
3632 struct wined3d_pixel_format *pixel_formats;
3633 unsigned int pixel_format_count;
3636 static inline struct wined3d_adapter_gl *wined3d_adapter_gl(struct wined3d_adapter *adapter)
3638 return CONTAINING_RECORD(adapter, struct wined3d_adapter_gl, a);
3641 static inline const struct wined3d_adapter_gl *wined3d_adapter_gl_const(const struct wined3d_adapter *adapter)
3643 return CONTAINING_RECORD(adapter, struct wined3d_adapter_gl, a);
3646 struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal,
3647 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
3649 struct wined3d_adapter_vk
3651 struct wined3d_adapter a;
3653 struct wined3d_vk_info vk_info;
3654 unsigned int device_extension_count;
3655 const char **device_extensions;
3656 VkPhysicalDevice physical_device;
3658 VkPhysicalDeviceLimits device_limits;
3659 VkPhysicalDeviceMemoryProperties memory_properties;
3662 static inline struct wined3d_adapter_vk *wined3d_adapter_vk(struct wined3d_adapter *adapter)
3664 return CONTAINING_RECORD(adapter, struct wined3d_adapter_vk, a);
3667 struct wined3d_adapter *wined3d_adapter_vk_create(unsigned int ordinal,
3668 unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
3669 unsigned int wined3d_adapter_vk_get_memory_type_index(const struct wined3d_adapter_vk *adapter_vk,
3670 uint32_t memory_type_mask, VkMemoryPropertyFlags flags) DECLSPEC_HIDDEN;
3671 void adapter_vk_copy_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *dst,
3672 const struct wined3d_bo_address *src,
3673 unsigned int range_count, const struct wined3d_range *ranges) DECLSPEC_HIDDEN;
3675 struct wined3d_caps_gl_ctx
3677 HDC dc;
3678 HWND wnd;
3679 HGLRC gl_ctx;
3680 HDC restore_dc;
3681 HGLRC restore_gl_ctx;
3683 const struct wined3d_gl_info *gl_info;
3684 GLuint test_vbo;
3685 GLuint test_program_id;
3687 const struct wined3d_gpu_description *gpu_description;
3688 UINT64 vram_bytes;
3691 BOOL wined3d_adapter_gl_init_format_info(struct wined3d_adapter *adapter,
3692 struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
3693 BOOL wined3d_adapter_no3d_init_format_info(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
3694 BOOL wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk *adapter_vk,
3695 const struct wined3d_vk_info *vk_info) DECLSPEC_HIDDEN;
3696 ssize_t adapter_adjust_mapped_memory(struct wined3d_adapter *adapter, ssize_t size) DECLSPEC_HIDDEN;
3697 UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount) DECLSPEC_HIDDEN;
3699 BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx *ctx) DECLSPEC_HIDDEN;
3700 bool wined3d_caps_gl_ctx_test_filling_convention(struct wined3d_caps_gl_ctx *ctx, float offset) DECLSPEC_HIDDEN;
3702 void install_gl_compat_wrapper(struct wined3d_gl_info *gl_info, enum wined3d_gl_extension ext) DECLSPEC_HIDDEN;
3704 enum wined3d_projection_type
3706 WINED3D_PROJECTION_NONE = 0,
3707 WINED3D_PROJECTION_COUNT3 = 1,
3708 WINED3D_PROJECTION_COUNT4 = 2
3711 /*****************************************************************************
3712 * Fixed function pipeline replacements
3714 #define ARG_UNUSED 0xff
3715 struct texture_stage_op
3717 unsigned cop : 8;
3718 unsigned carg1 : 8;
3719 unsigned carg2 : 8;
3720 unsigned carg0 : 8;
3722 unsigned aop : 8;
3723 unsigned aarg1 : 8;
3724 unsigned aarg2 : 8;
3725 unsigned aarg0 : 8;
3727 struct color_fixup_desc color_fixup;
3728 unsigned tex_type : 3;
3729 unsigned tmp_dst : 1;
3730 unsigned projected : 2;
3731 unsigned padding : 10;
3734 struct ffp_frag_settings
3736 struct texture_stage_op op[WINED3D_MAX_TEXTURES];
3737 enum wined3d_ffp_ps_fog_mode fog;
3738 unsigned char sRGB_write;
3739 unsigned char emul_clipplanes;
3740 unsigned char texcoords_initialized;
3741 unsigned char color_key_enabled : 1;
3742 unsigned char pointsprite : 1;
3743 unsigned char flatshading : 1;
3744 unsigned char alpha_test_func : 3;
3745 unsigned char padding : 2;
3748 struct ffp_frag_desc
3750 struct wine_rb_entry entry;
3751 struct ffp_frag_settings settings;
3754 int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
3755 int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry) DECLSPEC_HIDDEN;
3757 extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
3759 void wined3d_ffp_get_fs_settings(const struct wined3d_context *context, const struct wined3d_state *state,
3760 struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN;
3761 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
3762 const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
3763 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
3764 void wined3d_ftoa(float value, char *s) DECLSPEC_HIDDEN;
3766 enum wined3d_ffp_vs_fog_mode
3768 WINED3D_FFP_VS_FOG_OFF = 0,
3769 WINED3D_FFP_VS_FOG_FOGCOORD = 1,
3770 WINED3D_FFP_VS_FOG_DEPTH = 2,
3771 WINED3D_FFP_VS_FOG_RANGE = 3,
3774 #define WINED3D_FFP_TCI_SHIFT 16
3775 #define WINED3D_FFP_TCI_MASK 0xffu
3777 #define WINED3D_FFP_LIGHT_TYPE_SHIFT(idx) (3 * (idx))
3778 #define WINED3D_FFP_LIGHT_TYPE_MASK 0x7u
3780 struct wined3d_ffp_vs_settings
3782 DWORD point_light_count : 4;
3783 DWORD spot_light_count : 4;
3784 DWORD directional_light_count : 4;
3785 DWORD parallel_point_light_count : 4;
3786 DWORD diffuse_source : 2;
3787 DWORD emissive_source : 2;
3788 DWORD ambient_source : 2;
3789 DWORD specular_source : 2;
3790 DWORD transformed : 1;
3791 DWORD vertexblends : 2;
3792 DWORD clipping : 1;
3793 DWORD normal : 1;
3794 DWORD normalize : 1;
3795 DWORD lighting : 1;
3796 DWORD localviewer : 1;
3798 DWORD point_size : 1;
3799 DWORD per_vertex_point_size : 1;
3800 DWORD fog_mode : 2;
3801 DWORD texcoords : 8; /* WINED3D_MAX_TEXTURES */
3802 DWORD ortho_fog : 1;
3803 DWORD flatshading : 1;
3804 DWORD padding : 18;
3806 DWORD swizzle_map; /* MAX_ATTRIBS, 32 */
3808 unsigned int texgen[WINED3D_MAX_TEXTURES];
3811 struct wined3d_ffp_vs_desc
3813 struct wine_rb_entry entry;
3814 struct wined3d_ffp_vs_settings settings;
3817 void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
3818 const struct wined3d_state *state, struct wined3d_ffp_vs_settings *settings) DECLSPEC_HIDDEN;
3820 struct wined3d
3822 LONG ref;
3823 unsigned int flags;
3824 unsigned int adapter_count;
3825 struct wined3d_adapter *adapters[1];
3828 BOOL wined3d_filter_messages(HWND window, BOOL filter) DECLSPEC_HIDDEN;
3829 HRESULT wined3d_init(struct wined3d *wined3d, uint32_t flags) DECLSPEC_HIDDEN;
3830 void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
3832 BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size) DECLSPEC_HIDDEN;
3834 struct wined3d_blend_state
3836 LONG refcount;
3837 struct wined3d_blend_state_desc desc;
3838 BOOL dual_source;
3840 void *parent;
3841 const struct wined3d_parent_ops *parent_ops;
3843 struct wined3d_device *device;
3844 struct wine_rb_entry entry;
3847 static inline unsigned int wined3d_blend_state_get_writemask(const struct wined3d_blend_state *state,
3848 unsigned int index)
3850 if (!state)
3851 return 0xf;
3852 if (!state->desc.independent)
3853 index = 0;
3854 return state->desc.rt[index].writemask;
3857 struct wined3d_depth_stencil_state
3859 LONG refcount;
3860 struct wined3d_depth_stencil_state_desc desc;
3862 bool writes_ds;
3864 void *parent;
3865 const struct wined3d_parent_ops *parent_ops;
3867 struct wined3d_device *device;
3868 struct wine_rb_entry entry;
3871 struct wined3d_rasterizer_state
3873 LONG refcount;
3874 struct wined3d_rasterizer_state_desc desc;
3876 void *parent;
3877 const struct wined3d_parent_ops *parent_ops;
3879 struct wined3d_device *device;
3880 struct wine_rb_entry entry;
3883 struct wined3d_light_state
3885 struct rb_tree lights_tree;
3886 const struct wined3d_light_info *lights[WINED3D_MAX_ACTIVE_LIGHTS];
3889 #define WINED3D_STATE_NO_REF 0x00000001
3890 #define WINED3D_STATE_INIT_DEFAULT 0x00000002
3892 struct wined3d_state
3894 enum wined3d_feature_level feature_level;
3895 uint32_t flags;
3896 struct wined3d_fb_state fb;
3898 struct wined3d_vertex_declaration *vertex_declaration;
3899 struct wined3d_stream_output stream_output[WINED3D_MAX_STREAM_OUTPUT_BUFFERS];
3900 struct wined3d_stream_state streams[WINED3D_MAX_STREAMS];
3901 struct wined3d_buffer *index_buffer;
3902 enum wined3d_format_id index_format;
3903 unsigned int index_offset;
3904 int base_vertex_index;
3905 int load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
3906 enum wined3d_primitive_type primitive_type;
3907 unsigned int patch_vertex_count;
3908 struct wined3d_query *predicate;
3909 BOOL predicate_value;
3911 struct wined3d_shader *shader[WINED3D_SHADER_TYPE_COUNT];
3912 struct wined3d_constant_buffer_state cb[WINED3D_SHADER_TYPE_COUNT][MAX_CONSTANT_BUFFERS];
3913 struct wined3d_sampler *sampler[WINED3D_SHADER_TYPE_COUNT][MAX_SAMPLER_OBJECTS];
3914 struct wined3d_shader_resource_view *shader_resource_view[WINED3D_SHADER_TYPE_COUNT][MAX_SHADER_RESOURCE_VIEWS];
3915 struct wined3d_unordered_access_view *unordered_access_view[WINED3D_PIPELINE_COUNT][MAX_UNORDERED_ACCESS_VIEWS];
3917 struct wined3d_vec4 vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
3918 struct wined3d_ivec4 vs_consts_i[WINED3D_MAX_CONSTS_I];
3919 BOOL vs_consts_b[WINED3D_MAX_CONSTS_B];
3921 struct wined3d_vec4 ps_consts_f[WINED3D_MAX_PS_CONSTS_F];
3922 struct wined3d_ivec4 ps_consts_i[WINED3D_MAX_CONSTS_I];
3923 BOOL ps_consts_b[WINED3D_MAX_CONSTS_B];
3925 struct wined3d_texture *textures[WINED3D_MAX_COMBINED_SAMPLERS];
3926 uint32_t sampler_states[WINED3D_MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
3927 uint32_t texture_states[WINED3D_MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
3929 struct wined3d_matrix transforms[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
3930 struct wined3d_vec4 clip_planes[WINED3D_MAX_CLIP_DISTANCES];
3931 struct wined3d_material material;
3932 struct wined3d_viewport viewports[WINED3D_MAX_VIEWPORTS];
3933 unsigned int viewport_count;
3934 RECT scissor_rects[WINED3D_MAX_VIEWPORTS];
3935 unsigned int scissor_rect_count;
3937 struct wined3d_light_state light_state;
3939 unsigned int render_states[WINEHIGHEST_RENDER_STATE + 1];
3940 struct wined3d_blend_state *blend_state;
3941 struct wined3d_color blend_factor;
3942 unsigned int sample_mask;
3943 struct wined3d_depth_stencil_state *depth_stencil_state;
3944 unsigned int stencil_ref;
3945 bool depth_bounds_enable;
3946 float depth_bounds_min, depth_bounds_max;
3947 struct wined3d_rasterizer_state *rasterizer_state;
3950 void state_cleanup(struct wined3d_state *state) DECLSPEC_HIDDEN;
3951 void state_init(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info,
3952 uint32_t flags, enum wined3d_feature_level feature_level) DECLSPEC_HIDDEN;
3953 void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN;
3955 static inline void wined3d_state_reset(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info)
3957 enum wined3d_feature_level feature_level = state->feature_level;
3958 uint32_t flags = state->flags;
3960 memset(state, 0, sizeof(*state));
3961 state_init(state, d3d_info, flags, feature_level);
3964 static inline bool wined3d_state_uses_depth_buffer(const struct wined3d_state *state)
3966 if (!state->depth_stencil_state)
3967 return true;
3968 return state->depth_stencil_state->desc.depth || state->depth_stencil_state->desc.depth_write
3969 || state->depth_stencil_state->desc.stencil;
3972 struct wined3d_dummy_textures
3974 GLuint tex_1d;
3975 GLuint tex_2d;
3976 GLuint tex_rect;
3977 GLuint tex_3d;
3978 GLuint tex_cube;
3979 GLuint tex_cube_array;
3980 GLuint tex_1d_array;
3981 GLuint tex_2d_array;
3982 GLuint tex_buffer;
3983 GLuint tex_2d_ms;
3984 GLuint tex_2d_ms_array;
3987 #define WINED3D_UNMAPPED_STAGE ~0u
3989 /* Multithreaded flag. Removed from the public header to signal that
3990 * wined3d_device_create() ignores it. */
3991 #define WINED3DCREATE_MULTITHREADED 0x00000004
3993 struct wined3d_so_desc_entry
3995 struct wine_rb_entry entry;
3996 struct wined3d_stream_output_desc desc;
3997 struct wined3d_stream_output_element elements[1];
4000 struct wined3d_device
4002 LONG ref;
4004 /* WineD3D Information */
4005 struct wined3d_device_parent *device_parent;
4006 struct wined3d *wined3d;
4007 struct wined3d_adapter *adapter;
4009 const struct wined3d_shader_backend_ops *shader_backend;
4010 void *shader_priv;
4011 void *fragment_priv;
4012 void *vertex_priv;
4013 struct wined3d_state_entry state_table[STATE_HIGHEST + 1];
4014 /* Array of functions for states which are handled by more than one pipeline part */
4015 APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
4016 struct wined3d_blitter *blitter;
4018 BYTE bCursorVisible : 1;
4019 BYTE d3d_initialized : 1;
4020 BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */
4021 BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */
4022 BYTE restore_screensaver : 1;
4023 BYTE padding : 3;
4025 unsigned char surface_alignment; /* Line Alignment of surfaces */
4027 WORD padding2 : 16;
4029 /* Internal use fields */
4030 struct wined3d_device_creation_parameters create_parms;
4031 HWND focus_window;
4033 struct wined3d_rendertarget_view *back_buffer_view;
4034 struct wined3d_swapchain **swapchains;
4035 UINT swapchain_count;
4036 unsigned int max_frame_latency;
4038 struct list resources; /* a linked list to track resources created by the device */
4039 struct list shaders; /* a linked list to track shaders (pixel and vertex) */
4040 struct wine_rb_tree so_descs;
4041 struct wine_rb_tree samplers, rasterizer_states, blend_states, depth_stencil_states;
4043 /* Render Target Support */
4044 struct wined3d_rendertarget_view *auto_depth_stencil_view;
4046 /* Cursor management */
4047 UINT xHotSpot;
4048 UINT yHotSpot;
4049 UINT xScreenSpace;
4050 UINT yScreenSpace;
4051 UINT cursorWidth, cursorHeight;
4052 struct wined3d_texture *cursor_texture;
4053 HCURSOR hardwareCursor;
4055 /* The Wine logo texture */
4056 struct wined3d_texture *logo_texture;
4058 /* Default sampler used to emulate the direct resource access without using wined3d_sampler */
4059 struct wined3d_sampler *default_sampler;
4060 struct wined3d_sampler *null_sampler;
4062 /* Command stream */
4063 struct wined3d_cs *cs;
4065 /* Context management */
4066 struct wined3d_context **contexts;
4067 UINT context_count;
4069 CRITICAL_SECTION bo_map_lock;
4072 void wined3d_device_cleanup(struct wined3d_device *device) DECLSPEC_HIDDEN;
4073 BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
4074 void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
4075 void wined3d_device_create_default_samplers(struct wined3d_device *device,
4076 struct wined3d_context *context) DECLSPEC_HIDDEN;
4077 void wined3d_device_destroy_default_samplers(struct wined3d_device *device) DECLSPEC_HIDDEN;
4078 HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
4079 unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
4080 BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
4081 const BOOL *supported_extensions, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN;
4082 LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
4083 UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
4084 void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4085 void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4086 void device_invalidate_state(const struct wined3d_device *device, unsigned int state) DECLSPEC_HIDDEN;
4087 HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device,
4088 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4089 void wined3d_device_uninit_3d(struct wined3d_device *device) DECLSPEC_HIDDEN;
4091 static inline void wined3d_device_bo_map_lock(struct wined3d_device *device)
4093 EnterCriticalSection(&device->bo_map_lock);
4096 static inline void wined3d_device_bo_map_unlock(struct wined3d_device *device)
4098 LeaveCriticalSection(&device->bo_map_lock);
4101 struct wined3d_device_no3d
4103 struct wined3d_device d;
4105 struct wined3d_context context_no3d;
4108 static inline struct wined3d_device_no3d *wined3d_device_no3d(struct wined3d_device *device)
4110 return CONTAINING_RECORD(device, struct wined3d_device_no3d, d);
4113 struct wined3d_null_resources_vk
4115 struct wined3d_bo_vk bo;
4116 VkDescriptorBufferInfo buffer_info;
4118 struct wined3d_image_vk image_1d;
4119 struct wined3d_image_vk image_2d;
4120 struct wined3d_image_vk image_2dms;
4121 struct wined3d_image_vk image_3d;
4124 struct wined3d_null_views_vk
4126 VkBufferView vk_view_buffer_uint;
4127 VkBufferView vk_view_buffer_float;
4129 VkDescriptorImageInfo vk_info_1d;
4130 VkDescriptorImageInfo vk_info_2d;
4131 VkDescriptorImageInfo vk_info_2dms;
4132 VkDescriptorImageInfo vk_info_3d;
4133 VkDescriptorImageInfo vk_info_cube;
4134 VkDescriptorImageInfo vk_info_1d_array;
4135 VkDescriptorImageInfo vk_info_2d_array;
4136 VkDescriptorImageInfo vk_info_2dms_array;
4137 VkDescriptorImageInfo vk_info_cube_array;
4140 #define WINED3D_ALLOCATOR_CHUNK_SIZE (64 * 1024 * 1024)
4141 #define WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT 15
4142 #define WINED3D_ALLOCATOR_MIN_BLOCK_SIZE (WINED3D_ALLOCATOR_CHUNK_SIZE >> (WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT - 1))
4143 #define WINED3D_SLAB_BO_MIN_OBJECT_ALIGN 16
4144 #define WINED3D_RETIRED_BO_SIZE_THRESHOLD (64 * 1024 * 1024)
4146 struct wined3d_allocator_chunk
4148 struct list entry;
4149 struct list available[WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT];
4150 struct wined3d_allocator *allocator;
4151 unsigned int map_count;
4152 void *map_ptr;
4155 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk *chunk) DECLSPEC_HIDDEN;
4156 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk *chunk,
4157 struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
4159 struct wined3d_allocator_chunk_gl
4161 struct wined3d_allocator_chunk c;
4162 unsigned int memory_type;
4163 GLuint gl_buffer;
4166 static inline struct wined3d_allocator_chunk_gl *wined3d_allocator_chunk_gl(struct wined3d_allocator_chunk *chunk)
4168 return CONTAINING_RECORD(chunk, struct wined3d_allocator_chunk_gl, c);
4171 struct wined3d_allocator_chunk_vk
4173 struct wined3d_allocator_chunk c;
4174 VkDeviceMemory vk_memory;
4177 static inline struct wined3d_allocator_chunk_vk *wined3d_allocator_chunk_vk(struct wined3d_allocator_chunk *chunk)
4179 return CONTAINING_RECORD(chunk, struct wined3d_allocator_chunk_vk, c);
4182 void *wined3d_allocator_chunk_vk_map(struct wined3d_allocator_chunk_vk *chunk_vk,
4183 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4184 void wined3d_allocator_chunk_vk_unmap(struct wined3d_allocator_chunk_vk *chunk_vk,
4185 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4187 struct wined3d_allocator_block
4189 struct list entry;
4190 struct wined3d_allocator_chunk *chunk;
4191 struct wined3d_allocator_block *parent, *sibling;
4192 unsigned int order;
4193 size_t offset;
4194 bool free;
4197 void wined3d_allocator_block_free(struct wined3d_allocator_block *block) DECLSPEC_HIDDEN;
4199 struct wined3d_allocator_pool
4201 struct list chunks;
4204 struct wined3d_allocator_ops
4206 struct wined3d_allocator_chunk *(*allocator_create_chunk)(struct wined3d_allocator *allocator,
4207 struct wined3d_context *context, unsigned int memory_type, size_t chunk_size);
4208 void (*allocator_destroy_chunk)(struct wined3d_allocator_chunk *chunk);
4211 struct wined3d_allocator
4213 const struct wined3d_allocator_ops *ops;
4214 struct wined3d_allocator_pool *pools;
4215 size_t pool_count;
4216 struct wined3d_allocator_block *free;
4219 struct wined3d_allocator_block *wined3d_allocator_allocate(struct wined3d_allocator *allocator,
4220 struct wined3d_context *context, unsigned int memory_type, size_t size) DECLSPEC_HIDDEN;
4221 void wined3d_allocator_cleanup(struct wined3d_allocator *allocator) DECLSPEC_HIDDEN;
4222 bool wined3d_allocator_init(struct wined3d_allocator *allocator,
4223 size_t pool_count, const struct wined3d_allocator_ops *allocator_ops) DECLSPEC_HIDDEN;
4225 struct wined3d_uav_clear_pipelines_vk
4227 VkPipeline buffer;
4228 VkPipeline image_1d;
4229 VkPipeline image_1d_array;
4230 VkPipeline image_2d;
4231 VkPipeline image_2d_array;
4232 VkPipeline image_3d;
4235 struct wined3d_uav_clear_state_vk
4237 struct wined3d_uav_clear_pipelines_vk float_pipelines;
4238 struct wined3d_uav_clear_pipelines_vk uint_pipelines;
4240 struct wined3d_shader_thread_group_size buffer_group_size;
4241 struct wined3d_shader_thread_group_size image_1d_group_size;
4242 struct wined3d_shader_thread_group_size image_1d_array_group_size;
4243 struct wined3d_shader_thread_group_size image_2d_group_size;
4244 struct wined3d_shader_thread_group_size image_2d_array_group_size;
4245 struct wined3d_shader_thread_group_size image_3d_group_size;
4247 struct wined3d_pipeline_layout_vk *image_layout;
4248 struct wined3d_pipeline_layout_vk *buffer_layout;
4251 struct wined3d_device_vk
4253 struct wined3d_device d;
4255 struct wined3d_context_vk context_vk;
4257 VkDevice vk_device;
4258 VkQueue vk_queue;
4259 uint32_t vk_queue_family_index;
4260 uint32_t timestamp_bits;
4262 struct wined3d_vk_info vk_info;
4264 struct wined3d_null_resources_vk null_resources_vk;
4265 struct wined3d_null_views_vk null_views_vk;
4267 CRITICAL_SECTION allocator_cs;
4268 struct wined3d_allocator allocator;
4270 struct wined3d_uav_clear_state_vk uav_clear_state;
4273 static inline struct wined3d_device_vk *wined3d_device_vk(struct wined3d_device *device)
4275 return CONTAINING_RECORD(device, struct wined3d_device_vk, d);
4278 static inline struct wined3d_device_vk *wined3d_device_vk_from_allocator(struct wined3d_allocator *allocator)
4280 return CONTAINING_RECORD(allocator, struct wined3d_device_vk, allocator);
4283 static inline void wined3d_device_vk_allocator_lock(struct wined3d_device_vk *device_vk)
4285 EnterCriticalSection(&device_vk->allocator_cs);
4288 static inline void wined3d_device_vk_allocator_unlock(struct wined3d_device_vk *device_vk)
4290 LeaveCriticalSection(&device_vk->allocator_cs);
4293 bool wined3d_device_vk_create_null_resources(struct wined3d_device_vk *device_vk,
4294 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4295 bool wined3d_device_vk_create_null_views(struct wined3d_device_vk *device_vk,
4296 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4297 void wined3d_device_vk_destroy_null_resources(struct wined3d_device_vk *device_vk,
4298 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4299 void wined3d_device_vk_destroy_null_views(struct wined3d_device_vk *device_vk,
4300 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4302 void wined3d_device_vk_uav_clear_state_init(struct wined3d_device_vk *device_vk) DECLSPEC_HIDDEN;
4303 void wined3d_device_vk_uav_clear_state_cleanup(struct wined3d_device_vk *device_vk) DECLSPEC_HIDDEN;
4305 struct wined3d_device_gl
4307 struct wined3d_device d;
4309 /* Textures for when no other textures are bound. */
4310 struct wined3d_dummy_textures dummy_textures;
4312 CRITICAL_SECTION allocator_cs;
4313 struct wined3d_allocator allocator;
4314 uint64_t completed_fence_id;
4315 uint64_t current_fence_id;
4316 uint64_t retired_bo_size;
4318 struct wined3d_retired_block_gl
4320 struct wined3d_allocator_block *block;
4321 uint64_t fence_id;
4322 } *retired_blocks;
4323 SIZE_T retired_blocks_size;
4324 SIZE_T retired_block_count;
4326 HWND backup_wnd;
4327 HDC backup_dc;
4330 static inline struct wined3d_device_gl *wined3d_device_gl(struct wined3d_device *device)
4332 return CONTAINING_RECORD(device, struct wined3d_device_gl, d);
4335 static inline struct wined3d_device_gl *wined3d_device_gl_from_allocator(struct wined3d_allocator *allocator)
4337 return CONTAINING_RECORD(allocator, struct wined3d_device_gl, allocator);
4340 static inline void wined3d_device_gl_allocator_lock(struct wined3d_device_gl *device_gl)
4342 EnterCriticalSection(&device_gl->allocator_cs);
4345 static inline void wined3d_device_gl_allocator_unlock(struct wined3d_device_gl *device_gl)
4347 LeaveCriticalSection(&device_gl->allocator_cs);
4350 static inline void wined3d_allocator_chunk_gl_lock(struct wined3d_allocator_chunk_gl *chunk_gl)
4352 wined3d_device_gl_allocator_lock(wined3d_device_gl_from_allocator(chunk_gl->c.allocator));
4355 static inline void wined3d_allocator_chunk_gl_unlock(struct wined3d_allocator_chunk_gl *chunk_gl)
4357 wined3d_device_gl_allocator_unlock(wined3d_device_gl_from_allocator(chunk_gl->c.allocator));
4360 bool wined3d_device_gl_create_bo(struct wined3d_device_gl *device_gl,
4361 struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding,
4362 GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
4363 void wined3d_device_gl_create_primary_opengl_context_cs(void *object) DECLSPEC_HIDDEN;
4364 void wined3d_device_gl_delete_opengl_contexts_cs(void *object) DECLSPEC_HIDDEN;
4365 HDC wined3d_device_gl_get_backup_dc(struct wined3d_device_gl *device_gl) DECLSPEC_HIDDEN;
4366 GLbitfield wined3d_device_gl_get_memory_type_flags(unsigned int memory_type_idx) DECLSPEC_HIDDEN;
4368 static inline float wined3d_alpha_ref(const struct wined3d_state *state)
4370 return (state->render_states[WINED3D_RS_ALPHAREF] & 0xff) / 255.0f;
4373 const char *wined3d_debug_resource_access(uint32_t access) DECLSPEC_HIDDEN;
4374 const char *wined3d_debug_bind_flags(uint32_t bind_flags) DECLSPEC_HIDDEN;
4375 const char *wined3d_debug_view_desc(const struct wined3d_view_desc *d,
4376 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4377 const char *wined3d_debug_vkresult(VkResult vr) DECLSPEC_HIDDEN;
4379 static inline ULONG wined3d_atomic_decrement_mutex_lock(volatile LONG *refcount)
4381 ULONG count, old_count = *refcount;
4384 if ((count = old_count) == 1)
4386 wined3d_mutex_lock();
4387 count = InterlockedDecrement(refcount);
4388 if (count) wined3d_mutex_unlock();
4389 return count;
4392 old_count = InterlockedCompareExchange(refcount, count - 1, count);
4394 while (old_count != count);
4396 return count - 1;
4399 #define CLIENT_BO_DISCARDED ((struct wined3d_bo *)~(UINT_PTR)0)
4401 struct wined3d_client_resource
4403 /* The resource's persistently mapped address, which we may use to perform
4404 * NOOVERWRITE maps from the client thread. */
4405 struct wined3d_bo_address addr;
4407 /* The currently mapped upload BO, if applicable, and box. */
4408 struct upload_bo mapped_upload;
4409 struct wined3d_box mapped_box;
4412 static inline BOOL wined3d_resource_access_is_managed(unsigned int access)
4414 return !(~access & (WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU));
4417 struct wined3d_resource_ops
4419 ULONG (*resource_incref)(struct wined3d_resource *resource);
4420 ULONG (*resource_decref)(struct wined3d_resource *resource);
4421 void (*resource_preload)(struct wined3d_resource *resource);
4422 void (*resource_unload)(struct wined3d_resource *resource);
4423 HRESULT (*resource_sub_resource_get_desc)(struct wined3d_resource *resource,
4424 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc);
4425 void (*resource_sub_resource_get_map_pitch)(struct wined3d_resource *resource,
4426 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch);
4427 HRESULT (*resource_sub_resource_map)(struct wined3d_resource *resource, unsigned int sub_resource_idx,
4428 void **map_ptr, const struct wined3d_box *box, uint32_t flags);
4429 HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx);
4432 struct wined3d_resource
4434 LONG ref;
4435 LONG bind_count;
4436 LONG map_count;
4437 ULONG access_time;
4438 struct wined3d_device *device;
4439 enum wined3d_resource_type type;
4440 enum wined3d_gl_resource_type gl_type;
4441 const struct wined3d_format *format;
4442 unsigned int format_attrs;
4443 unsigned int format_caps;
4444 enum wined3d_multisample_type multisample_type;
4445 UINT multisample_quality;
4446 uint32_t usage;
4447 unsigned int bind_flags;
4448 unsigned int access;
4449 WORD draw_binding;
4450 WORD map_binding;
4451 UINT width;
4452 UINT height;
4453 UINT depth;
4454 UINT size;
4455 unsigned int priority;
4456 void *heap_memory;
4458 uint32_t pin_sysmem : 1;
4460 struct wined3d_client_resource client;
4462 void *parent;
4463 const struct wined3d_parent_ops *parent_ops;
4464 const struct wined3d_resource_ops *resource_ops;
4466 struct list resource_list_entry;
4468 LONG srv_bind_count_device;
4469 LONG rtv_bind_count_device;
4472 static inline ULONG wined3d_resource_incref(struct wined3d_resource *resource)
4474 return resource->resource_ops->resource_incref(resource);
4477 static inline ULONG wined3d_resource_decref(struct wined3d_resource *resource)
4479 return resource->resource_ops->resource_decref(resource);
4482 static inline HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_resource *resource,
4483 unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
4485 return resource->resource_ops->resource_sub_resource_get_desc(resource, sub_resource_idx, desc);
4488 static inline void wined3d_resource_get_sub_resource_map_pitch(struct wined3d_resource *resource,
4489 unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
4491 resource->resource_ops->resource_sub_resource_get_map_pitch(resource, sub_resource_idx, row_pitch, slice_pitch);
4494 void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4495 HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
4496 enum wined3d_resource_type type, const struct wined3d_format *format,
4497 enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, unsigned int usage,
4498 unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth,
4499 unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops,
4500 const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
4501 void *resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx,
4502 uint8_t *base_memory, const struct wined3d_box *box) DECLSPEC_HIDDEN;
4503 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4504 HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource,
4505 unsigned int sub_resource_idx, const struct wined3d_box *box) DECLSPEC_HIDDEN;
4506 void wined3d_resource_free_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4507 const struct wined3d_format *wined3d_resource_get_decompress_format(
4508 const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4509 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4510 GLbitfield wined3d_resource_gl_map_flags(const struct wined3d_bo_gl *bo, DWORD d3d_flags) DECLSPEC_HIDDEN;
4511 GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
4512 GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4513 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4514 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4515 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
4516 void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource,
4517 const struct wined3d_map_desc *map, const struct wined3d_color *colour,
4518 const struct wined3d_box *box, bool full_subresource) DECLSPEC_HIDDEN;
4520 /* Tests show that the start address of resources is 32 byte aligned */
4521 #define RESOURCE_ALIGNMENT 16
4522 #define WINED3D_CONSTANT_BUFFER_ALIGNMENT 16
4524 #define WINED3D_LOCATION_DISCARDED 0x00000001
4525 #define WINED3D_LOCATION_SYSMEM 0x00000002
4526 #define WINED3D_LOCATION_CLEARED 0x00000004
4527 #define WINED3D_LOCATION_BUFFER 0x00000008
4528 #define WINED3D_LOCATION_TEXTURE_RGB 0x00000010
4529 #define WINED3D_LOCATION_TEXTURE_SRGB 0x00000020
4530 #define WINED3D_LOCATION_DRAWABLE 0x00000040
4531 #define WINED3D_LOCATION_RB_MULTISAMPLE 0x00000080
4532 #define WINED3D_LOCATION_RB_RESOLVED 0x00000100
4534 const char *wined3d_debug_location(uint32_t location) DECLSPEC_HIDDEN;
4536 struct wined3d_blt_info
4538 GLenum bind_target;
4539 struct wined3d_vec3 texcoords[4];
4542 struct wined3d_texture_ops
4544 BOOL (*texture_prepare_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
4545 struct wined3d_context *context, unsigned int location);
4546 BOOL (*texture_load_location)(struct wined3d_texture *texture, unsigned int sub_resource_idx,
4547 struct wined3d_context *context, unsigned int location);
4548 void (*texture_unload_location)(struct wined3d_texture *texture,
4549 struct wined3d_context *context, unsigned int location);
4550 void (*texture_upload_data)(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr,
4551 const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch,
4552 unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
4553 unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z);
4554 void (*texture_download_data)(struct wined3d_context *context, struct wined3d_texture *src_texture,
4555 unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box,
4556 const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format,
4557 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z,
4558 unsigned int dst_row_pitch, unsigned int dst_slice_pitch);
4561 #define WINED3D_TEXTURE_COND_NP2 0x00000001
4562 #define WINED3D_TEXTURE_COND_NP2_EMULATED 0x00000002
4563 #define WINED3D_TEXTURE_POW2_MAT_IDENT 0x00000004
4564 #define WINED3D_TEXTURE_IS_SRGB 0x00000008
4565 #define WINED3D_TEXTURE_RGB_ALLOCATED 0x00000010
4566 #define WINED3D_TEXTURE_RGB_VALID 0x00000020
4567 #define WINED3D_TEXTURE_SRGB_ALLOCATED 0x00000040
4568 #define WINED3D_TEXTURE_SRGB_VALID 0x00000080
4569 #define WINED3D_TEXTURE_CONVERTED 0x00000100
4570 #define WINED3D_TEXTURE_NORMALIZED_COORDS 0x00000400
4571 #define WINED3D_TEXTURE_GET_DC_LENIENT 0x00000800
4572 #define WINED3D_TEXTURE_DC_IN_USE 0x00001000
4573 #define WINED3D_TEXTURE_DISCARD 0x00002000
4574 #define WINED3D_TEXTURE_GET_DC 0x00004000
4575 #define WINED3D_TEXTURE_GENERATE_MIPMAPS 0x00008000
4576 #define WINED3D_TEXTURE_DOWNLOADABLE 0x00010000
4578 #define WINED3D_TEXTURE_ASYNC_COLOR_KEY 0x00000001
4580 struct wined3d_texture
4582 struct wined3d_resource resource;
4583 const struct wined3d_texture_ops *texture_ops;
4584 struct wined3d_swapchain *swapchain;
4585 unsigned int pow2_width;
4586 unsigned int pow2_height;
4587 UINT layer_count;
4588 unsigned int level_count;
4589 unsigned int download_count;
4590 unsigned int sysmem_count;
4591 float pow2_matrix[16];
4592 unsigned int lod;
4593 DWORD sampler;
4594 uint32_t flags;
4595 DWORD update_map_binding;
4597 unsigned int row_pitch;
4598 unsigned int slice_pitch;
4600 /* May only be accessed from the command stream worker thread. */
4601 struct wined3d_texture_async
4603 uint32_t flags;
4605 /* Color keys for DDraw */
4606 struct wined3d_color_key dst_blt_color_key;
4607 struct wined3d_color_key src_blt_color_key;
4608 struct wined3d_color_key dst_overlay_color_key;
4609 struct wined3d_color_key src_overlay_color_key;
4610 struct wined3d_color_key gl_color_key;
4611 DWORD color_key_flags;
4612 } async;
4614 struct wined3d_dirty_regions
4616 struct wined3d_box *boxes;
4617 SIZE_T boxes_size;
4618 unsigned int box_count;
4619 } *dirty_regions;
4621 struct wined3d_overlay_info
4623 struct list entry;
4624 struct list overlays;
4625 struct wined3d_texture *dst_texture;
4626 unsigned int dst_sub_resource_idx;
4627 RECT src_rect;
4628 RECT dst_rect;
4629 } *overlay_info;
4631 struct wined3d_dc_info
4633 HBITMAP bitmap;
4634 HDC dc;
4635 } *dc_info;
4637 struct wined3d_texture_sub_resource
4639 void *parent;
4640 const struct wined3d_parent_ops *parent_ops;
4642 unsigned int offset;
4643 unsigned int size;
4645 unsigned int map_count;
4646 uint32_t map_flags;
4647 DWORD locations;
4648 struct wined3d_bo *bo;
4649 union
4651 struct wined3d_color colour;
4652 struct
4654 float depth;
4655 unsigned int stencil;
4657 } clear_value;
4659 void *user_memory;
4660 } *sub_resources;
4663 static inline void *wined3d_texture_allocate_object_memory(SIZE_T s, SIZE_T level_count, SIZE_T layer_count)
4665 struct wined3d_texture *t;
4667 if (level_count > ((~(SIZE_T)0 - s) / sizeof(*t->sub_resources)) / layer_count)
4668 return NULL;
4670 return heap_alloc_zero(s + level_count * layer_count * sizeof(*t->sub_resources));
4673 static inline struct wined3d_texture *texture_from_resource(struct wined3d_resource *resource)
4675 return CONTAINING_RECORD(resource, struct wined3d_texture, resource);
4678 static inline unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture,
4679 unsigned int level)
4681 return max(1, texture->resource.width >> level);
4684 static inline unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture,
4685 unsigned int level)
4687 return max(1, texture->resource.height >> level);
4690 static inline unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture,
4691 unsigned int level)
4693 return max(1, texture->resource.depth >> level);
4696 static inline unsigned int wined3d_texture_get_level_pow2_width(const struct wined3d_texture *texture,
4697 unsigned int level)
4699 return max(1, texture->pow2_width >> level);
4702 static inline unsigned int wined3d_texture_get_level_pow2_height(const struct wined3d_texture *texture,
4703 unsigned int level)
4705 return max(1, texture->pow2_height >> level);
4708 static inline void wined3d_texture_get_level_box(const struct wined3d_texture *texture,
4709 unsigned int level, struct wined3d_box *box)
4711 wined3d_box_set(box, 0, 0,
4712 wined3d_texture_get_level_width(texture, level),
4713 wined3d_texture_get_level_height(texture, level),
4714 0, wined3d_texture_get_level_depth(texture, level));
4717 static inline bool wined3d_texture_is_full_rect(const struct wined3d_texture *texture,
4718 unsigned int level, const RECT *r)
4720 unsigned int t;
4722 t = wined3d_texture_get_level_width(texture, level);
4723 if ((r->left && r->right) || abs(r->right - r->left) != t)
4724 return false;
4725 t = wined3d_texture_get_level_height(texture, level);
4726 if ((r->top && r->bottom) || abs(r->bottom - r->top) != t)
4727 return false;
4728 return true;
4731 HRESULT texture2d_blt(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
4732 const struct wined3d_box *dst_box, struct wined3d_texture *src_texture,
4733 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, uint32_t flags,
4734 const struct wined3d_blt_fx *blt_fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
4735 void texture2d_get_blt_info(const struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
4736 const RECT *rect, struct wined3d_blt_info *info) DECLSPEC_HIDDEN;
4737 void texture2d_load_fb_texture(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx,
4738 BOOL srgb, struct wined3d_context *context) DECLSPEC_HIDDEN;
4739 void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx,
4740 struct wined3d_context *context, DWORD src_location, DWORD dst_location) DECLSPEC_HIDDEN;
4742 void wined3d_texture_cleanup(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
4743 void wined3d_texture_download_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
4744 struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx) DECLSPEC_HIDDEN;
4745 void wined3d_texture_get_bo_address(const struct wined3d_texture *texture,
4746 unsigned int sub_resource_idx, struct wined3d_bo_address *data, uint32_t location) DECLSPEC_HIDDEN;
4747 GLenum wined3d_texture_get_gl_buffer(const struct wined3d_texture *texture) DECLSPEC_HIDDEN;
4748 void wined3d_texture_invalidate_location(struct wined3d_texture *texture,
4749 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
4750 void wined3d_texture_load(struct wined3d_texture *texture,
4751 struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
4752 BOOL wined3d_texture_load_location(struct wined3d_texture *texture,
4753 unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
4754 BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx,
4755 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
4756 void wined3d_texture_set_swapchain(struct wined3d_texture *texture,
4757 struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
4758 BOOL wined3d_texture_can_use_pbo(const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
4759 DECLSPEC_HIDDEN;
4760 void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
4761 void wined3d_texture_translate_drawable_coords(const struct wined3d_texture *texture,
4762 HWND window, RECT *rect) DECLSPEC_HIDDEN;
4763 void wined3d_texture_update_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx,
4764 struct wined3d_context *context, const struct upload_bo *upload_bo, const struct wined3d_box *box,
4765 unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
4766 void wined3d_texture_upload_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx,
4767 unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, struct wined3d_texture *src_texture,
4768 unsigned int src_sub_resource_idx, const struct wined3d_box *src_box) DECLSPEC_HIDDEN;
4769 void wined3d_texture_validate_location(struct wined3d_texture *texture,
4770 unsigned int sub_resource_idx, uint32_t location) DECLSPEC_HIDDEN;
4771 bool wined3d_texture_validate_sub_resource_idx(const struct wined3d_texture *texture,
4772 unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
4773 void wined3d_texture_clear_dirty_regions(struct wined3d_texture *texture) DECLSPEC_HIDDEN;
4775 HRESULT wined3d_texture_no3d_init(struct wined3d_texture *texture_no3d, struct wined3d_device *device,
4776 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
4777 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4779 void wined3d_gl_texture_swizzle_from_color_fixup(GLint swizzle[4], struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
4780 void wined3d_vk_swizzle_from_color_fixup(VkComponentMapping *mapping, struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
4782 struct gl_texture
4784 struct wined3d_sampler_desc sampler_desc;
4785 unsigned int base_level;
4786 GLuint name;
4789 struct wined3d_texture_gl
4791 struct wined3d_texture t;
4793 struct gl_texture texture_rgb, texture_srgb;
4795 GLenum target;
4797 GLuint rb_multisample;
4798 GLuint rb_resolved;
4800 struct list renderbuffers;
4801 const struct wined3d_renderbuffer_entry *current_renderbuffer;
4804 static inline struct wined3d_texture_gl *wined3d_texture_gl(struct wined3d_texture *texture)
4806 return CONTAINING_RECORD(texture, struct wined3d_texture_gl, t);
4809 static inline struct gl_texture *wined3d_texture_gl_get_gl_texture(struct wined3d_texture_gl *texture_gl,
4810 BOOL srgb)
4812 return srgb ? &texture_gl->texture_srgb : &texture_gl->texture_rgb;
4815 static inline GLenum wined3d_texture_gl_get_sub_resource_target(const struct wined3d_texture_gl *texture_gl,
4816 unsigned int sub_resource_idx)
4818 static const GLenum cube_targets[] =
4820 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
4821 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
4822 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
4823 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
4824 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
4825 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
4828 return texture_gl->t.resource.usage & WINED3DUSAGE_LEGACY_CUBEMAP
4829 ? cube_targets[sub_resource_idx / texture_gl->t.level_count] : texture_gl->target;
4832 static inline BOOL wined3d_texture_gl_is_multisample_location(const struct wined3d_texture_gl *texture_gl,
4833 uint32_t location)
4835 if (location == WINED3D_LOCATION_RB_MULTISAMPLE)
4836 return TRUE;
4837 if (location != WINED3D_LOCATION_TEXTURE_RGB && location != WINED3D_LOCATION_TEXTURE_SRGB)
4838 return FALSE;
4839 return texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE || texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY;
4842 void wined3d_texture_gl_apply_sampler_desc(struct wined3d_texture_gl *texture_gl,
4843 const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4844 void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl,
4845 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
4846 void wined3d_texture_gl_bind_and_dirtify(struct wined3d_texture_gl *texture_gl,
4847 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
4848 HRESULT wined3d_texture_gl_init(struct wined3d_texture_gl *texture_gl, struct wined3d_device *device,
4849 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
4850 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4851 void wined3d_texture_gl_prepare_texture(struct wined3d_texture_gl *texture_gl,
4852 struct wined3d_context_gl *context_gl, BOOL srgb) DECLSPEC_HIDDEN;
4853 void wined3d_texture_gl_set_compatible_renderbuffer(struct wined3d_texture_gl *texture_gl,
4854 struct wined3d_context_gl *context_gl, unsigned int level,
4855 const struct wined3d_rendertarget_info *rt) DECLSPEC_HIDDEN;
4857 struct wined3d_texture_vk
4859 struct wined3d_texture t;
4861 struct wined3d_image_vk image;
4862 enum VkImageLayout layout;
4863 uint32_t bind_mask;
4865 VkDescriptorImageInfo default_image_info;
4868 static inline struct wined3d_texture_vk *wined3d_texture_vk(struct wined3d_texture *texture)
4870 return CONTAINING_RECORD(texture, struct wined3d_texture_vk, t);
4873 void wined3d_texture_vk_barrier(struct wined3d_texture_vk *texture_vk,
4874 struct wined3d_context_vk *context_vk, uint32_t bind_mask) DECLSPEC_HIDDEN;
4875 const VkDescriptorImageInfo *wined3d_texture_vk_get_default_image_info(struct wined3d_texture_vk *texture_vk,
4876 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4877 HRESULT wined3d_texture_vk_init(struct wined3d_texture_vk *texture_vk, struct wined3d_device *device,
4878 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
4879 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4880 void wined3d_texture_vk_make_generic(struct wined3d_texture_vk *texture_vk,
4881 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4882 BOOL wined3d_texture_vk_prepare_texture(struct wined3d_texture_vk *texture_vk,
4883 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
4885 struct wined3d_renderbuffer_entry
4887 struct list entry;
4888 GLuint id;
4889 UINT width;
4890 UINT height;
4893 struct wined3d_fbo_resource
4895 GLuint object;
4896 GLenum target;
4897 GLuint level, layer;
4900 #define WINED3D_FBO_ENTRY_FLAG_ATTACHED 0x1
4901 #define WINED3D_FBO_ENTRY_FLAG_DEPTH 0x2
4902 #define WINED3D_FBO_ENTRY_FLAG_STENCIL 0x4
4904 struct fbo_entry
4906 struct list entry;
4907 uint32_t flags;
4908 uint32_t rt_mask;
4909 GLuint id;
4910 struct wined3d_fbo_entry_key
4912 DWORD rb_namespace;
4913 struct wined3d_fbo_resource objects[WINED3D_MAX_RENDER_TARGETS + 1];
4914 } key;
4917 struct wined3d_sampler
4919 struct wine_rb_entry entry;
4920 LONG refcount;
4921 struct wined3d_device *device;
4922 void *parent;
4923 const struct wined3d_parent_ops *parent_ops;
4924 struct wined3d_sampler_desc desc;
4927 struct wined3d_sampler_gl
4929 struct wined3d_sampler s;
4931 GLuint name;
4934 static inline struct wined3d_sampler_gl *wined3d_sampler_gl(struct wined3d_sampler *sampler)
4936 return CONTAINING_RECORD(sampler, struct wined3d_sampler_gl, s);
4939 void wined3d_sampler_gl_bind(struct wined3d_sampler_gl *sampler_gl, unsigned int unit,
4940 struct wined3d_texture_gl *texture_gl, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
4941 void wined3d_sampler_gl_init(struct wined3d_sampler_gl *sampler_gl,
4942 struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
4943 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4945 struct wined3d_sampler_vk
4947 struct wined3d_sampler s;
4949 VkDescriptorImageInfo vk_image_info;
4950 uint64_t command_buffer_id;
4953 static inline struct wined3d_sampler_vk *wined3d_sampler_vk(struct wined3d_sampler *sampler)
4955 return CONTAINING_RECORD(sampler, struct wined3d_sampler_vk, s);
4958 void wined3d_sampler_vk_init(struct wined3d_sampler_vk *sampler_vk,
4959 struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
4960 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
4962 struct wined3d_vertex_declaration_element
4964 const struct wined3d_format *format;
4965 BOOL ffp_valid;
4966 unsigned int input_slot;
4967 unsigned int offset;
4968 unsigned int output_slot;
4969 enum wined3d_input_classification input_slot_class;
4970 unsigned int instance_data_step_rate;
4971 BYTE method;
4972 BYTE usage;
4973 BYTE usage_idx;
4976 struct wined3d_vertex_declaration
4978 LONG ref;
4979 void *parent;
4980 const struct wined3d_parent_ops *parent_ops;
4981 struct wined3d_device *device;
4983 struct wined3d_vertex_declaration_element *elements;
4984 unsigned int element_count;
4986 BOOL position_transformed;
4989 struct wined3d_saved_states
4991 uint32_t vs_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_VS_CONSTS_F)];
4992 WORD vertexShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
4993 WORD vertexShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
4994 uint32_t ps_consts_f[WINED3D_BITMAP_SIZE(WINED3D_MAX_PS_CONSTS_F)];
4995 WORD pixelShaderConstantsI; /* WINED3D_MAX_CONSTS_I, 16 */
4996 WORD pixelShaderConstantsB; /* WINED3D_MAX_CONSTS_B, 16 */
4997 uint32_t transform[WINED3D_BITMAP_SIZE(WINED3D_HIGHEST_TRANSFORM_STATE + 1)];
4998 WORD streamSource; /* WINED3D_MAX_STREAMS, 16 */
4999 WORD streamFreq; /* WINED3D_MAX_STREAMS, 16 */
5000 uint32_t renderState[WINED3D_BITMAP_SIZE(WINEHIGHEST_RENDER_STATE + 1)];
5001 DWORD textureState[WINED3D_MAX_TEXTURES]; /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
5002 WORD samplerState[WINED3D_MAX_COMBINED_SAMPLERS]; /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
5003 DWORD clipplane; /* WINED3D_MAX_CLIP_DISTANCES, 8 */
5004 DWORD textures : 20; /* WINED3D_MAX_COMBINED_SAMPLERS, 20 */
5005 DWORD indices : 1;
5006 DWORD material : 1;
5007 DWORD viewport : 1;
5008 DWORD vertexDecl : 1;
5009 DWORD pixelShader : 1;
5010 DWORD vertexShader : 1;
5011 DWORD scissorRect : 1;
5012 DWORD store_stream_offset : 1;
5013 DWORD alpha_to_coverage : 1;
5014 DWORD lights : 1;
5015 DWORD transforms : 1;
5016 DWORD padding : 1;
5018 struct list changed_lights;
5021 struct StageState {
5022 DWORD stage;
5023 DWORD state;
5026 struct wined3d_stateblock
5028 LONG ref; /* Note: Ref counting not required */
5029 struct wined3d_device *device;
5031 /* Array indicating whether things have been set or changed */
5032 struct wined3d_saved_states changed;
5034 struct wined3d_stateblock_state stateblock_state;
5035 struct wined3d_light_state light_state;
5037 /* Contained state management */
5038 DWORD contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
5039 unsigned int num_contained_render_states;
5040 DWORD contained_transform_states[WINED3D_HIGHEST_TRANSFORM_STATE + 1];
5041 unsigned int num_contained_transform_states;
5042 struct StageState contained_tss_states[WINED3D_MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
5043 unsigned int num_contained_tss_states;
5044 struct StageState contained_sampler_states[WINED3D_MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
5045 unsigned int num_contained_sampler_states;
5048 void wined3d_stateblock_state_init(struct wined3d_stateblock_state *state,
5049 const struct wined3d_device *device, uint32_t flags) DECLSPEC_HIDDEN;
5050 void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) DECLSPEC_HIDDEN;
5052 bool wined3d_light_state_enable_light(struct wined3d_light_state *state, const struct wined3d_d3d_info *d3d_info,
5053 struct wined3d_light_info *light_info, BOOL enable) DECLSPEC_HIDDEN;
5054 struct wined3d_light_info *wined3d_light_state_get_light(const struct wined3d_light_state *state,
5055 unsigned int idx) DECLSPEC_HIDDEN;
5056 HRESULT wined3d_light_state_set_light(struct wined3d_light_state *state, DWORD light_idx,
5057 const struct wined3d_light *params, struct wined3d_light_info **light_info) DECLSPEC_HIDDEN;
5059 enum wined3d_cs_queue_id
5061 WINED3D_CS_QUEUE_DEFAULT = 0,
5062 WINED3D_CS_QUEUE_MAP,
5063 WINED3D_CS_QUEUE_COUNT,
5066 enum wined3d_push_constants
5068 WINED3D_PUSH_CONSTANTS_VS_F,
5069 WINED3D_PUSH_CONSTANTS_PS_F,
5070 WINED3D_PUSH_CONSTANTS_VS_I,
5071 WINED3D_PUSH_CONSTANTS_PS_I,
5072 WINED3D_PUSH_CONSTANTS_VS_B,
5073 WINED3D_PUSH_CONSTANTS_PS_B,
5076 #define WINED3D_CS_QUERY_POLL_INTERVAL 10u
5077 #define WINED3D_CS_QUEUE_SIZE 0x400000u
5078 #define WINED3D_CS_SPIN_COUNT 10000000u
5079 #define WINED3D_CS_QUEUE_MASK (WINED3D_CS_QUEUE_SIZE - 1)
5081 C_ASSERT(!(WINED3D_CS_QUEUE_SIZE & (WINED3D_CS_QUEUE_SIZE - 1)));
5083 struct wined3d_cs_queue
5085 ULONG head, tail;
5086 BYTE data[WINED3D_CS_QUEUE_SIZE];
5089 struct wined3d_device_context_ops
5091 void *(*require_space)(struct wined3d_device_context *context, size_t size, enum wined3d_cs_queue_id queue_id);
5092 void (*submit)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
5093 void (*finish)(struct wined3d_device_context *context, enum wined3d_cs_queue_id queue_id);
5094 void (*push_constants)(struct wined3d_device_context *context, enum wined3d_push_constants p,
5095 unsigned int start_idx, unsigned int count, const void *constants);
5096 bool (*map_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
5097 unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
5098 const struct wined3d_box *box, uint32_t flags);
5099 bool (*unmap_upload_bo)(struct wined3d_device_context *context, struct wined3d_resource *resource,
5100 unsigned int sub_resource_idx, struct wined3d_box *box, struct upload_bo *upload_bo);
5101 void (*issue_query)(struct wined3d_device_context *context, struct wined3d_query *query, unsigned int flags);
5102 void (*flush)(struct wined3d_device_context *context);
5103 void (*reference_resource)(struct wined3d_device_context *context, struct wined3d_resource *resource);
5104 void (*reference_command_list)(struct wined3d_device_context *context, struct wined3d_command_list *list);
5107 struct wined3d_device_context
5109 const struct wined3d_device_context_ops *ops;
5110 struct wined3d_device *device;
5111 struct wined3d_state *state;
5114 struct wined3d_cs
5116 struct wined3d_device_context c;
5118 struct wined3d_state state;
5119 HMODULE wined3d_module;
5120 HANDLE thread;
5121 DWORD thread_id;
5122 BOOL serialize_commands;
5124 struct wined3d_cs_queue queue[WINED3D_CS_QUEUE_COUNT];
5125 size_t data_size, start, end;
5126 void *data;
5127 struct list query_poll_list;
5128 BOOL queries_flushed;
5130 HANDLE event;
5131 LONG waiting_for_event;
5132 LONG pending_presents;
5135 static inline void wined3d_device_context_lock(struct wined3d_device_context *context)
5137 if (context == &context->device->cs->c)
5138 wined3d_mutex_lock();
5141 static inline void wined3d_device_context_unlock(struct wined3d_device_context *context)
5143 if (context == &context->device->cs->c)
5144 wined3d_mutex_unlock();
5147 struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device,
5148 const enum wined3d_feature_level *levels, unsigned int level_count) DECLSPEC_HIDDEN;
5149 void wined3d_cs_destroy(struct wined3d_cs *cs) DECLSPEC_HIDDEN;
5150 void wined3d_cs_destroy_object(struct wined3d_cs *cs,
5151 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
5152 void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs *cs,
5153 struct wined3d_texture *texture, unsigned int layer) DECLSPEC_HIDDEN;
5154 void wined3d_cs_emit_clear(struct wined3d_cs *cs, DWORD rect_count, const RECT *rects,
5155 uint32_t flags, const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
5156 void wined3d_device_context_emit_clear_uav(struct wined3d_device_context *context,
5157 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp) DECLSPEC_HIDDEN;
5158 void wined3d_cs_emit_preload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
5159 void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *swapchain, const RECT *src_rect,
5160 const RECT *dst_rect, HWND dst_window_override, unsigned int swap_interval, uint32_t flags) DECLSPEC_HIDDEN;
5161 void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture *texture,
5162 WORD flags, const struct wined3d_color_key *color_key) DECLSPEC_HIDDEN;
5163 void wined3d_cs_emit_set_render_state(struct wined3d_cs *cs,
5164 enum wined3d_render_state state, DWORD value) DECLSPEC_HIDDEN;
5165 void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
5166 void wined3d_cs_init_object(struct wined3d_cs *cs,
5167 void (*callback)(void *object), void *object) DECLSPEC_HIDDEN;
5168 void wined3d_cs_map_bo_address(struct wined3d_cs *cs,
5169 struct wined3d_bo_address *addr, size_t size, unsigned int flags) DECLSPEC_HIDDEN;
5170 void wined3d_device_context_set_depth_bounds(struct wined3d_device_context *context,
5171 bool enable, float min_depth, float max_depth);
5173 static inline void wined3d_cs_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
5175 cs->c.ops->finish(&cs->c, queue_id);
5178 static inline void wined3d_device_context_push_constants(struct wined3d_device_context *context,
5179 enum wined3d_push_constants p, unsigned int start_idx, unsigned int count, const void *constants)
5181 context->ops->push_constants(context, p, start_idx, count, constants);
5184 void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context *context,
5185 struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, const struct wined3d_box *dst_box,
5186 struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box,
5187 unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
5188 void wined3d_device_context_emit_clear_rendertarget_view(struct wined3d_device_context *context,
5189 struct wined3d_rendertarget_view *view, const RECT *rect, unsigned int flags,
5190 const struct wined3d_color *color, float depth, unsigned int stencil) DECLSPEC_HIDDEN;
5191 void wined3d_device_context_emit_copy_uav_counter(struct wined3d_device_context *context,
5192 struct wined3d_buffer *dst_buffer, unsigned int offset,
5193 struct wined3d_unordered_access_view *uav) DECLSPEC_HIDDEN;
5194 void wined3d_device_context_emit_draw(struct wined3d_device_context *context,
5195 enum wined3d_primitive_type primitive_type, unsigned int patch_vertex_count, int base_vertex_idx,
5196 unsigned int start_idx, unsigned int index_count, unsigned int start_instance, unsigned int instance_count,
5197 bool indexed) DECLSPEC_HIDDEN;
5198 void wined3d_device_context_emit_execute_command_list(struct wined3d_device_context *context,
5199 struct wined3d_command_list *list, bool restore_state) DECLSPEC_HIDDEN;
5200 void wined3d_device_context_emit_generate_mipmaps(struct wined3d_device_context *context,
5201 struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
5202 HRESULT wined3d_device_context_emit_map(struct wined3d_device_context *context,
5203 struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc,
5204 const struct wined3d_box *box, unsigned int flags) DECLSPEC_HIDDEN;
5205 void wined3d_device_context_emit_reset_state(struct wined3d_device_context *context, bool invalidate) DECLSPEC_HIDDEN;
5206 void wined3d_device_context_emit_set_blend_state(struct wined3d_device_context *context,
5207 struct wined3d_blend_state *state, const struct wined3d_color *blend_factor,
5208 unsigned int sample_mask) DECLSPEC_HIDDEN;
5209 void wined3d_device_context_emit_set_clip_plane(struct wined3d_device_context *context, unsigned int plane_idx,
5210 const struct wined3d_vec4 *plane) DECLSPEC_HIDDEN;
5211 void wined3d_device_context_emit_set_constant_buffers(struct wined3d_device_context *context,
5212 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
5213 const struct wined3d_constant_buffer_state *buffers) DECLSPEC_HIDDEN;
5214 void wined3d_device_context_emit_set_depth_stencil_state(struct wined3d_device_context *context,
5215 struct wined3d_depth_stencil_state *state, unsigned int stencil_ref) DECLSPEC_HIDDEN;
5216 void wined3d_device_context_emit_set_depth_stencil_view(struct wined3d_device_context *context,
5217 struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
5218 void wined3d_device_context_emit_set_feature_level(struct wined3d_device_context *context,
5219 enum wined3d_feature_level level) DECLSPEC_HIDDEN;
5220 void wined3d_device_context_emit_set_index_buffer(struct wined3d_device_context *context, struct wined3d_buffer *buffer,
5221 enum wined3d_format_id format_id, unsigned int offset) DECLSPEC_HIDDEN;
5222 void wined3d_device_context_emit_set_light(struct wined3d_device_context *context,
5223 const struct wined3d_light_info *light) DECLSPEC_HIDDEN;
5224 void wined3d_device_context_emit_set_light_enable(struct wined3d_device_context *context, unsigned int idx,
5225 BOOL enable) DECLSPEC_HIDDEN;
5226 void wined3d_device_context_emit_set_material(struct wined3d_device_context *context,
5227 const struct wined3d_material *material) DECLSPEC_HIDDEN;
5228 void wined3d_device_context_emit_set_predication(struct wined3d_device_context *context,
5229 struct wined3d_query *predicate, BOOL value) DECLSPEC_HIDDEN;
5230 void wined3d_device_context_emit_set_rasterizer_state(struct wined3d_device_context *context,
5231 struct wined3d_rasterizer_state *rasterizer_state) DECLSPEC_HIDDEN;
5232 void wined3d_device_context_emit_set_render_state(struct wined3d_device_context *context,
5233 enum wined3d_render_state state, unsigned int value) DECLSPEC_HIDDEN;
5234 void wined3d_device_context_emit_set_rendertarget_views(struct wined3d_device_context *context, unsigned int start_idx,
5235 unsigned int count, struct wined3d_rendertarget_view *const *views) DECLSPEC_HIDDEN;
5236 void wined3d_device_context_emit_set_samplers(struct wined3d_device_context *context, enum wined3d_shader_type type,
5237 unsigned int start_idx, unsigned int count, struct wined3d_sampler *const *samplers) DECLSPEC_HIDDEN;
5238 void wined3d_device_context_emit_set_sampler_state(struct wined3d_device_context *context, unsigned int sampler_idx,
5239 enum wined3d_sampler_state state, unsigned int value) DECLSPEC_HIDDEN;
5240 void wined3d_device_context_emit_set_scissor_rects(struct wined3d_device_context *context,
5241 unsigned int rect_count, const RECT *rects) DECLSPEC_HIDDEN;
5242 void wined3d_device_context_emit_set_shader(struct wined3d_device_context *context, enum wined3d_shader_type type,
5243 struct wined3d_shader *shader) DECLSPEC_HIDDEN;
5244 void wined3d_device_context_emit_set_shader_resource_views(struct wined3d_device_context *context,
5245 enum wined3d_shader_type type, unsigned int start_idx, unsigned int count,
5246 struct wined3d_shader_resource_view *const *views) DECLSPEC_HIDDEN;
5247 void wined3d_device_context_emit_set_stream_outputs(struct wined3d_device_context *context,
5248 const struct wined3d_stream_output outputs[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]) DECLSPEC_HIDDEN;
5249 void wined3d_device_context_emit_set_stream_sources(struct wined3d_device_context *context,
5250 unsigned int start_idx, unsigned int count, const struct wined3d_stream_state *streams) DECLSPEC_HIDDEN;
5251 void wined3d_device_context_emit_set_texture(struct wined3d_device_context *context, unsigned int stage,
5252 struct wined3d_texture *texture) DECLSPEC_HIDDEN;
5253 void wined3d_device_context_emit_set_texture_state(struct wined3d_device_context *context, unsigned int stage,
5254 enum wined3d_texture_stage_state state, unsigned int value) DECLSPEC_HIDDEN;
5255 void wined3d_device_context_emit_set_transform(struct wined3d_device_context *context,
5256 enum wined3d_transform_state state, const struct wined3d_matrix *matrix) DECLSPEC_HIDDEN;
5257 void wined3d_device_context_emit_set_unordered_access_views(struct wined3d_device_context *context,
5258 enum wined3d_pipeline pipeline, unsigned int start_idx, unsigned int count,
5259 struct wined3d_unordered_access_view *const *views, const unsigned int *initial_count) DECLSPEC_HIDDEN;
5260 void wined3d_device_context_emit_set_vertex_declaration(struct wined3d_device_context *context,
5261 struct wined3d_vertex_declaration *declaration) DECLSPEC_HIDDEN;
5262 void wined3d_device_context_emit_set_viewports(struct wined3d_device_context *context, unsigned int viewport_count,
5263 const struct wined3d_viewport *viewports) DECLSPEC_HIDDEN;
5264 void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context,
5265 struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box,
5266 const void *data, unsigned int row_pitch, unsigned int slice_pitch) DECLSPEC_HIDDEN;
5267 HRESULT wined3d_device_context_emit_unmap(struct wined3d_device_context *context,
5268 struct wined3d_resource *resource, unsigned int sub_resource_idx) DECLSPEC_HIDDEN;
5270 static inline void wined3d_resource_reference(struct wined3d_resource *resource)
5272 const struct wined3d_cs *cs = resource->device->cs;
5273 resource->access_time = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
5276 static inline BOOL wined3d_ge_wrap(ULONG x, ULONG y)
5278 return (x - y) < UINT_MAX / 2;
5280 C_ASSERT(WINED3D_CS_QUEUE_SIZE < UINT_MAX / 4);
5282 static inline void wined3d_resource_wait_idle(const struct wined3d_resource *resource)
5284 const struct wined3d_cs *cs = resource->device->cs;
5285 ULONG access_time, tail, head;
5287 if (!cs->thread || cs->thread_id == GetCurrentThreadId())
5288 return;
5290 access_time = resource->access_time;
5291 head = cs->queue[WINED3D_CS_QUEUE_DEFAULT].head;
5293 /* The basic idea is that a resource is busy if tail < access_time <= head.
5294 * But we have to be careful about wrap-around of the head and tail. The
5295 * wined3d_ge_wrap function considers x >= y if x - y is smaller than half the
5296 * UINT range. Head is at most WINED3D_CS_QUEUE_SIZE ahead of tail, because
5297 * otherwise the queue memory is considered full and queue_require_space
5298 * stalls. Thus wined3d_ge_wrap(head, tail) is always true. The C_ASSERT above
5299 * ensures this in case we decide to grow the queue size in the future.
5301 * It is possible that a resource has not been used for a long time and is idle, but the head and
5302 * tail wrapped around in such a way that the previously set access time falls between head and tail.
5303 * In this case we will incorrectly wait for the resource. Because we use the entire 32 bits of the
5304 * counters and not just the bits needed to address the actual queue memory, this should happen rarely.
5305 * If it turns out to be a problem we can switch to 64 bit counters or attempt to somehow mark the
5306 * access time of resources invalid. CS packets are at least 4 byte aligned, so we could use the lower
5307 * 2 bits in access_time for such a marker.
5309 * Note that the access time is set before the command is submitted, so we have to wait until the
5310 * tail is bigger than access_time, not equal. */
5312 if (!wined3d_ge_wrap(head, access_time))
5313 return;
5315 for (;;)
5317 tail = *(volatile ULONG *)&cs->queue[WINED3D_CS_QUEUE_DEFAULT].tail;
5318 if (head == tail) /* Queue empty. */
5319 break;
5321 if (!wined3d_ge_wrap(access_time, tail) && access_time != tail)
5322 break;
5324 YieldProcessor();
5328 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
5329 * fixed function semantics as D3DCOLOR or FLOAT16 */
5330 enum wined3d_buffer_conversion_type
5332 CONV_NONE,
5333 CONV_D3DCOLOR,
5334 CONV_POSITIONT,
5337 struct wined3d_buffer
5339 struct wined3d_resource resource;
5340 const struct wined3d_buffer_ops *buffer_ops;
5342 unsigned int structure_byte_stride;
5343 uint32_t flags;
5344 DWORD locations;
5345 void *map_ptr;
5346 struct wined3d_bo *buffer_object;
5347 struct wined3d_bo_user bo_user;
5349 struct wined3d_range *maps;
5350 SIZE_T maps_size, modified_areas;
5352 /* conversion stuff */
5353 UINT decl_change_count, full_conversion_count;
5354 UINT draw_count;
5355 UINT stride; /* 0 if no conversion */
5356 enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */
5357 UINT conversion_stride; /* 0 if no shifted conversion */
5360 static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resource *resource)
5362 return CONTAINING_RECORD(resource, struct wined3d_buffer, resource);
5365 void wined3d_buffer_cleanup(struct wined3d_buffer *buffer) DECLSPEC_HIDDEN;
5366 void wined3d_buffer_copy(struct wined3d_buffer *dst_buffer, unsigned int dst_offset,
5367 struct wined3d_buffer *src_buffer, unsigned int src_offset, unsigned int size) DECLSPEC_HIDDEN;
5368 void wined3d_buffer_copy_bo_address(struct wined3d_buffer *dst_buffer, struct wined3d_context *context,
5369 unsigned int dst_offset, const struct wined3d_const_bo_address *src_addr, unsigned int size) DECLSPEC_HIDDEN;
5370 DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, struct wined3d_context *context,
5371 struct wined3d_bo_address *data) DECLSPEC_HIDDEN;
5372 void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, uint32_t location) DECLSPEC_HIDDEN;
5373 void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context *context,
5374 const struct wined3d_state *state) DECLSPEC_HIDDEN;
5375 BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer,
5376 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
5377 BYTE *wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context) DECLSPEC_HIDDEN;
5378 BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer,
5379 struct wined3d_context *context, unsigned int location) DECLSPEC_HIDDEN;
5380 void wined3d_buffer_update_sub_resource(struct wined3d_buffer *buffer, struct wined3d_context *context,
5381 const struct upload_bo *upload_bo, unsigned int offset, unsigned int size) DECLSPEC_HIDDEN;
5383 HRESULT wined3d_buffer_no3d_init(struct wined3d_buffer *buffer_no3d, struct wined3d_device *device,
5384 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
5385 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5387 struct wined3d_buffer_gl
5389 struct wined3d_buffer b;
5392 static inline struct wined3d_buffer_gl *wined3d_buffer_gl(struct wined3d_buffer *buffer)
5394 return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
5397 static inline const struct wined3d_buffer_gl *wined3d_buffer_gl_const(const struct wined3d_buffer *buffer)
5399 return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
5402 GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info,
5403 uint32_t bind_flags) DECLSPEC_HIDDEN;
5404 HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device,
5405 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
5406 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5408 struct wined3d_buffer_vk
5410 struct wined3d_buffer b;
5412 VkDescriptorBufferInfo buffer_info;
5413 uint32_t bind_mask;
5416 static inline struct wined3d_buffer_vk *wined3d_buffer_vk(struct wined3d_buffer *buffer)
5418 return CONTAINING_RECORD(buffer, struct wined3d_buffer_vk, b);
5421 void wined3d_buffer_vk_barrier(struct wined3d_buffer_vk *buffer_vk,
5422 struct wined3d_context_vk *context_vk, uint32_t bind_mask) DECLSPEC_HIDDEN;
5423 const VkDescriptorBufferInfo *wined3d_buffer_vk_get_buffer_info(struct wined3d_buffer_vk *buffer_vk) DECLSPEC_HIDDEN;
5424 HRESULT wined3d_buffer_vk_init(struct wined3d_buffer_vk *buffer_vk, struct wined3d_device *device,
5425 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
5426 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5428 static inline void wined3d_resource_vk_barrier(struct wined3d_resource *resource,
5429 struct wined3d_context_vk *context_vk, uint32_t bind_mask)
5431 if (resource->type == WINED3D_RTYPE_BUFFER)
5432 wined3d_buffer_vk_barrier(wined3d_buffer_vk(buffer_from_resource(resource)), context_vk, bind_mask);
5433 else
5434 wined3d_texture_vk_barrier(wined3d_texture_vk(texture_from_resource(resource)), context_vk, bind_mask);
5437 struct wined3d_rendertarget_view
5439 LONG refcount;
5441 struct wined3d_resource *resource;
5442 void *parent;
5443 const struct wined3d_parent_ops *parent_ops;
5445 const struct wined3d_format *format;
5446 unsigned int format_attrs;
5447 unsigned int format_caps;
5448 unsigned int sub_resource_idx;
5449 unsigned int layer_count;
5451 unsigned int width;
5452 unsigned int height;
5454 struct wined3d_view_desc desc;
5457 void wined3d_rendertarget_view_cleanup(struct wined3d_rendertarget_view *view) DECLSPEC_HIDDEN;
5458 void wined3d_rendertarget_view_get_drawable_size(const struct wined3d_rendertarget_view *view,
5459 const struct wined3d_context *context, unsigned int *width, unsigned int *height) DECLSPEC_HIDDEN;
5460 void wined3d_rendertarget_view_get_box(struct wined3d_rendertarget_view *view,
5461 struct wined3d_box *box) DECLSPEC_HIDDEN;
5462 void wined3d_rendertarget_view_invalidate_location(struct wined3d_rendertarget_view *view,
5463 uint32_t location) DECLSPEC_HIDDEN;
5464 void wined3d_rendertarget_view_load_location(struct wined3d_rendertarget_view *view,
5465 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
5466 void wined3d_rendertarget_view_prepare_location(struct wined3d_rendertarget_view *view,
5467 struct wined3d_context *context, uint32_t location) DECLSPEC_HIDDEN;
5468 void wined3d_rendertarget_view_validate_location(struct wined3d_rendertarget_view *view,
5469 uint32_t location) DECLSPEC_HIDDEN;
5470 DWORD wined3d_rendertarget_view_get_locations(const struct wined3d_rendertarget_view *view)
5471 DECLSPEC_HIDDEN;
5473 HRESULT wined3d_rendertarget_view_no3d_init(struct wined3d_rendertarget_view *view_no3d,
5474 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5475 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5477 struct wined3d_rendertarget_view_gl
5479 struct wined3d_rendertarget_view v;
5480 struct wined3d_gl_view gl_view;
5483 static inline struct wined3d_rendertarget_view_gl *wined3d_rendertarget_view_gl(
5484 struct wined3d_rendertarget_view *view)
5486 return CONTAINING_RECORD(view, struct wined3d_rendertarget_view_gl, v);
5489 HRESULT wined3d_rendertarget_view_gl_init(struct wined3d_rendertarget_view_gl *view_gl,
5490 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5491 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5493 struct wined3d_rendertarget_view_vk
5495 struct wined3d_rendertarget_view v;
5497 VkImageView vk_image_view;
5498 uint64_t command_buffer_id;
5501 static inline struct wined3d_rendertarget_view_vk *wined3d_rendertarget_view_vk(
5502 struct wined3d_rendertarget_view *view)
5504 return CONTAINING_RECORD(view, struct wined3d_rendertarget_view_vk, v);
5507 static inline void wined3d_rendertarget_view_vk_barrier(struct wined3d_rendertarget_view_vk *rtv_vk,
5508 struct wined3d_context_vk *context_vk, uint32_t bind_mask)
5510 wined3d_resource_vk_barrier(rtv_vk->v.resource, context_vk, bind_mask);
5513 static inline VkImageView wined3d_rendertarget_view_vk_get_image_view(struct wined3d_rendertarget_view_vk *rtv_vk,
5514 struct wined3d_context_vk *context_vk)
5516 struct wined3d_texture_vk *texture_vk;
5518 if (rtv_vk->vk_image_view)
5519 return rtv_vk->vk_image_view;
5521 texture_vk = wined3d_texture_vk(wined3d_texture_from_resource(rtv_vk->v.resource));
5522 return wined3d_texture_vk_get_default_image_info(texture_vk, context_vk)->imageView;
5525 HRESULT wined3d_rendertarget_view_vk_init(struct wined3d_rendertarget_view_vk *view_vk,
5526 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5527 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5529 struct wined3d_shader_resource_view
5531 LONG refcount;
5533 struct wined3d_resource *resource;
5534 void *parent;
5535 const struct wined3d_parent_ops *parent_ops;
5537 const struct wined3d_format *format;
5539 struct wined3d_view_desc desc;
5542 void wined3d_shader_resource_view_cleanup(struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
5544 struct wined3d_shader_resource_view_gl
5546 struct wined3d_shader_resource_view v;
5547 struct wined3d_bo_user bo_user;
5548 struct wined3d_gl_view gl_view;
5551 static inline struct wined3d_shader_resource_view_gl *wined3d_shader_resource_view_gl(
5552 struct wined3d_shader_resource_view *view)
5554 return CONTAINING_RECORD(view, struct wined3d_shader_resource_view_gl, v);
5557 void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl *view_gl, unsigned int unit,
5558 struct wined3d_sampler_gl *sampler_gl, struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
5559 void wined3d_shader_resource_view_gl_generate_mipmap(struct wined3d_shader_resource_view_gl *srv_gl,
5560 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
5561 HRESULT wined3d_shader_resource_view_gl_init(struct wined3d_shader_resource_view_gl *view_gl,
5562 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5563 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5564 void wined3d_shader_resource_view_gl_update(struct wined3d_shader_resource_view_gl *srv_gl,
5565 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
5567 struct wined3d_view_vk
5569 struct wined3d_bo_user bo_user;
5570 union
5572 VkBufferView vk_buffer_view;
5573 VkDescriptorImageInfo vk_image_info;
5574 } u;
5575 uint64_t command_buffer_id;
5578 struct wined3d_shader_resource_view_vk
5580 struct wined3d_shader_resource_view v;
5581 struct wined3d_view_vk view_vk;
5584 static inline struct wined3d_shader_resource_view_vk *wined3d_shader_resource_view_vk(
5585 struct wined3d_shader_resource_view *view)
5587 return CONTAINING_RECORD(view, struct wined3d_shader_resource_view_vk, v);
5590 static inline void wined3d_shader_resource_view_vk_barrier(struct wined3d_shader_resource_view_vk *srv_vk,
5591 struct wined3d_context_vk *context_vk, uint32_t bind_mask)
5593 wined3d_resource_vk_barrier(srv_vk->v.resource, context_vk, bind_mask);
5596 void wined3d_shader_resource_view_vk_generate_mipmap(struct wined3d_shader_resource_view_vk *srv_vk,
5597 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
5598 HRESULT wined3d_shader_resource_view_vk_init(struct wined3d_shader_resource_view_vk *view_vk,
5599 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5600 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5601 void wined3d_shader_resource_view_vk_update_buffer(struct wined3d_shader_resource_view_vk *view_vk,
5602 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
5603 void wined3d_shader_resource_view_vk_update_layout(struct wined3d_shader_resource_view_vk *srv_vk,
5604 VkImageLayout layout) DECLSPEC_HIDDEN;
5606 struct wined3d_unordered_access_view
5608 LONG refcount;
5610 struct wined3d_resource *resource;
5611 void *parent;
5612 const struct wined3d_parent_ops *parent_ops;
5614 const struct wined3d_format *format;
5616 struct wined3d_view_desc desc;
5617 struct wined3d_bo *counter_bo;
5620 void wined3d_unordered_access_view_cleanup(struct wined3d_unordered_access_view *view) DECLSPEC_HIDDEN;
5621 void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_view *view,
5622 struct wined3d_buffer *buffer, unsigned int offset, struct wined3d_context *context) DECLSPEC_HIDDEN;
5623 void wined3d_unordered_access_view_invalidate_location(struct wined3d_unordered_access_view *view,
5624 uint32_t location) DECLSPEC_HIDDEN;
5625 void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_view *view,
5626 unsigned int value) DECLSPEC_HIDDEN;
5628 struct wined3d_unordered_access_view_gl
5630 struct wined3d_unordered_access_view v;
5631 struct wined3d_bo_user bo_user;
5632 struct wined3d_gl_view gl_view;
5633 struct wined3d_bo_gl counter_bo;
5636 static inline struct wined3d_unordered_access_view_gl *wined3d_unordered_access_view_gl(
5637 struct wined3d_unordered_access_view *view)
5639 return CONTAINING_RECORD(view, struct wined3d_unordered_access_view_gl, v);
5642 void wined3d_unordered_access_view_gl_clear(struct wined3d_unordered_access_view_gl *view_gl,
5643 const struct wined3d_uvec4 *clear_value, struct wined3d_context_gl *context_gl, bool fp) DECLSPEC_HIDDEN;
5644 HRESULT wined3d_unordered_access_view_gl_init(struct wined3d_unordered_access_view_gl *view_gl,
5645 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5646 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5647 void wined3d_unordered_access_view_gl_update(struct wined3d_unordered_access_view_gl *uav_gl,
5648 struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
5650 struct wined3d_unordered_access_view_vk
5652 struct wined3d_unordered_access_view v;
5653 struct wined3d_view_vk view_vk;
5655 VkBufferView vk_counter_view;
5656 struct wined3d_bo_vk counter_bo;
5659 static inline struct wined3d_unordered_access_view_vk *wined3d_unordered_access_view_vk(
5660 struct wined3d_unordered_access_view *view)
5662 return CONTAINING_RECORD(view, struct wined3d_unordered_access_view_vk, v);
5665 static inline void wined3d_unordered_access_view_vk_barrier(struct wined3d_unordered_access_view_vk *uav_vk,
5666 struct wined3d_context_vk *context_vk, uint32_t bind_mask)
5668 wined3d_resource_vk_barrier(uav_vk->v.resource, context_vk, bind_mask);
5671 void wined3d_unordered_access_view_vk_clear(struct wined3d_unordered_access_view_vk *view_vk,
5672 const struct wined3d_uvec4 *clear_value, struct wined3d_context_vk *context_vk, bool fp) DECLSPEC_HIDDEN;
5673 HRESULT wined3d_unordered_access_view_vk_init(struct wined3d_unordered_access_view_vk *view_vk,
5674 const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
5675 void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5676 void wined3d_unordered_access_view_vk_update(struct wined3d_unordered_access_view_vk *view_vk,
5677 struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
5679 struct wined3d_swapchain_state
5681 struct wined3d *wined3d;
5682 struct wined3d_swapchain_desc desc;
5683 struct wined3d_swapchain_state_parent *parent;
5685 struct wined3d_display_mode original_mode, d3d_mode;
5686 RECT original_window_rect;
5688 /* Window styles to restore when switching fullscreen mode. */
5689 LONG style;
5690 LONG exstyle;
5691 HWND device_window;
5694 void wined3d_swapchain_state_cleanup(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
5695 void wined3d_swapchain_state_register(struct wined3d_swapchain_state *state) DECLSPEC_HIDDEN;
5696 void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state,
5697 HWND window, const RECT *window_rect) DECLSPEC_HIDDEN;
5698 HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
5699 HWND window, int x, int y, int width, int height) DECLSPEC_HIDDEN;
5701 struct wined3d_swapchain_ops
5703 void (*swapchain_present)(struct wined3d_swapchain *swapchain,
5704 const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, uint32_t flags);
5705 void (*swapchain_frontbuffer_updated)(struct wined3d_swapchain *swapchain);
5708 struct wined3d_swapchain
5710 LONG ref;
5711 void *parent;
5712 const struct wined3d_parent_ops *parent_ops;
5713 const struct wined3d_swapchain_ops *swapchain_ops;
5714 struct wined3d_device *device;
5716 struct wined3d_texture **back_buffers;
5717 struct wined3d_texture *front_buffer;
5718 struct wined3d_gamma_ramp orig_gamma;
5719 bool reapply_mode;
5720 const struct wined3d_format *ds_format;
5721 struct wined3d_palette *palette;
5722 RECT front_buffer_update;
5723 unsigned int swap_interval;
5724 unsigned int max_frame_latency;
5726 LONG prev_time, frames; /* Performance tracking */
5728 struct wined3d_swapchain_state state;
5729 HWND win_handle;
5732 void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activate) DECLSPEC_HIDDEN;
5733 void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
5734 struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
5735 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
5736 void swapchain_set_max_frame_latency(struct wined3d_swapchain *swapchain,
5737 const struct wined3d_device *device) DECLSPEC_HIDDEN;
5739 HRESULT wined3d_swapchain_no3d_init(struct wined3d_swapchain *swapchain_no3d,
5740 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
5741 struct wined3d_swapchain_state_parent *state_parent, void *parent,
5742 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5744 struct wined3d_swapchain_gl
5746 struct wined3d_swapchain s;
5749 static inline struct wined3d_swapchain_gl *wined3d_swapchain_gl(struct wined3d_swapchain *swapchain)
5751 return CONTAINING_RECORD(swapchain, struct wined3d_swapchain_gl, s);
5754 void wined3d_swapchain_gl_cleanup(struct wined3d_swapchain_gl *swapchain_gl) DECLSPEC_HIDDEN;
5755 struct wined3d_context_gl *wined3d_swapchain_gl_get_context(struct wined3d_swapchain_gl *swapchain_gl) DECLSPEC_HIDDEN;
5756 HRESULT wined3d_swapchain_gl_init(struct wined3d_swapchain_gl *swapchain_gl,
5757 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
5758 struct wined3d_swapchain_state_parent *state_parent, void *parent,
5759 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5761 struct wined3d_swapchain_vk
5763 struct wined3d_swapchain s;
5765 VkSwapchainKHR vk_swapchain;
5766 VkSurfaceKHR vk_surface;
5767 VkImage *vk_images;
5768 struct
5770 VkSemaphore available;
5771 VkSemaphore presentable;
5772 uint64_t command_buffer_id;
5773 } *vk_semaphores;
5774 unsigned int current, image_count;
5775 unsigned int width, height;
5778 static inline struct wined3d_swapchain_vk *wined3d_swapchain_vk(struct wined3d_swapchain *swapchain)
5780 return CONTAINING_RECORD(swapchain, struct wined3d_swapchain_vk, s);
5783 void wined3d_swapchain_vk_cleanup(struct wined3d_swapchain_vk *swapchain_vk) DECLSPEC_HIDDEN;
5784 HRESULT wined3d_swapchain_vk_init(struct wined3d_swapchain_vk *swapchain_vk,
5785 struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
5786 struct wined3d_swapchain_state_parent *state_parent, void *parent,
5787 const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
5789 /*****************************************************************************
5790 * Utility function prototypes
5793 /* Trace routines */
5794 const char *debug_bo_address(const struct wined3d_bo_address *address) DECLSPEC_HIDDEN;
5795 const char *debug_box(const struct wined3d_box *box) DECLSPEC_HIDDEN;
5796 const char *debug_color(const struct wined3d_color *color) DECLSPEC_HIDDEN;
5797 const char *debug_const_bo_address(const struct wined3d_const_bo_address *address) DECLSPEC_HIDDEN;
5798 const char *debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx) DECLSPEC_HIDDEN;
5799 const char *debug_d3dformat(enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
5800 const char *debug_d3ddevicetype(enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
5801 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) DECLSPEC_HIDDEN;
5802 const char *debug_d3dusage(uint32_t usage) DECLSPEC_HIDDEN;
5803 const char *debug_d3ddeclmethod(enum wined3d_decl_method method) DECLSPEC_HIDDEN;
5804 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
5805 const char *debug_d3dinput_classification(enum wined3d_input_classification classification) DECLSPEC_HIDDEN;
5806 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) DECLSPEC_HIDDEN;
5807 const char *debug_d3drenderstate(enum wined3d_render_state state) DECLSPEC_HIDDEN;
5808 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) DECLSPEC_HIDDEN;
5809 const char *debug_d3dstate(uint32_t state) DECLSPEC_HIDDEN;
5810 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) DECLSPEC_HIDDEN;
5811 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) DECLSPEC_HIDDEN;
5812 const char *debug_d3dtop(enum wined3d_texture_op d3dtop) DECLSPEC_HIDDEN;
5813 const char *debug_d3dtstype(enum wined3d_transform_state tstype) DECLSPEC_HIDDEN;
5814 const char *debug_fboattachment(GLenum attachment) DECLSPEC_HIDDEN;
5815 const char *debug_fbostatus(GLenum status) DECLSPEC_HIDDEN;
5816 const char *debug_glerror(GLenum error) DECLSPEC_HIDDEN;
5817 const char *debug_ivec4(const struct wined3d_ivec4 *v) DECLSPEC_HIDDEN;
5818 const char *debug_uvec4(const struct wined3d_uvec4 *v) DECLSPEC_HIDDEN;
5819 const char *debug_shader_type(enum wined3d_shader_type shader_type) DECLSPEC_HIDDEN;
5820 const char *debug_vec4(const struct wined3d_vec4 *v) DECLSPEC_HIDDEN;
5821 const char *wined3d_debug_feature_level(enum wined3d_feature_level level) DECLSPEC_HIDDEN;
5822 void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
5824 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
5825 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
5826 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
5827 BOOL is_alpha, int stage, enum wined3d_texture_op op, uint32_t arg1, uint32_t arg2, uint32_t arg3,
5828 INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
5829 void texture_activate_dimensions(struct wined3d_texture *texture,
5830 const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
5831 void sampler_texdim(struct wined3d_context *context,
5832 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5833 void tex_alphaop(struct wined3d_context *context,
5834 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5835 void apply_pixelshader(struct wined3d_context *context,
5836 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5837 void state_alpha_test(struct wined3d_context *context,
5838 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5839 void state_fogcolor(struct wined3d_context *context,
5840 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5841 void state_fogdensity(struct wined3d_context *context,
5842 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5843 void state_fogstartend(struct wined3d_context *context,
5844 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5845 void state_fog_fragpart(struct wined3d_context *context,
5846 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5847 void state_nop(struct wined3d_context *context,
5848 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5849 void state_srgbwrite(struct wined3d_context *context,
5850 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5852 void state_clipping(struct wined3d_context *context,
5853 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5854 void clipplane(struct wined3d_context *context,
5855 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5856 void state_pointsprite_w(struct wined3d_context *context,
5857 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5858 void state_pointsprite(struct wined3d_context *context,
5859 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5860 void state_shademode(struct wined3d_context *context,
5861 const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
5863 /* Math utils */
5864 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
5865 const struct wined3d_matrix *src2) DECLSPEC_HIDDEN;
5867 void wined3d_release_dc(HWND window, HDC dc) DECLSPEC_HIDDEN;
5869 struct wined3d_shader_lconst
5871 struct list entry;
5872 unsigned int idx;
5873 unsigned int value[4];
5876 struct wined3d_shader_limits
5878 unsigned int sampler;
5879 unsigned int constant_int;
5880 unsigned int constant_float;
5881 unsigned int constant_bool;
5882 unsigned int packed_output;
5883 unsigned int packed_input;
5886 #define wined3d_lock_init(lock, name) wined3d_lock_init_(lock, __FILE__ ": " name)
5887 static inline void wined3d_lock_init_(CRITICAL_SECTION *lock, const char *name)
5889 InitializeCriticalSection(lock);
5890 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
5891 lock->DebugInfo->Spare[0] = (DWORD_PTR)name;
5894 static inline void wined3d_lock_cleanup(CRITICAL_SECTION *lock)
5896 if (lock->DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
5897 lock->DebugInfo->Spare[0] = 0;
5898 DeleteCriticalSection(lock);
5901 #ifdef __GNUC__
5902 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
5903 #else
5904 #define PRINTF_ATTR(fmt,args)
5905 #endif
5907 struct wined3d_string_buffer_list
5909 struct list list;
5912 struct wined3d_string_buffer *string_buffer_get(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
5913 void string_buffer_sprintf(struct wined3d_string_buffer *buffer, const char *format, ...) PRINTF_ATTR(2, 3) DECLSPEC_HIDDEN;
5914 void string_buffer_release(struct wined3d_string_buffer_list *list, struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
5915 void string_buffer_list_init(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
5916 void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list) DECLSPEC_HIDDEN;
5918 int shader_addline(struct wined3d_string_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
5919 BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc) DECLSPEC_HIDDEN;
5920 int shader_vaddline(struct wined3d_string_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
5922 struct wined3d_shader_phase
5924 const DWORD *start;
5925 const DWORD *end;
5926 unsigned int instance_count;
5927 unsigned int temporary_count;
5930 struct wined3d_vertex_shader
5932 struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
5935 struct wined3d_hull_shader
5937 struct
5939 struct wined3d_shader_phase *control_point;
5940 unsigned int fork_count;
5941 unsigned int join_count;
5942 struct wined3d_shader_phase *fork;
5943 SIZE_T fork_size;
5944 struct wined3d_shader_phase *join;
5945 SIZE_T join_size;
5946 } phases;
5947 unsigned int output_vertex_count;
5948 enum wined3d_tessellator_output_primitive tessellator_output_primitive;
5949 enum wined3d_tessellator_partitioning tessellator_partitioning;
5952 struct wined3d_domain_shader
5954 enum wined3d_tessellator_domain tessellator_domain;
5957 struct wined3d_geometry_shader
5959 enum wined3d_primitive_type input_type;
5960 enum wined3d_primitive_type output_type;
5961 unsigned int vertices_out;
5962 unsigned int instance_count;
5964 const struct wined3d_stream_output_desc *so_desc;
5967 struct wined3d_pixel_shader
5969 /* Pixel shader input semantics */
5970 unsigned int input_reg_map[MAX_REG_INPUT];
5971 DWORD input_reg_used; /* MAX_REG_INPUT, 32 */
5972 unsigned int declared_in_count;
5974 /* Some information about the shader behavior */
5975 BOOL color0_mov;
5976 unsigned int color0_reg;
5978 BOOL force_early_depth_stencil;
5979 enum wined3d_shader_register_type depth_output;
5980 uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE];
5983 struct wined3d_compute_shader
5985 struct wined3d_shader_thread_group_size thread_group_size;
5988 struct wined3d_shader
5990 LONG ref;
5991 const struct wined3d_shader_limits *limits;
5992 const DWORD *function;
5993 unsigned int functionLength;
5994 void *byte_code;
5995 unsigned int byte_code_size;
5996 BOOL load_local_constsF;
5997 const struct wined3d_shader_frontend *frontend;
5998 void *frontend_data;
5999 void *backend_data;
6001 void *parent;
6002 const struct wined3d_parent_ops *parent_ops;
6004 /* Programs this shader is linked with */
6005 struct list linked_programs;
6007 /* Immediate constants (override global ones) */
6008 struct list constantsB;
6009 struct list constantsF;
6010 struct list constantsI;
6011 struct wined3d_shader_reg_maps reg_maps;
6012 BOOL lconst_inf_or_nan;
6014 struct wined3d_shader_signature input_signature;
6015 struct wined3d_shader_signature output_signature;
6016 struct wined3d_shader_signature patch_constant_signature;
6018 /* Pointer to the parent device */
6019 struct wined3d_device *device;
6020 struct list shader_list_entry;
6022 union
6024 struct wined3d_vertex_shader vs;
6025 struct wined3d_hull_shader hs;
6026 struct wined3d_domain_shader ds;
6027 struct wined3d_geometry_shader gs;
6028 struct wined3d_pixel_shader ps;
6029 struct wined3d_compute_shader cs;
6030 } u;
6033 enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps,
6034 unsigned int resource_idx, DWORD tex_types) DECLSPEC_HIDDEN;
6035 void find_ps_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
6036 BOOL position_transformed, struct ps_compile_args *args,
6037 const struct wined3d_context *context) DECLSPEC_HIDDEN;
6039 bool vshader_get_input(const struct wined3d_shader *shader,
6040 uint8_t usage_req, uint8_t usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
6041 void find_vs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
6042 struct vs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
6044 void find_ds_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
6045 struct ds_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
6047 void find_gs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader,
6048 struct gs_compile_args *args, const struct wined3d_context *context) DECLSPEC_HIDDEN;
6050 void string_buffer_clear(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
6051 BOOL string_buffer_init(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
6052 void string_buffer_free(struct wined3d_string_buffer *buffer) DECLSPEC_HIDDEN;
6053 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps,
6054 unsigned int max) DECLSPEC_HIDDEN;
6055 HRESULT shader_generate_code(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer,
6056 const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx,
6057 const DWORD *start, const DWORD *end) DECLSPEC_HIDDEN;
6058 BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage) DECLSPEC_HIDDEN;
6060 static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
6062 switch (reg->type)
6064 case WINED3DSPR_RASTOUT:
6065 /* oFog & oPts */
6066 if (reg->idx[0].offset)
6067 return TRUE;
6068 /* oPos */
6069 return FALSE;
6071 case WINED3DSPR_CONSTBOOL: /* b# */
6072 case WINED3DSPR_DEPTHOUT: /* oDepth */
6073 case WINED3DSPR_DEPTHOUTGE:
6074 case WINED3DSPR_DEPTHOUTLE:
6075 case WINED3DSPR_LOOP: /* aL */
6076 case WINED3DSPR_OUTPOINTID:
6077 case WINED3DSPR_PREDICATE: /* p0 */
6078 case WINED3DSPR_PRIMID: /* primID */
6079 case WINED3DSPR_COVERAGE: /* vCoverage */
6080 case WINED3DSPR_SAMPLEMASK: /* oMask */
6081 return TRUE;
6083 case WINED3DSPR_MISCTYPE:
6084 switch (reg->idx[0].offset)
6086 case 0: /* vPos */
6087 return FALSE;
6088 case 1: /* vFace */
6089 return TRUE;
6090 default:
6091 return FALSE;
6094 case WINED3DSPR_IMMCONST:
6095 return reg->immconst_type == WINED3D_IMMCONST_SCALAR;
6097 default:
6098 return FALSE;
6102 static inline void shader_get_position_fixup(const struct wined3d_context *context,
6103 const struct wined3d_state *state, unsigned int fixup_count, float *position_fixup)
6105 float center_offset, x = 0.0f, y = 0.0f;
6106 unsigned int i;
6108 /* See get_projection_matrix() in utils.c for a discussion of the position fixup.
6109 * This function here also applies to d3d10+ which does not need adjustment for
6110 * integer pixel centers, but it may need the filling convention offset. */
6111 if (context->d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
6112 center_offset = 1.0f;
6113 else
6114 center_offset = 0.0f;
6116 center_offset += context->d3d_info->filling_convention_offset;
6118 for (i = 0; i < fixup_count; ++i)
6120 position_fixup[4 * i ] = 1.0f;
6121 position_fixup[4 * i + 1] = 1.0f;
6122 if (!context->d3d_info->subpixel_viewport)
6124 double dummy;
6125 x = modf(state->viewports[i].x, &dummy) * 2.0f;
6126 y = modf(state->viewports[i].y, &dummy) * 2.0f;
6128 position_fixup[4 * i + 2] = (center_offset + x) / state->viewports[i].width;
6129 position_fixup[4 * i + 3] = -(center_offset + y) / state->viewports[i].height;
6131 if (context->render_offscreen)
6133 position_fixup[4 * i + 1] *= -1.0f;
6134 position_fixup[4 * i + 3] *= -1.0f;
6139 static inline BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg)
6141 struct wined3d_shader_lconst *lconst;
6143 if (shader->load_local_constsF)
6144 return FALSE;
6146 LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
6148 if (lconst->idx == reg)
6149 return TRUE;
6152 return FALSE;
6155 void get_identity_matrix(struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
6156 void get_modelview_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
6157 unsigned int index, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
6158 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
6159 struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
6160 void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
6161 unsigned int tex, struct wined3d_matrix *mat) DECLSPEC_HIDDEN;
6162 void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state,
6163 float *out_min, float *out_max) DECLSPEC_HIDDEN;
6164 void get_pointsize(const struct wined3d_context *context, const struct wined3d_state *state,
6165 float *out_pointsize, float *out_att) DECLSPEC_HIDDEN;
6166 void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state,
6167 float *start, float *end) DECLSPEC_HIDDEN;
6169 /* Using additional shader constants (uniforms in GLSL / program environment
6170 * or local parameters in ARB) is costly:
6171 * ARB only knows float4 parameters and GLSL compiler are not really smart
6172 * when it comes to efficiently pack float2 uniforms, so no space is wasted
6173 * (in fact most compilers map a float2 to a full float4 uniform).
6175 * For NP2 texcoord fixup we only need 2 floats (width and height) for each
6176 * 2D texture used in the shader. We therefore pack fixup info for 2 textures
6177 * into a single shader constant (uniform / program parameter).
6179 * This structure is shared between the GLSL and the ARB backend.*/
6180 struct ps_np2fixup_info {
6181 unsigned char idx[WINED3D_MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
6182 WORD active; /* bitfield indicating if we can apply the fixup */
6183 WORD num_consts;
6186 void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLuint id, BOOL program) DECLSPEC_HIDDEN;
6187 void shader_glsl_validate_link(const struct wined3d_gl_info *gl_info, GLuint program) DECLSPEC_HIDDEN;
6189 struct wined3d_palette
6191 LONG ref;
6192 struct wined3d_device *device;
6194 unsigned int size;
6195 RGBQUAD colors[256];
6196 uint32_t flags;
6199 /* DirectDraw utility functions */
6200 extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
6202 /*****************************************************************************
6203 * Pixel format management
6206 /* Pixel format attributes */
6207 #define WINED3D_FORMAT_ATTR_FLOAT 0x00000001
6208 #define WINED3D_FORMAT_ATTR_INTEGER 0x00000002
6209 #define WINED3D_FORMAT_ATTR_NORMALISED 0x00000004
6210 #define WINED3D_FORMAT_ATTR_BUMPMAP 0x00000008
6211 #define WINED3D_FORMAT_ATTR_EXTENSION 0x00000010
6212 #define WINED3D_FORMAT_ATTR_BLOCKS 0x00000020
6213 #define WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY 0x00000040
6214 #define WINED3D_FORMAT_ATTR_COMPRESSED 0x00000080
6215 #define WINED3D_FORMAT_ATTR_BROKEN_PITCH 0x00000100
6216 #define WINED3D_FORMAT_ATTR_HEIGHT_SCALE 0x00000200
6217 #define WINED3D_FORMAT_ATTR_MAPPABLE 0x00000400
6218 #define WINED3D_FORMAT_ATTR_CAST_TO_BLOCK 0x00000800
6220 /* Pixel format capabilities */
6221 #define WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING 0x00000001
6222 #define WINED3D_FORMAT_CAP_FILTERING 0x00000002
6223 #define WINED3D_FORMAT_CAP_UNORDERED_ACCESS 0x00000004
6224 #define WINED3D_FORMAT_CAP_DEPTH_STENCIL 0x00000008
6225 #define WINED3D_FORMAT_CAP_RENDERTARGET 0x00000010
6226 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE 0x00000020
6227 #define WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB 0x00000040
6228 #define WINED3D_FORMAT_CAP_DECOMPRESS 0x00000080
6229 #define WINED3D_FORMAT_CAP_SRGB_READ 0x00000100
6230 #define WINED3D_FORMAT_CAP_SRGB_WRITE 0x00000200
6231 #define WINED3D_FORMAT_CAP_VTF 0x00000400
6232 #define WINED3D_FORMAT_CAP_SHADOW 0x00000800
6233 #define WINED3D_FORMAT_CAP_TEXTURE 0x00001000
6234 #define WINED3D_FORMAT_CAP_GEN_MIPMAP 0x00002000
6235 #define WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE 0x00004000
6236 #define WINED3D_FORMAT_CAP_BLIT 0x00008000
6237 #define WINED3D_FORMAT_CAP_INDEX_BUFFER 0x00010000
6239 struct wined3d_rational
6241 UINT numerator;
6242 UINT denominator;
6245 struct wined3d_color_key_conversion
6247 enum wined3d_format_id dst_format;
6248 void (*convert)(const BYTE *src, unsigned int src_pitch, BYTE *dst, unsigned int dst_pitch,
6249 unsigned int width, unsigned int height, const struct wined3d_color_key *colour_key);
6252 enum wined3d_channel_type
6254 WINED3D_CHANNEL_TYPE_NONE,
6255 WINED3D_CHANNEL_TYPE_UNORM,
6256 WINED3D_CHANNEL_TYPE_SNORM,
6257 WINED3D_CHANNEL_TYPE_UINT,
6258 WINED3D_CHANNEL_TYPE_SINT,
6259 WINED3D_CHANNEL_TYPE_FLOAT,
6260 WINED3D_CHANNEL_TYPE_DEPTH,
6261 WINED3D_CHANNEL_TYPE_STENCIL,
6262 WINED3D_CHANNEL_TYPE_UNUSED,
6265 struct wined3d_format
6267 enum wined3d_format_id id;
6269 D3DDDIFORMAT ddi_format;
6270 unsigned int component_count;
6271 DWORD red_size;
6272 DWORD green_size;
6273 DWORD blue_size;
6274 DWORD alpha_size;
6275 DWORD red_offset;
6276 DWORD green_offset;
6277 DWORD blue_offset;
6278 DWORD alpha_offset;
6279 UINT byte_count;
6280 BYTE depth_size;
6281 BYTE stencil_size;
6283 UINT block_width;
6284 UINT block_height;
6285 UINT block_byte_count;
6287 enum wined3d_ffp_emit_idx emit_idx;
6289 UINT conv_byte_count;
6290 DWORD multisample_types;
6291 unsigned int attrs;
6292 unsigned int caps[WINED3D_GL_RES_TYPE_COUNT];
6293 float depth_bias_scale;
6294 struct wined3d_rational height_scale;
6295 struct color_fixup_desc color_fixup;
6296 void (*upload)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
6297 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
6298 unsigned int width, unsigned int height, unsigned int depth);
6299 void (*download)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
6300 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
6301 unsigned int width, unsigned int height, unsigned int depth);
6302 void (*decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
6303 unsigned int dst_row_pitch, unsigned dst_slice_pitch,
6304 unsigned int width, unsigned int height, unsigned int depth);
6306 enum wined3d_format_id typeless_id;
6309 const struct wined3d_format *wined3d_get_format(const struct wined3d_adapter *adapter,
6310 enum wined3d_format_id format_id, unsigned int bind_flags) DECLSPEC_HIDDEN;
6311 enum wined3d_format_id wined3d_get_typed_format_id(const struct wined3d_adapter *adapter,
6312 const struct wined3d_format *format, enum wined3d_channel_type channel_type) DECLSPEC_HIDDEN;
6313 void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
6314 unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch) DECLSPEC_HIDDEN;
6315 UINT wined3d_format_calculate_size(const struct wined3d_format *format,
6316 UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
6317 void wined3d_format_colour_to_vk(const struct wined3d_format *format, const struct wined3d_color *c,
6318 VkClearColorValue *retval) DECLSPEC_HIDDEN;
6319 void wined3d_format_convert_from_float(const struct wined3d_format *format,
6320 const struct wined3d_color *color, void *ret) DECLSPEC_HIDDEN;
6321 void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src,
6322 unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
6323 unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d) DECLSPEC_HIDDEN;
6324 void wined3d_format_get_float_color_key(const struct wined3d_format *format,
6325 const struct wined3d_color_key *key, struct wined3d_color *float_colors) DECLSPEC_HIDDEN;
6326 BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id,
6327 enum wined3d_format_id view_format_id) DECLSPEC_HIDDEN;
6328 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
6329 const struct wined3d_texture *texture, BOOL need_alpha_ck) DECLSPEC_HIDDEN;
6330 uint32_t wined3d_format_pack(const struct wined3d_format *format, const struct wined3d_uvec4 *value) DECLSPEC_HIDDEN;
6331 BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1,
6332 enum wined3d_format_id format2) DECLSPEC_HIDDEN;
6334 struct wined3d_format_gl
6336 struct wined3d_format f;
6338 GLenum vtx_type;
6339 GLint vtx_format;
6341 GLint internal;
6342 GLint srgb_internal;
6343 GLint rt_internal;
6344 GLint format;
6345 GLint type;
6347 GLenum view_class;
6350 static inline const struct wined3d_format_gl *wined3d_format_gl(const struct wined3d_format *format)
6352 return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
6355 struct wined3d_format_vk
6357 struct wined3d_format f;
6359 VkFormat vk_format;
6362 static inline const struct wined3d_format_vk *wined3d_format_vk(const struct wined3d_format *format)
6364 return CONTAINING_RECORD(format, struct wined3d_format_vk, f);
6367 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size) DECLSPEC_HIDDEN;
6369 static inline BOOL wined3d_format_is_typeless(const struct wined3d_format *format)
6371 return format->id == format->typeless_id && format->id != WINED3DFMT_UNKNOWN;
6374 static inline BOOL use_vs(const struct wined3d_state *state)
6376 /* Check state->vertex_declaration to allow this to be used before the
6377 * stream info is validated, for example in device_update_tex_unit_map(). */
6378 return state->shader[WINED3D_SHADER_TYPE_VERTEX]
6379 && (!state->vertex_declaration || !state->vertex_declaration->position_transformed);
6382 static inline BOOL use_ps(const struct wined3d_state *state)
6384 return !!state->shader[WINED3D_SHADER_TYPE_PIXEL];
6387 static inline BOOL use_transform_feedback(const struct wined3d_state *state)
6389 const struct wined3d_shader *shader;
6391 if (!(shader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY]))
6392 return FALSE;
6393 return !!shader->u.gs.so_desc;
6396 static inline void context_apply_state(struct wined3d_context *context,
6397 const struct wined3d_state *state, DWORD state_id)
6399 const struct wined3d_state_entry *state_table = context->state_table;
6400 unsigned int rep = state_table[state_id].representative;
6401 state_table[rep].apply(context, state, rep);
6404 static inline BOOL is_srgb_enabled(const uint32_t *sampler_states)
6406 /* Only use the LSB of the WINED3D_SAMP_SRGB_TEXTURE value. This matches
6407 * the behaviour of the AMD Windows driver.
6409 * Might & Magic: Heroes VI - Shades of Darkness sets
6410 * WINED3D_SAMP_SRGB_TEXTURE to a large value that looks like a
6411 * pointer—presumably by accident—and expects sRGB decoding to be
6412 * disabled. */
6413 return sampler_states[WINED3D_SAMP_SRGB_TEXTURE] & 0x1;
6416 static inline BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context,
6417 const struct wined3d_texture *texture)
6419 if (!(context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
6420 return FALSE;
6422 if (!context->d3d_info->srgb_read_control
6423 && (texture->resource.bind_flags & WINED3D_BIND_SHADER_RESOURCE)
6424 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_READ))
6425 return TRUE;
6427 if (!context->d3d_info->srgb_write_control
6428 && (texture->resource.bind_flags & WINED3D_BIND_RENDER_TARGET)
6429 && (texture->resource.format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE))
6430 return TRUE;
6432 return FALSE;
6435 static inline BOOL needs_srgb_write(const struct wined3d_d3d_info *d3d_info,
6436 const struct wined3d_state *state, const struct wined3d_fb_state *fb)
6438 return (!(d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
6439 || state->render_states[WINED3D_RS_SRGBWRITEENABLE])
6440 && fb->render_targets[0] && fb->render_targets[0]->format_caps & WINED3D_FORMAT_CAP_SRGB_WRITE;
6443 static inline GLuint wined3d_texture_gl_get_texture_name(const struct wined3d_texture_gl *texture_gl,
6444 const struct wined3d_context *context, BOOL srgb)
6446 return srgb && needs_separate_srgb_gl_texture(context, &texture_gl->t)
6447 ? texture_gl->texture_srgb.name : texture_gl->texture_rgb.name;
6450 static inline GLuint wined3d_gl_get_internal_format(struct wined3d_resource *resource,
6451 const struct wined3d_format_gl *format_gl, bool srgb)
6453 if (srgb)
6454 return format_gl->srgb_internal;
6455 else if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET && wined3d_resource_is_offscreen(resource))
6456 return format_gl->rt_internal;
6457 else
6458 return format_gl->internal;
6461 static inline BOOL can_use_texture_swizzle(const struct wined3d_d3d_info *d3d_info, const struct wined3d_format *format)
6463 return d3d_info->texture_swizzle && !is_complex_fixup(format->color_fixup) && !is_scaling_fixup(format->color_fixup);
6466 static inline BOOL is_rasterization_disabled(const struct wined3d_shader *geometry_shader)
6468 return geometry_shader && geometry_shader->u.gs.so_desc
6469 && geometry_shader->u.gs.so_desc->rasterizer_stream_idx == WINED3D_NO_RASTERIZER_STREAM;
6472 static inline uint32_t wined3d_mask_from_size(unsigned int size)
6474 return size < 32 ? (1u << size) - 1 : ~0u;
6477 static inline DWORD wined3d_extract_bits(const uint32_t *bitstream,
6478 unsigned int offset, unsigned int count)
6480 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
6481 const unsigned int idx = offset / word_bit_count;
6482 const unsigned int shift = offset % word_bit_count;
6483 DWORD mask = (1u << count) - 1;
6484 DWORD ret;
6486 ret = (bitstream[idx] >> shift) & mask;
6487 if (shift + count > word_bit_count)
6489 const unsigned int extracted_bit_count = word_bit_count - shift;
6490 const unsigned int remaining_bit_count = count - extracted_bit_count;
6491 mask = (1u << remaining_bit_count) - 1;
6492 ret |= (bitstream[idx + 1] & mask) << extracted_bit_count;
6494 return ret;
6497 static inline void wined3d_insert_bits(uint32_t *bitstream,
6498 unsigned int offset, unsigned int count, DWORD bits)
6500 const unsigned int word_bit_count = sizeof(*bitstream) * CHAR_BIT;
6501 const unsigned int idx = offset / word_bit_count;
6502 const unsigned int shift = offset % word_bit_count;
6503 DWORD mask = (1u << count) - 1;
6505 bitstream[idx] |= (bits & mask) << shift;
6506 if (shift + count > word_bit_count)
6508 const unsigned int inserted_bit_count = word_bit_count - shift;
6509 const unsigned int remaining_bit_count = count - inserted_bit_count;
6510 mask = (1u << remaining_bit_count) - 1;
6511 bitstream[idx + 1] |= (bits >> inserted_bit_count) & mask;
6515 static inline void wined3d_from_cs(const struct wined3d_cs *cs)
6517 if (cs->thread)
6518 assert(cs->thread_id == GetCurrentThreadId());
6521 static inline void wined3d_not_from_cs(const struct wined3d_cs *cs)
6523 assert(cs->thread_id != GetCurrentThreadId());
6526 static inline enum wined3d_material_color_source validate_material_colour_source(WORD use_map,
6527 enum wined3d_material_color_source source)
6529 if (source == WINED3D_MCS_COLOR1 && use_map & (1u << WINED3D_FFP_DIFFUSE))
6530 return source;
6531 if (source == WINED3D_MCS_COLOR2 && use_map & (1u << WINED3D_FFP_SPECULAR))
6532 return source;
6533 return WINED3D_MCS_MATERIAL;
6536 static inline void wined3d_get_material_colour_source(enum wined3d_material_color_source *diffuse,
6537 enum wined3d_material_color_source *emissive, enum wined3d_material_color_source *ambient,
6538 enum wined3d_material_color_source *specular, const struct wined3d_state *state,
6539 const struct wined3d_stream_info *si)
6541 if (!state->render_states[WINED3D_RS_LIGHTING])
6543 *diffuse = WINED3D_MCS_COLOR1;
6544 *specular = WINED3D_MCS_COLOR2;
6545 *emissive = *ambient = WINED3D_MCS_MATERIAL;
6547 return;
6550 if (!state->render_states[WINED3D_RS_COLORVERTEX])
6552 *diffuse = *emissive = *ambient = *specular = WINED3D_MCS_MATERIAL;
6554 return;
6557 *diffuse = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE]);
6558 *emissive = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE]);
6559 *ambient = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE]);
6560 *specular = validate_material_colour_source(si->use_map, state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
6563 static inline void wined3d_vec4_transform(struct wined3d_vec4 *dst,
6564 const struct wined3d_vec4 *v, const struct wined3d_matrix *m)
6566 struct wined3d_vec4 tmp;
6568 tmp.x = v->x * m->_11 + v->y * m->_21 + v->z * m->_31 + v->w * m->_41;
6569 tmp.y = v->x * m->_12 + v->y * m->_22 + v->z * m->_32 + v->w * m->_42;
6570 tmp.z = v->x * m->_13 + v->y * m->_23 + v->z * m->_33 + v->w * m->_43;
6571 tmp.w = v->x * m->_14 + v->y * m->_24 + v->z * m->_34 + v->w * m->_44;
6573 *dst = tmp;
6576 BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m) DECLSPEC_HIDDEN;
6578 void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting,
6579 const struct wined3d_matrix *modelview) DECLSPEC_HIDDEN;
6581 static inline struct wined3d_context *context_acquire(struct wined3d_device *device,
6582 struct wined3d_texture *texture, unsigned int sub_resource_idx)
6584 wined3d_from_cs(device->cs);
6586 return device->adapter->adapter_ops->adapter_acquire_context(device, texture, sub_resource_idx);
6589 static inline void context_release(struct wined3d_context *context)
6591 context->device->adapter->adapter_ops->adapter_release_context(context);
6594 static inline float wined3d_get_float_state(const struct wined3d_state *state, enum wined3d_render_state rs)
6596 union
6598 DWORD d;
6599 float f;
6601 tmpvalue;
6603 tmpvalue.d = state->render_states[rs];
6604 return tmpvalue.f;
6607 static inline void *wined3d_context_map_bo_address(struct wined3d_context *context,
6608 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
6610 return context->device->adapter->adapter_ops->adapter_map_bo_address(context, data, size, map_flags);
6613 static inline void wined3d_context_unmap_bo_address(struct wined3d_context *context,
6614 const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
6616 context->device->adapter->adapter_ops->adapter_unmap_bo_address(context, data, range_count, ranges);
6619 static inline void wined3d_context_copy_bo_address(struct wined3d_context *context,
6620 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
6621 unsigned int range_count, const struct wined3d_range *ranges)
6623 context->device->adapter->adapter_ops->adapter_copy_bo_address(context, dst, src, range_count, ranges);
6626 static inline void wined3d_context_flush_bo_address(struct wined3d_context *context,
6627 const struct wined3d_const_bo_address *data, size_t size)
6629 context->device->adapter->adapter_ops->adapter_flush_bo_address(context, data, size);
6632 static inline void wined3d_context_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)
6634 context->device->adapter->adapter_ops->adapter_destroy_bo(context, bo);
6637 static inline void wined3d_context_vk_reference_bo(const struct wined3d_context_vk *context_vk,
6638 struct wined3d_bo_vk *bo)
6640 bo->command_buffer_id = context_vk->current_command_buffer.id;
6643 static inline void wined3d_context_vk_reference_image(const struct wined3d_context_vk *context_vk,
6644 struct wined3d_image_vk *image)
6646 image->command_buffer_id = context_vk->current_command_buffer.id;
6649 static inline void wined3d_context_vk_reference_texture(const struct wined3d_context_vk *context_vk,
6650 struct wined3d_texture_vk *texture_vk)
6652 wined3d_context_vk_reference_image(context_vk, &texture_vk->image);
6655 static inline void wined3d_context_vk_reference_resource(const struct wined3d_context_vk *context_vk,
6656 struct wined3d_resource *resource)
6658 if (resource->type == WINED3D_RTYPE_BUFFER)
6659 wined3d_context_vk_reference_bo(context_vk, wined3d_bo_vk(buffer_from_resource(resource)->buffer_object));
6660 else
6661 wined3d_context_vk_reference_texture(context_vk, wined3d_texture_vk(texture_from_resource(resource)));
6664 static inline void wined3d_context_vk_reference_query(const struct wined3d_context_vk *context_vk,
6665 struct wined3d_query_vk *query_vk)
6667 query_vk->command_buffer_id = context_vk->current_command_buffer.id;
6670 static inline void wined3d_context_vk_reference_sampler(const struct wined3d_context_vk *context_vk,
6671 struct wined3d_sampler_vk *sampler_vk)
6673 sampler_vk->command_buffer_id = context_vk->current_command_buffer.id;
6676 static inline void wined3d_context_vk_reference_rendertarget_view(const struct wined3d_context_vk *context_vk,
6677 struct wined3d_rendertarget_view_vk *rtv_vk)
6679 wined3d_context_vk_reference_resource(context_vk, rtv_vk->v.resource);
6680 rtv_vk->command_buffer_id = context_vk->current_command_buffer.id;
6683 static inline void wined3d_context_vk_reference_shader_resource_view(const struct wined3d_context_vk *context_vk,
6684 struct wined3d_shader_resource_view_vk *srv_vk)
6686 wined3d_context_vk_reference_resource(context_vk, srv_vk->v.resource);
6687 srv_vk->view_vk.command_buffer_id = context_vk->current_command_buffer.id;
6690 static inline void wined3d_context_vk_reference_unordered_access_view(const struct wined3d_context_vk *context_vk,
6691 struct wined3d_unordered_access_view_vk *uav_vk)
6693 wined3d_context_vk_reference_resource(context_vk, uav_vk->v.resource);
6694 uav_vk->view_vk.command_buffer_id = context_vk->current_command_buffer.id;
6697 static inline BOOL wined3d_dsv_srv_conflict(const struct wined3d_rendertarget_view *dsv,
6698 const struct wined3d_format *srv_format)
6700 return !srv_format || (srv_format->red_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_DEPTH))
6701 || (srv_format->green_size && !(dsv->desc.flags & WINED3D_VIEW_READ_ONLY_STENCIL));
6704 static inline unsigned int wined3d_bind_layer_count(const struct wined3d_texture *texture)
6706 return texture->resource.type == WINED3D_RTYPE_TEXTURE_3D ? texture->resource.depth : texture->layer_count;
6709 static inline bool wined3d_srv_all_subresources(const struct wined3d_shader_resource_view *srv)
6711 struct wined3d_texture *texture;
6713 if (srv->resource->type == WINED3D_RTYPE_BUFFER)
6714 return TRUE;
6716 if (srv->desc.u.texture.layer_idx || srv->desc.u.texture.level_idx)
6717 return FALSE;
6719 texture = texture_from_resource(srv->resource);
6720 return srv->desc.u.texture.level_count == texture->level_count
6721 && srv->desc.u.texture.layer_count == wined3d_bind_layer_count(texture);
6724 static inline bool wined3d_rtv_all_subresources(const struct wined3d_rendertarget_view *rtv)
6726 struct wined3d_texture *texture;
6728 if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
6729 return TRUE;
6731 if (rtv->sub_resource_idx)
6732 return FALSE;
6734 texture = texture_from_resource(rtv->resource);
6735 return texture->level_count == 1 && rtv->layer_count == wined3d_bind_layer_count(texture);
6738 static inline void wined3d_srv_bind_count_inc(struct wined3d_shader_resource_view *srv)
6740 InterlockedIncrement(&srv->resource->srv_bind_count_device);
6743 static inline void wined3d_srv_bind_count_dec(struct wined3d_shader_resource_view *srv)
6745 InterlockedDecrement(&srv->resource->srv_bind_count_device);
6748 static inline void wined3d_rtv_bind_count_inc(struct wined3d_rendertarget_view *rtv)
6750 InterlockedIncrement(&rtv->resource->rtv_bind_count_device);
6753 static inline void wined3d_rtv_bind_count_dec(struct wined3d_rendertarget_view *rtv)
6755 InterlockedDecrement(&rtv->resource->rtv_bind_count_device);
6758 static inline bool wined3d_rtv_overlaps_srv(const struct wined3d_rendertarget_view *rtv,
6759 const struct wined3d_shader_resource_view *srv)
6761 if (rtv->resource != srv->resource)
6762 return false;
6764 if (wined3d_srv_all_subresources(srv) || wined3d_rtv_all_subresources(rtv))
6765 return true;
6767 return rtv->sub_resource_idx >= srv->desc.u.texture.level_idx
6768 && rtv->sub_resource_idx < srv->desc.u.texture.level_idx + srv->desc.u.texture.level_count
6769 && rtv->layer_count >= srv->desc.u.texture.layer_idx;
6772 static inline bool wined3d_is_srv_rtv_bound(const struct wined3d_state *state,
6773 const struct wined3d_shader_resource_view *srv)
6775 unsigned int i;
6777 if (!srv->resource->rtv_bind_count_device)
6778 return false;
6780 for (i = 0; i < ARRAY_SIZE(state->fb.render_targets); ++i)
6782 const struct wined3d_rendertarget_view *rtv;
6784 if ((rtv = state->fb.render_targets[i]) && wined3d_rtv_overlaps_srv(rtv, srv))
6785 return true;
6788 return false;
6791 static inline void wined3d_viewport_get_z_range(const struct wined3d_viewport *vp, float *min_z, float *max_z)
6793 *min_z = vp->min_z;
6795 /* The magic constant is derived from tests. */
6796 *max_z = max(vp->max_z, vp->min_z + 0.001f);
6799 static inline BOOL wined3d_bitmap_clear(uint32_t *map, unsigned int idx)
6801 return map[idx >> 5] &= ~(1u << (idx & 0x1f));
6804 static inline BOOL wined3d_bitmap_set(uint32_t *map, unsigned int idx)
6806 return map[idx >> 5] |= (1u << (idx & 0x1f));
6809 static inline BOOL wined3d_bitmap_is_set(const uint32_t *map, unsigned int idx)
6811 return map[idx >> 5] & (1u << (idx & 0x1f));
6814 static inline unsigned int wined3d_bitmap_ffs_xor(const uint32_t *bitmap, unsigned int bit_count,
6815 unsigned int start, uint32_t xor_mask)
6817 const unsigned int word_bit_count = sizeof(*bitmap) * CHAR_BIT;
6818 const uint32_t *ptr, *end_ptr;
6819 uint32_t map, mask;
6821 assert(bit_count < word_bit_count || !(bit_count % word_bit_count));
6823 ptr = bitmap + start / word_bit_count;
6824 end_ptr = bitmap + (bit_count + word_bit_count - 1) / word_bit_count;
6826 if (ptr >= end_ptr)
6827 return ~0u;
6829 mask = ~0u << start % word_bit_count;
6830 map = (*ptr ^ xor_mask) & mask;
6831 while (!map)
6833 if (++ptr == end_ptr)
6834 return ~0u;
6835 map = *ptr ^ xor_mask;
6837 return (ptr - bitmap) * word_bit_count + wined3d_bit_scan(&map);
6840 static inline unsigned int wined3d_bitmap_ffs(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
6842 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, 0);
6845 static inline unsigned int wined3d_bitmap_ffz(const uint32_t *bitmap, unsigned int bit_count, unsigned int start)
6847 return wined3d_bitmap_ffs_xor(bitmap, bit_count, start, ~0u);
6850 static inline BOOL wined3d_bitmap_get_range(const uint32_t *bitmap, unsigned int bit_count,
6851 unsigned int start, struct wined3d_range *range)
6853 unsigned int range_start, range_end;
6855 range_start = wined3d_bitmap_ffs(bitmap, bit_count, start);
6856 if (range_start == ~0u)
6857 return FALSE;
6859 range_end = wined3d_bitmap_ffz(bitmap, bit_count, range_start + 1);
6860 if (range_end == ~0u)
6861 range_end = bit_count;
6863 range->offset = range_start;
6864 range->size = range_end - range_start;
6865 return TRUE;
6868 static inline bool wined3d_context_is_graphics_state_dirty(const struct wined3d_context *context, unsigned int state_id)
6870 return wined3d_bitmap_is_set(context->dirty_graphics_states, state_id);
6873 static inline bool wined3d_context_is_compute_state_dirty(const struct wined3d_context *context, unsigned int state_id)
6875 return wined3d_bitmap_is_set(context->dirty_compute_states, state_id - STATE_COMPUTE_OFFSET);
6878 static inline bool isStateDirty(const struct wined3d_context *context, unsigned int state_id)
6880 return wined3d_context_is_graphics_state_dirty(context, state_id);
6883 static inline VkImageAspectFlags vk_aspect_mask_from_format(const struct wined3d_format *format)
6885 VkImageAspectFlags mask = 0;
6887 if (format->depth_size)
6888 mask |= VK_IMAGE_ASPECT_DEPTH_BIT;
6889 if (format->stencil_size)
6890 mask |= VK_IMAGE_ASPECT_STENCIL_BIT;
6891 if (!mask || format->red_size || format->green_size || format->blue_size || format->alpha_size)
6892 mask |= VK_IMAGE_ASPECT_COLOR_BIT;
6894 return mask;
6897 static inline bool wined3d_primitive_type_is_list(enum wined3d_primitive_type t)
6899 return t == WINED3D_PT_POINTLIST
6900 || t == WINED3D_PT_LINELIST
6901 || t == WINED3D_PT_TRIANGLELIST
6902 || t == WINED3D_PT_LINELIST_ADJ
6903 || t == WINED3D_PT_TRIANGLELIST_ADJ
6904 || t == WINED3D_PT_PATCH;
6907 static inline void wined3d_context_gl_reference_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo_gl)
6909 struct wined3d_device_gl *device_gl = wined3d_device_gl(context_gl->c.device);
6911 bo_gl->command_fence_id = device_gl->current_fence_id;
6914 static inline void wined3d_context_gl_reference_buffer(struct wined3d_context_gl *context_gl,
6915 struct wined3d_buffer *buffer)
6917 if (buffer->buffer_object)
6918 wined3d_context_gl_reference_bo(context_gl, wined3d_bo_gl(buffer->buffer_object));
6921 static inline bool wined3d_map_persistent(void)
6923 return sizeof(void *) >= sizeof(uint64_t);
6926 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
6927 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
6929 extern CRITICAL_SECTION wined3d_command_cs;
6931 #endif