From af9ccb490a66d1991587a13b7e2aaa36a07bc7f9 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 10 Dec 2014 13:26:35 +0100 Subject: [PATCH] ddraw: Use wined3d_log2i() to calculate the level count in ddraw_surface_create(). --- dlls/ddraw/surface.c | 9 +-------- dlls/wined3d/utils.c | 31 ------------------------------- dlls/wined3d/wined3d_private.h | 1 - include/wine/wined3d.h | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 556d32f94e8..a4184b8aac6 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -5817,14 +5817,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_ { /* Undocumented feature: Create sublevels until either the * width or the height is 1. */ - DWORD min = desc->dwWidth < desc->dwHeight ? desc->dwWidth : desc->dwHeight; - - desc->u2.dwMipMapCount = 0; - while (min) - { - ++desc->u2.dwMipMapCount; - min >>= 1; - } + desc->u2.dwMipMapCount = wined3d_log2i(min(desc->dwWidth, desc->dwHeight)) + 1; } } else diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c index 566d9211bc0..6ce07b8e9b3 100644 --- a/dlls/wined3d/utils.c +++ b/dlls/wined3d/utils.c @@ -3929,37 +3929,6 @@ const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions = wined3d_ffp_vertex_program_key_compare, }; -/* Return the integer base-2 logarithm of x. Undefined for x == 0. */ -UINT wined3d_log2i(UINT32 x) -{ -#ifdef HAVE___BUILTIN_CLZ - return __builtin_clz(x) ^ 0x1f; -#else - static const UINT l[] = - { - ~0U, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - }; - UINT32 i; - - return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x]; -#endif -} - const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op, const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format, const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format) diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index e8e649a89e4..7935a5dc5a4 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2824,7 +2824,6 @@ GLenum gl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type) DE /* Math utils */ void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2) DECLSPEC_HIDDEN; -UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN; unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN; void wined3d_release_dc(HWND window, HDC dc) DECLSPEC_HIDDEN; diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index baa102a7c7e..0cf26e1dcb2 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -26,6 +26,10 @@ #ifndef __WINE_WINED3D_H #define __WINE_WINED3D_H +#ifndef __WINE_CONFIG_H +# error You must include config.h to use this header +#endif + #include "wine/list.h" #define WINED3D_OK S_OK @@ -2555,4 +2559,35 @@ HRESULT __cdecl wined3d_volume_map(struct wined3d_volume *volume, void __cdecl wined3d_volume_preload(struct wined3d_volume *volume); HRESULT __cdecl wined3d_volume_unmap(struct wined3d_volume *volume); +/* Return the integer base-2 logarithm of x. Undefined for x == 0. */ +static inline unsigned int wined3d_log2i(unsigned int x) +{ +#ifdef HAVE___BUILTIN_CLZ + return __builtin_clz(x) ^ 0x1f; +#else + static const unsigned int l[] = + { + ~0u, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + }; + unsigned int i; + + return (i = x >> 16) ? (x = i >> 8) ? l[x] + 24 : l[i] + 16 : (i = x >> 8) ? l[i] + 8 : l[x]; +#endif +} + #endif /* __WINE_WINED3D_H */ -- 2.11.4.GIT