欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

go語言Vulkan,Go語言面試題

Vulkan 內(nèi)存管理

內(nèi)存管理對開發(fā)者來說永遠是一個沉重的話題。

創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、雙橋網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5建站商城系統(tǒng)網(wǎng)站開發(fā)、集團公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為雙橋等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

現(xiàn)有的高級語言都在通過各種努力試圖讓開發(fā)者擺脫內(nèi)存管理的復(fù)雜工作,專注于業(yè)務(wù)邏輯的開發(fā)。這樣的做法對開發(fā)者是友好的,較低的語言門檻也能適應(yīng)當(dāng)前越來越快的敏捷開發(fā)的節(jié)奏。

但是,世上沒有免費的午餐,任何事情都有代價。除了應(yīng)用,沒人更清楚應(yīng)用的行為,有些應(yīng)用需要大量的小內(nèi)存,有些應(yīng)用只需要少量的大內(nèi)存,有些應(yīng)用會頻繁釋放和分頻內(nèi)存資源,有些應(yīng)用的內(nèi)存生命周期則很長。面對復(fù)雜的應(yīng)用場景,我們很難有一個統(tǒng)一的策略可以解決所有問題。不管是通過虛擬機還是驅(qū)動程序,幫助應(yīng)用進行內(nèi)存管理永遠是低效的。

Vulkan將內(nèi)存管理的工作交給了開發(fā)者自己負責(zé),如何分配釋放內(nèi)存,怎樣制定內(nèi)存策略都由開發(fā)者自己決定,因為沒人比開發(fā)者更清楚自己想做什么。

Vulkan將內(nèi)存劃分為兩大類: Host Memory 和 Device Memory 。

Host是運行應(yīng)用程序的處理器,在PC機上就是指CPU。

Device是執(zhí)行Vulkan命令的處理器,在PC機上就是指GPU。

所以,Host memory指的是對Host可見的內(nèi)存,Device memory指的是對Device可見的內(nèi)存。

更詳細的,Vulkan系統(tǒng)中的內(nèi)存有四種類型:

并不是所有設(shè)備都支持這四種類型。一些嵌入式系統(tǒng)、移動設(shè)備甚至是筆記本電腦的GPU,可能與CPU共享內(nèi)存控制器和內(nèi)存子系統(tǒng)。這種情況它的內(nèi)存只有一種類型,我們通常稱之為 unified memory architecture (統(tǒng)一內(nèi)存架構(gòu))。

Host Memory是CPU可以訪問的常規(guī)內(nèi)存,一般是通過調(diào)用malloc或new分配。

Vulkan API創(chuàng)建的對象通常需要一定數(shù)量的Host Memory,用來儲存對象和數(shù)據(jù)結(jié)構(gòu)。

Vulkan對Host Memory的要求就是內(nèi)存地址是對齊的!

這是因為某些高性能CPU指令在對齊的內(nèi)存地址上效果最佳。通過假定存儲CPU端數(shù)據(jù)結(jié)構(gòu)的分配是對齊的,Vulkan可以無條件使用這些高性能指令,從而提供顯著的性能優(yōu)勢。

如果內(nèi)存沒有對齊,你可能會發(fā)現(xiàn)程序運行一段時間后神秘崩潰!

任何可以由Device訪問的內(nèi)存,都被稱為Device Memory(設(shè)備內(nèi)存)。Device Memory距離Device更近,比Host Memory更有性能優(yōu)勢。Image object、Buffer object、UBO(uniform buffer objec)都由Device Memory分配。Vulkan中的所有資源都由Device Memory支持。

內(nèi)存是一種昂貴的資源,分配操作通常會有間接的系統(tǒng)代價。

Vulkan中通過資源池來平攤成本,一些創(chuàng)建比較頻繁的資源都由資源池統(tǒng)一管理:

內(nèi)存的作用是給資源做底層支持,不同的資源對內(nèi)存的要求并不一樣。

Vulkan有兩種基本資源類型:Buffer和Image。

Buffer 是最簡單的資源類型,可以用來儲存線性的結(jié)構(gòu)化的數(shù)據(jù),也可以儲存內(nèi)存中原始字節(jié)。

Image 則相對比較復(fù)雜,具有特殊的布局(layout)和格式(format),可用來做flitering,blending,depth 和 stencil testing等。

Image的布局(layout)對內(nèi)存有特殊需求,主要有兩種主要的平鋪模式(tiling modes):

線性布局(linear layout)適合連續(xù)的單行的讀寫,但是大多數(shù)圖形操作都涉及在跨行讀寫紋理元素(比如在計算A時,需要參考ABCD四個紋理像素),如果圖像的寬度非常寬,相鄰行的訪問在線性布局中會有非常大的跳轉(zhuǎn)。這可能會導(dǎo)致性能問題。

