为什么绘制调用很昂贵? [英] why are draw calls expensive?

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

问题描述

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

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.

那么所有的开销来自哪里?操作是否需要与 gpu 进行某种握手?

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

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

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)

推荐答案

首先,我假设绘制调用"是指告诉 GPU 将一组特定顶点渲染为三角形的命令某种状态(着色器、混合状态等).

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).

绘制调用不一定很昂贵.在旧版本的 Direct3D 中,许多调用需要上下文切换,这很昂贵,但在较新版本中则不然.

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.

减少绘制调用的主要原因是图形硬件可以比您提交三角形的速度快得多.如果您每次调用提交几个三角形,您将完全受制于CPU 和 GPU 将大部分处于空闲状态.CPU 将无法足够快地为 GPU 供电.

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.

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

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).

但是绘制调用的主要成本仅适用于每次调用提交的数据太少的情况,因为这会导致您受 CPU 限制,并阻止您充分利用硬件.

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.

就像 Josh 说的,绘制调用也会导致命令缓冲区被刷新,但根据我的经验,这通常发生在调用 SwapBuffers 时,而不是在提交几何体时.视频驱动程序通常会尝试尽可能多地缓冲(有时是几帧!)以从 GPU 中挤出尽可能多的并行性.

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.

您应该阅读 nVidia 演示文稿 Batch Batch Batch!,它是相当古老,但正好涵盖了这个主题.

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

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

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