phoboslab / wipeout-rewrite

2.64k stars 212 forks source link

Linux PowerPC: Endian issues #56

Closed chzigotzky closed 1 year ago

chzigotzky commented 1 year ago

Hello,

Thanks a lot for wipEout Rewrite! :-)

I was able to compile it on ubuntu MATE 16.04.7 PowerPC today. It starts but it has wrong colors and the sound isn't correct. I think it is an endian issue because Linux PowerPC runs on big endian machines. I tested it on Void PPC as well but unfortunately it has the same issues on it. Is it possible to fix these issues?

Screenshot:

wipEout_Rewrite_Linux_PowerPC

Thanks, Christian

Jamesf4 commented 1 year ago

Littlebit but still Cool

ส่งจาก Outlook for iOShttps://aka.ms/o0ukef


จาก: Christian Zigotzky @.> ส่ง: Monday, August 28, 2023 11:29:26 AM ถึง: phoboslab/wipeout-rewrite @.> สำเนาถึง: Subscribed @.***> ชื่อเรื่อง: [phoboslab/wipeout-rewrite] Linux PowerPC: Endian issues (Issue #56)

Hello,

Thanks a lot for wipEout Rewrite! :-)

I was able to compile it on ubuntu MATE 16.04.7 PowerPC today. It starts but it has wrong colors and the sound isn't correct. I think it is an endian issue because Linux PowerPC runs on big endian machines. I tested it on Void PPC as well but unfortunately it has the same issues on it. Is it possible to fix these issues?

Screenshot:

[wipEout_Rewrite_Linux_PowerPC]https://user-images.githubusercontent.com/43322007/263642597-48cd5647-0075-4f36-8cbd-69bce55a5976.png

Thanks, Christian

— Reply to this email directly, view it on GitHubhttps://github.com/phoboslab/wipeout-rewrite/issues/56, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AWWX633Y2I5ZSV56SXQO7QDXXRJGNANCNFSM6AAAAAA4BBZXPY. You are receiving this because you are subscribed to this thread.Message ID: @.***>

phoboslab commented 1 year ago

Very cool to see that you got it running at all!

Questions:

The title screen is in straight 16bit colors, while most (all?) of the textures are paletted. I assume reading the colors from the palette isn't endian agnostic. The palette lookup seems to work though.

I have a harder time to understand where the sound issues come from. The wipeout.vb file with all the samples is read one byte at a time. If there's issues with the music, there is probably a bug in the QOA decoder itself. You can change the volume of sound effects and music in the main options to check what exactly is broken.

phoboslab commented 1 year ago

Above commit should fix this color issues. Let me know if it works! :]

chzigotzky commented 1 year ago

Thanks for your fast answer. The color issue is partly fixed with your commit. :-)

wipEout_1

wipEout_2

wipEout_3

Music and sound effects are both garbled.

BeWorld2018 commented 1 year ago

Thanks for this fix, I had the same problem under MorphOS PPC.

For audio, you can modify this : https://github.com/phoboslab/wipeout-rewrite/blob/master/src/platform_sdl.c#L393 Put AUDIO_F32SYS (https://wiki.libsdl.org/SDL2/SDL_AudioFormat)

chzigotzky commented 1 year ago

Yes, the audio fix works! :-) Thanks!

There are still some color issues.

phoboslab commented 1 year ago

Thanks for the audio fix @BeWorld2018 and thanks for all the screenshots @chzigotzky; it helps a lot.

The 4bpp textures seem to work now, but the 8bpp track textures are still wrong and I can't figure out why. It's almost the same code for 4bpp and 8bpp...

phoboslab commented 1 year ago

I suspect I was overly smart; trying to swap the palette in-place. Which doesn't work when the whole get_u16_le() function is inlined. Hope that was it :]

chzigotzky commented 1 year ago

Many thanks for your help! :-) The colors partly arent't correct but it looks really better.

wipEout_4

BeWorld2018 commented 1 year ago

In my side, i use OpenGL Legacy renderer from unoffical repository : https://github.com/mrneo240/wipeout-rewrite/blob/master/src/render_gl_legacy.c but i have some problem with colors, i think i's better now but not perfect :

with MorphOS (PPC): image

with Windows (same renderer): image

phoboslab commented 1 year ago

Texture loading seems to work now, but the vertex colors for the track are backwards!? I'm looking into it.

Also, judging from the trees, this legacy OpenGL renderer is missing a glEnable(GL_ALPHA_TEST) :]

BeWorld2018 commented 1 year ago

Also, judging from the trees, this legacy OpenGL renderer is missing a glEnable(GL_ALPHA_TEST) :]

You right, i put that and tree are now correct, thanks

phoboslab commented 1 year ago

Well, I can't find anything wrong with the texture loading and I have no way to test big endian machines. Is there maybe some way I can do this in a VM?

Also, if you have a minute, can you please try and change this line from

vec4 color = tex_color * v_color;

to

vec4 color = v_color;

This will disable texture rendering. If you then enter the game, we can at least check if a) the vertex colors are wrong or b) it's still the texture loading.

chzigotzky commented 1 year ago

I have changed the line and compiled it again. Result:

wipEout_5

phoboslab commented 1 year ago

Thanks for the screenshot! So it was the vertex colors and initializing them with rgba_t color = {.as_uint32 = get_i32_le(bytes, &p) | 0xff000000}; obviously didn't work. Above commit should fix that.

I will clean up the code a little and get rid of the .as_uint32 union completely. I believe that was the only instance it was used anyway.

chzigotzky commented 1 year ago

The colors are all correct! Thanks a lot! :-) I compiled it on an old ubuntu MATE 16.04.7 PowerPC and it works without any problems. I also compiled and tested it on Void PPC and on a new Debian Sid PPC but unfortunately the sound stutters sometimes.

chzigotzky commented 1 year ago

The intro video also stutters on Void PPC and Debian PPC. An SDL issue?

They don't stutter on the old ubuntu MATE 16.04.7 PowerPC.

phoboslab commented 1 year ago

Sound stuttering can maybe be fixed by increasing the buffer size here at the cost of some sound latency. Try setting it to .samples = 4096, or even higher. Let me know if that helps; I can add that as in-game option.

As for the video: how's the CPU load during the intro?

chzigotzky commented 1 year ago

Thank you very much for your answer! Unfortunately, setting it to .samples = 4096 does not solve the stuttering problem. Even a higher level does not solve the problem.

During the stuttering the CPU load is about 90%.

BeWorld2018 commented 1 year ago

For me, i adapt OpenGL legacy render, and color seem ok here tooo (compare to Windows version) Now compare to OpenGL 3 renderere, there are some difference... but it's not your problem

Result MorphOS/Windows with OpenGL legacy 👍 (Track border seem yellow instead of purple) image

Thanks again !

chzigotzky commented 1 year ago

When I start a race, the sound stutters and the CPU usage increases to 90%. A short time later, the stuttering goes away and the CPU usage decreases.

Maybe I should test it with the libsdl2 from ubuntu MATE 16.04.7. (LD_LIBRARY_PATH)

phoboslab commented 1 year ago

Result MorphOS/Windows with OpenGL legacy 👍 (Track border seem yellow instead of purple)

Not really sure what's going on with the track colors, but the color blotches in the audience stands could be from an overflow!? I think this:

uint8_t R = tris.vertices[i].color.as_rgba.r;
uint8_t G = tris.vertices[i].color.as_rgba.g;
uint8_t B = tris.vertices[i].color.as_rgba.b;
if(R == 128){
    R = 255;
} else {
    R *=2;
}
if(G == 128){
    G = 255;
} else {
    G *=2;
}
if(B == 128){
    B = 255;
} else {
    B *=2;
}
tris.vertices[i].color.as_rgba.r = R;
tris.vertices[i].color.as_rgba.g = G;
tris.vertices[i].color.as_rgba.b = B;

should just be (sans as_rgba as removed in a commit today)

tris.vertices[i].color.r = clamp(tris.vertices[i].color.r * 2, 0, 255);
tris.vertices[i].color.g = clamp(tris.vertices[i].color.g * 2, 0, 255);
tris.vertices[i].color.b = clamp(tris.vertices[i].color.b * 2, 0, 255);

Or glColorPointer() needs to be float and you divide all color values by 128.0. For whatever reason wipEout mostly seems to use the 0..128 color range, but then sometimes exceeds it with > 128 "whiter than white" overbright values.

BeWorld2018 commented 1 year ago

