Hello fellow Racketeers,

during the spring and summer I worked on a side project to test what can
be done in pure Racket when it comes to raster graphics rendering. You
can imagine it like demo or game programming before the advent of GPUs.

It turned out that quite a lot can be achieved and it also turned out
that Racket performs really well when it comes to some hard number
crunching. And what else is computer graphics than just a number crunching?

As I consider this experiment basically completed, I release the source
code[1] to the public under the usual dual Apache/MIT license. A short
(25s) video in action can be seen on the project "website"[2].

For those wondering about the tut25 naming - the project started as an
attempt to rewrite all Denthor's VGA Trainers published between 1994 and
1996. There were 21 tutorials, I added four. I am publishing only the
final result - the 25th "tutorial". If I have some spare time in the
future, I'll write a series of articles about the journey from drawing
the first pixel in the window to full 3D triangle rasterizer with alpha
blending, perspective-correct texturing, z-buffering and Goraud shading.

And for those wondering "why?" - there are actually more answers:

1) Why not?
2) Projects like this stress-test Racket implementation and therefore
help its development (more on that below).
3) I want more people to start using futures for improving performance
without sacrificing code readability.
3b) Also I don't want to hear from the people in the core team "Oh, you
are probably the only one seriously using futures" ;-)

To inspire more people to start seemingly crazy projects like this, here
is a list of things that are now better in current Racket version as a
side-effect of this project (and yes, Matthew wrote all the patches):

* futures versus GC in BC - no more crashes[3]
* futures and the write barrier in BC - no more freezes[4]
* fsemaphores - no longer can go negative (actually the bug was
elsewhere)[5]
* safe and unsafe fl->fx unification[6]
* internal stack overflow fixed[7]
* box CAS operation troubles with futures[8]

The code comes however with a big red warning: some parts are as ugly as
they can get. On the other hand, there are some nice language features
that I consider worth investigating further. Mainly:

* using syntax macros to create procedure templates and then with
another layer of syntax macros instantiate those for specific task. See
for example the define/provide-draw-proc-variants and template-clear in
rcge/drawing.rkt. Yes, they are unhygienic - but just very slightly...

* context nesting using parameters (although I personally dislike the
need to wrap everything in so many parameterize layers) - see any of
rcge/*-run.rkt files for example.

* using syntax macros to provide hints to the compiler. The best example
of this is the matrix multiplication in rcge/algebra.rkt -
define-mat4*mat4!/let. Yes, definitely not the best practice in general,
but combined with unboxed flonums on CS, it improved the performance by
an order of magnitude compared to simple loop.

* define-futurized (rcge/futures.rkt) - in an ideal world, a generalized
version of a macro like this should be able to parallelize
computation-heavy algorithms with little to no effort for the programmer.

Things NOT to do: blit-to-cairo-data*-u16vector-hack - rcge/blit.rkt is
not for the weak. But I like the fact, that it is possible to interact
between different layers of the program, compiler and JIT.


Thank you for reading this far and if you have any questions, I'll be
more than happy to answer those.


Cheers,
Dominik

[1] https://joe.cz/rcge/
[2] https://gitlab.com/racketeer/rcge-tut25
[3] https://github.com/racket/racket/issues/3145
[4]
https://github.com/racket/racket/commit/fae20b4b8904bfcfba9808f56744950b049b6afd
[5]
https://github.com/racket/racket/commit/1117392cb5524a2ce150384d405fb2a81ef47daa
[6]
https://github.com/racket/racket/commit/42cb80bc70e1fb97dabd1e0a2dff5d93257b1f40
[7]
https://github.com/racket/racket/commit/265c9eaa57661a045feed85e1db45029aa9de7e2
[8]
https://github.com/racket/racket/commit/0af11de62b2eaa1f4f0977794a4dc9dcacabd945

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/a46338ba-51e1-e3f4-dba2-99d319b0b503%40trustica.cz.

Reply via email to