Skip to content

Commit

Permalink
[progress #146] custom bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tiawl committed Apr 6, 2024
1 parent e95e809 commit 1b7df46
Show file tree
Hide file tree
Showing 28 changed files with 1,593 additions and 760 deletions.
20 changes: 11 additions & 9 deletions src/binding/imgui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub const vk = struct

pub fn shutdown () void
{
imgui.cImGui_ImplVulkan_Shutdown ();
c.cImGui_ImplVulkan_Shutdown ();
}
};

Expand All @@ -96,7 +96,7 @@ pub const glfw = struct

pub fn shutdown () void
{
imgui.cImGui_ImplGlfw_Shutdown ();
c.cImGui_ImplGlfw_Shutdown ();
}
};

Expand Down Expand Up @@ -132,7 +132,7 @@ pub const Ex = struct
{
pub fn button (label: [] const u8, size: imgui.Vec2) bool
{
return c.ImGui_ButtonEx (label, size);
return c.ImGui_ButtonEx (label.ptr, size);
}

pub fn sameline (offset_from_start_x: f32, spacing: f32) void
Expand Down Expand Up @@ -226,7 +226,8 @@ pub const Vec2 = c.ImVec2;

pub const Window = struct
{
pub const Flags = c.ImGuiWindowFlags_;
//pub const Flags = c.ImGuiWindowFlags_;
pub const Flags = i32;

pub const Bit = enum (imgui.Window.Flags)
{
Expand All @@ -239,20 +240,21 @@ pub const Window = struct

pub fn begin (name: [] const u8, p_open: ?*bool, flags: imgui.Window.Flags) !void
{
if (!imgui.ImGui_Begin (name, p_open, flags)) return error.ImGuiBeginFailure;
if (!c.ImGui_Begin (name.ptr, p_open, flags)) return error.ImGuiBeginFailure;
}

pub fn end () void
{
imgui.ImGui_End ();
c.ImGui_End ();
}

pub fn render () void
{
imgui.ImGui_Render ();
c.ImGui_Render ();
}

pub fn text (comptime fmt: [] const u8, args: anytype) void
pub fn text (allocator: std.mem.Allocator, comptime fmt: [] const u8, args: anytype) !void
{
c.ImGui_Text (std.debug.comptimePrint (fmt, args));
const str = try std.fmt.allocPrint (allocator, fmt, args);
c.ImGui_Text (str.ptr);
}
38 changes: 30 additions & 8 deletions src/binding/vk/buffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,39 @@ pub const Buffer = enum (u64)

pub const Memory = extern struct
{
pub const Barrier = extern struct
{
s_type: vk.StructureType = .BUFFER_MEMORY_BARRIER,
p_next: ?*const anyopaque = null,
src_access_mask: vk.Access.Flags,
dst_access_mask: vk.Access.Flags,
src_queue_family_index: u32,
dst_queue_family_index: u32,
buffer: vk.Buffer,
offset: vk.Device.Size,
size: vk.Device.Size,
};

pub const Requirements = extern struct
{
pub fn get (device: vk.Device, buffer: vk.Buffer) vk.Memory.Requirements
{
var memory_requirements: vk.Memory.Requirements = undefined;
raw.prototypes.device.vkGetBufferMemoryRequirements (device, buffer, &memory_requirements);
raw.prototypes.device.vkGetBufferMemoryRequirements (device, buffer,
&memory_requirements);
return memory_requirements;
}
};

pub fn bind (device: vk.Device, buffer: vk.Buffer, memory: vk.Device.Memory, memory_offset: vk.Device.Size) !void
pub fn bind (device: vk.Device, buffer: vk.Buffer, memory: vk.Device.Memory,
memory_offset: vk.Device.Size) !void
{
const result = raw.prototypes.device.vkBindBufferMemory (device, buffer, memory, memory_offset);
const result = raw.prototypes.device.vkBindBufferMemory (device, buffer,
memory, memory_offset);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
Expand All @@ -71,20 +88,25 @@ pub const Buffer = enum (u64)

pub const View = enum (u64) { NULL_HANDLE = vk.NULL_HANDLE, _, };

pub fn create (device: vk.Device, p_create_info: *const vk.Buffer.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
pub fn create (device: vk.Device,
p_create_info: *const vk.Buffer.Create.Info) !@This ()
{
var buffer: @This () = undefined;
const result = raw.prototypes.device.vkCreateBuffer (device, p_create_info, p_allocator, &buffer);
const p_allocator: ?*const vk.AllocationCallbacks = null;
const result = raw.prototypes.device.vkCreateBuffer (device, p_create_info,
p_allocator, &buffer);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return buffer;
}

pub fn destroy (buffer: @This (), device: vk.Device, p_allocator: ?*const vk.AllocationCallbacks) void
pub fn destroy (buffer: @This (), device: vk.Device) void
{
const p_allocator: ?*const vk.AllocationCallbacks = null;
raw.prototypes.device.vkDestroyBuffer (device, buffer, p_allocator);
}
};
99 changes: 80 additions & 19 deletions src/binding/vk/command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ pub const Command = extern struct
};
};

pub fn begin (command_buffer: @This (), p_begin_info: *const vk.Command.Buffer.Begin.Info) !void
pub fn begin (command_buffer: @This (),
p_begin_info: *const vk.Command.Buffer.Begin.Info) !void
{
const result = raw.prototypes.device.vkBeginCommandBuffer (command_buffer, p_begin_info);
const result = raw.prototypes.device.vkBeginCommandBuffer (
command_buffer, p_begin_info);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
Expand All @@ -78,32 +81,81 @@ pub const Command = extern struct
const result = raw.prototypes.device.vkEndCommandBuffer (command_buffer);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}

pub fn copy_buffer (command_buffer: @This (), src_buffer: vk.Buffer, dst_buffer: vk.Buffer, region_count: u32, p_regions: [*] const vk.Buffer.Copy) void
pub fn blit_image (command_buffer: @This (), src_image: vk.Image,
src_image_layout: vk.Image.Layout, dst_image: vk.Image,
dst_image_layout: vk.Image.Layout, region_count: u32,
p_regions: [*] const vk.Image.Blit, filter: vk.Filter) void
{
raw.prototypes.device.vkCmdCopyBuffer (command_buffer, src_buffer, dst_buffer, region_count, p_regions);
raw.prototypes.device.vkCmdBlitImage (command_buffer, src_image,
@intFromEnum (src_image_layout), dst_image,
@intFromEnum (dst_image_layout), region_count, p_regions,
@intFromEnum (filter));
}

pub fn copy_buffer (command_buffer: @This (), src_buffer: vk.Buffer,
dst_buffer: vk.Buffer, region_count: u32,
p_regions: [*] const vk.Buffer.Copy) void
{
raw.prototypes.device.vkCmdCopyBuffer (command_buffer, src_buffer,
dst_buffer, region_count, p_regions);
}

pub fn copy_image (command_buffer: vk.Command.Buffer, src_image: vk.Image,
src_image_layout: vk.Image.Layout, dst_image: vk.Image,
dst_image_layout: vk.Image.Layout, region_count: u32,
p_regions: [*] const vk.Image.Copy) void
{
raw.prototypes.device.vkCmdCopyImage (command_buffer, src_image,
@intFromEnum (src_image_layout), dst_image,
@intFromEnum (dst_image_layout), region_count, p_regions);
}

pub fn pipeline_barrier (command_buffer: @This (),
src_stage_mask: vk.Pipeline.Stage.Flags,
dst_stage_mask: vk.Pipeline.Stage.Flags,
dependency_flags: vk.Dependency.Flags, memory_barrier_count: u32,
p_memory_barriers: ?[*] const vk.Memory.Barrier,
buffer_memory_barrier_count: u32,
p_buffer_memory_barriers: ?[*] const vk.Buffer.Memory.Barrier,
image_memory_barrier_count: u32,
p_image_memory_barriers: ?[*] const vk.Image.Memory.Barrier) void
{
raw.prototypes.device.vkCmdPipelineBarrier (command_buffer,
src_stage_mask, dst_stage_mask, dependency_flags, memory_barrier_count,
p_memory_barriers, buffer_memory_barrier_count,
p_buffer_memory_barriers, image_memory_barrier_count,
p_image_memory_barriers);
}
};

pub const Buffers = extern struct
{
pub fn allocate (device: vk.Device, p_allocate_info: *const vk.Command.Buffer.Allocate.Info, p_command_buffers: [*] vk.Command.Buffer) !void
pub fn allocate (device: vk.Device,
p_allocate_info: *const vk.Command.Buffer.Allocate.Info,
p_command_buffers: [*] vk.Command.Buffer) !void
{
const result = raw.prototypes.device.vkAllocateCommandBuffers (device, p_allocate_info, p_command_buffers);
const result = raw.prototypes.device.vkAllocateCommandBuffers (device,
p_allocate_info, p_command_buffers);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}

pub fn free (device: vk.Device, command_pool: vk.Command.Pool, command_buffer_count: u32, p_command_buffers: [*] const vk.Command.Buffer) void
pub fn free (device: vk.Device, command_pool: vk.Command.Pool,
command_buffer_count: u32,
p_command_buffers: [*] const vk.Command.Buffer) void
{
raw.prototypes.device.vkFreeCommandBuffers (device, command_pool, command_buffer_count, p_command_buffers);
raw.prototypes.device.vkFreeCommandBuffers (device, command_pool,
command_buffer_count, p_command_buffers);
}
};

Expand Down Expand Up @@ -135,29 +187,38 @@ pub const Command = extern struct
pub const Flags = u32;
};

pub fn create (device: vk.Device, p_create_info: *const vk.Command.Pool.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
pub fn create (device: vk.Device,
p_create_info: *const vk.Command.Pool.Create.Info) !@This ()
{
var command_pool: @This () = undefined;
const result = raw.prototypes.device.vkCreateCommandPool (device, p_create_info, p_allocator, &command_pool);
const p_allocator: ?*const vk.AllocationCallbacks = null;
const result = raw.prototypes.device.vkCreateCommandPool (device,
p_create_info, p_allocator, &command_pool);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return command_pool;
}

pub fn destroy (command_pool: @This (), device: vk.Device, p_allocator: ?*const vk.AllocationCallbacks) void
pub fn destroy (command_pool: @This (), device: vk.Device) void
{
raw.prototypes.device.vkDestroyCommandPool (device, command_pool, p_allocator);
const p_allocator: ?*const vk.AllocationCallbacks = null;
raw.prototypes.device.vkDestroyCommandPool (device, command_pool,
p_allocator);
}

pub fn reset (command_pool: @This (), device: vk.Device, flags: vk.Command.Pool.Reset.Flags) !void
pub fn reset (command_pool: @This (), device: vk.Device,
flags: vk.Command.Pool.Reset.Flags) !void
{
const result = raw.prototypes.device.vkResetCommandPool (device, command_pool, flags);
const result = raw.prototypes.device.vkResetCommandPool (device,
command_pool, flags);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
Expand Down
51 changes: 36 additions & 15 deletions src/binding/vk/descriptor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,27 @@ pub const Descriptor = extern struct
descriptor_count: u32,
};

pub fn create (device: vk.Device, p_create_info: *const vk.Descriptor.Pool.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
pub fn create (device: vk.Device,
p_create_info: *const vk.Descriptor.Pool.Create.Info) !@This ()
{
var descriptor_pool: @This () = undefined;
const result = raw.prototypes.device.vkCreateDescriptorPool (device, p_create_info, p_allocator, &descriptor_pool);
const p_allocator: ?*const vk.AllocationCallbacks = null;
const result = raw.prototypes.device.vkCreateDescriptorPool (device,
p_create_info, p_allocator, &descriptor_pool);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return descriptor_pool;
}

pub fn destroy (descriptor_pool: @This (), device: vk.Device, p_allocator: ?*const vk.AllocationCallbacks) void
pub fn destroy (descriptor_pool: @This (), device: vk.Device) void
{
raw.prototypes.device.vkDestroyDescriptorPool (device, descriptor_pool, p_allocator);
const p_allocator: ?*const vk.AllocationCallbacks = null;
raw.prototypes.device.vkDestroyDescriptorPool (device, descriptor_pool,
p_allocator);
}
};

Expand Down Expand Up @@ -136,40 +142,55 @@ pub const Descriptor = extern struct
};
};

