This commit is contained in:
Peter Li 2025-04-13 17:41:16 -07:00
parent f4381446db
commit 806c7942e8
29 changed files with 620 additions and 41 deletions

View File

@ -10,6 +10,7 @@ gltf2ozz: ozz.GltfToOzz,
options: *std.Build.Step.Options, options: *std.Build.Step.Options,
cookShaders: bool, cookShaders: bool,
backlogRoot: []const u8,
// list of all shaders discovered under // list of all shaders discovered under
// content/_shaders/def // content/_shaders/def
reflectShaderPathList: [][]u8 = undefined, reflectShaderPathList: [][]u8 = undefined,
@ -33,6 +34,7 @@ const ozz = @import("ozz");
pub const InitOptions = struct { pub const InitOptions = struct {
import_name: []const u8 = "Backlog", import_name: []const u8 = "Backlog",
backlogRoot: []const u8 = "./BacklogEngine",
target: Build.ResolvedTarget, target: Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode, optimize: std.builtin.OptimizeMode,
}; };
@ -49,6 +51,7 @@ pub fn init(b: *std.Build, opts: InitOptions) BuildSystem {
.target = opts.target, .target = opts.target,
.optimize = opts.optimize, .optimize = opts.optimize,
.nw_mod = nwdep.module("Backlog"), .nw_mod = nwdep.module("Backlog"),
.backlogRoot = opts.backlogRoot,
.spirvReflect = SpirvReflect.SpirvGenerator2.init(nwdep.builder, .{}), .spirvReflect = SpirvReflect.SpirvGenerator2.init(nwdep.builder, .{}),
.options = createGameOptions(b), .options = createGameOptions(b),
.gltf2ozz = ozz.GltfToOzz.init(nwdep.builder, .{}), .gltf2ozz = ozz.GltfToOzz.init(nwdep.builder, .{}),
@ -126,7 +129,13 @@ pub fn addProgram(self: *BuildSystem, opts: AddProgramOptions) *std.Build.Step.C
mod.addImport("Backlog", self.nw_mod); mod.addImport("Backlog", self.nw_mod);
exe.root_module.addOptions("BacklogOptions", self.options); exe.root_module.addOptions("BacklogOptions", self.options);
if (self.cookShaders) {} if (self.cookShaders) {
const cookShadersScript = b.fmt("{s}/tools/scripts/cookShaders.py", .{self.backlogRoot});
const cookShadersCommand = b.addSystemCommand(&[_][]const u8{"python"});
cookShadersCommand.addArg(cookShadersScript);
run_exe.dependOn(&cookShadersCommand.step);
}
// I want to generate definitions from the spirv-reflect-tool during pre-build. // I want to generate definitions from the spirv-reflect-tool during pre-build.
// //

View File

@ -1,4 +1,5 @@
const std = @import("std"); const std = @import("std");
const sdl3 = @import("sdl3");
// pub fn addLib(b: *std.Build, exe: *std.Build.Step.Compile, comptime packagePath: []const u8, cflags: []const []const u8) void { // pub fn addLib(b: *std.Build, exe: *std.Build.Step.Compile, comptime packagePath: []const u8, cflags: []const []const u8) void {
// _ = b; // _ = b;
@ -29,6 +30,9 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/platform.zig"), .root_source_file = b.path("src/platform.zig"),
}); });
const test_vert = sdl3.addShaderDefinition(b, "../../lib/sdl3", optimize, "test.vert", b.path("shaders/test.vert.json"));
mod.addImport("test.vert", test_vert);
const tests = b.addTest(.{ const tests = b.addTest(.{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,

View File

@ -4,6 +4,7 @@
.dependencies = .{ .dependencies = .{
.core = .{ .path = "../core" }, .core = .{ .path = "../core" },
.sdl3 = .{ .path = "../../lib/sdl3" }, .sdl3 = .{ .path = "../../lib/sdl3" },
.shaderTypes = .{ .path = "../../lib/sdl3/shaderTypes" },
}, },
.paths = .{ .paths = .{
"", "",

View File

@ -0,0 +1,46 @@
struct Input
{
uint VertexIndex : SV_VertexID;
};
struct Output
{
float4 Color : TEXCOORD0;
float4 Position : SV_Position;
};
struct Scene
{
float4 color;
};
StructuredBuffer<Scene> test: register(t0, space0);
Output main(Input input)
{
Output output;
float2 pos;
if (input.VertexIndex == 0)
{
pos = (-1.0f).xx;
output.Color = test[0].color;
}
else
{
if (input.VertexIndex == 1)
{
pos = float2(1.0f, -1.0f);
output.Color = test[1].color;
}
else
{
if (input.VertexIndex == 2)
{
pos = float2(0.0f, 1.0f);
output.Color = test[2].color;
}
}
}
output.Position = float4(pos, 0.0f, 1.0f);
return output;
}

View File

@ -0,0 +1,54 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "vert"
}
],
"types" : {
"_6" : {
"name" : "Scene",
"members" : [
{
"name" : "color",
"type" : "vec4",
"offset" : 0
}
]
},
"_5" : {
"name" : "type.StructuredBuffer.Scene",
"members" : [
{
"name" : "_m0",
"type" : "_6",
"array" : [
0
],
"array_size_is_literal" : [
true
],
"offset" : 0,
"array_stride" : 16
}
]
}
},
"outputs" : [
{
"type" : "vec4",
"name" : "out.var.TEXCOORD0",
"location" : 0
}
],
"ssbos" : [
{
"type" : "_5",
"name" : "test",
"readonly" : true,
"block_size" : 0,
"set" : 0,
"binding" : 0
}
]
}

View File

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const core = @import("core"); const core = @import("core");
const test_vert = @import("test.vert");
// controls glfw and general windowing // controls glfw and general windowing
// graphics depends on this one // graphics depends on this one
@ -21,6 +22,7 @@ pub fn setWindowSettings(params: windowing.PlatformParams) void {
pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std.mem.Allocator) !void { pub fn start_module(comptime programSpec: anytype, args: anytype, allocator: std.mem.Allocator) !void {
_ = args; _ = args;
_ = programSpec; _ = programSpec;
core.engine_log("shader compile test sizeof Scene = {d}", .{@sizeOf(test_vert.Scene)});
if (core.isUtility()) { if (core.isUtility()) {
return; return;
} }

View File

@ -0,0 +1,22 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "frag"
}
],
"inputs" : [
{
"type" : "vec4",
"name" : "in.var.TEXCOORD0",
"location" : 0
}
],
"outputs" : [
{
"type" : "vec4",
"name" : "out.var.SV_Target0",
"location" : 0
}
]
}

View File

@ -0,0 +1,54 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "vert"
}
],
"types" : {
"_6" : {
"name" : "Scene",
"members" : [
{
"name" : "color",
"type" : "vec3",
"offset" : 0
}
]
},
"_5" : {
"name" : "type.StructuredBuffer.Scene",
"members" : [
{
"name" : "_m0",
"type" : "_6",
"array" : [
0
],
"array_size_is_literal" : [
true
],
"offset" : 0,
"array_stride" : 16
}
]
}
},
"outputs" : [
{
"type" : "vec4",
"name" : "out.var.TEXCOORD0",
"location" : 0
}
],
"ssbos" : [
{
"type" : "_5",
"name" : "test",
"readonly" : true,
"block_size" : 0,
"set" : 0,
"binding" : 0
}
]
}

