Tip to improve performance on WP8.1/Win10 Mobile platform

Hello everyone i faced the project to make the game support windows platform (wp8.1/ win10 mobile) , but the issue that that the fps of the game is very slow especially i add listview and clipping node into scene (on the android / ios run normal) .

i also run the sample with the latest version (3.13.1 ) seem this issue still happened

i have spent many time to find the issue and after a long time i think this may be been fixed

first : i dont call render() func of renderer on Scene because the main render of CCDirector already has a renderer

void Scene::render(Renderer* renderer, const Mat4& eyeTransform, const Mat4* eyeProjection)
{
    auto director = Director::getInstance();
    Camera* defaultCamera = nullptr;
    const auto& transform = getNodeToParentTransform();

    for (const auto& camera : getCameras())
    {
     ....

// on platform wp8.1 / win10 mobile comment this line
//        renderer->render();
//
		
        camera->restore();

      ....
    }

....
}

second : i dont call sort in render because i have track the time sort to make the wp platform run slow (i dont know why but the ios/android run normal)

void Renderer::render()
{
    //Uncomment this once everything is rendered by new renderer
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //TODO: setup camera or MVP
    _isRendering = true;
    
    if (_glViewAssigned)
    {
        //Process render commands
        //1. Sort render commands based on ID
       
//begin do: on wp8.1 / w10 mobile comment this line
/*
        for (auto &renderqueue : _renderGroups)
        {
            renderqueue.sort();
        }
*/
//end do
        visitRenderQueue(_renderGroups[0]);
    }
    clean();
    _isRendering = false;
}

after 2 changes , the fps of game increase to ~60 when render on full resolution (check on lumia 640xl, lumia 630, lumia 920) in normal scene

but the last issue that when we have many nodes that use stencil buffer (clippingnode , listview , uilayout …) the fps drop to 10 fps and cannot play (android and ios run normal)

so after investigating , i found the render pipeline of cocos use difference with directX of wp8.1/10 , i saw that we copy vertex and indice buffer so many time from CPU to GPU and it cause bottleneck , so i change the code like this

 void Renderer::drawBatchedTriangles()
{
    ...

    /************** 2: Copy vertices/indices to GL objects *************/
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        ....
    }
    else
    {
        // Client Side Arrays
#define kQuadSize sizeof(_verts[0])
        glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);

        glBufferData(GL_ARRAY_BUFFER, sizeof(_verts[0]) * _filledVertex , _verts, GL_DYNAMIC_DRAW);

        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);

        // vertices
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, vertices));

        // colors
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, colors));

        // tex coords
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof(V3F_C4B_T2F, texCoords));

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);

		//chien todo: fix performance on wp platform
#if defined CC_WINDOWS_PHONE_8_1 || defined WIN10_ARM
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * _filledIndex, _indices, GL_DYNAMIC_DRAW);
#else
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices[0]) * _filledIndex, _indices, GL_STATIC_DRAW);
#endif

    }
    ....
}

so i use dynamic draw on wp8.1/win10 and the fps increase to ~40 fps with scene have many stencil node like clipping or listview , i saw there are many function use the GL_STATIC_DRAW for GL_ELEMENT_ARRAY_BUFFER like this , but i dont use these function, so i have not tested it yet .

any idear ?

1 Like