fixing linter errors
This commit is contained in:
@@ -8,8 +8,6 @@ scripts/__pycache__/
|
|||||||
*.o
|
*.o
|
||||||
.gdb_history
|
.gdb_history
|
||||||
*.json
|
*.json
|
||||||
*.png
|
|
||||||
!logo.png
|
|
||||||
*.bin
|
*.bin
|
||||||
*.qpa
|
*.qpa
|
||||||
*.xml
|
*.xml
|
||||||
|
|||||||
@@ -175,7 +175,13 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const install_step = b.step(impl.name, b.fmt("Build libvulkan_{s}", .{impl.name}));
|
const install_step = b.step(impl.name, b.fmt("Build libvulkan_{s}", .{impl.name}));
|
||||||
install_step.dependOn(&lib_install.step);
|
install_step.dependOn(&lib_install.step);
|
||||||
|
|
||||||
const lib_tests = b.addTest(.{ .root_module = lib_mod });
|
const lib_tests = b.addTest(.{
|
||||||
|
.root_module = lib_mod,
|
||||||
|
.test_runner = .{
|
||||||
|
.path = b.path("test/test_runner.zig"),
|
||||||
|
.mode = .simple,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const run_tests = b.addRunArtifact(lib_tests);
|
const run_tests = b.addRunArtifact(lib_tests);
|
||||||
const test_step = b.step(b.fmt("test-{s}", .{impl.name}), b.fmt("Run libvulkan_{s} tests", .{impl.name}));
|
const test_step = b.step(b.fmt("test-{s}", .{impl.name}), b.fmt("Run libvulkan_{s} tests", .{impl.name}));
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const soft = @import("soft");
|
|||||||
const flint = @import("flint");
|
const flint = @import("flint");
|
||||||
const phi = @import("phi");
|
const phi = @import("phi");
|
||||||
|
|
||||||
const Dispatchable = base.Dispatchable;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
@@ -37,15 +36,15 @@ pub fn create(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo)
|
|||||||
};
|
};
|
||||||
|
|
||||||
const soft_instance = try soft.Instance.create(allocator, infos);
|
const soft_instance = try soft.Instance.create(allocator, infos);
|
||||||
errdefer soft_instance.deinit(allocator) catch {};
|
errdefer soft_instance.deinit(allocator) catch @panic("Caught an error while handling an error");
|
||||||
self.backend_instances.append(allocator, soft_instance) catch return VkError.OutOfHostMemory;
|
self.backend_instances.append(allocator, soft_instance) catch return VkError.OutOfHostMemory;
|
||||||
|
|
||||||
const flint_instance = try flint.Instance.create(allocator, infos);
|
const flint_instance = try flint.Instance.create(allocator, infos);
|
||||||
errdefer flint_instance.deinit(allocator) catch {};
|
errdefer flint_instance.deinit(allocator) catch @panic("Caught an error while handling an error");
|
||||||
self.backend_instances.append(allocator, flint_instance) catch return VkError.OutOfHostMemory;
|
self.backend_instances.append(allocator, flint_instance) catch return VkError.OutOfHostMemory;
|
||||||
|
|
||||||
const phi_instance = try phi.Instance.create(allocator, infos);
|
const phi_instance = try phi.Instance.create(allocator, infos);
|
||||||
errdefer phi_instance.deinit(allocator) catch {};
|
errdefer phi_instance.deinit(allocator) catch @panic("Caught an error while handling an error");
|
||||||
self.backend_instances.append(allocator, phi_instance) catch return VkError.OutOfHostMemory;
|
self.backend_instances.append(allocator, phi_instance) catch return VkError.OutOfHostMemory;
|
||||||
|
|
||||||
return &self.interface;
|
return &self.interface;
|
||||||
@@ -68,7 +67,7 @@ fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, _
|
|||||||
|
|
||||||
fn appendBackendPhysicalDevices(self: *Self, allocator: std.mem.Allocator, backend: *Interface) VkError!void {
|
fn appendBackendPhysicalDevices(self: *Self, allocator: std.mem.Allocator, backend: *Interface) VkError!void {
|
||||||
try backend.requestPhysicalDevices(allocator);
|
try backend.requestPhysicalDevices(allocator);
|
||||||
errdefer backend.releasePhysicalDevices(allocator) catch {};
|
errdefer backend.releasePhysicalDevices(allocator) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
self.interface.physical_devices.appendSlice(allocator, backend.physical_devices.items) catch return VkError.OutOfHostMemory;
|
self.interface.physical_devices.appendSlice(allocator, backend.physical_devices.items) catch return VkError.OutOfHostMemory;
|
||||||
backend.physical_devices.deinit(allocator);
|
backend.physical_devices.deinit(allocator);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const base = @import("base");
|
|||||||
const kmd = @import("kmd.zig");
|
const kmd = @import("kmd.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
const FlintDevice = @import("FlintDevice.zig");
|
const FlintDevice = @import("FlintDevice.zig");
|
||||||
|
|
||||||
const drm_syncobj_create = 0xbf;
|
const drm_syncobj_create = 0xbf;
|
||||||
@@ -159,5 +158,5 @@ fn destroyHandle(device: *FlintDevice, io: std.Io, handle: u32) void {
|
|||||||
io,
|
io,
|
||||||
kmd.drmIoctlIowr(drm_syncobj_destroy, SyncObjDestroy),
|
kmd.drmIoctlIowr(drm_syncobj_destroy, SyncObjDestroy),
|
||||||
&destroy_info,
|
&destroy_info,
|
||||||
) catch {};
|
) catch @panic("Caught an error while handling an error");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Buffer;
|
pub const Interface = base.Buffer;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.BufferView;
|
pub const Interface = base.BufferView;
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ const kmd = @import("kmd.zig");
|
|||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const FlintDevice = @import("FlintDevice.zig");
|
const FlintDevice = @import("FlintDevice.zig");
|
||||||
const FlintDeviceMemory = @import("FlintDeviceMemory.zig");
|
|
||||||
const FlintImage = @import("FlintImage.zig");
|
|
||||||
|
|
||||||
const MemoryRange = @import("MemoryRange.zig");
|
const MemoryRange = @import("MemoryRange.zig");
|
||||||
|
|
||||||
@@ -96,7 +94,7 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
|||||||
|
|
||||||
pub fn submitGpuBatch(self: *Self, syncs: []const kmd.SyncDependency) VkError!void {
|
pub fn submitGpuBatch(self: *Self, syncs: []const kmd.SyncDependency) VkError!void {
|
||||||
try self.interface.submit();
|
try self.interface.submit();
|
||||||
defer self.interface.finish() catch {};
|
defer self.interface.finish() catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
if (self.batch.items.len == 0) return;
|
if (self.batch.items.len == 0) return;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const NonDispatchable = base.NonDispatchable;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const FlintCommandBuffer = @import("FlintCommandBuffer.zig");
|
const FlintCommandBuffer = @import("FlintCommandBuffer.zig");
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const VulkanAllocator = base.VulkanAllocator;
|
|
||||||
|
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorPool;
|
pub const Interface = base.DescriptorPool;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorSetLayout;
|
pub const Interface = base.DescriptorSetLayout;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Event;
|
pub const Interface = base.Event;
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ fn destroyHandle(device: *FlintDevice, io: std.Io, handle: u32) void {
|
|||||||
io,
|
io,
|
||||||
kmd.drmIoctlIowr(drm_syncobj_destroy, SyncObjDestroy),
|
kmd.drmIoctlIowr(drm_syncobj_destroy, SyncObjDestroy),
|
||||||
&destroy_info,
|
&destroy_info,
|
||||||
) catch {};
|
) catch @panic("ioctl failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn absoluteTimeout(io: std.Io, timeout: u64) i64 {
|
fn absoluteTimeout(io: std.Io, timeout: u64) i64 {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.ImageView;
|
pub const Interface = base.ImageView;
|
||||||
|
|||||||
@@ -80,17 +80,17 @@ fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, d
|
|||||||
defer version.deinit(allocator);
|
defer version.deinit(allocator);
|
||||||
|
|
||||||
const kmd_type: lib.KmdType = if (std.mem.eql(u8, version.name, "i915"))
|
const kmd_type: lib.KmdType = if (std.mem.eql(u8, version.name, "i915"))
|
||||||
.I915
|
.i915
|
||||||
else if (std.mem.eql(u8, version.name, "xe"))
|
else if (std.mem.eql(u8, version.name, "xe"))
|
||||||
.Xe
|
.xe
|
||||||
else
|
else
|
||||||
.Invalid;
|
.invalid;
|
||||||
|
|
||||||
if (kmd_type == .Invalid)
|
if (kmd_type == .invalid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const physical_device = try FlintPhysicalDevice.create(allocator, interface, &drm_device, kmd_type);
|
const physical_device = try FlintPhysicalDevice.create(allocator, interface, &drm_device, kmd_type);
|
||||||
errdefer physical_device.interface.release(allocator) catch {};
|
errdefer physical_device.interface.release(allocator) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
||||||
errdefer dispatchable.destroy(allocator);
|
errdefer dispatchable.destroy(allocator);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ const pci_ids = @import("pci_ids.zig").map;
|
|||||||
const FlintDevice = @import("FlintDevice.zig");
|
const FlintDevice = @import("FlintDevice.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const VulkanAllocator = base.VulkanAllocator;
|
|
||||||
const SurfaceKHR = base.SurfaceKHR;
|
const SurfaceKHR = base.SurfaceKHR;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
@@ -79,7 +78,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance, drm_device
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface.props.pipeline_cache_uuid = undefined;
|
interface.props.pipeline_cache_uuid = @splat(0);
|
||||||
interface.props.limits = .{
|
interface.props.limits = .{
|
||||||
.max_image_dimension_1d = 4096,
|
.max_image_dimension_1d = 4096,
|
||||||
.max_image_dimension_2d = 4096,
|
.max_image_dimension_2d = 4096,
|
||||||
@@ -867,10 +866,10 @@ fn cpuid(leaf_id: u32, subleaf_id: u32) CpuidRegs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var eax: u32 = undefined;
|
var eax: u32 = 0;
|
||||||
var ebx: u32 = undefined;
|
var ebx: u32 = 0;
|
||||||
var ecx: u32 = undefined;
|
var ecx: u32 = 0;
|
||||||
var edx: u32 = undefined;
|
var edx: u32 = 0;
|
||||||
|
|
||||||
asm volatile ("cpuid"
|
asm volatile ("cpuid"
|
||||||
: [_] "={eax}" (eax),
|
: [_] "={eax}" (eax),
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.PipelineLayout;
|
pub const Interface = base.PipelineLayout;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.QueryPool;
|
pub const Interface = base.QueryPool;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.RenderPass;
|
pub const Interface = base.RenderPass;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const kmd = @import("kmd.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const FlintImage = @import("FlintImage.zig");
|
const FlintImage = @import("FlintImage.zig");
|
||||||
@@ -158,7 +157,7 @@ fn bitwiseCompatibleFormats(src: vk.Format, dst: vk.Format) bool {
|
|||||||
|
|
||||||
fn nearestBlitCoordinate(src_0: i32, src_1: i32, dst_0: i32, dst_1: i32, dst: i32, extent: u32) usize {
|
fn nearestBlitCoordinate(src_0: i32, src_1: i32, dst_0: i32, dst_1: i32, dst: i32, extent: u32) usize {
|
||||||
const numerator = @as(i64, 2 * (dst - dst_0) + 1) * @as(i64, src_1 - src_0);
|
const numerator = @as(i64, 2 * (dst - dst_0) + 1) * @as(i64, src_1 - src_0);
|
||||||
const denominator = @as(i64, 2 * (dst_1 - dst_0));
|
const denominator: i64 = 2 * (dst_1 - dst_0);
|
||||||
const coordinate = @as(i64, src_0) + @divFloor(numerator, denominator);
|
const coordinate = @as(i64, src_0) + @divFloor(numerator, denominator);
|
||||||
return @intCast(std.math.clamp(coordinate, 0, @as(i64, extent) - 1));
|
return @intCast(std.math.clamp(coordinate, 0, @as(i64, extent) - 1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
const vk = @import("vulkan");
|
|
||||||
|
|
||||||
pub const command_base = 0x40;
|
pub const command_base = 0x40;
|
||||||
pub const i915_gem_create = 0x1b;
|
pub const gem_create = 0x1b;
|
||||||
pub const i915_gem_mmap_gtt = 0x24;
|
pub const gem_mmap_gtt = 0x24;
|
||||||
pub const i915_gem_set_domain = 0x1f;
|
pub const gem_set_domain = 0x1f;
|
||||||
pub const i915_gem_execbuffer2 = 0x29;
|
pub const gem_execbuffer2 = 0x29;
|
||||||
pub const gem_close = 0x09;
|
pub const gem_close = 0x09;
|
||||||
|
|
||||||
pub const i915_mmap_offset_wb = 2;
|
pub const mmap_offset_wb = 2;
|
||||||
pub const i915_gem_domain_cpu = 0x00000001;
|
pub const gem_domain_cpu = 0x00000001;
|
||||||
pub const i915_gem_domain_gtt = 0x00000040;
|
pub const gem_domain_gtt = 0x00000040;
|
||||||
pub const i915_exec_blt = 3 << 0;
|
pub const exec_blt = 3 << 0;
|
||||||
pub const i915_exec_fence_array: u64 = 1 << 19;
|
pub const exec_fence_array: u64 = 1 << 19;
|
||||||
pub const i915_exec_fence_wait: u32 = 1 << 0;
|
pub const exec_fence_wait: u32 = 1 << 0;
|
||||||
pub const i915_exec_fence_signal: u32 = 1 << 1;
|
pub const exec_fence_signal: u32 = 1 << 1;
|
||||||
pub const exec_object_write = 1 << 2;
|
pub const exec_object_write = 1 << 2;
|
||||||
pub const mi_flush_dw: u32 = (0x26 << 23) | 3;
|
pub const mi_flush_dw: u32 = (0x26 << 23) | 3;
|
||||||
|
|
||||||
+43
-26
@@ -2,13 +2,11 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const drm = @import("drm.zig");
|
const _i915 = @import("i915.zig");
|
||||||
const common_kmd = @import("../kmd.zig");
|
const common_kmd = @import("../kmd.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
const IOCTL = std.os.linux.IOCTL;
|
|
||||||
|
|
||||||
const Mapping = struct {
|
const Mapping = struct {
|
||||||
bytes: []align(std.heap.page_size_min) u8,
|
bytes: []align(std.heap.page_size_min) u8,
|
||||||
|
|
||||||
@@ -33,12 +31,17 @@ pub const Device = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocateMemory(self: *Device, io: std.Io, size: vk.DeviceSize) VkError!Memory {
|
pub fn allocateMemory(self: *Device, io: std.Io, size: vk.DeviceSize) VkError!Memory {
|
||||||
var create = drm.GemCreate{
|
var create = _i915.GemCreate{
|
||||||
.size = size,
|
.size = size,
|
||||||
.handle = 0,
|
.handle = 0,
|
||||||
.pad = 0,
|
.pad = 0,
|
||||||
};
|
};
|
||||||
base.utils.ioctl(self.card.handle, io, common_kmd.drmIoctlIowr(drm.command_base + drm.i915_gem_create, drm.GemCreate), &create) catch return VkError.OutOfDeviceMemory;
|
base.utils.ioctl(
|
||||||
|
self.card.handle,
|
||||||
|
io,
|
||||||
|
common_kmd.drmIoctlIowr(_i915.command_base + _i915.gem_create, _i915.GemCreate),
|
||||||
|
&create,
|
||||||
|
) catch return VkError.OutOfDeviceMemory;
|
||||||
|
|
||||||
var memory = Memory{
|
var memory = Memory{
|
||||||
.handle = create.handle,
|
.handle = create.handle,
|
||||||
@@ -47,7 +50,7 @@ pub const Device = struct {
|
|||||||
};
|
};
|
||||||
errdefer memory.deinit(self, io);
|
errdefer memory.deinit(self, io);
|
||||||
|
|
||||||
try memory.setDomain(self, io, drm.i915_gem_domain_cpu, 0);
|
try memory.setDomain(self, io, _i915.gem_domain_cpu, 0);
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ pub const Device = struct {
|
|||||||
const batch_map = try batch.map(self, io, 0, batch_size);
|
const batch_map = try batch.map(self, io, 0, batch_size);
|
||||||
const batch_words = std.mem.bytesAsSlice(u32, batch_map);
|
const batch_words = std.mem.bytesAsSlice(u32, batch_map);
|
||||||
@memcpy(batch_words[0..commands.len], commands);
|
@memcpy(batch_words[0..commands.len], commands);
|
||||||
batch_words[commands.len + 0] = drm.mi_flush_dw;
|
batch_words[commands.len + 0] = _i915.mi_flush_dw;
|
||||||
batch_words[commands.len + 1] = 0;
|
batch_words[commands.len + 1] = 0;
|
||||||
batch_words[commands.len + 2] = 0;
|
batch_words[commands.len + 2] = 0;
|
||||||
batch_words[commands.len + 3] = 0;
|
batch_words[commands.len + 3] = 0;
|
||||||
@@ -71,7 +74,7 @@ pub const Device = struct {
|
|||||||
}
|
}
|
||||||
try batch.flushRange(self, io, 0, batch_size);
|
try batch.flushRange(self, io, 0, batch_size);
|
||||||
|
|
||||||
var objects = std.ArrayList(drm.ExecObject2).empty;
|
var objects = std.ArrayList(_i915.ExecObject2).empty;
|
||||||
defer objects.deinit(allocator);
|
defer objects.deinit(allocator);
|
||||||
|
|
||||||
var object_handles = std.ArrayList(u32).empty;
|
var object_handles = std.ArrayList(u32).empty;
|
||||||
@@ -86,17 +89,17 @@ pub const Device = struct {
|
|||||||
.relocs_ptr = 0,
|
.relocs_ptr = 0,
|
||||||
.alignment = 0,
|
.alignment = 0,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.flags = if (relocation.write) drm.exec_object_write else 0,
|
.flags = if (relocation.write) _i915.exec_object_write else 0,
|
||||||
.rsvd1 = 0,
|
.rsvd1 = 0,
|
||||||
.rsvd2 = 0,
|
.rsvd2 = 0,
|
||||||
}) catch return VkError.OutOfHostMemory;
|
}) catch return VkError.OutOfHostMemory;
|
||||||
} else if (relocation.write) {
|
} else if (relocation.write) {
|
||||||
const index = std.mem.indexOfScalar(u32, object_handles.items, relocation.target_handle).?;
|
const index = std.mem.indexOfScalar(u32, object_handles.items, relocation.target_handle).?;
|
||||||
objects.items[index].flags |= drm.exec_object_write;
|
objects.items[index].flags |= _i915.exec_object_write;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var i915_relocations = std.ArrayList(drm.RelocationEntry).empty;
|
var i915_relocations = std.ArrayList(_i915.RelocationEntry).empty;
|
||||||
defer i915_relocations.deinit(allocator);
|
defer i915_relocations.deinit(allocator);
|
||||||
|
|
||||||
for (relocations) |relocation| {
|
for (relocations) |relocation| {
|
||||||
@@ -121,17 +124,16 @@ pub const Device = struct {
|
|||||||
.rsvd2 = 0,
|
.rsvd2 = 0,
|
||||||
}) catch return VkError.OutOfHostMemory;
|
}) catch return VkError.OutOfHostMemory;
|
||||||
|
|
||||||
var exec_fences = std.ArrayList(drm.ExecFence).empty;
|
var exec_fences = std.ArrayList(_i915.ExecFence).empty;
|
||||||
defer exec_fences.deinit(allocator);
|
defer exec_fences.deinit(allocator);
|
||||||
for (syncs) |sync| {
|
for (syncs) |sync| {
|
||||||
exec_fences.append(allocator, .{
|
exec_fences.append(allocator, .{
|
||||||
.handle = sync.handle,
|
.handle = sync.handle,
|
||||||
.flags = (if (sync.wait) drm.i915_exec_fence_wait else 0) |
|
.flags = (if (sync.wait) _i915.exec_fence_wait else 0) | (if (sync.signal) _i915.exec_fence_signal else 0),
|
||||||
(if (sync.signal) drm.i915_exec_fence_signal else 0),
|
|
||||||
}) catch return VkError.OutOfHostMemory;
|
}) catch return VkError.OutOfHostMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
var execbuffer = drm.ExecBuffer2{
|
var execbuffer = _i915.ExecBuffer2{
|
||||||
.buffers_ptr = @intFromPtr(objects.items.ptr),
|
.buffers_ptr = @intFromPtr(objects.items.ptr),
|
||||||
.buffer_count = @intCast(objects.items.len),
|
.buffer_count = @intCast(objects.items.len),
|
||||||
.batch_start_offset = 0,
|
.batch_start_offset = 0,
|
||||||
@@ -140,11 +142,16 @@ pub const Device = struct {
|
|||||||
.DR4 = 0,
|
.DR4 = 0,
|
||||||
.num_cliprects = @intCast(exec_fences.items.len),
|
.num_cliprects = @intCast(exec_fences.items.len),
|
||||||
.cliprects_ptr = if (exec_fences.items.len == 0) 0 else @intFromPtr(exec_fences.items.ptr),
|
.cliprects_ptr = if (exec_fences.items.len == 0) 0 else @intFromPtr(exec_fences.items.ptr),
|
||||||
.flags = drm.i915_exec_blt | (if (exec_fences.items.len == 0) 0 else drm.i915_exec_fence_array),
|
.flags = _i915.exec_blt | (if (exec_fences.items.len == 0) 0 else _i915.exec_fence_array),
|
||||||
.rsvd1 = 0,
|
.rsvd1 = 0,
|
||||||
.rsvd2 = 0,
|
.rsvd2 = 0,
|
||||||
};
|
};
|
||||||
base.utils.ioctl(self.card.handle, io, common_kmd.drmIoctlIowr(drm.command_base + drm.i915_gem_execbuffer2, drm.ExecBuffer2), &execbuffer) catch return VkError.DeviceLost;
|
base.utils.ioctl(
|
||||||
|
self.card.handle,
|
||||||
|
io,
|
||||||
|
common_kmd.drmIoctlIowr(_i915.command_base + _i915.gem_execbuffer2, _i915.ExecBuffer2),
|
||||||
|
&execbuffer,
|
||||||
|
) catch return VkError.DeviceLost;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -156,11 +163,11 @@ pub const Memory = struct {
|
|||||||
pub fn deinit(self: *Memory, device: *Device, io: std.Io) void {
|
pub fn deinit(self: *Memory, device: *Device, io: std.Io) void {
|
||||||
self.unmap();
|
self.unmap();
|
||||||
|
|
||||||
var close = drm.GemClose{
|
var close = _i915.GemClose{
|
||||||
.handle = self.handle,
|
.handle = self.handle,
|
||||||
.pad = 0,
|
.pad = 0,
|
||||||
};
|
};
|
||||||
base.utils.ioctl(device.card.handle, io, common_kmd.drmIoctlIow(drm.gem_close, drm.GemClose), &close) catch {};
|
base.utils.ioctl(device.card.handle, io, common_kmd.drmIoctlIow(_i915.gem_close, _i915.GemClose), &close) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
self.* = undefined;
|
self.* = undefined;
|
||||||
}
|
}
|
||||||
@@ -176,14 +183,19 @@ pub const Memory = struct {
|
|||||||
return mapping.slice(offset, map_size);
|
return mapping.slice(offset, map_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mmap_offset = drm.GemMmapOffset{
|
var mmap_offset = _i915.GemMmapOffset{
|
||||||
.handle = self.handle,
|
.handle = self.handle,
|
||||||
.pad = 0,
|
.pad = 0,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.flags = drm.i915_mmap_offset_wb,
|
.flags = _i915.mmap_offset_wb,
|
||||||
.extensions = 0,
|
.extensions = 0,
|
||||||
};
|
};
|
||||||
base.utils.ioctl(device.card.handle, io, common_kmd.drmIoctlIowr(drm.command_base + drm.i915_gem_mmap_gtt, drm.GemMmapOffset), &mmap_offset) catch return VkError.MemoryMapFailed;
|
base.utils.ioctl(
|
||||||
|
device.card.handle,
|
||||||
|
io,
|
||||||
|
common_kmd.drmIoctlIowr(_i915.command_base + _i915.gem_mmap_gtt, _i915.GemMmapOffset),
|
||||||
|
&mmap_offset,
|
||||||
|
) catch return VkError.MemoryMapFailed;
|
||||||
|
|
||||||
if (self.size > std.math.maxInt(usize)) return VkError.MemoryMapFailed;
|
if (self.size > std.math.maxInt(usize)) return VkError.MemoryMapFailed;
|
||||||
const full_size: usize = @intCast(self.size);
|
const full_size: usize = @intCast(self.size);
|
||||||
@@ -210,21 +222,26 @@ pub const Memory = struct {
|
|||||||
pub fn flushRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
pub fn flushRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
||||||
_ = offset;
|
_ = offset;
|
||||||
_ = size;
|
_ = size;
|
||||||
try self.setDomain(device, io, drm.i915_gem_domain_cpu, 0);
|
try self.setDomain(device, io, _i915.gem_domain_cpu, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidateRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
pub fn invalidateRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
||||||
_ = offset;
|
_ = offset;
|
||||||
_ = size;
|
_ = size;
|
||||||
try self.setDomain(device, io, drm.i915_gem_domain_cpu, 0);
|
try self.setDomain(device, io, _i915.gem_domain_cpu, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setDomain(self: *Memory, device: *Device, io: std.Io, read_domains: u32, write_domain: u32) VkError!void {
|
fn setDomain(self: *Memory, device: *Device, io: std.Io, read_domains: u32, write_domain: u32) VkError!void {
|
||||||
var domain = drm.GemSetDomain{
|
var domain = _i915.GemSetDomain{
|
||||||
.handle = self.handle,
|
.handle = self.handle,
|
||||||
.read_domains = read_domains,
|
.read_domains = read_domains,
|
||||||
.write_domain = write_domain,
|
.write_domain = write_domain,
|
||||||
};
|
};
|
||||||
base.utils.ioctl(device.card.handle, io, common_kmd.drmIoctlIow(drm.command_base + drm.i915_gem_set_domain, drm.GemSetDomain), &domain) catch return VkError.DeviceLost;
|
base.utils.ioctl(
|
||||||
|
device.card.handle,
|
||||||
|
io,
|
||||||
|
common_kmd.drmIoctlIow(_i915.command_base + _i915.gem_set_domain, _i915.GemSetDomain),
|
||||||
|
&domain,
|
||||||
|
) catch return VkError.DeviceLost;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+53
-52
@@ -1,7 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
const KmdType = @import("lib.zig").KmdType;
|
||||||
|
|
||||||
const FlintPhysicalDevice = @import("FlintPhysicalDevice.zig");
|
const FlintPhysicalDevice = @import("FlintPhysicalDevice.zig");
|
||||||
const i915_kmd = @import("i915/kmd.zig");
|
const i915_kmd = @import("i915/kmd.zig");
|
||||||
@@ -32,128 +33,128 @@ pub const SyncDependency = struct {
|
|||||||
signal: bool = false,
|
signal: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Device = union(lib.KmdType) {
|
pub const Device = union(KmdType) {
|
||||||
Invalid: void,
|
invalid: void,
|
||||||
I915: i915_kmd.Device,
|
i915: i915_kmd.Device,
|
||||||
Xe: xe.Device,
|
xe: xe.Device,
|
||||||
|
|
||||||
pub fn open(io: std.Io, physical_device: *const FlintPhysicalDevice) VkError!Device {
|
pub fn open(io: std.Io, physical_device: *const FlintPhysicalDevice) VkError!Device {
|
||||||
return switch (physical_device.kmd_type) {
|
return switch (physical_device.kmd_type) {
|
||||||
.I915 => .{ .I915 = try i915_kmd.Device.open(io, physical_device.getNodePath()) },
|
.i915 => .{ .i915 = try i915_kmd.Device.open(io, physical_device.getNodePath()) },
|
||||||
.Xe => .{ .Xe = try xe.Device.open(io, physical_device.getNodePath()) },
|
.xe => .{ .xe = try xe.Device.open(io, physical_device.getNodePath()) },
|
||||||
.Invalid => VkError.InitializationFailed,
|
.invalid => VkError.InitializationFailed,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(self: *Device, io: std.Io) void {
|
pub fn close(self: *Device, io: std.Io) void {
|
||||||
switch (self.*) {
|
switch (self.*) {
|
||||||
.I915 => |*device| device.close(io),
|
.i915 => |*device| device.close(io),
|
||||||
.Xe => |*device| device.close(io),
|
.xe => |*device| device.close(io),
|
||||||
.Invalid => {},
|
.invalid => {},
|
||||||
}
|
}
|
||||||
self.* = .{ .Invalid = {} };
|
self.* = .{ .invalid = {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocateMemory(self: *Device, io: std.Io, size: vk.DeviceSize) VkError!Memory {
|
pub fn allocateMemory(self: *Device, io: std.Io, size: vk.DeviceSize) VkError!Memory {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*device| .{ .I915 = try device.allocateMemory(io, size) },
|
.i915 => |*device| .{ .i915 = try device.allocateMemory(io, size) },
|
||||||
.Xe => |*device| .{ .Xe = try device.allocateMemory(io, size) },
|
.xe => |*device| .{ .xe = try device.allocateMemory(io, size) },
|
||||||
.Invalid => VkError.OutOfDeviceMemory,
|
.invalid => VkError.OutOfDeviceMemory,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submitBatch(self: *Device, io: std.Io, allocator: std.mem.Allocator, commands: []const u32, relocations: []const Relocation, syncs: []const SyncDependency) VkError!void {
|
pub fn submitBatch(self: *Device, io: std.Io, allocator: std.mem.Allocator, commands: []const u32, relocations: []const Relocation, syncs: []const SyncDependency) VkError!void {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*device| device.submitBatch(io, allocator, commands, relocations, syncs),
|
.i915 => |*device| device.submitBatch(io, allocator, commands, relocations, syncs),
|
||||||
.Xe => |*device| device.submitBatch(io, allocator, commands, relocations, syncs),
|
.xe => |*device| device.submitBatch(io, allocator, commands, relocations, syncs),
|
||||||
.Invalid => VkError.DeviceLost,
|
.invalid => VkError.DeviceLost,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file(self: *Device) VkError!std.Io.File {
|
pub fn file(self: *Device) VkError!std.Io.File {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*device| device.card.handle,
|
.i915 => |*device| device.card.handle,
|
||||||
.Xe => |*device| device.card.handle,
|
.xe => |*device| device.card.handle,
|
||||||
.Invalid => VkError.DeviceLost,
|
.invalid => VkError.DeviceLost,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Memory = union(lib.KmdType) {
|
pub const Memory = union(KmdType) {
|
||||||
Invalid: void,
|
invalid: void,
|
||||||
I915: i915_kmd.Memory,
|
i915: i915_kmd.Memory,
|
||||||
Xe: xe.Memory,
|
xe: xe.Memory,
|
||||||
|
|
||||||
pub fn deinit(self: *Memory, device: *Device, io: std.Io) void {
|
pub fn deinit(self: *Memory, device: *Device, io: std.Io) void {
|
||||||
switch (self.*) {
|
switch (self.*) {
|
||||||
.I915 => |*memory| switch (device.*) {
|
.i915 => |*memory| switch (device.*) {
|
||||||
.I915 => |*adapter| memory.deinit(adapter, io),
|
.i915 => |*adapter| memory.deinit(adapter, io),
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
.Xe => |*memory| switch (device.*) {
|
.xe => |*memory| switch (device.*) {
|
||||||
.Xe => |*adapter| memory.deinit(adapter, io),
|
.xe => |*adapter| memory.deinit(adapter, io),
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
.Invalid => {},
|
.invalid => {},
|
||||||
}
|
}
|
||||||
self.* = .{ .Invalid = {} };
|
self.* = .{ .invalid = {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError![]u8 {
|
pub fn map(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError![]u8 {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*memory| switch (device.*) {
|
.i915 => |*memory| switch (device.*) {
|
||||||
.I915 => |*adapter| memory.map(adapter, io, offset, size),
|
.i915 => |*adapter| memory.map(adapter, io, offset, size),
|
||||||
else => VkError.MemoryMapFailed,
|
else => VkError.MemoryMapFailed,
|
||||||
},
|
},
|
||||||
.Xe => |*memory| switch (device.*) {
|
.xe => |*memory| switch (device.*) {
|
||||||
.Xe => |*adapter| memory.map(adapter, io, offset, size),
|
.xe => |*adapter| memory.map(adapter, io, offset, size),
|
||||||
else => VkError.MemoryMapFailed,
|
else => VkError.MemoryMapFailed,
|
||||||
},
|
},
|
||||||
.Invalid => VkError.MemoryMapFailed,
|
.invalid => VkError.MemoryMapFailed,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmap(self: *Memory) void {
|
pub fn unmap(self: *Memory) void {
|
||||||
switch (self.*) {
|
switch (self.*) {
|
||||||
.I915 => |*memory| memory.unmap(),
|
.i915 => |*memory| memory.unmap(),
|
||||||
.Xe => |*memory| memory.unmap(),
|
.xe => |*memory| memory.unmap(),
|
||||||
.Invalid => {},
|
.invalid => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flushRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
pub fn flushRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*memory| switch (device.*) {
|
.i915 => |*memory| switch (device.*) {
|
||||||
.I915 => |*adapter| memory.flushRange(adapter, io, offset, size),
|
.i915 => |*adapter| memory.flushRange(adapter, io, offset, size),
|
||||||
else => VkError.InvalidDeviceMemoryDrv,
|
else => VkError.InvalidDeviceMemoryDrv,
|
||||||
},
|
},
|
||||||
.Xe => |*memory| switch (device.*) {
|
.xe => |*memory| switch (device.*) {
|
||||||
.Xe => |*adapter| memory.flushRange(adapter, io, offset, size),
|
.xe => |*adapter| memory.flushRange(adapter, io, offset, size),
|
||||||
else => VkError.InvalidDeviceMemoryDrv,
|
else => VkError.InvalidDeviceMemoryDrv,
|
||||||
},
|
},
|
||||||
.Invalid => VkError.InvalidDeviceMemoryDrv,
|
.invalid => VkError.InvalidDeviceMemoryDrv,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidateRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
pub fn invalidateRange(self: *Memory, device: *Device, io: std.Io, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!void {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*memory| switch (device.*) {
|
.i915 => |*memory| switch (device.*) {
|
||||||
.I915 => |*adapter| memory.invalidateRange(adapter, io, offset, size),
|
.i915 => |*adapter| memory.invalidateRange(adapter, io, offset, size),
|
||||||
else => VkError.InvalidDeviceMemoryDrv,
|
else => VkError.InvalidDeviceMemoryDrv,
|
||||||
},
|
},
|
||||||
.Xe => |*memory| switch (device.*) {
|
.xe => |*memory| switch (device.*) {
|
||||||
.Xe => |*adapter| memory.invalidateRange(adapter, io, offset, size),
|
.xe => |*adapter| memory.invalidateRange(adapter, io, offset, size),
|
||||||
else => VkError.InvalidDeviceMemoryDrv,
|
else => VkError.InvalidDeviceMemoryDrv,
|
||||||
},
|
},
|
||||||
.Invalid => VkError.InvalidDeviceMemoryDrv,
|
.invalid => VkError.InvalidDeviceMemoryDrv,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle(self: *const Memory) VkError!u32 {
|
pub fn handle(self: *const Memory) VkError!u32 {
|
||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.I915 => |*memory| memory.handle,
|
.i915 => |*memory| memory.handle,
|
||||||
.Xe => VkError.FeatureNotPresent,
|
.xe => VkError.FeatureNotPresent,
|
||||||
.Invalid => VkError.InvalidDeviceMemoryDrv,
|
.invalid => VkError.InvalidDeviceMemoryDrv,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -52,9 +52,9 @@ pub const VULKAN_VERSION = vk.makeApiVersion(
|
|||||||
pub const IMAGE_MEMORY_ALIGNMENT = std.heap.page_size_max;
|
pub const IMAGE_MEMORY_ALIGNMENT = std.heap.page_size_max;
|
||||||
|
|
||||||
pub const KmdType = enum {
|
pub const KmdType = enum {
|
||||||
Invalid,
|
invalid,
|
||||||
I915,
|
i915,
|
||||||
Xe,
|
xe,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const std_options = base.std_options;
|
pub const std_options = base.std_options;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
const PciInfo = struct {
|
const PciInfo = struct {
|
||||||
id: u16,
|
id: u16,
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.BinarySemaphore;
|
pub const Interface = base.BinarySemaphore;
|
||||||
|
|||||||
@@ -2,10 +2,8 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Buffer;
|
pub const Interface = base.Buffer;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.BufferView;
|
pub const Interface = base.BufferView;
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const NonDispatchable = base.NonDispatchable;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const PhiCommandBuffer = @import("PhiCommandBuffer.zig");
|
const PhiCommandBuffer = @import("PhiCommandBuffer.zig");
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const VulkanAllocator = base.VulkanAllocator;
|
|
||||||
|
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorPool;
|
pub const Interface = base.DescriptorPool;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorSetLayout;
|
pub const Interface = base.DescriptorSetLayout;
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ fn uploadAndLaunchDaemon(instance: *base.Instance, allocator: std.mem.Allocator,
|
|||||||
|
|
||||||
const local_path = std.fmt.allocPrint(allocator, "/tmp/ape_phi_device_{d}_{d}.mic", .{ std.os.linux.getpid(), mic_device_num }) catch return VkError.OutOfHostMemory;
|
const local_path = std.fmt.allocPrint(allocator, "/tmp/ape_phi_device_{d}_{d}.mic", .{ std.os.linux.getpid(), mic_device_num }) catch return VkError.OutOfHostMemory;
|
||||||
defer allocator.free(local_path);
|
defer allocator.free(local_path);
|
||||||
defer std.Io.Dir.deleteFileAbsolute(io, local_path) catch {};
|
defer std.Io.Dir.deleteFileAbsolute(io, local_path) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
std.Io.Dir.writeFile(.cwd(), io, .{
|
std.Io.Dir.writeFile(.cwd(), io, .{
|
||||||
.sub_path = local_path,
|
.sub_path = local_path,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ pub fn create(device: *PhiDevice, allocator: std.mem.Allocator, size: vk.DeviceS
|
|||||||
.flags = 0,
|
.flags = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
var reply: proto.PhiAllocMemoryReply = undefined;
|
var reply = std.mem.zeroes(proto.PhiAllocMemoryReply);
|
||||||
try device.transport.request(proto.PHI_PACKET_ALLOC_MEMORY, std.mem.asBytes(&alloc_request), std.mem.asBytes(&reply));
|
try device.transport.request(proto.PHI_PACKET_ALLOC_MEMORY, std.mem.asBytes(&alloc_request), std.mem.asBytes(&reply));
|
||||||
|
|
||||||
if (reply.result.status != proto.PHI_STATUS_OK) {
|
if (reply.result.status != proto.PHI_STATUS_OK) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Event;
|
pub const Interface = base.Event;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.ImageView;
|
pub const Interface = base.ImageView;
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, _
|
|||||||
defer device.deinit();
|
defer device.deinit();
|
||||||
|
|
||||||
const physical_device = try PhiPhysicalDevice.create(allocator, interface, device, device_num);
|
const physical_device = try PhiPhysicalDevice.create(allocator, interface, device, device_num);
|
||||||
errdefer physical_device.interface.release(allocator) catch {};
|
errdefer physical_device.interface.release(allocator) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
||||||
errdefer dispatchable.destroy(allocator);
|
errdefer dispatchable.destroy(allocator);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ const pci_ids = @import("pci_ids.zig").map;
|
|||||||
const PhiDevice = @import("PhiDevice.zig");
|
const PhiDevice = @import("PhiDevice.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const VulkanAllocator = base.VulkanAllocator;
|
|
||||||
const SurfaceKHR = base.SurfaceKHR;
|
const SurfaceKHR = base.SurfaceKHR;
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
@@ -87,7 +86,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *base.Instance, mic_device
|
|||||||
return VkError.InitializationFailed;
|
return VkError.InitializationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface.props.pipeline_cache_uuid = undefined;
|
interface.props.pipeline_cache_uuid = @splat(0);
|
||||||
interface.props.limits = .{
|
interface.props.limits = .{
|
||||||
.max_image_dimension_1d = 4096,
|
.max_image_dimension_1d = 4096,
|
||||||
.max_image_dimension_2d = 4096,
|
.max_image_dimension_2d = 4096,
|
||||||
@@ -872,10 +871,10 @@ fn cpuid(leaf_id: u32, subleaf_id: u32) CpuidRegs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var eax: u32 = undefined;
|
var eax: u32 = 0;
|
||||||
var ebx: u32 = undefined;
|
var ebx: u32 = 0;
|
||||||
var ecx: u32 = undefined;
|
var ecx: u32 = 0;
|
||||||
var edx: u32 = undefined;
|
var edx: u32 = 0;
|
||||||
|
|
||||||
asm volatile ("cpuid"
|
asm volatile ("cpuid"
|
||||||
: [_] "={eax}" (eax),
|
: [_] "={eax}" (eax),
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.PipelineLayout;
|
pub const Interface = base.PipelineLayout;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.QueryPool;
|
pub const Interface = base.QueryPool;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ pub fn submit(interface: *Interface, infos: []Interface.SubmitInfo, fence: ?*bas
|
|||||||
@memcpy(payload[@sizeOf(proto.PhiWorkExecutionRequest)..], phi_command_buffer.commands.items);
|
@memcpy(payload[@sizeOf(proto.PhiWorkExecutionRequest)..], phi_command_buffer.commands.items);
|
||||||
|
|
||||||
// Synchronous queues for now
|
// Synchronous queues for now
|
||||||
var reply: proto.PhiWorkExecutionReply = undefined;
|
var reply = std.mem.zeroes(proto.PhiWorkExecutionReply);
|
||||||
try device.transport.request(proto.PHI_PACKET_WORK_EXECUTION, payload, std.mem.asBytes(&reply));
|
try device.transport.request(proto.PHI_PACKET_WORK_EXECUTION, payload, std.mem.asBytes(&reply));
|
||||||
|
|
||||||
if (reply.result.status != proto.PHI_STATUS_OK) {
|
if (reply.result.status != proto.PHI_STATUS_OK) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.RenderPass;
|
pub const Interface = base.RenderPass;
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ pub fn request(self: *Self, command: c_uint, payload: []const u8, reply_payload:
|
|||||||
try self.writeAll(std.mem.asBytes(&header));
|
try self.writeAll(std.mem.asBytes(&header));
|
||||||
try self.writeAll(payload);
|
try self.writeAll(payload);
|
||||||
|
|
||||||
|
// SAFETY: will be entirely written with the readAll
|
||||||
var reply_header: proto.PhiMessageHeader = undefined;
|
var reply_header: proto.PhiMessageHeader = undefined;
|
||||||
try self.readAll(std.mem.asBytes(&reply_header));
|
try self.readAll(std.mem.asBytes(&reply_header));
|
||||||
|
|
||||||
@@ -119,6 +120,8 @@ fn handshake(self: *Self) VkError!void {
|
|||||||
.host_protocol_version = proto.PHI_PROTOCOL_VERSION,
|
.host_protocol_version = proto.PHI_PROTOCOL_VERSION,
|
||||||
.reserved = 0,
|
.reserved = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SAFETY: will be entirely written by the request
|
||||||
var reply: proto.PhiHelloReply = undefined;
|
var reply: proto.PhiHelloReply = undefined;
|
||||||
try self.request(proto.PHI_PACKET_HELLO, std.mem.asBytes(&request_payload), std.mem.asBytes(&reply));
|
try self.request(proto.PHI_PACKET_HELLO, std.mem.asBytes(&request_payload), std.mem.asBytes(&reply));
|
||||||
if (reply.result.status != proto.PHI_STATUS_OK) {
|
if (reply.result.status != proto.PHI_STATUS_OK) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
const PciInfo = struct {
|
const PciInfo = struct {
|
||||||
id: u16,
|
id: u16,
|
||||||
|
|||||||
@@ -13,12 +13,18 @@ pub const PortId = extern struct {
|
|||||||
pub const SEND_BLOCK = 1;
|
pub const SEND_BLOCK = 1;
|
||||||
pub const RECV_BLOCK = 1;
|
pub const RECV_BLOCK = 1;
|
||||||
|
|
||||||
|
// SAFETY: load assigns every function pointer before the public wrappers can be used.
|
||||||
var scif_open: *const fn () callconv(.c) epd_t = undefined;
|
var scif_open: *const fn () callconv(.c) epd_t = undefined;
|
||||||
|
// SAFETY: load assigns every function pointer before the public wrappers can be used.
|
||||||
var scif_close: *const fn (epd: epd_t) callconv(.c) c_int = undefined;
|
var scif_close: *const fn (epd: epd_t) callconv(.c) c_int = undefined;
|
||||||
|
// SAFETY: load assigns every function pointer before the public wrappers can be used.
|
||||||
var scif_connect: *const fn (epd: epd_t, dst: *const PortId) callconv(.c) c_int = undefined;
|
var scif_connect: *const fn (epd: epd_t, dst: *const PortId) callconv(.c) c_int = undefined;
|
||||||
|
// SAFETY: load assigns every function pointer before the public wrappers can be used.
|
||||||
var scif_send: *const fn (epd: epd_t, msg: ?*const anyopaque, len: usize, flags: c_int) callconv(.c) isize = undefined;
|
var scif_send: *const fn (epd: epd_t, msg: ?*const anyopaque, len: usize, flags: c_int) callconv(.c) isize = undefined;
|
||||||
|
// SAFETY: load assigns every function pointer before the public wrappers can be used.
|
||||||
var scif_recv: *const fn (epd: epd_t, msg: ?*anyopaque, len: usize, flags: c_int) callconv(.c) isize = undefined;
|
var scif_recv: *const fn (epd: epd_t, msg: ?*anyopaque, len: usize, flags: c_int) callconv(.c) isize = undefined;
|
||||||
|
|
||||||
|
// SAFETY: load initializes the module before it can be closed or queried.
|
||||||
var module: std.DynLib = undefined;
|
var module: std.DynLib = undefined;
|
||||||
var ref_count = std.atomic.Value(usize).init(0);
|
var ref_count = std.atomic.Value(usize).init(0);
|
||||||
var load_mutex: base.SpinMutex = .{};
|
var load_mutex: base.SpinMutex = .{};
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.BinarySemaphore;
|
pub const Interface = base.BinarySemaphore;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const base = @import("base");
|
|||||||
const lib = @import("lib.zig");
|
const lib = @import("lib.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Buffer;
|
pub const Interface = base.Buffer;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.BufferView;
|
pub const Interface = base.BufferView;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const lib = @import("lib.zig");
|
const lib = @import("lib.zig");
|
||||||
|
|
||||||
const Device = base.Device;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
const SoftBuffer = @import("SoftBuffer.zig");
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
@@ -129,10 +128,9 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
|||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.interface = interface,
|
.interface = interface,
|
||||||
.command_allocator = undefined,
|
.command_allocator = .init(interface.host_allocator.allocator()),
|
||||||
.commands = .empty,
|
.commands = .empty,
|
||||||
};
|
};
|
||||||
self.command_allocator = .init(self.interface.host_allocator.allocator());
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +142,7 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
|||||||
|
|
||||||
pub fn execute(self: *Self, device: *ExecutionDevice) VkError!void {
|
pub fn execute(self: *Self, device: *ExecutionDevice) VkError!void {
|
||||||
try self.interface.submit();
|
try self.interface.submit();
|
||||||
defer self.interface.finish() catch {};
|
defer self.interface.finish() catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
for (self.commands.items) |command| {
|
for (self.commands.items) |command| {
|
||||||
command.vtable.execute(@ptrCast(command.ptr), device) catch |err| {
|
command.vtable.execute(@ptrCast(command.ptr), device) catch |err| {
|
||||||
@@ -1063,7 +1061,11 @@ pub fn endRenderPass(interface: *Interface) VkError!void {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.commands.append(allocator, .{ .ptr = undefined, .vtable = &.{ .execute = CommandImpl.execute } }) catch return VkError.OutOfHostMemory;
|
self.commands.append(allocator, .{
|
||||||
|
// SAFETY: this command's execute callback does not inspect its context pointer.
|
||||||
|
.ptr = undefined,
|
||||||
|
.vtable = &.{ .execute = CommandImpl.execute },
|
||||||
|
}) catch return VkError.OutOfHostMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn executeCommands(interface: *Interface, commands: *Interface) VkError!void {
|
pub fn executeCommands(interface: *Interface, commands: *Interface) VkError!void {
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const NonDispatchable = base.NonDispatchable;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
|
const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const base = @import("base");
|
|||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const VulkanAllocator = base.VulkanAllocator;
|
const VulkanAllocator = base.VulkanAllocator;
|
||||||
|
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const SoftDescriptorSet = @import("SoftDescriptorSet.zig");
|
const SoftDescriptorSet = @import("SoftDescriptorSet.zig");
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
const Buffer = base.Buffer;
|
const Buffer = base.Buffer;
|
||||||
const BufferView = base.BufferView;
|
const BufferView = base.BufferView;
|
||||||
const ImageView = base.ImageView;
|
const ImageView = base.ImageView;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.DescriptorSetLayout;
|
pub const Interface = base.DescriptorSetLayout;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const builtin = @import("builtin");
|
|
||||||
const config = base.config;
|
|
||||||
|
|
||||||
const SoftQueue = @import("SoftQueue.zig");
|
const SoftQueue = @import("SoftQueue.zig");
|
||||||
|
|
||||||
@@ -33,8 +31,6 @@ const VkError = base.VkError;
|
|||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Device;
|
pub const Interface = base.Device;
|
||||||
|
|
||||||
const SpawnError = std.Thread.SpawnError;
|
|
||||||
|
|
||||||
interface: Interface,
|
interface: Interface,
|
||||||
|
|
||||||
pub fn create(instance: *base.Instance, physical_device: *base.PhysicalDevice, allocator: std.mem.Allocator, info: *const vk.DeviceCreateInfo) VkError!*Self {
|
pub fn create(instance: *base.Instance, physical_device: *base.PhysicalDevice, allocator: std.mem.Allocator, info: *const vk.DeviceCreateInfo) VkError!*Self {
|
||||||
@@ -42,7 +38,7 @@ pub fn create(instance: *base.Instance, physical_device: *base.PhysicalDevice, a
|
|||||||
var initialized = false;
|
var initialized = false;
|
||||||
errdefer {
|
errdefer {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
self.interface.destroy(allocator) catch {};
|
self.interface.destroy(allocator) catch @panic("Caught an error while handling an error");
|
||||||
} else {
|
} else {
|
||||||
allocator.destroy(self);
|
allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
const SoftDevice = @import("SoftDevice.zig");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Event;
|
pub const Interface = base.Event;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const blitter = @import("device/blitter.zig");
|
const blitter = @import("device/blitter.zig");
|
||||||
|
|
||||||
|
|||||||
@@ -61,10 +61,8 @@ const F32x4 = blitter.F32x4;
|
|||||||
const U32x4 = blitter.U32x4;
|
const U32x4 = blitter.U32x4;
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const SoftBuffer = @import("SoftBuffer.zig");
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.Image;
|
pub const Interface = base.Image;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.ImageView;
|
pub const Interface = base.ImageView;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
const SoftPhysicalDevice = @import("SoftPhysicalDevice.zig");
|
const SoftPhysicalDevice = @import("SoftPhysicalDevice.zig");
|
||||||
|
|
||||||
const Dispatchable = base.Dispatchable;
|
const Dispatchable = base.Dispatchable;
|
||||||
@@ -63,7 +62,7 @@ fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
|||||||
fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, _: []base.drm.Card) VkError!void {
|
fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator, _: []base.drm.Card) VkError!void {
|
||||||
// Software driver has only one physical device (the CPU)
|
// Software driver has only one physical device (the CPU)
|
||||||
const physical_device = try SoftPhysicalDevice.create(allocator, interface);
|
const physical_device = try SoftPhysicalDevice.create(allocator, interface);
|
||||||
errdefer physical_device.interface.release(allocator) catch {};
|
errdefer physical_device.interface.release(allocator) catch @panic("Caught an error while handling an error");
|
||||||
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
const dispatchable = try Dispatchable(base.PhysicalDevice).wrap(allocator, &physical_device.interface);
|
||||||
errdefer dispatchable.destroy(allocator);
|
errdefer dispatchable.destroy(allocator);
|
||||||
interface.physical_devices.append(allocator, dispatchable) catch return VkError.OutOfHostMemory;
|
interface.physical_devices.append(allocator, dispatchable) catch return VkError.OutOfHostMemory;
|
||||||
|
|||||||
@@ -925,10 +925,10 @@ fn cpuid(leaf_id: u32, subleaf_id: u32) CpuidRegs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var eax: u32 = undefined;
|
var eax: u32 = 0;
|
||||||
var ebx: u32 = undefined;
|
var ebx: u32 = 0;
|
||||||
var ecx: u32 = undefined;
|
var ecx: u32 = 0;
|
||||||
var edx: u32 = undefined;
|
var edx: u32 = 0;
|
||||||
|
|
||||||
asm volatile ("cpuid"
|
asm volatile ("cpuid"
|
||||||
: [_] "={eax}" (eax),
|
: [_] "={eax}" (eax),
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const zm = base.zm;
|
|||||||
|
|
||||||
const blitter = @import("device/blitter.zig");
|
const blitter = @import("device/blitter.zig");
|
||||||
|
|
||||||
const Device = base.Device;
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
||||||
|
|
||||||
@@ -31,7 +30,6 @@ pub threadlocal var current_framebuffer_attachment_count: usize = 0;
|
|||||||
const NonDispatchable = base.NonDispatchable;
|
const NonDispatchable = base.NonDispatchable;
|
||||||
const ShaderModule = base.ShaderModule;
|
const ShaderModule = base.ShaderModule;
|
||||||
|
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
|
||||||
const SoftBuffer = @import("SoftBuffer.zig");
|
const SoftBuffer = @import("SoftBuffer.zig");
|
||||||
const SoftBufferView = @import("SoftBufferView.zig");
|
const SoftBufferView = @import("SoftBufferView.zig");
|
||||||
const SoftImage = @import("SoftImage.zig");
|
const SoftImage = @import("SoftImage.zig");
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const base = @import("base");
|
|||||||
const spv = @import("spv");
|
const spv = @import("spv");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
|
||||||
const SoftShaderModule = @import("SoftShaderModule.zig");
|
const SoftShaderModule = @import("SoftShaderModule.zig");
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.PipelineLayout;
|
pub const Interface = base.PipelineLayout;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.QueryPool;
|
pub const Interface = base.QueryPool;
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const ExecutionDevice = @import("device/Device.zig");
|
const ExecutionDevice = @import("device/Device.zig");
|
||||||
const Dispatchable = base.Dispatchable;
|
|
||||||
|
|
||||||
const CommandBuffer = base.CommandBuffer;
|
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
const SoftDevice = @import("SoftDevice.zig");
|
||||||
const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
|
const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
|
||||||
|
|
||||||
@@ -109,6 +107,7 @@ fn executeSubmitInfo(soft_device: *SoftDevice, info: Interface.SubmitInfo) VkErr
|
|||||||
try semaphore.wait();
|
try semaphore.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SAFETY: setup initializes every field before execution_device is read.
|
||||||
var execution_device: ExecutionDevice = undefined;
|
var execution_device: ExecutionDevice = undefined;
|
||||||
execution_device.setup(soft_device);
|
execution_device.setup(soft_device);
|
||||||
defer execution_device.deinit(soft_device.interface.device_allocator.allocator());
|
defer execution_device.deinit(soft_device.interface.device_allocator.allocator());
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ const vk = @import("vulkan");
|
|||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.RenderPass;
|
pub const Interface = base.RenderPass;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const zm = base.zm;
|
|||||||
const blitter = @import("device/blitter.zig");
|
const blitter = @import("device/blitter.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
const F32x4 = zm.F32x4;
|
const F32x4 = zm.F32x4;
|
||||||
const U32x4 = blitter.U32x4;
|
const U32x4 = blitter.U32x4;
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const spv = @import("spv");
|
const spv = @import("spv");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const Device = base.Device;
|
|
||||||
|
|
||||||
const SoftDevice = @import("SoftDevice.zig");
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Interface = base.ShaderModule;
|
pub const Interface = base.ShaderModule;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const base = @import("base");
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
|
||||||
const base = @import("base");
|
const base = @import("base");
|
||||||
const spv = @import("spv");
|
const spv = @import("spv");
|
||||||
const lib = @import("../lib.zig");
|
|
||||||
|
|
||||||
const ExecutionDevice = @import("Device.zig");
|
const ExecutionDevice = @import("Device.zig");
|
||||||
const PipelineState = ExecutionDevice.PipelineState;
|
const PipelineState = ExecutionDevice.PipelineState;
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ const spv = @import("spv");
|
|||||||
|
|
||||||
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
||||||
const SoftDevice = @import("../SoftDevice.zig");
|
const SoftDevice = @import("../SoftDevice.zig");
|
||||||
const SoftFramebuffer = @import("../SoftFramebuffer.zig");
|
|
||||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||||
const SoftRenderPass = @import("../SoftRenderPass.zig");
|
|
||||||
|
|
||||||
const ComputeDispatcher = @import("ComputeDispatcher.zig");
|
const ComputeDispatcher = @import("ComputeDispatcher.zig");
|
||||||
const Renderer = @import("Renderer.zig");
|
const Renderer = @import("Renderer.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
pub const GRAPHICS_PIPELINE_STATE = 0;
|
pub const GRAPHICS_PIPELINE_STATE = 0;
|
||||||
@@ -58,7 +54,9 @@ pub fn setup(self: *Self, device: *SoftDevice) void {
|
|||||||
.data = switch (i) {
|
.data = switch (i) {
|
||||||
GRAPHICS_PIPELINE_STATE => .{
|
GRAPHICS_PIPELINE_STATE => .{
|
||||||
.graphics = .{
|
.graphics = .{
|
||||||
|
// SAFETY: indexed draws bind the index buffer before the renderer reads it.
|
||||||
.index_buffer = undefined,
|
.index_buffer = undefined,
|
||||||
|
// SAFETY: each vertex binding is populated before an attribute reads it.
|
||||||
.vertex_buffers = undefined,
|
.vertex_buffers = undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,16 +9,13 @@ const PipelineState = ExecutionDevice.PipelineState;
|
|||||||
const BoundedAllocator = @import("BoundedAllocator.zig");
|
const BoundedAllocator = @import("BoundedAllocator.zig");
|
||||||
|
|
||||||
const SoftBuffer = @import("../SoftBuffer.zig");
|
const SoftBuffer = @import("../SoftBuffer.zig");
|
||||||
const SoftDescriptorSet = @import("../SoftDescriptorSet.zig");
|
|
||||||
const SoftDevice = @import("../SoftDevice.zig");
|
const SoftDevice = @import("../SoftDevice.zig");
|
||||||
const SoftFramebuffer = @import("../SoftFramebuffer.zig");
|
const SoftFramebuffer = @import("../SoftFramebuffer.zig");
|
||||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||||
const SoftRenderPass = @import("../SoftRenderPass.zig");
|
const SoftRenderPass = @import("../SoftRenderPass.zig");
|
||||||
|
|
||||||
const blitter = @import("blitter.zig");
|
|
||||||
const rasterizer = @import("rasterizer.zig");
|
const rasterizer = @import("rasterizer.zig");
|
||||||
const vertex_dispatcher = @import("vertex_dispatcher.zig");
|
const vertex_dispatcher = @import("vertex_dispatcher.zig");
|
||||||
const clip = @import("clip.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const F32x4 = zm.F32x4;
|
const F32x4 = zm.F32x4;
|
||||||
@@ -110,7 +107,9 @@ pub const DrawCall = struct {
|
|||||||
.vertex_count = vertex_count,
|
.vertex_count = vertex_count,
|
||||||
.instance_count = instance_count,
|
.instance_count = instance_count,
|
||||||
.renderer = renderer,
|
.renderer = renderer,
|
||||||
|
// SAFETY: draw assigns the viewport before the rasterizer receives this value.
|
||||||
.viewport = undefined,
|
.viewport = undefined,
|
||||||
|
// SAFETY: draw assigns the scissor before the rasterizer receives this value.
|
||||||
.scissor = undefined,
|
.scissor = undefined,
|
||||||
.color_attachments = framebuffer.interface.attachments[0..],
|
.color_attachments = framebuffer.interface.attachments[0..],
|
||||||
.depth_attachment = if (render_pass.interface.subpasses[renderer.subpass_index].depth_stencil_attachments) |desc| framebuffer.interface.attachments[desc.attachment] else null,
|
.depth_attachment = if (render_pass.interface.subpasses[renderer.subpass_index].depth_stencil_attachments) |desc| framebuffer.interface.attachments[desc.attachment] else null,
|
||||||
|
|||||||
@@ -1640,7 +1640,7 @@ fn encodeUFloat(value: f32, mantissa_bits: comptime_int) u32 {
|
|||||||
return max_exponent << mantissa_bits;
|
return max_exponent << mantissa_bits;
|
||||||
|
|
||||||
if (adjusted_exponent <= 0) {
|
if (adjusted_exponent <= 0) {
|
||||||
const mantissa = @as(u32, @intFromFloat(@round(value * @as(f32, @floatFromInt(1 << (mantissa_bits + exponent_bias - 1))))));
|
const mantissa: u32 = @intFromFloat(@round(value * @as(f32, @floatFromInt(1 << (mantissa_bits + exponent_bias - 1)))));
|
||||||
|
|
||||||
return mantissa;
|
return mantissa;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ const VkError = base.VkError;
|
|||||||
const INTERFACE_BLOB_PADDING = @sizeOf(F32x4);
|
const INTERFACE_BLOB_PADDING = @sizeOf(F32x4);
|
||||||
|
|
||||||
const ClipPlane = enum {
|
const ClipPlane = enum {
|
||||||
Left,
|
left,
|
||||||
Right,
|
right,
|
||||||
Bottom,
|
bottom,
|
||||||
Top,
|
top,
|
||||||
Near,
|
near,
|
||||||
Far,
|
far,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_CLIPPED_POLYGON_VERTICES = 16;
|
const MAX_CLIPPED_POLYGON_VERTICES = 16;
|
||||||
@@ -29,7 +29,7 @@ pub const ClippedLine = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ClippedPolygon = struct {
|
const ClippedPolygon = struct {
|
||||||
vertices: [MAX_CLIPPED_POLYGON_VERTICES]Vertex = undefined,
|
vertices: [MAX_CLIPPED_POLYGON_VERTICES]Vertex = std.mem.zeroes([MAX_CLIPPED_POLYGON_VERTICES]Vertex),
|
||||||
len: usize = 0,
|
len: usize = 0,
|
||||||
|
|
||||||
fn append(self: *@This(), vertex: Vertex) VkError!void {
|
fn append(self: *@This(), vertex: Vertex) VkError!void {
|
||||||
@@ -48,12 +48,12 @@ pub fn clipTriangle(allocator: std.mem.Allocator, v0: *const Vertex, v1: *const
|
|||||||
try polygon.append(v2.*);
|
try polygon.append(v2.*);
|
||||||
|
|
||||||
const planes = [_]ClipPlane{
|
const planes = [_]ClipPlane{
|
||||||
.Left,
|
.left,
|
||||||
.Right,
|
.right,
|
||||||
.Bottom,
|
.bottom,
|
||||||
.Top,
|
.top,
|
||||||
.Near,
|
.near,
|
||||||
.Far,
|
.far,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (planes) |plane| {
|
for (planes) |plane| {
|
||||||
@@ -72,12 +72,12 @@ pub fn clipLine(allocator: std.mem.Allocator, v0: *const Vertex, v1: *const Vert
|
|||||||
};
|
};
|
||||||
|
|
||||||
const planes = [_]ClipPlane{
|
const planes = [_]ClipPlane{
|
||||||
.Left,
|
.left,
|
||||||
.Right,
|
.right,
|
||||||
.Bottom,
|
.bottom,
|
||||||
.Top,
|
.top,
|
||||||
.Near,
|
.near,
|
||||||
.Far,
|
.far,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (planes) |plane| {
|
for (planes) |plane| {
|
||||||
@@ -131,12 +131,12 @@ pub fn viewportTransformVertex(viewport: vk.Viewport, vertex: *Vertex) void {
|
|||||||
fn clipDistance(position: F32x4, plane: ClipPlane) f32 {
|
fn clipDistance(position: F32x4, plane: ClipPlane) f32 {
|
||||||
const x, const y, const z, const w = position;
|
const x, const y, const z, const w = position;
|
||||||
return switch (plane) {
|
return switch (plane) {
|
||||||
.Left => x + w,
|
.left => x + w,
|
||||||
.Right => w - x,
|
.right => w - x,
|
||||||
.Bottom => y + w,
|
.bottom => y + w,
|
||||||
.Top => w - y,
|
.top => w - y,
|
||||||
.Near => z,
|
.near => z,
|
||||||
.Far => w - z,
|
.far => w - z,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ fn interpolateVertexForClipping(allocator: std.mem.Allocator, a: *const Vertex,
|
|||||||
.primitive_restart = false,
|
.primitive_restart = false,
|
||||||
.position = a.position + ((b.position - a.position) * zm.f32x4s(t)),
|
.position = a.position + ((b.position - a.position) * zm.f32x4s(t)),
|
||||||
.point_size = a.point_size + ((b.point_size - a.point_size) * t),
|
.point_size = a.point_size + ((b.point_size - a.point_size) * t),
|
||||||
.outputs = undefined,
|
.outputs = @splat(@splat(null)),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (&result.outputs) |*location| {
|
for (&result.outputs) |*location| {
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ const VertexInterpolationLocation = @import("rasterizer/common.zig").VertexInter
|
|||||||
|
|
||||||
const ExecutionDevice = @import("Device.zig");
|
const ExecutionDevice = @import("Device.zig");
|
||||||
const Renderer = @import("Renderer.zig");
|
const Renderer = @import("Renderer.zig");
|
||||||
const SoftImage = @import("../SoftImage.zig");
|
|
||||||
const SoftPipeline = @import("../SoftPipeline.zig");
|
const SoftPipeline = @import("../SoftPipeline.zig");
|
||||||
|
|
||||||
const VkError = base.VkError;
|
|
||||||
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
||||||
const INTERFACE_BLOB_PADDING = @sizeOf(zm.F32x4);
|
const INTERFACE_BLOB_PADDING = @sizeOf(zm.F32x4);
|
||||||
const PROCESSED_INPUTS_STACK_CAPACITY = 4096;
|
const PROCESSED_INPUTS_STACK_CAPACITY = 4096;
|
||||||
@@ -49,8 +47,10 @@ pub fn shaderInvocation(
|
|||||||
|
|
||||||
const io = draw_call.renderer.device.interface.io();
|
const io = draw_call.renderer.device.interface.io();
|
||||||
|
|
||||||
|
// SAFETY: fragment dispatch only occurs after a graphics pipeline has been bound.
|
||||||
const pipeline = draw_call.renderer.state.pipeline orelse return undefined;
|
const pipeline = draw_call.renderer.state.pipeline orelse return undefined;
|
||||||
|
|
||||||
|
// SAFETY: fragment dispatch only occurs when the bound pipeline has a fragment stage.
|
||||||
const shader = pipeline.stages.getPtr(.fragment) orelse return undefined;
|
const shader = pipeline.stages.getPtr(.fragment) orelse return undefined;
|
||||||
const runtime = &shader.runtimes[batch_id];
|
const runtime = &shader.runtimes[batch_id];
|
||||||
const mutex = &runtime.mutex;
|
const mutex = &runtime.mutex;
|
||||||
@@ -245,7 +245,7 @@ pub fn shaderInvocation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var depth: ?f32 = null;
|
var depth: ?f32 = null;
|
||||||
var frag_depth: f32 = undefined;
|
var frag_depth: f32 = 0;
|
||||||
if (rt.readBuiltIn(std.mem.asBytes(&frag_depth), .FragDepth)) {
|
if (rt.readBuiltIn(std.mem.asBytes(&frag_depth), .FragDepth)) {
|
||||||
depth = frag_depth;
|
depth = frag_depth;
|
||||||
} else |err| switch (err) {
|
} else |err| switch (err) {
|
||||||
@@ -254,7 +254,7 @@ pub fn shaderInvocation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sample_mask: ?vk.SampleMask = null;
|
var sample_mask: ?vk.SampleMask = null;
|
||||||
var frag_sample_mask: [1]vk.SampleMask = undefined;
|
var frag_sample_mask: [1]vk.SampleMask = .{0};
|
||||||
if (rt.readBuiltIn(std.mem.asBytes(&frag_sample_mask), .SampleMask)) {
|
if (rt.readBuiltIn(std.mem.asBytes(&frag_sample_mask), .SampleMask)) {
|
||||||
sample_mask = frag_sample_mask[0];
|
sample_mask = frag_sample_mask[0];
|
||||||
} else |err| switch (err) {
|
} else |err| switch (err) {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ pub fn processThenFragmentStage(renderer: *Renderer, allocator: std.mem.Allocato
|
|||||||
);
|
);
|
||||||
const color_attachment_subresource_size = renderTargetSubresourceSize(render_target, render_target_view, color_range.aspect_mask, color_range.base_mip_level);
|
const color_attachment_subresource_size = renderTargetSubresourceSize(render_target, render_target_view, color_range.aspect_mask, color_range.base_mip_level);
|
||||||
access.* = .{
|
access.* = .{
|
||||||
.mutex = undefined,
|
.mutex = .init,
|
||||||
.base = try render_target.mapAsSliceWithAddedOffset(u8, color_attachment_subresource_offset, color_attachment_subresource_size),
|
.base = try render_target.mapAsSliceWithAddedOffset(u8, color_attachment_subresource_offset, color_attachment_subresource_size),
|
||||||
.row_pitch = render_target.getRowPitchMemSizeForMipLevelWithFormat(color_range.aspect_mask, color_range.base_mip_level, color_format),
|
.row_pitch = render_target.getRowPitchMemSizeForMipLevelWithFormat(color_range.aspect_mask, color_range.base_mip_level, color_format),
|
||||||
.texel_size = base.format.texelSize(color_format),
|
.texel_size = base.format.texelSize(color_format),
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ const common = @import("common.zig");
|
|||||||
const fragment = @import("../fragment.zig");
|
const fragment = @import("../fragment.zig");
|
||||||
|
|
||||||
const Renderer = @import("../Renderer.zig");
|
const Renderer = @import("../Renderer.zig");
|
||||||
const SoftImage = @import("../../SoftImage.zig");
|
|
||||||
|
|
||||||
const VkError = base.VkError;
|
const VkError = base.VkError;
|
||||||
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
const SpvRuntimeError = spv.Runtime.RuntimeError;
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ pub fn clampDepthBias(bias: f32, clamp: f32) f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn scissorContainsPixel(scissor: vk.Rect2D, x: i32, y: i32) bool {
|
pub fn scissorContainsPixel(scissor: vk.Rect2D, x: i32, y: i32) bool {
|
||||||
const min_x: i64 = @as(i64, scissor.offset.x);
|
const min_x: i64 = scissor.offset.x;
|
||||||
const min_y: i64 = @as(i64, scissor.offset.y);
|
const min_y: i64 = scissor.offset.y;
|
||||||
|
|
||||||
const max_x: i64 = min_x + @as(i64, @intCast(scissor.extent.width));
|
const max_x: i64 = min_x + @as(i64, @intCast(scissor.extent.width));
|
||||||
const max_y: i64 = min_y + @as(i64, @intCast(scissor.extent.height));
|
const max_y: i64 = min_y + @as(i64, @intCast(scissor.extent.height));
|
||||||
|
|
||||||
const pixel_x: i64 = @as(i64, x);
|
const pixel_x: i64 = x;
|
||||||
const pixel_y: i64 = @as(i64, y);
|
const pixel_y: i64 = y;
|
||||||
|
|
||||||
return pixel_x >= min_x and
|
return pixel_x >= min_x and
|
||||||
pixel_x < max_x and
|
pixel_x < max_x and
|
||||||
@@ -69,8 +69,8 @@ pub fn scissorContainsPixel(scissor: vk.Rect2D, x: i32, y: i32) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn rectContainsPixel(rect: vk.Rect2D, x: usize, y: usize) bool {
|
pub fn rectContainsPixel(rect: vk.Rect2D, x: usize, y: usize) bool {
|
||||||
const min_x: i64 = @as(i64, rect.offset.x);
|
const min_x: i64 = rect.offset.x;
|
||||||
const min_y: i64 = @as(i64, rect.offset.y);
|
const min_y: i64 = rect.offset.y;
|
||||||
|
|
||||||
const max_x: i64 = min_x + @as(i64, @intCast(rect.extent.width));
|
const max_x: i64 = min_x + @as(i64, @intCast(rect.extent.width));
|
||||||
const max_y: i64 = min_y + @as(i64, @intCast(rect.extent.height));
|
const max_y: i64 = min_y + @as(i64, @intCast(rect.extent.height));
|
||||||
|
|||||||
@@ -485,6 +485,7 @@ inline fn run(data: RunData) !void {
|
|||||||
centroid_b2,
|
centroid_b2,
|
||||||
);
|
);
|
||||||
const derivative_inputs: ?fragment.DerivativeInputs = if (data.fragment_uses_derivatives) blk: {
|
const derivative_inputs: ?fragment.DerivativeInputs = if (data.fragment_uses_derivatives) blk: {
|
||||||
|
// SAFETY: both dx and dy are assigned below before derivatives is returned.
|
||||||
var derivatives: fragment.DerivativeInputs = undefined;
|
var derivatives: fragment.DerivativeInputs = undefined;
|
||||||
|
|
||||||
const p_dx = zm.f32x4(@as(f32, @floatFromInt(x)) + 1.5, @as(f32, @floatFromInt(y)) + 0.5, 0.0, 1.0);
|
const p_dx = zm.f32x4(@as(f32, @floatFromInt(x)) + 1.5, @as(f32, @floatFromInt(y)) + 0.5, 0.0, 1.0);
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ fn isConstantZero(rt: *spv.Runtime, result_word: spv.SpvWord) bool {
|
|||||||
const variant = rt.results[result_word].variant orelse return false;
|
const variant = rt.results[result_word].variant orelse return false;
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
.Constant => |constant| {
|
.Constant => |constant| {
|
||||||
var value: u32 = undefined;
|
var value: u32 = 0;
|
||||||
_ = constant.value.read(std.mem.asBytes(&value)) catch return false;
|
_ = constant.value.read(std.mem.asBytes(&value)) catch return false;
|
||||||
return value == 0;
|
return value == 0;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
@@ -25,6 +23,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Semap
|
|||||||
_ = info;
|
_ = info;
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the semaphore.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Buffe
|
|||||||
.usage = info.usage,
|
.usage = info.usage,
|
||||||
.memory = null,
|
.memory = null,
|
||||||
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the buffer.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Buffe
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.buffer = try NonDispatchable(Buffer).fromHandleObject(info.buffer),
|
.buffer = try NonDispatchable(Buffer).fromHandleObject(info.buffer),
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the buffer view.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
.format = info.format,
|
.format = info.format,
|
||||||
.offset = info.offset,
|
.offset = info.offset,
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ const QueryPool = @import("QueryPool.zig");
|
|||||||
const RenderPass = @import("RenderPass.zig");
|
const RenderPass = @import("RenderPass.zig");
|
||||||
|
|
||||||
const State = enum {
|
const State = enum {
|
||||||
Initial,
|
initial,
|
||||||
Recording,
|
recording,
|
||||||
Executable,
|
executable,
|
||||||
Pending,
|
pending,
|
||||||
Invalid,
|
invalid,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
@@ -100,13 +100,15 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Comma
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.pool = try NonDispatchable(CommandPool).fromHandleObject(info.command_pool),
|
.pool = try NonDispatchable(CommandPool).fromHandleObject(info.command_pool),
|
||||||
.state = .Initial,
|
.state = .initial,
|
||||||
.begin_info = null,
|
.begin_info = null,
|
||||||
.usage_flags = .{},
|
.usage_flags = .{},
|
||||||
.device_mask = 1,
|
.device_mask = 1,
|
||||||
.host_allocator = VulkanAllocator.from(allocator).cloneWithScope(.object),
|
.host_allocator = VulkanAllocator.from(allocator).cloneWithScope(.object),
|
||||||
.state_mutex = .init,
|
.state_mutex = .init,
|
||||||
|
// SAFETY: the backend assigns both tables before returning the command buffer.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
|
// SAFETY: the backend assigns both tables before returning the command buffer.
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -128,9 +130,9 @@ pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError!void {
|
pub fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError!void {
|
||||||
const implicitly_reset = self.state == .Executable or self.state == .Invalid;
|
const implicitly_reset = self.state == .executable or self.state == .invalid;
|
||||||
|
|
||||||
self.transitionState(.Recording, &.{ .Initial, .Executable, .Invalid }) catch return VkError.ValidationFailed;
|
self.transitionState(.recording, &.{ .initial, .executable, .invalid }) catch return VkError.ValidationFailed;
|
||||||
if (implicitly_reset) {
|
if (implicitly_reset) {
|
||||||
try self.dispatch_table.reset(self, .{});
|
try self.dispatch_table.reset(self, .{});
|
||||||
self.begin_info = null;
|
self.begin_info = null;
|
||||||
@@ -143,7 +145,7 @@ pub fn begin(self: *Self, info: *const vk.CommandBufferBeginInfo) VkError!void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn end(self: *Self) VkError!void {
|
pub fn end(self: *Self) VkError!void {
|
||||||
self.transitionState(.Executable, &.{.Recording}) catch return VkError.ValidationFailed;
|
self.transitionState(.executable, &.{.recording}) catch return VkError.ValidationFailed;
|
||||||
try self.dispatch_table.end(self);
|
try self.dispatch_table.end(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +158,7 @@ pub fn reset(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn resetFromPool(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void {
|
pub fn resetFromPool(self: *Self, flags: vk.CommandBufferResetFlags) VkError!void {
|
||||||
self.transitionState(.Initial, &.{ .Initial, .Recording, .Executable, .Invalid }) catch return VkError.ValidationFailed;
|
self.transitionState(.initial, &.{ .initial, .recording, .executable, .invalid }) catch return VkError.ValidationFailed;
|
||||||
try self.dispatch_table.reset(self, flags);
|
try self.dispatch_table.reset(self, flags);
|
||||||
self.begin_info = null;
|
self.begin_info = null;
|
||||||
self.usage_flags = .{};
|
self.usage_flags = .{};
|
||||||
@@ -165,18 +167,18 @@ pub fn resetFromPool(self: *Self, flags: vk.CommandBufferResetFlags) VkError!voi
|
|||||||
|
|
||||||
pub fn submit(self: *Self) VkError!void {
|
pub fn submit(self: *Self) VkError!void {
|
||||||
if (!self.usage_flags.simultaneous_use_bit) {
|
if (!self.usage_flags.simultaneous_use_bit) {
|
||||||
self.transitionState(.Pending, &.{.Executable}) catch return VkError.ValidationFailed;
|
self.transitionState(.pending, &.{.executable}) catch return VkError.ValidationFailed;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.transitionState(.Pending, &.{ .Pending, .Executable }) catch return VkError.ValidationFailed;
|
self.transitionState(.pending, &.{ .pending, .executable }) catch return VkError.ValidationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish(self: *Self) VkError!void {
|
pub fn finish(self: *Self) VkError!void {
|
||||||
if (self.usage_flags.one_time_submit_bit) {
|
if (self.usage_flags.one_time_submit_bit) {
|
||||||
self.transitionState(.Invalid, &.{.Pending}) catch return VkError.ValidationFailed;
|
self.transitionState(.invalid, &.{.pending}) catch return VkError.ValidationFailed;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.transitionState(.Executable, &.{.Pending}) catch return VkError.ValidationFailed;
|
self.transitionState(.executable, &.{.pending}) catch return VkError.ValidationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commands ====================================================================================================
|
// Commands ====================================================================================================
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Comma
|
|||||||
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
||||||
.buffers = std.ArrayList(*Dispatchable(CommandBuffer)).initCapacity(allocator, BUFFER_POOL_BASE_CAPACITY) catch return VkError.OutOfHostMemory,
|
.buffers = std.ArrayList(*Dispatchable(CommandBuffer)).initCapacity(allocator, BUFFER_POOL_BASE_CAPACITY) catch return VkError.OutOfHostMemory,
|
||||||
.first_free_buffer_index = 0,
|
.first_free_buffer_index = 0,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the command pool.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -112,6 +113,6 @@ pub fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
|
|||||||
self.first_free_buffer_index = 0;
|
self.first_free_buffer_index = 0;
|
||||||
|
|
||||||
for (self.buffers.items) |dis_cmd| {
|
for (self.buffers.items) |dis_cmd| {
|
||||||
_ = dis_cmd.object.resetFromPool(.{ .release_resources_bit = flags.release_resources_bit }) catch {};
|
_ = dis_cmd.object.resetFromPool(.{ .release_resources_bit = flags.release_resources_bit }) catch @panic("Caught an error while handling an error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ const std = @import("std");
|
|||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.flags = info.flags,
|
.flags = info.flags,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the descriptor pool.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
@@ -29,6 +27,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, layout: *DescriptorSe
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.layout = layout,
|
.layout = layout,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the descriptor set.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const BindingLayout = struct {
|
|||||||
/// This slice points to an array located after the binding layouts array
|
/// This slice points to an array located after the binding layouts array
|
||||||
immutable_samplers: []const *const Sampler,
|
immutable_samplers: []const *const Sampler,
|
||||||
|
|
||||||
driver_data: *anyopaque,
|
driver_data: ?*anyopaque,
|
||||||
};
|
};
|
||||||
|
|
||||||
owner: *Device,
|
owner: *Device,
|
||||||
@@ -77,7 +77,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
|||||||
.array_size = 0,
|
.array_size = 0,
|
||||||
.dynamic_index = 0,
|
.dynamic_index = 0,
|
||||||
.immutable_samplers = &.{},
|
.immutable_samplers = &.{},
|
||||||
.driver_data = undefined,
|
.driver_data = null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
|||||||
.array_size = descriptor_count,
|
.array_size = descriptor_count,
|
||||||
.dynamic_index = dynamic_index,
|
.dynamic_index = dynamic_index,
|
||||||
.immutable_samplers = binding_immutable_samplers,
|
.immutable_samplers = binding_immutable_samplers,
|
||||||
.driver_data = undefined,
|
.driver_data = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
stages = stages.merge(binding_info.stage_flags);
|
stages = stages.merge(binding_info.stage_flags);
|
||||||
@@ -134,6 +134,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
|||||||
.dynamic_descriptor_count = dynamic_descriptor_count,
|
.dynamic_descriptor_count = dynamic_descriptor_count,
|
||||||
.stages = stages,
|
.stages = stages,
|
||||||
.ref_count = std.atomic.Value(usize).init(1),
|
.ref_count = std.atomic.Value(usize).init(1),
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the descriptor set layout.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const lib = @import("lib.zig");
|
|||||||
const config = lib.config;
|
const config = lib.config;
|
||||||
|
|
||||||
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
|
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
|
||||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
|
||||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
|
|
||||||
@@ -16,7 +15,6 @@ const Buffer = @import("Buffer.zig");
|
|||||||
const BufferView = @import("BufferView.zig");
|
const BufferView = @import("BufferView.zig");
|
||||||
const CommandPool = @import("CommandPool.zig");
|
const CommandPool = @import("CommandPool.zig");
|
||||||
const DescriptorPool = @import("DescriptorPool.zig");
|
const DescriptorPool = @import("DescriptorPool.zig");
|
||||||
const DescriptorSet = @import("DescriptorSet.zig");
|
|
||||||
const DescriptorSetLayout = @import("DescriptorSetLayout.zig");
|
const DescriptorSetLayout = @import("DescriptorSetLayout.zig");
|
||||||
const DeviceMemory = @import("DeviceMemory.zig");
|
const DeviceMemory = @import("DeviceMemory.zig");
|
||||||
const Event = @import("Event.zig");
|
const Event = @import("Event.zig");
|
||||||
@@ -34,7 +32,6 @@ const Sampler = @import("Sampler.zig");
|
|||||||
const ShaderModule = @import("ShaderModule.zig");
|
const ShaderModule = @import("ShaderModule.zig");
|
||||||
|
|
||||||
const SurfaceKHR = @import("wsi/SurfaceKHR.zig");
|
const SurfaceKHR = @import("wsi/SurfaceKHR.zig");
|
||||||
const SwapchainKHR = @import("wsi/SwapchainKHR.zig");
|
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .device;
|
pub const ObjectType: vk.ObjectType = .device;
|
||||||
@@ -120,7 +117,9 @@ pub fn init(allocator: std.mem.Allocator, instance: *Instance, physical_device:
|
|||||||
.enabled_khr_swapchain = enabled_khr_swapchain,
|
.enabled_khr_swapchain = enabled_khr_swapchain,
|
||||||
.enabled_khr_device_group = enabled_khr_device_group,
|
.enabled_khr_device_group = enabled_khr_device_group,
|
||||||
.device_allocator = if (config.device_debug_allocator) .init else .{},
|
.device_allocator = if (config.device_debug_allocator) .init else .{},
|
||||||
|
// SAFETY: the backend assigns both tables before returning the device.
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
|
// SAFETY: the backend assigns both tables before returning the device.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -141,7 +140,7 @@ pub fn createQueues(self: *Self, allocator: std.mem.Allocator, info: *const vk.D
|
|||||||
}
|
}
|
||||||
|
|
||||||
const queue = try self.vtable.createQueue(allocator, self, queue_info.queue_family_index, @intCast(family_ptr.items.len), queue_info.flags);
|
const queue = try self.vtable.createQueue(allocator, self, queue_info.queue_family_index, @intCast(family_ptr.items.len), queue_info.flags);
|
||||||
errdefer self.vtable.destroyQueue(queue, allocator) catch {};
|
errdefer self.vtable.destroyQueue(queue, allocator) catch @panic("Caught an error while handling an error");
|
||||||
|
|
||||||
const dispatchable_queue = try Dispatchable(Queue).wrap(allocator, queue);
|
const dispatchable_queue = try Dispatchable(Queue).wrap(allocator, queue);
|
||||||
errdefer dispatchable_queue.destroy(allocator);
|
errdefer dispatchable_queue.destroy(allocator);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ pub fn init(device: *Device, size: vk.DeviceSize, memory_type_index: u32) VkErro
|
|||||||
.size = size,
|
.size = size,
|
||||||
.memory_type_index = memory_type_index,
|
.memory_type_index = memory_type_index,
|
||||||
.is_mapped = false,
|
.is_mapped = false,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning device memory.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
|
|
||||||
const Device = @import("Device.zig");
|
const Device = @import("Device.zig");
|
||||||
@@ -27,6 +25,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Event
|
|||||||
_ = info;
|
_ = info;
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the event.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Fence
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.flags = info.flags,
|
.flags = info.flags,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the fence.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Frame
|
|||||||
.height = @intCast(info.height),
|
.height = @intCast(info.height),
|
||||||
.layers = @intCast(info.layers),
|
.layers = @intCast(info.layers),
|
||||||
.attachments = attachments,
|
.attachments = attachments,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the framebuffer.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Image
|
|||||||
.memory = null,
|
.memory = null,
|
||||||
.memory_offset = 0,
|
.memory_offset = 0,
|
||||||
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the image.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const lib = @import("lib.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||||
@@ -33,6 +32,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Image
|
|||||||
.format = info.format,
|
.format = info.format,
|
||||||
.components = info.components,
|
.components = info.components,
|
||||||
.subresource_range = info.subresource_range,
|
.subresource_range = info.subresource_range,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the image view.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const config = @import("lib.zig").config;
|
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
const drm = @import("drm.zig");
|
const drm = @import("drm.zig");
|
||||||
const lib = @import("lib.zig");
|
const lib = @import("lib.zig");
|
||||||
@@ -23,12 +22,6 @@ comptime {
|
|||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .instance;
|
pub const ObjectType: vk.ObjectType = .instance;
|
||||||
|
|
||||||
const DeviceAllocator = struct {
|
|
||||||
pub inline fn allocator(_: @This()) std.mem.Allocator {
|
|
||||||
return std.heap.smp_allocator;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Dummy
|
/// Dummy
|
||||||
pub const EXTENSIONS = [_]vk.ExtensionProperties{};
|
pub const EXTENSIONS = [_]vk.ExtensionProperties{};
|
||||||
|
|
||||||
@@ -52,7 +45,9 @@ pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) V
|
|||||||
_ = infos;
|
_ = infos;
|
||||||
return .{
|
return .{
|
||||||
.physical_devices = .empty,
|
.physical_devices = .empty,
|
||||||
|
// SAFETY: the backend assigns both tables before returning the instance.
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
|
// SAFETY: the backend assigns both tables before returning the instance.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,25 +38,26 @@ pub fn init(allocator: std.mem.Allocator, instance: *Instance) VkError!Self {
|
|||||||
_ = allocator;
|
_ = allocator;
|
||||||
return .{
|
return .{
|
||||||
.props = .{
|
.props = .{
|
||||||
.api_version = undefined,
|
.api_version = 0,
|
||||||
.driver_version = undefined,
|
.driver_version = 0,
|
||||||
.vendor_id = root.VULKAN_VENDOR_ID,
|
.vendor_id = root.VULKAN_VENDOR_ID,
|
||||||
.device_id = undefined,
|
.device_id = 0,
|
||||||
.device_type = undefined,
|
.device_type = .other,
|
||||||
.device_name = @as([vk.MAX_PHYSICAL_DEVICE_NAME_SIZE]u8, @splat(0)),
|
.device_name = @as([vk.MAX_PHYSICAL_DEVICE_NAME_SIZE]u8, @splat(0)),
|
||||||
.pipeline_cache_uuid = undefined,
|
.pipeline_cache_uuid = @splat(0),
|
||||||
.limits = std.mem.zeroInit(vk.PhysicalDeviceLimits, .{}),
|
.limits = std.mem.zeroInit(vk.PhysicalDeviceLimits, .{}),
|
||||||
.sparse_properties = undefined,
|
.sparse_properties = std.mem.zeroes(vk.PhysicalDeviceSparseProperties),
|
||||||
},
|
},
|
||||||
.mem_props = .{
|
.mem_props = .{
|
||||||
.memory_type_count = 0,
|
.memory_type_count = 0,
|
||||||
.memory_types = undefined,
|
.memory_types = @splat(.{ .heap_index = 0 }),
|
||||||
.memory_heap_count = 0,
|
.memory_heap_count = 0,
|
||||||
.memory_heaps = undefined,
|
.memory_heaps = @splat(.{ .size = 0 }),
|
||||||
},
|
},
|
||||||
.queue_family_props = .empty,
|
.queue_family_props = .empty,
|
||||||
.features = .{},
|
.features = .{},
|
||||||
.instance = instance,
|
.instance = instance,
|
||||||
|
// SAFETY: the backend assigns the dispatch table before returning the physical device.
|
||||||
.dispatch_table = undefined,
|
.dispatch_table = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ pub fn initCompute(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipel
|
|||||||
|
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the compute pipeline.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
.bind_point = .compute,
|
.bind_point = .compute,
|
||||||
.stages = info.stage.stage,
|
.stages = info.stage.stage,
|
||||||
@@ -132,6 +133,7 @@ pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipe
|
|||||||
|
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the graphics pipeline.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
.bind_point = .graphics,
|
.bind_point = .graphics,
|
||||||
.stages = stages,
|
.stages = stages,
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
|
||||||
|
|
||||||
const VkError = @import("error_set.zig").VkError;
|
const VkError = @import("error_set.zig").VkError;
|
||||||
const root = @import("lib.zig");
|
const root = @import("lib.zig");
|
||||||
|
|
||||||
@@ -42,6 +40,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Pipel
|
|||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.data = data,
|
.data = data,
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the pipeline cache.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Pipel
|
|||||||
.set_layouts = [_]?*DescriptorSetLayout{null} ** lib.VULKAN_MAX_DESCRIPTOR_SETS,
|
.set_layouts = [_]?*DescriptorSetLayout{null} ** lib.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||||
.dynamic_descriptor_offsets = [_]usize{0} ** lib.VULKAN_MAX_DESCRIPTOR_SETS,
|
.dynamic_descriptor_offsets = [_]usize{0} ** lib.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||||
.push_ranges_count = info.push_constant_range_count,
|
.push_ranges_count = info.push_constant_range_count,
|
||||||
.push_ranges = undefined,
|
.push_ranges = @splat(std.mem.zeroes(vk.PushConstantRange)),
|
||||||
.ref_count = std.atomic.Value(usize).init(1),
|
.ref_count = std.atomic.Value(usize).init(1),
|
||||||
|
// SAFETY: the backend assigns the vtable before returning the pipeline layout.
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user