27
lib/sdl3/build.zig vendored
View File

@ -1,5 +1,29 @@
const std = @import("std"); const std = @import("std");
pub fn addShaderDefinition(
b: *std.Build,
comptime sdl3Path: []const u8,
optimize: std.builtin.OptimizeMode,
shaderName: []const u8,
jsonPath: std.Build.LazyPath,
) *std.Build.Module {
const reflectedZig = b.addSystemCommand(&[_][]const u8{"python"});
reflectedZig.addArg(sdl3Path ++ "/spvreflect/spvreflect.py");
reflectedZig.addFileArg(jsonPath);
reflectedZig.addArg("--output");
const reflectedZigOut = reflectedZig.addOutputFileArg(b.fmt("reflected/{s}.zig", .{shaderName}));
const module = b.createModule(.{ .root_source_file = reflectedZigOut, .optimize = optimize });
const dep = b.dependency("shaderTypes", .{
.target = b.graph.host,
.optimize = optimize,
});
module.addImport("shaderTypes", dep.module("shaderTypes"));
return module;
}
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
@ -31,6 +55,9 @@ pub fn build(b: *std.Build) void {
tests.root_module.addImport("sdl3", mod); tests.root_module.addImport("sdl3", mod);
const vertexDefinitions = addShaderDefinition(b, ".", optimize, "hello-triangle.vert", b.path("content/hello-triangle.vert.json"));
tests.root_module.addImport("hello-triangle.vert", vertexDefinitions);
const runArtifact = b.addRunArtifact(tests); const runArtifact = b.addRunArtifact(tests);
test_step.dependOn(&runArtifact.step); test_step.dependOn(&runArtifact.step);

View File

@ -4,6 +4,7 @@
.fingerprint=0x6188f62f190b5e67, .fingerprint=0x6188f62f190b5e67,
.dependencies = .{ .dependencies = .{
.sdl = .{ .path = "SDL/" }, .sdl = .{ .path = "SDL/" },
.shaderTypes = .{ .path = "shaderTypes/" },
}, },
.paths = .{ .paths = .{
"", "",

View File

@ -38,17 +38,32 @@ def cookAll():
('msl', []), ('msl', []),
] ]
spvs = []
for fmt in outputFormats: for fmt in outputFormats:
outdir = os.path.join(cookedRoot, fmt[0]) outdir = os.path.join(cookedRoot, fmt[0])
for f in inputFiles: for f in inputFiles:
basefile = f[:-5] basefile = f[:-5]
outfile = os.path.join(outdir, os.path.basename(basefile) + '.' + fmt[0] ) outfile = os.path.abspath(os.path.join(outdir, os.path.basename(basefile) + '.' + fmt[0] ))
os.makedirs(os.path.dirname(outfile), exist_ok=True) os.makedirs(os.path.dirname(outfile), exist_ok=True)
cmd = [shadercross, f] + \ cmd = [shadercross, f] + fmt[1] + [ '-o', outfile ]
fmt[1] + [ '-o', outfile ]
if 'spv' == fmt[0]:
spvs.append((outfile, os.path.dirname(f)))
print(cmd) print(cmd)
subprocess.run(cmd) subprocess.run(cmd)
# run spirv-cross and generate .json files
for f in spvs:
basefile = f[0][:-4]
# outdir = os.path.join(cookedRoot, '_def')
outfile = os.path.join(f[1], os.path.basename(basefile) + '.json' )
os.makedirs(os.path.dirname(outfile), exist_ok=True)
cmd = ['spirv-cross', f[0], '--reflect', '--output', outfile ]
print(cmd)
subprocess.run(cmd)
if __name__ == '__main__': if __name__ == '__main__':
cookAll() cookAll()

View File

@ -11,7 +11,7 @@
"members" : [ "members" : [
{ {
"name" : "color", "name" : "color",
"type" : "vec3", "type" : "vec4",
"offset" : 0 "offset" : 0
} }
] ]

View File

@ -5,7 +5,7 @@ using namespace metal;
struct Scene struct Scene
{ {
float3 color; float4 color;
}; };
struct type_StructuredBuffer_Scene struct type_StructuredBuffer_Scene
@ -13,8 +13,8 @@ struct type_StructuredBuffer_Scene
Scene _m0[1]; Scene _m0[1];
}; };
constant float2 _31 = {}; constant float2 _30 = {};
constant float4 _32 = {}; constant float4 _31 = {};
struct main0_out struct main0_out
{ {
@ -25,42 +25,42 @@ struct main0_out
vertex main0_out main0(const device type_StructuredBuffer_Scene& test [[buffer(0)]], uint gl_VertexIndex [[vertex_id]]) vertex main0_out main0(const device type_StructuredBuffer_Scene& test [[buffer(0)]], uint gl_VertexIndex [[vertex_id]])
{ {
main0_out out = {}; main0_out out = {};
float4 _71; float4 _58;
float2 _72; float2 _59;
if (gl_VertexIndex == 0u) if (gl_VertexIndex == 0u)
{ {
_71 = float4(test._m0[0u].color, 1.0); _58 = test._m0[0u].color;
_72 = float2(-1.0); _59 = float2(-1.0);
} }
else else
{ {
float4 _69; float4 _56;
float2 _70; float2 _57;
if (gl_VertexIndex == 1u) if (gl_VertexIndex == 1u)
{ {
_69 = float4(test._m0[1u].color, 1.0); _56 = test._m0[1u].color;
_70 = float2(1.0, -1.0); _57 = float2(1.0, -1.0);
} }
else else
{ {
bool _57 = gl_VertexIndex == 2u; bool _48 = gl_VertexIndex == 2u;
float4 _66; float4 _53;
if (_57) if (_48)
{ {
_66 = float4(test._m0[2u].color, 1.0); _53 = test._m0[2u].color;
} }
else else
{ {
_66 = _32; _53 = _31;
} }
_69 = _66; _56 = _53;
_70 = select(_31, float2(0.0, 1.0), bool2(_57)); _57 = select(_30, float2(0.0, 1.0), bool2(_48));
} }
_71 = _69; _58 = _56;
_72 = _70; _59 = _57;
} }
out.out_var_TEXCOORD0 = _71; out.out_var_TEXCOORD0 = _58;
out.gl_Position = float4(_72, 0.0, 1.0); out.gl_Position = float4(_59, 0.0, 1.0);
return out; return out;
} }

View File

@ -0,0 +1,22 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "frag"
}
],
"inputs" : [
{
"type" : "vec4",
"name" : "in.var.TEXCOORD0",
"location" : 0
}
],
"outputs" : [
{
"type" : "vec4",
"name" : "out.var.SV_Target0",
"location" : 0
}
]
}

