% Tests for register space reservation syntax. We don't bother testing register
% space here, since it's specific to d3d12 and would require reworking a lot of
% the shader test code.

[require]
shader model >= 5.1

[srv 0]
size (2d, 1, 1)
0.0 0.0 0.0 99.0

[srv 1]
size (2d, 1, 1)
1.0 1.0 1.0 99.0

[srv 2]
size (2d, 1, 1)
2.0 2.0 2.0 99.0

[pixel shader]
Texture2D tex1 : register(t1, space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(msl & sm>=6) draw quad
probe (0, 0) rgba (1, 1, 1, 99)

% Bracket syntax for registers. Ignored in SM>=6.
[pixel shader]
Texture2D tex1 : register(t[1], space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(msl & sm>=6) draw quad
if(sm>=6) probe (0, 0) rgba (0, 0, 0, 99)
if(sm<6) probe (0, 0) rgba (1, 1, 1, 99)

[pixel shader fail(sm>=6)]
Texture2D tex1 : register(t1, sPaCe0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
draw quad
probe (0, 0) rgba (1, 1, 1, 99)


[pixel shader fail todo]
Texture2D tex1 : register(space0, t1);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}


[pixel shader fail(sm<6)]
Texture2D tex1 : register(ps, space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(msl & sm>=6) draw quad
probe (0, 0) rgba (0, 0, 0, 99)


[pixel shader fail(sm<6)]
Texture2D tex1 : register(space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(msl & sm>=6) draw quad
probe (0, 0) rgba (0, 0, 0, 99)


% Specifying a profile is just broken. The first reservation (or, with sm6, the
% last) is taken regardless of whether it actually matches the current profile.

[pixel shader todo]
Texture2D tex1 : register(vs, t1, space0) : register(ps, t2, space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(sm<6 | msl) draw quad
if(sm>=6) probe (0,0) rgba (2, 2, 2, 99)
if(sm<6)  probe (0,0) rgba (1, 1, 1, 99)

% Same as above, but with bracket exprs, which are ignored in SM>=6.

[pixel shader todo]
Texture2D tex1 : register(vs, t[1], space0) : register(ps, t[2], space0);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(sm<6 | msl) draw quad
if(sm>=6) probe (0, 0) rgba (0, 0, 0, 99)
if(sm<6) probe (0, 0) rgba (1, 1, 1, 99)

% This actually inheres to 5.1+; it doesn't matter whether "space" is specified.

[pixel shader todo]
Texture2D tex1 : register(vs, t1) : register(ps, t2);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(sm<6 | msl) draw quad
if(sm>=6) probe (0,0) rgba (2, 2, 2, 99)
if(sm<6)  probe (0,0) rgba (1, 1, 1, 99)


% It's still illegal to specify multiple contradictory reservations with the
% same profile...

[pixel shader fail todo]
Texture2D tex1 : register(vs, t1) : register(vs, t2);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}


% ...but it's not illegal to specify e.g. ps alongside ps_5_1.

[pixel shader todo]
Texture2D tex1 : register(ps, t1) : register(ps_5_1, t2);

float4 main() : sv_target
{
    return tex1.Load(int3(0, 0, 0));
}

[test]
todo(sm<6 | msl) draw quad
if(sm>=6) probe (0,0) rgba (2, 2, 2, 99)
if(sm<6)  probe (0,0) rgba (1, 1, 1, 99)


% Test conflicts.

[pixel shader fail]
Texture2D t : register(t1, space1);
Texture2D t2 : register(t1, space1);

float4 main() : sv_target
{
    return t.Load(0) + t2.Load(0);
}

[pixel shader fail]

cbuffer a : register(b1, space1)
{
    float4 f;
}

cbuffer a : register(b1, space1)
{
    float4 g;
}

float4 main() : sv_target
{
    return f + g;
}
