Multiboot2 spec for RGB colours.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
vinnie
Posts: 5
Joined: Fri Jul 10, 2020 9:27 pm

Multiboot2 spec for RGB colours.

Post by vinnie »

Hi Guys

I can't seem to find any limits on the RGB colour sizes for Multiboot2 Frame Buffers. I.e. framebuffer_red_mask_size, framebuffer_red_field_position, etc.

Being defined as a u8, it can obviously not be larger than 255 bits, but that seems rather impractical to implement as worst case guarantee. The example code uses a u32 to compute the colour, but I'm not sure this is a guaranteed limit either.

Are there any bounds defined for these properties? How do you guys write your unit tests?

Cheers
-Vinnie
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multiboot2 spec for RGB colours.

Post by Octocontrabass »

They can't exceed framebuffer_bpp bits in total, and they can't overlap each other.
vinnie
Posts: 5
Joined: Fri Jul 10, 2020 9:27 pm

Re: Multiboot2 spec for RGB colours.

Post by vinnie »

Is there a limit on the framebuffer_bpp?
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multiboot2 spec for RGB colours.

Post by Octocontrabass »

It's unlikely to ever exceed 64. (There's no practical use for more than 16 bits per channel or more than 3 channels. Pixel data is often padded to power-of-2 boundaries in memory.)
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Multiboot2 spec for RGB colours.

Post by bzt »

Octocontrabass wrote:It's unlikely to ever exceed 64. (There's no practical use for more than 16 bits per channel or more than 3 channels. Pixel data is often padded to power-of-2 boundaries in memory.)
I would say 32 bit is more reasonable (3 * 8 bit channels plus a padding for dword access). I've once seen a very old video card that used 96 bits (3 * 32 bit channels, using float), but that's very uncommon, and it was before 32 bit true-color framebuffers and VESA 2.0 got widespread. Today all float color channels are solely used by the GPU, and not on framebuffers which are shared with the CPU (however I believe on some cards you can set up a fragment shader to use float channels not only on the textures, but on the output framebuffer too. Anyway, nobody does that, even if it's possible because it quadriples the buffer's size without real benefit).

Cheers,
bzt
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multiboot2 spec for RGB colours.

Post by Octocontrabass »

bzt wrote:I would say 32 bit is more reasonable (3 * 8 bit channels plus a padding for dword access).
There are displays that support 10 bits per channel. You might end up with each channel padded to 16 bits and the entire pixel padded to 64 bits.
vinnie
Posts: 5
Joined: Fri Jul 10, 2020 9:27 pm

Re: Multiboot2 spec for RGB colours.

Post by vinnie »

Cheers. For performance sake, I ended up writing three versions, 32, 64 and generic that can support up to 256bit. I also applied the rules:
Octocontrabass wrote:They can't exceed framebuffer_bpp bits in total, and they can't overlap each other.
I think that address all the buffer size cases.
bzt wrote:Today all float color channels are solely used by the GPU, and not on framebuffers which are shared with the CPU...
I did not even think about float colours, though multiboot does not seem to even mention it in passing. It should not result in a buffer overflow / underflow if it's the wrong type of the same size, so I think that can be parked as a zero risk ... ?
Octocontrabass
Member
Member
Posts: 5567
Joined: Mon Mar 25, 2013 7:01 pm

Re: Multiboot2 spec for RGB colours.

Post by Octocontrabass »

vinnie wrote:It should not result in a buffer overflow / underflow if it's the wrong type of the same size, so I think that can be parked as a zero risk ... ?
Correct. If the type is wrong, you'll get very strange colors, but no overflow/underflow.
Post Reply