#
…

2021-04-12

00:05macc24 has quit [Ping timeout: 260 seconds]
00:07artemist has quit [Ping timeout: 260 seconds]
00:08artemist has joined #asahi-gpu
00:10bloomTaking a peak at fsin/fcos
00:10bloomObservation 1: the asm of fcos is identical to fsin, except the first instruction
00:10bloom 8: ba05c0021810 fmadd $r1, r0.discard, u0, 0.25
00:10bloomfadd r1, r0, u0
00:10bloomThis corresponds to the trig identity cos(x) = sin(x + pi/2) = sin(x + tau/4), so we expect that u0 = 2pi = tau
00:14bloomer, no, we want the reciprocal of that. units are hard
00:14bloomanyway, sure enough checking the memory dump u0 = 0x3E22F983, and
00:14bloomstruct.unpack('f', bytes([0x83, 0xF9, 0x22, 0x3E])) = 0.15915493667125702
00:14bloom1.0 / math.tau = 0.15915494309189535
00:15bloomSo the first thing we do in either sin or cos is divide by tau to change from radians to "times around the circle"
00:15bloomand for cos we just push forward by 90 degrees.
00:16bloomObservation 2: The next few instructions are the sequence floor/fsub. We immediately recognize this as the fract(...) function. This is again what we'd expect -- fsin/fcos are periodic, with period 2pi, which is now period 1 after the above change of units.
00:16bloomThe last four instructions are where things get mysterious.
00:17bloomThere are special one-op instructions dparametrized as 0b1010 and 0b1110... call them F and G
00:18bloomand reading off, we see take that angle 0 <= x < 1 and calculate... G(F(4 * x)) * F(4 * x)
00:18bloomand somehow that equals sin?
00:19bloomThe multiplication by four is just another change of units. Now the fraction is angle within a quadrant, and the integer part is the quadrant. This is natural enough given the quadrant (anti)symmetries we have with sin.
00:20bloomAll we're doing is a series of reductions to make G and F as simple as possible. Or rather, as small as possible -- they're probably lookup tables.
00:21bloomAt this point we have two options:
00:21bloom1. Just call F and G sin_pt_1 and sin_pt_2 and call it a day. Who cares?
00:21bloom2. Using a compute shader test (I believe dougallj has a script for this), run each op in isolation and dump the results. Then plot them and see what happens.
00:23bloom(There's no magic for tan. It's just computing fsin and fcos and dividing them. Just looks funny due to aggressive scheduling.)
00:28dougallyeah, maybe 1 is the way to go for now? (i do have a script that i have technically done something like this with, but it'll be a lot easier once we've made more progress on everything else)
00:28bloomdougall: sure
00:28bloomI was secretly hoping there would be Taylor series involved
00:29bloomThe lowering for Bifrost is super cute
00:29dougallbut yeah, it's a nice self-contained challenge for anyone interested in numerics if people want to try :)
00:32dougallhaha nice!
00:39odmir has quit [Remote host closed the connection]
00:40odmir has joined #asahi-gpu
00:44odmir has quit [Ping timeout: 246 seconds]
00:44bloompatches incoming
01:05bloomPatches sent
01:11odmir has joined #asahi-gpu
01:14dougalllooks great!
01:20bloomthanks!
01:20bloomno clue on the extended fields, although IIRC you have a clever way to determine those that I don't :p
01:24bloomalso, I still can't get over the fact the shaders are keyed to formats
01:24bloomI am not ok with this
01:24dougallwhat does 'keyed to formats' mean?
01:26bloomThe code of the vertex shader depends on the format of the vertex attributes,
01:26bloomlikewise the code of the fragment shader depends on the format of the framebuffer
01:26bloomThat means you *can't* compile shaders up front,
01:27bloomrather you have to wait until the app is actually drawing things and potentially have to recompile many times with different shader "keys" - combinations of "leaky" state
01:27bloom("shader variants")
01:28blooma number of architectures are specificalluy designed to eliminate all shader variants in e.g. core OpenGL ES
01:28bloomApple has gone the other end... why? well, because they can - Metal requires all this info at pipeline create time anyway, so why not use it? /s
01:29dougallah, that makes sense, thanks
01:45odmir has quit [Ping timeout: 240 seconds]
02:25chrisfonly trouble for GL. we know this upfront for vulkan too
02:26bloomchrisf: still means a lot more recompiles if the app swaps things in the pipeline
02:30chrisfmay be feasible to patch it?
02:31chrisfis just the shader epilog that's affected?
02:41bloomI've just compiled my first shader (from GLSL down to AGX machine code) with Mesa :)
02:42bloomit's gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0), don't get too excited :p
02:44bloomdoing all that dev on linux, let's see if it works on macos too :-p
02:52bloomIt does not work. Down the debug hole.
02:52bloomGlaring problems include missing a stop instruction :-p
02:56phiologe has quit [Ping timeout: 250 seconds]
02:58phiologe has joined #asahi-gpu
02:58bloomAlso, while obviously I can't enforce this, I kindly ask y'all not to make a splash about that before I can get around to blogging ;-P
03:01bloomok, stop/trap implemented
03:02bloomok, now it doesn't fault but there are crazy colours, guessing I screwd up the register alloc
03:04bloomofc I don't know the regalloc field for FS...
03:06bloomYep, there it is.
03:08bloomFirst shader compiled from GLSL with mesa running successfully on the hardware
03:08bloomnot bad seeing as I started writing the compiler yesterday :p
03:12mxw39 has joined #asahi-gpu
03:15dougallhaha awesome!
03:15bloomld_vary is up next at which point I can start writing real shaders and implementing the heaps of ALU needed for anything interesting
03:15bloomthanks :)
03:56bloomhave ld_var emitted but some cmdbuf work remains to use it in the demo..
04:15j`ey_ has joined #asahi-gpu
04:20mofux[m] has quit [*.net *.split]
04:20meiji163[m] has quit [*.net *.split]
04:20izzyisles[m] has quit [*.net *.split]
04:20winocm has quit [*.net *.split]
04:20j`ey has quit [*.net *.split]
04:38winocm has joined #asahi-gpu
04:39meiji163[m] has joined #asahi-gpu
04:39izzyisles[m] has joined #asahi-gpu
04:39mofux[m] has joined #asahi-gpu
05:25mxw39 has quit [Quit: Konversation terminated!]
05:26mxw39 has joined #asahi-gpu
05:37mxw39 has quit [Quit: Konversation terminated!]
05:38mxw39 has joined #asahi-gpu
06:12the-mentor3 has quit [Quit: The Lounge - https://thelounge.chat]
06:15the-mentor3 has joined #asahi-gpu
06:43mxw39 has quit [Quit: Konversation terminated!]
06:44mxw39 has joined #asahi-gpu
07:29j`ey_ is now known as j`ey
07:29j`ey has quit [Changing host]
07:29j`ey has joined #asahi-gpu
09:10cwabbott has joined #asahi-gpu
09:28jaalsa has joined #asahi-gpu
09:56macc24 has joined #asahi-gpu
13:57odmir has joined #asahi-gpu
14:01odmir has quit [Ping timeout: 240 seconds]
14:57artemist has quit [Quit: artemist]
16:38chrisfbloom: you seem to be making a ton of progress
17:42dhewgwoot, sounds like a milestone to me!
18:34radex has joined #asahi-gpu
19:23kendfinger has joined #asahi-gpu
21:29vlixa has quit [Remote host closed the connection]
21:42vlixa has joined #asahi-gpu
22:15jixbo has joined #asahi-gpu
22:40HeN has quit [Quit: Connection closed for inactivity]
23:12jixbo has quit [Quit: jixbo]
…