cpt-max / Docs

16 stars 0 forks source link

"BaseInstance not supported in ES profile" when compiling shader for Android #3

Open k4G17eYWI opened 4 months ago

k4G17eYWI commented 4 months ago

I try to compile this shader. It compiles ok when targeting Desktop but fails with an error "BaseInstance not supported in ES profile" on a content pipeline build phase when targeting Android. I've squeezed my shader to only reproduce this issue and here is a squeezed code:

#define VS_SHADERMODEL vs_5_0
#define PS_SHADERMODEL ps_5_0

StructuredBuffer<float4> particles;

Texture2D MainTex; // primary texture.
SamplerState MySampler  { };

struct VsInputQuad
{
    uint instance_id: SV_InstanceID;
};

struct VsOutputQuad
{
    float4 Position : SV_Position;
    float4 Color : COLOR0;
    float2 TexureCoordinateA : TEXCOORD0;
};

struct PsOutputQuad
{
    float4 Color : SV_TARGET;
};

VsOutputQuad vert(VsInputQuad input)
{
    uint ii = input.instance_id;    
    VsOutputQuad ret;
    ret.Position = float4(particles[ii].x,0,0,0);
    ret.TexureCoordinateA = float2(0,0);
    ret.Color = float4(1,1,1,1);
    return ret; 
}

PsOutputQuad frag(VsOutputQuad input)
{
    PsOutputQuad output;
    output.Color = MainTex.Sample(MySampler, input.TexureCoordinateA) * input.Color;
    clip(output.Color.a - 0.01);
    return output;
}

technique Draw
{
    pass
    {
        VertexShader = compile VS_SHADERMODEL vert();
        PixelShader = compile PS_SHADERMODEL frag();
    }
}
cpt-max commented 4 months ago

This seems to be coming from DirectXShaderCompiler when using SV_InstanceID: https://github.com/microsoft/DirectXShaderCompiler/issues/3106 I guess an update to the newest version would fix it. Unfortunately there have been some breaking changes, making the update more difficult.

cpt-max commented 4 months ago

Just noticed that this bug has already been reported in the Android shader samples repo: https://github.com/cpt-max/MonoGame-Shader-Samples-Mobile/issues/1