優(yōu)化布局(optimal layout)的好處是內(nèi)存數(shù)據(jù)根據(jù)不同內(nèi)存子系統(tǒng)進行優(yōu)化,比如將所有的紋理像素都優(yōu)化到一塊連續(xù)的內(nèi)存區(qū)域中,加快內(nèi)存處理速度。

GPU硬件通常傾向于使用優(yōu)化布局以實現(xiàn)更有效的渲染。但是優(yōu)化布局(optimal layout)通常是“不透明的”,這意味著優(yōu)化布局格式的詳細信息不會被其他需要讀取或?qū)懭雸D像數(shù)據(jù)的組件得知。

如果CPU如果想讀取生層的圖像信息,圖像在被讀取之前要進行布局轉(zhuǎn)換,將optimal layout轉(zhuǎn)換為普通布局后,CPU才能正確識別圖像信息。

Vulkan不同的內(nèi)存類型有不同的使用場景:

在Vulkan中,我們在進行內(nèi)存管理時要考慮到以下問題:

在使用Host Memory時,一定要注意內(nèi)存對齊。不允許簡單的直接把malloc hook到Vulkan的內(nèi)存分配函數(shù)上!

參考文檔:

如何選擇Unity 3d Shader編寫語言

What language

should I study for making shaders in Unity3d?

Yesterday I said Cg/HLSL was the best choice for writing

shaders in Unity. A couple of other interesting opinions came out so I did a

bit of reading before making this reply.

Metal API:

Others said that Metal API is the future for iOS. That’s great for you if you

don’t care about Android, PC, Xbox, PS, etc, etc. Anyway, Unity3d doesn’t

support writing in Metal and they said they have no intention to support it in

the near future. They only have support for automatic compiling into Metal API,

so you don’t really get much control over it. So it’s not a choice for a Unity

developer to start learning.

Vulkan:

Somebody said this is the future. Maybe. It’s made from a dead language called

Mantle developed by AMD, which only had a few games ever using it. They took

some ideas from Apple’s Metal and improved it, so people say. Apparently Vulkan

was announced in GDC 2015, but I didn’t see or hear it anywhere. Even if it is

the future, it is a far and distant uncertain future. Vulkan sounds nice, like

a dream come true in some ways, but it isn’t even released yet. Only Valve company

has used it. Do you work at Valve? Does your boss want to support this

technology yet? Too many questions. Plus, John Carmack hinted that Android

might have a similar kinda of Metal API of their own soon, so GPUs of Android

devices might not even need to adopt it. Well, when you consider everything

there is just too much questions surrounding this, too much unknown. In any

case, it’s not a choice for Unity at the moment.

GLSL: You can

write in GLSL in Unity now. Unity will compile this code to whatever platform

you like, though you may have to “-force-opengl” on a PC (or any non iOS/Apple)

device to get it to work properly. That will cause the Unity Profiler to be

unable to profile correctly on some GPUs of certain video cards. I’d love to

know if it’s possible to get around this. So, if you use a Mac and everyone in

your team uses a Mac, then sure you should probably use GLSL –it’s the logical

choice.

Surface Shaders:

You can use Unity shaderlab to do some cool stuff, but it won’t be very

efficient for mobile. Shaderlab is like a simplified and more humanly-readable

markup language, but you lose the control and performance options that you need

for mobile games. Since most of the jobs in China will be for making mobile

games, I don’t recommend it.

Cg/HLSL: Some

people said that Cg was a dead language. Well, the fact is that Cg and HLSL are

the same language which is maintained by two different companies, NVidia and

Microsoft. Now Nividia has stopped supporting Cg because there is no need since

Microsoft supports HLSL. People still use the name Cg, but hope nobody gets

confused about it. Cg/HLSL is certainly not dead, and after talking to several

high ups and forum veterans over at Unity, they all think that HLSL is the

future of shader writing in Unity because the company is doing a lot of console

and AAA promotion. Just look at Unity5 features and you will get my meaning.

Cg/HLSL can be compiled to any device you need and since Unity and Microsoft

seem like great friends now, I don’t think this is going to change.

Conclusion:

If you want to use Unity3d and make games for Windows,

Consoles, Android, and iOS, with decent performance on all platforms, you

should use Cg/HLSL.

If you want to use Unity3d and make games for mobile only

(don’t need to support Windows or Consoles), GLSL is a good choice, especially

if you work on Apple Macs.

If you don’t want to use Unity3d and only want to develop

for the newest iOS devices, then Metal is the best, though very few people in

China are using it right now.

If you want to use cocos2d, I am not the expert for

advice, but friends say GLSL is your best choice.

