Skip to content
Snippets Groups Projects
Commit 69ea0c9c authored by Artur Wasmut's avatar Artur Wasmut
Browse files

[#87] add general VertexCacheReorderResult struct. Adjust forsyth reordering accordingly.

parent 5f182098
No related branches found
No related tags found
1 merge request!74Resolve "Mesh Shader Implementation"
......@@ -14,5 +14,5 @@ namespace vkcv::meshlet
* https://www.martin.st/thesis/efficient_triangle_reordering.pdf
* https://github.com/vivkin/forsyth/blob/master/forsyth.h
*/
std::vector<uint32_t> forsythReorder(const std::vector<uint32_t> &idxBuf, const size_t vertexCount);
VertexCacheReorderResult forsythReorder(const std::vector<uint32_t> &idxBuf, const size_t vertexCount);
}
......@@ -23,6 +23,18 @@ namespace vkcv::meshlet {
float boundingSphereRadius;
};
struct VertexCacheReorderResult {
/**
* @param indexBuffer new indexBuffer
* @param skippedIndices indices that have a spacial break
*/
VertexCacheReorderResult(const std::vector<uint32_t> indexBuffer, const std::vector<uint32_t> skippedIndices)
:indexBuffer(indexBuffer), skippedIndices(skippedIndices) {}
std::vector<uint32_t> indexBuffer;
std::vector<uint32_t> skippedIndices;
};
struct MeshShaderModelData {
std::vector<Vertex> vertices;
std::vector<uint32_t> localIndices;
......
......@@ -5,19 +5,6 @@
#include <iostream>
namespace vkcv::meshlet {
struct tipsifyResult{
/**
*
* @param indexBuffer new indexBuffer
* @param skippedIndices indices that have a spacial break
*/
tipsifyResult(const std::vector<uint32_t> indexBuffer, const std::vector<uint32_t> skippedIndices)
:indexBuffer(indexBuffer), skippedIndices(skippedIndices) {}
std::vector<uint32_t> indexBuffer;
std::vector<uint32_t> skippedIndices;
};
/**
* reorders the IndexBuffer, so all usages of vertices to triangle are as close as possible
* @param indexBuffer32Bit current IndexBuffer
......@@ -31,8 +18,6 @@ namespace vkcv::meshlet {
* https://gfx.cs.princeton.edu/pubs/Sander_2007_%3ETR/tipsy.pdf
* https://www.martin.st/thesis/efficient_triangle_reordering.pdf
*/
tipsifyResult tipsifyMesh(
const std::vector<uint32_t> &indexBuffer32Bit,
const int vertexCount, const unsigned int cacheSize = 20);
VertexCacheReorderResult tipsifyMesh(const std::vector<uint32_t> &indexBuffer32Bit,
const int vertexCount, const unsigned int cacheSize = 20);
}
\ No newline at end of file
......@@ -82,8 +82,10 @@ namespace vkcv::meshlet
return score;
}
std::vector<uint32_t> forsythReorder(const std::vector<uint32_t> &idxBuf, const size_t vertexCount)
VertexCacheReorderResult forsythReorder(const std::vector<uint32_t> &idxBuf, const size_t vertexCount)
{
std::vector<uint32_t> skippedIndices;
initScoreTables();
// get the total triangle count from the index buffer
......@@ -98,7 +100,7 @@ namespace vkcv::meshlet
{
vkcv_log(LogLevel::ERROR, "Unsupported mesh.");
vkcv_log(LogLevel::ERROR, "Vertex shared by too many triangles.");
return {};
return VertexCacheReorderResult({}, {});
}
numActiveTris[index]++;
......@@ -287,6 +289,9 @@ namespace vkcv::meshlet
if(!triangleAdded[scanPos])
{
bestTriangle = scanPos;
skippedIndices.push_back(3 * outPos);
break;
}
}
......@@ -307,6 +312,6 @@ namespace vkcv::meshlet
}
}
return outIndices;
return VertexCacheReorderResult(outIndices, skippedIndices);
}
}
\ No newline at end of file
......@@ -118,14 +118,14 @@ namespace vkcv::meshlet {
return nextVertexIndex;
}
tipsifyResult tipsifyMesh(
VertexCacheReorderResult tipsifyMesh(
const std::vector<uint32_t> &indexBuffer32Bit,
const int vertexCount,
const unsigned int cacheSize) {
if (indexBuffer32Bit.empty() || vertexCount <= 0) {
vkcv_log(LogLevel::ERROR, "Invalid Input.");
return tipsifyResult(indexBuffer32Bit ,skippedIndices );
return VertexCacheReorderResult(indexBuffer32Bit ,skippedIndices);
}
int triangleCount = indexBuffer32Bit.size() / 3;
......@@ -271,6 +271,6 @@ namespace vkcv::meshlet {
}
}
return tipsifyResult(reorderedIndexBuffer, skippedIndices);
return VertexCacheReorderResult(reorderedIndexBuffer, skippedIndices);
}
}
\ No newline at end of file
......@@ -138,12 +138,12 @@ int main(int argc, const char** argv) {
const auto& bunny = mesh.vertexGroups[0];
std::vector<vkcv::meshlet::Vertex> interleavedVertices = vkcv::meshlet::convertToVertices(bunny.vertexBuffer.data, bunny.numVertices, attributes[0], attributes[1]);
// mesh shader buffers
const auto& assetLoaderIndexBuffer = mesh.vertexGroups[0].indexBuffer;
std::vector<uint32_t> indexBuffer32Bit = vkcv::meshlet::assetLoaderIndicesTo32BitIndices(assetLoaderIndexBuffer.data, assetLoaderIndexBuffer.type);
vkcv::meshlet::tipsifyResult tipsifyResult = vkcv::meshlet::tipsifyMesh(indexBuffer32Bit, interleavedVertices.size());
//std::vector<uint32_t> reorderedIndexBuffer32Bit = vkcv::meshlet::forsythReorder(indexBuffer32Bit, interleavedVertices.size());
const auto& assetLoaderIndexBuffer = mesh.vertexGroups[0].indexBuffer;
std::vector<uint32_t> indexBuffer32Bit = vkcv::meshlet::assetLoaderIndicesTo32BitIndices(assetLoaderIndexBuffer.data, assetLoaderIndexBuffer.type);
vkcv::meshlet::VertexCacheReorderResult tipsifyResult = vkcv::meshlet::tipsifyMesh(indexBuffer32Bit, interleavedVertices.size());
vkcv::meshlet::VertexCacheReorderResult forsythResult = vkcv::meshlet::forsythReorder(indexBuffer32Bit, interleavedVertices.size());
const auto meshShaderModelData = createMeshShaderModelData(interleavedVertices, tipsifyResult.indexBuffer, tipsifyResult.skippedIndices);
const auto meshShaderModelData = createMeshShaderModelData(interleavedVertices, forsythResult.indexBuffer, forsythResult.skippedIndices);
auto meshShaderVertexBuffer = core.createBuffer<vkcv::meshlet::Vertex>(
vkcv::BufferType::STORAGE,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment