Skip to content

Commit

Permalink
vertexcodec: Change new version from 0xe to 1
Browse files Browse the repository at this point in the history
With all the previous changes, the encoding format is now more or less
stable. While it is possible to expand the encoding a little more to
enhance XOR encoding in some cases, these are unlikely and should not
invalidate any existing v1 streams.

As part of this, -ce setting in gltfpack is enabled in release builds
for easier testing.
  • Loading branch information
zeux committed Dec 28, 2024
1 parent 978cca2 commit 546652c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ void processDev(const char* path)

meshopt_encodeVertexVersion(0);
encodeVertex<PackedVertex>(copy, "L");
meshopt_encodeVertexVersion(0xe);
meshopt_encodeVertexVersion(1);
encodeVertex<PackedVertex>(copy, "0", 0);
encodeVertex<PackedVertex>(copy, "1", 1);
encodeVertex<PackedVertex>(copy, "2", 2);
Expand All @@ -1427,7 +1427,7 @@ int main(int argc, char** argv)
{
void runTests();

meshopt_encodeVertexVersion(0);
meshopt_encodeVertexVersion(1);
meshopt_encodeIndexVersion(1);

if (argc == 1)
Expand Down
17 changes: 7 additions & 10 deletions demo/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const unsigned char kVertexDataV0[] = {
};

static const unsigned char kVertexDataV1[] = {
0xae, 0xee, 0xaa, 0xee, 0x00, 0x4b, 0x4b, 0x4b, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x7d, 0x7d, 0x7d,
0xa1, 0xee, 0xaa, 0xee, 0x00, 0x4b, 0x4b, 0x4b, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x7d, 0x7d, 0x7d,
0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x62, // clang-format :-/
};
Expand All @@ -68,7 +68,7 @@ static const unsigned char kVertexDataV1[] = {
// the encoder that exercised all features of the format; because of this it is much larger
// and will never be produced by the encoder itself.
static const unsigned char kVertexDataV1Custom[] = {
0xae, 0xd4, 0x94, 0xd4, 0x01, 0x0e, 0x00, 0x58, 0x57, 0x58, 0x02, 0x02, 0x12, 0x00, 0x00, 0x00,
0xa1, 0xd4, 0x94, 0xd4, 0x01, 0x0e, 0x00, 0x58, 0x57, 0x58, 0x02, 0x02, 0x12, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -2060,29 +2060,26 @@ void runTests()
encodeIndexSequenceEmpty();

decodeVertexV0();
encodeVertexMemorySafe();
decodeVertexMemorySafe();
decodeVertexRejectExtraBytes();
decodeVertexRejectMalformedHeaders();

decodeVertexV1();
decodeVertexV1Custom();

for (int version = 0; version <= 1; ++version)
{
meshopt_encodeVertexVersion(version == 1 ? 0xe : version);
meshopt_encodeVertexVersion(version);

decodeVertexMemorySafe();
decodeVertexRejectExtraBytes();
decodeVertexRejectMalformedHeaders();
decodeVertexBitGroups();
decodeVertexBitGroupSentinels();
decodeVertexDeltas();
decodeVertexBitXor();
decodeVertexLarge();
decodeVertexSmall();
encodeVertexEmpty();
encodeVertexMemorySafe();
}

meshopt_encodeVertexVersion(0);

decodeFilterOct8();
decodeFilterOct12();
decodeFilterQuat12();
Expand Down
6 changes: 2 additions & 4 deletions gltf/gltfpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,15 +1514,13 @@ int main(int argc, char** argv)
settings.compress = true;
settings.fallback = true;
}
#ifndef NDEBUG
else if (strcmp(arg, "-ce") == 0)
{
fprintf(stderr, "Warning: experimental compression will produce files that may not decode in the future!\n");
meshopt_encodeVertexVersion(0xe);
fprintf(stderr, "Warning: experimental compression will produce files that are not compliant with EXT_meshopt_compression\n");
meshopt_encodeVertexVersion(1);
settings.compress = true;
settings.compressmore = true;
}
#endif
else if (strcmp(arg, "-v") == 0)
{
settings.verbose = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/meshoptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ MESHOPTIMIZER_API size_t meshopt_encodeVertexBufferLevel(unsigned char* buffer,

/**
* Set vertex encoder format version
* version must specify the data format version to encode; valid values are 0 (decodable by all library versions)
* version must specify the data format version to encode; valid values are 0 (decodable by all library versions) and 1 (decodable by 0.23+)
*/
MESHOPTIMIZER_API void meshopt_encodeVertexVersion(int version);

Expand Down
5 changes: 2 additions & 3 deletions src/vertexcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,7 @@ size_t meshopt_encodeVertexBufferBound(size_t vertex_count, size_t vertex_size)

void meshopt_encodeVertexVersion(int version)
{
// note: this version is experimental and the binary format is not finalized; this should not be used in production!
assert(unsigned(version) <= 0 || version == 0xe);
assert(unsigned(version) <= 1);

meshopt::gEncodeVertexVersion = version;
}
Expand Down Expand Up @@ -1810,7 +1809,7 @@ int meshopt_decodeVertexBuffer(void* destination, size_t vertex_count, size_t ve
return -1;

int version = data_header & 0x0f;
if (version > 0 && version != 0xe)
if (version > 1)
return -1;

size_t tail_size = vertex_size + (version == 0 ? 0 : vertex_size / 4);
Expand Down
8 changes: 4 additions & 4 deletions tools/codecbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ File readFile(const char* path)
result.v0.resize(meshopt_encodeVertexBufferBound(result.count, result.stride));
result.v0.resize(meshopt_encodeVertexBuffer(result.v0.data(), result.v0.size(), decoded.data(), result.count, result.stride));

meshopt_encodeVertexVersion(0xe);
meshopt_encodeVertexVersion(1);
result.v1.resize(meshopt_encodeVertexBufferBound(result.count, result.stride));
result.v1.resize(meshopt_encodeVertexBuffer(result.v1.data(), result.v1.size(), decoded.data(), result.count, result.stride));

Expand Down Expand Up @@ -252,7 +252,7 @@ int main(int argc, char** argv)

std::vector<unsigned char> buffer(max_size);

printf("Algorithm :\tvtx\tvtxe\n");
printf("Algorithm :\tvtx0\tvtx1\n");
printf("Size (MB) :\t%.2f\t%.2f\n", double(total_v0) / 1024 / 1024, double(total_v1) / 1024 / 1024);
printf("Ratio :\t%.2f\t%.2f\n", double(total_v0) / double(total_size), double(total_v1) / double(total_size));

Expand Down Expand Up @@ -334,7 +334,7 @@ int main(int argc, char** argv)
}
}

printf("Algorithm :\tvtx\tvtxe\tidx\toct8\toct12\tquat12\texp\n");
printf("Algorithm :\tvtx0\tvtx1\tidx\toct8\toct12\tquat12\texp\n");

for (int l = 0; l < (loop ? 100 : 1); ++l)
{
Expand All @@ -343,7 +343,7 @@ int main(int argc, char** argv)
double bestvd0 = 0, bestid = 0;
benchCodecs(vertices, indices, bestvd0, bestid, verbose);

meshopt_encodeVertexVersion(0xe);
meshopt_encodeVertexVersion(1);

double bestvd1 = 0, bestidr = 0;
benchCodecs(vertices, indices, bestvd1, bestidr, verbose);
Expand Down
2 changes: 1 addition & 1 deletion tools/codecfuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
uint8_t data0 = size > 0 ? data[0] : 0;
int level = data0 % 5;

meshopt_encodeVertexVersion(level < 4 ? 0xe : 0);
meshopt_encodeVertexVersion(level < 4 ? 1 : 0);

fuzzRoundtrip(data, size, 4, level);
fuzzRoundtrip(data, size, 16, level);
Expand Down
7 changes: 4 additions & 3 deletions tools/codectest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ void testFile(FILE* file, size_t count, size_t stride, int level, Stats* stats =
int res = meshopt_decodeVertexBuffer(&decoded[0], count, stride, &input[0], input.size());
if (res != 0 && input.size() == decoded.size())
{
// some files are not encoded; encode them with v1 to let the rest of the flow proceed as is
// some files are not encoded; encode them with v0 to let the rest of the flow proceed as is
memcpy(decoded.data(), input.data(), decoded.size());
input.resize(meshopt_encodeVertexBufferBound(count, stride));
meshopt_encodeVertexVersion(0);
input.resize(meshopt_encodeVertexBuffer(input.data(), input.size(), decoded.data(), count, stride));
}
else if (res != 0)
Expand All @@ -80,9 +81,8 @@ void testFile(FILE* file, size_t count, size_t stride, int level, Stats* stats =
}

std::vector<unsigned char> output(meshopt_encodeVertexBufferBound(count, stride));
meshopt_encodeVertexVersion(0xe);
meshopt_encodeVertexVersion(1);
output.resize(meshopt_encodeVertexBufferLevel(output.data(), output.size(), decoded.data(), count, stride, level));
meshopt_encodeVertexVersion(0);

printf(" raw %zu KB\t", decoded.size() / 1024);
printf(" v0 %.2f", double(input.size()) / double(decoded.size()));
Expand Down Expand Up @@ -205,6 +205,7 @@ int main(int argc, char** argv)
}
else
{
meshopt_encodeVertexVersion(1);
size_t vertex_count = input.size() / stride;
std::vector<unsigned char> output(meshopt_encodeVertexBufferBound(vertex_count, stride));
size_t output_size = meshopt_encodeVertexBuffer(output.data(), output.size(), input.data(), vertex_count, stride);
Expand Down

0 comments on commit 546652c

Please sign in to comment.