gpu: begin implementing Surface

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-06 20:44:38 -07:00 committed by Stephen Gutekanst
parent 64e023c992
commit 89b1f31de8
4 changed files with 96 additions and 86 deletions

View file

@ -37,8 +37,67 @@ pub fn interface(native: *const NativeInstance) Interface {
} }
pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.Descriptor) Surface { pub fn createSurface(native: *const NativeInstance, descriptor: *const Surface.Descriptor) Surface {
// typedef enum WGPUSType {
// WGPUSType_Invalid = 0x00000000,
// WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001,
// WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002,
// WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003,
// WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
// WGPUSType_SurfaceDescriptorFromWindowsCoreWindow = 0x00000008,
// WGPUSType_SurfaceDescriptorFromWindowsSwapChainPanel = 0x0000000B,
// 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;
//c.wgpuInstanceCreateSurface(native.instance, )
_ = native; _ = native;
_ = descriptor; _ = descriptor;
// TODO: // TODO:
// WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor); // WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor);
} }
// var desc: c.WGPUSurfaceDescriptorFromWindowsHWND = undefined;
// desc.chain.next = null;
// desc.chain.sType = c.WGPUSType_SurfaceDescriptorFromWindowsHWND;
// desc.hinstance = std.os.windows.kernel32.GetModuleHandleW(null);
// desc.hwnd = glfw_native.getWin32Window(window);
// var descriptor: c.WGPUSurfaceDescriptor = undefined;
// descriptor.nextInChain = @ptrCast(*c.WGPUChainedStruct, &desc);
// descriptor.label = "basic surface";
// return c.wgpuInstanceCreateSurface(instance, &descriptor);

View file

@ -1,46 +1,39 @@
//! A native WebGPU surface //! A native WebGPU surface
// typedef enum WGPUSType { pub const DescriptorTag = enum {
// WGPUSType_Invalid = 0x00000000, metal_layer,
// WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001, windows_hwnd,
// WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002, windows_core_window,
// WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003, windows_swap_chain_panel,
// WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004, xlib_window,
canvas_html_selector,
};
const Descriptor = struct {}; pub const Descriptor = union(DescriptorTag) {
// typedef struct WGPUSurfaceDescriptor { metal_layer: struct {
// WGPUChainedStruct const * nextInChain; label: ?[]const u8,
// char const * label; layer: *anyopaque,
// } WGPUSurfaceDescriptor; },
windows_hwnd: struct {
// typedef struct WGPUSurfaceDescriptorFromCanvasHTMLSelector { label: ?[]const u8,
// WGPUChainedStruct chain; hinstance: *anyopaque,
// char const * selector; hwnd: *anyopaque,
// } WGPUSurfaceDescriptorFromCanvasHTMLSelector; },
windows_core_window: struct {
// typedef struct WGPUSurfaceDescriptorFromMetalLayer { label: ?[]const u8,
// WGPUChainedStruct chain; core_window: *anyopaque,
// void * layer; },
// } WGPUSurfaceDescriptorFromMetalLayer; windows_swap_chain_panel: struct {
label: ?[]const u8,
// typedef struct WGPUSurfaceDescriptorFromWindowsCoreWindow { swap_chain_panel: *anyopaque,
// WGPUChainedStruct chain; },
// void * coreWindow; xlib_window: struct {
// } WGPUSurfaceDescriptorFromWindowsCoreWindow; label: ?[]const u8,
display: *anyopaque,
// typedef struct WGPUSurfaceDescriptorFromWindowsHWND { window: u32,
// WGPUChainedStruct chain; },
// void * hinstance; canvas_html_selector: struct {
// void * hwnd; label: ?[]const u8,
// } WGPUSurfaceDescriptorFromWindowsHWND; selector: []const u8,
},
// typedef struct WGPUSurfaceDescriptorFromWindowsSwapChainPanel { };
// WGPUChainedStruct chain;
// void * swapChainPanel;
// } WGPUSurfaceDescriptorFromWindowsSwapChainPanel;
// typedef struct WGPUSurfaceDescriptorFromXlibWindow {
// WGPUChainedStruct chain;
// void * display;
// uint32_t window;
// } WGPUSurfaceDescriptorFromXlibWindow;

View file

@ -299,16 +299,10 @@ typedef enum WGPURequestDeviceStatus {
typedef enum WGPUSType { typedef enum WGPUSType {
WGPUSType_Invalid = 0x00000000, WGPUSType_Invalid = 0x00000000,
WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001,
WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002,
WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003,
WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
WGPUSType_ShaderModuleSPIRVDescriptor = 0x00000005, WGPUSType_ShaderModuleSPIRVDescriptor = 0x00000005,
WGPUSType_ShaderModuleWGSLDescriptor = 0x00000006, WGPUSType_ShaderModuleWGSLDescriptor = 0x00000006,
WGPUSType_SurfaceDescriptorFromWindowsCoreWindow = 0x00000008,
WGPUSType_ExternalTextureBindingEntry = 0x00000009, WGPUSType_ExternalTextureBindingEntry = 0x00000009,
WGPUSType_ExternalTextureBindingLayout = 0x0000000A, WGPUSType_ExternalTextureBindingLayout = 0x0000000A,
WGPUSType_SurfaceDescriptorFromWindowsSwapChainPanel = 0x0000000B,
WGPUSType_DawnTextureInternalUsageDescriptor = 0x000003E8, WGPUSType_DawnTextureInternalUsageDescriptor = 0x000003E8,
WGPUSType_PrimitiveDepthClampingState = 0x000003E9, WGPUSType_PrimitiveDepthClampingState = 0x000003E9,
WGPUSType_DawnTogglesDeviceDescriptor = 0x000003EA, WGPUSType_DawnTogglesDeviceDescriptor = 0x000003EA,
@ -872,43 +866,6 @@ typedef struct WGPUStorageTextureBindingLayout {
WGPUTextureViewDimension viewDimension; WGPUTextureViewDimension viewDimension;
} WGPUStorageTextureBindingLayout; } WGPUStorageTextureBindingLayout;
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;
typedef struct WGPUSwapChainDescriptor { typedef struct WGPUSwapChainDescriptor {
WGPUChainedStruct const * nextInChain; WGPUChainedStruct const * nextInChain;
char const * label; char const * label;

View file

@ -33,6 +33,7 @@ test "syntax" {
_ = Adapter; _ = Adapter;
_ = Device; _ = Device;
_ = Surface; _ = Surface;
_ = Surface.Descriptor;
_ = FeatureName; _ = FeatureName;
_ = SupportedLimits; _ = SupportedLimits;