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);
|
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor);
|
||||||
createCommandEncoder: fn (ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder,
|
createCommandEncoder: fn (ptr: *anyopaque, descriptor: ?*const CommandEncoder.Descriptor) CommandEncoder,
|
||||||
// WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor);
|
// 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 void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncCallback callback, void * userdata);
|
||||||
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateErrorBuffer(WGPUDevice device);
|
// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateErrorBuffer(WGPUDevice device);
|
||||||
// WGPU_EXPORT WGPUExternalTexture wgpuDeviceCreateExternalTexture(WGPUDevice device, WGPUExternalTextureDescriptor const * externalTextureDescriptor);
|
// 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 WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor);
|
||||||
// WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor);
|
// WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor);
|
||||||
createRenderPipeline: fn (ptr: *anyopaque, descriptor: *const RenderPipeline.Descriptor) RenderPipeline,
|
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 void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata);
|
||||||
// WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor);
|
// WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor);
|
||||||
createShaderModule: fn (ptr: *anyopaque, descriptor: *const ShaderModule.Descriptor) ShaderModule,
|
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 bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeature feature);
|
||||||
// WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message);
|
// WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message);
|
||||||
// WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device);
|
// WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device);
|
||||||
|
// TODO: callback
|
||||||
// WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
// WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
||||||
// WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter);
|
// WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter);
|
||||||
|
// TODO: callback
|
||||||
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata);
|
||||||
|
// TODO: callback
|
||||||
// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata);
|
// 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 wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata);
|
||||||
// WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device);
|
// WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -575,6 +575,25 @@ const shader_module_vtable = ShaderModule.VTable{
|
||||||
c.wgpuShaderModuleSetLabel(@ptrCast(c.WGPUShaderModule, ptr), label);
|
c.wgpuShaderModuleSetLabel(@ptrCast(c.WGPUShaderModule, ptr), label);
|
||||||
}
|
}
|
||||||
}).setLabel,
|
}).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 {
|
fn wrapSwapChain(swap_chain: c.WGPUSwapChain) SwapChain {
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,75 @@ vtable: *const VTable,
|
||||||
pub const VTable = struct {
|
pub const VTable = struct {
|
||||||
reference: fn (ptr: *anyopaque) void,
|
reference: fn (ptr: *anyopaque) void,
|
||||||
release: 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,
|
setLabel: fn (ptr: *anyopaque, label: [:0]const u8) void,
|
||||||
|
getCompilationInfo: fn (ptr: *anyopaque, callback: *CompilationInfoCallback) void,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub inline fn reference(queue: ShaderModule) void {
|
pub inline fn reference(shader: ShaderModule) void {
|
||||||
queue.vtable.reference(queue.ptr);
|
shader.vtable.reference(shader.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn release(queue: ShaderModule) void {
|
pub inline fn release(shader: ShaderModule) void {
|
||||||
queue.vtable.release(queue.ptr);
|
shader.vtable.release(shader.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn setLabel(queue: ShaderModule, label: [:0]const u8) void {
|
pub inline fn setLabel(shader: ShaderModule, label: [:0]const u8) void {
|
||||||
queue.vtable.setLabel(queue.ptr, label);
|
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 {
|
pub const CodeTag = enum {
|
||||||
spirv,
|
spirv,
|
||||||
wgsl,
|
wgsl,
|
||||||
|
|
@ -42,6 +94,10 @@ test "syntax" {
|
||||||
_ = VTable;
|
_ = VTable;
|
||||||
_ = reference;
|
_ = reference;
|
||||||
_ = release;
|
_ = release;
|
||||||
|
_ = CompilationInfoRequestStatus;
|
||||||
|
_ = CompilationInfo;
|
||||||
|
_ = CompilationMessageType;
|
||||||
|
_ = CompilationMessage;
|
||||||
_ = CodeTag;
|
_ = CodeTag;
|
||||||
_ = Descriptor;
|
_ = 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 (*WGPUCreateComputePipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, char const * message, void * userdata);
|
||||||
typedef void (*WGPUCreateRenderPipelineAsyncCallback)(WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline 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);
|
typedef void (*WGPUDeviceLostCallback)(WGPUDeviceLostReason reason, char const * message, void * userdata);
|
||||||
|
|
|
||||||
|
|
@ -69,19 +69,6 @@ pub const CompareFunction = enum(u32) {
|
||||||
always = 0x00000008,
|
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) {
|
pub const ComputePassTimestampLocation = enum(u32) {
|
||||||
beginning = 0x00000000,
|
beginning = 0x00000000,
|
||||||
end = 0x00000001,
|
end = 0x00000001,
|
||||||
|
|
@ -284,8 +271,6 @@ test "syntax" {
|
||||||
_ = BlendFactor;
|
_ = BlendFactor;
|
||||||
_ = BlendOperation;
|
_ = BlendOperation;
|
||||||
_ = CompareFunction;
|
_ = CompareFunction;
|
||||||
_ = CompilationInfoRequestStatus;
|
|
||||||
_ = CompilationMessageType;
|
|
||||||
_ = ComputePassTimestampLocation;
|
_ = ComputePassTimestampLocation;
|
||||||
_ = CreatePipelineAsyncStatus;
|
_ = CreatePipelineAsyncStatus;
|
||||||
_ = CullMode;
|
_ = CullMode;
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,6 @@ pub const BlendState = @import("data.zig").BlendState;
|
||||||
pub const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
pub const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
||||||
|
|
||||||
// Data structures not ABI-compatible with webgpu.h
|
// 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 MultisampleState = @import("structs.zig").MultisampleState;
|
||||||
pub const PrimitiveState = @import("structs.zig").PrimitiveState;
|
pub const PrimitiveState = @import("structs.zig").PrimitiveState;
|
||||||
pub const StorageTextureBindingLayout = @import("structs.zig").StorageTextureBindingLayout;
|
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 BlendFactor = @import("enums.zig").BlendFactor;
|
||||||
pub const BlendOperation = @import("enums.zig").BlendOperation;
|
pub const BlendOperation = @import("enums.zig").BlendOperation;
|
||||||
pub const CompareFunction = @import("enums.zig").CompareFunction;
|
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 ComputePassTimestampLocation = @import("enums.zig").ComputePassTimestampLocation;
|
||||||
pub const CreatePipelineAsyncStatus = @import("enums.zig").CreatePipelineAsyncStatus;
|
pub const CreatePipelineAsyncStatus = @import("enums.zig").CreatePipelineAsyncStatus;
|
||||||
pub const CullMode = @import("enums.zig").CullMode;
|
pub const CullMode = @import("enums.zig").CullMode;
|
||||||
|
|
@ -192,7 +188,7 @@ test "syntax" {
|
||||||
_ = Limits;
|
_ = Limits;
|
||||||
|
|
||||||
// Data structures not ABI-compatible with webgpu.h
|
// Data structures not ABI-compatible with webgpu.h
|
||||||
_ = CompilationMessage;
|
_ = MultisampleState;
|
||||||
|
|
||||||
// Enumerations
|
// Enumerations
|
||||||
_ = Feature;
|
_ = Feature;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ const Color = @import("data.zig").Color;
|
||||||
const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
const VertexBufferLayout = @import("data.zig").VertexBufferLayout;
|
||||||
const BlendState = @import("data.zig").BlendState;
|
const BlendState = @import("data.zig").BlendState;
|
||||||
const Origin3D = @import("data.zig").Origin3D;
|
const Origin3D = @import("data.zig").Origin3D;
|
||||||
const CompilationMessageType = @import("enums.zig").CompilationMessageType;
|
|
||||||
const PrimitiveTopology = @import("enums.zig").PrimitiveTopology;
|
const PrimitiveTopology = @import("enums.zig").PrimitiveTopology;
|
||||||
const IndexFormat = @import("enums.zig").IndexFormat;
|
const IndexFormat = @import("enums.zig").IndexFormat;
|
||||||
const FrontFace = @import("enums.zig").FrontFace;
|
const FrontFace = @import("enums.zig").FrontFace;
|
||||||
|
|
@ -23,19 +22,6 @@ const LoadOp = @import("enums.zig").LoadOp;
|
||||||
const StoreOp = @import("enums.zig").StoreOp;
|
const StoreOp = @import("enums.zig").StoreOp;
|
||||||
const ColorWriteMask = @import("enums.zig").ColorWriteMask;
|
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 {
|
pub const MultisampleState = struct {
|
||||||
count: u32,
|
count: u32,
|
||||||
mask: u32,
|
mask: u32,
|
||||||
|
|
@ -150,8 +136,6 @@ pub const ImageCopyTexture = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
test "syntax" {
|
test "syntax" {
|
||||||
_ = CompilationMessage;
|
|
||||||
_ = CompilationInfo;
|
|
||||||
_ = MultisampleState;
|
_ = MultisampleState;
|
||||||
_ = PrimitiveState;
|
_ = PrimitiveState;
|
||||||
_ = StorageTextureBindingLayout;
|
_ = StorageTextureBindingLayout;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue