adding base Image and ICD file generation
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
|
||||
const cmd = @import("base").commands;
|
||||
const cmd = base.commands;
|
||||
const VkError = base.VkError;
|
||||
|
||||
const Self = @This();
|
||||
|
||||
@@ -13,17 +15,33 @@ pub fn deinit(self: *Self) void {
|
||||
_ = self;
|
||||
}
|
||||
|
||||
pub fn dispatch(self: *Self, command: *const cmd.Command) void {
|
||||
pub fn dispatch(self: *Self, command: *const cmd.Command) VkError!void {
|
||||
_ = self;
|
||||
switch (command.*) {
|
||||
.FillBuffer => |data| fillBuffer(&data),
|
||||
.CopyBuffer => |data| try copyBuffer(&data),
|
||||
.FillBuffer => |data| try fillBuffer(&data),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn fillBuffer(data: *const cmd.CommandFillBuffer) void {
|
||||
const memory = if (data.buffer.memory) |memory| memory else unreachable;
|
||||
const raw_memory_map: [*]u32 = @ptrCast(@alignCast(memory.map(data.offset, data.size) catch unreachable));
|
||||
fn copyBuffer(data: *const cmd.CommandCopyBuffer) VkError!void {
|
||||
for (data.regions) |region| {
|
||||
const src_memory = if (data.src.memory) |memory| memory else return VkError.ValidationFailed;
|
||||
const dst_memory = if (data.dst.memory) |memory| memory else return VkError.ValidationFailed;
|
||||
|
||||
const src_map: []u8 = @as([*]u8, @ptrCast(try src_memory.map(region.src_offset, region.size)))[0..region.size];
|
||||
const dst_map: []u8 = @as([*]u8, @ptrCast(try dst_memory.map(region.dst_offset, region.size)))[0..region.size];
|
||||
|
||||
@memcpy(dst_map, src_map);
|
||||
|
||||
src_memory.unmap();
|
||||
dst_memory.unmap();
|
||||
}
|
||||
}
|
||||
|
||||
fn fillBuffer(data: *const cmd.CommandFillBuffer) VkError!void {
|
||||
const memory = if (data.buffer.memory) |memory| memory else return VkError.ValidationFailed;
|
||||
const raw_memory_map: [*]u32 = @ptrCast(@alignCast(try memory.map(data.offset, data.size)));
|
||||
var memory_map: []u32 = raw_memory_map[0..data.size];
|
||||
|
||||
for (0..@divExact(data.size, @sizeOf(u32))) |i| {
|
||||
|
||||
@@ -22,6 +22,7 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
|
||||
interface.dispatch_table = &.{
|
||||
.begin = begin,
|
||||
.copyBuffer = copyBuffer,
|
||||
.end = end,
|
||||
.fillBuffer = fillBuffer,
|
||||
.reset = reset,
|
||||
@@ -65,3 +66,11 @@ pub fn fillBuffer(interface: *Interface, buffer: *base.Buffer, offset: vk.Device
|
||||
_ = size;
|
||||
_ = data;
|
||||
}
|
||||
|
||||
pub fn copyBuffer(interface: *Interface, src: *base.Buffer, dst: *base.Buffer, regions: []const vk.BufferCopy) VkError!void {
|
||||
// No-op
|
||||
_ = interface;
|
||||
_ = src;
|
||||
_ = dst;
|
||||
_ = regions;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,9 @@ const SoftQueue = @import("SoftQueue.zig");
|
||||
const SoftBuffer = @import("SoftBuffer.zig");
|
||||
const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
|
||||
const SoftFence = @import("SoftFence.zig");
|
||||
const SoftImage = @import("SoftImage.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
const Dispatchable = base.Dispatchable;
|
||||
const NonDispatchable = base.NonDispatchable;
|
||||
|
||||
const Self = @This();
|
||||
pub const Interface = base.Device;
|
||||
@@ -41,6 +40,7 @@ pub fn create(physical_device: *base.PhysicalDevice, allocator: std.mem.Allocato
|
||||
.createBuffer = createBuffer,
|
||||
.createCommandPool = createCommandPool,
|
||||
.createFence = createFence,
|
||||
.createImage = createImage,
|
||||
.destroy = destroy,
|
||||
};
|
||||
|
||||
@@ -73,6 +73,12 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const device_memory = try SoftDeviceMemory.create(self, allocator, info.allocation_size, info.memory_type_index);
|
||||
return &device_memory.interface;
|
||||
}
|
||||
|
||||
pub fn createBuffer(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.BufferCreateInfo) VkError!*base.Buffer {
|
||||
const buffer = try SoftBuffer.create(interface, allocator, info);
|
||||
return &buffer.interface;
|
||||
@@ -88,8 +94,7 @@ pub fn createCommandPool(interface: *Interface, allocator: std.mem.Allocator, in
|
||||
return &pool.interface;
|
||||
}
|
||||
|
||||
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const device_memory = try SoftDeviceMemory.create(self, allocator, info.allocation_size, info.memory_type_index);
|
||||
return &device_memory.interface;
|
||||
pub fn createImage(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.ImageCreateInfo) VkError!*base.Image {
|
||||
const image = try SoftImage.create(interface, allocator, info);
|
||||
return &image.interface;
|
||||
}
|
||||
|
||||
40
src/soft/SoftImage.zig
git.filemode.normal_file
40
src/soft/SoftImage.zig
git.filemode.normal_file
@@ -0,0 +1,40 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const base = @import("base");
|
||||
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
const VkError = base.VkError;
|
||||
const Device = base.Device;
|
||||
|
||||
const Self = @This();
|
||||
pub const Interface = base.Image;
|
||||
|
||||
interface: Interface,
|
||||
|
||||
pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const vk.ImageCreateInfo) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
errdefer allocator.destroy(self);
|
||||
|
||||
var interface = try Interface.init(device, allocator, info);
|
||||
|
||||
interface.vtable = &.{
|
||||
.destroy = destroy,
|
||||
.getMemoryRequirements = getMemoryRequirements,
|
||||
};
|
||||
|
||||
self.* = .{
|
||||
.interface = interface,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub fn getMemoryRequirements(interface: *Interface, requirements: *vk.MemoryRequirements) void {
|
||||
_ = interface;
|
||||
requirements.alignment = lib.MEMORY_REQUIREMENTS_ALIGNMENT;
|
||||
}
|
||||
@@ -35,8 +35,114 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
||||
interface.props.device_id = root.DEVICE_ID;
|
||||
interface.props.device_type = .cpu;
|
||||
|
||||
interface.props.limits.max_bound_descriptor_sets = 1024; // tmp
|
||||
interface.props.limits.max_memory_allocation_count = 1024;
|
||||
interface.props.limits = .{
|
||||
.max_image_dimension_1d = 4096,
|
||||
.max_image_dimension_2d = 4096,
|
||||
.max_image_dimension_3d = 256,
|
||||
.max_image_dimension_cube = 4096,
|
||||
.max_image_array_layers = 256,
|
||||
.max_texel_buffer_elements = 65536,
|
||||
.max_uniform_buffer_range = 16384,
|
||||
.max_storage_buffer_range = 134217728,
|
||||
.max_push_constants_size = 128,
|
||||
.max_memory_allocation_count = std.math.maxInt(u32),
|
||||
.max_sampler_allocation_count = 4096,
|
||||
.buffer_image_granularity = 131072,
|
||||
.sparse_address_space_size = 0,
|
||||
.max_bound_descriptor_sets = 4,
|
||||
.max_per_stage_descriptor_samplers = 16,
|
||||
.max_per_stage_descriptor_uniform_buffers = 12,
|
||||
.max_per_stage_descriptor_storage_buffers = 4,
|
||||
.max_per_stage_descriptor_sampled_images = 16,
|
||||
.max_per_stage_descriptor_storage_images = 4,
|
||||
.max_per_stage_descriptor_input_attachments = 4,
|
||||
.max_per_stage_resources = 128,
|
||||
.max_descriptor_set_samplers = 96,
|
||||
.max_descriptor_set_uniform_buffers = 72,
|
||||
.max_descriptor_set_uniform_buffers_dynamic = 8,
|
||||
.max_descriptor_set_storage_buffers = 24,
|
||||
.max_descriptor_set_storage_buffers_dynamic = 4,
|
||||
.max_descriptor_set_sampled_images = 96,
|
||||
.max_descriptor_set_storage_images = 24,
|
||||
.max_descriptor_set_input_attachments = 4,
|
||||
.max_vertex_input_attributes = 16,
|
||||
.max_vertex_input_bindings = 16,
|
||||
.max_vertex_input_attribute_offset = 2047,
|
||||
.max_vertex_input_binding_stride = 2048,
|
||||
.max_vertex_output_components = 64,
|
||||
.max_tessellation_generation_level = 0,
|
||||
.max_tessellation_patch_size = 0,
|
||||
.max_tessellation_control_per_vertex_input_components = 0,
|
||||
.max_tessellation_control_per_vertex_output_components = 0,
|
||||
.max_tessellation_control_per_patch_output_components = 0,
|
||||
.max_tessellation_control_total_output_components = 0,
|
||||
.max_tessellation_evaluation_input_components = 0,
|
||||
.max_tessellation_evaluation_output_components = 0,
|
||||
.max_geometry_shader_invocations = 0,
|
||||
.max_geometry_input_components = 0,
|
||||
.max_geometry_output_components = 0,
|
||||
.max_geometry_output_vertices = 0,
|
||||
.max_geometry_total_output_components = 0,
|
||||
.max_fragment_input_components = 64,
|
||||
.max_fragment_output_attachments = 4,
|
||||
.max_fragment_dual_src_attachments = 0,
|
||||
.max_fragment_combined_output_resources = 4,
|
||||
.max_compute_shared_memory_size = 16384,
|
||||
.max_compute_work_group_count = .{ 65535, 65535, 65535 },
|
||||
.max_compute_work_group_invocations = 128,
|
||||
.max_compute_work_group_size = .{ 128, 128, 64 },
|
||||
.sub_pixel_precision_bits = 4,
|
||||
.sub_texel_precision_bits = 4,
|
||||
.mipmap_precision_bits = 4,
|
||||
.max_draw_indexed_index_value = 4294967295,
|
||||
.max_draw_indirect_count = 65535,
|
||||
.max_sampler_lod_bias = 2.0,
|
||||
.max_sampler_anisotropy = 1.0,
|
||||
.max_viewports = 1,
|
||||
.max_viewport_dimensions = .{ 4096, 4096 },
|
||||
.viewport_bounds_range = .{ -8192.0, 8191.0 },
|
||||
.viewport_sub_pixel_bits = 0,
|
||||
.min_memory_map_alignment = 64,
|
||||
.min_texel_buffer_offset_alignment = 256,
|
||||
.min_uniform_buffer_offset_alignment = 256,
|
||||
.min_storage_buffer_offset_alignment = 256,
|
||||
.min_texel_offset = -8,
|
||||
.max_texel_offset = 7,
|
||||
.min_texel_gather_offset = 0,
|
||||
.max_texel_gather_offset = 0,
|
||||
.min_interpolation_offset = 0.0,
|
||||
.max_interpolation_offset = 0.0,
|
||||
.sub_pixel_interpolation_offset_bits = 0,
|
||||
.max_framebuffer_width = 4096,
|
||||
.max_framebuffer_height = 4096,
|
||||
.max_framebuffer_layers = 256,
|
||||
.framebuffer_color_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.framebuffer_depth_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.framebuffer_stencil_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.framebuffer_no_attachments_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.max_color_attachments = 4,
|
||||
.sampled_image_color_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.sampled_image_integer_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.sampled_image_depth_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.sampled_image_stencil_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.storage_image_sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.max_sample_mask_words = 1,
|
||||
.timestamp_compute_and_graphics = .false,
|
||||
.timestamp_period = 1.0,
|
||||
.max_clip_distances = 0,
|
||||
.max_cull_distances = 0,
|
||||
.max_combined_clip_and_cull_distances = 0,
|
||||
.discrete_queue_priorities = 2,
|
||||
.point_size_range = .{ 1.0, 1.0 },
|
||||
.line_width_range = .{ 1.0, 1.0 },
|
||||
.point_size_granularity = 0.0,
|
||||
.line_width_granularity = 0.0,
|
||||
.strict_lines = .false,
|
||||
.standard_sample_locations = .true,
|
||||
.optimal_buffer_copy_offset_alignment = 1,
|
||||
.optimal_buffer_copy_row_pitch_alignment = 1,
|
||||
.non_coherent_atom_size = 256,
|
||||
};
|
||||
|
||||
interface.mem_props.memory_type_count = 1;
|
||||
interface.mem_props.memory_types[0] = .{
|
||||
@@ -122,7 +228,13 @@ pub fn getImageFormatProperties(
|
||||
_ = tiling;
|
||||
_ = usage;
|
||||
_ = flags;
|
||||
return VkError.FormatNotSupported;
|
||||
return .{
|
||||
.max_extent = undefined,
|
||||
.max_mip_levels = 1,
|
||||
.max_array_layers = 6,
|
||||
.sample_counts = .{ .@"1_bit" = true, .@"4_bit" = true },
|
||||
.max_resource_size = 0,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getSparseImageFormatProperties(
|
||||
@@ -141,7 +253,7 @@ pub fn getSparseImageFormatProperties(
|
||||
_ = tiling;
|
||||
_ = usage;
|
||||
_ = flags;
|
||||
return VkError.FormatNotSupported;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
|
||||
|
||||
@@ -89,7 +89,7 @@ fn taskRunner(self: *Self, info: Interface.SubmitInfo, p_fence: ?*base.Fence) vo
|
||||
loop: for (info.command_buffers.items) |command_buffer| {
|
||||
command_buffer.submit() catch continue :loop;
|
||||
for (command_buffer.commands.items) |command| {
|
||||
executor.dispatch(&command);
|
||||
executor.dispatch(&command) catch |err| base.errors.errorLoggerContext(err, "the software command dispatcher");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ pub const SoftCommandBuffer = @import("SoftCommandBuffer.zig");
|
||||
pub const SoftCommandPool = @import("SoftCommandPool.zig");
|
||||
pub const SoftDeviceMemory = @import("SoftDeviceMemory.zig");
|
||||
pub const SoftFence = @import("SoftFence.zig");
|
||||
pub const SoftImage = @import("SoftImage.zig");
|
||||
|
||||
pub const Instance = SoftInstance;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user