View File

@ -11,7 +11,7 @@ struct Output
struct Scene struct Scene
{ {
float3 color; float4 color;
}; };
StructuredBuffer<Scene> test: register(t0, space0); StructuredBuffer<Scene> test: register(t0, space0);
@ -23,21 +23,21 @@ Output main(Input input)
if (input.VertexIndex == 0) if (input.VertexIndex == 0)
{ {
pos = (-1.0f).xx; pos = (-1.0f).xx;
output.Color = float4(test[0].color, 1.0f); output.Color = test[0].color;
} }
else else
{ {
if (input.VertexIndex == 1) if (input.VertexIndex == 1)
{ {
pos = float2(1.0f, -1.0f); pos = float2(1.0f, -1.0f);
output.Color = float4(test[1].color, 1.0f); output.Color = test[1].color;
} }
else else
{ {
if (input.VertexIndex == 2) if (input.VertexIndex == 2)
{ {
pos = float2(0.0f, 1.0f); pos = float2(0.0f, 1.0f);
output.Color = float4(test[2].color, 1.0f); output.Color = test[2].color;
} }
} }
} }

View File

@ -0,0 +1,54 @@
{
"entryPoints" : [
{
"name" : "main",
"mode" : "vert"
}
],
"types" : {
"_6" : {
"name" : "Scene",
"members" : [
{
"name" : "color",
"type" : "vec4",
"offset" : 0
}
]
},
"_5" : {
"name" : "type.StructuredBuffer.Scene",
"members" : [
{
"name" : "_m0",
"type" : "_6",
"array" : [
0
],
"array_size_is_literal" : [
true
],
"offset" : 0,
"array_stride" : 16
}
]
}
},
"outputs" : [
{
"type" : "vec4",
"name" : "out.var.TEXCOORD0",
"location" : 0
}
],
"ssbos" : [
{
"type" : "_5",
"name" : "test",
"readonly" : true,
"block_size" : 0,
"set" : 0,
"binding" : 0
}
]
}

14
lib/sdl3/shaderTypes/build.zig vendored Normal file
View File

@ -0,0 +1,14 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("shaderTypes", .{
.target = target,
.optimize = optimize,
.root_source_file = b.path("shaderTypes.zig"),
});
_ = mod;
}

9
lib/sdl3/shaderTypes/build.zig.zon vendored Normal file
View File

@ -0,0 +1,9 @@
.{
.name = .shaderTypes,
.version = "0.0.0",
.dependencies = .{},
.paths = .{
"",
},
.fingerprint = 0x1079649dca1ffcc3,
}

94
lib/sdl3/shaderTypes/shaderTypes.zig vendored Normal file
View File

@ -0,0 +1,94 @@
// Copyright (c) peterino2@github.com
//
// just struct definitions
const std = @import("std");
pub const vec2 = extern struct {
x: f32,
y: f32,
pub fn from(o: anytype) @This() {
return .{
.x = o.x,
.y = o.y,
};
}
};
pub const int = i32;
pub const uint = u32;
pub const u8vec4 = [4]u8;
pub const vec3 = extern struct {
x: f32,
y: f32,
z: f32,
pub fn from(o: anytype) @This() {
return .{
.x = o.x,
.y = o.y,
.z = o.z,
.pad = 0,
};
}
};
pub const vec4 = extern struct {
x: f32,
y: f32,
z: f32,
w: f32,
pub fn from(o: anytype) @This() {
return .{
.x = o.x,
.y = o.y,
.z = o.z,
.w = o.w,
};
}
};
pub const mat4 = [4][4]f32;
pub const float = f32;
pub fn CheckFieldDetails(
comptime T: type,
comptime fieldName: []const u8,
expectedOffset: usize,
expectedSize: usize,
) void {
const offset = @offsetOf(T, fieldName);
const size = @sizeOf(@TypeOf(@field(std.mem.zeroes(T), fieldName)));
if (offset != expectedOffset) {
const msg = std.fmt.comptimePrint(
"Unexpected field offset, {s} was expected at offset {d} but found at offset {d}",
.{ fieldName, expectedOffset, offset },
);
@compileError(msg);
}
if (size != expectedSize) {
const msg = std.fmt.comptimePrint(
"Unexpected field size, '{s}' was expected with size {d} but found at size {d}",
.{ fieldName, expectedSize, size },
);
@compileError(msg);
}
}
pub fn ValidateGeneratedStruct(comptime T: type) void {
for (@field(T, "FieldDetails")) |detail| {
CheckFieldDetails(T, detail.name, detail.offset, detail.size);
}
}
pub const FieldDetail = struct {
name: []const u8,
size: usize,
offset: usize,
};

15
lib/sdl3/spvreflect/reflected.zig vendored Normal file
View File

@ -0,0 +1,15 @@
pub const shaderTypes = @import("shaderTypes");
pub const int = shaderTypes.int;
pub const uint = shaderTypes.uint;
pub const vec2 = shaderTypes.vec2;
pub const u8vec4 = shaderTypes.u8vec4;
pub const vec3 = shaderTypes.vec3;
pub const vec4 = shaderTypes.vec4;
pub const mat4 = shaderTypes.mat4;
pub const float = shaderTypes.float;
pub const Scene = struct {
color: vec4,
};

View File

@ -1,5 +1,7 @@
import os import os
import argparse
import subprocess
import json
# quick and dirty dependency-free script to # quick and dirty dependency-free script to
# build and output reflected zig files for # build and output reflected zig files for
@ -8,3 +10,68 @@ import os
# usage: # usage:
# python spvreflect defs.json # python spvreflect defs.json
def generate():
print()
parser = argparse.ArgumentParser()
parser.add_argument('input', type=str, help="input file")
parser.add_argument('-o', '--output', type=str, help="output file")
args = parser.parse_args()
infile = os.path.abspath(args.input)
outfile = 'reflected.zig'
if args.output is not None:
outfile = args.output
reflect = None
with open(infile) as f:
reflect = json.load(f)
print(reflect)
ostring = "pub const shaderTypes = @import(\"shaderTypes\");\n"
ostring += """
pub const int = shaderTypes.int;
pub const uint = shaderTypes.uint;
pub const vec2 = shaderTypes.vec2;
pub const u8vec4 = shaderTypes.u8vec4;
pub const vec3 = shaderTypes.vec3;
pub const vec4 = shaderTypes.vec4;
pub const mat4 = shaderTypes.mat4;
pub const float = shaderTypes.float;
"""
types = reflect['types']
for t in types:
name = types[t]['name'];
if 'type.StructuredBuffer' in name:
continue
if name.startswith("type.StructuredBuffer"):
name = name[len("type.StructuredBuffer"):]
zs = f"pub const {name} = " + 'struct {\n'
for member in types[t]['members']:
zs += member['name'] + ':' + member['type'] + ',\n'
zs += "};\n"
print(zs)
ostring += zs
with open(outfile, 'w') as f:
f.write(ostring)
subprocess.run(['zig', 'fmt', outfile])
if __name__ == '__main__':
generate()
pass

View File

@ -139,6 +139,7 @@ pub fn loadShader(
.num_uniform_buffers = num_uniform_buffers, // The number of uniform buffers defined in the shader. .num_uniform_buffers = num_uniform_buffers, // The number of uniform buffers defined in the shader.
.props = 0, .props = 0,
}; };
std.debug.print("hello_triangle_vert.Scene => sizeof() = {d}", .{@sizeOf(hello_triangle_vert.Scene)});
return self.device.createGPUShader(&sci); return self.device.createGPUShader(&sci);
} }
@ -182,9 +183,9 @@ pub fn draw(self: *@This(), dt: f64) void {
var b: [*][4]f32 = @ptrCast(@alignCast(buffer)); var b: [*][4]f32 = @ptrCast(@alignCast(buffer));
b[0] = .{ @floatCast(std.math.sin(self.totalTime * 3 * 2 + 0.8) * 0.2 + 0.8), 0.4, 0.4, 0.0 }; b[0] = .{ @floatCast(std.math.sin(self.totalTime * 3 * 2 + 0.8) * 0.2 + 0.8), 0.4, 0.4, 1.0 };
b[1] = .{ 0.4, @floatCast(std.math.sin(self.totalTime * 2 * 2 + 0.3) * 0.2 + 0.8), 0.4, 0.0 }; b[1] = .{ 0.4, @floatCast(std.math.sin(self.totalTime * 2 * 2 + 0.3) * 0.2 + 0.8), 0.4, 1.0 };
b[2] = .{ 0.4, 0.4, @floatCast(std.math.sin(self.totalTime * 4 * 2) * 0.2 + 0.8), 0.0 }; b[2] = .{ 0.4, 0.4, @floatCast(std.math.sin(self.totalTime * 4 * 2) * 0.2 + 0.8), 1.0 };
self.device.unmapGPUTransferBuffer(self.colorBufferTransfer); self.device.unmapGPUTransferBuffer(self.colorBufferTransfer);
} }
@ -233,6 +234,7 @@ pub fn main() !void {
defer app.destroy(); defer app.destroy();
} }
const hello_triangle_vert = @import("hello-triangle.vert");
const sdl3 = @import("sdl3"); const sdl3 = @import("sdl3");
const gpu = sdl3.gpu; const gpu = sdl3.gpu;
const sdl_event = sdl3.events; const sdl_event = sdl3.events;

