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 2, 2024
1 parent 835b653 commit c4fb972
Show file tree
Hide file tree
Showing 17 changed files with 798 additions and 307 deletions.
41 changes: 41 additions & 0 deletions src/binding/vk/attachment.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const std = @import ("std");
const c = @import ("c");

const vk = @import ("vk");
const raw = @import ("raw");

pub const Attachment = extern struct
{
pub const Description = extern struct
{
flags: vk.Attachment.Description.Flags = 0,
format: vk.Format,
samples: vk.SampleCount.Flags,
load_op: vk.Attachment.LoadOp,
store_op: vk.Attachment.StoreOp,
stencil_load_op: vk.Attachment.LoadOp,
stencil_store_op: vk.Attachment.StoreOp,
initial_layout: vk.Image.Layout,
final_layout: vk.Image.Layout,

pub const Flags = u32;
};

pub const LoadOp = enum (i32)
{
CLEAR = c.VK_ATTACHMENT_LOAD_OP_CLEAR,
DONT_CARE = c.VK_ATTACHMENT_LOAD_OP_DONT_CARE,
};

pub const Reference = extern struct
{
attachment: u32,
layout: vk.Image.Layout,
};

pub const StoreOp = enum (i32)
{
STORE = c.VK_ATTACHMENT_STORE_OP_STORE,
DONT_CARE = c.VK_ATTACHMENT_STORE_OP_DONT_CARE,
};
};
65 changes: 65 additions & 0 deletions src/binding/vk/descriptor.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const std = @import ("std");
const c = @import ("c");

const vk = @import ("vk");
const raw = @import ("raw");

pub const Descriptor = extern struct
{
pub const Pool = enum (u64) { NULL_HANDLE = vk.NULL_HANDLE, _, };

pub const Set = enum (u64)
{
NULL_HANDLE = vk.NULL_HANDLE, _,

pub const Layout = enum (u64)
{
NULL_HANDLE = vk.NULL_HANDLE, _,

pub const Binding = extern struct
{
binding: u32,
descriptor_type: vk.Descriptor.Type,
descriptor_count: u32 = 0,
stage_flags: vk.ShaderStage.Flags,
p_immutable_samplers: ?[*] const vk.Sampler = null,
};

pub const Create = extern struct
{
pub const Flags = u32;

pub const Info = extern struct
{
s_type: vk.StructureType = .DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
p_next: ?*const anyopaque = null,
flags: vk.Descriptor.Set.Layout.Create.Flags = 0,
binding_count: u32 = 0,
p_bindings: ?[*] const vk.Descriptor.Set.Layout.Binding = null,
};
};
pub fn create (device: vk.Device, p_create_info: *const vk.Descriptor.Set.Layout.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !vk.Descriptor.Set.Layout
{
var set_layout: vk.Descriptor.Set.Layout = undefined;
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, });
return error.UnexpectedResult;
}
return set_layout;
}

pub fn destroy (device: vk.Device, descriptor_set_layout: vk.Descriptor.Set.Layout, p_allocator: ?*const vk.AllocationCallbacks) void
{
raw.prototypes.device.vkDestroyDescriptorSetLayout(device, descriptor_set_layout, p_allocator);
}
};
};

pub const Type = enum (i32)
{
UNIFORM_BUFFER = c.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
COMBINED_IMAGE_SAMPLER = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
};
};
6 changes: 3 additions & 3 deletions src/binding/vk/device.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const raw = @import ("raw");

