vrend: reduce number of re-allocations in constant copying

Also use memcpy to copy the constats. These two things might shave of some
cycles but the measureable performance benefit is marginal.

v2: Avoid the memcpy that ralloc does when increasing the size, the data
   is overwritten anyway.

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Signed-off-by: Jakob Bornecrantz <jakob@collabora.com>
macos/master
Gert Wollny 6 years ago committed by Jakob Bornecrantz
parent 3cb469599e
commit c1b6c98589
  1. 16
      src/vrend_renderer.c

@ -420,6 +420,7 @@ struct vrend_vertex_element_array {
struct vrend_constants {
unsigned int *consts;
uint32_t num_consts;
uint32_t num_allocated_consts;
};
struct vrend_shader_view {
@ -2379,18 +2380,21 @@ void vrend_set_constants(struct vrend_context *ctx,
float *data)
{
struct vrend_constants *consts;
uint i;
consts = &ctx->sub->consts[shader];
ctx->sub->const_dirty[shader] = true;
consts->consts = realloc(consts->consts, num_constant * sizeof(float));
if (!consts->consts)
return;
/* avoid reallocations by only growing the buffer */
if (consts->num_allocated_consts < num_constant) {
free(consts->consts);
consts->consts = malloc(num_constant * sizeof(float));
if (!consts->consts)
return;
consts->num_allocated_consts = num_constant;
}
memcpy(consts->consts, data, num_constant * sizeof(unsigned int));
consts->num_consts = num_constant;
for (i = 0; i < num_constant; i++)
consts->consts[i] = ((unsigned int *)data)[i];
}
void vrend_set_uniform_buffer(struct vrend_context *ctx,

Loading…
Cancel
Save