Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
VulkanCommon.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#ifdef CORRELATION_USE_VULKAN
12#include <vulkan/vulkan.h>
13#endif
14
15#include <cstdint>
16#include <span>
17#include <stdexcept>
18#include <string>
19#include <string_view>
20
22
23#ifdef CORRELATION_USE_VULKAN
24
30inline void checkVkResult(VkResult result, std::string_view message) {
31 if (result != VK_SUCCESS) {
32 throw std::runtime_error(std::string(message) +
33 " (VkResult: " + std::to_string(static_cast<int>(result)) + ")");
34 }
35}
36
44inline uint32_t findMemoryType(VkPhysicalDevice physical_device, uint32_t type_filter,
45 VkMemoryPropertyFlags properties) {
46 VkPhysicalDeviceMemoryProperties mem_properties{};
47 vkGetPhysicalDeviceMemoryProperties(physical_device, &mem_properties);
48
49 const auto memory_types =
50 std::span(mem_properties.memoryTypes).subspan(0, mem_properties.memoryTypeCount);
51 for (uint32_t i = 0; i < mem_properties.memoryTypeCount; ++i) {
52 const bool is_type_set = (type_filter & (1U << i)) != 0;
53 const bool has_properties = (memory_types[i].propertyFlags & properties) == properties;
54 if (is_type_set && has_properties) {
55 return i;
56 }
57 }
58
59 throw std::runtime_error("Failed to find suitable Vulkan device memory type");
60}
61
62#endif // CORRELATION_USE_VULKAN
63
64} // namespace correlation::render3d::vulkan
Definition VulkanComputeService.hpp:24