This repository was archived by the owner on Feb 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathremeshing_operator.hpp
148 lines (112 loc) · 5.33 KB
/
remeshing_operator.hpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2014-2023, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#pragma once
#include <micromesh/micromesh_displacement_remeshing.h>
#ifdef __cplusplus // GLSL Type
#include <glm/glm.hpp>
using namespace glm;
#endif
#include "shaders/remeshing_host_device.h"
#include "micromesh/micromesh_gpu.h"
#include "nvvk/images_vk.hpp"
#include "nvh/timesampler.hpp"
#include "nvvk/resourceallocator_vk.hpp"
#include "nvh/nvprint.hpp"
#include "nvvk/memallocator_vma_vk.hpp"
#include "vk_mem_alloc.h"
#include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/compute_vk.hpp"
#include "meshops/meshops_operations.h"
#include <array>
namespace meshops {
class RemeshingOperator_c
{
public:
bool create(Context context);
bool destroy(Context context);
micromesh::Result remesh(Context context,
const OpRemesh_input& input,
OpRemesh_modified& modified,
DeviceMesh modifiedMesh,
uint32_t* outputTriangleCount,
uint32_t* outputVertexCount);
std::vector<DeviceMesh> inputDeviceMeshes;
std::vector<DeviceMesh> modifiedDeviceMeshes;
std::vector<DeviceMesh> localDeviceMeshes;
private:
bool beginRemeshTask(Context context);
bool endRemeshTask(Context context);
bool m_isInitialized{false};
micromesh::gpu::GpuRemeshing m_remesher = nullptr;
micromesh::gpu::SetupInfo m_remesherSetupInfo;
micromesh::OpRemeshing_settings m_remesherParams;
struct PipelineLayout
{
VkPipelineLayout layout;
nvvk::DescriptorSetBindings bindings;
VkDescriptorSetLayout descriptorSetLayout{VK_NULL_HANDLE};
VkDescriptorPool descriptorPool{VK_NULL_HANDLE};
std::array<VkDescriptorSet, 8> descriptorSets;
uint32_t currentDescriptorSet;
VkDescriptorSet getNextDescriptorSet() { return descriptorSets[currentDescriptorSet++ % descriptorSets.size()]; }
};
std::vector<PipelineLayout> m_pipelineLayouts;
std::vector<nvvk::Buffer> m_scratchPersistentResources;
std::vector<VkPipeline> m_pipelines;
std::vector<VkPipeline> m_userPipelines;
std::vector<micromesh::gpu::ResourceInfo<micromesh::gpu::GpuRemeshingResource>> m_readResourceInfos;
std::vector<void*> m_readResourceDatas;
std::vector<uint64_t> m_readResourceSizes;
nvvk::Buffer m_globalConstantBuffer;
void createPipelineLayout(Context context, const micromesh::gpu::PipelineLayoutInfo& info, size_t index);
void createPipeline(Context context, const micromesh::gpu::PipelineInfo& info, size_t index);
void createRemesherResources(Context context, const OpRemesh_input& input, OpRemesh_modified& modified, DeviceMesh modifiedMesh);
void freeRemesherBuffers(Context context);
void copyMeshToRemesher(VkCommandBuffer cmd, const OpRemesh_input& inputs);
struct TaskBuffer
{
VkBuffer deviceBuffer{};
size_t size{0ull};
nvvk::Buffer hostVisibleBuffer{};
};
struct TaskData
{
std::vector<nvvk::Buffer> scratchTaskResources;
std::vector<TaskBuffer> allResourceHandles;
RemeshingOperator_c* sysData;
//SystemData* sysData;
VkCommandBuffer cmd;
micromesh::gpu::ReadResourceData<micromesh::gpu::GpuRemeshingResource> readData;
bool hadRead = false;
std::vector<std::vector<uint8_t>> hostReadBuffers;
meshops::Context context;
std::vector<nvvk::Buffer> localTaskResources;
} m_taskData;
micromesh::gpu::GpuRemeshingTask m_task = nullptr;
micromesh::gpu::CommandSequenceInfo<micromesh::gpu::GpuRemeshingResource> m_seq;
micromesh::gpu::GpuRemeshing_input m_input;
micromesh::gpu::GpuRemeshing_output m_output;
micromesh::RemeshingCurrentState m_currentState{};
nvvk::PushComputeDispatcher<VertexCopyConstants, VertexKernelBindings> m_vertexCopy;
nvvk::PushComputeDispatcher<VertexMergeConstants, VertexKernelBindings> m_vertexMerge;
meshops::MeshAttributeFlags m_preservedAttributes = {};
uint32_t m_primId{};
struct TriangleSubdivisionInfo
{
uint16_t edgeFlags;
uint16_t subdivLevel;
};
// FIXME: should be provided outside
float m_curvaturePower = 1.f;
uint32_t m_texcoordCount{};
uint32_t m_texcoordIndex{};
uint32_t m_heightmapTextureCoord = ~0u;
};
} // namespace meshops