forked from mirror/vulkan-zig
Adapt to latest Zig master
See ziglang/zig/pull/10055
This commit is contained in:
@@ -93,7 +93,7 @@ pub const GraphicsContext = struct {
|
||||
graphics_queue: Queue,
|
||||
present_queue: Queue,
|
||||
|
||||
pub fn init(allocator: *Allocator, app_name: [*:0]const u8, window: *c.GLFWwindow) !GraphicsContext {
|
||||
pub fn init(allocator: Allocator, app_name: [*:0]const u8, window: *c.GLFWwindow) !GraphicsContext {
|
||||
var self: GraphicsContext = undefined;
|
||||
self.vkb = try BaseDispatch.load(c.glfwGetInstanceProcAddress);
|
||||
|
||||
@@ -236,7 +236,7 @@ const QueueAllocation = struct {
|
||||
fn pickPhysicalDevice(
|
||||
vki: InstanceDispatch,
|
||||
instance: vk.Instance,
|
||||
allocator: *Allocator,
|
||||
allocator: Allocator,
|
||||
surface: vk.SurfaceKHR,
|
||||
) !DeviceCandidate {
|
||||
var device_count: u32 = undefined;
|
||||
@@ -259,7 +259,7 @@ fn pickPhysicalDevice(
|
||||
fn checkSuitable(
|
||||
vki: InstanceDispatch,
|
||||
pdev: vk.PhysicalDevice,
|
||||
allocator: *Allocator,
|
||||
allocator: Allocator,
|
||||
surface: vk.SurfaceKHR,
|
||||
) !?DeviceCandidate {
|
||||
const props = vki.getPhysicalDeviceProperties(pdev);
|
||||
@@ -283,7 +283,7 @@ fn checkSuitable(
|
||||
return null;
|
||||
}
|
||||
|
||||
fn allocateQueues(vki: InstanceDispatch, pdev: vk.PhysicalDevice, allocator: *Allocator, surface: vk.SurfaceKHR) !?QueueAllocation {
|
||||
fn allocateQueues(vki: InstanceDispatch, pdev: vk.PhysicalDevice, allocator: Allocator, surface: vk.SurfaceKHR) !?QueueAllocation {
|
||||
var family_count: u32 = undefined;
|
||||
vki.getPhysicalDeviceQueueFamilyProperties(pdev, &family_count, null);
|
||||
|
||||
@@ -329,7 +329,7 @@ fn checkSurfaceSupport(vki: InstanceDispatch, pdev: vk.PhysicalDevice, surface:
|
||||
fn checkExtensionSupport(
|
||||
vki: InstanceDispatch,
|
||||
pdev: vk.PhysicalDevice,
|
||||
allocator: *Allocator,
|
||||
allocator: Allocator,
|
||||
) !bool {
|
||||
var count: u32 = undefined;
|
||||
_ = try vki.enumerateDeviceExtensionProperties(pdev, null, &count, null);
|
||||
|
||||
@@ -10,7 +10,7 @@ pub const Swapchain = struct {
|
||||
};
|
||||
|
||||
gc: *const GraphicsContext,
|
||||
allocator: *Allocator,
|
||||
allocator: Allocator,
|
||||
|
||||
surface_format: vk.SurfaceFormatKHR,
|
||||
present_mode: vk.PresentModeKHR,
|
||||
@@ -21,11 +21,11 @@ pub const Swapchain = struct {
|
||||
image_index: u32,
|
||||
next_image_acquired: vk.Semaphore,
|
||||
|
||||
pub fn init(gc: *const GraphicsContext, allocator: *Allocator, extent: vk.Extent2D) !Swapchain {
|
||||
pub fn init(gc: *const GraphicsContext, allocator: Allocator, extent: vk.Extent2D) !Swapchain {
|
||||
return try initRecycle(gc, allocator, extent, .null_handle);
|
||||
}
|
||||
|
||||
pub fn initRecycle(gc: *const GraphicsContext, allocator: *Allocator, extent: vk.Extent2D, old_handle: vk.SwapchainKHR) !Swapchain {
|
||||
pub fn initRecycle(gc: *const GraphicsContext, allocator: Allocator, extent: vk.Extent2D, old_handle: vk.SwapchainKHR) !Swapchain {
|
||||
const caps = try gc.vki.getPhysicalDeviceSurfaceCapabilitiesKHR(gc.pdev, gc.surface);
|
||||
const actual_extent = findActualExtent(caps, extent);
|
||||
if (actual_extent.width == 0 or actual_extent.height == 0) {
|
||||
@@ -243,7 +243,7 @@ const SwapImage = struct {
|
||||
}
|
||||
};
|
||||
|
||||
fn initSwapchainImages(gc: *const GraphicsContext, swapchain: vk.SwapchainKHR, format: vk.Format, allocator: *Allocator) ![]SwapImage {
|
||||
fn initSwapchainImages(gc: *const GraphicsContext, swapchain: vk.SwapchainKHR, format: vk.Format, allocator: Allocator) ![]SwapImage {
|
||||
var count: u32 = undefined;
|
||||
_ = try gc.vkd.getSwapchainImagesKHR(gc.dev, swapchain, &count, null);
|
||||
const images = try allocator.alloc(vk.Image, count);
|
||||
@@ -264,7 +264,7 @@ fn initSwapchainImages(gc: *const GraphicsContext, swapchain: vk.SwapchainKHR, f
|
||||
return swap_images;
|
||||
}
|
||||
|
||||
fn findSurfaceFormat(gc: *const GraphicsContext, allocator: *Allocator) !vk.SurfaceFormatKHR {
|
||||
fn findSurfaceFormat(gc: *const GraphicsContext, allocator: Allocator) !vk.SurfaceFormatKHR {
|
||||
const preferred = vk.SurfaceFormatKHR{
|
||||
.format = .b8g8r8a8_srgb,
|
||||
.color_space = .srgb_nonlinear_khr,
|
||||
@@ -285,7 +285,7 @@ fn findSurfaceFormat(gc: *const GraphicsContext, allocator: *Allocator) !vk.Surf
|
||||
return surface_formats[0]; // There must always be at least one supported surface format
|
||||
}
|
||||
|
||||
fn findPresentMode(gc: *const GraphicsContext, allocator: *Allocator) !vk.PresentModeKHR {
|
||||
fn findPresentMode(gc: *const GraphicsContext, allocator: Allocator) !vk.PresentModeKHR {
|
||||
var count: u32 = undefined;
|
||||
_ = try gc.vki.getPhysicalDeviceSurfacePresentModesKHR(gc.pdev, gc.surface, &count, null);
|
||||
const present_modes = try allocator.alloc(vk.PresentModeKHR, count);
|
||||
|
||||
@@ -224,7 +224,7 @@ fn copyBuffer(gc: *const GraphicsContext, pool: vk.CommandPool, dst: vk.Buffer,
|
||||
fn createCommandBuffers(
|
||||
gc: *const GraphicsContext,
|
||||
pool: vk.CommandPool,
|
||||
allocator: *Allocator,
|
||||
allocator: Allocator,
|
||||
buffer: vk.Buffer,
|
||||
extent: vk.Extent2D,
|
||||
render_pass: vk.RenderPass,
|
||||
@@ -291,12 +291,12 @@ fn createCommandBuffers(
|
||||
return cmdbufs;
|
||||
}
|
||||
|
||||
fn destroyCommandBuffers(gc: *const GraphicsContext, pool: vk.CommandPool, allocator: *Allocator, cmdbufs: []vk.CommandBuffer) void {
|
||||
fn destroyCommandBuffers(gc: *const GraphicsContext, pool: vk.CommandPool, allocator: Allocator, cmdbufs: []vk.CommandBuffer) void {
|
||||
gc.vkd.freeCommandBuffers(gc.dev, pool, @truncate(u32, cmdbufs.len), cmdbufs.ptr);
|
||||
allocator.free(cmdbufs);
|
||||
}
|
||||
|
||||
fn createFramebuffers(gc: *const GraphicsContext, allocator: *Allocator, render_pass: vk.RenderPass, swapchain: Swapchain) ![]vk.Framebuffer {
|
||||
fn createFramebuffers(gc: *const GraphicsContext, allocator: Allocator, render_pass: vk.RenderPass, swapchain: Swapchain) ![]vk.Framebuffer {
|
||||
const framebuffers = try allocator.alloc(vk.Framebuffer, swapchain.swap_images.len);
|
||||
errdefer allocator.free(framebuffers);
|
||||
|
||||
@@ -319,7 +319,7 @@ fn createFramebuffers(gc: *const GraphicsContext, allocator: *Allocator, render_
|
||||
return framebuffers;
|
||||
}
|
||||
|
||||
fn destroyFramebuffers(gc: *const GraphicsContext, allocator: *Allocator, framebuffers: []const vk.Framebuffer) void {
|
||||
fn destroyFramebuffers(gc: *const GraphicsContext, allocator: Allocator, framebuffers: []const vk.Framebuffer) void {
|
||||
for (framebuffers) |fb| gc.vkd.destroyFramebuffer(gc.dev, fb, null);
|
||||
allocator.free(framebuffers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user