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 Mar 19, 2024
1 parent f725d96 commit 26cf987
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 33 deletions.
64 changes: 64 additions & 0 deletions src/binding/vk/khr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const raw = @import ("prototypes.zig");
pub const KHR = extern struct
{
pub const SHADER_NON_SEMANTIC_INFO = c.VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME;
pub const SWAPCHAIN = c.VK_KHR_SWAPCHAIN_EXTENSION_NAME;

pub const ColorSpace = enum (i32)
{
SRGB_NONLINEAR_KHR = c.VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
Expand All @@ -20,6 +22,68 @@ pub const KHR = extern struct
};
};

pub const PhysicalDevice = extern struct
{
pub const Surface = extern struct
{
pub const Capabilities = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, surface: vk.KHR.Surface) !vk.KHR.Surface.Capabilities
{
var surface_capabilities: vk.KHR.Surface.Capabilities = undefined;
const result = raw.prototypes.instance.vkGetPhysicalDeviceSurfaceCapabilitiesKHR (physical_device, surface, &surface_capabilities);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return surface_capabilities;
}
};

pub const Formats = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, surface: vk.KHR.Surface, p_surface_format_count: *u32, p_surface_formats: ?[*] vk.KHR.Surface.Format) !void
{
const result = raw.prototypes.instance.vkGetPhysicalDeviceSurfaceFormatsKHR (physical_device, surface, p_surface_format_count, p_surface_formats);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
};

pub const PresentModes = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, surface: vk.KHR.Surface, p_present_mode_count: *u32, p_present_modes: ?[*] vk.KHR.PresentMode) !void
{
const result = raw.prototypes.instance.vkGetPhysicalDeviceSurfacePresentModesKHR (physical_device, surface, p_present_mode_count, @ptrCast (@alignCast (p_present_modes)));
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
};

pub const Support = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, queue_family_index: u32, surface: vk.KHR.Surface) !vk.Bool32
{
var supported: vk.Bool32 = undefined;
const result = raw.prototypes.instance.vkGetPhysicalDeviceSurfaceSupportKHR (physical_device, queue_family_index, surface, &supported);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
return supported;
}
};
};
};

pub const PresentMode = enum (i32)
{
IMMEDIATE_KHR = c.VK_PRESENT_MODE_IMMEDIATE_KHR,
Expand Down
105 changes: 100 additions & 5 deletions src/binding/vk/vk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ pub const Device = enum (usize)
@field (raw.prototypes.device, field.name) = @ptrCast (pointer);
}
}

pub const ExtensionProperties = extern struct
{
pub fn enumerate (physical_device: PhysicalDevice, p_layer_name: ?[*:0] const u8, p_property_count: *u32, p_properties: ?[*] vk.ExtensionProperties) !void
{
const result = raw.prototypes.structless.vkEnumerateDeviceExtensionProperties (physical_device, p_layer_name, p_property_count, p_properties);
if (result > 0)
{
std.debug.print ("{s} failed with {} status code\n", .{ @typeName (@This ()) ++ "." ++ @src ().fn_name, result, });
return error.UnexpectedResult;
}
}
};
};

pub const ExtensionProperties = extern struct
Expand All @@ -119,13 +132,45 @@ pub const Extent2D = extern struct
height: u32,
};

pub const Extent3D = extern struct
{
width: u32,
height: u32,
depth: u32,
};

pub const Fence = enum (u64) { NULL_HANDLE = 0, _, };

pub const Format = enum (i32)
pub const Format = enum (u32)
{
UNDEFINED = c.VK_FORMAT_UNDEFINED,
R4G4_UNORM_PACK8 = c.VK_FORMAT_R4G4_UNORM_PACK8,
A8B8G8R8_UNORM_PACK32 = c.VK_FORMAT_A8B8G8R8_UNORM_PACK32,
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 in (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,
};
};

pub const Framebuffer = enum (u64) { NULL_HANDLE = 0, _, };
Expand Down Expand Up @@ -311,6 +356,19 @@ pub const PhysicalDevice = enum (usize)
}
};

pub const Format = extern struct
{
pub const Properties = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, format: vk.Format) vk.Format.Properties
{
var format_properties: vk.Format.Properties = undefined;
raw.prototypes.instance.vkGetPhysicalDeviceFormatProperties (physical_device, @intFromEnum (format), &format_properties);
return format_properties;
}
};
};

pub const Limits = extern struct
{
max_image_dimension_1d: u32,
Expand Down Expand Up @@ -441,6 +499,17 @@ pub const PhysicalDevice = enum (usize)
}
};

pub const Queue = extern struct
{
pub const FamilyProperties = extern struct
{
pub fn get (physical_device: vk.PhysicalDevice, p_queue_family_property_count: *u32, p_queue_family_properties: ?[*] vk.Queue.FamilyProperties) void
{
raw.prototypes.instance.vkGetPhysicalDeviceQueueFamilyProperties (physical_device, p_queue_family_property_count, p_queue_family_properties);
}
};
};

pub const SparseProperties = extern struct
{
residency_standard_2d_block_shape: vk.Bool32,
Expand All @@ -450,7 +519,10 @@ pub const PhysicalDevice = enum (usize)
residency_non_resident_strict: vk.Bool32,
};

pub const Type = enum (i32) {};
pub const Type = enum (i32)
{
DISCRETE_GPU = c.VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
};
};

pub const PhysicalDevices = extern struct
Expand All @@ -472,7 +544,30 @@ pub const Pipeline = enum (u64)
pub const Layout = enum (u64) { NULL_HANDLE = 0, _, };
};

pub const Queue = enum (usize) { NULL_HANDLE = 0, _, };
pub const Queue = enum (usize)
{
NULL_HANDLE = 0, _,

pub const Flags = u32;

pub const Bit = enum (vk.Queue.Flags)
{
GRAPHICS = c.VK_QUEUE_GRAPHICS_BIT,

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

pub const FamilyProperties = extern struct
{
queue_flags: vk.Queue.Flags = 0,
queue_count: u32,
timestamp_valid_bits: u32,
min_image_transfer_granularity: vk.Extent3D,
};
};

pub const Rect2D = extern struct
{
Expand Down
Loading

0 comments on commit 26cf987

Please sign in to comment.