pub const Device = enum (usize)
{
NULL_HANDLE = 0, _,
pub const Memory = enum (u64) { NULL_HANDLE = 0, _, };
NULL_HANDLE = vk.NULL_HANDLE, _,
pub const Memory = enum (u64) { NULL_HANDLE = vk.NULL_HANDLE, _, };
pub const Size = u64;

pub fn load (self: @This ()) !void
Expand All @@ -23,7 +23,7 @@ pub const Device = enum (usize)

pub fn create (physical_device: vk.PhysicalDevice, p_create_info: *const vk.Device.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !vk.Device
{
var device: Device = undefined;
var device: vk.Device = undefined;
const result = raw.prototypes.instance.vkCreateDevice (physical_device, p_create_info, p_allocator, &device);
if (result > 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/binding/vk/ext/debug_utils.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub const DebugUtils = extern struct
WARNING = c.VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT,
ERROR = c.VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT,

pub fn in (self: @This (), flags: vk.EXT.DebugUtils.Message.Severity.Flags) bool
pub fn contains (self: @This (), flags: vk.EXT.DebugUtils.Message.Severity.Flags) bool
{
return (flags & @intFromEnum (self)) == @intFromEnum (self);
}
Expand All @@ -45,7 +45,7 @@ pub const DebugUtils = extern struct
PERFORMANCE = c.VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT,
DEVICE_ADDRESS_BINDING = c.VK_DEBUG_UTILS_MESSAGE_TYPE_DEVICE_ADDRESS_BINDING_BIT_EXT,

pub fn in (self: @This (), flags: vk.EXT.DebugUtils.Message.Type.Flags) bool
pub fn contains (self: @This (), flags: vk.EXT.DebugUtils.Message.Type.Flags) bool
{
return (flags & @intFromEnum (self)) == @intFromEnum (self);
}
Expand All @@ -55,7 +55,7 @@ pub const DebugUtils = extern struct

pub const Messenger = enum (u64)
{
NULL_HANDLE = 0, _,
NULL_HANDLE = vk.NULL_HANDLE, _,

pub fn create (instance: vk.Instance, p_create_info: *const vk.EXT.DebugUtils.Messenger.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
{
Expand Down
38 changes: 38 additions & 0 deletions src/binding/vk/format.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const std = @import ("std");
const c = @import ("c");

const vk = @import ("vk");
const raw = @import ("raw");

pub const Format = enum (u32)
{
A8B8G8R8_UNORM_PACK32 = c.VK_FORMAT_A8B8G8R8_UNORM_PACK32,
B8G8R8A8_SRGB = c.VK_FORMAT_B8G8R8A8_SRGB,
B8G8R8A8_UNORM = c.VK_FORMAT_B8G8R8A8_UNORM,
R8G8B8_UNORM = c.VK_FORMAT_R8G8B8_UNORM,
R8G8B8A8_UNORM = c.VK_FORMAT_R8G8B8A8_UNORM,
_,

pub const Feature = extern struct
{
pub const Flags = u32;

pub const Bit = enum (vk.Format.Feature.Flags)
{
BLIT_SRC = c.VK_FORMAT_FEATURE_BLIT_SRC_BIT,
BLIT_DST = c.VK_FORMAT_FEATURE_BLIT_DST_BIT,

pub fn contains (self: @This (), flags: vk.Format.Feature.Flags) bool
{
return (flags & @intFromEnum (self)) == @intFromEnum (self);
}
};
};

pub const Properties = extern struct
{
linear_tiling_features: vk.Format.Feature.Flags = 0,
optimal_tiling_features: vk.Format.Feature.Flags = 0,
buffer_features: vk.Format.Feature.Flags = 0,
};
};
45 changes: 45 additions & 0 deletions src/binding/vk/framebuffer.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const std = @import ("std");
const c = @import ("c");

const vk = @import ("vk");
const raw = @import ("raw");

pub const Framebuffer = enum (u64)
{
NULL_HANDLE = vk.NULL_HANDLE, _,

pub const Create = extern struct
{
pub const Flags = u32;

pub const Info = extern struct
{
s_type: vk.StructureType = .FRAMEBUFFER_CREATE_INFO,
p_next: ?*const anyopaque = null,
flags: vk.Framebuffer.Create.Flags = 0,
render_pass: vk.RenderPass,
attachment_count: u32 = 0,
p_attachments: ?[*] const vk.Image.View = null,
width: u32,
height: u32,
layers: u32,
};
};

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

pub fn destroy (device: vk.Device, framebuffer: vk.Framebuffer, p_allocator: ?*const vk.AllocationCallbacks) void
{
raw.prototypes.device.vkDestroyFramebuffer (device, framebuffer, p_allocator);
}
};
89 changes: 87 additions & 2 deletions src/binding/vk/image.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const raw = @import ("raw");

pub const Image = enum (u64)
{
NULL_HANDLE = 0, _,
NULL_HANDLE = vk.NULL_HANDLE, _,

pub const Aspect = extern struct
{
Expand All @@ -18,6 +18,61 @@ pub const Image = enum (u64)
};
};

pub const Create = extern struct
{
pub const Flags = u32;

pub const Info = extern struct
{
s_type: vk.StructureType = .IMAGE_CREATE_INFO,
p_next: ?*const anyopaque = null,
flags: vk.Image.Create.Flags = 0,
image_type: vk.Image.Type,
format: vk.Format,
extent: vk.Extent3D,
mip_levels: u32,
array_layers: u32,
samples: vk.SampleCount.Flags,
tiling: vk.Image.Tiling,
usage: vk.Image.Usage.Flags,
sharing_mode: vk.SharingMode,
queue_family_index_count: u32 = 0,
p_queue_family_indices: ?[*] const u32 = null,
initial_layout: vk.Image.Layout,
};
};

pub const Layout = enum (i32)
{
UNDEFINED = c.VK_IMAGE_LAYOUT_UNDEFINED,
PRESENT_SRC_KHR = c.VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
COLOR_ATTACHMENT_OPTIMAL = c.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
SHADER_READ_ONLY_OPTIMAL = c.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
};

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

pub fn bind (device: vk.Device, image: vk.Image, memory: vk.Device.Memory, memory_offset: vk.Device.Size) !void
{
const result = raw.prototypes.device.vkBindImageMemory (device, image, memory, memory_offset);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
};

pub const SubresourceRange = extern struct
{
aspect_mask: vk.Image.Aspect.Flags,
Expand All @@ -27,6 +82,16 @@ pub const Image = enum (u64)
layer_count: u32,
};

pub const Tiling = enum (i32)
{
OPTIMAL = c.VK_IMAGE_TILING_OPTIMAL,
};

pub const Type = enum (i32)
{
@"2D" = c.VK_IMAGE_TYPE_2D,
};

pub const Usage = extern struct
{
pub const Flags = u32;
Expand All @@ -36,12 +101,13 @@ pub const Image = enum (u64)
COLOR_ATTACHMENT = c.VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
TRANSFER_DST = c.VK_IMAGE_USAGE_TRANSFER_DST_BIT,
TRANSFER_SRC = c.VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
SAMPLED = c.VK_IMAGE_USAGE_SAMPLED_BIT,
};
};

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

pub fn create (device: vk.Device, p_create_info: *const vk.Image.View.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !vk.Image.View
{
Expand All @@ -64,6 +130,8 @@ pub const Image = enum (u64)
{
pub const Flags = u32;

pub const Bit = enum (vk.Image.View.Create.Flags) {};

pub const Info = extern struct
{
s_type: vk.StructureType = .IMAGE_VIEW_CREATE_INFO,
Expand All @@ -82,4 +150,21 @@ pub const Image = enum (u64)
@"2D" = c.VK_IMAGE_VIEW_TYPE_2D,
};
};

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

pub fn destroy (device: vk.Device, image: vk.Image, p_allocator: ?*const vk.AllocationCallbacks) void
{
raw.prototypes.device.vkDestroyImage (device, image, p_allocator);
}
};
2 changes: 1 addition & 1 deletion src/binding/vk/instance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const raw = @import ("raw");

pub const Instance = enum (usize)
{
NULL_HANDLE = 0, _,
NULL_HANDLE = vk.NULL_HANDLE, _,

pub fn create (p_create_info: *const vk.Instance.Create.Info, p_allocator: ?*const vk.AllocationCallbacks) !@This ()
{
Expand Down
2 changes: 1 addition & 1 deletion src/binding/vk/khr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub const PresentMode = enum (i32)

pub const Surface = enum (u64)
{
NULL_HANDLE = 0, _,
NULL_HANDLE = vk.NULL_HANDLE, _,
pub const Capabilities = extern struct
{
min_image_count: u32,
Expand Down
Loading

0 comments on commit c4fb972

Please sign in to comment.