Reverting to 32 bit indices

This commit is contained in:
Dynamitos
2024-04-07 16:33:32 +02:00
parent 7a713afdb4
commit cde48f0d15
9 changed files with 29 additions and 26 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ struct Scene
StructuredBuffer<MeshData> meshData; StructuredBuffer<MeshData> meshData;
StructuredBuffer<MeshletDescription> meshletInfos; StructuredBuffer<MeshletDescription> meshletInfos;
StructuredBuffer<uint8_t> primitiveIndices; StructuredBuffer<uint8_t> primitiveIndices;
StructuredBuffer<uint16_t> vertexIndices; StructuredBuffer<uint32_t> vertexIndices;
}; };
ParameterBlock<Scene> pScene; ParameterBlock<Scene> pScene;
+1 -4
View File
@@ -258,12 +258,9 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
vertexData->loadBiTangents(id, biTangents); vertexData->loadBiTangents(id, biTangents);
vertexData->loadColors(id, colors); vertexData->loadColors(id, colors);
Array<uint16> indices(mesh->mNumFaces * 3); Array<uint32> indices(mesh->mNumFaces * 3);
for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex) for (size_t faceIndex = 0; faceIndex < mesh->mNumFaces; ++faceIndex)
{ {
assert(mesh->mFaces[faceIndex].mIndices[0] < std::numeric_limits<uint16>::max());
assert(mesh->mFaces[faceIndex].mIndices[1] < std::numeric_limits<uint16>::max());
assert(mesh->mFaces[faceIndex].mIndices[2] < std::numeric_limits<uint16>::max());
indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0]; indices[faceIndex * 3 + 0] = mesh->mFaces[faceIndex].mIndices[0];
indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1]; indices[faceIndex * 3 + 1] = mesh->mFaces[faceIndex].mIndices[1];
indices[faceIndex * 3 + 2] = mesh->mFaces[faceIndex].mIndices[2]; indices[faceIndex * 3 + 2] = mesh->mFaces[faceIndex].mIndices[2];
+4 -4
View File
@@ -127,7 +127,7 @@ void computeFaceIntegrals(Face& f, ComputationState& state)
+ w * (2 * (n[state.A] * state.Paa + n[state.B] * state.Pab) + w * state.Pa)); + w * (2 * (n[state.A] * state.Paa + n[state.B] * state.Pab) + w * state.Pa));
} }
void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint16>& indices, ComputationState& state) void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint32>& indices, ComputationState& state)
{ {
std::memset(&state, 0, sizeof(ComputationState)); std::memset(&state, 0, sizeof(ComputationState));
for (size_t i = 0; i < indices.size(); i+=3) for (size_t i = 0; i < indices.size(); i+=3)
@@ -172,7 +172,7 @@ void computeVolumeIntegrals(const Array<Vector> vertices, const Array<uint16>& i
state.TP /= 2.0f; state.TP /= 2.0f;
} }
void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint16>& indices, Matrix3& bodyInertia, Vector& centerOfMass, float& mass) void computePhysicsParamsForMesh(Array<Vector>& vertices, const Array<uint32>& indices, Matrix3& bodyInertia, Vector& centerOfMass, float& mass)
{ {
ComputationState state; ComputationState state;
computeVolumeIntegrals(vertices, indices, state); computeVolumeIntegrals(vertices, indices, state);
@@ -200,7 +200,7 @@ ShapeBase::ShapeBase()
} }
ShapeBase::ShapeBase(Array<Vector> vertices, Array<uint16> indices) ShapeBase::ShapeBase(Array<Vector> vertices, Array<uint32> indices)
: vertices(vertices) : vertices(vertices)
, indices(indices) , indices(indices)
{ {
@@ -217,7 +217,7 @@ ShapeBase ShapeBase::transform(const Component::Transform& transform) const
return result; return result;
} }
void ShapeBase::addCollider(Array<Vector> verts, Array<uint16> inds, Matrix4 matrix) void ShapeBase::addCollider(Array<Vector> verts, Array<uint32> inds, Matrix4 matrix)
{ {
size_t indOffset = vertices.size(); size_t indOffset = vertices.size();
for(auto vert : verts) for(auto vert : verts)
+3 -3
View File
@@ -10,15 +10,15 @@ namespace Component
struct ShapeBase struct ShapeBase
{ {
ShapeBase(); ShapeBase();
ShapeBase(Array<Vector> vertices, Array<uint16> indices); ShapeBase(Array<Vector> vertices, Array<uint32> indices);
ShapeBase transform(const Component::Transform& transform) const; ShapeBase transform(const Component::Transform& transform) const;
void addCollider(Array<Vector> vertices, Array<uint16> indices, Matrix4 matrix); void addCollider(Array<Vector> vertices, Array<uint32> indices, Matrix4 matrix);
void visualize() const; void visualize() const;
Vector centerOfMass; Vector centerOfMass;
float mass; float mass;
Matrix3 bodyInertia; Matrix3 bodyInertia;
Array<Vector> vertices; Array<Vector> vertices;
Array<uint16> indices; Array<uint32> indices;
}; };
} // namespace Component } // namespace Component
} // namespace Seele } // namespace Seele
+1 -1
View File
@@ -15,7 +15,7 @@ public:
MeshId id; MeshId id;
uint64 vertexCount; uint64 vertexCount;
PMaterialInstanceAsset referencedMaterial; PMaterialInstanceAsset referencedMaterial;
Array<uint16> indices; Array<uint32> indices;
Array<Meshlet> meshlets; Array<Meshlet> meshlets;
void save(ArchiveBuffer& buffer) const; void save(ArchiveBuffer& buffer) const;
void load(ArchiveBuffer& buffer); void load(ArchiveBuffer& buffer);
+9 -3
View File
@@ -61,20 +61,26 @@ void addTriangle(Array<Meshlet>& meshlets, Meshlet& current, Triangle tri)
} }
} }
void Meshlet::build(const Array<Vector>& positions, const Array<uint16>& indices, Array<Meshlet>& meshlets) void Meshlet::build(const Array<Vector>& positions, const Array<uint32>& indices, Array<Meshlet>& meshlets)
{ {
Meshlet current = { Meshlet current = {
.numVertices = 0, .numVertices = 0,
.numPrimitives = 0, .numPrimitives = 0,
}; };
for (size_t i = 0; i < indices.size() / 3; ++i) Array<Triangle> triangles(indices.size() / 3);
for (size_t i = 0; i < triangles.size(); ++i)
{ {
addTriangle(meshlets, current, Triangle{ triangles.add(Triangle{
.indices = { .indices = {
indices[i * 3 + 0], indices[i * 3 + 0],
indices[i * 3 + 1], indices[i * 3 + 1],
indices[i * 3 + 2], indices[i * 3 + 2],
}, },
}); });
}
if (current.numVertices > 0)
{
completeMeshlet(meshlets, current);
} }
} }
+2 -2
View File
@@ -7,10 +7,10 @@ namespace Seele
struct Meshlet struct Meshlet
{ {
AABB boundingBox; AABB boundingBox;
uint16 uniqueVertices[Gfx::numVerticesPerMeshlet]; // unique vertiex indices in the vertex data uint32 uniqueVertices[Gfx::numVerticesPerMeshlet]; // unique vertiex indices in the vertex data
uint8 primitiveLayout[Gfx::numPrimitivesPerMeshlet * 3]; // indices into the uniqueVertices array, only uint8 needed uint8 primitiveLayout[Gfx::numPrimitivesPerMeshlet * 3]; // indices into the uniqueVertices array, only uint8 needed
uint32 numVertices; uint32 numVertices;
uint32 numPrimitives; uint32 numPrimitives;
static void build(const Array<Vector>& positions, const Array<uint16>& indices, Array<Meshlet>& meshlets); static void build(const Array<Vector>& positions, const Array<uint32>& indices, Array<Meshlet>& meshlets);
}; };
} // namespace Seele } // namespace Seele
+5 -5
View File
@@ -142,7 +142,7 @@ void VertexData::createDescriptors()
} }
} }
void VertexData::loadMesh(MeshId id, Array<uint16> loadedIndices, Array<Meshlet> loadedMeshlets) void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet> loadedMeshlets)
{ {
meshlets.reserve(meshlets.size() + loadedMeshlets.size()); meshlets.reserve(meshlets.size() + loadedMeshlets.size());
vertexIndices.reserve(vertexIndices.size() + loadedMeshlets.size() * Gfx::numVerticesPerMeshlet); vertexIndices.reserve(vertexIndices.size() + loadedMeshlets.size() * Gfx::numVerticesPerMeshlet);
@@ -183,13 +183,13 @@ void VertexData::loadMesh(MeshId id, Array<uint16> loadedIndices, Array<Meshlet>
meshData[id][0].firstIndex = indices.size(); meshData[id][0].firstIndex = indices.size();
meshData[id][0].numIndices = loadedIndices.size(); meshData[id][0].numIndices = loadedIndices.size();
indices.resize(indices.size() + loadedIndices.size()); indices.resize(indices.size() + loadedIndices.size());
std::memcpy(indices.data() + meshData[id][0].firstIndex, loadedIndices.data(), loadedIndices.size() * sizeof(uint16)); std::memcpy(indices.data() + meshData[id][0].firstIndex, loadedIndices.data(), loadedIndices.size() * sizeof(uint32));
indexBuffer = graphics->createIndexBuffer(IndexBufferCreateInfo{ indexBuffer = graphics->createIndexBuffer(IndexBufferCreateInfo{
.sourceData = { .sourceData = {
.size = sizeof(uint16) * indices.size(), .size = sizeof(uint32) * indices.size(),
.data = (uint8*)indices.data(), .data = (uint8*)indices.data(),
}, },
.indexType = Gfx::SE_INDEX_TYPE_UINT16, .indexType = Gfx::SE_INDEX_TYPE_UINT32,
}); });
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
@@ -201,7 +201,7 @@ void VertexData::loadMesh(MeshId id, Array<uint16> loadedIndices, Array<Meshlet>
}); });
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{ vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData = { .sourceData = {
.size = sizeof(uint16) * vertexIndices.size(), .size = sizeof(uint32) * vertexIndices.size(),
.data = (uint8*)vertexIndices.data(), .data = (uint8*)vertexIndices.data(),
}, },
.numElements = vertexIndices.size(), .numElements = vertexIndices.size(),
+3 -3
View File
@@ -61,7 +61,7 @@ public:
void resetMeshData(); void resetMeshData();
void updateMesh(PMesh mesh, Component::Transform& transform); void updateMesh(PMesh mesh, Component::Transform& transform);
void createDescriptors(); void createDescriptors();
void loadMesh(MeshId id, Array<uint16> indices, Array<Meshlet> meshlets); void loadMesh(MeshId id, Array<uint32> indices, Array<Meshlet> meshlets);
MeshId allocateVertexData(uint64 numVertices); MeshId allocateVertexData(uint64 numVertices);
uint64 getMeshOffset(MeshId id); uint64 getMeshOffset(MeshId id);
uint64 getMeshVertexCount(MeshId id); uint64 getMeshVertexCount(MeshId id);
@@ -100,8 +100,8 @@ protected:
Map<MeshId, uint64> meshVertexCounts; Map<MeshId, uint64> meshVertexCounts;
Array<MeshletDescription> meshlets; Array<MeshletDescription> meshlets;
Array<uint8> primitiveIndices; Array<uint8> primitiveIndices;
Array<uint16> vertexIndices; Array<uint32> vertexIndices;
Array<uint16> indices; Array<uint32> indices;
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
Gfx::ODescriptorLayout instanceDataLayout; Gfx::ODescriptorLayout instanceDataLayout;
// for mesh shading // for mesh shading