From 9f182ade30680d47f300e47d9afa5ce06586eb65 Mon Sep 17 00:00:00 2001 From: Evan Mark Hopkins Date: Sun, 22 Jan 2023 14:24:47 -0500 Subject: [PATCH] [wgsl] Add refract built-in --- src/back/wgsl/writer.rs | 1 + src/front/wgsl/conv.rs | 1 + tests/in/math-functions.wgsl | 1 + .../out/glsl/math-functions.main.Vertex.glsl | 1 + tests/out/hlsl/math-functions.hlsl | 1 + tests/out/msl/math-functions.msl | 1 + tests/out/spv/math-functions.spvasm | 21 ++++++++++--------- tests/out/wgsl/math-functions.wgsl | 1 + 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/back/wgsl/writer.rs b/src/back/wgsl/writer.rs index b2cec92da3..74c0bf3e88 100644 --- a/src/back/wgsl/writer.rs +++ b/src/back/wgsl/writer.rs @@ -1582,6 +1582,7 @@ impl Writer { Mf::Normalize => Function::Regular("normalize"), Mf::FaceForward => Function::Regular("faceForward"), Mf::Reflect => Function::Regular("reflect"), + Mf::Refract => Function::Regular("refract"), // computational Mf::Sign => Function::Regular("sign"), Mf::Fma => Function::Regular("fma"), diff --git a/src/front/wgsl/conv.rs b/src/front/wgsl/conv.rs index 645f90b011..e4c29f7939 100644 --- a/src/front/wgsl/conv.rs +++ b/src/front/wgsl/conv.rs @@ -178,6 +178,7 @@ pub fn map_standard_fun(word: &str) -> Option { "normalize" => Mf::Normalize, "faceForward" => Mf::FaceForward, "reflect" => Mf::Reflect, + "refract" => Mf::Refract, // computational "sign" => Mf::Sign, "fma" => Mf::Fma, diff --git a/tests/in/math-functions.wgsl b/tests/in/math-functions.wgsl index 9ecac80499..13b080e927 100644 --- a/tests/in/math-functions.wgsl +++ b/tests/in/math-functions.wgsl @@ -7,6 +7,7 @@ fn main() { let c = degrees(v); let d = radians(v); let e = saturate(v); + let g = refract(v, v, f); let const_dot = dot(vec2(), vec2()); let first_leading_bit_abs = firstLeadingBit(abs(0u)); } diff --git a/tests/out/glsl/math-functions.main.Vertex.glsl b/tests/out/glsl/math-functions.main.Vertex.glsl index f0954772e6..5efa8f27ca 100644 --- a/tests/out/glsl/math-functions.main.Vertex.glsl +++ b/tests/out/glsl/math-functions.main.Vertex.glsl @@ -11,6 +11,7 @@ void main() { vec4 c = degrees(v); vec4 d = radians(v); vec4 e = clamp(v, vec4(0.0), vec4(1.0)); + vec4 g = refract(v, v, 1.0); int const_dot = ( + ivec2(0, 0).x * ivec2(0, 0).x + ivec2(0, 0).y * ivec2(0, 0).y); uint first_leading_bit_abs = uint(findMSB(uint(abs(int(0u))))); } diff --git a/tests/out/hlsl/math-functions.hlsl b/tests/out/hlsl/math-functions.hlsl index 827da71b4a..64c2e87eab 100644 --- a/tests/out/hlsl/math-functions.hlsl +++ b/tests/out/hlsl/math-functions.hlsl @@ -7,6 +7,7 @@ void main() float4 c = degrees(v); float4 d = radians(v); float4 e = saturate(v); + float4 g = refract(v, v, 1.0); int const_dot = dot(int2(0, 0), int2(0, 0)); uint first_leading_bit_abs = firstbithigh(abs(0u)); } diff --git a/tests/out/msl/math-functions.msl b/tests/out/msl/math-functions.msl index 559d464681..d097be47a8 100644 --- a/tests/out/msl/math-functions.msl +++ b/tests/out/msl/math-functions.msl @@ -14,6 +14,7 @@ vertex void main_( metal::float4 c = ((v) * 57.295779513082322865); metal::float4 d = ((v) * 0.017453292519943295474); metal::float4 e = metal::saturate(v); + metal::float4 g = metal::refract(v, v, 1.0); int const_dot = ( + const_type_1_.x * const_type_1_.x + const_type_1_.y * const_type_1_.y); uint first_leading_bit_abs = (((metal::clz(metal::abs(0u)) + 1) % 33) - 1); } diff --git a/tests/out/spv/math-functions.spvasm b/tests/out/spv/math-functions.spvasm index 194024b769..4fada56c7f 100644 --- a/tests/out/spv/math-functions.spvasm +++ b/tests/out/spv/math-functions.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.1 ; Generator: rspirv -; Bound: 36 +; Bound: 37 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 @@ -18,7 +18,7 @@ OpEntryPoint Vertex %14 "main" %11 = OpTypeVector %7 2 %12 = OpConstantComposite %11 %6 %6 %15 = OpTypeFunction %2 -%26 = OpConstantNull %7 +%27 = OpConstantNull %7 %14 = OpFunction %2 None %15 %13 = OpLabel OpBranch %16 @@ -31,15 +31,16 @@ OpBranch %16 %23 = OpCompositeConstruct %10 %5 %5 %5 %5 %24 = OpCompositeConstruct %10 %3 %3 %3 %3 %22 = OpExtInst %10 %1 FClamp %17 %23 %24 -%27 = OpCompositeExtract %7 %12 0 +%25 = OpExtInst %10 %1 Refract %17 %17 %3 %28 = OpCompositeExtract %7 %12 0 -%29 = OpIMul %7 %27 %28 -%30 = OpIAdd %7 %26 %29 -%31 = OpCompositeExtract %7 %12 1 +%29 = OpCompositeExtract %7 %12 0 +%30 = OpIMul %7 %28 %29 +%31 = OpIAdd %7 %27 %30 %32 = OpCompositeExtract %7 %12 1 -%33 = OpIMul %7 %31 %32 -%25 = OpIAdd %7 %30 %33 -%34 = OpCopyObject %9 %8 -%35 = OpExtInst %9 %1 FindUMsb %34 +%33 = OpCompositeExtract %7 %12 1 +%34 = OpIMul %7 %32 %33 +%26 = OpIAdd %7 %31 %34 +%35 = OpCopyObject %9 %8 +%36 = OpExtInst %9 %1 FindUMsb %35 OpReturn OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/math-functions.wgsl b/tests/out/wgsl/math-functions.wgsl index 2643879ee3..004d9cf5be 100644 --- a/tests/out/wgsl/math-functions.wgsl +++ b/tests/out/wgsl/math-functions.wgsl @@ -6,6 +6,7 @@ fn main() { let c = degrees(v); let d = radians(v); let e = saturate(v); + let g = refract(v, v, 1.0); let const_dot = dot(vec2(0, 0), vec2(0, 0)); let first_leading_bit_abs = firstLeadingBit(abs(0u)); }