Global Variable and Register don't connect in HLSL

I define this gloabal variable in my Shader fx file:

float MyTime : register(c0);

And my pixel shader (in asm format in my fx file) I use the c0 register

I thought I could Set the value of MyTime in my cpp code and that the c0
register would use that value...but apparently it's not working

Now I use a workaround and use dlc t0.x to use the vertex shader output texture

But what is wrong with the register(c0) that when I set this global value the asm code don't use it...is there something else I have to do

How do you send info to a register from the cpp code

How do the pixel shader read global variable (can they do this )



Answer this question

Global Variable and Register don't connect in HLSL

  • harbonne nathalie

    Neither of those items are very well documented, are they

    You can use either (variable) or <variable> to reference a variable when setting an effect state.

    The '1' on the end specifies that there is one float4, you can also specify 2,3, or 4 to set arrays of float2x4, float3x4, or float4x4.

    Robert Dunlop.
    Microsoft DirectX MVP
    www.directxzone.org


  • Tim Scarfe

    The :register() tag does not apply to asm shaders, rather it is used to specify what constant register will be assigned when referenced in an HLSL shader function or fragment. Without this flag a constant register will automatically be assigned for the paramter when it is used in a shader.

    To bind it to a register for use in an asm shader, I would use the PixelShaderConstant[0] state in the pass to set the value of the c0 register equal to your MyTime parameter. This will cause the value of that parameter set by your application to be set prior to calling the shader.

    Robert Dunlop
    Microsoft DirectX MVP
    www.directxzone.org


  • VBISKING

    Robert, thank you for your answer :-)

    So the :register(c0) do not apply to asm at all...just HLSL...
    No wounder it was not doing anything in asm...
    Now I have confirmation of this so I will not try to make this work

    For the PixelShaderConstant[0] it was exactly the right solution

    The documentation is not very precise and It took me a while to make it work
    It turn out that I had to use this :

    In the Cpp code :
    D3DCOLOR ColorValue(1,1,0,1);
    pEffect->SetValue("Color14",ColorValue);

    In BasicHLSL.fx :

    float4 Color14;

    pass p0 {
    PixelShaderConstant1[14] =(Color14); //a 1 after and the parenthesis are important

    asm{
    ...

    mov r0.w , C14

    ...

    }

    }

    There is no example for PixelShaderConstant in the documentation
    And the fact that you need to have the parenthese for variable was not said either...
    and the fact that you need to add a little 1 to make it a float4...

    It's very cool to have this because now I control all my constant value from the cpp code, thank you :-)


  • Global Variable and Register don't connect in HLSL