Skip to content

Commit

Permalink
multi-threaded scene loading
Browse files Browse the repository at this point in the history
  • Loading branch information
beaumanvienna committed Sep 8, 2024
1 parent 57b3133 commit f36d79c
Show file tree
Hide file tree
Showing 59 changed files with 441 additions and 219 deletions.
4 changes: 2 additions & 2 deletions application/lucre/UI/UIControllerIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace LucreApp
MeshComponent mesh{"controller icon", model};

{
m_ID1 = m_Registry.create();
m_ID1 = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_ID1, mesh);

TransformComponent transform{};
Expand All @@ -241,7 +241,7 @@ namespace LucreApp
m_Registry.emplace<SpriteRendererComponent2D>(m_ID1, spriteRendererComponent2D);
}
{
m_ID2 = m_Registry.create();
m_ID2 = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_ID2, mesh);

TransformComponent transform{};
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/UI/UIControllerIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace LucreApp
void Init();

public:
entt::registry m_Registry;
Registry m_Registry;

private:
void LoadModels();
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/sceneDescriptions/terrain.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
],
"translation":
[
-3.22584, 5.06019, 41.9383
1.0569, 2.24202, -0.363263
]
}
}
Expand Down
6 changes: 3 additions & 3 deletions application/lucre/scenes/beachScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace LucreApp
PerspectiveCameraComponent perspectiveCameraComponent(aspectRatio, yfov, zfar, znear);
m_CameraController = std::make_shared<CameraController>(perspectiveCameraComponent);

