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
39 changes: 39 additions & 0 deletions EppoEngine/Source/Platform/ComPtr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

// clang-format off
#if defined(EP_PLATFORM_WINDOWS)
#include <wrl/client.h>
template<typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
#else
#include <dxc/WinAdapter.h>
template<typename T>
class ComPtr : public CComPtr<T>
{
using Base = CComPtr<T>;
public:
using Base::Base;
using Base::operator=;

ComPtr() noexcept = default;

T* Get() const noexcept { return this->p; }

T* const* GetAddressOf() const noexcept { return &this->p; }
T** GetAddressOf() noexcept
{
assert(this->p == nullptr);
return &this->p;
}

T** ReleaseAndGetAddressOf() noexcept
{
this->Release();
return &this->p;
}

void Reset() noexcept { this->Release(); }
explicit operator bool() const noexcept { return this->p != nullptr; }
};
#endif
// clang-format on
29 changes: 14 additions & 15 deletions EppoEngine/Source/Platform/Vulkan/DeviceManagerVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,12 @@ namespace Eppo
m_LogicalDevice = nullptr;
m_PhysicalDevice = nullptr;

if (g_EnableValidationLayers)
if (s_EnableValidationLayers)
DestroyDebugUtilsMessengerEXT(m_Instance, m_DebugMessenger, nullptr);

vkDestroyInstance(m_Instance, nullptr);
}

auto DeviceManagerVK::GetDevice() const -> nvrhi::IDevice*
{
if (m_ValidationLayer)
return m_ValidationLayer;

return m_Device;
}

auto DeviceManagerVK::BeginFrame() -> bool
{
return m_Swapchain->BeginFrame();
Expand All @@ -66,6 +58,14 @@ namespace Eppo
return m_Swapchain->Present();
}

auto DeviceManagerVK::GetDevice() const -> nvrhi::IDevice*
{
if (m_ValidationLayer)
return m_ValidationLayer;

return m_Device;
}

auto DeviceManagerVK::CreateVulkanInstance() -> void
{
// Create instance
Expand All @@ -84,9 +84,8 @@ namespace Eppo

const std::vector extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);

#if !defined(EP_DIST)
m_Params.RequiredVulkanInstanceExtensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif
if (s_EnableValidationLayers)
m_Params.RequiredVulkanInstanceExtensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);

for (const auto& extension : extensions)
m_Params.RequiredVulkanInstanceExtensions.emplace_back(extension);
Expand All @@ -106,7 +105,7 @@ namespace Eppo
};

