Anyone had success with >8bpp indexed textures?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Anyone had success with >8bpp indexed textures?

Post by jsgf »

I've played with them a bit, but I can't get them to come out right. Is there something stupid I'm overlooking? I'm assuming the index is little-endian, and the CLUT is just linear in memory, and then doing the equivalent of

Code: Select all

sceGuClutMode(GU_PSM_8888, 0, 0xff, 0);
sceGuClutLoad(65536/8, myclut);
(BTW, "a2" for sceGuClutMode() need to be 0xff; I think its a bit mask which is applied to something, but I'm not quite sure what.)

I'm wondering if large CLUTs need to be uploaded/installed in pieces or something.

Any ideas?
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

/**
* Upload CLUT (Color Lookup Table)
*
* NOTE: Data must be aligned to 1 quad word (16 bytes)
*
* @param num_blocks - How many blocks of 8 entries to upload (32*8 is 256 colors)
* @param cbp - Pointer to palette (16 byte aligned)
**/
void sceGuClutLoad(int num_blocks, const void* cbp);


a) make sure myclut was aligned on 16 byte on allocation
b) you're trying to submit (65536/8) * 8 = 65536 entries. Yet a CLUT4 has only 16 and a CLUT8 only 256 entries. So the only two possible parameters for num_blocks would be 2 or 32.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Raphael wrote:a) make sure myclut was aligned on 16 byte on allocation
Yup, got that.
b) you're trying to submit (65536/8) * 8 = 65536 entries. Yet a CLUT4 has only 16 and a CLUT8 only 256 entries. So the only two possible parameters for num_blocks would be 2 or 32.
No, you missed my point. The hardware appears to also support 16 and 32 bit CLUT indices (see src/gu/doc/commands.txt for command 195), but I can't get them to do anything useful.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Well, apart from the fact that I don't get the point, why anyone would use a 16 or even 32bit indexed palette as it's only memory waste and nothing else... did you set
sceGuTexMode(GU_PSM_T16, maxmips, a2, swizzle) and also upload the texture correctly? I'd guess the GU needs to know the tex mod
Also GU_PSM_T16 isn't mentioned in the description of the function although it is defined in the gu header. So probably it's not correctly implemented yet?

You could however send the raw commands to the gu and try your luck. Should be something like this:

Code: Select all

sceGuSendCommandi(0xC3, 6); // Texture Pixel Storage Format CLUT16
sceGuSendCommandi&#40;0xC5, &#40;11b | &#40;0xff << 8&#41;&#41; &#41;; // Set CLUT8888 &#40;bit order could be wrong&#41;
sceGuSendCommand&#40;0xB0, &#40;&#40;int&#41;CLUT&#41; & 0xfffffff &#41;; // send 24 LSB of clut pointer
sceGuSendCommand&#40;0xB1, &#40;&#40;int&#41;CLUT&#41; >> 24 &#41;; // send 4 MSB of clut pointer
sceGuSendCommandi&#40;0xC4, 65536/8&#41;; // Set number of Colors and upload the data
I haven't tried anything like that yet, though. But if the GU really supports it, this has to work.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Raphael wrote:Well, apart from the fact that I don't get the point, why anyone would use a 16 or even 32bit indexed palette as it's only memory waste and nothing else...
I've been working on two uses:
  1. Using the depth buffer as a texture, and using the CLUT to tint the depth buffer in interesting ways. chp has a demo where you can use the depth buffer as an 8bpp format texture (by scaling it down so it ignores every second byte), but using it in 16bpp format could be useful.
  2. for general colour transforms: if render into a texture with 16bpp, then you can use the texture as a 16-bit index texture, and apply arbitrary colour transforms with the CLUT.
But I haven't had much success with either of these. It seems to only use the lower 8 bits of the index either way (though it does seem to treat them as 16-bit indices).

I suspect the other arguments to sceGuClutMode() are the key. I wonder if you can only use 2^8 CLUT entries at once, but the other params to ClutMode define how your 16/32bpp index gets mapped to the 2^8 entries...
sceGuTexMode(GU_PSM_T16, maxmips, a2, swizzle) and also upload the texture correctly? I'd guess the GU needs to know the tex mod
Also GU_PSM_T16 isn't mentioned in the description of the function although it is defined in the gu header. So probably it's not correctly implemented yet?
I don't think there's anything special to implement. The existing sceGuClutMode/ClutLoad are equivalent to your open-coded versions.
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

jsgf wrote: I suspect the other arguments to sceGuClutMode() are the key. I wonder if you can only use 2^8 CLUT entries at once, but the other params to ClutMode define how your 16/32bpp index gets mapped to the 2^8 entries...
I played around with these parameters a some point, for the same reason as you, but I didn't get to understand it all and haven't looked at it since.

As I remember the second argument is a shift value and the third is a mask (or the other way around, try setting one to zero and play with the other, the shift value is quite easy to find). The last parameter is probably the interesting part, which I never got to understand, only getting some strange stuff that didn't make sense.

I you figure out the last part, please post, since I could still use it :)
Br, Sandberg
rinco
Posts: 255
Joined: Fri Jan 21, 2005 2:12 pm
Location: Canberra, Australia

Post by rinco »

I also spent many hours trying to get 16 or 32bpp CLUT to work with SDL video (so noiz2sa can do hw accelerated blits and rects). In the end I decided that not enough is known about the parameters to sceGuClutMode - and gave up.
subbie
Posts: 122
Joined: Thu May 05, 2005 4:14 am

Post by subbie »

I have a question. Are you trying to make an index table greater then 256 entries? I am a little confused on what your trying to do. Like on my project iris I use cluts but reduce textures to less then 256 entries but each entrie in the clut is 32bit 8888 rgba.

Also when you render your texture you making to the proper mode?

Like if your going to use a 16bit/32bit clut (in size, not color depth), setting the texture mode to GU_PSM_T16/GU_PSM_T32.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

I'm generating a 64k entry table with RGBA8888 colours in each entry, and then using a 16bit-per-pixel texture with the mode set to GU_PSM_T16.
ayatollah
Posts: 15
Joined: Sun Sep 04, 2005 10:49 am

Post by ayatollah »

Well in the official Docs of Library 1.5 it says:

** Please do not spread me like butter on a hot summer day **

Yes edited by blackdroid.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

ayatollah wrote:Well in the official Docs of Library 1.5 it says:
Hey! Don't ever do that! It's an absolute no-no to post any official docs here.
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

Why are you posting official Sony SDK material here?! Can a moderator please delete this?
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Come to think, since we mask the indices with 0xff, only the lower 8bit would be used, thus only 256 of the 65536 or more only be used. So we'd have to apply a mask 0xffff, but this isn't possible, because the mask sent can be only 8bit wide. However there's the shift argument as sandberg said and if it does what I suspect, you'd have to call sceGuClutMode with the appropriate shift bit, so you can reach the higher regions of the CLUT. This would mean that you really can only use 256CLUT entries at once, and have to change the shift bit everytime you want to access higher values. So it would be a real pain in the ass to make it work as we want.

But that's just my enlightening thoughts I came up with.
jsgf
Posts: 254
Joined: Tue Jul 12, 2005 11:02 am
Contact:

Post by jsgf »

Yeah, I'm not sure what they were thinking. You could use it to do channel-by-channel remappings in 3 passes.
Post Reply