-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangle_gas.h
78 lines (62 loc) · 2.49 KB
/
triangle_gas.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef __TRIANGLE_GAS_H__
#define __TRIANGLE_GAS_H__
#include <spdlog/spdlog.h>
#include <string>
#include <tuple>
#include "cuda_runtime_api.h"
#include "device.h"
#include "driver_types.h"
#include "optix_types.h"
#include "vector_types.h"
#include <imgui/imgui.h>
class TriangleGAS
{
public:
TriangleGAS(const Device &device, const std::string &filename);
TriangleGAS(const TriangleGAS &other) = delete;
TriangleGAS(TriangleGAS &&other) = delete;
void operator=(const TriangleGAS &other) = delete;
void operator=(TriangleGAS &&other) = delete;
~TriangleGAS();
[[nodiscard]] OptixTraversableHandle get_gas_handle() const noexcept { return m_gas_handle; }
[[nodiscard]] float3 *get_device_normals() const noexcept
{
spdlog::info("copy {} normals to device", m_normals.size());
float3 *ptr = nullptr;
cudaMalloc(reinterpret_cast<void **>(&ptr), sizeof(float3) * m_normals.size());
cudaMemcpy(reinterpret_cast<void *>(ptr),
reinterpret_cast<const void *>(m_normals.data()),
sizeof(float3) * m_normals.size(),
cudaMemcpyHostToDevice);
return ptr;
}
[[nodiscard]] float3 *get_device_vertices() const noexcept
{
spdlog::info("copy {} vertices to device", m_vertices.size());
float3 *ptr = nullptr;
cudaMalloc(reinterpret_cast<void **>(&ptr), sizeof(float3) * m_vertices.size());
cudaMemcpy(reinterpret_cast<void *>(ptr),
reinterpret_cast<const void *>(m_vertices.data()),
sizeof(float3) * m_vertices.size(),
cudaMemcpyHostToDevice);
return ptr;
}
[[nodiscard]] std::vector<int> const &get_mat_indices() const { return m_mat_indices; }
void imgui() const
{
if (ImGui::CollapsingHeader("Triangle GAS")) {
ImGui::Text("vertices: %d K", m_vertices.size() / 1000);
ImGui::Text("GAS buffer size: %d MB", m_gas_buffer_sizes.outputSizeInBytes / 1024 / 1024);
}
}
private:
OptixTraversableHandle m_gas_handle;
OptixAccelBufferSizes m_gas_buffer_sizes;
CUdeviceptr m_d_gas_output_buffer;
std::vector<float3> m_vertices;
std::vector<float3> m_normals;
std::vector<int> m_mat_indices;
};
std::tuple<std::vector<float3>, std::vector<float3>, std::vector<int>> load_assimp(const std::string &filename);
std::tuple<std::vector<float3>, std::vector<float3>, std::vector<int>> load_nbt(const std::string &filename);
#endif