However, also, but, maybe…. In China, the dominant art

style is hand-painted stuff. This doesn’t require very deep shader knowledge,

and is very little work for an experienced guy to achieve. Shader coding is

mainly for trying to go beyond current gen graphics, or create specific

effects, or to get around some graphical issues. So you have to think about if

it’s worth to study, because many kinds of games may not need this.

非常感謝知友@王邢敏 的翻譯,他的微博:One Double()

昨天我說過,在Unity里寫shader,Cg/ HLSL是最佳選擇。后來冒出了幾個很有意思的觀點,所以我特意查閱了一下資料再來回復(fù)。

Metal API:有人說,Metal API是iOS的未來。如果你完全不關(guān)心Android,PC,Xbox,PS等平臺,那么你的確可以奉之為圭臬。反正,Unity3d 是不支持用Metal寫的,而且他們說近期也沒有要去支持Metal的打算。他們只支持自動編譯成Metal API,但這樣你能控制的就很少。因此,這不是一個Unity開發(fā)者入門的選擇。

Vulkan:有人說這才是未來。大概吧。AMD開發(fā)過一個叫做Mantle 的語言,只有很少的幾個游戲用過它,然后它還死了,現(xiàn)在有人用它搞出了這個。人們說他們從蘋果公司的Metal借鑒了一些理念,用之以完善Vulkan。很顯然,Vulkan是在2015年GDC公布的,但我沒有在其他任何地方聽說或看到。即使它真是未來,那也是一個遠到不著邊際的未來。Vulkan 聽起來不錯,像是某種方式的夢想成真,但它甚至沒有發(fā)行。只有Valve公司用過它。什么?你在Valve工作?你的上司是要支持這個技術(shù)了嗎?太多問題了。此外,約翰·卡馬克暗示Android可能不久會有一個類似Metal API的東西,所以Android設(shè)備的GPU甚至不需要接受它。那么,當(dāng)你考慮所有事情時,就是有太多的問題圍繞著它,太多的未知。無論如何,它不是Unity當(dāng)下的選擇。

GLSL:現(xiàn)在你可以在Unity里寫GLSL了。Unity會將這段代碼編譯到任何平臺,雖然你可能要在PC(或任何非iOS / Apple設(shè)備)上執(zhí)行“-force-opengl”,以使之正常工作。那會導(dǎo)致在某些顯卡GPU上,Unity Profiler不能正確地執(zhí)行配置。我很想知道,是否有可能解決這問題。所以,如果你用著Mac,團隊里人人用著Mac,那么相信你應(yīng)該使用GLSL- 絕對是明智之選。

Surface Shaders:你可以用Unity shader庫做些很酷的東西,但它不一定會在移動設(shè)備上有效果。 Shader庫就像一個簡化的,更易于閱讀的標(biāo)記語言,但你失去了你手機游戲需要的控制和性能選項。鑒于大多數(shù)在中國的工作是做手游,我不推薦這樣做。

Cg/HLSL:有人說,Cg是死的語言。那么,事實是,Cg和HLSL是同一個語言,只是由兩個不同的公司,NVIDIA 和Microsoft分別維護。現(xiàn)在NIVIDIA已停止支持Cg,沒有必要啊是不,反正Microsoft在維護HLSL。人們?nèi)匀皇褂弥鳦g的名字,但愿沒有人對此困惑了。 Cg/ HLSL當(dāng)然沒有死,在跟幾個大牛以及論壇老兵聊過Unity,他們都認為HLSL是Unity shader的未來,因為公司為游戲機做了很多,為3A級提升了許多。只要看看Unity5的特性,你會懂我意思了。Cg/HLSL可以被編譯到你需要的任何設(shè)備,同時Unity和微軟已經(jīng)親密得像兄弟一樣,并且將一直親密下去直到地老天荒。

為什么安裝不上vulkan語言庫

若使用的是vivo手機,可進入應(yīng)用商店搜索安裝“安兔兔評測”軟件,打開安兔兔評測,首頁,選擇我的手機,進入硬件配置,上滑界面即可查看手機是否支持Vulkan及Vulkan版本。

電腦顯卡型號可在MuMu模擬器右上角-三條杠-幫助中心-問題診斷-所有顯卡中查看到。可能是最新版本或較老版本的N卡驅(qū)動不兼容導(dǎo)致,可以通過回退或更新顯卡驅(qū)動解決,比如472以上版本。

本文標(biāo)題:go語言Vulkan,Go語言面試題
轉(zhuǎn)載來于:http://chinadenli.net/article14/hedide.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站網(wǎng)站收錄標(biāo)簽優(yōu)化網(wǎng)站建設(shè)小程序開發(fā)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)