Skip to content

Commit 5307d70

Browse files
committed
Continued work on Vulkan with Wayland.
1 parent f51dfa4 commit 5307d70

File tree

7 files changed

+81
-10
lines changed

7 files changed

+81
-10
lines changed

source/code/modules/vulkan_renderer/private/vk_driver.cxx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include <ice/container/array.hxx>
1111
#include <ice/assert.hxx>
1212

13+
extern "C"
14+
{
15+
struct wl_display;
16+
struct wl_surface;
17+
}
18+
1319

1420
namespace ice::render::vk
1521
{
@@ -71,6 +77,11 @@ namespace ice::render::vk
7177
{
7278
_vk_physical_device = physical_device;
7379
}
80+
if (physical_device_properties.deviceType == VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_CPU
81+
&& _vk_physical_device == vk_nullptr)
82+
{
83+
_vk_physical_device = physical_device;
84+
}
7485
}
7586
}
7687

@@ -211,6 +222,61 @@ namespace ice::render::vk
211222

212223
return _vk_alloc->create<VulkanRenderSurface>(_vk_instance, vulkan_surface);
213224
}
225+
#elif ISP_LINUX
226+
auto VulkanRenderDriver::create_surface(
227+
ice::render::SurfaceInfo const& surface_info
228+
) noexcept -> ice::render::RenderSurface*
229+
{
230+
ICE_ASSERT(
231+
surface_info.type == ice::render::SurfaceType::Wayland_Window,
232+
"Unsupported surface type provided, accepting 'Wayland_Window' surfaces only!"
233+
);
234+
235+
VkWaylandSurfaceCreateInfoKHR surface_create_info{ VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR };
236+
surface_create_info.display = static_cast<wl_display*>(surface_info.wayland.display);
237+
surface_create_info.surface = static_cast<wl_surface*>(surface_info.wayland.surface);
238+
239+
VkSurfaceKHR vulkan_surface;
240+
auto api_result = vkCreateWaylandSurfaceKHR(_vk_instance, &surface_create_info, nullptr, &vulkan_surface);
241+
ICE_ASSERT(api_result == VkResult::VK_SUCCESS, "Failed to create Vulkan surface!");
242+
243+
ice::i32 family_index = 0;
244+
for (VkQueueFamilyProperties const& queue_family_props : _vk_queue_family_properties)
245+
{
246+
VkBool32 supports_presenting;
247+
248+
[[maybe_unused]]
249+
VkResult ph_api_result = vkGetPhysicalDeviceSurfaceSupportKHR(
250+
_vk_physical_device,
251+
family_index,
252+
vulkan_surface,
253+
&supports_presenting
254+
);
255+
ICE_ASSERT(
256+
ph_api_result == VkResult::VK_SUCCESS,
257+
"Couldn't query information if family {} (index) supports presenting!",
258+
family_index
259+
);
260+
261+
if (supports_presenting == VK_TRUE)
262+
{
263+
if (_vk_presentation_queue_family_index == -1)
264+
{
265+
_vk_presentation_queue_family_index = family_index;
266+
}
267+
else if ((queue_family_props.queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)
268+
{
269+
_vk_presentation_queue_family_index = family_index;
270+
}
271+
}
272+
273+
family_index += 1;
274+
}
275+
276+
return _vk_alloc->create<VulkanRenderSurface>(_vk_instance, vulkan_surface);
277+
}
278+
#else
279+
#error Missing implementation
214280
#endif
215281

216282
void VulkanRenderDriver::destroy_surface(

source/code/modules/vulkan_renderer/private/vk_extensions.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ice::render::vk
1414
{ ExtensionTarget::InstanceExtension, Extension::VkI_Win32Surface, 0, VK_KHR_WIN32_SURFACE_EXTENSION_NAME },
1515
#elif ISP_ANDROID
1616
{ ExtensionTarget::InstanceExtension, Extension::VkI_AndroidSurface, 0, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME },
17+
#elif ISP_LINUX
18+
{ ExtensionTarget::InstanceExtension, Extension::VkI_WaylandSurface, 0, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME },
1719
#else
1820
#error Unknown platform
1921
#endif

source/code/modules/vulkan_renderer/private/vk_extensions.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ namespace ice::render::vk
1414

1515
// Core instance extensions
1616
VkI_Surface = 0x0000'0001,
17-
VkI_Win32Surface= 0x0000'0002,
18-
VkI_AndroidSurface= 0x0000'0004,
17+
VkI_Win32Surface = 0x0000'0002, // The three surfaces are mutually exclusive so they may share the same value
18+
VkI_AndroidSurface = 0x0000'0002,
19+
VkI_WaylandSurface = 0x0000'0002,
1920
VkI_GetPhysicalDeviceProperties2 = 0x0000'0008,
2021

2122
// Core device extensions

source/code/platforms/platform_linux/private/linux_sdl2_platform_render_surface.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace ice::platform::linux::sdl2
1414

1515
RenderSurface_WaylandSDL2::RenderSurface_WaylandSDL2() noexcept
1616
{
17+
SDL_VideoInit("wayland");
1718
SDL_InitSubSystem(SDL_INIT_VIDEO);
1819
}
1920

@@ -26,6 +27,7 @@ namespace ice::platform::linux::sdl2
2627
}
2728

2829
SDL_QuitSubSystem(SDL_INIT_VIDEO);
30+
SDL_VideoQuit();
2931
}
3032

