fixing recurrent panic
All checks were successful
Build / build (push) Successful in 2m14s
Test / build (push) Successful in 7m13s

This commit is contained in:
2026-01-27 22:55:02 +01:00
parent 1ad7b644c4
commit 57de432d0b
7 changed files with 639 additions and 304 deletions

View File

@@ -18,11 +18,6 @@ pub fn build(b: *std.Build) void {
const pretty = b.dependency("pretty", .{ .target = target, .optimize = optimize }); const pretty = b.dependency("pretty", .{ .target = target, .optimize = optimize });
mod.addImport("pretty", pretty.module("pretty")); mod.addImport("pretty", pretty.module("pretty"));
var it = b.user_input_options.iterator();
while (it.next()) |entry| {
std.debug.print("{s} - {s} {any}", .{ entry.key_ptr.*, entry.value_ptr.name, entry.value_ptr.used });
}
const lib = b.addLibrary(.{ const lib = b.addLibrary(.{
.name = "spirv_interpreter", .name = "spirv_interpreter",
.root_module = mod, .root_module = mod,

View File

@@ -15,27 +15,27 @@ pub fn main() !void {
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{}); var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
defer module.deinit(allocator); defer module.deinit(allocator);
//var rt = try spv.Runtime.init(allocator, &module); var rt = try spv.Runtime.init(allocator, &module);
//defer rt.deinit(allocator); defer rt.deinit(allocator);
//const entry = try rt.getEntryPointByName("main"); const entry = try rt.getEntryPointByName("main");
//const color = try rt.getResultByName("color"); const color = try rt.getResultByName("color");
//const time = try rt.getResultByName("time"); const time = try rt.getResultByName("time");
//const pos = try rt.getResultByName("pos"); const pos = try rt.getResultByName("pos");
//const res = try rt.getResultByName("res"); const res = try rt.getResultByName("res");
//var output: [4]f32 = undefined; var output: [4]f32 = undefined;
//try rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time); try rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time);
//try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res); try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res);
//try rt.writeInput(f32, &.{ 0.0, 0.0 }, pos); try rt.writeInput(f32, &.{ 0.0, 0.0 }, pos);
//try rt.callEntryPoint(allocator, entry); try rt.callEntryPoint(allocator, entry);
//try rt.readOutput(f32, output[0..output.len], color); try rt.readOutput(f32, output[0..output.len], color);
//std.log.info("Output: Vec4{any}", .{output}); std.log.info("Output: Vec4{any}", .{output});
std.log.info("Total memory used: {d:.3} MB\n", .{@as(f32, @floatFromInt(gpa.total_requested_bytes)) / 1000.0}); std.log.info("\nTotal memory used: {d:.3} KB\n", .{@as(f32, @floatFromInt(gpa.total_requested_bytes)) / 1000.0});
} }
std.log.info("Successfully executed", .{}); std.log.info("Successfully executed", .{});
} }

Binary file not shown.

View File

@@ -1,281 +1,604 @@
Version 1.0 ; SPIR-V
Generator: 2560130 ; Version: 1.0
Bound: 203 ; Generator: Khronos Glslang Reference Front End; 11
Schema: 0 ; Bound: 408
OpCapability Capability(Shader) ; Schema: 0
%42 = OpExtInstImport "GLSL.std.450" OpCapability Shader
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450) %1 = OpExtInstImport "GLSL.std.450"
OpEntryPoint ExecutionModel(Fragment) %43 "main" %5 %11 %14 %20 OpMemoryModel Logical GLSL450
OpExecutionMode %43 ExecutionMode(OriginUpperLeft) OpEntryPoint Vertex %4 "main" %312 %314 %406
OpSource SourceLanguage(NZSL) 4198400 OpDecorate %11 RelaxedPrecision
OpSourceExtension "Version: 1.1" OpDecorate %18 RelaxedPrecision
OpName %16 "FragIn" OpDecorate %25 RelaxedPrecision
OpMemberName %16 0 "time" OpDecorate %32 RelaxedPrecision
OpMemberName %16 1 "res" OpDecorate %39 RelaxedPrecision
OpMemberName %16 2 "pos" OpDecorate %46 RelaxedPrecision
OpName %21 "FragOut" OpDecorate %53 RelaxedPrecision
OpMemberName %21 0 "color" OpDecorate %61 RelaxedPrecision
OpName %5 "time" OpDecorate %69 RelaxedPrecision
OpName %11 "res" OpDecorate %76 RelaxedPrecision
OpName %14 "pos" OpDecorate %84 RelaxedPrecision
OpName %20 "color" OpDecorate %104 RelaxedPrecision
OpName %43 "main" OpDecorate %112 RelaxedPrecision
OpDecorate %5 Decoration(Location) 0 OpDecorate %113 RelaxedPrecision
OpDecorate %11 Decoration(Location) 1 OpDecorate %122 RelaxedPrecision
OpDecorate %14 Decoration(Location) 2 OpDecorate %129 RelaxedPrecision
OpDecorate %20 Decoration(Location) 0 OpDecorate %130 RelaxedPrecision
OpMemberDecorate %16 0 Decoration(Offset) 0 OpDecorate %138 RelaxedPrecision
OpMemberDecorate %16 1 Decoration(Offset) 8 OpDecorate %139 RelaxedPrecision
OpMemberDecorate %16 2 Decoration(Offset) 16 OpDecorate %148 RelaxedPrecision
OpMemberDecorate %21 0 Decoration(Offset) 0 OpDecorate %155 RelaxedPrecision
%1 = OpTypeVoid OpDecorate %156 RelaxedPrecision
%2 = OpTypeFunction %1 OpDecorate %163 RelaxedPrecision
%3 = OpTypeFloat 32 OpDecorate %164 RelaxedPrecision
%4 = OpTypePointer StorageClass(Input) %3 OpDecorate %172 RelaxedPrecision
%6 = OpTypeInt 32 1 OpDecorate %173 RelaxedPrecision
%7 = OpConstant %6 i32(0) OpDecorate %183 RelaxedPrecision
%8 = OpTypePointer StorageClass(Function) %3 OpDecorate %191 RelaxedPrecision
%9 = OpTypeVector %3 2 OpDecorate %192 RelaxedPrecision
%10 = OpTypePointer StorageClass(Input) %9 OpDecorate %200 RelaxedPrecision
%12 = OpConstant %6 i32(1) OpDecorate %201 RelaxedPrecision
%13 = OpTypePointer StorageClass(Function) %9 OpDecorate %209 RelaxedPrecision
%15 = OpConstant %6 i32(2) OpDecorate %210 RelaxedPrecision
%16 = OpTypeStruct %3 %9 %9 OpDecorate %219 RelaxedPrecision
%17 = OpTypePointer StorageClass(Function) %16 OpDecorate %226 RelaxedPrecision
%18 = OpTypeVector %3 4 OpDecorate %227 RelaxedPrecision
%19 = OpTypePointer StorageClass(Output) %18 OpDecorate %234 RelaxedPrecision
%21 = OpTypeStruct %18 OpDecorate %235 RelaxedPrecision
%22 = OpConstant %3 f32(2) OpDecorate %242 RelaxedPrecision
%23 = OpConstant %3 f32(1) OpDecorate %243 RelaxedPrecision
%24 = OpConstant %3 f32(0) OpDecorate %252 RelaxedPrecision
%25 = OpTypeVector %3 3 OpDecorate %259 RelaxedPrecision
%26 = OpTypePointer StorageClass(Function) %25 OpDecorate %260 RelaxedPrecision
%27 = OpConstant %3 f32(-2) OpDecorate %267 RelaxedPrecision
%28 = OpConstant %3 f32(-1) OpDecorate %268 RelaxedPrecision
%29 = OpConstant %3 f32(0.2) OpDecorate %275 RelaxedPrecision
%30 = OpConstant %3 f32(4) OpDecorate %276 RelaxedPrecision
%31 = OpTypePointer StorageClass(Function) %6 OpDecorate %_struct_310 Block
%32 = OpConstant %6 i32(128) OpMemberDecorate %_struct_310 0 BuiltIn Position
%33 = OpTypeBool OpMemberDecorate %_struct_310 1 BuiltIn PointSize
%34 = OpConstant %3 f32(0.001) OpMemberDecorate %_struct_310 2 BuiltIn ClipDistance
%35 = OpConstant %3 f32(0.35) OpMemberDecorate %_struct_310 3 BuiltIn CullDistance
%36 = OpConstant %3 f32(100) OpDecorate %314 Location 0
%37 = OpConstant %3 f32(0.15) OpDecorate %318 RelaxedPrecision
%38 = OpConstant %3 f32(0.05) OpDecorate %_arr_mat2v3float_uint_3 ArrayStride 48
%39 = OpConstant %3 f32(1.15) OpDecorate %_struct_322 Block
%40 = OpConstant %3 f32(7.5) OpMemberDecorate %_struct_322 0 Offset 0
%41 = OpTypePointer StorageClass(Function) %21 OpMemberDecorate %_struct_322 1 RelaxedPrecision
%200 = OpTypePointer StorageClass(Function) %18 OpMemberDecorate %_struct_322 1 Offset 16
%5 = OpVariable %4 StorageClass(Input) OpMemberDecorate %_struct_322 2 RowMajor
%11 = OpVariable %10 StorageClass(Input) OpMemberDecorate %_struct_322 2 MatrixStride 16
%14 = OpVariable %10 StorageClass(Input) OpMemberDecorate %_struct_322 2 Offset 32
%20 = OpVariable %19 StorageClass(Output) OpMemberDecorate %_struct_322 3 RowMajor
%43 = OpFunction %1 FunctionControl(0) %2 OpMemberDecorate %_struct_322 3 MatrixStride 16
%44 = OpLabel OpMemberDecorate %_struct_322 3 Offset 64
%45 = OpVariable %13 StorageClass(Function) OpDecorate %324 Binding 0
%46 = OpVariable %13 StorageClass(Function) OpDecorate %324 DescriptorSet 0
%47 = OpVariable %26 StorageClass(Function) OpDecorate %334 RelaxedPrecision
%48 = OpVariable %26 StorageClass(Function) OpDecorate %335 RelaxedPrecision
%49 = OpVariable %26 StorageClass(Function) OpDecorate %336 RelaxedPrecision
%50 = OpVariable %8 StorageClass(Function) OpDecorate %341 RelaxedPrecision
%51 = OpVariable %8 StorageClass(Function) OpDecorate %343 RelaxedPrecision
%52 = OpVariable %8 StorageClass(Function) OpDecorate %344 RelaxedPrecision
%53 = OpVariable %26 StorageClass(Function) OpDecorate %345 RelaxedPrecision
%54 = OpVariable %26 StorageClass(Function) OpDecorate %353 RelaxedPrecision
%55 = OpVariable %26 StorageClass(Function) OpDecorate %354 RelaxedPrecision
%56 = OpVariable %31 StorageClass(Function) OpDecorate %355 RelaxedPrecision
%57 = OpVariable %31 StorageClass(Function) OpDecorate %_struct_356 Block
%58 = OpVariable %8 StorageClass(Function) OpMemberDecorate %_struct_356 0 RelaxedPrecision
%59 = OpVariable %8 StorageClass(Function) OpMemberDecorate %_struct_356 0 Offset 0
%60 = OpVariable %41 StorageClass(Function) OpDecorate %358 Binding 1
%61 = OpVariable %17 StorageClass(Function) OpDecorate %358 DescriptorSet 0
%62 = OpAccessChain %8 %61 %7 OpDecorate %363 RelaxedPrecision
OpCopyMemory %62 %5 OpDecorate %365 RelaxedPrecision
%63 = OpAccessChain %13 %61 %12 OpDecorate %366 RelaxedPrecision
OpCopyMemory %63 %11 OpDecorate %367 RelaxedPrecision
%64 = OpAccessChain %13 %61 %15 OpDecorate %_struct_368 Block
OpCopyMemory %64 %14 OpMemberDecorate %_struct_368 0 RelaxedPrecision
%65 = OpAccessChain %13 %61 %15 OpMemberDecorate %_struct_368 0 Offset 0
%66 = OpLoad %9 %65 OpDecorate %370 Binding 2
%67 = OpAccessChain %13 %61 %12 OpDecorate %370 DescriptorSet 0
%68 = OpLoad %9 %67 OpDecorate %375 RelaxedPrecision
%69 = OpFDiv %9 %66 %68 OpDecorate %377 RelaxedPrecision
%70 = OpVectorTimesScalar %9 %69 %22 OpDecorate %378 RelaxedPrecision
%71 = OpCompositeConstruct %9 %23 %23 OpDecorate %379 RelaxedPrecision
%72 = OpFSub %9 %70 %71 OpDecorate %_struct_382 Block
OpStore %45 %72 OpMemberDecorate %_struct_382 0 ColMajor
%73 = OpLoad %9 %45 OpMemberDecorate %_struct_382 0 MatrixStride 16
%74 = OpCompositeExtract %3 %73 0 OpMemberDecorate %_struct_382 0 Offset 0
%75 = OpAccessChain %13 %61 %12 OpMemberDecorate %_struct_382 1 Offset 48
%76 = OpLoad %9 %75 OpMemberDecorate %_struct_382 2 RelaxedPrecision
%77 = OpCompositeExtract %3 %76 0 OpMemberDecorate %_struct_382 2 ColMajor
%78 = OpAccessChain %13 %61 %12 OpMemberDecorate %_struct_382 2 MatrixStride 16
%79 = OpLoad %9 %78 OpMemberDecorate %_struct_382 2 Offset 64
%80 = OpCompositeExtract %3 %79 1 OpMemberDecorate %_struct_382 3 RelaxedPrecision
%81 = OpFDiv %3 %77 %80 OpMemberDecorate %_struct_382 3 ColMajor
%82 = OpFMul %3 %74 %81 OpMemberDecorate %_struct_382 3 MatrixStride 16
%83 = OpLoad %9 %45 OpMemberDecorate %_struct_382 3 Offset 128
%84 = OpCompositeExtract %3 %83 1 OpDecorate %384 Binding 3
%85 = OpCompositeConstruct %9 %82 %84 OpDecorate %384 DescriptorSet 0
OpStore %46 %85 OpDecorate %390 RelaxedPrecision
%86 = OpCompositeConstruct %25 %24 %24 %24 OpDecorate %392 RelaxedPrecision
OpStore %47 %86 OpDecorate %393 RelaxedPrecision
%87 = OpCompositeConstruct %25 %24 %24 %27 OpDecorate %394 RelaxedPrecision
OpStore %48 %87 OpDecorate %400 RelaxedPrecision
%88 = OpLoad %9 %46 OpDecorate %402 RelaxedPrecision
%89 = OpCompositeExtract %3 %88 0 OpDecorate %403 RelaxedPrecision
%90 = OpLoad %9 %46 OpDecorate %404 RelaxedPrecision
%91 = OpCompositeExtract %3 %90 1 OpDecorate %406 RelaxedPrecision
%92 = OpCompositeConstruct %25 %89 %91 %23 OpDecorate %406 Location 0
OpStore %49 %92 OpDecorate %407 RelaxedPrecision
OpStore %50 %24 %void = OpTypeVoid
OpStore %51 %24 %3 = OpTypeFunction %void
OpStore %52 %28 %float = OpTypeFloat 32
%93 = OpLoad %25 %48 %_ptr_Function_float = OpTypePointer Function %float
OpStore %53 %93 %8 = OpTypeFunction %float %_ptr_Function_float %_ptr_Function_float
%94 = OpCompositeConstruct %25 %24 %24 %24 %v2float = OpTypeVector %float 2
OpStore %54 %94 %_ptr_Function_v2float = OpTypePointer Function %v2float
%95 = OpAccessChain %8 %61 %7 %15 = OpTypeFunction %float %_ptr_Function_v2float %_ptr_Function_v2float
%96 = OpLoad %3 %95 %v3float = OpTypeVector %float 3
%97 = OpFMul %3 %96 %29 %_ptr_Function_v3float = OpTypePointer Function %v3float
%98 = OpExtInst %3 GLSLstd450 Sin %97 %22 = OpTypeFunction %float %_ptr_Function_v3float %_ptr_Function_v3float
%99 = OpFMul %3 %98 %30 %v4float = OpTypeVector %float 4
%100 = OpAccessChain %8 %61 %7 %_ptr_Function_v4float = OpTypePointer Function %v4float
%101 = OpLoad %3 %100 %29 = OpTypeFunction %float %_ptr_Function_v4float %_ptr_Function_v4float
%102 = OpFMul %3 %101 %29 %mat4v2float = OpTypeMatrix %v2float 4
%103 = OpExtInst %3 GLSLstd450 Cos %102 %_ptr_Function_mat4v2float = OpTypePointer Function %mat4v2float
%104 = OpFMul %3 %103 %30 %36 = OpTypeFunction %float %_ptr_Function_mat4v2float %_ptr_Function_mat4v2float
%105 = OpCompositeConstruct %25 %24 %99 %104 %mat4v3float = OpTypeMatrix %v3float 4
OpStore %55 %105 %_ptr_Function_mat4v3float = OpTypePointer Function %mat4v3float
OpStore %56 %7 %43 = OpTypeFunction %float %_ptr_Function_mat4v3float %_ptr_Function_mat4v3float
OpStore %57 %32 %mat4v4float = OpTypeMatrix %v4float 4
OpBranch %106 %_ptr_Function_mat4v4float = OpTypePointer Function %mat4v4float
%106 = OpLabel %50 = OpTypeFunction %float %_ptr_Function_mat4v4float %_ptr_Function_mat4v4float
%110 = OpLoad %6 %56 %int = OpTypeInt 32 1
%111 = OpLoad %6 %57 %v2int = OpTypeVector %int 2
%112 = OpSLessThan %33 %110 %111 %_ptr_Function_v2int = OpTypePointer Function %v2int
OpLoopMerge %108 %109 LoopControl(0) %58 = OpTypeFunction %float %_ptr_Function_v2int %_ptr_Function_v2int
OpBranchConditional %112 %107 %108 %uint = OpTypeInt 32 0
%107 = OpLabel %v2uint = OpTypeVector %uint 2
%113 = OpLoad %25 %48 %_ptr_Function_v2uint = OpTypePointer Function %v2uint
%114 = OpLoad %25 %49 %66 = OpTypeFunction %float %_ptr_Function_v2uint %_ptr_Function_v2uint
%115 = OpLoad %3 %50 %v4uint = OpTypeVector %uint 4
%116 = OpVectorTimesScalar %25 %114 %115 %_ptr_Function_v4uint = OpTypePointer Function %v4uint
%117 = OpFAdd %25 %113 %116 %73 = OpTypeFunction %float %_ptr_Function_v4uint %_ptr_Function_v4uint
OpStore %53 %117 %bool = OpTypeBool
%118 = OpLoad %25 %54 %v3bool = OpTypeVector %bool 3
%119 = OpLoad %25 %53 %_ptr_Function_v3bool = OpTypePointer Function %v3bool
%120 = OpFSub %25 %118 %119 %81 = OpTypeFunction %float %_ptr_Function_v3bool %_ptr_Function_v3bool
%121 = OpExtInst %3 GLSLstd450 Length %120 %float_0_0500000007 = OpConstant %float 0.0500000007
%122 = OpFSub %3 %121 %23 %float_1 = OpConstant %float 1
OpStore %51 %122 %float_0 = OpConstant %float 0
%123 = OpLoad %3 %50 %uint_0 = OpConstant %uint 0
%124 = OpLoad %3 %51 %uint_1 = OpConstant %uint 1
%125 = OpFAdd %3 %123 %124 %uint_2 = OpConstant %uint 2
OpStore %50 %125 %uint_3 = OpConstant %uint 3
%129 = OpLoad %3 %52 %int_0 = OpConstant %int 0
%130 = OpFOrdEqual %33 %129 %28 %int_1 = OpConstant %int 1
%131 = OpLoad %3 %51 %int_2 = OpConstant %int 2
%132 = OpLoad %3 %52 %int_3 = OpConstant %int 3
%133 = OpFOrdLessThan %33 %131 %132 %v2bool = OpTypeVector %bool 2
%134 = OpLogicalOr %33 %130 %133 %v4bool = OpTypeVector %bool 4
OpSelectionMerge %126 SelectionControl(0) %_arr_float_uint_1 = OpTypeArray %float %uint_1
OpBranchConditional %134 %127 %128 %_struct_310 = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%127 = OpLabel %_ptr_Output__struct_310 = OpTypePointer Output %_struct_310
%135 = OpLoad %3 %51 %312 = OpVariable %_ptr_Output__struct_310 Output
OpStore %52 %135 %_ptr_Input_v4float = OpTypePointer Input %v4float
OpBranch %126 %314 = OpVariable %_ptr_Input_v4float Input
%128 = OpLabel %_ptr_Output_v4float = OpTypePointer Output %v4float
OpBranch %126 %v3uint = OpTypeVector %uint 3
%126 = OpLabel %mat2v3float = OpTypeMatrix %v3float 2
%139 = OpLoad %3 %51 %_arr_mat2v3float_uint_3 = OpTypeArray %mat2v3float %uint_3
%140 = OpFOrdLessThanEqual %33 %139 %34 %_struct_322 = OpTypeStruct %v3uint %v2uint %mat4v2float %_arr_mat2v3float_uint_3
OpSelectionMerge %136 SelectionControl(0) %_ptr_Uniform__struct_322 = OpTypePointer Uniform %_struct_322
OpBranchConditional %140 %137 %138 %324 = OpVariable %_ptr_Uniform__struct_322 Uniform
%137 = OpLabel %false = OpConstantFalse %bool
%141 = OpLoad %25 %54 %326 = OpConstantComposite %v3bool %false %false %false
%142 = OpLoad %25 %53 %_ptr_Uniform_v3uint = OpTypePointer Uniform %v3uint
%143 = OpFSub %25 %141 %142 %331 = OpConstantComposite %v3uint %uint_0 %uint_0 %uint_0
%144 = OpExtInst %25 GLSLstd450 Normalize %143 %337 = OpConstantComposite %v2uint %uint_0 %uint_0
%145 = OpLoad %25 %53 %_ptr_Uniform_v2uint = OpTypePointer Uniform %v2uint
%146 = OpLoad %25 %55 %346 = OpConstantComposite %v2float %float_0 %float_0
%147 = OpFSub %25 %145 %146 %347 = OpConstantComposite %mat4v2float %346 %346 %346 %346
%148 = OpExtInst %25 GLSLstd450 Normalize %147 %_ptr_Uniform_mat4v2float = OpTypePointer Uniform %mat4v2float
%149 = OpDot %3 %144 %148 %_struct_356 = OpTypeStruct %v2int
%150 = OpFSub %3 %149 %35 %_ptr_Uniform__struct_356 = OpTypePointer Uniform %_struct_356
%151 = OpExtInst %3 GLSLstd450 FMax %150 %24 %358 = OpVariable %_ptr_Uniform__struct_356 Uniform
OpStore %58 %151 %359 = OpConstantComposite %v2int %int_0 %int_0
%152 = OpLoad %3 %58 %_ptr_Uniform_v2int = OpTypePointer Uniform %v2int
%153 = OpLoad %3 %58 %_struct_368 = OpTypeStruct %v4uint
%154 = OpLoad %3 %58 %_ptr_Uniform__struct_368 = OpTypePointer Uniform %_struct_368
%155 = OpCompositeConstruct %25 %152 %153 %154 %370 = OpVariable %_ptr_Uniform__struct_368 Uniform
OpStore %47 %155 %371 = OpConstantComposite %v4uint %uint_0 %uint_0 %uint_0 %uint_0
OpBranch %108 %_ptr_Uniform_v4uint = OpTypePointer Uniform %v4uint
%138 = OpLabel %mat3v3float = OpTypeMatrix %v3float 3
OpBranch %136 %v3int = OpTypeVector %int 3
%136 = OpLabel %_struct_382 = OpTypeStruct %mat3v3float %v3int %mat4v4float %mat4v3float
%159 = OpLoad %3 %51 %_ptr_Uniform__struct_382 = OpTypePointer Uniform %_struct_382
%160 = OpFOrdGreaterThanEqual %33 %159 %36 %384 = OpVariable %_ptr_Uniform__struct_382 Uniform
OpSelectionMerge %156 SelectionControl(0) %385 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
OpBranchConditional %160 %157 %158 %386 = OpConstantComposite %mat4v4float %385 %385 %385 %385
%157 = OpLabel %_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
%164 = OpLoad %25 %49 %395 = OpConstantComposite %v3float %float_0 %float_0 %float_0
%165 = OpExtInst %25 GLSLstd450 Normalize %164 %396 = OpConstantComposite %mat4v3float %395 %395 %395 %395
%166 = OpLoad %25 %55 %_ptr_Uniform_mat4v3float = OpTypePointer Uniform %mat4v3float
%167 = OpLoad %25 %48 %_ptr_Output_float = OpTypePointer Output %float
%168 = OpFSub %25 %166 %167 %406 = OpVariable %_ptr_Output_float Output
%169 = OpExtInst %25 GLSLstd450 Normalize %168 %4 = OpFunction %void None %3
%170 = OpDot %3 %165 %169 %5 = OpLabel
%171 = OpFOrdLessThanEqual %33 %170 %23 %318 = OpVariable %_ptr_Function_float Function
OpSelectionMerge %161 SelectionControl(0) %327 = OpVariable %_ptr_Function_v3bool Function
OpBranchConditional %171 %162 %163 %333 = OpVariable %_ptr_Function_v3bool Function
%162 = OpLabel %338 = OpVariable %_ptr_Function_v2uint Function
%172 = OpLoad %25 %49 %342 = OpVariable %_ptr_Function_v2uint Function
%173 = OpExtInst %25 GLSLstd450 Normalize %172 %348 = OpVariable %_ptr_Function_mat4v2float Function
%174 = OpLoad %25 %55 %352 = OpVariable %_ptr_Function_mat4v2float Function
%175 = OpLoad %25 %48 %360 = OpVariable %_ptr_Function_v2int Function
%176 = OpFSub %25 %174 %175 %364 = OpVariable %_ptr_Function_v2int Function
%177 = OpExtInst %25 GLSLstd450 Normalize %176 %372 = OpVariable %_ptr_Function_v4uint Function
%178 = OpDot %3 %173 %177 %376 = OpVariable %_ptr_Function_v4uint Function
%179 = OpFAdd %3 %178 %37 %387 = OpVariable %_ptr_Function_mat4v4float Function
%180 = OpExtInst %3 GLSLstd450 FMax %179 %38 %391 = OpVariable %_ptr_Function_mat4v4float Function
%181 = OpFDiv %3 %180 %39 %397 = OpVariable %_ptr_Function_mat4v3float Function
%182 = OpLoad %3 %52 %401 = OpVariable %_ptr_Function_mat4v3float Function
%183 = OpFMul %3 %182 %40 %315 = OpLoad %v4float %314
%184 = OpFSub %3 %23 %183 %317 = OpAccessChain %_ptr_Output_v4float %312 %int_0
%185 = OpFMul %3 %181 %184 OpStore %317 %315
OpStore %59 %185 OpStore %318 %float_1
%186 = OpLoad %3 %59 %329 = OpAccessChain %_ptr_Uniform_v3uint %324 %int_0
%187 = OpLoad %3 %59 %330 = OpLoad %v3uint %329
%188 = OpLoad %3 %59 %332 = OpINotEqual %v3bool %330 %331
%189 = OpCompositeConstruct %25 %186 %187 %188 OpStore %327 %332
OpStore %47 %189 OpStore %333 %326
OpBranch %161 %334 = OpFunctionCall %float %84 %327 %333
%163 = OpLabel %335 = OpLoad %float %318
OpBranch %161 %336 = OpFMul %float %335 %334
%161 = OpLabel OpStore %318 %336
OpBranch %108 %340 = OpAccessChain %_ptr_Uniform_v2uint %324 %int_1
%158 = OpLabel %341 = OpLoad %v2uint %340
OpBranch %156 OpStore %338 %341
%156 = OpLabel OpStore %342 %337
%190 = OpLoad %6 %56 %343 = OpFunctionCall %float %69 %338 %342
%191 = OpIAdd %6 %190 %12 %344 = OpLoad %float %318
OpStore %56 %191 %345 = OpFMul %float %344 %343
OpBranch %109 OpStore %318 %345
%109 = OpLabel %350 = OpAccessChain %_ptr_Uniform_mat4v2float %324 %int_2
OpBranch %106 %351 = OpLoad %mat4v2float %350
%108 = OpLabel OpStore %348 %351
%192 = OpLoad %25 %47 OpStore %352 %347
%193 = OpCompositeExtract %3 %192 0 %353 = OpFunctionCall %float %39 %348 %352
%194 = OpLoad %25 %47 %354 = OpLoad %float %318
%195 = OpCompositeExtract %3 %194 1 %355 = OpFMul %float %354 %353
%196 = OpLoad %25 %47 OpStore %318 %355
%197 = OpCompositeExtract %3 %196 2 %362 = OpAccessChain %_ptr_Uniform_v2int %358 %int_0
%198 = OpCompositeConstruct %18 %193 %195 %197 %23 %363 = OpLoad %v2int %362
%199 = OpAccessChain %200 %60 %7 OpStore %360 %363
OpStore %199 %198 OpStore %364 %359
%201 = OpLoad %21 %60 %365 = OpFunctionCall %float %61 %360 %364
%202 = OpCompositeExtract %18 %201 0 %366 = OpLoad %float %318
OpStore %20 %202 %367 = OpFMul %float %366 %365
OpReturn OpStore %318 %367
OpFunctionEnd %374 = OpAccessChain %_ptr_Uniform_v4uint %370 %int_0
%375 = OpLoad %v4uint %374
OpStore %372 %375
OpStore %376 %371
%377 = OpFunctionCall %float %76 %372 %376
%378 = OpLoad %float %318
%379 = OpFMul %float %378 %377
OpStore %318 %379
%389 = OpAccessChain %_ptr_Uniform_mat4v4float %384 %int_2
%390 = OpLoad %mat4v4float %389
OpStore %387 %390
OpStore %391 %386
%392 = OpFunctionCall %float %53 %387 %391
%393 = OpLoad %float %318
%394 = OpFMul %float %393 %392
OpStore %318 %394
%399 = OpAccessChain %_ptr_Uniform_mat4v3float %384 %int_3
%400 = OpLoad %mat4v3float %399
OpStore %397 %400
OpStore %401 %396
%402 = OpFunctionCall %float %46 %397 %401
%403 = OpLoad %float %318
%404 = OpFMul %float %403 %402
OpStore %318 %404
%407 = OpLoad %float %318
OpStore %406 %407
OpReturn
OpFunctionEnd
%11 = OpFunction %float None %8
%9 = OpFunctionParameter %_ptr_Function_float
%10 = OpFunctionParameter %_ptr_Function_float
%12 = OpLabel
%86 = OpLoad %float %9
%87 = OpLoad %float %10
%88 = OpFSub %float %86 %87
%89 = OpExtInst %float %1 FAbs %88
%91 = OpFOrdLessThan %bool %89 %float_0_0500000007
%94 = OpSelect %float %91 %float_1 %float_0
OpReturnValue %94
OpFunctionEnd
%18 = OpFunction %float None %15
%16 = OpFunctionParameter %_ptr_Function_v2float
%17 = OpFunctionParameter %_ptr_Function_v2float
%19 = OpLabel
%97 = OpVariable %_ptr_Function_float Function
%101 = OpVariable %_ptr_Function_float Function
%105 = OpVariable %_ptr_Function_float Function
%109 = OpVariable %_ptr_Function_float Function
%99 = OpAccessChain %_ptr_Function_float %16 %uint_0
%100 = OpLoad %float %99
OpStore %97 %100
%102 = OpAccessChain %_ptr_Function_float %17 %uint_0
%103 = OpLoad %float %102
OpStore %101 %103
%104 = OpFunctionCall %float %11 %97 %101
%107 = OpAccessChain %_ptr_Function_float %16 %uint_1
%108 = OpLoad %float %107
OpStore %105 %108
%110 = OpAccessChain %_ptr_Function_float %17 %uint_1
%111 = OpLoad %float %110
OpStore %109 %111
%112 = OpFunctionCall %float %11 %105 %109
%113 = OpFMul %float %104 %112
OpReturnValue %113
OpFunctionEnd
%25 = OpFunction %float None %22
%23 = OpFunctionParameter %_ptr_Function_v3float
%24 = OpFunctionParameter %_ptr_Function_v3float
%26 = OpLabel
%116 = OpVariable %_ptr_Function_float Function
%119 = OpVariable %_ptr_Function_float Function
%123 = OpVariable %_ptr_Function_float Function
%126 = OpVariable %_ptr_Function_float Function
%131 = OpVariable %_ptr_Function_float Function
%135 = OpVariable %_ptr_Function_float Function
%117 = OpAccessChain %_ptr_Function_float %23 %uint_0
%118 = OpLoad %float %117
OpStore %116 %118
%120 = OpAccessChain %_ptr_Function_float %24 %uint_0
%121 = OpLoad %float %120
OpStore %119 %121
%122 = OpFunctionCall %float %11 %116 %119
%124 = OpAccessChain %_ptr_Function_float %23 %uint_1
%125 = OpLoad %float %124
OpStore %123 %125
%127 = OpAccessChain %_ptr_Function_float %24 %uint_1
%128 = OpLoad %float %127
OpStore %126 %128
%129 = OpFunctionCall %float %11 %123 %126
%130 = OpFMul %float %122 %129
%133 = OpAccessChain %_ptr_Function_float %23 %uint_2
%134 = OpLoad %float %133
OpStore %131 %134
%136 = OpAccessChain %_ptr_Function_float %24 %uint_2
%137 = OpLoad %float %136
OpStore %135 %137
%138 = OpFunctionCall %float %11 %131 %135
%139 = OpFMul %float %130 %138
OpReturnValue %139
OpFunctionEnd
%32 = OpFunction %float None %29
%30 = OpFunctionParameter %_ptr_Function_v4float
%31 = OpFunctionParameter %_ptr_Function_v4float
%33 = OpLabel
%142 = OpVariable %_ptr_Function_float Function
%145 = OpVariable %_ptr_Function_float Function
%149 = OpVariable %_ptr_Function_float Function
%152 = OpVariable %_ptr_Function_float Function
%157 = OpVariable %_ptr_Function_float Function
%160 = OpVariable %_ptr_Function_float Function
%165 = OpVariable %_ptr_Function_float Function
%169 = OpVariable %_ptr_Function_float Function
%143 = OpAccessChain %_ptr_Function_float %30 %uint_0
%144 = OpLoad %float %143
OpStore %142 %144
%146 = OpAccessChain %_ptr_Function_float %31 %uint_0
%147 = OpLoad %float %146
OpStore %145 %147
%148 = OpFunctionCall %float %11 %142 %145
%150 = OpAccessChain %_ptr_Function_float %30 %uint_1
%151 = OpLoad %float %150
OpStore %149 %151
%153 = OpAccessChain %_ptr_Function_float %31 %uint_1
%154 = OpLoad %float %153
OpStore %152 %154
%155 = OpFunctionCall %float %11 %149 %152
%156 = OpFMul %float %148 %155
%158 = OpAccessChain %_ptr_Function_float %30 %uint_2
%159 = OpLoad %float %158
OpStore %157 %159
%161 = OpAccessChain %_ptr_Function_float %31 %uint_2
%162 = OpLoad %float %161
OpStore %160 %162
%163 = OpFunctionCall %float %11 %157 %160
%164 = OpFMul %float %156 %163
%167 = OpAccessChain %_ptr_Function_float %30 %uint_3
%168 = OpLoad %float %167
OpStore %165 %168
%170 = OpAccessChain %_ptr_Function_float %31 %uint_3
%171 = OpLoad %float %170
OpStore %169 %171
%172 = OpFunctionCall %float %11 %165 %169
%173 = OpFMul %float %164 %172
OpReturnValue %173
OpFunctionEnd
%39 = OpFunction %float None %36
%37 = OpFunctionParameter %_ptr_Function_mat4v2float
%38 = OpFunctionParameter %_ptr_Function_mat4v2float
%40 = OpLabel
%177 = OpVariable %_ptr_Function_v2float Function
%180 = OpVariable %_ptr_Function_v2float Function
%185 = OpVariable %_ptr_Function_v2float Function
%188 = OpVariable %_ptr_Function_v2float Function
%194 = OpVariable %_ptr_Function_v2float Function
%197 = OpVariable %_ptr_Function_v2float Function
%203 = OpVariable %_ptr_Function_v2float Function
%206 = OpVariable %_ptr_Function_v2float Function
%178 = OpAccessChain %_ptr_Function_v2float %37 %int_0
%179 = OpLoad %v2float %178
OpStore %177 %179
%181 = OpAccessChain %_ptr_Function_v2float %38 %int_0
%182 = OpLoad %v2float %181
OpStore %180 %182
%183 = OpFunctionCall %float %18 %177 %180
%186 = OpAccessChain %_ptr_Function_v2float %37 %int_1
%187 = OpLoad %v2float %186
OpStore %185 %187
%189 = OpAccessChain %_ptr_Function_v2float %38 %int_1
%190 = OpLoad %v2float %189
OpStore %188 %190
%191 = OpFunctionCall %float %18 %185 %188
%192 = OpFMul %float %183 %191
%195 = OpAccessChain %_ptr_Function_v2float %37 %int_2
%196 = OpLoad %v2float %195
OpStore %194 %196
%198 = OpAccessChain %_ptr_Function_v2float %38 %int_2
%199 = OpLoad %v2float %198
OpStore %197 %199
%200 = OpFunctionCall %float %18 %194 %197
%201 = OpFMul %float %192 %200
%204 = OpAccessChain %_ptr_Function_v2float %37 %int_3
%205 = OpLoad %v2float %204
OpStore %203 %205
%207 = OpAccessChain %_ptr_Function_v2float %38 %int_3
%208 = OpLoad %v2float %207
OpStore %206 %208
%209 = OpFunctionCall %float %18 %203 %206
%210 = OpFMul %float %201 %209
OpReturnValue %210
OpFunctionEnd
%46 = OpFunction %float None %43
%44 = OpFunctionParameter %_ptr_Function_mat4v3float
%45 = OpFunctionParameter %_ptr_Function_mat4v3float
%47 = OpLabel
%213 = OpVariable %_ptr_Function_v3float Function
%216 = OpVariable %_ptr_Function_v3float Function
%220 = OpVariable %_ptr_Function_v3float Function
%223 = OpVariable %_ptr_Function_v3float Function
%228 = OpVariable %_ptr_Function_v3float Function
%231 = OpVariable %_ptr_Function_v3float Function
%236 = OpVariable %_ptr_Function_v3float Function
%239 = OpVariable %_ptr_Function_v3float Function
%214 = OpAccessChain %_ptr_Function_v3float %44 %int_0
%215 = OpLoad %v3float %214
OpStore %213 %215
%217 = OpAccessChain %_ptr_Function_v3float %45 %int_0
%218 = OpLoad %v3float %217
OpStore %216 %218
%219 = OpFunctionCall %float %25 %213 %216
%221 = OpAccessChain %_ptr_Function_v3float %44 %int_1
%222 = OpLoad %v3float %221
OpStore %220 %222
%224 = OpAccessChain %_ptr_Function_v3float %45 %int_1
%225 = OpLoad %v3float %224
OpStore %223 %225
%226 = OpFunctionCall %float %25 %220 %223
%227 = OpFMul %float %219 %226
%229 = OpAccessChain %_ptr_Function_v3float %44 %int_2
%230 = OpLoad %v3float %229
OpStore %228 %230
%232 = OpAccessChain %_ptr_Function_v3float %45 %int_2
%233 = OpLoad %v3float %232
OpStore %231 %233
%234 = OpFunctionCall %float %25 %228 %231
%235 = OpFMul %float %227 %234
%237 = OpAccessChain %_ptr_Function_v3float %44 %int_3
%238 = OpLoad %v3float %237
OpStore %236 %238
%240 = OpAccessChain %_ptr_Function_v3float %45 %int_3
%241 = OpLoad %v3float %240
OpStore %239 %241
%242 = OpFunctionCall %float %25 %236 %239
%243 = OpFMul %float %235 %242
OpReturnValue %243
OpFunctionEnd
%53 = OpFunction %float None %50
%51 = OpFunctionParameter %_ptr_Function_mat4v4float
%52 = OpFunctionParameter %_ptr_Function_mat4v4float
%54 = OpLabel
%246 = OpVariable %_ptr_Function_v4float Function
%249 = OpVariable %_ptr_Function_v4float Function
%253 = OpVariable %_ptr_Function_v4float Function
%256 = OpVariable %_ptr_Function_v4float Function
%261 = OpVariable %_ptr_Function_v4float Function
%264 = OpVariable %_ptr_Function_v4float Function
%269 = OpVariable %_ptr_Function_v4float Function
%272 = OpVariable %_ptr_Function_v4float Function
%247 = OpAccessChain %_ptr_Function_v4float %51 %int_0
%248 = OpLoad %v4float %247
OpStore %246 %248
%250 = OpAccessChain %_ptr_Function_v4float %52 %int_0
%251 = OpLoad %v4float %250
OpStore %249 %251
%252 = OpFunctionCall %float %32 %246 %249
%254 = OpAccessChain %_ptr_Function_v4float %51 %int_1
%255 = OpLoad %v4float %254
OpStore %253 %255
%257 = OpAccessChain %_ptr_Function_v4float %52 %int_1
%258 = OpLoad %v4float %257
OpStore %256 %258
%259 = OpFunctionCall %float %32 %253 %256
%260 = OpFMul %float %252 %259
%262 = OpAccessChain %_ptr_Function_v4float %51 %int_2
%263 = OpLoad %v4float %262
OpStore %261 %263
%265 = OpAccessChain %_ptr_Function_v4float %52 %int_2
%266 = OpLoad %v4float %265
OpStore %264 %266
%267 = OpFunctionCall %float %32 %261 %264
%268 = OpFMul %float %260 %267
%270 = OpAccessChain %_ptr_Function_v4float %51 %int_3
%271 = OpLoad %v4float %270
OpStore %269 %271
%273 = OpAccessChain %_ptr_Function_v4float %52 %int_3
%274 = OpLoad %v4float %273
OpStore %272 %274
%275 = OpFunctionCall %float %32 %269 %272
%276 = OpFMul %float %268 %275
OpReturnValue %276
OpFunctionEnd
%61 = OpFunction %float None %58
%59 = OpFunctionParameter %_ptr_Function_v2int
%60 = OpFunctionParameter %_ptr_Function_v2int
%62 = OpLabel
%279 = OpLoad %v2int %59
%280 = OpLoad %v2int %60
%282 = OpIEqual %v2bool %279 %280
%283 = OpAll %bool %282
%284 = OpSelect %float %283 %float_1 %float_0
OpReturnValue %284
OpFunctionEnd
%69 = OpFunction %float None %66
%67 = OpFunctionParameter %_ptr_Function_v2uint
%68 = OpFunctionParameter %_ptr_Function_v2uint
%70 = OpLabel
%287 = OpLoad %v2uint %67
%288 = OpLoad %v2uint %68
%289 = OpIEqual %v2bool %287 %288
%290 = OpAll %bool %289
%291 = OpSelect %float %290 %float_1 %float_0
OpReturnValue %291
OpFunctionEnd
%76 = OpFunction %float None %73
%74 = OpFunctionParameter %_ptr_Function_v4uint
%75 = OpFunctionParameter %_ptr_Function_v4uint
%77 = OpLabel
%294 = OpLoad %v4uint %74
%295 = OpLoad %v4uint %75
%297 = OpIEqual %v4bool %294 %295
%298 = OpAll %bool %297
%299 = OpSelect %float %298 %float_1 %float_0
OpReturnValue %299
OpFunctionEnd
%84 = OpFunction %float None %81
%82 = OpFunctionParameter %_ptr_Function_v3bool
%83 = OpFunctionParameter %_ptr_Function_v3bool
%85 = OpLabel
%302 = OpLoad %v3bool %82
%303 = OpLoad %v3bool %83
%304 = OpLogicalEqual %v3bool %302 %303
%305 = OpAll %bool %304
%306 = OpSelect %float %305 %float_1 %float_0
OpReturnValue %306
OpFunctionEnd

