Perfomance issue....

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
haust
Posts: 25
Joined: Sat Oct 01, 2005 12:37 am
Location: France

Perfomance issue....

Post by haust »

Well I would like some comments on the tests I performed with v0.11 to determine how many sprites I could blit in brute force.
Following is the little app I've coded for the test. It just load an image then when you press cross sprites are added and when you press circle sprites are removed. In the upper left the FPS and the sprites count are displayed.

Currentlty I could blit 63 sprites 16x16 @ 60 FPS with transparency turned off, and somthing like 47 sprite with transparency turned on.
Is something wrong ??

One thing I've discovered is that Controls.read() eats lots of time. So much that with 2 Controls.read() calls and no sprite displayed FPS started @30 !! Therefore Controls.read() should be called once per app loop and stored for future use in that loop. Maybe some of you already knew it but I didn't....

vh

Code: Select all

-- -----------------------------------------------------------------------
-- CFpsTester
-- -----------------------------------------------------------------------
CFpsTester = {}
CFpsTesterMetaTable = { __index = CFpsTester }

-- -----------------------------------------------------------------------
-- CFpsTester:new
-- -----------------------------------------------------------------------
function CFpsTester:new(ImageName)
	local Table =
	{
		m_Image = Image.load(ImageName),
		m_SpriteSize = { m_Width = 16, m_Height = 16 },
		m_Sprites = {},
		m_Frames = 0,
		m_FPS = 0,
		m_Timer = -1,
		m_CurrentTime = 0,
		m_LastFPSTime = 0,
		m_InkColor = Color.new(0, 255, 0),
		m_BackColor = Color.new(55, 102, 104),
		m_Buttons = -1,
	}

	setmetatable(Table, CFpsTesterMetaTable);

	local Now = os.date("*t");
	local Seed = Now.hour + Now.min + Now.wday + Now.year + Now.yday + Now.month + Now.sec + Now.day;

	math.randomseed(Seed);

	Table.m_Timer = Timer.new();
	Table.m_Timer:start();
	Table.m_Buttons = Controls.read();

	return (Table);
end

-- -----------------------------------------------------------------------
-- CFpsTester:update
-- -----------------------------------------------------------------------
function CFpsTester:update()
	self.m_Buttons = Controls.read();
	self.m_CurrentTime = self.m_Timer:time();

	if &#40;1000 <= &#40;self.m_CurrentTime - self.m_LastFPSTime&#41;&#41; then
		self.m_LastFPSTime = self.m_CurrentTime;
		self.m_FPS = self.m_Frames;
		self.m_Frames = 0;
	end

	self.m_Frames = self.m_Frames + 1;

	if &#40;self.m_Buttons&#58;cross&#40;&#41;&#41; then
		self&#58;privateAddSprite&#40;&#41;;
	end
	if &#40;self.m_Buttons&#58;circle&#40;&#41;&#41; then
		self&#58;privateRemoveSprite&#40;&#41;;
	end
end

-- -----------------------------------------------------------------------
-- CFpsTester&#58;draw
-- -----------------------------------------------------------------------
function CFpsTester&#58;draw&#40;TargetImage&#41;
	TargetImage&#58;clear&#40;self.m_BackColor&#41;;

	for Index, Sprite in self.m_Sprites do
		TargetImage&#58;blit&#40;Sprite.m_X, Sprite.m_Y, self.m_Image, Sprite.m_SourceX, Sprite.m_SourceY, self.m_SpriteSize.m_Width, self.m_SpriteSize.m_Height, false&#41;;
	end

	TargetImage&#58;print&#40;5, 5, "FPS " .. tostring&#40;self.m_FPS&#41;, self.m_InkColor&#41;;
	TargetImage&#58;print&#40;5, 15, "Sprites " .. tostring&#40;table.getn&#40;self.m_Sprites&#41;&#41;, self.m_InkColor&#41;;
end

-- -----------------------------------------------------------------------
-- CFpsTester&#58;checkExistApp
-- -----------------------------------------------------------------------
function CFpsTester&#58;checkExistApp&#40;&#41;
	return &#40;self.m_Buttons&#58;start&#40;&#41;&#41;;
end

