Enabled warnings and fixes the warnings gcc/clang showed. Formatted CMakeLists.txt

This commit is contained in:
Charles Giessen 2020-03-07 22:58:23 -07:00
parent 10d9c2ee1b
commit 3097f46074
3 changed files with 77 additions and 46 deletions

View File

@ -7,19 +7,37 @@ add_library(vk-bootstrap src/VkBootstrap.h src/VkBootstrap.cpp)
target_include_directories(vk-bootstrap PUBLIC src) target_include_directories(vk-bootstrap PUBLIC src)
target_include_directories(vk-bootstrap PUBLIC ${Vulkan_INCLUDE_DIR}) target_include_directories(vk-bootstrap PRIVATE ${Vulkan_INCLUDE_DIR})
target_link_libraries(vk-bootstrap PUBLIC ${Vulkan_LIBRARY}) target_link_libraries(vk-bootstrap PRIVATE ${Vulkan_LIBRARY})
target_compile_features(vk-bootstrap PUBLIC cxx_std_11) target_compile_features(vk-bootstrap PUBLIC cxx_std_11)
target_compile_options(
vk-bootstrap
PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall
-Wextra
-pedantic-errors
-Wconversion
-Wsign-conversion>
$<$<CXX_COMPILER_ID:MSVC>:
/WX
/W4>)
option(VK_BOOTSTRAP_TEST "Test Vk-Bootstrap with glfw and Catch2" OFF) option(VK_BOOTSTRAP_TEST "Test Vk-Bootstrap with glfw and Catch2" OFF)
if(VK_BOOTSTRAP_TEST) if(VK_BOOTSTRAP_TEST)
set(GLFW_BUILD_TESTS
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) OFF
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_DOCS
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) OFF
CACHE BOOL "" FORCE)
set(GLFW_INSTALL
OFF
CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES
OFF
CACHE BOOL "" FORCE)
add_subdirectory(ext/glfw) add_subdirectory(ext/glfw)
add_subdirectory(ext/Catch2) add_subdirectory(ext/Catch2)
@ -34,8 +52,10 @@ if (VK_BOOTSTRAP_TEST)
target_link_libraries(vk-bootstrap-triangle glfw) target_link_libraries(vk-bootstrap-triangle glfw)
add_custom_command( add_custom_command(
TARGET vk-bootstrap-triangle POST_BUILD TARGET vk-bootstrap-triangle
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/example/shaders ${CMAKE_CURRENT_BINARY_DIR} POST_BUILD
DEPENDS ${CMAKE_CURRENT_BINARY_DIR} COMMAND
) ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/example/shaders ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR})
endif() endif()

View File

@ -112,6 +112,8 @@ VkBool32 default_debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageS
auto ms = to_string_message_severity (messageSeverity); auto ms = to_string_message_severity (messageSeverity);
auto mt = to_string_message_type (messageType); auto mt = to_string_message_type (messageType);
printf ("[%s: %s]\n%s\n", ms, mt, pCallbackData->pMessage); printf ("[%s: %s]\n%s\n", ms, mt, pCallbackData->pMessage);
assert (pUserData == nullptr && "Default debug callback should have no user data");
return VK_FALSE; return VK_FALSE;
} }
@ -159,7 +161,7 @@ template <typename T>
void setup_pNext_chain (T& structure, std::vector<VkBaseOutStructure*> const& structs) { void setup_pNext_chain (T& structure, std::vector<VkBaseOutStructure*> const& structs) {
structure.pNext = nullptr; structure.pNext = nullptr;
if (structs.size () <= 0) return; if (structs.size () <= 0) return;
for (int i = 0; i < structs.size () - 1; i++) { for (size_t i = 0; i < structs.size () - 1; i++) {
structs.at (i)->pNext = structs.at (i + 1); structs.at (i)->pNext = structs.at (i + 1);
} }
structure.pNext = structs.at (0); structure.pNext = structs.at (0);
@ -339,9 +341,11 @@ detail::Expected<Instance, detail::Error<InstanceError>> InstanceBuilder::build
if (info.enabled_validation_features.size () != 0 || info.disabled_validation_features.size ()) { if (info.enabled_validation_features.size () != 0 || info.disabled_validation_features.size ()) {
features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT; features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT;
features.pNext = nullptr; features.pNext = nullptr;
features.enabledValidationFeatureCount = info.enabled_validation_features.size (); features.enabledValidationFeatureCount =
static_cast<uint32_t> (info.enabled_validation_features.size ());
features.pEnabledValidationFeatures = info.enabled_validation_features.data (); features.pEnabledValidationFeatures = info.enabled_validation_features.data ();
features.disabledValidationFeatureCount = info.disabled_validation_features.size (); features.disabledValidationFeatureCount =
static_cast<uint32_t> (info.disabled_validation_features.size ());
features.pDisabledValidationFeatures = info.disabled_validation_features.data (); features.pDisabledValidationFeatures = info.disabled_validation_features.data ();
pNext_chain.push_back (reinterpret_cast<VkBaseOutStructure*> (&features)); pNext_chain.push_back (reinterpret_cast<VkBaseOutStructure*> (&features));
} }
@ -350,7 +354,8 @@ detail::Expected<Instance, detail::Error<InstanceError>> InstanceBuilder::build
if (info.disabled_validation_checks.size () != 0) { if (info.disabled_validation_checks.size () != 0) {
checks.sType = VK_STRUCTURE_TYPE_VALIDATION_FLAGS_EXT; checks.sType = VK_STRUCTURE_TYPE_VALIDATION_FLAGS_EXT;
checks.pNext = nullptr; checks.pNext = nullptr;
checks.disabledValidationCheckCount = info.disabled_validation_checks.size (); checks.disabledValidationCheckCount =
static_cast<uint32_t> (info.disabled_validation_checks.size ());
checks.pDisabledValidationChecks = info.disabled_validation_checks.data (); checks.pDisabledValidationChecks = info.disabled_validation_checks.data ();
pNext_chain.push_back (reinterpret_cast<VkBaseOutStructure*> (&checks)); pNext_chain.push_back (reinterpret_cast<VkBaseOutStructure*> (&checks));
} }
@ -597,8 +602,8 @@ bool supports_features (VkPhysicalDeviceFeatures supported, VkPhysicalDeviceFeat
// finds the first queue which supports graphics operations. returns -1 if none is found // finds the first queue which supports graphics operations. returns -1 if none is found
int get_graphics_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_graphics_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
if (families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) return i; if (families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) return static_cast<int> (i);
} }
return -1; return -1;
} }
@ -606,13 +611,13 @@ int get_graphics_queue_index (std::vector<VkQueueFamilyProperties> const& famili
// transfer support returns -1 if none is found // transfer support returns -1 if none is found
int get_separate_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_separate_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
int compute = -1; int compute = -1;
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) && if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) &&
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) { ((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0) { if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0) {
return i; return static_cast<int> (i);
} else { } else {
compute = i; compute = static_cast<int> (i);
} }
} }
} }
@ -622,13 +627,13 @@ int get_separate_compute_queue_index (std::vector<VkQueueFamilyProperties> const
// compute support returns -1 if none is found // compute support returns -1 if none is found
int get_separate_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_separate_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
int transfer = -1; int transfer = -1;
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) && if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) &&
((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) { ((families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)) {
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) { if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
return i; return static_cast<int> (i);
} else { } else {
transfer = i; transfer = static_cast<int> (i);
} }
} }
} }
@ -636,21 +641,21 @@ int get_separate_transfer_queue_index (std::vector<VkQueueFamilyProperties> cons
} }
// finds the first queue which supports only compute (not graphics or transfer). returns -1 if none is found // finds the first queue which supports only compute (not graphics or transfer). returns -1 if none is found
int get_dedicated_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_dedicated_compute_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) && if ((families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) &&
(families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0 && (families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0 &&
(families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0) (families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) == 0)
return i; return static_cast<int> (i);
} }
return -1; return -1;
} }
// finds the first queue which supports only transfer (not graphics or compute). returns -1 if none is found // finds the first queue which supports only transfer (not graphics or compute). returns -1 if none is found
int get_dedicated_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) { int get_dedicated_transfer_queue_index (std::vector<VkQueueFamilyProperties> const& families) {
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) && if ((families[i].queueFlags & VK_QUEUE_TRANSFER_BIT) &&
(families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0 && (families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0 &&
(families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) (families[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0)
return i; return static_cast<int> (i);
} }
return -1; return -1;
} }
@ -658,12 +663,14 @@ int get_dedicated_transfer_queue_index (std::vector<VkQueueFamilyProperties> con
int get_present_queue_index (VkPhysicalDevice const phys_device, int get_present_queue_index (VkPhysicalDevice const phys_device,
VkSurfaceKHR const surface, VkSurfaceKHR const surface,
std::vector<VkQueueFamilyProperties> const& families) { std::vector<VkQueueFamilyProperties> const& families) {
for (int i = 0; i < families.size (); i++) { for (size_t i = 0; i < families.size (); i++) {
VkBool32 presentSupport = false; VkBool32 presentSupport = false;
if (surface != VK_NULL_HANDLE) { if (surface != VK_NULL_HANDLE) {
VkResult res = vkGetPhysicalDeviceSurfaceSupportKHR (phys_device, i, surface, &presentSupport); VkResult res = vkGetPhysicalDeviceSurfaceSupportKHR (
phys_device, static_cast<uint32_t> (i), surface, &presentSupport);
if (res != VK_SUCCESS) return -1; // TODO: determine if this should fail another way
} }
if (presentSupport == true) return i; if (presentSupport == true) return static_cast<int> (i);
} }
return -1; return -1;
} }
@ -740,7 +747,7 @@ PhysicalDeviceSelector::Suitable PhysicalDeviceSelector::is_device_suitable (Phy
bool has_required_memory = false; bool has_required_memory = false;
bool has_preferred_memory = false; bool has_preferred_memory = false;
for (int i = 0; i < pd.mem_properties.memoryHeapCount; i++) { for (uint32_t i = 0; i < pd.mem_properties.memoryHeapCount; i++) {
if (pd.mem_properties.memoryHeaps[i].flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { if (pd.mem_properties.memoryHeaps[i].flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
if (pd.mem_properties.memoryHeaps[i].size > criteria.required_mem_size) { if (pd.mem_properties.memoryHeaps[i].size > criteria.required_mem_size) {
has_required_memory = true; has_required_memory = true;
@ -905,7 +912,7 @@ bool PhysicalDevice::has_separate_transfer_queue () const {
// ---- Queues ---- // // ---- Queues ---- //
detail::Expected<int32_t, detail::Error<QueueError>> Device::get_queue_index (QueueType type) const { detail::Expected<uint32_t, detail::Error<QueueError>> Device::get_queue_index (QueueType type) const {
int index = -1; int index = -1;
switch (type) { switch (type) {
case QueueType::present: case QueueType::present:
@ -927,9 +934,9 @@ detail::Expected<int32_t, detail::Error<QueueError>> Device::get_queue_index (Qu
default: default:
return detail::Error<QueueError>{ QueueError::invalid_queue_family_index }; return detail::Error<QueueError>{ QueueError::invalid_queue_family_index };
} }
return index; return static_cast<uint32_t> (index);
} }
detail::Expected<int32_t, detail::Error<QueueError>> Device::get_dedicated_queue_index (QueueType type) const { detail::Expected<uint32_t, detail::Error<QueueError>> Device::get_dedicated_queue_index (QueueType type) const {
int index = -1; int index = -1;
switch (type) { switch (type) {
case QueueType::compute: case QueueType::compute:
@ -943,10 +950,10 @@ detail::Expected<int32_t, detail::Error<QueueError>> Device::get_dedicated_queue
default: default:
return detail::Error<QueueError>{ QueueError::invalid_queue_family_index }; return detail::Error<QueueError>{ QueueError::invalid_queue_family_index };
} }
return index; return static_cast<uint32_t> (index);
} }
namespace detail { namespace detail {
VkQueue get_queue (VkDevice device, int32_t family) { VkQueue get_queue (VkDevice device, uint32_t family) {
VkQueue out_queue; VkQueue out_queue;
vkGetDeviceQueue (device, family, 0, &out_queue); vkGetDeviceQueue (device, family, 0, &out_queue);
return out_queue; return out_queue;
@ -1074,9 +1081,7 @@ VkExtent2D find_extent (
if (capabilities.currentExtent.width != UINT32_MAX) { if (capabilities.currentExtent.width != UINT32_MAX) {
return capabilities.currentExtent; return capabilities.currentExtent;
} else { } else {
const int WIDTH = 800; VkExtent2D actualExtent = { desired_width, desired_height };
const int HEIGHT = 600;
VkExtent2D actualExtent = { WIDTH, HEIGHT };
actualExtent.width = maximum (capabilities.minImageExtent.width, actualExtent.width = maximum (capabilities.minImageExtent.width,
minimum (capabilities.maxImageExtent.width, actualExtent.width)); minimum (capabilities.maxImageExtent.width, actualExtent.width));
@ -1173,7 +1178,7 @@ detail::Expected<Swapchain, detail::Error<SwapchainError>> SwapchainBuilder::bui
swapchain.image_format = surface_format.format; swapchain.image_format = surface_format.format;
swapchain.extent = extent; swapchain.extent = extent;
auto images = get_swapchain_images (swapchain); auto images = get_swapchain_images (swapchain);
swapchain.image_count = images.value ().size (); swapchain.image_count = static_cast<uint32_t> (images.value ().size ());
swapchain.allocation_callbacks = info.allocation_callbacks; swapchain.allocation_callbacks = info.allocation_callbacks;
return swapchain; return swapchain;
} }
@ -1224,7 +1229,11 @@ void destroy_swapchain (Swapchain const& swapchain) {
if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE) if (swapchain.device != VK_NULL_HANDLE && swapchain.swapchain != VK_NULL_HANDLE)
vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks); vkDestroySwapchainKHR (swapchain.device, swapchain.swapchain, swapchain.allocation_callbacks);
} }
SwapchainBuilder& SwapchainBuilder::set_desired_extent (uint32_t width, uint32_t height) {
info.desired_width = width;
info.desired_height = height;
return *this;
}
SwapchainBuilder& SwapchainBuilder::set_desired_format (VkSurfaceFormatKHR format) { SwapchainBuilder& SwapchainBuilder::set_desired_format (VkSurfaceFormatKHR format) {
info.desired_formats.insert (info.desired_formats.begin (), format); info.desired_formats.insert (info.desired_formats.begin (), format);
return *this; return *this;

View File

@ -424,9 +424,9 @@ struct Device {
std::vector<VkQueueFamilyProperties> queue_families; std::vector<VkQueueFamilyProperties> queue_families;
VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE; VkAllocationCallbacks* allocation_callbacks = VK_NULL_HANDLE;
detail::Expected<int32_t, detail::Error<QueueError>> get_queue_index (QueueType type) const; detail::Expected<uint32_t, detail::Error<QueueError>> get_queue_index (QueueType type) const;
// Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue index // Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue index
detail::Expected<int32_t, detail::Error<QueueError>> get_dedicated_queue_index (QueueType type) const; detail::Expected<uint32_t, detail::Error<QueueError>> get_dedicated_queue_index (QueueType type) const;
detail::Expected<VkQueue, detail::Error<QueueError>> get_queue (QueueType type) const; detail::Expected<VkQueue, detail::Error<QueueError>> get_queue (QueueType type) const;
// Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue // Only a compute or transfer queue type is valid. All other queue types do not support a 'dedicated' queue
@ -504,6 +504,8 @@ class SwapchainBuilder {
detail::Expected<Swapchain, detail::Error<SwapchainError>> build () const; detail::Expected<Swapchain, detail::Error<SwapchainError>> build () const;
detail::Expected<Swapchain, detail::Error<SwapchainError>> recreate (Swapchain const& swapchain) const; detail::Expected<Swapchain, detail::Error<SwapchainError>> recreate (Swapchain const& swapchain) const;
SwapchainBuilder& set_desired_extent (uint32_t width, uint32_t height);
SwapchainBuilder& set_desired_format (VkSurfaceFormatKHR format); SwapchainBuilder& set_desired_format (VkSurfaceFormatKHR format);
SwapchainBuilder& add_fallback_format (VkSurfaceFormatKHR format); SwapchainBuilder& add_fallback_format (VkSurfaceFormatKHR format);
SwapchainBuilder& use_default_format_selection (); SwapchainBuilder& use_default_format_selection ();