From 0657489117c70ca364157554170a78bc78b40cc4 Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Thu, 4 Sep 2014 10:07:46 +0100 Subject: [PATCH] Lazy load programs [Problem] startup is slow [Cause] unnecessary loading of shaders that may not be used [Solution] lazy load Change-Id: I7ad9d8182aa2e1e650decb04cebf6f7752b99afc --- automated-tests/src/dali/utc-Dali-ShaderEffect.cpp | 14 ++++---------- dali/internal/render/shaders/program.cpp | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp index e57f493..1fa2684 100644 --- a/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/src/dali/utc-Dali-ShaderEffect.cpp @@ -281,6 +281,8 @@ int UtcDaliShaderEffectMethodDelete01(void) application.SendNotification(); application.Render(); + GLuint beforeShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled(); + // create a new shader effect // the vertex and fragment shader will be cached in the ShaderFactory ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource ); @@ -297,16 +299,8 @@ int UtcDaliShaderEffectMethodDelete01(void) application.Render(); GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled(); - - // get the vertex shader (compiled before fragment shader). - // this last shaders compiled is for text. - GLuint vertexShaderId = lastShaderCompiled - 1; - - // compare the vertex shader sent to be compiled, with the shader string that ended up being compiled - // this is to confirm the string hasn't been deleted / corrupted. - std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( vertexShaderId ); - DALI_TEST_EQUALS( VertexSource, - actualVertexShader.substr( actualVertexShader.length() - strlen( VertexSource ) ), TEST_LOCATION ); + // no shaders were compiled as they are now compiled on demand and this shader was not used + DALI_TEST_EQUALS( beforeShaderCompiled, lastShaderCompiled, TEST_LOCATION ); END_TEST; } diff --git a/dali/internal/render/shaders/program.cpp b/dali/internal/render/shaders/program.cpp index c25fdb0..0deb6f6 100644 --- a/dali/internal/render/shaders/program.cpp +++ b/dali/internal/render/shaders/program.cpp @@ -128,7 +128,7 @@ Program* Program::New( const Integration::ResourceId& resourceId, Integration::S // program not found so create it program = new Program( shaderData, context, modifiesGeometry ); - program->Load(); + // we want to lazy load programs so dont do a Load yet, it gets done in Use // tell context to cache it context.CacheProgram( shaderHash, program ); -- 2.7.4