Rendering issues with shaders only on Android

I have a problem I’ve been working on for a few days porting my current work to Android, I have quite a few shaders that I’ve tested on Windows 10, Windows Phone, and Windows GL projects, and I have them all working correctly:

Windows Version with DirectX

Windows Version with OpenGL

However, I’ve had multiple issues porting these shaders onto Android. My first attempt in porting resulted in all of my graphics turning bright red, as referenced in Second spriteBatch.Draw() always turns textures Red to which I was able to fix this issue by explicitly writing my own pass-through vertex shader (I have no idea why this worked). However, my new issue is that either the vertex shader or the pixel shader is not operating on Android, as seen here:

Android Version, Platform 5.0.1, API Level 21, background not working

The shader responsible for managing this background work is a fairly simple Gaussian blur with a few settings (simplified to cut down on reading):

#define pixelX (10.0 / 1300)
#define pixelY (10.0 / 740)
#define reduction 0.22

float2 Viewport;

void SpriteVertexShader(inout float4 position : SV_Position, inout float4 color : COLOR0, inout float2 texCoord : TEXCOORD0)
{
    // Correction for texel centering.
    position.xy -= 0.5;
    // Viewport fix.
    position.xy = position.xy / Viewport;
    position.xy *= float2(2, -2);
    position.xy -= float2(1, -1);
}

sampler TextureSampler : register(s0);

float4 HorizontalGaussianBlur(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
    float4 tex1 = tex2D(TextureSampler, texCoord + float2(pixelX * 6, 0));
    ...
    float4 result = (0.7 * tex1 + 0.9 * tex2 + tex3 + 1.1 * tex4 + 1.2 * tex5 + 1.3 * tex6 + 1.4 * tex7 + 1.3 * tex8 + 1.2 * tex9 + 1.1 * texA + texB + 0.9 * texC + 0.7 * texD);
    return float4(result.r * reduction, result.r * reduction, result.r * reduction, 1);
}

...

float4 EffectOff(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
    float4 tex = tex2D(TextureSampler, texCoord);
    return tex * color;
}

technique BlurTechnique
{
    pass HorizontalGaussianBlurPass
    {
#if HLSL
        VertexShader = compile vs_4_0_level_9_3 SpriteVertexShader();
        PixelShader = compile ps_4_0_level_9_3 HorizontalGaussianBlur();
#else
        VertexShader = compile vs_2_0 SpriteVertexShader();
        PixelShader = compile ps_2_0 HorizontalGaussianBlur();
#endif
    }
    ...
}

So my primary question is: Am I doing something wrong when working with Android, such as missing a step when preparing my shaders, or do I have some underlying bug in my shaders that I’m not seeing?

It’s always about half an hour after I post something that I find the solution to my own problem, my apologies. It was an issue with me creating the task pool for creating the background image on the title screen, which meant that I was feeding my shaders a blank RenderTarget2D instead of the one I wanted to create. I’m just testing to make sure my fixes work quickly, and if they do, I’ll delete this topic.

That would be unfortunate, maybe you can just explain what was your mistake, especially if it is specific to a given platform (I can only assume that’s not exactly the same code for all, right ? Or the issue would occurred on all, not just one).

We can also learn from others’ mistake(s) :wink: (not just our own).

It’s actually a really boring fix, I was creating a threadpool for a device by querying how many threads the device had available (max of 3), and making the threadpool as - 1 of that amount. My Android emulator was returning to this function saying it only had 1 thread, and so my pool was being initialized without any threads to do the job, hence my RenderTarget2D had nobody writing information to it, leaving it blank. Simple personal bug, simple fix.

Funny enough, I now appear to have an issue with BackBuffer size on Android, but I’d consider it unrelated to this.