In my cross-renderer I have a function that sets shader's constant:
inline void CRenderer::setVertexShaderConstant_ogl_d3d9(const string& name, const mtx& m)
{
#ifdef RENDERER_OGL
if (!currentShaderProgram->setMatrix(name, m))
{
SAFE_CALL(Renderer_outputMessageFunction)(string("WARNING: There is no uniform with given name or it's not used in the shader"));
SAFE_CALL(Renderer_outputMessageFunction)("\tVertex shader: " + currentVertexShader->name);
SAFE_CALL(Renderer_outputMessageFunction)("\tUniform name: " + name);
}
#elif RENDERER_D3D9
currentVertexShader->constantTable.setMatrix(D3D9Device, name, m);
#endif
}
Now, in my rendering loop I call this function:
renderer.setVertexShaderConstant_ogl_d3d9("worldTransform", worldTransform);
renderer.setVertexShaderConstant_ogl_d3d9("viewProjTransform", viewProjTransform);
It works fine. The problem is that when I switch to D3D10 renderer (whose source is empty in this function) VC++ generates some redundant code for it.
This is assembly when these two lines are commented out:
; 210 : // renderer.setVertexShaderConstant_ogl_d3d9("worldTransform", worldTransform);
; 211 : // renderer.setVertexShaderConstant_ogl_d3d9("viewProjTransform", viewProjTransform);
And the assembly when these two functions are called:
; 210 : renderer.setVertexShaderConstant_ogl_d3d9("worldTransform", worldTransform);
push OFFSET ??_C@_0P@KOAAPGHC@worldTransform?$AA@
lea ecx, DWORD PTR $T190163[esp+392]
call DWORD PTR __imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z
lea ecx, DWORD PTR $T190163[esp+388]
call DWORD PTR __imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ
; 211 : renderer.setVertexShaderConstant_ogl_d3d9("viewProjTransform", viewProjTransform);
push OFFSET ??_C@_0BC@FADNJIOD@viewProjTransform?$AA@
lea ecx, DWORD PTR $T190164[esp+392]
call DWORD PTR __imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z
lea ecx, DWORD PTR $T190164[esp+388]
call DWORD PTR __imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ
My intuition would be that if the function is empty for D3D10 renderer and it is inline, the compiler will simply skip it, but it doesn't. Any idea why?