#asahi-gpu · 2021-04-12 00:28
bloomI was secretly hoping there would be Taylor series involved#asahi-gpu · 2021-04-12 00:28
bloomdougall: sure#asahi-gpu · 2021-04-12 00:28
dougallyeah, 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)#asahi-gpu · 2021-04-12 00:23
bloom(There's no magic for tan. It's just computing fsin and fcos and dividing them. Just looks funny due to aggressive scheduling.)#asahi-gpu · 2021-04-12 00:21
bloom2. 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.#asahi-gpu · 2021-04-12 00:21
bloom1. Just call F and G sin_pt_1 and sin_pt_2 and call it a day. Who cares?#asahi-gpu · 2021-04-12 00:21
bloomAt this point we have two options:#asahi-gpu · 2021-04-12 00:20
bloomAll 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.#asahi-gpu · 2021-04-12 00:19
bloomThe 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.#asahi-gpu · 2021-04-12 00:18
bloomand somehow that equals sin?#asahi-gpu · 2021-04-12 00:18
bloomand reading off, we see take that angle 0 <= x < 1 and calculate... G(F(4 * x)) * F(4 * x)#asahi-gpu · 2021-04-12 00:17
bloomThere are special one-op instructions dparametrized as 0b1010 and 0b1110... call them F and G#asahi-gpu · 2021-04-12 00:16
bloomThe last four instructions are where things get mysterious.#asahi-gpu · 2021-04-12 00:16
bloomObservation 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.#asahi-gpu · 2021-04-12 00:15
bloomand for cos we just push forward by 90 degrees.#asahi-gpu · 2021-04-12 00:15
bloomSo the first thing we do in either sin or cos is divide by tau to change from radians to "times around the circle"#asahi-gpu · 2021-04-12 00:14
bloom1.0 / math.tau = 0.15915494309189535#asahi-gpu · 2021-04-12 00:14
bloomstruct.unpack('f', bytes([0x83, 0xF9, 0x22, 0x3E])) = 0.15915493667125702#asahi-gpu · 2021-04-12 00:14
bloomanyway, sure enough checking the memory dump u0 = 0x3E22F983, and#asahi-gpu · 2021-04-12 00:14
bloomer, no, we want the reciprocal of that. units are hard#asahi-gpu · 2021-04-12 00:10
bloomThis corresponds to the trig identity cos(x) = sin(x + pi/2) = sin(x + tau/4), so we expect that u0 = 2pi = tau#asahi-gpu · 2021-04-12 00:10
bloom*fmul#asahi-gpu · 2021-04-12 00:10
bloomfadd r1, r0, u0#asahi-gpu · 2021-04-12 00:10
bloomvs#asahi-gpu · 2021-04-12 00:10
bloom 8: ba05c0021810 fmadd $r1, r0.discard, u0, 0.25#asahi-gpu · 2021-04-12 00:10
bloomObservation 1: the asm of fcos is identical to fsin, except the first instruction#asahi-gpu · 2021-04-12 00:10
bloomTaking a peak at fsin/fcos#asahi-gpu · 2021-04-11 23:18
bloombut if the idea is right it should be obvious how to construct test programs for that#asahi-gpu · 2021-04-11 23:18
bloomprobably worth confirming issue a lot more loads#asahi-gpu · 2021-04-11 23:17
dougallah yeah, great find on i/u2! i think that makes sense#asahi-gpu · 2021-04-11 23:15
bloomAck#asahi-gpu · 2021-04-11 23:15
dougallbloom: A vs At etc is arbitrary, as you say, i just wanted to have splitting in one place, and try to separate 'instruction' from 'data' in the bit diagram (A can be a literal immediate, although also sometimes the low bit indicates whether or not the reg is 64-bit, so it's not perfect)#asahi-gpu · 2021-04-11 23:14
bloomNote to self: >4 render targets has some seriously weird shader stuff#asahi-gpu · 2021-04-11 22:18
bloomdougall: Also, patches incoming for `blend` and maybe `ld_var` if I have time before getting bored and reading a novel :p#asahi-gpu · 2021-04-11 20:40
bloomI guess just more convenient that way. Probably will merge them for whatever i end up doing.#asahi-gpu · 2021-04-11 20:39
bloomdougall: Any reason why applegpu.py seperates {A,B,C,D} from {A,B,C,D}t? It looks like the fields are always adjacent#asahi-gpu · 2021-04-11 20:11
bloomDarkShadow44: I'm not sure if they added support or not, it's definitely on their wishlist though.#asahi-gpu · 2021-04-11 18:29
DarkShadow44bloom: Say, do you know if isaspec from mesa can be used to create an assembler? Because from reading their docs it seems like this is not yet the case#asahi-gpu · 2021-04-11 18:24
DarkShadow44downloading that is kinda savage indeed, but I like the idea ^#asahi-gpu · 2021-04-11 18:24
DarkShadow44cool, I kinda thought once it's uploaded you can't access it anymore#asahi-gpu · 2021-04-11 18:23
bloomat the cost of introducing a slew of other issues..#asahi-gpu · 2021-04-11 18:23
bloomand it avoids ^^ those sorts of issues#asahi-gpu · 2021-04-11 18:23
bloomDarkShadow44: yep.#asahi-gpu · 2021-04-11 18:22
DarkShadow44...if you want to run them in the first place#asahi-gpu · 2021-04-11 18:22
DarkShadow44so if you try to run them, you better check they load/store data at the right offsets :P#asahi-gpu · 2021-04-11 18:22
DarkShadow44they're compiled as "functions" (for lack of a better word) instead of a standalone program#asahi-gpu · 2021-04-11 18:21
DarkShadow44glibc: One more thing I forgot: Keep in mind that the metallib way of getting a shader produces different bytecode from loading a shader normally#asahi-gpu · 2021-04-11 18:21
glibcDarkShadow44: thanks :)#asahi-gpu · 2021-04-11 18:19
DarkShadow44bloom: You can extract shaders from GPU memory after they've been uploaded?#asahi-gpu · 2021-04-11 18:18
bloomhas always ignored the 'nice' methods of doing this, preferring to just savagely parse GPU memory at runtime