Skip to content

Commit 16f0899

Browse files
committed
Implement SwapChain and GraphicsResource, minor fixes
1 parent 970a518 commit 16f0899

18 files changed

+437
-21
lines changed

src/engine/renderer-vulkan/GraphicsCore/CapabilityPack.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ namespace CapabilityPackType {
7575

7676
constexpr Array instanceExtensions {
7777
"VK_LAYER_KHRONOS_validation",
78-
"VK_KHR_get_physical_device_properties2"
78+
"VK_KHR_get_physical_device_properties2",
79+
"VK_KHR_get_surface_capabilities2"
7980
};
8081

8182
constexpr Array extensionsMinimal {
82-
"VK_EXT_descriptor_indexing"
83+
"VK_EXT_descriptor_indexing",
84+
"VK_KHR_swapchain"
8385
};
8486

8587
constexpr Array featuresMinimal {

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreCVars.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3737

3838
#include "CapabilityPack.h"
3939

40+
#include "SwapChain.h"
41+
4042
#include "GraphicsCoreCVars.h"
4143

4244
Cvar::Cvar<int> r_rendererApi( "r_rendererAPI", "Renderer API: 0: OpenGL, 1: Vulkan", Cvar::ROM, 1 );
@@ -46,4 +48,9 @@ Cvar::Cvar<std::string> r_vkVersion( "r_vkVersion", "Daemon-vulkan version", Cva
4648
Cvar::Range<Cvar::Cvar<int>> r_vkCapabilityPack( "r_vkCapabilityPack", "CapabilityPack override",
4749
Cvar::NONE, CapabilityPackType::MINIMAL, CapabilityPackType::MINIMAL, CapabilityPackType::EXPERIMENTAL );
4850

49-
Cvar::Cvar<int> r_vkDevice( "r_vkDevice", "Use specific GPU (-1: auto)", Cvar::NONE, -1 );
51+
Cvar::Cvar<int> r_vkDevice( "r_vkDevice", "Use specific GPU (-1: auto)", Cvar::NONE, -1 );
52+
53+
Cvar::Range<Cvar::Cvar<int>> r_vkPresentMode( "r_vkPresentMode",
54+
"Presentation mode: 0 - immediate, 1 - vsync on last frame, 2 - vsync on first new frame, "
55+
"3 - relaxed vsync on first new frame, 4 - vsync on the closest frame to scanout",
56+
Cvar::NONE, PresentMode::IMMEDIATE, PresentMode::IMMEDIATE, PresentMode::SCANOUT_SYNC_LATEST );

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreCVars.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ extern Cvar::Range<Cvar::Cvar<int>> r_vkCapabilityPack;
4646

4747
extern Cvar::Cvar<int> r_vkDevice;
4848

49+
extern Cvar::Range<Cvar::Cvar<int>> r_vkPresentMode;
50+
4951
#endif // GRAPHICS_CORE_CVARS_H

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreStore.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535

3636
#include "Vulkan.h"
3737

38+
#include "../Surface/Surface.h"
39+
40+
#include "SwapChain.h"
41+
3842
#include "EngineConfig.h"
3943
#include "QueuesConfig.h"
4044
#include "Queue.h"
4145

4246
#include "GraphicsCoreStore.h"
4347

48+
Surface mainSurface;
49+
50+
SwapChain mainSwapChain;
51+
4452
EngineConfig engineConfig;
4553
QueuesConfig queuesConfig;
4654

src/engine/renderer-vulkan/GraphicsCore/GraphicsCoreStore.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
#ifndef GRAPHICS_CORE_STORE_H
3737
#define GRAPHICS_CORE_STORE_H
3838

39+
#include "Vulkan.h"
40+
3941
struct GraphicsQueueRingBuffer;
4042
struct EngineConfig;
4143
struct QueuesConfig;
44+
class Surface;
45+
struct SwapChain;
46+
47+
extern Surface mainSurface;
48+
49+
extern SwapChain mainSwapChain;
4250

4351
extern EngineConfig engineConfig;
4452
extern QueuesConfig queuesConfig;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// GraphicsResource.h
35+
36+
#include "GraphicsResource.h"
37+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
===========================================================================
3+
4+
Daemon BSD Source Code
5+
Copyright (c) 2025 Daemon Developers
6+
All rights reserved.
7+
8+
This file is part of the Daemon BSD Source Code (Daemon Source Code).
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
* Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of the Daemon developers nor the
18+
names of its contributors may be used to endorse or promote products
19+
derived from this software without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
25+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
===========================================================================
33+
*/
34+
// GraphicsResource.h
35+
36+
#ifndef GRAPHICS_RESOURCE_H
37+
#define GRAPHICS_RESOURCE_H
38+
39+
struct GraphicsResource {
40+
virtual void Free() = 0;
41+
};
42+
43+
#endif // GRAPHICS_RESOURCE_H

src/engine/renderer-vulkan/GraphicsCore/Instance.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4040
#include "../Math/NumberTypes.h"
4141
#include "../Memory/DynamicArray.h"
4242

43+
#include "../Error.h"
44+
4345
#include "Vulkan.h"
4446
#include "../VulkanLoader/VulkanLoadFunctions.h"
4547

48+
#include "SwapChain.h"
49+
4650
#include "CapabilityPack.h"
4751
#include "EngineConfig.h"
4852
#include "QueuesConfig.h"
@@ -124,17 +128,34 @@ void Instance::Init( const char* engineName, const char* appName ) {
124128

125129
VulkanLoadDeviceFunctions( device, instance );
126130

127-
graphicsQueue.Init( device, queuesConfig.graphicsQueue.id, queuesConfig.graphicsQueue.queues );
131+
mainSwapChain.Init( instance );
132+
133+
std::string foundQueues = "Found queues: graphics (present: true)";
134+
graphicsQueue.Init( device, queuesConfig.graphicsQueue.id, queuesConfig.graphicsQueue.queues );
135+
136+
uint32 presentSupported;
137+
vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevice, graphicsQueue.id, mainSwapChain.surface, &presentSupported );
138+
139+
if ( !presentSupported ) {
140+
Err( "Graphics queue doesn't support present" );
141+
return;
142+
}
128143

129144
if( queuesConfig.computeQueue.queues ) {
130-
computeQueue.Init( device, queuesConfig.computeQueue.id, queuesConfig.computeQueue.queues );
145+
computeQueue.Init( device, queuesConfig.computeQueue.id, queuesConfig.computeQueue.queues );
146+
vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevice, computeQueue.id, mainSwapChain.surface, &presentSupported );
147+
foundQueues += Str::Format( ", async compute (present: %s)", ( bool ) presentSupported );
131148
}
132149

133150
if ( queuesConfig.transferQueue.queues ) {
134151
transferQueue.Init( device, queuesConfig.transferQueue.id, queuesConfig.transferQueue.queues );
152+
foundQueues += Str::Format( ", async transfer" );
135153
}
136154

137155
if ( queuesConfig.sparseQueue.queues ) {
138-
sparseQueue.Init( device, queuesConfig.sparseQueue.id, queuesConfig.sparseQueue.queues );
156+
sparseQueue.Init( device, queuesConfig.sparseQueue.id, queuesConfig.sparseQueue.queues );
157+
foundQueues += Str::Format( ", async sparse binding" );
139158
}
159+
160+
Log::Notice( foundQueues );
140161
}

src/engine/renderer-vulkan/GraphicsCore/Queue.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
#include "Queue.h"
3939

4040
void GraphicsQueueRingBuffer::Init( const VkDevice device, const uint32 queueGroup, uint32 count ) {
41+
id = queueGroup;
4142
count = count > maxQueues ? maxQueues : count;
4243

4344
for ( GraphicsQueue* queue = queues; queue < queues + count; queue++ ) {
4445
VkDeviceQueueInfo2 info {
45-
.queueFamilyIndex = queueGroup,
46+
.queueFamilyIndex = id,
4647
.queueIndex = ( uint32 ) ( queue - queues )
4748
};
4849

4950
vkGetDeviceQueue2( device, &info, &queue->queue );
51+
52+
queue->index = info.queueIndex;
5053
}
5154
}

src/engine/renderer-vulkan/GraphicsCore/Queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ struct GraphicsQueue {
5151
struct GraphicsQueueRingBuffer {
5252
static constexpr uint32 maxQueues = 64;
5353

54+
uint32 id;
55+
5456
GraphicsQueue queues[maxQueues] {};
5557

5658
void Init( const VkDevice device, const uint32 queueGroup, uint32 count );

0 commit comments

Comments
 (0)