mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 15:24:34 +00:00
Added glfw as git submodule + Catch2
Made the physical device, device, and swapchain builders take the required parameters as constructor arugments. Made tests optional using a cmake bool
This commit is contained in:
parent
d9ca075c86
commit
155677ec0f
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[submodule "ext/glfw"]
|
||||||
|
path = ext/glfw
|
||||||
|
url = https://github.com/glfw/glfw
|
||||||
|
[submodule "ext/Catch2"]
|
||||||
|
path = ext/Catch2
|
||||||
|
url = https://github.com/catchorg/Catch2
|
@ -3,10 +3,12 @@ project(VulkanBootstrap)
|
|||||||
|
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
find_package(glfw3)
|
|
||||||
|
|
||||||
add_library(vk-bootstrap
|
add_library(vk-bootstrap
|
||||||
src/VkBootstrap.h
|
src/VkBootstrap.h
|
||||||
|
src/Util.h
|
||||||
|
src/Instance.h
|
||||||
|
src/Device.h
|
||||||
|
src/Swapchain.h
|
||||||
src/Instance.cpp
|
src/Instance.cpp
|
||||||
src/Device.cpp
|
src/Device.cpp
|
||||||
src/Swapchain.cpp)
|
src/Swapchain.cpp)
|
||||||
@ -18,12 +20,16 @@ target_link_libraries(vk-bootstrap PRIVATE ${Vulkan_LIBRARIES})
|
|||||||
|
|
||||||
target_compile_features(vk-bootstrap PUBLIC cxx_std_11)
|
target_compile_features(vk-bootstrap PUBLIC cxx_std_11)
|
||||||
|
|
||||||
target_compile_options(vk-bootstrap PUBLIC -fsanitize=address)
|
option(VK_BOOTSTRAP_TEST "Test Vk-Bootstrap with glfw and Catch2" OFF)
|
||||||
target_link_options(vk-bootstrap PUBLIC -fsanitize=address)
|
|
||||||
|
|
||||||
|
if (VK_BOOTSTRAP_TEST)
|
||||||
|
|
||||||
|
add_subdirectory(ext/glfw)
|
||||||
|
add_subdirectory(ext/Catch2)
|
||||||
|
|
||||||
add_executable(vk-bootstrap-test tests/run_tests.cpp)
|
add_executable(vk-bootstrap-test tests/run_tests.cpp)
|
||||||
|
|
||||||
target_link_libraries(vk-bootstrap-test vk-bootstrap)
|
target_link_libraries(vk-bootstrap-test vk-bootstrap)
|
||||||
target_link_libraries(vk-bootstrap-test glfw)
|
target_link_libraries(vk-bootstrap-test glfw)
|
||||||
|
|
||||||
|
endif(VK_BOOTSTRAP_TEST)
|
1
ext/Catch2
Submodule
1
ext/Catch2
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 2d172dc688ffab0867a94928159e93384475a870
|
1
ext/glfw
Submodule
1
ext/glfw
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit d973acc123826666ecc9e6fd475682e3d84c54a6
|
@ -276,6 +276,13 @@ PhysicalDeviceSelector::Suitable PhysicalDeviceSelector::is_device_suitable (VkP
|
|||||||
return suitable;
|
return suitable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PhysicalDeviceSelector::PhysicalDeviceSelector (Instance instance)
|
||||||
|
{
|
||||||
|
info.instance = instance.instance;
|
||||||
|
info.headless = instance.headless;
|
||||||
|
criteria.require_present = !instance.headless;
|
||||||
|
}
|
||||||
|
|
||||||
detail::Expected<PhysicalDevice, VkResult> PhysicalDeviceSelector::select ()
|
detail::Expected<PhysicalDevice, VkResult> PhysicalDeviceSelector::select ()
|
||||||
{
|
{
|
||||||
auto physical_devices = detail::get_vector<VkPhysicalDevice> (vkEnumeratePhysicalDevices, info.instance);
|
auto physical_devices = detail::get_vector<VkPhysicalDevice> (vkEnumeratePhysicalDevices, info.instance);
|
||||||
@ -311,13 +318,6 @@ detail::Expected<PhysicalDevice, VkResult> PhysicalDeviceSelector::select ()
|
|||||||
return physical_device;
|
return physical_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicalDeviceSelector& PhysicalDeviceSelector::set_instance (Instance instance)
|
|
||||||
{
|
|
||||||
info.instance = instance.instance;
|
|
||||||
info.headless = instance.headless;
|
|
||||||
criteria.require_present = !instance.headless;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
PhysicalDeviceSelector& PhysicalDeviceSelector::set_surface (VkSurfaceKHR surface)
|
PhysicalDeviceSelector& PhysicalDeviceSelector::set_surface (VkSurfaceKHR surface)
|
||||||
{
|
{
|
||||||
info.surface = surface;
|
info.surface = surface;
|
||||||
@ -399,6 +399,8 @@ struct QueueFamily
|
|||||||
int32_t family;
|
int32_t family;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
};
|
};
|
||||||
|
DeviceBuilder::DeviceBuilder (PhysicalDevice device) { info.physical_device = device; }
|
||||||
|
|
||||||
detail::Expected<Device, VkResult> DeviceBuilder::build ()
|
detail::Expected<Device, VkResult> DeviceBuilder::build ()
|
||||||
{
|
{
|
||||||
auto& queue_properties = info.physical_device.queue_family_properties;
|
auto& queue_properties = info.physical_device.queue_family_properties;
|
||||||
@ -449,12 +451,6 @@ detail::Expected<Device, VkResult> DeviceBuilder::build ()
|
|||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceBuilder& DeviceBuilder::set_physical_device (PhysicalDevice const& phys_device)
|
|
||||||
{
|
|
||||||
info.physical_device = phys_device;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> DeviceBuilder& DeviceBuilder::add_pNext (T* structure)
|
template <typename T> DeviceBuilder& DeviceBuilder::add_pNext (T* structure)
|
||||||
{
|
{
|
||||||
if (info.pNext_chain == nullptr)
|
if (info.pNext_chain == nullptr)
|
||||||
|
@ -67,9 +67,10 @@ void populate_physical_device_details (PhysicalDevice physical_device);
|
|||||||
struct PhysicalDeviceSelector
|
struct PhysicalDeviceSelector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
PhysicalDeviceSelector (Instance instance);
|
||||||
|
|
||||||
detail::Expected<PhysicalDevice, VkResult> select ();
|
detail::Expected<PhysicalDevice, VkResult> select ();
|
||||||
|
|
||||||
PhysicalDeviceSelector& set_instance (Instance instance);
|
|
||||||
PhysicalDeviceSelector& set_surface (VkSurfaceKHR instance);
|
PhysicalDeviceSelector& set_surface (VkSurfaceKHR instance);
|
||||||
|
|
||||||
PhysicalDeviceSelector& prefer_discrete (bool prefer_discrete = true);
|
PhysicalDeviceSelector& prefer_discrete (bool prefer_discrete = true);
|
||||||
@ -145,10 +146,9 @@ void destroy_device (Device device);
|
|||||||
class DeviceBuilder
|
class DeviceBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DeviceBuilder (PhysicalDevice device);
|
||||||
detail::Expected<Device, VkResult> build ();
|
detail::Expected<Device, VkResult> build ();
|
||||||
|
|
||||||
DeviceBuilder& set_physical_device (PhysicalDevice const& phys_device);
|
|
||||||
|
|
||||||
template <typename T> DeviceBuilder& add_pNext (T* structure);
|
template <typename T> DeviceBuilder& add_pNext (T* structure);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -52,6 +52,14 @@ VkExtent2D choose_swap_extent (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
SwapchainBuilder::SwapchainBuilder (Device const& device)
|
||||||
|
{
|
||||||
|
info.device = device.device;
|
||||||
|
info.physical_device = device.physical_device;
|
||||||
|
info.surface = device.surface;
|
||||||
|
}
|
||||||
|
|
||||||
detail::Expected<Swapchain, VkResult> SwapchainBuilder::build ()
|
detail::Expected<Swapchain, VkResult> SwapchainBuilder::build ()
|
||||||
{
|
{
|
||||||
auto surface_support =
|
auto surface_support =
|
||||||
|
@ -26,12 +26,12 @@ struct Swapchain
|
|||||||
class SwapchainBuilder
|
class SwapchainBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
SwapchainBuilder (Device const& device);
|
||||||
|
|
||||||
detail::Expected<Swapchain, VkResult> build ();
|
detail::Expected<Swapchain, VkResult> build ();
|
||||||
detail::Expected<Swapchain, VkResult> recreate (Swapchain const& swapchain);
|
detail::Expected<Swapchain, VkResult> recreate (Swapchain const& swapchain);
|
||||||
void destroy (Swapchain const& swapchain);
|
void destroy (Swapchain const& swapchain);
|
||||||
|
|
||||||
SwapchainBuilder& set_device (Device const& device);
|
|
||||||
|
|
||||||
SwapchainBuilder& set_desired_format (VkFormat format);
|
SwapchainBuilder& set_desired_format (VkFormat format);
|
||||||
SwapchainBuilder& set_fallback_format (VkFormat format);
|
SwapchainBuilder& set_fallback_format (VkFormat format);
|
||||||
|
|
||||||
|
@ -37,13 +37,13 @@ int test_happy_path ()
|
|||||||
|
|
||||||
auto surface = create_surface_glfw (instance.instance, window);
|
auto surface = create_surface_glfw (instance.instance, window);
|
||||||
|
|
||||||
vkbs::PhysicalDeviceSelector phys_device_selector;
|
vkbs::PhysicalDeviceSelector phys_device_selector (instance);
|
||||||
auto phys_device_ret = phys_device_selector.set_instance (instance).set_surface (surface).select ();
|
auto phys_device_ret = phys_device_selector.set_surface (surface).select ();
|
||||||
if (!phys_device_ret) return -2; // couldn't select physical device
|
if (!phys_device_ret) return -2; // couldn't select physical device
|
||||||
vkbs::PhysicalDevice physical_device = phys_device_ret.value ();
|
vkbs::PhysicalDevice physical_device = phys_device_ret.value ();
|
||||||
|
|
||||||
vkbs::DeviceBuilder device_builder;
|
vkbs::DeviceBuilder device_builder (physical_device);
|
||||||
auto device_ret = device_builder.set_physical_device (physical_device).build ();
|
auto device_ret = device_builder.build ();
|
||||||
if (!device_ret) return -3; // couldn't create device
|
if (!device_ret) return -3; // couldn't create device
|
||||||
vkbs::Device device = device_ret.value ();
|
vkbs::Device device = device_ret.value ();
|
||||||
|
|
||||||
@ -110,9 +110,8 @@ int test_physical_device_selection ()
|
|||||||
auto window = create_window_glfw ();
|
auto window = create_window_glfw ();
|
||||||
auto surface = create_surface_glfw (instance.instance, window);
|
auto surface = create_surface_glfw (instance.instance, window);
|
||||||
|
|
||||||
vkbs::PhysicalDeviceSelector selector;
|
vkbs::PhysicalDeviceSelector selector (instance);
|
||||||
auto phys_dev_ret = selector.set_instance (instance)
|
auto phys_dev_ret = selector.set_surface (surface)
|
||||||
.set_surface (surface)
|
|
||||||
.add_desired_extension (VK_KHR_MULTIVIEW_EXTENSION_NAME)
|
.add_desired_extension (VK_KHR_MULTIVIEW_EXTENSION_NAME)
|
||||||
.add_required_extension (VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME)
|
.add_required_extension (VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME)
|
||||||
.set_minimum_version (1, 0)
|
.set_minimum_version (1, 0)
|
||||||
@ -135,12 +134,12 @@ int test_device_creation ()
|
|||||||
auto window = create_window_glfw ();
|
auto window = create_window_glfw ();
|
||||||
auto surface = create_surface_glfw (instance.instance, window);
|
auto surface = create_surface_glfw (instance.instance, window);
|
||||||
|
|
||||||
vkbs::PhysicalDeviceSelector selector;
|
vkbs::PhysicalDeviceSelector selector (instance);
|
||||||
auto phys_dev_ret = selector.set_instance (instance).set_surface (surface).select ();
|
auto phys_dev_ret = selector.set_surface (surface).select ();
|
||||||
auto phys_dev = phys_dev_ret.value ();
|
auto phys_dev = phys_dev_ret.value ();
|
||||||
|
|
||||||
vkbs::DeviceBuilder device_builder;
|
vkbs::DeviceBuilder device_builder (phys_dev);
|
||||||
auto dev_ret = device_builder.set_physical_device (phys_dev).build ();
|
auto dev_ret = device_builder.build ();
|
||||||
if (!dev_ret.has_value ())
|
if (!dev_ret.has_value ())
|
||||||
{
|
{
|
||||||
printf ("%s\n", dev_ret.error ().msg);
|
printf ("%s\n", dev_ret.error ().msg);
|
||||||
|
Loading…
Reference in New Issue
Block a user