Skip to content

Commit

Permalink
Merge pull request #820 from zeux/vcone-delc
Browse files Browse the repository at this point in the history
vertexcodec: Implement enhanced delta encoding
  • Loading branch information
zeux authored Dec 13, 2024
2 parents 28549cb + 0c69838 commit fbc7c93
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: test
run: find glTF-Sample-Assets -name '*.gltf' -or -name '*.glb' | xargs -P 2 -L 16 -d '\n' ./gltfpack -cc -test
- name: pack
run: find glTF-Sample-Assets -name '*.gltf' | grep -v 'glTF-Draco' | xargs -P 2 -L 16 -d '\n' -I '{}' ./gltfpack -i '{}' -o '{}pack.gltf'
run: find glTF-Sample-Assets -name '*.gltf' | grep -v '\-Draco/' | xargs -P 2 -L 16 -d '\n' -I '{}' ./gltfpack -i '{}' -o '{}pack.gltf'
- name: validate
run: |
curl -sL $VALIDATOR | tar xJ
Expand Down
9 changes: 6 additions & 3 deletions demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,12 @@ void encodeIndex(const Mesh& mesh, char desc)
(result[i + 2] == mesh.indices[i + 0] && result[i + 0] == mesh.indices[i + 1] && result[i + 1] == mesh.indices[i + 2]));
}

printf("IdxCodec%c: %.1f bits/triangle (post-deflate %.1f bits/triangle); encode %.2f msec, decode %.2f msec (%.2f GB/s)\n",
printf("IdxCodec%c: %.1f bits/triangle (post-deflate %.1f bits/triangle); encode %.2f msec (%.3f GB/s), decode %.2f msec (%.2f GB/s)\n",
desc,
double(buffer.size() * 8) / double(mesh.indices.size() / 3),
double(csize * 8) / double(mesh.indices.size() / 3),
(middle - start) * 1000,
(double(result.size() * 4) / (1 << 30)) / (middle - start),
(end - middle) * 1000,
(double(result.size() * 4) / (1 << 30)) / (end - middle));
}
Expand All @@ -799,11 +800,12 @@ void encodeIndexSequence(const std::vector<unsigned int>& data, size_t vertex_co

assert(memcmp(&data[0], &result[0], data.size() * sizeof(unsigned int)) == 0);

printf("IdxCodec%c: %.1f bits/index (post-deflate %.1f bits/index); encode %.2f msec, decode %.2f msec (%.2f GB/s)\n",
printf("IdxCodec%c: %.1f bits/index (post-deflate %.1f bits/index); encode %.2f msec (%.3f GB/s), decode %.2f msec (%.2f GB/s)\n",
desc,
double(buffer.size() * 8) / double(data.size()),
double(csize * 8) / double(data.size()),
(middle - start) * 1000,
(double(result.size() * 4) / (1 << 30)) / (middle - start),
(end - middle) * 1000,
(double(result.size() * 4) / (1 << 30)) / (end - middle));
}
Expand Down Expand Up @@ -847,11 +849,12 @@ void encodeVertex(const Mesh& mesh, const char* pvn, bool validate = true)

size_t csize = compress(vbuf);

printf("VtxCodec%1s%s: %.1f bits/vertex (post-deflate %.1f bits/vertex); encode %.2f msec, decode %.2f msec (%.2f GB/s)\n", pvn,
printf("VtxCodec%1s%s: %.1f bits/vertex (post-deflate %.1f bits/vertex); encode %.2f msec (%.3f GB/s), decode %.2f msec (%.2f GB/s)\n", pvn,
res == 0 && memcmp(&pv[0], &result[0], pv.size() * sizeof(PV)) == 0 ? "" : "!",
double(vbuf.size() * 8) / double(mesh.vertices.size()),
double(csize * 8) / double(mesh.vertices.size()),
(middle - start) * 1000,
(double(result.size() * sizeof(PV)) / (1 << 30)) / (middle - start),
(end - middle) * 1000,
(double(result.size() * sizeof(PV)) / (1 << 30)) / (end - middle));
}
Expand Down
24 changes: 24 additions & 0 deletions demo/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,27 @@ static void decodeVertexLarge()
assert(memcmp(decoded, data, sizeof(data)) == 0);
}

static void decodeVertexSmall()
{
unsigned char data[13 * 4];

// this tests 0/2/4/8 bit groups in one stream
for (size_t i = 0; i < 13; ++i)
{
data[i * 4 + 0] = 0;
data[i * 4 + 1] = (unsigned char)(i * 1);
data[i * 4 + 2] = (unsigned char)(i * 2);
data[i * 4 + 3] = (unsigned char)(i * 8);
}

std::vector<unsigned char> buffer(meshopt_encodeVertexBufferBound(13, 4));
buffer.resize(meshopt_encodeVertexBuffer(&buffer[0], buffer.size(), data, 13, 4));

unsigned char decoded[13 * 4];
assert(meshopt_decodeVertexBuffer(decoded, 13, 4, &buffer[0], buffer.size()) == 0);
assert(memcmp(decoded, data, sizeof(data)) == 0);
}

static void encodeVertexEmpty()
{
std::vector<unsigned char> buffer(meshopt_encodeVertexBufferBound(0, 16));
Expand Down Expand Up @@ -1960,15 +1981,18 @@ void runTests()
decodeVertexMemorySafe();
decodeVertexRejectExtraBytes();
decodeVertexRejectMalformedHeaders();

decodeVertexBitGroups();
decodeVertexBitGroupSentinels();
decodeVertexLarge();
decodeVertexSmall();
encodeVertexEmpty();

meshopt_encodeVertexVersion(0xe);
decodeVertexBitGroups();
decodeVertexBitGroupSentinels();
decodeVertexLarge();
decodeVertexSmall();
encodeVertexEmpty();
meshopt_encodeVertexVersion(0);

Expand Down
Loading

0 comments on commit fbc7c93

Please sign in to comment.