FIx/workaround wrong number of primitives in PBVG grid buffers

Nodes can have different number of grids, so can not so simply
re-use index buffer across nodes. For now allow re-using buffer
if number of grids matches.

The issue is, number of grids is probably almost never matches,
so in order to have this optimization working need more tricks.
Maybe we can "instance" index buffers?
This commit is contained in:
2018-09-11 14:41:39 +02:00
parent 7951adfb9c
commit 8dde1e13e2

View File

@@ -64,6 +64,7 @@ static ThreadMutex buffer_mutex = BLI_MUTEX_INITIALIZER;
typedef struct GridCommonGPUBuffer {
GPUIndexBuf *mres_buffer;
int mres_prev_gridsize;
int mres_prev_totgrid;
unsigned mres_prev_totquad;
} GridCommonGPUBuffer;
@@ -499,10 +500,11 @@ static GPUIndexBuf *gpu_get_grid_buffer(
gridbuff->mres_buffer = NULL;
gridbuff->mres_prev_gridsize = -1;
gridbuff->mres_prev_totquad = 0;
gridbuff->mres_prev_totgrid = 0;
}
/* VBO is already built */
if (gridbuff->mres_buffer && gridbuff->mres_prev_gridsize == gridsize) {
if (gridbuff->mres_buffer && gridbuff->mres_prev_gridsize == gridsize && gridbuff->mres_prev_totgrid == totgrid) {
*totquad = gridbuff->mres_prev_totquad;
return gridbuff->mres_buffer;
}
@@ -520,6 +522,7 @@ static GPUIndexBuf *gpu_get_grid_buffer(
gridbuff->mres_prev_gridsize = gridsize;
gridbuff->mres_prev_totquad = *totquad;
gridbuff->mres_prev_totgrid = totgrid;
return gridbuff->mres_buffer;
}