-
Notifications
You must be signed in to change notification settings - Fork 45
/
VkeGameRendererDynamic.cpp
1461 lines (1133 loc) · 54.9 KB
/
VkeGameRendererDynamic.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
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2014-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) 2014-2024 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/
/* Contact [email protected] (Chris Hebert) for feedback */
#include <include_gl.h>
#include "VkeCamera.h"
#include "VkeGameRendererDynamic.h"
#include "VkeIBO.h"
#include "VkeMaterial.h"
#include "VkeTexture.h"
#include "VkeVBO.h"
#include "VulkanAppContext.h"
#include <algorithm>
#include <chrono>
#ifndef INIT_COMMAND_ID
#define INIT_COMMAND_ID 1
#endif
#ifndef GL_NV_draw_vulkan_image
#define GL_NV_draw_vulkan_image 1
//typedef GLVULKANPROCNV (GLAPIENTRY* PFNGLGETVKINSTANCEPROCADDRNVPROC) (const GLchar *name);
typedef void(GLAPIENTRY* PFNGLWAITVKSEMAPHORENVPROC)(GLuint64 vkSemaphore);
typedef void(GLAPIENTRY* PFNGLSIGNALVKSEMAPHORENVPROC)(GLuint64 vkSemaphore);
typedef void(GLAPIENTRY* PFNGLSIGNALVKFENCENVPROC)(GLuint64 vkFence);
typedef void(GLAPIENTRY* PFNGLDRAWVKIMAGENVPROC)(GLuint64 vkImage,
GLuint sampler,
GLfloat x0,
GLfloat y0,
GLfloat x1,
GLfloat y1,
GLfloat z,
GLfloat s0,
GLfloat t0,
GLfloat s1,
GLfloat t1);
//PFNGLGETVKINSTANCEPROCADDRNVPROC glGetVkInstanceProcAddrNV;
PFNGLWAITVKSEMAPHORENVPROC glWaitVkSemaphoreNV;
PFNGLSIGNALVKSEMAPHORENVPROC glSignalVkSemaphoreNV;
PFNGLSIGNALVKFENCENVPROC glSignalVkFenceNV;
PFNGLDRAWVKIMAGENVPROC glDrawVkImageNV;
#endif
#ifdef GL_GLEXT_PROTOTYPES
//GLAPI GLVULKANPROCNV GLAPIENTRY glGetVkInstanceProcAddrNV (const GLchar *name);
//GLAPI void GLAPIENTRY glWaitVkSemaphoreNV(GLuint64 vkSemaphore);
//GLAPI void GLAPIENTRY glSignalVkSemaphoreNV(GLuint64 vkSemaphore);
//GLAPI void GLAPIENTRY glSignalVkFenceNV(GLuint64 vkFence);
//GLAPI void GLAPIENTRY glDrawVkImageNV(GLuint64 vkImage, GLuint sampler, GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1, GLfloat z, GLfloat s0, GLfloat t0, GLfloat s1, GLfloat t1);
#endif /* GL_GLEXT_PROTOTYPES */
static void setDefaultViewportAndScissor(VkCommandBuffer cmd, uint32_t width, uint32_t height)
{
VkViewport vp{};
VkRect2D sc{};
vp.x = 0;
vp.y = 0;
vp.height = (float)(height);
vp.width = (float)(width);
vp.minDepth = 0.0f;
vp.maxDepth = 1.0f;
sc.offset.x = 0;
sc.offset.y = 0;
sc.extent.width = width;
sc.extent.height = height;
vkCmdSetViewport(cmd, 0, 1, &vp);
vkCmdSetScissor(cmd, 0, 1, &sc);
}
VkeDrawCall::VkeDrawCall(vkeGameRendererDynamic* inRenderer)
: m_renderer(inRenderer)
, m_buffer_ready(false)
{
m_draw_command[0] = VK_NULL_HANDLE;
m_draw_command[1] = VK_NULL_HANDLE;
initCommandPool();
initDescriptorPool();
}
VkeDrawCall::~VkeDrawCall() {}
VkCommandBuffer VkeDrawCall::getDrawCommand(const uint32_t inFrameIndex)
{
return m_draw_command[inFrameIndex];
}
void VkeDrawCall::initCommandPool()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
VkCommandPoolCreateInfo cmdPoolInfo = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
cmdPoolInfo.queueFamilyIndex = 0;
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VKA_CHECK_ERROR(vkCreateCommandPool(device->getVKDevice(), &cmdPoolInfo, NULL, &m_command_pool), "Could not create command pool.\n");
VkCommandBufferAllocateInfo cmdBufInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
cmdBufInfo.commandBufferCount = 2;
cmdBufInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
cmdBufInfo.commandPool = m_command_pool;
VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, m_draw_command),
"Could not allocate secondary command buffers.\n");
}
void VkeDrawCall::initDescriptorPool()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
VkDescriptorPoolSize poolSize = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1};
VkDescriptorPoolCreateInfo poolInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
poolInfo.maxSets = 1;
poolInfo.poolSizeCount = 1;
poolInfo.pPoolSizes = &poolSize;
poolInfo.flags = 0;
VKA_CHECK_ERROR(vkCreateDescriptorPool(device->getVKDevice(), &poolInfo, NULL, &m_descriptor_pool),
"Could not create descriptor pool.\n");
}
void VkeDrawCall::initDescriptor()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
VkWriteDescriptorSet writes[1];
vkResetDescriptorPool(device->getVKDevice(), m_descriptor_pool, 0);
VkDescriptorSetAllocateInfo descAlloc = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
descAlloc.descriptorPool = m_descriptor_pool;
descAlloc.pSetLayouts = (m_renderer->getTransformDescriptorLayout());
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_transform_descriptor_set),
"Could not allocate descriptor sets.\n");
descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, (m_renderer->getTransformsDescriptor()),
VK_NULL_HANDLE, 0, m_transform_descriptor_set); //transform
vkUpdateDescriptorSets(device->getVKDevice(), 1, writes, 0, NULL);
}
void VkeDrawCall::initDrawCommands(const uint32_t inCount,
const uint32_t inCommandIndex,
VkRenderPass parentRenderPass,
uint32_t viewportWidth,
uint32_t viewportHeight)
{
VkPipelineLayout layout = m_renderer->getPipelineLayout();
VkPipeline pipeline = m_renderer->getPipeline();
VkDescriptorSet sceneDescriptor = m_renderer->getSceneDescriptorSet();
VkDescriptorSet* textureDescriptors = m_renderer->getTextureDescriptorSets();
VkBuffer sceneIndirectBuffer = m_renderer->getSceneIndirectBuffer();
VulkanAppContext* ctxt = VulkanAppContext::GetInstance();
vkResetCommandBuffer(m_draw_command[inCommandIndex], 0);
VkCommandBufferInheritanceInfo cmdInheritanceInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO};
cmdInheritanceInfo.renderPass = parentRenderPass;
cmdInheritanceInfo.subpass = 0;
VkCommandBufferBeginInfo cmdBeginInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
cmdBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
cmdBeginInfo.pInheritanceInfo = &cmdInheritanceInfo;
VKA_CHECK_ERROR(vkBeginCommandBuffer(m_draw_command[inCommandIndex], &cmdBeginInfo), "Could not begin command buffer.\n");
// TODO: Switch to using inherited viewport and scissor
setDefaultViewportAndScissor(m_draw_command[inCommandIndex], viewportWidth, viewportHeight);
vkCmdBindPipeline(m_draw_command[inCommandIndex], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
VkeVBO* theVBO = ctxt->getVBO();
VkeIBO* theIBO = ctxt->getIBO();
theVBO->bind(&m_draw_command[inCommandIndex]);
theIBO->bind(&m_draw_command[inCommandIndex]);
VkDescriptorSet sets[3] = {sceneDescriptor, textureDescriptors[0], m_transform_descriptor_set};
vkCmdBindDescriptorSets(m_draw_command[inCommandIndex], VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, 3, sets, 0, NULL);
vkCmdDrawIndexedIndirect(m_draw_command[inCommandIndex], sceneIndirectBuffer, 0, inCount, sizeof(VkDrawIndexedIndirectCommand));
vkCmdDraw(m_draw_command[inCommandIndex], 1, 1, 0, 0);
vkEndCommandBuffer(m_draw_command[inCommandIndex]);
/*
Lock mutex to update generated call count.
*/
//std::lock_guard<std::mutex> lk(m_renderer->getSecondaryCmdBufferMutex());
/*
Increment the generated call count
*/
m_renderer->incrementDrawCallsGenerated();
}
vkeGameRendererDynamic::vkeGameRendererDynamic()
: VkeRenderer()
, m_node_data(NULL)
{
initRenderer();
}
vkeGameRendererDynamic::~vkeGameRendererDynamic() {}
void vkeGameRendererDynamic::initIndirectCommands()
{
if(!m_node_data)
return;
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
VulkanDC::Device::Queue* queue = dc->getDefaultQueue();
size_t cnt = m_node_data->count();
size_t sz = sizeof(VkDrawIndexedIndirectCommand) * cnt;
VkBuffer sceneIndirectStaging;
VkDeviceMemory sceneIndirectMemStaging;
VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
bufferCreate(&m_scene_indirect_buffer, sz, (VkBufferUsageFlagBits)usageFlags);
bufferAlloc(&m_scene_indirect_buffer, &m_scene_indirect_memory, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
usageFlags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
bufferCreate(&sceneIndirectStaging, sz, (VkBufferUsageFlagBits)usageFlags);
bufferAlloc(&sceneIndirectStaging, &sceneIndirectMemStaging, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
VkDrawIndexedIndirectCommand* commands = NULL;
VKA_CHECK_ERROR(vkMapMemory(device->getVKDevice(), sceneIndirectMemStaging, 0, sz, 0, (void**)&commands),
"Could not map indirect buffer memory.\n");
for(size_t i = 0; i < cnt; ++i)
{
VkeMesh* mesh = m_node_data->getData(i)->getMesh();
commands[i].firstIndex = mesh->getFirstIndex();
commands[i].firstInstance = uint32_t(i * m_instance_count);
commands[i].vertexOffset = mesh->getFirstVertex();
commands[i].indexCount = mesh->getIndexCount();
commands[i].instanceCount = uint32_t(m_instance_count);
}
vkUnmapMemory(device->getVKDevice(), sceneIndirectMemStaging);
VkBufferCopy bufCpy;
bufCpy.dstOffset = 0;
bufCpy.srcOffset = 0;
bufCpy.size = sz;
VkCommandBuffer copyCmd;
VkCommandBufferAllocateInfo cmdBufInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
cmdBufInfo.commandBufferCount = 1;
cmdBufInfo.commandPool = queue->getCommandPool();
cmdBufInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, ©Cmd), "Could not allocate command buffers.\n");
VkCommandBufferBeginInfo cmdBeginInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
cmdBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
VKA_CHECK_ERROR(vkBeginCommandBuffer(copyCmd, &cmdBeginInfo), "Could not begin commmand buffer.\n");
vkCmdCopyBuffer(copyCmd, sceneIndirectStaging, m_scene_indirect_buffer, 1, &bufCpy);
VKA_CHECK_ERROR(vkEndCommandBuffer(copyCmd), "Could not end command buffer.\n");
VkSubmitInfo subInfo = {VK_STRUCTURE_TYPE_SUBMIT_INFO};
subInfo.commandBufferCount = 1;
subInfo.pCommandBuffers = ©Cmd;
VkFence theFence;
VkFenceCreateInfo fenceInfo = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
VKA_CHECK_ERROR(vkCreateFence(device->getVKDevice(), &fenceInfo, NULL, &theFence), "Could not create fence.\n");
VKA_CHECK_ERROR(vkQueueSubmit(queue->getVKQueue(), 1, &subInfo, theFence), "Could not submit queue for indirect buffer copy.\n");
VKA_CHECK_ERROR(vkWaitForFences(device->getVKDevice(), 1, &theFence, VK_TRUE, UINT_MAX), "Could not wait for fence.\n");
vkFreeCommandBuffers(device->getVKDevice(), queue->getCommandPool(), 1, ©Cmd);
vkDestroyFence(device->getVKDevice(), theFence, NULL);
}
void vkeGameRendererDynamic::initDescriptorPool()
{
VkeRenderer::initDescriptorPool();
VkDescriptorPoolSize typeCounts[] = {{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1},
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 2},
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}};
VulkanDC* dc = VulkanDC::Get();
if(!dc)
return;
VulkanDC::Device* device = dc->getDefaultDevice();
VkDescriptorPoolCreateInfo descriptorPoolInfo = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
descriptorPoolInfo.poolSizeCount = 3;
descriptorPoolInfo.pPoolSizes = typeCounts;
descriptorPoolInfo.maxSets = (m_descriptor_pool_size * 2) + 3;
VKA_CHECK_ERROR(vkCreateDescriptorPool(device->getVKDevice(), &descriptorPoolInfo, NULL, &m_descriptor_pool),
"Could not create descriptor pool.\n");
}
float quickRandomUVD()
{
return ((float)rand() / (float)RAND_MAX) * 2.0f - 1.0f;
}
void vkeGameRendererDynamic::initRenderer()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDevice();
m_instance_count = 128;
//glWaitVkSemaphoreNV = (PFNGLWAITVKSEMAPHORENVPROC)NVPSystem::GetProcAddressGL("glWaitVkSemaphoreNV");
//glSignalVkSemaphoreNV = (PFNGLSIGNALVKSEMAPHORENVPROC)NVPSystem::GetProcAddressGL("glSignalVkSemaphoreNV");
//glSignalVkFenceNV = (PFNGLSIGNALVKFENCENVPROC)NVPSystem::GetProcAddressGL("glSignalVkFenceNV");
// glDrawVkImageNV = (PFNGLDRAWVKIMAGENVPROC)NVPSystem::GetProcAddressGL("glDrawVkImageNV");
VkSemaphoreCreateInfo semInfo = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
VkFenceCreateInfo fenceInfo = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_present_done[0]),
"Could not create present done semaphore.\n");
VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_render_done[0]),
"Could not create render done semaphore.\n");
VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_present_done[1]),
"Could not create present done semaphore.\n");
VKA_CHECK_ERROR(vkCreateSemaphore(device->getVKDevice(), &semInfo, NULL, &m_render_done[1]),
"Could not create render done semaphore.\n");
VKA_CHECK_ERROR(vkCreateFence(device->getVKDevice(), &fenceInfo, NULL, &m_update_fence[0]), "Could not create update fence.\n");
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
VKA_CHECK_ERROR(vkCreateFence(device->getVKDevice(), &fenceInfo, NULL, &m_update_fence[1]), "Could not create update fence.\n");
m_terrain_command[0] = VK_NULL_HANDLE;
m_terrain_command[1] = VK_NULL_HANDLE;
m_framebuffers[0] = VK_NULL_HANDLE;
m_framebuffers[1] = VK_NULL_HANDLE;
m_update_commands[0] = VK_NULL_HANDLE;
m_update_commands[1] = VK_NULL_HANDLE;
m_is_first_frame = true;
glm::vec4 table[128][128];
for(int v = 0; v < 128; ++v)
{
for(int u = 0; u < 128; ++u)
{
glm::vec2 vctr(quickRandomUVD(), quickRandomUVD());
vctr = glm::normalize(vctr);
// VK_FORMAT_R32G32B32_SFLOAT isn't so widely supported, so we use
// VK_FORMAT_R32G32B32A32_SFLOAT instead.
table[u][v] = glm::vec4(vctr.x, vctr.y, vctr.x, 0.f);
}
}
m_cube_textures.newTexture(1)->loadCubeDDS("environ.dds");
m_screen_quad.initQuadData();
m_terrain_quad.initQuadData();
m_textures.newTexture(0)->setFormat(VK_FORMAT_R32G32B32A32_SFLOAT);
m_textures.getTexture(0)->loadTextureFloatData((float*)&(table[0][0].x), 128, 128, 4);
m_flight_paths.resize(m_instance_count);
for(uint32_t i = 0; i < m_instance_count; ++i)
{
glm::vec2 initPos(quickRandomUVD() * 100.0f, -200.f + (quickRandomUVD() * 20.f));
glm::vec2 endPos(quickRandomUVD() * 100.0f, 200.f + (quickRandomUVD() * 20.f));
m_flight_paths[i] =
std::make_unique<FlightPath>(initPos, endPos, quickRandomUVD() * 0.5f + 0.5f, quickRandomUVD() * 4.f + 10.f);
}
/*
Just initialises the draw call objects
not the threads. They store thread local
data for the threaded cmd buffer builds.
*/
initDrawCalls();
/*
Create primary command pool for the
*/
VkCommandPoolCreateInfo cmdPoolInfo = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
cmdPoolInfo.queueFamilyIndex = 0;
cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
VKA_CHECK_ERROR(vkCreateCommandPool(device->getVKDevice(), &cmdPoolInfo, NULL, &m_primary_buffer_cmd_pool),
"Could not create primary command pool.\n");
m_primary_commands[0] = VK_NULL_HANDLE;
m_primary_commands[1] = VK_NULL_HANDLE;
VkCommandBufferAllocateInfo cmdBufInfo = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
cmdBufInfo.commandBufferCount = 2;
cmdBufInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cmdBufInfo.commandPool = m_primary_buffer_cmd_pool;
VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, m_primary_commands),
"Could not allocate primary command buffers.\n");
VKA_CHECK_ERROR(vkAllocateCommandBuffers(device->getVKDevice(), &cmdBufInfo, m_update_commands),
"Could not allocate primary command buffers.\n");
m_current_buffer_index = 0;
}
void vkeGameRendererDynamic::setNodeData(VkeNodeData::List* inData)
{
m_node_data = inData;
if(m_node_data != NULL)
{
size_t cnt = m_node_data->count();
size_t transformsSize = 64 * m_instance_count;
size_t sz = sizeof(VkeNodeUniform) * cnt;
sz += (transformsSize);
m_uniforms_local = (float*)malloc(sz);
bufferCreate(&m_uniforms_buffer, sz, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
bufferAlloc(&m_uniforms_buffer, &m_uniforms_memory, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
m_uniforms_descriptor.buffer = m_uniforms_buffer;
m_uniforms_descriptor.offset = 0;
m_uniforms_descriptor.range = sizeof(VkeNodeUniform) * cnt;
m_transforms_descriptor.buffer = m_uniforms_buffer;
m_transforms_descriptor.offset = sizeof(VkeNodeUniform) * cnt;
m_transforms_descriptor.range = transformsSize;
}
}
void vkeGameRendererDynamic::setMaterialData(VkeMaterial::List* inData)
{
m_materials = inData;
if(m_materials != NULL)
{
size_t cnt = m_materials->count();
size_t sz = sizeof(VkeMaterialUniform) * cnt;
VkBufferUsageFlags usageFlags = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
bufferCreate(&m_material_buffer_staging, sz, (VkBufferUsageFlagBits)usageFlags);
bufferAlloc(&m_material_buffer_staging, &m_material_staging, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
VkeMaterialUniform* uniforms = NULL;
VKA_CHECK_ERROR(vkMapMemory(getDefaultDevice(), m_material_staging, 0, sz, 0, (void**)&uniforms), "Could not map buffer memory.\n");
for(size_t i = 0; i < cnt; ++i)
{
VkeMaterial* mat = m_materials->getMaterial(i);
mat->initVKBufferData(m_material_buffer_staging);
mat->updateVKBufferData(uniforms);
}
vkUnmapMemory(getDefaultDevice(), m_material_staging);
}
}
size_t vkeGameRendererDynamic::getRequiredDescriptorCount()
{
if(!m_node_data)
return 0;
return m_node_data->count();
}
void vkeGameRendererDynamic::update()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
static float totalTime = 0.0f;
static auto lastFrameStart = std::chrono::high_resolution_clock::now();
auto thisFrameStart = std::chrono::high_resolution_clock::now();
float deltaTime = std::chrono::duration<float>(thisFrameStart - lastFrameStart).count();
totalTime += deltaTime;
lastFrameStart = thisFrameStart;
size_t cnt = m_node_data->count();
for(size_t i = 0; i < m_instance_count; ++i)
{
size_t pointerOffset = (sizeof(VkeNodeUniform) * cnt) + (64 * i);
glm::mat4* matPtr = (glm::mat4*)(((uint8_t*)m_uniforms_local) + pointerOffset);
m_flight_paths[i]->update(matPtr, deltaTime);
}
m_node_data->update((VkeNodeUniform*)m_uniforms_local, m_instance_count);
m_camera->setViewport(0, 0, (float)m_width, (float)m_height);
m_camera->update(totalTime);
generateDrawCommands();
if(!m_is_first_frame)
{
vkResetFences(device->getVKDevice(), 1, &m_update_fence[m_current_buffer_index]);
const VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo subInfo = {VK_STRUCTURE_TYPE_SUBMIT_INFO};
subInfo.commandBufferCount = 1;
subInfo.pCommandBuffers = &m_primary_commands[m_current_buffer_index];
#if defined(WIN32)
subInfo.waitSemaphoreCount = 1;
subInfo.pWaitSemaphores = &m_present_done[m_current_buffer_index];
subInfo.pWaitDstStageMask = &waitStages;
subInfo.signalSemaphoreCount = 1;
subInfo.pSignalSemaphores = &m_render_done[m_current_buffer_index];
#endif
vkQueueSubmit(dc->getDefaultQueue()->getVKQueue(), 1, &subInfo, m_update_fence[m_current_buffer_index]);
/*
Synchronise the next buffer.
This prevents the buffer from being reset when still in use
when we have more than 2 frames in flight.
*/
uint32_t nextBufferIndex = (m_current_buffer_index + 1) % 2;
present();
vkWaitForFences(device->getVKDevice(), 1, &m_update_fence[nextBufferIndex], VK_TRUE, 1000000);
}
else
{
m_is_first_frame = false;
}
m_current_buffer_index++;
m_current_buffer_index %= 2;
}
void vkeGameRendererDynamic::present()
{
glDisable(GL_DEPTH_TEST);
#if defined(WIN32)
glWaitVkSemaphoreNV((GLuint64)m_render_done[m_current_buffer_index]);
#endif
glDrawVkImageNV((GLuint64)m_resolve_attachment[m_current_buffer_index].image, 0, 0, 0, float(m_width),
float(m_height), 0, 0, 1, 1, 0);
glEnable(GL_DEPTH_TEST);
#if defined(WIN32)
glSignalVkSemaphoreNV((GLuint64)m_present_done[m_current_buffer_index]);
#endif
}
void vkeGameRendererDynamic::initDescriptorLayout()
{
VkDescriptorSetLayoutBinding sceneLayoutBindings[4];
VkDescriptorSetLayoutBinding textureLayoutBindings[1];
VkDescriptorSetLayoutBinding transformLayoutBinding;
VkDescriptorSetLayoutBinding quadBinding[3];
VkDescriptorSetLayoutBinding terrainBinding[5];
/*----------------------------------------------------------
Scene (Gazelle) objects descriptor and pipeline layout.
----------------------------------------------------------*/
/*
Scene layout bindings (set 0)
Binding 0: Environment Cube Map
Binding 1: Camera Matrix
Binding 2: Model Matrix
Binding 3: Material
*/
layoutBinding(&sceneLayoutBindings[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1);
layoutBinding(&sceneLayoutBindings[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1);
layoutBinding(&sceneLayoutBindings[2], 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 1);
layoutBinding(&sceneLayoutBindings[3], 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_FRAGMENT_BIT, 1);
/*
Transform layout binding (set 2)
Binding 1: Transform Matrix
*/
layoutBinding(&transformLayoutBinding, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 1);
/*
Texture Layout Bindings (Set 1)
Binding 0: Diffuse Texture.
*/
assert(m_materials->count() == 6); // We include 6 slots for textures in the shader
layoutBinding(&textureLayoutBindings[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 6);
descriptorSetLayoutCreate(&m_transform_descriptor_layout, 1, &transformLayoutBinding);
descriptorSetLayoutCreate(&m_scene_descriptor_layout, 4, sceneLayoutBindings);
descriptorSetLayoutCreate(&m_texture_descriptor_set_layout, 1, textureLayoutBindings);
VkDescriptorSetLayout layouts[3] = {m_scene_descriptor_layout, m_texture_descriptor_set_layout, m_transform_descriptor_layout};
/*
Create pipeline layout for the scene.
*/
pipelineLayoutCreate(&m_pipeline_layout, 3, layouts);
/*----------------------------------------------------------
Skybox descriptor and pipeline layout.
----------------------------------------------------------*/
layoutBinding(&quadBinding[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1);
layoutBinding(&quadBinding[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 1);
//descriptor layout describing the bindings.
descriptorSetLayoutCreate(&m_quad_descriptor_set_layout, 2, quadBinding);
//create the pipeline layout
pipelineLayoutCreate(&m_quad_pipeline_layout, 1, &m_quad_descriptor_set_layout);
/*----------------------------------------------------------
Terrain descriptor and pipeline layout.
----------------------------------------------------------*/
layoutBinding(&terrainBinding[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 1);
layoutBinding(&terrainBinding[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
| VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
1);
layoutBinding(&terrainBinding[2], 2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 1);
layoutBinding(&terrainBinding[3], 3, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1);
//descriptor layout describing the bindings.
descriptorSetLayoutCreate(&m_terrain_descriptor_set_layout, 4, terrainBinding);
//create the pipeline layout
pipelineLayoutCreate(&m_terrain_pipeline_layout, 1, &m_terrain_descriptor_set_layout);
}
void vkeGameRendererDynamic::initDescriptorSets()
{
VulkanDC* dc = VulkanDC::Get();
if(!dc)
return;
VulkanDC::Device* device = dc->getDefaultDevice();
initCamera();
vkResetDescriptorPool(device->getVKDevice(), getDescriptorPool(), 0);
VkWriteDescriptorSet writes[6]{};
/*----------------------------------------------------------
Get the resource data for the bindings.
----------------------------------------------------------*/
/*
Terrain textures.
*/
VkeTexture::Data terrain = m_textures.getTexture(0)->getData();
/*
Camera uniform
*/
VkDescriptorBufferInfo camInfo = m_camera->getDescriptor();
/*
Cube map texture.
*/
VkeCubeTexture::Data cube = m_cube_textures.getTexture(1)->getData();
/*
Create descriptor image info array
for the terrain textures.
*/
VkDescriptorImageInfo fpSampler = {terrain.sampler, terrain.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL};
VkeMaterial* material = m_materials->getMaterial(0);
/*
Create descriptor image info array
for the scene textures.
*/
size_t texCount = m_materials->count();
VkDescriptorImageInfo* texImageInfo = (VkDescriptorImageInfo*)malloc(texCount * sizeof(VkDescriptorImageInfo));
for(size_t i = 0; i < texCount; ++i)
{
VkeMaterial* mtrl = m_materials->getMaterial(i);
VkeTexture::Data texData = mtrl->getTextures().getTexture(0)->getData();
texImageInfo[i].imageView = texData.view;
texImageInfo[i].sampler = texData.sampler;
texImageInfo[i].imageLayout = texData.imageLayout;
}
/*
Create descriptor image info for
the cube map texture.
*/
VkDescriptorImageInfo cubeTexture;
cubeTexture.sampler = cube.sampler;
cubeTexture.imageView = cube.view;
cubeTexture.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
/*
Allocate storage for the scene and
texture descriptor sets.
*/
/*----------------------------------------------------------
Allocate the descriptor sets.
----------------------------------------------------------*/
m_texture_descriptor_sets = (VkDescriptorSet*)malloc(sizeof(VkDescriptorSet));
/*
Set up the alocate info structure for
the descriptor sets.
*/
VkDescriptorSetAllocateInfo descAlloc;
memset(&descAlloc, 0, sizeof(descAlloc));
descAlloc.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
descAlloc.descriptorPool = getDescriptorPool();
descAlloc.pSetLayouts = &m_scene_descriptor_layout;
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_scene_descriptor_set),
"Could not allocate descriptor sets.\n");
/*
Set up the texture descriptor sets.
*/
descAlloc.pSetLayouts = &m_texture_descriptor_set_layout;
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, m_texture_descriptor_sets),
"Could not allocate texture descriptor sets.\n");
/*
Set up the skybox descriptor sets.
*/
descAlloc.pSetLayouts = &m_quad_descriptor_set_layout;
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_quad_descriptor_set),
"Could not allocate descriptor sets.\n");
/*
Set up the terrian descriptor sets.
*/
descAlloc.pSetLayouts = &m_terrain_descriptor_set_layout;
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_terrain_descriptor_set),
"Could not allocate descriptor sets.\n");
/*
Set up the transforms descriptor sets.
*/
descAlloc.pSetLayouts = &m_transform_descriptor_layout;
descAlloc.descriptorSetCount = 1;
VKA_CHECK_ERROR(vkAllocateDescriptorSets(device->getVKDevice(), &descAlloc, &m_transform_descriptor_set),
"Could not allocate descriptor sets.\n");
/*----------------------------------------------------------
Update the descriptor sets with resource bindings.
----------------------------------------------------------*/
/*
Scene layout bindings (set 0)
Binding 0: Environment Cube Map
Binding 1: Camera Matrix
Binding 2: Model Matrix
Binding 3: Material
*/
descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &cubeTexture, 0,
m_scene_descriptor_set); //cubemap
descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_scene_descriptor_set); //Camera
descriptorSetWrite(&writes[2], 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_uniforms_descriptor, VK_NULL_HANDLE, 0,
m_scene_descriptor_set); //modelview
descriptorSetWrite(&writes[3], 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &material->getDescriptor(), VK_NULL_HANDLE, 0,
m_scene_descriptor_set); //material
vkUpdateDescriptorSets(device->getVKDevice(), 4, writes, 0, NULL);
/*
Transform layout bindings (set 0)
Binding 0: Transform
*/
descriptorSetWrite(&writes[4], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_transforms_descriptor, VK_NULL_HANDLE, 0,
m_transform_descriptor_set); //transform
vkUpdateDescriptorSets(device->getVKDevice(), 1, writes, 0, NULL);
/*
Scene layout bindings (set 1)
Binding 0: Scene texture array
*/
descriptorSetWrite(&writes[5], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32_t(texCount), VK_NULL_HANDLE,
texImageInfo, 0, m_texture_descriptor_sets[0]); //cubemap
vkUpdateDescriptorSets(device->getVKDevice(), 6, writes, 0, NULL);
//Free the texture image info allocated earlier.
free(texImageInfo);
/*
Skybox layout bindings (set 0)
Binding 0: Skybox Textures
Binding 1: Camera uniforms
*/
descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &cubeTexture, 0, m_quad_descriptor_set);
descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_quad_descriptor_set);
vkUpdateDescriptorSets(device->getVKDevice(), 2, writes, 0, NULL);
/*
Terrain layout bindings (set 0)
Binding 0: Terrain Uniforms
Binding 1: Camera Uniforms
Binding 2: Terrain texture array
*/
descriptorSetWrite(&writes[0], 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &m_terrain_quad.getData().descriptor,
VK_NULL_HANDLE, 0, m_terrain_descriptor_set);
descriptorSetWrite(&writes[1], 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, &camInfo, VK_NULL_HANDLE, 0, m_terrain_descriptor_set);
descriptorSetWrite(&writes[2], 2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &fpSampler, 0, m_terrain_descriptor_set);
descriptorSetWrite(&writes[3], 3, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_NULL_HANDLE, &cubeTexture, 0,
m_terrain_descriptor_set);
vkUpdateDescriptorSets(device->getVKDevice(), 4, writes, 0, NULL);
/*----------------------------------------------------------
Initialise the terrain and scene command buffers.
----------------------------------------------------------*/
initTerrainCommand();
for(uint32_t i = 0; i < m_max_draw_calls; ++i)
{
m_draw_calls[i]->initDescriptor();
}
}
void vkeGameRendererDynamic::initPipeline()
{
VulkanDC* dc = VulkanDC::Get();
VulkanDC::Device* device = dc->getDefaultDevice();
VkPipelineCacheCreateInfo pipelineCache = {VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO};
VkPipelineVertexInputStateCreateInfo vertexState;
VkPipelineInputAssemblyStateCreateInfo inputState;
VkPipelineRasterizationStateCreateInfo rasterState;
VkPipelineColorBlendStateCreateInfo blendState;
VkPipelineDepthStencilStateCreateInfo depthState;
VkPipelineViewportStateCreateInfo viewportState;
VkPipelineMultisampleStateCreateInfo multisampleState;
VkVertexInputBindingDescription binding;
VkVertexInputAttributeDescription attrs[3];
/*----------------------------------------------------------
Create the pipeline cache.
----------------------------------------------------------*/
VKA_CHECK_ERROR(vkCreatePipelineCache(device->getVKDevice(), &pipelineCache, NULL, &m_pipeline_cache),
"Couldn not create pipeline cache.\n");
/*----------------------------------------------------------
Create the scene pipeline.
----------------------------------------------------------*/
/*
Create the vertex input state.
Binding at location 0.
3 attributes:
1 : Vertex Position : vec4
2 : Vertex Normal : vec4
3 : UV : vec2
*/
vertexBinding(&binding, 0, sizeof(VertexObject), VK_VERTEX_INPUT_RATE_VERTEX);
vertexAttributef(&attrs[0], 0, binding.binding, VK_FORMAT_R32G32B32A32_SFLOAT, 0);
vertexAttributef(&attrs[1], 1, binding.binding, VK_FORMAT_R32G32B32A32_SFLOAT, 4);
vertexStateInfo(&vertexState, 1, 2, &binding, attrs);
/*
Create the input assembly state
Topology: Triangle List
Primitive restart enable : false
*/
inputAssemblyStateInfo(&inputState, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, VK_FALSE);
/*
Create the raster state
*/
rasterStateInfo(&rasterState, VK_POLYGON_MODE_FILL);
/*
Create the color blend state.
*/
VkPipelineColorBlendAttachmentState attState[1];
uint32_t sampleMask = 0xFF;
blendAttachmentStateN(1, attState);
blendStateInfo(&blendState, 1, attState);
/*
Create the viewport state
*/
viewportStateInfo(&viewportState, 1);
/*
Create the depth stencil state
*/
depthStateInfo(&depthState);
/*
Create the multisample state
*/
multisampleStateInfo(&multisampleState, getSamples(), &sampleMask);
/*
Create the pipeline shaders.
*/
VkPipelineShaderStageCreateInfo shaderStages[4];
createShaderStage(&shaderStages[0], VK_SHADER_STAGE_VERTEX_BIT, m_shaders.scene_vertex);
createShaderStage(&shaderStages[1], VK_SHADER_STAGE_FRAGMENT_BIT, m_shaders.scene_fragment);
/*
Create the graphics pipeline.
*/
graphicsPipelineCreate(&m_pipeline, &m_pipeline_cache, m_pipeline_layout, 2, shaderStages, &vertexState, &inputState,
&rasterState, &blendState, &multisampleState, &viewportState, &depthState, &m_render_pass, 0,