-
Notifications
You must be signed in to change notification settings - Fork 14
/
mm_opacity.cpp
897 lines (749 loc) · 38.5 KB
/
mm_opacity.cpp
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
/*
* Copyright (c) 2023-2024, 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) 2023-2024, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/
//////////////////////////////////////////////////////////////////////////
/*
This sample raytraces a plane made of 6x6 triangles with Micro-Mesh displacement
- The scene is created in createScene()
- Micro-mesh creation uses the MicromapProcess class
- Vulkan buffers holding the scene are created in createVkBuffers()
- Bottom and Top level acceleration structures are using the Vulkan buffers
and scene description in createBottomLevelAS() and createTopLevelAS()
- The raytracing pipeline, composed of RayGen, Miss, ClosestHit shaders
and the creation of the shader binding table, is done increateRtxPipeline()
- Rendering is done in onRender()
Note: search for #MICROMAP for specific changes for Micro-Mesh
*/
//////////////////////////////////////////////////////////////////////////
#include <array>
#include <glm/detail/type_half.hpp> // for half float
#include <vulkan/vulkan_core.h>
#define VMA_IMPLEMENTATION
#include "imgui/imgui_camera_widget.h"
#include "imgui/imgui_helper.h"
#include "nvh/primitives.hpp"
#include "nvvk/acceleration_structures.hpp"
#include "nvvk/buffers_vk.hpp"
#include "nvvk/commands_vk.hpp"
#include "nvvk/debug_util_vk.hpp"
#include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/dynamicrendering_vk.hpp"
#include "nvvk/pipeline_vk.hpp"
#include "nvvk/sbtwrapper_vk.hpp"
#include "nvvk/shaders_vk.hpp"
#include "nvvkhl/alloc_vma.hpp"
#include "nvvkhl/application.hpp"
#include "nvvkhl/element_benchmark_parameters.hpp"
#include "nvvkhl/element_camera.hpp"
#include "nvvkhl/element_gui.hpp"
#include "nvvkhl/gbuffer.hpp"
#include "nvvkhl/pipeline_container.hpp"
#include "nvvkhl/shaders/dh_sky.h"
#include "common/vk_context.hpp"
#include "nvvk/extensions_vk.hpp"
#include "shaders/dh_bindings.h"
namespace DH {
using namespace glm;
#include "shaders/device_host.h" // Shared between host and device
} // namespace DH
#include "mm_process.hpp"
#include "common/bird_curve_helper.hpp"
//#undef USE_HLSL
#if USE_HLSL
#include "_autogen/raytrace_rgenMain.spirv.h"
#include "_autogen/raytrace_rchitMain.spirv.h"
#include "_autogen/raytrace_rmissMain.spirv.h"
#include "_autogen/raytrace_rahitMain.spirv.h"
const auto& rgen_shd = std::vector<char>{std::begin(raytrace_rgenMain), std::end(raytrace_rgenMain)};
const auto& rchit_shd = std::vector<char>{std::begin(raytrace_rchitMain), std::end(raytrace_rchitMain)};
const auto& rmiss_shd = std::vector<char>{std::begin(raytrace_rmissMain), std::end(raytrace_rmissMain)};
const auto& rahit_shd = std::vector<char>{std::begin(raytrace_rahitMain), std::end(raytrace_rahitMain)};
#elif USE_SLANG
#include "_autogen/raytrace_slang.h"
#else
#include "_autogen/raytrace.rchit.glsl.h"
#include "_autogen/raytrace.rgen.glsl.h"
#include "_autogen/raytrace.rmiss.glsl.h"
#include "_autogen/raytrace.rahit.glsl.h"
const auto& rgen_shd = std::vector<uint32_t>{std::begin(raytrace_rgen_glsl), std::end(raytrace_rgen_glsl)};
const auto& rchit_shd = std::vector<uint32_t>{std::begin(raytrace_rchit_glsl), std::end(raytrace_rchit_glsl)};
const auto& rmiss_shd = std::vector<uint32_t>{std::begin(raytrace_rmiss_glsl), std::end(raytrace_rmiss_glsl)};
const auto& rahit_shd = std::vector<uint32_t>{std::begin(raytrace_rahit_glsl), std::end(raytrace_rahit_glsl)};
#endif
//////////////////////////////////////////////////////////////////////////
/// </summary> Ray trace multiple primitives
class MicomapOpacity : public nvvkhl::IAppElement
{
struct Settings
{
float intensity{5.0F};
float metallic{0.5F};
float roughness{1.0F};
int maxDepth{5};
// #MICROMAP
bool enableOpacity{true};
int subdivlevel{3};
bool showWireframe{true};
float radius{0.5F};
bool useAnyHit{true};
uint16_t micromapFormat{VK_OPACITY_MICROMAP_FORMAT_4_STATE_EXT};
} m_settings;
public:
MicomapOpacity() = default;
~MicomapOpacity() override = default;
void onAttach(nvvkhl::Application* app) override
{
m_app = app;
m_device = m_app->getDevice();
m_dutil = std::make_unique<nvvk::DebugUtil>(m_device); // Debug utility
m_alloc = std::make_unique<nvvkhl::AllocVma>(VmaAllocatorCreateInfo{
.flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT,
.physicalDevice = app->getPhysicalDevice(),
.device = app->getDevice(),
.instance = app->getInstance(),
}); // Allocator
m_rtSet = std::make_unique<nvvk::DescriptorSetContainer>(m_device);
m_micromap = std::make_unique<MicromapProcess>(m_device, app->getPhysicalDevice(), m_alloc.get());
// Requesting ray tracing properties
VkPhysicalDeviceProperties2 prop2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2};
m_rtProperties.pNext = &m_mmProperties;
prop2.pNext = &m_rtProperties;
vkGetPhysicalDeviceProperties2(m_app->getPhysicalDevice(), &prop2);
// Create utilities to create BLAS/TLAS and the Shader Binding Table (SBT)
const uint32_t gct_queue_index = m_app->getQueue(0).familyIndex;
m_sbt.setup(m_device, gct_queue_index, m_alloc.get(), m_rtProperties);
// Create resources
createScene();
createVkBuffers();
// #MICROMAP
{
nvh::ScopedTimer stimer("Create MICROMAP");
VkCommandBuffer cmd = m_app->createTempCmdBuffer();
m_micromap->createMicromapData(cmd, m_meshes[0], m_settings.subdivlevel, m_settings.radius, m_settings.micromapFormat);
m_app->submitAndWaitTempCmdBuffer(cmd);
m_micromap->cleanBuildData();
}
createBottomLevelAS();
createTopLevelAS();
createRtxPipeline();
}
void onDetach() override
{
vkDeviceWaitIdle(m_device);
destroyResources();
}
void onResize(uint32_t width, uint32_t height) override
{
createGbuffers({width, height});
writeRtDesc();
}
void onUIRender() override
{
{ // Setting menu
ImGui::Begin("Settings");
ImGuiH::CameraWidget();
using namespace ImGuiH;
// #MICROMAP - begin
ImGui::Text("Micro-Mesh");
PropertyEditor::begin();
if(PropertyEditor::entry("Enable", [&] { return ImGui::Checkbox("##ll", &m_settings.enableOpacity); }))
{
vkDeviceWaitIdle(m_device);
destroyAccelerationStructures();
createBottomLevelAS();
createTopLevelAS();
writeRtDesc();
}
bool subdiv_changed{false};
subdiv_changed |= PropertyEditor::entry("Subdivision Level", [&] {
return ImGui::SliderInt("#1", &m_settings.subdivlevel, 0, m_mmProperties.maxOpacity4StateSubdivisionLevel);
});
subdiv_changed |=
PropertyEditor::entry("Radius", [&] { return ImGui::SliderFloat("#1", &m_settings.radius, 0.0F, 1.0F); });
subdiv_changed |= PropertyEditor::entry("Micro-map format", [&] {
return ImGui::RadioButton("2-States", (int*)&m_settings.micromapFormat, VK_OPACITY_MICROMAP_FORMAT_2_STATE_EXT);
});
subdiv_changed |= PropertyEditor::entry("", [&] {
return ImGui::RadioButton("4-States", (int*)&m_settings.micromapFormat, VK_OPACITY_MICROMAP_FORMAT_4_STATE_EXT);
});
PropertyEditor::entry("Show Wireframe", [&] { return ImGui::Checkbox("##ll", &m_settings.showWireframe); });
PropertyEditor::entry("Use AnyHit", [&] { return ImGui::Checkbox("##ll", &m_settings.useAnyHit); });
if(subdiv_changed)
{
nvh::ScopedTimer stimer("Create MICROMAP");
vkDeviceWaitIdle(m_device);
VkCommandBuffer cmd = m_app->createTempCmdBuffer();
// Recreate all values
m_micromap->createMicromapData(cmd, m_meshes[0], m_settings.subdivlevel, m_settings.radius, m_settings.micromapFormat);
m_app->submitAndWaitTempCmdBuffer(cmd);
m_micromap->cleanBuildData();
// Recreate the acceleration structure
destroyAccelerationStructures();
createBottomLevelAS();
createTopLevelAS();
writeRtDesc();
}
// #MICROMAP - end
PropertyEditor::end();
ImGui::Text("Material");
PropertyEditor::begin();
PropertyEditor::entry("Metallic", [&] { return ImGui::SliderFloat("#1", &m_settings.metallic, 0.0F, 1.0F); });
PropertyEditor::entry("Roughness", [&] { return ImGui::SliderFloat("#1", &m_settings.roughness, 0.0F, 1.0F); });
PropertyEditor::entry("Intensity", [&] { return ImGui::SliderFloat("#1", &m_settings.intensity, 0.0F, 10.0F); });
PropertyEditor::end();
ImGui::Separator();
ImGui::Text("Sun Orientation");
PropertyEditor::begin();
glm::vec3 dir = m_skyParams.directionToLight;
ImGuiH::azimuthElevationSliders(dir, false);
m_skyParams.directionToLight = dir;
PropertyEditor::end();
ImGui::End();
}
{ // Rendering Viewport
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0F, 0.0F));
ImGui::Begin("Viewport");
// Display the G-Buffer image
ImGui::Image(m_gBuffer->getDescriptorSet(), ImGui::GetContentRegionAvail());
ImGui::End();
ImGui::PopStyleVar();
}
}
void onRender(VkCommandBuffer cmd) override
{
const nvvk::DebugUtil::ScopedCmdLabel sdbg = m_dutil->DBG_SCOPE(cmd);
const float view_aspect_ratio = m_viewSize.x / m_viewSize.y;
// Update the uniform buffer containing frame info
DH::FrameInfo finfo{};
const glm::vec2& clip = CameraManip.getClipPlanes();
finfo.view = CameraManip.getMatrix();
finfo.proj = glm::perspectiveRH_ZO(glm::radians(CameraManip.getFov()), view_aspect_ratio, clip.x, clip.y);
finfo.proj[1][1] *= -1;
finfo.projInv = glm::inverse(finfo.proj);
finfo.viewInv = glm::inverse(finfo.view);
finfo.camPos = CameraManip.getEye();
vkCmdUpdateBuffer(cmd, m_bFrameInfo.buffer, 0, sizeof(DH::FrameInfo), &finfo);
// Update the sky
vkCmdUpdateBuffer(cmd, m_bSkyParams.buffer, 0, sizeof(nvvkhl_shaders::SimpleSkyParameters), &m_skyParams);
// Ray trace
std::vector<VkDescriptorSet> desc_sets{m_rtSet->getSet()};
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, m_rtPipe.plines[0]);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, m_rtPipe.layout, 0,
static_cast<uint32_t>(desc_sets.size()), desc_sets.data(), 0, nullptr);
m_pushConst.intensity = m_settings.intensity;
m_pushConst.metallic = m_settings.metallic;
m_pushConst.roughness = m_settings.roughness;
m_pushConst.maxDepth = m_settings.maxDepth;
m_pushConst.numBaseTriangles = m_settings.showWireframe ? (m_settings.enableOpacity ? 1 << m_settings.subdivlevel : 1) : 0;
m_pushConst.radius = m_settings.radius;
m_pushConst.useAnyhit = m_settings.useAnyHit ? 1 : 0;
vkCmdPushConstants(cmd, m_rtPipe.layout, VK_SHADER_STAGE_ALL, 0, sizeof(DH::PushConstant), &m_pushConst);
const std::array<VkStridedDeviceAddressRegionKHR, 4>& regions = m_sbt.getRegions();
const VkExtent2D& size = m_app->getViewportSize();
vkCmdTraceRaysKHR(cmd, regions.data(), ®ions[1], ®ions[2], ®ions[3], size.width, size.height, 1);
}
private:
void createScene()
{
// Adding a plane & material
m_materials.push_back({glm::vec4(.7F, .7F, .7F, 1.0F)});
m_meshes.emplace_back(nvh::createPlane(3, 1.0F, 1.0F));
nvh::Node& n = m_nodes.emplace_back();
n.mesh = static_cast<int>(m_meshes.size()) - 1;
n.material = static_cast<int>(m_materials.size()) - 1;
n.translation = {0.0F, 0.0F, 0.0F};
// Setting camera to see the scene
CameraManip.setClipPlanes({0.01F, 100.0F});
CameraManip.setLookat({0.96F, 1.33F, 1.3F}, {0.0F, 0.0F, 0.0F}, {0.0, 1.0F, 0.0F});
// Default Sky values
m_skyParams = nvvkhl_shaders::initSimpleSkyParameters();
}
void createGbuffers(const glm::vec2& size)
{
// Rendering image targets
m_viewSize = size;
m_gBuffer = std::make_unique<nvvkhl::GBuffer>(m_device, m_alloc.get(),
VkExtent2D{static_cast<uint32_t>(size.x), static_cast<uint32_t>(size.y)},
m_colorFormat, m_depthFormat);
}
// Create all Vulkan buffer data
void createVkBuffers()
{
VkCommandBuffer cmd = m_app->createTempCmdBuffer();
m_bMeshes.resize(m_meshes.size());
const VkBufferUsageFlags rt_usage_flag = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR;
// Create a buffer of Vertex and Index per mesh
for(size_t i = 0; i < m_meshes.size(); i++)
{
PrimitiveMeshVk& m = m_bMeshes[i];
m.vertices = m_alloc->createBuffer(cmd, m_meshes[i].vertices, rt_usage_flag);
m.indices = m_alloc->createBuffer(cmd, m_meshes[i].triangles, rt_usage_flag);
m_dutil->DBG_NAME_IDX(m.vertices.buffer, i);
m_dutil->DBG_NAME_IDX(m.indices.buffer, i);
}
// Create the buffer of the current frame, changing at each frame
m_bFrameInfo = m_alloc->createBuffer(sizeof(DH::FrameInfo), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
m_dutil->DBG_NAME(m_bFrameInfo.buffer);
// Create the buffer of sky parameters, updated at each frame
m_bSkyParams = m_alloc->createBuffer(sizeof(nvvkhl_shaders::SimpleSkyParameters), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
m_dutil->DBG_NAME(m_bSkyParams.buffer);
// Primitive instance information
std::vector<DH::InstanceInfo> inst_info;
inst_info.reserve(m_nodes.size());
for(const nvh::Node& node : m_nodes)
{
DH::InstanceInfo info{};
info.transform = node.localMatrix();
info.materialID = node.material;
inst_info.push_back(info);
}
m_bInstInfoBuffer =
m_alloc->createBuffer(cmd, inst_info, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
m_dutil->DBG_NAME(m_bInstInfoBuffer.buffer);
m_bMaterials = m_alloc->createBuffer(cmd, m_materials, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
m_dutil->DBG_NAME(m_bMaterials.buffer);
m_app->submitAndWaitTempCmdBuffer(cmd);
}
//--------------------------------------------------------------------------------------------------
// Converting a PrimitiveMesh as input for BLAS
//
static nvvk::AccelerationStructureGeometryInfo primitiveToGeometry(const nvh::PrimitiveMesh& prim,
VkDeviceAddress vertexAddress,
VkDeviceAddress indexAddress)
{
const auto max_primitive_count = static_cast<uint32_t>(prim.triangles.size());
// Describe buffer as array of VertexObj.
VkAccelerationStructureGeometryTrianglesDataKHR triangles{VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR};
triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; // vec3 vertex position data.
triangles.vertexData.deviceAddress = vertexAddress;
triangles.vertexStride = sizeof(nvh::PrimitiveVertex);
triangles.indexType = VK_INDEX_TYPE_UINT32;
triangles.indexData.deviceAddress = indexAddress;
triangles.maxVertex = static_cast<uint32_t>(prim.vertices.size()) - 1;
//triangles.transformData; // Identity
nvvk::AccelerationStructureGeometryInfo result;
// Identify the above data as containing opaque triangles.
result.geometry = VkAccelerationStructureGeometryKHR{
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,
.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR,
.geometry = {triangles},
.flags = VK_GEOMETRY_OPAQUE_BIT_KHR | VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR,
};
result.rangeInfo = VkAccelerationStructureBuildRangeInfoKHR{.primitiveCount = max_primitive_count};
return result;
}
//--------------------------------------------------------------------------------------------------
// Create all bottom level acceleration structures (BLAS)
//
void createBottomLevelAS()
{
nvh::ScopedTimer stimer("Create BLAS");
// BLAS - Storing each primitive in a geometry
std::vector<nvvk::AccelerationStructureBuildData> blasBuildData;
blasBuildData.reserve(m_meshes.size());
m_blas.resize(m_meshes.size());
// #MICROMAP
assert(m_meshes.size() == 1); // The micromap is created for only one mesh
std::vector<VkAccelerationStructureTrianglesOpacityMicromapEXT> geometry_opacity; // hold data until BLAS is created
geometry_opacity.reserve(m_meshes.size());
for(uint32_t p_idx = 0; p_idx < m_meshes.size(); p_idx++)
{
nvvk::AccelerationStructureBuildData buildData{VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR};
const VkDeviceAddress vertex_address = m_bMeshes[p_idx].vertices.address;
const VkDeviceAddress index_address = m_bMeshes[p_idx].indices.address;
nvvk::AccelerationStructureGeometryInfo geo = primitiveToGeometry(m_meshes[p_idx], vertex_address, index_address);
// #MICROMAP
VkAccelerationStructureTrianglesOpacityMicromapEXT opacity_geometry_micromap = {
VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_TRIANGLES_OPACITY_MICROMAP_EXT};
if(m_settings.enableOpacity)
{
const VkDeviceAddress indexT_address = m_micromap->indexBuffer().address;
opacity_geometry_micromap.indexType = VK_INDEX_TYPE_UINT32;
opacity_geometry_micromap.indexBuffer.deviceAddress = indexT_address;
opacity_geometry_micromap.indexStride = sizeof(int32_t);
opacity_geometry_micromap.baseTriangle = 0;
opacity_geometry_micromap.micromap = m_micromap->micromap();
// Adding micromap
geometry_opacity.emplace_back(opacity_geometry_micromap);
geo.geometry.geometry.triangles.pNext = &geometry_opacity.back();
}
buildData.addGeometry(geo);
auto sizeInfo = buildData.finalizeGeometry(m_device, VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR);
blasBuildData.push_back(buildData);
}
VkDeviceSize maxScratchSize = nvvk::getMaxScratchSize(blasBuildData);
// Scratch buffer
nvvk::Buffer scratchBuffer =
m_alloc->createBuffer(maxScratchSize, VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
VkCommandBuffer cmd = m_app->createTempCmdBuffer();
for(uint32_t p_idx = 0; p_idx < m_meshes.size(); p_idx++)
{
auto createInfo = blasBuildData[p_idx].makeCreateInfo();
m_blas[p_idx] = m_alloc->createAcceleration(createInfo);
blasBuildData[p_idx].cmdBuildAccelerationStructure(cmd, m_blas[p_idx].accel, scratchBuffer.address);
}
m_app->submitAndWaitTempCmdBuffer(cmd);
m_alloc->destroy(scratchBuffer);
}
//--------------------------------------------------------------------------------------------------
// Create the top level acceleration structures, referencing all BLAS
//
void createTopLevelAS()
{
nvh::ScopedTimer stimer("Create TLAS");
// #MICROMAP
const VkBuildAccelerationStructureFlagsKHR buildFlags =
VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR | VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_UPDATE_BIT_KHR
| VK_BUILD_ACCELERATION_STRUCTURE_ALLOW_OPACITY_MICROMAP_UPDATE_EXT;
nvvk::AccelerationStructureBuildData tlasBuildData{VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR};
std::vector<VkAccelerationStructureInstanceKHR> tlasInstances;
tlasInstances.reserve(m_nodes.size());
for(const nvh::Node& node : m_nodes)
{
const VkGeometryInstanceFlagsKHR flags{VK_GEOMETRY_INSTANCE_TRIANGLE_CULL_DISABLE_BIT_NV};
//flags |= VK_GEOMETRY_INSTANCE_FORCE_OPACITY_MICROMAP_2_STATE_EXT; // #MICROMAP
VkAccelerationStructureInstanceKHR ray_inst{};
ray_inst.transform = nvvk::toTransformMatrixKHR(node.localMatrix()); // Position of the instance
ray_inst.instanceCustomIndex = node.mesh; // gl_InstanceCustomIndexEXT
ray_inst.accelerationStructureReference = m_blas[node.mesh].address;
ray_inst.instanceShaderBindingTableRecordOffset = 0; // We will use the same hit group for all objects
ray_inst.flags = flags;
ray_inst.mask = 0xFF;
tlasInstances.emplace_back(ray_inst);
}
VkCommandBuffer cmd = m_app->createTempCmdBuffer();
nvvk::Buffer instanceBuffer = m_alloc->createBuffer(cmd, tlasInstances,
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT
| VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR);
nvvk::accelerationStructureBarrier(cmd, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR);
auto geo = tlasBuildData.makeInstanceGeometry(tlasInstances.size(), instanceBuffer.address);
tlasBuildData.addGeometry(geo);
auto sizeInfo = tlasBuildData.finalizeGeometry(m_device, buildFlags);
// Scratch buffer
nvvk::Buffer scratchBuffer =
m_alloc->createBuffer(sizeInfo.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
VkAccelerationStructureCreateInfoKHR createInfo = tlasBuildData.makeCreateInfo();
m_tlas = m_alloc->createAcceleration(createInfo);
tlasBuildData.cmdBuildAccelerationStructure(cmd, m_tlas.accel, scratchBuffer.address);
m_app->submitAndWaitTempCmdBuffer(cmd);
m_alloc->destroy(scratchBuffer);
m_alloc->destroy(instanceBuffer);
}
//--------------------------------------------------------------------------------------------------
// Pipeline for the ray tracer: all shaders, raygen, chit, miss
//
void createRtxPipeline()
{
m_rtPipe.plines.resize(1);
// This descriptor set, holds the top level acceleration structure and the output image
// Create Binding Set
m_rtSet->addBinding(B_tlas, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_outImage, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_frameInfo, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_skyParam, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_materials, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_instances, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_vertex, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, (uint32_t)m_bMeshes.size(), VK_SHADER_STAGE_ALL);
m_rtSet->addBinding(B_index, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, (uint32_t)m_bMeshes.size(), VK_SHADER_STAGE_ALL);
m_rtSet->initLayout();
m_rtSet->initPool(1);
m_dutil->DBG_NAME(m_rtSet->getLayout());
m_dutil->DBG_NAME(m_rtSet->getSet(0));
// Creating all shaders
enum StageIndices
{
eRaygen,
eMiss,
eClosestHit,
eAnyHit,
eShaderGroupCount
};
std::array<VkPipelineShaderStageCreateInfo, eShaderGroupCount> stages{};
for(auto& s : stages)
s.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
#if USE_SLANG
VkShaderModule shaderModule = nvvk::createShaderModule(m_device, &raytraceSlang[0], sizeof(raytraceSlang));
stages[eRaygen].module = shaderModule;
stages[eRaygen].pName = "rgenMain";
stages[eRaygen].stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR;
stages[eMiss].module = shaderModule;
stages[eMiss].pName = "rmissMain";
stages[eMiss].stage = VK_SHADER_STAGE_MISS_BIT_KHR;
stages[eClosestHit].module = shaderModule;
stages[eClosestHit].pName = "rchitMain";
stages[eClosestHit].stage = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
stages[eAnyHit].module = shaderModule;
stages[eAnyHit].pName = "rahitMain";
stages[eAnyHit].stage = VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
#else
stages[eRaygen].module = nvvk::createShaderModule(m_device, rgen_shd);
stages[eRaygen].pName = USE_HLSL ? "rgenMain" : "main";
stages[eRaygen].stage = VK_SHADER_STAGE_RAYGEN_BIT_KHR;
stages[eMiss].module = nvvk::createShaderModule(m_device, rmiss_shd);
stages[eMiss].pName = USE_HLSL ? "rmissMain" : "main";
stages[eMiss].stage = VK_SHADER_STAGE_MISS_BIT_KHR;
stages[eClosestHit].module = nvvk::createShaderModule(m_device, rchit_shd);
stages[eClosestHit].pName = USE_HLSL ? "rchitMain" : "main";
stages[eClosestHit].stage = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
stages[eAnyHit].module = nvvk::createShaderModule(m_device, rahit_shd);
stages[eAnyHit].pName = USE_HLSL ? "rahitMain" : "main";
stages[eAnyHit].stage = VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
#endif
m_dutil->setObjectName(stages[eRaygen].module, "Raygen");
m_dutil->setObjectName(stages[eMiss].module, "Miss");
m_dutil->setObjectName(stages[eClosestHit].module, "Closest Hit");
m_dutil->setObjectName(stages[eAnyHit].module, "Any Hit");
// Shader groups
VkRayTracingShaderGroupCreateInfoKHR group{VK_STRUCTURE_TYPE_RAY_TRACING_SHADER_GROUP_CREATE_INFO_KHR};
group.anyHitShader = VK_SHADER_UNUSED_KHR;
group.closestHitShader = VK_SHADER_UNUSED_KHR;
group.generalShader = VK_SHADER_UNUSED_KHR;
group.intersectionShader = VK_SHADER_UNUSED_KHR;
std::vector<VkRayTracingShaderGroupCreateInfoKHR> shader_groups;
// Raygen
group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR;
group.generalShader = eRaygen;
shader_groups.push_back(group);
// Miss
group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_KHR;
group.generalShader = eMiss;
shader_groups.push_back(group);
// Hit shader
group.type = VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_KHR;
group.generalShader = VK_SHADER_UNUSED_KHR;
group.closestHitShader = eClosestHit;
group.anyHitShader = eAnyHit;
shader_groups.push_back(group);
// Push constant: we want to be able to update constants used by the shaders
const VkPushConstantRange push_constant{VK_SHADER_STAGE_ALL, 0, sizeof(DH::PushConstant)};
VkPipelineLayoutCreateInfo pipeline_layout_create_info{VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
pipeline_layout_create_info.pushConstantRangeCount = 1;
pipeline_layout_create_info.pPushConstantRanges = &push_constant;
// Descriptor sets: one specific to ray tracing, and one shared with the rasterization pipeline
std::vector<VkDescriptorSetLayout> rt_desc_set_layouts = {m_rtSet->getLayout()}; // , m_pContainer[eGraphic].dstLayout};
pipeline_layout_create_info.setLayoutCount = static_cast<uint32_t>(rt_desc_set_layouts.size());
pipeline_layout_create_info.pSetLayouts = rt_desc_set_layouts.data();
NVVK_CHECK(vkCreatePipelineLayout(m_device, &pipeline_layout_create_info, nullptr, &m_rtPipe.layout));
m_dutil->DBG_NAME(m_rtPipe.layout);
// Assemble the shader stages and recursion depth info into the ray tracing pipeline
VkRayTracingPipelineCreateInfoKHR ray_pipeline_info{VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR};
ray_pipeline_info.flags = VK_PIPELINE_CREATE_RAY_TRACING_OPACITY_MICROMAP_BIT_EXT; // #MICROMAP
ray_pipeline_info.stageCount = static_cast<uint32_t>(stages.size()); // Stages are shaders
ray_pipeline_info.pStages = stages.data();
ray_pipeline_info.groupCount = static_cast<uint32_t>(shader_groups.size());
ray_pipeline_info.pGroups = shader_groups.data();
ray_pipeline_info.maxPipelineRayRecursionDepth = 10; // Ray depth
ray_pipeline_info.layout = m_rtPipe.layout;
NVVK_CHECK(vkCreateRayTracingPipelinesKHR(m_device, {}, {}, 1, &ray_pipeline_info, nullptr, (m_rtPipe.plines).data()));
m_dutil->DBG_NAME(m_rtPipe.plines[0]);
// Creating the SBT
m_sbt.create(m_rtPipe.plines[0], ray_pipeline_info);
// Removing temp modules
#if USE_SLANG
vkDestroyShaderModule(m_device, shaderModule, nullptr);
#else
for(const VkPipelineShaderStageCreateInfo& s : stages)
vkDestroyShaderModule(m_device, s.module, nullptr);
#endif
}
void writeRtDesc()
{
// Write to descriptors
VkAccelerationStructureKHR tlas = m_tlas.accel;
VkWriteDescriptorSetAccelerationStructureKHR desc_as_info{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
desc_as_info.accelerationStructureCount = 1;
desc_as_info.pAccelerationStructures = &tlas;
const VkDescriptorImageInfo image_info{{}, m_gBuffer->getColorImageView(), VK_IMAGE_LAYOUT_GENERAL};
const VkDescriptorBufferInfo dbi_unif{m_bFrameInfo.buffer, 0, VK_WHOLE_SIZE};
const VkDescriptorBufferInfo dbi_sky{m_bSkyParams.buffer, 0, VK_WHOLE_SIZE};
const VkDescriptorBufferInfo mat_desc{m_bMaterials.buffer, 0, VK_WHOLE_SIZE};
const VkDescriptorBufferInfo inst_desc{m_bInstInfoBuffer.buffer, 0, VK_WHOLE_SIZE};
std::vector<VkDescriptorBufferInfo> vertex_desc;
std::vector<VkDescriptorBufferInfo> index_desc;
vertex_desc.reserve(m_bMeshes.size());
index_desc.reserve(m_bMeshes.size());
for(auto& m : m_bMeshes)
{
vertex_desc.push_back({m.vertices.buffer, 0, VK_WHOLE_SIZE});
index_desc.push_back({m.indices.buffer, 0, VK_WHOLE_SIZE});
}
std::vector<VkWriteDescriptorSet> writes;
writes.emplace_back(m_rtSet->makeWrite(0, B_tlas, &desc_as_info));
writes.emplace_back(m_rtSet->makeWrite(0, B_outImage, &image_info));
writes.emplace_back(m_rtSet->makeWrite(0, B_frameInfo, &dbi_unif));
writes.emplace_back(m_rtSet->makeWrite(0, B_skyParam, &dbi_sky));
writes.emplace_back(m_rtSet->makeWrite(0, B_materials, &mat_desc));
writes.emplace_back(m_rtSet->makeWrite(0, B_instances, &inst_desc));
writes.emplace_back(m_rtSet->makeWriteArray(0, B_vertex, vertex_desc.data()));
writes.emplace_back(m_rtSet->makeWriteArray(0, B_index, index_desc.data()));
writes.emplace_back(m_rtSet->makeWrite(0, B_tlas, &desc_as_info));
writes.emplace_back(m_rtSet->makeWrite(0, B_outImage, &image_info));
writes.emplace_back(m_rtSet->makeWrite(0, B_frameInfo, &dbi_unif));
writes.emplace_back(m_rtSet->makeWrite(0, B_skyParam, &dbi_sky));
writes.emplace_back(m_rtSet->makeWrite(0, B_materials, &mat_desc));
writes.emplace_back(m_rtSet->makeWrite(0, B_instances, &inst_desc));
writes.emplace_back(m_rtSet->makeWriteArray(0, B_vertex, vertex_desc.data()));
writes.emplace_back(m_rtSet->makeWriteArray(0, B_index, index_desc.data()));
vkUpdateDescriptorSets(m_device, static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
}
void destroyAccelerationStructures()
{
for(auto& b : m_blas)
{
m_alloc->destroy(b);
}
m_blas.clear();
m_alloc->destroy(m_tlas);
}
void destroyResources()
{
vkDestroyPipelineLayout(m_device, m_pipelineLayout, nullptr);
vkDestroyPipeline(m_device, m_graphicsPipeline, nullptr);
for(PrimitiveMeshVk& m : m_bMeshes)
{
m_alloc->destroy(m.vertices);
m_alloc->destroy(m.indices);
}
m_alloc->destroy(m_bFrameInfo);
m_alloc->destroy(m_bInstInfoBuffer);
m_alloc->destroy(m_bMaterials);
m_alloc->destroy(m_bSkyParams);
m_rtSet->deinit();
m_gBuffer.reset();
m_rtPipe.destroy(m_device);
m_sbt.destroy();
destroyAccelerationStructures();
}
//--------------------------------------------------------------------------------------------------
//
//
nvvkhl::Application* m_app{nullptr};
std::unique_ptr<nvvk::DebugUtil> m_dutil;
std::unique_ptr<nvvkhl::AllocVma> m_alloc;
std::unique_ptr<nvvk::DescriptorSetContainer> m_rtSet; // Descriptor set
std::unique_ptr<MicromapProcess> m_micromap;
glm::vec2 m_viewSize = {1, 1};
VkFormat m_colorFormat = VK_FORMAT_R8G8B8A8_UNORM; // Color format of the image
VkFormat m_depthFormat = VK_FORMAT_X8_D24_UNORM_PACK32; // Depth format of the depth buffer
VkDevice m_device = VK_NULL_HANDLE; // Convenient
std::unique_ptr<nvvkhl::GBuffer> m_gBuffer; // G-Buffers: color + depth
nvvkhl_shaders::SimpleSkyParameters m_skyParams{};
// Resources
struct PrimitiveMeshVk
{
nvvk::Buffer vertices; // Buffer of the vertices
nvvk::Buffer indices; // Buffer of the indices
};
std::vector<PrimitiveMeshVk> m_bMeshes;
nvvk::Buffer m_bFrameInfo;
nvvk::Buffer m_bInstInfoBuffer;
nvvk::Buffer m_bMaterials;
nvvk::Buffer m_bSkyParams;
std::vector<VkSampler> m_samplers;
// Data and setting
struct Material
{
glm::vec4 color{1.F};
};
std::vector<nvh::PrimitiveMesh> m_meshes;
std::vector<nvh::Node> m_nodes;
std::vector<Material> m_materials;
// Pipeline
DH::PushConstant m_pushConst{}; // Information sent to the shader
VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE; // The description of the pipeline
VkPipeline m_graphicsPipeline = VK_NULL_HANDLE; // The graphic pipeline to render
VkPhysicalDeviceRayTracingPipelinePropertiesKHR m_rtProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_PROPERTIES_KHR};
VkPhysicalDeviceOpacityMicromapPropertiesEXT m_mmProperties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPACITY_MICROMAP_PROPERTIES_EXT};
nvvk::SBTWrapper m_sbt; // Shader binding table wrapper
nvvkhl::PipelineContainer m_rtPipe;
std::vector<nvvk::AccelKHR> m_blas; // Hold the bottom-level AS
nvvk::AccelKHR m_tlas; // Top-level acceleration structure
};
//////////////////////////////////////////////////////////////////////////
///
///
///
int main(int argc, char** argv)
{
// #MICROMAP
ValidationSettings vvl{
.unique_handles = false, // This is required for the validation layers to work properly
};
VkPhysicalDeviceAccelerationStructureFeaturesKHR accel_feature{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR};
VkPhysicalDeviceRayTracingPipelineFeaturesKHR rt_pipeline_feature{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR};
// #MICROMAP
VkPhysicalDeviceOpacityMicromapFeaturesEXT mm_opacity_features{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPACITY_MICROMAP_FEATURES_EXT};
// Setting how we want Vulkan context to be created
VkContextSettings vkSetup;
vkSetup.instanceCreateInfoExt = vvl.buildPNextChain();
nvvkhl::addSurfaceExtensions(vkSetup.instanceExtensions);
vkSetup.instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
vkSetup.deviceExtensions.push_back({VK_KHR_SWAPCHAIN_EXTENSION_NAME});
vkSetup.deviceExtensions.push_back({VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME});
vkSetup.deviceExtensions.push_back({VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, &accel_feature}); // To build acceleration structures
vkSetup.deviceExtensions.push_back({VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, &rt_pipeline_feature}); // To use vkCmdTraceRaysKHR
vkSetup.deviceExtensions.push_back({VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME}); // Required by ray tracing pipeline
vkSetup.deviceExtensions.push_back({VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME});
vkSetup.deviceExtensions.push_back({VK_EXT_OPACITY_MICROMAP_EXTENSION_NAME, &mm_opacity_features});
#if USE_HLSL // DXC is automatically adding the extension
VkPhysicalDeviceRayQueryFeaturesKHR rayqueryFeature{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR};
vkSetup.deviceExtensions.push_back({VK_KHR_RAY_QUERY_EXTENSION_NAME, &rayqueryFeature});
#endif // USE_HLSL
#if(VK_HEADER_VERSION >= 283)
// To enable ray tracing validation, set the NV_ALLOW_RAYTRACING_VALIDATION=1 environment variable
// https://developer.nvidia.com/blog/ray-tracing-validation-at-the-driver-level/
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_NV_ray_tracing_validation.html
VkPhysicalDeviceRayTracingValidationFeaturesNV validationFeatures = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_VALIDATION_FEATURES_NV};
vkSetup.deviceExtensions.push_back({VK_NV_RAY_TRACING_VALIDATION_EXTENSION_NAME, &validationFeatures, false});
#endif
// Creating the Vulkan context
VulkanContext vkContext(vkSetup);
if(!vkContext.isValid())
std::exit(0);
load_VK_EXTENSIONS(vkContext.getInstance(), vkGetInstanceProcAddr, vkContext.getDevice(), vkGetDeviceProcAddr); // Loading the Vulkan extension pointers
nvvkhl::ApplicationCreateInfo appSetup;
appSetup.name = fmt::format("{} ({})", PROJECT_NAME, SHADER_LANGUAGE_STR);
appSetup.vSync = false;
appSetup.instance = vkContext.getInstance();
appSetup.device = vkContext.getDevice();
appSetup.physicalDevice = vkContext.getPhysicalDevice();
appSetup.queues = vkContext.getQueueInfos();
// Create the application
auto app = std::make_unique<nvvkhl::Application>(appSetup);
// #MICROMAP
if(mm_opacity_features.micromap == VK_FALSE)
{
LOGE("ERROR: Micro-Mesh not supported");
exit(1);
}
// Create the test framework
auto test = std::make_shared<nvvkhl::ElementBenchmarkParameters>(argc, argv);
// Add all application elements
app->addElement(test);
app->addElement(std::make_shared<nvvkhl::ElementCamera>());
app->addElement(std::make_shared<nvvkhl::ElementDefaultMenu>()); // Menu / Quit
app->addElement(std::make_shared<nvvkhl::ElementDefaultWindowTitle>("", fmt::format("({})", SHADER_LANGUAGE_STR))); // Window title info
app->addElement(std::make_shared<MicomapOpacity>());
app->run();
app.reset();
vkContext.deinit();
return test->errorCode();
}