Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering pipeline #33

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
64bed93
Begin the process of building the rendering pipeline
Rinzii Jul 14, 2023
a084e08
Clean up the cmake and add NDEBUG
Rinzii Jul 14, 2023
008b0ed
Added some logging
Rinzii Jul 14, 2023
db607d8
Merge branch 'main' into vk
Rinzii Jul 15, 2023
8770fb3
more work being done
Rinzii Jul 15, 2023
a63a314
Merge remote-tracking branch 'origin/main' into vk
Rinzii Jul 16, 2023
fcdce75
add devices
Rinzii Jul 17, 2023
1801250
remove hashing. Not yet ready for it.
Rinzii Jul 17, 2023
042aa93
more work to go
Rinzii Jul 18, 2023
d24ef94
add more helpers and build further on device
Rinzii Jul 18, 2023
85be9a0
Merge remote-tracking branch 'origin/main' into vk
Rinzii Aug 2, 2023
42b9a54
Add the ability for logging to be disabled when GEN_NDEBUG is defined
Rinzii Aug 2, 2023
bd938b4
Removed for more explicit route
Rinzii Aug 2, 2023
89bf599
Add common mathematical constants to hlsl
Rinzii Aug 2, 2023
86d1e1b
Minor cleaning on main
Rinzii Aug 2, 2023
394e6ce
Add more of the rendering pipeline
Rinzii Aug 2, 2023
19db378
get rid of merge conflicts build script
Rinzii Aug 2, 2023
cb8c71b
Merge remote-tracking branch 'origin/main' into vk
Rinzii Aug 2, 2023
6172b0e
Merge pull request #35 from Rinzii/main
Rinzii Aug 2, 2023
c8ef864
Merge remote-tracking branch 'origin/vk' into vk
Rinzii Aug 2, 2023
708f270
Remove old headers
Rinzii Aug 2, 2023
57013eb
Update vulkan hpp to 1.3.260
Rinzii Aug 2, 2023
53fe1d2
Refresh
Rinzii Aug 2, 2023
7f25ce0
Disable logging if we are in release
Rinzii Aug 3, 2023
23142cb
Disable logging if we are in release
Rinzii Aug 3, 2023
4bbb328
add some of the starting bits of the pipeline
Rinzii Aug 3, 2023
454c7a5
Fix small typo
Rinzii Aug 3, 2023
a13d01e
First layout of instance creation
Rinzii Aug 3, 2023
cbab7ba
Merge branch 'main' into vk
Rinzii Aug 3, 2023
b6da942
Need to pull this
Rinzii Aug 4, 2023
6c7303d
Merge remote-tracking branch 'origin/vk' into vk
Rinzii Aug 4, 2023
8e80e62
Vulkan instance creation (#37)
Rinzii Aug 9, 2023
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
3 changes: 3 additions & 0 deletions editor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include <logger/log.hpp>

int main() {
// We don't want to initialize the logger in release mode.
Rinzii marked this conversation as resolved.
Show resolved Hide resolved
#ifndef GEN_NDEBUG
auto logger = gen::logger::Instance{}; // Required to initialize the logger
#endif

gen::Application app;

Expand Down
5 changes: 3 additions & 2 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ add_library(genesis::lib ALIAS genesis)

target_compile_definitions(genesis
PUBLIC
$<$<CONFIG:Debug>:GENESIS_DEBUG>
$<$<CONFIG:Release>:GENESIS_NDEBUG>
$<$<CONFIG:Debug>:GEN_DEBUG>
$<$<CONFIG:RelWithDebInfo>:GEN_DEBUG>
$<$<CONFIG:Release>:GEN_NDEBUG>
)

if (GENESIS_ENABLE_SIMD)
Expand Down
28 changes: 14 additions & 14 deletions engine/include/graphics/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace gen
GraphicsDevice& operator=(GraphicsDevice&&) = delete;


#if defined(NDEBUG) || defined(GEN_NDEBUG)
#if defined(GEN_NDEBUG)
static constexpr bool enableValidationLayers = false;
#else
static constexpr bool enableValidationLayers = true;
Expand Down Expand Up @@ -98,19 +98,19 @@ namespace gen
std::vector<std::string> const & extensions,
u32 const & apiVersion
);
/*
void createDebugMessenger();
void createSurface();
void pickPhysicalDevice();
void createLogicalDevice();
void createCommandPool();

bool isDeviceSuitable(vk::PhysicalDevice device);
QueueFamilyIndices findQueueFamilies(vk::PhysicalDevice device);
bool checkDeviceExtensionSupport(vk::PhysicalDevice device);
SwapChainSupportDetails querySwapChainSupport(vk::PhysicalDevice device);
//void createDebugMessenger();
//void createSurface();
//void pickPhysicalDevice();
//void createLogicalDevice();
//void createCommandPool();
Rinzii marked this conversation as resolved.
Show resolved Hide resolved

//bool isDeviceSuitable(const vk::PhysicalDevice & device);
//QueueFamilyIndices findQueueFamilies(vk::PhysicalDevice device);
//bool checkDeviceExtensionSupport(vk::PhysicalDevice device);
//SwapChainSupportDetails querySwapChainSupport(vk::PhysicalDevice device);


*/

vk::Instance m_instance;
vk::DebugUtilsMessengerEXT m_debugMessenger;
Expand All @@ -126,8 +126,8 @@ namespace gen

Window &m_window; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
Rinzii marked this conversation as resolved.
Show resolved Hide resolved

const std::vector<const char *> validationLayers = {"VK_LAYER_KHRONOS_validation"};
const std::vector<const char *> deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
const std::vector<std::string> validationLayers = {"VK_LAYER_KHRONOS_validation"};
const std::vector<std::string> deviceExtensions = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
Rinzii marked this conversation as resolved.
Show resolved Hide resolved


};
Expand Down
8 changes: 4 additions & 4 deletions engine/include/graphics/vkHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( VkDebugUtilsMessageS
void * /*pUserData*/ );

