A trip through the Graphics Pipeline 2011, part 11

Jim Blinn's Corner - A trip down the graphics pipeline Jim Blinn's Corner - A trip down the graphics pipeline。难得的稀有资料 立即下载

A trip through the Graphics Pipeline 2011, part 11

by fgiesen on August 14, 2011

Welcome back! This time, the focus is going to be on Stream-Out (SO). This is a facility for storing the Output of the Geometry Shader stage to memory, instead of sending it down the rest of the pipeline. This can be used to e.g. cache skinned vertex data, or as a sort of poor man’s Compute Shader on D3D10-level hardware using the D3D10 API (note that with D3D11, you can just use CS 4.0, even on D3D10 hardware). And just like the GS Instancing I mentioned last time, some of this is very poorly described in the API docs, so I’ll have a few comments about API usage even though it’s technically out of the intended scope of this series.

Vertex Shader Stream-Out (i.e. SO with NULL GS)

This is one of the features that’s not properly explained in the D3D10 (or D3D11, for that matter) docs; in fact, it’s not mentioned there at all except for a small throwaway remark in “Getting Started with the Stream-Output Stage (Direct3D 10)”. You’re supposed to figure it out from the examples – which themselves don’t exactly go out of their way to make it clear what’s going on. That’s a pity – VS Stream-Out is easier than GS SO, and has some pretty useful applications by itself (e.g. caching skinned vertices).

So here’s how it’s done in D3D10 and 11: You simply pass Vertex Shader bytecode (instead of GS bytecode) to CreateGeometryShaderWithStreamOutput. Yes, the docs mention something about “Size of the compiled geometry shader” here – ignore it. What you get back is a Geometry Shader object that you can then pass to GSSetShader. This is, in effect, a NULL Geometry Shader – it doesn’t actually go through GS processing. It’s just some wrapper (more like duct tape really) to make it fit into the API model, where all rendering passes through the GS stage and SO comes right after GS – though as I’ve explained last time, actual HW tends to skip the GS stage completely when there’s no GS set.

So the shaded vertices get assembled into primitives as before, but instead of getting sent down the rest of the pipeline as already described, they get forwarded to Stream-Out, where they arrive – as always – in a buffer. What exactly happens with them then depends on the Stream-Out declaration (which is passed at creation time). In the Stream-Out declaration, the app gets to specify where it wants each output vector to end up in the Stream-Out targets (or SO targets for short). If the SO declaration “matches” the Vertex Shader Output Declaration (i.e. the same attributes in the same order), data from the input buffers can be streamed more or less unprocessed into memory. If it doesn’t match the declaration exactly – it might skip some attributes written by the shader, or write them in a different order – either way, there’s some extra reordering involved. This might involve a dedicated reordering unit (which basically implements a gather-type operation from the SO input buffers), or it might involve generating lots of small memory writes instead of large burst writes, or something similar. Either way, it’s extra effort and generally slower; the details of what exactly triggers a slow path depend on the hardware specifics, but really, it doesn’t matter that much. If you want optimal SO performance, just make sure the SO declaration and Output declarations agree.

Another point is that SO usually doesn’t have access to a very high-performance path to the memory subsystem. Unlike e.g. the ROPs, SO isn’t really (yet?) a full citizen in current GPU designs, so it often only has access to one memory channel or something of the sort. That’s something to keep in mind if you’re producing a lot of data via SO. This is compounded by SO outputs always being full floats, so there’s no way to conserve bandwidth by using one of the packed vertex data types.

Final remark on VS SO: As I mentioned earlier, SO operates on assembled primitives, not individual vertices. Note that Primitive Assembly discards adjacency information if it makes it that far down the pipeline, and since this happens before SO, vertices corresponding to adjacency info won’t make it into SO buffers either. SO working on primitives not individual vertices is relevant for use cases like instancing a single skinned mesh (in a single pose) several times. If you were to draw your triangle mesh as you usually would and then use SO on that, this results in a data explosion – you get 3 unpacked, unshared vertices per input primitive. This works, but isn’t exactly an efficient use of bandwidth, both on the SO and the later vertex input side. Instead, you should draw your triangle mesh as a (non-indexed) point list in the first pass, thereby shading each vertex exactly once. The SO buffer then ends up in 1:1 correspondence to your original vertex buffer, only with skinned instead of non-skinned vertices. You can then use that vertex buffer with your original primitive topology and index buffer.

