Batch commands memory optim.
This commit is contained in:
parent
628f8bcaa4
commit
3b21e1610a
@ -355,6 +355,7 @@ create_batch.restype = ctypes.c_void_p
|
|||||||
create_batch.argtypes = (
|
create_batch.argtypes = (
|
||||||
ctypes.c_void_p, # vertices
|
ctypes.c_void_p, # vertices
|
||||||
ctypes.c_uint, # max_size
|
ctypes.c_uint, # max_size
|
||||||
|
ctypes.c_uint, # max_meshes
|
||||||
ctypes.c_char_p) # params_format
|
ctypes.c_char_p) # params_format
|
||||||
|
|
||||||
begin_frame = _engine.rk_begin_frame
|
begin_frame = _engine.rk_begin_frame
|
||||||
|
@ -121,6 +121,7 @@ RK_EXPORT rk_vertices_t rk_create_vertices(
|
|||||||
RK_EXPORT rk_batch_t rk_create_batch(
|
RK_EXPORT rk_batch_t rk_create_batch(
|
||||||
rk_vertices_t vertices,
|
rk_vertices_t vertices,
|
||||||
rk_uint max_size,
|
rk_uint max_size,
|
||||||
|
rk_uint max_meshes,
|
||||||
rk_param_format const * params_format);
|
rk_param_format const * params_format);
|
||||||
|
|
||||||
RK_EXPORT void rk_begin_frame();
|
RK_EXPORT void rk_begin_frame();
|
||||||
|
@ -484,6 +484,7 @@ static void rk_pack_mat3_int10_norm(
|
|||||||
rk_batch_t rk_create_batch(
|
rk_batch_t rk_create_batch(
|
||||||
rk_vertices_t _vertices,
|
rk_vertices_t _vertices,
|
||||||
rk_uint max_size,
|
rk_uint max_size,
|
||||||
|
rk_uint max_meshes,
|
||||||
rk_param_format const * params_format) {
|
rk_param_format const * params_format) {
|
||||||
rk_vertices const * const vertices = reinterpret_cast<rk_vertices const *>(_vertices);
|
rk_vertices const * const vertices = reinterpret_cast<rk_vertices const *>(_vertices);
|
||||||
if (!vertices || !max_size || max_size > RK_BATCH_MAX_SIZE) {
|
if (!vertices || !max_size || max_size > RK_BATCH_MAX_SIZE) {
|
||||||
@ -496,6 +497,7 @@ rk_batch_t rk_create_batch(
|
|||||||
}
|
}
|
||||||
rk_batch * batch = new rk_batch;
|
rk_batch * batch = new rk_batch;
|
||||||
batch->max_size = max_size;
|
batch->max_size = max_size;
|
||||||
|
batch->max_meshes = max_meshes;
|
||||||
batch->nparams = nparams;
|
batch->nparams = nparams;
|
||||||
batch->commands_size = 0;
|
batch->commands_size = 0;
|
||||||
batch->packed_size = 0;
|
batch->packed_size = 0;
|
||||||
@ -542,11 +544,10 @@ rk_batch_t rk_create_batch(
|
|||||||
packed_size += max_size * param->size;
|
packed_size += max_size * param->size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batch->commands_size = max_size * sizeof(rk_command);
|
batch->commands_size = max_meshes * sizeof(rk_command);
|
||||||
batch->packed_size = packed_size;
|
batch->packed_size = packed_size;
|
||||||
batch->indices = new rk_ushort[max_size];
|
batch->indices = new rk_ushort[max_size];
|
||||||
batch->commands = new rk_command[max_size];
|
batch->commands = new rk_command[max_meshes];
|
||||||
memset(batch->commands, 0, batch->commands_size);
|
|
||||||
if (rk_MultiDrawElementsIndirect) {
|
if (rk_MultiDrawElementsIndirect) {
|
||||||
glGenBuffers(1, &batch->commands_buffer);
|
glGenBuffers(1, &batch->commands_buffer);
|
||||||
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch->commands_buffer);
|
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, batch->commands_buffer);
|
||||||
@ -733,10 +734,11 @@ static unsigned rk_batch_build_commands(
|
|||||||
rk_batch & batch,
|
rk_batch & batch,
|
||||||
unsigned const ninstances,
|
unsigned const ninstances,
|
||||||
rk_mesh const * const meshes) {
|
rk_mesh const * const meshes) {
|
||||||
rk_command * commands = batch.commands;
|
rk_command * const last_command = batch.commands + batch.max_meshes;
|
||||||
|
rk_command * command = batch.commands;
|
||||||
rk_ushort * base = batch.indices;
|
rk_ushort * base = batch.indices;
|
||||||
rk_ushort * const last = batch.indices + ninstances;
|
rk_ushort * const last = batch.indices + ninstances;
|
||||||
for (rk_ushort * first = batch.indices; first < last; base = first, ++commands) {
|
for (rk_ushort * first = batch.indices; first < last && command < last_command; base = first, ++command) {
|
||||||
rk_mesh const & mesh = meshes[*first++];
|
rk_mesh const & mesh = meshes[*first++];
|
||||||
for ( ; first < last && meshes[*first].packed == mesh.packed; ++first) {
|
for ( ; first < last && meshes[*first].packed == mesh.packed; ++first) {
|
||||||
}
|
}
|
||||||
@ -747,13 +749,13 @@ static unsigned rk_batch_build_commands(
|
|||||||
*first++ = static_cast<rk_ushort>(index);
|
*first++ = static_cast<rk_ushort>(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands->nvertices = static_cast<GLuint>(mesh.ntriangles) * 3;
|
command->nvertices = static_cast<GLuint>(mesh.ntriangles) * 3;
|
||||||
commands->ninstances = first - base;
|
command->ninstances = first - base;
|
||||||
commands->base_index = mesh.base_index;
|
command->base_index = mesh.base_index;
|
||||||
commands->base_vertex = 0;
|
command->base_vertex = 0;
|
||||||
commands->base_instance = base - batch.indices;
|
command->base_instance = base - batch.indices;
|
||||||
}
|
}
|
||||||
return commands - batch.commands;
|
return command - batch.commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rk_batch_pack(
|
static void rk_batch_pack(
|
||||||
|
@ -101,6 +101,7 @@ struct rk_parameter {
|
|||||||
|
|
||||||
struct rk_batch {
|
struct rk_batch {
|
||||||
unsigned max_size;
|
unsigned max_size;
|
||||||
|
unsigned max_meshes;
|
||||||
unsigned nparams;
|
unsigned nparams;
|
||||||
unsigned commands_size;
|
unsigned commands_size;
|
||||||
unsigned packed_size;
|
unsigned packed_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user