fixing linter errors
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
@@ -25,6 +23,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Semap
|
||||
_ = info;
|
||||
return .{
|
||||
.owner = device,
|
||||
// SAFETY: the backend assigns the vtable before returning the semaphore.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Buffe
|
||||
.usage = info.usage,
|
||||
.memory = null,
|
||||
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
||||
// SAFETY: the backend assigns the vtable before returning the buffer.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Buffe
|
||||
return .{
|
||||
.owner = device,
|
||||
.buffer = try NonDispatchable(Buffer).fromHandleObject(info.buffer),
|
||||
// SAFETY: the backend assigns the vtable before returning the buffer view.
|
||||
.vtable = undefined,
|
||||
.format = info.format,
|
||||
.offset = info.offset,
|
||||
|
||||
@@ -18,11 +18,11 @@ const QueryPool = @import("QueryPool.zig");
|
||||
const RenderPass = @import("RenderPass.zig");
|
||||
|
||||
const State = enum {
|
||||
Initial,
|
||||
Recording,
|
||||
Executable,
|
||||
Pending,
|
||||
Invalid,
|
||||
initial,
|
||||
recording,
|
||||
executable,
|
||||
pending,
|
||||
invalid,
|
||||
};
|
||||
|
||||
const Self = @This();
|
||||
@@ -100,13 +100,15 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Comma
|
||||
return .{
|
||||
.owner = device,
|
||||
.pool = try NonDispatchable(CommandPool).fromHandleObject(info.command_pool),
|
||||
.state = .Initial,
|
||||
.state = .initial,
|
||||
.begin_info = null,
|
||||
.usage_flags = .{},
|
||||
.device_mask = 1,
|
||||
.host_allocator = VulkanAllocator.from(allocator).cloneWithScope(.object),
|
||||
.state_mutex = .init,
|
||||
// SAFETY: the backend assigns both tables before returning the command buffer.
|
||||
.vtable = undefined,
|
||||
// SAFETY: the backend assigns both tables before returning the command buffer.
|
||||
.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 {
|
||||
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) {
|
||||
try self.dispatch_table.reset(self, .{});
|
||||
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 {
|
||||
self.transitionState(.Executable, &.{.Recording}) catch return VkError.ValidationFailed;
|
||||
self.transitionState(.executable, &.{.recording}) catch return VkError.ValidationFailed;
|
||||
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 {
|
||||
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);
|
||||
self.begin_info = null;
|
||||
self.usage_flags = .{};
|
||||
@@ -165,18 +167,18 @@ pub fn resetFromPool(self: *Self, flags: vk.CommandBufferResetFlags) VkError!voi
|
||||
|
||||
pub fn submit(self: *Self) VkError!void {
|
||||
if (!self.usage_flags.simultaneous_use_bit) {
|
||||
self.transitionState(.Pending, &.{.Executable}) catch return VkError.ValidationFailed;
|
||||
self.transitionState(.pending, &.{.executable}) catch return VkError.ValidationFailed;
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
self.transitionState(.Executable, &.{.Pending}) catch return VkError.ValidationFailed;
|
||||
self.transitionState(.executable, &.{.pending}) catch return VkError.ValidationFailed;
|
||||
}
|
||||
|
||||
// Commands ====================================================================================================
|
||||
|
||||
@@ -44,6 +44,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Comma
|
||||
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
||||
.buffers = std.ArrayList(*Dispatchable(CommandBuffer)).initCapacity(allocator, BUFFER_POOL_BASE_CAPACITY) catch return VkError.OutOfHostMemory,
|
||||
.first_free_buffer_index = 0,
|
||||
// SAFETY: the backend assigns the vtable before returning the command pool.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
@@ -112,6 +113,6 @@ pub fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
|
||||
self.first_free_buffer_index = 0;
|
||||
|
||||
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 VkError = @import("error_set.zig").VkError;
|
||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
|
||||
@@ -29,6 +28,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
||||
return .{
|
||||
.owner = device,
|
||||
.flags = info.flags,
|
||||
// SAFETY: the backend assigns the vtable before returning the descriptor pool.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
@@ -29,6 +27,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, layout: *DescriptorSe
|
||||
return .{
|
||||
.owner = device,
|
||||
.layout = layout,
|
||||
// SAFETY: the backend assigns the vtable before returning the descriptor set.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const BindingLayout = struct {
|
||||
/// This slice points to an array located after the binding layouts array
|
||||
immutable_samplers: []const *const Sampler,
|
||||
|
||||
driver_data: *anyopaque,
|
||||
driver_data: ?*anyopaque,
|
||||
};
|
||||
|
||||
owner: *Device,
|
||||
@@ -77,7 +77,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
|
||||
.array_size = 0,
|
||||
.dynamic_index = 0,
|
||||
.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,
|
||||
.dynamic_index = dynamic_index,
|
||||
.immutable_samplers = binding_immutable_samplers,
|
||||
.driver_data = undefined,
|
||||
.driver_data = null,
|
||||
};
|
||||
|
||||
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,
|
||||
.stages = stages,
|
||||
.ref_count = std.atomic.Value(usize).init(1),
|
||||
// SAFETY: the backend assigns the vtable before returning the descriptor set layout.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ const lib = @import("lib.zig");
|
||||
const config = lib.config;
|
||||
|
||||
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
|
||||
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||
const VulkanAllocator = @import("VulkanAllocator.zig");
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
@@ -16,7 +15,6 @@ const Buffer = @import("Buffer.zig");
|
||||
const BufferView = @import("BufferView.zig");
|
||||
const CommandPool = @import("CommandPool.zig");
|
||||
const DescriptorPool = @import("DescriptorPool.zig");
|
||||
const DescriptorSet = @import("DescriptorSet.zig");
|
||||
const DescriptorSetLayout = @import("DescriptorSetLayout.zig");
|
||||
const DeviceMemory = @import("DeviceMemory.zig");
|
||||
const Event = @import("Event.zig");
|
||||
@@ -34,7 +32,6 @@ const Sampler = @import("Sampler.zig");
|
||||
const ShaderModule = @import("ShaderModule.zig");
|
||||
|
||||
const SurfaceKHR = @import("wsi/SurfaceKHR.zig");
|
||||
const SwapchainKHR = @import("wsi/SwapchainKHR.zig");
|
||||
|
||||
const Self = @This();
|
||||
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_device_group = enabled_khr_device_group,
|
||||
.device_allocator = if (config.device_debug_allocator) .init else .{},
|
||||
// SAFETY: the backend assigns both tables before returning the device.
|
||||
.dispatch_table = undefined,
|
||||
// SAFETY: the backend assigns both tables before returning the device.
|
||||
.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);
|
||||
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);
|
||||
errdefer dispatchable_queue.destroy(allocator);
|
||||
|
||||
@@ -28,6 +28,7 @@ pub fn init(device: *Device, size: vk.DeviceSize, memory_type_index: u32) VkErro
|
||||
.size = size,
|
||||
.memory_type_index = memory_type_index,
|
||||
.is_mapped = false,
|
||||
// SAFETY: the backend assigns the vtable before returning device memory.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
@@ -27,6 +25,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Event
|
||||
_ = info;
|
||||
return .{
|
||||
.owner = device,
|
||||
// SAFETY: the backend assigns the vtable before returning the event.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Fence
|
||||
return .{
|
||||
.owner = device,
|
||||
.flags = info.flags,
|
||||
// SAFETY: the backend assigns the vtable before returning the fence.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Frame
|
||||
.height = @intCast(info.height),
|
||||
.layers = @intCast(info.layers),
|
||||
.attachments = attachments,
|
||||
// SAFETY: the backend assigns the vtable before returning the framebuffer.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Image
|
||||
.memory = null,
|
||||
.memory_offset = 0,
|
||||
.allowed_memory_types = std.bit_set.IntegerBitSet(32).initFull(),
|
||||
// SAFETY: the backend assigns the vtable before returning the image.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
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,
|
||||
.components = info.components,
|
||||
.subresource_range = info.subresource_range,
|
||||
// SAFETY: the backend assigns the vtable before returning the image view.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const vk = @import("vulkan");
|
||||
const config = @import("lib.zig").config;
|
||||
const utils = @import("utils.zig");
|
||||
const drm = @import("drm.zig");
|
||||
const lib = @import("lib.zig");
|
||||
@@ -23,12 +22,6 @@ comptime {
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .instance;
|
||||
|
||||
const DeviceAllocator = struct {
|
||||
pub inline fn allocator(_: @This()) std.mem.Allocator {
|
||||
return std.heap.smp_allocator;
|
||||
}
|
||||
};
|
||||
|
||||
/// Dummy
|
||||
pub const EXTENSIONS = [_]vk.ExtensionProperties{};
|
||||
|
||||
@@ -52,7 +45,9 @@ pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) V
|
||||
_ = infos;
|
||||
return .{
|
||||
.physical_devices = .empty,
|
||||
// SAFETY: the backend assigns both tables before returning the instance.
|
||||
.dispatch_table = undefined,
|
||||
// SAFETY: the backend assigns both tables before returning the instance.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,25 +38,26 @@ pub fn init(allocator: std.mem.Allocator, instance: *Instance) VkError!Self {
|
||||
_ = allocator;
|
||||
return .{
|
||||
.props = .{
|
||||
.api_version = undefined,
|
||||
.driver_version = undefined,
|
||||
.api_version = 0,
|
||||
.driver_version = 0,
|
||||
.vendor_id = root.VULKAN_VENDOR_ID,
|
||||
.device_id = undefined,
|
||||
.device_type = undefined,
|
||||
.device_id = 0,
|
||||
.device_type = .other,
|
||||
.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, .{}),
|
||||
.sparse_properties = undefined,
|
||||
.sparse_properties = std.mem.zeroes(vk.PhysicalDeviceSparseProperties),
|
||||
},
|
||||
.mem_props = .{
|
||||
.memory_type_count = 0,
|
||||
.memory_types = undefined,
|
||||
.memory_types = @splat(.{ .heap_index = 0 }),
|
||||
.memory_heap_count = 0,
|
||||
.memory_heaps = undefined,
|
||||
.memory_heaps = @splat(.{ .size = 0 }),
|
||||
},
|
||||
.queue_family_props = .empty,
|
||||
.features = .{},
|
||||
.instance = instance,
|
||||
// SAFETY: the backend assigns the dispatch table before returning the physical device.
|
||||
.dispatch_table = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ pub fn initCompute(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipel
|
||||
|
||||
return .{
|
||||
.owner = device,
|
||||
// SAFETY: the backend assigns the vtable before returning the compute pipeline.
|
||||
.vtable = undefined,
|
||||
.bind_point = .compute,
|
||||
.stages = info.stage.stage,
|
||||
@@ -132,6 +133,7 @@ pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipe
|
||||
|
||||
return .{
|
||||
.owner = device,
|
||||
// SAFETY: the backend assigns the vtable before returning the graphics pipeline.
|
||||
.vtable = undefined,
|
||||
.bind_point = .graphics,
|
||||
.stages = stages,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
const root = @import("lib.zig");
|
||||
|
||||
@@ -42,6 +40,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Pipel
|
||||
return .{
|
||||
.owner = device,
|
||||
.data = data,
|
||||
// SAFETY: the backend assigns the vtable before returning the pipeline cache.
|
||||
.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,
|
||||
.dynamic_descriptor_offsets = [_]usize{0} ** lib.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||
.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),
|
||||
// SAFETY: the backend assigns the vtable before returning the pipeline layout.
|
||||
.vtable = undefined,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
@@ -37,6 +35,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Query
|
||||
.owner = device,
|
||||
.query_type = info.query_type,
|
||||
.queries = queries,
|
||||
// SAFETY: the backend assigns the vtable before returning the query pool.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ pub fn init(allocator: std.mem.Allocator, device: *Device, index: u32, family_in
|
||||
.index = index,
|
||||
.flags = flags,
|
||||
.host_allocator = VulkanAllocator.from(allocator).clone(),
|
||||
// SAFETY: the backend assigns the dispatch table before returning the queue.
|
||||
.dispatch_table = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Rende
|
||||
.owner = device,
|
||||
.attachments = attachments,
|
||||
.subpasses = subpasses,
|
||||
// SAFETY: the backend assigns the vtable before returning the render pass.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
const Device = @import("Device.zig");
|
||||
@@ -48,6 +46,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Sampl
|
||||
.max_lod = info.max_lod,
|
||||
.border_color = info.border_color,
|
||||
.unnormalized_coordinates = info.unnormalized_coordinates,
|
||||
// SAFETY: the backend assigns the vtable before returning the sampler.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const NonDispatchable = @import("NonDispatchable.zig");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
@@ -24,6 +21,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Shade
|
||||
_ = info;
|
||||
return .{
|
||||
.owner = device,
|
||||
// SAFETY: the backend assigns the vtable before returning the shader module.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ const SpinMutex = @import("SpinMutex.zig");
|
||||
|
||||
var mutex: SpinMutex = .{};
|
||||
var child_allocator: std.mem.Allocator = if (builtin.link_libc) std.heap.c_allocator else std.heap.smp_allocator;
|
||||
var fallback_host_allocator_context: u8 = 0;
|
||||
|
||||
pub const fallback_host_allocator: Allocator = .{
|
||||
.ptr = undefined,
|
||||
.ptr = &fallback_host_allocator_context,
|
||||
.vtable = &vtable,
|
||||
};
|
||||
|
||||
|
||||
@@ -177,11 +177,11 @@ pub inline fn blockHeight(format: vk.Format) usize {
|
||||
}
|
||||
|
||||
pub inline fn blockCountX(format: vk.Format, width: usize) usize {
|
||||
return std.math.divCeil(usize, width, blockWidth(format)) catch unreachable;
|
||||
return std.math.divCeil(usize, width, blockWidth(format)) catch @panic("Division failed");
|
||||
}
|
||||
|
||||
pub inline fn blockCountY(format: vk.Format, height: usize) usize {
|
||||
return std.math.divCeil(usize, height, blockHeight(format)) catch unreachable;
|
||||
return std.math.divCeil(usize, height, blockHeight(format)) catch @panic("Division failed");
|
||||
}
|
||||
|
||||
pub inline fn componentCount(format: vk.Format) usize {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Here lies the documentation of the common internal API that Ape backends need to implement
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const vk = @import("vulkan");
|
||||
pub const c = @import("base_c");
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ const has_wayland = switch (builtin.os.tag) {
|
||||
else => false,
|
||||
};
|
||||
|
||||
pub const WaylandSurfaceKHR = if (has_wayland) @import("wsi/WaylandSurfaceKHR.zig") else undefined;
|
||||
pub const WaylandSurfaceKHR = if (has_wayland) @import("wsi/WaylandSurfaceKHR.zig") else null;
|
||||
|
||||
inline fn entryPointBeginLogTrace(comptime scope: @EnumLiteral()) void {
|
||||
std.log.scoped(scope).debug("Calling {s}...", .{@tagName(scope)});
|
||||
@@ -358,6 +358,7 @@ pub export fn apeCreateInstance(info: *const vk.InstanceCreateInfo, callbacks: ?
|
||||
const allocator = VulkanAllocator.init(callbacks, .instance).allocator();
|
||||
Instance.validateCreateInfo(info) catch |err| return toVkResult(err);
|
||||
|
||||
// SAFETY: will be proprely initiated when not in test
|
||||
var instance: *lib.Instance = undefined;
|
||||
if (!builtin.is_test) {
|
||||
// Will call impl instead of interface as `root` refs the impl module
|
||||
@@ -365,12 +366,12 @@ pub export fn apeCreateInstance(info: *const vk.InstanceCreateInfo, callbacks: ?
|
||||
}
|
||||
|
||||
instance.requestPhysicalDevices(allocator) catch |err| {
|
||||
if (!builtin.is_test) instance.deinit(allocator) catch {};
|
||||
if (!builtin.is_test) instance.deinit(allocator) catch @panic("Caught an error while handling an error");
|
||||
return toVkResult(err);
|
||||
};
|
||||
|
||||
const dispatchable = Dispatchable(Instance).wrap(allocator, instance) catch |err| {
|
||||
if (!builtin.is_test) instance.deinit(allocator) catch {};
|
||||
if (!builtin.is_test) instance.deinit(allocator) catch @panic("Caught an error while handling an error");
|
||||
return toVkResult(err);
|
||||
};
|
||||
p_instance.* = dispatchable.toVkHandle(vk.Instance);
|
||||
@@ -489,7 +490,7 @@ pub export fn apeCreateDevice(p_physical_device: vk.PhysicalDevice, info: *const
|
||||
|
||||
const device = physical_device.createDevice(allocator, info) catch |err| return toVkResult(err);
|
||||
const dispatchable = Dispatchable(Device).wrap(allocator, device) catch |err| {
|
||||
device.destroy(allocator) catch {};
|
||||
device.destroy(allocator) catch @panic("Caught an error while handling an error");
|
||||
return toVkResult(err);
|
||||
};
|
||||
p_device.* = dispatchable.toVkHandle(vk.Device);
|
||||
|
||||
+10
-10
@@ -56,7 +56,7 @@ pub fn log(comptime level: std.log.Level, comptime scope: @EnumLiteral(), compti
|
||||
.warn, .err => stderr_file,
|
||||
};
|
||||
|
||||
file.lock(io, .exclusive) catch {};
|
||||
file.lock(io, .exclusive) catch @panic("Caught an error while handling an error");
|
||||
defer file.unlock(io);
|
||||
|
||||
const now = std.Io.Timestamp.now(io, .real).toMicroseconds();
|
||||
@@ -69,7 +69,7 @@ pub fn log(comptime level: std.log.Level, comptime scope: @EnumLiteral(), compti
|
||||
|
||||
var fmt_buffer = std.mem.zeroes([4096]u8);
|
||||
var fmt_writer = std.Io.Writer.fixed(&fmt_buffer);
|
||||
fmt_writer.print(format ++ "\n", args) catch {};
|
||||
fmt_writer.print(format ++ "\n", args) catch @panic("Caught an error while handling an error");
|
||||
fmt_writer.flush() catch return;
|
||||
|
||||
mutex.lock(io) catch return;
|
||||
@@ -86,31 +86,31 @@ pub fn log(comptime level: std.log.Level, comptime scope: @EnumLiteral(), compti
|
||||
.mode = std.Io.Terminal.Mode.detect(io, file, false, false) catch return,
|
||||
};
|
||||
|
||||
term.setColor(.magenta) catch {};
|
||||
term.setColor(.magenta) catch @panic("Caught an error while handling an error");
|
||||
writer.writeAll("[ApeDriver") catch continue;
|
||||
if (!builtin.is_test) {
|
||||
term.setColor(.cyan) catch {};
|
||||
term.setColor(.cyan) catch @panic("Caught an error while handling an error");
|
||||
writer.print(" {s} ", .{root.DRIVER_NAME}) catch continue;
|
||||
}
|
||||
term.setColor(.yellow) catch {};
|
||||
term.setColor(.yellow) catch @panic("Caught an error while handling an error");
|
||||
writer.print("{d}:{d}:{d}.{d:0>3}.{d:0>3}", .{ now_hour, now_min, now_sec, now_ms, now_us }) catch continue;
|
||||
term.setColor(.magenta) catch {};
|
||||
term.setColor(.magenta) catch @panic("Caught an error while handling an error");
|
||||
writer.writeAll("]") catch continue;
|
||||
|
||||
term.setColor(.cyan) catch {};
|
||||
term.setColor(.cyan) catch @panic("Caught an error while handling an error");
|
||||
writer.print("[Thread {d: >8}]", .{std.Thread.getCurrentId()}) catch continue;
|
||||
|
||||
term.setColor(level_color) catch {};
|
||||
term.setColor(level_color) catch @panic("Caught an error while handling an error");
|
||||
writer.print(prefix, .{}) catch continue;
|
||||
|
||||
term.setColor(switch (level) {
|
||||
.err => .red,
|
||||
.warn => .magenta,
|
||||
else => .green,
|
||||
}) catch {};
|
||||
}) catch @panic("Caught an error while handling an error");
|
||||
writer.print("{s: >30}", .{scope_prefix}) catch continue;
|
||||
|
||||
term.setColor(.reset) catch {};
|
||||
term.setColor(.reset) catch @panic("Caught an error while handling an error");
|
||||
|
||||
writer.print("{s}\n", .{fmt_buffer[last_pos..pos]}) catch continue;
|
||||
writer.flush() catch continue;
|
||||
|
||||
@@ -9,9 +9,9 @@ const Image = @import("../Image.zig");
|
||||
const NonDispatchable = @import("../NonDispatchable.zig").NonDispatchable;
|
||||
|
||||
pub const State = enum {
|
||||
Available,
|
||||
Drawing,
|
||||
Presenting,
|
||||
available,
|
||||
drawing,
|
||||
presenting,
|
||||
};
|
||||
|
||||
const Self = @This();
|
||||
@@ -25,7 +25,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Image
|
||||
const image = try device.createImage(allocator, info);
|
||||
errdefer image.destroy(allocator);
|
||||
|
||||
var requirements: vk.MemoryRequirements = undefined;
|
||||
var requirements = std.mem.zeroes(vk.MemoryRequirements);
|
||||
try image.getMemoryRequirements(&requirements);
|
||||
|
||||
const memory = try device.allocateMemory(allocator, &.{
|
||||
@@ -40,7 +40,7 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Image
|
||||
.image = image,
|
||||
.non_dispatchable_image = try NonDispatchable(Image).wrap(allocator, image),
|
||||
.memory = memory,
|
||||
.state = .Available,
|
||||
.state = .available,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ pub fn init(instance: *Instance, allocator: std.mem.Allocator) VkError!Self {
|
||||
return .{
|
||||
.owner = instance,
|
||||
.swapchain = null,
|
||||
// SAFETY: the backend assigns the vtable before returning the surface.
|
||||
.vtable = undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ const VkError = @import("../error_set.zig").VkError;
|
||||
const BinarySemaphore = lib.BinarySemaphore;
|
||||
const Device = @import("../Device.zig");
|
||||
const Fence = lib.Fence;
|
||||
const Image = lib.Image;
|
||||
const PresentImage = @import("PresentImage.zig");
|
||||
const SurfaceKHR = lib.SurfaceKHR;
|
||||
|
||||
@@ -42,7 +41,7 @@ pub fn create(device: *Device, allocator: std.mem.Allocator, surface: *SurfaceKH
|
||||
var initialized_image_count: usize = 0;
|
||||
errdefer {
|
||||
for (images[0..initialized_image_count]) |*image| {
|
||||
surface.detachImage(allocator, image) catch {};
|
||||
surface.detachImage(allocator, image) catch @panic("Caught an error while handling an error");
|
||||
image.deinit(allocator);
|
||||
}
|
||||
}
|
||||
@@ -86,8 +85,8 @@ pub fn getNextImage(self: *const Self, timeout: u64, semaphore: ?*BinarySemaphor
|
||||
// TODO: handle timeout correctly
|
||||
|
||||
for (self.images, 0..) |*image, i| {
|
||||
if (image.state == .Available) {
|
||||
image.state = .Drawing;
|
||||
if (image.state == .available) {
|
||||
image.state = .drawing;
|
||||
index.* = @intCast(i);
|
||||
if (semaphore) |s|
|
||||
try s.signal();
|
||||
@@ -105,7 +104,7 @@ pub fn present(self: *Self, index: usize) VkError!void {
|
||||
|
||||
const image = &self.images[index];
|
||||
if (self.surface) |surface| {
|
||||
image.state = .Presenting;
|
||||
image.state = .presenting;
|
||||
try surface.presentImage(allocator, image);
|
||||
}
|
||||
}
|
||||
@@ -116,7 +115,7 @@ pub fn detachSurface(self: *Self) VkError!void {
|
||||
if (self.surface) |surface| {
|
||||
surface.swapchain = null;
|
||||
for (self.images) |*image| {
|
||||
if (image.state == .Available)
|
||||
if (image.state == .available)
|
||||
try surface.detachImage(allocator, image);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +125,7 @@ pub fn detachSurface(self: *Self) VkError!void {
|
||||
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
for (self.images) |*image| {
|
||||
if (self.surface) |surface| {
|
||||
surface.detachImage(allocator, image) catch {};
|
||||
surface.detachImage(allocator, image) catch @panic("Caught an error while handling an error");
|
||||
}
|
||||
image.deinit(allocator);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const WaylandImage = struct {
|
||||
};
|
||||
|
||||
fn wlRegistryHandleGlobal(data: ?*anyopaque, registry: ?*wayland.wl_registry, name: u32, interface: [*c]const u8, _: u32) callconv(.c) void {
|
||||
const pshm: **wayland.wl_shm = @ptrCast(@alignCast(data orelse return));
|
||||
const pshm: *?*wayland.wl_shm = @ptrCast(@alignCast(data orelse return));
|
||||
if (std.mem.eql(u8, std.mem.span(interface), "wl_shm")) {
|
||||
if (wayland.wl_registry_bind(registry orelse return, name, wayland.wl_shm_interface, 1)) |shm| {
|
||||
pshm.* = @ptrCast(@alignCast(shm));
|
||||
@@ -38,7 +38,7 @@ const wl_registry_listener: wayland.wl_registry_listener = .{
|
||||
interface: Interface,
|
||||
display: *wayland.wl_display,
|
||||
surface: *wayland.wl_surface,
|
||||
shm: *wayland.wl_shm,
|
||||
shm: ?*wayland.wl_shm,
|
||||
image_map: std.AutoHashMapUnmanaged(*PresentImage, *WaylandImage),
|
||||
|
||||
pub fn create(instance: *Instance, allocator: std.mem.Allocator, info: *const vk.WaylandSurfaceCreateInfoKHR) VkError!*Interface {
|
||||
@@ -61,13 +61,14 @@ pub fn create(instance: *Instance, allocator: std.mem.Allocator, info: *const vk
|
||||
.interface = interface,
|
||||
.display = info.display,
|
||||
.surface = info.surface,
|
||||
.shm = undefined,
|
||||
.shm = null,
|
||||
.image_map = .empty,
|
||||
};
|
||||
|
||||
const registry = wayland.wl_display_get_registry(@ptrCast(self.display)) orelse return VkError.Unknown;
|
||||
_ = wayland.wl_registry_add_listener(registry, &wl_registry_listener, @ptrCast(&self.shm));
|
||||
_ = wayland.wl_display_dispatch(@ptrCast(self.display));
|
||||
if (self.shm == null) return VkError.Unknown;
|
||||
|
||||
return &self.interface;
|
||||
}
|
||||
@@ -106,7 +107,8 @@ pub fn attachImage(interface: *Interface, allocator: std.mem.Allocator, image: *
|
||||
const data = std.posix.mmap(null, size, .{ .READ = true, .WRITE = true }, .{ .TYPE = .SHARED }, fd, 0) catch return VkError.OutOfHostMemory;
|
||||
errdefer std.posix.munmap(data);
|
||||
|
||||
const pool = wayland.wl_shm_create_pool(self.shm, fd, @intCast(size)) orelse return VkError.Unknown;
|
||||
const shm = self.shm orelse return VkError.Unknown;
|
||||
const pool = wayland.wl_shm_create_pool(shm, fd, @intCast(size)) orelse return VkError.Unknown;
|
||||
defer wayland.wl_shm_pool_destroy(pool);
|
||||
|
||||
const buffer = wayland.wl_shm_pool_create_buffer(pool, 0, @intCast(width), @intCast(height), @intCast(stride), wayland.WL_SHM_FORMAT_ARGB8888) orelse return VkError.Unknown;
|
||||
@@ -152,7 +154,7 @@ pub fn presentImage(interface: *Interface, allocator: std.mem.Allocator, image:
|
||||
|
||||
_ = wayland.wl_display_flush(@ptrCast(self.display));
|
||||
|
||||
image.state = .Available;
|
||||
image.state = .available;
|
||||
}
|
||||
|
||||
fn createShmFile(size: usize) VkError!std.posix.fd_t {
|
||||
|
||||
@@ -11,16 +11,16 @@ pub const wl_registry_listener = extern struct {
|
||||
global_remove: ?*const fn (data: ?*anyopaque, wl_registry: ?*wl_registry, name: u32) callconv(.c) void = null,
|
||||
};
|
||||
|
||||
pub const WL_BUFFER_DESTROY = @as(c_int, 0);
|
||||
pub const WL_DISPLAY_GET_REGISTRY = @as(c_int, 1);
|
||||
pub const WL_REGISTRY_BIND = @as(c_int, 0);
|
||||
pub const WL_SHM_CREATE_POOL = @as(c_int, 0);
|
||||
pub const WL_SHM_FORMAT_ARGB8888 = @as(c_int, 0);
|
||||
pub const WL_SHM_POOL_CREATE_BUFFER = @as(c_int, 0);
|
||||
pub const WL_SHM_POOL_DESTROY = @as(c_int, 1);
|
||||
pub const WL_SURFACE_ATTACH = @as(c_int, 1);
|
||||
pub const WL_SURFACE_COMMIT = @as(c_int, 6);
|
||||
pub const WL_SURFACE_DAMAGE = @as(c_int, 2);
|
||||
pub const WL_BUFFER_DESTROY: c_int = 0;
|
||||
pub const WL_DISPLAY_GET_REGISTRY: c_int = 1;
|
||||
pub const WL_REGISTRY_BIND: c_int = 0;
|
||||
pub const WL_SHM_CREATE_POOL: c_int = 0;
|
||||
pub const WL_SHM_FORMAT_ARGB8888: c_int = 0;
|
||||
pub const WL_SHM_POOL_CREATE_BUFFER: c_int = 0;
|
||||
pub const WL_SHM_POOL_DESTROY: c_int = 1;
|
||||
pub const WL_SURFACE_ATTACH: c_int = 1;
|
||||
pub const WL_SURFACE_COMMIT: c_int = 6;
|
||||
pub const WL_SURFACE_DAMAGE: c_int = 2;
|
||||
|
||||
pub const wl_buffer = opaque {};
|
||||
pub const wl_callback = opaque {};
|
||||
@@ -46,17 +46,27 @@ pub const wl_interface = extern struct {
|
||||
events: ?[*]const wl_message = null,
|
||||
};
|
||||
|
||||
// SAFETY: load assigns every function pointer before any protocol wrapper is used.
|
||||
pub var wl_display_dispatch: *const fn (*wl_display) callconv(.c) c_int = undefined;
|
||||
// SAFETY: load assigns every function pointer before any protocol wrapper is used.
|
||||
pub var wl_proxy_marshal_flags: *const fn (*wl_proxy, u32, ?*const wl_interface, u32, u32, ...) callconv(.c) ?*wl_proxy = undefined;
|
||||
// SAFETY: load assigns every function pointer before any protocol wrapper is used.
|
||||
pub var wl_proxy_get_version: *const fn (*wl_proxy) callconv(.c) u32 = undefined;
|
||||
// SAFETY: load assigns every function pointer before any protocol wrapper is used.
|
||||
pub var wl_proxy_add_listener: *const fn (*wl_proxy, **const fn (void) void, ?*anyopaque) callconv(.c) c_int = undefined;
|
||||
// SAFETY: load assigns every function pointer before any protocol wrapper is used.
|
||||
pub var wl_display_flush: *const fn (*wl_display) callconv(.c) c_int = undefined;
|
||||
|
||||
// SAFETY: load resolves every interface pointer before a surface can be created.
|
||||
pub var wl_buffer_interface: *wl_interface = undefined;
|
||||
// SAFETY: load resolves every interface pointer before a surface can be created.
|
||||
pub var wl_registry_interface: *wl_interface = undefined;
|
||||
// SAFETY: load resolves every interface pointer before a surface can be created.
|
||||
pub var wl_shm_interface: *wl_interface = undefined;
|
||||
// SAFETY: load resolves every interface pointer before a surface can be created.
|
||||
pub var wl_shm_pool_interface: *wl_interface = undefined;
|
||||
|
||||
// SAFETY: load initializes the module before it can be closed or queried.
|
||||
pub var module: std.DynLib = undefined;
|
||||
|
||||
pub var ref_count = std.atomic.Value(usize).init(0);
|
||||
|
||||
Reference in New Issue
Block a user