Derivative tests

This commit is contained in:
Dzmitry Malyshau
2021-05-14 09:45:37 -04:00
committed by Dzmitry Malyshau
parent 057d03ad86
commit 418e71281e
8 changed files with 83 additions and 3 deletions

View File

@@ -797,12 +797,13 @@ impl FlowGraph {
Terminator::Branch { target_id } => {
let target_index = self.block_to_node[&target_id];
let edge = self.flow[self.flow.find_edge(node_index, target_index).unwrap()];
let edge =
self.flow[self.flow.find_edge(node_index, target_index).unwrap()];
if edge == ControlFlowEdgeType::LoopBreak {
result.push(crate::Statement::Break);
}
},
}
_ => return Err(Error::InvalidTerminator),
};
Ok(result)

View File

@@ -118,7 +118,7 @@ pub fn map_derivative_axis(word: &str) -> Option<crate::DerivativeAxis> {
match word {
"dpdx" => Some(crate::DerivativeAxis::X),
"dpdy" => Some(crate::DerivativeAxis::Y),
"dwidth" => Some(crate::DerivativeAxis::Width),
"fwidth" => Some(crate::DerivativeAxis::Width),
_ => None,
}
}

View File

@@ -0,0 +1,5 @@
(
spv_version: (1, 0),
spv_capabilities: [ Shader ],
spv_adjust_coordinate_space: false,
)

9
tests/in/standard.wgsl Normal file
View File

@@ -0,0 +1,9 @@
// Standard functions.
[[stage(fragment)]]
fn derivatives([[builtin(position)]] foo: vec4<f32>) -> [[location(0)]] vec4<f32> {
let x = dpdx(foo);
let y = dpdy(foo);
let z = fwidth(foo);
return (x + y) * z;
}

View File

@@ -0,0 +1,15 @@
#version 310 es
precision highp float;
layout(location = 0) out vec4 _fs2p_location0;
void main() {
vec4 foo = gl_FragCoord;
vec4 _expr1 = dFdx(foo);
vec4 _expr2 = dFdy(foo);
vec4 _expr3 = fwidth(foo);
_fs2p_location0 = ((_expr1 + _expr2) * _expr3);
return;
}

17
tests/out/standard.msl Normal file
View File

@@ -0,0 +1,17 @@
#include <metal_stdlib>
#include <simd/simd.h>
struct derivativesInput {
};
struct derivativesOutput {
metal::float4 member [[color(0)]];
};
fragment derivativesOutput derivatives(
metal::float4 foo [[position]]
) {
metal::float4 _e1 = metal::dfdx(foo);
metal::float4 _e2 = metal::dfdy(foo);
metal::float4 _e3 = metal::fwidth(foo);
return derivativesOutput { (_e1 + _e2) * _e3 };
}

32
tests/out/standard.spvasm Normal file
View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 19
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %11 "derivatives" %6 %9
OpExecutionMode %11 OriginUpperLeft
OpDecorate %6 BuiltIn FragCoord
OpDecorate %9 Location 0
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpTypeVector %4 4
%7 = OpTypePointer Input %3
%6 = OpVariable %7 Input
%10 = OpTypePointer Output %3
%9 = OpVariable %10 Output
%12 = OpTypeFunction %2
%11 = OpFunction %2 None %12
%5 = OpLabel
%8 = OpLoad %3 %6
OpBranch %13
%13 = OpLabel
%14 = OpDPdx %3 %8
%15 = OpDPdy %3 %8
%16 = OpFwidth %3 %8
%17 = OpFAdd %3 %14 %15
%18 = OpFMul %3 %17 %16
OpStore %9 %18
OpReturn
OpFunctionEnd

View File

@@ -266,6 +266,7 @@ fn convert_wgsl() {
"control-flow",
Targets::SPIRV | Targets::METAL | Targets::GLSL,
),
("standard", Targets::SPIRV | Targets::METAL | Targets::GLSL),
];
for &(name, targets) in inputs.iter() {