Okay so this strategy seems to be working! Hopefully will have some cool code to share soon.
Notices by dave (dthompson@toot.cat), page 3
-
Embed this notice
dave (dthompson@toot.cat)'s status on Sunday, 19-Feb-2023 00:10:43 JST dave -
Embed this notice
dave (dthompson@toot.cat)'s status on Sunday, 19-Feb-2023 00:10:36 JST dave Here's a simple example program:
(top-level ((in int x))
(let ((f (lambda (x) (+ x 1))))
(f 2)))The only type declaration is on the shader input attribute 'x'. Here's the typed program that the compiler generates:
(t ((primitive int))
(top-level
((in int V0)
(function
V2
(t ((for-all
((tvar T3) (tvar T7))
(-> ((tvar T3)) ((tvar T7)))
(and (= (tvar T3) (primitive int))
(substitute (tvar T7) (tvar T3)))))
(lambda (V1)
(t ((tvar T7))
(primcall
+
(t ((tvar T3)) V1)
(t ((primitive int)) 1)))))))
(t ((primitive int))
(call (t ((-> ((primitive int)) ((primitive int)))) V2)
(t ((primitive int)) 2)))))The interesting bit is the 'for-all' expression that generalizes the function 'f' to accept any arguments as long as they satisfy the predicate (the 'and' expression). In this case the only valid type for 'x' is an integer.
The compiler is currently unable to emit GLSL code for the function because it doesn't yet know how to translate a 'for-all' into a series of functions for each valid type combination. That's the next step.
-
Embed this notice
dave (dthompson@toot.cat)'s status on Sunday, 19-Feb-2023 00:10:29 JST dave Okay now I can emit GLSL for functions with multiple signatures!
Contrived input program:
(let* ((f (lambda (x y) (+ x y)))
(z (f 1.0 2.0)))
(f 3 4))'z' is a useless binding that just demonstrates that 'f' can be called with floats and ints. good thing I don't do dead code elimination yet.
GLSL output:
void V2(in int V0, in int V1, out int V4) {
int V5 = V0 + V1;
V4 = V5;
}
void V2(in float V0, in float V1, out float V6) {
float V7 = V0 + V1;
V6 = V7;
}
void main() {
float V8 = 1.0;
float V9 = 2.0;
float V10;
V2(V8, V9, V10);
float V3 = V10;
int V11 = 3;
int V12 = 4;
int V13;
V2(V11, V12, V13);
int V14 = V13;
} -
Embed this notice
dave (dthompson@toot.cat)'s status on Sunday, 19-Feb-2023 00:10:23 JST dave I now have basic struct types working. The qualified type logic was extended to support them and overloaded function generation was extended to deal with structs as arguments. I also added function signatures for a number of built-in GLSL functions. I can once again compile the simple vertex shader I use for 2d sprites:
(top-level
((in vec2 position)
(in vec2 texcoords)
(out vec2 frag-tex)
(uniform mat4 mvp))
(outputs
(vertex:position (* mvp
(vec4 (-> position x)
(-> position y)
0.0 1.0)))
(frag-tex texcoords)))GLSL output:
in vec2 V0;
in vec2 V1;
out vec2 V2;
uniform mat4 V3;
void main() {
float V4 = V0.x;
float V5 = V0.y;
float V6 = 0.0;
float V7 = 1.0;
vec4 V8 = vec4(V4, V5, V6, V7);
vec4 V9 = V3 * V8;
gl_Position = V9;
V2 = V1;
} -
Embed this notice
dave (dthompson@toot.cat)'s status on Sunday, 19-Feb-2023 00:10:14 JST dave I took a look at the type inference code in guile-prescheme and I'm impressed with how elegant it is. However, it's an imperative implementation. My algorithm is functional and I'd like to keep it that way. Once I have something that produces correct output for all of my existing shaders I will try to refactor the code into something nicer.
-
Embed this notice
dave (dthompson@toot.cat)'s status on Thursday, 01-Dec-2022 05:34:55 JST dave @mattl unhinged behavior
-
Embed this notice
dave (dthompson@toot.cat)'s status on Thursday, 01-Dec-2022 04:52:02 JST dave my new laptop is here :blobcatbongo:
-
Embed this notice
dave (dthompson@toot.cat)'s status on Thursday, 01-Dec-2022 04:52:01 JST dave I haven't bought a new computer for myself since like 2009. I bought a used thinkpad in 2013. sooo I treated myself.
-
Embed this notice
dave (dthompson@toot.cat)'s status on Thursday, 01-Dec-2022 01:01:31 JST dave @gnu2 yeah I don't agree that the free software movement has failed, either. I think it has stalled in some ways *but* there are important projects pushing it forward like this wonderful ActivityPub powered social network we are using now!
-
Embed this notice
dave (dthompson@toot.cat)'s status on Wednesday, 16-Nov-2022 10:24:59 JST dave my wife was up a good chunk of the night because the dog started barfing. she barfed up a ponytail holder and eventually went to sleep. this morning she was really low energy at first but eventually got up and ate food, but she just barfed it all up so now she's going to the vet to see if there's a blockage or something. hope it's all okay.
-
Embed this notice
dave (dthompson@toot.cat)'s status on Wednesday, 16-Nov-2022 10:24:58 JST dave issues are still ongoing. going to an emergency place now. the vet reassured us some but I am still very worried.
-
Embed this notice
dave (dthompson@toot.cat)'s status on Tuesday, 04-Oct-2022 12:33:15 JST dave just read this blog post about rms/fsf. the tl;dr is that rms is so behind the times on technical matters that he is a hindrance to both gnu and fsf. I agree. https://catgirl.ai/log/elegy-gnu/