inspecting without glfw
This commit is contained in:
59
src/dsa.zig
Normal file
59
src/dsa.zig
Normal file
@@ -0,0 +1,59 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Slices must be sorted. Checks if `a` includes all elements of `b`.
|
||||
pub fn includes(comptime T: type, a: []const T, b: []const T) bool {
|
||||
var ia: usize = 0;
|
||||
var ib: usize = 0;
|
||||
|
||||
while (ib != b.len) {
|
||||
if (ia == a.len) return false;
|
||||
if (b[ib] < a[ia]) return false;
|
||||
if (!(a[ia] < b[ib])) ib += 1;
|
||||
ia += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
test includes {
|
||||
try std.testing.expect(includes(
|
||||
usize,
|
||||
&.{},
|
||||
&.{},
|
||||
));
|
||||
try std.testing.expect(includes(
|
||||
usize,
|
||||
&.{ 1, 2, 3, 4, 5 },
|
||||
&.{},
|
||||
));
|
||||
try std.testing.expect(includes(
|
||||
usize,
|
||||
&.{ 1, 2, 3, 4, 5 },
|
||||
&.{ 1, 2, 3, 4, 5 },
|
||||
));
|
||||
try std.testing.expect(!includes(
|
||||
usize,
|
||||
&.{},
|
||||
&.{ 1, 2, 3, 4, 5 },
|
||||
));
|
||||
|
||||
try std.testing.expect(includes(
|
||||
usize,
|
||||
&.{ 1, 2, 2, 4 },
|
||||
&.{ 2, 2 },
|
||||
));
|
||||
try std.testing.expect(includes(
|
||||
usize,
|
||||
&.{ 1, 2, 2, 4 },
|
||||
&.{ 1, 2, 2, 4 },
|
||||
));
|
||||
try std.testing.expect(!includes(
|
||||
usize,
|
||||
&.{ 1, 2, 2, 4 },
|
||||
&.{ 2, 2, 2 },
|
||||
));
|
||||
try std.testing.expect(!includes(
|
||||
usize,
|
||||
&.{ 1, 2, 2, 4 },
|
||||
&.{ 2, 2, 3 },
|
||||
));
|
||||
}
|
63
src/inspect.zig
Normal file
63
src/inspect.zig
Normal file
@@ -0,0 +1,63 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vk");
|
||||
|
||||
const BaseWrapper = vk.BaseWrapper(.{
|
||||
.getInstanceProcAddr = true,
|
||||
.createInstance = true,
|
||||
});
|
||||
|
||||
const InstanceWrapper = vk.InstanceWrapper(.{
|
||||
.destroyInstance = true,
|
||||
.enumeratePhysicalDevices = true,
|
||||
.getPhysicalDeviceProperties = true,
|
||||
.getPhysicalDeviceQueueFamilyProperties = true,
|
||||
});
|
||||
|
||||
extern fn vkGetInstanceProcAddr(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction;
|
||||
extern fn vkGetDeviceProcAddr(device: vk.Device, procname: [*:0]const u8) vk.PfnVoidFunction;
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const ally = gpa.allocator();
|
||||
|
||||
const vkb = try BaseWrapper.load(vkGetInstanceProcAddr);
|
||||
|
||||
const instance = try vkb.createInstance(&.{
|
||||
.p_application_info = &.{
|
||||
.p_application_name = "vkinspect",
|
||||
.application_version = 0,
|
||||
.p_engine_name = "vkinspect",
|
||||
.engine_version = 0,
|
||||
.api_version = vk.API_VERSION_1_3,
|
||||
},
|
||||
.enabled_extension_count = 0,
|
||||
.enabled_layer_count = 0,
|
||||
}, null);
|
||||
const vki = try InstanceWrapper.load(instance, vkGetInstanceProcAddr);
|
||||
defer vki.destroyInstance(instance, null);
|
||||
|
||||
var pdev_count: u32 = undefined;
|
||||
_ = try vki.enumeratePhysicalDevices(instance, &pdev_count, null);
|
||||
const pdevs = try ally.alloc(vk.PhysicalDevice, pdev_count);
|
||||
defer ally.free(pdevs);
|
||||
_ = try vki.enumeratePhysicalDevices(instance, &pdev_count, pdevs.ptr);
|
||||
|
||||
std.debug.print("{d} physical devices:\n", .{pdev_count});
|
||||
for (pdevs) |pdev| {
|
||||
const props = vki.getPhysicalDeviceProperties(pdev);
|
||||
const name = std.mem.sliceTo(&props.device_name, 0);
|
||||
std.debug.print("- {s}\n", .{name});
|
||||
|
||||
var family_count: u32 = undefined;
|
||||
vki.getPhysicalDeviceQueueFamilyProperties(pdev, &family_count, null);
|
||||
const families = try ally.alloc(vk.QueueFamilyProperties, family_count);
|
||||
defer ally.free(families);
|
||||
vki.getPhysicalDeviceQueueFamilyProperties(pdev, &family_count, families.ptr);
|
||||
|
||||
std.debug.print(" {d} queue families:\n", .{family_count});
|
||||
for (families) |family| {
|
||||
std.debug.print(" - {any}\n", .{family.queue_flags});
|
||||
std.debug.print(" (max {d})\n", .{family.queue_count});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user