Fix lightmap temporary buffer size calculation

Introduced in a1249534, fixed load of mgu3m2 in vk render.
This commit is contained in:
Denis Pauk 2023-10-15 12:47:30 +03:00
parent 9346b08e74
commit 2790b0de92
6 changed files with 40 additions and 56 deletions

View file

@ -8,9 +8,9 @@
* B - can't load.
Notes:
* mgu5m1: non transparent flowers
* mgu3m2: broken allocation of lightmap
* mgu5m2: Too many models 256 (226 inline models)
* mgu5m1: gl1,vk: non transparent flowers
* mgu3m2: gl1: broken allocation of lightmap
* mgu5m2: server code: Too many models 256 (226 inline models)
# Quake2 ReRelease

View file

@ -409,13 +409,19 @@ R_BuildLightMap(msurface_t *surf, byte *dest, int stride, refdef_t *r_newrefdef,
if (surf->texinfo->flags &
(SURF_SKY | SURF_TRANS33 | SURF_TRANS66 | SURF_WARP))
{
Com_Error(ERR_DROP, "RI_BuildLightMap called for non-lit surface");
Com_Error(ERR_DROP, "%s called for non-lit surface", __func__);
}
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax;
if ((size * 3) >= (s_blocklights_max - s_blocklights))
{
Com_Error(ERR_DROP, "%s lighmap requires more space %ld < %d",
__func__, s_blocklights_max - s_blocklights, size * 3);
}
/* set to full bright if no light data */
if (!surf->samples)
{

View file

@ -138,9 +138,11 @@ float *s_blocklights = NULL, *s_blocklights_max = NULL;
void
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
{
int size;
int size, smax, tmax;
size = surf->extents[0] * surf->extents[1];
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax;
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
{

View file

@ -240,7 +240,6 @@ void Vk_FreeUnusedImages (void);
qboolean Vk_ImageHasFreeSpace(void);
void LM_InitBlock(void);
void LM_UploadBlock(qboolean dynamic);
qboolean LM_AllocBlock(int w, int h, int *x, int *y);
void RE_BeginRegistration (const char *model);

View file

@ -128,9 +128,11 @@ float *s_blocklights = NULL, *s_blocklights_max = NULL;
void
RI_BuildLightMap(msurface_t *surf, byte *dest, int stride)
{
int size;
int size, smax, tmax;
size = surf->extents[0] * surf->extents[1];
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
size = smax * tmax;
if (!s_blocklights || (s_blocklights + (size * 3) >= s_blocklights_max))
{

View file

@ -36,61 +36,36 @@ LM_InitBlock(void)
}
void
LM_UploadBlock(qboolean dynamic)
LM_UploadBlock()
{
int texture;
if (dynamic)
texture = vk_lms.current_lightmap_texture;
if (vk_state.lightmap_textures[texture].resource.image != VK_NULL_HANDLE)
{
texture = 0;
/* FIXME: Incorrect lightmap load: mgu3m2 */
QVk_UpdateTextureData(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT);
}
else
{
texture = vk_lms.current_lightmap_texture;
QVVKTEXTURE_CLEAR(vk_state.lightmap_textures[texture]);
QVk_CreateTexture(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer,
BLOCK_WIDTH, BLOCK_HEIGHT, vk_current_lmap_sampler, false);
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].resource.image,
VK_OBJECT_TYPE_IMAGE, va("Image: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].imageView,
VK_OBJECT_TYPE_IMAGE_VIEW, va("Image View: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].descriptorSet,
VK_OBJECT_TYPE_DESCRIPTOR_SET, va("Descriptor Set: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].resource.memory,
VK_OBJECT_TYPE_DEVICE_MEMORY, va("Memory: dynamic lightmap #%d", texture));
}
if (dynamic)
if (++vk_lms.current_lightmap_texture == MAX_LIGHTMAPS)
{
int i;
int height = 0;
for (i = 0; i < BLOCK_WIDTH; i++)
{
if (vk_lms.allocated[i] > height)
{
height = vk_lms.allocated[i];
}
}
QVk_UpdateTextureData(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer, 0, 0, BLOCK_WIDTH, height);
}
else
{
if (vk_state.lightmap_textures[texture].resource.image != VK_NULL_HANDLE)
{
/* FIXME: Incorrect lightmap load: mgu3m2 */
QVk_UpdateTextureData(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT);
}
else
{
QVVKTEXTURE_CLEAR(vk_state.lightmap_textures[texture]);
QVk_CreateTexture(&vk_state.lightmap_textures[texture], vk_lms.lightmap_buffer,
BLOCK_WIDTH, BLOCK_HEIGHT, vk_current_lmap_sampler, false);
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].resource.image,
VK_OBJECT_TYPE_IMAGE, va("Image: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].imageView,
VK_OBJECT_TYPE_IMAGE_VIEW, va("Image View: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].descriptorSet,
VK_OBJECT_TYPE_DESCRIPTOR_SET, va("Descriptor Set: dynamic lightmap #%d", texture));
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[texture].resource.memory,
VK_OBJECT_TYPE_DEVICE_MEMORY, va("Memory: dynamic lightmap #%d", texture));
}
if (++vk_lms.current_lightmap_texture == MAX_LIGHTMAPS)
{
Com_Error(ERR_DROP,
"%s() - MAX_LIGHTMAPS exceeded\n", __func__);
}
Com_Error(ERR_DROP,
"%s() - MAX_LIGHTMAPS exceeded\n", __func__);
}
}
@ -246,7 +221,7 @@ Vk_CreateSurfaceLightmap(msurface_t *surf)
if (!LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t))
{
LM_UploadBlock(false);
LM_UploadBlock();
LM_InitBlock();
if (!LM_AllocBlock(smax, tmax, &surf->light_s, &surf->light_t))
@ -318,6 +293,6 @@ Vk_BeginBuildingLightmaps(model_t *m)
void
Vk_EndBuildingLightmaps(void)
{
LM_UploadBlock(false);
LM_UploadBlock();
}