Skip to content

Commit f4ad839

Browse files
directly create a surface
1 parent 5bdc3ff commit f4ad839

File tree

7 files changed

+46
-145
lines changed

7 files changed

+46
-145
lines changed

bldsys/cmake/component_helpers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function(vkb__register_component)
4444
if(TARGET_SRC) # Create static library
4545
message("ADDING STATIC: vkb__${TARGET_NAME}")
4646

47-
add_library("vkb__${TARGET_NAME}" STATIC ${TARGET_SRC} ${TARGET_HEADERS})
47+
add_library("vkb__${TARGET_NAME}" STATIC ${TARGET_SRC})
4848

4949
if(TARGET_LINK_LIBS)
5050
target_link_libraries("vkb__${TARGET_NAME}" PUBLIC ${TARGET_LINK_LIBS})

components/windows/include/components/windows/glfw.hpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,47 +34,18 @@ class GLFWWindow : public Window
3434

3535
public:
3636
GLFWWindow(const std::string &title = "New Window", const Extent &initial_extent = {600, 600});
37-
virtual ~GLFWWindow();
38-
virtual void set_extent(const Extent &extent) override;
39-
virtual Extent extent() const override;
40-
virtual void set_position(const Position &position) override;
41-
virtual Position position() const override;
42-
virtual float dpi_factor() const override;
43-
virtual void set_title(const std::string &title) override;
44-
virtual std::string_view title() const override;
45-
virtual void update() override;
46-
virtual void attach(events::EventBus &bus) override;
37+
~GLFWWindow();
38+
void set_extent(const Extent &extent) override;
39+
Extent extent() const override;
40+
void set_position(const Position &position) override;
41+
Position position() const override;
42+
float dpi_factor() const override;
43+
void set_title(const std::string &title) override;
44+
std::string_view title() const override;
45+
void update() override;
46+
void attach(events::EventBus &bus) override;
4747

48-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
49-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const override
50-
{
51-
return VK_INCOMPLETE;
52-
}
53-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
54-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const override;
55-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
56-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const override
57-
{
58-
return VK_INCOMPLETE;
59-
}
60-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
61-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const override;
62-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
63-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const override
64-
{
65-
return VK_INCOMPLETE;
66-
}
67-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
68-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const override
69-
{
70-
return VK_INCOMPLETE;
71-
}
72-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
73-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const override
74-
{
75-
return VK_INCOMPLETE;
76-
}
77-
#endif
48+
VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) override;
7849

7950
protected:
8051
std::string m_title;

components/windows/include/components/windows/headless.hpp

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,53 +27,18 @@ class HeadlessWindow : public Window
2727
{
2828
public:
2929
HeadlessWindow(const std::string &title = "New Window", const Extent &initial_extent = {600, 600});
30-
virtual ~HeadlessWindow() = default;
31-
virtual void set_extent(const Extent &extent) override;
32-
virtual Extent extent() const override;
33-
virtual void set_position(const Position &position) override;
34-
virtual Position position() const override;
35-
virtual float dpi_factor() const override;
36-
virtual void set_title(const std::string &title) override;
37-
virtual std::string_view title() const override;
38-
virtual void update() override;
39-
virtual void attach(events::EventBus &bus) override;
40-
41-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
42-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const override
43-
{
44-
return VK_INCOMPLETE;
45-
}
46-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
47-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const override
48-
{
49-
return VK_INCOMPLETE;
50-
}
51-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
52-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const override
53-
{
54-
return VK_INCOMPLETE;
55-
}
56-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
57-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const override
58-
{
59-
return VK_INCOMPLETE;
60-
}
61-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
62-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const override
63-
{
64-
return VK_INCOMPLETE;
65-
}
66-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
67-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const override
68-
{
69-
return VK_INCOMPLETE;
70-
}
71-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
72-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const override
73-
{
74-
return VK_INCOMPLETE;
75-
}
76-
#endif
30+
~HeadlessWindow() = default;
31+
void set_extent(const Extent &extent) override;
32+
Extent extent() const override;
33+
void set_position(const Position &position) override;
34+
Position position() const override;
35+
float dpi_factor() const override;
36+
void set_title(const std::string &title) override;
37+
std::string_view title() const override;
38+
void update() override;
39+
void attach(events::EventBus &bus) override;
40+
41+
VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) override;
7742

7843
private:
7944
std::string m_title;

components/windows/include/components/windows/window.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,7 @@ class Window : public events::EventObserver
7676
virtual void set_title(const std::string &title) = 0;
7777
virtual std::string_view title() const = 0;
7878

79-
// supported vulkan surface create infos
80-
// compile errors indicate that a platform supports a surface but we do not have an implementation for it
81-
82-
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
83-
virtual VkResult populate_surface_create_info(VkAndroidSurfaceCreateInfoKHR * /* info */) const = 0;
84-
#elif defined(VK_USE_PLATFORM_WIN32_KHR)
85-
virtual VkResult populate_surface_create_info(VkWin32SurfaceCreateInfoKHR * /* info */) const = 0;
86-
#elif defined(VK_USE_PLATFORM_METAL_EXT)
87-
virtual VkResult populate_surface_create_info(VkMetalSurfaceCreateInfoEXT * /* info */) const = 0;
88-
#elif defined(VK_USE_PLATFORM_XLIB_KHR)
89-
virtual VkResult populate_surface_create_info(VkXlibSurfaceCreateInfoKHR * /* info */) const = 0;
90-
#elif defined(VK_USE_PLATFORM_XCB_KHR)
91-
virtual VkResult populate_surface_create_info(VkXcbSurfaceCreateInfoKHR * /* info */) const = 0;
92-
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
93-
virtual VkResult populate_surface_create_info(VkWaylandSurfaceCreateInfoKHR * /* info */) const = 0;
94-
#elif defined(VK_USE_PLATFORM_DISPLAY_KHR)
95-
virtual VkResult populate_surface_create_info(VkDisplaySurfaceCreateInfoKHR * /* info */) const = 0;
96-
#endif
79+
virtual VkResult create_surface(VkInstance instance, VkSurfaceKHR* surface) = 0;
9780
};
9881
} // namespace windows
9982
} // namespace components

components/windows/src/glfw.cpp

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <components/windows/glfw.hpp>
1919

20+
#include <vulkan/vulkan.h>
21+
2022
#include <GLFW/glfw3.h>
2123

2224
#ifdef VK_USE_PLATFORM_WIN32_KHR
@@ -469,36 +471,9 @@ void GLFWWindow::attach(events::EventBus &bus)
469471
m_touch_sender = bus.request_sender<events::TouchEvent>();
470472
}
471473

472-
#ifdef VK_USE_PLATFORM_WIN32_KHR
473-
VkResult GLFWWindow::populate_surface_create_info(VkWin32SurfaceCreateInfoKHR *o_info) const
474+
VkResult GLFWWindow::create_surface(VkInstance instance, VkSurfaceKHR *surface)
474475
{
475-
assert(o_info);
476-
477-
VkWin32SurfaceCreateInfoKHR info{};
478-
info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
479-
info.hwnd = glfwGetWin32Window(m_handle);
480-
481-
*o_info = info;
482-
483-
return VK_SUCCESS;
476+
return glfwCreateWindowSurface(instance, m_handle, nullptr, surface);
484477
}
485-
#endif
486-
487-
#ifdef VK_USE_PLATFORM_XLIB_KHR
488-
VkResult GLFWWindow::populate_surface_create_info(VkXlibSurfaceCreateInfoKHR *o_info) const
489-
{
490-
assert(o_info);
491-
492-
VkXlibSurfaceCreateInfoKHR info{};
493-
info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
494-
info.window = glfwGetX11Window(m_handle);
495-
info.dpy = glfwGetX11Display();
496-
497-
*o_info = info;
498-
499-
return VK_SUCCESS;
500-
}
501-
#endif
502-
503478
} // namespace windows
504479
} // namespace components

components/windows/src/headless.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <components/windows/headless.hpp>
1919

20+
#include <vulkan/vulkan.h>
21+
2022
namespace components
2123
{
2224
namespace windows
@@ -86,5 +88,10 @@ void HeadlessWindow::attach(events::EventBus &bus)
8688
m_position_sender = bus.request_sender<PositionChangedEvent>();
8789
}
8890

91+
VkResult HeadlessWindow::create_surface(VkInstance /* instance */, VkSurfaceKHR * /* surface */)
92+
{
93+
return VK_ERROR_INCOMPATIBLE_DISPLAY_KHR;
94+
}
95+
8996
} // namespace windows
9097
} // namespace components

third_party/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,16 @@ set_property(TARGET GenericCodeGen PROPERTY FOLDER "third_party")
259259
set_property(TARGET MachineIndependent PROPERTY FOLDER "third_party")
260260

261261
# spirv-cross
262-
add_subdirectory(spirv-cross)
263-
264-
set_property(TARGET spirv-cross PROPERTY FOLDER "third_party")
265-
set_property(TARGET spirv-cross-core PROPERTY FOLDER "third_party")
266-
set_property(TARGET spirv-cross-glsl PROPERTY FOLDER "third_party")
267-
set_property(TARGET spirv-cross-cpp PROPERTY FOLDER "third_party")
268-
set_property(TARGET spirv-cross-hlsl PROPERTY FOLDER "third_party")
269-
set_property(TARGET spirv-cross-msl PROPERTY FOLDER "third_party")
270-
set_property(TARGET spirv-cross-reflect PROPERTY FOLDER "third_party")
271-
set_property(TARGET spirv-cross-util PROPERTY FOLDER "third_party")
262+
# add_subdirectory(spirv-cross)
263+
264+
# set_property(TARGET spirv-cross PROPERTY FOLDER "ThirdParty")
265+
# set_property(TARGET spirv-cross-core PROPERTY FOLDER "ThirdParty")
266+
# set_property(TARGET spirv-cross-glsl PROPERTY FOLDER "ThirdParty")
267+
# set_property(TARGET spirv-cross-cpp PROPERTY FOLDER "ThirdParty")
268+
# set_property(TARGET spirv-cross-hlsl PROPERTY FOLDER "ThirdParty")
269+
# set_property(TARGET spirv-cross-msl PROPERTY FOLDER "ThirdParty")
270+
# set_property(TARGET spirv-cross-reflect PROPERTY FOLDER "ThirdParty")
271+
# set_property(TARGET spirv-cross-util PROPERTY FOLDER "ThirdParty")
272272

273273
# hwcpipe
274274
add_subdirectory(hwcpipe)

0 commit comments

Comments
 (0)