PeriDyno 1.0.0
Loading...
Searching...
No Matches
ArrayList.inl
Go to the documentation of this file.
1#include "VkDeviceArray.h"
2#include "VkUniform.h"
3
4#include "Catalyzer/VkScan.h"
6
7namespace dyno
8{
10 {
11 uint32_t arraySize = 0;
12 uint32_t totalSize = 0;
13 };
14
15 template<typename T>
16 class ArrayList<T, DeviceType::GPU>
17 {
18 public:
19 ArrayList();
20
25
26 void resize(const std::vector<uint32_t>& num);
27 void resize(const VkDeviceArray<uint32_t>& num);
28
29 void assign(const ArrayList<T, DeviceType::GPU>& src);
30 void assign(const ArrayList<T, DeviceType::CPU>& src);
31
32 uint32_t size() { return mIndex.size(); }
33 inline uint elementSize() const { return mElements.size(); }
34
35 const DArray<uint32_t>& index() const { return mIndex; }
36 const DArray<T>& elements() const { return mElements; }
37
38 inline bool isCPU() const { return false; }
39 inline bool isGPU() const { return true; }
40 inline bool isEmpty() const { return mIndex.size() == 0; }
41
42 void clear();
43
44 public:
47
49 };
50
51 template<typename T>
53
54 template<typename T>
56 {
57 mIndex.assign(src.index());
58 mElements.assign(src.elements());
59
60 mLists.resize(mIndex.size());
61
62 //redirect the element address
63 for (int i = 0; i < mIndex.size(); i++)
64 {
65 //mLists[i].reserve(mElements.begin() + mIndex[i], this->size(i));
66 uint num = size(i);
67 mLists[i].assign(mElements.begin() + mIndex[i], num, num);
68 }
69 }
70
71 template<typename T>
76
77 template<typename T>
78 void ArrayList<T, DeviceType::GPU>::resize(const std::vector<uint32_t>& num)
79 {
81 deviceNum.resize(num.size());
82
83 vkTransfer(deviceNum, num);
84
85 this->resize(deviceNum);
86
87 deviceNum.clear();
88 }
89
90 template<typename T>
92 {
93 mIndex.resize(num.size());
94
95 VkScan<uint32_t> mScan;
96 VkReduce<uint32_t> mReduce;
97
98 mScan.scan(*mIndex.handle(), num, EXCLUSIVESCAN);
99
100 uint32_t totalNum = mReduce.reduce(num);
101
102 mElements.resize(totalNum);
103
104 ArrayListInfo info;
105 info.arraySize = num.size();
106 info.totalSize = totalNum;
107
108 mInfo.setValue(info);
109 }
110
111 template<typename T>
116
117 template<typename T>
122
123 template<typename T>
125 {
126 mIndex.clear();
127 mElements.clear();
128 }
129
130}
#define EXCLUSIVESCAN
Definition VkScan.h:6
const DArray< uint32_t > & index() const
Definition ArrayList.inl:35
VkUniform< ArrayListInfo > mInfo
Definition ArrayList.inl:48
const DArray< T > & elements() const
Definition ArrayList.inl:36
void resize(const std::vector< uint32_t > &num)
Definition ArrayList.inl:78
~ArrayList()
Should not release data here, call Release() explicitly.
Definition ArrayList.inl:24
VkResizeType resize(uint32_t num, VkBufferUsageFlags usageFlags=0)
uint32_t size() const
implement functions for reducing a range to a single value
Definition VkReduce.h:12
T reduce(const std::vector< T > &input)
Definition VkReduce.inl:13
void scan(std::vector< T > &input, uint ScanType)
Definition VkScan.inl:10
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89
ArrayList< ElementType, DeviceType::GPU > DArrayList
Definition ArrayList.inl:83
unsigned int uint
Definition VkProgram.h:14
bool vkTransfer(VkHostArray< T > &dst, const VkDeviceArray< T > &src)
Definition VkTransfer.inl:7