-- -----------------------------------------------------------------------
-- CFpsTester&#58;privateAddSprite
-- -----------------------------------------------------------------------
function CFpsTester&#58;privateAddSprite&#40;&#41;
	local Sprite =
	&#123;
		m_X = math.random&#40;screen&#58;width&#40;&#41; - self.m_SpriteSize.m_Width&#41;,
		m_Y = math.random&#40;screen&#58;height&#40;&#41; - self.m_SpriteSize.m_Height&#41;,
		m_SourceX = math.random&#40;self.m_Image&#58;width&#40;&#41; - self.m_SpriteSize.m_Width&#41;,
		m_SourceY = math.random&#40;self.m_Image&#58;height&#40;&#41; - self.m_SpriteSize.m_Height&#41;,
	&#125;

	self.m_Sprites&#91;table.getn&#40;self.m_Sprites&#41; + 1&#93; = Sprite;
end

-- -----------------------------------------------------------------------
-- CFpsTester&#58;privateRemoveSprite
-- -----------------------------------------------------------------------
function CFpsTester&#58;privateRemoveSprite&#40;&#41;
	self.m_Sprites&#91;table.getn&#40;self.m_Sprites&#41;&#93; = nil;
end


g_App = -1;

-- -----------------------------------------------------------------------
-- Update
-- -----------------------------------------------------------------------
function Update&#40;&#41;
	g_App&#58;update&#40;&#41;;
end

-- -----------------------------------------------------------------------
-- Draw
-- -----------------------------------------------------------------------
function Draw&#40;&#41;
	g_App&#58;draw&#40;screen&#41;;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
end

-- -----------------------------------------------------------------------
-- main
-- -----------------------------------------------------------------------
function main&#40;&#41;
	g_App = CFpsTester&#58;new&#40;"Image.png"&#41;; -- for safety should be at least 64x64

	while &#40;false == g_App&#58;checkExistApp&#40;&#41;&#41; do
		Update&#40;&#41;;
		Draw&#40;&#41;;
	end
end

main&#40;&#41;;
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

those findings are concurrent with my own.. lua is very slow when it comes to multiple small blits. you have to be clever and combine your small blits into a few large ones, only update what has changed, etc.. i hope my game will be a good example of this when i finally release it.
Chaosmachine Studios: High Quality Homebrew.
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

Just for shits and giggles I did some tests on my version of Luaplayer. I can do about 110 64 * 64 alpha blended 32 bit blits to the screen currently, in the 60 fps timeframe. Not that much, but enough for my purposes.
Last edited by Durante on Sat Oct 29, 2005 3:26 am, edited 2 times in total.
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

Durante wrote:Just for shits and giggles I did some tests on my version of Luaplayer. I can do about 110 64 * 64 alpha blended 32 bit blits to the screen currently, in the 60 fps timeframe. Not that much, but enough for my purposes.
what's different in your version, and why aren't your changes in v0.12?
Chaosmachine Studios: High Quality Homebrew.
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

chaos wrote:what's different in your version,
Among other things, that it uses pspGL to blit images to the screen.
chaos wrote:and why aren't your changes in v0.12?
Because Shine decided to go with Gu, and so they're incompatible. But it shouldn't be hard to get at least the same performance out of Gu. Just have some patience or implement it yourself.

For more information read this thread:
http://forums.ps2dev.org/viewtopic.php?t=3583
xyuppiex
Posts: 2
Joined: Fri Oct 28, 2005 7:04 pm

Post by xyuppiex »

Durante,

I checked out the LuaPlayer code form the svn on tuesday and added your pspGL files. My blitting speed was cut in half compared to the 0.11 release!

Would you mind posting your lua code for blitting 110 sprites @ 60 fps?

/xyux
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

xyuppiex wrote:Durante,

I checked out the LuaPlayer code form the svn on tuesday and added your pspGL files. My blitting speed was cut in half compared to the 0.11 release!

Would you mind posting your lua code for blitting 110 sprites @ 60 fps?

/xyux
speed cut is quite simple due 32bit instead of 16 before...
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

Durante wrote:Just for shits and giggles I did some tests on my version of Luaplayer. I can do about 110 64 * 64 alpha blended 32 bit blits to the screen currently, in the 60 fps timeframe. Not that much, but enough for my purposes.
Software blits from image to image are indeed slower (a lot). Just don't do them ;)

Also, the code in that thread is a bit out of date.


[edit]
I just vastly improved my pspgl usage, I can now do 140 in 16 ms. That doesn't seem like too much of an increase, but that's because the true advantage only becomes visible if you use many different textures. My game performance increased nearly twofold.
xyuppiex
Posts: 2
Joined: Fri Oct 28, 2005 7:04 pm

Post by xyuppiex »

Durante,

Mind putting together a new pack of files for us to compile?
I need all the speed I can get!
Post Reply