周一到周五,每天一篇,北京時間早上7點準時更新~
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為競秀等服務建站,競秀等地企業(yè),進行企業(yè)商務咨詢服務。為競秀企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務解決您的所有建站問題。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(這個階段獨立的運行,不與其他繪圖相關的渲染管線階段有任何聯(lián)系). 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把每一個數(shù)據(jù)單元做為工作對象); 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(大量的這樣的本地工作組可以被發(fā)送給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沒有任何固定的輸入和輸出的數(shù)據(jù)). 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(任何被顯示寫入內存的數(shù)據(jù)都是shader它自己完成的,而不是像其他shader一樣,輸出數(shù)據(jù)會被當成后面渲染階段的輸入). 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()(你需要先創(chuàng)建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(編譯好了之后,就可以用于進行大規(guī)模的并行運算了)
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(為了創(chuàng)建一個compute shader并干點什么,你必須先了解以下OpenGL,所以我們將在后面的內容中再來討論這個話題)
本日的翻譯就到這里,明天見,拜拜~~
第一時間獲取最新橋段,請關注東漢書院以及圖形之心公眾號
東漢書院,等你來玩哦
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。