Geometry Shader SO: Multiple streams

This basically works like SO with a NULL GS, except there’s a Geometry Shader involved, which adds some new capabilities (and complications). In the VS case, we just had one output stream (note that streams are a D3D11+ feature – they don’t exist on D3D10-level HW). That stream could be sent to SO or not, and it could also be sent to down the pipeline to viewport/clip/cull or not, but that’s it. But Geometry Shaders allow multiple streams, which makes output routing a bit more difficult.

Basically, every GS can write to (as of D3D11) up to 4 streams. Each stream may be sent on to SO targets – yes, plural: a single stream can write to multiple SO targets, but a single SO target can receive values from only one stream, i.e. this is a one-to-many relationship, not a fully general many-to-many one. The presence of streams has some implications for SO buffering – instead of a single input buffer like I described in the NULL GS case, we now may have multiple input buffers, one per stream. In addition to SO targets, up to one stream may be sent down the pipe – i.e. the regular rendering pipeline and SO may be used simultaneously.

As in the NULL GS case, SO works on primitives, not individual vertices – that is, the strips you output in the GS get expanded out to full lines or triangles before they get into SO.

Tracking output size

There’s another issue here: we don’t necessarily know how much output data is going to be produced from SO. For GS, this comes about because each GS invocation may produce a variable number of output primitives; but even in the simpler VS case, as soon as indexed primitives are involved, the app might slip some “primitive cut” indices in there that influence how many primitives actually get written. This is a problem if we then want to draw from that SO buffer later, because we don’t know how many vertices are actually in there! We do have an upper bound – the maximum capacity of the buffer as created – but that’s it. Now, this could be resolved using some kind of query mechanism, but once you think it through, that seems fairly backwards: at the point we’re using the SO buffer for drawing, we obviously do know how many primitives we actually wrote – the SO unit needs to keep track of its current output position, after all! If we employed some query mechanism, we would end up transporting that single 32-bit value back over the bus to the driver, which passes it on to the API, which passes it on to the app – which then immediately dispatches another draw, going through all the layers again in the opposite direction.

So that’s now how it’s solved. Instead, there’s DrawAuto. The idea is very simple – the GPU already knows how many valid vertices it actually wrote to the output buffer; the SO unit keeps track of that while it’s writing, and the final counter is also kept in memory (along with the buffer) since the app may render to a SO buffer in multiple passes. This counter is then used for DrawAuto, instead of having the app submit an explicit count itself – simplifying things considerably and avoiding the costly round-trip completely. Note that this query mechanism does exist – both for checking the number of vertices written and to determine whether an overflow occurred. But it’s not on the critical path for rendering from SO buffers, which makes things a lot simpler for driver developers.

And that’s it for SO, really. Not really a lot of HW info in this one, and not really a super-interesting topic from a pipeline perspective, which is why it took me so long to finish; sorry about that. Next up is Tessellation – this should be a lot quicker, since it’s a fun topic :)

A trip through the Graphics Pipeline 2011 介绍图形管线的书籍,对想了解和学习图形管线的人有很大的帮助,可以了解图形管线的主要流程。 立即下载

相关推荐

Jim Blinn's Corner - A trip down the graphics pipeline.djvu电子书

Jim Blinn's Corner - A trip down the graphics 经典图形学书籍,很多基础的详解。

A trip through the Graphics Pipeline 2011, part 10

A trip through the Graphics Pipeline 2011, part 10 by fgiesen on July 20, 2011 Welcome back. Last time, we dove into bottom end of the pixel pipeline. This time, we’ll switch back to the midd

killcpp的专栏 1593

A trip through the Graphics Pipeline

Graphics Pipeline的详细描述。整理自国外牛人博客。

A trip through the Graphics Pipeline 2011_02

