About Monkey 2 › Forums › Monkey 2 Programming Help › Slower graphics (Emscripten/Wasm) with v1.1.05
This topic contains 7 replies, has 2 voices, and was last updated by
Pakz 1 year, 9 months ago.
-
AuthorPosts
-
June 27, 2017 at 4:18 am #8949
I wanted to switch to the new version of monkey so I copied my code over and compiled. The desktop version runs as it did but the emscripten and wasm now makes my game unplayable. There is a big slowdown with drawing now.
Did anyone else encounter this yet and is there a method I could use to bypass/fix this?
I tried to place counters to see where the slowdown is but I could not immediatly find the problem. I tried to count the millisecs it takes to flush the canvas and this was a huge number. But when I removed the flushes the speed did not improve at all. I then timed a drawing section of my code and compared it to the previous monkey2 version and there was a rather big difference.
edit : I will try to spend more time investigating to pinpoint the problem.
June 27, 2017 at 7:56 pm #8963I was drawing to images(buffers) and I had used static images and tried to set them up as dynamic images but it made no difference. It takes about 2 seconds now to redraw everything while in the previous monkey version it was done in a fraction of a second.
I am using a lot of drawrect and drawpoint and drawoval and drawcircle commands. Rnd and new color.
edit: I did some side by side testing. In the method I tested now it seems that the graphics drawing speed has halved in the new version.
edit: I will spend some time creating code that shows the speed difference between the two versions. Might take a while since I am having such a fun time working on my current project. (I am using the previous monkey2 version) I am not to sure if it is my coding that is the blame for the problem so I will wait to post a bug report (spamming it with my newb things)
edit : here is the project with which I tested it. It is a lot of code though.
https://github.com/Pakz001/Monkey2examples/blob/master/CivClone%200.6.monkey2
When I used to press ‘b’ to build a city it was immediat, now it takes a second or two. Happens with the map redraw.
June 27, 2017 at 10:07 pm #8965Just looking into this now…
The actually canvas drawing code hasn’t changed, but the ‘render to texture’ system has so I’ll start there…
June 27, 2017 at 10:20 pm #8967I created a little test program just in case it is my bad programming.
The speed difference is. WIth the previous version ( +/-80ms per redraw) and with the new version (+/-600ms)
This is emscripten in debug mode in latest chrome browser.
Monkey1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class worldField Width:Int,Height:IntField image:ImageField icanvas:CanvasMethod New(Width:Int,Height:Int)Self.Width = WidthSelf.Height = Heightimage=New Image( Width,Height)image.Handle=New Vec2f( 0,0 )icanvas=New Canvas( image )End MethodMethod redraw(canvas:Canvas)Local t:Int=Millisecs()canvas.Clear(Color.Black)For Local i:=0 Until 1500drawgrass(Rnd(Width,Height),Rnd(Width,Height),canvas)Nextcanvas.Flush()Print "Took :"+(Millisecs()-t)End MethodMethod drawgrass(x:Float,y:Float,canvas:Canvas)Local tw:Float=10 'tilewidthLocal th:Float=10 'tileheightSeedRnd(x*y)canvas.Color = New Color(0,0.5,0)canvas.DrawRect(x,y,tw,th)' noiseFor Local y2:Int=y Until y+thFor Local x2:Int=x Until x+tw'noiseIf Rnd(2)<.1canvas.Color = New Color(0,Rnd(0.2,0.6),0)canvas.DrawPoint(x2,y2)' highlight noiseIf Rnd(1)>.9 ThenLocal grey:Float=Rnd(.3,.7)canvas.Color = New Color(grey,Rnd(0.2,0.3)+grey,grey)canvas.DrawPoint(x2,y2)End IfEnd IfNextNextEnd MethodEnd ClassGlobal myworld:worldClass MyWindow Extends WindowMethod New()myworld = New world(Width,Height)End MethodMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender() ' Activate this methodIf Keyboard.KeyReleased(Key.Space) Then myworld.redraw(myworld.icanvas)canvas.Color = Color.Whitecanvas.DrawText("Press space to test draw speed",0,0)' if key escape then quitIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEnd ClassFunction Main()New AppInstanceNew MyWindowApp.Run()End FunctionJune 27, 2017 at 10:49 pm #8968Ok, I can reproduce now and it appears to be Chrome related.
Can you try ‘firefox nightly’ instead? The above little demo actually goes a bit faster in V1.1.05 with nightly for me (and using WASM) – but I can confirm very slow performance with Chrome.
Firefox nightly is my default browser of choice for dev work as it’s usually the first to support any fancy new fangled features and seems to offer the best performance with webgl, wasm etc. I should probably test more often with Chrome though, as it’s now the IE of the tenties…
Will keep looking into this though – could just be something I’m doing slightly differently is ‘trigerring’ crap performance on Chrome.
June 27, 2017 at 10:58 pm #8970Unrelated, but another thing I recommend is using ‘TextureFlags.Dynamic’ when creating textures that are being constantly rendered to, eg: if you’re rendering frames off screen, eg: image=New Image( w,h,TextureFlags.Dynamic ).
This tells monkey2 not to bother ‘backing up’ the texture after you’ve modified it in case of a ‘lost device’ event, eg: Alt-Tab, display mode change etc. Backing up after modification is slow, and there’s no point backing it up if you’re just gonna redraw it again next frame.
Wont affect the above little demo, but could affect Civ.
June 27, 2017 at 11:06 pm #8971I think I may have found it!
As far as I can tell, glGetError() is VERY slow on Chrome. Perhaps it’s doing an internal flush or something?
Anyway, you can verify this by sticking a ‘Return’ at the top of the glCheck function in modules/mojo/graphics/glutil.monkey2 and rebuilding modules for emscripten etc.
Plese let me know if this fixes it. This may be worth a 1.1.05b release as it’ll affect 3d stuff too…
(…that’ll teach me to ‘code defensively’!)
June 28, 2017 at 12:12 am #8975Yes, this fixed it! Thanks.. Both Emscripten and Wasm now are fast as the previous version. I wil now start using 1.1.05 for development.
And I wil start using the dynamic flags if I draw on them reguraly.
-
AuthorPosts
You must be logged in to reply to this topic.