Improve compare-memcopy.

This commit is contained in:
2023-01-03 20:50:18 +01:00
parent 558ec08614
commit 3e0ea2560a
3 changed files with 180 additions and 33 deletions

View File

@ -18,6 +18,7 @@
#include "../render.hpp"
#include "render_opengles.hpp"
#include "../display/display_glx.hpp"
#include "../cmp_memcpy.hpp"
#include <cstdlib>
#include <cstdio>
#include <cstring>
@ -28,32 +29,6 @@ typedef void (*rk_MultiDrawElementsIndirectFunc)(rk_uint, rk_uint, const void *,
static rk_DrawElementsInstancedBaseInstanceFunc rk_DrawElementsInstancedBaseInstance = nullptr;
static rk_MultiDrawElementsIndirectFunc rk_MultiDrawElementsIndirect = nullptr;
static bool rk_compare_replace(
void * __restrict _dst,
void const * __restrict _src,
unsigned const size) {
rk_ulong hash = 0;
rk_ulong * dst = reinterpret_cast<rk_ulong *>(_dst);
rk_ulong const * src = reinterpret_cast<rk_ulong const *>(_src);
unsigned count = size / sizeof(rk_ulong);
unsigned remain = (size - count * sizeof(rk_ulong));
if (count) {
do {
hash |= *dst ^ *src;
*dst++ = *src++;
} while(--count > 0);
}
if (remain) {
rk_ubyte * rdst = reinterpret_cast<rk_ubyte *>(dst);
rk_ubyte const * rsrc = reinterpret_cast<rk_ubyte const *>(src);
do {
hash |= *rdst ^ *rsrc;
*rdst++ = *rsrc++;
} while(--remain > 0);
}
return (hash != 0);
}
#ifdef RK_BUCKETS_SORT
struct rk_bucket {
@ -143,7 +118,7 @@ static bool rk_buckets_sort(
command->base_index = mesh->base_index;
command->base_vertex = 0;
command->base_instance = indices - batch.indices;
modified |= rk_compare_replace(indices, bucket->indices, bucket->count * sizeof(rk_ushort));
modified |= rk_cmp_memcpy<sizeof(rk_ushort)>(indices, bucket->indices, bucket->count * sizeof(rk_ushort));
indices += bucket->count;
++command;
}
@ -937,18 +912,19 @@ void rk_fill_batch(
return;
}
batch->count = count;
bool const cmp_flags =
(flags && rk_compare_replace(batch->flags, flags, batch->count * sizeof(rk_instance_flags)));
bool const cmp_meshes =
(meshes && rk_compare_replace(batch->meshes, meshes, batch->count * sizeof(rk_mesh)));
bool const cmp_flags = (flags &&
rk_cmp_memcpy<sizeof(rk_ubyte)>(batch->flags, flags, batch->count * sizeof(rk_instance_flags)));
bool const cmp_meshes = (meshes &&
rk_cmp_memcpy<sizeof(rk_ushort)>(batch->meshes, meshes, batch->count * sizeof(rk_mesh)));
bool const need_sorting = (cmp_flags || cmp_meshes || resized);
if (batch->nparams) {
rk_parameter const * const last_param = batch->params + batch->nparams;
if (got_any_params) {
rk_ubyte const * const * src = params;
for (rk_parameter const * dst = batch->params; dst < last_param; ++dst, ++src) {
dst->dirty =
(*src && rk_compare_replace(dst->source, *src, batch->count * dst->src_size)) || need_sorting;
dst->dirty = ((*src &&
rk_cmp_memcpy<sizeof(rk_uint)>(dst->source, *src, batch->count * dst->src_size))
|| need_sorting);
}
} else if (need_sorting) {
for (rk_parameter const * dst = batch->params; dst < last_param; ++dst) {