47 lines
1.3 KiB
Zig
47 lines
1.3 KiB
Zig
const std = @import("std");
|
|
const spv = @import("spv");
|
|
|
|
const shader_source = @embedFile("shader.spv");
|
|
|
|
const Input = struct {
|
|
value: [4]i32 = [4]i32{ 0, 0, 0, 0 },
|
|
};
|
|
|
|
const Output = struct {
|
|
value: [4]i32 = [4]i32{ 0, 0, 0, 0 },
|
|
};
|
|
|
|
pub fn main() !void {
|
|
{
|
|
var gpa: std.heap.DebugAllocator(.{
|
|
.enable_memory_limit = true,
|
|
}) = .init;
|
|
defer _ = gpa.deinit();
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
|
|
defer module.deinit(allocator);
|
|
|
|
var rt = try spv.Runtime.init(allocator, &module);
|
|
defer rt.deinit(allocator);
|
|
|
|
const entry = try rt.getEntryPointByName("main");
|
|
|
|
var input: Input = .{};
|
|
var output: Output = .{};
|
|
|
|
try rt.writeDescriptorSet(Input, allocator, &input, 0, 0);
|
|
try rt.writeDescriptorSet(Output, allocator, &output, 0, 1);
|
|
|
|
try rt.callEntryPoint(allocator, entry);
|
|
|
|
try rt.readDescriptorSet(Output, allocator, &output, 0, 1);
|
|
|
|
std.log.info("Output: {any}", .{output});
|
|
|
|
std.log.info("\nTotal memory used: {d:.3} KB\n", .{@as(f32, @floatFromInt(gpa.total_requested_bytes)) / 1000.0});
|
|
}
|
|
std.log.info("Successfully executed", .{});
|
|
}
|