快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

ComputeShaders-创新互联

周一到周五,每天一篇,北京时间早上7点准时更新~

创新互联2013年开创至今,先为竞秀等服务建站,竞秀等地企业,进行企业商务咨询服务。为竞秀企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

The first sections of this chapter describe the graphics pipeline in OpenGL(本章的第一个部分描述了OpenGL的图形管线). However, OpenGL also includes the compute shader stage(OpenGL同样包含Compute Shader的阶段), which can almost be thought of as a separate pipeline that runs indepdendently of the other graphics-oriented stages(这个阶段独立的运行,不与其他绘图相关的渲染管线阶段有任何联系). Compute shaders are a way of getting at the computational power possessed by the graphics processor in the system(Compute shader的目的是为了让程序员得到图形显卡的计算能力). Unlike the graphics-centric vertex, tessellation, geometry, and fragment shaders, compute shaders could be considered as a special, single-stage pipeline all on their own(与其他shader不一样,compute shader可以被认为是一个单独的模块). Each compute shader operates on a single unit of work known as a work item(每个compute shader把每一个数据单元做为工作对象); these items are, in turn, collected together into small groups called local workgroups(那些工作对象被组织成为组,被叫做本地工作组). Collections of these workgroups can be sent into OpenGL’s compute pipeline to be processed(大量的这样的本地工作组可以被发送给OpenGL的compute shader处理阶段进行处理). The compute shader doesn’t have any fixed inputs or outputs besides a handful of built-in variables to tell the shader which item it is working on(除了一些用于告诉shader它的工作对象的一些内置的控制变量以外,这个shader没有任何固定的输入和输出的数据). All processing performed by a compute shader is explicitly written to memory by the shader itself, rather than being consumed by a subsequent pipeline stage(任何被显示写入内存的数据都是shader它自己完成的,而不是像其他shader一样,输出数据会被当成后面渲染阶段的输入). A very basic compute shader is shown in Listing 3.13 (Listing3.13展示了一个基本的compute shader)

#version 450 core
layout (local_size_x = 32, local_size_y = 32) in;
void main(void)
{
// Do nothing
}
Listing 3.13: Simple do-nothing compute shader

Compute shaders are otherwise just like any other shader stage in OpenGL(compute shaders就像是其他shader一样). To compile one, you create a shader object with the type GL_COMPUTE_SHADER, attach yourGLSL source code to it with glShaderSource(), compile it with glCompileShader(), and then link it into a program with glAttachShader() and glLinkProgram()(你需要先创建shader、然后attach它给一个shader source,然后编译它,链接成为GPU程序). The result is a program object with a compiled compute shader in it that can be launched to do work for you(编译好了之后,就可以用于进行大规模的并行运算了)

The shader in Listing 3.13 tells OpenGL that the size of the local workgroup will be 32 by 32 work items, but then proceeds to do nothing(Listing3.13中的代码告诉OpenGL本地工作组的大小是32x32,然而这个shader啥都没做). To create a compute shader that actually does something useful, you need to know a bit more about OpenGL—so we’ll revisit this topic later in the book(为了创建一个compute shader并干点什么,你必须先了解以下OpenGL,所以我们将在后面的内容中再来讨论这个话题)

本日的翻译就到这里,明天见,拜拜~~

第一时间获取最新桥段,请关注东汉书院以及图形之心公众号

东汉书院,等你来玩哦

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


标题名称:ComputeShaders-创新互联
当前链接:http://6mz.cn/article/cdjshh.html

其他资讯