VkDebugUtilsMessengerCreateInfoEXT debugMessengerInfo{};
if (g_EnableValidationLayers)
if (s_EnableValidationLayers)
{
instanceInfo.enabledLayerCount = static_cast<uint32_t>(g_ValidationLayers.size());
instanceInfo.ppEnabledLayerNames = g_ValidationLayers.data();
Expand All @@ -127,7 +126,7 @@ namespace Eppo
VK_CHECK(vkCreateInstance(&instanceInfo, nullptr, &m_Instance), "Failed to create vulkan instance!");
EP_ASSERT(m_Instance);

if (g_EnableValidationLayers)
if (s_EnableValidationLayers)
{
VK_CHECK(
CreateDebugUtilsMessengerEXT(m_Instance, &debugMessengerInfo, nullptr, &m_DebugMessenger),
Expand Down Expand Up @@ -162,7 +161,7 @@ namespace Eppo

m_Device = nvrhi::vulkan::createDevice(deviceDesc);

if (g_EnableValidationLayers)
if (s_EnableValidationLayers)
m_ValidationLayer = nvrhi::validation::createValidationLayer(m_Device);
}
}
5 changes: 2 additions & 3 deletions EppoEngine/Source/Platform/Vulkan/DeviceManagerVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ namespace Eppo
class DeviceManagerVK : public DeviceManager
{
public:
DeviceManagerVK(const Ref<Window>& window, const DeviceParams& params);
explicit DeviceManagerVK(const Ref<Window>& window, const DeviceParams& params);
~DeviceManagerVK() override = default;

auto Init() -> void override;
auto Shutdown() -> void override;

[[nodiscard]] auto GetDevice() const -> nvrhi::IDevice* override;

auto BeginFrame() -> bool override;
auto Present() -> bool override;

Expand All @@ -31,6 +29,7 @@ namespace Eppo
[[nodiscard]] auto GetCurrentBackBufferIndex() const -> uint32_t override { return m_Swapchain->GetCurrentBackBufferIndex(); }
[[nodiscard]] auto GetBackBufferCount() const -> uint32_t override { return m_Swapchain->GetImageCount(); }
auto GetCurrentSwapchainImage() -> const SwapchainImage& override { return m_Swapchain->GetCurrentSwapchainImage(); }
[[nodiscard]] auto GetDevice() const -> nvrhi::IDevice* override;

[[nodiscard]] constexpr auto GetVulkanInstance() const -> VkInstance { return m_Instance; }
[[nodiscard]] constexpr auto GetPhysicalDevice() const -> const ScopedPtr<PhysicalDevice>& { return m_PhysicalDevice; }
Expand Down
4 changes: 3 additions & 1 deletion EppoEngine/Source/Platform/Vulkan/LogicalDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "pch.h"
#include "Platform/Vulkan/LogicalDevice.h"

#include "Renderer/DeviceManager.h"

namespace Eppo
{
LogicalDevice::LogicalDevice(const ScopedPtr<PhysicalDevice>& physicalDevice)
Expand Down Expand Up @@ -89,7 +91,7 @@ namespace Eppo
.ppEnabledExtensionNames = g_DeviceExtensions.data(),
};

if (g_EnableValidationLayers)
if (s_EnableValidationLayers)
{
deviceInfo.enabledLayerCount = static_cast<uint32_t>(g_ValidationLayers.size());
deviceInfo.ppEnabledLayerNames = g_ValidationLayers.data();
Expand Down
6 changes: 0 additions & 6 deletions EppoEngine/Source/Platform/Vulkan/Vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Eppo
if (fn != VK_SUCCESS) \
Log::Error(LogSource::Vulkan, msg);

#if !defined(EP_DIST)
constexpr bool g_EnableValidationLayers = true;
#else
constexpr bool g_EnableValidationLayers = false;
#endif

constexpr std::array g_ValidationLayers = { "VK_LAYER_KHRONOS_validation" };
constexpr std::array g_DeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_MAINTENANCE_1_EXTENSION_NAME,
VK_GOOGLE_HLSL_FUNCTIONALITY_1_EXTENSION_NAME, VK_GOOGLE_USER_TYPE_EXTENSION_NAME,
Expand Down
28 changes: 11 additions & 17 deletions EppoEngine/Source/Platform/Vulkan/VulkanShader.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#include "pch.h"
#include "Platform/Vulkan/VulkanShader.h"

#include "Platform/ComPtr.h"
#include "Renderer/DeviceManager.h"

#if defined(EP_PLATFORM_WINDOWS)
#include <atlbase.h>
#else
#include <dxc/WinAdapter.h>
#endif

#include <dxc/dxcapi.h>

#include <ranges>
#include <nvrhi/utils.h>
#include <spirv_cross/spirv_cross.hpp>

Expand Down Expand Up @@ -74,7 +68,7 @@ namespace Eppo
return E_FAIL;
}

CComPtr<IDxcBlobEncoding> blob;
ComPtr<IDxcBlobEncoding> blob;
if (FAILED(m_Utils->CreateBlob(source->data(), static_cast<uint32_t>(source->size()), DXC_CP_UTF8, &blob)))
return E_FAIL;

Expand Down Expand Up @@ -298,8 +292,8 @@ namespace Eppo
auto VulkanShader::Compile(const nvrhi::ShaderType type) -> bool
{
// Create compiler
CComPtr<IDxcUtils> utils;
CComPtr<IDxcCompiler3> compiler;
ComPtr<IDxcUtils> utils;
ComPtr<IDxcCompiler3> compiler;
if (FAILED(DxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&utils))) ||
FAILED(DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&compiler))))
{
Expand All @@ -310,11 +304,11 @@ namespace Eppo
// Create include handler. A packed shader gets the pack-backed one and never the default:
// the default reads from disk, which a deployed game has none of.
const bool packed = !m_Specification.Source.empty();
PackedIncludeHandler packedIncludeHandler(utils, m_Specification.Includes);
CComPtr<IDxcIncludeHandler> diskIncludeHandler;
PackedIncludeHandler packedIncludeHandler(utils.Get(), m_Specification.Includes);
ComPtr<IDxcIncludeHandler> diskIncludeHandler;
if (!packed)
utils->CreateDefaultIncludeHandler(&diskIncludeHandler);
IDxcIncludeHandler* includeHandler = packed ? static_cast<IDxcIncludeHandler*>(&packedIncludeHandler) : diskIncludeHandler.p;
IDxcIncludeHandler* includeHandler = packed ? static_cast<IDxcIncludeHandler*>(&packedIncludeHandler) : diskIncludeHandler.Get();

// Command line args for compiler. A packed shader is named relative to the virtual Resources/Shaders
// root, so DXC hands its #include paths to the handler the way the pack keys them.
Expand Down Expand Up @@ -365,14 +359,14 @@ namespace Eppo
};

// Execute compiler
CComPtr<IDxcResult> result;
ComPtr<IDxcResult> result;
if (FAILED(compiler->Compile(&srcBuffer, args, _countof(args), includeHandler, IID_PPV_ARGS(&result))) || !result)
{
Log::Error("Invoking the compiler for shader '{}' failed!", m_Specification.Name);
return false;
}

CComPtr<IDxcBlobUtf8> errors = nullptr;
ComPtr<IDxcBlobUtf8> errors;
result->GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&errors), nullptr);

