Created
May 3, 2024 15:04
-
-
Save ant1fact/025ec1941944781fcf85550492c51a2d to your computer and use it in GitHub Desktop.
Enumerate available Vulkan extensions using Zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Zig 0.12.0 | |
// Vulkan 1.3.280.0 | |
// Get the number of extensions | |
var extension_count: u32 = 0; | |
if (vk.vkEnumerateInstanceExtensionProperties(null, &extension_count, null) != vk.VK_SUCCESS) { | |
std.debug.panic("Failed to retrieve instance extension count.", .{}); | |
} | |
// Allocate array to hold enumerated extension properties | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
const allocator = gpa.allocator(); | |
const extension_properties = try allocator.alloc(vk.VkExtensionProperties, extension_count); | |
defer allocator.free(extension_properties); | |
// Enumerate & store extension properties | |
if (vk.vkEnumerateInstanceExtensionProperties(null, &extension_count, extension_properties.ptr) != vk.VK_SUCCESS) { | |
std.debug.panic("Failed to enumerate instance extension properties.", .{}); | |
} | |
// Print extension names | |
std.debug.print("VkInstance Extensions:\n", .{}); | |
for (extension_properties) |ep| { | |
const name: [*:0]const u8 = @ptrCast(&ep.extensionName); | |
std.debug.print("{s}\n", .{name}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment