Featured image of post Am I an open source contributor now?

Am I an open source contributor now?

Ya know since SUBMITTED A PR!!!

A few days ago, I made my first real open source contribution. I’ve meddled around within my own projects before, using pull requests as a purely functional means to manage my code bases. But I need to take it upon myself to learn how to collaboratively build with others. To that extent, when I ran into a wall with my mGBA shaders from the other day, I realized I could help engineer the solution.

Some of the following is covered in my previous post, but that was very brief so I’m expanding it out here.

In service of playing some games in Super Game Boy mode, I wanted to simulate the SGB experience. The SGB was an add-on Nintendo made for the Super Nintendo that allowed you to play Game Boy and Game Boy Color games on your SNES. Some games even supported SGB-only enhancements that lift the experience above and beyond how they played on their original systems. Part of this process requires that I port TheMaister’s NTSC shaders to work with mGBA. It was… almost working. Everything was tinted magenta.

Why is it so ourple

TheMaister’s NTSC shaders work by passing the output image through 2 different shader passes: the first processes the image into a format closer to that sent over analog video cables (complete with noisiness and blurring), and the second processes it back into a human-viewable color space. While trying to figure out why it was turning everything magenta, I noticed a couple things:

  • In the original shader, the first pass requests a floating-point framebuffer instead of an integer one
  • When disabling the original shader’s floating-point framebuffer, it also turned everything magenta

With float_framebuffer on With float_framebuffer off… isn’t this familiar?

So basically, when passing the data between the first pass and the second, it needs to write the image’s colors down somewhere. Normally it’s OK to use the bog-standard 8-bit integers per channel (that means each pixel’s color is written as 3 integers from 0 to 255, one per Red, Green, and Blue channel). But in this case, rounding all the numbers to be within that range causes some data loss, and the colors go all funky. I suspect it’s crushing low numbers to pure black, but that’s just a hunch. We need a floating point framebuffer to allow significantly less data loss to occur. It’s essentially a computer’s way of writing things in scientific notation, so it becomes practical to compute very small and very large numbers with minimal error.

So I got digging, figuring out where mGBA makes its framebuffers and figuring out where RetroArch (where the original shader was intended to be used) makes its framebuffers (and most particularly where it makes its floating point framebuffers), analyzing the differences and banging my head against a wall. Eventually I figured out exactly where I needed to make changes. After a little back-and-forth within the mGBA dev community to figure out if my approach was acceptable for the project, I opened up a request to pull my code on Halloween. A few days later, it was accepted into the project. My first real open-source PR! I’m a big kid now! You can check it out here.

It’s pretty again!

I have a couple more things to fix before I can consider this obsession completed, but I can’t just rush things just because I’m excited. One of the next things involves getting the frame counter passed into the shader, but the lead dev has asked me to hold off while some other frame counter issues are fixed in the meantime. I tried my hand at looking into it myself, but it may requrie some advanced knowledge of the architecture of the Game Boy family of systems and the emulator itself so my hands are tied for now. Maybe I can work on aspect ratio correction… :)

This project took a lot from me… I’m more used to writing small codebases only meant for myself, but this involved jumping into a large and mature codebase, where even figuring out where to start wasn’t something that came naturally. It all worked out in the end though, since I wanted a feature and I typed away until I brought it into reality myself. I’ve even started to see other places where I can improve other open-source projects I use. A whole new world of potential is opening up in front of me.

Thank you so much for reading, have a nice day.

– Patch

Please contact me with any questions
Built with Hugo
Theme Stack designed by Jimmy