简体   繁体   English

实时2D渲染到系统内存

[英]Real-time 2D rendering to system memory

By writing a video filter which processes image/frame data in system ( not video ) memory, renders 2D graphics, should be cross-platform (at least Windows, Linux & OSX ) and work very fast, i looked over different renderers, like Cairo , AGG and many other projects. 通过编写处理系统( 非视频 )内存中的图像/帧数据的视频滤镜,渲染2D图形,应该是跨平台的(至少是Windows,Linux和OSX )并且工作得非常快,我查看了不同的渲染器,比如开罗AGG和许多其他项目。 I'd prefer no GPU requirement, so my focus was on software rendering so far. 我不喜欢GPU要求,因此到目前为止我的重点是软件渲染。

Regrettably Cairo could become very slow on complex paths & gradients and produced ugly geometry faults by tiny path segments, AGG was slow too because of missing optimizations which requires a lot of work by users, other projects just rendered to windows or performance wasn't important for them. 令人遗憾的是, 开罗在复杂的路径和渐变上变得非常慢,并且通过微小的路径段产生了丑陋的几何缺陷, AGG也很慢,因为缺少优化需要用户进行大量工作,其他项目只是渲染到窗口或性能不重要对他们来说 Blend2D made me curious but takes his time to grow mature. Blend2D让我很好奇但是他的时间变得成熟了。

Now i'm asking me: should i just render to an OpenGL framebuffer and do the 2D-to-3D stuff by a geometry library, take the challenge to develop a software renderer from scratch (accelerated by SIMD, threaded pipeline, etc.) or did i miss a library which is fitting for me? 现在我问我:我应该渲染一个OpenGL帧缓冲区并通过几何库做2D到3D的东西,接受挑战从头开发软件渲染器(由SIMD,线程管道等加速)还是我想念一个适合我的图书馆?

Is pushing everything graphics related to GPU always worth because of cheap data transfer to & from video memory these days, even with 1080p or larger images? 推动与GPU相关的所有图形总是值得的,因为近来便宜的数据传输到视频内存和从视频内存传输,即使使用1080p或更大的图像?

A typical desktop CPU has 4 processing cores running at 2.5GHz. 典型的台式机CPU有4个处理核心,运行频率为2.5GHz。 A modern desktop GPU (circa 2010) has 48 to 480 shaders running at 1.4GHz. 现代桌面GPU (大约2010年)有48到480个着色器,运行频率为1.4GHz。 So in terms of raw processing power, the GPU can process graphics 7 to 70 times faster than the CPU. 因此,就原始处理能力而言,GPU可以比CPU快7到70倍处理图形。

As for transfer bandwidth, a 1080p image is 1920x1080 pixels, the frame rate is 30 frames per second, and a pixel is 4 bytes (32 bits). 至于传输带宽,1080p图像是1920×1080像素,帧速率是每秒30帧,像素是4字节(32位)。 So the total bus bandwidth required for realtime 1080p processing is 因此,实时1080p处理所需的总总线带宽是

1920 x 1080 x 30 x 4 = 248 MB/s

The bandwidth of a PCI Express 2.0 x16 slot is 8000 MB/s. PCI Express 2.0 x16插槽的带宽为8000 MB / s。 Which is to say that the CPU to GPU transfer rate is not an issue. 也就是说CPU到GPU的传输速率不是问题。

So, to answer your question: Yes, pushing everything graphics related to the GPU is always worth it, even with 1080p or larger images. 所以,回答你的问题:是的,即使使用1080p或更大的图像,推送与GPU相关的所有图形总是值得的。

Alternative to OpenCV could be SDL . OpenCV的替代品可能是SDL There is at least a tutorial and documentation that specifically talks about streaming video data to the hardware . 至少有一个教程和文档专门讨论将视频数据流式传输到硬件 Of course, you'll have to rewrite your filter in glsl to get any decent acceleration. 当然,你必须用glsl重写你的过滤器来获得任何不错的加速度。

That said, it sounds like your problem may benefit more from a GPU-compute solution such as OpenCL or Cuda. 也就是说,听起来您的问题可能会从OpenCL或Cuda等GPU计算解决方案中获益更多。 In this case there's no rendering involved, instead you send your data to a GPU-kernel, and get it back when it is processed. 在这种情况下,不涉及渲染,而是将数据发送到GPU内核,并在处理时将其恢复。 Or can send it to OpenGL/DirectX (the video memory can be reused as texture quite easily without performance loss) for rendering. 或者可以将它发送到OpenGL / DirectX(视频内存可以很容易地作为纹理重用而不会丢失性能)进行渲染。 If you are not keen on moving beyond the OpenGL api, you can also use a compute-shader . 如果您不想超越OpenGL api,还可以使用计算着色器 Works like a traditional shader except that it computes in a pass, but with a few additional constraints and restrictions. 像传统着色器一样工作,除了它在传递中计算,但有一些额外的约束和限制。

Have you tried OpenCV ? 你试过OpenCV吗?

It provides both the software and the hardware renderer with the huge library of highly optimized functions for the real-time image processing and rendering. 它为软件和硬件渲染器提供了大量高度优化的函数 ,用于实时图像处理和渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM