一般渲染和性能问题(OpenGL)

时间:2022-04-02 03:52:29

I'm working with LibGDX, and I need answers to some general optimization questions:

我正在使用LibGDX,我需要一些常规优化问题的答案:

  1. If I draw a sprite that is only partially visible to the viewport/camera, does it have the same performance hit as drawing it completely visible to the viewport?
  2. 如果我绘制一个只对视口/相机部分可见的精灵,它是否具有与绘制视口完全可见的相同的性能命中?

  3. If I draw a sprite outside the boundaries of the the active viewport, does it affect the performance same way as not drawing the sprite at all OR similar to drawing it inside the viewport? In other words: What kind of performance impact off-screen sprites have?
  4. 如果我在活动视口的边界之外绘制一个精灵,它是否会影响性能,就像没有绘制精灵一样,或者类似于在视口内绘制精灵?换句话说:屏幕外精灵有什么样的性能影响?

  5. When drawing a small (for example 32x32) region of a large TextureAtlas (2048x2048) on the screen, does it have a similar performance hit as drawing a small 32x32 single texture? I know that large textures affect memory usage, but do they affect real-time rendering performance when rendering only a small region?
  6. 在屏幕上绘制一个大型TextureAtlas(2048x2048)的小区域(例如32x32)时,它是否具有与绘制小型32x32单个纹理相似的性能?我知道大纹理会影响内存使用,但是只渲染一个小区域时它们会影响实时渲染性能吗?

  7. If I rotate a big sprite while rendering it, does it affect performance?
  8. 如果我在渲染时旋转一个大精灵,它会影响性能吗?

  9. If I draw a 4096x4096 texture on the screen, but scale it down so that on the screen it looks like 10x10, does it have the same performance as rendering it full sized? i.e. does the apparent size of a texture on the screen affect rendering performance?
  10. 如果我在屏幕上绘制4096x4096纹理,但是将其缩小以使其在屏幕上看起来像10x10,它是否具有与渲染全尺寸相同的性能?即屏幕上纹理的表观大小是否会影响渲染性能?

3 个解决方案

#1


  1. No.
  2. Its more permormant than drawing it inside the viewport, but still not as performant as not drawing it at all.
  3. 它比在视口中绘制它更具渗透性,但仍然没有完全没有绘制它的性能。

  4. The bigger image will take more time to be prepared for rendering. The actual rendering will be the same as fast.
  5. 较大的图像需要更多时间来准备渲染。实际渲染与快速渲染相同。

  6. Yes.
  7. No.

#2


  1. No. Vertex processing will be the same, but the fragments outside the viewport will be clipped, reducing fragment processing.

    不会。顶点处理将是相同的,但视口外的片段将被剪切,从而减少片段处理。

  2. This is just an extreme case of question 1. Now there's no fragment processing, but still all the vertex processing. Depending on how cheap/expensive your vertex processing is, this can be very variable. It's certainly more than not drawing at all. On the other hand, if you add a lot of logic in your app to avoid drawing a sprite, you may be adding more overhead than you save by not rendering it.

    这只是问题1的极端情况。现在没有片段处理,但仍然是所有顶点处理。根据顶点处理的便宜/昂贵程度,这可能会变化很大。这当然不仅仅是绘画。另一方面,如果您在应用程序中添加了大量逻辑以避免绘制精灵,那么您可能会添加比通过不渲染而节省的更多开销。

  3. Once the texture is loaded, the rendering itself should be fairly similar. But of course loading the texture is going to be much more expensive. This is not only for the OpenGL call you make to load the texture data, but also the overhead to map it into the GPU address space before rendering, and other related memory management overhead.

    加载纹理后,渲染本身应该非常相似。但是当然加载纹理会更加昂贵。这不仅适用于加载纹理数据的OpenGL调用,还适用于在渲染之前将其映射到GPU地址空间的开销,以及其他相关的内存管理开销。

  4. Maybe. But probably not much. GPUs use memory layouts that are optimized for local access, without much dependence on the orientation of the access pattern.

    也许。但可能并不多。 GPU使用针对本地访问进行优化的内存布局,而不太依赖于访问模式的方向。

  5. Rendering at 10x10 is certainly much cheaper because there are a lot fewer fragments, and corresponding sampling operations. But it can still be much more expensive than rendering with a 10x10 texture, because access is much less localized, so there will be a lot more cache misses. To avoid that, use mipmapping, which will give you most of the performance of a smaller texture if you render a large texture scaled down.

    以10x10渲染肯定要便宜得多,因为碎片和相应的采样操作要少得多。但它仍然比使用10x10纹理渲染要昂贵得多,因为访问的本地化程度要低得多,因此会有更多的缓存未命中。为避免这种情况,请使用mipmapping,如果渲染缩小的大纹理,它将为您提供较小纹理的大部分性能。

#3


When talking about performance, the impact depends on what your bottle neck is. Drawing a sprite uses some CPU and a tiny bit of GPU regardless of how much, if any, of it is on screen. In general, the more pixels of a sprite are actually on screen, the more GPU it will use.

