From 89b1f31de8564beede00bd8fdaec2ec87af68aef Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 6 Mar 2022 20:44:38 -0700 Subject: [PATCH] gpu: begin implementing Surface Signed-off-by: Stephen Gutekanst --- gpu/src/NativeInstance.zig | 59 ++++++++++++++++++++++++++++ gpu/src/Surface.zig | 79 +++++++++++++++++--------------------- gpu/src/TODO | 43 --------------------- gpu/src/main.zig | 1 + 4 files changed, 96 insertions(+), 86 deletions(-) diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index da38fe87..daa370e1 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -37,8 +37,67 @@ pub fn interface(native: *const NativeInstance) Interface { } 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; _ = descriptor; // TODO: // 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); diff --git a/gpu/src/Surface.zig b/gpu/src/Surface.zig index 262b7e73..16162e7b 100644 --- a/gpu/src/Surface.zig +++ b/gpu/src/Surface.zig @@ -1,46 +1,39 @@ //! A native WebGPU surface -// typedef enum WGPUSType { -// WGPUSType_Invalid = 0x00000000, -// WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001, -// WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002, -// WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003, -// WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004, +pub const DescriptorTag = enum { + metal_layer, + windows_hwnd, + windows_core_window, + windows_swap_chain_panel, + xlib_window, + canvas_html_selector, +}; -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; +pub const Descriptor = union(DescriptorTag) { + metal_layer: struct { + label: ?[]const u8, + layer: *anyopaque, + }, + windows_hwnd: struct { + label: ?[]const u8, + hinstance: *anyopaque, + hwnd: *anyopaque, + }, + windows_core_window: struct { + label: ?[]const u8, + core_window: *anyopaque, + }, + windows_swap_chain_panel: struct { + label: ?[]const u8, + swap_chain_panel: *anyopaque, + }, + xlib_window: struct { + label: ?[]const u8, + display: *anyopaque, + window: u32, + }, + canvas_html_selector: struct { + label: ?[]const u8, + selector: []const u8, + }, +}; diff --git a/gpu/src/TODO b/gpu/src/TODO index 0a4bd22b..b4cafc59 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -299,16 +299,10 @@ typedef enum WGPURequestDeviceStatus { typedef enum WGPUSType { WGPUSType_Invalid = 0x00000000, - WGPUSType_SurfaceDescriptorFromMetalLayer = 0x00000001, - WGPUSType_SurfaceDescriptorFromWindowsHWND = 0x00000002, - WGPUSType_SurfaceDescriptorFromXlibWindow = 0x00000003, - WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004, WGPUSType_ShaderModuleSPIRVDescriptor = 0x00000005, WGPUSType_ShaderModuleWGSLDescriptor = 0x00000006, - WGPUSType_SurfaceDescriptorFromWindowsCoreWindow = 0x00000008, WGPUSType_ExternalTextureBindingEntry = 0x00000009, WGPUSType_ExternalTextureBindingLayout = 0x0000000A, - WGPUSType_SurfaceDescriptorFromWindowsSwapChainPanel = 0x0000000B, WGPUSType_DawnTextureInternalUsageDescriptor = 0x000003E8, WGPUSType_PrimitiveDepthClampingState = 0x000003E9, WGPUSType_DawnTogglesDeviceDescriptor = 0x000003EA, @@ -872,43 +866,6 @@ typedef struct WGPUStorageTextureBindingLayout { WGPUTextureViewDimension viewDimension; } 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 { WGPUChainedStruct const * nextInChain; char const * label; diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 8c7342d4..3c1b77c5 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -33,6 +33,7 @@ test "syntax" { _ = Adapter; _ = Device; _ = Surface; + _ = Surface.Descriptor; _ = FeatureName; _ = SupportedLimits;