Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
VulkanComputeService.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#ifdef CORRELATION_USE_VULKAN
14#include <vulkan/vulkan.h>
15#endif
16
18#include <array>
19#include <cstdint>
20#include <memory>
21#include <span>
22#include <vector>
23
25
26#ifdef CORRELATION_USE_VULKAN
27
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};
37};
38
39struct GpuHistogramOutput {
40 std::array<uint32_t, 100> bins{};
41 uint32_t matching_count{0};
42 uint32_t total_count{0};
43};
44
45class VulkanComputeService {
46public:
47 VulkanComputeService() = default;
48 ~VulkanComputeService() noexcept { cleanup(); }
49
50 VulkanComputeService(const VulkanComputeService &) = delete;
51 VulkanComputeService &operator=(const VulkanComputeService &) = delete;
52
53 [[nodiscard]] bool initialize(VkDevice device, VkPhysicalDevice physical_device,
54 VkQueue compute_queue, uint32_t queue_family_index);
55 void cleanup() noexcept;
56
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);
71
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,
79 app::PhaseDescriptor descriptor,
80 std::vector<float> &out_values);
81
82 [[nodiscard]] bool isValid() const noexcept { return is_initialized_; }
83
84private:
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);
96
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};
103
104 VulkanComputePipelineManager pipelines_;
105
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_;
117
118 uint32_t allocated_atom_capacity_{0};
119 uint32_t allocated_cell_capacity_{0};
120 bool is_initialized_{false};
121};
122
123#endif // CORRELATION_USE_VULKAN
124
125} // namespace correlation::render3d::vulkan
Data types, descriptor enums, crystal presets, and telemetry models for Phase Search.
RAII encapsulation of a Vulkan buffer and its associated device memory.
Manages Vulkan compute pipelines for GPU order parameter and halo evaluation.
PhaseDescriptor
Bond-orientational order parameter descriptors available for phase filtering.
Definition PhaseSearchTypes.hpp:23
@ Q6Bar
Lechner-Dellago averaged q̄₆ (primary crystal symmetry descriptor).
Definition PhaseSearchTypes.hpp:24
Definition VulkanComputeService.hpp:24