m_Camera = m_Registry.create();
m_Camera = m_Registry.Create();
TransformComponent cameraTransform{};
m_Registry.emplace<TransformComponent>(m_Camera, cameraTransform);
uint cameraNode = m_SceneGraph.CreateNode(m_Camera, "defaultCamera", "defaultCamera", m_Dictionary);
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace LucreApp
m_Dictionary.Retrieve("application/lucre/models/external_3D_files/lightBulb/lightBulb.gltf::0::root");
if (m_Lightbulb0 == entt::null)
{
m_Lightbulb0 = m_Registry.create();
m_Lightbulb0 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999978, 0.0100001, 0.0100001});
Expand All @@ -165,7 +165,7 @@ namespace LucreApp
m_Dictionary.Retrieve("application/lucre/models/external_3D_files/lightBulb/lightBulb2.gltf::0::root");
if (m_Lightbulb1 == entt::null)
{
m_Lightbulb1 = m_Registry.create();
m_Lightbulb1 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999934, 0.00999997, 0.00999993});
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/scenes/characterAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace LucreApp
{

CharacterAnimation::CharacterAnimation(entt::registry& registry, entt::entity gameObject, SkeletalAnimations& animations)
CharacterAnimation::CharacterAnimation(Registry& registry, entt::entity gameObject, SkeletalAnimations& animations)
: m_Registry{registry}, m_GameObject{gameObject}, m_Animations{animations}, m_DirToTheRight{false},
m_Transform{glm::mat4(1.0f)}, m_PreviousPositionX{0.0f}, m_MotionState{MotionState::IDLE},
m_FramesPerRotation{FRAMES_PER_ROTATION}, m_FramesToRotate{0}, m_Speed{0.0f}, m_WaitStartWalk{0.0f},
Expand Down
4 changes: 2 additions & 2 deletions application/lucre/scenes/characterAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace LucreApp
{

public:
CharacterAnimation(entt::registry& registry, entt::entity gameObject, SkeletalAnimations& animations);
CharacterAnimation(Registry& registry, entt::entity gameObject, SkeletalAnimations& animations);
~CharacterAnimation() {}

void Start();
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace LucreApp
float ToDegree(float rotation);

private:
entt::registry& m_Registry;
Registry& m_Registry;
std::unique_ptr<GamepadInputController> m_GamepadInputController;
entt::entity m_GameObject;
SkeletalAnimations& m_Animations;
Expand Down
6 changes: 3 additions & 3 deletions application/lucre/scenes/cutScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace LucreApp
MeshComponent mesh{"walk animation", model};
mesh.m_Enabled = false;

m_Guybrush[i] = m_Registry.create();
m_Guybrush[i] = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_Guybrush[i], mesh);

TransformComponent transform{};
Expand All @@ -71,7 +71,7 @@ namespace LucreApp

// beach
{
m_Beach = m_Registry.create();
m_Beach = m_Registry.Create();

TransformComponent transform{};
m_Registry.emplace<TransformComponent>(m_Beach, transform);
Expand All @@ -81,7 +81,7 @@ namespace LucreApp
{
for (uint i = 0; i < 2; i++)
{
m_Clouds[i] = m_Registry.create();
m_Clouds[i] = m_Registry.Create();

TransformComponent transform{};
m_Registry.emplace<TransformComponent>(m_Clouds[i], transform);
Expand Down
6 changes: 3 additions & 3 deletions application/lucre/scenes/dessertScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace LucreApp
PerspectiveCameraComponent perspectiveCameraComponent(aspectRatio, yfov, zfar, znear);
m_CameraControllers[CameraTypes::DefaultCamera] = std::make_shared<CameraController>(perspectiveCameraComponent);
m_CameraControllers[CameraTypes::DefaultCamera]->GetCamera().SetName("default camera");
m_Camera[CameraTypes::DefaultCamera] = m_Registry.create();
m_Camera[CameraTypes::DefaultCamera] = m_Registry.Create();
TransformComponent cameraTransform{};
m_Registry.emplace<TransformComponent>(m_Camera[CameraTypes::DefaultCamera], cameraTransform);
uint cameraNode = m_SceneGraph.CreateNode(m_Camera[CameraTypes::DefaultCamera], "defaultCamera", "defaultCamera",
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace LucreApp
if (m_Lightbulb0 == entt::null)
{
LOG_APP_INFO("m_Lightbulb0 not found");
m_Lightbulb0 = m_Registry.create();
m_Lightbulb0 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.01, 0.01, 0.01});
Expand All @@ -313,7 +313,7 @@ namespace LucreApp
if (m_Lightbulb1 == entt::null)
{
LOG_APP_INFO("m_Lightbulb1 not found");
m_Lightbulb1 = m_Registry.create();
m_Lightbulb1 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999934, 0.00999997, 0.00999993});
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/scenes/mainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace LucreApp
PerspectiveCameraComponent perspectiveCameraComponent(aspectRatio, yfov, zfar, znear);
m_CameraController = std::make_shared<CameraController>(perspectiveCameraComponent);

m_Camera = m_Registry.create();
m_Camera = m_Registry.Create();
TransformComponent cameraTransform{};
m_Registry.emplace<TransformComponent>(m_Camera, cameraTransform);
uint cameraNode = m_SceneGraph.CreateNode(m_Camera, "defaultCamera", "defaultCamera", m_Dictionary);
Expand Down
2 changes: 1 addition & 1 deletion application/lucre/scenes/mainSceneModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace LucreApp
MeshComponent mesh{"horn animation", model};
mesh.m_Enabled = false;

m_Guybrush[i] = m_Registry.create();
m_Guybrush[i] = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_Guybrush[i], mesh);

TransformComponent transform{};
Expand Down
6 changes: 3 additions & 3 deletions application/lucre/scenes/nightScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace LucreApp
PerspectiveCameraComponent perspectiveCameraComponent(aspectRatio, yfov, zfar, znear);
m_CameraController = std::make_shared<CameraController>(perspectiveCameraComponent);

m_Camera = m_Registry.create();
m_Camera = m_Registry.Create();
TransformComponent cameraTransform{};
m_Registry.emplace<TransformComponent>(m_Camera, cameraTransform);
uint cameraNode = m_SceneGraph.CreateNode(m_Camera, "defaultCamera", "defaultCamera", m_Dictionary);
Expand Down Expand Up @@ -256,7 +256,7 @@ namespace LucreApp
if (m_Lightbulb0 == entt::null)
{
LOG_APP_INFO("m_Lightbulb0 not found");
m_Lightbulb0 = m_Registry.create();
m_Lightbulb0 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999978, 0.0100001, 0.0100001});
Expand All @@ -282,7 +282,7 @@ namespace LucreApp
if (m_Lightbulb1 == entt::null)
{
LOG_APP_INFO("m_Lightbulb1 not found");
m_Lightbulb1 = m_Registry.create();
m_Lightbulb1 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999934, 0.00999997, 0.00999993});
Expand Down
4 changes: 2 additions & 2 deletions application/lucre/scenes/settingsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace LucreApp
m_BarrelTranslationSpeed[i] = 250.0f + (50.0f * EngineCore::RandomPlusMinusOne());
m_BarrelRotationSpeed[i] = 2.0f + (0.1f * EngineCore::RandomPlusMinusOne());

