fixing wsi crashes
Build / build (push) Successful in 2m19s
Test / build_and_test (push) Successful in 1m54s

This commit is contained in:
2026-07-01 13:56:47 +02:00
parent 762d414d54
commit 5b182580a7
11 changed files with 118 additions and 47 deletions
+12 -4
View File
@@ -164,21 +164,29 @@ pub fn getSurfaceCapabilitiesKHR(_: *Self, surface: *SurfaceKHR, capabilities: *
pub fn getSurfaceFormatsKHR(_: *Self, _: *SurfaceKHR, count: *u32, p_formats: ?[*]vk.SurfaceFormatKHR) VkError!void {
const surface_formats = SurfaceKHR.getFormats();
count.* = surface_formats.len;
if (p_formats) |formats| {
for (formats[0..], surface_formats[0..]) |*format, surface_format| {
const write_count = @min(count.*, surface_formats.len);
for (formats[0..write_count], surface_formats[0..write_count]) |*format, surface_format| {
format.* = surface_format;
}
count.* = @intCast(write_count);
if (write_count < surface_formats.len) return VkError.Incomplete;
} else {
count.* = @intCast(surface_formats.len);
}
}
pub fn getSurfacePresentModesKHR(_: *Self, _: *SurfaceKHR, count: *u32, p_modes: ?[*]vk.PresentModeKHR) VkError!void {
const surface_modes = SurfaceKHR.getPresentModes();
count.* = surface_modes.len;
if (p_modes) |modes| {
for (modes[0..], surface_modes[0..]) |*mode, surface_mode| {
const write_count = @min(count.*, surface_modes.len);
for (modes[0..write_count], surface_modes[0..write_count]) |*mode, surface_mode| {
mode.* = surface_mode;
}
count.* = @intCast(write_count);
if (write_count < surface_modes.len) return VkError.Incomplete;
} else {
count.* = @intCast(surface_modes.len);
}
}
+4
View File
@@ -149,7 +149,11 @@ pub fn presentKHR(_: *Self, info: *const vk.PresentInfoKHR) VkError!void {
}
else
cmd_err = err;
continue;
};
if (info.p_results) |results| {
results[i] = .success;
}
}
if (cmd_err) |err|
+6 -2
View File
@@ -2458,11 +2458,15 @@ pub export fn apeGetSwapchainImagesKHR(p_device: vk.Device, p_swapchain: vk.Swap
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err);
const swapchain = NonDispatchable(SwapchainKHR).fromHandleObject(p_swapchain) catch |err| return toVkResult(err);
count.* = @intCast(swapchain.images.len);
if (p_images) |images| {
for (images[0..], swapchain.images[0..]) |*image, *swapchain_image| {
const write_count = @min(count.*, swapchain.images.len);
for (images[0..write_count], swapchain.images[0..write_count]) |*image, *swapchain_image| {
image.* = swapchain_image.non_dispatchable_image.toVkHandle(vk.Image);
}
count.* = @intCast(write_count);
if (write_count < swapchain.images.len) return .incomplete;
} else {
count.* = @intCast(swapchain.images.len);
}
return .success;
+1
View File
@@ -17,6 +17,7 @@ const formats = [_]vk.SurfaceFormatKHR{
};
const present_modes = [_]vk.PresentModeKHR{
.fifo_khr,
.immediate_khr,
};
+21
View File
@@ -18,7 +18,19 @@ owner: *Device,
surface: ?*SurfaceKHR,
images: []PresentImage,
fn validateImageAllocationSize(info: *const vk.SwapchainCreateInfoKHR) VkError!void {
if (info.image_extent.width == 0 or info.image_extent.height == 0 or info.image_array_layers == 0)
return VkError.OutOfDeviceMemory;
const texel_size = lib.format.texelSize(info.image_format);
var size = std.math.mul(usize, texel_size, info.image_extent.width) catch return VkError.OutOfDeviceMemory;
size = std.math.mul(usize, size, info.image_extent.height) catch return VkError.OutOfDeviceMemory;
_ = std.math.mul(usize, size, info.image_array_layers) catch return VkError.OutOfDeviceMemory;
}
pub fn create(device: *Device, allocator: std.mem.Allocator, surface: *SurfaceKHR, info: *const vk.SwapchainCreateInfoKHR) VkError!*Self {
try validateImageAllocationSize(info);
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
errdefer allocator.destroy(self);
@@ -27,6 +39,14 @@ pub fn create(device: *Device, allocator: std.mem.Allocator, surface: *SurfaceKH
allocator.free(images);
}
var initialized_image_count: usize = 0;
errdefer {
for (images[0..initialized_image_count]) |*image| {
surface.detachImage(allocator, image) catch {};
image.deinit(allocator);
}
}
for (images) |*image| {
image.* = try .init(device, allocator, &.{
.format = info.image_format,
@@ -46,6 +66,7 @@ pub fn create(device: *Device, allocator: std.mem.Allocator, surface: *SurfaceKH
.queue_family_index_count = info.queue_family_index_count,
.initial_layout = .general,
});
initialized_image_count += 1;
try surface.attachImage(allocator, image);
}