std::vector<char const*> gatherExtensions(std::vector<std::string> const& extensions
#if !defined(NDEBUG) || !defined(GEN_NDEBUG)
#ifndef GEN_NDEBUG
,
std::vector<vk::ExtensionProperties> const& extensionProperties
#endif
);

std::vector<char const*> gatherLayers(std::vector<std::string> const& layers
#if !defined(NDEBUG) || !defined(GEN_NDEBUG)
#ifndef GEN_NDEBUG
,
std::vector<vk::LayerProperties> const& layerProperties
#endif
);

#if defined(NDEBUG) || defined(GEN_NDEBUG)
#ifdef GEN_NDEBUG
vk::StructureChain<vk::InstanceCreateInfo>
#else
vk::StructureChain<vk::InstanceCreateInfo, vk::DebugUtilsMessengerCreateInfoEXT>
Expand All @@ -45,7 +45,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugUtilsMessengerCallback( VkDebugUtilsMessageS

vk::DebugUtilsMessengerCreateInfoEXT makeDebugUtilsMessengerCreateInfoEXT();

bool checkValidationLayerSupport(const std::vector<const char*>& validationLayers);
bool checkValidationLayerSupport(const std::vector<std::string>& validationLayers);

bool checkDeviceExtensionSupport(vk::PhysicalDevice device, const std::vector<const char*>& deviceExtensions);

Expand Down
147 changes: 81 additions & 66 deletions engine/src/graphics/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ namespace gen

GraphicsDevice::GraphicsDevice(gen::Window & window) : m_window{window}
{
createInstance(window.getTitle(), "Genesis Engine", {}, {}, VK_API_VERSION_1_0);
/*
createDebugMessenger();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createCommandPool();
*/
// TODO: Allow for the vulkan api to be specified in a config file or through command line arguments.
// We could also dynamically check for the highest supported version of the vulkan api, but that feels outside the scope of this project.
createInstance(window.getTitle(), "Genesis Engine", validationLayers, {}, VK_API_VERSION_1_0);
Rinzii marked this conversation as resolved.
Show resolved Hide resolved

//createDebugMessenger();
//createSurface();
//pickPhysicalDevice();
//createLogicalDevice();
//createCommandPool();
Rinzii marked this conversation as resolved.
Show resolved Hide resolved
}

GraphicsDevice::~GraphicsDevice()
Rinzii marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -41,6 +42,7 @@ namespace gen
auto vkGetInstanceProcAddr = vkdl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
#endif

if (enableValidationLayers) //NOLINT validation layers are enabled conditionally and this trips up clang-tidy
{
if (!vk::util::checkValidationLayerSupport(validationLayers))
Expand All @@ -50,6 +52,7 @@ namespace gen
}
}

