-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathresources_vk.hpp
245 lines (184 loc) · 7.25 KB
/
resources_vk.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: Copyright (c) 2016-2022 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "cadscene_vk.hpp"
#include "resources.hpp"
#include <nvvk/context_vk.hpp>
#include <nvvk/profiler_vk.hpp>
#include <nvvk/shadermodulemanager_vk.hpp>
#include <nvvk/swapchain_vk.hpp>
#include <nvvk/buffers_vk.hpp>
#include <nvvk/commands_vk.hpp>
#include <nvvk/descriptorsets_vk.hpp>
#include <nvvk/error_vk.hpp>
#include <nvvk/memorymanagement_vk.hpp>
#include <nvvk/renderpasses_vk.hpp>
#include "vk_ext_mesh_shader.h"
class NVPWindow;
#define DSET_COUNT 3
namespace meshlettest {
class ResourcesVK : public Resources
{
public:
// must be static because we are changing resource object during ui events
// while imgui resources must remain unchanged over app's lifetime
static VkRenderPass s_passUI;
static void initImGui(const nvvk::Context& context);
static void deinitImGui(const nvvk::Context& context);
struct FrameBuffer
{
int renderWidth = 0;
int renderHeight = 0;
int supersample = 0;
bool useResolved = false;
bool vsync = false;
int msaa = 0;
VkViewport viewport{};
VkViewport viewportUI{};
VkRect2D scissor{};
VkRect2D scissorUI{};
VkRenderPass passClear = VK_NULL_HANDLE;
VkRenderPass passPreserve = VK_NULL_HANDLE;
VkFramebuffer fboScene = VK_NULL_HANDLE;
VkFramebuffer fboUI = VK_NULL_HANDLE;
VkImage imgColor = VK_NULL_HANDLE;
VkImage imgColorResolved = VK_NULL_HANDLE;
VkImage imgDepthStencil = VK_NULL_HANDLE;
VkImageView viewColor = VK_NULL_HANDLE;
VkImageView viewColorResolved = VK_NULL_HANDLE;
VkImageView viewDepthStencil = VK_NULL_HANDLE;
nvvk::DeviceMemoryAllocator memAllocator;
};
struct Common
{
nvvk::AllocationID viewAID;
VkBuffer viewBuffer{};
VkDescriptorBufferInfo viewInfo{};
nvvk::AllocationID statsAID;
VkBuffer statsBuffer{};
VkDescriptorBufferInfo statsInfo{};
nvvk::AllocationID statsReadAID;
VkBuffer statsReadBuffer{};
VkDescriptorBufferInfo statsReadInfo{};
};
struct MeshShaderModuleIDs
{
nvvk::ShaderModuleID task;
nvvk::ShaderModuleID mesh_fragment;
nvvk::ShaderModuleID mesh;
nvvk::ShaderModuleID task_mesh;
nvvk::ShaderModuleID cull_mesh;
nvvk::ShaderModuleID cull_task_mesh;
};
struct ShaderModuleIDs
{
nvvk::ShaderModuleID standard_vertex;
nvvk::ShaderModuleID standard_fragment;
MeshShaderModuleIDs meshNV;
MeshShaderModuleIDs meshEXT;
nvvk::ShaderModuleID bbox_vertex;
nvvk::ShaderModuleID bbox_geometry;
nvvk::ShaderModuleID bbox_fragment;
};
struct DrawSetup
{
VkPipeline pipeline = VK_NULL_HANDLE;
VkPipeline pipelineTask = VK_NULL_HANDLE;
VkPipeline pipelineCull = VK_NULL_HANDLE;
VkPipeline pipelineCullTask = VK_NULL_HANDLE;
nvvk::TDescriptorSetContainer<DSET_COUNT> container;
};
bool m_withinFrame = false;
bool m_supportsMeshNV = false;
bool m_supportsMeshEXT = false;
nvvk::ShaderModuleManager m_shaderManager;
ShaderModuleIDs m_shaders;
const nvvk::SwapChain* m_swapChain{};
const nvvk::Context* m_context = nullptr;
VkDevice m_device = VK_NULL_HANDLE;
VkPhysicalDevice m_physical{};
VkQueue m_queue{};
uint32_t m_queueFamily{};
nvvk::DeviceMemoryAllocator m_memAllocator;
nvvk::RingFences m_ringFences;
nvvk::RingCommandPool m_ringCmdPool;
nvvk::BatchSubmission m_submission;
bool m_submissionWaitForRead{};
FrameBuffer m_framebuffer;
Common m_common;
CadSceneVK m_scene;
DrawSetup m_setupStandard;
DrawSetup m_setupBbox;
DrawSetup m_setupMeshNV;
DrawSetup m_setupMeshEXT;
nvvk::ProfilerVK m_profilerVK;
size_t m_pipeChangeID{};
size_t m_fboChangeID{};
ResourcesVK() = default;
static ResourcesVK* get()
{
static ResourcesVK res;
return &res;
}
bool init(const nvvk::Context* context, const nvvk::SwapChain* swapChain, nvh::Profiler* profiler) override;
void deinit() override;
void initPipeLayouts();
void initPipes();
void deinitPipes();
bool hasPipes() const { return m_setupStandard.pipeline != nullptr; }
bool initPrograms(const std::string& path, const std::string& prepend) override;
void reloadPrograms(const std::string& prepend) override;
void updatedPrograms();
void deinitPrograms();
bool initFramebuffer(int width, int height, int supersample, bool vsync) override;
void deinitFramebuffer();
bool initScene(const CadScene&) override;
void deinitScene() override;
void synchronize() override;
void beginFrame() override;
void blitFrame(const FrameConfig& global) override;
void endFrame() override;
void cmdCopyStats(VkCommandBuffer cmd) const;
void getStats(CullStats& stats) override;
glm::mat4 perspectiveProjection(float fovy, float aspect, float nearPlane, float farPlane) const override;
//////////////////////////////////////////////////////////////////////////
VkRenderPass createPass(bool clear, int msaa) const;
VkCommandBuffer createCmdBuffer(VkCommandPool pool, bool singleshot, bool primary, bool secondaryInClear) const;
VkCommandBuffer createTempCmdBuffer(bool primary = true, bool secondaryInClear = false);
VkCommandBuffer createBoundingBoxCmdBuffer(VkCommandPool pool, const class RenderList* NV_RESTRICT list) const;
// submit for batched execution
void submissionEnqueue(VkCommandBuffer cmdbuffer) { m_submission.enqueue(cmdbuffer); }
void submissionEnqueue(uint32_t num, const VkCommandBuffer* cmdbuffers) { m_submission.enqueue(num, cmdbuffers); }
// perform queue submit
void submissionExecute(VkFence fence = VK_NULL_HANDLE, bool useImageReadWait = false, bool useImageWriteSignals = false);
// synchronizes to queue
void resetTempResources();
void cmdBeginRenderPass(VkCommandBuffer cmd, bool clear, bool hasSecondary = false) const;
void cmdPipelineBarrier(VkCommandBuffer cmd) const;
void cmdDynamicState(VkCommandBuffer cmd) const;
static void cmdImageTransition(VkCommandBuffer cmd,
VkImage img,
VkImageAspectFlags aspects,
VkAccessFlags src,
VkAccessFlags dst,
VkImageLayout oldLayout,
VkImageLayout newLayout);
void cmdBegin(VkCommandBuffer cmd, bool singleshot, bool primary, bool secondaryInClear) const;
};
} // namespace meshlettest