http://developer.nvidia.com/object/gpu_programming_guide.html
大量零散的coding tips:只是针对dx9的做些笔记
vertex processing
- indexed vertex buffer 最好nvstrip一下,可以有效提高post vertex cache hit rate
- vertex attribute什么的也是一个unit(vertex assembly),attribute多了(attribute/vertex or vertex number)也会bound
- 获取vertex输入的时候,gpu是一个clock里面获得attribute数量固定的,所以一个float4的attribute比一个float3+float这样的attribute要快。
- 必要的话,用uv从texture里读取vertex attribute
shaders
- 用尽可能高的shader model来编译----这个真没想到,原来的建议是用尽可能低的,不过现在的编译器进化到了尽可能高的最好
- prefer half to float----文中说用好了性能可以快3倍,以后就跟half哥混了,可以用/Gpp来使代码中的都变成half,用来测试性能很方便,
- 复杂的计算如果能用texture来lookup table是一个不错的选择
- 但是sincos,exp,log是内部指令,算起来刷刷的,就不用了。
- driver做unified shader资源的分配
- pixel shader calculation转到vertex shader中去的时候要考虑下post vertex cache,越多的attribute输出会导致cache效率越低
- vs输出attribute的时候很多不必要的pack需要避免,这样可以让compiler更好的来优化,attribute的效率在于scalar数量,也就是一个float4和2个float2是等量的,所以多余的pack不仅没有加速计算,反而给compiler制造麻烦
- 有内部库可用的时候就不要自己来写了
rasterization
- double speed z
- z cull
texture
- mipmap是好东西,少见的quality和performance都提高的好东西
- 做mipmap不要自己就直接box filter,用一些dx给的工具,gauss filter这一类的会让结果更棒
- 用的多的surface,rendertarget什么的,先allocate
降低cpu端的api性能消耗
api调的越少越好,基本都耳熟能详了:
- texture atlas
- instancing
- batching
- group shader constants setting
anti aliasing
CSAA很好,有机会用就用。
others:
- 8以下的gpu架构和feature截然不同,所以最好可以写多个方案,根据不同gpu来使用不同算法
- nv hardware shadow map
- DepthBoundTest, Geforece6系列以后都有这个东东在
- direct depth buffer access用一些特殊格式,可以直接访问depth buffer