SNES Doom development, Randy Linden

You can talk about almost anything that you want to on this board.

Moderator: Moderators

calima
Posts: 1125
Joined: Tue Oct 06, 2015 10:16 am

Re: SNES Doom development, Randy Linden

Post by calima » Sat Jun 06, 2020 12:16 am

For something that niche, a rare expansion chip or a 200$ flashcard, don't count on anything happening unless you do it yourself.

User avatar
aa-dav
Posts: 56
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: SNES Doom development, Randy Linden

Post by aa-dav » Sun Jun 07, 2020 7:50 pm

It's very interesting interview!
I didn't even know that SNES port was started as unofficial one.

I have read about SuperFX a little and it's architecture is very interesting one (at least for me).
It has 16 general registers (also there is a lot of control registers, but it's not important here) R0..R15, where R15 is instruction pointer, R11 - link register and some other specialized stuff.
R0 is accumulator by default. But in fact there are two internal registers Sreg and Dreg - they are numbers of source register and destination register.
After reset and in the end of execution of instructions which uses source/destination registers they are zeroed, that is are pointer to R0/accumulator.
But there are three instructions to change them:

Code: Select all

FROM Rn ; opcode 0xBn - sets Sreg to n
TO Rn   ; opcode 0x1n - sets Dreg to n
WITH Rn ; opcode 0x2n - sets Sreg and Dreg to n
And for example ADD instruction has parameter n in it's opcode like above:

Code: Select all

ADD Rn ; opcode 0x5n
It sums up Sreg with Rn and places result in Dreg.
That is ADD Rn adds Rn to R0 by default.
But sequence of instructions:

Code: Select all

FROM R3
TO R4
ADD R5
will write sum of R3 and R5 to R4.
Well, this is interesting.
Moreover - there is no dedicated "MOVE Rn, Rm" instruction code. Instead of that prefix instruction "TO Rn" works as "MOVE Rm, Rn" if it is preceded by "WITH Rm" instruction. That is "MOVE" is two-byte instruction reusing WITH/TO 1-byte prefixes.
Interestion instruction set and I think it's not RISC at all. It's full of prefixes/immediate data/different instruction formats.

However some things resemble RISC. For example there is no CALL instruction. Instead it has four LINK 1...LINK 4 instructions (opcodes 0x91-0x94) which copies R15+imm to R11 (link register). Usually this instruction is followed by immediate word transfer to R15 (PC) "IWT R15, #proc_addr16" and later R11 was used as return address. But different LINK offsets are used for different loading schemes of R15 instruction pointer.

So there are a lot of prefixes/extended opcodes/immediate data/specialised registers and asymmetries in operations for me to honestly claim that SuperFX architecture is RISC.

93143
Posts: 1146
Joined: Fri Jul 04, 2014 9:31 pm

Re: SNES Doom development, Randy Linden

Post by 93143 » Mon Jun 08, 2020 12:24 am

That's what you get when you design a RISC chip with single-word instructions and an 8-bit bus. That just isn't enough bits for all the instructions that you'd want to pack with even one 4-bit register name, never mind two or three.

(There's also the fact that it was somewhat specialized for drawing graphics. The merge opcode doesn't make much sense until you realize it's ideal for texture mapping...)

I wonder how much more expensive a Super FX with full 16-bit external data busing would have been. Not only would memory access have been faster, but the instruction set would have had room to breathe. I imagine the instruction cache might have had to be a KB instead of 512 bytes... Memory compatibility with the S-CPU wouldn't have been an issue because it's easy to use the bottom address bit as a half-word selector...

93143
Posts: 1146
Joined: Fri Jul 04, 2014 9:31 pm

Re: SNES Doom development, Randy Linden

Post by 93143 » Tue Jun 16, 2020 4:34 pm

So I've had a quick look through the Doom code in Mesen-S, and I don't see a whole lot of ldw; color; plot; swap; color; plot or anything like that. I do see a fair bit of getc; plot; plot; dec R1; dec R1; dec R2 (with other stuff mixed in, control code and branches and such). In other words: get a colour from the ROM buffer, draw two pixels to the coordinates (R1,R2) with R1 incrementing after each pixel, undo the autoincrement on the X-coordinate (R1), and decrement the Y-coordinate (R2).

(There's also some getb; color; plot; from R4; color; loop; plot, which by how the color sources are handled looks like it might be dither code (you can't autodither at 8bpp unless I'm greatly mistaken). And some plot; plot; plot; plot; plot; plot; plot; plot, which was amusing but I'm not sure what it could be for. Maybe it's for clearing the map screen, but why does it show up more than once? None of these methods appears to be using a secondary buffer or any way to run multiple columns at a time.)

Looks like Randy didn't try to get fancy with the renderer. Unless I missed something, or the debugger misinterpreted code as data somewhere, most things seem to be drawn directly with plot in individual columns of double pixels. Based on my understanding of the Super FX, I believe it is possible (at least with some CPU-ROM added; this game is pretty squished I'm told) to speed things up significantly.

Take with a grain of salt; I haven't done a thorough code review or anything...

93143
Posts: 1146
Joined: Fri Jul 04, 2014 9:31 pm

Re: SNES Doom development, Randy Linden

Post by 93143 » Fri Jul 03, 2020 1:25 am

I guess I'm the only one who's suddenly developed a semi-obsession with SNES Doom after watching the Randy Linden interview.

Once the source code drops, it will hopefully be possible to figure out how he did what he did in detail, and from that whether it's possible to materially improve it in certain ways. (It's eye-opening reading the Doom Black Book; apparently just the visplane array alone in the PC version was larger than the RAM available to the Super FX in the SNES version.) Some potential improvements, however, are apparent even now, as the port was somewhat limited by incidental technical and schedule constraints.

...

We know it's possible to add up to 6 MB of CPU-only ROM in parallel with the Super FX, although apparently Nintendo didn't offer this early enough for Doom to use it. This alone would have noticeably improved Randy's port, by allowing him to remove a bunch of stuff like splash screens, gun and status bar graphics, and audio data from the Super FX's ROM, thus making room for some of the stuff he had to cut (in addition to allowing for higher quality in the moved items - e.g. the title screen in the released game is multipalette 4bpp, and looks somewhat hideous).

I've thought of a way to further compress most of the graphics - walls, objects, maybe even skies. I haven't tested it, but if it works well, it could cut the size of the assets almost in half compared to RLE while being almost as fast. I've also come up with what I think is a good way to compress textures for flats without slowing down texturing much. This could allow more of the original game's assets to fit in the Super FX's ROM. Randy mentioned he wanted to look into improved compression but ran out of time.

Although it needs further development, I'm just about convinced that my intermediate buffering idea constitutes a practical way to improve the rendering speed. (Also, if done fullscreen rather than just for walls, it would enable framebuffer effects like Spectres, although this would eat into the speed advantage.) Depending on the situation, using this method might save as much as a frame or two per viewport update, even while ditching low-detail mode for full resolution at the same time.

Speaking of low-detail mode, with the mosaic trick it's pretty much a straight-up 50% savings on pixels drawn and a 50% savings on DMA time, and with textured flats you wouldn't miss the dither. It might be worth it to include it as an option even if full resolution works well, because low-detail mode might work better. Especially at frame sizes that don't work at all in full resolution due to VRAM limits...

Circle-strafing should be easy to enable. Figuring out what causes Doomguy to get stuck on walls might be more complicated...

...

My big question right now is whether the S-CPU, running in a large pool of FastROM with tons of lookup tables and provided with a fast SRAM scratch pad, could handle the bulk of the non-rendering part of the engine fast enough to keep pace with an optimized GSU renderer. If so, a substantial performance increase could be on the cards.

If the CPU can handle enough of the pre-render setup, the level data could even be moved out of Super FX ROM to free up more space. And if enough space can be saved in Super FX ROM (and my compression techniques perform as hoped), it might be possible to include all of the PC version's graphical assets.

User avatar
aa-dav
Posts: 56
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: SNES Doom development, Randy Linden

Post by aa-dav » Fri Jul 03, 2020 7:39 am

I think it is very interesting topic/theme.
But Randy Linden still didn't publish code and this is sad.
Definitely I want to see it and do some analysis (but I do not plan to do some serious work/research).
Moreover, I think Doom community is strong (I am part of it as gamer and I complete tops of 'Cocawards' every year and enjoy it every time) and I think it will become part of this culture/society.
Because it is special thing in many aspects.
Maybe some 'collective letter' to Linden? Just to ask why sources are not published yet? Maybe some problems with publisher or something?

Post Reply