Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ include_directories(Dependencies/src/glslang/src)
include_directories(Dependencies/src/ImGuizmo/src)
include_directories(Dependencies/src/spdlog/include)
include_directories(Dependencies/src/json/include)
include_directories(Dependencies/src/fastgltf/include)

set(VMA_BUILD_SAMPLE OFF CACHE BOOL "")
set(VMA_BUILD_SAMPLE_SHADERS OFF CACHE BOOL "")
Expand Down Expand Up @@ -150,6 +151,7 @@ add_subdirectory(Dependencies/src/cubbyflow)
add_subdirectory(Dependencies/src/etc2comp)
add_subdirectory(Dependencies/src/spdlog)
add_subdirectory(Dependencies/src/backward-cpp)
add_subdirectory(Dependencies/src/fastgltf)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET glfw PROPERTY FOLDER "ThirdPartyLibraries")
Expand Down
14 changes: 11 additions & 3 deletions Dependencies/bootstrap.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"source": {
"type": "git",
"url": "https://github.com/KhronosGroup/Vulkan-Headers.git",
"revision": "v1.3.208"
"revision": "v1.3.268"
}
},
{
"name": "volk",
"source": {
"type": "git",
"url": "https://github.com/zeux/volk.git",
"revision": "1.3.204"
"revision": "1.3.250"
}
},
{
Expand Down Expand Up @@ -52,7 +52,7 @@
"source": {
"type": "git",
"url": "https://github.com/ocornut/imgui.git",
"revision": "v1.87"
"revision": "v1.90.1"
}
},
{
Expand Down Expand Up @@ -166,5 +166,13 @@
"url": "https://github.com/jarro2783/cxxopts",
"revision": "v3.1.1"
}
},
{
"name": "fastgltf",
"source": {
"type": "git",
"url": "https://github.com/spnda/fastgltf",
"revision": "v0.6.1"
}
}
]
5 changes: 5 additions & 0 deletions Includes/VoxFlow/Core/Devices/LogicalDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ class LogicalDevice : NonCopyable
return _physicalDevice;
}

inline const Instance* getInstance() const
{
return _instance;
}

inline CommandJobSystem* getCommandJobSystem() const
{
return _commandJobSystem.get();
Expand Down
2 changes: 1 addition & 1 deletion Includes/VoxFlow/Core/Devices/RenderDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SceneRenderer;
class LogicalDevice;
class CommandJobSystem;
class SwapChain;
class ResourceUploadContext;

class RenderDevice final : private NonCopyable
{
Expand Down Expand Up @@ -70,7 +71,6 @@ class RenderDevice final : private NonCopyable
std::vector<std::unique_ptr<LogicalDevice>> _logicalDevices;
std::unique_ptr<SceneRenderer> _sceneRenderer;
Context* _deviceSetupCtx = nullptr;
RenderGraph::FrameGraph _frameGraph;
FrameContext _frameContext;
std::shared_ptr<SwapChain> _mainSwapChain;
CommandJobSystem* _mainCmdJobSystem = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <VoxFlow/Core/Graphics/Commands/CommandBuffer.hpp>
#include <VoxFlow/Core/Graphics/Commands/CommandJobSystem.hpp>
#include <VoxFlow/Core/Graphics/Pipelines/ResourceBindingLayout.hpp>
#include <VoxFlow/Core/Utils/Logger.hpp>
#include <type_traits>

namespace VoxFlow
Expand Down Expand Up @@ -60,45 +61,39 @@ void CommandStream::addJob(CommandJobType jobType, CommandJobArgs&&... args)
case CommandJobType::BindPipeline:
cmdBuffer->bindPipeline(params.getParam<BasePipeline*>(0));
break;

case CommandJobType::SetViewport:
cmdBuffer->setViewport(params.getParam<glm::uvec2>(0));
break;

case CommandJobType::BindResourceGroup:
cmdBuffer->bindResourceGroup(params.getParam<SetSlotCategory>(0), params.getParam<std::vector<ShaderVariableBinding>>(1));
break;

case CommandJobType::UploadBuffer:
cmdBuffer->uploadBuffer(params.getParam<Buffer*>(0), params.getParam<StagingBuffer*>(1), params.getParam<uint32_t>(2), params.getParam<uint32_t>(3),
params.getParam<uint32_t>(4));
break;

case CommandJobType::UploadTexture:
cmdBuffer->uploadTexture(params.getParam<Texture*>(0), params.getParam<StagingBuffer*>(1), params.getParam<uint32_t>(2),
params.getParam<uint32_t>(3), params.getParam<uint32_t>(4));
break;

case CommandJobType::Draw:
cmdBuffer->draw(params.getParam<uint32_t>(0), params.getParam<uint32_t>(1), params.getParam<uint32_t>(2), params.getParam<uint32_t>(3));
break;

case CommandJobType::DrawIndexed:
cmdBuffer->drawIndexed(params.getParam<uint32_t>(0), params.getParam<uint32_t>(1), params.getParam<uint32_t>(2), params.getParam<uint32_t>(3),
params.getParam<uint32_t>(4));
break;

case CommandJobType::MakeSwapChainFinalLayout:
cmdBuffer->makeSwapChainFinalLayout(params.getParam<SwapChain*>(0), params.getParam<uint32_t>(1));
break;

case CommandJobType::BindVertexBuffer:
cmdBuffer->bindVertexBuffer(params.getParam<Buffer*>(0));
break;

case CommandJobType::BindIndexBuffer:
cmdBuffer->bindIndexBuffer(params.getParam<Buffer*>(0));
break;
default:
VOX_ASSERT(false, "Unknown CommandJobType({})", static_cast<uint32_t>(jobType));
break;
}
}
} // namespace VoxFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CommandJobSystem final : private NonCopyable
explicit CommandJobSystem(LogicalDevice* logicalDevice);
~CommandJobSystem() override;

