Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void {

const registry = b.dependency("vulkan_headers", .{}).path("registry/vk.xml");
const shader_compiler = b.dependency("shader_compiler", .{
.target = b.host,
.target = target,
.optimize = .ReleaseFast,
}).artifact("shader_compiler");

Expand All @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.link_libc = true,
});
exe.linkSystemLibrary("vulkan");
exe.linkSystemLibrary(if (target.result.os.tag == .windows) "vulkan-1" else "vulkan");
exe.linkSystemLibrary("xcb");
b.installArtifact(exe);

Expand Down
15 changes: 8 additions & 7 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
.{
.name = "vulkan-triangle-example",
.name = .vulkan_triangle_example,
.fingerprint = 0xf097961d7296a5b3,
.version = "0.0.0",
.minimum_zig_version = "0.14.0-dev.1359+e9a00ba7f",

.dependencies = .{
.vulkan = .{
.url = "git+https://github.com/andrewrk/vulkan-zig.git#b6e589d62bc1d9070c47d73ce942168fb92624c8",
.hash = "12201e484e173e70634e664864763223427703e677f28c63ebec9332513c8ca5121c",
.url = "git+https://github.com/Snektron/vulkan-zig.git#c66bddee009a8c4b71082ab7af723ed885161650",
.hash = "vulkan-0.0.0-r7YtxwZVAwDbCFXX5GpnS436SfBec9INY0zq-2OQ2BUp",
},
.vulkan_headers = .{
.url = "https://github.com/KhronosGroup/Vulkan-Headers/archive/v1.3.283.tar.gz",
.hash = "1220a7e73d72a0d56bc2a65f9d8999a7c019e42260a0744c408d1cded111bc205e10",
.url = "https://github.com/KhronosGroup/Vulkan-Headers/archive/v1.4.318.tar.gz",
.hash = "N-V-__8AAMij4AF5GEdLDdD4cLQXQQkzIhgsX3LcMZ7Tx4Gn",
},
.shader_compiler = .{
.url = "git+https://github.com/andrewrk/shader_compiler.git#89550bb2cbe85276bd1fd89d020f3bbd686937c3",
.hash = "12207b775b98ac87f583d5ca95386537432c22f4bc83bc0c7fd9d6cbfdf265cc0444",
.url = "https://github.com/Games-by-Mason/shader_compiler/archive/refs/tags/v0.1.0.tar.gz",
.hash = "shader_compiler-1.0.0-bOVsasuGAADsqQPvVDRD-bSkQCwDBQx06dVyrQws0EFK",
},
},

Expand Down
48 changes: 12 additions & 36 deletions src/GraphicsContext.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,13 @@ const GraphicsContext = @This();

const required_device_extensions = [_][*:0]const u8{vk.extensions.khr_swapchain.name};

/// To construct base, instance and device wrappers for vulkan-zig, you need to pass a list of 'apis' to it.
const apis: []const vk.ApiInfo = &.{
// You can either add invidiual functions by manually creating an 'api'
.{
.base_commands = .{
.createInstance = true,
.enumerateInstanceLayerProperties = true,
},
.instance_commands = .{
.createDevice = true,
.createXcbSurfaceKHR = true,
},
},
// Or you can add entire feature sets or extensions
vk.features.version_1_0,
vk.extensions.khr_surface,
vk.extensions.khr_swapchain,
vk.extensions.ext_debug_utils,
};

/// Next, pass the `apis` to the wrappers to create dispatch tables.
const BaseDispatch = vk.BaseWrapper(apis);
const InstanceDispatch = vk.InstanceWrapper(apis);
const DeviceDispatch = vk.DeviceWrapper(apis);

// Also create some proxying wrappers, which also have the respective handles
const Instance = vk.InstanceProxy(apis);
const Device = vk.DeviceProxy(apis);
const BaseDispatch = vk.BaseWrapper;
const InstanceDispatch = vk.InstanceWrapper;
const DeviceDispatch = vk.DeviceWrapper;
const Instance = vk.InstanceProxy;
const Device = vk.DeviceProxy;

pub const CommandBuffer = vk.CommandBufferProxy(apis);
pub const CommandBuffer = vk.CommandBufferProxy;

allocator: Allocator,

Expand All @@ -54,7 +31,6 @@ debug_messenger: vk.DebugUtilsMessengerEXT,

const vkGetInstanceProcAddr = @extern(vk.PfnGetInstanceProcAddr, .{
.name = "vkGetInstanceProcAddr",
.library_name = "vulkan",
});

pub fn init(
Expand All @@ -66,14 +42,14 @@ pub fn init(
) !GraphicsContext {
var self: GraphicsContext = undefined;
self.allocator = allocator;
self.vkb = try BaseDispatch.load(vkGetInstanceProcAddr);
self.vkb = BaseDispatch.load(vkGetInstanceProcAddr);

const app_info: vk.ApplicationInfo = .{
.p_application_name = app_name,
.application_version = vk.makeApiVersion(0, 0, 0, 0),
.application_version = @bitCast(vk.makeApiVersion(0, 0, 0, 0)),
.p_engine_name = app_name,
.engine_version = vk.makeApiVersion(0, 0, 0, 0),
.api_version = vk.API_VERSION_1_2,
.engine_version = @bitCast(vk.makeApiVersion(0, 0, 0, 0)),
.api_version = @bitCast(vk.API_VERSION_1_2),
};

var extension_names_buffer: [3][*:0]const u8 = undefined;
Expand Down Expand Up @@ -101,7 +77,7 @@ pub fn init(

const vki = try allocator.create(InstanceDispatch);
errdefer allocator.destroy(vki);
vki.* = try InstanceDispatch.load(instance, self.vkb.dispatch.vkGetInstanceProcAddr);
vki.* = InstanceDispatch.load(instance, self.vkb.dispatch.vkGetInstanceProcAddr.?);
self.instance = Instance.init(instance, vki);
errdefer self.instance.destroyInstance(null);

Expand Down Expand Up @@ -132,7 +108,7 @@ pub fn init(

const vkd = try allocator.create(DeviceDispatch);
errdefer allocator.destroy(vkd);
vkd.* = try DeviceDispatch.load(dev, self.instance.wrapper.dispatch.vkGetDeviceProcAddr);
vkd.* = DeviceDispatch.load(dev, self.instance.wrapper.dispatch.vkGetDeviceProcAddr.?);
self.dev = Device.init(dev, vkd);
errdefer self.dev.destroyDevice(null);

Expand Down