在谈论性能时,影响取决于瓶颈是什么。绘制一个精灵使用一些CPU和一小部分GPU,无论它在屏幕上有多少(如果有的话)。通常,精灵的实际像素越多,它将使用的GPU就越多。

  1. In terms of CPU, no difference, but for the GPU, drawing fewer pixels of the sprite is better.

    就CPU而言,没有区别,但对于GPU来说,绘制更少的精灵像素效果更好。

  2. Off screen sprites have a CPU impact and small GPU impact. If you have a lot of off screen sprites, you may need to avoid drawing them, but you should check them in groups instead of one-by-one, or you risk spending more CPU to check them than it would take to draw them off screen.

    屏幕外精灵具有CPU影响和小GPU影响。如果你有很多屏幕外的精灵,你可能需要避免绘制它们,但你应该分组而不是逐一检查它们,否则你可能会花费更多的CPU来检查它们而不是将它们抽出来屏幕。

  3. Drawing a small region of a big texture has same performance hit as drawing a small texture. But the first option allows you to batch a lot of different images into one draw call, which is a big saver.

    绘制大纹理的小区域与绘制小纹理具有相同的性能。但第一个选项允许您将许多不同的图像批量处理为一个绘图调用,这是一个大的保护程序。

  4. Some, because you'll recalculating its vertices on each frame.

    一些,因为你将在每个帧上重新计算它的顶点。

  5. Drawing it smaller means you're drawing fewer pixels, so that's faster.

    将其绘制得更小意味着您绘制更少的像素,因此速度更快。

#1


  1. No.
  2. Its more permormant than drawing it inside the viewport, but still not as performant as not drawing it at all.
  3. 它比在视口中绘制它更具渗透性,但仍然没有完全没有绘制它的性能。

  4. The bigger image will take more time to be prepared for rendering. The actual rendering will be the same as fast.
  5. 较大的图像需要更多时间来准备渲染。实际渲染与快速渲染相同。

  6. Yes.
  7. No.

#2


  1. No. Vertex processing will be the same, but the fragments outside the viewport will be clipped, reducing fragment processing.

    不会。顶点处理将是相同的,但视口外的片段将被剪切,从而减少片段处理。

  2. This is just an extreme case of question 1. Now there's no fragment processing, but still all the vertex processing. Depending on how cheap/expensive your vertex processing is, this can be very variable. It's certainly more than not drawing at all. On the other hand, if you add a lot of logic in your app to avoid drawing a sprite, you may be adding more overhead than you save by not rendering it.

    这只是问题1的极端情况。现在没有片段处理,但仍然是所有顶点处理。根据顶点处理的便宜/昂贵程度,这可能会变化很大。这当然不仅仅是绘画。另一方面,如果您在应用程序中添加了大量逻辑以避免绘制精灵,那么您可能会添加比通过不渲染而节省的更多开销。

  3. Once the texture is loaded, the rendering itself should be fairly similar. But of course loading the texture is going to be much more expensive. This is not only for the OpenGL call you make to load the texture data, but also the overhead to map it into the GPU address space before rendering, and other related memory management overhead.

    加载纹理后,渲染本身应该非常相似。但是当然加载纹理会更加昂贵。这不仅适用于加载纹理数据的OpenGL调用,还适用于在渲染之前将其映射到GPU地址空间的开销,以及其他相关的内存管理开销。

  4. Maybe. But probably not much. GPUs use memory layouts that are optimized for local access, without much dependence on the orientation of the access pattern.

    也许。但可能并不多。 GPU使用针对本地访问进行优化的内存布局,而不太依赖于访问模式的方向。

  5. Rendering at 10x10 is certainly much cheaper because there are a lot fewer fragments, and corresponding sampling operations. But it can still be much more expensive than rendering with a 10x10 texture, because access is much less localized, so there will be a lot more cache misses. To avoid that, use mipmapping, which will give you most of the performance of a smaller texture if you render a large texture scaled down.

    以10x10渲染肯定要便宜得多,因为碎片和相应的采样操作要少得多。但它仍然比使用10x10纹理渲染要昂贵得多,因为访问的本地化程度要低得多,因此会有更多的缓存未命中。为避免这种情况,请使用mipmapping,如果渲染缩小的大纹理,它将为您提供较小纹理的大部分性能。

#3


When talking about performance, the impact depends on what your bottle neck is. Drawing a sprite uses some CPU and a tiny bit of GPU regardless of how much, if any, of it is on screen. In general, the more pixels of a sprite are actually on screen, the more GPU it will use.

在谈论性能时,影响取决于瓶颈是什么。绘制一个精灵使用一些CPU和一小部分GPU,无论它在屏幕上有多少(如果有的话)。通常,精灵的实际像素越多,它将使用的GPU就越多。

  1. In terms of CPU, no difference, but for the GPU, drawing fewer pixels of the sprite is better.

    就CPU而言,没有区别,但对于GPU来说,绘制更少的精灵像素效果更好。

  2. Off screen sprites have a CPU impact and small GPU impact. If you have a lot of off screen sprites, you may need to avoid drawing them, but you should check them in groups instead of one-by-one, or you risk spending more CPU to check them than it would take to draw them off screen.

    屏幕外精灵具有CPU影响和小GPU影响。如果你有很多屏幕外的精灵,你可能需要避免绘制它们,但你应该分组而不是逐一检查它们,否则你可能会花费更多的CPU来检查它们而不是将它们抽出来屏幕。

  3. Drawing a small region of a big texture has same performance hit as drawing a small texture. But the first option allows you to batch a lot of different images into one draw call, which is a big saver.

    绘制大纹理的小区域与绘制小纹理具有相同的性能。但第一个选项允许您将许多不同的图像批量处理为一个绘图调用,这是一个大的保护程序。

  4. Some, because you'll recalculating its vertices on each frame.

    一些,因为你将在每个帧上重新计算它的顶点。

  5. Drawing it smaller means you're drawing fewer pixels, so that's faster.

    将其绘制得更小意味着您绘制更少的像素,因此速度更快。