mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-15 13:41:33 +01:00
vk: use debuffer for geometry mem management
This commit is contained in:
parent
a2b083300c
commit
118bdd9985
@ -132,7 +132,7 @@ uint32_t R_DEBuffer_Alloc(r_debuffer_t* debuf, r_lifetime_t lifetime, uint32_t s
|
||||
const uint32_t offset = R_FlippingBuffer_Alloc(&debuf->dynamic, size, align);
|
||||
if (offset == ALO_ALLOC_FAILED)
|
||||
return ALO_ALLOC_FAILED;
|
||||
return offset + debuf->static_offset;
|
||||
return offset + debuf->static_size;
|
||||
}
|
||||
case LifetimeStatic:
|
||||
{
|
||||
|
@ -15,34 +15,22 @@
|
||||
|
||||
static struct {
|
||||
vk_buffer_t buffer;
|
||||
alo_ring_t static_ring;
|
||||
alo_ring_t dynamic_ring;
|
||||
|
||||
int frame_index;
|
||||
uint32_t dynamic_offsets[MAX_CONCURRENT_FRAMES];
|
||||
r_debuffer_t alloc;
|
||||
} g_geom;
|
||||
|
||||
qboolean R_GeometryBufferAllocAndLock( r_geometry_buffer_lock_t *lock, int vertex_count, int index_count, r_geometry_lifetime_t lifetime ) {
|
||||
const uint32_t vertices_size = vertex_count * sizeof(vk_vertex_t);
|
||||
const uint32_t indices_size = index_count * sizeof(uint16_t);
|
||||
const uint32_t total_size = vertices_size + indices_size;
|
||||
alo_ring_t * const ring = (lifetime != LifetimeSingleFrame) ? &g_geom.static_ring : &g_geom.dynamic_ring;
|
||||
|
||||
const uint32_t alloc_offset = aloRingAlloc(ring, total_size, sizeof(vk_vertex_t));
|
||||
const uint32_t offset = alloc_offset + ((lifetime == LifetimeSingleFrame) ? GEOMETRY_BUFFER_STATIC_SIZE : 0);
|
||||
if (alloc_offset == ALO_ALLOC_FAILED) {
|
||||
const uint32_t offset = R_DEBuffer_Alloc(&g_geom.alloc, (lifetime == LifetimeSingleFrame) ? LifetimeDynamic : LifetimeStatic, total_size, sizeof(vk_vertex_t));
|
||||
if (offset == ALO_ALLOC_FAILED) {
|
||||
/* gEngine.Con_Printf(S_ERROR "Cannot allocate %s geometry buffer for %d vertices (%d bytes) and %d indices (%d bytes)\n", */
|
||||
/* lifetime == LifetimeSingleFrame ? "dynamic" : "static", */
|
||||
/* vertex_count, vertices_size, index_count, indices_size); */
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store first dynamic allocation this frame
|
||||
if (lifetime == LifetimeSingleFrame && g_geom.dynamic_offsets[g_geom.frame_index] == ALO_ALLOC_FAILED) {
|
||||
//gEngine.Con_Reportf("FRAME=%d FIRST_OFFSET=%d\n", g_geom.frame_index, alloc_offset);
|
||||
g_geom.dynamic_offsets[g_geom.frame_index] = alloc_offset;
|
||||
}
|
||||
|
||||
{
|
||||
const uint32_t vertices_offset = offset / sizeof(vk_vertex_t);
|
||||
const uint32_t indices_offset = (offset + vertices_size) / sizeof(uint16_t);
|
||||
@ -83,19 +71,13 @@ void R_GeometryBufferUnlock( const r_geometry_buffer_lock_t *lock ) {
|
||||
R_VkStagingUnlock(lock->impl_.staging_handle);
|
||||
}
|
||||
|
||||
void XVK_RenderBufferMapClear( void ) {
|
||||
aloRingInit(&g_geom.static_ring, GEOMETRY_BUFFER_STATIC_SIZE);
|
||||
aloRingInit(&g_geom.dynamic_ring, GEOMETRY_BUFFER_DYNAMIC_SIZE);
|
||||
for (int i = 0; i < COUNTOF(g_geom.dynamic_offsets); ++i) {
|
||||
g_geom.dynamic_offsets[i] = ALO_ALLOC_FAILED;
|
||||
}
|
||||
g_geom.frame_index = 0;
|
||||
void R_GeometryBuffer_MapClear( void ) {
|
||||
R_DEBuffer_Init(&g_geom.alloc, GEOMETRY_BUFFER_STATIC_SIZE, GEOMETRY_BUFFER_DYNAMIC_SIZE);
|
||||
}
|
||||
|
||||
void XVK_RenderBufferPrintStats( void ) {
|
||||
// TODO get alignment holes size
|
||||
gEngine.Con_Reportf("Buffer usage: %uKiB of (%uKiB)\n",
|
||||
g_geom.static_ring.head / 1024, g_geom.static_ring.size / 1024);
|
||||
// gEngine.Con_Reportf("Buffer usage: %uKiB of (%uKiB)\n", g_geom.alloc..head / 1024, g_geom.static_ring.size / 1024);
|
||||
}
|
||||
|
||||
qboolean R_GeometryBuffer_Init(void) {
|
||||
@ -106,7 +88,7 @@ qboolean R_GeometryBuffer_Init(void) {
|
||||
(vk_core.rtx ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0))) // TODO staging buffer?
|
||||
return false;
|
||||
|
||||
XVK_RenderBufferMapClear();
|
||||
R_GeometryBuffer_MapClear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -115,13 +97,7 @@ void R_GeometryBuffer_Shutdown(void) {
|
||||
}
|
||||
|
||||
void R_GeometryBuffer_Flip(void) {
|
||||
const int new_frame = (g_geom.frame_index + 1) % COUNTOF(g_geom.dynamic_offsets);
|
||||
if (g_geom.dynamic_offsets[new_frame] != ALO_ALLOC_FAILED) {
|
||||
//gEngine.Con_Reportf("FRAME=%d FREE_OFFSET=%d\n", g_geom.frame_index, g_geom.dynamic_offsets[new_frame]);
|
||||
aloRingFree(&g_geom.dynamic_ring, g_geom.dynamic_offsets[new_frame]);
|
||||
g_geom.dynamic_offsets[new_frame] = ALO_ALLOC_FAILED;
|
||||
}
|
||||
g_geom.frame_index = new_frame;
|
||||
R_DEBuffer_Flip(&g_geom.alloc);
|
||||
}
|
||||
|
||||
VkBuffer R_GeometryBuffer_Get(void) {
|
||||
|
@ -51,7 +51,7 @@ qboolean R_GeometryBufferAllocAndLock( r_geometry_buffer_lock_t *lock, int verte
|
||||
void R_GeometryBufferUnlock( const r_geometry_buffer_lock_t *lock );
|
||||
//void R_VkGeometryBufferFree( int handle );
|
||||
|
||||
void R_GeometryBufferMapClear( void ); // Free the entire buffer for a new map
|
||||
void R_GeometryBuffer_MapClear( void ); // Free the entire buffer for a new map
|
||||
|
||||
void R_GeometryBufferPrintStats( void );
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "vk_lightmap.h"
|
||||
#include "vk_const.h"
|
||||
#include "vk_render.h"
|
||||
#include "vk_geometry.h"
|
||||
#include "vk_math.h"
|
||||
#include "vk_common.h"
|
||||
#include "vk_core.h"
|
||||
@ -155,7 +156,7 @@ void R_NewMap( void ) {
|
||||
// TODO should we do something like VK_BrushBeginLoad?
|
||||
VK_BrushStatsClear();
|
||||
|
||||
XVK_RenderBufferMapClear();
|
||||
R_GeometryBuffer_MapClear();
|
||||
|
||||
VK_ClearLightmap();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user