Feature checking at instance.zig | ImGui example README.md
This commit is contained in:
parent
8c7421b978
commit
b7d2d46e8b
9 changed files with 68 additions and 18 deletions
6
examples/imgui/README.md
Normal file
6
examples/imgui/README.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# ImGui Example
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Used dear_bindings with docking imgui branch
|
||||||
|
https://mrscriptx.github.io/devlog/zig/2025/04/30/zig-linking-dear-imgui.html
|
||||||
BIN
examples/imgui/image.png
Normal file
BIN
examples/imgui/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
|
|
@ -45,9 +45,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
|
|
||||||
// --- # ---
|
// --- # ---
|
||||||
const instance = try gfx.makeInstance(.{
|
const instance = try gfx.makeInstance(.{
|
||||||
.vulkan = .{
|
.vulkan = .{},
|
||||||
.api_version = .v1_3,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const surface = try gfx.makeSurface(.{
|
const surface = try gfx.makeSurface(.{
|
||||||
|
|
@ -58,7 +56,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
}, instance);
|
}, instance);
|
||||||
|
|
||||||
const adapter = try gfx.makeAdapter(.{}, instance);
|
const adapter = try gfx.makeAdapter(.{}, instance);
|
||||||
const device = try gfx.makeDevice(adapter, surface);
|
const device = try gfx.makeDevice(instance, adapter, surface);
|
||||||
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
|
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ pub fn main(init: std.process.Init) !void {
|
||||||
const instance = try gfx.makeInstance(.{
|
const instance = try gfx.makeInstance(.{
|
||||||
.vulkan = .{
|
.vulkan = .{
|
||||||
.api_version = .v1_3,
|
.api_version = .v1_3,
|
||||||
|
.vk_14_features = .{
|
||||||
|
.dynamic_rendering_local_read = false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -59,7 +62,7 @@ pub fn main(init: std.process.Init) !void {
|
||||||
}, instance);
|
}, instance);
|
||||||
|
|
||||||
const adapter = try gfx.makeAdapter(.{}, instance);
|
const adapter = try gfx.makeAdapter(.{}, instance);
|
||||||
const device = try gfx.makeDevice(adapter, surface);
|
const device = try gfx.makeDevice(instance, adapter, surface);
|
||||||
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
|
const swapchain = try gfx.makeSwapchain(adapter, device, surface);
|
||||||
|
|
||||||
// --- TEXTURES ---
|
// --- TEXTURES ---
|
||||||
|
|
|
||||||
|
|
@ -208,11 +208,12 @@ pub fn getRawAdapter(self: *Self, adapter: Handle(Adapter)) !RawAdapter {
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn makeDevice(
|
pub fn makeDevice(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
instance: Handle(Instance),
|
||||||
adapter: Handle(Adapter),
|
adapter: Handle(Adapter),
|
||||||
surface: Handle(Surface),
|
surface: Handle(Surface),
|
||||||
) !Handle(Device) {
|
) !Handle(Device) {
|
||||||
return try switch ((try self.getBackend()).*) {
|
return try switch ((try self.getBackend()).*) {
|
||||||
.vulkan => |*v| v.makeDevice(adapter, surface),
|
.vulkan => |*v| v.makeDevice(instance, adapter, surface),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ pub const VK13Features = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const VK14Features = struct {
|
pub const VK14Features = struct {
|
||||||
dynamic_rendering_local_read: bool = true,
|
dynamic_rendering_local_read: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DeviceType = enum {
|
pub const DeviceType = enum {
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,12 @@
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
const Adapter = @import("adapter.zig");
|
|
||||||
const Surface = @import("surface.zig");
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
|
const Instance = @import("instance.zig");
|
||||||
|
const Surface = @import("surface.zig");
|
||||||
|
const Adapter = @import("adapter.zig");
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub const QueueFamilies = struct {
|
pub const QueueFamilies = struct {
|
||||||
|
|
@ -28,19 +30,41 @@ graphics_command_pool: *vk.VkCommandPool_T,
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn init(
|
pub fn init(
|
||||||
adapter: *Adapter,
|
instance: *const Instance,
|
||||||
surface: *Surface,
|
adapter: *const Adapter,
|
||||||
|
surface: *const Surface,
|
||||||
alloc: std.mem.Allocator,
|
alloc: std.mem.Allocator,
|
||||||
) !Self {
|
) !Self {
|
||||||
// --- # ---
|
|
||||||
const extensions: []const [*:0]const u8 = &.{
|
const extensions: []const [*:0]const u8 = &.{
|
||||||
"VK_KHR_swapchain",
|
"VK_KHR_swapchain",
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- # ---
|
var features14: vk.VkPhysicalDeviceVulkan14Features = .{
|
||||||
|
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_4_FEATURES,
|
||||||
|
.dynamicRenderingLocalRead = @intFromBool(instance.vk_14_features.dynamic_rendering_local_read),
|
||||||
|
};
|
||||||
|
|
||||||
var features13: vk.VkPhysicalDeviceVulkan13Features = .{
|
var features13: vk.VkPhysicalDeviceVulkan13Features = .{
|
||||||
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
|
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
|
||||||
.dynamicRendering = vk.VK_TRUE,
|
.dynamicRendering = @intFromBool(instance.vk_13_features.dynamic_rendering),
|
||||||
|
.synchronization2 = @intFromBool(instance.vk_13_features.synchronization2),
|
||||||
|
.pNext = &features14,
|
||||||
|
};
|
||||||
|
|
||||||
|
var features12: vk.VkPhysicalDeviceVulkan12Features = .{
|
||||||
|
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
|
||||||
|
.pNext = &features13,
|
||||||
|
};
|
||||||
|
|
||||||
|
var features11: vk.VkPhysicalDeviceVulkan11Features = .{
|
||||||
|
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES,
|
||||||
|
.shaderDrawParameters = @intFromBool(instance.vk_11_features.shader_draw_parameters),
|
||||||
|
.pNext = &features12,
|
||||||
|
};
|
||||||
|
|
||||||
|
var features: vk.VkPhysicalDeviceFeatures2 = .{
|
||||||
|
.sType = vk.VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
|
||||||
|
.pNext = &features11,
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- FIND QUEUE FAMILIES ---
|
// --- FIND QUEUE FAMILIES ---
|
||||||
|
|
@ -73,15 +97,13 @@ pub fn init(
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- DEVICE CREATE INFO ---
|
// --- DEVICE CREATE INFO ---
|
||||||
var features: vk.VkPhysicalDeviceFeatures = .{};
|
|
||||||
var create_info: vk.VkDeviceCreateInfo = .{
|
var create_info: vk.VkDeviceCreateInfo = .{
|
||||||
.sType = vk.VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
.sType = vk.VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
.pQueueCreateInfos = &queue_create_infos,
|
.pQueueCreateInfos = &queue_create_infos,
|
||||||
.queueCreateInfoCount = queue_create_info_count,
|
.queueCreateInfoCount = queue_create_info_count,
|
||||||
.pEnabledFeatures = &features,
|
|
||||||
.enabledExtensionCount = extensions.len,
|
.enabledExtensionCount = extensions.len,
|
||||||
.ppEnabledExtensionNames = extensions.ptr,
|
.ppEnabledExtensionNames = extensions.ptr,
|
||||||
.pNext = &features13,
|
.pNext = &features,
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- # ---
|
// --- # ---
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,24 @@ vk_14_features: cmn.VK14Features,
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn init(config: cmn.VKInstanceConfig, alloc: std.mem.Allocator) !Self {
|
pub fn init(config: cmn.VKInstanceConfig, alloc: std.mem.Allocator) !Self {
|
||||||
|
// --- ENSURE CORRECT FEATURES ---
|
||||||
|
switch (config.api_version) {
|
||||||
|
.v1_0, .v1_1, .v1_2 => {
|
||||||
|
if (config.vk_14_features.dynamic_rendering_local_read or
|
||||||
|
config.vk_13_features.dynamic_rendering or
|
||||||
|
config.vk_13_features.synchronization2)
|
||||||
|
{
|
||||||
|
return error.FeatureNotSupported;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.v1_3 => {
|
||||||
|
if (config.vk_14_features.dynamic_rendering_local_read) {
|
||||||
|
return error.FeatureNotSupported;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.v1_4 => {},
|
||||||
|
}
|
||||||
|
|
||||||
const validation_layers: []const [*:0]const u8 = &.{
|
const validation_layers: []const [*:0]const u8 = &.{
|
||||||
"VK_LAYER_KHRONOS_validation",
|
"VK_LAYER_KHRONOS_validation",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -206,12 +206,14 @@ pub fn getRawAdapter(self: *Self, adapter: Handle(Adapter)) !*vk.VkPhysicalDevic
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
pub fn makeDevice(
|
pub fn makeDevice(
|
||||||
self: *Self,
|
self: *Self,
|
||||||
|
instance: Handle(common.Instance),
|
||||||
adapter: Handle(Adapter),
|
adapter: Handle(Adapter),
|
||||||
surface: Handle(Surface),
|
surface: Handle(Surface),
|
||||||
) !Handle(Device) {
|
) !Handle(Device) {
|
||||||
|
const raw_instance = self.resource.instances.get(instance) orelse return error.InstanceNotFound;
|
||||||
const raw_adapter = self.resource.adapters.get(adapter) orelse return error.AdapterNotFound;
|
const raw_adapter = self.resource.adapters.get(adapter) orelse return error.AdapterNotFound;
|
||||||
const raw_surface = self.resource.surfaces.get(surface) orelse return error.SurfaceNotFound;
|
const raw_surface = self.resource.surfaces.get(surface) orelse return error.SurfaceNotFound;
|
||||||
return try self.resource.devices.put(try .init(raw_adapter, raw_surface, self.alloc));
|
return try self.resource.devices.put(try .init(raw_instance, raw_adapter, raw_surface, self.alloc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ----------------------------------------------------
|
/// ----------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue