Merge SPIRV backend with shader module
This commit is contained in:
parent
d5a61d3642
commit
8566345f5e
@ -8,8 +8,6 @@ pub const Type = @import("./shaders/Type.zig");
|
||||
|
||||
const coral = @import("./coral.zig");
|
||||
|
||||
const spirv = @import("./shaders/spirv.zig");
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const tokens = @import("./shaders/tokens.zig");
|
||||
@ -349,14 +347,3 @@ pub const Uniform = struct {
|
||||
binding: u8,
|
||||
has_field: ?*const Field = null,
|
||||
};
|
||||
|
||||
pub fn compileFragmentSpirv(arena: *std.heap.ArenaAllocator, function: *const coral.shaders.Function) spirv.BuildError!spirv.Module {
|
||||
var module = spirv.Module{
|
||||
.capabilities = &.{.shader},
|
||||
.memory_model = .{ .logical, .glsl450 },
|
||||
};
|
||||
|
||||
_ = try module.shaderEntryPoint(arena, .fragment, function);
|
||||
|
||||
return module;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
const coral = @import("../coral.zig");
|
||||
|
||||
const spirv = @import("./spirv.zig");
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const tokens = @import("./tokens.zig");
|
||||
@ -11,6 +13,10 @@ uniforms: std.BoundedArray(*const coral.shaders.Uniform, 15) = .{},
|
||||
textures: std.BoundedArray(*const coral.shaders.Texture, 15) = .{},
|
||||
functions: std.BoundedArray(*const coral.shaders.Function, max_functions) = .{},
|
||||
|
||||
pub const BuildError = spirv.BuildError || error{
|
||||
InvalidEntryPoint,
|
||||
};
|
||||
|
||||
pub const ParseResult = union(enum) {
|
||||
ok,
|
||||
failure: [:0]const u8,
|
||||
@ -18,6 +24,19 @@ pub const ParseResult = union(enum) {
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub fn buildSpirvFragment(self: *Self, arena: *std.heap.ArenaAllocator, identifier: []const u8) BuildError!spirv.Module {
|
||||
var module = spirv.Module{
|
||||
.capabilities = &.{.shader},
|
||||
.memory_model = .{ .logical, .glsl450 },
|
||||
};
|
||||
|
||||
_ = try module.shaderEntryPoint(arena, .fragment, self.hasFunction(identifier) orelse {
|
||||
return error.InvalidEntryPoint;
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
pub fn clear(self: *Self) void {
|
||||
self.scope.clear();
|
||||
self.inputs.clear();
|
||||
|
@ -112,6 +112,11 @@ pub const Module = struct {
|
||||
};
|
||||
},
|
||||
|
||||
.convert => |_| {
|
||||
// TODO: Review how type conversions are represented in AST.
|
||||
unreachable;
|
||||
},
|
||||
|
||||
.invoke => |invoke| {
|
||||
const arguments = try arena.allocator().alloc(*const Value, invoke.argument_count);
|
||||
|
||||
|
@ -72,12 +72,7 @@ fn compile_shaders(_: ona.Write(Context), assets: ona.Assets) !void {
|
||||
|
||||
switch (try root.parse(&arena, try assets.load(shader_path, arena.allocator()))) {
|
||||
.ok => {
|
||||
const spirv_module = try coral.shaders.compileFragmentSpirv(&arena, root.hasFunction("frag") orelse {
|
||||
std.log.err("effect shader {s} requires an entry-point named `frag`", .{shader_path});
|
||||
|
||||
return error.ShaderParseFailure;
|
||||
});
|
||||
|
||||
const spirv_module = try root.buildSpirvFragment(&arena, "frag");
|
||||
var codes = coral.Stack(u8).empty;
|
||||
|
||||
defer {
|
||||
|
Loading…
x
Reference in New Issue
Block a user