2022-05-10 06:08:30 -07:00
|
|
|
[require]
|
|
|
|
shader model >= 4.0
|
|
|
|
|
|
|
|
[texture 0]
|
|
|
|
size (3, 3)
|
|
|
|
0.1 0.1 0.1 0.1 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3
|
|
|
|
0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.6 0.6 0.6 0.6
|
|
|
|
0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9
|
|
|
|
|
|
|
|
[texture 1]
|
|
|
|
size (2, 2)
|
|
|
|
0.1 0.1 0.1 0.0 0.2 0.2 0.2 0.0
|
|
|
|
0.4 0.4 0.4 0.0 0.5 0.5 0.5 0.0
|
|
|
|
|
|
|
|
|
|
|
|
[pixel shader]
|
|
|
|
Texture2D tex1;
|
|
|
|
Texture2D tex2;
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
Texture2D q[2] = {tex1, tex2};
|
|
|
|
|
|
|
|
return q[0].Load(int3(0, 0, 0)) + q[1].Load(int3(0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
2024-01-24 19:28:46 -08:00
|
|
|
draw quad
|
2022-07-22 12:28:19 -07:00
|
|
|
probe all rgba (0.2, 0.2, 0.2, 0.1)
|
2022-05-10 06:08:30 -07:00
|
|
|
|
|
|
|
|
vkd3d-shader/hlsl: Replace loads with constants in copy prop.
If a hlsl_ir_load loads a variable whose components are stored from different
instructions, copy propagation doesn't replace it.
But if all these instructions are constants (which currently is the case
for value constructors), the load could be replaced with a constant value.
Which is expected in some other instructions, e.g. texel_offsets when
using aoffimmi modifiers.
For instance, this shader:
```
sampler s;
Texture2D t;
float4 main() : sv_target
{
return t.Gather(s, float2(0.6, 0.6), int2(0, 0));
}
```
results in the following IR before applying the patch:
```
float | 6.00000024e-01
float | 6.00000024e-01
uint | 0
| = (<constructor-2>[@4].x @2)
uint | 1
| = (<constructor-2>[@6].x @3)
float2 | <constructor-2>
int | 0
int | 0
uint | 0
| = (<constructor-5>[@11].x @9)
uint | 1
| = (<constructor-5>[@13].x @10)
int2 | <constructor-5>
float4 | gather_red(resource = t, sampler = s, coords = @8, offset = @15)
| return
| = (<output-sv_target0> @16)
```
and this IR afterwards:
```
float2 | {6.00000024e-01 6.00000024e-01 }
int2 | {0 0 }
float4 | gather_red(resource = t, sampler = s, coords = @2, offset = @3)
| return
| = (<output-sv_target0> @4)
```
2022-11-17 12:49:28 -08:00
|
|
|
[pixel shader]
|
2022-05-10 06:08:30 -07:00
|
|
|
Texture2D tex;
|
|
|
|
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
float2 aa;
|
|
|
|
Texture2D bb;
|
|
|
|
Texture2D cc;
|
|
|
|
float4 dd;
|
|
|
|
};
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
struct foo q = {10, 20, tex, tex, 30, 40, 50, 60};
|
|
|
|
|
|
|
|
return q.bb.Load(int3(2, 0, 0)) + q.cc.Load(int3(1, 2, 0)) + q.dd;
|
|
|
|
}
|
|
|
|
|
|
|
|
[test]
|
2024-01-24 19:28:46 -08:00
|
|
|
draw quad
|
vkd3d-shader/hlsl: Replace loads with constants in copy prop.
If a hlsl_ir_load loads a variable whose components are stored from different
instructions, copy propagation doesn't replace it.
But if all these instructions are constants (which currently is the case
for value constructors), the load could be replaced with a constant value.
Which is expected in some other instructions, e.g. texel_offsets when
using aoffimmi modifiers.
For instance, this shader:
```
sampler s;
Texture2D t;
float4 main() : sv_target
{
return t.Gather(s, float2(0.6, 0.6), int2(0, 0));
}
```
results in the following IR before applying the patch:
```
float | 6.00000024e-01
float | 6.00000024e-01
uint | 0
| = (<constructor-2>[@4].x @2)
uint | 1
| = (<constructor-2>[@6].x @3)
float2 | <constructor-2>
int | 0
int | 0
uint | 0
| = (<constructor-5>[@11].x @9)
uint | 1
| = (<constructor-5>[@13].x @10)
int2 | <constructor-5>
float4 | gather_red(resource = t, sampler = s, coords = @8, offset = @15)
| return
| = (<output-sv_target0> @16)
```
and this IR afterwards:
```
float2 | {6.00000024e-01 6.00000024e-01 }
int2 | {0 0 }
float4 | gather_red(resource = t, sampler = s, coords = @2, offset = @3)
| return
| = (<output-sv_target0> @4)
```
2022-11-17 12:49:28 -08:00
|
|
|
probe all rgba (31.1, 41.1, 51.1, 61.1) 1
|
2022-05-10 06:08:30 -07:00
|
|
|
|
|
|
|
|
vkd3d-shader/hlsl: Replace loads with constants in copy prop.
If a hlsl_ir_load loads a variable whose components are stored from different
instructions, copy propagation doesn't replace it.
But if all these instructions are constants (which currently is the case
for value constructors), the load could be replaced with a constant value.
Which is expected in some other instructions, e.g. texel_offsets when
using aoffimmi modifiers.
For instance, this shader:
```
sampler s;
Texture2D t;
float4 main() : sv_target
{
return t.Gather(s, float2(0.6, 0.6), int2(0, 0));
}
```
results in the following IR before applying the patch:
```
float | 6.00000024e-01
float | 6.00000024e-01
uint | 0
| = (<constructor-2>[@4].x @2)
uint | 1
| = (<constructor-2>[@6].x @3)
float2 | <constructor-2>
int | 0
int | 0
uint | 0
| = (<constructor-5>[@11].x @9)
uint | 1
| = (<constructor-5>[@13].x @10)
int2 | <constructor-5>
float4 | gather_red(resource = t, sampler = s, coords = @8, offset = @15)
| return
| = (<output-sv_target0> @16)
```
and this IR afterwards:
```
float2 | {6.00000024e-01 6.00000024e-01 }
int2 | {0 0 }
float4 | gather_red(resource = t, sampler = s, coords = @2, offset = @3)
| return
| = (<output-sv_target0> @4)
```
2022-11-17 12:49:28 -08:00
|
|
|
[pixel shader]
|
2022-05-10 06:08:30 -07:00
|
|
|
Texture2D tex1;
|
|
|
|
Texture2D tex2;
|
|
|
|
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
float2 aa;
|
|
|
|
Texture2D bb[2]; // NOTE: this cannot be initialized in shader model >= 5.1
|
|
|
|
float4 cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
struct foo q = {10, 20, tex1, tex2, 30, 40, 50, 60};
|
|
|
|
|
|
|
|
return q.bb[0].Load(int3(0, 0, 0)) + q.bb[1].Load(int3(1, 1, 0)) + q.cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-22 09:42:17 -07:00
|
|
|
[pixel shader fail]
|
2022-05-10 06:08:30 -07:00
|
|
|
Texture2D tex;
|
|
|
|
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
float2 aa;
|
|
|
|
Texture2D bb;
|
|
|
|
Texture2D cc;
|
|
|
|
float4 dd;
|
|
|
|
};
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
struct foo q = {10, 20, tex, 30, 40, 50, 60};
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-22 09:42:17 -07:00
|
|
|
[pixel shader fail]
|
2022-05-10 06:08:30 -07:00
|
|
|
Texture2D tex;
|
|
|
|
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
float2 aa;
|
|
|
|
Texture2D bb;
|
|
|
|
Texture2D cc;
|
|
|
|
float4 dd;
|
|
|
|
};
|
|
|
|
|
|
|
|
float4 main() : sv_target
|
|
|
|
{
|
|
|
|
struct foo q = {10, 20, tex, tex, tex, 30, 40, 50, 60};
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|