PeriDyno 1.0.0
Loading...
Searching...
No Matches
GPUBuffer.h
Go to the documentation of this file.
1
16
17#pragma once
18
19#include "Buffer.h"
20#include <Array/Array.h>
21
22#include <Vector.h>
23#include <Matrix/Transform3x3.h>
25
26#ifdef CUDA_BACKEND
27struct cudaGraphicsResource;
28#endif
29
30#ifdef VK_BACKEND
31#include <VkDeviceArray.h>
32#endif
33
34namespace dyno
35{
36
37 // buffer for exchange data from simulation to rendering
38 // please note that we use additional buffer for r/w consistency between simulation and rendering loop
39 template<typename T>
40 class XBuffer : public Buffer
41 {
42 public:
43 // update OpenGL buffer within GL context
44 void updateGL();
45 // return number of elements
46 int count() const;
47
48 // load data to into an intermediate buffer
49 template<typename T1>
51 {
52#ifdef VK_BACKEND
53 this->loadVkBuffer(data.buffer(), data.bufferSize());
54#endif // VK_BACKEND
55
56#ifdef CUDA_BACKEND
57 buffer.assign(data);
58#endif // CUDA_BACKEND
59 }
60
61 private:
62
63#ifdef VK_BACKEND
64 VkBuffer buffer = VK_NULL_HANDLE;
65 VkDeviceMemory memory = VK_NULL_HANDLE;
66 int srcBufferSize = -1; // real size of the data
67 int allocatedSize = -1; // allocated buffer size
68#ifdef WIN32
69 HANDLE handle = nullptr; // The Win32 handle
70#else
71 int fd = -1;
72#endif
73 // command for copy buffer
74 VkCommandBuffer copyCmd = VK_NULL_HANDLE;
75
76 unsigned int memoryObject = 0; // OpenGL memory object
77 unsigned int tempBuffer = 0xffffffff; // temp buffer
78 bool resized = true;
79
80 void loadVkBuffer(VkBuffer src, int size);
81 void allocateVkBuffer(int size);
82
83#endif //VK_BACKEND
84
85
86#ifdef CUDA_BACKEND
87 dyno::DArray<T> buffer;
88 cudaGraphicsResource* resource = 0;
89#endif
90 };
91
92 template class XBuffer<dyno::Vec2f>;
93 template class XBuffer<dyno::Vec3f>;
94 template class XBuffer<dyno::Transform3f>;
95 template class XBuffer<dyno::TopologyModule::Edge>;
96 template class XBuffer<dyno::TopologyModule::Triangle>;
97}
int count() const
void load(dyno::DArray< T1 > data)
Definition GPUBuffer.h:50
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array< T, DeviceType::GPU > DArray
Definition Array.inl:89