@@ -161,12 +161,6 @@ class VkRegistryEmitter {
161161 file.writefln! " import vulkan.%s.%s;" (deprecated_.prefix, deprecated_.shortName);
162162 }
163163
164- if (auto deps = ext.name in dependencies) {
165- foreach (ref dep; (* deps).map! (d => registry.extensions[d])) {
166- file.writefln! " import vulkan.%s.%s;" (dep.prefix, dep.shortName);
167- }
168- }
169-
170164 if (auto video = ext.name in videos) {
171165 foreach (v; * video) {
172166 file.writefln! " import vulkan.video.%s;" (v);
@@ -340,7 +334,7 @@ class VkRegistryEmitter {
340334 * Emit a section from core Vulkan.
341335 */
342336 private void emitCoreSection (const ref VkSection section, const ref VkFeature feature, ref VkTypeCategory prevcategory) {
343- emitSection(section, prevcategory);
337+ emitSection(section, prevcategory, null );
344338
345339 if (! section.commands.empty) {
346340 if (prevcategory) {
@@ -369,11 +363,11 @@ class VkRegistryEmitter {
369363 * Emit a section from a Vulkan extension.
370364 */
371365 private void emitExtSection (const ref VkSection section, const ref VkExtension ext, ref VkTypeCategory prevcategory) {
372- emitSection(section, prevcategory);
366+ emitSection(section, prevcategory, &ext );
373367
374368 foreach (ref command; section.commands.map! (c => registry.commands[c])) {
375369 file.writeln();
376- emitFuncPtr(command);
370+ emitFuncPtr(command, &ext );
377371 }
378372 }
379373
@@ -432,7 +426,7 @@ class VkRegistryEmitter {
432426 /**
433427 * Common functionality between all functions that emit Vulkan sections.
434428 */
435- private VkTypeCategory emitSection (const ref VkSection section, ref VkTypeCategory prevcategory) {
429+ private VkTypeCategory emitSection (const ref VkSection section, ref VkTypeCategory prevcategory, const VkExtension * current ) {
436430 // Section marker.
437431 if (! section.name.empty) {
438432 file.writeln();
@@ -476,23 +470,23 @@ class VkRegistryEmitter {
476470 break ;
477471
478472 case VkTypeCategory.Bitmask:
479- emitBitmask(registry.bitmasks[type.name]);
473+ emitBitmask(registry.bitmasks[type.name], current );
480474 break ;
481475
482476 case VkTypeCategory.Handle:
483477 emitHandle(registry.handles[type.name]);
484478 break ;
485479
486480 case VkTypeCategory.Enum:
487- emitEnum(registry.enums[type.name]);
481+ emitEnum(registry.enums[type.name], current );
488482 break ;
489483
490484 case VkTypeCategory.FuncPtr:
491- emitFuncPtr(registry.funcptrs[type.name]);
485+ emitFuncPtr(registry.funcptrs[type.name], current );
492486 break ;
493487
494488 case VkTypeCategory.Struct:
495- emitStruct(registry.structs[type.name]);
489+ emitStruct(registry.structs[type.name], current );
496490 break ;
497491
498492 case VkTypeCategory.Union:
@@ -522,7 +516,7 @@ class VkRegistryEmitter {
522516 (typeof (null )) {},
523517 (string name) {
524518 if (name in registry.features) {
525- file.writefln! " version (%s):" (name);
519+ // file.writefln!"version (%s):"(name);
526520 } else if (auto dep = name in registry.extensions) {
527521 file.writefln! " public import vulkan.%s.%s;" (dep.prefix, dep.shortName);
528522 } else {
@@ -572,8 +566,11 @@ class VkRegistryEmitter {
572566 }
573567 }
574568
575- private void emitBitmask (const ref VkBitmaskType bitmask) {
576- if (bitmask.alias_.empty) {
569+ private void emitBitmask (const ref VkBitmaskType bitmask, const VkExtension* current) {
570+ if (bitmask.bitvalues) {
571+ emitProvenance(bitmask.bitvalues, current);
572+ file.writefln! " alias %s = VkBitFlagsBase!(%s, %s);" (bitmask.name, bitmask.backing, bitmask.bitvalues);
573+ } else if (bitmask.alias_.empty) {
577574 file.writefln! " alias %s = %s;" (bitmask.name, bitmask.backing);
578575 } else {
579576 file.writefln! " alias %s = %s;" (bitmask.name, bitmask.alias_);
@@ -589,7 +586,8 @@ class VkRegistryEmitter {
589586 }
590587 }
591588
592- private void emitEnum (const ref VkEnumType enum_) {
589+ private void emitEnum (const ref VkEnumType enum_, const (VkExtension)* current) {
590+ emitProvenance(enum_, current);
593591 if (enum_.alias_) {
594592 emitAlias(enum_.name, enum_.alias_);
595593 } else if (enum_.bitmask) {
@@ -649,20 +647,21 @@ class VkRegistryEmitter {
649647 }
650648 }
651649
652- private void emitFuncPtr (const ref VkCommand command) {
650+ private void emitFuncPtr (const ref VkCommand command, const (VkExtension) * current ) {
653651 if (command.alias_) {
654652 auto funcptr = registry.commands[command.alias_].funcptr;
655- emitFuncPtr(funcptr);
653+ emitFuncPtr(funcptr, current );
656654 } else {
657655 auto funcptr = command.funcptr;
658- emitFuncPtr(funcptr);
656+ emitFuncPtr(funcptr, current );
659657 }
660658 }
661659
662- private void emitFuncPtr (const ref VkFuncPtrType funcptr) {
660+ private void emitFuncPtr (const ref VkFuncPtrType funcptr, const (VkExtension) * current ) {
663661 if (funcptr.params.empty) {
664662 file.writefln! " alias %s = %s function();" (funcptr.name, funcptr.type);
665663 } else {
664+ emitProvenance(funcptr, current);
666665 file.openf! " alias %s = %s function(" (funcptr.name, funcptr.type);
667666 foreach (ref param; funcptr.params) {
668667 file.writefln! " %s %s," (param.type, param.safename);
@@ -671,11 +670,12 @@ class VkRegistryEmitter {
671670 }
672671 }
673672
674- private void emitStruct (const ref VkStructType struct_) {
673+ private void emitStruct (const ref VkStructType struct_, const (VkExtension) * current ) {
675674 if (struct_.name.isBespoke) {
676675 return ;
677676 }
678677
678+ emitProvenance(struct_, current);
679679 if (! struct_.alias_.empty) {
680680 emitAlias(struct_.name, struct_.alias_);
681681 } else if (struct_.members.empty) {
@@ -735,6 +735,7 @@ class VkRegistryEmitter {
735735 if (command.params.empty) {
736736 file.writefln! " extern %s %s();" (command.type, command.name);
737737 } else {
738+ emitProvenance(command, null );
738739 file.openf! " extern %s %s(" (command.type, command.name);
739740 foreach (param; command.params) {
740741 file.writefln! " %s %s," (param.type, param.safename);
@@ -749,6 +750,77 @@ class VkRegistryEmitter {
749750 }
750751 }
751752
753+ private void emitProvenance (const ref VkEnumType enum_, const (VkExtension)* current) {
754+ if (enum_.alias_) {
755+ emitProvenance(enum_.alias_, current);
756+ return ;
757+ }
758+ }
759+
760+ private void emitProvenance (const ref VkStructType struct_, const (VkExtension)* current) {
761+ if (struct_.alias_) {
762+ emitProvenance(struct_.alias_, current);
763+ return ;
764+ }
765+
766+ string [][string ] provs;
767+ foreach (ref member; struct_.members) {
768+ if (auto ext = registry.provenance(member.utype)) {
769+ provs[ext.name] ~= member.utype;
770+ }
771+ }
772+
773+ foreach (ext, deps; provs) {
774+ emitImport(registry.extensions[ext], deps.filter! (d => d ! in * current).array);
775+ }
776+ }
777+
778+ private void emitProvenance (const ref VkFuncPtrType funcptr, const (VkExtension)* current) {
779+ string [][string ] provs;
780+ foreach (ref param; funcptr.params) {
781+ if (auto ext = registry.provenance(param.utype)) {
782+ provs[ext.name] ~= param.utype;
783+ }
784+ }
785+
786+ foreach (ext, deps; provs) {
787+ emitImport(registry.extensions[ext], deps.filter! (d => d ! in * current).array);
788+ }
789+ }
790+
791+ private void emitProvenance (const ref VkCommand command, const (VkExtension)* current) {
792+ string [][string ] provs;
793+ foreach (ref param; command.params) {
794+ if (auto ext = registry.provenance(param.utype)) {
795+ provs[ext.name] ~= param.utype;
796+ }
797+ }
798+
799+ foreach (ext, deps; provs) {
800+ emitImport(registry.extensions[ext], deps.filter! (d => d ! in * current).array);
801+ }
802+ }
803+
804+ private void emitProvenance (string name, const (VkExtension)* current) {
805+ if (! current || name ! in * current) {
806+ if (auto ext = registry.provenance(name)) {
807+ if (! current || ext.name != current.name) {
808+ emitImport(* ext, [name]);
809+ }
810+ }
811+ }
812+ }
813+
814+ private void emitImport (const ref VkExtension ext) {
815+ file.writefln! " import vulkan.%s.%s;" (ext.prefix, ext.shortName);
816+ }
817+
818+ private void emitImport (const ref VkExtension ext, string [] deps) {
819+ if (! deps.empty) {
820+ file.writefln! " import vulkan.%s.%s : %s;" (ext.prefix, ext.shortName, deps.join(" , " ));
821+ }
822+ }
823+
752824 private void emitAlias (string lhs, string rhs) {
753825 file.writefln! " alias %s = %s;" (lhs, rhs);
754826 }
@@ -877,35 +949,6 @@ private const string[string] platforms = [
877949 " macos" : " OSX" ,
878950];
879951
880- /**
881- * Dependencies between extensions that have to be manually added because
882- * vk.xml is a mess.
883- */
884- private string [][string ] dependencies = [
885- " VK_EXT_pipeline_properties" : [
886- " VK_KHR_pipeline_executable_properties" ,
887- ],
888- " VK_KHR_ray_tracing_pipeline" : [
889- " VK_KHR_pipeline_library" ,
890- ],
891- " VK_NV_framebuffer_mixed_samples" : [
892- " VK_AMD_mixed_attachment_samples" ,
893- ],
894- " VK_NV_cooperative_matrix" : [
895- " VK_KHR_shader_bfloat16" ,
896- " VK_KHR_cooperative_matrix" ,
897- ],
898- " VK_NV_partitioned_acceleration_structure" : [
899- " VK_NV_cluster_acceleration_structure" ,
900- ],
901- " VK_QCOM_render_pass_transform" : [
902- " VK_KHR_surface" ,
903- ],
904- " VK_QCOM_rotated_copy_commands" : [
905- " VK_KHR_surface" ,
906- ],
907- ];
908-
909952/**
910953 * Map Vulkan extensions to Vulkan Video modules.
911954 */
0 commit comments