// This sample makes sure unbounded arrays are supported across all register classes t,u,s,b,
// the extension is ".azsl_manual" instead of ".azsl" because it is required to run manually with --use-spaces to pass.
// otherwise the test automation system will pick it up and attempt to compile it without --use-spaces.
// and it's used for full emission validation.
// For this shader to compile it is necessary to use --use-spaces.

ShaderResourceGroupSemantic slot1
{
    FrequencyId = 1;
};

ShaderResourceGroupSemantic slot2
{
    FrequencyId = 2;
};

struct MyStruct
{
    float4 m_a;
    float4 m_b;
};

ShaderResourceGroup SRG1 : slot1
{
    int m_index; // Triggers usage of b0.
    uint2 m_rwTexCoord;

    Texture2D<float4>        m_texSRVa;        // Takes t0, space0
    Texture2D<float4>        m_texSRVb[];      // Takes t1+, space0
    RWTexture2D<float4>      m_texUAVa;        // Takes u0, space0
    RWTexture2D<float4>      m_texUAVb[];      // Takes u1+, space0
    Sampler                  m_samplera;       // Takes s0, space0
    Sampler                  m_samplerb[];     // Takes s1+, space0
    ConstantBuffer<MyStruct> m_structArraya;   // Takes b1, space0
    ConstantBuffer<MyStruct> m_structArrayb[]; // Takes b2+, space0 
};

// When using --use-spaces this SRG2 will take space1... Otherwise
// this shader won't compile because all unbounded arrays in SRG1
// take over all available registers in space0. 
ShaderResourceGroup SRG2 : slot2
{
    int m_index; // Triggers usage of b0.
    uint2 m_rwTexCoord;

    Texture2D<float4>        m_texSRVa;        // Takes t0, space0
    Texture2D<float4>        m_texSRVb[];      // Takes t1+, space0
    RWTexture2D<float4>      m_texUAVa;        // Takes u0, space0
    RWTexture2D<float4>      m_texUAVb[];      // Takes u1+, space0
    Sampler                  m_samplera;       // Takes s0, space0
    Sampler                  m_samplerb[];     // Takes s1+, space0
    ConstantBuffer<MyStruct> m_structArraya;   // Takes b1, space0
    ConstantBuffer<MyStruct> m_structArrayb[]; // Takes b2+, space0 
}

float4 MainPS(float2 uv : TEXCOORD0) : SV_Target0
{
    float4 diffuse = float4(0, 0, 0, 1);

    diffuse += SRG1::m_texSRVa.Sample(SRG1::m_samplera, uv);
    diffuse += SRG1::m_texSRVb[SRG1::m_index].Sample(SRG1::m_samplerb[SRG1::m_index], uv);
    diffuse += SRG1::m_texUAVa[SRG1::m_rwTexCoord];
    diffuse += SRG1::m_texUAVb[SRG1::m_index][SRG1::m_rwTexCoord];
    diffuse += SRG1::m_structArraya.m_a;
    diffuse += SRG1::m_structArrayb[SRG1::m_index].m_b;

    diffuse += SRG2::m_texSRVa.Sample(SRG2::m_samplera, uv);
    diffuse += SRG2::m_texSRVb[SRG2::m_index].Sample(SRG2::m_samplerb[SRG2::m_index], uv);
    diffuse += SRG2::m_texUAVa[SRG2::m_rwTexCoord];
    diffuse += SRG2::m_texUAVb[SRG2::m_index][SRG2::m_rwTexCoord];
    diffuse += SRG2::m_structArraya.m_a;
    diffuse += SRG2::m_structArrayb[SRG2::m_index].m_b;
    
    return diffuse;
}
