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
|
|
@ -29,6 +29,7 @@ pub const VTable = struct {
|
|||
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
|
||||
createCommandEncoder: fn (ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder,
|
||||
// WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor);
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncCallback callback, void * userdata);
|
||||
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateErrorBuffer(WGPUDevice device);
|
||||
// WGPU_EXPORT WGPUExternalTexture wgpuDeviceCreateExternalTexture(WGPUDevice device, WGPUExternalTextureDescriptor const * externalTextureDescriptor);
|
||||
|
|
@ -36,6 +37,7 @@ pub const VTable = struct {
|
|||
// WGPU_EXPORT WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor);
|
||||
// WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor);
|
||||
createRenderPipeline: fn (ptr: *anyopaque, descriptor: *const RenderPipeline.Descriptor) RenderPipeline,
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata);
|
||||
// WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor);
|
||||
createShaderModule: fn (ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule,
|
||||
|
|
@ -48,10 +50,14 @@ pub const VTable = struct {
|
|||
// WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeature feature);
|
||||
// WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message);
|
||||
// WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device);
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
||||
// WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter);
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
||||
// TODO: callback
|
||||
// WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
||||
// WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device);
|
||||
|
||||
|
|
|
|||
|
|
@ -575,6 +575,25 @@ const shader_module_vtable = ShaderModule.VTable{
|
|||
c.wgpuShaderModuleSetLabel(@ptrCast(c.WGPUShaderModule, ptr), label);
|
||||
}
|
||||
}).setLabel,
|
||||
.getCompilationInfo = (struct {
|
||||
pub fn getCompilationInfo(ptr: *anyopaque, callback: *ShaderModule.CompilationInfoCallback) void {
|
||||
const cCallback = (struct {
|
||||
pub fn cCallback(status: c.WGPUCompilationInfoRequestStatus, info: [*c]const c.WGPUCompilationInfo, userdata: ?*anyopaque) callconv(.C) void {
|
||||
const callback_info = @ptrCast(*ShaderModule.CompilationInfoCallback, @alignCast(@alignOf(*ShaderModule.CompilationInfoCallback), userdata.?));
|
||||
|
||||
callback_info.type_erased_callback(
|
||||
callback_info.type_erased_ctx,
|
||||
@intToEnum(ShaderModule.CompilationInfoRequestStatus, status),
|
||||
&ShaderModule.CompilationInfo{
|
||||
.messages = @bitCast([]const ShaderModule.CompilationMessage, info[0].messages[0..info[0].messageCount]),
|
||||
},
|
||||
);
|
||||
}
|
||||
}).cCallback;
|
||||
|
||||
c.wgpuShaderModuleGetCompilationInfo(@ptrCast(c.WGPUShaderModule, ptr), cCallback, callback);
|
||||
}
|
||||
}).getCompilationInfo,
|
||||
};
|
||||
|
||||
fn wrapSwapChain(swap_chain: c.WGPUSwapChain) SwapChain {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ typedef struct WGPUCopyTextureForBrowserOptions {
|
|||
|
||||
|
||||
|
||||
typedef void (*WGPUBufferMapCallback)(WGPUBufferMapAsyncStatus status, void * userdata);
|
||||
typedef void (*WGPUCompilationInfoCallback)(WGPUCompilationInfoRequestStatus status, WGPUCompilationInfo const * compilationInfo, void * userdata);
|
||||
typedef void (*WGPUCreateComputePipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, char const * message, void * userdata);
|
||||
typedef void (*WGPUCreateRenderPipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, char const * message, void * userdata);
|
||||
typedef void (*WGPUDeviceLostCallback)(WGPUDeviceLostReason reason, char const * message, void * userdata);
|
||||
|
|
|
|||
|
|
@ -69,19 +69,6 @@ pub const CompareFunction = enum(u32) {
|
|||
always = 0x00000008,
|
||||
};
|
||||
|
||||
pub const CompilationInfoRequestStatus = enum(u32) {
|
||||
success = 0x00000000,
|
||||
err = 0x00000001,
|
||||
device_lost = 0x00000002,
|
||||
unknown = 0x00000003,
|
||||
};
|
||||
|
||||
pub const CompilationMessageType = enum(u32) {
|
||||
err = 0x00000000,
|
||||
warning = 0x00000001,
|
||||
info = 0x00000002,
|
||||
};
|
||||
|
||||
pub const ComputePassTimestampLocation = enum(u32) {
|
||||
beginning = 0x00000000,
|
||||
end = 0x00000001,
|
||||
|
|
@ -284,8 +271,6 @@ test "syntax" {
|
|||
_ = BlendFactor;
|
||||
_ = BlendOperation;
|
||||
_ = CompareFunction;
|
||||
_ = CompilationInfoRequestStatus;
|
||||
_ = CompilationMessageType;
|
||||
_ = ComputePassTimestampLocation;
|
||||
_ = CreatePipelineAsyncStatus;
|
||||
_ = CullMode;
|
||||
|
|
|
|||
|
|
@ -94,8 +94,6 @@ pub const BlendState = @import("data.zig").BlendState;
|
|||
pub const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
||||
|
||||
// Data structures not ABI-compatible with webgpu.h
|
||||
pub const CompilationMessage = @import("structs.zig").CompilationMessage;
|
||||
pub const CompilationInfo = @import("structs.zig").CompilationInfo;
|
||||
pub const MultisampleState = @import("structs.zig").MultisampleState;
|
||||
pub const PrimitiveState = @import("structs.zig").PrimitiveState;
|
||||
pub const StorageTextureBindingLayout = @import("structs.zig").StorageTextureBindingLayout;
|
||||
|
|
@ -120,8 +118,6 @@ pub const AlphaMode = @import("enums.zig").AlphaMode;
|
|||
pub const BlendFactor = @import("enums.zig").BlendFactor;
|
||||
pub const BlendOperation = @import("enums.zig").BlendOperation;
|
||||
pub const CompareFunction = @import("enums.zig").CompareFunction;
|
||||
pub const CompilationInfoRequestStatus = @import("enums.zig").CompilationInfoRequestStatus;
|
||||
pub const CompilationMessageType = @import("enums.zig").CompilationMessageType;
|
||||
pub const ComputePassTimestampLocation = @import("enums.zig").ComputePassTimestampLocation;
|
||||
pub const CreatePipelineAsyncStatus = @import("enums.zig").CreatePipelineAsyncStatus;
|
||||
pub const CullMode = @import("enums.zig").CullMode;
|
||||
|
|
@ -192,7 +188,7 @@ test "syntax" {
|
|||
_ = Limits;
|
||||
|
||||
// Data structures not ABI-compatible with webgpu.h
|
||||
_ = CompilationMessage;
|
||||
_ = MultisampleState;
|
||||
|
||||
// Enumerations
|
||||
_ = Feature;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ const Color = @import("data.zig").Color;
|
|||
const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
||||
const BlendState = @import("data.zig").BlendState;
|
||||
const Origin3D = @import("data.zig").Origin3D;
|
||||
const CompilationMessageType = @import("enums.zig").CompilationMessageType;
|
||||
const PrimitiveTopology = @import("enums.zig").PrimitiveTopology;
|
||||
const IndexFormat = @import("enums.zig").IndexFormat;
|
||||
const FrontFace = @import("enums.zig").FrontFace;
|
||||
|
|
@ -23,19 +22,6 @@ const LoadOp = @import("enums.zig").LoadOp;
|
|||
const StoreOp = @import("enums.zig").StoreOp;
|
||||
const ColorWriteMask = @import("enums.zig").ColorWriteMask;
|
||||
|
||||
pub const CompilationMessage = struct {
|
||||
message: [:0]const u8,
|
||||
type: CompilationMessageType,
|
||||
line_num: u64,
|
||||
line_pos: u64,
|
||||
offset: u64,
|
||||
length: u64,
|
||||
};
|
||||
|
||||
pub const CompilationInfo = struct {
|
||||
messages: []const CompilationMessage,
|
||||
};
|
||||
|
||||
pub const MultisampleState = struct {
|
||||
count: u32,
|
||||
mask: u32,
|
||||
|
|
@ -150,8 +136,6 @@ pub const ImageCopyTexture = struct {
|
|||
};
|
||||
|
||||
test "syntax" {
|
||||
_ = CompilationMessage;
|
||||
_ = CompilationInfo;
|
||||
_ = MultisampleState;
|
||||
_ = PrimitiveState;
|
||||
_ = StorageTextureBindingLayout;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue