Compare commits

..

No commits in common. "6ed76af2100247cb14aaa5b5c14fda619d605d18" and "020993fb19b326adb692ff2aa2635936078f82a7" have entirely different histories.

View file

@ -203,11 +203,6 @@ image::Bl dither::blue_noise(int width, int height, int threads,
VK_EXTENSIONS.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); VK_EXTENSIONS.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
#endif // VULKAN_VALIDATION == 1 #endif // VULKAN_VALIDATION == 1
VkInstance instance;
utility::Cleanup cleanup_vk_instance{};
VkDebugUtilsMessengerEXT debug_messenger;
utility::Cleanup cleanup_debug_messenger{};
{
VkApplicationInfo app_info{}; VkApplicationInfo app_info{};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pApplicationName = "Blue Noise Generation"; app_info.pApplicationName = "Blue Noise Generation";
@ -230,8 +225,7 @@ image::Bl dither::blue_noise(int width, int height, int threads,
const auto populate_debug_info = const auto populate_debug_info =
[](VkDebugUtilsMessengerCreateInfoEXT *info) { [](VkDebugUtilsMessengerCreateInfoEXT *info) {
info->sType = info->sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
info->messageSeverity = info->messageSeverity =
VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
@ -249,28 +243,30 @@ image::Bl dither::blue_noise(int width, int height, int threads,
create_info.enabledLayerCount = 0; create_info.enabledLayerCount = 0;
create_info.pNext = nullptr; create_info.pNext = nullptr;
#endif // VULKAN_VALIDATION == 1 #endif // VULKAN_VALIDATION == 1
VkInstance instance;
if (vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS) { if (vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS) {
std::clog << "WARNING: Failed to create Vulkan instance!\n"; std::clog << "WARNING: Failed to create Vulkan instance!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
} }
cleanup_vk_instance = utility::Cleanup( utility::Cleanup cleanup_vk_instance(
[](void *ptr) { vkDestroyInstance(*((VkInstance *)ptr), nullptr); }, [](void *ptr) { vkDestroyInstance(*((VkInstance *)ptr), nullptr); },
&instance); &instance);
#if VULKAN_VALIDATION == 1 #if VULKAN_VALIDATION == 1
populate_debug_info(&debug_create_info); populate_debug_info(&debug_create_info);
VkDebugUtilsMessengerEXT debug_messenger;
auto create_debug_utils_messenger_func = auto create_debug_utils_messenger_func =
(PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr( (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
instance, "vkCreateDebugUtilsMessengerEXT"); instance, "vkCreateDebugUtilsMessengerEXT");
if (create_debug_utils_messenger_func != nullptr && if (create_debug_utils_messenger_func != nullptr &&
create_debug_utils_messenger_func(instance, &debug_create_info, create_debug_utils_messenger_func(instance, &debug_create_info, nullptr,
nullptr,
&debug_messenger) != VK_SUCCESS) { &debug_messenger) != VK_SUCCESS) {
std::clog << "WARNING: Failed to set up Vulkan debug messenger!\n"; std::clog << "WARNING: Failed to set up Vulkan debug messenger!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
} }
cleanup_debug_messenger = utility::Cleanup( utility::Cleanup cleanup_debug_messenger(
[instance](void *ptr) { [instance](void *ptr) {
auto func = auto func =
(PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr( (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
@ -281,10 +277,6 @@ image::Bl dither::blue_noise(int width, int height, int threads,
}, },
&debug_messenger); &debug_messenger);
#endif // VULKAN_VALIDATION == 1 #endif // VULKAN_VALIDATION == 1
}
VkPhysicalDevice phys_device;
{
uint32_t device_count = 0; uint32_t device_count = 0;
vkEnumeratePhysicalDevices(instance, &device_count, nullptr); vkEnumeratePhysicalDevices(instance, &device_count, nullptr);
if (device_count == 0) { if (device_count == 0) {
@ -312,22 +304,18 @@ image::Bl dither::blue_noise(int width, int height, int threads,
} }
} }
VkPhysicalDevice phys_device;
if (gpu_dev_discrete.has_value()) { if (gpu_dev_discrete.has_value()) {
std::clog << "NOTICE: Found discrete GPU supporting Vulkan compute.\n"; std::clog << "NOTICE: Found discrete GPU supporting Vulkan compute.\n";
phys_device = gpu_dev_discrete.value(); phys_device = gpu_dev_discrete.value();
} else if (gpu_dev_integrated.has_value()) { } else if (gpu_dev_integrated.has_value()) {
std::clog std::clog << "NOTICE: Found integrated GPU supporting Vulkan compute.\n";
<< "NOTICE: Found integrated GPU supporting Vulkan compute.\n";
phys_device = gpu_dev_integrated.value(); phys_device = gpu_dev_integrated.value();
} else { } else {
std::clog << "WARNING: No suitable GPUs found!\n"; std::clog << "WARNING: No suitable GPUs found!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
} }
}
VkDevice device;
utility::Cleanup device_cleanup{};
{
auto indices = find_queue_families(phys_device); auto indices = find_queue_families(phys_device);
std::vector<VkDeviceQueueCreateInfo> queue_create_infos; std::vector<VkDeviceQueueCreateInfo> queue_create_infos;
std::unordered_set<uint32_t> unique_queue_families = { std::unordered_set<uint32_t> unique_queue_families = {
@ -362,24 +350,19 @@ image::Bl dither::blue_noise(int width, int height, int threads,
dev_create_info.enabledLayerCount = 0; dev_create_info.enabledLayerCount = 0;
#endif #endif
VkDevice device;
if (vkCreateDevice(phys_device, &dev_create_info, nullptr, &device) != if (vkCreateDevice(phys_device, &dev_create_info, nullptr, &device) !=
VK_SUCCESS) { VK_SUCCESS) {
std::clog << "WARNING: Failed to create VkDevice!\n"; std::clog << "WARNING: Failed to create VkDevice!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
} }
device_cleanup = utility::Cleanup( utility::Cleanup device_cleanup(
[](void *ptr) { vkDestroyDevice(*((VkDevice *)ptr), nullptr); }, [](void *ptr) { vkDestroyDevice(*((VkDevice *)ptr), nullptr); },
&device); &device);
}
VkQueue compute_queue; VkQueue compute_queue;
vkGetDeviceQueue(device, vkGetDeviceQueue(device, indices.computeFamily.value(), 0, &compute_queue);
find_queue_families(phys_device).computeFamily.value(), 0,
&compute_queue);
VkDescriptorSetLayout compute_desc_set_layout;
utility::Cleanup compute_desc_set_layout_cleanup{};
{
std::array<VkDescriptorSetLayoutBinding, 4> compute_layout_bindings{}; std::array<VkDescriptorSetLayoutBinding, 4> compute_layout_bindings{};
compute_layout_bindings[0].binding = 0; compute_layout_bindings[0].binding = 0;
compute_layout_bindings[0].descriptorCount = 1; compute_layout_bindings[0].descriptorCount = 1;
@ -414,19 +397,18 @@ image::Bl dither::blue_noise(int width, int height, int threads,
layout_info.bindingCount = compute_layout_bindings.size(); layout_info.bindingCount = compute_layout_bindings.size();
layout_info.pBindings = compute_layout_bindings.data(); layout_info.pBindings = compute_layout_bindings.data();
VkDescriptorSetLayout compute_desc_set_layout;
if (vkCreateDescriptorSetLayout(device, &layout_info, nullptr, if (vkCreateDescriptorSetLayout(device, &layout_info, nullptr,
&compute_desc_set_layout) != VK_SUCCESS) { &compute_desc_set_layout) != VK_SUCCESS) {
std::clog std::clog << "WARNING: Failed to create compute descriptor set layout!\n";
<< "WARNING: Failed to create compute descriptor set layout!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
} }
compute_desc_set_layout_cleanup = utility::Cleanup( utility::Cleanup compute_desc_set_layout_cleanup(
[device](void *ptr) { [device](void *ptr) {
vkDestroyDescriptorSetLayout( vkDestroyDescriptorSetLayout(device, *((VkDescriptorSetLayout *)ptr),
device, *((VkDescriptorSetLayout *)ptr), nullptr); nullptr);
}, },
&compute_desc_set_layout); &compute_desc_set_layout);
}
// Check and compile compute shader. // Check and compile compute shader.
{ {
@ -544,8 +526,7 @@ image::Bl dither::blue_noise(int width, int height, int threads,
VkCommandPoolCreateInfo pool_info{}; VkCommandPoolCreateInfo pool_info{};
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; pool_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
pool_info.queueFamilyIndex = pool_info.queueFamilyIndex = indices.computeFamily.value();
find_queue_families(phys_device).computeFamily.value();
if (vkCreateCommandPool(device, &pool_info, nullptr, &command_pool) != if (vkCreateCommandPool(device, &pool_info, nullptr, &command_pool) !=
VK_SUCCESS) { VK_SUCCESS) {