【问题标题】:How to measure a GPU Context Switch from Compute to Rendering Shader如何测量从计算到渲染着色器的 GPU 上下文切换
【发布时间】:2017-12-01 04:37:47
【问题描述】:

在 OpenGL 中,我调度计算着色器以根据运动方程计算给定对象模型中的新顶点位置。然后我通过顶点/片段渲染着色器程序渲染这些新的顶点位置。我的理解是,每次我调度一个计算着色器时,它都会启动一个 GPU 设备上下文切换,该切换需要有限的时间。

有人可以分享如何在 OpenGL 中测量计算着色器和渲染着色器之间的上下文切换。我假设它的时间非常短,但我需要测量它。感谢您的洞察力。

【问题讨论】:

    标签: c++ opengl opengl-es glsl compute-shader


    【解决方案1】:

    没有办法专门测量上下文切换时间。您只能测量特定 OpenGL 命令之间的时间(通过计时器查询),并且没有 OpenGL 命令来执行上下文切换。它是您发送的实际 OpenGL 命令的副产品。

    你能得到的最接近的是这样的:

    glBindVertexArray(emptyVAO);
    glEnable(GL_RASTERIZER_DISCARD); //Do the absolute minimal rendering.
    glBindProgramPipeline(minimalComputeTask); //Compute shader that does nothing, using no resources and writing no values.
    glDispatchCompute(1, 1, 1); //Done before the timer query, to force a switch to compute contexts.
    glBeginQuery(GL_TIME_ELAPSED​, queryObject);
    glDispatchCompute(1, 1, 1);
    glBindProgramPipeline(minimalRenderShaders); //VS does nothing and takes no inputs; no FS at all, since we're discarding.
    glDrawArrays(GL_POINTS, 0, 1);
    glEndQuery(GL_TIME_ELAPSED);
    glDisable(GL_RASTERIZER_DISCARD);
    

    然后您提取查询并读取时间。但即使这将包括实际执行计算和渲染操作所花费的时间。在您的情况下,您的时间可能应该包括一个glMemoryBarrier,它允许渲染操作读取计算着色器写入的内容。

    【讨论】:

      【解决方案2】:

      Timer queries 听起来应该可以工作,假设您的 GL 实现 meaningfully supports them:

      计时器查询是查询类型 GL_TIMESTAMP 和 GL_TIME_ELAPSED 的统称。 这些用于测量各种操作的 GPU 时间。所有返回的时间都以纳秒为单位。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        • 2015-03-26
        • 1970-01-01
        • 1970-01-01
        • 2014-02-16
        • 2013-07-24
        相关资源
        最近更新 更多