removing recursion test
This commit is contained in:
@@ -4,19 +4,17 @@ module;
|
|||||||
|
|
||||||
struct FragOut
|
struct FragOut
|
||||||
{
|
{
|
||||||
[location(0)] color: vec4[i32]
|
[location(0)] color: vec4[f32]
|
||||||
}
|
|
||||||
|
|
||||||
fn fibonacci(n: i32) -> i32
|
|
||||||
{
|
|
||||||
if (n <= i32(1)) return n;
|
|
||||||
return fibonacci(n - i32(1)) + fibonacci(n - i32(2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag)]
|
[entry(frag)]
|
||||||
fn main() -> FragOut
|
fn main() -> FragOut
|
||||||
{
|
{
|
||||||
|
let value: f32 = 0.0;
|
||||||
|
for i in 1 -> 20 {
|
||||||
|
value *= f32(i);
|
||||||
|
}
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.color = vec4[i32](fibonacci(2), fibonacci(2), fibonacci(2), fibonacci(2));
|
output.color = vec4[f32](value, value, value, value);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -1,82 +1,75 @@
|
|||||||
Version 1.0
|
Version 1.0
|
||||||
Generator: 2560130
|
Generator: 2560130
|
||||||
Bound: 49
|
Bound: 45
|
||||||
Schema: 0
|
Schema: 0
|
||||||
OpCapability Capability(Shader)
|
OpCapability Capability(Shader)
|
||||||
OpCapability Capability(Float64)
|
OpCapability Capability(Float64)
|
||||||
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
||||||
OpEntryPoint ExecutionModel(Fragment) %16 "main" %11
|
OpEntryPoint ExecutionModel(Fragment) %17 "main" %6
|
||||||
OpExecutionMode %16 ExecutionMode(OriginUpperLeft)
|
OpExecutionMode %17 ExecutionMode(OriginUpperLeft)
|
||||||
OpSource SourceLanguage(NZSL) 4198400
|
OpSource SourceLanguage(NZSL) 4198400
|
||||||
OpSourceExtension "Version: 1.1"
|
OpSourceExtension "Version: 1.1"
|
||||||
OpName %12 "FragOut"
|
OpName %7 "FragOut"
|
||||||
OpMemberName %12 0 "color"
|
OpMemberName %7 0 "color"
|
||||||
OpName %11 "color"
|
OpName %6 "color"
|
||||||
OpName %15 "fibonacci"
|
OpName %17 "main"
|
||||||
OpName %16 "main"
|
OpDecorate %6 Decoration(Location) 0
|
||||||
OpDecorate %11 Decoration(Location) 0
|
OpMemberDecorate %7 0 Decoration(Offset) 0
|
||||||
OpMemberDecorate %12 0 Decoration(Offset) 0
|
%1 = OpTypeVoid
|
||||||
%1 = OpTypeInt 32 1
|
%2 = OpTypeFunction %1
|
||||||
%2 = OpTypePointer StorageClass(Function) %1
|
%3 = OpTypeFloat 32
|
||||||
%3 = OpTypeFunction %1 %2
|
%4 = OpTypeVector %3 4
|
||||||
%4 = OpConstant %1 i32(1)
|
%5 = OpTypePointer StorageClass(Output) %4
|
||||||
%5 = OpTypeBool
|
%7 = OpTypeStruct %4
|
||||||
%6 = OpConstant %1 i32(2)
|
%8 = OpConstant %3 f32(0)
|
||||||
%7 = OpTypeVoid
|
%9 = OpTypePointer StorageClass(Function) %3
|
||||||
%8 = OpTypeFunction %7
|
%10 = OpTypeInt 32 1
|
||||||
%9 = OpTypeVector %1 4
|
%11 = OpConstant %10 i32(1)
|
||||||
%10 = OpTypePointer StorageClass(Output) %9
|
%12 = OpTypePointer StorageClass(Function) %10
|
||||||
%12 = OpTypeStruct %9
|
%13 = OpConstant %10 i32(20)
|
||||||
%13 = OpTypePointer StorageClass(Function) %12
|
%14 = OpTypeBool
|
||||||
%14 = OpConstant %1 i32(0)
|
%15 = OpTypePointer StorageClass(Function) %7
|
||||||
%46 = OpTypePointer StorageClass(Function) %9
|
%16 = OpConstant %10 i32(0)
|
||||||
%11 = OpVariable %10 StorageClass(Output)
|
%42 = OpTypePointer StorageClass(Function) %4
|
||||||
%15 = OpFunction %1 FunctionControl(0) %3
|
%6 = OpVariable %5 StorageClass(Output)
|
||||||
%17 = OpFunctionParameter %2
|
%17 = OpFunction %1 FunctionControl(0) %2
|
||||||
%18 = OpLabel
|
%18 = OpLabel
|
||||||
%19 = OpVariable %2 StorageClass(Function)
|
%19 = OpVariable %9 StorageClass(Function)
|
||||||
%20 = OpVariable %2 StorageClass(Function)
|
%20 = OpVariable %12 StorageClass(Function)
|
||||||
%24 = OpLoad %1 %17
|
%21 = OpVariable %12 StorageClass(Function)
|
||||||
%25 = OpSLessThanEqual %5 %24 %4
|
%22 = OpVariable %15 StorageClass(Function)
|
||||||
OpSelectionMerge %21 SelectionControl(0)
|
OpStore %19 %8
|
||||||
OpBranchConditional %25 %22 %23
|
OpStore %20 %11
|
||||||
%22 = OpLabel
|
OpStore %21 %13
|
||||||
%26 = OpLoad %1 %17
|
OpBranch %23
|
||||||
OpReturnValue %26
|
|
||||||
%23 = OpLabel
|
%23 = OpLabel
|
||||||
OpBranch %21
|
%27 = OpLoad %10 %20
|
||||||
%21 = OpLabel
|
%28 = OpLoad %10 %21
|
||||||
%27 = OpLoad %1 %17
|
%29 = OpSLessThan %14 %27 %28
|
||||||
%28 = OpISub %1 %27 %4
|
OpLoopMerge %25 %26 LoopControl(0)
|
||||||
OpStore %19 %28
|
OpBranchConditional %29 %24 %25
|
||||||
%29 = OpFunctionCall %1 %15 %19
|
%24 = OpLabel
|
||||||
%30 = OpLoad %1 %17
|
%30 = OpLoad %3 %19
|
||||||
%31 = OpISub %1 %30 %6
|
%31 = OpLoad %10 %20
|
||||||
OpStore %20 %31
|
%32 = OpConvertSToF %3 %31
|
||||||
%32 = OpFunctionCall %1 %15 %20
|
%33 = OpFMul %3 %30 %32
|
||||||
%33 = OpIAdd %1 %29 %32
|
OpStore %19 %33
|
||||||
OpReturnValue %33
|
%34 = OpLoad %10 %20
|
||||||
OpFunctionEnd
|
%35 = OpIAdd %10 %34 %11
|
||||||
%16 = OpFunction %7 FunctionControl(0) %8
|
OpStore %20 %35
|
||||||
%34 = OpLabel
|
OpBranch %26
|
||||||
%35 = OpVariable %13 StorageClass(Function)
|
%26 = OpLabel
|
||||||
%36 = OpVariable %2 StorageClass(Function)
|
OpBranch %23
|
||||||
%37 = OpVariable %2 StorageClass(Function)
|
%25 = OpLabel
|
||||||
%38 = OpVariable %2 StorageClass(Function)
|
%36 = OpLoad %3 %19
|
||||||
%39 = OpVariable %2 StorageClass(Function)
|
%37 = OpLoad %3 %19
|
||||||
OpStore %36 %6
|
%38 = OpLoad %3 %19
|
||||||
%40 = OpFunctionCall %1 %15 %36
|
%39 = OpLoad %3 %19
|
||||||
OpStore %37 %6
|
%40 = OpCompositeConstruct %4 %36 %37 %38 %39
|
||||||
%41 = OpFunctionCall %1 %15 %37
|
%41 = OpAccessChain %42 %22 %16
|
||||||
OpStore %38 %6
|
OpStore %41 %40
|
||||||
%42 = OpFunctionCall %1 %15 %38
|
%43 = OpLoad %7 %22
|
||||||
OpStore %39 %6
|
%44 = OpCompositeExtract %4 %43 0
|
||||||
%43 = OpFunctionCall %1 %15 %39
|
OpStore %6 %44
|
||||||
%44 = OpCompositeConstruct %9 %40 %41 %42 %43
|
|
||||||
%45 = OpAccessChain %46 %35 %14
|
|
||||||
OpStore %45 %44
|
|
||||||
%47 = OpLoad %12 %35
|
|
||||||
%48 = OpCompositeExtract %9 %47 0
|
|
||||||
OpStore %11 %48
|
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
|
|||||||
@@ -98,65 +98,3 @@ test "Nested function calls" {
|
|||||||
try case.expectOutput(T, 4, code, "color", &.{ n, n, n, n });
|
try case.expectOutput(T, 4, code, "color", &.{ n, n, n, n });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Recursive function calls" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const types = [_]type{ i32, u32, f32, f64 };
|
|
||||||
|
|
||||||
inline for (types) |T| {
|
|
||||||
const iterations = 10;
|
|
||||||
|
|
||||||
const fib = struct {
|
|
||||||
fn onacci(n: T) T {
|
|
||||||
if (n <= 0) return n;
|
|
||||||
return onacci(n - 1) + onacci(n - 2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const expected = fib.onacci(iterations);
|
|
||||||
|
|
||||||
const shader = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
\\ [nzsl_version("1.1")]
|
|
||||||
\\ [feature(float64)]
|
|
||||||
\\ module;
|
|
||||||
\\
|
|
||||||
\\ struct FragOut
|
|
||||||
\\ {{
|
|
||||||
\\ [location(0)] color: vec4[{s}]
|
|
||||||
\\ }}
|
|
||||||
\\
|
|
||||||
\\ fn fibonacci(n: {s}) -> {s}
|
|
||||||
\\ {{
|
|
||||||
\\ if (n <= {s}(1)) return n;
|
|
||||||
\\ return fibonacci(n - {s}(1)) + fibonacci(n - {s}(2));
|
|
||||||
\\ }}
|
|
||||||
\\
|
|
||||||
\\ [entry(frag)]
|
|
||||||
\\ fn main() -> FragOut
|
|
||||||
\\ {{
|
|
||||||
\\ let output: FragOut;
|
|
||||||
\\ output.color = vec4[{s}](fibonacci({d}), fibonacci({d}), fibonacci({d}), fibonacci({d}));
|
|
||||||
\\ return output;
|
|
||||||
\\ }}
|
|
||||||
,
|
|
||||||
.{
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
@typeName(T),
|
|
||||||
iterations,
|
|
||||||
iterations,
|
|
||||||
iterations,
|
|
||||||
iterations,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
defer allocator.free(shader);
|
|
||||||
std.debug.print("{s}\n\n", .{shader});
|
|
||||||
const code = try compileNzsl(allocator, shader);
|
|
||||||
defer allocator.free(code);
|
|
||||||
try case.expectOutput(T, 4, code, "color", &.{ expected, expected, expected, expected });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user