improving readme
This commit is contained in:
29
README.md
29
README.md
@@ -1,9 +1,32 @@
|
|||||||
# Stroll Vulkan Driver
|
# Stroll Vulkan ICD
|
||||||
|
|
||||||
<img align="right" src="https://matthew.kerwin.net.au/blog_files/kappa"/>
|
<img align="right" src="https://matthew.kerwin.net.au/blog_files/kappa"/>
|
||||||
|
|
||||||
A driver as slow as Lance Stroll.
|
A driver as slow as Lance Stroll.
|
||||||
|
|
||||||
Here is the source code of a disastrous implementation of the Vulkan specification as an Installable Client Driver (ICD) in a software graphics driver written in Zig.
|
Here lies the source code of a rather calamitous attempt at the Vulkan specification, shaped into an Installable Client Driver for a software-based renderer, all written in Zig.
|
||||||
|
|
||||||
It exists solely for my own educational purposes and should not be taken seriously or be used in any *real* project.
|
It was forged for my own learning and amusement alone. Pray, do not wield it in any earnest project, lest thy hopes and frame rates both find themselves entombed.
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
To understand Vulkan — not as a humble API mere mortals call upon, but as a labyrinthine system where one may craft a driver by hand.
|
||||||
|
It does not seek to produce a performant or production-worthy driver. \
|
||||||
|
*The gods are merciful, but not that merciful.*
|
||||||
|
|
||||||
|
# Build
|
||||||
|
|
||||||
|
If thou art truly determined:
|
||||||
|
```
|
||||||
|
zig build
|
||||||
|
```
|
||||||
|
|
||||||
|
Then ensure thy Vulkan loader is pointed toward the ICD manifest.
|
||||||
|
The precise ritual varies by system — consult the tomes of your operating system, or wander the web’s endless mausoleum of documentation.
|
||||||
|
|
||||||
|
Use at your own risk. If thy machine shudders, weeps, or attempts to flee — know that it was warned.
|
||||||
|
|
||||||
|
# License
|
||||||
|
|
||||||
|
Released unto the world as MIT for study, experimentation, and the occasional horrified whisper.
|
||||||
|
Do with it as thou wilt, but accept the consequences as thine own.
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
|||||||
defer info.deinit(allocator);
|
defer info.deinit(allocator);
|
||||||
|
|
||||||
var writer = std.Io.Writer.fixed(interface.props.device_name[0 .. vk.MAX_PHYSICAL_DEVICE_NAME_SIZE - 1]);
|
var writer = std.Io.Writer.fixed(interface.props.device_name[0 .. vk.MAX_PHYSICAL_DEVICE_NAME_SIZE - 1]);
|
||||||
writer.print("{s} [Soft Vulkan Driver]", .{info.name}) catch return VkError.InitializationFailed;
|
writer.print("{s} [" ++ root.DRIVER_NAME ++ " StrollDriver]", .{info.name}) catch return VkError.InitializationFailed;
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.interface = interface,
|
.interface = interface,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
pub const base = @import("base");
|
||||||
|
|
||||||
pub const Instance = @import("Instance.zig");
|
pub const Instance = @import("Instance.zig");
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ pub const Instance = @import("Instance.zig");
|
|||||||
pub const Device = @import("Device.zig");
|
pub const Device = @import("Device.zig");
|
||||||
pub const PhysicalDevice = @import("PhysicalDevice.zig");
|
pub const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||||
pub const VulkanAllocator = @import("VulkanAllocator.zig");
|
pub const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||||
//pub const Device = @import("Device.zig");
|
|
||||||
|
|
||||||
pub const VULKAN_VENDOR_ID = @typeInfo(vk.VendorId).@"enum".fields[@typeInfo(vk.VendorId).@"enum".fields.len - 1].value + 1;
|
pub const VULKAN_VENDOR_ID = @typeInfo(vk.VendorId).@"enum".fields[@typeInfo(vk.VendorId).@"enum".fields.len - 1].value + 1;
|
||||||
pub const DRIVER_LOGS_ENV_NAME = "DRIVER_LOGS";
|
pub const DRIVER_LOGS_ENV_NAME = "STROLL_LOGS";
|
||||||
|
|
||||||
pub const std_options: std.Options = .{
|
pub const std_options: std.Options = .{
|
||||||
.log_level = .debug,
|
.log_level = .debug,
|
||||||
|
|||||||
@@ -16,19 +16,16 @@ const Device = @import("Device.zig");
|
|||||||
const PhysicalDevice = @import("PhysicalDevice.zig");
|
const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||||
|
|
||||||
// This file contains all exported Vulkan entrypoints.
|
// 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.
|
|
||||||
|
|
||||||
fn functionMapElement(comptime name: []const u8) struct { []const u8, vk.PfnVoidFunction } {
|
fn functionMapElement(comptime name: []const u8) struct { []const u8, vk.PfnVoidFunction } {
|
||||||
const stroll_name = std.fmt.comptimePrint("stroll{s}", .{name[2..]});
|
const stroll_name = std.fmt.comptimePrint("stroll{s}", .{name[2..]});
|
||||||
|
|
||||||
if (std.meta.hasFn(@This(), name)) {
|
return if (std.meta.hasFn(@This(), name))
|
||||||
return .{ name, @as(vk.PfnVoidFunction, @ptrCast(&@field(@This(), name))) };
|
.{ name, @as(vk.PfnVoidFunction, @ptrCast(&@field(@This(), name))) }
|
||||||
} else if (std.meta.hasFn(@This(), stroll_name)) {
|
else if (std.meta.hasFn(@This(), stroll_name))
|
||||||
return .{ name, @as(vk.PfnVoidFunction, @ptrCast(&@field(@This(), stroll_name))) };
|
.{ name, @as(vk.PfnVoidFunction, @ptrCast(&@field(@This(), stroll_name))) }
|
||||||
}
|
else
|
||||||
return .{ name, null };
|
.{ name, null };
|
||||||
}
|
}
|
||||||
|
|
||||||
const icd_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
const icd_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||||
@@ -59,6 +56,7 @@ const physical_device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComp
|
|||||||
functionMapElement("vkGetPhysicalDeviceProperties"),
|
functionMapElement("vkGetPhysicalDeviceProperties"),
|
||||||
functionMapElement("vkGetPhysicalDeviceMemoryProperties"),
|
functionMapElement("vkGetPhysicalDeviceMemoryProperties"),
|
||||||
functionMapElement("vkGetPhysicalDeviceQueueFamilyProperties"),
|
functionMapElement("vkGetPhysicalDeviceQueueFamilyProperties"),
|
||||||
|
functionMapElement("vkGetPhysicalDeviceSparseImageFormatProperties"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
const device_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||||
@@ -76,10 +74,6 @@ pub export fn vk_icdGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]c
|
|||||||
if (p_name == null) return null;
|
if (p_name == null) return null;
|
||||||
const name = std.mem.span(p_name.?);
|
const name = std.mem.span(p_name.?);
|
||||||
|
|
||||||
std.log.scoped(.vk_icdGetInstanceProcAddr).info("Loading {s}...", .{name});
|
|
||||||
logger.indent();
|
|
||||||
defer logger.unindent();
|
|
||||||
|
|
||||||
if (icd_pfn_map.get(name)) |pfn| return pfn;
|
if (icd_pfn_map.get(name)) |pfn| return pfn;
|
||||||
return vkGetInstanceProcAddr(p_instance, p_name);
|
return vkGetInstanceProcAddr(p_instance, p_name);
|
||||||
}
|
}
|
||||||
@@ -88,10 +82,6 @@ pub export fn stroll_icdGetPhysicalDeviceProcAddr(_: vk.Instance, p_name: ?[*:0]
|
|||||||
if (p_name == null) return null;
|
if (p_name == null) return null;
|
||||||
const name = std.mem.span(p_name.?);
|
const name = std.mem.span(p_name.?);
|
||||||
|
|
||||||
std.log.scoped(.vk_icdGetPhysicalDeviceProcAddr).info("Loading {s}...", .{name});
|
|
||||||
logger.indent();
|
|
||||||
defer logger.unindent();
|
|
||||||
|
|
||||||
if (physical_device_pfn_map.get(name)) |pfn| return pfn;
|
if (physical_device_pfn_map.get(name)) |pfn| return pfn;
|
||||||
|
|
||||||
std.log.scoped(.vk_icdGetPhysicalDeviceProcAddr).err("Could not find function {s}", .{name});
|
std.log.scoped(.vk_icdGetPhysicalDeviceProcAddr).err("Could not find function {s}", .{name});
|
||||||
@@ -104,10 +94,6 @@ pub export fn vkGetInstanceProcAddr(p_instance: vk.Instance, p_name: ?[*:0]const
|
|||||||
if (p_name == null) return null;
|
if (p_name == null) return null;
|
||||||
const name = std.mem.span(p_name.?);
|
const name = std.mem.span(p_name.?);
|
||||||
|
|
||||||
std.log.scoped(.vkGetInstanceProcAddr).info("Loading {s}...", .{name});
|
|
||||||
logger.indent();
|
|
||||||
defer logger.unindent();
|
|
||||||
|
|
||||||
if (global_pfn_map.get(name)) |pfn| return pfn;
|
if (global_pfn_map.get(name)) |pfn| return pfn;
|
||||||
if (p_instance == .null_handle) {
|
if (p_instance == .null_handle) {
|
||||||
std.log.scoped(.vkGetInstanceProcAddr).err("Could not find global entrypoint {s}", .{name});
|
std.log.scoped(.vkGetInstanceProcAddr).err("Could not find global entrypoint {s}", .{name});
|
||||||
@@ -245,6 +231,27 @@ pub export fn strollGetPhysicalDeviceQueueFamilyProperties(p_physical_device: vk
|
|||||||
count.* = 0;
|
count.* = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub export fn strollGetPhysicalDeviceSparseImageFormatProperties(
|
||||||
|
p_physical_device: vk.PhysicalDevice,
|
||||||
|
format: vk.Format,
|
||||||
|
image_type: vk.ImageType,
|
||||||
|
samples: vk.SampleCountFlags,
|
||||||
|
tiling: vk.ImageTiling,
|
||||||
|
usage: vk.ImageUsageFlags,
|
||||||
|
flags: vk.ImageCreateFlags,
|
||||||
|
properties: *vk.SparseImageFormatProperties,
|
||||||
|
) callconv(vk.vulkan_call_conv) vk.Result {
|
||||||
|
_ = p_physical_device;
|
||||||
|
_ = format;
|
||||||
|
_ = image_type;
|
||||||
|
_ = samples;
|
||||||
|
_ = tiling;
|
||||||
|
_ = usage;
|
||||||
|
_ = flags;
|
||||||
|
_ = properties;
|
||||||
|
return .error_format_not_supported;
|
||||||
|
}
|
||||||
|
|
||||||
// Device functions ==========================================================================================================================================
|
// Device functions ==========================================================================================================================================
|
||||||
|
|
||||||
pub export fn strollDestroyDevice(p_device: vk.Device, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
pub export fn strollDestroyDevice(p_device: vk.Device, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
||||||
@@ -262,10 +269,6 @@ pub export fn strollGetDeviceProcAddr(p_device: vk.Device, p_name: ?[*:0]const u
|
|||||||
if (p_name == null) return null;
|
if (p_name == null) return null;
|
||||||
const name = std.mem.span(p_name.?);
|
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;
|
if (p_device == .null_handle) return null;
|
||||||
if (device_pfn_map.get(name)) |pfn| return pfn;
|
if (device_pfn_map.get(name)) |pfn| return pfn;
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ pub fn log(comptime level: std.log.Level, comptime scope: @Type(.enum_literal),
|
|||||||
const now = zdt.Datetime.now(.{ .tz = &timezone }) catch return;
|
const now = zdt.Datetime.now(.{ .tz = &timezone }) catch return;
|
||||||
|
|
||||||
out_config.setColor(writer, .magenta) catch {};
|
out_config.setColor(writer, .magenta) catch {};
|
||||||
writer.print("[" ++ root.DRIVER_NAME ++ "Driver ", .{}) catch return;
|
writer.print("[" ++ root.DRIVER_NAME ++ " StrollDriver ", .{}) catch return;
|
||||||
out_config.setColor(writer, .yellow) catch {};
|
out_config.setColor(writer, .yellow) catch {};
|
||||||
writer.print("{d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch return;
|
writer.print("{d:02}:{d:02}:{d:02}.{d:03}", .{ now.hour, now.minute, now.second, @divFloor(now.nanosecond, std.time.ns_per_ms) }) catch return;
|
||||||
out_config.setColor(writer, .magenta) catch {};
|
out_config.setColor(writer, .magenta) catch {};
|
||||||
|
|||||||
Reference in New Issue
Block a user