Microsoft provides a list explaining the input and output semantics of vertex and pixel shaders. By now I've seen some code examples that don't use the documented data types. They are using float3
as input COLOR
to the pixel shader or float2
as input POSITION
to the vertex shader. Even though a 2-component position or a 3-component color do make sense to me, I can't find this documented, which makes me wonder
Can I use float3
as vertex shader input POSITION
(if I know I won't be using the W component) without expecting errors?
If I can use data types other than the documented ones, is there a list available that shows every allowed data type for a semantic or a rule like "As long as the used data type is smaller or equally sized as the documented one, you can use it"?
Code examples not following the documentation:
StackOverflow - Passing colors through a pixel shader in HLSL
C++ / DirectX11 Tutorials - S02E05 - Creating and loading Shaders at 9:33
In shader model 4.0 and later (DX10+), the only semantic names that matter are system-value semantics (those prefixed by SV_
). Other semantics have no special treatment aside from being used to match shader parameters to their inputs. The documentation regarding semantics such as COLOR
being float4
is purely convention, or legacy from DX9. In DX10/SM4+, there's nothing stopping you from declaring COLOR
as a float2
, or deciding to use UNICORN
as the semantic name for your colors, though don't be surprised if this confuses other developers (or yourself) reviewing the code in the future.
To answer your specific question, yes you can use any data type you want for non-SV_
semantics, or even invent your own names. Just make sure you use consistent naming and channel counts between stages and input layout declaration.