I've been researching a game's engine for the last few months and after extracting the DX9 bytecode, have begun examining the game's shaders. I mainly worked with OpenGL so some of the syntax or way of doing things is new to me.
Anyway, this is a 5x5 gaussian blur pixel shader (3.0). Can anyone explain what is going on with the texture coords declaration? Does this mean 4 coordinates are being sent into the pixel shader? Or is the same texture coordinate being reused?
def c0, 0.120259, 0.162103, 0.089216, 0.000000
dcl_texcoord0 v0.xy
dcl_texcoord1 v1
dcl_texcoord2 v2
dcl_texcoord3 v3
dcl_texcoord4 v4
dcl_2d s0
tex_pp r0, v1.zwzw, s0
mul r0, r0, c0.x
tex_pp r1, v1, s0
mad_pp r0, r1, c0.y, r0
tex_pp r1, v2, s0
mad_pp r0, r1, c0.x, r0
tex_pp r1, v2.zwzw, s0
mad_pp r0, r1, c0.x, r0
tex_pp r1, v3, s0
mad_pp r0, r1, c0.x, r0
tex_pp r1, v3.zwzw, s0
mad_pp r0, r1, c0.z, r0
tex_pp r1, v4, s0
mad_pp r0, r1, c0.z, r0
tex_pp r1, v4.zwzw, s0
mad_pp r0, r1, c0.z, r0
tex_pp r1, v0, s0
mad_pp oC0, r1, c0.z, r0
end
The dcl_texcoord
ASM instruction declares a register that contains data. For a pixel shader in D3D9, this data would be written in the vertex stage. So, yes, in this shader there are in fact 5 sets of texture coordinates in use (0..4). The first coordinate only uses the two first components, which is why is declared with those explicitly (this reduces the bandwidth required between the stages). The other four do additional samples with the upper two components as well, so the shader samples in 9 times total.