diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 6ceb0ad1b4..453a078b3e 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -116,3 +116,9 @@ fn converts_wgsl_quad() { fn converts_wgsl_simple() { convert_wgsl("simple"); } + +#[cfg(feature = "wgsl-in")] +#[test] +fn converts_wgsl_function() { + convert_wgsl("function"); +} diff --git a/tests/snapshots/in/function.param.ron b/tests/snapshots/in/function.param.ron new file mode 100644 index 0000000000..4adad36220 --- /dev/null +++ b/tests/snapshots/in/function.param.ron @@ -0,0 +1,5 @@ +( + spv_capabilities: [ Shader ], + mtl_bindings: { + } +) diff --git a/tests/snapshots/in/function.wgsl b/tests/snapshots/in/function.wgsl new file mode 100644 index 0000000000..12549c7f97 --- /dev/null +++ b/tests/snapshots/in/function.wgsl @@ -0,0 +1,8 @@ +fn test_function(test: f32) -> f32 { + return test; +} + +[[stage(vertex)]] +fn main() -> void { + var test: f32 = test_function(1.0); +} diff --git a/tests/snapshots/snapshots__function.msl.snap b/tests/snapshots/snapshots__function.msl.snap new file mode 100644 index 0000000000..cbaab56341 --- /dev/null +++ b/tests/snapshots/snapshots__function.msl.snap @@ -0,0 +1,27 @@ +--- +source: tests/snapshots.rs +expression: msl +--- +#include +#include + +typedef float type; + +type test_function( + type test +) { + return test; +} +struct main1Input { +}; +struct main1Output { +}; +vertex main1Output main1( + main1Input input [[stage_in]] +) { + main1Output output; + type test1; + test1 = test_function(1.0); + return output; +} + diff --git a/tests/snapshots/snapshots__function.spvasm.snap b/tests/snapshots/snapshots__function.spvasm.snap new file mode 100644 index 0000000000..a28f333e15 --- /dev/null +++ b/tests/snapshots/snapshots__function.spvasm.snap @@ -0,0 +1,31 @@ +--- +source: tests/snapshots.rs +expression: dis +--- +; SPIR-V +; Version: 1.0 +; Generator: rspirv +; Bound: 16 +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Vertex %11 "main" +%2 = OpTypeFloat 32 +%4 = OpTypePointer Function %2 +%6 = OpTypeFunction %2 %4 +%10 = OpTypeVoid +%12 = OpTypeFunction %10 +%15 = OpConstant %2 1.0 +%5 = OpFunction %2 None %6 +%3 = OpFunctionParameter %4 +%7 = OpLabel +%8 = OpLoad %2 %3 +OpReturnValue %8 +OpFunctionEnd +%11 = OpFunction %10 None %12 +%13 = OpLabel +%9 = OpVariable %4 Function +%14 = OpFunctionCall %2 %5 %15 +OpStore %9 %14 +OpReturn +OpFunctionEnd