if (errors != nullptr && errors->GetStringLength() != 0)
Expand All @@ -389,8 +383,8 @@ namespace Eppo
}

// Save shader binary
CComPtr<IDxcBlob> binary = nullptr;
CComPtr<IDxcBlobWide> binaryName = nullptr;
ComPtr<IDxcBlob> binary;
ComPtr<IDxcBlobWide> binaryName;
result->GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&binary), &binaryName);

if (binary == nullptr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "Renderer/IndexBuffer.h"
#include "Renderer/Buffer/IndexBuffer.h"

#include "Renderer/DeviceManager.h"
#include "Renderer/Mesh.h"
Expand Down Expand Up @@ -240,4 +240,4 @@ namespace Eppo
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "Renderer/StorageBuffer.h"
#include "Renderer/Buffer/StorageBuffer.h"

#include "Renderer/DeviceManager.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "Renderer/UniformBuffer.h"
#include "Renderer/Buffer/UniformBuffer.h"

#include "Renderer/DeviceManager.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "pch.h"
#include "Renderer/VertexBuffer.h"
#include "Renderer/Buffer/VertexBuffer.h"

#include "Renderer/DeviceManager.h"
#include "Renderer/Mesh.h"
Expand Down Expand Up @@ -328,4 +328,4 @@ namespace Eppo
}
}
}
}
}
4 changes: 2 additions & 2 deletions EppoEngine/Source/Renderer/DescriptorManager.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include "Renderer/Buffer/StorageBuffer.h"
#include "Renderer/Buffer/UniformBuffer.h"
#include "Renderer/DeviceManager.h"
#include "Renderer/Image.h"
#include "Renderer/StorageBuffer.h"
#include "Renderer/UniformBuffer.h"

#include <nvrhi/nvrhi.h>

Expand Down
7 changes: 0 additions & 7 deletions EppoEngine/Source/Renderer/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@ namespace Eppo
{
EP_ASSERT(params.API != RendererAPI::None, "No renderer api selected!");
#if !defined(EP_PLATFORM_WINDOWS)
EP_ASSERT(params.API != RendererAPI::DX11, "DX11 renderer api selected on a non windows target!");
EP_ASSERT(params.API != RendererAPI::DX12, "DX12 renderer api selected on a non windows target!");
#endif
EP_ASSERT(params.MaxFramesInFlight >= 2);

switch (params.API)
{
#if defined(EP_PLATFORM_WINDOWS)
case RendererAPI::DX11:
{
EP_ASSERT(false, "Currently we do not support DX11!");
break;
}

case RendererAPI::DX12:
{
EP_ASSERT(false, "Currently we do not support DX12!");
Expand Down
7 changes: 6 additions & 1 deletion EppoEngine/Source/Renderer/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ namespace Eppo
{
class DeviceManagerVK;

#if !defined(EP_DIST)
constexpr bool s_EnableValidationLayers = true;
#else
constexpr bool s_EnableValidationLayers = false;
#endif

enum class RendererAPI
{
None,
DX11,
DX12,
Vulkan,
};
Expand Down
4 changes: 2 additions & 2 deletions EppoEngine/Source/Renderer/Mesh.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "Asset/Asset.h"
#include "Renderer/Buffer/IndexBuffer.h"
#include "Renderer/Buffer/VertexBuffer.h"
#include "Renderer/Image.h"
#include "Renderer/IndexBuffer.h"
#include "Renderer/Material.h"
#include "Renderer/Sampler.h"
#include "Renderer/VertexBuffer.h"

#include <glm/glm.hpp>

Expand Down
4 changes: 2 additions & 2 deletions EppoEngine/Source/Renderer/RenderPass.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "pch.h"
#include "Renderer/RenderPass.h"

#include "Renderer/Buffer/StorageBuffer.h"
#include "Renderer/Buffer/UniformBuffer.h"
#include "Renderer/DescriptorManager.h"
#include "Renderer/DeviceManager.h"
#include "Renderer/Image.h"
#include "Renderer/Renderer.h"
#include "Renderer/Sampler.h"
#include "Renderer/StorageBuffer.h"
#include "Renderer/UniformBuffer.h"

namespace Eppo
{
Expand Down
4 changes: 2 additions & 2 deletions EppoEngine/Source/Renderer/SceneRenderer.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include "Renderer/Buffer/StorageBuffer.h"
#include "Renderer/Buffer/UniformBuffer.h"
#include "Renderer/Camera/EditorCamera.h"
#include "Renderer/Camera/SceneCamera.h"
#include "Renderer/Mesh.h"
#include "Renderer/RenderCommandBuffer.h"
#include "Renderer/RenderPass.h"
#include "Renderer/Sampler.h"
#include "Renderer/StorageBuffer.h"
#include "Renderer/UniformBuffer.h"
#include "Scene/Entity.h"
#include "Scene/Scene.h"

Expand Down
Loading
Loading