2013-07-29 32 views
1

当我设置一个字节4作为位置语义的顶点声明,并在着色器我用的是页免费为相应的数据类型(因为没有字节4)会发生什么。HLSL顶点声明语义问题

uint4测试:POSITION0;

,什么会发生在这里,具有浮动?

个float4色调:POSTION0;

回答

2

uint4是正确的。

无论顶点缓冲数据是8位,16位还是32位整数,数据都将转换为32位整数。对于浮点数也是如此,着色器在32位浮点数中进行处理(除非使用double类型),并且任何输入数据都从其基础格式转换而来。

但是你不能做的是从整数和浮点数转换为获取顶点缓冲区的一部分。获得数据后,您可以自由地在浮点数和整数之间进行转换,但输入属性类型(uint或float)必须与输入布局中指定的DXGI_FORMAT匹配。如果您尝试将输入声明为float4,那么它实际上是一个uint4,您将收到类似下面的警告:

D3D11 WARNING: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'POSITION'/0 and component(s) of the type 'float32'. However, the matching entry in the Input Layout declaration, element[0], specifies mismatched format: 'R8G8B8A8_UINT'. This is not an error, since behavior is well defined: The element format determines what data conversion algorithm gets applied before it shows up in a shader register. Independently, the shader input signature defines how the shader will interpret the data that has been placed in its input registers, with no change in the bits stored. It is valid for the application to reinterpret data as a different type once it is in the vertex shader, so this warning is issued just in case reinterpretation was not intended by the author. [ STATE_CREATION WARNING #391: CREATEINPUTLAYOUT_TYPE_MISMATCH]