fixing example performance issues
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@
|
||||
zig-out/
|
||||
.gdb_history
|
||||
*.o
|
||||
vgcore*
|
||||
callgrind*
|
||||
|
||||
14
build.zig
14
build.zig
@@ -23,6 +23,11 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
// Zig example setup
|
||||
|
||||
const sdl3 = b.lazyDependency("sdl3", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
}) orelse return;
|
||||
|
||||
const example_exe = b.addExecutable(.{
|
||||
.name = "spirv_interpreter_example",
|
||||
.root_module = b.createModule(.{
|
||||
@@ -31,17 +36,12 @@ pub fn build(b: *std.Build) void {
|
||||
.optimize = optimize,
|
||||
.imports = &.{
|
||||
.{ .name = "spv", .module = mod },
|
||||
.{ .name = "pretty", .module = pretty.module("pretty") },
|
||||
.{ .name = "sdl3", .module = sdl3.module("sdl3") },
|
||||
//.{ .name = "pretty", .module = pretty.module("pretty") },
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const sdl3 = b.lazyDependency("sdl3", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
}) orelse return;
|
||||
example_exe.root_module.addImport("sdl3", sdl3.module("sdl3"));
|
||||
|
||||
const example_install = b.addInstallArtifact(example_exe, .{});
|
||||
example_install.step.dependOn(&lib_install.step);
|
||||
|
||||
|
||||
@@ -9,8 +9,11 @@ const screen_height = 480;
|
||||
|
||||
pub fn main() !void {
|
||||
{
|
||||
var gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
defer _ = gpa.deinit();
|
||||
//var gpa: std.heap.DebugAllocator(.{}) = .init;
|
||||
//defer _ = gpa.deinit();
|
||||
|
||||
var gpa = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
defer gpa.deinit();
|
||||
|
||||
defer sdl3.shutdown();
|
||||
const init_flags = sdl3.InitFlags{ .video = true };
|
||||
@@ -22,7 +25,7 @@ pub fn main() !void {
|
||||
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
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);
|
||||
|
||||
const surface = try window.getSurface();
|
||||
@@ -72,10 +75,10 @@ pub fn main() !void {
|
||||
try rt.readOutput(f32, output[0..], color);
|
||||
|
||||
const rgba = surface.mapRgba(
|
||||
@intFromFloat(output[0] * 255.0),
|
||||
@intFromFloat(output[1] * 255.0),
|
||||
@intFromFloat(output[2] * 255.0),
|
||||
@intFromFloat(output[3] * 255.0),
|
||||
@truncate(@as(u32, @intFromFloat(output[0] * 255.0))),
|
||||
@truncate(@as(u32, @intFromFloat(output[1] * 255.0))),
|
||||
@truncate(@as(u32, @intFromFloat(output[2] * 255.0))),
|
||||
@truncate(@as(u32, @intFromFloat(output[3] * 255.0))),
|
||||
);
|
||||
|
||||
pixel_map[(y * surface.getWidth()) + x] = rgba.value;
|
||||
|
||||
@@ -270,39 +270,39 @@ fn writeValue(self: *const Self, comptime T: type, input: []const T, value: *Res
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
}
|
||||
},
|
||||
.Vector4f32 => |vec| inline for (0..4) |i| switch (T) {
|
||||
.Vector4f32 => |*vec| inline for (0..4) |i| switch (T) {
|
||||
f32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector3f32 => |vec| inline for (0..3) |i| switch (T) {
|
||||
.Vector3f32 => |*vec| inline for (0..3) |i| switch (T) {
|
||||
f32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector2f32 => |vec| inline for (0..2) |i| switch (T) {
|
||||
.Vector2f32 => |*vec| inline for (0..2) |i| switch (T) {
|
||||
f32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector4i32 => |vec| inline for (0..4) |i| switch (T) {
|
||||
.Vector4i32 => |*vec| inline for (0..4) |i| switch (T) {
|
||||
i32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector3i32 => |vec| inline for (0..3) |i| switch (T) {
|
||||
.Vector3i32 => |*vec| inline for (0..3) |i| switch (T) {
|
||||
i32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector2i32 => |vec| inline for (0..2) |i| switch (T) {
|
||||
.Vector2i32 => |*vec| inline for (0..2) |i| switch (T) {
|
||||
i32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector4u32 => |vec| inline for (0..4) |i| switch (T) {
|
||||
.Vector4u32 => |*vec| inline for (0..4) |i| switch (T) {
|
||||
u32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector3u32 => |vec| inline for (0..3) |i| switch (T) {
|
||||
.Vector3u32 => |*vec| inline for (0..3) |i| switch (T) {
|
||||
u32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
.Vector2u32 => |vec| inline for (0..2) |i| switch (T) {
|
||||
.Vector2u32 => |*vec| inline for (0..2) |i| switch (T) {
|
||||
u32 => vec[i] = input[i],
|
||||
inline else => return RuntimeError.InvalidValueType,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user