26#ifdef CORRELATION_USE_VULKAN
28struct GpuHaloSettings {
30 float min_threshold{0.46F};
31 float max_threshold{0.58F};
32 float halo_radius_ratio{2.70F};
33 float halo_intensity{0.85F};
34 std::array<float, 4> halo_color{1.0F, 0.84F, 0.0F, 1.0F};
35 bool dim_non_matching{
false};
36 bool hide_non_matching{
false};
39struct GpuHistogramOutput {
40 std::array<uint32_t, 100> bins{};
41 uint32_t matching_count{0};
42 uint32_t total_count{0};
45class VulkanComputeService {
47 VulkanComputeService() =
default;
48 ~VulkanComputeService()
noexcept { cleanup(); }
50 VulkanComputeService(
const VulkanComputeService &) =
delete;
51 VulkanComputeService &operator=(
const VulkanComputeService &) =
delete;
53 [[nodiscard]]
bool initialize(VkDevice device, VkPhysicalDevice physical_device,
54 VkQueue compute_queue, uint32_t queue_family_index);
55 void cleanup()
noexcept;
64 bool evaluateOrderParametersAndApplyHalos(VkBuffer atom_positions_buffer,
65 VkBuffer atom_instance_buffer, uint32_t num_atoms,
66 const std::array<float, 4> &box_min,
67 const std::array<float, 4> &box_max,
float cutoff,
68 const GpuHaloSettings &settings,
69 GpuHistogramOutput &out_histogram,
70 std::vector<float> *out_descriptors =
nullptr);
76 [[nodiscard]]
bool computeDescriptorValues(
const std::vector<std::array<float, 4>> &positions,
77 const std::array<float, 4> &box_min,
78 const std::array<float, 4> &box_max,
float cutoff,
80 std::vector<float> &out_values);
82 [[nodiscard]]
bool isValid()
const noexcept {
return is_initialized_; }
85 void ensureBuffers(uint32_t num_atoms);
86 void ensureCellGridBuffers(uint32_t total_cells);
87 void recordCellListBuildPass(VkCommandBuffer cmd_buffer, VkBuffer atom_positions_buffer,
88 uint32_t num_atoms,
const std::array<float, 4> &box_min,
89 const std::array<float, 4> &box_max,
90 const std::array<int32_t, 4> &grid_dims, uint32_t total_cells);
91 void recordNeighborGridPass(VkCommandBuffer cmd_buffer, VkBuffer atom_positions_buffer,
92 uint32_t num_atoms,
const std::array<float, 4> &box_min,
93 const std::array<float, 4> &box_max,
94 const std::array<int32_t, 4> &grid_dims,
float cutoff,
95 uint32_t total_cells);
97 VkDevice device_{VK_NULL_HANDLE};
98 VkPhysicalDevice physical_device_{VK_NULL_HANDLE};
99 VkQueue queue_{VK_NULL_HANDLE};
100 uint32_t queue_family_{0};
101 VkCommandPool command_pool_{VK_NULL_HANDLE};
102 VkDescriptorPool descriptor_pool_{VK_NULL_HANDLE};
104 VulkanComputePipelineManager pipelines_;
106 VulkanBuffer cell_head_;
107 VulkanBuffer atom_next_;
108 VulkanBuffer neighbor_counts_;
109 VulkanBuffer neighbor_indices_;
110 VulkanBuffer descriptor_values_;
111 VulkanBuffer complex_harmonics_;
112 VulkanBuffer histogram_ssbo_;
113 VulkanBuffer histogram_readback_;
114 VulkanBuffer descriptor_readback_;
115 VulkanBuffer host_positions_buf_;
116 VulkanBuffer scratch_instances_buf_;
118 uint32_t allocated_atom_capacity_{0};
119 uint32_t allocated_cell_capacity_{0};
120 bool is_initialized_{
false};