Skip to content

Commit

Permalink
Traktor: **WIP** InstanceMesh being rewritten; using GPU culling and …
Browse files Browse the repository at this point in the history
…indirect draw.
  • Loading branch information
apistol78 committed Feb 16, 2024
1 parent fb21931 commit df9a040
Show file tree
Hide file tree
Showing 28 changed files with 1,380 additions and 426 deletions.
3 changes: 1 addition & 2 deletions code/Mesh/Editor/IMeshConverter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -49,7 +49,6 @@ class IMeshConverter : public Object
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const = 0;
Expand Down
27 changes: 15 additions & 12 deletions code/Mesh/Editor/Instance/InstanceMeshConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,6 +11,7 @@
#include "Core/Log/Log.h"
#include "Core/Math/Half.h"
#include "Core/Misc/String.h"
#include "Editor/IPipelineDepends.h"
#include "Mesh/Editor/IndexRange.h"
#include "Mesh/Editor/MeshVertexWriter.h"
#include "Mesh/Editor/Instance/InstanceMeshConverter.h"
Expand All @@ -27,11 +28,16 @@
#include "Render/Mesh/MeshWriter.h"
#include "Render/Mesh/SystemMeshFactory.h"

namespace traktor
namespace traktor::mesh
{
namespace mesh
namespace
{

const Guid c_shaderInstanceMeshCull(L"{37998131-BDA1-DE45-B175-35B088FEE61C}");
const Guid c_shaderInstanceMeshDraw(L"{A8FDE33C-D75B-4D4E-848F-7D7CF97F11D0}");

}

Ref< MeshResource > InstanceMeshConverter::createResource() const
{
return new InstanceMeshResource();
Expand All @@ -54,17 +60,10 @@ bool InstanceMeshConverter::convert(
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const
{
if (maxInstanceCount <= 0)
{
log::error << L"No per-instance parameter data, max instance count is zero." << Endl;
return false;
}

const model::Model* model = models[0];
T_FATAL_ASSERT(model != nullptr);

Expand Down Expand Up @@ -213,10 +212,14 @@ bool InstanceMeshConverter::convert(
checked_type_cast< InstanceMeshResource* >(meshResource)->m_haveRenderMesh = true;
checked_type_cast< InstanceMeshResource* >(meshResource)->m_shader = resource::Id< render::Shader >(materialGuid);
checked_type_cast< InstanceMeshResource* >(meshResource)->m_parts = parts;
checked_type_cast< InstanceMeshResource* >(meshResource)->m_maxInstanceCount = maxInstanceCount;

return true;
}

}
void InstanceMeshConverter::addDependencies(editor::IPipelineDepends* pipelineDepends)
{
pipelineDepends->addDependency(c_shaderInstanceMeshCull, editor::PdfBuild);
pipelineDepends->addDependency(c_shaderInstanceMeshDraw, editor::PdfBuild);
}

}
18 changes: 11 additions & 7 deletions code/Mesh/Editor/Instance/InstanceMeshConverter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,15 @@

#include "Mesh/Editor/IMeshConverter.h"

namespace traktor
namespace traktor::editor
{

class IPipelineDepends;

}

namespace traktor::mesh
{
namespace mesh
{

class InstanceMeshConverter : public IMeshConverter
{
Expand All @@ -28,12 +33,11 @@ class InstanceMeshConverter : public IMeshConverter
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const override final;

static void addDependencies(editor::IPipelineDepends* pipelineDepends);
};

}
}

16 changes: 5 additions & 11 deletions code/Mesh/Editor/MeshPipeline.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022-2023 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -145,7 +145,7 @@ bool buildEmbeddedTexture(editor::IPipelineBuilder* pipelineBuilder, model::Mate

}

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.mesh.MeshPipeline", 38, MeshPipeline, editor::IPipeline)
T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.mesh.MeshPipeline", 39, MeshPipeline, editor::IPipeline)

MeshPipeline::MeshPipeline()
: m_promoteHalf(false)
Expand Down Expand Up @@ -230,6 +230,9 @@ bool MeshPipeline::buildDependencies(
pipelineDepends->addDependency(it.second, editor::PdfBuild | editor::PdfResource);

pipelineDepends->addDependency< render::ShaderGraph >();

// Add dependencies from mesh subsystems.
InstanceMeshConverter::addDependencies(pipelineDepends);
return true;
}

Expand Down Expand Up @@ -449,7 +452,6 @@ bool MeshPipeline::buildOutput(

const int32_t jointCount = models[0]->getJointCount();
const bool vertexColor = haveVertexColors(*models[0]);
int32_t maxInstanceCount = 0;

for (const auto& materialPair : materials)
{
Expand Down Expand Up @@ -637,13 +639,6 @@ bool MeshPipeline::buildOutput(
if (uniformJointCount * 2 != indexedUniform->getLength())
indexedUniform->setLength(uniformJointCount * 2); // Each bone is represented of a quaternion and a vector thus multiply by 2.
}
else if (indexedUniform->getParameterName() == L"InstanceWorld")
{
// Determine how many instances we can use when rendering instanced meshed
// based on how many entries in uniform.
if (maxInstanceCount <= 0 || maxInstanceCount > indexedUniform->getLength() / 2)
maxInstanceCount = indexedUniform->getLength() / 2; // Length of uniform is twice of max number of instances.
}
}
}

Expand Down Expand Up @@ -827,7 +822,6 @@ bool MeshPipeline::buildOutput(
materialGuid,
materialTechniqueMap,
vertexElements,
maxInstanceCount,
resource,
stream
))
Expand Down
8 changes: 2 additions & 6 deletions code/Mesh/Editor/Skinned/SkinnedMeshConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -27,10 +27,8 @@
#include "Render/Mesh/MeshWriter.h"
#include "Render/Mesh/SystemMeshFactory.h"

namespace traktor
namespace traktor::mesh
{
namespace mesh
{

Ref< MeshResource > SkinnedMeshConverter::createResource() const
{
Expand All @@ -54,7 +52,6 @@ bool SkinnedMeshConverter::convert(
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const
Expand Down Expand Up @@ -264,5 +261,4 @@ bool SkinnedMeshConverter::convert(
return true;
}

}
}
9 changes: 2 additions & 7 deletions code/Mesh/Editor/Skinned/SkinnedMeshConverter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@

#include "Mesh/Editor/IMeshConverter.h"

namespace traktor
namespace traktor::mesh
{
namespace mesh
{

class SkinnedMeshConverter : public IMeshConverter
{
Expand All @@ -28,12 +26,9 @@ class SkinnedMeshConverter : public IMeshConverter
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const override final;
};

}
}

8 changes: 2 additions & 6 deletions code/Mesh/Editor/Static/StaticMeshConverter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -26,10 +26,8 @@
#include "Render/Mesh/MeshWriter.h"
#include "Render/Mesh/SystemMeshFactory.h"

namespace traktor
namespace traktor::mesh
{
namespace mesh
{

Ref< MeshResource > StaticMeshConverter::createResource() const
{
Expand All @@ -54,7 +52,6 @@ bool StaticMeshConverter::convert(
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const
Expand Down Expand Up @@ -228,5 +225,4 @@ bool StaticMeshConverter::convert(
return true;
}

}
}
9 changes: 2 additions & 7 deletions code/Mesh/Editor/Static/StaticMeshConverter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@

#include "Mesh/Editor/IMeshConverter.h"

namespace traktor
namespace traktor::mesh
{
namespace mesh
{

class StaticMeshConverter : public IMeshConverter
{
Expand All @@ -28,12 +26,9 @@ class StaticMeshConverter : public IMeshConverter
const Guid& materialGuid,
const std::map< std::wstring, std::list< MeshMaterialTechnique > >& materialTechniqueMap,
const AlignedVector< render::VertexElement >& vertexElements,
int32_t maxInstanceCount,
MeshResource* meshResource,
IStream* meshResourceStream
) const override final;
};

}
}

Loading

0 comments on commit df9a040

Please sign in to comment.