Welcome back. Last part was about vertex shaders, with some coverage of GPU shader units in general. Mostly, they’re just vector processors, but they have access to one resource that doesn’t exi...

weixin_34404393的博客 501

私彩视频开奖动画直播源码内部核心技术解析及修改可增加后台操控-持续更新文章!

其实在此很感谢能做出H5开奖系统的码农们,而我本人也喜欢分解此类的东西。 因为特殊原因,该东西本人就不做图片展示,以防他人商业化。 借用开奖摇奖代码首先分解首页index文件。代码如下:(后面持续在原有的作品上添加后台操作) 代码里写的//.....是我的注明代码的所需。 ​ <!DOCTYPE html> <html> <head> <...

yugua3837的博客 5995

RocketMQ 5.3.1 集成 Spring Boot 3.4.3 就这么简单

RocketMQ 是一个分布式消息中间件,支持发布/订阅模型,具有高吞吐量、高可用性和事务消息等特性。它广泛应用于日志处理、订单系统和异步任务等场景。Spring Boot 3.4.3 集成 RocketMQ 5.3.1 的过程异常简单,仅需少量配置即可实现消息的生产和消费。本文从环境搭建到代码实现,覆盖了核心步骤。

lssffy的博客 1385

[转] A trip through the Graphics Pipeline

转一个国外牛人的文章;深入浅出的介绍了现代GPU的方方面面,从软件到硬件都有。理解了这些对理解新一代图形API大有好处! 原文 A trip through the Graphics Pipeline 2011: Index A trip through the Graphics Pipeline 2011: Index

蓝天和白云的博客 8589

CODESYS安装全攻略:从下载到配置的保姆级教程(含常见问题解决)

本文提供了一份详细的CODESYS安装与配置指南,涵盖从系统环境准备、安装包下载、Development System安装到Runtime System配置的全过程。教程重点解决了安装过程中的常见权限、兼容性和连接问题,并指导用户完成第一个PLC程序的创建与调试,帮助工业自动化开发者快速上手这一通用开发平台。

kkk56的博客 420

A trip through the graphics pipeline 2011 Part 10(翻译)

之前的几篇翻译都烂尾了,这篇希望。。。。能好些,恩,还有往昔呢。 ------------------------------------------------------------- primitive 图元 tris  三角形 quad  栅格 -----------------------------------------------------------...

anfu8346的博客 263

Proxmox VE 9 更换源

创建一键更换Proxmox VE 9.0源的Bash脚本,实现快速替换软件源。脚本需包含订阅提醒关闭功能,兼容Proxmox VE 9.0系统,执行命令为bash /proxmox_9.0_Repo.sh。该工具可简化源配置过程,自动处理系统更新源替换及订阅提示屏蔽,适合需要快速配置Proxmox环境的用户使用。

极致,细节 4982

第 8 篇:TMC2240 电机正反转实现|DIR 引脚控制 + 代码优化(稳定不抖动)

本文详细介绍了TMC2240电机驱动芯片的正反转实现方法,重点解决方向切换时的抖动和冲击问题。文章首先明确了硬件连接、基础配置和使能状态三个前提条件,然后阐述了DIR引脚电平控制方向的核心原理,提供了STM32的GPIO配置代码。针对方向切换时的电流冲击问题,作者提出了"停止-延迟-切换-启动"的平滑切换逻辑,并给出了包含方向枚举、转速控制和方向切换函数的完整代码实现方案。通过这种优化方法,可以有效避免电机在正反转切换时产生的抖动、冲击声和发热问题,实现稳定的双向控制。文章还提示了后续可

BackCatK Chen的博客 2073

A trip through the Graphics Pipeline 2011, part 1

http://fgiesen.wordpress.com/2011/07/01/a-trip-through-the-graphics-pipeline-2011-part-1/ A trip through the Graphics Pipeline 2011, part 1 by fgiesen on July 1, 2011 It’s been awhile since

killcpp的专栏 1025

《YOLOv8:从入门到实战》专栏介绍 & 专栏目录

