Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
#include "Runtime/Renderer/Core/Scene/SceneView.h"
#include "Runtime/Renderer/Deferred/DeferredRenderer.h"

namespace tf
{
class Executor;
}

namespace krendrr::Runtime::Application::Core
{
class Window;
Expand Down Expand Up @@ -55,6 +50,8 @@ namespace krendrr::Examples::SimpleDeferredRendering

bool InitializeSceneViewAndCamera();

bool FillRenderTaskflow(tf::Taskflow& Taskflow);

};
}

Expand Down
68 changes: 53 additions & 15 deletions Source/Examples/DeferredRendering/Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include "Runtime/Application/Core/Window.h"
#include "Runtime/ModelLoader/Loader.h"
#include "Runtime/RenderApi/Core/RenderApi.h"
#include "Runtime/Renderer/Core/Lights/PointLight.h"
#include "Runtime/Renderer/Core/Scene/Lights/PointLight.h"
#include "Runtime/Renderer/Core/Scene/Scene.h"
#include "Runtime/TfExecutorBuilder/TaskFailedException.h"
#include "Runtime/TfExecutorBuilder/TfExecutorBuilder.h"

IMPLEMENT_ENTRY_POINT(krendrr::Examples::SimpleDeferredRendering::Application)
Expand All @@ -31,8 +32,8 @@ bool krendrr::Examples::SimpleDeferredRendering::Application::Initialize(const R
const bool bRenderApiInitResult = RenderApi->Initialize({
.Debug = Runtime::RenderApi::Core::RenderApi::InitParams::Debug::DebugLayerWithGpuBasedValidation,
.bEnableShadersDebug = true
//.Debug = Runtime::RenderApi::Core::RenderApi::InitParams::Debug::None,
//.bEnableShadersDebug = false
// .Debug = Runtime::RenderApi::Core::RenderApi::InitParams::Debug::None,
// .bEnableShadersDebug = false
});

if (!bRenderApiInitResult)
Expand Down Expand Up @@ -86,7 +87,7 @@ bool krendrr::Examples::SimpleDeferredRendering::Application::Initialize(const R
SetupSponzaScene();

Renderer = std::make_unique<Runtime::Renderer::Deferred::DeferredRenderer>();
if (!Renderer->Initialize(RenderApi, TfExecutor, Scene))
if (!Renderer->Initialize(RenderApi, TfExecutor))
{
// TODO: log error
return false;
Expand All @@ -102,11 +103,55 @@ bool krendrr::Examples::SimpleDeferredRendering::Application::Tick(float DeltaTi
static std::size_t FpsDisplayCounter = 0;
FpsDisplayCounter++;
if (FpsDisplayCounter % 100 == 0)
{
FpsDisplayCounter = 0;
std::cout << "Delta: " << DeltaTime << " FPS: " << 1.f / DeltaTime << std::endl;
}
}

Camera.Update(DeltaTime);

tf::Taskflow MainTaskFlow {};

tf::Taskflow RenderTaskFlow {};
if (!FillRenderTaskflow(RenderTaskFlow))
return false;

tf::Task RendererTickTask = MainTaskFlow
.composed_of(RenderTaskFlow)
.name("Renderer Tick Task");

tf::Task SwapTask = MainTaskFlow.emplace(
[&]()
{
if (!Window->Swap())
{
// TODO: add error log
Runtime::TaskFlowEx::CancelCurrentTaskflow();
}
}
).name("Window Swap Task");

// Allow render tick task to go straight to end task in case of an error
RendererTickTask.precede(SwapTask);

try
{
TfExecutor->run(MainTaskFlow).wait();
}
catch (const Runtime::TaskFlowEx::TaskFailedException&)
{
// TODO: add error log "Application tick failed. Taskflow task failed."
return false;
}

return true;
}

bool krendrr::Examples::SimpleDeferredRendering::Application::FillRenderTaskflow(tf::Taskflow& Taskflow)
{
const glm::ivec2 WindowSize = Window->GetSize();
Runtime::Application::Core::Window::WindowRenderData RenderData = Window->GetCurrentRenderTargetView();
const Runtime::Application::Core::Window::WindowRenderData RenderData = Window->GetCurrentRenderTargetView();

const bool bRenderDataSetSuccess = SceneView.SetRenderData(
{
Expand All @@ -124,20 +169,14 @@ bool krendrr::Examples::SimpleDeferredRendering::Application::Tick(float DeltaTi
if (!bRenderDataSetSuccess)
return false;

Camera.Update(DeltaTime);

std::array Views = {
SceneView
};
if (!Renderer->Render(Views))
{
// TODO: add error log
return false;
}

if (!Window->Swap())
if (!Renderer->Render(Scene.get(), Views, Taskflow))
{
// TODO: add error log

return false;
}

Expand Down Expand Up @@ -191,8 +230,7 @@ void krendrr::Examples::SimpleDeferredRendering::Application::SetupSponzaScene()

auto PointLight1 = Scene->SpawnPointLight();
PointLight1->SetPosition({1000, 250, 0});
PointLight1->SetColor({1.f, 0.3f, 0.3f});
PointLight1->SetCastsShadows(false);
PointLight1->SetColor({1.f, 1.f, 1.f});

auto PointLight2 = Scene->SpawnPointLight();
PointLight2->SetPosition({-1100, 250, 0});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string_view>
#include <vector>
#include "Runtime/RenderApi/Core/RenderApi.h"
#include "Runtime/Renderer/Core/TexturedMesh/TexturedMesh.h"
#include "Runtime/Renderer/Core/Scene/Objects/TexturedStaticMesh.h"
#include "taskflow/taskflow.hpp"

namespace krendrr::Runtime::ModelLoader
Expand Down Expand Up @@ -33,7 +33,7 @@ namespace krendrr::Runtime::ModelLoader
struct LoadResult
{
bool bSuccess {};
std::vector<std::shared_ptr<Renderer::Core::TexturedMesh>> TexturedMeshes {};
std::vector<std::shared_ptr<Renderer::Core::TexturedStaticMesh>> TexturedMeshes {};

[[nodiscard]] bool HasLoadedAtLeastOne() const
{
Expand Down
20 changes: 10 additions & 10 deletions Source/Runtime/ModelLoader/Source/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include <glm/vec2.hpp>
#include "Runtime/MipMapsGenerator/Generator.h"
#include "Runtime/RenderApi/Core/ApiCallCheck.h"
#include "Runtime/Renderer/Core/TexturedMesh/Mesh.h"
#include "Runtime/Renderer/Core/TexturedMesh/Texture.h"
#include "Runtime/RenderApi/Core/Resources/StaticMesh.h"
#include "Runtime/RenderApi/Core/Resources/Texture2D.h"

namespace krendrr::Runtime::ModelLoader
{
// a bunch of data shared between thread pool jobs
struct LoadData
{
std::unordered_map<std::string, std::shared_ptr<Renderer::Core::Texture>> TextureCache {};
std::unordered_map<std::string, std::shared_ptr<RenderApi::Core::Texture2D>> TextureCache {};
std::vector<MipMapsGenerator::Generator::TextureToProcess> TexturesToGenerateMipMaps {};
std::mutex TextureCacheMutex {};

Expand Down Expand Up @@ -155,7 +155,7 @@ namespace krendrr::Runtime::ModelLoader
return;

// Create final object
std::shared_ptr<Renderer::Core::TexturedMesh> NewTexturedMesh = std::make_shared<Renderer::Core::TexturedMesh>();
std::shared_ptr<Renderer::Core::TexturedStaticMesh> NewTexturedMesh = std::make_shared<Renderer::Core::TexturedStaticMesh>();

NewTexturedMesh->SetMeshColor(glm::vec3{
static_cast<double>(rand()) / (RAND_MAX + 1.0),
Expand Down Expand Up @@ -184,10 +184,10 @@ namespace krendrr::Runtime::ModelLoader

// Create Mesh
{
std::shared_ptr<Renderer::Core::Mesh> NewMesh = std::make_shared<Renderer::Core::Mesh>();
std::shared_ptr<RenderApi::Core::StaticMesh> NewMesh = std::make_shared<RenderApi::Core::StaticMesh>();
NewTexturedMesh->AssignMesh(NewMesh);

Renderer::Core::Mesh::MeshLoadOperation MeshLoadOperation = NewMesh->LoadIndexed(
RenderApi::Core::StaticMesh::MeshLoadOperation MeshLoadOperation = NewMesh->LoadIndexed(
RenderApi, *NewCommandList.Get(), RenderApi::Core::RenderApi::ContainerToBytes(Vertices), Indices);

if (!MeshLoadOperation.WasSuccessful())
Expand All @@ -214,7 +214,7 @@ namespace krendrr::Runtime::ModelLoader
return;

const aiMaterial* Material = Scene->mMaterials[Mesh->mMaterialIndex];
auto LoadTexture = [&](aiTextureType Type, Renderer::Core::TexturedMesh& TargetMesh, const std::string_view& TextureName) -> bool
auto LoadTexture = [&](aiTextureType Type, Renderer::Core::TexturedStaticMesh& TargetMesh, const std::string_view& TextureName) -> bool
{
if(Material->GetTextureCount(Type) > 0)
{
Expand All @@ -225,7 +225,7 @@ namespace krendrr::Runtime::ModelLoader
TexturePath.append("/");
TexturePath.append(RelativeTexturePath.C_Str());

std::shared_ptr<Renderer::Core::Texture> Texture {};
std::shared_ptr<RenderApi::Core::Texture2D> Texture {};

std::unique_lock TextureCacheLock(LoadData.TextureCacheMutex);

Expand All @@ -238,9 +238,9 @@ namespace krendrr::Runtime::ModelLoader
// Since texture loading may take a while, do not keep the mutex ownership
TextureCacheLock.unlock();

Texture = std::make_shared<Renderer::Core::Texture>();
Texture = std::make_shared<RenderApi::Core::Texture2D>();

const Renderer::Core::Texture::TextureLoadOperation TextureLoadOperation = Texture->Load(RenderApi, *NewCommandList.Get(), TexturePath);
const RenderApi::Core::Texture2D::TextureLoadOperation TextureLoadOperation = Texture->Load(RenderApi, *NewCommandList.Get(), TexturePath);

if (!TextureLoadOperation.WasSuccessful())
{
Expand Down
2 changes: 2 additions & 0 deletions Source/Runtime/RenderApi/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ add_krendrr_target(STATIC RenderAPI TARGET_NAME)

target_link_libraries(${TARGET_NAME} PUBLIC
krendrr::thirdparty::directx12
krendrr::thirdparty::glm
krendrr::thirdparty::stb_image
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__debugbreak(); \
return {}; \
} \
} \
}

/**
* Checks if api call was successful. returns false or default value if false
Expand All @@ -25,7 +25,7 @@
__debugbreak(); \
return {}; \
} \
} \
}

// TODO: add error log
/**
Expand All @@ -38,7 +38,7 @@
__debugbreak(); \
return; \
} \
} \
}

/**
* Checks if api call was successful. Returns if not
Expand All @@ -50,4 +50,4 @@
__debugbreak(); \
return; \
} \
} \
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
#include "Runtime/RenderApi/Core/RenderApi.h"
#include "d3dx12/d3dx12.h"

namespace krendrr::Runtime::Renderer::Core
namespace krendrr::Runtime::RenderApi::Core
{
class Mesh
class StaticMesh
{
public:

Mesh() = default;
Mesh(const Mesh& Other) = delete;
Mesh& operator=(const Mesh& Other) = delete;
Mesh(Mesh&& Other) noexcept = default;
Mesh& operator=(Mesh&& Other) noexcept = default;
~Mesh() = default;
StaticMesh() = default;
StaticMesh(const StaticMesh& Other) = delete;
StaticMesh& operator=(const StaticMesh& Other) = delete;
StaticMesh(StaticMesh&& Other) noexcept = default;
StaticMesh& operator=(StaticMesh&& Other) noexcept = default;
~StaticMesh() = default;

struct MeshLoadOperation
{
Expand All @@ -34,13 +34,13 @@ namespace krendrr::Runtime::Renderer::Core
* Creates upload heaps and fills provided command list with copy operations.
* Caller need to execute the command list and keep upload buffers alive while copy is not finished.
*/
MeshLoadOperation Load(const RenderApi::Core::RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList, const std::span<const std::byte>& VertexData);
MeshLoadOperation Load(const RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList, const std::span<const std::byte>& VertexData);

/**
* Creates upload heaps and fills provided command list with copy operations.
* Caller need to execute the command list and keep upload buffers alive while copy is not finished.
*/
MeshLoadOperation LoadIndexed(const RenderApi::Core::RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
MeshLoadOperation LoadIndexed(const RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
const std::span<const std::byte>& VertexData, const std::span<const std::uint32_t>& IndexData);

/**
Expand All @@ -67,7 +67,7 @@ namespace krendrr::Runtime::Renderer::Core

[[nodiscard]] bool CheckLoaded() const;

Microsoft::WRL::ComPtr<ID3D12Resource> LoadVertexBuffer(const RenderApi::Core::RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
Microsoft::WRL::ComPtr<ID3D12Resource> LoadVertexBuffer(const RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
const std::span<const std::byte>& VertexData);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
#include <string_view>
#include <wrl/client.h>
#include <d3dx12/d3dx12.h>

#include "glm/vec2.hpp"
#include "Runtime/RenderApi/Core/RenderApi.h"

namespace krendrr::Runtime::Renderer::Core
namespace krendrr::Runtime::RenderApi::Core
{
class Texture
class Texture2D
{
public:

Texture() = default;
Texture(const Texture& Other) = delete;
Texture& operator=(const Texture& Other) = delete;
Texture(Texture&& Other) noexcept = default;
Texture& operator=(Texture&& Other) noexcept = default;
~Texture() = default;
Texture2D() = default;
Texture2D(const Texture2D& Other) = delete;
Texture2D& operator=(const Texture2D& Other) = delete;
Texture2D(Texture2D&& Other) noexcept = default;
Texture2D& operator=(Texture2D&& Other) noexcept = default;
~Texture2D() = default;

struct TextureLoadParams
{
Expand Down Expand Up @@ -53,7 +52,7 @@ namespace krendrr::Runtime::Renderer::Core
* Creates upload heaps and fills provided command list with copy operations.
* Caller need to execute the command list and keep upload buffers alive while copy is not finished.
*/
TextureLoadOperation Load(const RenderApi::Core::RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
TextureLoadOperation Load(const RenderApi& RenderApi, ID3D12GraphicsCommandList& CommandList,
const std::string_view& TextureFileName, const TextureLoadParams& Params = TextureLoadParams::Default());

D3D12_CPU_DESCRIPTOR_HANDLE GetTextureHandle() const;
Expand Down
Loading