adding DRM device search and intel pci device map
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const FlintPhysicalDevice = @import("FlintPhysicalDevice.zig");
|
||||
|
||||
const Dispatchable = base.Dispatchable;
|
||||
@@ -59,17 +61,59 @@ fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||
_ = interface;
|
||||
_ = allocator;
|
||||
fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, devices: []base.drm.Card) VkError!void {
|
||||
if (interface.physical_devices.items.len != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const io_var = interface.io();
|
||||
|
||||
for (devices[0..]) |device| {
|
||||
const drm_device = device.getDevice(io_var, allocator, .{}) catch continue;
|
||||
|
||||
if (drm_device.node_type != .render or
|
||||
std.meta.activeTag(drm_device.device_info) != .pci or
|
||||
drm_device.device_info.pci.vendor_id != lib.INTEL_PCI_VENDOR_ID)
|
||||
continue;
|
||||
|
||||
const physical_device = try FlintPhysicalDevice.create(allocator, interface, &drm_device);
|
||||
errdefer physical_device.interface.release(allocator) catch {};
|
||||
|
||||
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
||||
errdefer dispatchable.destroy(allocator);
|
||||
|
||||
interface.physical_devices.append(allocator, dispatchable) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
}
|
||||
|
||||
fn releasePhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||
_ = interface;
|
||||
_ = allocator;
|
||||
var result: ?VkError = null;
|
||||
|
||||
for (interface.physical_devices.items) |physical_device| {
|
||||
physical_device.object.release(allocator) catch |err| {
|
||||
if (result == null) {
|
||||
result = err;
|
||||
}
|
||||
};
|
||||
physical_device.destroy(allocator);
|
||||
}
|
||||
|
||||
interface.physical_devices.deinit(allocator);
|
||||
interface.physical_devices = .empty;
|
||||
|
||||
if (result) |err| {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
fn io(interface: *Interface) std.Io {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
return self.io_impl;
|
||||
}
|
||||
|
||||
fn mapDeviceEnumerationError(err: anyerror) VkError {
|
||||
return switch (err) {
|
||||
error.OutOfMemory => VkError.OutOfHostMemory,
|
||||
else => VkError.InitializationFailed,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user