adding software blitter base
This commit is contained in:
@@ -40,7 +40,7 @@ dispatch_table: *const DispatchTable,
|
||||
|
||||
pub const DispatchTable = struct {
|
||||
begin: *const fn (*Self, *const vk.CommandBufferBeginInfo) VkError!void,
|
||||
clearColorImage: *const fn (*Self, *Image, vk.ImageLayout, *const vk.ClearColorValue, []const vk.ImageSubresourceRange) VkError!void,
|
||||
clearColorImage: *const fn (*Self, *Image, vk.ImageLayout, *const vk.ClearColorValue, vk.ImageSubresourceRange) VkError!void,
|
||||
copyBuffer: *const fn (*Self, *Buffer, *Buffer, []const vk.BufferCopy) VkError!void,
|
||||
copyImage: *const fn (*Self, *Image, vk.ImageLayout, *Image, vk.ImageLayout, []const vk.ImageCopy) VkError!void,
|
||||
end: *const fn (*Self) VkError!void,
|
||||
@@ -122,7 +122,6 @@ fn cleanCommandList(self: *Self) void {
|
||||
const allocator = self.host_allocator.allocator();
|
||||
for (self.commands.items) |command| {
|
||||
switch (command) {
|
||||
.ClearColorImage => |data| allocator.free(data.ranges),
|
||||
.CopyBuffer => |data| allocator.free(data.regions),
|
||||
.CopyImage => |data| allocator.free(data.regions),
|
||||
else => {},
|
||||
@@ -134,13 +133,15 @@ fn cleanCommandList(self: *Self) void {
|
||||
|
||||
pub inline fn clearColorImage(self: *Self, image: *Image, layout: vk.ImageLayout, color: *const vk.ClearColorValue, ranges: []const vk.ImageSubresourceRange) VkError!void {
|
||||
const allocator = self.host_allocator.allocator();
|
||||
self.commands.append(allocator, .{ .ClearColorImage = .{
|
||||
.image = image,
|
||||
.layout = layout,
|
||||
.clear_color = color.*,
|
||||
.ranges = allocator.dupe(vk.ImageSubresourceRange, ranges) catch return VkError.OutOfHostMemory,
|
||||
} }) catch return VkError.OutOfHostMemory;
|
||||
try self.dispatch_table.clearColorImage(self, image, layout, color, ranges);
|
||||
for (ranges) |range| {
|
||||
self.commands.append(allocator, .{ .ClearColorImage = .{
|
||||
.image = image,
|
||||
.layout = layout,
|
||||
.clear_color = color.*,
|
||||
.range = range,
|
||||
} }) catch return VkError.OutOfHostMemory;
|
||||
try self.dispatch_table.clearColorImage(self, image, layout, color, range);
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn copyBuffer(self: *Self, src: *Buffer, dst: *Buffer, regions: []const vk.BufferCopy) VkError!void {
|
||||
|
||||
@@ -125,3 +125,23 @@ pub fn formatSupportsColorAttachemendBlend(format: vk.Format) bool {
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn formatFromAspect(base_format: vk.Format, aspect: vk.ImageAspectFlags) vk.Format {
|
||||
if (aspect.color_bit or (aspect.color_bit and aspect.stencil_bit)) {
|
||||
return base_format;
|
||||
} else if (aspect.depth_bit) {
|
||||
if (base_format == .d16_unorm or base_format == .d16_unorm_s8_uint) {
|
||||
return .d16_unorm;
|
||||
} else if (base_format == .d24_unorm_s8_uint) {
|
||||
return .x8_d24_unorm_pack32;
|
||||
} else if (base_format == .d32_sfloat or base_format == .d32_sfloat_s8_uint) {
|
||||
return .d32_sfloat;
|
||||
}
|
||||
} else if (aspect.stencil_bit) {
|
||||
if (base_format == .s8_uint or base_format == .d16_unorm_s8_uint or base_format == .d24_unorm_s8_uint or base_format == .d32_sfloat_s8_uint) {
|
||||
return .s8_uint;
|
||||
}
|
||||
}
|
||||
lib.unsupported("format {d}", .{@intFromEnum(base_format)});
|
||||
return base_format;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ pub const CommandClearColorImage = struct {
|
||||
image: *Image,
|
||||
layout: vk.ImageLayout,
|
||||
clear_color: vk.ClearColorValue,
|
||||
ranges: []const vk.ImageSubresourceRange,
|
||||
range: vk.ImageSubresourceRange,
|
||||
};
|
||||
pub const CommandCopyBuffer = struct {
|
||||
src: *Buffer,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Here lies the documentation of the common internal API that backends need to implement
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const vk = @import("vulkan");
|
||||
pub const vku = @cImport({
|
||||
@cInclude("vulkan/utility/vk_format_utils.h");
|
||||
@@ -79,6 +80,14 @@ pub inline fn getLogVerboseLevel() LogVerboseLevel {
|
||||
.Standard;
|
||||
}
|
||||
|
||||
pub fn unsupported(comptime fmt: []const u8, args: anytype) void {
|
||||
if (builtin.mode == std.builtin.OptimizeMode.Debug) {
|
||||
std.debug.panic("UNSUPPORTED " ++ fmt, args);
|
||||
} else {
|
||||
std.log.scoped(.UNSUPPORTED).warn(fmt, args);
|
||||
}
|
||||
}
|
||||
|
||||
comptime {
|
||||
_ = lib_vulkan;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user