假设我创建了树并初始化了它。 现在,我如何在 openCL 中将节点向量移动到 GPU?
struct BVHNode {
BoundingBox bbox;
BoundingSphere bsphere;
std::vector<int> obj_triangles; // Store triangle indices that is inside node's volume
int parentIndex; // Index of the parent node (-1 for root)
int level;
std::vector<int> childrenIndices; // Indices of the child nodes
}
class BVHTree {
public:
std::vector<BVHNode> nodes;
int maxDepth;
int nodeSize;
}
I tried to move like this
size_t dataSize = bvhTree.nodes.size() * sizeof(BVHNode);
cl::Buffer d_BVHtree_buf(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, dataSize, BVHTree.nodes.data());
but it didn't work.
GPU 既不支持函数递归,也不支持类,并且内存带宽对于 AoS 来说非常差(无合并)。
将树形数据结构扁平化为数组布局结构。您可能需要限制树深度并添加填充节点,以便数据索引规则间隔。或者,您可以使用间接寻址,这意味着添加一个额外的数组,其中包含节点的内存位置;这可以节省内存容量,但会破坏内存合并。您可以将固定深度递归作为函数调用的循环或链进行。