View File

@@ -99,7 +99,7 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
.output_locations = std.ArrayList(SpvWord).empty, .output_locations = std.ArrayList(SpvWord).empty,
.bindings = std.AutoHashMap(SpvBinding, Value).init(allocator), .bindings = std.AutoHashMap(SpvBinding, Value).init(allocator),
}); });
errdefer self.deinit(allocator); errdefer allocator.free(self.code);
op.initRuntimeDispatcher(); op.initRuntimeDispatcher();
@@ -123,9 +123,16 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
self.bound = self.it.next() catch return ModuleError.InvalidSpirV; self.bound = self.it.next() catch return ModuleError.InvalidSpirV;
self.results = allocator.alloc(Result, self.bound) catch return ModuleError.OutOfMemory; self.results = allocator.alloc(Result, self.bound) catch return ModuleError.OutOfMemory;
errdefer allocator.free(self.results);
for (self.results) |*result| { for (self.results) |*result| {
result.* = Result.init(); result.* = Result.init();
} }
errdefer {
for (self.results) |*result| {
result.deinit(allocator);
}
}
_ = self.it.skip(); // Skip schema _ = self.it.skip(); // Skip schema

View File

@@ -176,6 +176,7 @@ pub const Value = union(Type) {
} }
break :blk self; break :blk self;
}, },
.RuntimeArray => .{ .RuntimeArray = .{} },
else => unreachable, else => unreachable,
}, },
else => unreachable, else => unreachable,
@@ -322,9 +323,7 @@ pub const VariantData = union(Variant) {
const Self = @This(); const Self = @This();
name: ?[]const u8, name: ?[]const u8,
decorations: std.ArrayList(Decoration), decorations: std.ArrayList(Decoration),
variant: ?VariantData, variant: ?VariantData,
pub fn init() Self { pub fn init() Self {

View File

@@ -158,6 +158,7 @@ pub const SetupDispatcher = block: {
.TypeInt = opTypeInt, .TypeInt = opTypeInt,
.TypeMatrix = opTypeMatrix, .TypeMatrix = opTypeMatrix,
.TypePointer = opTypePointer, .TypePointer = opTypePointer,
.TypeRuntimeArray = opTypeRuntimeArray,
.TypeStruct = opTypeStruct, .TypeStruct = opTypeStruct,
.TypeVector = opTypeVector, .TypeVector = opTypeVector,
.TypeVoid = opTypeVoid, .TypeVoid = opTypeVoid,
@@ -1248,6 +1249,7 @@ fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeErr
rt.mod.results[function_type_id].variant.?.Type.Function.source_location = source_location; rt.mod.results[function_type_id].variant.?.Type.Function.source_location = source_location;
rt.current_function = &rt.mod.results[id]; rt.current_function = &rt.mod.results[id];
rt.current_parameter_index = 0;
} }
fn opFunctionCall(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void { fn opFunctionCall(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
@@ -1519,6 +1521,15 @@ fn opTypePointer(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!vo
}; };
} }
fn opTypeRuntimeArray(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next();
rt.mod.results[id].variant = .{
.Type = .{
.RuntimeArray = .{},
},
};
}
fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void { fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
const id = try rt.it.next(); const id = try rt.it.next();
const members_type_word = blk: { const members_type_word = blk: {