mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader/hlsl: Fold some general conditional identities.
The following conditional identities are applied: c ? x : x -> x false ? x : y -> y; true ? x : y -> x c ? true : false -> c; c ? false : true -> !c !c ? x : y -> c ? y : x Lastly, for expression chains x, y in a conditional expression c ? x : y, we evaluate all conditionals in the expression chains with the condition c, assuming c is true (for x), or false (for y).
This commit is contained in:
Notes:
Henri Verbeet
2025-08-21 16:34:35 +02:00
Approved-by: Francisco Casas (@fcasas) Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1648
@@ -160,6 +160,123 @@ float4 main() : sv_target
|
||||
draw quad
|
||||
probe (0, 0) rgba (1.0, 6.0, 7.0, 4.0)
|
||||
|
||||
[pixel shader]
|
||||
static float4 cond = {1, 0, 0, 1};
|
||||
uniform float4 a;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
return cond ? a : a;
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 1.0 2.0 3.0 4.0
|
||||
draw quad
|
||||
probe (0, 0) f32(1.0, 2.0, 3.0, 4.0)
|
||||
|
||||
[pixel shader]
|
||||
uniform float4 a;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
return float4(false ? a.x : a.y, true ? a.x : a.y, 0, 0);
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 1.0 2.0 0.0 0.0
|
||||
draw quad
|
||||
probe (0, 0) f32(2.0, 1.0, 0.0, 0.0)
|
||||
|
||||
[pixel shader todo(sm<4)]
|
||||
uniform float c;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
bool cond = c >= 0;
|
||||
return float4(cond ? true : false, cond ? false : true, 0, 0);
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float -1.0
|
||||
todo(sm<4) draw quad
|
||||
probe (0, 0) f32(0.0, 1.0, 0.0, 0.0)
|
||||
|
||||
[pixel shader]
|
||||
uniform bool cond;
|
||||
uniform float4 a, b;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
return !cond ? a : b;
|
||||
}
|
||||
|
||||
[test]
|
||||
if(sm<4) uniform 0 float 0.0
|
||||
if(sm>=4) uniform 0 uint 0
|
||||
uniform 4 float4 1.0 2.0 3.0 4.0
|
||||
uniform 8 float4 5.0 6.0 7.0 8.0
|
||||
draw quad
|
||||
probe (0, 0) f32(1.0, 2.0, 3.0, 4.0)
|
||||
|
||||
[pixel shader]
|
||||
uniform float4 a;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
bool cond1 = a.x > 0, cond2 = a.x > 2;
|
||||
float4 ret;
|
||||
|
||||
ret.x = cond1 ? (cond1 ? a.x : a.y) : a.z;
|
||||
ret.y = cond1 ? a.x : (cond1 ? a.y : a.z);
|
||||
ret.z = cond2 ? (cond2 ? a.x : a.y) : a.z;
|
||||
ret.w = cond2 ? a.x : (cond2 ? a.y : a.z);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 1.0 2.0 3.0 0.0
|
||||
draw quad
|
||||
probe (0, 0) f32(1.0, 1.0, 3.0, 3.0)
|
||||
|
||||
[pixel shader]
|
||||
uniform float a;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
bool cond1 = a > 0, cond2 = a > 2;
|
||||
float4 ret;
|
||||
|
||||
ret.xy = cond1 ? (cond1 ? float2(0, 1) : float2(1, 0)) : float2(1, 1);
|
||||
ret.zw = cond2 ? float2(0, 2) : (cond2 ? float2(2, 0) : float2(2, 2));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float 1.0
|
||||
draw quad
|
||||
probe (0, 0) f32(0.0, 1.0, 2.0, 2.0)
|
||||
|
||||
[pixel shader]
|
||||
uniform float4 a;
|
||||
|
||||
float4 main() : sv_target
|
||||
{
|
||||
bool cond1 = a.x > 2, cond2 = a.x > 0, cond3 = a.y > 3;
|
||||
|
||||
float b = cond1 ? a.x : a.y;
|
||||
float c = cond2 ? a.z : b;
|
||||
float d = cond3 ? a.w : c + 10;
|
||||
float e = cond1 ? a.x : d;
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
[test]
|
||||
uniform 0 float4 1.0 2.0 3.0 4.0
|
||||
draw quad
|
||||
probe (0, 0) f32(13.0, 13.0, 13.0, 13.0)
|
||||
|
||||
[pixel shader fail]
|
||||
|
||||
|
Reference in New Issue
Block a user