DirectX 9 HLSL与DirectX 10 HLSL:语法相同? [英] DirectX 9 HLSL vs. DirectX 10 HLSL: syntax the same?

查看:600
本文介绍了DirectX 9 HLSL与DirectX 10 HLSL:语法相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去一个月左右,我一直在努力学习DirectX。所以我一直在DirectX 9和10之间来回混合。我看到的两个主要变化之一是如何处理图形卡中的向量。



我注意到的一个重大变化是如何让GPU识别你的结构。在DirectX 9中,您定义了灵活的顶点格式。



您的典型设置如下:

  #define CUSTOMFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

我相信等效的输入顶点描述:

  D3D10_INPUT_ELEMENT_DESC布局[] = {
{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}
};



我注意到在DirectX 10它更具描述性。除此之外,什么是一些剧烈的变化,是HLSL语法是一样的?

解决方案

在DX9和DX10(和扩展名DX11)之间的HLSL语法本身没有根本的变化。



Codeka说,更改更多的是清理API和向通用化的道路(为了GPGPU)。但确实存在明显的区别:



显着差异




  • 要将常量传递给着色器,您
    现在必须通过常量缓冲区。


  • < :所有类型的
    着色器都可以访问同一组
    固有函数(有一些例外,例如GS阶段)。整数和逐位操作现在完全符合IEEE标准(而不是通过浮点模拟)。您现在可以访问二进制转换,将int解释为float,float作为uint等。


  • 纹理和取样器已解离。现在使用 g_myTexture.Sample(g_mySampler,texCoord)
    而不是 tex2D(g_mySampledTexture,texCoord)


  • 缓冲区:一种新型资源,用于访问不需要以随机访问方式进行过滤的数据,使用新的 Object.Load


  • 系统价值语义: POSITION的扩展和扩展 DEPTH COLOR 语义,现在 SV_Position SV_Depth SV_Target 并添加每个阶段的新语义如 SV_InstanceID SV_VertexId 等。




我现在看到了。如果有新的东西出现,我会更新我的答案。


For the past month or so, I have been busting my behind trying to learn 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.

One of the drastic changes I notice is how you get the GPU to recognize your structs. In DirectX 9, you define the Flexible Vertex Formats.

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:

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. Besides this, what are some of the drastic changes made, and is the HLSL syntax the same for both?

解决方案

I would say there's no radical changes in the HLSL syntax itself between DX9 and DX10 (and by extension DX11).

As codeka said, changes are more a matter of cleaning the API and a road toward generalization (for the sake of GPGPU). But there are indeed noticable differences:

Noticable differences:

  • To pass constant to the shaders, you now have to go through 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). Integer and bitwise operations are now fully IEEE-compliant (and not emulated via floating point). You have now access to binary casts to interpret an int as a float, a float as an uint etc..

  • Textures and Samplers have been dissociated. You now use syntax g_myTexture.Sample( g_mySampler, texCoord ) instead of 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.

  • 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.

That's all what I see for now. If something new pops up of my mind I will update my answer.

这篇关于DirectX 9 HLSL与DirectX 10 HLSL:语法相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