fixing synchronization issues, implementing missing entrypoints
This commit is contained in:
@@ -78,7 +78,10 @@ pub const DispatchTable = struct {
|
||||
resolveImage: *const fn (*Self, *Image, vk.ImageLayout, *Image, vk.ImageLayout, vk.ImageResolve) VkError!void,
|
||||
setEvent: *const fn (*Self, *Event, vk.PipelineStageFlags) VkError!void,
|
||||
setBlendConstants: *const fn (*Self, [4]f32) VkError!void,
|
||||
setDepthBias: *const fn (*Self, f32, f32, f32) VkError!void,
|
||||
setDepthBounds: *const fn (*Self, f32, f32) VkError!void,
|
||||
setDeviceMask: *const fn (*Self, u32) VkError!void,
|
||||
setLineWidth: *const fn (*Self, f32) VkError!void,
|
||||
setScissor: *const fn (*Self, u32, []const vk.Rect2D) VkError!void,
|
||||
setStencilCompareMask: *const fn (*Self, vk.StencilFaceFlags, u32) VkError!void,
|
||||
setStencilReference: *const fn (*Self, vk.StencilFaceFlags, u32) VkError!void,
|
||||
@@ -86,6 +89,7 @@ pub const DispatchTable = struct {
|
||||
setViewport: *const fn (*Self, u32, []const vk.Viewport) VkError!void,
|
||||
updateBuffer: *const fn (*Self, *Buffer, vk.DeviceSize, []const u8) VkError!void,
|
||||
waitEvent: *const fn (*Self, *Event, vk.PipelineStageFlags, vk.PipelineStageFlags, []const vk.MemoryBarrier, []const vk.BufferMemoryBarrier, []const vk.ImageMemoryBarrier) VkError!void,
|
||||
writeTimestamp: *const fn (*Self, vk.PipelineStageFlags, *QueryPool, u32) VkError!void,
|
||||
};
|
||||
|
||||
pub const VTable = struct {
|
||||
@@ -338,6 +342,14 @@ pub inline fn setBlendConstants(self: *Self, constants: [4]f32) VkError!void {
|
||||
try self.dispatch_table.setBlendConstants(self, constants);
|
||||
}
|
||||
|
||||
pub inline fn setDepthBias(self: *Self, constant_factor: f32, clamp: f32, slope_factor: f32) VkError!void {
|
||||
try self.dispatch_table.setDepthBias(self, constant_factor, clamp, slope_factor);
|
||||
}
|
||||
|
||||
pub inline fn setDepthBounds(self: *Self, min: f32, max: f32) VkError!void {
|
||||
try self.dispatch_table.setDepthBounds(self, min, max);
|
||||
}
|
||||
|
||||
pub inline fn setDeviceMask(self: *Self, device_mask: u32) VkError!void {
|
||||
if (device_mask != 1)
|
||||
return VkError.ValidationFailed;
|
||||
@@ -345,6 +357,10 @@ pub inline fn setDeviceMask(self: *Self, device_mask: u32) VkError!void {
|
||||
try self.dispatch_table.setDeviceMask(self, device_mask);
|
||||
}
|
||||
|
||||
pub inline fn setLineWidth(self: *Self, width: f32) VkError!void {
|
||||
try self.dispatch_table.setLineWidth(self, width);
|
||||
}
|
||||
|
||||
pub inline fn setScissor(self: *Self, first: u32, scissor: []const vk.Rect2D) VkError!void {
|
||||
try self.dispatch_table.setScissor(self, first, scissor);
|
||||
}
|
||||
@@ -376,3 +392,7 @@ pub inline fn waitEvent(
|
||||
) VkError!void {
|
||||
try self.dispatch_table.waitEvent(self, event, src_stage, dst_stage, memory_barriers, buffer_barriers, image_barriers);
|
||||
}
|
||||
|
||||
pub inline fn writeTimestamp(self: *Self, stage: vk.PipelineStageFlags, pool: *QueryPool, query: u32) VkError!void {
|
||||
try self.dispatch_table.writeTimestamp(self, stage, pool, query);
|
||||
}
|
||||
|
||||
@@ -48,3 +48,41 @@ pub inline fn signal(self: *Self) VkError!void {
|
||||
pub inline fn wait(self: *Self, timeout: u64) VkError!void {
|
||||
try self.vtable.wait(self, timeout);
|
||||
}
|
||||
|
||||
pub fn waitMany(device: *Device, fences: []const *Self, wait_for_all: vk.Bool32, timeout: u64) VkError!void {
|
||||
const forever = timeout == std.math.maxInt(@TypeOf(timeout));
|
||||
const io = device.io();
|
||||
const deadline = if (forever) null else std.Io.Clock.Timestamp.fromNow(io, .{
|
||||
.raw = .fromNanoseconds(@intCast(timeout)),
|
||||
.clock = .awake,
|
||||
});
|
||||
|
||||
while (true) {
|
||||
var signaled_count: usize = 0;
|
||||
for (fences) |fence| {
|
||||
if (fence.owner != device) return VkError.InvalidHandleDrv;
|
||||
|
||||
fence.getStatus() catch |err| switch (err) {
|
||||
VkError.NotReady => continue,
|
||||
else => return err,
|
||||
};
|
||||
|
||||
if (wait_for_all == .false) return;
|
||||
signaled_count += 1;
|
||||
}
|
||||
|
||||
if (signaled_count == fences.len) return;
|
||||
if (timeout == 0) return VkError.Timeout;
|
||||
|
||||
const sleep_ns = if (deadline) |value| blk: {
|
||||
const remaining = value.durationFromNow(io);
|
||||
if (remaining.raw.nanoseconds <= 0) return VkError.Timeout;
|
||||
break :blk @min(remaining.raw.nanoseconds, std.time.ns_per_ms);
|
||||
} else std.time.ns_per_ms;
|
||||
|
||||
(std.Io.Clock.Duration{
|
||||
.raw = .fromNanoseconds(sleep_ns),
|
||||
.clock = .awake,
|
||||
}).sleep(io) catch return VkError.DeviceLost;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ mode: union(enum) {
|
||||
cull_mode: vk.CullModeFlags,
|
||||
front_face: vk.FrontFace,
|
||||
line_width: f32,
|
||||
depth_bias_enable: vk.Bool32,
|
||||
depth_bias_constant_factor: f32,
|
||||
depth_bias_clamp: f32,
|
||||
depth_bias_slope_factor: f32,
|
||||
},
|
||||
multisample: struct {
|
||||
rasterization_samples: vk.SampleCountFlags,
|
||||
@@ -194,6 +198,10 @@ pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipe
|
||||
.cull_mode = if (info.p_rasterization_state) |state| state.cull_mode else return VkError.ValidationFailed,
|
||||
.front_face = if (info.p_rasterization_state) |state| state.front_face else return VkError.ValidationFailed,
|
||||
.line_width = if (info.p_rasterization_state) |state| state.line_width else return VkError.ValidationFailed,
|
||||
.depth_bias_enable = if (info.p_rasterization_state) |state| state.depth_bias_enable else return VkError.ValidationFailed,
|
||||
.depth_bias_constant_factor = if (info.p_rasterization_state) |state| state.depth_bias_constant_factor else return VkError.ValidationFailed,
|
||||
.depth_bias_clamp = if (info.p_rasterization_state) |state| state.depth_bias_clamp else return VkError.ValidationFailed,
|
||||
.depth_bias_slope_factor = if (info.p_rasterization_state) |state| state.depth_bias_slope_factor else return VkError.ValidationFailed,
|
||||
},
|
||||
.multisample = blk: {
|
||||
if (rasterizer_discard_enable) {
|
||||
|
||||
@@ -69,6 +69,16 @@ pub fn end(self: *Self, query: u32) VkError!void {
|
||||
q.available = true;
|
||||
}
|
||||
|
||||
pub fn writeTimestamp(self: *Self, query: u32, value: u64) VkError!void {
|
||||
if (self.query_type != .timestamp)
|
||||
return VkError.ValidationFailed;
|
||||
|
||||
const q = try self.queryAt(query);
|
||||
q.value.store(value, .seq_cst);
|
||||
q.available = true;
|
||||
q.active = false;
|
||||
}
|
||||
|
||||
pub fn addSamples(self: *Self, query: u32, samples: u64) VkError!void {
|
||||
const q = try self.queryAt(query);
|
||||
if (q.active)
|
||||
|
||||
+18
-36
@@ -1434,13 +1434,11 @@ pub export fn apeGetDeviceMemoryCommitment(p_device: vk.Device, p_memory: vk.Dev
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return errorLogger(err);
|
||||
const memory = Dispatchable(DeviceMemory).fromHandleObject(p_memory) catch |err| return errorLogger(err);
|
||||
const memory = NonDispatchable(DeviceMemory).fromHandleObject(p_memory) catch |err| return errorLogger(err);
|
||||
if (memory.owner != device)
|
||||
return errorLogger(VkError.InvalidHandleDrv);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = device;
|
||||
_ = memory;
|
||||
_ = committed_memory;
|
||||
committed_memory.* = memory.size;
|
||||
}
|
||||
|
||||
pub export fn apeGetDeviceGroupPeerMemoryFeatures(
|
||||
@@ -1759,13 +1757,17 @@ pub export fn apeWaitForFences(p_device: vk.Device, count: u32, p_fences: [*]con
|
||||
entryPointBeginLogTrace(.vkWaitForFences);
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
Dispatchable(Device).checkHandleValidity(p_device) catch |err| return toVkResult(err);
|
||||
const device = Dispatchable(Device).fromHandleObject(p_device) catch |err| return toVkResult(err);
|
||||
|
||||
for (p_fences, 0..count) |p_fence, _| {
|
||||
const fence = NonDispatchable(Fence).fromHandleObject(p_fence) catch |err| return toVkResult(err);
|
||||
fence.wait(timeout) catch |err| return toVkResult(err);
|
||||
if (waitForAll == .false) break;
|
||||
const allocator = VulkanAllocator.init(null, .command).allocator();
|
||||
const fences = allocator.alloc(*Fence, count) catch return toVkResult(VkError.OutOfHostMemory);
|
||||
defer allocator.free(fences);
|
||||
|
||||
for (p_fences[0..count], fences) |p_fence, *fence| {
|
||||
fence.* = NonDispatchable(Fence).fromHandleObject(p_fence) catch |err| return toVkResult(err);
|
||||
}
|
||||
|
||||
Fence.waitMany(device, fences, waitForAll, timeout) catch |err| return toVkResult(err);
|
||||
return .success;
|
||||
}
|
||||
|
||||
@@ -2152,13 +2154,7 @@ pub export fn apeCmdSetDepthBias(p_cmd: vk.CommandBuffer, constant_factor: f32,
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = constant_factor;
|
||||
_ = clamp;
|
||||
_ = slope_factor;
|
||||
cmd.setDepthBias(constant_factor, clamp, slope_factor) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn apeCmdSetDepthBounds(p_cmd: vk.CommandBuffer, min: f32, max: f32) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -2166,12 +2162,7 @@ pub export fn apeCmdSetDepthBounds(p_cmd: vk.CommandBuffer, min: f32, max: f32)
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = min;
|
||||
_ = max;
|
||||
cmd.setDepthBounds(min, max) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn apeCmdSetDeviceMask(p_cmd: vk.CommandBuffer, device_mask: u32) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -2200,11 +2191,7 @@ pub export fn apeCmdSetLineWidth(p_cmd: vk.CommandBuffer, width: f32) callconv(v
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = width;
|
||||
cmd.setLineWidth(width) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn apeCmdSetScissor(p_cmd: vk.CommandBuffer, first: u32, count: u32, scissors: [*]const vk.Rect2D) callconv(vk.vulkan_call_conv) void {
|
||||
@@ -2292,13 +2279,8 @@ pub export fn apeCmdWriteTimestamp(p_cmd: vk.CommandBuffer, stage: vk.PipelineSt
|
||||
defer entryPointEndLogTrace();
|
||||
|
||||
const cmd = Dispatchable(CommandBuffer).fromHandleObject(p_cmd) catch |err| return errorLogger(err);
|
||||
|
||||
notImplementedWarning();
|
||||
|
||||
_ = cmd;
|
||||
_ = stage;
|
||||
_ = p_pool;
|
||||
_ = query;
|
||||
const pool = NonDispatchable(QueryPool).fromHandleObject(p_pool) catch |err| return errorLogger(err);
|
||||
cmd.writeTimestamp(stage, pool, query) catch |err| return errorLogger(err);
|
||||
}
|
||||
|
||||
pub export fn apeEndCommandBuffer(p_cmd: vk.CommandBuffer) callconv(vk.vulkan_call_conv) vk.Result {
|
||||
|
||||
Reference in New Issue
Block a user