SetFloat() in HLSL shader (effect) has no effect - variables stay at 0

I have a problem wherein I'm trying to set two simple float variables in my shader. I have a dozen other shaders in this project where it works fine, but for some reason, I've got a bug in this one that I just can't spot.

Here's what I'm doing; I'll edit it down for brevity but try to stay complete. Any suggestions are very welcome!

First, I store the video width and height in the class that represents my shader, and then call functions that set the variables.

    _hVideoWidth           = _ptrEffect->GetParameterByName(0, "videoWidth");
_hVideoHeight          = _ptrEffect->GetParameterByName(0, "videoHeight");

_ptrEffect->SetFloat(_hVideoWidth,  _videoWidth);
_ptrEffect->SetFloat(_hVideoHeight, _videoHeight);


Then I do my drawing:

    UINT cPasses;
// Drawing code here


My shader will use the videoHeight/Width in order to scale it to the viewport. If I hardcode the width and height, it all works perfectly.

cbuffer VideoData : register(b0)
{
float    videoWidth;
float    videoHeight;
}

{

output.Position = input.Position;

// Convert pixel coords to (-1, +1)

output.Position.x = output.Position.x / videoWidth  * 2.0f - 1.0f;
output.Position.y = output.Position.y / videoHeight * 2.0f - 1.0f;
output.Color    = input.Color;

return output;
}


The mystery, however, is that at this point the shader has videoWidth and videoHeight still as zero. If I just hardcode those two expressions to 1280 and 1024 respectively, it works perfectly.

So, there's SOMETHING about the way I'm setting the videoWidth and videoHeight. I've confirmed that at the point I call SetFloat() they are in fact passing in the right values, but they just never seem to make it to the shader variables.

Any suggestions or anything obvious? Even a guess would help, I've been looking at this one for a while!

Thanks, Dave

• Your question is tagged directx9 and it looks like you're using the DX9 effect interface, but your HLSL has a constant buffer which is a DX10+ feature? I'm confused. And really surprised that you're not getting tons of errors either when compiling or loading the shader. – Nathan Reed Feb 9 '14 at 2:47
• The HLSL is compiled with Shader Model 2.0 and (the other shaders in the project) works perfectly with the rest of the code (DX9). I have cbuffer sections in all the other shaders, and have tried this with and without them at global scope or a cbuffer, no difference unfortunately. – Dave Feb 9 '14 at 20:42
• You show how you're calling Begin() and End(), but are you also calling BeginPass() and EndPass()? – Nathan Reed Feb 9 '14 at 22:11
• Nathan - you are correct. I just figured it out and came back to update the question with the answer, but since you came up with it if you'd like to post it as the answer (instead of a comment) I'll accept it! – Dave Feb 9 '14 at 22:37

Besides calling Begin() and End() around the draw calls, you have to also call BeginPass() and EndPass() for the effect system to set up all the shader parameters and state.