Sign in to follow this  
chema

How does exactly semantic mapping work between ps and vs?

Recommended Posts

chema    122
Hello, I'm studying the data flow between the vertex shader and pixel shader in shader model 3.0 to model it in a GPU simulator. Reading directx sdk docs it seems that vs declares semantics for its output and ps declares semantics for its input. Then the vs output registers are paired with the ps input registers that have the same semantics. Sdk docs also talk about packing semantics, but for now I will forget this. According to that this code is legal (it compiles as well): Vertex shader
vs_3_0
dcl_normal0 v0
dcl_normal1 v1
dcl_color0 v2
dcl_color1 v3
dcl_position v4

dcl_normal0 o0
dcl_normal1 o1
dcl_color0  o2
dcl_color1  o3
dcl_position o4

mov o0, v0
mov o1, v1
mov o2, v2
mov o3, v3
mov o4, v4


Pixel shader
ps_3_0

dcl_color0 v0
dcl_normal0 v1
dcl_color1 v2
dcl_normal1 v3

def c0, 0.0f, 0.0f, 0.0f, 0.0f
def c1, 1.0f, 1.0f, 1.0f, 1.0f

mov r0, c0
add r0, r0, v0
add r0, r0, v1
mov r1, c1
mul r1, r1, v2
mul r1, r1, v3
mul oC0, r0, r1


The mapping seems to be:
VS     Semantic   PS
o0-----Normal0----v1
o1-----Normal0----v3
o2-----Color0-----v0
o3-----Color1-----v2
This it what I think reading SDK docs, but when I go for real world examples everybody seems to use Texcoord# semantics to pass data for VS output to PS input. The questions are: Are this pixel-vertex shaders legal? Have I interpreted the data flow correctly? Why can't I find any example of this kind of data flow? Why everybody uses Texcoord#? Any kind of help/orientation will be very appreciated.

Share this post


Link to post
Share on other sites
ET3D    810
I imagine that the main reason you don't see this is that texture coord semantics are compatible with all shader models, and therefore a better choice if you're not writing exclusively for SM3.

Share this post


Link to post
Share on other sites
chema    122
Yes, it seems a good reason to stick to texture coords, everybody seems to use it. Thank you.

This leaves my first question. In the case someone decide not to use texture coords semantics exclusively...Have I understand how the data flow should work?

Share this post


Link to post
Share on other sites
ET3D    810
It looks correct to me, but frankly I'm only using HLSL. You should have no problem trying it, though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this