You right on first solution ! Thanks again ;-) image

chzigotzky commented 1 year ago

I have found the issue. -> A L T I V E C

We have stuttering on Void PPC on a Non-AltiVec PowerPC machine. (FSL P50x0)

We don't have stuttering on Void PPC on a PowerPC machine with a SoC with AltiVec support. (P.A. Semi PA6T)

It seems the libs on ubuntu MATE 16.04.7 PowerPC aren't compiled with AltiVec support so wipEout runs without stuttering on a Non-AltiVec PowerPC machine.

Is it possible to compile a static wipEout binary (.a)? Maybe this is a solution.

chzigotzky commented 1 year ago

Hi BeWorld,

Congratulations! Maybe I should test the OpenGL Legacy renderer version as well.

Could you please share your modified source code of the OpenGL Legacy renderer version?

Thanks, Christian

chzigotzky commented 1 year ago

Hi All,

I patched the OpenGL Legacy renderer version and it runs without any stuttering on Void PPC on my Non-AltiVec PowerPC machine.

There are some graphical issues for example missing transparency.

wipEout_legacy_render_Linux_PPC

BeWorld2018 commented 1 year ago

hi,

On this file: https://github.com/mrneo240/wipeout-rewrite/blob/master/src/render_gl_legacy.c

i just add after line 114 glEnable(GL_ALPHA_TEST); And add patch:

void render_push_tris(tris_t tris, uint16_t texture_index) {
    error_if(texture_index >= textures_len, "Invalid texture %d", texture_index);

    if (tris_len >= RENDER_TRIS_BUFFER_CAPACITY) {
        render_flush();
    }
    if(texture_index != texture_index_prev){
        render_flush();
    }
    texture_index_prev = texture_index;

    render_texture_t *t = &textures[texture_index];

    for (int i = 0; i < 3; i++) {

        // resize back to (0,1) uv space
        tris.vertices[i].uv.x = (tris.vertices[i].uv.x / t->size.x) * t->scale.x;
        tris.vertices[i].uv.y = (tris.vertices[i].uv.y / t->size.y) * t->scale.y;
        if(tris.vertices[i].color.a == 0){
            continue;
        }
        tris.vertices[i].color.r = clamp(tris.vertices[i].color.r * 2, 0, 255);
        tris.vertices[i].color.g = clamp(tris.vertices[i].color.g * 2, 0, 255);;
        tris.vertices[i].color.b = clamp(tris.vertices[i].color.b * 2, 0, 255);;

    }
    tris_buffer[tris_len++] = tris;
}

And i add patch to release textures when exit game:

void render_cleanup(void) {
    // TODO
    render_textures_reset(render_textures_len());

}
chzigotzky commented 1 year ago

Hi BeWorld,

Thanks a lot for your answer. I modified the render_gl_legacy.c with your changes and compiled it again.

Unfortunately, the issue with the missing transparency still exist. (see my last screenshot)

Thanks, Christian

chzigotzky commented 1 year ago

BeWorld,

Have you applied all patches from phoboslab to the OpenGL Legacy renderer version?

Thanks, Christian

BeWorld2018 commented 1 year ago

i recompare my file with original opengl legacy and all difference are mentioned in my reply.

chzigotzky commented 1 year ago

BeWorld,

Thanks for your answer. It works with the correct colors and sound now! :-)

Many thanks to all! :-)

Cheers, Christian

chzigotzky commented 1 year ago

It works with the correct colors and without sound stutters with my AMD Radeon HD6970 (Cayman XT).

Unfortunately it has color issues with the ATi Radeon X1900 XT (R580):

Screenshot-at-2023-09-02-15-23-25

madskateman commented 1 year ago

It works with the correct colors and without sound stutters with my AMD Radeon HD6970 (Cayman XT).

Unfortunately it has color issues with the ATi Radeon X1900 XT (R580):

Screenshot-at-2023-09-02-15-23-25

On this PPC machine the BeWorld MorphOS port is working perfect. So the X1900 (R580) GPU is ok.

https://www.skateman.nl/wp-content/uploads/2023/09/MOS_WIPEOUT.jpg

phoboslab commented 1 year ago

Closing this issue. The problems that remain seem to be driver specific. Feel free to open another issue if you find more problems with the game itself.