fixing some tests

This commit is contained in:
2025-12-09 00:09:02 +01:00
parent c67cb86dff
commit 8b33e61903
10 changed files with 542 additions and 62 deletions

View File

@@ -2,11 +2,12 @@ const std = @import("std");
const vk = @import("vulkan");
const VkError = @import("error_set.zig").VkError;
const Dispatchable = @import("Dispatchable.zig").Dispatchable;
const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
const Device = @import("Device.zig");
const DescriptorSet = @import("DescriptorSet.zig");
const DescriptorSetLayout = @import("DescriptorSetLayout.zig");
const Self = @This();
pub const ObjectType: vk.ObjectType = .descriptor_pool;
@@ -17,8 +18,9 @@ flags: vk.DescriptorPoolCreateFlags,
vtable: *const VTable,
pub const VTable = struct {
allocateDescriptorSet: *const fn (*Self, *DescriptorSetLayout) VkError!*DescriptorSet,
destroy: *const fn (*Self, std.mem.Allocator) void,
freeDescriptorSets: *const fn (*Self, []*Dispatchable(DescriptorSet)) VkError!void,
freeDescriptorSet: *const fn (*Self, *DescriptorSet) VkError!void,
};
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.DescriptorPoolCreateInfo) VkError!Self {
@@ -30,10 +32,14 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Descr
};
}
pub inline fn allocateDescriptorSet(self: *Self, layout: *DescriptorSetLayout) VkError!*DescriptorSet {
return self.vtable.allocateDescriptorSet(self, layout);
}
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
self.vtable.destroy(self, allocator);
}
pub inline fn freeDescriptorSets(self: *Self, sets: []*Dispatchable(DescriptorSet)) VkError!void {
try self.vtable.freeDescriptorSets(self, sets);
pub inline fn freeDescriptorSet(self: *Self, set: *DescriptorSet) VkError!void {
try self.vtable.freeDescriptorSet(self, set);
}

View File

@@ -13,7 +13,7 @@ const Self = @This();
pub const ObjectType: vk.ObjectType = .descriptor_set;
owner: *Device,
layouts: []*const DescriptorSetLayout,
layout: *DescriptorSetLayout,
vtable: *const VTable,
@@ -21,17 +21,11 @@ pub const VTable = struct {
destroy: *const fn (*Self, std.mem.Allocator) void,
};
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.DescriptorSetAllocateInfo) VkError!Self {
var layouts = allocator.alloc(*DescriptorSetLayout, info.descriptor_set_count) catch return VkError.OutOfHostMemory;
errdefer allocator.free(layouts);
for (info.p_set_layouts, 0..info.descriptor_set_count) |p_set_layout, i| {
layouts[i] = try NonDispatchable(DescriptorSetLayout).fromHandleObject(p_set_layout);
}
pub fn init(device: *Device, allocator: std.mem.Allocator, layout: *DescriptorSetLayout) VkError!Self {
_ = allocator;
return .{
.owner = device,
.layouts = layouts,
.layout = layout,
.vtable = undefined,
};
}

View File

@@ -87,3 +87,41 @@ pub inline fn getTotalSize(self: *Self) usize {
const pixel_size = self.getPixelSize();
return self.extent.width * self.extent.height * self.extent.depth * pixel_size;
}
pub fn formatSupportsColorAttachemendBlend(format: vk.Format) bool {
return switch (format) {
// Vulkan 1.1 mandatory
.r5g6b5_unorm_pack16,
.a1r5g5b5_unorm_pack16,
.r8_unorm,
.r8g8_unorm,
.r8g8b8a8_unorm,
.r8g8b8a8_srgb,
.b8g8r8a8_unorm,
.b8g8r8a8_srgb,
.a8b8g8r8_unorm_pack32,
.a8b8g8r8_srgb_pack32,
.a2b10g10r10_unorm_pack32,
.r16_sfloat,
.r16g16_sfloat,
.r16g16b16a16_sfloat,
// optional
.r4g4b4a4_unorm_pack16,
.b4g4r4a4_unorm_pack16,
.b5g6r5_unorm_pack16,
.r5g5b5a1_unorm_pack16,
.b5g5r5a1_unorm_pack16,
.a2r10g10b10_unorm_pack32,
.r16_unorm,
.r16g16_unorm,
.r16g16b16a16_unorm,
.r32_sfloat,
.r32g32_sfloat,
.r32g32b32a32_sfloat,
.b10g11r11_ufloat_pack32,
.a4r4g4b4_unorm_pack16,
.a4b4g4r4_unorm_pack16,
=> true,
else => false,
};
}

View File

@@ -526,20 +526,24 @@ pub export fn strollAllocateCommandBuffers(p_device: vk.Device, info: *const vk.
return .success;
}
pub export fn strollAllocateDescriptorSets(p_device: vk.Device, info: *const vk.DescriptorSetAllocateInfo, p_set: *vk.DescriptorSet) callconv(vk.vulkan_call_conv) vk.Result {
pub export fn strollAllocateDescriptorSets(p_device: vk.Device, info: *const vk.DescriptorSetAllocateInfo, p_sets: [*]vk.DescriptorSet) callconv(vk.vulkan_call_conv) vk.Result {
entryPointBeginLogTrace(.vkAllocateCommandBuffers);
defer entryPointEndLogTrace();
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err);
if (info.s_type != .descriptor_set_allocate_info) {
return .error_validation_failed;
}
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
const allocator = VulkanAllocator.init(null, .command).allocator();
notImplementedWarning();
_ = device;
_ = p_set;
const pool = NonDispatchable(DescriptorPool).fromHandleObject(info.descriptor_pool) catch |err| return toVkResult(err);
for (0..info.descriptor_set_count) |i| {
const layout = NonDispatchable(DescriptorSetLayout).fromHandleObject(info.p_set_layouts[i]) catch |err| return toVkResult(err);
const set = pool.allocateDescriptorSet(layout) catch |err| return toVkResult(err);
p_sets[i] = (NonDispatchable(DescriptorSet).wrap(allocator, set) catch |err| return toVkResult(err)).toVkHandle(vk.DescriptorSet);
}
return .success;
}
@@ -1127,11 +1131,16 @@ pub export fn strollFreeDescriptorSets(p_device: vk.Device, p_pool: vk.CommandPo
entryPointBeginLogTrace(.vkFreeDescriptorSets);
defer entryPointEndLogTrace();
const allocator = VulkanAllocator.init(null, .command).allocator();
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return errorLogger(err);
const pool = NonDispatchable(DescriptorPool).fromHandleObject(p_pool) catch |err| return errorLogger(err);
const sets: [*]*Dispatchable(DescriptorSet) = @ptrCast(@constCast(p_sets));
pool.freeDescriptorSets(sets[0..count]) catch |err| return errorLogger(err);
for (p_sets[0..], 0..count) |p_set, _| {
const non_dispatchable_set = NonDispatchable(DescriptorSet).fromHandle(p_set) catch |err| return errorLogger(err);
pool.freeDescriptorSet(non_dispatchable_set.object) catch |err| return errorLogger(err);
non_dispatchable_set.destroy(allocator);
}
}
pub export fn strollFreeMemory(p_device: vk.Device, p_memory: vk.DeviceMemory, callbacks: ?*const vk.AllocationCallbacks) callconv(vk.vulkan_call_conv) void {