Skip to content

Commit 63ca127

Browse files
Add Graphics tests for ddx/y_fine (#510)
Relies on llvm/offload-golden-images#5 Adds Graphics tests for ddx_coarse and ddy_coarse intrinsics. The tests use the dd_coarse intrinsics to apply a very basic anti-aliasing style blur to the edges of a circle in either the X or Y dimension.
1 parent 96dbb6c commit 63ca127

2 files changed

Lines changed: 186 additions & 0 deletions

File tree

test/Graphics/ddx_fine.test

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#--- vertex.hlsl
2+
struct PSInput {
3+
float4 position : SV_POSITION;
4+
};
5+
6+
PSInput main(float4 position : POSITION) {
7+
PSInput result;
8+
9+
result.position = position;
10+
11+
return result;
12+
}
13+
14+
#--- pixel.hlsl
15+
16+
// Offset into the image of our circle
17+
#define OFFSET 128.0
18+
// Radius of our circle
19+
#define RADIUS 32.0
20+
// Blur intensity
21+
#define INTENSITY 5.0
22+
23+
struct PSInput {
24+
float4 position : SV_POSITION;
25+
};
26+
27+
float4 main(PSInput input) : SV_TARGET {
28+
float4 c1 = float4(1.0, 1.0, 1.0, 1.0);
29+
float4 c2 = float4(0.0, 0.0, 0.0, 1.0);
30+
31+
float2 coord = input.position.xy - OFFSET;
32+
33+
float dist = length(coord) - RADIUS;
34+
float ddx = abs(ddx_fine(dist));
35+
float effect = clamp(dist / ddx / INTENSITY, 0.0, 1.0);
36+
37+
float result = lerp(c1, c2, effect);
38+
39+
return float4(result, result, result, 1.0);
40+
}
41+
42+
#--- pipeline.yaml
43+
---
44+
Shaders:
45+
- Stage: Vertex
46+
Entry: main
47+
- Stage: Pixel
48+
Entry: main
49+
Buffers:
50+
- Name: VertexData
51+
Format: Float32
52+
Stride: 12 # 16 bytes per vertex
53+
Data: [ -1.0, -1.0, 0.0,
54+
-1.0, 1.0, 0.0,
55+
1.0, 1.0, 0.0,
56+
1.0, 1.0, 0.0,
57+
1.0, -1.0, 0.0,
58+
-1.0, -1.0, 0.0 ]
59+
- Name: Output
60+
Format: Float32
61+
Channels: 4
62+
FillSize: 1048576 # 256x256 @ 16 bytes per pixel
63+
OutputProps:
64+
Height: 256
65+
Width: 256
66+
Depth: 1
67+
Bindings:
68+
VertexBuffer: VertexData
69+
VertexAttributes:
70+
- Format: Float32
71+
Channels: 3
72+
Offset: 0
73+
Name: POSITION
74+
RenderTarget: Output
75+
DescriptorSets: []
76+
...
77+
#--- rules.yaml
78+
---
79+
- Type: PixelPercent
80+
Val: 0.2 # No more than 0.2% of pixels may be visibly different.
81+
...
82+
#--- end
83+
84+
# Bug https://github.com/llvm/wg-hlsl/issues/145
85+
# Bug https://github.com/llvm/wg-hlsl/issues/146
86+
# XFAIL: Clang && DirectX || Clang && Metal
87+
# REQUIRES: goldenimage
88+
89+
# RUN: split-file %s %t
90+
# RUN: %dxc_target -T vs_6_0 -Fo %t-vertex.o %t/vertex.hlsl
91+
# RUN: %dxc_target -T ps_6_0 -Fo %t-pixel.o %t/pixel.hlsl
92+
# RUN: %offloader %t/pipeline.yaml %t-vertex.o %t-pixel.o -r Output -o %t/Output.png
93+
# RUN: imgdiff %t/Output.png %goldenimage_dir/hlsl/Graphics/DdxFine.png -rules %t/rules.yaml

test/Graphics/ddy_fine.test

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#--- vertex.hlsl
2+
struct PSInput {
3+
float4 position : SV_POSITION;
4+
};
5+
6+
PSInput main(float4 position : POSITION) {
7+
PSInput result;
8+
9+
result.position = position;
10+
11+
return result;
12+
}
13+
14+
#--- pixel.hlsl
15+
16+
// Offset into the image of our circle
17+
#define OFFSET 128.0
18+
// Radius of our circle
19+
#define RADIUS 32.0
20+
// Blur intensity
21+
#define INTENSITY 5.0
22+
23+
struct PSInput {
24+
float4 position : SV_POSITION;
25+
};
26+
27+
float4 main(PSInput input) : SV_TARGET {
28+
float4 c1 = float4(1.0, 1.0, 1.0, 1.0);
29+
float4 c2 = float4(0.0, 0.0, 0.0, 1.0);
30+
31+
float2 coord = input.position.xy - OFFSET;
32+
33+
float dist = length(coord) - RADIUS;
34+
float ddx = abs(ddy_fine(dist));
35+
float effect = clamp(dist / ddx / INTENSITY, 0.0, 1.0);
36+
37+
float result = lerp(c1, c2, effect);
38+
39+
return float4(result, result, result, 1.0);
40+
}
41+
42+
#--- pipeline.yaml
43+
---
44+
Shaders:
45+
- Stage: Vertex
46+
Entry: main
47+
- Stage: Pixel
48+
Entry: main
49+
Buffers:
50+
- Name: VertexData
51+
Format: Float32
52+
Stride: 12 # 16 bytes per vertex
53+
Data: [ -1.0, -1.0, 0.0,
54+
-1.0, 1.0, 0.0,
55+
1.0, 1.0, 0.0,
56+
1.0, 1.0, 0.0,
57+
1.0, -1.0, 0.0,
58+
-1.0, -1.0, 0.0 ]
59+
- Name: Output
60+
Format: Float32
61+
Channels: 4
62+
FillSize: 1048576 # 256x256 @ 16 bytes per pixel
63+
OutputProps:
64+
Height: 256
65+
Width: 256
66+
Depth: 1
67+
Bindings:
68+
VertexBuffer: VertexData
69+
VertexAttributes:
70+
- Format: Float32
71+
Channels: 3
72+
Offset: 0
73+
Name: POSITION
74+
RenderTarget: Output
75+
DescriptorSets: []
76+
...
77+
#--- rules.yaml
78+
---
79+
- Type: PixelPercent
80+
Val: 0.2 # No more than 0.2% of pixels may be visibly different.
81+
...
82+
#--- end
83+
84+
# Bug https://github.com/llvm/wg-hlsl/issues/145
85+
# Bug https://github.com/llvm/wg-hlsl/issues/146
86+
# XFAIL: Clang && DirectX || Clang && Metal
87+
# REQUIRES: goldenimage
88+
89+
# RUN: split-file %s %t
90+
# RUN: %dxc_target -T vs_6_0 -Fo %t-vertex.o %t/vertex.hlsl
91+
# RUN: %dxc_target -T ps_6_0 -Fo %t-pixel.o %t/pixel.hlsl
92+
# RUN: %offloader %t/pipeline.yaml %t-vertex.o %t-pixel.o -r Output -o %t/Output.png
93+
# RUN: imgdiff %t/Output.png %goldenimage_dir/hlsl/Graphics/DdyFine.png -rules %t/rules.yaml

0 commit comments

Comments
 (0)