void createCommandStream(const CommandStreamKey& streamKey, Queue* queue);
CommandStream* createCommandStream(const CommandStreamKey& streamKey, Queue* queue);
CommandStream* getCommandStream(const CommandStreamKey& streamKey);

private:
Expand Down
4 changes: 2 additions & 2 deletions Includes/VoxFlow/Core/Renderer/SceneRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SwapChain;
class SceneRenderer final : NonCopyable
{
public:
SceneRenderer(LogicalDevice* mainLogicalDevice, RenderGraph::FrameGraph* frameGraph);
SceneRenderer(LogicalDevice* mainLogicalDevice);
~SceneRenderer() override;

public:
Expand All @@ -47,7 +47,7 @@ class SceneRenderer final : NonCopyable
protected:
private:
LogicalDevice* _mainLogicalDevice = nullptr;
RenderGraph::FrameGraph* _frameGraph = nullptr;
RenderGraph::FrameGraph _frameGraph;
FrameContext _currentFrameContext;
CommandJobSystem* _commandJobSystem = nullptr;
std::unique_ptr<RenderResourceAllocator> _renderResourceAllocator;
Expand Down
39 changes: 3 additions & 36 deletions Includes/VoxFlow/Core/Resources/RenderResourceGarbageCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,15 @@ namespace VoxFlow
{
struct RenderResourceGarbage
{
std::vector<FenceObject> _accessedFences;
std::function<void()> _deletionDelegate;

RenderResourceGarbage() = default;
RenderResourceGarbage(std::vector<FenceObject>&& accessedFences, std::function<void()>&& deletionDelegate)
: _accessedFences(std::move(accessedFences)), _deletionDelegate(std::move(deletionDelegate))
{
}
~RenderResourceGarbage() = default;
RenderResourceGarbage(const RenderResourceGarbage& rhs)
{
operator=(rhs);
}
RenderResourceGarbage(RenderResourceGarbage&& rhs)
{
operator=(std::move(rhs));
}
RenderResourceGarbage& operator=(const RenderResourceGarbage& rhs)
{
if (this != &rhs)
{
_accessedFences = rhs._accessedFences;
_deletionDelegate = rhs._deletionDelegate;
}
return *this;
}
RenderResourceGarbage& operator=(RenderResourceGarbage&& rhs)
{
if (this != &rhs)
{
_accessedFences.swap(rhs._accessedFences);
_deletionDelegate.swap(rhs._deletionDelegate);
}
return *this;
}
std::vector<FenceObject> accessedFences;
std::function<void()> deletionDelegate;
};

class RenderResourceGarbageCollector : private Thread
{
public:
// Push render resource garbage (buffer, texture, or etc..) to the queue
void pushRenderResourceGarbage(RenderResourceGarbage&& garbage);
void dispose(RenderResourceGarbage&& garbage);

// Get global instance of render resource garbage collector
static RenderResourceGarbageCollector& Get();
Expand Down
45 changes: 45 additions & 0 deletions Includes/VoxFlow/Core/Scene/Material.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Author : snowapril

#ifndef VOXEL_FLOW_MATERIAL_HPP
#define VOXEL_FLOW_MATERIAL_HPP

#include <VoxFlow/Core/Utils/NonCopyable.hpp>
#include <glm/vec4.hpp>
#include <memory>

namespace VoxFlow
{
class TextureView;

struct MaterialUniformBase
{
};

struct MaterialBaseColor : public MaterialUniformBase
{
float alphaCutOff = 0.0f;
glm::vec4 baseColorFactor;
TextureView* baseColorView = nullptr;

MaterialBaseColor(float alphaCutOff, glm::vec4 baseColorFactor, TextureView* baseColorView)
: alphaCutOff(alphaCutOff), baseColorFactor(baseColorFactor), baseColorView(baseColorView)
{

}
};

class Material : private NonCopyable
{
public:
Material(std::unique_ptr<MaterialUniformBase>&& materialUniform) : _materialUniform(std::move(materialUniform))
{
}
~Material() = default;

private:
std::unique_ptr<MaterialUniformBase> _materialUniform;
};

} // namespace VoxFlow

#endif
36 changes: 36 additions & 0 deletions Includes/VoxFlow/Core/Scene/SceneObject.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Author : snowapril

#ifndef VOXEL_FLOW_SCENE_OBJECT_HPP
#define VOXEL_FLOW_SCENE_OBJECT_HPP

#include <VoxFlow/Core/Utils/NonCopyable.hpp>
#include <cstdint>

namespace VoxFlow
{

enum class SceneObjectType : uint8_t
{
Opaque = 0,
Transparent = 1,
Undefined = 2,
Count = Undefined
};

class SceneObject : private NonCopyable
{
public:
[[nodiscard]] inline SceneObjectType getType() const
{
return _type;
}

private:
// primitive buffer
// material ...
SceneObjectType _type;
};

} // namespace VoxFlow

#endif
29 changes: 29 additions & 0 deletions Includes/VoxFlow/Core/Scene/SceneObjectCollection.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Author : snowapril

#ifndef VOXEL_FLOW_SCENE_OBJECT_COLLECTION_HPP
#define VOXEL_FLOW_SCENE_OBJECT_COLLECTION_HPP

#include <VoxFlow/Core/Scene/SceneObject.hpp>
#include <array>
#include <vector>
#include <memory>

namespace VoxFlow
{

class SceneObject;

class SceneObjectCollection
{
public:
SceneObjectCollection() = default;
~SceneObjectCollection() = default;

private:
SceneObjectType _sceneObjectType;
std::vector<std::unique_ptr<SceneObject>> _sceneObjects;
};

} // namespace VoxFlow

#endif
44 changes: 44 additions & 0 deletions Includes/VoxFlow/Core/Scene/SceneObjectLoader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Author : snowapril

#ifndef VOXEL_FLOW_SCENE_OBJECT_LOADER_HPP
#define VOXEL_FLOW_SCENE_OBJECT_LOADER_HPP

#include <filesystem>
#include <glm/vec2.hpp>

namespace VoxFlow
{

class SceneObjectCollection;
class Texture;
class CommandStream;
class ResourceUploadContext;

struct StaticMeshInfo
{

};

struct TextureUploadInfo
{
Texture* uploadDstTexture = nullptr;
void* textureRawData = nullptr;
glm::vec2 extent;
int numChannels;
size_t numBytes;
};

class SceneObjectLoader
{
public:
SceneObjectLoader() = default;
~SceneObjectLoader() = default;

// Blocking
bool loadSceneObject(const std::filesystem::path& gltfPath, ResourceUploadContext* asyncUploadContext, CommandStream* asyncCmdStream,
SceneObjectCollection* outCollection);
};

} // namespace VoxFlow

#endif
Loading