为什么绘画电话昂贵? [英] why are draw calls expensive?

查看:210
本文介绍了为什么绘画电话昂贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设纹理,顶点和着色器数据已经在图形卡上,则不需要向卡发送太多数据。有几个字节来识别数据,大概是一个4x4的矩阵,以及一些其他的参数。

所以所有的开销都来自哪里?这些操作是否需要与gpu进行某种形式的握手?



为什么发送一个包含一堆在CPU上计算的小型模型的网格通常比发送顶点id和变换矩阵? (第二个选项看起来像应该有更少的数据发送,除非模型比4x4矩阵小)解决方案

第一个所有,我假设用绘制调用,你的意思是告诉GPU渲染一定顶点作为具有特定状态(着色器,混合状态等)的三角形的命令。



平局呼叫不一定很贵。在较旧版本的Direct3D中,许多调用需要上下文切换,这很昂贵,但在新版本中并不是这样。



制作主要原因更少的绘制调用是图形硬件可以转换和渲染三角形的速度比您提交它们要快得多。如果每次调用都提交几个三角形,那么CPU将完全绑定,GPU将大部分处于空闲状态。 CPU无法以足够快的速度提供GPU。



使用两个三角形进行单个绘制调用便宜,但如果每次调用提交的数据太少,您将没有足够的CPU时间向GPU提交尽可能多的几何图形。



在进行绘图调用时存在一些实际成本,它需要设置在硬件方面(更新一堆寄存器)和驱动程序方面(验证和翻译你的一系列状态(使用顶点集合,使用什么着色器等)以及状态更改都会产生成本)调用设置状态)。



但是的主要花费仅适用于每次调用提交的数据太少,因为这会导致您并且阻止你完全使用硬件。

就像Josh说的那样,绘制调用也可以使命令缓冲区被刷新,但是在我的经验通常发生在您调用SwapBuffers时,而不是在提交ge时发生ometry。视频驱动程序通常会尝试尽可能多地缓冲(有时候需要几帧),以便尽可能多地从GPU中获得并行性。

您应该阅读nVidia演示文稿批量批处理!,它相当陈旧但涵盖了精确这个主题。


assuming the texture, vertex, and shader data are already on the graphics card, you don't need to send much data to the card. there's a few bytes to identify the data, and presumably a 4x4 matrix, and some assorted other parameters.

so where is all of the overhead coming from? do the operations require a handshake of some sort with the gpu?

why is sending a single mesh containing a bunch of small models, calculated on the CPU, often faster than sending the vertex id and transformation matrices? (the second option looks like there should be less data sent, unless the models are smaller than a 4x4 matrix)

解决方案

First of all, I'm assuming that with "draw calls", you mean the command that tells the GPU to render a certain set of vertices as triangles with a certain state (shaders, blend state and so on).

Draw calls aren't necessarily expensive. In older versions of Direct3D, many calls required a context switch, which was expensive, but this isn't true in newer versions.

The main reason to make fewer draw calls is that graphics hardware can transform and render triangles much faster than you can submit them. If you submit few triangles with each call, you will be completely bound by the CPU and the GPU will be mostly idle. The CPU won't be able to feed the GPU fast enough.

Making a single draw call with two triangles is cheap, but if you submit too little data with each call, you won't have enough CPU time to submit as much geometry to the GPU as you could have.

There are some real costs with making draw calls, it requires setting up a bunch of state (which set of vertices to use, what shader to use and so on), and state changes have a cost both on the hardware side (updating a bunch of registers) and on the driver side (validating and translating your calls that set state).

But the main cost of draw calls only apply if each call submits too little data, since this will cause you to be CPU-bound, and stop you from utilizing the hardware fully.

Just like Josh said, draw calls can also cause the command buffer to be flushed, but in my experience that usually happens when you call SwapBuffers, not when submitting geometry. Video drivers generally try to buffer as much as they can get away with (several frames sometimes!) to squeeze out as much parallelism from the GPU as possible.

You should read the nVidia presentation Batch Batch Batch!, it's fairly old but covers exactly this topic.

这篇关于为什么绘画电话昂贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