Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples to be compatible with self-hosted #26

Merged
merged 4 commits into from
Nov 3, 2022

Conversation

kcbanner
Copy link
Contributor

@kcbanner kcbanner commented Aug 28, 2022

All the examples (except for instancing.zig) run for me on self-hosted (Windows, x86_64) in both opengl and directx. I did notice the point size seems different between dx and gl for sgl-points, but this seems true with -fstage1 as well.

The instancing.zig example crashes on self-hosted with a stack overflow, at the start of frame(). Debugging this, it seems that it tries to pass ~40M to ___chkstk_ms, which comes from lib/compiler_rt/stack_probe.zig. I recall seeing some activity about this so this may just be a self-hosted bug. I only have access to Windows, so it may not affect other platforms. This may also be related to the issue with structs being copied on to the stack (ziglang/zig#12638) but I'm not familiar with how the stack probe is supposed to work, so I can't say without more investigating.

…ed, change Mat4 to extern struct as arrays in packed structs are no longer supported
@jeffkdev
Copy link

My own zig implementation of the sokol instancing example is is actually what triggered this issue: ziglang/zig#12568

If you do a similar workaround to the one I posted there you can probably get the instancing to work on stage2 too.

@jeffkdev
Copy link

For reference, this is what my update loop looks like now on my side (I don't have the data wrapped in a state struct and just use the sokol c code directly, so maybe it won't work here):

    {
        var i: u32 = 0;
        // update particle positions
        while (i < cur_num_particles) : (i += 1) {
            const particle_pos =  &pos[i];
            const particle_vel =  &vel[i];

            particle_vel.y -= frame_time;
            particle_pos.* = particle_pos.add(particle_vel.scl(frame_time));
            // bounce back from 'ground'
            if (particle_pos.y < -2.0) {
                particle_vel.y = -1.8;
                particle_vel.y = -particle_vel.y;
                particle_vel.x *= 0.8;
                particle_vel.y *= 0.8;
                particle_vel.z *= 0.8;
            }
        }
    }

@kcbanner
Copy link
Contributor Author

Ah, thanks! Indeed that workaround works here as well, just added the change. Cheers!

@floooh floooh marked this pull request as draft October 16, 2022 18:08
@floooh
Copy link
Owner

floooh commented Oct 16, 2022

Ok, I have merged this PR manually into a new sokol-zig branch 0.10.0:

https://github.com/floooh/sokol-zig/tree/zig-0.10.0

...once Zig 0.10.0 is officially released, I'll merge that back into master, and (hopefully), this PR should then automatically resolve too.

PS: ...and I have converted this PR to a draft so that I don't accidentally press the merge button ...

PPS: many thanks for the PR :)

@floooh floooh merged commit 9e22cf6 into floooh:master Nov 3, 2022
@floooh
Copy link
Owner

floooh commented Nov 3, 2022

...and it's in master now.

@kcbanner
Copy link
Contributor Author

kcbanner commented Nov 3, 2022

awesome!

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.

3 participants