Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xfitgd committed Dec 7, 2024
1 parent 688635f commit 5e73f89
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 74 deletions.
9 changes: 5 additions & 4 deletions examples/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub const CANVAS_H: f32 = 720;

fn error_func(text: []u8, stack_trace: []u8) void {
var fs: file = .{};
fs.open("xfit_err.log", .{
fs.create("xfit_err.log", .{
.truncate = false,
}) catch return;
defer fs.close();
Expand Down Expand Up @@ -130,9 +130,6 @@ pub fn xfit_init() !void {

//graphics.set_render_clear_color(.{ 1, 1, 1, 0 });

var button_src = try components.button.make_square_button_raw(.{ 200, 100 }, 2, arena_alloc);
defer button_src[1].deinit(arena_alloc);

//load and decode test.webp
const data = file_.read_file("test.webp", allocator) catch |e| xfit.herr3("test.webp read_file", e);
defer allocator.free(data);
Expand Down Expand Up @@ -219,6 +216,9 @@ pub fn xfit_init() !void {
//

//build button
var button_src = try components.button.make_square_button_raw(.{ 200, 100 }, 2, arena_alloc);
defer button_src[1].deinit(arena_alloc);

const rect_text_src_raw = try font0.render_string_raw("버튼", .{ .pivot = .{ 0.5, 0.3 }, .scale = .{ 4.5, 4.5 }, .color = .{ 0, 0, 0, 1 } }, allocator);
defer rect_text_src_raw.deinit(allocator);
var concat_button_src = try button_src[1].concat(rect_text_src_raw, allocator);
Expand All @@ -233,6 +233,7 @@ pub fn xfit_init() !void {
rect_button.*.build();

g_rect_button = &rect_button.*._button;

//

//load svg and build
Expand Down
122 changes: 122 additions & 0 deletions src/__vulkan.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,128 @@ pub fn drawFrame() void {
}
}

pub fn draw_offscreen(allocator: std.mem.Allocator, size: ?math.pointu, render_commands: []*render_command) !*graphics.image {
_ = allocator;
_ = size;
if (render_commands.len == 0) xfit.herrm("draw_offscreen render_commands empty");
@trap();

//TODO 함수 나머지 내용은 __vulkan_allocator의 스레드 내에서 실행되어야 함. 왜냐하면 먼저 필요한 이미지 생성이 비동기로 실행되어야 하기 때문이고 전체 비동기 함수로 만든다.
// const cmds = std.heap.c_allocator.alloc(vk.CommandBuffer, render_commands.len + 1) catch xfit.herrm("draw_offscreen cmds alloc");
// defer std.heap.c_allocator.free(cmds);

// const poolInfo: vk.CommandPoolCreateInfo = .{
// .flags = .{ .reset_command_buffer_bit = true },
// .queue_family_index = graphicsFamilyIndex,
// };

// const local_command_pool = vkd.?.createCommandPool(&poolInfo, null) catch |e| xfit.herr3("__vulkan.vulkan_start createCommandPool vkCommandPool", e);
// defer vkd.?.destroyCommandPool(local_command_pool, null);

// const allocInfo: vk.CommandBufferAllocateInfo = .{
// .command_pool = local_command_pool,
// .level = .primary,
// .command_buffer_count = 1 + render_commands.len,
// };
// vkd.?.allocateCommandBuffers(&allocInfo, cmds.ptr) catch |e| xfit.herr3("draw_offscreen allocateCommandBuffers cmds", e);

// var cmdidx: usize = 1;

// for (render_commands) |*cmd| {
// if (@cmpxchgStrong(bool, &cmd.*.*.__refesh, true, false, .monotonic, .monotonic) == null) {
// // recordCommandBuffer(cmd, @intCast(state.frame));
// }
// if (cmd.*.*.scene != null and cmd.*.*.scene.?.len > 0) {
// cmdidx += 1;
// }
// }

// const waitStages: vk.PipelineStageFlags = .{ .color_attachment_output_bit = true };
// var submitInfo: vk.SubmitInfo = .{
// .wait_semaphore_count = 0,
// .command_buffer_count = @intCast(cmdidx),
// .signal_semaphore_count = 0,
// .p_wait_semaphores = null,
// .p_wait_dst_stage_mask = @ptrCast(&waitStages),
// .p_command_buffers = cmds.ptr,
// .p_signal_semaphores = null,
// };

// const cls_color0 = @atomicLoad(f32, &clear_color._0, .monotonic);
// const cls_color1 = @atomicLoad(f32, &clear_color._1, .monotonic);
// const cls_color2 = @atomicLoad(f32, &clear_color._2, .monotonic);
// const cls_color3 = @atomicLoad(f32, &clear_color._3, .monotonic);
// const clearColor: vk.ClearValue = .{ .color = .{ .float_32 = .{ cls_color0, cls_color1, cls_color2, cls_color3 } } };

// const clearDepthStencil: vk.ClearValue = .{ .depth_stencil = .{ .stencil = 0, .depth = 1 } };
// var renderPassInfo: vk.RenderPassBeginInfo = .{
// .render_pass = vkRenderPassClear,
// .framebuffer = vk_swapchain_frame_buffers[imageIndex].clear.res,
// .render_area = .{ .offset = .{ .x = 0, .y = 0 }, .extent = vkExtent_rotation },
// .clear_value_count = 2,
// .p_clear_values = &[_]vk.ClearValue{ clearColor, clearDepthStencil },
// };
// const beginInfo: vk.CommandBufferBeginInfo = .{
// .flags = .{ .one_time_submit_bit = true },
// .p_inheritance_info = null,
// };
// vkd.?.beginCommandBuffer(vkCommandBuffer[state.frame], &beginInfo) catch |e| xfit.herr3("__vulkan.drawFrame.beginCommandBuffer", e);
// vkd.?.cmdBeginRenderPass(vkCommandBuffer[state.frame], &renderPassInfo, .@"inline");
// vkd.?.cmdEndRenderPass(vkCommandBuffer[state.frame]);
// vkd.?.endCommandBuffer(vkCommandBuffer[state.frame]) catch |e| xfit.herr3("__vulkan.drawFrame.endCommandBuffer", e);

// vkd.?.resetFences(1, @ptrCast(&vkInFlightFence[state.frame])) catch |e| xfit.herr3("__vulkan.drawFrame.resetFences", e);

// __vulkan_allocator.submit_mutex.lock();
// vkd.?.queueSubmit(vkGraphicsQueue, 1, @ptrCast(&submitInfo), vkInFlightFence[state.frame]) catch |e| xfit.herr3("__vulkan.drawFrame.queueSubmit", e);
// __vulkan_allocator.submit_mutex.unlock();

// const swapChains = [_]vk.SwapchainKHR{vkSwapchain};

// const presentInfo: vk.PresentInfoKHR = .{
// .wait_semaphore_count = 1,
// .swapchain_count = 1,
// .p_wait_semaphores = @ptrCast(&vkRenderFinishedSemaphore[state.frame]),
// .p_swapchains = @ptrCast(&swapChains),
// .p_image_indices = @ptrCast(&imageIndex),
// };
// __vulkan_allocator.submit_mutex.lock();
// const queuePresentKHR_result = vkd.?.queuePresentKHR(vkPresentQueue, &presentInfo) catch |e| {
// if (e == error.OutOfDateKHR) {
// __vulkan_allocator.submit_mutex.unlock();
// recreate_swapchain();
// return;
// } else if (e == error.SurfaceLostKHR) {
// __vulkan_allocator.submit_mutex.unlock();
// recreateSurface();
// recreate_swapchain();
// return;
// } else {
// xfit.herr3("__vulkan.drawFrame.queuePresentKHR", e);
// }
// };
// __vulkan_allocator.submit_mutex.unlock();

// if (queuePresentKHR_result == .error_out_of_date_khr) {
// recreate_swapchain();
// return;
// } else if (queuePresentKHR_result == .suboptimal_khr) {
// var prop: vk.SurfaceCapabilitiesKHR = undefined;
// prop = vki.?.getPhysicalDeviceSurfaceCapabilitiesKHR(vk_physical_device, vkSurface) catch |e| xfit.herr3("__vulkan.drawFrame.getPhysicalDeviceSurfaceCapabilitiesKHR", e);
// if (prop.current_extent.width != vkExtent.width or prop.current_extent.height != vkExtent.height) {
// recreate_swapchain();
// return;
// }
// } else if (queuePresentKHR_result == .error_surface_lost_khr) {
// recreateSurface();
// recreate_swapchain();
// return;
// } else {
// xfit.herr(queuePresentKHR_result == .success, "__vulkan.drawFrame.vkQueuePresentKHR : {}", .{queuePresentKHR_result});
// }
// state.frame = (state.frame + 1) % render_command.MAX_FRAME;
}

pub fn wait_device_idle() void {
vkd.?.deviceWaitIdle() catch |e| xfit.herr3("__vulkan.deviceWaitIdle", e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/__vulkan_allocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub const descriptor_set = struct {
__set: vk.DescriptorSet = .null_handle,
size: []const descriptor_pool_size,
bindings: []const c_uint,
__res: []const res_union = undefined,
__res: []res_union = undefined,
};

pub fn update_descriptor_sets(sets: []descriptor_set) void {
Expand Down Expand Up @@ -972,7 +972,7 @@ fn append_op(node: operation_node) void {

if (node == .__update_descriptor_sets) {
for (node.__update_descriptor_sets.sets) |*v| {
v.*.__res = @constCast(arena_allocator.allocator().dupe(res_union, v.*.__res) catch unreachable);
v.*.__res = arena_allocator.allocator().dupe(res_union, v.*.__res) catch unreachable;
}
}
op_queue.append(__system.allocator, node) catch xfit.herrm("self.op_queue.append");
Expand Down
4 changes: 2 additions & 2 deletions src/components.zig
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ pub fn button_(_msaa: bool) type {
pub fn deinit(self: *Self) void {
self.*.shape.deinit();
}
pub inline fn deinit_callback(self: *Self, callback: ?*const fn (caller: *anyopaque) void) void {
self.*.shape.deinit_callback(callback);
pub inline fn deinit_callback(self: *Self, callback: ?*const fn (caller: *anyopaque) void, data: anytype) void {
self.*.shape.deinit_callback(callback, data);
}
pub fn __draw(self: *Self, cmd: vk.CommandBuffer) void {
self.*.shape.__draw(cmd);
Expand Down
7 changes: 5 additions & 2 deletions src/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ hFile: std.fs.File = .{ .handle = INVALID_FILE_HANDLE },
pub inline fn is_open(self: *Self) bool {
return self.hFile.handle != INVALID_FILE_HANDLE;
}
pub inline fn open(self: *Self, path: []const u8, create_flags: std.fs.File.CreateFlags) !void {
pub inline fn create(self: *Self, path: []const u8, create_flags: std.fs.File.CreateFlags) !void {
self.hFile = try std.fs.cwd().createFile(path, create_flags);
}
pub inline fn open(self: *Self, path: []const u8, open_flags: std.fs.File.OpenFlags) !void {
self.hFile = try std.fs.cwd().openFile(path, open_flags);
}
pub inline fn read(self: *Self, buffer: []u8) !usize {
return try self.hFile.read(buffer);
}
Expand Down Expand Up @@ -58,7 +61,7 @@ pub inline fn reader(self: *Self) std.fs.File.Reader {
pub fn read_file(path: []const u8, allocator: std.mem.Allocator) ![]u8 {
var buffer: []u8 = undefined;

const _file = try std.fs.cwd().createFile(path, .{ .read = true, .truncate = false });
const _file = try std.fs.cwd().openFile(path, .{});
defer _file.close();
const _size = (try _file.stat()).size;

Expand Down
Loading

0 comments on commit 5e73f89

Please sign in to comment.