Skip to content

Commit 1b43764

Browse files
committed
adding RHI base
1 parent 887d2ce commit 1b43764

9 files changed

Lines changed: 260 additions & 13 deletions

File tree

Engine/Runtime/Includes/Graphics/GraphicsModule.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#ifndef MLK_GRAPHICS_MODULE_HPP
2-
#define MLK_GRAPHICS_MODULE_HPP
1+
#ifndef MLK_GRAPHICS_MODULE_HPP__
2+
#define MLK_GRAPHICS_MODULE_HPP__
33

4-
#include <Core/OS/LibLoader.hpp>
54
#include <Graphics/PreCompiled.hpp>
65
#include <Core/Module.hpp>
76
#include <Utils/TypeList.hpp>
8-
#include <Graphics/Enums.hpp>
97

108
namespace Mlk
119
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef MLK_VULKAN_PRE_COMPILED_HEADER_HPP__
2+
#define MLK_VULKAN_PRE_COMPILED_HEADER_HPP__
3+
4+
#include <vulkan/vulkan_core.h>
5+
6+
#endif

Engine/Runtime/Includes/Renderer/PreCompiled.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef MLK_GRAPHICS_PRE_COMPILED_HEADER_HPP__
2-
#define MLK_GRAPHICS_PRE_COMPILED_HEADER_HPP__
1+
#ifndef MLK_RENDERER_PRE_COMPILED_HEADER_HPP__
2+
#define MLK_RENDERER_PRE_COMPILED_HEADER_HPP__
33

44
#include <Core/CompilationProfile.hpp>
55
#include <Renderer/Renderer.hpp>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef MLK_RHI_DEFS_HPP__
2+
#define MLK_RHI_DEFS_HPP__
3+
4+
#include <Maths/Vec4.hpp>
5+
#include <Utils/NonOwningPtr.hpp>
6+
#include <Renderer/PreCompiled.hpp>
7+
#include <Renderer/RHI/Enums.hpp>
8+
9+
namespace Mlk
10+
{
11+
using DeviceSize = std::uint64_t;
12+
13+
constexpr std::size_t MacRenderTargets = 8;
14+
15+
struct BufferDescription
16+
{
17+
const void* initial_data = nullptr;
18+
const char* debug_name = nullptr;
19+
DeviceSize size;
20+
BufferUsage usage;
21+
BufferType type;
22+
};
23+
24+
struct TextureDescription
25+
{
26+
const void* initial_data = nullptr;
27+
const char* debug_name = nullptr;
28+
TextureFormat format;
29+
TextureType type;
30+
std::size_t width;
31+
std::size_t height;
32+
TextureFlags flags;
33+
};
34+
35+
struct GraphicPipelineDescription
36+
{
37+
std::vector<NonOwningPtr<class RHIShader>> shaders;
38+
std::array<NonOwningPtr<class RHITexture>, MacRenderTargets> render_targets;
39+
Vec4f clear_color;
40+
const char* debug_name = nullptr;
41+
NonOwningPtr<class RHITexture> depth_target;
42+
CullMode cull_mode = CullMode::Back;
43+
RenderMode render_mode = RenderMode::Fill;
44+
std::size_t line_width = 1;
45+
bool clear_target = false;
46+
};
47+
48+
struct ShaderDescription
49+
{
50+
};
51+
52+
struct RenderPassDescription
53+
{
54+
};
55+
56+
struct FrameBufferDescription
57+
{
58+
};
59+
60+
struct PhysicalDeviceMinimalSpecs
61+
{
62+
PhysicalDeviceType type = PhysicalDeviceType::Any;
63+
PhysicalDeviceVendors vendors = PhysicalDeviceVendorAny;
64+
std::size_t memory = 128; // Mo
65+
};
66+
}
67+
68+
#endif
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#ifndef MLK_RHI_ENUMS_HPP__
2+
#define MLK_RHI_ENUMS_HPP__
3+
4+
#include <Renderer/PreCompiled.hpp>
5+
6+
#ifdef None // Thanks x11 :)
7+
#undef None
8+
#endif
9+
10+
namespace Mlk
11+
{
12+
enum class BufferType
13+
{
14+
Constant = 0,
15+
HighDynamic, // typically stored in RAM
16+
LowDynamic, // typically stored in VRAM
17+
18+
EndEnum
19+
};
20+
constexpr std::size_t BufferTypeCount = static_cast<std::size_t>(BufferType::EndEnum);
21+
22+
enum BufferUsageBits
23+
{
24+
BufferUsageTransferSrc = 1 << 0,
25+
BufferUsageTransferDst = 1 << 1,
26+
BufferUsageVertex = 1 << 2,
27+
BufferUsageIndex = 1 << 3,
28+
BufferUsageUniform = 1 << 4,
29+
BufferUsageStorage = 1 << 5
30+
};
31+
constexpr std::size_t BufferUsageCount = 6;
32+
using BufferUsage = std::uint32_t;
33+
34+
enum class CullMode
35+
{
36+
None = 0,
37+
Front,
38+
Back,
39+
BackAndFront,
40+
41+
EndEnum
42+
};
43+
constexpr std::size_t CullModeCount = static_cast<std::size_t>(CullMode::EndEnum);
44+
45+
enum class PhysicalDeviceType
46+
{
47+
Any = 0,
48+
Other,
49+
CPU,
50+
Virtual,
51+
Integrated,
52+
Discrete,
53+
54+
EndEnum
55+
};
56+
constexpr std::size_t PhysicalDeviceTypeCount = static_cast<std::size_t>(PhysicalDeviceType::EndEnum);
57+
58+
enum PhysicalDeviceVendorBits
59+
{
60+
PhysicalDeviceVendorAny = 1 << 0,
61+
PhysicalDeviceVendorAmd = 1 << 1,
62+
PhysicalDeviceVendorMesa = 1 << 2,
63+
PhysicalDeviceVendorImgTec = 1 << 3,
64+
PhysicalDeviceVendorNvidia = 1 << 4,
65+
PhysicalDeviceVendorArm = 1 << 5,
66+
PhysicalDeviceVendorBroadcom = 1 << 6,
67+
PhysicalDeviceVendorQualcomm = 1 << 7,
68+
PhysicalDeviceVendorIntel = 1 << 8,
69+
PhysicalDeviceVendorSamsungAMD = 1 << 9,
70+
PhysicalDeviceVendorMicrosoft = 1 << 10,
71+
};
72+
constexpr std::size_t PhysicalDeviceVendorsCount = 11;
73+
using PhysicalDeviceVendors = std::uint32_t;
74+
75+
enum class RenderMode
76+
{
77+
Fill = 0,
78+
Wireframe,
79+
Points,
80+
81+
EndEnum
82+
};
83+
constexpr std::size_t RenderModeCount = static_cast<std::size_t>(RenderMode::EndEnum);
84+
85+
enum class TextureFormat
86+
{
87+
None = 0,
88+
R8_Unorm,
89+
R8G8_Unorm,
90+
R8G8B8_Unorm,
91+
R8G8B8A8_Unorm,
92+
93+
R8_UInt,
94+
95+
R11G11B10_Float,
96+
R10G10B10A2_Unorm,
97+
98+
R32_Int,
99+
R32G32_Int,
100+
R32G32B32_Int,
101+
R32G32B32A32_Int,
102+
103+
R32_UInt,
104+
R32G32_UInt,
105+
R32G32B32_UInt,
106+
R32G32B32A32_UInt,
107+
108+
R16_Float,
109+
R16G16_Float,
110+
R16G16B16_Float,
111+
R16G16B16A16_Float,
112+
113+
R32_Float,
114+
R32G32_Float,
115+
R32G32B32_Float,
116+
R32G32B32A32_Float,
117+
118+
D16_Unorm,
119+
D32_Float,
120+
D16_Unorm_S8_UInt,
121+
D24_Unorm_S8_UInt,
122+
D32_Float_S8_UInt,
123+
124+
EndEnum
125+
};
126+
constexpr std::size_t TextureFormatCount = static_cast<std::size_t>(TextureFormat::EndEnum);
127+
128+
enum class TextureType
129+
{
130+
Color = 0,
131+
Depth,
132+
DepthArray,
133+
Cube,
134+
Other,
135+
136+
EndEnum
137+
};
138+
constexpr std::size_t TextureTypeCount = static_cast<std::size_t>(TextureType::EndEnum);
139+
140+
enum TextureFlagsBits
141+
{
142+
TextureFlagSampled = 1 << 0,
143+
TextureFlagStorage = 1 << 1,
144+
TextureFlagDepthStencil = 1 << 2,
145+
};
146+
constexpr std::size_t TextureFlagsCount = 3;
147+
using TextureFlags = std::uint32_t;
148+
}
149+
150+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef MLK_RHI_RENDERER_HPP__
2+
#define MLK_RHI_RENDERER_HPP__
3+
4+
#include <Renderer/PreCompiled.hpp>
5+
#include <Renderer/RHI/Defs.hpp>
6+
7+
namespace Mlk
8+
{
9+
class MLK_RENDERER_API RHIRenderer
10+
{
11+
public:
12+
RHIRenderer() = default;
13+
14+
virtual std::uint32_t LoadNewDevice(const PhysicalDeviceMinimalSpecs& specs) noexcept = 0;
15+
virtual class RHIDevice& GetDevice(std::uint32_t index) = 0;
16+
17+
virtual ~RHIRenderer() = default;
18+
};
19+
}
20+
21+
#endif

Engine/Runtime/Includes/Renderer/RendererModule.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Core/Module.hpp>
77
#include <Utils/TypeList.hpp>
88
#include <Renderer/Enums.hpp>
9+
#include <Renderer/RHI/RHIRenderer.hpp>
910

1011
namespace Mlk
1112
{
@@ -31,6 +32,7 @@ namespace Mlk
3132
private:
3233
static RendererModule* s_instance;
3334
RendererDrivers m_chosen_driver = RendererDrivers::None;
35+
RHIRenderer* m_renderer = nullptr;
3436
LibModule m_driver_lib = NullModule;
3537
};
3638
}

Engine/Runtime/Sources/Graphics/GraphicsModule.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
#include <Core/OS/OSInstance.h>
2-
#include <Graphics/Enums.h>
3-
#include <Core/Application.h>
4-
#include <Graphics/GraphicsModule.h>
5-
#include <Core/CLI.h>
6-
#include <Core/Logs.h>
7-
#include <Utils/ConstMap.h>
1+
#include <Graphics/GraphicsModule.hpp>
2+
#include <Core/OS/OSInstance.hpp>
3+
#include <Core/Application.hpp>
4+
#include <Core/Logs.hpp>
85

96
namespace Mlk
107
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <Renderer/RHI/RHIRenderer.hpp>
2+
3+
namespace Mlk
4+
{
5+
}

0 commit comments

Comments
 (0)