gl1,vk: reuse initial shared lightmap buffer

This commit is contained in:
Denis Pauk 2023-10-15 21:29:10 +03:00
parent 0506b02c60
commit c3c80593c8
8 changed files with 113 additions and 50 deletions

View file

@ -7,16 +7,17 @@
* G - texture glitches,
* B - can't load.
## Quake2 ReRelease
Notes:
* mgu2m3: vk: crash
* mgu5m1: gl1,vk: non transparent flowers
* mgu5m2: server code: Too many models 256 (226 inline models)
# Quake2 ReRelease
| map | gl1.4 | gl3/gles3 | gl4.6 | vk | soft |
| ----------------------------------- | ------ | --------- | ----- | ------ | ----------- |
| maps/badlands.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/base1.bsp | ML/MD5 | WL/ML/MD5 | N/A | ML/MD5 | WL/ML/MD5/G |
| maps/base1.bsp | ML/MD5 | WL/ML/MD5 | N/A | MD5 | WL/ML/MD5/G |
| maps/base2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/base3.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/base64.bsp | N/A | N/A | N/A | N/A | N/A |
@ -62,35 +63,35 @@ Notes:
| maps/jail4.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/jail5.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/lab.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgdm1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1m2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1m3.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1m4.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1m5.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu1trial.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu2m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu2m2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu2m3.bsp | B | N/A | N/A | ML | N/A |
| maps/mgu3m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu3m2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu3m3.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu3m4.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu3secret.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu4m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu4m2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu4m3.bsp | B | N/A | N/A | B | N/A |
| maps/mgu4trial.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu5m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgdm1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1m2.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1m3.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1m4.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1m5.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu1trial.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu2m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu2m2.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu2m3.bsp | B | N/A | N/A | B | N/A |
| maps/mgu3m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu3m2.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu3m3.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu3m4.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu3secret.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu4m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu4m2.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu4m3.bsp | B | N/A | N/A | MD5 | N/A |
| maps/mgu4trial.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu5m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu5m2.bsp | B | N/A | N/A | B | N/A |
| maps/mgu5m3.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu5trial.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu6m1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu6m2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu6m3.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mgu6trial.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mguboss.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mguhub.bsp | ML | G | B | ML | ML |
| maps/mgu5m3.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu5trial.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu6m1.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu6m2.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu6m3.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mgu6trial.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mguboss.bsp | N/A | N/A | N/A | MD5 | N/A |
| maps/mguhub.bsp | MD5 | ML/MD5 | ML/MD5| MD5 | ML/MD5 |
| maps/mine1.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mine2.bsp | N/A | N/A | N/A | N/A | N/A |
| maps/mine3.bsp | N/A | N/A | N/A | N/A | N/A |

View file