m_Barrel[i] = m_Registry.create();
m_Barrel[i] = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_Barrel[i], mesh);

TransformComponent transform = TransformComponent(barrelSprite.GetMat4());
Expand All @@ -77,7 +77,7 @@ namespace LucreApp
MeshComponent mesh{"background", model};
mesh.m_Enabled = true;

m_BackGround = m_Registry.create();
m_BackGround = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_BackGround, mesh);

TransformComponent transform = TransformComponent(backGroundSprite.GetMat4());
Expand Down
4 changes: 2 additions & 2 deletions application/lucre/scenes/splashScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace LucreApp
MeshComponent mesh{"walk animation", model};
mesh.m_Enabled = false;

m_Guybrush[i] = m_Registry.create();
m_Guybrush[i] = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_Guybrush[i], mesh);

TransformComponent transform{};
Expand All @@ -83,7 +83,7 @@ namespace LucreApp
MeshComponent mesh{"logo", model};
mesh.m_Enabled = true;

m_Logo = m_Registry.create();
m_Logo = m_Registry.Create();
m_Registry.emplace<MeshComponent>(m_Logo, mesh);

TransformComponent transform{};
Expand Down
6 changes: 3 additions & 3 deletions application/lucre/scenes/terrainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace LucreApp
PerspectiveCameraComponent perspectiveCameraComponent(aspectRatio, yfov, zfar, znear);
m_CameraController = std::make_shared<CameraController>(perspectiveCameraComponent);

m_Camera = m_Registry.create();
m_Camera = m_Registry.Create();
TransformComponent cameraTransform{};
m_Registry.emplace<TransformComponent>(m_Camera, cameraTransform);
uint cameraNode = m_SceneGraph.CreateNode(m_Camera, "defaultCamera", "defaultCamera", m_Dictionary);
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace LucreApp
if (m_Lightbulb0 == entt::null)
{
LOG_APP_INFO("m_Lightbulb0 not found");
m_Lightbulb0 = m_Registry.create();
m_Lightbulb0 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.01, 0.01, 0.01});
Expand All @@ -199,7 +199,7 @@ namespace LucreApp
if (m_Lightbulb1 == entt::null)
{
LOG_APP_INFO("m_Lightbulb1 not found");
m_Lightbulb1 = m_Registry.create();
m_Lightbulb1 = m_Registry.Create();
TransformComponent transform{};

transform.SetScale({0.00999934, 0.00999997, 0.00999993});
Expand Down
33 changes: 31 additions & 2 deletions engine/platform/Vulkan/VKpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace GfxRenderEngine

auto createDescriptorPool = [this, device]()
{
static constexpr uint POOL_SIZE = 500;
static constexpr uint POOL_SIZE = 5000;
std::unique_ptr<VK_DescriptorPool> descriptorPool =
VK_DescriptorPool::Builder(device)
.SetMaxSets(VK_SwapChain::MAX_FRAMES_IN_FLIGHT * POOL_SIZE)
Expand Down Expand Up @@ -114,9 +114,9 @@ namespace GfxRenderEngine
CORE_ASSERT(pool != nullptr, "no command pool found!");
if (!pool)
{
std::cout << "terminating because of thread id:" << threadID << "\n";
exit(1);
}

return pool;
}

Expand All @@ -127,9 +127,38 @@ namespace GfxRenderEngine
CORE_ASSERT(m_DescriptorPools[hash] != nullptr, "no command pool found!");
if (!m_DescriptorPools[hash])
{
std::cout << "thread id:" << threadID << "\n";
exit(1);
}
return *m_DescriptorPools[hash];
}

void VK_Pool::ResetCommandPool()
{
VkCommandPoolResetFlags flags{VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT};
vkResetCommandPool(m_Device, GetCommandPool(), flags);
}

void VK_Pool::ResetCommandPools(ThreadPool& threadpool)
{
VkCommandPoolResetFlags flags{VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT};
for (auto& threadID : threadpool.GetThreadIDs())
{
std::cout << "VK_Pool::ResetAllCommandPools: " << "):" << threadID << "\n";
uint64 hash = std::hash<std::thread::id>()(threadID);
vkResetCommandPool(m_Device, m_CommandPools[hash], flags);
}
}

void VK_Pool::ResetDescriptorPool() { GetDescriptorPool().ResetPool(); }

void VK_Pool::ResetDescriptorPools(ThreadPool& threadpool)
{
for (auto& threadID : threadpool.GetThreadIDs())
{
std::cout << "VK_Pool::ResetAllCommandPools: " << "):" << threadID << "\n";
uint64 hash = std::hash<std::thread::id>()(threadID);
m_DescriptorPools[hash]->ResetPool();
}
}
} // namespace GfxRenderEngine
9 changes: 9 additions & 0 deletions engine/platform/Vulkan/VKpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ namespace GfxRenderEngine
VkCommandPool& GetCommandPool();
VK_DescriptorPool& GetDescriptorPool();

void ResetCommandPool();
void ResetCommandPools(ThreadPool& threadpool);

void ResetDescriptorPool();
void ResetDescriptorPools(ThreadPool& threadpool);

// Not copyable or movable
VK_Pool(const VK_Pool&) = delete;
VK_Pool& operator=(const VK_Pool&) = delete;
Expand All @@ -52,7 +58,10 @@ namespace GfxRenderEngine
QueueFamilyIndices& m_QueueFamilyIndices;
ThreadPool& m_PoolPrimary;
ThreadPool& m_PoolSecondary;

// pool of command pools
std::unordered_map<uint64, VkCommandPool> m_CommandPools;
// pool of descriptor pools
std::unordered_map<uint64, std::unique_ptr<VK_DescriptorPool>> m_DescriptorPools;
};
} // namespace GfxRenderEngine
10 changes: 5 additions & 5 deletions engine/platform/Vulkan/VKrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ namespace GfxRenderEngine
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
}

void VK_Renderer::SubmitShadows(entt::registry& registry,
void VK_Renderer::SubmitShadows(Registry& registry,
const std::vector<DirectionalLightComponent*>& directionalLights)
{
// this function supports one directional light
Expand Down Expand Up @@ -785,7 +785,7 @@ namespace GfxRenderEngine
}
}

void VK_Renderer::Renderpass3D(entt::registry& registry)
void VK_Renderer::Renderpass3D(Registry& registry)
{
if (m_CurrentCommandBuffer)
{
Expand Down Expand Up @@ -844,7 +844,7 @@ namespace GfxRenderEngine
}
}

void VK_Renderer::TransparencyPass(entt::registry& registry, ParticleSystem* particleSystem)
void VK_Renderer::TransparencyPass(Registry& registry, ParticleSystem* particleSystem)
{
if (m_CurrentCommandBuffer)
{
Expand Down Expand Up @@ -889,7 +889,7 @@ namespace GfxRenderEngine
}
}

void VK_Renderer::Submit2D(Camera* camera, entt::registry& registry)
void VK_Renderer::Submit2D(Camera* camera, Registry& registry)
{
if (m_CurrentCommandBuffer)
{
Expand Down Expand Up @@ -917,7 +917,7 @@ namespace GfxRenderEngine
return m_CurrentFrameIndex;
}

void VK_Renderer::UpdateAnimations(entt::registry& registry, const Timestep& timestep)
void VK_Renderer::UpdateAnimations(Registry& registry, const Timestep& timestep)
{
auto view = registry.view<MeshComponent, TransformComponent, SkeletalAnimationTag>();
for (auto entity : view)
Expand Down
Loading

0 comments on commit f36d79c

Please sign in to comment.