Global Constant Arrays in Shaders don't work

I’m trying to convert my XNA project to MonoGame, and I had this problem, which took ages to track down because it fails silently with no error message. There’s an easy workaround which I’m now using, but I thought I’d post it here to see if anyone’s heard of it.

Here’s part of my Guassian blur shader, as it was in the XNA project:

const float gaussian[] =
{
    0.0539909676,
    0.241970733,
    0.3989423,
    0.241970733,
    0.0539909676,
};

void AddTap(in out float4 sum, float2 tex_coord, float weight)
{
    float4 tex_col = tex2D(TexSampler, tex_coord);
    sum += tex_col*weight;
}

float4 GaussianBlurStage1PS(VertexShaderOutput input) : COLOR0
{
    float4 sum = float4(0,0,0,0);

    // blur in x (horizontal)
    for (int i = -1; i <= 1; i++)
        AddTap(sum, float2(input.TexCoord.x + float(i)/TexSize, input.TexCoord.y), gaussian[i+1]);

    return float4(sum.rgb,1);
}

float4 GaussianBlurStage2PS(VertexShaderOutput input) : COLOR0
{
    float4 sum = float4(0,0,0,0);

    // blur in y (vertical)
    for (int i = -1; i <= 1; i++)
        AddTap(sum, float2(input.TexCoord.x, input.TexCoord.y + float(i)/TexSize), gaussian[i+1]);

    return float4(sum.rgb,1);
}

This doesn’t work, and doesn’t give any error messages. The problem seems to be that it doesn’t like the global const array “gaussian”. If I move this into the functions, it works. But because there are two functions I have to copy the array into each of them, so the code is duplicated. Which… doesn’t really matter, but it’s a bit annoying :wink:

Which PS_SHADERMODEL do you use ?

Though I’m not sure you can create arrays without setting their size (i’ve never used it like this)
Have you tried with the ‘uniform’ semantic and setting the size of the array. My arrays have always looked like
float gWeights3x3[3][3] = { { 0.0625, 0.1250, 0.0625 }, { 0.1250, 0.2500, 0.1250 }, { 0.0625, 0.1250, 0.0625 } };

Shader model 4. On a Windows build. Using ‘uniform’ and setting the size of the array doesn’t fix it. Are you saying global arrays work for you?