-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVCK.h
More file actions
1243 lines (1169 loc) · 71.8 KB
/
VCK.h
File metadata and controls
1243 lines (1169 loc) · 71.8 KB
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
// =============================================================================
// VCK.h - Vulkan Core Kit
//
// This header is the SINGLE SOURCE OF TRUTH for the VCK public API.
// Every class, free function, config knob, enum, macro and design rule
// that the user is expected to know about is documented here. The .h
// / .cpp files under layers/ carry only a one-line "what am I" comment
// and link back to this file. Long-form guides live in docs/ and the
// GitHub wiki; this file is deliberately the only place that tries to
// document the surface in depth.
//
// REPOSITORY LAYOUT
// ─────────────────
// VCK.h (this file, main include)
// layers/
// core/ - primitive Vulkan wrappers +
// VCK::Window cross-platform facade.
// VCKCrossplatform.{h,cpp} VCK::Window, WindowCreateInfo,
// VCK_PLATFORM_* detection macros.
// VulkanHelpers.h VCKLog, VK_CHECK, Config, enums.
// VulkanContext.{h,cpp} VkInstance + surface (+ debug).
// VulkanDevice.{h,cpp} VkDevice + queues + features.
// VulkanSwapchain.{h,cpp} VkSwapchain + MSAA + AA detect.
// VulkanBuffer.{h,cpp} Buffers, vertex/index/uniform.
// VulkanImage.{h,cpp} 2D/MSAA images + attachments.
// VulkanPipeline.{h,cpp} Graphics pipeline + A2C + SRS.
// VulkanCommand.{h,cpp} Command pool + primaries.
// VulkanSync.{h,cpp} Per-frame semaphores + fences.
// VmaImpl.cpp VMA single TU (VMA_IMPLEMENTATION).
// expansion/ - reusable rendering building blocks.
// VCKExpansion.{h,cpp} Classes [1]-[12] + [23]-[25] + [26]-[33] +
// HandleLiveResize overloads.
// VCKMath.h Vec2/3/4, Mat4 + free helpers.
// execution/ - frame scheduling & observability.
// VCKExecution.{h,cpp} Classes [13]-[22] + timeline-aware
// and scheduler-aware HandleLiveResize
// overloads.
// vmm/ - memory manager (optional).
// VulkanMemoryManager.{h,cpp}
// vendor/ - source-only third-party deps (in repo).
// vulkan_headers/vulkan/ - Vulkan SDK headers, vendored.
// glfw/include/GLFW/ - GLFW C API headers (used by VCKCrossplatform).
// vma/vk_mem_alloc.h - AMD VMA allocator (used by VmaImpl.cpp).
// example/
// deps/ - binary-only Windows build assets.
// libglfw3.a - GLFW pre-compiled MinGW lib (download,
// not source - Linux/macOS use pkg-config).
// build.bat / build.sh - Windows / Linux+macOS build scripts.
// <14 example dirs> - see example/README.md or docs/Examples.md.
// Menu now runs [1]-[14], [A] builds all.
// docs/ - design, build, examples, API reference.
// Start with docs/Overview.md for the
// one-page "what VCK is / gives / never
// takes / modern v0.3 optimisations" tour.
// .github/workflows/build.yml - CI (Windows runner, build.bat [A]).
//
// LAYERING
// ────────
// layers/core/ instance, device, swapchain, pipeline, sync.
// ↓
// layers/expansion/ textures, meshes, descriptors, framebuffers,
// HandleLiveResize (base + depth).
// ↓
// layers/execution/ FrameScheduler, JobGraph, DebugTimeline,
// timeline-aware HandleLiveResize.
// ↓
// layers/vmm/ (optional) allocator policies + lifetime tags.
// ↓
// your renderer / game / tool
//
// Each layer only depends on the layers above it. Expansion never
// references execution. Core never references expansion.
//
// INIT / SHUTDOWN ORDER
// ─────────────────────
// Init: Window → Context → Device → Swapchain → Pipeline
// → Command → Sync → (expansion resources) → (frame loop)
// Shutdown: Sync → Command → Pipeline → Swapchain → Device → Context
// (expansion resources and VMM allocations must be destroyed
// BEFORE the core object they reference)
//
// NAMESPACE
// ─────────
// Everything VCK exposes lives in: namespace VCK { ... }
// LogVk and VK_CHECK are deliberately at global scope so every TU can
// use them without a `using` declaration.
//
// ONE-HOUR QUICK START (HELLO VCK)
// ────────────────────────────────
// #include "VCK.h"
//
// int main() {
// // 1. Window (GLFW under the hood; one-shot platform init inside).
// VCK::Window window;
// VCK::WindowCreateInfo wci;
// wci.width = 1280; wci.height = 720; wci.title = "Hello VCK";
// wci.resizable = true;
// window.Create(wci);
//
// // 2. Optional non-default knobs. Leave for defaults to get:
// // AATechnique::Auto (first-run 5-step detect),
// // Mailbox→FIFO present, framesInFlight=2, debug=false.
// VCK::Config cfg;
// cfg.swapchain.presentMode = VCK::PresentMode::Mailbox;
// cfg.sync.framesInFlight = 3;
// // cfg.debug = true; // VCKLog Info lines only surface when true.
//
// // 3. Init chain in order. Every step has a zero-Config overload.
// VCK::VulkanContext ctx; ctx .Initialize(window, cfg);
// VCK::VulkanDevice dev; dev .Initialize(ctx, cfg);
// VCK::VulkanSwapchain sc; sc .Initialize(dev, ctx,
// window.GetWidth(),
// window.GetHeight(), cfg);
// VCK::VulkanPipeline pipe; pipe.Initialize(dev, sc, shaders, vi);
// VCK::VulkanCommand cmd; cmd .Initialize(dev, cfg);
// VCK::VulkanSync sync; sync.Initialize(dev, cfg);
// VCK::VulkanFramebufferSet fb; fb.Initialize(dev, sc, pipe);
//
// // 4. Per-frame loop. Drive it yourself, or hand off to
// // VCK::FrameScheduler for automatic pipelining.
// while (!window.ShouldClose()) {
// window.PollEvents();
// if (window.IsMinimized()) { window.WaitEvents(); continue; }
// VCK::HandleLiveResize(window, dev, sc, fb, pipe);
// // ... record commands + submit + present ...
// }
//
// // 5. Reverse teardown. Expansion/VMM first, then core, then window.
// fb.Shutdown(); sync.Shutdown(); cmd.Shutdown();
// pipe.Shutdown(); sc.Shutdown(); dev.Shutdown(); ctx.Shutdown();
// window.Destroy();
// }
//
// See example/HelloExample for the full compilable version, and the
// wiki page "Build your first app" for a per-line walkthrough of why
// each call exists.
//
// CLASS / FREE-FUNCTION INDEX
// ───────────────────────────
// layers/core/
// VCK::Window cross-platform window + input.
// VCK::VulkanContext VkInstance + debug + surface.
// VCK::VulkanDevice VkPhysicalDevice + VkDevice.
// VCK::VulkanSwapchain VkSwapchainKHR + MSAA resolve +
// GetAATechnique() / GetAACfg().
// VCK::VulkanBuffer generic VkBuffer wrapper.
// VCK::VulkanImage 2D / MSAA image + view.
// VCK::VulkanPipeline VkPipeline + A2C + SampleRateShading.
// VCK::VulkanCommand command pool + frame primaries.
// VCK::VulkanSync image-available / render-finished /
// in-flight fences, per frame.
// VCK::VCKLog Info / Notice / Warn / Error with
// dedup + SetDebug(bool).
// VCK::DetectRecommendedAA(...) 5-step AA decision tree (tier →
// forward → motion vectors → pick).
// VCK::AATechnique { Auto, Off, MSAA, MSAA_A2C, SampleRate,
// FXAA, SMAA_1x, SMAA_T2x, TAA, TAAU };
// layers/expansion/
// [1] VulkanOneTimeCommand scoped single-submit command buffer.
// [2] VulkanFramebufferSet one framebuffer per swapchain image.
// [3] VulkanDepthBuffer depth attachment + format pick.
// [4] VulkanSampler VkSampler wrapper + defaults.
// [5] VulkanTexture sampled 2D image + staging upload.
// [6] VulkanMesh vertex + index buffer bundle.
// [7] VulkanDescriptorLayoutBuilder
// [8] VulkanDescriptorPool
// [9] VulkanUniformSet<T> per-frame uniform buffer slots.
// [10] VulkanDescriptorAllocator allocator around 7/8/9.
// [11] VulkanModelPipeline pipeline preset for textured model.
// [12] VulkanMipmapGenerator runtime mipmap blit utility.
// [23] VertexLayout named vertex-input builder.
// [24] PushConstants named push-constant block.
// [25] Primitives Cube/Plane/Sphere/Quad/Line mesh builders.
// VCK::Vec2/3/4 + Mat4 POD math primitives (VCKMath.h).
// HandleLiveResize(window, dev, sc, fb, pipe) base overload.
// HandleLiveResize(window, dev, sc, fb, pipe, depth) + depth buffer.
// HandleLiveResize(window, sc, fb, pipe, scheduler) scheduler-aware
// (v0.3: drains the
// scheduler's timeline
// or fences instead
// of vkDeviceWaitIdle).
// HandleLiveResize(window, sc, fb, pipe, depth, sch) + depth buffer.
// VulkanCommand::AllocateSecondary / BeginSecondary / EndSecondary /
// FreeSecondary / ExecuteSecondaries secondary command
// buffer lifecycle
// (v0.3).
// VulkanDevice::HasTimelineSemaphores() reports whether
// VK_KHR_timeline_semaphore
// is enabled at
// device-create time
// (v0.3).
// VulkanDevice::GetComputeQueue / GetTransferQueue dedicated queues,
// fall back to
// graphics queue +
// VCKLog::Notice
// when vendor does
// not expose them
// (v0.3).
// layers/execution/
// [13] FramePolicy / FrameConfig Pipelined | Lockstep | AsyncMax.
// [14] TimelineSemaphore VK_KHR_timeline_semaphore wrapper.
// [15] DependencyToken cross-frame GPU dependency.
// [16] QueueSet graphics + async compute + transfer.
// [17] GpuSubmissionBatcher coalesce vkQueueSubmit calls.
// [18] BackpressureGovernor cap frames-in-flight under stress.
// [19] JobGraph DAG scheduler for frame sub-tasks.
// [20] DebugTimeline observable span log + Dump() +
// DumpChromeTracing("trace.json").
// [21] Frame per-frame handle: cmd + semaphores.
// [22] FrameScheduler the whole loop as one object.
// HandleLiveResize(window, dev, sc, fb, pipe, timeline)
// HandleLiveResize(window, dev, sc, fb, pipe, depth, timeline)
// FrameScheduler::FrameTimeline() the scheduler's
// per-scheduler
// TimelineSemaphore
// (v0.3).
// FrameScheduler::SlotToken(slot) DependencyToken
// bound to the
// slot's last signalled
// timeline value.
// FrameScheduler::DrainInFlight() wait on every slot's
// most recent submit
// without touching
// vkDeviceWaitIdle
// (v0.3).
// FrameScheduler::SlotCount() → uint32_t number of in-flight slots
// (== framesInFlight).
// Use to initialize FrameData<T>:
// frameData.Initialize(scheduler.SlotCount())
// [23] FrameData<T> - per-frame typed resource ring (UBOs, sets, etc.)
// [24] RenderGraph - declarative barrier-aware render graph skeleton.
// layers/vmm/ (optional)
// VmmRawAlloc / VmmRegistry / VulkanMemoryManager - see its header.
//
// CONFIG KNOBS (VCK::Config)
// ──────────────────────────
// debug surfaces VCKLog Info lines when true.
// context.{appName, validation} instance-layer config.
// device.{preferDiscreteGpu, physical-device selection + extras.
// extraDeviceExtensions,
// queuePref,
// enableTimelineSemaphores, v0.3: chain VK_KHR_timeline_semaphore
// enableDedicatedComputeQueue, when the device supports it; when
// enableDedicatedTransferQueue, off VulkanDevice::HasTimeline-
// enableBindless} Semaphores()/GetComputeQueue()/
// GetTransferQueue() fall back to the
// graphics queue (rule 19).
// enableBindless (post-v0.3, R24): when
// true requests VK_EXT_descriptor_indexing
// and announces it via R23 Notice. Stage-1
// surface only - bindless descriptor
// helpers ship in v0.4.
// rendering.{mode} post-v0.3 (R24): mode = Classic (default,
// VkRenderPass + VkFramebuffer) or
// Dynamic (requests VK_KHR_dynamic_
// rendering; codepath ships in v0.4 -
// today the request is acknowledged via
// R23 Notice and rendering stays Classic).
// swapchain.{presentMode, Mailbox / Fifo / Immediate / FifoLatest-
// msaaSamples, Ready (post-v0.3, R24: requests
// preferredSurfaceFmt} VK_EXT_present_mode_fifo_latest_ready;
// falls back to FIFO with a Warn when
// unavailable, fully wired through
// VulkanDevice + VulkanSwapchain).
// msaaSamples: 1/2/4/8 or MSAA_AUTO
// sentinel (pick from device).
// sync.{framesInFlight} clamped to [1, MAX_FRAMES_IN_FLIGHT].
// aa.{technique, alphaToCoverage, technique=Auto runs detector once;
// sampleRateShading, user inputs forwardRenderer + motion
// minSampleShading, vectors so VCK can pick an AA name.
// forwardRenderer,
// supportsMotionVectors}
// pipeline.{alphaToCoverage, both fed by aa.* if Auto picks MSAA.
// sampleRateShading}
//
// DESIGN RULES (SHORT FORM, see docs/Design.md for full text)
// ───────────────────────────────────────────────────────────
// 1 Explicit > magic. Init/Shutdown pairs, no singletons.
// 2 No ownership leaks. Expansion/execution borrow core by pointer.
// 3 Strict lifecycle order (see INIT / SHUTDOWN ORDER above).
// 4 No hidden sync - only Shutdown() paths may call vkDeviceWaitIdle;
// the runtime hot path never does (v0.3: scheduler-aware HandleLiveResize
// drains via FrameScheduler::DrainInFlight, and VMM staging uses a
// per-submit VkFence). The legacy Swapchain::Recreate default still
// calls vkDeviceWaitIdle unless the caller passes drainedExternally=true
// (scheduler-aware path).
// 5 Frame-scoped or persistent; no orphan allocations.
// 6 No hidden behaviour. Every non-trivial decision is logged.
// 7 User owns the frame, opt in to FrameScheduler.
// 8 Explicit synchronisation model.
// 9 Escape hatch: every class exposes its raw Vk* handle.
// 10 Zero hidden GPU state. VCKLog dedup is a logger convention.
// 11 Deterministic frame behaviour (Pipelined/Lockstep).
// 12 Explicit recreation events - logged + timeline span.
// 13 Debuggability is a core feature (VCKLog + DebugTimeline).
// 14 Fail fast, fail loud. Every failure returns an explicit bool AND
// logs via VCKLog::Error("<subsystem>", ...). VK_CHECK routes non-
// VK_SUCCESS to VCKLog::Error regardless of cfg.debug.
// 15 Minimal core surface - VCK stops at the pipeline.
// 16 No engine assumptions - no scene graph, no material system.
// 17 Frame is the unit of truth.
// 18 External synchronisation. VCK instances are externally synced
// (Vulkan spec); concurrent access from multiple threads is UB
// unless the caller locks. JobGraph is the sole exception.
// 19 Zero cost for unused features. Un-Initialize'd modules allocate
// nothing, spawn no thread, emit no log line.
// 20 Every public class in VCK.h is exercised by at least one example
// under example/.
// 21 VCK.h is the API surface. Layer headers under layers/* are
// implementation detail and may move. Breaking changes to VCK.h
// bump the minor version (0.x) until v1.0.0.
// 22 VCK never owns user handles. Raw Vk* passed in is caller-owned;
// handles VCK returns via getters are borrows, do not destroy them.
// 23 Extension transparency. Every instance- / device-level extension
// VCK enables silently is announced via VCKLog::Notice("Context"|
// "Device", ...) at init, including extension name, support verdict,
// and fallback path. The user is never surprised by what is running
// underneath - grep the init log for "ext " to see the full set.
// 24 cfg is the contract. Every behavioural difference VCK can express
// that the user can reasonably want to choose between lives in cfg.
// Litmus test: "If it changes how the user writes their renderer ->
// cfg. If it changes how VCK works underneath -> silent bundle."
// Today's silent bundle: VK_KHR_synchronization2, VK_KHR_buffer_
// device_address, VK_EXT_memory_budget, VK_EXT_device_fault,
// VK_KHR_present_wait, VK_KHR_present_id (probed + enabled when the
// device advertises them, R23 Notice per result). Today's cfg knobs
// for extensions: cfg.rendering.mode, cfg.device.enableBindless,
// cfg.swapchain.presentMode = FifoLatestReady (see entries above).
// =============================================================================
#pragma once
// ─── System / Vulkan prerequisites ───────────────────────────────────────────
// Platform detection lives in VCKCrossplatform.h - include it first so
// the VCK_PLATFORM_* macros are defined before we use them below.
#include "layers/core/VCKCrossplatform.h"
#if VCK_PLATFORM_WINDOWS
// WIN32_LEAN_AND_MEAN and NOMINMAX are defined by premake / build.bat -
// do NOT redefine here.
#include <windows.h>
#endif
#include <vulkan/vulkan.h>
#if VCK_PLATFORM_WINDOWS
#include <vulkan/vulkan_win32.h>
#endif
#include "vk_mem_alloc.h"
#include "layers/core/VulkanHelpers.h" // VCKLog/LogVk, VK_CHECK, VCK::Config, PresentMode, QueuePreference, MAX_FRAMES_IN_FLIGHT
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <optional>
#include <cstdint>
// =============================================================================
// ██╗ ██╗███████╗██╗ ██████╗ ███████╗██████╗ ███████╗
// ██║ ██║██╔════╝██║ ██╔══██╗██╔════╝██╔══██╗██╔════╝
// ███████║█████╗ ██║ ██████╔╝█████╗ ██████╔╝███████╗
// ██╔══██║██╔══╝ ██║ ██╔═══╝ ██╔══╝ ██╔══██╗╚════██║
// ██║ ██║███████╗███████╗██║ ███████╗██║ ██║███████║
// ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚══════╝╚═╝ ╚═╝╚══════╝
// =============================================================================
// -----------------------------------------------------------------------------
// VulkanHelpers.h
// Global logging utility and VK_CHECK macro.
// No namespace - usable everywhere.
// -----------------------------------------------------------------------------
// LogVk and VK_CHECK are provided by VulkanHelpers.h (included above). They
// remain at global scope so every TU can use them without a `using` decl.
// =============================================================================
// ██████╗ ██╗ █████╗ ███████╗███████╗███████╗███████╗
// ██╔════╝██║ ██╔══██╗██╔════╝██╔════╝██╔════╝██╔════╝
// ██║ ██║ ███████║███████╗███████╗█████╗ ███████╗
// ██║ ██║ ██╔══██║╚════██║╚════██║██╔══╝ ╚════██║
// ╚██████╗███████╗██║ ██║███████║███████║███████╗███████║
// ╚═════╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚══════╝
// =============================================================================
// The class declarations below were previously inlined in this file; they now
// live in the per-class headers so there is a single source of truth. Users
// still include only "VCK.h" (or "VCKExpansion.h") - the amalgam pulls in the
// whole core API. Internal .cpp files can keep including individual headers.
#include "layers/core/VCKMath.h" // Vec2/3/4, Mat4, free functions (no Vulkan deps)
#include "layers/core/VulkanContext.h"
#include "layers/core/VulkanDevice.h"
#include "layers/core/VulkanSwapchain.h"
#include "layers/core/VulkanBuffer.h"
#include "layers/core/VulkanImage.h"
#include "layers/core/VulkanPipeline.h"
#include "layers/core/VulkanSync.h"
#include "layers/core/VulkanCommand.h"
// VCKCrossplatform.h (VCK::Window + VCK_PLATFORM_*) is included at the top of
// this file before any platform conditionals - see line ~90.
// =============================================================================
// ███████╗██╗ ██╗██████╗ █████╗ ███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗
// ██╔════╝╚██╗██╔╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║
// █████╗ ╚███╔╝ ██████╔╝███████║██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║
// ██╔══╝ ██╔██╗ ██╔═══╝ ██╔══██║██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║
// ███████╗██╔╝ ██╗██║ ██║ ██║██║ ╚████║███████║██║╚██████╔╝██║ ╚████║
// ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝
// =============================================================================
// VCKExpansion - higher-level building blocks on top of VCK core
//
// Declared in VCKExpansion.h (auto-included below).
// Implemented in VCKExpansion.cpp.
// All classes live in namespace VCK.
//
// DESIGN RULE
// ───────────
// Every expansion class receives the core objects by reference or raw
// pointer. They do NOT own, construct, or destroy any core object.
// The core init/shutdown order is completely unchanged:
//
// Init: Context → Device → Swapchain → Pipeline → Command → Sync
// Shutdown: Sync → Command → Pipeline → Swapchain → Device → Context
//
// All expansion objects must be Shutdown() BEFORE the core objects they
// reference. A typical ordering is shown in the function index below.
//
// SOURCE FILES ADDED
// ──────────────────
// Header : VCKExpansion.h
// Implementation : VCKExpansion.cpp
//
// CLASSES (20)
// ─────────────
// [1] VulkanOneTimeCommand - one-shot GPU command using the existing pool
// [2] VulkanFramebufferSet - per-swapchain-image VkFramebuffers
// [3] VulkanDepthBuffer - depth/stencil image wrapping VulkanImage
// [4] VulkanSampler - VkSampler with nearest / linear factory methods
// [5] VulkanTexture - VulkanImage + VulkanSampler, hidden staging upload
// [6] VulkanMesh - vertex + index VulkanBuffers with RecordDraw()
// [7] VulkanDescriptorLayoutBuilder - fluent VkDescriptorSetLayout builder
// [8] VulkanDescriptorPool - VkDescriptorPool + per-frame set allocation
// [9] VulkanUniformSet<T> - per-frame typed UBO with Write() + GetSet()
// [10] VulkanDescriptorAllocator - general-purpose pool supporting multiple descriptor types
// [11] VulkanModelPipeline - full model pipeline with UBO layouts + push constants
// [12] VulkanMipmapGenerator - blit-based mip chain generation for any VkImage
// [23] VertexLayout - named vertex-input builder (VkVertex* structs)
// [24] PushConstants - named push-constant block (Declare / Set / Apply)
// [25] Primitives - Cube / Plane / Sphere / Quad / Line mesh builders
// [26] ShaderLoader - loads SPIR-V from .spv files, optional GLSL via glslangValidator
// [27] ShaderWatcher - polls .spv timestamps for hot reload (debug-only)
// [28] SpecConstants - VkSpecializationInfo builder (specialization constants)
// [29] ShaderStage - per-stage VertexLayout / PushConstants / binding declaration
// [30] ShaderInterface - merges ShaderStages into pipeline cfg + descriptor layouts
// [31] HotReload - drives ShaderWatcher→DrainInFlight→Reinitialize→Recreate (debug-only)
// [32] OffscreenTarget - VulkanImage + VkRenderPass + VkFramebuffer for render-to-texture
// [33] FullscreenPass - fullscreen triangle with one COMBINED_IMAGE_SAMPLER input
//
// (Numbers [13]-[22] are used by the execution layer - see below.)
//
// CORE MATHS (header-only, no Vulkan deps)
// ────────────────────────────────────────
// Vec2 / Vec3 / Vec4 plain POD, tightly packed (memcpy-safe).
// Mat4 column-major, 16 floats, identity default.
// Translate / Rotate / Scale affine builders.
// Perspective / LookAt Vulkan-ready (Y-flipped, depth [0,1]).
// operator+ / - / * / Dot / Cross / Normalize / Length / Transpose / Radians / Degrees
//
// HELPER FUNCTION (file-static, internal)
// ───────────────────────────────────────
// FindDepthFormat(VulkanDevice&)
// Iterates D32_SFLOAT → D32_SFLOAT_S8_UINT → D24_UNORM_S8_UINT and
// returns the first format that supports DEPTH_STENCIL_ATTACHMENT optimal
// tiling. Called internally by VulkanDepthBuffer::Initialize() and Recreate().
// =============================================================================
// -----------------------------------------------------------------------------
// VulkanOneTimeCommand
//
// Allocates a single transient VkCommandBuffer from the existing
// VulkanCommand pool, records your work, submits it to the graphics queue,
// and blocks (vkQueueWaitIdle) until the GPU is done.
// Frees the command buffer on End().
//
// Use for one-off GPU operations: staging copies, image layout transitions,
// mipmap generation. Not intended for per-frame use.
//
// Usage:
// VulkanOneTimeCommand otc;
// if (otc.Begin(device, command))
// {
// // record vkCmd* calls via otc.Cmd()
// otc.End(); // submit + vkQueueWaitIdle + free
// }
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Begin(VulkanDevice& device, VulkanCommand& command)
// Allocates from command.GetCommandPool() and opens the buffer.
// Returns false if allocation or vkBeginCommandBuffer fails.
// void End()
// Ends recording, submits to device.GetGraphicsQueue(),
// calls vkQueueWaitIdle, then frees the buffer back to the pool.
//
// ── Accessor ──────────────────────────────────────────────────────────────
// VkCommandBuffer Cmd() const
// Returns the open command buffer. Valid between Begin() and End().
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanFramebufferSet
//
// Creates one VkFramebuffer per swapchain image and stores them in a vector.
// Optionally attaches a depth image view as the second framebuffer attachment.
//
// Typically created after VulkanPipeline and recreated on every resize.
// Pass Get(imageIndex) as the framebuffer in VkRenderPassBeginInfo.
//
// Usage:
// VulkanFramebufferSet fbs;
// fbs.Initialize(device, swapchain, pipeline.GetRenderPass(),
// depth.GetImageView()); // omit last arg for colour-only
//
// // on resize (after swapchain.Recreate() + depth.Recreate()):
// fbs.Recreate(pipeline.GetRenderPass(), depth.GetImageView());
//
// // per frame:
// beginInfo.framebuffer = fbs.Get(frame.ImageIndex);
//
// fbs.Shutdown(); // before pipeline.Shutdown()
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device,
// VulkanSwapchain& swapchain,
// VkRenderPass renderPass,
// VkImageView depthView = VK_NULL_HANDLE)
// Creates one framebuffer per swapchain image view.
// Pass VK_NULL_HANDLE for depthView on colour-only render passes.
// void Shutdown()
// Destroys all framebuffers and releases references.
// bool Recreate(VkRenderPass renderPass,
// VkImageView depthView = VK_NULL_HANDLE)
// Destroys existing framebuffers and rebuilds from the current swapchain
// image views. Call after VulkanSwapchain::Recreate().
//
// ── Accessors ─────────────────────────────────────────────────────────────
// VkFramebuffer Get(uint32_t imageIndex) const
// Returns the framebuffer for the given swapchain image index.
// uint32_t Count() const
// Number of framebuffers (equals swapchain image count).
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanDepthBuffer
//
// Depth/stencil image backed by VulkanImage. The best available format is
// chosen automatically by FindDepthFormat():
// D32_SFLOAT → D32_SFLOAT_S8_UINT → D24_UNORM_S8_UINT
//
// The image is created and immediately transitioned to
// VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL on Initialize().
//
// Usage:
// VulkanDepthBuffer depth;
// depth.Initialize(device, width, height);
//
// // pass to VulkanFramebufferSet:
// fbs.Initialize(device, swapchain, renderPass, depth.GetImageView());
//
// // on resize (after swapchain.Recreate()):
// depth.Recreate(newWidth, newHeight);
//
// depth.Shutdown(); // before device.Shutdown()
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device, uint32_t width, uint32_t height)
// void Shutdown()
// bool Recreate(uint32_t width, uint32_t height)
// Calls Shutdown() + Initialize() in one step. device reference is kept
// from the original Initialize() call.
//
// ── Accessors ─────────────────────────────────────────────────────────────
// VkImageView GetImageView() const
// VkFormat GetFormat() const
// bool IsValid() const
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanSampler
//
// Thin wrapper around VkSampler with two filter-mode factory methods.
// Anisotropy is queried from the physical device and enabled automatically
// when the device supports it.
//
// Usage:
// VulkanSampler sampler;
// sampler.CreateLinear(device);
//
// // in a descriptor write:
// imageInfo.sampler = sampler.GetSampler();
//
// sampler.Shutdown(); // before device.Shutdown()
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool CreateNearest(VulkanDevice& device)
// VK_FILTER_NEAREST, no mipmapping.
// Best for pixel-perfect / UI textures.
// bool CreateLinear(VulkanDevice& device)
// VK_FILTER_LINEAR, no mipmapping.
// General-purpose smooth textures.
// void Shutdown()
// Destroys the VkSampler.
//
// ── Accessors ─────────────────────────────────────────────────────────────
// VkSampler GetSampler() const
// bool IsValid() const
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanTexture
//
// One-stop GPU texture: VulkanImage (R8G8B8A8_SRGB) + VulkanSampler (linear).
// CreateFromPixels() performs the complete CPU→GPU upload without any manual
// staging management:
// 1. Allocates a staging VulkanBuffer.
// 2. Copies pixels into it.
// 3. Opens a VulkanOneTimeCommand.
// 4. Transitions image UNDEFINED → TRANSFER_DST_OPTIMAL.
// 5. Copies buffer → image.
// 6. Transitions image TRANSFER_DST_OPTIMAL → SHADER_READ_ONLY_OPTIMAL.
// 7. Submits, waits, frees the staging buffer.
//
// NOTE: Each call to CreateFromPixels submits a one-shot command and stalls
// the GPU queue until it completes. For bulk uploads, use the VMM staging ring.
//
// Usage:
// VulkanTexture tex;
// tex.CreateFromPixels(device, command, pixels, 512, 512);
//
// // in a descriptor write:
// imageInfo.imageView = tex.GetImageView();
// imageInfo.sampler = tex.GetSampler();
// imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
//
// tex.Shutdown(); // before device.Shutdown()
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool CreateFromPixels(VulkanDevice& device,
// VulkanCommand& command,
// const uint8_t* pixels,
// uint32_t width,
// uint32_t height)
// pixels must point to width * height * 4 bytes (RGBA8).
// void Shutdown()
// Destroys the image and sampler.
//
// ── Accessors ─────────────────────────────────────────────────────────────
// VkImageView GetImageView() const
// VkSampler GetSampler() const
// bool IsValid() const
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanMesh
//
// GPU-resident vertex buffer and optional index buffer.
// Upload is done once via a VulkanOneTimeCommand + staging buffers.
// Staging memory is freed immediately after the GPU copy completes.
// Call RecordDraw() every frame inside an active render pass.
//
// Usage:
// VulkanMesh mesh;
// mesh.Upload(device, command,
// verts.data(), sizeof(verts),
// indices.data(), (uint32_t)indices.size());
//
// // non-indexed:
// mesh.Upload(device, command, verts.data(), sizeof(verts), nullptr, 0);
//
// // inside render pass, per frame:
// mesh.RecordDraw(cmd);
//
// mesh.Shutdown(); // before device.Shutdown()
//
// RecordDraw() will:
// • vkCmdBindVertexBuffers - binding 0
// • vkCmdBindIndexBuffer - only when an index buffer was uploaded
// • vkCmdDrawIndexed / vkCmdDraw
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Upload(VulkanDevice& device,
// VulkanCommand& command,
// const void* vertices, // raw vertex data
// VkDeviceSize vertexSize, // total byte size of vertex data
// const uint32_t* indices, // uint32 index array (or nullptr)
// uint32_t indexCount) // 0 for non-indexed
// void Shutdown()
//
// ── Per-frame recording ───────────────────────────────────────────────────
// void RecordDraw(VkCommandBuffer cmd) const
// Binds buffers and issues one draw call.
//
// ── Accessors ─────────────────────────────────────────────────────────────
// bool IsValid() const - true if the vertex buffer was uploaded successfully
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanDescriptorLayoutBuilder
//
// Fluent builder for VkDescriptorSetLayout.
// Chain Add() calls in binding-slot order, then call Build().
// The returned layout is caller-owned - destroy it with
// vkDestroyDescriptorSetLayout(device.GetDevice(), layout, nullptr) when done.
//
// Usage:
// VkDescriptorSetLayout layout =
// VulkanDescriptorLayoutBuilder{}
// .Add(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// VK_SHADER_STAGE_VERTEX_BIT)
// .Add(1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
// VK_SHADER_STAGE_FRAGMENT_BIT)
// .Build(device);
//
// // …use layout…
//
// vkDestroyDescriptorSetLayout(device.GetDevice(), layout, nullptr);
//
// ── Builder methods ───────────────────────────────────────────────────────
// VulkanDescriptorLayoutBuilder& Add(uint32_t binding,
// VkDescriptorType type,
// VkShaderStageFlags stages)
// Appends one binding and returns *this for chaining.
// VkDescriptorSetLayout Build(VulkanDevice& device) const
// Creates and returns the layout. Returns VK_NULL_HANDLE on failure.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanDescriptorPool
//
// Creates a VkDescriptorPool pre-sized for one descriptor type and
// pre-allocates exactly `framesInFlight` descriptor sets from a given
// layout in a single Initialize() call - the standard pattern for per-frame
// uniform data. The caller passes `framesInFlight` (typically
// cfg.sync.framesInFlight) so the descriptor ring matches the runtime
// frame ring exactly - no unused slots, no stale sets.
//
// Usage:
// VkDescriptorSetLayout layout =
// VulkanDescriptorLayoutBuilder{}
// .Add(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// VK_SHADER_STAGE_VERTEX_BIT)
// .Build(device);
//
// VulkanDescriptorPool pool;
// pool.Initialize(device, layout, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// /*framesInFlight=*/cfg.sync.framesInFlight);
//
// // per frame:
// VkDescriptorSet set = pool.GetSet(frameIndex);
//
// pool.Shutdown();
// vkDestroyDescriptorSetLayout(device.GetDevice(), layout, nullptr);
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device,
// VkDescriptorSetLayout layout,
// VkDescriptorType type,
// uint32_t framesInFlight)
// Creates the pool and allocates exactly `framesInFlight` sets from
// the layout. framesInFlight must be in [1, MAX_FRAMES_IN_FLIGHT].
// void Shutdown()
// Destroys the pool (all allocated sets are implicitly freed).
//
// ── Accessor ──────────────────────────────────────────────────────────────
// VkDescriptorSet GetSet(uint32_t frameIndex) const
// Returns the pre-allocated descriptor set for the given frame slot.
// Out-of-range frameIndex returns VK_NULL_HANDLE + VCKLog::Error.
// uint32_t GetFramesInFlight() const
// Returns the value passed to Initialize() (0 before/after). Used by
// VulkanUniformSet<T> so the UBO ring sizes itself to the pool.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanUniformSet<T>
//
// Template wrapper: one per-frame uniform buffer of type T, wired to the
// descriptor sets provided by VulkanDescriptorPool.
// T must be a trivially-copyable struct (matrices, light params, etc.).
//
// Initialize() creates exactly pool.GetFramesInFlight() VulkanBuffer
// per-frame uniform buffers and calls vkUpdateDescriptorSets to point each
// frame's descriptor set at its matching buffer.
// Write() does a plain memcpy into the persistently-mapped buffer.
//
// Usage:
// struct FrameUBO { float viewProj[16]; float camPos[4]; };
//
// VkDescriptorSetLayout layout =
// VulkanDescriptorLayoutBuilder{}
// .Add(0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// VK_SHADER_STAGE_VERTEX_BIT)
// .Build(device);
//
// VulkanDescriptorPool pool;
// pool.Initialize(device, layout, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
// /*framesInFlight=*/cfg.sync.framesInFlight);
//
// VulkanUniformSet<FrameUBO> ubo;
// ubo.Initialize(device, pool, 0 /* binding */);
//
// // every frame:
// ubo.Write(frameIndex, frameData);
// vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
// pipelineLayout, 0, 1,
// &ubo.GetSet(frameIndex), 0, nullptr);
//
// ubo.Shutdown(); // before pool.Shutdown()
// pool.Shutdown();
// vkDestroyDescriptorSetLayout(device.GetDevice(), layout, nullptr);
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device,
// VulkanDescriptorPool& pool,
// uint32_t binding)
// Allocates per-frame UBO buffers and writes descriptor updates.
// void Shutdown()
// Calls VulkanBuffer::Shutdown() on all per-frame buffers.
//
// ── Per-frame use ─────────────────────────────────────────────────────────
// void Write(uint32_t frameIndex, const T& data)
// memcpy T into the frame slot's mapped uniform buffer.
// VkDescriptorSet GetSet(uint32_t frameIndex) const
// Returns the descriptor set for binding via vkCmdBindDescriptorSets.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanDescriptorAllocator
//
// General-purpose VkDescriptorPool that supports multiple descriptor types in
// a single pool and exposes Allocate() to pull individual VkDescriptorSets
// from any compatible layout. All sets are freed implicitly when Shutdown()
// destroys the pool.
//
// Unlike VulkanDescriptorPool (which pre-allocates a fixed number of sets of
// one type), this class is suitable for mixed layouts - e.g. a set-0 UBO
// layout and a set-1 sampler layout allocated from the same pool.
//
// Usage:
// VulkanDescriptorAllocator alloc;
// alloc.Initialize(device, 8,
// {{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4 },
// { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 }});
//
// VkDescriptorSet s0 = alloc.Allocate(set0Layout);
// VkDescriptorSet s1 = alloc.Allocate(set1Layout);
// // ...use sets...
// alloc.Shutdown(); // frees pool + all sets implicitly
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device,
// uint32_t maxSets,
// initializer_list<PoolSize> sizes)
// Creates the pool. maxSets is the total set count across all Allocate()
// calls. sizes lists each descriptor type and its total count in the pool.
// void Shutdown()
// Destroys the pool (all allocated sets freed implicitly).
//
// ── Allocation ────────────────────────────────────────────────────────────
// VkDescriptorSet Allocate(VkDescriptorSetLayout layout)
// Allocates one descriptor set. Returns VK_NULL_HANDLE on failure.
//
// ── Nested type ───────────────────────────────────────────────────────────
// struct PoolSize { VkDescriptorType type; uint32_t count; }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// VulkanModelPipeline
//
// A fully-wired model pipeline. VulkanPipeline owns the VkRenderPass and
// creates a baseline VkPipeline with an empty layout. VulkanModelPipeline
// takes that render pass and builds the properly-wired VkPipeline that App
// actually draws with.
//
// Descriptor layout:
// set 0, binding 0 - per-frame UBO (VK_SHADER_STAGE_VERTEX_BIT)
// set 1, binding 0 - combined image/sampler (VK_SHADER_STAGE_FRAGMENT_BIT)
//
// Push constant (VK_SHADER_STAGE_VERTEX_BIT, 64 bytes):
// mat4 model
//
// Usage (after VulkanPipeline::Initialize has run):
// VulkanModelPipeline mp;
// mp.Initialize(device, pipeline.GetRenderPass(), shaders, vertexInput);
//
// // per frame:
// vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, mp.GetPipeline());
// vkCmdBindDescriptorSets(cmd, ..., mp.GetPipelineLayout(), ...);
// vkCmdPushConstants(cmd, mp.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT,
// 0, 64, &pc);
// mesh.RecordDraw(cmd);
//
// // shutdown before VulkanPipeline:
// mp.Shutdown();
//
// ── Lifecycle ─────────────────────────────────────────────────────────────
// bool Initialize(VulkanDevice& device,
// VkRenderPass renderPass,
// const VulkanPipeline::ShaderInfo& shaders,
// const VulkanPipeline::VertexInputInfo& vertexInput)
// renderPass is borrowed from VulkanPipeline::GetRenderPass() - NOT owned.
// void Shutdown()
// Destroys pipeline, pipeline layout, and both descriptor set layouts.
// Must be called before the VulkanPipeline that provided the render pass.
//
// ── Accessors ─────────────────────────────────────────────────────────────
// VkPipeline GetPipeline() const
// VkPipelineLayout GetPipelineLayout() const
// VkDescriptorSetLayout GetSet0Layout() const - use with VulkanDescriptorAllocator
// VkDescriptorSetLayout GetSet1Layout() const - use with VulkanDescriptorAllocator
// -----------------------------------------------------------------------------
// =============================================================================
// IMPLEMENTATION FUNCTION INDEX
// All functions defined across the .cpp files, grouped by translation unit.
// (Declarations above; implementations in their respective .cpp files.)
// =============================================================================
/*
────────────────────────────────────────────────────────────────────────────────
VmaImpl.cpp
(VMA implementation unit - define VMA_IMPLEMENTATION before including
vk_mem_alloc.h in exactly one .cpp file)
────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────
VulkanContext.cpp
────────────────────────────────────────────────────────────────────────────────
bool VulkanContext::Initialize(const Window&, const std::string& appName, const Config& = {})
bool VulkanContext::Initialize(HWND windowHandle, const std::string& appName) // Windows-only legacy overload
void VulkanContext::Shutdown()
bool VulkanContext::CreateInstance(const std::string& appName, const std::vector<const char*>& surfaceExtensions)
bool VulkanContext::CreateDebugMessenger()
bool VulkanContext::CreateSurface(const Window&)
bool VulkanContext::CreateSurface(HWND windowHandle) // Windows-only legacy overload
bool VulkanContext::CheckValidationLayerSupport()
VkBool32 VulkanContext::DebugCallback(severity, type, pCallbackData, pUserData)
────────────────────────────────────────────────────────────────────────────────
VulkanDevice.cpp
────────────────────────────────────────────────────────────────────────────────
bool VulkanDevice::Initialize(VkInstance, VkSurfaceKHR)
void VulkanDevice::Shutdown()
bool VulkanDevice::PickPhysicalDevice(VkInstance, VkSurfaceKHR)
int VulkanDevice::ScorePhysicalDevice(VkPhysicalDevice, VkSurfaceKHR) const
bool VulkanDevice::IsPhysicalDeviceSuitable(VkPhysicalDevice, VkSurfaceKHR) const
bool VulkanDevice::CheckDeviceExtensionSupport(VkPhysicalDevice) const
QueueFamilyIndices VulkanDevice::FindQueueFamilies(VkPhysicalDevice, VkSurfaceKHR) const
bool VulkanDevice::CreateLogicalDevice()
bool VulkanDevice::CreateAllocator(VkInstance)
SwapchainSupportDetails VulkanDevice::QuerySwapchainSupport(VkSurfaceKHR) const
────────────────────────────────────────────────────────────────────────────────
VulkanSwapchain.cpp
────────────────────────────────────────────────────────────────────────────────
bool VulkanSwapchain::Initialize(VulkanDevice&, VkSurfaceKHR, uint32_t w, uint32_t h)
void VulkanSwapchain::Shutdown()
bool VulkanSwapchain::Recreate(uint32_t width, uint32_t height,
bool drainedExternally = false)
// v0.3: drainedExternally=true skips the internal vkDeviceWaitIdle; the
// scheduler-aware HandleLiveResize overload sets it after DrainInFlight().
bool VulkanSwapchain::CreateSwapchain(uint32_t width, uint32_t height)
void VulkanSwapchain::DestroySwapchainResources()
VkSurfaceFormatKHR VulkanSwapchain::ChooseSurfaceFormat(const vector<VkSurfaceFormatKHR>&) const
VkPresentModeKHR VulkanSwapchain::ChoosePresentMode(const vector<VkPresentModeKHR>&) const
VkExtent2D VulkanSwapchain::ChooseExtent(const VkSurfaceCapabilitiesKHR&, uint32_t w, uint32_t h) const
────────────────────────────────────────────────────────────────────────────────
VulkanBuffer.cpp
────────────────────────────────────────────────────────────────────────────────
bool VulkanBuffer::Create(VulkanDevice&, VkDeviceSize, VkBufferUsageFlags, VmaMemoryUsage)
void VulkanBuffer::Shutdown()