Skip to content

Commit 7a43090

Browse files
committed
derivative: add compiletests
1 parent 6c027c7 commit 7a43090

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

crates/spirv-std/src/arch/derivative.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub unsafe trait Derivative: Sealed + Default {
3636
///
3737
/// This instruction is only valid in the Fragment Execution Model.
3838
#[crate::macros::gpu_only]
39+
#[inline]
3940
fn ddx(self) -> Self {
4041
deriv_fn!(OpDPdx, self)
4142
}
@@ -48,6 +49,7 @@ pub unsafe trait Derivative: Sealed + Default {
4849
///
4950
/// This instruction is only valid in the Fragment Execution Model.
5051
#[crate::macros::gpu_only]
52+
#[inline]
5153
fn ddx_fine(self) -> Self {
5254
cap_deriv_control!();
5355
deriv_fn!(OpDPdxFine, self)
@@ -63,6 +65,7 @@ pub unsafe trait Derivative: Sealed + Default {
6365
///
6466
/// This instruction is only valid in the Fragment Execution Model.
6567
#[crate::macros::gpu_only]
68+
#[inline]
6669
fn ddx_coarse(self) -> Self {
6770
cap_deriv_control!();
6871
deriv_fn!(OpDPdxCoarse, self)
@@ -77,6 +80,7 @@ pub unsafe trait Derivative: Sealed + Default {
7780
///
7881
/// This instruction is only valid in the Fragment Execution Model.
7982
#[crate::macros::gpu_only]
83+
#[inline]
8084
fn ddy(self) -> Self {
8185
deriv_fn!(OpDPdy, self)
8286
}
@@ -89,6 +93,7 @@ pub unsafe trait Derivative: Sealed + Default {
8993
///
9094
/// This instruction is only valid in the Fragment Execution Model.
9195
#[crate::macros::gpu_only]
96+
#[inline]
9297
fn ddy_fine(self) -> Self {
9398
cap_deriv_control!();
9499
deriv_fn!(OpDPdyFine, self)
@@ -104,6 +109,7 @@ pub unsafe trait Derivative: Sealed + Default {
104109
///
105110
/// This instruction is only valid in the Fragment Execution Model.
106111
#[crate::macros::gpu_only]
112+
#[inline]
107113
fn ddy_coarse(self) -> Self {
108114
cap_deriv_control!();
109115
deriv_fn!(OpDPdyCoarse, self)
@@ -116,6 +122,7 @@ pub unsafe trait Derivative: Sealed + Default {
116122
///
117123
/// This instruction is only valid in the Fragment Execution Model.
118124
#[crate::macros::gpu_only]
125+
#[inline]
119126
fn fwidth(self) -> Self {
120127
deriv_fn!(OpFwidth, self)
121128
}
@@ -127,6 +134,7 @@ pub unsafe trait Derivative: Sealed + Default {
127134
///
128135
/// This instruction is only valid in the Fragment Execution Model.
129136
#[crate::macros::gpu_only]
137+
#[inline]
130138
fn fwidth_fine(self) -> Self {
131139
cap_deriv_control!();
132140
deriv_fn!(OpFwidthFine, self)
@@ -139,6 +147,7 @@ pub unsafe trait Derivative: Sealed + Default {
139147
///
140148
/// This instruction is only valid in the Fragment Execution Model.
141149
#[crate::macros::gpu_only]
150+
#[inline]
142151
fn fwidth_coarse(self) -> Self {
143152
cap_deriv_control!();
144153
deriv_fn!(OpFwidthCoarse, self)

tests/ui/arch/derivative.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build-pass
2+
// compile-flags: -C llvm-args=--disassemble-fn=derivative::derivative
3+
4+
use spirv_std::arch::Derivative;
5+
use spirv_std::spirv;
6+
7+
#[spirv(fragment)]
8+
pub fn main() {
9+
derivative();
10+
}
11+
12+
pub fn derivative() {
13+
Derivative::ddx(0.);
14+
Derivative::ddy(0.);
15+
Derivative::fwidth(0.);
16+
}

tests/ui/arch/derivative.stderr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
OpLine %5 41 8
4+
%6 = OpDPdx %7 %8
5+
OpLine %5 85 8
6+
%9 = OpDPdy %7 %8
7+
OpLine %5 127 8
8+
%10 = OpFwidth %7 %8
9+
OpNoLine
10+
OpReturn
11+
OpFunctionEnd

tests/ui/arch/derivative_control.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// build-pass
2+
// compile-flags: -C target-feature=+DerivativeControl
3+
// compile-flags: -C llvm-args=--disassemble-fn=derivative_control::derivative
4+
5+
use spirv_std::arch::Derivative;
6+
use spirv_std::spirv;
7+
8+
#[spirv(fragment)]
9+
pub fn main() {
10+
derivative();
11+
}
12+
13+
pub fn derivative() {
14+
Derivative::ddx_fine(0.);
15+
Derivative::ddy_fine(0.);
16+
Derivative::fwidth_fine(0.);
17+
18+
Derivative::ddx_coarse(0.);
19+
Derivative::ddy_coarse(0.);
20+
Derivative::fwidth_coarse(0.);
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%1 = OpFunction %2 None %3
2+
%4 = OpLabel
3+
OpLine %5 55 8
4+
%6 = OpDPdxFine %7 %8
5+
OpLine %5 99 8
6+
%9 = OpDPdyFine %7 %8
7+
OpLine %5 140 8
8+
%10 = OpFwidthFine %7 %8
9+
OpLine %5 71 8
10+
%11 = OpDPdxCoarse %7 %8
11+
OpLine %5 115 8
12+
%12 = OpDPdyCoarse %7 %8
13+
OpLine %5 153 8
14+
%13 = OpFwidthCoarse %7 %8
15+
OpNoLine
16+
OpReturn
17+
OpFunctionEnd

0 commit comments

Comments
 (0)