ci skip
This commit is contained in:
@@ -54,7 +54,9 @@ pub const DispatchTable = struct {
|
||||
dispatch: *const fn (*Self, u32, u32, u32) VkError!void,
|
||||
dispatchIndirect: *const fn (*Self, *Buffer, vk.DeviceSize) VkError!void,
|
||||
draw: *const fn (*Self, usize, usize, usize, usize) VkError!void,
|
||||
drawIndexed: *const fn (*Self, usize, usize, usize, usize, usize) VkError!void,
|
||||
drawIndexed: *const fn (*Self, usize, usize, usize, i32, usize) VkError!void,
|
||||
drawIndexedIndirect: *const fn (*Self, *Buffer, usize, usize, usize) VkError!void,
|
||||
drawIndirect: *const fn (*Self, *Buffer, usize, usize, usize) VkError!void,
|
||||
end: *const fn (*Self) VkError!void,
|
||||
endRenderPass: *const fn (*Self) VkError!void,
|
||||
executeCommands: *const fn (*Self, *Self) VkError!void,
|
||||
@@ -215,10 +217,18 @@ pub inline fn draw(self: *Self, vertex_count: usize, instance_count: usize, firs
|
||||
try self.dispatch_table.draw(self, vertex_count, instance_count, first_vertex, first_instance);
|
||||
}
|
||||
|
||||
pub inline fn drawIndexed(self: *Self, index_count: usize, instance_count: usize, first_index: usize, vertex_offset: usize, first_instance: usize) VkError!void {
|
||||
pub inline fn drawIndexed(self: *Self, index_count: usize, instance_count: usize, first_index: usize, vertex_offset: i32, first_instance: usize) VkError!void {
|
||||
try self.dispatch_table.drawIndexed(self, index_count, instance_count, first_index, vertex_offset, first_instance);
|
||||
}
|
||||
|
||||
pub inline fn drawIndexedIndirect(self: *Self, buffer: *Buffer, offset: usize, count: usize, stride: usize) VkError!void {
|
||||
try self.dispatch_table.drawIndexedIndirect(self, buffer, offset, count, stride);
|
||||
}
|
||||
|
||||
pub inline fn drawIndirect(self: *Self, buffer: *Buffer, offset: usize, count: usize, stride: usize) VkError!void {
|
||||
try self.dispatch_table.drawIndirect(self, buffer, offset, count, stride);
|
||||
}
|
||||
|
||||
pub inline fn endRenderPass(self: *Self) VkError!void {
|
||||
try self.dispatch_table.endRenderPass(self);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ const RenderPass = @import("RenderPass.zig");
|
||||
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;
|
||||
|
||||
@@ -203,7 +206,7 @@ pub inline fn createShaderModule(self: *Self, allocator: std.mem.Allocator, info
|
||||
return self.dispatch_table.createShaderModule(self, allocator, info);
|
||||
}
|
||||
|
||||
pub inline fn waitIdle(self: *Self) VkError!void {
|
||||
pub fn waitIdle(self: *Self) VkError!void {
|
||||
var it = self.queues.iterator();
|
||||
while (it.next()) |family| {
|
||||
for (family.value_ptr.items) |queue| {
|
||||
|
||||
+61
-19
@@ -44,6 +44,10 @@ pub const RenderPass = @import("RenderPass.zig");
|
||||
pub const Sampler = @import("Sampler.zig");
|
||||
pub const ShaderModule = @import("ShaderModule.zig");
|
||||
|
||||
pub const SurfaceKHR = @import("wsi/SurfaceKHR.zig");
|
||||
pub const SwapchainKHR = @import("wsi/SwapchainKHR.zig");
|
||||
pub const WaylandSurfaceKHR = @import("wsi/WaylandSurfaceKHR.zig");
|
||||
|
||||
fn entryPointBeginLogTrace(comptime scope: @EnumLiteral()) void {
|
||||
std.log.scoped(scope).debug("Calling {s}...", .{@tagName(scope)});
|
||||
}
|
||||
@@ -1817,7 +1821,7 @@ pub export fn strollCmdDraw(p_cmd: vk.CommandBuffer, vertex_count: u32, instance
|
||||
cmd.draw(vertex_count, instance_count, first_vertex, first_instance) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn strollCmdDrawIndexed(p_cmd: vk.CommandBuffer, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: u32, first_instance: u32) callconv(vk.vulkan_call_conv) void {
|
||||
pub export fn strollCmdDrawIndexed(p_cmd: vk.CommandBuffer, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32) callconv(vk.vulkan_call_conv) void {
|
||||
entryPointBeginLogTrace(.vkCmdDrawIndexed);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
@@ -1830,15 +1834,8 @@ pub export fn strollCmdDrawIndexedIndirect(p_cmd: vk.CommandBuffer, p_buffer: vk
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
const buffer = Dispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = buffer;
|
||||
_ = offset;
|
||||
_ = count;
|
||||
_ = stride;
|
||||
const buffer = NonDispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
|
||||
cmd.drawIndexedIndirect(buffer, offset, count, stride) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn strollCmdDrawIndirect(p_cmd: vk.CommandBuffer, p_buffer: vk.Buffer, offset: vk.DeviceSize, count: u32, stride: u32) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -1846,15 +1843,8 @@ pub export fn strollCmdDrawIndirect(p_cmd: vk.CommandBuffer, p_buffer: vk.Buffer
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
const buffer = Dispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = buffer;
|
||||
_ = offset;
|
||||
_ = count;
|
||||
_ = stride;
|
||||
const buffer = NonDispatchable(Buffer).fromHandleObject(p_buffer) catch |err| return errorLogger(err);
|
||||
cmd.drawIndirect(buffer, offset, count, stride) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn strollCmdEndQuery(p_cmd: vk.CommandBuffer, p_pool: vk.QueryPool, query: u32) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -2201,3 +2191,55 @@ pub export fn strollResetCommandBuffer(p_cmd: vk.CommandBuffer, flags: vk.Comman
|
||||
cmd.reset(flags) catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
// WSI functions ===================================================================================================================================
|
||||
|
||||
pub export fn strollCreateSwapchainKHR(p_device: vk.Device, info: *const vk.SwapchainCreateInfoKHR, callbacks: ?*const vk.AllocationCallbacks, p_swapchain: *vk.Swapchain) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
entryPointBeginLogTrace(.vkCreateSwapchainKHR);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
if (info.s_type != .swapchain_create_info_khr) {
|
||||
return .error_validation_failed;
|
||||
}
|
||||
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
|
||||
const swapchain = SwapchainKHR.create(device, allocator, info) catch |err| return toVkResult(err);
|
||||
p_swapchain.* = (NonDispatchable(SwapchainKHR).wrap(allocator, swapchain) catch |err| return toVkResult(err)).toVkHandle(vk.SwapchainKHR);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollDestroySwapchainKHR(p_device: vk.Device, p_swapchain: vk.Swapchain, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
||||
entryPointBeginLogTrace(.vkDestroySwapchainKHR);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return errorLogger(err);
|
||||
|
||||
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
|
||||
const non_dispatchable = NonDispatchable(SwapchainKHR).fromHandle(p_swapchain) catch |err| return errorLogger(err);
|
||||
non_dispatchable.intrusiveDestroy(allocator);
|
||||
}
|
||||
|
||||
pub export fn strollCreateWaylandSurfaceKHR(p_device: vk.Device, info: *const vk.WaylandSurfaceCreateInfoKHR, callbacks: ?*const vk.AllocationCallbacks, p_surface: *vk.SurfaceKHR) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
entryPointBeginLogTrace(.vkCreateWaylandSurfaceKHR);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
if (info.s_type != .surface_create_info_khr) {
|
||||
return .error_validation_failed;
|
||||
}
|
||||
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
|
||||
const surface = WaylandSurfaceKHR.create(device, allocator, info) catch |err| return toVkResult(err);
|
||||
p_surface.* = (NonDispatchable(SurfaceKHR).wrap(allocator, surface) catch |err| return toVkResult(err)).toVkHandle(vk.SurfaceKHR);
|
||||
return .success;
|
||||
}
|
||||
|
||||
pub export fn strollDestroySurfaceKHR(p_device: vk.Device, p_surface: vk.SurfaceKHR, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {
|
||||
entryPointBeginLogTrace(.vkDestroySurfaceKHR);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return errorLogger(err);
|
||||
|
||||
const allocator = VulkanAllocator.init(callbacks, .object).allocator();
|
||||
const non_dispatchable = NonDispatchable(SurfaceKHR).fromHandle(p_surface) catch |err| return errorLogger(err);
|
||||
non_dispatchable.intrusiveDestroy(allocator);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const VkError = @import("../error_set.zig").VkError;
|
||||
|
||||
const Device = @import("../Device.zig");
|
||||
const DeviceMemory = @import("../DeviceMemory.zig");
|
||||
const Image = @import("../Image.zig");
|
||||
|
||||
pub const State = enum {
|
||||
Available,
|
||||
Drawing,
|
||||
Presenting,
|
||||
};
|
||||
|
||||
const Self = @This();
|
||||
|
||||
image: *Image,
|
||||
memory: *DeviceMemory,
|
||||
state: State,
|
||||
|
||||
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.ImageCreateInfo) VkError!Self {
|
||||
const image = try device.createImage(allocator, info);
|
||||
errdefer image.destroy(allocator);
|
||||
|
||||
const requirements: vk.MemoryRequirements = undefined;
|
||||
try image.getMemoryRequirements(&requirements);
|
||||
|
||||
const memory = try device.allocateMemory(allocator, &.{
|
||||
.allocation_size = requirements.size,
|
||||
.memory_type_index = requirements.memory_type_bits,
|
||||
});
|
||||
errdefer memory.destroy(allocator);
|
||||
|
||||
try image.bindMemory(memory, 0);
|
||||
|
||||
return .{
|
||||
.image = image,
|
||||
.memory = memory,
|
||||
.state = .Available,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||
self.image.destroy(allocator);
|
||||
self.memory.destroy(allocator);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const VkError = @import("../error_set.zig").VkError;
|
||||
|
||||
const Device = @import("../Device.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub const ObjectType: vk.ObjectType = .surface_khr;
|
||||
@@ -0,0 +1,53 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const VkError = @import("../error_set.zig").VkError;
|
||||
|
||||
const Device = @import("../Device.zig");
|
||||
const SurfaceKHR = @import("SurfaceKHR.zig");
|
||||
const PresentImage = @import("PresentImage.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .swapchain_khr;
|
||||
|
||||
owner: *Device,
|
||||
surface: *SurfaceKHR,
|
||||
images: []PresentImage,
|
||||
|
||||
pub fn create(device: *Device, allocator: std.mem.Allocator, info: *const vk.SwapchainCreateInfoKHR) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(self);
|
||||
|
||||
const images = allocator.alloc(PresentImage, info.min_image_count) catch return VkError.OutOfHostMemory;
|
||||
errdefer {
|
||||
allocator.free(images);
|
||||
}
|
||||
|
||||
for (images) |*image| {
|
||||
image.* = try .init(device, allocator, .{
|
||||
.format = info.image_format,
|
||||
.image_type = .@"2d",
|
||||
.extent = .{
|
||||
.width = info.image_extent.width,
|
||||
.height = info.image_extent.height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mip_levels = 1,
|
||||
.array_layers = info.image_array_layers,
|
||||
.samples = .@"1_bit",
|
||||
.tiling = .optimal,
|
||||
.usage = info.image_usage,
|
||||
.sharing_mode = info.image_sharing_mode,
|
||||
.p_queue_family_indices = info.p_queue_family_indices,
|
||||
.queue_family_index_count = info.queue_family_index_count,
|
||||
.initial_layout = .general,
|
||||
});
|
||||
}
|
||||
|
||||
self.* = .{
|
||||
.owner = device,
|
||||
.images = images,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
Reference in New Issue
Block a user