Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building gets stuck while compiling AudioBank.cpp (Linux aarch64) #114

Open
jasaldivara opened this issue Jul 24, 2021 · 7 comments
Open

Comments

@jasaldivara
Copy link

I'm trying to build Spelunky-PSP on Linux aarch64
My OS is Fedora 34 AArch64
My CPU is RK3399 (6 cores ARM 64 bits) and have 4 GB of RAM

I have followed the instructions, running first ./scripts/config-linux.sh, and then ./scripts/build-linux.sh

Building process starts fast, but then gets stuck on 20%, after:

[ 20%] Linking CXX static library libCollisions.a
[ 20%] Built target Collisions

It stays there for hours without making any progress. One of the CPU cores stays working at 100% while the other ones are not doing any hard work.

On the system monitor I see the process cc1plus (gcc c++ compiler?) is the one using 100% of one core and 1.3 GB of RAM. After examining it's command line I see it's trying to compile src/audio/src/AudioBank.cpp. When viewing it's opened files, the last one is 'src/audio/include/generated/title.wav.hpp', which is a 13MB source file containing raw data in the form of a char array.

It has been there by 5 hours without making any progress.

Maybe 13 MB is too heavy for being parsed and compiled by g++? Is there any way to import the WAV binary files without compiling them as sources? I know in some ASM dialects there is an incbin command which just import a a binary raw file, but I don't know if c++ has something similar.

Captura de pantalla de 2021-07-24 13-05-14

@dbeef
Copy link
Owner

dbeef commented Jul 25, 2021

Hello @jasaldivara.

You are correct, compiling AudioBank requires relatively high amount of RAM and this happened to me when compiling directly on a Raspberry Pi.

As a workaround, you can either download a Linux release from Github (forgot you're on ARM64), cross-compile from another computer or disable the Audio altogether by replacing in src/audio/CMakeLists.txt:

add_library(Audio STATIC
        include/AudioBank.hpp
        interface/audio/Audio.hpp
        interface/audio/SFXType.hpp
        interface/audio/MusicType.hpp
        # Compile AudioBank only when it is actually utilized on target platform:
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,src/AudioBank.cpp,>
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,src/AudioBank.cpp,>
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,src/AudioBank.cpp,>
        # Compile audio backend (dummy when audio is not supported):
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_PSP}>,src/Audio_SDL_mixer.cpp,>
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_WINDOWS}>,src/Audio_SDL_mixer.cpp,>
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_LINUX}>,src/Audio_SDL_mixer.cpp,>
        $<IF:$<BOOL:${SPELUNKY_PSP_PLATFORM_ANDROID}>,src/Audio_Dummy.cpp,>
)

with:

add_library(Audio STATIC
        include/AudioBank.hpp
        interface/audio/Audio.hpp
        interface/audio/SFXType.hpp
        interface/audio/MusicType.hpp
        src/Audio_Dummy.cpp
)

Regarding the asm, I think it would be possible without incbin you mentioned - I could re-work the resource compiler to output the asm files directly, with the same data contents as is defined in the header file. Not sure how portable between toolchains these files will be - only data section will be defined, no instructions, but still. Will try to come up with some proof of concept later.

@dbeef
Copy link
Owner

dbeef commented Jul 25, 2021

Also what came to my mind - try creating/increasing a swap file.

@jasaldivara
Copy link
Author

jasaldivara commented Jul 25, 2021

How much RAM would be required for compiling AudioBank?

I have 4 GB of RAM, and 4 GB of swap, but cc1plus is only taking 1.3GB. Maybe there are some parameter I could pass to GCC to use more RAM?

@dbeef
Copy link
Owner

dbeef commented Jul 25, 2021

Weird, I would expect it to work given the swap.
Please edit the /scripts/build-linux.sh and change nproc to 1, so to make sure it only does the job on one core (less parallel allocations) and try again.

@jasaldivara
Copy link
Author

When I disable audio on src/audio/CMakeLists.txt it takes less than 10 minutes to successfully produce a working executable.

Please edit the /scripts/build-linux.sh and change nproc to 1, so to make sure it only does the job on one core (less parallel allocations) and try again.

Changed nproc to 1 with audio enabled, but still gets stuck while compiling AudioBank.cpp. cc1plus still just takes 1.3 GB of RAM.

@dbeef
Copy link
Owner

dbeef commented Aug 1, 2021

I spent some time today on this and made a working solution - I pushed it to resource-compiler-outputs-asm branch in case you wanted to test it.

I re-worked resource-compiler to output .asm files in the following manner:

dbeef@dbeefstation-big:~/Desktop/spelunky-psp/cmake-build-debug/tools/resource-compiler$ cat test.txt 
This is an arbitrary file
dbeef@dbeefstation-big:~/Desktop/spelunky-psp/cmake-build-debug/tools/resource-compiler$ ./resource-compiler test.txt test.txt.asm
Finished successfuly.
dbeef@dbeefstation-big:~/Desktop/spelunky-psp/cmake-build-debug/tools/resource-compiler$ cat test.txt.asm 
    .section .rodata
    .align 1
    .global test_txt
    .hidden test_txt
test_txt:
    .byte 84,104,105,115,32,105,115,32,97,110,32,97,114,98,105,116,114,97,114,121,32,102,105,108,101,10
    .align 4
    .global test_txt_length
    .hidden test_txt_length
test_txt_length:
    .4byte 26

Instead of outputting a header file, as in current master:

#pragma once
// Generated from: test.txt, at: Sun Aug  1 16:43:38 2021

char data[] = 
{
    84,104,105,115,32,105,115,32,97,110,32,97,114,98,105,116,114,
    97,114,121,32,102,105,108,101,10,
};

It is less accessible than the header-file version - you can't just include it and use the char*, now you need to define an extern symbol and know its name, that corresponds to the resource-compiled filename - in the end doesn't matter much as I encapsulate access to it in AudioBank.hpp anyway.

As I guessed, this removed a significant amount of work from the compiler - not only peak memory usage is smaller, but build is much faster:

Master:
real    1m36,283s
user    8m2,106s
sys     0m24,829s
resource-compiler-outputs-asm:
real    0m54,400s
user    7m15,484s
sys     0m23,726s

I did the final verification by setting up a VM with 1 GB of RAM + 2 GB of swap. I used all 8 CPU cores.

It froze building master, as in your case, but did finish successfully when building the .asm version.

I leave the issue opened untill #115 is merged (so far only Windows is failing with these changes).

@jasaldivara
Copy link
Author

Hi @dbeef

I tried building your resource-compiler-outputs-asm branch and it worked perfectly on my ARM64 Linux system.

Now I have a working Spelunky_PSP with audio enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants