D
D
Daniel2020-03-09 23:34:02
css
Daniel, 2020-03-09 23:34:02

SwapBuffers/ glXSwapBuffers consumes exactly 50% of the application's time (the load is not important), what could be the reason?

here is the output of strace and ltrace

strace

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 47.21    0.193640          21      9088           ioctl
 15.72    0.064488          11      5500      3806 recvmsg
  9.47    0.038823          14      2654           poll
  8.50    0.034849          18      1891           writev
  7.95    0.032610          13      2412           write
  6.98    0.028625           3      8835           getpid
  2.27    0.009293           7      1194           clock_gettime
  0.25    0.001022           5       204        61 openat
  0.23    0.000951           3       294           lstat
  0.23    0.000945           4       208           mmap
  0.22    0.000882           3       276           read
  0.18    0.000753          39        19           munmap
  0.16    0.000666          10        61           mprotect
  0.11    0.000459           3       151           close
  0.09    0.000355           2       136           fstat
  0.08    0.000334           4        72           brk
  0.06    0.000260           3        66           readlink
  0.05    0.000207          18        11         1 recvfrom
  0.05    0.000205          10        20           getdents64
  0.04    0.000158           3        44         7 stat
  0.04    0.000147           7        21         2 futex
  0.02    0.000067          16         4           clone
  0.01    0.000059           6         9           rt_sigprocmask
  0.01    0.000034          11         3           socket
  0.01    0.000033          11         3         2 connect
  0.01    0.000032           3         9           getrandom
  0.01    0.000032          16         2           memfd_create
  0.01    0.000024           3         8           pread64
  0.01    0.000022          22         1           set_robust_list
  0.01    0.000021          10         2           sendmsg
  0.00    0.000020           5         4         1 access
  0.00    0.000017           3         5           fcntl
  0.00    0.000017           8         2           ftruncate
  0.00    0.000014           2         5           getuid
  0.00    0.000013           3         4           sched_setscheduler
  0.00    0.000011           2         4           geteuid
  0.00    0.000009           4         2           rt_sigaction
  0.00    0.000008           1         6           lseek
  0.00    0.000007           2         3           uname
  0.00    0.000005           5         1           getpeername
  0.00    0.000005           5         1           set_tid_address
  0.00    0.000004           2         2         1 arch_prctl
  0.00    0.000003           3         1           getsockname
  0.00    0.000003           3         1           prlimit64
  0.00    0.000000           0         1           shutdown
  0.00    0.000000           0         1           execve
------ ----------- ----------- --------- --------- ----------------
100.00    0.410132                 33241      3881 total


ltrace
% time     seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 50.85   24.402492       26874       908 glXSwapBuffers
 22.31   10.705584       11777       909 XGetWindowAttributes
  4.48    2.147792         262      8167 clock_gettime
  2.15    1.031597         189      5450 memcpy
  1.56    0.748925         825       907 XPending
  1.56    0.747812         205      3647 _ZNSo3putEc
  1.40    0.672953         184      3646 strlen
  1.39    0.667833         183      3647 _ZNSo5flushEv
  1.26    0.604373         407      1483 XNextEvent
  1.20    0.574001         157      3644 _ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
  1.13    0.543004         382      1420 XGetEventData
  1.10    0.529293         582       908 glClear
  0.99    0.473619         319      1483 XFindContext
  0.85    0.410097         226      1814 clock
------ ----------- ----------- --------- --------------------
100.00   47.991318                 67130 total


and here is the main loop code:
spoiler
while (!glfwWindowShouldClose(test.window))
    {
        // Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions
        glfwPollEvents();
         movent();
         Do_Movement();
        // Check and call events


        // Clear the colorbuffer
        glClearColor(0.2f, 0.4f, 0.3f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        view=camera.GetViewMatrix();
        projection=glm::perspective(glm::radians(camera.Zoom), static_cast<GLfloat>(WIDTH) / static_cast<GLfloat>(HEIGHT), 0.1f, 100.0f);


        Mold_of_part::DRAW();
        }
        
        glfwSwapBuffers(test.window);
    }


and the render function code:
spoiler
#include <display.h>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <GLFW/glfw3.h>

void Display::start(Buffer_VAO &VAO,Shader &shader,std::vector<Animation> & textures,GLint  count){
    double end=0.0;
    double start =glfwGetTime();
    shader.use();
     //анимация
     for(auto &T:textures){
         if(T.Texture::type_image==D21A){
     T.new_cicl();
     T.new_fream();
         }
    };


     //присоединение текстур и анимации
     int i=0;
     std::string nomer;

     std::string name("");
     std::string name1("ourColor");
     for(auto &T:textures){

        switch (T.Texture::type_texture) {
            case Map_diffusion  : name="ourTexture";            break;
            case Map_normals    : name="ourTexture_normal";     break;
            case Map_reflection : name="ourTexture_reflection"; break;
            case Map_height     : name="ourTexture_height"; break;
      }

    if(T.Texture::type_image==D21 || T.Texture::type_image==D21A){
     glActiveTexture(static_cast<unsigned int>(GL_TEXTURE0+i));
     nomer=std::to_string(i);


     shader.Uniform((name+nomer).c_str(), i);


     glBindTexture(GL_TEXTURE_2D,T.texture());
    }

     if(T.Texture::type_image==D21){
       shader.Uniform((name1+nomer).c_str(),0.0f, 0.0f,1.0f,1.0f);
     }else{
       shader.Uniform((name1+nomer).c_str(),T.result[0], T.result[1],T.result[2],T.result[3]);
     }
     i++;

    }




(this->*draw_type)(VAO,count);
 glActiveTexture(GL_TEXTURE0);

end += (glfwGetTime()-start);
 std::cout<<"test drawwwwwww"<<std::endl;
  std::cout<<"draw:"<<end<<std::endl;

};

Display::Display(Buffer_VAO &VAO_){
    std::cout<<"new desplay"<<std::endl;
    if(VAO_.indices_size){
    draw_type=&Display::DrawElements;
    };
}


void Display::DrawArrays(Buffer_VAO &VAO,GLint &count){
 glBindVertexArray(VAO.VAO);
 glDrawArraysInstanced(GL_TRIANGLES,0,GL_UNSIGNED_INT,count);
 glBindVertexArray(0);
};


void Display::DrawElements(Buffer_VAO &VAO,GLint & count){
  glBindVertexArray(VAO.VAO);
  glDrawElementsInstanced(GL_TRIANGLES, static_cast<GLint>(VAO.indices_size), GL_UNSIGNED_INT, nullptr,count);
  glBindVertexArray(0);
};






void Display::VAO_update(Buffer_VAO VAO_new){
    if(VAO_new.indices_size){
    draw_type=&Display::DrawElements;
    };
};

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Udaltsov, 2019-07-31
@imageneyshen

This is very easy to make using Flexbox
I made an example for you:
https://codepen.io/anon/pen/aeWZjm
Recommended for review:
Layout on Flexbox in CSS. Complete reference

D
Dima Polos, 2019-07-30
@dimovich85

Background image, and padding on the left.

M
Mercury13, 2020-03-10
@Mercury13

glSwapBuffers is spinning around waiting for VSYNC. That's why it consumes so much.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question