Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples startup slow #17

Open
kingofoz opened this issue Feb 13, 2019 · 9 comments
Open

Examples startup slow #17

kingofoz opened this issue Feb 13, 2019 · 9 comments

Comments

@kingofoz
Copy link

Hi @BearishSun
Seems all examples need about 2s to render after I execute them. Do we have some methods to speed up? I ran these examples on an old Macbook air with i5 cpu.

Thanks,
Yingjun

@BearishSun
Copy link
Member

Most examples do some resource loading at start-up, which could take a moment or two at start-up. To keep examples simple as possible there aren't any loading screens.

Also make sure to compile in release mode.

Other than that I cannot tell what the issue could be. You can profile the application and see which parts are taking a long time.

@kingofoz
Copy link
Author

Thanks for the comment. @BearishSun Yes, it is in release mode.
Please see this program:

#include "BsApplication.h"
#include "Scene/BsSceneObject.h"
#include "Components/BsCCamera.h"

int main()
{
using namespace bs;

VideoMode videoMode(720, 480);
Application::startUp(videoMode, "Example", false);

HSceneObject sceneCameraSO = SceneObject::create("SceneCamera");
HCamera sceneCamera = sceneCameraSO->addComponent<CCamera>();
sceneCamera->setMain(true);
sceneCameraSO->setPosition(Vector3(40.0f, 30.0f, 230.0f));
sceneCameraSO->lookAt(Vector3(0, 0, 0));

Application::instance().runMainLoop();
Application::shutDown();

return 0;

}
Even such a simple program need 1 ~ 2s to load. Have you noticed this issue on your machine? I am pretty new to bsf. If you like, please give me some instructions so I can figure it out.

Thanks,
Yingjun

@BearishSun
Copy link
Member

I don't have the time to investigate properly right now but the only thing that comes to mind is shader compilation - OpenGL has no support for shader bytecode caching, so shaders need to be recompiled every time the application is ran, and the default renderer uses quite a lot of them. It could take a couple of seconds in a slower machine.

I'd accept a PR if you were to come up with a shader caching solution for OpenGL, but I likely won't spend time on it as I'd plan on replacing OpenGL with Metal anyway.

@kingofoz
Copy link
Author

Wow, Metal. That sounds exciting. I would try on Windows and see if the issue still exists. Thanks!

@kingofoz
Copy link
Author

Hi @BearishSun
Is it possible to change the render from dx11 to opengl on Windows? I found my win7 box only supports dx10. And the examples can not run on it.

@BearishSun
Copy link
Member

BearishSun commented Feb 14, 2019

You can provide -DRENDER_API_MODULE="OpenGL" to CMake, or use CMake GUI and select it from the drop-down.

However you will likely not be able to run the examples on OpenGL either if your card is DirectX 10 only. The reason it works on macOS is because OpenGL 4.1 is expected, while on Windows/Linux OpenGL 4.5 is required instead (and the hardware that supports it - and your card is unlikely to support 4.5 since it's DX10 only).

You might be able to get it to work by changing a few defines in BsGLPrerequisites.h, in particular

	#define BS_OPENGL_4_2 1
	#define BS_OPENGL_4_3 1
	#define BS_OPENGL_4_4 1
	#define BS_OPENGL_4_5 1
	#define BS_OPENGL_4_6 0

Should all be set to 0. But this is unsupported officially as plans are to drop OpenGL 4.1 support eventually.

@kingofoz
Copy link
Author

CrashReports.zip
I set DRENDER_API_MODULE="OpenGL" and set those values to 0 in BsGLPrerequisites.h. Compilation is successful, but all examples can not be run normally, they just show black windows and stop working. I uploaded some crash reports. Please take a look.
@BearishSun Thanks!

@BearishSun
Copy link
Member

It's unclear what exactly is causing the crashes, except that OpenGL fails to load. But it is likely due to the DX10 hardware as I mentioned, and officially Windows requires OpenGL 4.5. There are probably some tweaks required to get it running with less features.

@kingofoz
Copy link
Author

Hi @BearishSun
Thanks for the comment. I have seen some code in BsWin32GLSupport.cpp. Please see:
attribs[i++] = 0;
glrc = wglCreateContextAttribsARB(hdc, 0, attribs);
}
else
glrc = wglCreateContext(hdc);

			if (glrc == 0)
				BS_EXCEPT(RenderingAPIException, "wglCreateContext failed: " + translateWGLError());

Seems wglCreateContext(hdc) returns 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants