[vulkan] Move mip map generation commands to image

This commit is contained in:
Bill Currie 2021-02-02 00:04:45 +09:00
parent ea72d0c60e
commit 0d4ca46923
3 changed files with 32 additions and 25 deletions

View file

@ -82,5 +82,6 @@ VkImageView QFV_CreateImageView (struct qfv_device_s *device,
void QFV_GenerateMipMaps (struct qfv_device_s *device, VkCommandBuffer cmd,
VkImage image, unsigned mips,
unsigned width, unsigned height, unsigned layers);
int QFV_MipLevels (int width, int height) __attribute__((const));
#endif//__QF_Vulkan_image_h

View file

@ -275,3 +275,33 @@ QFV_GenerateMipMaps (qfv_device_t *device, VkCommandBuffer cmd,
0, 0, 0, 0,
1, &final_barrier);
}
static int
ilog2 (unsigned x)
{
unsigned o = x;
if (x > 0x7fffffff) {
// avoid overflow
return 31;
}
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
int y = 0;
y |= ((x & 0xffff0000) != 0) << 4;
y |= ((x & 0xff00ff00) != 0) << 3;
y |= ((x & 0xf0f0f0f0) != 0) << 2;
y |= ((x & 0xcccccccc) != 0) << 1;
y |= ((x & 0xaaaaaaaa) != 0) << 0;
return y - ((o & (x - 1)) != 0);
}
int
QFV_MipLevels (int width, int height)
{
return ilog2 (max (width, height)) + 1;
}

View file

@ -64,30 +64,6 @@
#include "r_scrap.h"
#include "vid_vulkan.h"
static int
ilog2 (unsigned x)
{
unsigned o = x;
if (x > 0x7fffffff) {
// avoid overflow
return 31;
}
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;
int y = 0;
y |= ((x & 0xffff0000) != 0) << 4;
y |= ((x & 0xff00ff00) != 0) << 3;
y |= ((x & 0xf0f0f0f0) != 0) << 2;
y |= ((x & 0xcccccccc) != 0) << 1;
y |= ((x & 0xaaaaaaaa) != 0) << 0;
return y - ((o & (x - 1)) != 0);
}
void
Vulkan_ExpandPalette (byte *dst, const byte *src, const byte *palette,
int alpha, int count)
@ -164,7 +140,7 @@ Vulkan_LoadTex (vulkan_ctx_t *ctx, tex_t *tex, int mip, const char *name)
}
if (mip) {
mip = ilog2 (max (tex->width, tex->height)) + 1;
mip = QFV_MipLevels (tex->width, tex->height);
} else {
mip = 1;
}