gpu: implement ShaderModule.getCompilationInfo
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
77b2210587
commit
3ce0e1258a
7 changed files with 90 additions and 46 deletions
|
|
@ -8,23 +8,75 @@ vtable: *const VTable,
|
|||
pub const VTable = struct {
|
||||
reference: fn (ptr: *anyopaque) void,
|
||||
release: fn (ptr: *anyopaque) void,
|
||||
// TODO:
|
||||
// WGPU_EXPORT void wgpuShaderModuleGetCompilationInfo(WGPUShaderModule shaderModule, WGPUCompilationInfoCallback callback, void * userdata);
|
||||
setLabel: fn (ptr: *anyopaque, label: [:0]const u8) void,
|
||||
getCompilationInfo: fn (ptr: *anyopaque, callback: *CompilationInfoCallback) void,
|
||||
};
|
||||
|
||||
pub inline fn reference(queue: ShaderModule) void {
|
||||
queue.vtable.reference(queue.ptr);
|
||||
pub inline fn reference(shader: ShaderModule) void {
|
||||
shader.vtable.reference(shader.ptr);
|
||||
}
|
||||
|
||||
pub inline fn release(queue: ShaderModule) void {
|
||||
queue.vtable.release(queue.ptr);
|
||||
pub inline fn release(shader: ShaderModule) void {
|
||||
shader.vtable.release(shader.ptr);
|
||||
}
|
||||
|
||||
pub inline fn setLabel(queue: ShaderModule, label: [:0]const u8) void {
|
||||
queue.vtable.setLabel(queue.ptr, label);
|
||||
pub inline fn setLabel(shader: ShaderModule, label: [:0]const u8) void {
|
||||
shader.vtable.setLabel(shader.ptr, label);
|
||||
}
|
||||
|
||||
pub inline fn getCompilationInfo(shader: ShaderModule, callback: *CompilationInfoCallback) void {
|
||||
shader.vtable.getCompilationInfo(shader.ptr, callback);
|
||||
}
|
||||
|
||||
pub const CompilationInfoCallback = struct {
|
||||
type_erased_ctx: *anyopaque,
|
||||
type_erased_callback: fn (ctx: *anyopaque, status: CompilationInfoRequestStatus, info: *const CompilationInfo) callconv(.Inline) void,
|
||||
|
||||
pub fn init(
|
||||
comptime Context: type,
|
||||
ctx: *Context,
|
||||
comptime callback: fn (ctx: *Context, status: CompilationInfoRequestStatus, info: *const CompilationInfo) void,
|
||||
) CompilationInfoCallback {
|
||||
const erased = (struct {
|
||||
pub inline fn erased(type_erased_ctx: *anyopaque, status: CompilationInfoRequestStatus) void {
|
||||
callback(@ptrCast(*Context, @alignCast(@alignOf(*Context), type_erased_ctx)), status);
|
||||
}
|
||||
}).erased;
|
||||
|
||||
return .{
|
||||
.type_erased_ctx = ctx,
|
||||
.type_erased_callback = erased,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const CompilationInfoRequestStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
device_lost = 0x00000002,
|
||||
unknown = 0x00000003,
|
||||
};
|
||||
|
||||
pub const CompilationInfo = struct {
|
||||
messages: []const CompilationMessage,
|
||||
};
|
||||
|
||||
pub const CompilationMessageType = enum(u32) {
|
||||
err = 0x00000000,
|
||||
warning = 0x00000001,
|
||||
info = 0x00000002,
|
||||
};
|
||||
|
||||
pub const CompilationMessage = extern struct {
|
||||
reserved: ?*anyopaque = null,
|
||||
message: [*:0]const u8,
|
||||
type: CompilationMessageType,
|
||||
line_num: u64,
|
||||
line_pos: u64,
|
||||
offset: u64,
|
||||
length: u64,
|
||||
};
|
||||
|
||||
pub const CodeTag = enum {
|
||||
spirv,
|
||||
wgsl,
|
||||
|
|
@ -42,6 +94,10 @@ test "syntax" {
|
|||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
_ = CompilationInfoRequestStatus;
|
||||
_ = CompilationInfo;
|
||||
_ = CompilationMessageType;
|
||||
_ = CompilationMessage;
|
||||
_ = CodeTag;
|
||||
_ = Descriptor;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue