REleted gpu.zig and created a lib.zig to output a module

This commit is contained in:
adrien 2026-05-15 10:27:45 +02:00
parent 6018b5f0ff
commit 4725723d42
4 changed files with 11 additions and 9 deletions

View File

@ -17,6 +17,11 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// 1. Define the module so other projects can import it
_ = b.addModule("zig-wgpu", .{
.root_source_file = b.path("src/lib.zig"),
});
const exe = b.addExecutable(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),

View File

@ -1,5 +0,0 @@
const std = @import("std");
const c = @import("c.zig").c;
pub const GpuAllocator = @import("GpuAllocator.zig");
pub const Mat = @import("Mat.zig");

1
src/lib.zig Normal file
View File

@ -0,0 +1 @@
pub const GpuAllocator = @import("GpuAllocator.zig");

View File

@ -1,8 +1,9 @@
const std = @import("std");
const gpu = @import("gpu.zig");
const GpuAllocator = @import("GpuAllocator.zig");
const Mat = @import("Mat.zig");
pub fn main() !void {
var gloc = try gpu.GpuAllocator.init();
var gloc = try GpuAllocator.init();
defer gloc.deinit();
// Input data: a[i] = i, b[i] = 15 - i add should give all 15s
@ -13,9 +14,9 @@ pub fn main() !void {
data_b[i] = @floatFromInt(15 - i);
}
const a = try gpu.Mat.load(&gloc, &data_a, 4, 4);
const a = try Mat.load(&gloc, &data_a, 4, 4);
defer a.deinit();
const b = try gpu.Mat.load(&gloc, &data_b, 4, 4);
const b = try Mat.load(&gloc, &data_b, 4, 4);
defer b.deinit();
// a + b