PS2 Linux Programming



Uploading VU Programs During Run-Time




This tutorial will introduce a VU manager class which is used to organise and manage different VU1 micro programs within an application. The tutorial will illustrate how to upload different micro programs during run time.





In all of the tutorials up to this point a single VU micro program has been used to render graphics. However, in some circumstances it is convenient to change the micro program during run time so as to alter the rendering algorithm.


The VIF1 has a VIFCode which is used to transfer data to VU1 program memory; MPG is used to transfer the subsequent data (specified in chunks of 64-bits) to VU1 program memory.



The Example Code


A VU1 manager class is contained within the files vumanager.h and vumanager.cpp. The VU manager class contains only two method CVU1MicroProgram::Upload() and CVU1MicroProgram::GetCodeSizeDW(). The Upload() method is the used to upload the micro program into VU1 program memory. The constructor of the CVU1MicroProgram class takes the start address and the end address of the micro program in the compiled object code and transfers the program into static memory for subsequent upload.


The VU manager class is used as follows: First the VU manager class in initialised with the pointers to the start and end of the micro program.



CVU1MicroProgram VU1Normal(&VU_vu1code_start, &VU_vu1code_end);



To upload the micro program the upload method is called.






In the example code, two 3d models are rendered using different micro programs. The first micro program (vu1code.vcl) is quad buffered program from before which used three directional lights and ambient light. The second micro program (vu1codeSM.vcl) is also quad buffered but renders primitives with no directional lights and ambient light set fully on (255).


The render loop contains the following code extract:



// Render the model


Model.Render(matWorld1 * matView * matProj, matWorld1 );


// Render the model


Model.Render(matWorld2 * matView * matProj, matWorld2 );



The normal micro program is uploaded then the first model is rendered. Following this, the “NoLights” micro program is uploaded then the second model is rendered.





In this tutorial a manager class has been introduced to organise and manipulate VU1 micro programs.



Dr Henry S Fortuna

University of Abertay Dundee