Skip to content

Commit

Permalink
Remove TRACE code from vertex/index codec
Browse files Browse the repository at this point in the history
Index codec is basically finished and unlikely to get updated at this
point in a meaningful way (short of dynamic codeaux which hasn't proved
useful so far so it's unlikely it will...); vertex codec might still get
revved in the future but the existing stats aren't likely to be terribly
useful, as we'll need more thorough information about the distribution
of individual components to make progress.
  • Loading branch information
zeux committed Dec 28, 2020
1 parent 1999d7e commit 4600e89
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 144 deletions.
78 changes: 0 additions & 78 deletions src/indexcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
#include <assert.h>
#include <string.h>

#ifndef TRACE
#define TRACE 0
#endif

#if TRACE
#include <stdio.h>
#endif

// This work is based on:
// Fabian Giesen. Simple lossless index buffer compression & follow-up. 2013
// Conor Stokes. Vertex Cache Optimised Index Buffer Compression. 2014
Expand Down Expand Up @@ -167,38 +159,6 @@ static void writeTriangle(void* destination, size_t offset, size_t index_size, u
}
}

#if TRACE
static size_t sortTop16(unsigned char dest[16], size_t stats[256])
{
size_t destsize = 0;

for (size_t i = 0; i < 256; ++i)
{
size_t j = 0;
for (; j < destsize; ++j)
{
if (stats[i] >= stats[dest[j]])
{
if (destsize < 16)
destsize++;

memmove(&dest[j + 1], &dest[j], destsize - 1 - j);
dest[j] = (unsigned char)i;
break;
}
}

if (j == destsize && destsize < 16)
{
dest[destsize] = (unsigned char)i;
destsize++;
}
}

return destsize;
}
#endif

} // namespace meshopt

size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, const unsigned int* indices, size_t index_count)
Expand All @@ -207,11 +167,6 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons

assert(index_count % 3 == 0);

#if TRACE
size_t codestats[256] = {};
size_t codeauxstats[256] = {};
#endif

// the minimum valid encoding is header, 1 byte per triangle and a 16-byte codeaux table
if (buffer_size < 1 + index_count / 3 + 16)
return 0;
Expand Down Expand Up @@ -275,10 +230,6 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons

*code++ = (unsigned char)((fe << 4) | fec);

#if TRACE
codestats[code[-1]]++;
#endif

// note that we need to update the last index since free indices are delta-encoded
if (fec == 15)
encodeIndex(data, c, last), last = c;
Expand Down Expand Up @@ -334,11 +285,6 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons
*data++ = codeaux;
}

#if TRACE
codestats[code[-1]]++;
codeauxstats[codeaux]++;
#endif

// note that we need to update the last index since free indices are delta-encoded
if (fea == 15)
encodeIndex(data, a, last), last = a;
Expand Down Expand Up @@ -387,30 +333,6 @@ size_t meshopt_encodeIndexBuffer(unsigned char* buffer, size_t buffer_size, cons
assert(data >= buffer + index_count / 3 + 16);
assert(data <= buffer + buffer_size);

#if TRACE
unsigned char codetop[16], codeauxtop[16];
size_t codetopsize = sortTop16(codetop, codestats);
size_t codeauxtopsize = sortTop16(codeauxtop, codeauxstats);

size_t sumcode = 0, sumcodeaux = 0;
for (size_t i = 0; i < 256; ++i)
sumcode += codestats[i], sumcodeaux += codeauxstats[i];

size_t acccode = 0, acccodeaux = 0;

printf("code\t\t\t\t\tcodeaux\n");

for (size_t i = 0; i < codetopsize && i < codeauxtopsize; ++i)
{
acccode += codestats[codetop[i]];
acccodeaux += codeauxstats[codeauxtop[i]];

printf("%2d: %02x = %d (%.1f%% ..%.1f%%)\t\t%2d: %02x = %d (%.1f%% ..%.1f%%)\n",
int(i), codetop[i], int(codestats[codetop[i]]), double(codestats[codetop[i]]) / double(sumcode) * 100, double(acccode) / double(sumcode) * 100,
int(i), codeauxtop[i], int(codeauxstats[codeauxtop[i]]), double(codeauxstats[codeauxtop[i]]) / double(sumcodeaux) * 100, double(acccodeaux) / double(sumcodeaux) * 100);
}
#endif

return data - buffer;
}

Expand Down
66 changes: 0 additions & 66 deletions src/vertexcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4600e89

Please sign in to comment.