Camera 使用复杂片段着色器时摄影机预览流放置帧的GPU渲染

Camera 使用复杂片段着色器时摄影机预览流放置帧的GPU渲染,camera,gpu,shader,surface,Camera,Gpu,Shader,Surface,我的目标设备是一个带有PowerVR GPU的android 4.4.2 pad设备。现在,我设计了一个程序,从摄像机中检索实时视频,然后将其馈送到GPU进行渲染,结果被编码为H.264流 此流程与bigflake上的流程非常相似: 我也利用这个代码来做整个工作人员 现在问题来了。我需要提高输出视频分辨率,例如2048x2048,我还需要使用非常复杂的片段着色器。然后我发现应用程序掉了一些帧。我输入的视频是30fps,而结果视频的平均速度是22fps,而有时视频会占用大约1秒左右的时间 我怀疑G

我的目标设备是一个带有PowerVR GPU的android 4.4.2 pad设备。现在,我设计了一个程序,从摄像机中检索实时视频,然后将其馈送到GPU进行渲染,结果被编码为H.264流

此流程与bigflake上的流程非常相似: 我也利用这个代码来做整个工作人员

现在问题来了。我需要提高输出视频分辨率,例如2048x2048,我还需要使用非常复杂的片段着色器。然后我发现应用程序掉了一些帧。我输入的视频是30fps,而结果视频的平均速度是22fps,而有时视频会占用大约1秒左右的时间

我怀疑GPU的工作负载可能太高了。因此,我使用PVRTune来分析应用程序的工作负载。GPU任务负载:tiler非常低,每帧仅消耗0.4ms左右,而GPU任务负载:渲染器非常高,每帧消耗15~19ms。其他GPU任务负载和CPU负载都非常低。在相邻的渲染帧中,GPU空闲时间约为10~30ms,并且每个渲染帧的空闲时间不同

我修改了CameraToMpegTest.java代码,将drainEncoder()函数调用放在一个独立线程中,以加快处理速度,因此我的应用程序主工作循环如下:

while (System.nanoTime() < desiredEnd) {
    mnGPUOpCount++;

    // Acquire a new frame of input, and render it to the Surface.  If we had a
    // GLSurfaceView we could switch EGL contexts and call drawImage() a second
    // time to render it on screen.  The texture can be shared between contexts by
    // passing the GLSurfaceView's EGLContext as eglCreateContext()'s share_context
    // argument.
    mStManager.awaitNewImage();
    mStManager.drawImage();

    // Set the presentation time stamp from the SurfaceTexture's time stamp.  This
    // will be used by MediaMuxer to set the PTS in the video.
    if (VERBOSE) {
        Log.d(TAG, "present: " + ((st.getTimestamp() - startWhen) / 1000000.0) + "ms");
    }
    mInputSurface.setPresentationTime(st.getTimestamp());

    // Submit it to the encoder.  The eglSwapBuffers call will block if the input
    // is full, which would be bad if it stayed full until we dequeued an output
    // buffer (which we can't do, since we're stuck here).  So long as we fully drain
    // the encoder before supplying additional input, the system guarantees that we
    // can supply another frame without blocking.
    if (VERBOSE) Log.d(TAG, "sending frame to encoder");
    mInputSurface.swapBuffers();
}
while(System.nanoTime()

如果片段着色器无法再优化,并且分辨率仍然很大,则GPU渲染时间将高达19毫秒。在这种情况下,我可以得到流畅的视频渲染吗?我认为对于30fps,我们有33ms的运行时间,所以很有可能实现。那么,是什么原因导致帧下降?我不知道如何进一步改进主工作循环。

更新它,希望更多的人能看到这个问题。有人能给我一个提示吗?