1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Meshoptimizer update library

This commit is contained in:
K. S. Ernest (iFire) Lee
2020-12-27 16:54:21 -08:00
parent 59b30e1d23
commit 8b69f9c18a
7 changed files with 223 additions and 365 deletions

View File

@@ -80,14 +80,6 @@
#include <wasm_simd128.h>
#endif
#ifndef TRACE
#define TRACE 0
#endif
#if TRACE
#include <stdio.h>
#endif
#ifdef SIMD_WASM
#define wasmx_splat_v32x4(v, i) wasm_v32x4_shuffle(v, v, i, i, i, i)
#define wasmx_unpacklo_v8x16(a, b) wasm_v8x16_shuffle(a, b, 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23)
@@ -133,19 +125,6 @@ inline unsigned char unzigzag8(unsigned char v)
return -(v & 1) ^ (v >> 1);
}
#if TRACE
struct Stats
{
size_t size;
size_t header;
size_t bitg[4];
size_t bitb[4];
};
Stats* bytestats;
Stats vertexstats[256];
#endif
static bool encodeBytesGroupZero(const unsigned char* buffer)
{
for (size_t i = 0; i < kByteGroupSize; ++i)
@@ -267,17 +246,8 @@ static unsigned char* encodeBytes(unsigned char* data, unsigned char* data_end,
assert(data + best_size == next);
data = next;
#if TRACE > 1
bytestats->bitg[bitslog2]++;
bytestats->bitb[bitslog2] += best_size;
#endif
}
#if TRACE > 1
bytestats->header += header_size;
#endif
return data;
}
@@ -306,19 +276,9 @@ static unsigned char* encodeVertexBlock(unsigned char* data, unsigned char* data
vertex_offset += vertex_size;
}
#if TRACE
const unsigned char* olddata = data;
bytestats = &vertexstats[k];
#endif
data = encodeBytes(data, data_end, buffer, (vertex_count + kByteGroupSize - 1) & ~(kByteGroupSize - 1));
if (!data)
return 0;
#if TRACE
bytestats = 0;
vertexstats[k].size += data - olddata;
#endif
}
memcpy(last_vertex, &vertex_data[vertex_size * (vertex_count - 1)], vertex_size);
@@ -1086,10 +1046,6 @@ size_t meshopt_encodeVertexBuffer(unsigned char* buffer, size_t buffer_size, con
assert(vertex_size > 0 && vertex_size <= 256);
assert(vertex_size % 4 == 0);
#if TRACE
memset(vertexstats, 0, sizeof(vertexstats));
#endif
const unsigned char* vertex_data = static_cast<const unsigned char*>(vertices);
unsigned char* data = buffer;
@@ -1142,28 +1098,6 @@ size_t meshopt_encodeVertexBuffer(unsigned char* buffer, size_t buffer_size, con
assert(data >= buffer + tail_size);
assert(data <= buffer + buffer_size);
#if TRACE
size_t total_size = data - buffer;
for (size_t k = 0; k < vertex_size; ++k)
{
const Stats& vsk = vertexstats[k];
printf("%2d: %d bytes\t%.1f%%\t%.1f bpv", int(k), int(vsk.size), double(vsk.size) / double(total_size) * 100, double(vsk.size) / double(vertex_count) * 8);
#if TRACE > 1
printf("\t\thdr %d bytes\tbit0 %d (%d bytes)\tbit1 %d (%d bytes)\tbit2 %d (%d bytes)\tbit3 %d (%d bytes)",
int(vsk.header),
int(vsk.bitg[0]), int(vsk.bitb[0]),
int(vsk.bitg[1]), int(vsk.bitb[1]),
int(vsk.bitg[2]), int(vsk.bitb[2]),
int(vsk.bitg[3]), int(vsk.bitb[3]));
#endif
printf("\n");
}
#endif
return data - buffer;
}