[split] Compiler off-loading discussion

Moderators: Rachael, dpJudas

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

[split] Compiler off-loading discussion

Post by Rachael » Mon Nov 28, 2016 12:35

Curious but wouldn't it be better, perhaps, instead of providing .asm files, to compile the code directly into the executable? That way the source stays consistently C++ and LLVM is just used more or less as a bridge for the drawers.

I really don't mind having the LLVM dependency, but all things considered (and especially after playing with the LLVM target types) I'm thinking it would be better to have a single block of code that gets put together by the compiler and associated utilities rather than having to compile in the .asm files manually. That would also be beneficial for cross-architecture compiles - for example, compiling QZDoom for ARM devices. (ARMs have souls too, ya know! Even if you mostly hold it with your arm! .... okay I'll show myself out... sorry...)

Sorry, I am not trying to be nitpicky. :) I just dislike the idea of dealing with .asm files at all, and having the drawer code right at the gate seems to be more ideal for anyone trying to mod the engine, rather than someone who would have to eventually get LLVM anyway just to even make changes to the drawers.
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by dpJudas » Mon Nov 28, 2016 13:01

Well, the .asm files gets linked into the executable - all of them. For example, there would be a DrawColumnSSE2, DrawColumnSSE4, DrawColumnAVX and DrawColumnAVX2. When QZDoom boots, it looks at the CPU and decides it can do SSE4. So it points DrawColumn to DrawColumnSSE4.

The drawergen tool could theoretically output .cpp files instead of .asm, but the catch here is that such .cpp files would have to be compiled with specific flags to inform the compiler that it can safely generate SSE and AVX opcodes. The actual contents of those .cpp files would probably not be much more readable than the corresponding .asm files. It would remove the need for LLVM, but using LLVM still has the advantage of being able to "talk" more directly to a compiler backend. Stuff like me already telling LLVM that there cannot possibly be any pointer aliasing going on between the texture pointers and the framebuffer pointers, or which for loops to unroll and by how much.

Writing the drawers as purely C++ code is not really an option. The LLVM drawers are somewhere between 50% to 100% faster than the SSE intrinsics versions that the truecolor branch had. Those, in turn, were twice as fast as pure C++ code without intrinsics. We also have something like 50 drawer variations at this point, which is one of the reasons the launch time has gone up as much as it has.

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by Rachael » Mon Nov 28, 2016 13:11

What I mean is leaving the LLVM drawer code as-is, but instead of compiling at run-time, to compile it directly into the executable at compile time, and not have to embed the LLVM libraries themselves directly into the executable.

LLVM would be executed by MSVC++, and would simply compile the drawers into the 4 sets you mentioned and then MSVC++ would pick up the 4 generated .asm files, run NASM/YASM to get .obj files, and link them accordingly.

It's almost the same as your original proposal, except a: the .asm files would not exist in the actual source, and b: it would still improve boot times by offloading the compile to the compiler, rather than the user.
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by dpJudas » Mon Nov 28, 2016 13:15

That's exactly what that the drawergen tool would do. It is the drawergen tool that needs LLVM, and not QZDoom. Either then run the drawergen tool as part of CMake, or just add the .asm files to the repository so only LLVM is needed if you need to update the drawers.

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by Rachael » Mon Nov 28, 2016 13:17

Running drawergen as part of CMake sounds fine to me.

(I am *really* sorry if I seem so nit-picky >_<)

My goal with this suggestion is - if the person preparing the executable modifies any part of the original source - including the drawers - those changes are effected immediately without the need to manually run an intermediary tool (which would be run automatically by MSVC++, anyway).
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by dpJudas » Mon Nov 28, 2016 13:31

Yeah, I guess it could build the drawer tool first, and then use what it built to generate .asm files (or .obj files directly, as theoretically LLVM can do that).

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by Rachael » Mon Nov 28, 2016 13:36

I'm sorry. I am not trying to make this difficult for you. :( It was just a suggestion.
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by dpJudas » Mon Nov 28, 2016 14:19

Actually, just discovered I could loot the updaterevision CMake files for this, so already half way done with that part of it.

What I'm really trying to figure out now is if it should output .asm or .obj files.

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: Choose OpenGL or software rendere at the startup [IWAD] menu

Post by Rachael » Mon Nov 28, 2016 14:27

Wouldn't .obj files be less work for you?
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [split] Compiler off-loading discussion

Post by dpJudas » Mon Nov 28, 2016 14:34

Trouble with .obj is that I don't know how to get LLVM to output that (although I'm 100% sure it can). It is probably the best option, but I don't like going through hell first. LLVM's documentation is virtually non-existent for its C++ API.

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: [split] Compiler off-loading discussion

Post by Rachael » Mon Nov 28, 2016 14:43

Well - the .asm -> NASM path is fine even if not preferable - whatever works comes first over efficiency and cleanliness.

ZDoom may be eliminating its NASM dependency soon though, which will put QZDoom in a bind because that's one commit that it will have to delay.
Spoiler: Zen Sarcasm

User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: [split] Compiler off-loading discussion

Post by Graf Zahl » Mon Nov 28, 2016 15:43

Concerning assemblers, the only reason ZDoom uses NASM is because it's platform independent. If you can create files for both MASM and GAS it should work everywhere, as MASM is part of the VS distribution.

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [split] Compiler off-loading discussion

Post by dpJudas » Mon Nov 28, 2016 17:39

Turns out getting it to create the .obj file was a lot easier than I expected. The drawers are now generated at compile time rather than run time. It only creates the SSE 2 version for now, because from what I could tell it didn't really make any speed difference between that and the AVX-2 version. Good news is this doesn't require any assembler at all and the start time is now as fast as ZDoom.

The bad news is that the tool runs on every build, which is not really needed. I need to find some good way for it to know that the .obj file is already up to date and doesn't need a recompile.

User avatar
Rachael
Developer
Developer
Posts: 3617
Joined: Sat May 13, 2006 10:30

Re: [split] Compiler off-loading discussion

Post by Rachael » Mon Nov 28, 2016 22:09

Is there anything special I need to do to get this working? Currently I am getting this linker error:

Code: Select all

3>LINK : fatal error LNK1181: cannot open input file 'P:\Users\Guest\Desktop\build\QZDoom\src\r_drawersasm.obj'
Spoiler: Zen Sarcasm

dpJudas
Developer
Developer
Posts: 798
Joined: Sat Jul 23, 2016 7:53

Re: [split] Compiler off-loading discussion

Post by dpJudas » Mon Nov 28, 2016 23:51

Hmm, it should be writing something like this earlier in the log:

Code: Select all

1>------ Build started: Project: drawergen_target, Configuration: RelWithDebInfo x64 ------
1>  Compiling drawer code for pentium4..
That step outputs that .obj file that it says it cannot find.

Locked

Return to “Closed Suggestions”