[patch] Some GU findings

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

[patch] Some GU findings

Post by Raphael »

I just decided to roll the few findings I had on my journey with GU.
The last thing was yesterday, when I suddenly had a single sceGuSync(0,0) call freeze my application for no apparent reason.
Until I just added a sceGuFinish() call before the sync and it worked as normal, so I dug further into why that would happen.
After some trying, I found that sceGuSync(0,2) would solve my problem without having to finish the current display list.

Other than that, I also fiddled a little with the mipmap level mode function and found about it's first parameter, which sets the mipmap mode to auto, constant or user slope (using sceGuTexSlope). The second parameter, obviously is a mipmap bias.

I also added description to the sceGuClutMode functions second and third parameters, which are a shift and mask (as was already stated somewhere quite some time ago IIRC). Still haven't found out about the last parameter though :/

Well, here's the patch to be applied within src/gu

Code: Select all

Index: sceGuClutMode.c
===================================================================
--- sceGuClutMode.c	(revision 2259)
+++ sceGuClutMode.c	(working copy)
@@ -8,8 +8,8 @@
 
 #include "guInternal.h"
 
-void sceGuClutMode(unsigned int cpsm, unsigned int a1, unsigned int a2, unsigned int a3)
+void sceGuClutMode(unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int a3)
 {
-	unsigned int argument = &#40;cpsm&#41; | &#40;a1 << 2&#41; | &#40;a2 << 8&#41; | &#40;a3 << 16&#41;;
+	unsigned int argument = &#40;cpsm&#41; | &#40;shift << 2&#41; | &#40;mask << 8&#41; | &#40;a3 << 16&#41;;
 	sendCommandi&#40;197,argument&#41;;
 &#125;
Index&#58; sceGuSync.c
===================================================================
--- sceGuSync.c	&#40;revision 2259&#41;
+++ sceGuSync.c	&#40;working copy&#41;
@@ -11,11 +11,11 @@
 #include <pspkernel.h>
 #include <pspge.h>
 
-int sceGuSync&#40;int mode, int a1&#41;
+int sceGuSync&#40;int mode, int what&#41;
 &#123;
 	switch &#40;mode&#41;
 	&#123;
-		case 0&#58; return sceGeDrawSync&#40;a1&#41;; break;
+		case 0&#58; return sceGeDrawSync&#40;what&#41;; break;
 		case 3&#58; return sceGeDrawSync&#40;ge_list_executed&#91;0&#93;&#41;;
 		case 4&#58; return sceGeDrawSync&#40;ge_list_executed&#91;1&#93;&#41;;
 		default&#58; case 1&#58; case 2&#58; return 0;
Index&#58; pspgu.h
===================================================================
--- pspgu.h	&#40;revision 2259&#41;
+++ pspgu.h	&#40;working copy&#41;
@@ -168,6 +168,11 @@
 #define GU_TEXTURE_MATRIX	&#40;1&#41;
 #define GU_ENVIRONMENT_MAP	&#40;2&#41;
 
+/* Texture Level Mode */
+#define GU_TEXTURE_AUTO		&#40;0&#41;
+#define GU_TEXTURE_CONST	&#40;1&#41;
+#define GU_TEXTURE_SLOPE	&#40;2&#41;
+
 /* Texture Projection Map Mode */
 #define GU_POSITION		&#40;0&#41;
 #define GU_UV			&#40;1&#41;
@@ -262,6 +267,11 @@
 #define GU_TAIL			&#40;0&#41;
 #define GU_HEAD			&#40;1&#41;
 
+/* Sync behavior */
+#define GU_SYNC_FINISH	&#40;0&#41;
+#define GU_SYNC_SIGNAL	&#40;1&#41;
+#define GU_SYNC_DONE	&#40;2&#41;
+
 /* Signals */
 #define GU_CALLBACK_SIGNAL	&#40;1&#41;
 #define GU_CALLBACK_FINISH	&#40;4&#41;
@@ -538,7 +548,7 @@
   *   - GU_TAIL - Place list last in the queue, so it executes in-order
   *   - GU_HEAD - Place list first in queue so that it executes as soon as possible
   *
-  * @param mode - Wether to place the list first or last in queue
+  * @param mode - Whether to place the list first or last in queue
   * @param list - List to send
   * @param context - Temporary storage for the GE context
 **/
@@ -559,11 +569,20 @@
   * sceGuSync&#40;0,0&#41;;
   * @endcode
   *
-  * @param mode - Unknown meaning, pass 0 for now
-  * @param a1 - Unknown meaning, pass 0 for now
+  * Available modes are&#58;
+  *   - GU_SYNC_WAIT
+  *   - GU_SYNC_NOWAIT
+  *
+  * Available what are&#58;
+  *   - GU_SYNC_FINISH - Wait until the last sceGuFinish command is reached
+  *   - GU_SYNC_SIGNAL - Wait until the last &#40;?&#41; signal is executed
+  *   - GU_SYNC_DONE - Wait until all commands currently in list are executed
+  *
+  * @param mode - Whether to wait or not
+  * @param what - What to sync to
   * @returns Unknown at this time
 **/
-int sceGuSync&#40;int mode, int a1&#41;;
+int sceGuSync&#40;int mode, int what&#41;;
 
 /**
   * Draw array of vertices forming primitives
@@ -1160,9 +1179,21 @@
   * @param tbp - Texture buffer pointer &#40;16 byte aligned&#41;
 **/
 void sceGuTexImage&#40;int mipmap, int width, int height, int tbw, const void* tbp&#41;;
-void sceGuTexLevelMode&#40;unsigned int a0, float f12&#41;;
 
 /**
+  * Set texture-level mode &#40;mipmapping&#41;
+  *
+  * Available modes are&#58;
+  *   - GU_TEXTURE_AUTO
+  *   - GU_TEXTURE_CONST
+  *   - GU_TEXTURE_SLOPE
+  *
+  * @param mode - Which mode to use
+  * @param bias - Which mipmap bias to use
+**/
+void sceGuTexLevelMode&#40;unsigned int mode, float bias&#41;;
+
+/**
   * Set the texture-mapping mode
   *
   * Available modes are&#58;
@@ -1270,11 +1301,11 @@
   *   - GU_PSM_8888
   *
   * @param cpsm - Which pixel format to use for the palette
-  * @param a1 - Unknown, set to 0
-  * @param a2 - Unknown, set to 0
+  * @param shift - Shifts color index by that many bits to the right
+  * @param mask - Masks the color index with this bitmask after the shift &#40;0-0xFF&#41;
   * @param a3 - Unknown, set to 0
 **/
-void sceGuClutMode&#40;unsigned int cpsm, unsigned int a1, unsigned int a2, unsigned int a3&#41;;
+void sceGuClutMode&#40;unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int a3&#41;;
 
 /**
   * Set virtual coordinate offset
Index&#58; sceGuTexLevelMode.c
===================================================================
--- sceGuTexLevelMode.c	&#40;revision 2259&#41;
+++ sceGuTexLevelMode.c	&#40;working copy&#41;
@@ -10,9 +10,9 @@
 
 #include <math.h>
 
-void sceGuTexLevelMode&#40;unsigned int a0, float f12&#41;
+void sceGuTexLevelMode&#40;unsigned int mode, float bias&#41;
 &#123;
-	int offset = &#40;int&#41;truncf&#40;f12 * 16.0f&#41;;
+	int offset = &#40;int&#41;truncf&#40;bias * 16.0f&#41;;
 
 	// mip map bias?
 	if &#40;offset >= 128&#41;
@@ -20,5 +20,5 @@
 	else if &#40;offset < -128&#41;
 		offset = -128;
 
-	sendCommandi&#40;200,&#40;&#40;&#40;unsigned int&#41;&#40;offset&#41;&#41; << 16&#41; | a0&#41;;
+	sendCommandi&#40;200,&#40;&#40;&#40;unsigned int&#41;&#40;offset&#41;&#41; << 16&#41; | mode&#41;;
 &#125;
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

I've applied this patch and committed it to the repository.
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Wow, that was fast. Thanks ooPo :)
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Post Reply