1

What happens when I set a byte4 as the vertex declaration in the POSITION semantic, and in the shader I use the unit4 as the corresponding data type (because there is no byte4).

uint4 Test : POSITION0;

and what would happen here, with a float?

float4 Tint : POSTION0;

4

1 回答 1

2

uint4 is correct.

The data will be converted into 32 bit integer irrespective of whether the vertex buffer data was 8 bit, 16 bit or 32bit integer. The same goes for floats, the shader deals in 32 bit floats (unless you use the double type) and any input data gets converted from its underlying format.

What you can't do however is convert from integer and float as part of fetching the vertex buffer. You're free to convert between float and integer once you've got the data, but the input attribute type (uint or float) must match the DXGI_FORMAT specified in the input layout. If you try declaring the input as a float4 when it's actually a uint4 you'll get a warning similar to this one:

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]
于 2013-07-29T23:06:02.293 回答