diff --git a/doc/100_tested_maps.md b/doc/100_tested_maps.md index 925a4584..583140bf 100644 --- a/doc/100_tested_maps.md +++ b/doc/100_tested_maps.md @@ -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 diff --git a/src/client/refresh/files/light.c b/src/client/refresh/files/light.c index 6b9a06bd..d00ce3a8 100644 --- a/src/client/refresh/files/light.c +++ b/src/client/refresh/files/light.c @@ -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) { diff --git a/src/client/refresh/gl1/gl1_light.c b/src/client/refresh/gl1/gl1_light.c index d8438a63..fbfbcea7 100644 --- a/src/client/refresh/gl1/gl1_light.c +++ b/src/client/refresh/gl1/gl1_light.c @@ -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)) { diff --git a/src/client/refresh/vk/header/local.h b/src/client/refresh/vk/header/local.h index c9dfed08..67da2bf3 100644 --- a/src/client/refresh/vk/header/local.h +++ b/src/client/refresh/vk/header/local.h @@ -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); diff --git a/src/client/refresh/vk/vk_light.c b/src/client/refresh/vk/vk_light.c index e567b33d..16933bc2 100644 --- a/src/client/refresh/vk/vk_light.c +++ b/src/client/refresh/vk/vk_light.c @@ -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)) { diff --git a/src/client/refresh/vk/vk_lightmap.c b/src/client/refresh/vk/vk_lightmap.c index 6300ac7e..2f50facc 100644 --- a/src/client/refresh/vk/vk_lightmap.c +++ b/src/client/refresh/vk/vk_lightmap.c @@ -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(); }