forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Step up to become the VU master!

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jan 22, 2004 2:52 am    Post subject: Step up to become the VU master! Reply with quote

Want to be a VU master? Well, here's your chance to stand up and become one. We need a beginners guide to getting into VU coding. I know there's information out there but... we need information in here. So, start posting info. Either a full guide (ha!) or pieces that I can cobble into a guide. Maybe a general overview of how the process works, or a piece on how to compile VU code. Example code, or a discussion on what the VU can do or not do. Anything would be good...
Back to top
View user's profile Send private message Visit poster's website
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Thu Jan 22, 2004 2:57 am    Post subject: Reply with quote

I think this is a VERY good idea and hope lots of information gets posted.
I'd like to start by posting everything I know about using the VUs.

If anyone knows anything I haven't posted, please post :)
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Thu Jan 22, 2004 5:56 am    Post subject: Reply with quote

Ok this will be short pointers rather than a full document describing the odd ends of VU programming.

The easiest path to get something running on the VU is to do what druckluft made in Funslower, Sinde VU0 and VU1 have both code and data memory mapped on EE you can copy the code and data to those areas and kick VU0 or VU1, the code for this can be found in the Funslower source. The copy could be a simple memcpy or your ownmade

lq t0, 0(a0)
sq t0, 0(a1)

styled loop, with a0 as the source for your code/data block and a1 the vu0/1 data/code memory.

to kick the vu0 you use an opcode called vcallms or vcallmsr ( call micro subroutine [register]) with the start address.

vcallms 0
vcallmsr zero

for vu1 you need to use the ctc2 opcode which stands for
copy to coprocessor2, and what you want to copy is the start address.
so to have vu1 start at position 0 in vu1code mem do

; zero == $0 and cmsar1 == $31
ctc2.i zero, cmsar1

The way of the VIF.
Now VIF works the same way as GIF, you have a tag wich tells VIF what comes after it, to upload code and have the vu to execute you will have a sequence that looks like this.

VIF_MPG
code
VIF_MSCAL

in dvp-as language that would end up being

DMAcnt *
MPG 0, *
maddw.xyzw vf1, vf0, vf0 iaddiu vi1, vi0, 0xff
.EndMPG
MSCAL 0
.EndDmaData

the small code just adds some to vf1 and vi1, you could store them to
vu data memory and then check that its reasonable by printing from the EE mapped memory area.

Uploading data via VIF can be done in various ways since the UNPACK
tag has alot of attributes, the basic one is calle V4_32, basically the data is expected to be arranged as 4 32bit floats that will go directly to x,y,z,w.
a simple dvp-as example

unpack 4, 4, V4_32, 4, *
fwzyx 0.0, 1.0, 2.0, 3.0
fwzyx 0.0, 1.0, 2.0, 3.0
fwzyx 0.0, 1.0, 2.0, 3.0
fwzyx 0.0, 1.0, 2.0, 3.0
.EndUnpack

Normally you will upload the code without any MSCAL or MSCNT, and upload data with the MSCAL or MSCNT after the Unpack data since you will most often upload data alot more than code. so upload code once, then for each data uploaded you have the MSCAL/MSCNT tag to tell vu to start kicking it.

For more reading material check out the source for Funslower or Aura for Laura, also Jar has included source in 2 of his contriubtions to www.thethirdcreation.net. be sure to check them out aswell.
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jan 22, 2004 6:04 am    Post subject: Reply with quote

Some questions: What can you see/access from a running VU program? Can it access the main EE memory? Can it access the GS/GIF? I've seen some programs say they use an interrupt-based way of getting a texture uploaded before the geometry is sent to the GS. How would that work?
Back to top
View user's profile Send private message Visit poster's website
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Thu Jan 22, 2004 6:08 am    Post subject: Reply with quote

ooPo wrote:
Some questions: What can you see/access from a running VU program? Can it access the main EE memory? Can it access the GS/GIF? I've seen some programs say they use an interrupt-based way of getting a texture uploaded before the geometry is sent to the GS. How would that work?


I believe VU1 can access VU0 RAM, or it may be the other way around I'm not sure. Remember that VU0 is 4k Code and 4k Data, and VU1 is 16k Code and 16k Data.

