adding base extension support
This commit is contained in:
@@ -94,15 +94,15 @@ const Runner = struct {
|
|||||||
rt: spv.Runtime,
|
rt: spv.Runtime,
|
||||||
|
|
||||||
fn run(self: *Self, y: usize, pixel_map: [*]u32) void {
|
fn run(self: *Self, y: usize, pixel_map: [*]u32) void {
|
||||||
const entry = self.rt.getEntryPointByName("main") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
|
||||||
const color = self.rt.getResultByName("color") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
|
||||||
const time = self.rt.getResultByName("time") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
|
||||||
const pos = self.rt.getResultByName("pos") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
|
||||||
const res = self.rt.getResultByName("res") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
|
||||||
var output: [4]f32 = undefined;
|
|
||||||
|
|
||||||
var rt = self.rt; // Copy to avoid pointer access of `self` at runtime. Okay as Runtime contains only pointers and trivially copyable fields
|
var rt = self.rt; // Copy to avoid pointer access of `self` at runtime. Okay as Runtime contains only pointers and trivially copyable fields
|
||||||
|
|
||||||
|
const entry = rt.getEntryPointByName("main") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
const color = rt.getResultByName("color") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
const time = rt.getResultByName("time") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
const pos = rt.getResultByName("pos") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
const res = rt.getResultByName("res") catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
var output: [4]f32 = undefined;
|
||||||
|
|
||||||
for (0..screen_width) |x| {
|
for (0..screen_width) |x| {
|
||||||
rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time) catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time) catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
rt.writeInput(f32, &.{ @floatFromInt(screen_width), @floatFromInt(screen_height) }, res) catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
rt.writeInput(f32, &.{ @floatFromInt(screen_width), @floatFromInt(screen_height) }, res) catch |err| std.debug.panic("Catch error {s}", .{@errorName(err)});
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ module;
|
|||||||
|
|
||||||
struct FragIn
|
struct FragIn
|
||||||
{
|
{
|
||||||
[location(0)] time: u32,
|
[location(0)] time: f32,
|
||||||
[location(1)] dim: vec2[f32],
|
[location(1)] res: vec2[f32],
|
||||||
[location(2)] pos: vec2[f32],
|
[location(2)] pos: vec2[f32],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ fn main(input: FragIn) -> FragOut
|
|||||||
{
|
{
|
||||||
let output: FragOut;
|
let output: FragOut;
|
||||||
output.color = vec4[f32](
|
output.color = vec4[f32](
|
||||||
input.pos.x / input.dim.x,
|
input.pos.x / input.res.x,
|
||||||
input.pos.y / input.dim.y,
|
input.pos.y / input.res.y,
|
||||||
1.0,
|
1.0,
|
||||||
1.0
|
1.0
|
||||||
);
|
);
|
||||||
|
|||||||
Binary file not shown.
@@ -1,86 +1,85 @@
|
|||||||
Version 1.0
|
Version 1.0
|
||||||
Generator: 2560130
|
Generator: 2560130
|
||||||
Bound: 51
|
Bound: 50
|
||||||
Schema: 0
|
Schema: 0
|
||||||
OpCapability Capability(Shader)
|
OpCapability Capability(Shader)
|
||||||
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
OpMemoryModel AddressingModel(Logical) MemoryModel(GLSL450)
|
||||||
OpEntryPoint ExecutionModel(Fragment) %25 "main" %5 %12 %15 %21
|
OpEntryPoint ExecutionModel(Fragment) %24 "main" %5 %11 %14 %20
|
||||||
OpExecutionMode %25 ExecutionMode(OriginUpperLeft)
|
OpExecutionMode %24 ExecutionMode(OriginUpperLeft)
|
||||||
OpSource SourceLanguage(NZSL) 4198400
|
OpSource SourceLanguage(NZSL) 4198400
|
||||||
OpSourceExtension "Version: 1.1"
|
OpSourceExtension "Version: 1.1"
|
||||||
OpName %17 "FragIn"
|
OpName %16 "FragIn"
|
||||||
OpMemberName %17 0 "time"
|
OpMemberName %16 0 "time"
|
||||||
OpMemberName %17 1 "dim"
|
OpMemberName %16 1 "res"
|
||||||
OpMemberName %17 2 "pos"
|
OpMemberName %16 2 "pos"
|
||||||
OpName %22 "FragOut"
|
OpName %21 "FragOut"
|
||||||
OpMemberName %22 0 "color"
|
OpMemberName %21 0 "color"
|
||||||
OpName %5 "time"
|
OpName %5 "time"
|
||||||
OpName %12 "dim"
|
OpName %11 "res"
|
||||||
OpName %15 "pos"
|
OpName %14 "pos"
|
||||||
OpName %21 "color"
|
OpName %20 "color"
|
||||||
OpName %25 "main"
|
OpName %24 "main"
|
||||||
OpDecorate %5 Decoration(Location) 0
|
OpDecorate %5 Decoration(Location) 0
|
||||||
OpDecorate %12 Decoration(Location) 1
|
OpDecorate %11 Decoration(Location) 1
|
||||||
OpDecorate %15 Decoration(Location) 2
|
OpDecorate %14 Decoration(Location) 2
|
||||||
OpDecorate %21 Decoration(Location) 0
|
OpDecorate %20 Decoration(Location) 0
|
||||||
OpMemberDecorate %17 0 Decoration(Offset) 0
|
OpMemberDecorate %16 0 Decoration(Offset) 0
|
||||||
OpMemberDecorate %17 1 Decoration(Offset) 8
|
OpMemberDecorate %16 1 Decoration(Offset) 8
|
||||||
OpMemberDecorate %17 2 Decoration(Offset) 16
|
OpMemberDecorate %16 2 Decoration(Offset) 16
|
||||||
OpMemberDecorate %22 0 Decoration(Offset) 0
|
OpMemberDecorate %21 0 Decoration(Offset) 0
|
||||||
%1 = OpTypeVoid
|
%1 = OpTypeVoid
|
||||||
%2 = OpTypeFunction %1
|
%2 = OpTypeFunction %1
|
||||||
%3 = OpTypeInt 32 0
|
%3 = OpTypeFloat 32
|
||||||
%4 = OpTypePointer StorageClass(Input) %3
|
%4 = OpTypePointer StorageClass(Input) %3
|
||||||
%6 = OpTypeInt 32 1
|
%6 = OpTypeInt 32 1
|
||||||
%7 = OpConstant %6 i32(0)
|
%7 = OpConstant %6 i32(0)
|
||||||
%8 = OpTypePointer StorageClass(Function) %3
|
%8 = OpTypePointer StorageClass(Function) %3
|
||||||
%9 = OpTypeFloat 32
|
%9 = OpTypeVector %3 2
|
||||||
%10 = OpTypeVector %9 2
|
%10 = OpTypePointer StorageClass(Input) %9
|
||||||
%11 = OpTypePointer StorageClass(Input) %10
|
%12 = OpConstant %6 i32(1)
|
||||||
%13 = OpConstant %6 i32(1)
|
%13 = OpTypePointer StorageClass(Function) %9
|
||||||
%14 = OpTypePointer StorageClass(Function) %10
|
%15 = OpConstant %6 i32(2)
|
||||||
%16 = OpConstant %6 i32(2)
|
%16 = OpTypeStruct %3 %9 %9
|
||||||
%17 = OpTypeStruct %3 %10 %10
|
%17 = OpTypePointer StorageClass(Function) %16
|
||||||
%18 = OpTypePointer StorageClass(Function) %17
|
%18 = OpTypeVector %3 4
|
||||||
%19 = OpTypeVector %9 4
|
%19 = OpTypePointer StorageClass(Output) %18
|
||||||
%20 = OpTypePointer StorageClass(Output) %19
|
%21 = OpTypeStruct %18
|
||||||
%22 = OpTypeStruct %19
|
%22 = OpTypePointer StorageClass(Function) %21
|
||||||
%23 = OpTypePointer StorageClass(Function) %22
|
%23 = OpConstant %3 f32(1)
|
||||||
%24 = OpConstant %9 f32(1)
|
%47 = OpTypePointer StorageClass(Function) %18
|
||||||
%48 = OpTypePointer StorageClass(Function) %19
|
|
||||||
%5 = OpVariable %4 StorageClass(Input)
|
%5 = OpVariable %4 StorageClass(Input)
|
||||||
%12 = OpVariable %11 StorageClass(Input)
|
%11 = OpVariable %10 StorageClass(Input)
|
||||||
%15 = OpVariable %11 StorageClass(Input)
|
%14 = OpVariable %10 StorageClass(Input)
|
||||||
%21 = OpVariable %20 StorageClass(Output)
|
%20 = OpVariable %19 StorageClass(Output)
|
||||||
%25 = OpFunction %1 FunctionControl(0) %2
|
%24 = OpFunction %1 FunctionControl(0) %2
|
||||||
%26 = OpLabel
|
%25 = OpLabel
|
||||||
%27 = OpVariable %23 StorageClass(Function)
|
%26 = OpVariable %22 StorageClass(Function)
|
||||||
%28 = OpVariable %18 StorageClass(Function)
|
%27 = OpVariable %17 StorageClass(Function)
|
||||||
%29 = OpAccessChain %8 %28 %7
|
%28 = OpAccessChain %8 %27 %7
|
||||||
OpCopyMemory %29 %5
|
OpCopyMemory %28 %5
|
||||||
%30 = OpAccessChain %14 %28 %13
|
%29 = OpAccessChain %13 %27 %12
|
||||||
OpCopyMemory %30 %12
|
OpCopyMemory %29 %11
|
||||||
%31 = OpAccessChain %14 %28 %16
|
%30 = OpAccessChain %13 %27 %15
|
||||||
OpCopyMemory %31 %15
|
OpCopyMemory %30 %14
|
||||||
%32 = OpAccessChain %14 %28 %16
|
%31 = OpAccessChain %13 %27 %15
|
||||||
%33 = OpLoad %10 %32
|
%32 = OpLoad %9 %31
|
||||||
%34 = OpCompositeExtract %9 %33 0
|
%33 = OpCompositeExtract %3 %32 0
|
||||||
%35 = OpAccessChain %14 %28 %13
|
%34 = OpAccessChain %13 %27 %12
|
||||||
%36 = OpLoad %10 %35
|
%35 = OpLoad %9 %34
|
||||||
%37 = OpCompositeExtract %9 %36 0
|
%36 = OpCompositeExtract %3 %35 0
|
||||||
%38 = OpFDiv %9 %34 %37
|
%37 = OpFDiv %3 %33 %36
|
||||||
%39 = OpAccessChain %14 %28 %16
|
%38 = OpAccessChain %13 %27 %15
|
||||||
%40 = OpLoad %10 %39
|
%39 = OpLoad %9 %38
|
||||||
%41 = OpCompositeExtract %9 %40 1
|
%40 = OpCompositeExtract %3 %39 1
|
||||||
%42 = OpAccessChain %14 %28 %13
|
%41 = OpAccessChain %13 %27 %12
|
||||||
%43 = OpLoad %10 %42
|
%42 = OpLoad %9 %41
|
||||||
%44 = OpCompositeExtract %9 %43 1
|
%43 = OpCompositeExtract %3 %42 1
|
||||||
%45 = OpFDiv %9 %41 %44
|
%44 = OpFDiv %3 %40 %43
|
||||||
%46 = OpCompositeConstruct %19 %38 %45 %24 %24
|
%45 = OpCompositeConstruct %18 %37 %44 %23 %23
|
||||||
%47 = OpAccessChain %48 %27 %7
|
%46 = OpAccessChain %47 %26 %7
|
||||||
OpStore %47 %46
|
OpStore %46 %45
|
||||||
%49 = OpLoad %22 %27
|
%48 = OpLoad %21 %26
|
||||||
%50 = OpCompositeExtract %19 %49 0
|
%49 = OpCompositeExtract %18 %48 0
|
||||||
OpStore %21 %50
|
OpStore %20 %49
|
||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const ModuleError = error{
|
|||||||
InvalidSpirV,
|
InvalidSpirV,
|
||||||
InvalidMagic,
|
InvalidMagic,
|
||||||
UnsupportedEndianness,
|
UnsupportedEndianness,
|
||||||
|
UnsupportedExtension,
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const spv = @import("spv.zig");
|
const spv = @import("spv.zig");
|
||||||
|
const op = @import("opcodes.zig");
|
||||||
|
|
||||||
const RuntimeError = @import("Runtime.zig").RuntimeError;
|
const RuntimeError = @import("Runtime.zig").RuntimeError;
|
||||||
|
|
||||||
@@ -228,7 +229,10 @@ pub const Value = union(Type) {
|
|||||||
|
|
||||||
pub const VariantData = union(Variant) {
|
pub const VariantData = union(Variant) {
|
||||||
String: []const u8,
|
String: []const u8,
|
||||||
Extension: struct {},
|
Extension: struct {
|
||||||
|
/// Should not be allocated but rather a pointer to a static array
|
||||||
|
dispatcher: []op.OpCodeExtFunc,
|
||||||
|
},
|
||||||
Type: union(Type) {
|
Type: union(Type) {
|
||||||
Void: struct {},
|
Void: struct {},
|
||||||
Bool: struct {},
|
Bool: struct {},
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub const RuntimeError = error{
|
|||||||
ToDo,
|
ToDo,
|
||||||
Unreachable,
|
Unreachable,
|
||||||
UnsupportedSpirV,
|
UnsupportedSpirV,
|
||||||
|
UnsupportedExtension,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Function = struct {
|
pub const Function = struct {
|
||||||
|
|||||||
0
src/ext/GLSL_std_450.zig
git.filemode.normal_file
0
src/ext/GLSL_std_450.zig
git.filemode.normal_file
@@ -13,7 +13,6 @@ const SpvByte = spv.SpvByte;
|
|||||||
const SpvWord = spv.SpvWord;
|
const SpvWord = spv.SpvWord;
|
||||||
const SpvBool = spv.SpvBool;
|
const SpvBool = spv.SpvBool;
|
||||||
|
|
||||||
// OpExtInstImport
|
|
||||||
// OpExtInst Sin
|
// OpExtInst Sin
|
||||||
// OpExtInst Cos
|
// OpExtInst Cos
|
||||||
// OpExtInst Length
|
// OpExtInst Length
|
||||||
@@ -71,6 +70,7 @@ const BitOp = enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const OpCodeFunc = *const fn (std.mem.Allocator, SpvWord, *Runtime) RuntimeError!void;
|
pub const OpCodeFunc = *const fn (std.mem.Allocator, SpvWord, *Runtime) RuntimeError!void;
|
||||||
|
pub const OpCodeExtFunc = *const fn (std.mem.Allocator, SpvWord, SpvWord, SpvWord, *Runtime) RuntimeError!void;
|
||||||
|
|
||||||
pub const SetupDispatcher = block: {
|
pub const SetupDispatcher = block: {
|
||||||
@setEvalBranchQuota(65535);
|
@setEvalBranchQuota(65535);
|
||||||
@@ -174,6 +174,8 @@ pub const SetupDispatcher = block: {
|
|||||||
.Variable = opVariable,
|
.Variable = opVariable,
|
||||||
.VectorTimesMatrix = autoSetupConstant,
|
.VectorTimesMatrix = autoSetupConstant,
|
||||||
.VectorTimesScalar = autoSetupConstant,
|
.VectorTimesScalar = autoSetupConstant,
|
||||||
|
.ExtInst = autoSetupConstant,
|
||||||
|
.ExtInstImport = opExtInstImport,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1104,6 +1106,30 @@ fn opExecutionMode(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn opExtInst(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
|
const target_type = try rt.it.next();
|
||||||
|
const id = try rt.it.next();
|
||||||
|
const set = try rt.it.next();
|
||||||
|
const inst = try rt.it.next();
|
||||||
|
|
||||||
|
switch (try rt.results[set].getVariant()) {
|
||||||
|
.Extension => |ext| if (ext.dispatcher[inst]) |pfn| {
|
||||||
|
try pfn(allocator, target_type, id, word_count, rt);
|
||||||
|
},
|
||||||
|
else => return RuntimeError.InvalidSpirV,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn opExtInstImport(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
|
const id = try rt.it.next();
|
||||||
|
rt.mod.results[id].name = try readStringN(allocator, &rt.it, word_count - 1);
|
||||||
|
rt.mod.results[id].variant = .{
|
||||||
|
.Extension = .{
|
||||||
|
.dispatcher = undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
fn opFunction(allocator: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
const return_type = try rt.it.next();
|
const return_type = try rt.it.next();
|
||||||
const id = try rt.it.next();
|
const id = try rt.it.next();
|
||||||
|
|||||||
Reference in New Issue
Block a user