ye
This commit is contained in:
@@ -17,9 +17,11 @@ pub fn main() !void {
|
|||||||
defer rt.deinit(allocator);
|
defer rt.deinit(allocator);
|
||||||
|
|
||||||
try rt.callEntryPoint(allocator, try rt.getEntryPointByName("main"));
|
try rt.callEntryPoint(allocator, try rt.getEntryPointByName("main"));
|
||||||
var output: [4]f32 = undefined;
|
var value: f32 = undefined;
|
||||||
try rt.readOutput(f32, output[0..output.len], try rt.getResultByName("color"));
|
var value2: f32 = undefined;
|
||||||
std.log.info("Output: Vec4{any}", .{output});
|
try rt.readOutput(f32, @as([*]f32, @ptrCast(&value))[0..1], try rt.getResultByName("value"));
|
||||||
|
try rt.readOutput(f32, @as([*]f32, @ptrCast(&value2))[0..1], try rt.getResultByName("value2"));
|
||||||
|
std.log.info("Output: {d} {d}", .{ value, value2 });
|
||||||
}
|
}
|
||||||
std.log.info("Successfully executed", .{});
|
std.log.info("Successfully executed", .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
[nzsl_version("1.1")]
|
[nzsl_version("1.1")]
|
||||||
[feature(float64)]
|
|
||||||
module;
|
module;
|
||||||
|
|
||||||
struct FragOut
|
struct FragOut
|
||||||
{
|
{
|
||||||
[location(0)] color: vec4[f32]
|
[location(0)] value: f32,
|
||||||
|
[location(1)] value2: f32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn Half(inout color: vec3[f32], out value: f32, in inValue: f32, inValue2: f32)
|
||||||
|
{
|
||||||
|
color *= 2.0;
|
||||||
|
value = 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[entry(frag)]
|
[entry(frag)]
|
||||||
fn main() -> FragOut
|
fn main() -> FragOut
|
||||||
{
|
{
|
||||||
let value: f32 = 1.0;
|
let output: FragOut;
|
||||||
for i in 1 -> 5 {
|
let mainColor = vec3[f32](1.0, 1.0, 1.0);
|
||||||
if (i == 3)
|
let inValue = 2.0;
|
||||||
continue;
|
let inValue2 = 1.0;
|
||||||
value *= f32(i);
|
Half(inout mainColor, out output.value2, in inValue, inValue2);
|
||||||
}
|
output.value = mainColor.x;
|
||||||
let output: FragOut;
|
|
||||||
output.color = vec4[f32](value, value, value, value);
|
return output;
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -3,83 +3,86 @@ Generator: 2560130
|
|||||||
Bound: 51
|
Bound: 51
|
||||||
Schema: 0
|
Schema: 0
|
||||||
OpCapability Capability(Shader)
|
OpCapability Capability(Shader)
|
||||||
OpCapability Capability(Float64)
|
|
||||||
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
||||||
OpEntryPoint ExecutionModel(Fragment) %18 "main" %6
|
OpEntryPoint ExecutionModel(Fragment) %20 "main" %11 %12
|
||||||
OpExecutionMode %18 ExecutionMode(OriginUpperLeft)
|
OpExecutionMode %20 ExecutionMode(OriginUpperLeft)
|
||||||
OpSource SourceLanguage(NZSL) 4198400
|
OpSource SourceLanguage(NZSL) 4198400
|
||||||
OpSourceExtension "Version: 1.1"
|
OpSourceExtension "Version: 1.1"
|
||||||
OpName %7 "FragOut"
|
OpName %13 "FragOut"
|
||||||
OpMemberName %7 0 "color"
|
OpMemberName %13 0 "value"
|
||||||
OpName %6 "color"
|
OpMemberName %13 1 "value2"
|
||||||
OpName %18 "main"
|
OpName %11 "value"
|
||||||
OpDecorate %6 Decoration(Location) 0
|
OpName %12 "value2"
|
||||||
OpMemberDecorate %7 0 Decoration(Offset) 0
|
OpName %19 "Half"
|
||||||
|
OpName %20 "main"
|
||||||
|
OpDecorate %11 Decoration(Location) 0
|
||||||
|
OpDecorate %12 Decoration(Location) 1
|
||||||
|
OpMemberDecorate %13 0 Decoration(Offset) 0
|
||||||
|
OpMemberDecorate %13 1 Decoration(Offset) 4
|
||||||
%1 = OpTypeVoid
|
%1 = OpTypeVoid
|
||||||
%2 = OpTypeFunction %1
|
%2 = OpTypeFloat 32
|
||||||
%3 = OpTypeFloat 32
|
%3 = OpTypeVector %2 3
|
||||||
%4 = OpTypeVector %3 4
|
%4 = OpTypePointer StorageClass(Function) %3
|
||||||
%5 = OpTypePointer StorageClass(Output) %4
|
%5 = OpTypePointer StorageClass(Function) %2
|
||||||
%7 = OpTypeStruct %4
|
%6 = OpTypeFunction %1 %4 %5 %5 %5
|
||||||
%8 = OpConstant %3 f32(1)
|
%7 = OpConstant %2 f32(2)
|
||||||
%9 = OpTypePointer StorageClass(Function) %3
|
%8 = OpConstant %2 f32(10)
|
||||||
%10 = OpTypeInt 32 1
|
%9 = OpTypeFunction %1
|
||||||
%11 = OpConstant %10 i32(1)
|
%10 = OpTypePointer StorageClass(Output) %2
|
||||||
%12 = OpTypePointer StorageClass(Function) %10
|
%13 = OpTypeStruct %2 %2
|
||||||
%13 = OpConstant %10 i32(5)
|
%14 = OpTypePointer StorageClass(Function) %13
|
||||||
%14 = OpTypeBool
|
%15 = OpConstant %2 f32(1)
|
||||||
%15 = OpConstant %10 i32(3)
|
%16 = OpTypeInt 32 1
|
||||||
%16 = OpTypePointer StorageClass(Function) %7
|
%17 = OpConstant %16 i32(1)
|
||||||
%17 = OpConstant %10 i32(0)
|
%18 = OpConstant %16 i32(0)
|
||||||
%48 = OpTypePointer StorageClass(Function) %4
|
%11 = OpVariable %10 StorageClass(Output)
|
||||||
%6 = OpVariable %5 StorageClass(Output)
|
%12 = OpVariable %10 StorageClass(Output)
|
||||||
%18 = OpFunction %1 FunctionControl(0) %2
|
%19 = OpFunction %1 FunctionControl(0) %6
|
||||||
%19 = OpLabel
|
%21 = OpFunctionParameter %4
|
||||||
%20 = OpVariable %9 StorageClass(Function)
|
%22 = OpFunctionParameter %5
|
||||||
%21 = OpVariable %12 StorageClass(Function)
|
%23 = OpFunctionParameter %5
|
||||||
%22 = OpVariable %12 StorageClass(Function)
|
%24 = OpFunctionParameter %5
|
||||||
%23 = OpVariable %16 StorageClass(Function)
|
|
||||||
OpStore %20 %8
|
|
||||||
OpStore %21 %11
|
|
||||||
OpStore %22 %13
|
|
||||||
OpBranch %24
|
|
||||||
%24 = OpLabel
|
|
||||||
%28 = OpLoad %10 %21
|
|
||||||
%29 = OpLoad %10 %22
|
|
||||||
%30 = OpSLessThan %14 %28 %29
|
|
||||||
OpLoopMerge %26 %27 LoopControl(0)
|
|
||||||
OpBranchConditional %30 %25 %26
|
|
||||||
%25 = OpLabel
|
%25 = OpLabel
|
||||||
%34 = OpLoad %10 %21
|
%26 = OpLoad %3 %21
|
||||||
%35 = OpIEqual %14 %34 %15
|
%27 = OpVectorTimesScalar %3 %26 %7
|
||||||
OpSelectionMerge %31 SelectionControl(0)
|
OpStore %21 %27
|
||||||
OpBranchConditional %35 %32 %33
|
OpStore %22 %8
|
||||||
%32 = OpLabel
|
OpReturn
|
||||||
OpBranch %27
|
OpFunctionEnd
|
||||||
%33 = OpLabel
|
%20 = OpFunction %1 FunctionControl(0) %9
|
||||||
OpBranch %31
|
%28 = OpLabel
|
||||||
%31 = OpLabel
|
%29 = OpVariable %14 StorageClass(Function)
|
||||||
%36 = OpLoad %3 %20
|
%30 = OpVariable %4 StorageClass(Function)
|
||||||
%37 = OpLoad %10 %21
|
%31 = OpVariable %5 StorageClass(Function)
|
||||||
%38 = OpConvertSToF %3 %37
|
%32 = OpVariable %5 StorageClass(Function)
|
||||||
%39 = OpFMul %3 %36 %38
|
%33 = OpVariable %4 StorageClass(Function)
|
||||||
OpStore %20 %39
|
%34 = OpVariable %5 StorageClass(Function)
|
||||||
%40 = OpLoad %10 %21
|
%35 = OpVariable %5 StorageClass(Function)
|
||||||
%41 = OpIAdd %10 %40 %11
|
%36 = OpVariable %5 StorageClass(Function)
|
||||||
OpStore %21 %41
|
%37 = OpCompositeConstruct %3 %15 %15 %15
|
||||||
OpBranch %27
|
OpStore %30 %37
|
||||||
%27 = OpLabel
|
OpStore %31 %7
|
||||||
OpBranch %24
|
OpStore %32 %15
|
||||||
%26 = OpLabel
|
%38 = OpLoad %3 %30
|
||||||
%42 = OpLoad %3 %20
|
OpStore %33 %38
|
||||||
%43 = OpLoad %3 %20
|
%39 = OpLoad %2 %31
|
||||||
%44 = OpLoad %3 %20
|
OpStore %35 %39
|
||||||
%45 = OpLoad %3 %20
|
%40 = OpLoad %2 %32
|
||||||
%46 = OpCompositeConstruct %4 %42 %43 %44 %45
|
OpStore %36 %40
|
||||||
%47 = OpAccessChain %48 %23 %17
|
%41 = OpFunctionCall %1 %19 %33 %34 %35 %36
|
||||||
OpStore %47 %46
|
%42 = OpLoad %3 %33
|
||||||
%49 = OpLoad %7 %23
|
OpStore %30 %42
|
||||||
%50 = OpCompositeExtract %4 %49 0
|
%43 = OpLoad %2 %34
|
||||||
OpStore %6 %50
|
%44 = OpAccessChain %5 %29 %17
|
||||||
|
OpStore %44 %43
|
||||||
|
%45 = OpLoad %3 %30
|
||||||
|
%46 = OpCompositeExtract %2 %45 0
|
||||||
|
%47 = OpAccessChain %5 %29 %18
|
||||||
|
OpStore %47 %46
|
||||||
|
%48 = OpLoad %13 %29
|
||||||
|
%49 = OpCompositeExtract %2 %48 0
|
||||||
|
OpStore %11 %49
|
||||||
|
%50 = OpCompositeExtract %2 %48 1
|
||||||
|
OpStore %12 %50
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ const Decoration = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Value = union(Type) {
|
pub const Value = union(Type) {
|
||||||
Void: noreturn,
|
Void: struct {},
|
||||||
Bool: bool,
|
Bool: bool,
|
||||||
Int: extern union {
|
Int: extern union {
|
||||||
sint8: i8,
|
sint8: i8,
|
||||||
@@ -74,7 +74,7 @@ pub const Value = union(Type) {
|
|||||||
},
|
},
|
||||||
Vector: []Value,
|
Vector: []Value,
|
||||||
Matrix: []Value,
|
Matrix: []Value,
|
||||||
Array: struct {},
|
Array: []Value,
|
||||||
RuntimeArray: struct {},
|
RuntimeArray: struct {},
|
||||||
Structure: []Value,
|
Structure: []Value,
|
||||||
Function: noreturn,
|
Function: noreturn,
|
||||||
@@ -87,7 +87,7 @@ pub const Value = union(Type) {
|
|||||||
return switch (self.*) {
|
return switch (self.*) {
|
||||||
.Vector => |v| v,
|
.Vector => |v| v,
|
||||||
.Matrix => |m| m,
|
.Matrix => |m| m,
|
||||||
.Array => |_| unreachable,
|
.Array => |a| a,
|
||||||
.Structure => |s| s,
|
.Structure => |s| s,
|
||||||
else => null,
|
else => null,
|
||||||
};
|
};
|
||||||
@@ -120,8 +120,14 @@ pub const Value = union(Type) {
|
|||||||
}
|
}
|
||||||
break :blk self;
|
break :blk self;
|
||||||
},
|
},
|
||||||
.Array => |_| {
|
.Array => |a| blk: {
|
||||||
unreachable;
|
var self: Value = .{ .Array = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
||||||
|
errdefer self.deinit(allocator);
|
||||||
|
|
||||||
|
for (self.Array) |*value| {
|
||||||
|
value.* = try Value.init(allocator, results, a.components_type_word);
|
||||||
|
}
|
||||||
|
break :blk self;
|
||||||
},
|
},
|
||||||
.Structure => |s| blk: {
|
.Structure => |s| blk: {
|
||||||
var self: Value = .{ .Structure = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
var self: Value = .{ .Structure = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
||||||
@@ -155,6 +161,13 @@ pub const Value = union(Type) {
|
|||||||
break :blk values;
|
break :blk values;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
.Array => |a| .{
|
||||||
|
.Array = blk: {
|
||||||
|
const values = allocator.dupe(Value, a) catch return RuntimeError.OutOfMemory;
|
||||||
|
for (values, a) |*new_value, value| new_value.* = try value.dupe(allocator);
|
||||||
|
break :blk values;
|
||||||
|
},
|
||||||
|
},
|
||||||
.Structure => |s| .{
|
.Structure => |s| .{
|
||||||
.Structure = blk: {
|
.Structure = blk: {
|
||||||
const values = allocator.dupe(Value, s) catch return RuntimeError.OutOfMemory;
|
const values = allocator.dupe(Value, s) catch return RuntimeError.OutOfMemory;
|
||||||
@@ -176,6 +189,10 @@ pub const Value = union(Type) {
|
|||||||
for (values) |*value| value.deinit(allocator);
|
for (values) |*value| value.deinit(allocator);
|
||||||
allocator.free(values);
|
allocator.free(values);
|
||||||
},
|
},
|
||||||
|
.Array => |values| {
|
||||||
|
for (values) |*value| value.deinit(allocator);
|
||||||
|
allocator.free(values);
|
||||||
|
},
|
||||||
.Structure => |values| {
|
.Structure => |values| {
|
||||||
for (values) |*value| value.deinit(allocator);
|
for (values) |*value| value.deinit(allocator);
|
||||||
allocator.free(values);
|
allocator.free(values);
|
||||||
@@ -208,7 +225,11 @@ pub const VariantData = union(Variant) {
|
|||||||
column_type: Type,
|
column_type: Type,
|
||||||
member_count: SpvWord,
|
member_count: SpvWord,
|
||||||
},
|
},
|
||||||
Array: struct {},
|
Array: struct {
|
||||||
|
components_type_word: SpvWord,
|
||||||
|
components_type: Type,
|
||||||
|
member_count: SpvWord,
|
||||||
|
},
|
||||||
RuntimeArray: struct {},
|
RuntimeArray: struct {},
|
||||||
Structure: struct {
|
Structure: struct {
|
||||||
members_type_word: []const SpvWord,
|
members_type_word: []const SpvWord,
|
||||||
@@ -433,6 +454,7 @@ pub fn getMemberCounts(self: *const Self) usize {
|
|||||||
.Bool, .Int, .Float, .Image, .Sampler => return 1,
|
.Bool, .Int, .Float, .Image, .Sampler => return 1,
|
||||||
.Vector => |v| return v.member_count,
|
.Vector => |v| return v.member_count,
|
||||||
.Matrix => |m| return m.member_count,
|
.Matrix => |m| return m.member_count,
|
||||||
|
.Array => |a| return a.member_count,
|
||||||
.SampledImage => return 2,
|
.SampledImage => return 2,
|
||||||
.Structure => |s| return s.members.len,
|
.Structure => |s| return s.members.len,
|
||||||
.Function => |f| return f.params.len,
|
.Function => |f| return f.params.len,
|
||||||
@@ -447,6 +469,7 @@ pub fn getMemberCounts(self: *const Self) usize {
|
|||||||
pub fn initValue(allocator: std.mem.Allocator, member_count: usize, results: []const Self, resolved: *const Self) RuntimeError!Value {
|
pub fn initValue(allocator: std.mem.Allocator, member_count: usize, results: []const Self, resolved: *const Self) RuntimeError!Value {
|
||||||
return switch (resolved.variant.?) {
|
return switch (resolved.variant.?) {
|
||||||
.Type => |t| switch (t) {
|
.Type => |t| switch (t) {
|
||||||
|
.Void => .{ .Void = .{} },
|
||||||
.Bool => .{ .Bool = false },
|
.Bool => .{ .Bool = false },
|
||||||
.Int => .{ .Int = .{ .uint64 = 0 } },
|
.Int => .{ .Int = .{ .uint64 = 0 } },
|
||||||
.Float => .{ .Float = .{ .float64 = 0.0 } },
|
.Float => .{ .Float = .{ .float64 = 0.0 } },
|
||||||
@@ -466,7 +489,14 @@ pub fn initValue(allocator: std.mem.Allocator, member_count: usize, results: []c
|
|||||||
}
|
}
|
||||||
break :blk value;
|
break :blk value;
|
||||||
},
|
},
|
||||||
.Array => |_| RuntimeError.ToDo,
|
.Array => |a| blk: {
|
||||||
|
const value: Value = .{ .Array = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
||||||
|
errdefer allocator.free(value.Vector);
|
||||||
|
for (value.Array) |*val| {
|
||||||
|
val.* = try Value.init(allocator, results, a.components_type_word);
|
||||||
|
}
|
||||||
|
break :blk value;
|
||||||
|
},
|
||||||
.Structure => |s| blk: {
|
.Structure => |s| blk: {
|
||||||
const value: Value = .{ .Structure = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
const value: Value = .{ .Structure = allocator.alloc(Value, member_count) catch return RuntimeError.OutOfMemory };
|
||||||
errdefer allocator.free(value.Structure);
|
errdefer allocator.free(value.Structure);
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ pub const SetupDispatcher = block: {
|
|||||||
.SatConvertUToS = autoSetupConstant,
|
.SatConvertUToS = autoSetupConstant,
|
||||||
.Source = opSource,
|
.Source = opSource,
|
||||||
.SourceExtension = opSourceExtension,
|
.SourceExtension = opSourceExtension,
|
||||||
|
.TypeArray = opTypeArray,
|
||||||
.TypeBool = opTypeBool,
|
.TypeBool = opTypeBool,
|
||||||
.TypeFloat = opTypeFloat,
|
.TypeFloat = opTypeFloat,
|
||||||
.TypeFunction = opTypeFunction,
|
.TypeFunction = opTypeFunction,
|
||||||
@@ -505,7 +506,10 @@ fn opAccessChain(_: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) Runtim
|
|||||||
if (i.uint32 > m.len) return RuntimeError.InvalidSpirV;
|
if (i.uint32 > m.len) return RuntimeError.InvalidSpirV;
|
||||||
value_ptr = &m[i.uint32];
|
value_ptr = &m[i.uint32];
|
||||||
},
|
},
|
||||||
.Array => |_| return RuntimeError.ToDo,
|
.Array => |a| {
|
||||||
|
if (i.uint32 > a.len) return RuntimeError.InvalidSpirV;
|
||||||
|
value_ptr = &a[i.uint32];
|
||||||
|
},
|
||||||
.Structure => |s| {
|
.Structure => |s| {
|
||||||
if (i.uint32 > s.len) return RuntimeError.InvalidSpirV;
|
if (i.uint32 > s.len) return RuntimeError.InvalidSpirV;
|
||||||
value_ptr = &s[i.uint32];
|
value_ptr = &s[i.uint32];
|
||||||
@@ -866,6 +870,23 @@ fn opStore(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
|||||||
copyValue(try rt.results[ptr_id].getValue(), try rt.results[val_id].getValue());
|
copyValue(try rt.results[ptr_id].getValue(), try rt.results[val_id].getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn opTypeArray(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
|
const id = try rt.it.next();
|
||||||
|
const components_type_word = try rt.it.next();
|
||||||
|
rt.mod.results[id].variant = .{
|
||||||
|
.Type = .{
|
||||||
|
.Array = .{
|
||||||
|
.components_type_word = components_type_word,
|
||||||
|
.components_type = switch ((try rt.mod.results[components_type_word].getVariant()).*) {
|
||||||
|
.Type => |t| @as(Result.Type, t),
|
||||||
|
else => return RuntimeError.InvalidSpirV,
|
||||||
|
},
|
||||||
|
.member_count = try rt.it.next(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn opTypeBool(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
fn opTypeBool(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
const id = try rt.it.next();
|
const id = try rt.it.next();
|
||||||
rt.mod.results[id].variant = .{
|
rt.mod.results[id].variant = .{
|
||||||
@@ -1076,9 +1097,6 @@ fn setupConstant(allocator: std.mem.Allocator, rt: *Runtime) RuntimeError!*Resul
|
|||||||
|
|
||||||
const resolved = rt.mod.results[res_type].resolveType(rt.mod.results);
|
const resolved = rt.mod.results[res_type].resolveType(rt.mod.results);
|
||||||
const member_count = resolved.getMemberCounts();
|
const member_count = resolved.getMemberCounts();
|
||||||
if (member_count == 0) {
|
|
||||||
return RuntimeError.InvalidSpirV;
|
|
||||||
}
|
|
||||||
target.variant = .{
|
target.variant = .{
|
||||||
.Constant = .{
|
.Constant = .{
|
||||||
.value = try Result.initValue(allocator, member_count, rt.mod.results, resolved),
|
.value = try Result.initValue(allocator, member_count, rt.mod.results, resolved),
|
||||||
|
|||||||
30
test/arrays.zig
git.filemode.normal_file
30
test/arrays.zig
git.filemode.normal_file
@@ -0,0 +1,30 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const root = @import("root.zig");
|
||||||
|
const compileNzsl = root.compileNzsl;
|
||||||
|
const case = root.case;
|
||||||
|
|
||||||
|
test "Simple array" {
|
||||||
|
const allocator = std.testing.allocator;
|
||||||
|
const shader =
|
||||||
|
\\ [nzsl_version("1.1")]
|
||||||
|
\\ module;
|
||||||
|
\\
|
||||||
|
\\ struct FragOut
|
||||||
|
\\ {
|
||||||
|
\\ [location(0)] color: vec4[f32]
|
||||||
|
\\ }
|
||||||
|
\\
|
||||||
|
\\ [entry(frag)]
|
||||||
|
\\ fn main() -> FragOut
|
||||||
|
\\ {
|
||||||
|
\\ let value = array[f32](4.0, 3.0, 2.0, 1.0);
|
||||||
|
\\ let output: FragOut;
|
||||||
|
\\ output.color = vec4[f32](value[0], value[1], value[2], value[3]);
|
||||||
|
\\ return output;
|
||||||
|
\\ }
|
||||||
|
;
|
||||||
|
const code = try compileNzsl(allocator, shader);
|
||||||
|
defer allocator.free(code);
|
||||||
|
|
||||||
|
try case.expectOutput(f32, 4, code, "color", &.{ 4, 3, 2, 1 });
|
||||||
|
}
|
||||||
@@ -3,51 +3,6 @@ const root = @import("root.zig");
|
|||||||
const compileNzsl = root.compileNzsl;
|
const compileNzsl = root.compileNzsl;
|
||||||
const case = root.case;
|
const case = root.case;
|
||||||
|
|
||||||
test "Simple for loop" {
|
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
const base = @mod(case.random(f32), 5.0);
|
|
||||||
const iterations = 5;
|
|
||||||
|
|
||||||
var expected = base;
|
|
||||||
for (1..iterations) |i| {
|
|
||||||
expected *= @floatFromInt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
const shader = try std.fmt.allocPrint(
|
|
||||||
allocator,
|
|
||||||
\\ [nzsl_version("1.1")]
|
|
||||||
\\ [feature(float64)]
|
|
||||||
\\ module;
|
|
||||||
\\
|
|
||||||
\\ struct FragOut
|
|
||||||
\\ {{
|
|
||||||
\\ [location(0)] color: vec4[f32]
|
|
||||||
\\ }}
|
|
||||||
\\
|
|
||||||
\\ [entry(frag)]
|
|
||||||
\\ fn main() -> FragOut
|
|
||||||
\\ {{
|
|
||||||
\\ let value = f32({d});
|
|
||||||
\\ for i in 1 -> {d}
|
|
||||||
\\ {{
|
|
||||||
\\ value *= f32(i);
|
|
||||||
\\ }}
|
|
||||||
\\ let output: FragOut;
|
|
||||||
\\ output.color = vec4[f32](value, value, value, value);
|
|
||||||
\\ return output;
|
|
||||||
\\ }}
|
|
||||||
,
|
|
||||||
.{
|
|
||||||
base,
|
|
||||||
iterations,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
defer allocator.free(shader);
|
|
||||||
const code = try compileNzsl(allocator, shader);
|
|
||||||
defer allocator.free(code);
|
|
||||||
try case.expectOutput(f32, 4, code, "color", &.{ expected, expected, expected, expected });
|
|
||||||
}
|
|
||||||
|
|
||||||
test "Simple while loop" {
|
test "Simple while loop" {
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
const base = @mod(case.random(f32), 5.0);
|
const base = @mod(case.random(f32), 5.0);
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ pub const case = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
std.testing.refAllDecls(@import("arrays.zig"));
|
||||||
std.testing.refAllDecls(@import("basics.zig"));
|
std.testing.refAllDecls(@import("basics.zig"));
|
||||||
std.testing.refAllDecls(@import("branching.zig"));
|
std.testing.refAllDecls(@import("branching.zig"));
|
||||||
std.testing.refAllDecls(@import("casts.zig"));
|
std.testing.refAllDecls(@import("casts.zig"));
|
||||||
|
|||||||
Reference in New Issue
Block a user