gpu: prepare to implement Surface
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
9888d8fe36
commit
64e023c992
4 changed files with 74 additions and 8 deletions
|
|
@ -8,5 +8,10 @@ vtable: *const VTable,
|
|||
|
||||
pub const VTable = struct {
|
||||
// TODO(gpu): make these *const fn once stage2 is released.
|
||||
free: fn (ptr: *anyopaque, buf: []u8, buf_align: u29, ret_addr: usize) void,
|
||||
deinit: fn (ptr: *anyopaque) void,
|
||||
};
|
||||
|
||||
// TODO:
|
||||
// WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata);
|
||||
// WGPU_EXPORT void wgpuInstanceReference(WGPUInstance instance);
|
||||
// WGPU_EXPORT void wgpuInstanceRelease(WGPUInstance instance);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,29 @@
|
|||
//! A native webgpu.h implementation of the gpu.Interface
|
||||
const c = @import("c.zig").c;
|
||||
const Interface = @import("Interface.zig");
|
||||
const Surface = @import("Surface.zig");
|
||||
|
||||
const NativeInstance = @This();
|
||||
|
||||
/// The WGPUInstance that is wrapped by this native instance.
|
||||
instance: c.WGPUInstance,
|
||||
|
||||
/// Returns the gpu.Interface for interacting with this native instance.
|
||||
pub fn interface(native: NativeInstance) Interface {
|
||||
_ = native;
|
||||
@panic("not implemented");
|
||||
vtable: Interface.VTable,
|
||||
|
||||
/// Wraps a native WGPUInstance to provide an implementation of the gpu.Interface.
|
||||
pub fn wrap(instance: c.WGPUInstance) NativeInstance {
|
||||
return .{ .instance = instance };
|
||||
}
|
||||
|
||||
/// Returns the gpu.Interface for interacting with this native instance.
|
||||
pub fn interface(native: *const NativeInstance) Interface {
|
||||
return .{
|
||||
.ptr = native,
|
||||
.vtable = native.vtable,
|
||||
};
|
||||
// TODO: implement Interface
|
||||
// WGPU_EXPORT void wgpuInstanceReference(WGPUInstance instance);
|
||||
// WGPU_EXPORT void wgpuInstanceRelease(WGPUInstance instance);
|
||||
|
||||
// TODO: implement Device interface
|
||||
|
||||
|
|
@ -25,7 +36,9 @@ pub fn interface(native: NativeInstance) Interface {
|
|||
// WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties);
|
||||
}
|
||||
|
||||
/// Wraps a native WGPUInstance to provide an implementation of the gpu.Interface.
|
||||
pub fn wrap(instance: c.WGPUInstance) NativeInstance {
|
||||
return .{ .instance = instance };
|
||||
pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.Descriptor) Surface {
|
||||
_ = native;
|
||||
_ = descriptor;
|
||||
// TODO:
|
||||
// WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor);
|
||||
}
|
||||
|
|
|
|||
46
gpu/src/Surface.zig
Normal file
46
gpu/src/Surface.zig
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//! A native WebGPU surface
|
||||
|
||||
// typedef enum WGPUSType {
|
||||
// WGPUSType_Invalid = 0x00000000,
|
||||
// WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001,
|
||||
// WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002,
|
||||
// WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003,
|
||||
// WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
|
||||
|
||||
const Descriptor = struct {};
|
||||
// typedef struct WGPUSurfaceDescriptor {
|
||||
// WGPUChainedStruct const * nextInChain;
|
||||
// char const * label;
|
||||
// } WGPUSurfaceDescriptor;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromCanvasHTMLSelector {
|
||||
// WGPUChainedStruct chain;
|
||||
// char const * selector;
|
||||
// } WGPUSurfaceDescriptorFromCanvasHTMLSelector;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromMetalLayer {
|
||||
// WGPUChainedStruct chain;
|
||||
// void * layer;
|
||||
// } WGPUSurfaceDescriptorFromMetalLayer;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromWindowsCoreWindow {
|
||||
// WGPUChainedStruct chain;
|
||||
// void * coreWindow;
|
||||
// } WGPUSurfaceDescriptorFromWindowsCoreWindow;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromWindowsHWND {
|
||||
// WGPUChainedStruct chain;
|
||||
// void * hinstance;
|
||||
// void * hwnd;
|
||||
// } WGPUSurfaceDescriptorFromWindowsHWND;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromWindowsSwapChainPanel {
|
||||
// WGPUChainedStruct chain;
|
||||
// void * swapChainPanel;
|
||||
// } WGPUSurfaceDescriptorFromWindowsSwapChainPanel;
|
||||
|
||||
// typedef struct WGPUSurfaceDescriptorFromXlibWindow {
|
||||
// WGPUChainedStruct chain;
|
||||
// void * display;
|
||||
// uint32_t window;
|
||||
// } WGPUSurfaceDescriptorFromXlibWindow;
|
||||
|
|
@ -21,6 +21,7 @@ const NativeInstance = @import("NativeInstance.zig");
|
|||
|
||||
const Adapter = @import("Adapter.zig");
|
||||
const Device = @import("Device.zig");
|
||||
const Surface = @import("Surface.zig");
|
||||
|
||||
const FeatureName = @import("feature_name.zig").FeatureName;
|
||||
const SupportedLimits = @import("supported_limits.zig").SupportedLimits;
|
||||
|
|
@ -31,6 +32,7 @@ test "syntax" {
|
|||
|
||||
_ = Adapter;
|
||||
_ = Device;
|
||||
_ = Surface;
|
||||
|
||||
_ = FeatureName;
|
||||
_ = SupportedLimits;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue