Skip to content

Commit

Permalink
Merge commit '1e3aa3477e60a05710689c5799751f6a55918071'
Browse files Browse the repository at this point in the history
  • Loading branch information
nurpax committed Apr 30, 2023
2 parents 6c49ae7 + f0a04f4 commit dd20110
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/example_glfw_vulkan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn SetupVulkan(extensions: []const [*:0]const u8, allocator: std.mem.Allocator)
// If a number >1 of GPUs got reported, find discrete GPU if present, or use first one available. This covers
// most common cases (multi-gpu/integrated+dedicated graphics). Handling more complicated setups (multiple
// dedicated GPUs) is out of scope of this sample.
const use_gpu = for (gpus) |gpu, i| {
const use_gpu = for (gpus, 0..) |gpu, i| {
const properties = vk.GetPhysicalDeviceProperties(gpu);
if (properties.deviceType == .DISCRETE_GPU) break i;
} else 0;
Expand All @@ -111,7 +111,7 @@ fn SetupVulkan(extensions: []const [*:0]const u8, allocator: std.mem.Allocator)
var queues = try allocator.alloc(vk.QueueFamilyProperties, count);
defer allocator.free(queues);
_ = vk.GetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, queues);
for (queues) |queue, i| {
for (queues, 0..) |queue, i| {
if (queue.queueFlags.graphics) {
g_QueueFamily = @intCast(u32, i);
break;
Expand Down
11 changes: 6 additions & 5 deletions examples/imgui_impl_vulkan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,15 @@ const __glsl_shader_frag_spv = [_]u32{
fn GetBackendData() ?*Data {
return if (imgui.GetCurrentContext() != null)
@ptrCast(?*Data, @alignCast(@alignOf(Data), imgui.GetIO().BackendRendererUserData))
else null;
else
null;
}

fn MemoryType(properties: vk.MemoryPropertyFlags, type_bits: u32) ?u32 {
const bd = GetBackendData().?;
var v = &bd.VulkanInitInfo;
var prop = vk.GetPhysicalDeviceMemoryProperties(v.PhysicalDevice);
for (prop.memoryTypes[0..prop.memoryTypeCount]) |memType, i|
for (prop.memoryTypes[0..prop.memoryTypeCount], 0..) |memType, i|
if (memType.propertyFlags.hasAllSet(properties) and type_bits & (@as(u32, 1) << @intCast(u5, i)) != 0)
return @intCast(u32, i);
return null; // Unable to find memoryType
Expand Down Expand Up @@ -1062,7 +1063,7 @@ pub fn AddTexture(sampler: vk.Sampler, image_view: vk.ImageView, image_layout: v
const bd = GetBackendData().?;
const v = &bd.VulkanInitInfo;

var descriptor_sets: [1]vk.DescriptorSet = .{ .Null };
var descriptor_sets: [1]vk.DescriptorSet = .{.Null};
try vk.AllocateDescriptorSets(v.Device, .{
.descriptorPool = v.DescriptorPool,
.descriptorSetCount = 1,
Expand Down Expand Up @@ -1287,7 +1288,7 @@ fn CreateWindowSwapChain(physical_device: vk.PhysicalDevice, device: vk.Device,
wd.Frames = try wd.Allocator.alloc(Frame, wd.ImageCount);
wd.FrameSemaphores = try wd.Allocator.alloc(FrameSemaphores, wd.ImageCount);

for (wd.Frames) |*frame, i| frame.* = Frame{ .Backbuffer = imagesResult.swapchainImages[i] };
for (wd.Frames, 0..) |*frame, i| frame.* = Frame{ .Backbuffer = imagesResult.swapchainImages[i] };
for (wd.FrameSemaphores) |*fs| fs.* = FrameSemaphores{};
}
if (old_swapchain != .Null)
Expand Down Expand Up @@ -1393,7 +1394,7 @@ pub fn DestroyWindow(instance: vk.Instance, device: vk.Device, wd: *Window, allo
try vk.DeviceWaitIdle(device); // FIXME: We could wait on the Queue if we had the queue in wd. (otherwise VulkanH functions can't use globals)
//vk.QueueWaitIdle(bd.Queue);

for (wd.Frames) |_, i| {
for (wd.Frames, 0..) |_, i| {
DestroyFrame(device, &wd.Frames[i], allocator);
DestroyFrameSemaphores(device, &wd.FrameSemaphores[i], allocator);
}
Expand Down
3 changes: 2 additions & 1 deletion generate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ where python || goto NO_PYTHON

:PYTHON_GENERATE
@echo Generating Zig Bindings...
python3 "%~dp0\generate.py"
python "%~dp0\generate.py"
zig fmt zig-imgui\imgui.zig

:VENDOR_IMGUI
pushd "%~dp0"
Expand Down
9 changes: 4 additions & 5 deletions template.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn Vector(comptime T: type) type {
var cloned = @This(){};
if (self.Size != 0) {
cloned.resize_undefined(self.Size);
@memcpy(@ptrCast([*]u8, cloned.Data.?), @ptrCast([*]const u8, self.Data.?), self.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, cloned.Data.?)[0..self.Size], @ptrCast([*]const T, self.Data.?));
}
return cloned;
}
Expand All @@ -100,15 +100,15 @@ pub fn Vector(comptime T: type) type {
self.Size = 0;
if (other.Size != 0) {
self.resize_undefined(other.Size);
@memcpy(@ptrCast([*]u8, self.Data.?), @ptrCast([*]const u8, other.Data.?), other.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, self.Data.?)[0..self.Size], @ptrCast([*]const T, other.Data.?));
}
}

pub fn from_slice(slice: []const T) @This() {
var result = @This(){};
if (slice.len != 0) {
result.resize_undefined(@intCast(u32, slice.len));
@memcpy(@ptrCast([*]u8, result.Data.?), @ptrCast([*]const u8, slice.ptr), slice.len * @sizeOf(T));
@memcpy(@ptrCast([*]T, result.Data.?)[0..slice.len], @ptrCast([*]const T, slice.ptr));
}
return result;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn Vector(comptime T: type) type {
const new_data = @ptrCast(?[*]T, @alignCast(@alignOf(T), raw.igMemAlloc(new_capacity * @sizeOf(T))));
if (self.Data) |sd| {
if (self.Size != 0) {
@memcpy(@ptrCast([*]u8, new_data.?), @ptrCast([*]const u8, sd), self.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, new_data.?)[0..self.Size], @ptrCast([*]const T, sd));
}
raw.igMemFree(@ptrCast(*anyopaque, sd));
}
Expand Down Expand Up @@ -439,4 +439,3 @@ pub const allocator: std.mem.Allocator = .{

// ---------------- Everything above here comes from template.zig ------------------
// ---------------- Everything below here is generated -----------------------------

10 changes: 4 additions & 6 deletions zig-imgui/imgui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn Vector(comptime T: type) type {
var cloned = @This(){};
if (self.Size != 0) {
cloned.resize_undefined(self.Size);
@memcpy(@ptrCast([*]u8, cloned.Data.?), @ptrCast([*]const u8, self.Data.?), self.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, cloned.Data.?)[0..self.Size], @ptrCast([*]const T, self.Data.?));
}
return cloned;
}
Expand All @@ -100,15 +100,15 @@ pub fn Vector(comptime T: type) type {
self.Size = 0;
if (other.Size != 0) {
self.resize_undefined(other.Size);
@memcpy(@ptrCast([*]u8, self.Data.?), @ptrCast([*]const u8, other.Data.?), other.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, self.Data.?)[0..self.Size], @ptrCast([*]const T, other.Data.?));
}
}

pub fn from_slice(slice: []const T) @This() {
var result = @This(){};
if (slice.len != 0) {
result.resize_undefined(@intCast(u32, slice.len));
@memcpy(@ptrCast([*]u8, result.Data.?), @ptrCast([*]const u8, slice.ptr), slice.len * @sizeOf(T));
@memcpy(@ptrCast([*]T, result.Data.?)[0..slice.len], @ptrCast([*]const T, slice.ptr));
}
return result;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ pub fn Vector(comptime T: type) type {
const new_data = @ptrCast(?[*]T, @alignCast(@alignOf(T), raw.igMemAlloc(new_capacity * @sizeOf(T))));
if (self.Data) |sd| {
if (self.Size != 0) {
@memcpy(@ptrCast([*]u8, new_data.?), @ptrCast([*]const u8, sd), self.Size * @sizeOf(T));
@memcpy(@ptrCast([*]T, new_data.?)[0..self.Size], @ptrCast([*]const T, sd));
}
raw.igMemFree(@ptrCast(*anyopaque, sd));
}
Expand Down Expand Up @@ -439,7 +439,6 @@ pub const allocator: std.mem.Allocator = .{

// ---------------- Everything above here comes from template.zig ------------------
// ---------------- Everything below here is generated -----------------------------

pub const DrawListSharedData = opaque {};
pub const FontBuilderIO = opaque {};
pub const Context = opaque {};
Expand Down Expand Up @@ -1684,7 +1683,6 @@ pub const Key = enum(i32) {
ReservedForModShift = 649,
ReservedForModAlt = 650,
ReservedForModSuper = 651,

//ImGuiMod_None = 0,
ImGuiMod_Ctrl = 1 << 12,
ImGuiMod_Shift = 1 << 13,
Expand Down

0 comments on commit dd20110

Please sign in to comment.