View File

@ -8,6 +8,7 @@ pub fn build(b: *std.Build) void {
var blbuild = Backlog.init(b, .{ var blbuild = Backlog.init(b, .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.backlogRoot = "../",
}); });
_ = blbuild.addProgram(.{ _ = blbuild.addProgram(.{

Binary file not shown.

View File

@ -0,0 +1,66 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Scene
{
float4 color;
};
struct type_StructuredBuffer_Scene
{
Scene _m0[1];
};
constant float2 _30 = {};
constant float4 _31 = {};
struct main0_out
{
float4 out_var_TEXCOORD0 [[user(locn0)]];
float4 gl_Position [[position]];
};
vertex main0_out main0(const device type_StructuredBuffer_Scene& test [[buffer(0)]], uint gl_VertexIndex [[vertex_id]])
{
main0_out out = {};
float4 _58;
float2 _59;
if (gl_VertexIndex == 0u)
{
_58 = test._m0[0u].color;
_59 = float2(-1.0);
}
else
{
float4 _56;
float2 _57;
if (gl_VertexIndex == 1u)
{
_56 = test._m0[1u].color;
_57 = float2(1.0, -1.0);
}
else
{
bool _48 = gl_VertexIndex == 2u;
float4 _53;
if (_48)
{
_53 = test._m0[2u].color;
}
else
{
_53 = _31;
}
_56 = _53;
_57 = select(_30, float2(0.0, 1.0), bool2(_48));
}
_58 = _56;
_59 = _57;
}
out.out_var_TEXCOORD0 = _58;
out.gl_Position = float4(_59, 0.0, 1.0);
return out;
}

Binary file not shown.

View File

@ -56,7 +56,8 @@ def discoverShaders():
shaderRoot = os.path.abspath(os.path.join(modRoot, 'shaders/')) shaderRoot = os.path.abspath(os.path.join(modRoot, 'shaders/'))
if os.path.isdir(os.path.join(modRoot, 'shaders/')): if os.path.isdir(os.path.join(modRoot, 'shaders/')):
for x in os.listdir(shaderRoot): for x in os.listdir(shaderRoot):
rv.append(os.path.abspath(os.path.join(shaderRoot, x))) if x.endswith(".hlsl"):
rv.append(os.path.abspath(os.path.join(shaderRoot, x)))
return rv return rv
@ -87,19 +88,18 @@ def cookList(inputFiles):
cmd = [shadercross, f] + fmt[1] + [ '-o', outfile ] cmd = [shadercross, f] + fmt[1] + [ '-o', outfile ]
if 'spv' == fmt[0]: if 'spv' == fmt[0]:
spvs.append(outfile) spvs.append((outfile, os.path.dirname(f)))
print(cmd) print(cmd)
subprocess.run(cmd) subprocess.run(cmd)
# run spirv-cross and generate .json files # run spirv-cross and generate .json files
for f in spvs: for f in spvs:
basefile = f[:-4] basefile = f[0][:-4]
outdir = os.path.join(cookedRoot, '_def') outfile = os.path.join(f[1], os.path.basename(basefile) + '.json' )
outfile = os.path.join(outdir, os.path.basename(basefile) + '.json' )
os.makedirs(os.path.dirname(outfile), exist_ok=True) os.makedirs(os.path.dirname(outfile), exist_ok=True)
cmd = ['spirv-cross', f, '--reflect', '--output', outfile ] cmd = ['spirv-cross', f[0], '--reflect', '--output', outfile ]
print(cmd) print(cmd)
subprocess.run(cmd) subprocess.run(cmd)