Skip to content

Commit 64af182

Browse files
committed
adding VK_KHR_get_physical_device_properties2 and bug fixes
1 parent 48af5e3 commit 64af182

13 files changed

Lines changed: 290 additions & 72 deletions

build.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn build(b: *std.Build) !void {
3131
});
3232

3333
const zdt = b.dependency("zdt", .{}).module("zdt");
34+
const zigrc = b.dependency("zigrc", .{}).module("zigrc");
3435
const vulkan_headers = b.dependency("vulkan_headers", .{});
3536
const vulkan_utility_libraries = b.dependency("vulkan_utility_libraries", .{});
3637

@@ -39,6 +40,7 @@ pub fn build(b: *std.Build) !void {
3940
}).module("vulkan-zig");
4041

4142
base_mod.addImport("zdt", zdt);
43+
base_mod.addImport("zigrc", zigrc);
4244
base_mod.addImport("vulkan", vulkan);
4345
base_mod.addSystemIncludePath(vulkan_headers.path("include"));
4446
base_mod.addSystemIncludePath(vulkan_utility_libraries.path("include"));
@@ -184,7 +186,7 @@ fn addCTS(b: *std.Build, target: std.Build.ResolvedTarget, impl: *const Implemen
184186
}));
185187

186188
const mustpass = try cts.path(
187-
b.fmt("mustpass/{}.{}.0/vk-default.txt", .{
189+
b.fmt("mustpass/{}.{}.2/vk-default.txt", .{
188190
impl.vulkan_version.major,
189191
impl.vulkan_version.minor,
190192
}),

build.zig.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
.url = "git+https://github.com/Kbz-8/Vulkan-CTS-bin#19ce2da05f8176348064a9fc6688847e5f76a46e",
3030
.hash = "N-V-__8AAHDV0xtS93nAGaYd7YWxBLnvHDEplwIpC29izSGa",
3131
},
32+
.zigrc = .{
33+
.url = "https://github.com/Aandreba/zigrc/archive/refs/tags/1.1.0.tar.gz",
34+
.hash = "zigrc-1.0.0-lENlWzvQAACulrbkL9PVhWjFsWSkYhi7AmfSbCM-2Xlh",
35+
},
3236
.cpuinfo = .{
3337
.url = "git+https://github.com/Kbz-8/cpuinfo#4883954cfcec3f6c9ca9c4aaddfc26107e08726f",
3438
.hash = "cpuinfo-0.0.1-RLgIQTLRMgF4dLo8AJ-HvnpFsJe6jmXCJjMWWjil6RF1",

src/soft/SoftCommandBuffer.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ pub fn copyBuffer(interface: *Interface, src: *base.Buffer, dst: *base.Buffer, r
8989
_ = regions;
9090
}
9191

92-
pub fn copyImage(interface: *Interface, src: *base.Image, dst: *base.Image, regions: []const vk.ImageCopy) VkError!void {
92+
pub fn copyImage(interface: *Interface, src: *base.Image, src_layout: vk.ImageLayout, dst: *base.Image, dst_layout: vk.ImageLayout, regions: []const vk.ImageCopy) VkError!void {
9393
// No-op
9494
_ = interface;
9595
_ = src;
96+
_ = src_layout;
9697
_ = dst;
98+
_ = dst_layout;
9799
_ = regions;
98100
}
99101

src/soft/SoftInstance.zig

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ pub const Interface = base.Instance;
1212

1313
interface: Interface,
1414

15+
fn castExtension(comptime ext: vk.ApiInfo) vk.ExtensionProperties {
16+
var props: vk.ExtensionProperties = .{
17+
.extension_name = undefined,
18+
.spec_version = @bitCast(ext.version),
19+
};
20+
@memcpy(props.extension_name[0..ext.name.len], ext.name);
21+
return props;
22+
}
23+
24+
pub const EXTENSIONS = [_]vk.ExtensionProperties{
25+
castExtension(vk.extensions.khr_get_physical_device_properties_2),
26+
};
27+
1528
pub fn create(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) VkError!*Interface {
1629
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
1730
errdefer allocator.destroy(self);
1831

1932
self.interface = try base.Instance.init(allocator, infos);
2033
self.interface.dispatch_table = &.{
21-
.destroyInstance = destroyInstance,
34+
.destroy = destroy,
2235
};
2336
self.interface.vtable = &.{
2437
.requestPhysicalDevices = requestPhysicalDevices,
@@ -27,6 +40,11 @@ pub fn create(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo)
2740
return &self.interface;
2841
}
2942

43+
fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
44+
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
45+
allocator.destroy(self);
46+
}
47+
3048
fn requestPhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
3149
// Software driver has only one physical device (the CPU)
3250
const physical_device = try SoftPhysicalDevice.create(allocator, interface);
@@ -42,8 +60,3 @@ fn releasePhysicalDevices(interface: *Interface, allocator: std.mem.Allocator) V
4260
interface.physical_devices.deinit(allocator);
4361
interface.physical_devices = .empty;
4462
}
45-
46-
fn destroyInstance(interface: *Interface, allocator: std.mem.Allocator) VkError!void {
47-
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
48-
allocator.destroy(self);
49-
}

src/soft/SoftPhysicalDevice.zig

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
3030
.getFormatProperties = getFormatProperties,
3131
.getImageFormatProperties = getImageFormatProperties,
3232
.getSparseImageFormatProperties = getSparseImageFormatProperties,
33+
.getSparseImageFormatProperties2 = getSparseImageFormatProperties2,
3334
.release = destroy,
3435
};
3536

@@ -670,21 +671,42 @@ pub fn getImageFormatProperties(
670671
};
671672
}
672673

674+
/// Soft does not support sparse images.
673675
pub fn getSparseImageFormatProperties(
674676
interface: *Interface,
675677
format: vk.Format,
676678
image_type: vk.ImageType,
677679
samples: vk.SampleCountFlags,
678680
tiling: vk.ImageTiling,
679681
usage: vk.ImageUsageFlags,
680-
flags: vk.ImageCreateFlags,
681-
) VkError!vk.SparseImageFormatProperties {
682+
properties: ?[*]vk.SparseImageFormatProperties,
683+
) VkError!u32 {
682684
_ = interface;
683685
_ = format;
684686
_ = image_type;
685687
_ = samples;
686688
_ = tiling;
687689
_ = usage;
688-
_ = flags;
689-
return undefined;
690+
_ = properties;
691+
return 0;
692+
}
693+
694+
/// Soft does not support sparse images.
695+
pub fn getSparseImageFormatProperties2(
696+
interface: *Interface,
697+
format: vk.Format,
698+
image_type: vk.ImageType,
699+
samples: vk.SampleCountFlags,
700+
tiling: vk.ImageTiling,
701+
usage: vk.ImageUsageFlags,
702+
properties: ?[*]vk.SparseImageFormatProperties2,
703+
) VkError!u32 {
704+
_ = interface;
705+
_ = format;
706+
_ = image_type;
707+
_ = samples;
708+
_ = tiling;
709+
_ = usage;
710+
_ = properties;
711+
return 0;
690712
}

src/vulkan/CommandBuffer.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const DispatchTable = struct {
4242
begin: *const fn (*Self, *const vk.CommandBufferBeginInfo) VkError!void,
4343
clearColorImage: *const fn (*Self, *Image, vk.ImageLayout, *const vk.ClearColorValue, []const vk.ImageSubresourceRange) VkError!void,
4444
copyBuffer: *const fn (*Self, *Buffer, *Buffer, []const vk.BufferCopy) VkError!void,
45-
copyImage: *const fn (*Self, *Image, *Image, []const vk.ImageCopy) VkError!void,
45+
copyImage: *const fn (*Self, *Image, vk.ImageLayout, *Image, vk.ImageLayout, []const vk.ImageCopy) VkError!void,
4646
end: *const fn (*Self) VkError!void,
4747
fillBuffer: *const fn (*Self, *Buffer, vk.DeviceSize, vk.DeviceSize, u32) VkError!void,
4848
reset: *const fn (*Self, vk.CommandBufferResetFlags) VkError!void,
@@ -153,14 +153,16 @@ pub inline fn copyBuffer(self: *Self, src: *Buffer, dst: *Buffer, regions: []con
153153
try self.dispatch_table.copyBuffer(self, src, dst, regions);
154154
}
155155

156-
pub inline fn copyImage(self: *Self, src: *Image, dst: *Image, regions: []const vk.ImageCopy) VkError!void {
156+
pub inline fn copyImage(self: *Self, src: *Image, src_layout: vk.ImageLayout, dst: *Image, dst_layout: vk.ImageLayout, regions: []const vk.ImageCopy) VkError!void {
157157
const allocator = self.host_allocator.allocator();
158158
self.commands.append(allocator, .{ .CopyImage = .{
159159
.src = src,
160+
.src_layout = src_layout,
160161
.dst = dst,
162+
.dst_layout = dst_layout,
161163
.regions = allocator.dupe(vk.ImageCopy, regions) catch return VkError.OutOfHostMemory,
162164
} }) catch return VkError.OutOfHostMemory;
163-
try self.dispatch_table.copyImage(self, src, dst, regions);
165+
try self.dispatch_table.copyImage(self, src, src_layout, dst, dst_layout, regions);
164166
}
165167

166168
pub inline fn fillBuffer(self: *Self, buffer: *Buffer, offset: vk.DeviceSize, size: vk.DeviceSize, data: u32) VkError!void {

src/vulkan/Device.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub fn createQueues(self: *Self, allocator: std.mem.Allocator, info: *const vk.D
9999

100100
const queue = try self.vtable.createQueue(allocator, self, queue_info.queue_family_index, @intCast(family_ptr.items.len), queue_info.flags);
101101

102-
logger.manager.get().indent();
103-
defer logger.manager.get().unindent();
102+
logger.getManager().get().indent();
103+
defer logger.getManager().get().unindent();
104104

105105
const dispatchable_queue = try Dispatchable(Queue).wrap(allocator, queue);
106106
family_ptr.append(allocator, dispatchable_queue) catch return VkError.OutOfHostMemory;

src/vulkan/Instance.zig

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ comptime {
1515
if (!@hasDecl(root, "VULKAN_VERSION")) {
1616
@compileError("Missing VULKAN_VERSION in module root");
1717
}
18+
if (!@hasDecl(root.Instance, "EXTENSIONS")) {
19+
@compileError("Missing EXTENSIONS in Instance's implementation");
20+
}
1821
}
1922
}
2023

@@ -31,7 +34,7 @@ pub const VTable = struct {
3134
};
3235

3336
pub const DispatchTable = struct {
34-
destroyInstance: *const fn (*Self, std.mem.Allocator) VkError!void,
37+
destroy: *const fn (*Self, std.mem.Allocator) VkError!void,
3538
};
3639

3740
pub fn init(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo) VkError!Self {
@@ -53,18 +56,19 @@ pub fn create(allocator: std.mem.Allocator, infos: *const vk.InstanceCreateInfo)
5356

5457
pub fn deinit(self: *Self, allocator: std.mem.Allocator) VkError!void {
5558
try self.releasePhysicalDevices(allocator);
56-
try self.dispatch_table.destroyInstance(self, allocator);
59+
try self.dispatch_table.destroy(self, allocator);
5760
}
5861

59-
pub fn enumerateExtensionProperties(layer_name: ?[]const u8, property_count: *u32, properties: ?*vk.ExtensionProperties) VkError!void {
62+
pub fn enumerateExtensionProperties(layer_name: ?[]const u8, count: *u32, p_properties: ?[*]vk.ExtensionProperties) VkError!void {
6063
if (layer_name) |_| {
6164
return VkError.LayerNotPresent;
6265
}
63-
64-
_ = properties;
65-
_ = std.StaticStringMap(vk.ExtensionProperties).initComptime(.{});
66-
67-
property_count.* = 0;
66+
count.* = root.Instance.EXTENSIONS.len;
67+
if (p_properties) |properties| {
68+
for (root.Instance.EXTENSIONS, 0..) |ext, i| {
69+
properties[i] = ext;
70+
}
71+
}
6872
}
6973

7074
pub fn enumerateVersion(version: *u32) VkError!void {
@@ -80,8 +84,8 @@ pub fn releasePhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError
8084
}
8185

8286
pub fn requestPhysicalDevices(self: *Self, allocator: std.mem.Allocator) VkError!void {
83-
logger.manager.get().indent();
84-
defer logger.manager.get().unindent();
87+
logger.getManager().get().indent();
88+
defer logger.getManager().get().unindent();
8589

8690
try self.vtable.requestPhysicalDevices(self, allocator);
8791
if (self.physical_devices.items.len == 0) {

src/vulkan/PhysicalDevice.zig

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub const DispatchTable = struct {
2020
createDevice: *const fn (*Self, std.mem.Allocator, *const vk.DeviceCreateInfo) VkError!*Device,
2121
getFormatProperties: *const fn (*Self, vk.Format) VkError!vk.FormatProperties,
2222
getImageFormatProperties: *const fn (*Self, vk.Format, vk.ImageType, vk.ImageTiling, vk.ImageUsageFlags, vk.ImageCreateFlags) VkError!vk.ImageFormatProperties,
23-
getSparseImageFormatProperties: *const fn (*Self, vk.Format, vk.ImageType, vk.SampleCountFlags, vk.ImageTiling, vk.ImageUsageFlags, vk.ImageCreateFlags) VkError!vk.SparseImageFormatProperties,
23+
getSparseImageFormatProperties: *const fn (*Self, vk.Format, vk.ImageType, vk.SampleCountFlags, vk.ImageTiling, vk.ImageUsageFlags, ?[*]vk.SparseImageFormatProperties) VkError!u32,
24+
getSparseImageFormatProperties2: ?*const fn (*Self, vk.Format, vk.ImageType, vk.SampleCountFlags, vk.ImageTiling, vk.ImageUsageFlags, ?[*]vk.SparseImageFormatProperties2) VkError!u32,
2425
release: *const fn (*Self, std.mem.Allocator) VkError!void,
2526
};
2627

@@ -67,7 +68,7 @@ pub fn getImageFormatProperties(
6768
usage: vk.ImageUsageFlags,
6869
flags: vk.ImageCreateFlags,
6970
) VkError!vk.ImageFormatProperties {
70-
return try self.dispatch_table.getImageFormatProperties(self, format, image_type, tiling, usage, flags);
71+
return self.dispatch_table.getImageFormatProperties(self, format, image_type, tiling, usage, flags);
7172
}
7273

7374
pub fn getSparseImageFormatProperties(
@@ -77,9 +78,24 @@ pub fn getSparseImageFormatProperties(
7778
samples: vk.SampleCountFlags,
7879
tiling: vk.ImageTiling,
7980
usage: vk.ImageUsageFlags,
80-
flags: vk.ImageCreateFlags,
81-
) VkError!vk.SparseImageFormatProperties {
82-
return try self.dispatch_table.getSparseImageFormatProperties(self, format, image_type, samples, tiling, usage, flags);
81+
properties: ?[*]vk.SparseImageFormatProperties,
82+
) VkError!u32 {
83+
return self.dispatch_table.getSparseImageFormatProperties(self, format, image_type, samples, tiling, usage, properties);
84+
}
85+
86+
pub fn getSparseImageFormatProperties2(
87+
self: *Self,
88+
format: vk.Format,
89+
image_type: vk.ImageType,
90+
samples: vk.SampleCountFlags,
91+
tiling: vk.ImageTiling,
92+
usage: vk.ImageUsageFlags,
93+
properties: ?[*]vk.SparseImageFormatProperties2,
94+
) VkError!u32 {
95+
return if (self.dispatch_table.getSparseImageFormatProperties2) |pfn|
96+
pfn(self, format, image_type, samples, tiling, usage, properties)
97+
else
98+
0;
8399
}
84100

85101
pub fn releasePhysicalDevice(self: *Self, allocator: std.mem.Allocator) VkError!void {

src/vulkan/commands.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ pub const CommandCopyBuffer = struct {
3838
};
3939
pub const CommandCopyImage = struct {
4040
src: *Image,
41+
src_layout: vk.ImageLayout,
4142
dst: *Image,
43+
dst_layout: vk.ImageLayout,
4244
regions: []const vk.ImageCopy,
4345
};
4446
pub const CommandDraw = struct {

0 commit comments

Comments
 (0)