adding icd base
This commit is contained in:
@@ -11,9 +11,9 @@ physical_devices: std.ArrayList(*Dispatchable(PhysicalDevice)),
|
||||
dispatch_table: *const DispatchTable,
|
||||
|
||||
pub const DispatchTable = struct {
|
||||
requestPhysicalDevices: *const fn (*Self, std.mem.Allocator) VkError!void,
|
||||
releasePhysicalDevices: *const fn (*Self, std.mem.Allocator) VkError!void,
|
||||
destroyInstance: *const fn (*Self, std.mem.Allocator) VkError!void,
|
||||
releasePhysicalDevices: *const fn (*Self, std.mem.Allocator) VkError!void,
|
||||
requestPhysicalDevices: *const fn (*Self, std.mem.Allocator) VkError!void,
|
||||
};
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) VkError!Self {
|
||||
@@ -25,6 +25,26 @@ pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) V
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||
try self.dispatch_table.releasePhysicalDevices(self, allocator);
|
||||
try self.dispatch_table.destroyInstance(self, allocator);
|
||||
}
|
||||
|
||||
pub fn enumerateExtensionProperties(layer_name: ?[]const u8, property_count: *u32, properties: ?*vk.ExtensionProperties) VkError!void {
|
||||
if (layer_name) |_| {
|
||||
return VkError.LayerNotPresent;
|
||||
}
|
||||
|
||||
_ = properties;
|
||||
_ = std.StaticStringMap(vk.ExtensionProperties).initComptime(.{});
|
||||
|
||||
property_count.* = 0;
|
||||
}
|
||||
|
||||
pub fn releasePhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||
try self.dispatch_table.releasePhysicalDevices(self, allocator);
|
||||
}
|
||||
|
||||
pub fn requestPhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||
try self.dispatch_table.requestPhysicalDevices(self, allocator);
|
||||
if (self.physical_devices.items.len == 0) {
|
||||
@@ -35,12 +55,3 @@ pub fn requestPhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError
|
||||
std.log.scoped(.vkCreateInstance).info("Found VkPhysicalDevice named {s}", .{physical_device.object.props.device_name});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn releasePhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||
try self.dispatch_table.releasePhysicalDevices(self, allocator);
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) VkError!void {
|
||||
try self.dispatch_table.releasePhysicalDevices(self, allocator);
|
||||
try self.dispatch_table.destroyInstance(self, allocator);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,38 @@ const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||
|
||||
extern fn __vkImplCreateInstance(*const std.mem.Allocator, *const vk.InstanceCreateInfo) ?*Instance;
|
||||
|
||||
/// This file contains all exported Vulkan entrypoints.
|
||||
///
|
||||
/// The use of official Vulkan function names is assumed
|
||||
/// and is not a concern, given that this driver only implements Vulkan's API.
|
||||
|
||||
// ICD Interface =============================================================================================================================================
|
||||
|
||||
pub export fn vk_icdNegotiateLoaderICDInterfaceVersion(p_version: *u32) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
p_version.* = 7;
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn vk_icdGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction {
|
||||
if (p_name == null) {
|
||||
return null;
|
||||
}
|
||||
const name = std.mem.span(p_name.?);
|
||||
|
||||
std.log.scoped(.vk_icdGetInstanceProcAddr).info("Loading {s}...", .{name});
|
||||
logger.indent();
|
||||
defer logger.unindent();
|
||||
|
||||
const icd_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapElement("vk_icdGetInstanceProcAddr"),
|
||||
functionMapElement("vk_icdNegotiateLoaderICDInterfaceVersion"),
|
||||
});
|
||||
if (icd_pfn_map.get(name)) |pfn| return pfn;
|
||||
return vkGetInstanceProcAddr(p_instance, p_name);
|
||||
}
|
||||
|
||||
// Global functions ==========================================================================================================================================
|
||||
|
||||
fn functionMapElement(name: []const u8) struct { []const u8, vk.PfnVoidFunction } {
|
||||
if (!std.meta.hasFn(@This(), name)) {
|
||||
std.log.scoped(.vkGetInstanceProcAddr).err("Could not find function {s}", .{name});
|
||||
@@ -25,6 +57,10 @@ fn functionMapElement(name: []const u8) struct { []const u8, vk.PfnVoidFunction
|
||||
return .{ name, @as(vk.PfnVoidFunction, @ptrCast(&@field(@This(), name))) };
|
||||
}
|
||||
|
||||
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapElement("vkDestroyDevice"),
|
||||
});
|
||||
|
||||
pub export fn vkGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction {
|
||||
if (p_name == null) {
|
||||
return null;
|
||||
@@ -32,30 +68,34 @@ pub export fn vkGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]const
|
||||
const name = std.mem.span(p_name.?);
|
||||
|
||||
const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapElement("vkGetInstanceProcAddr"),
|
||||
functionMapElement("vkCreateInstance"),
|
||||
functionMapElement("vkGetInstanceProcAddr"),
|
||||
functionMapElement("vkEnumerateInstanceExtensionProperties"),
|
||||
});
|
||||
|
||||
const instance_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapElement("vkCreateDevice"),
|
||||
functionMapElement("vkDestroyInstance"),
|
||||
functionMapElement("vkEnumeratePhysicalDevices"),
|
||||
functionMapElement("vkGetDeviceProcAddr"),
|
||||
functionMapElement("vkGetPhysicalDeviceProperties"),
|
||||
functionMapElement("vkGetPhysicalDeviceProperties"),
|
||||
});
|
||||
|
||||
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
functionMapElement("vkDestroyDevice"),
|
||||
});
|
||||
|
||||
std.log.scoped(.vkGetInstanceProcAddr).info("Loading {s}...", .{name});
|
||||
logger.indent();
|
||||
defer logger.unindent();
|
||||
|
||||
if (global_pfn_map.get(name)) |pfn| return pfn;
|
||||
if (p_instance == .null_handle) return null;
|
||||
if (p_instance == .null_handle) {
|
||||
std.log.scoped(.vkGetInstanceProcAddr).err("Could not find global entrypoint {s}", .{name});
|
||||
return null;
|
||||
}
|
||||
if (instance_pfn_map.get(name)) |pfn| return pfn;
|
||||
return if (device_pfn_map.get(name)) |pfn| pfn else null;
|
||||
if (device_pfn_map.get(name)) |pfn| return pfn;
|
||||
|
||||
std.log.scoped(.vkGetInstanceProcAddr).err("Could not find entrypoint {s}", .{name});
|
||||
return null;
|
||||
}
|
||||
|
||||
pub export fn vkCreateInstance(p_infos: ?*const vk.InstanceCreateInfo, callbacks: ?*const vk.AllocationCallbacks, p_instance: *vk.Instance) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
@@ -75,6 +115,17 @@ pub export fn vkCreateInstance(p_infos: ?*const vk.InstanceCreateInfo, callbacks
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn vkEnumerateInstanceExtensionProperties(p_layer_name: ?[*:0]const u8, property_count: *u32, properties: ?*vk.ExtensionProperties) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
var name: ?[]const u8 = null;
|
||||
if (p_layer_name) |layer_name| {
|
||||
name = std.mem.span(layer_name);
|
||||
}
|
||||
Instance.enumerateExtensionProperties(name, property_count, properties) catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
// Instance functions ========================================================================================================================================
|
||||
|
||||
pub export fn vkDestroyInstance(p_instance: vk.Instance, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
||||
std.log.scoped(.vkDestroyInstance).info("Destroying VkInstance", .{});
|
||||
logger.indent();
|
||||
@@ -123,6 +174,8 @@ pub export fn vkCreateDevice(p_physical_device: vk.PhysicalDevice, p_infos: ?*co
|
||||
return .success;
|
||||
}
|
||||
|
||||
// Device functions ==========================================================================================================================================
|
||||
|
||||
pub export fn vkDestroyDevice(p_device: vk.Device, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
||||
const allocator = VulkanAllocator.init(callbacks, .device).allocator();
|
||||
const dispatchable = Dispatchable(Device).fromHandle(p_device) catch return;
|
||||
@@ -133,3 +186,17 @@ pub export fn vkDestroyDevice(p_device: vk.Device, callbacks: ?*const vk.Allocat
|
||||
dispatchable.object.destroy(allocator) catch return;
|
||||
dispatchable.destroy(allocator);
|
||||
}
|
||||
|
||||
pub export fn vkGetDeviceProcAddr(p_device: vk.Device, p_name: ?[*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction {
|
||||
if (p_name == null) {
|
||||
return null;
|
||||
}
|
||||
const name = std.mem.span(p_name.?);
|
||||
|
||||
std.log.scoped(.vkGetDeviceProcAddr).info("Loading {s}...", .{name});
|
||||
logger.indent();
|
||||
defer logger.unindent();
|
||||
|
||||
if (p_device == .null_handle) return null;
|
||||
return if (device_pfn_map.get(name)) |pfn| pfn else null;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
|
||||
std.fmt.comptimePrint("({s}): ", .{scope_name});
|
||||
};
|
||||
|
||||
const prefix = "[" ++ comptime level.asText() ++ "] ";
|
||||
const prefix = std.fmt.comptimePrint("{s: <8}", .{"[" ++ comptime level.asText() ++ "] "});
|
||||
|
||||
const level_color: std.Io.tty.Color = switch (level) {
|
||||
.info => .blue,
|
||||
|
||||
Reference in New Issue
Block a user