pub fn create (device: vk.Device, p_create_info: *const vk.Descriptor.Set.Layout.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
pub fn create (device: vk.Device,
p_create_info: *const vk.Descriptor.Set.Layout.Create.Info) !@This ()
{
var set_layout: @This () = undefined;
const result = raw.prototypes.device.vkCreateDescriptorSetLayout (device, p_create_info, p_allocator, &set_layout);
const p_allocator: ?*const vk.AllocationCallbacks = null;
const result = raw.prototypes.device.vkCreateDescriptorSetLayout (
device, p_create_info, p_allocator, &set_layout);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return set_layout;
}

pub fn destroy (descriptor_set_layout: @This (), device: vk.Device, p_allocator: ?*const vk.AllocationCallbacks) void
pub fn destroy (descriptor_set_layout: @This (), device: vk.Device) void
{
raw.prototypes.device.vkDestroyDescriptorSetLayout(device, descriptor_set_layout, p_allocator);
const p_allocator: ?*const vk.AllocationCallbacks = null;
raw.prototypes.device.vkDestroyDescriptorSetLayout(device,
descriptor_set_layout, p_allocator);
}
};
};

pub const Sets = extern struct
{
pub fn allocate (device: vk.Device, p_allocate_info: *const vk.Descriptor.Set.Allocate.Info, p_descriptor_sets: [*] vk.Descriptor.Set) !void
pub fn allocate (device: vk.Device,
p_allocate_info: *const vk.Descriptor.Set.Allocate.Info,
p_descriptor_sets: [*] vk.Descriptor.Set) !void
{
const result = raw.prototypes.device.vkAllocateDescriptorSets (device, p_allocate_info, p_descriptor_sets);
const result = raw.prototypes.device.vkAllocateDescriptorSets (device,
p_allocate_info, p_descriptor_sets);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
std.debug.print ("{s} failed with {} status code\n",
.{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}

pub fn update (device: vk.Device, descriptor_write_count: u32, p_descriptor_writes: ?[*] const vk.Write.Descriptor.Set, descriptor_copy_count: u32, p_descriptor_copies: ?[*] const vk.Copy.Descriptor.Set) void
pub fn update (device: vk.Device, descriptor_write_count: u32,
p_descriptor_writes: ?[*] const vk.Write.Descriptor.Set,
descriptor_copy_count: u32,
p_descriptor_copies: ?[*] const vk.Copy.Descriptor.Set) void
{
raw.prototypes.device.vkUpdateDescriptorSets (device, descriptor_write_count, p_descriptor_writes, descriptor_copy_count, p_descriptor_copies);
raw.prototypes.device.vkUpdateDescriptorSets (device,
descriptor_write_count, p_descriptor_writes, descriptor_copy_count,
p_descriptor_copies);
}
};

Expand Down
Loading

0 comments on commit 1b7df46

Please sign in to comment.