@@ -9,40 +9,47 @@ const Self = @This();
99pub const ObjectType : vk.ObjectType = .instance ;
1010
1111common_instance : common.Instance ,
12- physical_device : dispatchable . Dispatchable ( PhysicalDevice ) , // Software driver only has one physical device (CPU)
12+ physical_device : vk. PhysicalDevice , // Software driver only has one physical device (CPU)
1313
1414pub fn create (p_infos : ? * const vk.InstanceCreateInfo , callbacks : ? * const vk.AllocationCallbacks , p_instance : * vk.Instance ) callconv (vk .vulkan_call_conv ) vk.Result {
1515 const allocator = std .heap .c_allocator ;
1616
17- const dispatchable_object = dispatchable .Dispatchable (Self ).create (allocator , ObjectType ) catch return .error_out_of_host_memory ;
18- common .Instance .init (& dispatchable_object .object .common_instance , p_infos , callbacks ) catch return .error_initialization_failed ;
17+ const dispatchable_instance = dispatchable .Dispatchable (Self ).create (allocator ) catch return .error_out_of_host_memory ;
18+ const instance = dispatchable_instance .object ;
19+ common .Instance .init (& instance .common_instance , p_infos , callbacks ) catch return .error_initialization_failed ;
1920
20- dispatchable_object . object .common_instance .vtable = .{
21+ instance .common_instance .vtable = .{
2122 .destroyInstance = destroy ,
2223 .enumeratePhysicalDevices = enumeratePhysicalDevices ,
2324 .enumerateInstanceVersion = null ,
2425 //.enumerateInstanceLayerProperties = null,
2526 .enumerateInstanceExtensionProperties = null ,
27+ .getPhysicalDeviceProperties = PhysicalDevice .getProperties ,
2628 };
2729
28- dispatchable_object .object .physical_device .init () catch return .error_initialization_failed ;
30+ const dispatchable_physical_device = dispatchable .Dispatchable (PhysicalDevice ).create (allocator ) catch return .error_out_of_host_memory ;
31+ PhysicalDevice .init (dispatchable_physical_device .object ) catch return .error_initialization_failed ;
32+ instance .physical_device = @enumFromInt (dispatchable_physical_device .toHandle ());
2933
30- p_instance .* = @enumFromInt (dispatchable .toHandle (Self , dispatchable_object ));
34+ p_instance .* = @enumFromInt (dispatchable_instance .toHandle ());
3135 return .success ;
3236}
3337
34- pub fn enumeratePhysicalDevices (p_instance : vk.Instance , count : * u32 , devices : * vk.PhysicalDevice ) callconv (vk .vulkan_call_conv ) vk.Result {
35- const dispatchable_object = common .dispatchable .fromHandle (Self , @intFromEnum (p_instance )) catch return .error_initialization_failed ;
36- _ = dispatchable_object ;
37- _ = count ;
38- _ = devices ;
38+ pub fn enumeratePhysicalDevices (p_instance : vk.Instance , count : * u32 , p_devices : ? [* ]vk.PhysicalDevice ) callconv (vk .vulkan_call_conv ) vk.Result {
39+ const instance = dispatchable .fromHandleObject (Self , @intFromEnum (p_instance )) catch return .error_initialization_failed ;
40+ count .* = 1 ;
41+ if (p_devices ) | devices | {
42+ devices [0 ] = instance .physical_device ;
43+ }
3944 return .success ;
4045}
4146
4247pub fn destroy (p_instance : vk.Instance , callbacks : ? * const vk.AllocationCallbacks ) callconv (vk .vulkan_call_conv ) void {
4348 const allocator = std .heap .c_allocator ;
4449 _ = callbacks ;
4550
46- const dispatchable_object = common .dispatchable .fromHandle (Self , @intFromEnum (p_instance )) catch return ;
47- dispatchable_object .destroy (allocator );
51+ const dispatchable_instance = dispatchable .fromHandle (Self , @intFromEnum (p_instance )) catch return ;
52+ const dispatchable_physical_device = dispatchable .fromHandle (PhysicalDevice , @intFromEnum (dispatchable_instance .object .physical_device )) catch return ;
53+ dispatchable_physical_device .destroy (allocator );
54+ dispatchable_instance .destroy (allocator );
4855}
0 commit comments