Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
108 stars 83 forks source link

Tilemap drawcalls in C3 editor have higher impact than in C2 editor #2977

Closed SnipG closed 5 years ago

SnipG commented 5 years ago

Problem description

Was testing some old tilemap example i found on forum. First i tried it out on Construct 2, everything was fine and had very good performance ~5%cpu on standby and ~40% when i interact with it. But then i tried it out on C3 with both runtimes, drawcalls are super high and CPU hits 100%. Is it bug. If so, what is causing it. Could one work around it?

Attach a .c3p

Construct 3 test case: TerrainC3_02.zip Construct 2 test case: C2Terrain.zip

Steps to reproduce

1.Open C3 test case in C3. Preview in debug mode(See fps and cpu, i get 5fps 100%cpu) 2.Open C2 test case and preview in debug mode. Also click on screen and see no massive fps drop or cpu increase.

Observed result

In c3, with both runtimes, tilemap has different behavior then Construct 2 tilemap, which results much higher cpu use and fps drops. Not sure what is causing it, but it should be checked out.

Expected result

C3 editor somehow have different behavior then Construct 2. In Construct 2 same example runs much faster and smoother, than Construct 3.

More details

Construct 2 version where i tested example was r266.

Affected browsers/platforms:

First affected release: All releases of Construct 3, both runtimes

System details

View details Platform information Browser: Chrome Browser version: 74.0.3729.169 Browser engine: Chromium Browser architecture: 64-bit Context: browser Operating system: Windows Operating system version: 10 Operating system architecture: 64-bit Device type: desktop Device pixel ratio: 1 Logical CPU cores: 4 Approx. device memory: 4 GB User agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36 C3 release: r150 (beta) Language setting: en-US Local storage Storage quota (approx): 13 gb Storage usage (approx): 1.6 gb (11.7%) Persistant storage: Yes Browser support notes This list contains missing features that are not required, but could improve performance or user experience if supported. Nothing is missing. Everything is OK! WebGL information Version string: WebGL 2.0 (OpenGL ES 3.0 Chromium) Numeric version: 2 Supports NPOT textures: yes Supports GPU profiling: yes Supports highp precision: yes Vendor: Google Inc. Renderer: ANGLE (AMD Radeon HD 5700 Series Direct3D11 vs_5_0 ps_5_0) Major performance caveat: no Maximum texture size: 16384 Point size range: 1 to 1024 Extensions: EXT_color_buffer_float EXT_disjoint_timer_query_webgl2 EXT_texture_filter_anisotropic OES_texture_float_linear WEBGL_compressed_texture_s3tc WEBGL_compressed_texture_s3tc_srgb WEBGL_debug_renderer_info WEBGL_debug_shaders WEBGL_lose_context Audio information System sample rate: 44100 Hz Output channels: 2 Output interpretation: speakers Supported decode formats: Ogg Opus (audio/ogg; codecs=opus) WebM Opus (audio/webm; codecs=opus) Ogg Vorbis (audio/ogg; codecs=vorbis) WebM Vorbis (audio/webm; codecs=vorbis) MPEG-4 AAC (audio/mp4; codecs=mp4a.40.5) MP3 (audio/mpeg) FLAC (audio/flac) PCM WAV (audio/wav; codecs=1) Supported encode formats: WebM Opus (audio/webm; codecs=opus) Video information Supported decode formats: WebM VP9 (video/webm; codecs=vp9) WebM VP8 (video/webm; codecs=vp8) Ogg Theora (video/ogg; codecs=theora) H.264 (video/mp4; codecs=avc1.42E01E) Supported encode formats: WebM VP9 (video/webm; codecs=vp9) WebM VP8 (video/webm; codecs=vp8)
AshleyScirra commented 5 years ago

It's not clear whether you're talking about performance in the editor, in the runtime, or both. Can you clarify?

SnipG commented 5 years ago

In C3 editor, with both runtimes, example have bad performance. While in Construct 2 software its pretty good in editor and outside. Is it just some editor edge case? If so, it would be nice to know what causing it. So i would know when its still good but just editor handles it differently.

AshleyScirra commented 5 years ago

Do you mean the layout view, or when running the game? I can't tell what you mean by "In C3 editor with both runtimes", you're mentioning both in the same sentence.

SnipG commented 5 years ago

When you preview the example: "1.Open C3 test case in C3. Preview in debug mode(See fps and cpu, i get 5fps 100%cpu)" I get it in Preview. I use editor, as C3 editor. Because it happes in C3 editor with both runtimes when you preview it. But is good With Construct 2 software/app/editor when you preview

I mean i don't preview it inside editor - as I look at it. But Preview as preview mode!

kingpirux commented 5 years ago

i had this issue too in a project for a client, they have a very low profile android hardware, but i made the construct 3 game work with a firefox gecko viewer, but there were 3 very clear problems:

AshleyScirra commented 5 years ago

@kingpirux - please note if you have any issues not described by the issue posted above, they will not be investigated unless you file separate issues for them. Further please do not mention unrelated issues in bug reports as it quickly becomes very confusing and can be a significant obstacle in resolving the issue.

AshleyScirra commented 5 years ago

The performance difference comes from "Seamless mode". This is off in C2, and in C3 it's not supported and is always on. If you turn it on in C2 the performance is the same as in C3.

"Seamless mode" was a broken feature: despite the name, it actually introduced seams where there previously were none before, hence its removal in C3. When seamless mode was enabled it would effectively group regions of the same tile in to tiled backgrounds and render them all in one go. However if there is transparency at the edge of the tile image, in some cases that will wrap around to the other side of the rectangle and introduce a seam along the edge of the identified area. So actually "seamless mode" off was the way to get seamless rendering, and instead rendered tiles individually with no wrapping so there was never any transparency wrapping that causes seams.

Since in this specific case you have over a million tiles on-screen which are all identical, C2 with seamless mode off can essentially turn the whole thing in to a single tiled background. However in C3 it renders tiles one-by-one, involving over a million draw calls per frame. This explains the performance difference. Even in C2 with seamless mode off, as you start to change the tiles so they're different, the performance will quickly plummet way back down, especially since the C2 engine is much slower overall. Try setting every tile to a random tile and comparing the performance difference!

Tilemap is not designed to be used like this and so isn't optimised for it. In realistic cases (particularly with every tile different) C3's tilemap rendering is many times faster than C2 (40x by one measurement). If you want to control individual pixels, you should be using Drawing Canvas instead.

SnipG commented 5 years ago

Indeed, it is this seemless mode, this option is missing from C3 c2runtime so i diden't know to look for it in Construct 2. And it is bad case to use tilemap, but original example(from where i got it) used it for collisions, with added solid behavior. So some ppl still might use it for that. But something like panthfinding obstacle map would do much better job, if it could add solid behavior to each cell, but this is out of topic info.