@ -27,6 +27,7 @@
#include "../ref_shared.h"
static float *s_blocklights = NULL, *s_blocklights_max = NULL;
static byte *s_bufferlights = NULL, *s_bufferlights_max = NULL;
static int
@ -397,8 +398,12 @@ R_AddDynamicLights(const msurface_t *surf, const refdef_t *r_newrefdef,
void
R_InitTemporaryLMBuffer(void)
{
/* buffer for generate light maps */
s_blocklights = NULL;
s_blocklights_max = NULL;
/* buffer for temporary copy light maps */
s_bufferlights = NULL;
s_bufferlights_max = NULL;
}
void
@ -412,6 +417,15 @@ R_FreeTemporaryLMBuffer(void)
s_blocklights = NULL;
s_blocklights_max = NULL;
/* Cleanup temp buffers */
if (s_bufferlights)
{
free(s_bufferlights);
}
s_bufferlights = NULL;
s_bufferlights_max = NULL;
}
static void
@ -441,6 +455,37 @@ R_ResizeTemporaryLMBuffer(size_t size)
}
}
/* Use this one instead allocate in stack */
byte*
R_GetTemporaryLMBuffer(size_t size)
{
if (!s_bufferlights || ((s_bufferlights + size) >= s_bufferlights_max))
{
int new_size = ROUNDUP(size, 1024);
if (new_size < 4096)
{
new_size = 4096;
}
if (s_bufferlights)
{
free(s_bufferlights);
}
s_bufferlights = malloc(new_size);
s_bufferlights_max = s_bufferlights + new_size;
if (!s_bufferlights)
{
Com_Error(ERR_DROP, "Can't alloc s_bufferlights");
}
}
memset(s_bufferlights, 0, size);
return s_bufferlights;
}
/*
* Combine and scale multiple lightmaps into the floating format in blocklights
*/
@ -583,7 +628,7 @@ store:
stride -= (smax << 2);
bl = s_blocklights;
if ((dest + (stride * (tmax - 1)) + smax * LIGHTMAP_BYTES) >= destmax)
if ((dest + (stride * (tmax - 1)) + smax * LIGHTMAP_BYTES) > destmax)
{
Com_Error(ERR_DROP, "%s destination too small for lightmap %d > %ld",
__func__, (stride * (tmax - 1)) + smax * LIGHTMAP_BYTES, destmax - dest);

View file

@ -261,8 +261,11 @@ void
LM_BeginBuildingLightmaps(model_t *m)
{
static lightstyle_t lightstyles[MAX_LIGHTSTYLES];
int i;
unsigned dummy[BLOCK_WIDTH * BLOCK_HEIGHT] = {0};
int i, size;
byte *dummy;
size = BLOCK_WIDTH * BLOCK_HEIGHT * LIGHTMAP_BYTES;
dummy = R_GetTemporaryLMBuffer(size);
memset(gl_lms.allocated, 0, sizeof(gl_lms.allocated));

View file

@ -504,14 +504,17 @@ R_RenderBrushPoly(entity_t *currententity, msurface_t *fa)
(fa->styles[maps] == 0)) &&
(fa->dlightframe != r_framecount))
{
unsigned temp[34 * 34];
int smax, tmax;
int smax, tmax, size;
byte *temp;
smax = (fa->extents[0] >> fa->lmshift) + 1;
tmax = (fa->extents[1] >> fa->lmshift) + 1;
R_BuildLightMap(fa, (void *)temp, smax * 4,
(byte*)temp + sizeof(temp),
size = smax * tmax * LIGHTMAP_BYTES;
temp = R_GetTemporaryLMBuffer(size);
R_BuildLightMap(fa, temp, smax * 4,
temp + size,
&r_newrefdef, r_modulate->value, r_framecount);
R_SetCacheState(fa, &r_newrefdef);

View file

@ -383,6 +383,7 @@ extern void R_BuildLightMap(const msurface_t *surf, byte *dest, int stride, cons
const refdef_t *r_newrefdef, float modulate, int r_framecount);
extern void R_InitTemporaryLMBuffer(void);
extern void R_FreeTemporaryLMBuffer(void);
extern byte *R_GetTemporaryLMBuffer(size_t size);
/* Warp Sky logic */
extern void R_ClipSkyPolygon(int nump, vec3_t vecs, int stage,

View file

@ -32,7 +32,7 @@
#include <string.h>
#include <stdarg.h>
#define REF_VERSION "SOFT 0.01"
#define REF_VERSION "Yamagi Quake II Software Refresher"
/*

View file

@ -270,12 +270,16 @@ Vk_BeginBuildingLightmaps(model_t *m)
*/
if (vk_state.lightmap_textures[DYNLIGHTMAP_OFFSET].resource.image == VK_NULL_HANDLE)
{
for (i = DYNLIGHTMAP_OFFSET; i < MAX_LIGHTMAPS*2; i++)
for (i = DYNLIGHTMAP_OFFSET; i < MAX_LIGHTMAPS * 2; i++)
{
unsigned dummy[BLOCK_WIDTH * BLOCK_HEIGHT];
byte *dummy;
int size;
size = BLOCK_WIDTH * BLOCK_HEIGHT * LIGHTMAP_BYTES;
dummy = R_GetTemporaryLMBuffer(size);
QVVKTEXTURE_CLEAR(vk_state.lightmap_textures[i]);
QVk_CreateTexture(&vk_state.lightmap_textures[i], (unsigned char*)dummy,
QVk_CreateTexture(&vk_state.lightmap_textures[i], dummy,
BLOCK_WIDTH, BLOCK_HEIGHT, vk_current_lmap_sampler, false);
QVk_DebugSetObjectName((uint64_t)vk_state.lightmap_textures[i].resource.image,
VK_OBJECT_TYPE_IMAGE, va("Image: dynamic lightmap #%d", i));

View file

@ -241,14 +241,17 @@ R_RenderBrushPoly(msurface_t *fa, float *modelMatrix, float alpha, entity_t *cur
{
if ((fa->styles[maps] >= 32 || fa->styles[maps] == 0) && (fa->dlightframe != r_framecount))
{
unsigned temp[BLOCK_WIDTH * BLOCK_HEIGHT];
int smax, tmax;
int smax, tmax, size;
byte *temp;
smax = (fa->extents[0] >> fa->lmshift) + 1;
tmax = (fa->extents[1] >> fa->lmshift) + 1;
R_BuildLightMap(fa, (void *)temp, smax * 4,
(byte*)temp + sizeof(temp),
size = smax * tmax * LIGHTMAP_BYTES;
temp = R_GetTemporaryLMBuffer(size);
R_BuildLightMap(fa, temp, smax * 4,
temp + size,
&r_newrefdef, r_modulate->value, r_framecount);
R_SetCacheState(fa, &r_newrefdef);
@ -445,14 +448,17 @@ Vk_RenderLightmappedPoly(msurface_t *surf, float *modelMatrix, float alpha, enti
if (is_dynamic)
{
unsigned temp[BLOCK_WIDTH * BLOCK_HEIGHT];
int smax, tmax;
int smax, tmax, size;
byte *temp;
smax = (surf->extents[0] >> surf->lmshift) + 1;
tmax = (surf->extents[1] >> surf->lmshift) + 1;
R_BuildLightMap(surf, (void *)temp, smax * 4,
(byte*)temp + sizeof(temp),
size = smax * tmax * LIGHTMAP_BYTES;
temp = R_GetTemporaryLMBuffer(size);
R_BuildLightMap(surf, temp, smax * 4,
temp + size,
&r_newrefdef, r_modulate->value, r_framecount);
if ((surf->styles[map] >= 32 || surf->styles[map] == 0) && (surf->dlightframe != r_framecount))