Global arrays don't work in shaders, workaround?

If you declare a global array in a shader and access it via a pixel shader it will always return 0 regardless of the actual value stored.

If anyone knows any workarounds please let me know. Here is an example of the issue.

float test = 1;
float test2[2] = { 0.5, 1 };
float4 PixelShaderFunction(float4 position : SV_Position, float4 c : COLOR0, float2 uv : TEXCOORD0) : COLOR
{
	return float4(test, 0, 0, 1); //This returns red (1,0,0,1)
	return float4(test2[0], 0, 0, 1); //This returns black (0,0,0,1) , I would expect dark red
	return float4(test2[1], 0, 0, 1); //This returns black (0,0,0,1) , I would expect red
}

It is a major pain when converting shaders to monogame.

I have tried changing the shader flags, and have tried using the uniform keyword.

float test = 1
static float2 test2[2] = { 0.5, 1 };

Oh i noticed a bigger mistake

you declared
float test2

but it should be
float2 test2

you declared
float test2

but it should be
float2 test2

Why is that? I am storing two single floats.

oh yeah I was mistaken, sorry

the way you wrote it was correct. Try with the static or const flag before, I’m a bit confused myself now