FIx/workaround wrong number of primitives in PBVG grid buffers
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Sep 2018 12:41:39 +0000 (14:41 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Sep 2018 12:45:13 +0000 (14:45 +0200)
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?

source/blender/gpu/intern/gpu_buffers.c

index 6584836d32d185da716d24fcea9711d10289704d..f970717c2c9533c4263e4af6a4c1d7854e7e904a 100644 (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;
 }