// TODO: Allow for the application to be able to specify its version itself. Instead of just using the engine version.
vk::ApplicationInfo const appInfo(
appName.c_str(),
gen::version_v.getVersion(),
Expand All @@ -60,14 +63,14 @@ namespace gen
vk::InstanceCreateInfo const createInfo({}, &appInfo);

auto enabledLayers = vk::util::gatherLayers(layers
#if !defined(NDEBUG) || !defined(GEN_NDEBUG)
#ifndef GEN_NDEBUG
,
vk::enumerateInstanceLayerProperties()
#endif
);

auto enabledExtensions = vk::util::gatherExtensions(extensions
#if !defined(NDEBUG) || !defined(GEN_NDEBUG)
#ifndef GEN_NDEBUG
,
vk::enumerateInstanceExtensionProperties()
#endif
Expand All @@ -80,7 +83,53 @@ namespace gen
VULKAN_HPP_DEFAULT_DISPATCHER.init(m_instance);
#endif
}
/*

/*
QueueFamilyIndices GraphicsDevice::findQueueFamilies(vk::PhysicalDevice device)
{
QueueFamilyIndices indices;

std::vector<vk::QueueFamilyProperties> const queueFamilies = device.getQueueFamilyProperties();

gen::u32 index = 0;
for (const auto & queueFamily : queueFamilies)
{
if (queueFamily.queueFlags & vk::QueueFlagBits::eGraphics)
{
indices.graphicsFamily = index;
}

vk::Bool32 const presentSupport = device.getSurfaceSupportKHR(index, m_surface);
if (presentSupport != 0U)
{
indices.presentFamily = index;
}

if (indices.isComplete())
{
break;
}

index++;
}

return indices;
}

bool GraphicsDevice::checkDeviceExtensionSupport(vk::PhysicalDevice device)
{
std::vector<vk::ExtensionProperties> const availableExtensions = device.enumerateDeviceExtensionProperties();

std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());

for (const auto & extension : availableExtensions)
{
requiredExtensions.erase(extension.extensionName.data());
}

return requiredExtensions.empty();
}


void GraphicsDevice::createDebugMessenger()
{
Expand All @@ -89,6 +138,24 @@ namespace gen
#endif
}

bool GraphicsDevice::isDeviceSuitable(const vk::PhysicalDevice & device)
{
QueueFamilyIndices const indices = findQueueFamilies(device);

bool const extensionsSupported = checkDeviceExtensionSupport(device);

bool swapChainAdequate = false;
if (extensionsSupported)
{
SwapChainSupportDetails const swapChainSupport = querySwapChainSupport(device);
swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();
}

return indices.isComplete() && extensionsSupported && swapChainAdequate;
}
*/
/*

void GraphicsDevice::createSurface()
{
m_surface = m_window.createWindowSurface(m_instance);
Expand Down Expand Up @@ -120,6 +187,9 @@ namespace gen
}
}

*/

/*
void GraphicsDevice::createLogicalDevice()
{
QueueFamilyIndices indices = findQueueFamilies(m_physicalDevice);
Expand Down Expand Up @@ -153,65 +223,10 @@ namespace gen

m_commandPool = m_device.createCommandPool(poolInfo);
}
bool GraphicsDevice::isDeviceSuitable(vk::PhysicalDevice device)
{
QueueFamilyIndices const indices = findQueueFamilies(device);

bool const extensionsSupported = checkDeviceExtensionSupport(device);

bool swapChainAdequate = false;
if (extensionsSupported)
{
SwapChainSupportDetails const swapChainSupport = querySwapChainSupport(device);
swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();
}

return indices.isComplete() && extensionsSupported && swapChainAdequate;
}
bool GraphicsDevice::checkDeviceExtensionSupport(vk::PhysicalDevice device)
{
std::vector<vk::ExtensionProperties> const availableExtensions = device.enumerateDeviceExtensionProperties();

std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());

for (const auto & extension : availableExtensions)
{
requiredExtensions.erase(extension.extensionName.data());
}

return requiredExtensions.empty();
}

QueueFamilyIndices GraphicsDevice::findQueueFamilies(vk::PhysicalDevice device)
{
QueueFamilyIndices indices;

std::vector<vk::QueueFamilyProperties> const queueFamilies = device.getQueueFamilyProperties();

gen::u32 index = 0;
for (const auto & queueFamily : queueFamilies)
{
if (queueFamily.queueFlags & vk::QueueFlagBits::eGraphics)
{
indices.graphicsFamily = index;
}

vk::Bool32 const presentSupport = device.getSurfaceSupportKHR(index, m_surface);
if (presentSupport != 0U)
{
indices.presentFamily = index;
}

if (indices.isComplete())
{
break;
}

index++;
}

return indices;
}

SwapChainSupportDetails GraphicsDevice::querySwapChainSupport(vk::PhysicalDevice device)
{
Expand Down
9 changes: 5 additions & 4 deletions engine/src/graphics/pipeline.cpp
Rinzii marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ namespace gen {

void GraphicsPipeline::createGraphicsPipeline()
{
auto vertShaderCode = readFile("shaders/vert.spv");
auto fragShaderCode = readFile("shaders/frag.spv");
//auto vertShaderCode = readFile("shaders/vert.spv");
//auto fragShaderCode = readFile("shaders/frag.spv");

gen::logger::debug("graphics", "vertShaderCode size: " + std::to_string(vertShaderCode.size()));
gen::logger::debug("graphics", "fragShaderCode size: " + std::to_string(fragShaderCode.size()));
//gen::logger::debug("graphics", "vertShaderCode size: " + std::to_string(vertShaderCode.size()));
//gen::logger::debug("graphics", "fragShaderCode size: " + std::to_string(fragShaderCode.size()));
}

void GraphicsPipeline::destroyGraphicsPipeline()
{

}

void GraphicsPipeline::createShaderModule(const std::vector<char> & code, vk::ShaderModule * shaderModule)
{
m_vertShaderModule = vk::util::createShaderModule(m_device.getDevice(), vk::ShaderStageFlagBits::eVertex, code.data());
Expand Down
Loading