Skip to content

Conversation

Logickin-Lambda
Copy link

@Logickin-Lambda Logickin-Lambda commented Sep 9, 2025

The commit addresses the outdated zig version used in the library. While most of the code can use the same treatment by updating callconv(.c) and the build structure of build.zig; there are two changes might require follow up though:

As discussed in this issue, we can directly remove the usingnamespace keyword surrounding the function, but since emscripten_sleep(1) is exclusive for emscripten build, I ended up conditionally build the function by checking if the target platform is emscripten; otherwise, it will be an empty function.

var wgpuDeviceTickWarnPrinted: bool = false;

pub fn wgpuDeviceTick() void {
    if (emscripten) {
        if (!wgpuDeviceTickWarnPrinted) {
            std.log.warn("wgpuDeviceTick(): this fn should be avoided! RequestAnimationFrame() is advised for smooth rendering in browser.", .{});
            wgpuDeviceTickWarnPrinted = true;
        }
        emscripten_sleep(1);
    }
}

Since I don't have any emscripten project on hands, I might need others to confirm if this implementation works.

Another change is the use of std.BoundedBuffer which is also deprecated in the 0.15.1, and suggested by the release notes, the substitution is to use ArrayListUnmanaged which will also be removed in the future version; thus, I have to use ArrayList, but because ArrayList requires an allocator for appending items, i ended up choosing fixedBufferAllocator like shown:

// TODO: We support up to 32 command buffers for now. Make it more robust.
var buffer: [32]wgpu.CommandBuffer = undefined;
var fb_allocator = std.heap.FixedBufferAllocator.init(@ptrCast(&buffer));

var command_buffers = std.ArrayList(wgpu.CommandBuffer).initCapacity(fb_allocator.allocator(), 32) catch unreachable;
command_buffers.append(fb_allocator.allocator(), stage_commands) catch unreachable;
command_buffers.appendSlice(fb_allocator.allocator(), commands) catch unreachable;

However, although this solution works and I have successfully to replicate the triangle example from the zig-gamedev with the updated library, the current solution doesn't address the TODO item.

The library has syntax updated to the lastest
zig version; however, because of the usingnamespace
update, this might requires people who use emscripten
to confirm the validity of the new implementation.
Suggested by https://ziglang.org/download/0.15.1/release-notes.html#Removal-of-BoundedArray,
since std.BoundedArray is removed, the alternative is to use
std.ArrayListUnmanaged; however, this type is also soon to be
removed, in favor of std.ArrayList, but since this type
require an allocator for appending the items; because
the array is bounded, I decided to use a fixed buffer,
with creating a fixedBufferAllocator for the arraylist.
@Logickin-Lambda
Copy link
Author

Hmmm... I think I need some help this time, mainly about not familiar with ELF file, and I primary worked on windows. Tried to build the project with linux, and the same error pops up, but there is not much information about where it causes the issue.

@Erdragh
Copy link

Erdragh commented Sep 18, 2025

I'm new to zig, but I can at least get it to get through zig build when I change zdawn to be linked dynamically:

zgpu.patch

@Logickin-Lambda
Copy link
Author

Logickin-Lambda commented Sep 20, 2025

Thanks, added linkage to dynamic, it seems worked without the compile error. Tried to build the project from my testing triangle shader program, and it still works without any issues.

Edit: the change has been committed, and let's see if this is a valid fix.

Suggested by @Erdragh, seems like setting the linkage
for the dawn library could fix the linux build problem,
and not impacted to other platform because running
a testing triangle shader program with zgpu on
windows still works without any issue.

Let's see if this version could pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants