[SOLVED] Weird Canvas redering behavior.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
YoungFlyme
Prole
Posts: 5
Joined: Sat Dec 15, 2018 5:30 pm

[SOLVED] Weird Canvas redering behavior.

Post by YoungFlyme »

Hey guys, I have a little weird behavior when I render my Canvases (7+).

Let me explain it:
I have a little map which can get x layers of the z axis. As long as the map has less then 7 layers it renders normally and my cpu is always smaller then 2%.
If I now get over 6 layers (7+) it still renders totally fine (+- 900 FPS) but my CPU is always at 25% (Maxed out).

The affected code snippets:

Code: Select all

function DrawMap(Level) -- Is the love.draw() callback, I just have implemented a custom Event-System to make it bit easier for me
	map:Draw()
end
Thats my drawing code (its a callback of love.draw(), this cant be the reason for the CPU usage)
And here is my drawing code:

Code: Select all

function CMap:Draw()
	love.graphics.setColor(1,1,1)
	for i = #self.Canvas, 1 , -1 do
		love.graphics.draw(self.Canvas[i])
	end
end
Note:
self.Canvas[X]
just stores a canvas which is getting created when the map is getting created too
self.Canvas[d] = love.graphics.newCanvas( Screen.x, Screen.y, {msaa = 16} )
Changing the MSAA of the canvas does not solve the problem at all.

Here are some (may be) helpfull information:
  • Canvas does NOT get modified every Update OR Draw (will just get modified when it needs to)
  • With a depth of 7 layers it will draw 7 canvases not more, not less
  • enabling vsync does not help in this case
  • Canvases overdraw each other (obviously xD)
  • I dont work with threads at all
Here are some screens:
Using 6 Canvases
Using 6 Canvases
CPU Nuse.png (317.69 KiB) Viewed 5449 times
Using 7 Canvases
Using 7 Canvases
CPU use.png (436.79 KiB) Viewed 5449 times
Using 8 Canvases
Using 8 Canvases
CPU use 8.png (360.52 KiB) Viewed 5449 times
Last edited by YoungFlyme on Sat Dec 15, 2018 8:55 pm, edited 1 time in total.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Weird Canvas redering behavior.

Post by grump »

Welcome! If you expect any useful help beyond speculation with that, you might want to post a love file that reproduces the problem.
YoungFlyme
Prole
Posts: 5
Joined: Sat Dec 15, 2018 5:30 pm

Re: Weird Canvas redering behavior.

Post by YoungFlyme »

Sadly I fixed on my own xD (well thats not sad at all :P).
I now just draw 1 canvas instead of 7+.
I also got it why it was 7+. It has to do smth with the amount of pixels getting send to the GPU and my hardware acceleration gets in when the amount exceeds a limit (actually that is the only thing which makes sense in this case).

Hope I'm right with my thoughts, atleast its working now ^^
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Weird Canvas redering behavior.

Post by grump »

YoungFlyme wrote: Sat Dec 15, 2018 8:55 pm It has to do smth with the amount of pixels getting send to the GPU and my hardware acceleration gets in when the amount exceeds a limit (actually that is the only thing which makes sense in this case).
Glad it works now. How are you rendering these? "Amount of pixels getting send to the GPU" sounds a little... unusual.
YoungFlyme
Prole
Posts: 5
Joined: Sat Dec 15, 2018 5:30 pm

Re: [SOLVED] Weird Canvas redering behavior.

Post by YoungFlyme »

Well its kinda simple.
Lets suppose I'm building a map with 1920 pixels in widht and 1080 pixels in height.
Now has 8 layers. With my old method I created 8 canvases and filled every pixel and after all that it would draw them (results in a total data of 16.588.800 pixels). The mentioned a limt-number (when the CPU is used max) is somewhere between 12,441,600 and 14,515,200 (the "limit" could be hardware dependent). What ever, now I just drawing all the map (every layer of it) in just 1 canvas -> same graphical result no CPU usage at all (so it just needs 2.073.600 pixel).
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [SOLVED] Weird Canvas redering behavior.

Post by zorg »

You did say that you turned off vsync; did that mean you were drawing the canvases thousands of times a second?

If so, you could have coded a "manual" framerate limiter, and i'd wager you could have drawn a hundred canvases before it would have become an issue.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
YoungFlyme
Prole
Posts: 5
Joined: Sat Dec 15, 2018 5:30 pm

Re: [SOLVED] Weird Canvas redering behavior.

Post by YoungFlyme »

Without VSync i got about 950 FPS and drawing 7 canvases (would result in a total draws of 6.650 canvases per second) and this is ending up in a mess where my poor GPU gets about 13150.63 Mbyte data per second.
Calculation:
6650 * 1920 * 1080 = 13.789.440.000 (Pixels)
13.789.440.000 * 8 = 110.315.520.000 (8 bits per pixel because I'm using the "normal" format (all formats can be found here))
110.315.520.000 / 8 = 13.789.440.000 (8 bits = 1 byte)
13.789.440.000 / 1024 = 13.466.250 (1024 byte = 1 KByte)
13.466.250 / 1024 = 13.150,63 (1024 KByte= 1 MByte)
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [SOLVED] Weird Canvas redering behavior.

Post by zorg »

This is my exact point that you don't have a screen with a refresh rate of 950 Hz; it's wasted processing power.
If you only drew the 7 canvases 60-144 times per second, then you probably would avert this issue altogether; still, if you managed to solve the issue by combining the canvases into one, then that's as good of a solution as any.

(Also, technically the 1024 units are the binary versions; kiB, MiB, GiB, etc.; the regular kB, MB, GB, etc. all use a unit of 1000)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
YoungFlyme
Prole
Posts: 5
Joined: Sat Dec 15, 2018 5:30 pm

Re: [SOLVED] Weird Canvas redering behavior.

Post by YoungFlyme »

Ahh alright thanks for that info ^^ :3
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: [SOLVED] Weird Canvas redering behavior.

Post by grump »

YoungFlyme wrote: Sun Dec 16, 2018 7:34 am Calculation:
You calculation is off by a factor of 4, because you forgot about the pixel components. Also, those don't get actually "sent" to the GPU, they are already on the GPU. What you describe is called the fillrate.

The CPU load problem that you described is still kinda strange, but if it works now, then all is fine :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 71 guests