The EE can access either of VU0 or VU1 code or data, but not the other way around.

VU1 is directly tied to the GIF.
Back to top
View user's profile Send private message
jar



Joined: 18 Jan 2004
Posts: 7
Location: Denmark

PostPosted: Thu Jan 22, 2004 6:19 am    Post subject: Reply with quote

One thing I think should be mentioned in this regard, which seems obvious once you've done some VU stuff, but i didn't know when i started out, is that you need to use packed mode for your GIF packets rather than A+D, as most tutorials do.

I recommend playing around with packed mode and getting transformations/lighting/texturing right on the EE-core (ie. in your normal C code), and then convert it to VU code.

Also, when trying to get VIF packages right it's, imho, best to try uploading the package and then some kind of vif_wait() and read back the memory to see if it was written as expected, this goes especially for the more obscure unpacking methods.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Thu Jan 22, 2004 7:03 am    Post subject: Reply with quote

I'm using packed mode currently for my gif packets, but I was pondering going to A+D mode for the xyz register so I can remove the drawing kick if the poly is clipped. Is there any reason other that memory size to do packed mode on the VU?
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Thu Jan 22, 2004 7:23 am    Post subject: Reply with quote

ooPo wrote:
Some questions: What can you see/access from a running VU program? Can it access the main EE memory? Can it access the GS/GIF? I've seen some programs say they use an interrupt-based way of getting a texture uploaded before the geometry is sent to the GS. How would that work?


neither vu0 or vu1 in micromode can access EE, they are running in a standalone mode and can only be controlled by VIF ( you can start, stop and reset from without VIF thats it ) when running,
when not running you can upload code/data to the EE mapped memory,
and also you must stop VU0/VU1 and VIF0/VIF1 before reading since you cant trust the mapped data when they are in the run state.

now that being said, VIF and VU can generate an interrupt normally, for example you have an unpack batch being sent and then mscal with interrupt bit set ( all VIF tags have a bit for interrupt generation ), on the R5900 you would have a something that checks for it to be set and sends of texture or whatever you want todo.
_________________
Kung VU


Last edited by blackdroid on Thu Jan 22, 2004 7:46 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Thu Jan 22, 2004 7:27 am    Post subject: Reply with quote

Quote:
I believe VU1 can access VU0 RAM, or it may be the other way around I'm not sure. Remember that VU0 is 4k Code and 4k Data, and VU1 is 16k Code and 16k Data.

The EE can access either of VU0 or VU1 code or data, but not the other way around.

VU1 is directly tied to the GIF.


Vu1's registers are mapped to Vu0 mem after 0x4000
nothing else is crossmapped.
_________________
Kung VU


Last edited by blackdroid on Thu Jan 22, 2004 7:51 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Thu Jan 22, 2004 7:39 am    Post subject: Reply with quote

ooPo wrote:
I'm using packed mode currently for my gif packets, but I was pondering going to A+D mode for the xyz register so I can remove the drawing kick if the poly is clipped. Is there any reason other that memory size to do packed mode on the VU?


squeezing xyz into 64bits is something that the VU's was not designed for.
therefor packed mode is the logical choice for the VU's, which is abit of
a dumb name since the packing gets done by GIF.
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Sat Jan 24, 2004 1:41 am    Post subject: Reply with quote

i have posted some Vu documentations on ps2dev.org. I don t know who's the authors but i think it could be usefull, i am not a dever, maybe later :-)
Back to top
Guest






PostPosted: Sat Jan 24, 2004 1:48 am    Post subject: Reply with quote

Sorry, i am Chandler...problem registration :-)
Back to top
jar



Joined: 18 Jan 2004
Posts: 7
Location: Denmark

PostPosted: Sat Jan 24, 2004 1:57 am    Post subject: Reply with quote

btw: http://ps2linux.diabolus-ex-machina.com/wiki/index.php?Vector%20Units has some nice links
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
dagamer34



Joined: 24 Jan 2004
Posts: 35

PostPosted: Sat Jan 24, 2004 12:16 pm    Post subject: Reply with quote

Since I am a newbie at PS2 programming, let me be the first to ask this question...