3133
auto RenderSurface_WaylandSDL2::create(ice::platform::RenderSurfaceParams surface_params) noexcept -> ice::Result
@@ -78,9 +80,10 @@ namespace ice::platform::linux::sdl2
7880
}
7981

8082
SDL_SysWMinfo wm_info{};
83+
SDL_VERSION(&wm_info.version);
8184
SDL_GetWindowWMInfo(_window, &wm_info);
8285

83-
out_surface_info.type = ice::render::SurfaceType::Win32_Window;
86+
out_surface_info.type = ice::render::SurfaceType::Wayland_Window;
8487
out_surface_info.wayland.surface = wm_info.info.wl.surface;
8588
out_surface_info.wayland.display = wm_info.info.wl.display;
8689
return true;

source/code/systems/render_system/public/ice/render/render_surface.hxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace ice::render
1717
{
1818
Win32_Window,
1919
UWP_Window,
20+
Wayland_Window,
2021
Android_NativeWindow,
2122
HTML5_DOMCanvas
2223
};

source/conanfile.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ rapidxml_ns/1.13.2@iceshard/stable
1818
rapidjson/1.1.0
1919
rapidfuzz_cpp/3.0.5@iceshard/stable
2020

21-
[requires-Windows-MSVC]
2221
vulkan-memory-allocator/3.0.1
22+
23+
[requires-Windows-MSVC]
2324
catch2/3.3.2@iceshard/stable
2425

2526
assimp/5.2.5@iceshard/stable
@@ -33,7 +34,6 @@ msdf_atlas_gen/1.2.2@iceshard/stable
3334
imguizmo/1.91.3@iceshard/stable
3435

3536
[requires-Linux-Clang]
36-
vulkan-memory-allocator/3.0.1
3737
catch2/3.3.2@iceshard/stable
3838

3939
assimp/5.2.5@iceshard/stable
@@ -46,11 +46,6 @@ msdf_atlas_gen/1.2.2@iceshard/stable
4646
# Editor only packages
4747
imguizmo/1.91.3@iceshard/stable
4848

49-
[requires-Android-Arm64]
50-
vulkan-memory-allocator/3.0.1
51-
52-
[requires-Android-x64]
53-
vulkan-memory-allocator/3.0.1
5449

5550
[options-Android-Arm64]
5651
tracy/*:shared=False

tools/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@
4040
},
4141
"doxy": {
4242
"config": "source/configs/doxyfile"
43+
},
44+
"vulkan": {
45+
"version": "1.4.313.0"
4346
}
4447
}

0 commit comments

Comments
 (0)