Page 1 of 2

1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 7:37 pm
by TheCaptain
Hi,

first of all, very impressive engine. Some HowTos more would be nice, i struggled finding out theres an animation framework for löve. BTW don't google for "AnAL Löve", it won't give you any useful results :)

My Problem is that a background-image with 512x256px is using about 0-1% of CPU, but 513x256px is using 99%.

WTF ??

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 7:55 pm
by Robin
Simply put: it's likely because 512 is a power of two, which is what computer are optimized for.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:02 pm
by TheCaptain
Likewise is 1024x512, but this also gives 99% CPU. Definitely not a normal behaviour, and I'm just using the examples.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:06 pm
by Robin
TheCaptain wrote:Likewise is 1024x512, but this also gives 99% CPU. Definitely not a normal behaviour, and I'm just using the examples.
I think I have an idea: your computer can comfortably handle 512x256, but 513x256 is "rounded up" to 1024x256, giving similar performance. This is called "padding", and we actually use it in our games, because some computers simply can't handle non-PO2 images at all, displaying white rectangles instead.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:12 pm
by T-Bone
Still, rendering a 1024*256 image shouldn't be all that hard, it shouldn't use all the cpu, even on a crappy computer, if it's just rendering a single image.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:14 pm
by TechnoCat
Shouldn't it be the case the 512x256 pixel image also uses 99%? That is, unless you are doing vsync or framerate management.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:21 pm
by TheCaptain
Yeah, i read something about the PO2_Syndrome, but graphic card is not that old.

I found the problem. Seems that cutting off background images to the size of the screen is extremely inefficient. If the image extends screen.width or screen.height set in conf.lua, then CPU goes crazy. The 513px image probably was padded to 1024px like you say, which was more than the 600 or so pixel that I've set as width in configuration. If I use 1024x512px image on 1024x512px viewport, everything works fine.

Still I would think cutting a too big image to the viewport size doesn't make your CPU sweat. Thanks anyway.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:29 pm
by kikito
Can you show us the code you are using? Maybe there's more than meets the eye.

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 8:39 pm
by TheCaptain
Sure. Just plain simple though. With 513x256px image for 1a.jpg, its getting hot in here.

Code: Select all

require("lua/AnAL.lua")

function love.load()
	image = love.graphics.newImage("images/bg/1a.jpg")
	player = love.graphics.newImage("images/run/c2.jpg")
	anim = newAnimation(player, 45, 113, 0.1, 0)
	anim:setMode("bounce")
end

function love.draw()	
	love.graphics.draw(image, imgx, imgy)	
	anim:draw(400, 300)
end

function love.update(dt)
	anim:update(dt)
end

Code: Select all

function love.conf(t)
    t.screen.width = 557
    t.screen.height = 441
end

Re: 1 Pixel more needs +98% CPU

Posted: Sun Jun 26, 2011 9:08 pm
by Taehl
T-Bone wrote:Still, rendering a 1024*256 image shouldn't be all that hard, it shouldn't use all the cpu, even on a crappy computer, if it's just rendering a single image.
Don't make assumptions. Ensayia was making a screensaver for someone at some point, and after a lot of frustration, discovered that the target computer choked when handed anything bigger than 256x256. The solution is simply to cut your huge image into smaller pieces.