From 5f7fe4d7e2afe55380a4e54ba80fbb2f47dc41e8 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 6 Mar 2022 19:05:00 -0700 Subject: [PATCH] gpu: prepare to add Device interface Signed-off-by: Stephen Gutekanst --- gpu/src/Device.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ gpu/src/TODO | 35 ----------------------------------- gpu/src/main.zig | 2 ++ gpu/src/native.zig | 2 ++ 4 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 gpu/src/Device.zig diff --git a/gpu/src/Device.zig b/gpu/src/Device.zig new file mode 100644 index 00000000..9fee0b53 --- /dev/null +++ b/gpu/src/Device.zig @@ -0,0 +1,45 @@ +//! A GPUDevice / logical instantiation of an adapter. +//! +//! A device is the exclusive owner of all internal objects created from it: when the device is +//! lost or destroyed, it and all objects created on it (directly, e.g. createTexture(), or +//! indirectly, e.g. createView()) become implicitly unusable. +//! +//! https://gpuweb.github.io/gpuweb/#devices +//! https://gpuweb.github.io/gpuweb/#gpuadapter + +// TODO: +// typedef struct WGPUDeviceImpl* WGPUDevice; + +// Methods of Device +// WGPU_EXPORT WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor); +// WGPU_EXPORT WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor); +// WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor); +// WGPU_EXPORT WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor); +// WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor); +// 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); +// WGPU_EXPORT WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor); +// WGPU_EXPORT WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor); +// WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor); +// WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor); +// WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata); +// WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor); +// WGPU_EXPORT WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor); +// WGPU_EXPORT WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor); +// WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor); +// WGPU_EXPORT void wgpuDeviceDestroy(WGPUDevice device); +// WGPU_EXPORT size_t wgpuDeviceEnumerateFeatures(WGPUDevice device, WGPUFeatureName * features); +// WGPU_EXPORT bool wgpuDeviceGetLimits(WGPUDevice device, WGPUSupportedLimits * limits); +// WGPU_EXPORT WGPUQueue wgpuDeviceGetQueue(WGPUDevice device); +// WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature); +// WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message); +// WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device); +// WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +// WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter); +// WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata); +// WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata); +// WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata); +// WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device); +// WGPU_EXPORT void wgpuDeviceReference(WGPUDevice device); +// WGPU_EXPORT void wgpuDeviceRelease(WGPUDevice device); diff --git a/gpu/src/TODO b/gpu/src/TODO index 8331f70f..ded1021e 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -16,7 +16,6 @@ typedef struct WGPUCommandBufferImpl* WGPUCommandBuffer; typedef struct WGPUCommandEncoderImpl* WGPUCommandEncoder; typedef struct WGPUComputePassEncoderImpl* WGPUComputePassEncoder; typedef struct WGPUComputePipelineImpl* WGPUComputePipeline; -typedef struct WGPUDeviceImpl* WGPUDevice; typedef struct WGPUExternalTextureImpl* WGPUExternalTexture; typedef struct WGPUInstanceImpl* WGPUInstance; typedef struct WGPUPipelineLayoutImpl* WGPUPipelineLayout; @@ -1235,40 +1234,6 @@ WGPU_EXPORT void wgpuComputePipelineSetLabel(WGPUComputePipeline computePipeline WGPU_EXPORT void wgpuComputePipelineReference(WGPUComputePipeline computePipeline); WGPU_EXPORT void wgpuComputePipelineRelease(WGPUComputePipeline computePipeline); -// Methods of Device -WGPU_EXPORT WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, WGPUBindGroupDescriptor const * descriptor); -WGPU_EXPORT WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, WGPUBindGroupLayoutDescriptor const * descriptor); -WGPU_EXPORT WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, WGPUBufferDescriptor const * descriptor); -WGPU_EXPORT WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, WGPUCommandEncoderDescriptor const * descriptor); -WGPU_EXPORT WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor); -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); -WGPU_EXPORT WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, WGPUPipelineLayoutDescriptor const * descriptor); -WGPU_EXPORT WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, WGPUQuerySetDescriptor const * descriptor); -WGPU_EXPORT WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, WGPURenderBundleEncoderDescriptor const * descriptor); -WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor); -WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata); -WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPUSamplerDescriptor const * descriptor); -WGPU_EXPORT WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor); -WGPU_EXPORT WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor); -WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor); -WGPU_EXPORT void wgpuDeviceDestroy(WGPUDevice device); -WGPU_EXPORT size_t wgpuDeviceEnumerateFeatures(WGPUDevice device, WGPUFeatureName * features); -WGPU_EXPORT bool wgpuDeviceGetLimits(WGPUDevice device, WGPUSupportedLimits * limits); -WGPU_EXPORT WGPUQueue wgpuDeviceGetQueue(WGPUDevice device); -WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature); -WGPU_EXPORT void wgpuDeviceInjectError(WGPUDevice device, WGPUErrorType type, char const * message); -WGPU_EXPORT void wgpuDeviceLoseForTesting(WGPUDevice device); -WGPU_EXPORT bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata); -WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter); -WGPU_EXPORT void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void * userdata); -WGPU_EXPORT void wgpuDeviceSetLoggingCallback(WGPUDevice device, WGPULoggingCallback callback, void * userdata); -WGPU_EXPORT void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void * userdata); -WGPU_EXPORT void wgpuDeviceTick(WGPUDevice device); -WGPU_EXPORT void wgpuDeviceReference(WGPUDevice device); -WGPU_EXPORT void wgpuDeviceRelease(WGPUDevice device); - // Methods of ExternalTexture WGPU_EXPORT void wgpuExternalTextureDestroy(WGPUExternalTexture externalTexture); WGPU_EXPORT void wgpuExternalTextureSetLabel(WGPUExternalTexture externalTexture, char const * label); diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 690a0121..2094b50b 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -20,12 +20,14 @@ const Interface = @import("Interface.zig"); const native = @import("native.zig").native; const Adapter = @import("Adapter.zig"); +const Device = @import("Device.zig"); const FeatureName = @import("feature_name.zig").FeatureName; const SupportedLimits = @import("supported_limits.zig").SupportedLimits; test "syntax" { _ = Adapter; + _ = Device; _ = Interface; _ = native; _ = FeatureName; diff --git a/gpu/src/native.zig b/gpu/src/native.zig index 4c6e471a..99aa2828 100644 --- a/gpu/src/native.zig +++ b/gpu/src/native.zig @@ -6,6 +6,8 @@ pub fn native() Interface { // TODO: implement Interface @panic("not implemented"); + // TODO: implement Device interface + // TODO: implement Adapter interface: // typedef struct WGPUAdapterImpl* WGPUAdapter; // // Methods of Adapter