diff --git a/src/front/spv/flow.rs b/src/front/spv/flow.rs index 19db91ffda..e9dd5b8353 100644 --- a/src/front/spv/flow.rs +++ b/src/front/spv/flow.rs @@ -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) diff --git a/src/front/wgsl/conv.rs b/src/front/wgsl/conv.rs index f9b79290d1..7187bd5602 100644 --- a/src/front/wgsl/conv.rs +++ b/src/front/wgsl/conv.rs @@ -118,7 +118,7 @@ pub fn map_derivative_axis(word: &str) -> Option { match word { "dpdx" => Some(crate::DerivativeAxis::X), "dpdy" => Some(crate::DerivativeAxis::Y), - "dwidth" => Some(crate::DerivativeAxis::Width), + "fwidth" => Some(crate::DerivativeAxis::Width), _ => None, } } diff --git a/tests/in/standard.param.ron b/tests/in/standard.param.ron new file mode 100644 index 0000000000..1eb59329eb --- /dev/null +++ b/tests/in/standard.param.ron @@ -0,0 +1,5 @@ +( + spv_version: (1, 0), + spv_capabilities: [ Shader ], + spv_adjust_coordinate_space: false, +) diff --git a/tests/in/standard.wgsl b/tests/in/standard.wgsl new file mode 100644 index 0000000000..a9db49e784 --- /dev/null +++ b/tests/in/standard.wgsl @@ -0,0 +1,9 @@ +// Standard functions. + +[[stage(fragment)]] +fn derivatives([[builtin(position)]] foo: vec4) -> [[location(0)]] vec4 { + let x = dpdx(foo); + let y = dpdy(foo); + let z = fwidth(foo); + return (x + y) * z; +} diff --git a/tests/out/standard.Fragment.glsl b/tests/out/standard.Fragment.glsl new file mode 100644 index 0000000000..d39147bfb5 --- /dev/null +++ b/tests/out/standard.Fragment.glsl @@ -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; +} + diff --git a/tests/out/standard.msl b/tests/out/standard.msl new file mode 100644 index 0000000000..3909bef27c --- /dev/null +++ b/tests/out/standard.msl @@ -0,0 +1,17 @@ +#include +#include + + +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 }; +} diff --git a/tests/out/standard.spvasm b/tests/out/standard.spvasm new file mode 100644 index 0000000000..a8c5d06939 --- /dev/null +++ b/tests/out/standard.spvasm @@ -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 \ No newline at end of file diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 8a85ee32cf..fb4bb824f4 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -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() {