<korvo>
cfbolz, arigato: While we're on GPU stuff, I can sometimes answer questions about GPU ISAs, even if the answer is vague and can't cite anybody directly for ~the reasons~
<korvo>
On GPUs where I can go find a PDF of the ISA, like any ATI/AMD Radeon in the past couple decades, the main issues are all conceptual. There's a cool Dyalog APL compiler, co-dfns, whose design is like 20% APL on GPU and 80% compiler on GPU.
<korvo>
"computing the full expression at every pixel" is often the best choice, yeah. I'm a big believer in Inigo Quizlez' approach, even if I don't use their "ShaderToy" product; evaluating a signed distance function is usually not that slow and the cost is really in the size of the shader and textures.
<korvo>
...At risk of sounding like a crank, the issue of needing a driver for a GPU is tangent to an #esolangs conversation from a while ago. The different parts of a modern motherboard are effectively message-passing actors.
<korvo>
Not every actor is going to be capable of driving itself. The CPU is only Turing-complete when paired with a nice memory controller, even! So it shouldn't be surprising that some actors effectively require a driving actor next to them in order to be Turing-complete.
<korvo>
...Actually, at risk of being a bold crank who over-promises, I've been thinking about this for a while. In a serious way, there's nothing technically preventing an RPython process from opening up a DRI/DRM node on Linux or BSD and asking for a compute handle.
<korvo>
I know libdrm and can help anybody with the basic ioctls. But there's a bunch of device-specific initialization that has to be done, and we really only have the docs to do it on Radeon cards.
<korvo>
I have no idea how guards would work, and that was enough for me to stop thinking about it.
derpydoo has joined #pypy
jcea has quit [Ping timeout: 248 seconds]
derpydoo has quit [Quit: derpydoo]
itamarst has quit [Quit: Connection closed for inactivity]
auk has quit [Quit: Leaving]
[Arfrever] has quit [Ping timeout: 252 seconds]
<arigato>
cfbolz: fwiw, I'm pretty sure we could get massive speedups on the Prospero challenge because it's just made of individual letter parts which repeat
<arigato>
in a very gamedev-oriented solution (instead of CUDA), I would extract the 665 independent bits, then identify which ones are actually the same ones that only differ by a translation, further reducing the number
<arigato>
then compute the bounding box of each of these parts, by doing some range analysis
<arigato>
then we get 665 quads on the screen, which we can implement as a mesh of 665*2 triangles, with UV coordinates that encode the coordinates of the vertices plus translations, and a 3rd UV coordinate that selects which of the faces to use
<arigato>
we end up with a single mesh draw call, with some overlap, where every mesh uses only one block of 10 or 20 instructions
[Arfrever] has joined #pypy
<arigato>
with a single switch which is constant for the whole quad
<arigato>
that's pretty much the best possible case for GPUs drawing triangles
<arigato>
I'd expect this to be maybe 20 times faster than what I did yesterday
<arigato>
s/every mesh/every quad (there is a single mesh)
<arigato>
(also, if some more advanced range analysis says the points are inside some other tigher polygonal shape than an axis-aligned bounding box, then there is no runtime cost in replacing the quad with this other shape, further increasing performance)
<cfbolz>
arigato: right
<cfbolz>
if the application is some kind of 3d CAD it becomes a bit trickier though, I assume
derpydoo has joined #pypy
<arigato>
if the 3d model is the union of a large number of small pieces, the same approach should work
<arigato>
but maybe we could treat large pieces differently? like, stick them all inside the same union-based formula and use a single quad covering the whole window for it
<arigato>
...I actually did exactly that (with lots of small pieces) in a VR game I made: it renders many many bubbles, which are small spheres, but rendered as octagons---so only 4 triangles per sphere, and a custom shader that make the triangle appear exactly like its spherical subset
<arigato>
(4 visible triangles, plus 4 triangles on the other side that the GPU discards early)
<arigato>
I don't know why but it is apparently an uncommon solution (within games). Normally spheres are rendered as high-poly surfaces, but hundreds of faces times thousands of spheres is too much for the Quest VR device
<arigato>
(a good PC GPU would be fine with 10 times more spheres, but not 100 times more)
derpydoo has quit [Quit: derpydoo]
otisolsen70 has joined #pypy
otisolsen70 has quit [Remote host closed the connection]
otisolsen70 has joined #pypy
itamarst has joined #pypy
jcea has joined #pypy
otisolsen70 has quit [Quit: Leaving]
nimaje1 has joined #pypy
solremn has joined #pypy
krono_ has joined #pypy
infernixx has joined #pypy
remn has quit [*.net *.split]
mjacob has quit [*.net *.split]
infernix has quit [*.net *.split]
nimaje has quit [*.net *.split]
krono has quit [*.net *.split]
krono_ is now known as krono
mjacob has joined #pypy
infernixx is now known as infernix
nimaje1 is now known as nimaje
<korvo>
It's not just gamedev; X11 and other windowing systems capture the "glyphs" of a font and re-use each glyph as a texture or stencil.
Diggsey has joined #pypy
jcea has quit [Ping timeout: 248 seconds]
<arigato>
korvo: right, and we can also compare that with signed distance fields, which give a nicer-looking result than just rendering a texture, for fonts
<korvo>
arigato: Yep. I haven't dug into Prospero yet, but I hear that it was designed by generating bytecode which approximates an SDF? So we come full circle.
<arigato>
yes, it is based on a SDF defined entirely by computations, and no texture sampling at all
<arigato>
but of course it makes sense to think about font-rendering systems for Prospero, because in that case the image we want to render is actually some text
<korvo>
2D SDFs on a 2D projection can usually be pre-composed with that projection, too, so if the SDF has *any* repeating structure then it can be isolated and cached. This is in stark contrast to 3D SDFs, where the projection isn't just a linear mapping but requires a loop and numerical methods.
<arigato>
yet I believe we can still do the same in 3D in the general case, e.g. splitting it as a bunch of 3D bounding box isolated from each other, and then rendering it as one 3D cube each
<korvo>
I guess that I should point out the other reason that glyphs make sense for windowing systems: at a fixed (small) point size, fonts need subpixel information to get legible rendering. So they have to be rendered in software on the CPU and transferred to the GPU as stencilling textures anyway.
Dejan has joined #pypy
<korvo>
...Wait, I see how to encode guards. Just pick a sentinel value that indicates that the computation failed and designate one channel to carry error information showing which guard failed. That would even be Vulkan-compatible.
[Arfrever] has quit [Ping timeout: 276 seconds]
<korvo>
Okay, so the main problems are (1) not all cards have Vulkan yet, (2) I feel like it'd be worthwhile to just write our own drivers, (3) this is an enormous amount of work regardless of whether the API is DRI/DRM or Vulkan.
<arigato>
korvo: just to check, you're talking about PyPy's JIT-produced guards, right?
<korvo>
arigato: Yes.
<arigato>
OK
<korvo>
Oh! I was sleep-deprived and didn't explain myself. So right now my Cammy implementation in RPython can ray-trace basic scenes at 2-3 megapixels/second. Not bad for a CPU renderer. I have multiple tiers of optimization and think I've gotten down to an assembly-like language that could be compiled to machine code.
<korvo>
It wouldn't be *that* hard to put Cammy on a GPU, or at least straight-line Cammy which only manipulates floats. The corresponding shader is just bytecode, really; Mesa3D is millions of lines of code because it's C/C++, not because the task is tricky.
[Arfrever] has joined #pypy
jcea has joined #pypy
jcea has quit [Ping timeout: 276 seconds]
dmalcolm_ has joined #pypy
dmalcolm has quit [Remote host closed the connection]