本专栏涵盖了丰富的YOLOv8算法从入门到实战系列教程,专为学习YOLOv8的同学而设计,堪称全网最详细的教程!🌈🌈🌈

小哥谈 6486

A trip through the Graphics Pipeline 2011, part 2

A trip through the Graphics Pipeline 2011, part 2 by fgiesen on July 2, 2011 Not so fast. In the previous part I explained the various stages that your 3D rendering commands go through on a P

killcpp的专栏 1104

[Python图像识别] 五十二.水书图像识别 (2)基于机器学习的濒危水书古文字识别研究

上一篇文章详细讲解如何利用数据增强方法实现图像数据集的扩充,并以濒危水书作为案例讲解。这篇文章将详细讲解基于机器学习的水书图像识别方法,以图像像素统计为特征开展图像分类讲解,这是最基础的方法,也为后续深度学习图像分类描述提供支撑。基础性文章,希望对您有所帮助!让我们开始吧,且看且珍惜。

杨秀璋的专栏 989

【Linux命令大全】006.网络通讯之write命令(实操篇)

Linux write命令摘要 write是Linux系统中用于用户间实时通讯的命令工具,允许向其他登录用户的终端发送消息。主要功能包括: 基本使用:通过write username向指定用户发送消息,Ctrl+D结束输入 终端指定:当用户登录多个终端时,可用write username tty指定目标终端 实用技巧: 使用who查看在线用户 通过管道发送单行消息:echo "内容" | write user 支持多行消息发送和简单聊天会话。

yuhuasheng1997的博客 213

A trip through the Graphics Pipeline 2011, part 8

A trip through the Graphics Pipeline 2011, part 8 by fgiesen on July 10, 2011 In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel shading. In fact

killcpp的专栏 871

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

A trip through the Graphics Pipeline 2011, part 13

A trip through the Graphics Pipeline 2011, part 13 by fgiesen Welcome back to what’s going to be the last “official” part of this series – I’ll do more GPU-related posts in the future, but th

killcpp的专栏 1074

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

A trip through the Graphics Pipeline 2011_13 Compute Shaders, UAV, atomic, structured buffer

Welcome back to what’s going to be the last “official” part of this series – I’ll do more GPU-related posts in the future, but this series is long enough already. We’ve been touring all the regular...

weixin_34024034的博客 341

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

A trip through the Graphics Pipeline 2011, part 9

A trip through the Graphics Pipeline 2011, part 9 by fgiesen on July 12, 2011 Welcome back! This post deals with the second half of pixel processing, the “join phase”. The previous phase was al

killcpp的专栏 767

A trip through the Graphics Pipeline 2011, part 3

A trip through the Graphics Pipeline 2011, part 3 by fgiesen on July 3, 2011 At this point, we’ve sent draw calls down from our app all the way through various driver layers and the command p

killcpp的专栏 783

A trip through the Graphics Pipeline 2011, part 12

A trip through the Graphics Pipeline 2011, part 12 by fgiesen on September 6, 2011 Welcome back! This time, we’ll look into what is perhaps the “poster boy” feature introduced with the D3D11 /

killcpp的专栏 918

A trip through the Graphics Pipeline 2011, part 4

A trip through the Graphics Pipeline 2011, part 4 by fgiesen on July 4, 2011 Welcome back. Last part was about vertex shaders, with some coverage of GPU shader units in general. Mostly, they’

killcpp的专栏 877

A trip through the Graphics Pipeline 2011, part 6

A trip through the Graphics Pipeline 2011, part 6 by fgiesen on July 6, 2011 Welcome back. This time we’re actually gonna see triangles being rasterized – finally! But before we can rasterize t

killcpp的专栏 646

A trip through the Graphics Pipeline 2011, part 7

A trip through the Graphics Pipeline 2011, part 7 by fgiesen on July 8, 2011 In this installment, I’ll be talking about the (early) Z pipeline and how it interacts with rasterization. Like

killcpp的专栏 936
上一篇: A trip through the Graphics Pipeline 2011, part 10
下一篇: A trip through the Graphics Pipeline 2011, part 12
killcpp
博客等级 码龄20年 13粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值