What is a Vector Unit?


Now, please stay in your chairs and stop yourself from laughing as much as you can.... please....stop. Anyway, the PS2 seems so complicated compared to the GBA (which I am working on right now). There really is only one set of tutorials out there for a newbie like me.

So just use me as a guinea pig. I'll ask yall guys questions and you *will* answer them, then stuff them into a FAQ, hopefully a guide, maybe someday an SDK, so n00bs don't have to suffer.

Oh, yea, hello everyone.
_________________
while (your_engine >= my_engine)
my_engine++; :P
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Sat Jan 24, 2004 3:04 pm    Post subject: Reply with quote

The vector unit can be described as a very specialized processor, a kind of cross between MMX and a vertex shader on a graphic card. You can write a small program to get a VU to quickly do math on data, like 3D transformations or complex physics. It has some useful SIMD (single instruction multiple data) opcodes and a special connection linked directly to the GS. Very useful, but very exotic.
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Sat Jan 24, 2004 4:12 pm    Post subject: Reply with quote

It might be good to mention that there is no "the" vector unit.
Since the ps2 has 2 vector units, one (VU0) that is closer to the r5900 cpu ( since it can operate in coprocessor mode ) and the other (VU1) which has its own bus to the GIF.

Vu0 as mentioned before has 4KB for data and 4KB for code.
Vu1 as mentioned before has 16KB for data and 16KB for code.

And what they are really good at is matrix math, why ? well
mul.xyzw vf3, vf2, vf1 <- 4 mul in one go, which fits nicely for
4x4 matrices(and less), and thats what 3d engines likes to do the most.
All the float registers on the vector unit are 128bit wide and divided in
4 so we have 4 32bit single precision floats in each register, the memory
on the Vu's are laid out in 128bit fashion so when do load/store against it
you do it on 128bit align.

Anything else ?
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Sat Jan 24, 2004 4:17 pm    Post subject: Reply with quote

Does it serve fries?
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Sat Jan 24, 2004 4:22 pm    Post subject: Reply with quote

yes beatifully rendered in golden yellow.
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
dagamer34



Joined: 24 Jan 2004
Posts: 35

PostPosted: Wed Jan 28, 2004 9:08 am    Post subject: Reply with quote

I am going out on a limb here but I am guessing this is where you do all your math-intensive calculations, right?
_________________
while (your_engine >= my_engine)
my_engine++; :P
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
ooPo
Site Admin


Joined: 17 Jan 2004
Posts: 2032
Location: Canada

PostPosted: Wed Jan 28, 2004 10:02 am    Post subject: Reply with quote

You're a quick one, aren't you? :)
Back to top
View user's profile Send private message Visit poster's website
dagamer34



Joined: 24 Jan 2004
Posts: 35

PostPosted: Wed Jan 28, 2004 10:54 am    Post subject: Reply with quote

If only everything else dealing with the PS2 were this easy (besides turning it on...)
_________________
while (your_engine >= my_engine)
my_engine++; :P
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
p0ison



Joined: 30 Nov 2004
Posts: 5

PostPosted: Tue Nov 30, 2004 7:56 am    Post subject: Reply with quote

What's the `GIF' ?
Back to top
View user's profile Send private message
radad



Joined: 19 May 2004
Posts: 246
Location: Melbourne, Australia

PostPosted: Tue Nov 30, 2004 3:23 pm    Post subject: Reply with quote

Given that the vector units are good at matrix math, would it be worthwhile developing a matrix math library which made full use of these processors?
Back to top
View user's profile Send private message
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Tue Nov 30, 2004 7:13 pm    Post subject: Reply with quote

p0ison wrote:
What's the `GIF' ?


the InterFace to Gs, just as VIF is the InterFace to Vu etc.
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
blackdroid



Joined: 17 Jan 2004
Posts: 564
Location: Sweden

PostPosted: Tue Nov 30, 2004 7:45 pm    Post subject: Reply with quote

radad wrote:
Given that the vector units are good at matrix math, would it be worthwhile developing a matrix math library which made full use of these processors?


uhm yes. there are even some in cvs (BPDemo harness) that could serve as a base for such a math lib.
_________________
Kung VU
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group