ReactOS 0.4.17-dev-923-g4c9a150
vkd3d_common.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Józef Kucia for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#ifndef __VKD3D_COMMON_H
20#define __VKD3D_COMMON_H
21
22#include "config.h"
23#define WIN32_LEAN_AND_MEAN
24#include "windows.h"
25#include "vkd3d_types.h"
26
27#include <ctype.h>
28#include <limits.h>
29#include <stdbool.h>
30#include <stdint.h>
31#include <stdio.h>
32#include <stdlib.h>
33#ifndef _WIN32
34#include <pthread.h>
35#endif
36
37#ifdef _MSC_VER
38#include <intrin.h>
39#endif
40
41#ifndef ARRAY_SIZE
42# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
43#endif
44
45#define DIV_ROUND_UP(a, b) ((a) % (b) == 0 ? (a) / (b) : (a) / (b) + 1)
46
47#define STATIC_ASSERT(e) extern void __VKD3D_STATIC_ASSERT__(int [(e) ? 1 : -1])
48
49#define VKD3D_ASSERT(cond) \
50 do { \
51 if (!(cond)) \
52 ERR("Failed assertion: %s\n", #cond); \
53 } while (0)
54
55#define MEMBER_SIZE(t, m) sizeof(((t *)0)->m)
56
57#define VKD3D_MAKE_TAG(ch0, ch1, ch2, ch3) \
58 ((uint32_t)(ch0) | ((uint32_t)(ch1) << 8) \
59 | ((uint32_t)(ch2) << 16) | ((uint32_t)(ch3) << 24))
60
61#define VKD3D_EXPAND(x) x
62#define VKD3D_STRINGIFY(x) #x
63#define VKD3D_EXPAND_AND_STRINGIFY(x) VKD3D_EXPAND(VKD3D_STRINGIFY(x))
64
65#define vkd3d_clamp(value, lower, upper) max(min(value, upper), lower)
66
67#define TAG_AON9 VKD3D_MAKE_TAG('A', 'o', 'n', '9')
68#define TAG_DXBC VKD3D_MAKE_TAG('D', 'X', 'B', 'C')
69#define TAG_DXIL VKD3D_MAKE_TAG('D', 'X', 'I', 'L')
70#define TAG_FX10 VKD3D_MAKE_TAG('F', 'X', '1', '0')
71#define TAG_ISG1 VKD3D_MAKE_TAG('I', 'S', 'G', '1')
72#define TAG_ISGN VKD3D_MAKE_TAG('I', 'S', 'G', 'N')
73#define TAG_OSG1 VKD3D_MAKE_TAG('O', 'S', 'G', '1')
74#define TAG_OSG5 VKD3D_MAKE_TAG('O', 'S', 'G', '5')
75#define TAG_OSGN VKD3D_MAKE_TAG('O', 'S', 'G', 'N')
76#define TAG_PCSG VKD3D_MAKE_TAG('P', 'C', 'S', 'G')
77#define TAG_PSG1 VKD3D_MAKE_TAG('P', 'S', 'G', '1')
78#define TAG_RD11 VKD3D_MAKE_TAG('R', 'D', '1', '1')
79#define TAG_RDEF VKD3D_MAKE_TAG('R', 'D', 'E', 'F')
80#define TAG_RTS0 VKD3D_MAKE_TAG('R', 'T', 'S', '0')
81#define TAG_SDBG VKD3D_MAKE_TAG('S', 'D', 'B', 'G')
82#define TAG_SFI0 VKD3D_MAKE_TAG('S', 'F', 'I', '0')
83#define TAG_SHDR VKD3D_MAKE_TAG('S', 'H', 'D', 'R')
84#define TAG_SHEX VKD3D_MAKE_TAG('S', 'H', 'E', 'X')
85#define TAG_STAT VKD3D_MAKE_TAG('S', 'T', 'A', 'T')
86#define TAG_TEXT VKD3D_MAKE_TAG('T', 'E', 'X', 'T')
87#define TAG_XNAP VKD3D_MAKE_TAG('X', 'N', 'A', 'P')
88#define TAG_XNAS VKD3D_MAKE_TAG('X', 'N', 'A', 'S')
89
90#define TAG_RD11_REVERSE 0x25441313
91
92static inline uint64_t align(uint64_t addr, size_t alignment)
93{
94 return (addr + (alignment - 1)) & ~(alignment - 1);
95}
96
97#if defined(__GNUC__) || defined(__clang__)
98# define VKD3D_NORETURN __attribute__((noreturn))
99# ifdef __MINGW_PRINTF_FORMAT
100# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(__MINGW_PRINTF_FORMAT, fmt, args)))
101# else
102# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args)))
103# endif
104# define VKD3D_UNUSED __attribute__((unused))
105# define VKD3D_UNREACHABLE __builtin_unreachable()
106#elif defined(_MSC_VER) // __REACTOS__
107# define VKD3D_NORETURN __declspec(noreturn)
108# define VKD3D_PRINTF_FUNC(fmt, args)
109# define VKD3D_UNUSED
110# define VKD3D_UNREACHABLE __assume(0)
111# define __alignof__(type) __alignof(type)
112#else
113# define VKD3D_NORETURN
114# define VKD3D_PRINTF_FUNC(fmt, args)
115# define VKD3D_UNUSED
116# define VKD3D_UNREACHABLE (void)0
117#endif /* __GNUC__ */
118
119#define vkd3d_unreachable() \
120 do { \
121 ERR("%s:%u: Unreachable code reached.\n", __FILE__, __LINE__); \
122 VKD3D_UNREACHABLE; \
123 } while (0)
124
125#ifdef VKD3D_NO_TRACE_MESSAGES
126#define TRACE(args...) do { } while (0)
127#define TRACE_ON() (false)
128#endif
129
130#ifdef VKD3D_NO_DEBUG_MESSAGES
131#define WARN(args...) do { } while (0)
132#define FIXME(args...) do { } while (0)
133#define WARN_ON() (false)
134#define FIXME_ONCE(args...) do { } while (0)
135#endif
136
137#ifdef VKD3D_NO_ERROR_MESSAGES
138#define ERR(args...) do { } while (0)
139#define MESSAGE(args...) do { } while (0)
140#endif
141
143{
150};
151
153
154void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4);
156
159const char *debugstr_a(const char *str);
160const char *debugstr_an(const char *str, size_t n);
161const char *debugstr_w(const WCHAR *wstr, size_t wchar_size);
162
163#define VKD3D_DBG_LOG(level) \
164 do { \
165 const enum vkd3d_dbg_level vkd3d_dbg_level = VKD3D_DBG_LEVEL_##level; \
166 VKD3D_DBG_PRINTF_##level
167
168#define VKD3D_DBG_LOG_ONCE(first_time_level, level) \
169 do { \
170 static bool vkd3d_dbg_next_time; \
171 const enum vkd3d_dbg_level vkd3d_dbg_level = vkd3d_dbg_next_time \
172 ? VKD3D_DBG_LEVEL_##level : VKD3D_DBG_LEVEL_##first_time_level; \
173 vkd3d_dbg_next_time = true; \
174 VKD3D_DBG_PRINTF_##level
175
176#define VKD3D_DBG_PRINTF(...) \
177 vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0)
178
179#define VKD3D_DBG_PRINTF_TRACE(...) VKD3D_DBG_PRINTF(__VA_ARGS__)
180#define VKD3D_DBG_PRINTF_WARN(...) VKD3D_DBG_PRINTF(__VA_ARGS__)
181#define VKD3D_DBG_PRINTF_FIXME(...) VKD3D_DBG_PRINTF(__VA_ARGS__)
182#define VKD3D_DBG_PRINTF_MESSAGE(...) VKD3D_DBG_PRINTF(__VA_ARGS__)
183
184#ifdef VKD3D_ABORT_ON_ERR
185#define VKD3D_DBG_PRINTF_ERR(...) \
186 vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); \
187 abort(); \
188 } while (0)
189#else
190#define VKD3D_DBG_PRINTF_ERR(...) VKD3D_DBG_PRINTF(__VA_ARGS__)
191#endif
192
193/* Used by vkd3d_unreachable(). */
194#ifdef VKD3D_CROSSTEST
195#undef ERR
196#define ERR(...) do { fprintf(stderr, __VA_ARGS__); abort(); } while (0)
197#endif
198
199#ifndef TRACE
200#define TRACE VKD3D_DBG_LOG(TRACE)
201#endif
202
203#ifndef WARN
204#define WARN VKD3D_DBG_LOG(WARN)
205#endif
206
207#ifndef FIXME
208#define FIXME VKD3D_DBG_LOG(FIXME)
209#endif
210
211#ifndef ERR
212#define ERR VKD3D_DBG_LOG(ERR)
213#endif
214
215#ifndef MESSAGE
216#define MESSAGE VKD3D_DBG_LOG(MESSAGE)
217#endif
218
219#ifndef TRACE_ON
220#define TRACE_ON() (vkd3d_dbg_get_level() == VKD3D_DBG_LEVEL_TRACE)
221#endif
222
223#ifndef WARN_ON
224#define WARN_ON() (vkd3d_dbg_get_level() >= VKD3D_DBG_LEVEL_WARN)
225#endif
226
227#ifndef FIXME_ONCE
228#define FIXME_ONCE VKD3D_DBG_LOG_ONCE(FIXME, WARN)
229#endif
230
231#define VKD3D_DEBUG_ENV_NAME(name) const char *const vkd3d_dbg_env_name = name
232
233static inline const char *debugstr_guid(const GUID *guid)
234{
235 if (!guid)
236 return "(null)";
237
238 return vkd3d_dbg_sprintf("{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
239 (unsigned long)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
240 guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
241 guid->Data4[5], guid->Data4[6], guid->Data4[7]);
242}
243
244static inline const char *debugstr_hresult(HRESULT hr)
245{
246 switch (hr)
247 {
248#define TO_STR(u) case u: return #u;
249 TO_STR(S_OK)
261#undef TO_STR
262 default:
263 return vkd3d_dbg_sprintf("%#x", (int)hr);
264 }
265}
266
267unsigned int vkd3d_env_var_as_uint(const char *name, unsigned int default_value);
268
270{
271 const char *name;
273};
274
275bool vkd3d_debug_list_has_member(const char *string, const char *member);
276uint64_t vkd3d_parse_debug_options(const char *string,
277 const struct vkd3d_debug_option *options, unsigned int option_count);
278void vkd3d_set_thread_name(const char *name);
279
280static inline unsigned int vkd3d_popcount(unsigned int v)
281{
282#ifdef _MSC_VER
283 return __popcnt(v);
284#elif defined(__MINGW32__)
285 return __builtin_popcount(v);
286#else
287 v -= (v >> 1) & 0x55555555;
288 v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
289 return (((v + (v >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
290#endif
291}
292
293static inline bool vkd3d_bitmask_is_contiguous(unsigned int mask)
294{
295 unsigned int i, j;
296
297 for (i = 0, j = 0; i < sizeof(mask) * CHAR_BIT; ++i)
298 {
299 if (mask & (1u << i))
300 ++j;
301 else if (j)
302 break;
303 }
304
305 return vkd3d_popcount(mask) == j;
306}
307
308/* Undefined for x == 0. */
309static inline unsigned int vkd3d_log2i(unsigned int x)
310{
311#ifdef _WIN32
312 /* _BitScanReverse returns the index of the highest set bit,
313 * unlike clz which is 31 - index. */
316 return (unsigned int)result;
317#elif defined(HAVE_BUILTIN_CLZ)
318 return __builtin_clz(x) ^ 0x1f;
319#else
320 static const unsigned int l[] =
321 {
322 ~0u, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
323 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
324 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
325 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
326 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
327 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
328 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
329 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
330 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
331 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
332 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
333 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
334 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
335 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
336 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
337 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
338 };
339 unsigned int i;
340
341 return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24
342 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x];
343#endif
344}
345
346static inline void *vkd3d_memmem( const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
347{
348 const char *str = haystack;
349
350 while (haystack_len >= needle_len)
351 {
352 if (!memcmp(str, needle, needle_len))
353 return (char *)str;
354 ++str;
355 --haystack_len;
356 }
357 return NULL;
358}
359
360static inline bool vkd3d_bound_range(size_t start, size_t count, size_t limit)
361{
362#ifdef HAVE_BUILTIN_ADD_OVERFLOW
363 size_t sum;
364
365 return !__builtin_add_overflow(start, count, &sum) && sum <= limit;
366#else
367 return start <= limit && count <= limit - start;
368#endif
369}
370
371static inline bool vkd3d_object_range_overflow(size_t start, size_t count, size_t size)
372{
373 return (~(size_t)0 - start) / size < count;
374}
375
376static inline uint16_t vkd3d_make_u16(uint8_t low, uint8_t high)
377{
378 return low | ((uint16_t)high << 8);
379}
380
381static inline uint32_t vkd3d_make_u32(uint16_t low, uint16_t high)
382{
383 return low | ((uint32_t)high << 16);
384}
385
387{
388 return (x > y) - (x < y);
389}
390
392{
393 return (x > y) - (x < y);
394}
395
396#define VKD3D_BITMAP_SIZE(x) (((x) + 0x1f) >> 5)
397
398static inline bool bitmap_clear(uint32_t *map, unsigned int idx)
399{
400 return map[idx >> 5] &= ~(1u << (idx & 0x1f));
401}
402
403static inline bool bitmap_set(uint32_t *map, unsigned int idx)
404{
405 return map[idx >> 5] |= (1u << (idx & 0x1f));
406}
407
408static inline bool bitmap_is_set(const uint32_t *map, unsigned int idx)
409{
410 return map[idx >> 5] & (1u << (idx & 0x1f));
411}
412
413static inline int ascii_isupper(int c)
414{
415 return 'A' <= c && c <= 'Z';
416}
417
418static inline int ascii_tolower(int c)
419{
420 return ascii_isupper(c) ? c - 'A' + 'a' : c;
421}
422
423static inline int ascii_strncasecmp(const char *a, const char *b, size_t n)
424{
425 int c_a, c_b;
426
427 while (n--)
428 {
429 c_a = ascii_tolower(*a++);
430 c_b = ascii_tolower(*b++);
431 if (c_a != c_b || !c_a)
432 return c_a - c_b;
433 }
434 return 0;
435}
436
437static inline int ascii_strcasecmp(const char *a, const char *b)
438{
439 int c_a, c_b;
440
441 do
442 {
443 c_a = ascii_tolower(*a++);
444 c_b = ascii_tolower(*b++);
445 } while (c_a == c_b && c_a != '\0');
446
447 return c_a - c_b;
448}
449
451{
452#if HAVE_SYNC_ADD_AND_FETCH
453 return __sync_add_and_fetch(x, val);
454#elif defined(_WIN32)
455 return InterlockedAdd64((LONG64 *)x, val);
456#else
457# error "vkd3d_atomic_add_fetch_u64() not implemented for this platform"
458#endif
459}
460
462{
463#if HAVE_SYNC_ADD_AND_FETCH
464 return __sync_add_and_fetch(x, val);
465#elif defined(_WIN32)
466 return InterlockedAdd((LONG *)x, val);
467#else
468# error "vkd3d_atomic_add_fetch_u32() not implemented for this platform"
469#endif
470}
471
473{
474 return vkd3d_atomic_add_fetch_u64(x, 1);
475}
476
478{
479 return vkd3d_atomic_add_fetch_u32(x, ~0u);
480}
481
483{
484 return vkd3d_atomic_add_fetch_u32(x, 1);
485}
486
488{
489#if HAVE_SYNC_BOOL_COMPARE_AND_SWAP
490 return __sync_bool_compare_and_swap(x, expected, val);
491#elif defined(_WIN32)
493#else
494# error "vkd3d_atomic_compare_exchange_u32() not implemented for this platform"
495#endif
496}
497
498static inline bool vkd3d_atomic_compare_exchange_ptr(void * volatile *x, void *expected, void *val)
499{
500#if HAVE_SYNC_BOOL_COMPARE_AND_SWAP
501 return __sync_bool_compare_and_swap(x, expected, val);
502#elif defined(_WIN32)
504#else
505# error "vkd3d_atomic_compare_exchange_ptr() not implemented for this platform"
506#endif
507}
508
510{
511#if HAVE_ATOMIC_EXCHANGE_N
512 return __atomic_exchange_n(x, val, __ATOMIC_SEQ_CST);
513#elif defined(_WIN32)
514 return InterlockedExchange((LONG *)x, val);
515#else
517
518 do
519 {
520 expected = *x;
522
523 return expected;
524#endif
525}
526
527static inline void *vkd3d_atomic_exchange_ptr(void * volatile *x, void *val)
528{
529#if HAVE_ATOMIC_EXCHANGE_N
530 return __atomic_exchange_n(x, val, __ATOMIC_SEQ_CST);
531#elif defined(_WIN32)
533#else
534 void *expected;
535
536 do
537 {
538 expected = *x;
540
541 return expected;
542#endif
543}
544
546{
547#ifdef _WIN32
549#else
550 pthread_mutex_t lock;
551#endif
552};
553
554#ifdef _WIN32
555#define VKD3D_MUTEX_INITIALIZER {{NULL, -1, 0, 0, 0, 0}}
556#else
557#define VKD3D_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
558#endif
559
560static inline void vkd3d_mutex_init(struct vkd3d_mutex *lock)
561{
562#ifdef _WIN32
564#else
565 int ret;
566
567 if ((ret = pthread_mutex_init(&lock->lock, NULL)))
568 ERR("Failed to initialise the mutex, ret %d.\n", ret);
569#endif
570}
571
572static inline void vkd3d_mutex_lock(struct vkd3d_mutex *lock)
573{
574#ifdef _WIN32
576#else
577 int ret;
578
579 if ((ret = pthread_mutex_lock(&lock->lock)))
580 ERR("Failed to lock the mutex, ret %d.\n", ret);
581#endif
582}
583
584static inline void vkd3d_mutex_unlock(struct vkd3d_mutex *lock)
585{
586#ifdef _WIN32
588#else
589 int ret;
590
591 if ((ret = pthread_mutex_unlock(&lock->lock)))
592 ERR("Failed to unlock the mutex, ret %d.\n", ret);
593#endif
594}
595
596static inline void vkd3d_mutex_destroy(struct vkd3d_mutex *lock)
597{
598#ifdef _WIN32
600#else
601 int ret;
602
603 if ((ret = pthread_mutex_destroy(&lock->lock)))
604 ERR("Failed to destroy the mutex, ret %d.\n", ret);
605#endif
606}
607
609{
610#ifdef _WIN32
611 CONDITION_VARIABLE cond;
612#else
613 pthread_cond_t cond;
614#endif
615};
616
617static inline void vkd3d_cond_init(struct vkd3d_cond *cond)
618{
619#ifdef _WIN32
621#else
622 int ret;
623
624 if ((ret = pthread_cond_init(&cond->cond, NULL)))
625 ERR("Failed to initialise the condition variable, ret %d.\n", ret);
626#endif
627}
628
629static inline void vkd3d_cond_signal(struct vkd3d_cond *cond)
630{
631#ifdef _WIN32
633#else
634 int ret;
635
636 if ((ret = pthread_cond_signal(&cond->cond)))
637 ERR("Failed to signal the condition variable, ret %d.\n", ret);
638#endif
639}
640
641static inline void vkd3d_cond_broadcast(struct vkd3d_cond *cond)
642{
643#ifdef _WIN32
645#else
646 int ret;
647
648 if ((ret = pthread_cond_broadcast(&cond->cond)))
649 ERR("Failed to broadcast the condition variable, ret %d.\n", ret);
650#endif
651}
652
653static inline void vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock)
654{
655#ifdef _WIN32
657 ERR("Failed to wait on the condition variable, error %lu.\n", GetLastError());
658#else
659 int ret;
660
661 if ((ret = pthread_cond_wait(&cond->cond, &lock->lock)))
662 ERR("Failed to wait on the condition variable, ret %d.\n", ret);
663#endif
664}
665
666static inline void vkd3d_cond_destroy(struct vkd3d_cond *cond)
667{
668#ifdef _WIN32
669 /* Nothing to do. */
670#else
671 int ret;
672
673 if ((ret = pthread_cond_destroy(&cond->cond)))
674 ERR("Failed to destroy the condition variable, ret %d.\n", ret);
675#endif
676}
677
678static inline void vkd3d_parse_version(const char *version, int *major, int *minor)
679{
680 *major = atoi(version);
681
682 while (isdigit(*version))
683 ++version;
684 if (*version == '.')
685 ++version;
686
687 *minor = atoi(version);
688}
689
691
692#ifdef _WIN32
693static inline void *vkd3d_dlopen(const char *name)
694{
695 return LoadLibraryA(name);
696}
697
698static inline void *vkd3d_dlsym(void *handle, const char *symbol)
699{
700 return GetProcAddress(handle, symbol);
701}
702
703static inline int vkd3d_dlclose(void *handle)
704{
705 return FreeLibrary(handle);
706}
707
708static inline const char *vkd3d_dlerror(void)
709{
710 unsigned int error = GetLastError();
711 static char message[256];
712
714 return message;
715 sprintf(message, "Unknown error %u.\n", error);
716 return message;
717}
718#elif defined(HAVE_DLFCN_H)
719#include <dlfcn.h>
720
721static inline void *vkd3d_dlopen(const char *name)
722{
723 return dlopen(name, RTLD_NOW);
724}
725
726static inline void *vkd3d_dlsym(void *handle, const char *symbol)
727{
728 return dlsym(handle, symbol);
729}
730
731static inline int vkd3d_dlclose(void *handle)
732{
733 return dlclose(handle);
734}
735
736static inline const char *vkd3d_dlerror(void)
737{
738 return dlerror();
739}
740#else
741static inline void *vkd3d_dlopen(const char *name)
742{
743 return NULL;
744}
745
746static inline void *vkd3d_dlsym(void *handle, const char *symbol)
747{
748 return NULL;
749}
750
751static inline int vkd3d_dlclose(void *handle)
752{
753 return 0;
754}
755
756static inline const char *vkd3d_dlerror(void)
757{
758 return "Not implemented for this platform.\n";
759}
760#endif
761
762#endif /* __VKD3D_COMMON_H */
#define isdigit(c)
Definition: acclib.h:68
_Check_return_ _Ret_maybenull_ _In_ size_t alignment
Definition: align.cpp:48
#define InterlockedExchange
Definition: armddk.h:54
r l[0]
Definition: byte_order.h:168
Definition: _map.h:48
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
unsigned int idx
Definition: utils.c:40
#define CHAR_BIT
Definition: cabinet.h:45
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
static const WCHAR version[]
Definition: asmname.c:66
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
BOOL WINAPI SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD Timeout)
Definition: sync.c:59
VOID WINAPI WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable)
Definition: sync.c:91
VOID WINAPI InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
Definition: sync.c:22
VOID WINAPI WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable)
Definition: sync.c:98
DWORD WINAPI FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:483
GUID guid
Definition: version.c:147
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
unsigned short uint16_t
Definition: stdint.h:35
unsigned char uint8_t
Definition: stdint.h:33
_ACRTIMP int __cdecl atoi(const char *)
Definition: string.c:1720
char * va_list
Definition: vadefs.h:50
return ret
Definition: mutex.c:147
#define INFINITE
Definition: serial.h:102
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
GLuint start
Definition: gl.h:1545
GLint level
Definition: gl.h:1546
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLenum GLint GLuint mask
Definition: glext.h:6028
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLint limit
Definition: glext.h:10326
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint GLfloat * val
Definition: glext.h:7180
GLuint64EXT * result
Definition: glext.h:11304
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define InterlockedAdd64
Definition: interlocked.h:72
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
#define InterlockedAdd
Definition: interlocked.h:66
#define InterlockedCompareExchange
Definition: interlocked.h:119
__INTRIN_INLINE unsigned int __popcnt(unsigned int value)
Definition: intrin_x86.h:1458
#define S_OK
Definition: intsafe.h:52
#define c
Definition: ke_i.h:80
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define error(str)
Definition: mkdosfs.c:1605
#define sprintf
Definition: sprintf.c:45
static IPrintDialogCallback callback
Definition: printdlg.c:325
BOOL expected
Definition: store.c:2000
static const char haystack[]
Definition: editor.c:190
#define RTLD_NOW
Definition: port.h:100
#define uint32_t
Definition: nsiface.idl:61
#define uint16_t
Definition: nsiface.idl:60
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
const WCHAR * str
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:180
#define minor(rdev)
Definition: propsheet.cpp:929
#define major(rdev)
Definition: propsheet.cpp:928
Definition: match.c:390
Definition: dsound.c:943
Definition: tftpd.h:60
Definition: name.c:39
volatile unsigned int lock
Definition: linux.h:833
pthread_cond_t cond
Definition: vkd3d_common.h:613
const char * name
Definition: vkd3d_common.h:271
pthread_mutex_t lock
Definition: vkd3d_common.h:550
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:687
rwlock_t lock
Definition: tcpcore.h:0
int64_t LONG64
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
static void * vkd3d_atomic_exchange_ptr(void *volatile *x, void *val)
Definition: vkd3d_common.h:527
static int vkd3d_dlclose(void *handle)
Definition: vkd3d_common.h:751
static const char * debugstr_hresult(HRESULT hr)
Definition: vkd3d_common.h:244
static unsigned int vkd3d_popcount(unsigned int v)
Definition: vkd3d_common.h:280
static bool vkd3d_bound_range(size_t start, size_t count, size_t limit)
Definition: vkd3d_common.h:360
static void * vkd3d_memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
Definition: vkd3d_common.h:346
static void vkd3d_cond_init(struct vkd3d_cond *cond)
Definition: vkd3d_common.h:617
static void * vkd3d_dlsym(void *handle, const char *symbol)
Definition: vkd3d_common.h:746
static uint64_t vkd3d_atomic_increment_u64(uint64_t volatile *x)
Definition: vkd3d_common.h:472
void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt,...) VKD3D_PRINTF_FUNC(3
const char * vkd3d_dbg_sprintf(const char *fmt,...) VKD3D_PRINTF_FUNC(1
vkd3d_dbg_level
Definition: vkd3d_common.h:143
@ VKD3D_DBG_LEVEL_WARN
Definition: vkd3d_common.h:148
@ VKD3D_DBG_LEVEL_NONE
Definition: vkd3d_common.h:144
@ VKD3D_DBG_LEVEL_TRACE
Definition: vkd3d_common.h:149
@ VKD3D_DBG_LEVEL_MESSAGE
Definition: vkd3d_common.h:145
@ VKD3D_DBG_LEVEL_ERR
Definition: vkd3d_common.h:146
@ VKD3D_DBG_LEVEL_FIXME
Definition: vkd3d_common.h:147
static unsigned int vkd3d_log2i(unsigned int x)
Definition: vkd3d_common.h:309
static void vkd3d_parse_version(const char *version, int *major, int *minor)
Definition: vkd3d_common.h:678
static void vkd3d_mutex_init(struct vkd3d_mutex *lock)
Definition: vkd3d_common.h:560
static void vkd3d_mutex_unlock(struct vkd3d_mutex *lock)
Definition: vkd3d_common.h:584
void void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback)
Definition: debug.c:119
enum vkd3d_dbg_level vkd3d_dbg_get_level(void)
Definition: debug.c:55
static bool bitmap_set(uint32_t *map, unsigned int idx)
Definition: vkd3d_common.h:403
static const char * vkd3d_dlerror(void)
Definition: vkd3d_common.h:756
static void vkd3d_mutex_lock(struct vkd3d_mutex *lock)
Definition: vkd3d_common.h:572
void vkd3d_set_thread_name(const char *name)
Definition: debug.c:405
static void vkd3d_cond_broadcast(struct vkd3d_cond *cond)
Definition: vkd3d_common.h:641
#define VKD3D_PRINTF_FUNC(fmt, args)
Definition: vkd3d_common.h:114
static bool bitmap_is_set(const uint32_t *map, unsigned int idx)
Definition: vkd3d_common.h:408
static int ascii_isupper(int c)
Definition: vkd3d_common.h:413
uint64_t vkd3d_parse_debug_options(const char *string, const struct vkd3d_debug_option *options, unsigned int option_count)
Definition: debug.c:370
static uint16_t vkd3d_make_u16(uint8_t low, uint8_t high)
Definition: vkd3d_common.h:376
static uint32_t vkd3d_atomic_exchange_u32(uint32_t volatile *x, uint32_t val)
Definition: vkd3d_common.h:509
static void vkd3d_mutex_destroy(struct vkd3d_mutex *lock)
Definition: vkd3d_common.h:596
#define ERR
Definition: vkd3d_common.h:212
static uint64_t vkd3d_atomic_add_fetch_u64(uint64_t volatile *x, uint64_t val)
Definition: vkd3d_common.h:450
static uint32_t vkd3d_atomic_decrement_u32(uint32_t volatile *x)
Definition: vkd3d_common.h:477
static int vkd3d_u64_compare(uint64_t x, uint64_t y)
Definition: vkd3d_common.h:391
static bool vkd3d_atomic_compare_exchange_ptr(void *volatile *x, void *expected, void *val)
Definition: vkd3d_common.h:498
static void vkd3d_cond_destroy(struct vkd3d_cond *cond)
Definition: vkd3d_common.h:666
HRESULT hresult_from_vkd3d_result(int vkd3d_result)
Definition: error.c:21
static bool vkd3d_atomic_compare_exchange_u32(uint32_t volatile *x, uint32_t expected, uint32_t val)
Definition: vkd3d_common.h:487
static uint32_t vkd3d_make_u32(uint16_t low, uint16_t high)
Definition: vkd3d_common.h:381
static void * vkd3d_dlopen(const char *name)
Definition: vkd3d_common.h:741
static uint64_t align(uint64_t addr, size_t alignment)
Definition: vkd3d_common.h:92
const char * debugstr_an(const char *str, size_t n)
Definition: debug.c:173
static bool vkd3d_bitmask_is_contiguous(unsigned int mask)
Definition: vkd3d_common.h:293
bool vkd3d_debug_list_has_member(const char *string, const char *member)
Definition: debug.c:348
static int ascii_strcasecmp(const char *a, const char *b)
Definition: vkd3d_common.h:437
const char const char * vkd3d_dbg_vsprintf(const char *fmt, va_list args)
Definition: debug.c:134
static uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x)
Definition: vkd3d_common.h:482
static int ascii_tolower(int c)
Definition: vkd3d_common.h:418
static int ascii_strncasecmp(const char *a, const char *b, size_t n)
Definition: vkd3d_common.h:423
#define TO_STR(u)
static int vkd3d_u32_compare(uint32_t x, uint32_t y)
Definition: vkd3d_common.h:386
unsigned int vkd3d_env_var_as_uint(const char *name, unsigned int default_value)
Definition: debug.c:326
static bool bitmap_clear(uint32_t *map, unsigned int idx)
Definition: vkd3d_common.h:398
static uint32_t vkd3d_atomic_add_fetch_u32(uint32_t volatile *x, uint32_t val)
Definition: vkd3d_common.h:461
static void vkd3d_cond_wait(struct vkd3d_cond *cond, struct vkd3d_mutex *lock)
Definition: vkd3d_common.h:653
static void vkd3d_cond_signal(struct vkd3d_cond *cond)
Definition: vkd3d_common.h:629
static bool vkd3d_object_range_overflow(size_t start, size_t count, size_t size)
Definition: vkd3d_common.h:371
vkd3d_result
Definition: vkd3d_types.h:41
void(* PFN_vkd3d_log)(const char *format, va_list args)
Definition: vkd3d_types.h:66
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define S_FALSE
Definition: winerror.h:3451
#define DXGI_ERROR_NOT_FOUND
Definition: winerror.h:7122
#define DXGI_ERROR_UNSUPPORTED
Definition: winerror.h:7125
#define E_NOINTERFACE
Definition: winerror.h:3479
#define DXGI_ERROR_MORE_DATA
Definition: winerror.h:7123
#define E_POINTER
Definition: winerror.h:3480
#define E_ABORT
Definition: winerror.h:3481
#define const
Definition: zconf.h:233