dimenus has quit [Remote host closed the connection]
dimenus has joined #zig
<fengb>
Yeah that’s a good point
_Vi has quit [Ping timeout: 252 seconds]
qazo has joined #zig
<dimenus>
wow, i cannot believe how much sampling from an MSAA buffer costs in performance
<dimenus>
(this is in Vulkan)
<dimenus>
MSAA vs non-MSAA halves my framerate (but has barely any effect if I don't do any post processing)
<shakesoda>
dimenus: even worse, the performance is vastly different between vendors
<dimenus>
i think i'm overcreating buffers though, shouldn't need an MSAA buffer / render target per swapchain
<shakesoda>
on some mobile hardware the msaa is full rate and you mostly have to worry about the resolve cost
<fengb>
I’m actually happy that nobody is complaining about my leak detector. Literally slapped together without any forethought
<shakesoda>
there's also all kinds of gotchas, like if you actually use the sample id in your shader then you get more pixel shader invocations (iirc you can avoid this, but i don't remember the details)
<dimenus>
5500 fps to 2700 fps from using MSAA
<dimenus>
it's still faster than the GL clone, but nowhere near the 4x I originally had
<dimenus>
in short, MSAA on a shader attachment is super expensive
<shakesoda>
eh, the fps makes it sound a lot worse
<dimenus>
yeah, my frame time is still ~0.5ms :P
<shakesoda>
it's a bad relative difference, but that's still pretty dang fast :)
<dimenus>
but the numbers!
<dimenus>
this is obviously a simple game, but I love how Vulkan forces you out of the OO style
<shakesoda>
good, oo style is an insanely bad habit for doing renderers
<shakesoda>
i have to get on people's cases a lot for shooting themselves in the foot trying to abstract GL that way
<dimenus>
i have barely any uniforms in this program, just a textures essentially
<dimenus>
*just for textures
<shakesoda>
i haven't got too many uniforms in general anymore, most stuff ends up in ubo/ssbos unless it truly needs to change per draw
<dimenus>
this is on a RX550 btw
<dimenus>
eer isn't a uniform a ubo?
<dimenus>
or am i confused
<dimenus>
Vulkan only has blocks, no standalone uniforms
<shakesoda>
aye, i'm on GL
<shakesoda>
vulkan renderer is a bit stillborn, haven't had the need to complete that project
mgxm has quit [Ping timeout: 260 seconds]
mgxm_ has joined #zig
mgxm_ is now known as mgxm
<dimenus>
this project is about 5k lines so far
<shakesoda>
when i think 5k lines and vulkan i think "ah, a triangle"
<shakesoda>
:P
<dimenus>
hah! it's not that bad. I'm not including the zig generated vulkan headers
<dimenus>
if i do that it's 30k
<dimenus>
that's including the cimports for a couple libraries though, not just vulkan
<shakesoda>
30k D:
<shakesoda>
at least it's just generated code, i guess
<shakesoda>
i think my entire engine currently amounts to something like 50k
<dimenus>
how do you handle a uniform of arrays in gl, does it make a copy in the background and align them to 16 bytes?
<Snektron>
Dimenus, its logical that fps is slower with MSAA of course
<Snektron>
Especially considering 5500 fps on a 550 means youre not doing a lot
<dimenus>
Snektron: agreed, but didn't think it would be 50%
mahmudov has quit [Ping timeout: 265 seconds]
<dimenus>
without rendering to a shader attachment, it barely even hicked up when adding MSAA
<dimenus>
*hiccuped
<Snektron>
4x msaa is rendering at 4 times higher resolution, so 50% is alright
<Snektron>
This one time i changed one variable in my compute shader and doubled performance
<Snektron>
Anyway, if youre not doing a lot of rendering, anything can have a large impact
<Snektron>
Because the whole shader switching thing has a lot of overhead
<Snektron>
Its probably more fair to test the difference when you render a lot of things
<shakesoda>
dimenus: i have everything packed into vec4's to maintain 16 byte alignment without really doing anything special
<shakesoda>
no magic
sean2 has quit [Ping timeout: 265 seconds]
<Snektron>
In vulkan theres this nice feature called push constants
<Snektron>
You can embed a shader variable directly in a command stream
<Snektron>
Its really efficient for things that update every frame
<shakesoda>
sounds like a regular uniform in gl?
<Snektron>
Hm i dont know, depends on implementation
<Snektron>
I expect opengl to do a staging buffer kind of thing in the background
<dimenus>
Snektron: not sure if you missed some of the convo earlier, but the only uniform blocks i'm using are for textures / combined samplers
<dimenus>
indices and small values all come of push constants
<dimenus>
the other nice thing is that push constants are align(4)
<Snektron>
Instead of align(16) you mean?
<dimenus>
yep, I just wrapped uniform types in a struct and that solved the issue
<Snektron>
Isnt any glsl value aligned by its size, up to 16 bytes
<dimenus>
no, arrays are 16 regardless of size
<Snektron>
I see
<dimenus>
eg vec2 would be align(8) but vec2 foo[3] would be align(16)
<Snektron>
Hm, i thought it rounded up
<dimenus>
And MSAA is just overkill for a breakout clone, it's only rendering at 800x600 :D
<Snektron>
dimenus, i assume you saw that im working on a zig generator from vk.xml
<dimenus>
nice
<Snektron>
Do you happen to have any feature requests?
<shakesoda>
dimenus: think of the smooth edges you could have on the backgrounds!
<shakesoda>
of course it's not overkill! ;)
<dimenus>
no, i'm not an idea man and i don't work for a game dev company - so I don't really have a business case for Vulkan. I just wanted to try building the learnopengl.com breakout clone in zig/vulkan
<dimenus>
and see how fast I could makme it
<dimenus>
but i apprecate the thought, I'll let you know if I need something :)
<Snektron>
Currently i mostly have default values for some struct fields (like sType), error sets instead if VkResult, more accurate pointer types, and stuff like that
<dimenus>
those are all nice to haves, i went through the generated code and set a good chunk of defaults, but i haven't touched any code I don't need yet
<dimenus>
default struct init is a really nice feature to have in a language with Vulkan's API
<Snektron>
Doesn't matter if youre a professional game dev or not (im certainly not), just if you maybe thought "this would be useful"
<Snektron>
Yeah, its mostly just about nice-to-haves
<Snektron>
Stuff that cant be expressed in C but can in zig, and happens to be defined in vk.xml
<Snektron>
Theres also information about optional types but i was told that its incorrect
<Snektron>
Too bad
<dimenus>
50% performance was at 8x btw, definitely overkill for 800x600 :P
<shakesoda>
8x is always overkill :P
<fengb>
I have an important question
<shakesoda>
unless you've got some special needs, at least (i.e. msaa trick + additional msaa... but i haven't seen anyone do that in a while)
<fengb>
How should the community name projects? Java likes to append 4j, Python prepends Py, etc
<fengb>
We need a dumb standard
<shakesoda>
i'm fine with zig-whatever or just nothing
<companion_cube>
suffix with -zag
<shakesoda>
zig-thing-zag
<companion_cube>
(which means zig becomes zig-zag, badum-tss)
<companion_cube>
yep
<shakesoda>
i like the (old and now somewhat discouraged) love2d library naming scheme of "plausibly deniable sexual innuendo"
<shakesoda>
alas, it has fallen out of favor
<companion_cube>
like, weboob?
<shakesoda>
usually a bit more subtle than that, although not always
<Snektron>
Java also prepends j
<companion_cube>
just suffix your project name with `.comptime`
<companion_cube>
(or prefix?)
<pmwhite>
comptime-websockets
<companion_cube>
there's a ring to it, right?
<pmwhite>
I'm not sure what I would think when I see that title. I don't want my program to require an internet connection while it compiles.
<pmwhite>
It has google-ability going for it though.
<companion_cube>
it'd be a private joke in the community, is all :p
rom1504 has quit [Ping timeout: 245 seconds]
rom1504 has joined #zig
return0e has joined #zig
return0e has quit [Ping timeout: 240 seconds]
seoushi has joined #zig
<seoushi>
so I made a basic zig uild file based off the tetris project. It references the root source file main.zig. I want to start writing a lot of code but not nessiarly put anything in main.zig yet. If I import the file it seems like ti doesn't compile it till I reference the struct in the file. Is there a better way to just add files to the build script or something to force compilation? I can't seem to find any documentation on
<andrewrk>
zig has lazy analysis, so you will have to reference things before they are checked by the compiler
<andrewrk>
one thing you can do is to add unit tests
<seoushi>
ok
<seoushi>
thanks
<andrewrk>
even something as simple as `test "stuff" { _ = foo; }` will now semantically analyze `foo` when you run `zig test file.zig`
<seoushi>
is this true for libraries as well? or just executables? I would figure that libraries would evaulate everything marked with pub?
<andrewrk>
exported symbols are entry points
<andrewrk>
but a zig package to be used by other zig code is subject to the same lazy analysis rules
<andrewrk>
this is an acknowledged issue, with open github issues related to it
<seoushi>
ok
<andrewrk>
note that any programming language that has generic functions suffers from this same problem. it's just that in zig, generic functions and regular functions are treated less differently
<andrewrk>
nofmal, it looks like termios is a POSIX standard, which means that it's a good candidate to go into lib/std/os.zig, following the pattern of the other functions there
<nofmal>
yes. i've only tested it in my machine (linux x86_64)
<nofmal>
well either way i cannot be sure if it works perfectly in bsd
<nofmal>
the only differences from what i've looked is that, in powerpc, the `NCCS` constant is 19 instead of 32
<nofmal>
anything else is the same
nofmal75 has joined #zig
nofmal75 has quit [Remote host closed the connection]
<andrewrk>
still, if you are considering submitting it as a pull request to zig, it should be structured in a way so that bsd programmers will be able to contribute to
nofmal14 has joined #zig
<andrewrk>
(the structure of the existing things in std.os)
ajl has joined #zig
ajl has quit [Client Quit]
ajl has joined #zig
nofmal has quit [Ping timeout: 268 seconds]
ajl has quit [Client Quit]
nofmal14 has quit [Remote host closed the connection]
ajl has joined #zig
lunamn_ has joined #zig
ur5us has joined #zig
lunamn has quit [Ping timeout: 272 seconds]
dddddd has quit [Remote host closed the connection]
<ajl>
A function in a C library is returning a value of type [*c]const u8. I believe that means a c style pointer to a const u8, and I think its actually a null terminated array of const u8. Is there any way to cast that array into a zig style []const u8 string?
<andrewrk>
ajl, `[]const u8` needs to know the length. you can convert with std.mem.toSliceConst(u8, your_c_ptr)
<ajl>
That was exactly what I was looking for. Thank you.
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 260 seconds]
marmotini_ has joined #zig
ajl has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
return0e has joined #zig
ltriant has quit [Quit: leaving]
return0e has quit [Ping timeout: 268 seconds]
adamkowalski has quit [Remote host closed the connection]
adamkowalski has joined #zig
<adamkowalski>
How do I include a file that is in the parent directory? when I did @import("../foo.zig"); I get an error 19: error: import of file outside package path: '../util/array_info.zig'
<adamkowalski>
When I test by doing zig test src/main.zig everything passes however, it's only when trying to test files within the nested folder
jabb has joined #zig
jabb is now known as gruebite
<gruebite>
heyo, i'm getting this when compiling master: zig_clang_cc1as_main.cpp:511:23: error: ‘Value’ may be used uninitialized in this function
<gruebite>
clang version 9.0.1
<adamkowalski>
whats your os?
<gruebite>
linux
<gruebite>
Linux zork 5.4.13-arch1-1 #1 SMP PREEMPT Fri, 17 Jan 2020 23:09:54 +0000 x86_64 GNU/Linux
<adamkowalski>
hmm, i'm on arch and I'm running master build just fine. Did you run `pacman -Sy clang cmake gcc llvm lld`
<gruebite>
yeah, good there. weird
<adamkowalski>
how are you compiling? mkdir build; cd build; cmake -G Ninja ..; cmake --build .;
<adamkowalski>
I also usually throw on a release flag
_whitelogger has joined #zig
<gruebite>
got it working, thanks
<gruebite>
is c"foo" still a thing? i'm getting an error and can't find any documentation
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #zig
<gruebite>
foo_struct.@"bar" is interesting. i do not anything for accessing it at runtime? for anonymous lists it would be useful for callee's to iterate over the struct members at compile time
<gruebite>
runtime/compiletime
marmotini_ has quit [Ping timeout: 268 seconds]
<gruebite>
can i purposefully disqualify const qualify if say... c code doesn't have a const function pointer?
<fengb>
The nuclear option: @intToPtr(*T, @ptrToInt(ptr_const))
<gruebite>
heh
<gruebite>
for every function pointer D:
<gruebite>
i'm dealing with an api that heavily uses function pointers (dynamic plugins, register callbacks all the time)
<gruebite>
i had a patch file that just added consts everywhere but i don't like that solution
<traviss>
it looks like the lhs of == between @Vector(4, usize) usize is being turned into @Vector(4, u64) inside a function but not outside of it
_Vi has joined #zig
return0e has joined #zig
bheads has quit [Quit: bheads]
bheads has joined #zig
eagle2com has joined #zig
_Vi has quit [Ping timeout: 260 seconds]
bav has joined #zig
Demos[m] has quit [Quit: User has been idle for 30+ days.]
<betawaffle>
how does one define a function with is_var_args == true?
<betawaffle>
does that just mean "has at least one argument with type `var`", or is it related to variable-length argument lists?
waleee-cl has joined #zig
forgot-password has joined #zig
<Snektron>
traviss, i think boolean operators aren't implemented yet for vectors
<Snektron>
or at least not properly
marmotini_ has joined #zig
eagle2com has quit [Read error: Connection reset by peer]
eagle2com has joined #zig
marmotini_ has quit [Ping timeout: 260 seconds]
doublex_ has joined #zig
doublex__ has quit [Ping timeout: 265 seconds]
dddddd has joined #zig
sean2 has joined #zig
sean2 has quit [Ping timeout: 265 seconds]
Snetry has quit [Ping timeout: 240 seconds]
bav has quit [Remote host closed the connection]
_Vi has joined #zig
Snetry has joined #zig
<traviss>
Snektron, == does work for other vector types. in the example i linked, i can do `const v = v1 == v2` where v1 and v2 are @Vector(4, usize). the issue is when i try that inside a function. i think v1 gets interpreted as @Vector(4, u64) and there is a compiler error.
<traviss>
also errors for isize. the error goes away if the vectors are declared as u64.
<Snektron>
i see, i actually ran into that issue before too
<traviss>
i couldn't find a github issue so i wanted to see there's already one created
<andrewrk>
nice work on finding and fixing BufMap value leak
<fengb>
👍 I hope this ref counting is good enough™ for now. I had to fix a few errors so my biggest fear is false negatives
Snetry has quit [Ping timeout: 252 seconds]
<fengb>
For the builder, I think it'd be even better if it auto creates an arena so it always does the correct thing. But until we get the optional shrink, chaining arenas seems to degenerate a bit
<andrewrk>
that makes sense
<andrewrk>
ugh annoying time for sourcehut to shit the bed
<andrewrk>
I'm pretty sure the only admin is on a plane to FOSDEM
<fengb>
The parseList needs to happen before assigning the arena
<Snektron>
yeah, i've noticed a few cases in the std where theres a workaround for that
<fengb>
I'm glad the leak detection is working :D
metaleap has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
<betawaffle>
is it always safe to assume *c_void and usize are the same size? can i use either one for a field in an `extern struct`?
<andrewrk>
zig target cpu/features already having a wider ecosystem impact: https://clbin.com/i3zFL
<andrewrk>
betawaffle, yes, usize is defined to be the size of pointers
<betawaffle>
when the package manager is a thing, is the std library going to be... uhh... pluggable?
<Snektron>
I never understood why there are different types for size_t and intptr_t
<betawaffle>
size_t is unsigned and intptr_t is signed, right?
<Snektron>
you're thinking of ptrdiff_t
<Snektron>
oh nevermind
<Snektron>
theres also an uintptr_t
<andrewrk>
I think there were once upon a time, systems that had pointers of different sizes than registers
<Snektron>
because why not
decentpenguin has quit [Quit: decentpenguin]
<andrewrk>
betawaffle, what use case specifically are you thinking of?
<betawaffle>
andrewrk: this very moment, byo event loop?
<andrewrk>
event loop is already pluggable
<betawaffle>
oh?
<betawaffle>
i suppose there are probably a lot of things like that, but there's no documentation yet
<andrewrk>
yeah
<andrewrk>
I was also considering whether making an event loop an interface would make sense. kinda like Allocator
phillyiscool has joined #zig
<betawaffle>
i think that could be good, yeah
<companion_cube>
(are event loops going to be composable as well? :p)
<betawaffle>
speaking of interfaces... the documentation really needs to discuss them, at least a little
<phillyiscool>
Something I'm curious about, if you want to libraries that are consumable from C using Zig, does this mean you can't use comptime (and possibly other Zig features)?
<betawaffle>
because afaict, there are already a number of them in std, and i don't know what they are or how to use them
<companion_cube>
amen to this betawaffle
<andrewrk>
phillyiscool, only types that are compatible with the C ABI are available when exporting symbols
<betawaffle>
what i want is to be able to have per-thread event loops
<andrewrk>
betawaffle, that's already a thing too
<companion_cube>
if you use zig with libuv and jemalloc… are you cheating? :D
<andrewrk>
betawaffle, oops, spoke too soon. I think there are a couple problems to solve to make that work. but that's planned too
<andrewrk>
the way zig does async functions makes this possible:
<andrewrk>
switchToGuiThread();
<betawaffle>
i want resume/suspend to have atomics be optional
tane has joined #zig
<fengb>
Ah so do generators :P
<andrewrk>
betawaffle, yes I've been thinking about that too
<andrewrk>
you can use --single-threaded to avoid that, but it's a global setting
<phillyiscool>
andrewrk Thanks. What do you recommend when you want to have both a C ABI and a "nicer" Zig API? Write a low-level C compatible layer and "wrap" that with Zig niceness?
<betawaffle>
because sometimes you have your own locking wrapping the resume/suspend stuff
<andrewrk>
phillyiscool, other way around. have a nice zig package api, and wrap it with a C compatible layer
<phillyiscool>
How is that possible if the nice zig package depends on comptime? The C layer can't use that, right?
<andrewrk>
the parameters of the exported function cannot. but the function implementation can call zig functions
<phillyiscool>
Hm, ok thank you very much. I'm currently working on something where I do this. I haven't gotten to the point yet where I can have more feedback but hopefully I can share something soon.
<phillyiscool>
Would love to write an article or something on this to share with the community once I've figured out how to do it.
<andrewrk>
you can have pointers to zig types in exported functions
dingenskirchen has joined #zig
<companion_cube>
why hello this is a void*
dingenskirchen has quit [Remote host closed the connection]
<andrewrk>
better yet it can be a fwd struct decl
eagle2com has quit [Ping timeout: 268 seconds]
_Vi has quit [Ping timeout: 272 seconds]
phillyiscool has quit [Remote host closed the connection]
marmotini_ has joined #zig
qazo has quit [Ping timeout: 260 seconds]
dingenskirchen has joined #zig
ajl has joined #zig
ajl has quit [Client Quit]
<betawaffle>
hmm... what's the "right" way to read errno in zig?
<andrewrk>
you can see a lot of examples of this in std/os.zig
<andrewrk>
without knowing any more about what you're doing, the right way might be contributing another function to os.zig
<betawaffle>
it's a function that returns a file descriptor, or -1 + sets errno
<betawaffle>
which is such a stupid interface, why do people suck
<andrewrk>
ok so you're interfacing with a third party c library that messes with errno
<metaleap>
(unless someone took a stab at that somewhere? havent searched tbh. std.meta is helpful but here wouldnt save all that much)
<betawaffle>
you could definitely break that into functions
<metaleap>
yeah there's even some structurual repetition of similar test-and-traverse paths 3x in there so, sure. thats the first step towards a comptime-reflection-queryer-lib/api/lang
<mq32>
metaleap, that can be written much easier
<betawaffle>
what you need is the equivilent of rust's `if let Variant(...) = ...` stuff
<metaleap>
mq32: thats what i hoped! :P
<companion_cube>
and use `return false;` early
<companion_cube>
betawaffle: but you can do that here
<mq32>
you are NOT required to switch on tagged unions
<adamkowalski>
If I run zig test src/lazy/add.zig then I get this error. However, I run zig test src/main.zig which itself references lazy/add.zig then everything works fine
<andrewrk>
adamkowalski, --main-pkg-path ..
<andrewrk>
we're in a bit of a transition to packages, bear with me
<adamkowalski>
thanks that works!
<adamkowalski>
well it's not a big issue, my entire test suite runs in 0.08 seconds since zig is awesome
_Vi has joined #zig
wootehfoot has joined #zig
<metaleap>
i think i'll write a general `fn doesTypeMatch(comptime T: type, comptime Spec: builtin.TypeInfo) bool` to ditch my above ad-hoc whopper.. let's see how that goes *giddy*
wootehfoot has quit [Read error: Connection reset by peer]
<gruebite>
fengb: removeConst
marmotini_ has quit [Remote host closed the connection]
<fengb>
Oh I added that as a small joke because it’s not as gross looking as it should be :P
<gruebite>
yeah, it's better than what I was doing, more type safe
<andrewrk>
better yet, fix the .h file upstream
waleee-cl has joined #zig
return0e has joined #zig
return0e_ has joined #zig
lunamn_ has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
<gruebite>
andrewrk: true. one is slower than the other, but they can certainly be done in parallel
<BaroqueLarouche>
then you don't have to specify the file extension
<gruebite>
cool
<SyrupThinker>
Good to know, time to clean some stuff up
<gruebite>
i feel like my conversion is wrong
<gruebite>
in zig a function pointer does not need a "&" preceding the alias?
<gruebite>
fn foo() {}; const bar = foo; // bar is a function pointer
return0e has quit []
<gruebite>
am i correct?
eagle2com has quit [Ping timeout: 265 seconds]
<andrewrk>
correct
<gruebite>
is there some magic when passing it to C then? i've been doing `removeConst(&func_ptr)` but that's wrong, it should be `removeConst(func_ptr)` but it isn't treated as a pointer type
<gruebite>
it's like a const reference that coerces to a const pointer?
forgot-password has quit [Quit: leaving]
<gruebite>
basically: `@TypeInfo(func_ptr)` is not `.Pointer`
<gruebite>
it's .Fn, so i cannot remove const easily when passing to C
<metaleap>
i'm still bit new to mem-mgmt.. how does anyAllocator.shrink of some previously alloc'd bytes "return to the caller the just freed bytes"? i mean ..
<gruebite>
fixing upstream seems like the *only* option
<metaleap>
take Buffer.toOwnedSlice: "The caller owns the returned memory." and inside it calls allocator.shrink(). which becomes the result of toOwnedSlice..
<metaleap>
so i call that and now "own" the memory but it was just freed so does that mean i need to put it somewhere STAT before it gets overwritten... it cant be on stack AFAIK
<gruebite>
also, side note, what's the significance of capitalization convention regarding: @typeInfo and @TypeOf?
<metaleap>
gruebite: convention is, `type`-typed expressions are uppercase
<metaleap>
also goes for funcs that return `type`s (because thats how the generics work, eg. `std.ArrayList(T)`)
<andrewrk>
gruebite, the pointer casting builtins work for functions as well as pointers
<gruebite>
how do i get around "cast discards const qualifier"
<andrewrk>
you never need to type [*c] into your keyboard
<andrewrk>
@ptrCast does not have the ability to strip `const`
<andrewrk>
the nuclear option is @ptrToInt/@intToPtr
<gruebite>
is that the nuclear or only option?
<gruebite>
or both :D
<metaleap>
so real-world example on my above mem-mgmt-newb question.. lets say a user-defined func, passed to some zig lib ("use this func to get say some id") to return a string. might be tempting for the implementer to use its own favorite allocator and a std.Buffer, then return `buf.toOwnedSlice()` which cleans up the buffer kinda. now the "caller owns" the returned string but also needs to free it (at some point) "from somewhere". so the caller needs to know the
<metaleap>
user-code's allocator used, i guess?
<pmwhite>
that would be a leaky abstraction, no?
<metaleap>
how so
<metaleap>
libs allowing "user-specified fn impls of certain signatures" isnt all that uncommon pattern in interface-less langs I'd have to presume?
adamkowalski has quit [Remote host closed the connection]
_Vi has quit [Ping timeout: 272 seconds]
<metaleap>
guess i have to give an alloc (for the implementer to alloc his ret-value from but not free from.. hum) to such a sig, to keep things predictable
<pmwhite>
Oh, I misunderstood your explanation I think.
_Vi has joined #zig
<pmwhite>
Perhaps you don't actually want to return the owned version of the slice to the caller?
<metaleap>
np.. somehow i tend to run into issues that defy clear problem description. might be a sign of garbled synapses :D
<pmwhite>
I think I get your conundrum now, but of course I don't have the whole picture.
<gruebite>
checking my sanity: `.create_func = @intToPtr(*fn(?*c_void, ?*c_void) callconv(.C) ?*c_void, @ptrToInt(test_constructor))` should work if `create_func` is defined by: GDCALLINGCONV void *(*create_func)(godot_object *, void *), where godot_object is void, and GDCALLINGCONV is __attribute__((sysv_abi))
<gruebite>
it's crashing godot, so something is off
<andrewrk>
gruebite, `fn()void` is already a pointer. `*fn()void` is a double pointer
<Snektron>
function point syntax is honestly kind of confusing
<Snektron>
because its a pointer yet there is no star
<gruebite>
removing it i get: error: expected type '[*c]fn(?*c_void, ?*c_void) callconv(.C) ?*c_void', found 'fn(?*c_void, ?*c_void) callconv(.C) ?*c_void'
<gruebite>
yeah, so used to C and having to provide an asterisk
<gruebite>
heh
<Snektron>
ah, at least its nothing compared to c++ member function pointers
<gruebite>
oof
<gruebite>
yeah
occivink has quit [*.net *.split]
m6w6 has quit [*.net *.split]
m6w6_ has joined #zig
occivink has joined #zig
m6w6_ is now known as m6w6
return0e has joined #zig
jicksaw has quit [Ping timeout: 268 seconds]
jicksaw has joined #zig
<andrewrk>
gruebite, it's expecting a double pointer then, so you do need the *
<gruebite>
this is in cimport.zig: create_func: [*c]fn (?*godot_object, ?*c_void) callconv(.C) ?*const c_void,
marijnfs has quit [Remote host closed the connection]
return0e has quit [Ping timeout: 240 seconds]
<andrewrk>
let me just take a look at godot and see
<gruebite>
struct foo { __attribute__((sysv_abi)) void (*bar)(void); }; doesn't work
<gruebite>
struct foo { void (*bar)(void); }; works
<metaleap>
thx andrewrk will follow the issue
<andrewrk>
gruebite, nice find. would you mind filing an issue?
<gruebite>
yeah
<gruebite>
if this is an easy fix, it'd be fun for me to do
<betawaffle>
has anyone already suggested the ability to embed the fields from one type into another? something like usingnamespace, but for fields, rather than declarations
<andrewrk>
it might involve adding a new calling convention to zig. the first step is understanding what does that attribute mean
<andrewrk>
that would be easier than it sounds, however, it's likely just an enum value to llvm
<Snektron>
hm, this whole Vulkan thing turned out to be quite complicated
<Snektron>
one thing i wanted to do was add a way to make using the function pointers a little less of a nuisance to set up
<Snektron>
since you can either dispatch statically or dynamically
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 260 seconds]
<TheLemonMan>
andrewrk, what would be a nice API for a binary-search-in-slice function? I wanted to add one to the stdlib but I'm not sure about the API
<gruebite>
yeah, how does the predicate know the fixed value?
<TheLemonMan>
and the predicate should be able to return more than a bool, it's a full-fledged comparison operator with the usual {.gt,.eq,.lt}
<andrewrk>
does it need that though? sorting doesn't need that
<gruebite>
need a compare enum :P
<gruebite>
Lt, Eq, Gt
<TheLemonMan>
two args means you're passing the value to be searched
<andrewrk>
if it needs it, that's std.math.Order
<Snektron>
Until theres some kind of closure i think its better to pass in both arguments
<Snektron>
makes it compatible with asc and desc too
<TheLemonMan>
if you want to return a ?usize you need that, it's needed to handle the failure case
<andrewrk>
with two args, it can be lessThan, because the code can swap the args order to find greater than
<andrewrk>
oh yeah return vaule should be ?usize
metaleap has quit [Quit: Leaving]
<gruebite>
what would be a failure case of a sort?
<andrewrk>
I think it should be lessThan, and then the impl swaps lhs, rhs, to find greater than, and therefore also equal
<TheLemonMan>
yeah, if we go for the two-args route then we can avoid the predicate
<TheLemonMan>
gruebite, it's a binary search, the element you're searching for may not be there
<gruebite>
ohhhh bsearch, not sort
<gruebite>
do'h
<traviss>
anyone have a build.zig i can look which installs a test artifact? i want a fixed path to my test exe which i can use to launch a debugger. something like zig-cache/bin/my_tests.
<TheLemonMan>
the only downside is that you need one more call to the comparison function
<andrewrk>
traviss, the default `zig init-exe` does that I believe (do that in an empty dir)
<andrewrk>
oh that's a good point
<andrewrk>
I'd be ok with either
<andrewrk>
but the enum you're looking for is std.math.Order
<traviss>
oh nice. i'm working from an 'init-lib'. i'll have a look.
<andrewrk>
traviss, it's just exe.install();
<andrewrk>
and the fn should be comptime, because zig is getting pretty hostile to runtime-known function pointers
<fengb>
That function pointer fix is to delete a bunch of edge cases? lol
<pixelherodev>
`might have to drop @newStackCall in 0.6.0` will there be a replacement?
<Snektron>
@call
<traviss>
this doesn't seem to work for a test created using `var main_tests = b.addTest("tests.zig");` i moved my main test into my root package directory. the only test binary i'm seeing is buried within zig-cache/o, not in zig-cache/bin or zig-cache/lib where i hoped.
<andrewrk>
pixelherodev, inline assembly
<andrewrk>
traviss, you want your test binary to get installed?
<pixelherodev>
If it can be done with manual assembly, the compiler should be able to do it, no? Couldn't the implementation just be inline asm for the specific target?
<andrewrk>
if you're trying to run it in a debugger, you have a few options:
<traviss>
yes i want a fixed location for a debugging script
<TheLemonMan>
you have to be extra careful even with inline asm, gcc and llvm don't like their sp being clobbered
<pixelherodev>
Yes, but it's doable, and in some cases necessary
<pixelherodev>
I don't think I've seen a single freestanding application that doesn't need it, for instance
<traviss>
or if i can just get the path to the artifact, i can manually move it in build.zig
<TheLemonMan>
of course it is, nobody stated otherwise
<andrewrk>
pixelherodev, yes zig should be able to do it
<TheLemonMan>
use a naked function to act as a trampoline and you should sidestep any trouble
<andrewrk>
the problem is that it is getting dropped now, in the llvm10 branch, because the current implementation is no good. so if a more robust implementation can be completed by the master branch merge, then it will be available
<andrewrk>
I'll try the naked function strategy before merging llvm10
jessermeyer has joined #zig
<jessermeyer>
Are the semantics different between these two statements?
<jessermeyer>
var d12_device: *ID3D12Device = undefined; var result = D3D12CreateDevice(null, D3D_FEATURE_LEVEL_12_1, &IID_ID3D12Device, @ptrCast(**c_void, &d12_device));
<jessermeyer>
var d12_device: *ID3D12Device = undefined; var result = D3D12CreateDevice(null, D3D_FEATURE_LEVEL_12_1, &IID_ID3D12Device, &@ptrCast(*c_void, d12_device));
<jessermeyer>
Both compile, but the first one is what works.
<andrewrk>
yes
<jessermeyer>
And by works, I mean the com init succeeds.
<Snektron>
youre taking an address of a stack variable in the second case
<andrewrk>
one of them is taking a pointer to a temporary; the other is taking a pointer to the variable
<jessermeyer>
Huh, I have to think about that.
Snetry has quit [Ping timeout: 268 seconds]
Snetry has joined #zig
<jessermeyer>
I'm amazed you both could parse that so quickly.
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 272 seconds]
<andrewrk>
I copy pasted it into vim and maximized the window
<fengb>
I'm a little surprised a @ptrCast introduces a new variable. Does it also in C?
<jessermeyer>
I think that's what's throwing me.
<Snektron>
it would be weirder if it didn't
<jessermeyer>
So it's causing a copy, or a move instruction?
<Snektron>
the generated assembly is probably the same
<Snektron>
semantically its causing a copy
<Snektron>
or rather, a copy at a different point
<jessermeyer>
So why does is it more natural to cause a copy to perform an interpretation?
<andrewrk>
fengb, you can put & in front of any expression in zig
<jessermeyer>
So, yeah, it has a return type (sort of obviously)
<jessermeyer>
Which I guess is what Snek is referring to?
<jessermeyer>
It's quite a mental task to go from Zig code to C code, back to back.
<Snektron>
What i mean is, the result of @ptrCast is a temporary value, even though in code-terms its a no-op]
_Vi has quit [Ping timeout: 260 seconds]
<jessermeyer>
Right. It's an actual function.
<Snektron>
You can view it as such, yes
<jessermeyer>
I mean, it's defined that way.
<jessermeyer>
It may be useful to add a comment to this effect for its documentation, to ease the psyche from those coming from a C background.
<andrewrk>
it's not an actual function
<andrewrk>
builtin functions in zig are syntax
<Snektron>
but it acts as an actual function
<andrewrk>
in some ways
<Snektron>
I understand why you think that way, even without a C background
<andrewrk>
it can't be passed as a pointer
<andrewrk>
it has to be called directly
<andrewrk>
var x = @ptrCast; // error
<jessermeyer>
Good distinction.
<jessermeyer>
If not already, might be a good documentation addition =)
<Snektron>
I think the important thing here is that functions in zig are call-by-value
<fengb>
andrewrk: ah but not any expression... because double address && is parsing incorrectly 🙃
<Snektron>
if @ptrCast would be call-by-reference, those cases would be equal
<jessermeyer>
Right.
<jessermeyer>
That was my null-hypothesis.
<andrewrk>
feng, always keeping me honest
<fengb>
I'm technically correct, the best kind of asshole
<jessermeyer>
lol
<Snektron>
by the way, are `(void**) a` and `&(void*) a` the same in c?
<jessermeyer>
Maybe I'm not testing it correctly but
<jessermeyer>
test_translate.c(31,19): error: cannot take the address of an rvalue of type 'void *'
<Snektron>
ah, no
<jessermeyer>
void** test = &(void*)device;
<Snektron>
latter is not allowed since its not an lvalue
Snetry has quit [Ping timeout: 240 seconds]
Snetry has joined #zig
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 268 seconds]
<traviss>
anyone know how to get the path to a test artifact in build.zig created by `b.addTest("tests.zig")`. i'm looking for something like zig-cache/o/iAwVl8Fjwhfh.../test
<andrewrk>
traviss, pass --verbose to `zig build`
<andrewrk>
you can also use setExecCmd to make it run in a debugger
<andrewrk>
which you could integrate with b.option
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
Snetry has quit [Ping timeout: 268 seconds]
<andrewrk>
finally you can use setOutputDir, which is a bit unstable API and disables caching
<traviss>
i was hoping to do this within build.zig, not externally. ok thanks i'll have a look at setOutputDir
<andrewrk>
this is within build.zig
<andrewrk>
it also looks like tests support being installed
Snetry has joined #zig
jessermeyer has quit [Remote host closed the connection]