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 all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ cmake-build-*/

#project specific excludes
!tools/**
genesis.log
Empty file removed editor/shaders/common.hlsl
Empty file.
33 changes: 33 additions & 0 deletions editor/shaders/math/const.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef QTR_PI
#define QTR_PI 0.78539816339
#endif
#ifndef HALF_PI
#define HALF_PI 1.5707963267948966192313216916398
#endif
#ifndef PI
#define PI 3.1415926535897932384626433832795
#endif
#ifndef TWO_PI
#define TWO_PI 6.2831853071795864769252867665590
#endif
#ifndef TAU
#define TAU 6.2831853071795864769252867665590
#endif
#ifndef INVERSE_PI
#define INVERSE_PI 0.31830988618
#endif
#ifndef PHI
#define PHI 1.618033988749894848204586834
#endif
#ifndef EPSILON
#define EPSILON 0.0000001
#endif
#ifndef GOLDEN_RATIO
#define GOLDEN_RATIO 1.6180339887
#endif
#ifndef GOLDEN_RATIO_CONJUGATE
#define GOLDEN_RATIO_CONJUGATE 0.61803398875
#endif
#ifndef GOLDEN_ANGLE // (3.-sqrt(5.0))*PI radians
#define GOLDEN_ANGLE 2.39996323
#endif
2 changes: 1 addition & 1 deletion editor/shaders/simplePS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PSOutput
float4 outColor : SV_Target0;
};

PSOutput Main()
PSOutput main()
{
PSOutput output;
output.outColor = float4(1.0, 0.0, 0.0, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion editor/shaders/simpleVS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct VSOutput
};


VSOutput Main(VSInput input)
VSOutput main(VSInput input)
{
float2 position[3];

Expand Down
20 changes: 11 additions & 9 deletions editor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
#include <logger/instance.hpp>
#include <logger/log.hpp>

int main() {
auto logger = gen::logger::Instance{};

gen::Application app;
int main()
{
try
{
auto logger = gen::logger::Instance{}; // Required to initialize the logger

gen::logger::info("Hello, world!");

try {
gen::Application app;
app.run();
} catch (std::exception const& e) {
}
catch (std::exception const & e)
{
gen::logger::error(e.what());
return EXIT_FAILURE;
return 1;
}

return EXIT_SUCCESS;
return 0;
}
29 changes: 18 additions & 11 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
include(CMakeDependentOption)

option(GENESIS_PCH "Use pre-compiled headers for the Genesis Engine" ON)
option(ENABLE_SIMD "Enable SIMD for Genesis" OFF)
option(GENESIS_ENABLE_SIMD "Enable SIMD for Genesis" OFF)


add_library(genesis)
add_library(genesis::lib ALIAS genesis)

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

if (ENABLE_SIMD)
if (GENESIS_ENABLE_SIMD)
# This create an internal definition that allows our project to check if it can use simd.
# If the code decides it can then GEN_SIMD will be defined along with a bunch of other SIMD related defines.
# This definition is only used once to to allow GEN_SIMD to figure out if it can be enabled and nowhere else.
add_compile_definitions(INTERNAL_GEN_SIMD_ENABLE)
endif()

Expand Down Expand Up @@ -103,19 +108,19 @@ if (GENESIS_BUILD_SHADERS)

if (${SHADER_EXTENSION} STREQUAL ".hlsl")
if (${SHADER_NAME} MATCHES ".*VS\\.hlsl$") # Vertex Shader
set(SHADER_TYPE "vs")
set(SHADER_TYPE "vs") # Vertex Shader
elseif (${SHADER_NAME} MATCHES ".*PS\\.hlsl$") # Pixel Shader
set(SHADER_TYPE "ps")
set(SHADER_TYPE "ps") # Pixel (Fragment) Shader
elseif (${SHADER_NAME} MATCHES ".*CS\\.hlsl$") # Compute Shader
set(SHADER_TYPE "cs")
set(SHADER_TYPE "cs") # Compute Shader
elseif (${SHADER_NAME} MATCHES ".*GS\\.hlsl$") # Geometry Shader
set(SHADER_TYPE "gs")
set(SHADER_TYPE "gs") # Geometry Shader
elseif (${SHADER_NAME} MATCHES ".*DS\\.hlsl$") # Domain Shader
set(SHADER_TYPE "ds")
set(SHADER_TYPE "ds") # Domain Shader
elseif (${SHADER_NAME} MATCHES ".*HS\\.hlsl$") # Hull Shader
set(SHADER_TYPE "hs")
set(SHADER_TYPE "hs") # Hull Shader
elseif (${SHADER_NAME} MATCHES ".*LIB\\.hlsl$") # Library Shader - may not work with spirv
if (${TARGET_SHADER_MODEL} VERSION_LESS "6_3") # TODO: Not sure if this works.
if (${TARGET_SHADER_MODEL} VERSION_LESS "6_3") # Library shaders require shader model 6_3 or higher
message(FATAL_ERROR "Shader model 6_0 or higher is required for file: ${SHADER_SOURCE_FILE}")
endif ()
message(WARNING "WARNING: Library shaders may not work with spirv")
Expand Down Expand Up @@ -152,7 +157,7 @@ if (GENESIS_BUILD_SHADERS)
# Add a custom command for each shader file.
add_custom_command(
TARGET CmakeCompileShaders
COMMAND ${DXC_EXECUTABLE_PATH} -spirv -T ${SHADER_TYPE}_${TARGET_SHADER_MODEL} -E Main ${ABSOLUTE_SHADER_SOURCE_FILE} -Fo ${OUTPUT_SHADER_FILE}.spv
COMMAND ${DXC_EXECUTABLE_PATH} -spirv -T ${SHADER_TYPE}_${TARGET_SHADER_MODEL} -E main ${ABSOLUTE_SHADER_SOURCE_FILE} -Fo ${OUTPUT_SHADER_FILE}.spv
DEPENDS ${SHADER_SOURCE_FILE}
COMMENT "Compiling ${SHADER_SOURCE_FILE} to SPIR-V"
VERBATIM
Expand All @@ -171,6 +176,8 @@ target_link_libraries(genesis
PUBLIC
mim::mim
imgui::imgui
glfw::glfw
vk-dynamic::vk-dynamic

PRIVATE
genesis::ext
Expand Down
4 changes: 3 additions & 1 deletion engine/header_list.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ set(base_headers
)

set(graphics_headers
include/graphics/device.hpp
include/graphics/pipeline.hpp
include/graphics/vkHelpers.hpp
)

set(io_headers
Expand Down Expand Up @@ -58,7 +60,7 @@ set(windowing_headers
# core header include
set(genesis_headers
${base_headers}
#${graphics_headers}
${graphics_headers}
${io_headers}
${system_headers}
${util_headers}
Expand Down
39 changes: 26 additions & 13 deletions engine/include/application.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
// Copyright Ian Pike. All Rights Reserved.
// Copyright (c) 2023-present Genesis Engine contributors (see LICENSE.txt)

#pragma once

#include "core.hpp"

#include "util/version.hpp"

#include "graphics/device.hpp"
#include "graphics/pipeline.hpp"
#include "windowing/window.hpp"

namespace gen {
namespace gen
{

class Application
{
public:

void run();

class Application {
public:
private:
void gameLoop();
void shutdown();

void run();

// This is all kinda bad but it is gonna be replaced later
// Just using it for testing the rendering pipeline
public:
static constexpr u32 m_width = 800;
static constexpr u32 m_height = 600;
public:
static constexpr auto m_appName { "Genesis Engine Game" };
static constexpr u32 m_width { 800 };
static constexpr u32 m_height { 600 };

private:
Window m_window{ 800, 600, "Genesis Engine" };

};
private:
Window m_window { m_width, m_height, m_appName };
GraphicsDevice m_graphicsDevice { m_appName };
};

} // namespace gen
1 change: 1 addition & 0 deletions engine/include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/base.hpp"
#include "system/types.hpp"
#include "genesis_version.hpp"



31 changes: 31 additions & 0 deletions engine/include/graphics/device.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2023-present Genesis Engine contributors (see LICENSE.txt)

#pragma once

#include "core.hpp"
#include "windowing/window.hpp"

#include <vector>

#include <vulkan/vulkan.hpp>

namespace gen
{

class GraphicsDevice
{
public:
GraphicsDevice(const GraphicsDevice &) = delete;
GraphicsDevice & operator=(const GraphicsDevice &) = delete;
GraphicsDevice(GraphicsDevice &&) = delete;
GraphicsDevice & operator=(GraphicsDevice &&) = delete;

explicit GraphicsDevice( std::string const & appName );
~GraphicsDevice();

private:
void createInstance(const std::string & appName, const std::string & engineName, const gen::u32 & apiVersion);

vk::UniqueInstance m_instance;
};
} // namespace gen
50 changes: 41 additions & 9 deletions engine/include/graphics/pipeline.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,52 @@
// Copyright Ian Pike. All Rights Reserved.
// Copyright (c) 2023-present Genesis Engine contributors (see LICENSE.txt)

#pragma once

#include <vulkan/vulkan.hpp>
#include <string>
#include <vector>

namespace gen {
#include "core.hpp"

class Pipeline {
public:
Pipeline(const std::string& vertFilePath, const std::string& fragFilePath);
#include "device.hpp"

private:
static std::vector<char> readFile(const std::string& filePath);
namespace gen
{
struct PipelineConfigInfo
{
};

void createGraphicsPipeline(const std::string& vertFilePath, const std::string &fragFilePath);
};
class GraphicsPipeline
{
public:
GraphicsPipeline(GraphicsDevice & device, const PipelineConfigInfo & configInfo);
~GraphicsPipeline();

GraphicsPipeline(const GraphicsPipeline &) = delete;
GraphicsPipeline & operator=(const GraphicsPipeline &) = delete;

static PipelineConfigInfo defaultPipelineConfigInfo(u32 width, u32 height);

private:
static std::vector<char> readFile(const std::string & filePath);

void createGraphicsPipeline();

void createShaderModule(const std::vector<char> & code, vk::ShaderModule * shaderModule);

void destroyGraphicsPipeline();

// NOLINTNEXTLINE The assumption with this is that the device will outlive the pipeline at all times since a device fundamentally needs a pipeline to
// exist
GraphicsDevice & m_device;
vk::UniquePipeline m_graphicsPipeline;
vk::UniqueShaderModule m_vertShaderModule;
vk::UniqueShaderModule m_fragShaderModule;

const PipelineConfigInfo m_configInfo;

vk::UniqueInstance m_instance;
vk::DebugUtilsMessengerEXT m_debugMessenger;
};

} // namespace gen
40 changes: 40 additions & 0 deletions engine/include/graphics/vkHelpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023-present Genesis Engine contributors (see LICENSE.txt)

#pragma once

#include <limits>
#include <map>
#include <memory> // std::unique_ptr
#include <set>

#include <vulkan/vulkan.hpp>
#ifndef GLFW_INCLUDE_NONE
# define GLFW_INCLUDE_NONE
#endif
#include <GLFW/glfw3.h>

#include "core.hpp"
#include "logger/log.hpp"
#include "windowing/window.hpp"

namespace vk::util
{

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

vk::StructureChain<vk::InstanceCreateInfo> makeInstanceCreateInfoChain(vk::ApplicationInfo appInfo, std::vector<const char *> const & layers, std::vector<const char *> const & extensions);

vk::DebugUtilsMessengerCreateInfoEXT makeDebugUtilsMessengerCreateInfoEXT();

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

vk::UniqueShaderModule createShaderModule(vk::Device device, vk::ShaderStageFlagBits shaderStage, std::string const & shaderText);

vk::UniqueSurfaceKHR createWindowSurface(vk::Instance instance, gen::Window const & window);

} // namespace vk::util
Loading
Loading