Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for fma function #1580

Merged
merged 7 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
Mf::Refract => Function::Regular("refract"),
// computational
Mf::Sign => Function::Regular("sign"),
Mf::Fma => Function::Regular("fma"),
Mf::Fma => Function::Regular("mad"),
Mf::Mix => Function::Regular("lerp"),
Mf::Step => Function::Regular("step"),
Mf::SmoothStep => Function::Regular("smoothstep"),
Expand Down
2 changes: 2 additions & 0 deletions tests/in/functions.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(
)
15 changes: 15 additions & 0 deletions tests/in/functions.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn test_fma() -> vec2<f32> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably move a few things from operators.wgsl into here

let a = vec2<f32>(2.0, 2.0);
let b = vec2<f32>(0.5, 0.5);
let c = vec2<f32>(0.5, 0.5);

// Hazard: HLSL needs a different intrinsic function for f32 and f64
// See: https://github.com/gfx-rs/naga/issues/1579
return fma(a, b, c);
}


[[stage(compute), workgroup_size(1)]]
fn main() {
let a = test_fma();
}
20 changes: 20 additions & 0 deletions tests/out/glsl/functions.main.Compute.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 310 es

precision highp float;
precision highp int;

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;


vec2 test_fma() {
vec2 a = vec2(2.0, 2.0);
vec2 b = vec2(0.5, 0.5);
vec2 c = vec2(0.5, 0.5);
return fma(a, b, c);
}

void main() {
vec2 _e0 = test_fma();
return;
}

15 changes: 15 additions & 0 deletions tests/out/hlsl/functions.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

float2 test_fma()
{
float2 a = float2(2.0, 2.0);
float2 b = float2(0.5, 0.5);
float2 c = float2(0.5, 0.5);
return mad(a, b, c);
}

[numthreads(1, 1, 1)]
void main()
{
const float2 _e0 = test_fma();
return;
}
3 changes: 3 additions & 0 deletions tests/out/hlsl/functions.hlsl.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vertex=()
fragment=()
compute=(main:cs_5_1 )
18 changes: 18 additions & 0 deletions tests/out/msl/functions.msl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// language: metal1.1
#include <metal_stdlib>
#include <simd/simd.h>


metal::float2 test_fma(
) {
metal::float2 a = metal::float2(2.0, 2.0);
metal::float2 b = metal::float2(0.5, 0.5);
metal::float2 c = metal::float2(0.5, 0.5);
return metal::fma(a, b, c);
}

kernel void main_(
) {
metal::float2 _e0 = test_fma();
return;
}
33 changes: 33 additions & 0 deletions tests/out/spv/functions.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 20
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %16 "main"
OpExecutionMode %16 LocalSize 1 1 1
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpConstant %4 2.0
%5 = OpConstant %4 0.5
%6 = OpTypeVector %4 2
%9 = OpTypeFunction %6
%17 = OpTypeFunction %2
%8 = OpFunction %6 None %9
%7 = OpLabel
OpBranch %10
%10 = OpLabel
%11 = OpCompositeConstruct %6 %3 %3
%12 = OpCompositeConstruct %6 %5 %5
%13 = OpCompositeConstruct %6 %5 %5
%14 = OpExtInst %6 %1 Fma %11 %12 %13
OpReturnValue %14
OpFunctionEnd
%16 = OpFunction %2 None %17
%15 = OpLabel
OpBranch %18
%18 = OpLabel
%19 = OpFunctionCall %6 %8
OpReturn
OpFunctionEnd
12 changes: 12 additions & 0 deletions tests/out/wgsl/functions.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn test_fma() -> vec2<f32> {
let a = vec2<f32>(2.0, 2.0);
let b = vec2<f32>(0.5, 0.5);
let c = vec2<f32>(0.5, 0.5);
return fma(a, b, c);
}

[[stage(compute), workgroup_size(1, 1, 1)]]
fn main() {
let _e0 = test_fma();
return;
}
4 changes: 4 additions & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ fn convert_wgsl() {
"operators",
Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,
),
(
"functions",
Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,
),
(
"interpolate",
Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,
Expand Down