vkd3d/include/private/vkd3d_common.h
Józef Kucia 2ea8ffb554 libs/vkd3d: Avoid vkCmdCopyQueryPoolResults() for not issued queries.
The Vulkan spec states:

  * "If the query does not become available in a finite amount of time
    (e.g.  due to not issuing a query since the last reset), a
    VK_ERROR_DEVICE_LOST error may occur."

  * "If queries will never finish (e.g. due to being reset but not
    issued), then vkGetQueryPoolResults may not return in finite time."
2017-09-14 14:57:09 +02:00

74 lines
2.1 KiB
C

/*
* Copyright 2016 Józef Kucia for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __VKD3D_COMMON_H
#define __VKD3D_COMMON_H
#include "config.h"
#include "vkd3d_windows.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define DIV_ROUND_UP(a, b) ((a) % (b) == 0 ? (a) / (b) : (a) / (b) + 1)
static inline size_t align(size_t addr, size_t alignment)
{
return (addr + (alignment - 1)) & ~(alignment - 1);
}
#ifdef __GNUC__
# define VKD3D_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args)))
# define VKD3D_UNUSED __attribute__((unused))
#else
# define VKD3D_PRINTF_FUNC(fmt, args)
# define VKD3D_UNUSED
#endif /* __GNUC__ */
static inline unsigned int vkd3d_popcount(unsigned int v)
{
#ifdef HAVE_BUILTIN_POPCOUNT
return __builtin_popcount(v);
#else
v -= (v >> 1) & 0x55555555;
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
return (((v + (v >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
#endif
}
#ifndef _WIN32
# if HAVE_SYNC_ADD_AND_FETCH
static inline LONG InterlockedIncrement(LONG volatile *x)
{
return __sync_add_and_fetch(x, 1);
}
# else
# error "InterlockedIncrement not implemented for this platform"
# endif /* HAVE_SYNC_ADD_AND_FETCH */
# if HAVE_SYNC_SUB_AND_FETCH
static inline LONG InterlockedDecrement(LONG volatile *x)
{
return __sync_sub_and_fetch(x, 1);
}
# else
# error "InterlockedDecrement not implemented for this platform"
# endif
#endif /* _WIN32 */
#endif /* __VKD3D_COMMON_H */