mach/src/gpu/shader_module.zig
Stephen Gutekanst 2cf68adcc7 src/gpu: move github.com/hexops/mach-gpu here
This moves github.com/hexops/mach-gpu@528dad0823dafeae5d474c88cc658b091bf2e605 to
this repository in the src/gpu directory. It can be imported via `@import("mach").gpu`.

Soon we will move away from mach-gpu entirely as part of #1166 - but in the meantime
I am giving a workshop at https://sycl.it and it would be nice for people using the
`mach.gpu.*` API to be able to search the API in this single repository.

There's not much harm to moving this code here.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2024-04-13 11:25:45 -07:00

69 lines
2.5 KiB
Zig

const ChainedStruct = @import("main.zig").ChainedStruct;
const CompilationInfoCallback = @import("main.zig").CompilationInfoCallback;
const CompilationInfoRequestStatus = @import("main.zig").CompilationInfoRequestStatus;
const CompilationInfo = @import("main.zig").CompilationInfo;
const Impl = @import("interface.zig").Impl;
const dawn = @import("dawn.zig");
pub const ShaderModule = opaque {
pub const Descriptor = extern struct {
pub const NextInChain = extern union {
generic: ?*const ChainedStruct,
spirv_descriptor: ?*const SPIRVDescriptor,
wgsl_descriptor: ?*const WGSLDescriptor,
dawn_shader_module_spirv_options_descriptor: ?*const dawn.ShaderModuleSPIRVOptionsDescriptor,
};
next_in_chain: NextInChain = .{ .generic = null },
label: ?[*:0]const u8 = null,
};
pub const SPIRVDescriptor = extern struct {
chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_spirv_descriptor },
code_size: u32,
code: [*]const u32,
};
pub const WGSLDescriptor = extern struct {
chain: ChainedStruct = .{ .next = null, .s_type = .shader_module_wgsl_descriptor },
code: [*:0]const u8,
};
pub inline fn getCompilationInfo(
shader_module: *ShaderModule,
context: anytype,
comptime callback: fn (
ctx: @TypeOf(context),
status: CompilationInfoRequestStatus,
compilation_info: *const CompilationInfo,
) callconv(.Inline) void,
) void {
const Context = @TypeOf(context);
const Helper = struct {
pub fn cCallback(
status: CompilationInfoRequestStatus,
compilation_info: *const CompilationInfo,
userdata: ?*anyopaque,
) callconv(.C) void {
callback(
if (Context == void) {} else @as(Context, @ptrCast(@alignCast(userdata))),
status,
compilation_info,
);
}
};
Impl.shaderModuleGetCompilationInfo(shader_module, Helper.cCallback, if (Context == void) null else context);
}
pub inline fn setLabel(shader_module: *ShaderModule, label: [*:0]const u8) void {
Impl.shaderModuleSetLabel(shader_module, label);
}
pub inline fn reference(shader_module: *ShaderModule) void {
Impl.shaderModuleReference(shader_module);
}
pub inline fn release(shader_module: *ShaderModule) void {
Impl.shaderModuleRelease(shader_module);
}
};