简体   繁体   English

DirectX 9 HLSL与DirectX 10 HLSL:语法相同吗?

[英]DirectX 9 HLSL vs. DirectX 10 HLSL: syntax the same?

For the past month or so, I have been busting my behind trying to learn DirectX. 在过去一个月左右的时间里,我一直在努力学习DirectX。 So I've been mixing back back and forth between DirectX 9 and 10. One of the major changes I've seen in the two is how to process vectors in the graphics card. 所以我一直在DirectX 9和10之间来回混音。我在两者中看到的一个主要变化是如何在图形卡中处理矢量。

One of the drastic changes I notice is how you get the GPU to recognize your structs. 我注意到的一个重大变化是你如何让GPU识别你的结构。 In DirectX 9, you define the Flexible Vertex Formats. 在DirectX 9中,您可以定义灵活顶点格式。

Your typical set up would be like this: 您的典型设置如下:

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

In DirectX 10, I believe the equivalent is the input vertex description: 在DirectX 10中,我相信等效的是输入顶点描述:

D3D10_INPUT_ELEMENT_DESC layout[] = {
    {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT, 0 , 0,
        D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",0,DXGI_FORMAT_R32G32B32A32_FLOAT, 0 , 12,
        D3D10_INPUT_PER_VERTEX_DATA, 0}
};

I notice in DirectX 10 that it is more descriptive. 我在DirectX 10中注意到它更具描述性。 Besides this, what are some of the drastic changes made, and is the HLSL syntax the same for both? 除此之外,还有哪些重大变化,两者的HLSL语法是否相同?

I would say there's no radical changes in the HLSL syntax itself between DX9 and DX10 (and by extension DX11). 我想说在DX9和DX10(以及扩展DX11)之间的HLSL语法本身没有根本性的变化。

As codeka said, changes are more a matter of cleaning the API and a road toward generalization (for the sake of GPGPU). 正如codeka所说,变化更多的是清理API和走向泛化的道路(为了GPGPU)。 But there are indeed noticable differences: 但确实有明显的差异:

Noticable differences: 明显的差异:

  • To pass constant to the shaders, you now have to go through Constant Buffers. 要将常量传递给着色器,您现在必须通过Constant Buffers。

  • A Common-Shader Core: all types of shader have access to the same set of intrinsic functions (with some exceptions like for GS stage). 共同着色器核心:所有类型的着色器都可以访问同一组内部函数(有一些例外,如GS阶段)。 Integer and bitwise operations are now fully IEEE-compliant (and not emulated via floating point). 整数和按位运算现在完全符合IEEE标准(并且不通过浮点模拟)。 You have now access to binary casts to interpret an int as a float, a float as an uint etc.. 您现在可以访问二进制强制转换,将int解释为float,将float解释为uint等。

  • Textures and Samplers have been dissociated. 纹理和采样器已经分离。 You now use syntax g_myTexture.Sample( g_mySampler, texCoord ) instead of tex2D( g_mySampledTexture, texCoord ) 您现在使用语法g_myTexture.Sample( g_mySampler, texCoord )而不是tex2D( g_mySampledTexture, texCoord )

  • Buffers: a new kind of resource for accessing data that need no filtering in a random access way, using the new Object.Load function. 缓冲区:一种新的资源,用于访问不需要以随机访问方式进行过滤的数据,使用新的Object.Load函数。

  • System-Value Semantics: a generalization and extensions of POSITION , DEPTH , COLOR semantics, that are now SV_Position , SV_Depth , SV_Target and add of per stage new semantics like SV_InstanceID , SV_VertexId , etc. 系统值语义: POSITIONDEPTHCOLOR语义的泛化和扩展,现在是SV_PositionSV_DepthSV_Target和每级新语义的添加,如SV_InstanceIDSV_VertexId等。

That's all what I see for now. 这就是我现在所看到的一切。 If something new pops up of my mind I will update my answer. 如果有什么新东西突然出现,我会更新我的答案。

The biggest change I've noticed between DX9 and DX10 is the fact that under DX10 you need to set an entire renderstate block where in DX9 you could change individual states. 我在DX9和DX10之间注意到的最大变化是,在DX10下你需要设置一个整个渲染块,在DX9中你可以改变各个状态。 This broke my architecture somewhat because I was rather relying on being able to make a small change and leave all the rest of the states the same (This only really becomes a problem when you set states from a shader). 这在某种程度上打破了我的架构,因为我更依赖于能够进行一些小改动并使所有其他状态保持不变(当你从着色器设置状态时,这只会成为一个问题)。

The other big change is the fact that under DX10 vertex declarations are tied to a compiled shader (in CreateInputLayout). 另一个重大变化是DX10顶点声明与编译着色器(在CreateInputLayout中)相关联。 Under DX9 this wasn't the case. 在DX9下,情况并非如此。 You just set a declaration and set a shader. 您只需设置声明并设置着色器。 Under DX10 you need to create a shader then create an input layout attached to a given shader. 在DX10下,您需要创建着色器,然后创建附加到给定着色器的输入布局。

As codeka points out the D3DVERTEXELEMENT9 has been the recommended way to create shader signatures since DX9 was introduced. 正如codeka所指出的,D3DVERTEXELEMENT9一直是推出着色器签名的推荐方法,因为引入了DX9。 FVF was already depreciated and through FVF you are unable to do things like set up a tangent basis. FVF已经折旧,通过FVF,您无法执行设置切线基础的操作。 Vertex layours are far far more powerful and don't cause you to get fixed to a layout. 顶点铺设的功能远远强大,不会让您固定到布局。 You can put the vertex elements wherever you like. 您可以将顶点元素放在任何您喜欢的位置。

If you want to know more about DX9 input layouts then i suggest you start with MSDN . 如果您想了解有关DX9输入布局的更多信息,那么我建议您从MSDN开始。

FVFs were (kind-of) deprecated in favour of D3DVERTEXELEMENT9 (aka Vertex Declarations ) - which is remarkably similar to D3D10_INPUT_ELEMENT_DESC - anyway. FVF(有点)不赞成使用D3DVERTEXELEMENT9 (又名顶点声明 ) - 这与D3D10_INPUT_ELEMENT_DESC非常相似 - 无论如何。 In fact, most of what's in DirectX 10 is remarkably similar to what was in DirectX 9 minus the fixed-function pipeline . 实际上,DirectX 10中的大多数内容与DirectX 9中的内容非常相似,而不是固定功能管道

The biggest change between DirectX9 and DirectX10 was the cleaning up of the API (in terms of the separation of concerns, making it much clearer what goes with what stage of the pipeline, etc). DirectX9和DirectX10之间的最大变化是API的清理(在关注点的分离方面,使管道的哪个阶段更加清晰,等等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM