From 84c20948219c33cc89031faae3c3b3cbdb769dd1 Mon Sep 17 00:00:00 2001 From: boyan1742 Date: Fri, 10 Nov 2023 22:30:44 +0200 Subject: [PATCH] Updated the wgpu to the latest version (v. 0.18.0.2). Exposed wgpu functions. --- .../headers/webgpu-headers/webgpu.h | 222 ++-- BindingsGenerator/headers/wgpu.h | 139 ++- WGPU.NET/Helpers/Util.cs | 41 +- WGPU.NET/Helpers/WgpuStructChain.cs | 18 +- WGPU.NET/WGPU.cs | 523 +++++----- WGPU.NET/Wrappers/Adapter.cs | 40 +- WGPU.NET/Wrappers/BindGroup.cs | 4 + WGPU.NET/Wrappers/CommandEncoder.cs | 4 +- WGPU.NET/Wrappers/Device.cs | 22 +- WGPU.NET/Wrappers/Instance.cs | 69 +- WGPU.NET/Wrappers/Misc.cs | 4 +- WGPU.NET/Wrappers/Queue.cs | 5 + WGPU.NET/Wrappers/Surface.cs | 133 ++- WGPU.NET/Wrappers/SurfaceCapabilities.cs | 15 + WGPU.NET/Wrappers/SurfaceConfiguration.cs | 23 + WGPU.NET/Wrappers/SurfaceTexture.cs | 10 + WGPU.NET/Wrappers/TextureView.cs | 26 +- WGPU.Tests/Test.cs | 987 +++++++++--------- WGPU.Tests/shader.wgsl | 24 +- 19 files changed, 1340 insertions(+), 969 deletions(-) create mode 100644 WGPU.NET/Wrappers/SurfaceCapabilities.cs create mode 100644 WGPU.NET/Wrappers/SurfaceConfiguration.cs create mode 100644 WGPU.NET/Wrappers/SurfaceTexture.cs diff --git a/BindingsGenerator/headers/webgpu-headers/webgpu.h b/BindingsGenerator/headers/webgpu-headers/webgpu.h index 8356d66..79c0bc0 100644 --- a/BindingsGenerator/headers/webgpu-headers/webgpu.h +++ b/BindingsGenerator/headers/webgpu-headers/webgpu.h @@ -66,17 +66,18 @@ #include #include -#include #define WGPU_ARRAY_LAYER_COUNT_UNDEFINED (0xffffffffUL) #define WGPU_COPY_STRIDE_UNDEFINED (0xffffffffUL) #define WGPU_LIMIT_U32_UNDEFINED (0xffffffffUL) #define WGPU_LIMIT_U64_UNDEFINED (0xffffffffffffffffULL) #define WGPU_MIP_LEVEL_COUNT_UNDEFINED (0xffffffffUL) +#define WGPU_QUERY_SET_INDEX_UNDEFINED (0xffffffffUL) #define WGPU_WHOLE_MAP_SIZE SIZE_MAX #define WGPU_WHOLE_SIZE (0xffffffffffffffffULL) typedef uint32_t WGPUFlags; +typedef uint32_t WGPUBool; typedef struct WGPUAdapterImpl* WGPUAdapter WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUBindGroupImpl* WGPUBindGroup WGPU_OBJECT_ATTRIBUTE; @@ -98,7 +99,6 @@ typedef struct WGPURenderPipelineImpl* WGPURenderPipeline WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUSamplerImpl* WGPUSampler WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUShaderModuleImpl* WGPUShaderModule WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUSurfaceImpl* WGPUSurface WGPU_OBJECT_ATTRIBUTE; -typedef struct WGPUSwapChainImpl* WGPUSwapChain WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUTextureImpl* WGPUTexture WGPU_OBJECT_ATTRIBUTE; typedef struct WGPUTextureViewImpl* WGPUTextureView WGPU_OBJECT_ATTRIBUTE; @@ -112,7 +112,7 @@ struct WGPUColor; struct WGPUCommandBufferDescriptor; struct WGPUCommandEncoderDescriptor; struct WGPUCompilationMessage; -struct WGPUComputePassTimestampWrite; +struct WGPUComputePassTimestampWrites; struct WGPUConstantEntry; struct WGPUExtent3D; struct WGPUInstanceDescriptor; @@ -128,7 +128,7 @@ struct WGPURenderBundleDescriptor; struct WGPURenderBundleEncoderDescriptor; struct WGPURenderPassDepthStencilAttachment; struct WGPURenderPassDescriptorMaxDrawCount; -struct WGPURenderPassTimestampWrite; +struct WGPURenderPassTimestampWrites; struct WGPURequestAdapterOptions; struct WGPUSamplerBindingLayout; struct WGPUSamplerDescriptor; @@ -137,6 +137,8 @@ struct WGPUShaderModuleSPIRVDescriptor; struct WGPUShaderModuleWGSLDescriptor; struct WGPUStencilFaceState; struct WGPUStorageTextureBindingLayout; +struct WGPUSurfaceCapabilities; +struct WGPUSurfaceConfiguration; struct WGPUSurfaceDescriptor; struct WGPUSurfaceDescriptorFromAndroidNativeWindow; struct WGPUSurfaceDescriptorFromCanvasHTMLSelector; @@ -145,7 +147,7 @@ struct WGPUSurfaceDescriptorFromWaylandSurface; struct WGPUSurfaceDescriptorFromWindowsHWND; struct WGPUSurfaceDescriptorFromXcbWindow; struct WGPUSurfaceDescriptorFromXlibWindow; -struct WGPUSwapChainDescriptor; +struct WGPUSurfaceTexture; struct WGPUTextureBindingLayout; struct WGPUTextureDataLayout; struct WGPUTextureViewDescriptor; @@ -284,11 +286,14 @@ typedef enum WGPUCompilationMessageType { WGPUCompilationMessageType_Force32 = 0x7FFFFFFF } WGPUCompilationMessageType WGPU_ENUM_ATTRIBUTE; -typedef enum WGPUComputePassTimestampLocation { - WGPUComputePassTimestampLocation_Beginning = 0x00000000, - WGPUComputePassTimestampLocation_End = 0x00000001, - WGPUComputePassTimestampLocation_Force32 = 0x7FFFFFFF -} WGPUComputePassTimestampLocation WGPU_ENUM_ATTRIBUTE; +typedef enum WGPUCompositeAlphaMode { + WGPUCompositeAlphaMode_Auto = 0x00000000, + WGPUCompositeAlphaMode_Opaque = 0x00000001, + WGPUCompositeAlphaMode_Premultiplied = 0x00000002, + WGPUCompositeAlphaMode_Unpremultiplied = 0x00000003, + WGPUCompositeAlphaMode_Inherit = 0x00000004, + WGPUCompositeAlphaMode_Force32 = 0x7FFFFFFF +} WGPUCompositeAlphaMode WGPU_ENUM_ATTRIBUTE; typedef enum WGPUCreatePipelineAsyncStatus { WGPUCreatePipelineAsyncStatus_Success = 0x00000000, @@ -335,15 +340,14 @@ typedef enum WGPUFeatureName { WGPUFeatureName_DepthClipControl = 0x00000001, WGPUFeatureName_Depth32FloatStencil8 = 0x00000002, WGPUFeatureName_TimestampQuery = 0x00000003, - WGPUFeatureName_PipelineStatisticsQuery = 0x00000004, - WGPUFeatureName_TextureCompressionBC = 0x00000005, - WGPUFeatureName_TextureCompressionETC2 = 0x00000006, - WGPUFeatureName_TextureCompressionASTC = 0x00000007, - WGPUFeatureName_IndirectFirstInstance = 0x00000008, - WGPUFeatureName_ShaderF16 = 0x00000009, - WGPUFeatureName_RG11B10UfloatRenderable = 0x0000000A, - WGPUFeatureName_BGRA8UnormStorage = 0x0000000B, - WGPUFeatureName_Float32Filterable = 0x0000000C, + WGPUFeatureName_TextureCompressionBC = 0x00000004, + WGPUFeatureName_TextureCompressionETC2 = 0x00000005, + WGPUFeatureName_TextureCompressionASTC = 0x00000006, + WGPUFeatureName_IndirectFirstInstance = 0x00000007, + WGPUFeatureName_ShaderF16 = 0x00000008, + WGPUFeatureName_RG11B10UfloatRenderable = 0x00000009, + WGPUFeatureName_BGRA8UnormStorage = 0x0000000A, + WGPUFeatureName_Float32Filterable = 0x0000000B, WGPUFeatureName_Force32 = 0x7FFFFFFF } WGPUFeatureName WGPU_ENUM_ATTRIBUTE; @@ -379,15 +383,6 @@ typedef enum WGPUMipmapFilterMode { WGPUMipmapFilterMode_Force32 = 0x7FFFFFFF } WGPUMipmapFilterMode WGPU_ENUM_ATTRIBUTE; -typedef enum WGPUPipelineStatisticName { - WGPUPipelineStatisticName_VertexShaderInvocations = 0x00000000, - WGPUPipelineStatisticName_ClipperInvocations = 0x00000001, - WGPUPipelineStatisticName_ClipperPrimitivesOut = 0x00000002, - WGPUPipelineStatisticName_FragmentShaderInvocations = 0x00000003, - WGPUPipelineStatisticName_ComputeShaderInvocations = 0x00000004, - WGPUPipelineStatisticName_Force32 = 0x7FFFFFFF -} WGPUPipelineStatisticName WGPU_ENUM_ATTRIBUTE; - typedef enum WGPUPowerPreference { WGPUPowerPreference_Undefined = 0x00000000, WGPUPowerPreference_LowPower = 0x00000001, @@ -396,9 +391,10 @@ typedef enum WGPUPowerPreference { } WGPUPowerPreference WGPU_ENUM_ATTRIBUTE; typedef enum WGPUPresentMode { - WGPUPresentMode_Immediate = 0x00000000, - WGPUPresentMode_Mailbox = 0x00000001, - WGPUPresentMode_Fifo = 0x00000002, + WGPUPresentMode_Fifo = 0x00000000, + WGPUPresentMode_FifoRelaxed = 0x00000001, + WGPUPresentMode_Immediate = 0x00000002, + WGPUPresentMode_Mailbox = 0x00000003, WGPUPresentMode_Force32 = 0x7FFFFFFF } WGPUPresentMode WGPU_ENUM_ATTRIBUTE; @@ -413,8 +409,7 @@ typedef enum WGPUPrimitiveTopology { typedef enum WGPUQueryType { WGPUQueryType_Occlusion = 0x00000000, - WGPUQueryType_PipelineStatistics = 0x00000001, - WGPUQueryType_Timestamp = 0x00000002, + WGPUQueryType_Timestamp = 0x00000001, WGPUQueryType_Force32 = 0x7FFFFFFF } WGPUQueryType WGPU_ENUM_ATTRIBUTE; @@ -426,12 +421,6 @@ typedef enum WGPUQueueWorkDoneStatus { WGPUQueueWorkDoneStatus_Force32 = 0x7FFFFFFF } WGPUQueueWorkDoneStatus WGPU_ENUM_ATTRIBUTE; -typedef enum WGPURenderPassTimestampLocation { - WGPURenderPassTimestampLocation_Beginning = 0x00000000, - WGPURenderPassTimestampLocation_End = 0x00000001, - WGPURenderPassTimestampLocation_Force32 = 0x7FFFFFFF -} WGPURenderPassTimestampLocation WGPU_ENUM_ATTRIBUTE; - typedef enum WGPURequestAdapterStatus { WGPURequestAdapterStatus_Success = 0x00000000, WGPURequestAdapterStatus_Unavailable = 0x00000001, @@ -496,6 +485,16 @@ typedef enum WGPUStoreOp { WGPUStoreOp_Force32 = 0x7FFFFFFF } WGPUStoreOp WGPU_ENUM_ATTRIBUTE; +typedef enum WGPUSurfaceGetCurrentTextureStatus { + WGPUSurfaceGetCurrentTextureStatus_Success = 0x00000000, + WGPUSurfaceGetCurrentTextureStatus_Timeout = 0x00000001, + WGPUSurfaceGetCurrentTextureStatus_Outdated = 0x00000002, + WGPUSurfaceGetCurrentTextureStatus_Lost = 0x00000003, + WGPUSurfaceGetCurrentTextureStatus_OutOfMemory = 0x00000004, + WGPUSurfaceGetCurrentTextureStatus_DeviceLost = 0x00000005, + WGPUSurfaceGetCurrentTextureStatus_Force32 = 0x7FFFFFFF +} WGPUSurfaceGetCurrentTextureStatus WGPU_ENUM_ATTRIBUTE; + typedef enum WGPUTextureAspect { WGPUTextureAspect_All = 0x00000000, WGPUTextureAspect_StencilOnly = 0x00000001, @@ -779,7 +778,7 @@ typedef struct WGPUBlendComponent { typedef struct WGPUBufferBindingLayout { WGPUChainedStruct const * nextInChain; WGPUBufferBindingType type; - bool hasDynamicOffset; + WGPUBool hasDynamicOffset; uint64_t minBindingSize; } WGPUBufferBindingLayout WGPU_STRUCTURE_ATTRIBUTE; @@ -788,7 +787,7 @@ typedef struct WGPUBufferDescriptor { WGPU_NULLABLE char const * label; WGPUBufferUsageFlags usage; uint64_t size; - bool mappedAtCreation; + WGPUBool mappedAtCreation; } WGPUBufferDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUColor { @@ -821,11 +820,11 @@ typedef struct WGPUCompilationMessage { uint64_t utf16Length; } WGPUCompilationMessage WGPU_STRUCTURE_ATTRIBUTE; -typedef struct WGPUComputePassTimestampWrite { +typedef struct WGPUComputePassTimestampWrites { WGPUQuerySet querySet; - uint32_t queryIndex; - WGPUComputePassTimestampLocation location; -} WGPUComputePassTimestampWrite WGPU_STRUCTURE_ATTRIBUTE; + uint32_t beginningOfPassWriteIndex; + uint32_t endOfPassWriteIndex; +} WGPUComputePassTimestampWrites WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUConstantEntry { WGPUChainedStruct const * nextInChain; @@ -849,6 +848,7 @@ typedef struct WGPULimits { uint32_t maxTextureDimension3D; uint32_t maxTextureArrayLayers; uint32_t maxBindGroups; + uint32_t maxBindGroupsPlusVertexBuffers; uint32_t maxBindingsPerBindGroup; uint32_t maxDynamicUniformBuffersPerPipelineLayout; uint32_t maxDynamicStorageBuffersPerPipelineLayout; @@ -881,7 +881,7 @@ typedef struct WGPUMultisampleState { WGPUChainedStruct const * nextInChain; uint32_t count; uint32_t mask; - bool alphaToCoverageEnabled; + WGPUBool alphaToCoverageEnabled; } WGPUMultisampleState WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUOrigin3D { @@ -900,7 +900,7 @@ typedef struct WGPUPipelineLayoutDescriptor { // Can be chained in WGPUPrimitiveState typedef struct WGPUPrimitiveDepthClipControl { WGPUChainedStruct chain; - bool unclippedDepth; + WGPUBool unclippedDepth; } WGPUPrimitiveDepthClipControl WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUPrimitiveState { @@ -916,8 +916,6 @@ typedef struct WGPUQuerySetDescriptor { WGPU_NULLABLE char const * label; WGPUQueryType type; uint32_t count; - WGPUPipelineStatisticName const * pipelineStatistics; - size_t pipelineStatisticsCount; } WGPUQuerySetDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUQueueDescriptor { @@ -933,12 +931,12 @@ typedef struct WGPURenderBundleDescriptor { typedef struct WGPURenderBundleEncoderDescriptor { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE char const * label; - size_t colorFormatsCount; + size_t colorFormatCount; WGPUTextureFormat const * colorFormats; WGPUTextureFormat depthStencilFormat; uint32_t sampleCount; - bool depthReadOnly; - bool stencilReadOnly; + WGPUBool depthReadOnly; + WGPUBool stencilReadOnly; } WGPURenderBundleEncoderDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPURenderPassDepthStencilAttachment { @@ -946,11 +944,11 @@ typedef struct WGPURenderPassDepthStencilAttachment { WGPULoadOp depthLoadOp; WGPUStoreOp depthStoreOp; float depthClearValue; - bool depthReadOnly; + WGPUBool depthReadOnly; WGPULoadOp stencilLoadOp; WGPUStoreOp stencilStoreOp; uint32_t stencilClearValue; - bool stencilReadOnly; + WGPUBool stencilReadOnly; } WGPURenderPassDepthStencilAttachment WGPU_STRUCTURE_ATTRIBUTE; // Can be chained in WGPURenderPassDescriptor @@ -959,18 +957,18 @@ typedef struct WGPURenderPassDescriptorMaxDrawCount { uint64_t maxDrawCount; } WGPURenderPassDescriptorMaxDrawCount WGPU_STRUCTURE_ATTRIBUTE; -typedef struct WGPURenderPassTimestampWrite { +typedef struct WGPURenderPassTimestampWrites { WGPUQuerySet querySet; - uint32_t queryIndex; - WGPURenderPassTimestampLocation location; -} WGPURenderPassTimestampWrite WGPU_STRUCTURE_ATTRIBUTE; + uint32_t beginningOfPassWriteIndex; + uint32_t endOfPassWriteIndex; +} WGPURenderPassTimestampWrites WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPURequestAdapterOptions { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE WGPUSurface compatibleSurface; WGPUPowerPreference powerPreference; WGPUBackendType backendType; - bool forceFallbackAdapter; + WGPUBool forceFallbackAdapter; } WGPURequestAdapterOptions WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUSamplerBindingLayout { @@ -1026,6 +1024,29 @@ typedef struct WGPUStorageTextureBindingLayout { WGPUTextureViewDimension viewDimension; } WGPUStorageTextureBindingLayout WGPU_STRUCTURE_ATTRIBUTE; +typedef struct WGPUSurfaceCapabilities { + WGPUChainedStructOut * nextInChain; + size_t formatCount; + WGPUTextureFormat * formats; + size_t presentModeCount; + WGPUPresentMode * presentModes; + size_t alphaModeCount; + WGPUCompositeAlphaMode * alphaModes; +} WGPUSurfaceCapabilities WGPU_STRUCTURE_ATTRIBUTE; + +typedef struct WGPUSurfaceConfiguration { + WGPUChainedStruct const * nextInChain; + WGPUDevice device; + WGPUTextureFormat format; + WGPUTextureUsageFlags usage; + size_t viewFormatCount; + WGPUTextureFormat const * viewFormats; + WGPUCompositeAlphaMode alphaMode; + uint32_t width; + uint32_t height; + WGPUPresentMode presentMode; +} WGPUSurfaceConfiguration WGPU_STRUCTURE_ATTRIBUTE; + typedef struct WGPUSurfaceDescriptor { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE char const * label; @@ -1077,21 +1098,17 @@ typedef struct WGPUSurfaceDescriptorFromXlibWindow { uint32_t window; } WGPUSurfaceDescriptorFromXlibWindow WGPU_STRUCTURE_ATTRIBUTE; -typedef struct WGPUSwapChainDescriptor { - WGPUChainedStruct const * nextInChain; - WGPU_NULLABLE char const * label; - WGPUTextureUsageFlags usage; - WGPUTextureFormat format; - uint32_t width; - uint32_t height; - WGPUPresentMode presentMode; -} WGPUSwapChainDescriptor WGPU_STRUCTURE_ATTRIBUTE; +typedef struct WGPUSurfaceTexture { + WGPUTexture texture; + WGPUBool suboptimal; + WGPUSurfaceGetCurrentTextureStatus status; +} WGPUSurfaceTexture WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUTextureBindingLayout { WGPUChainedStruct const * nextInChain; WGPUTextureSampleType sampleType; WGPUTextureViewDimension viewDimension; - bool multisampled; + WGPUBool multisampled; } WGPUTextureBindingLayout WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUTextureDataLayout { @@ -1151,14 +1168,13 @@ typedef struct WGPUCompilationInfo { typedef struct WGPUComputePassDescriptor { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE char const * label; - size_t timestampWriteCount; - WGPUComputePassTimestampWrite const * timestampWrites; + WGPU_NULLABLE WGPUComputePassTimestampWrites const * timestampWrites; } WGPUComputePassDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUDepthStencilState { WGPUChainedStruct const * nextInChain; WGPUTextureFormat format; - bool depthWriteEnabled; + WGPUBool depthWriteEnabled; WGPUCompareFunction depthCompare; WGPUStencilFaceState stencilFront; WGPUStencilFaceState stencilBack; @@ -1192,6 +1208,7 @@ typedef struct WGPUProgrammableStageDescriptor { } WGPUProgrammableStageDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPURenderPassColorAttachment { + WGPUChainedStruct const * nextInChain; WGPU_NULLABLE WGPUTextureView view; WGPU_NULLABLE WGPUTextureView resolveTarget; WGPULoadOp loadOp; @@ -1260,7 +1277,7 @@ typedef struct WGPUComputePipelineDescriptor { typedef struct WGPUDeviceDescriptor { WGPUChainedStruct const * nextInChain; WGPU_NULLABLE char const * label; - size_t requiredFeaturesCount; + size_t requiredFeatureCount; WGPUFeatureName const * requiredFeatures; WGPU_NULLABLE WGPURequiredLimits const * requiredLimits; WGPUQueueDescriptor defaultQueue; @@ -1275,8 +1292,7 @@ typedef struct WGPURenderPassDescriptor { WGPURenderPassColorAttachment const * colorAttachments; WGPU_NULLABLE WGPURenderPassDepthStencilAttachment const * depthStencilAttachment; WGPU_NULLABLE WGPUQuerySet occlusionQuerySet; - size_t timestampWriteCount; - WGPURenderPassTimestampWrite const * timestampWrites; + WGPU_NULLABLE WGPURenderPassTimestampWrites const * timestampWrites; } WGPURenderPassDescriptor WGPU_STRUCTURE_ATTRIBUTE; typedef struct WGPUVertexState { @@ -1316,14 +1332,14 @@ extern "C" { #if !defined(WGPU_SKIP_PROCS) -typedef WGPUInstance (*WGPUProcCreateInstance)(WGPUInstanceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUInstance (*WGPUProcCreateInstance)(WGPU_NULLABLE WGPUInstanceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUProc (*WGPUProcGetProcAddress)(WGPUDevice device, char const * procName) WGPU_FUNCTION_ATTRIBUTE; // Procs of Adapter typedef size_t (*WGPUProcAdapterEnumerateFeatures)(WGPUAdapter adapter, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; -typedef bool (*WGPUProcAdapterGetLimits)(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUBool (*WGPUProcAdapterGetLimits)(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterGetProperties)(WGPUAdapter adapter, WGPUAdapterProperties * properties) WGPU_FUNCTION_ATTRIBUTE; -typedef bool (*WGPUProcAdapterHasFeature)(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUBool (*WGPUProcAdapterHasFeature)(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterRequestDevice)(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterReference)(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcAdapterRelease)(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; @@ -1375,11 +1391,9 @@ typedef void (*WGPUProcCommandEncoderReference)(WGPUCommandEncoder commandEncode typedef void (*WGPUProcCommandEncoderRelease)(WGPUCommandEncoder commandEncoder) WGPU_FUNCTION_ATTRIBUTE; // Procs of ComputePassEncoder -typedef void (*WGPUProcComputePassEncoderBeginPipelineStatisticsQuery)(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderDispatchWorkgroups)(WGPUComputePassEncoder computePassEncoder, uint32_t workgroupCountX, uint32_t workgroupCountY, uint32_t workgroupCountZ) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderDispatchWorkgroupsIndirect)(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderEnd)(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcComputePassEncoderEndPipelineStatisticsQuery)(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderInsertDebugMarker)(WGPUComputePassEncoder computePassEncoder, char const * markerLabel) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderPopDebugGroup)(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcComputePassEncoderPushDebugGroup)(WGPUComputePassEncoder computePassEncoder, char const * groupLabel) WGPU_FUNCTION_ATTRIBUTE; @@ -1409,13 +1423,12 @@ typedef WGPURenderPipeline (*WGPUProcDeviceCreateRenderPipeline)(WGPUDevice devi typedef void (*WGPUProcDeviceCreateRenderPipelineAsync)(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUSampler (*WGPUProcDeviceCreateSampler)(WGPUDevice device, WGPU_NULLABLE WGPUSamplerDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUShaderModule (*WGPUProcDeviceCreateShaderModule)(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -typedef WGPUSwapChain (*WGPUProcDeviceCreateSwapChain)(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUTexture (*WGPUProcDeviceCreateTexture)(WGPUDevice device, WGPUTextureDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDeviceDestroy)(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; typedef size_t (*WGPUProcDeviceEnumerateFeatures)(WGPUDevice device, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; -typedef bool (*WGPUProcDeviceGetLimits)(WGPUDevice device, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUBool (*WGPUProcDeviceGetLimits)(WGPUDevice device, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUQueue (*WGPUProcDeviceGetQueue)(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; -typedef bool (*WGPUProcDeviceHasFeature)(WGPUDevice device, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; +typedef WGPUBool (*WGPUProcDeviceHasFeature)(WGPUDevice device, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDevicePopErrorScope)(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDevicePushErrorScope)(WGPUDevice device, WGPUErrorFilter filter) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcDeviceSetLabel)(WGPUDevice device, char const * label) WGPU_FUNCTION_ATTRIBUTE; @@ -1476,14 +1489,12 @@ typedef void (*WGPUProcRenderBundleEncoderRelease)(WGPURenderBundleEncoder rende // Procs of RenderPassEncoder typedef void (*WGPUProcRenderPassEncoderBeginOcclusionQuery)(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcRenderPassEncoderBeginPipelineStatisticsQuery)(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderDraw)(WGPURenderPassEncoder renderPassEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderDrawIndexed)(WGPURenderPassEncoder renderPassEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderDrawIndexedIndirect)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderDrawIndirect)(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderEnd)(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderEndOcclusionQuery)(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcRenderPassEncoderEndPipelineStatisticsQuery)(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderExecuteBundles)(WGPURenderPassEncoder renderPassEncoder, size_t bundleCount, WGPURenderBundle const * bundles) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderInsertDebugMarker)(WGPURenderPassEncoder renderPassEncoder, char const * markerLabel) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcRenderPassEncoderPopDebugGroup)(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; @@ -1518,15 +1529,17 @@ typedef void (*WGPUProcShaderModuleReference)(WGPUShaderModule shaderModule) WGP typedef void (*WGPUProcShaderModuleRelease)(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; // Procs of Surface +typedef void (*WGPUProcSurfaceConfigure)(WGPUSurface surface, WGPUSurfaceConfiguration const * config) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfaceGetCapabilities)(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfaceGetCurrentTexture)(WGPUSurface surface, WGPUSurfaceTexture * surfaceTexture) WGPU_FUNCTION_ATTRIBUTE; typedef WGPUTextureFormat (*WGPUProcSurfaceGetPreferredFormat)(WGPUSurface surface, WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfacePresent)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; +typedef void (*WGPUProcSurfaceUnconfigure)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceReference)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; typedef void (*WGPUProcSurfaceRelease)(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; -// Procs of SwapChain -typedef WGPUTextureView (*WGPUProcSwapChainGetCurrentTextureView)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcSwapChainPresent)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcSwapChainReference)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -typedef void (*WGPUProcSwapChainRelease)(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; +// Procs of SurfaceCapabilities +typedef void (*WGPUProcSurfaceCapabilitiesFreeMembers)(WGPUSurfaceCapabilities capabilities) WGPU_FUNCTION_ATTRIBUTE; // Procs of Texture typedef WGPUTextureView (*WGPUProcTextureCreateView)(WGPUTexture texture, WGPU_NULLABLE WGPUTextureViewDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; @@ -1552,14 +1565,14 @@ typedef void (*WGPUProcTextureViewRelease)(WGPUTextureView textureView) WGPU_FUN #if !defined(WGPU_SKIP_DECLARATIONS) -WGPU_EXPORT WGPUInstance wgpuCreateInstance(WGPUInstanceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUInstance wgpuCreateInstance(WGPU_NULLABLE WGPUInstanceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUProc wgpuGetProcAddress(WGPUDevice device, char const * procName) WGPU_FUNCTION_ATTRIBUTE; // Methods of Adapter WGPU_EXPORT size_t wgpuAdapterEnumerateFeatures(WGPUAdapter adapter, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT bool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUBool wgpuAdapterGetLimits(WGPUAdapter adapter, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterGetProperties(WGPUAdapter adapter, WGPUAdapterProperties * properties) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT bool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUBool wgpuAdapterHasFeature(WGPUAdapter adapter, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterRequestDevice(WGPUAdapter adapter, WGPU_NULLABLE WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterReference(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuAdapterRelease(WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; @@ -1611,11 +1624,9 @@ WGPU_EXPORT void wgpuCommandEncoderReference(WGPUCommandEncoder commandEncoder) WGPU_EXPORT void wgpuCommandEncoderRelease(WGPUCommandEncoder commandEncoder) WGPU_FUNCTION_ATTRIBUTE; // Methods of ComputePassEncoder -WGPU_EXPORT void wgpuComputePassEncoderBeginPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderDispatchWorkgroups(WGPUComputePassEncoder computePassEncoder, uint32_t workgroupCountX, uint32_t workgroupCountY, uint32_t workgroupCountZ) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderDispatchWorkgroupsIndirect(WGPUComputePassEncoder computePassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderEnd(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuComputePassEncoderEndPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderInsertDebugMarker(WGPUComputePassEncoder computePassEncoder, char const * markerLabel) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderPopDebugGroup(WGPUComputePassEncoder computePassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuComputePassEncoderPushDebugGroup(WGPUComputePassEncoder computePassEncoder, char const * groupLabel) WGPU_FUNCTION_ATTRIBUTE; @@ -1645,13 +1656,12 @@ WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPU_EXPORT void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, WGPU_NULLABLE WGPUSamplerDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, WGPUShaderModuleDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, WGPUSwapChainDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, WGPUTextureDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDeviceDestroy(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT size_t wgpuDeviceEnumerateFeatures(WGPUDevice device, WGPUFeatureName * features) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT bool wgpuDeviceGetLimits(WGPUDevice device, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUBool wgpuDeviceGetLimits(WGPUDevice device, WGPUSupportedLimits * limits) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUQueue wgpuDeviceGetQueue(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT WGPUBool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDevicePushErrorScope(WGPUDevice device, WGPUErrorFilter filter) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuDeviceSetLabel(WGPUDevice device, char const * label) WGPU_FUNCTION_ATTRIBUTE; @@ -1712,14 +1722,12 @@ WGPU_EXPORT void wgpuRenderBundleEncoderRelease(WGPURenderBundleEncoder renderBu // Methods of RenderPassEncoder WGPU_EXPORT void wgpuRenderPassEncoderBeginOcclusionQuery(WGPURenderPassEncoder renderPassEncoder, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuRenderPassEncoderBeginPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDraw(WGPURenderPassEncoder renderPassEncoder, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDrawIndexed(WGPURenderPassEncoder renderPassEncoder, uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDrawIndexedIndirect(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderDrawIndirect(WGPURenderPassEncoder renderPassEncoder, WGPUBuffer indirectBuffer, uint64_t indirectOffset) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderEnd(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderEndOcclusionQuery(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuRenderPassEncoderEndPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderExecuteBundles(WGPURenderPassEncoder renderPassEncoder, size_t bundleCount, WGPURenderBundle const * bundles) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderInsertDebugMarker(WGPURenderPassEncoder renderPassEncoder, char const * markerLabel) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuRenderPassEncoderPopDebugGroup(WGPURenderPassEncoder renderPassEncoder) WGPU_FUNCTION_ATTRIBUTE; @@ -1754,15 +1762,17 @@ WGPU_EXPORT void wgpuShaderModuleReference(WGPUShaderModule shaderModule) WGPU_F WGPU_EXPORT void wgpuShaderModuleRelease(WGPUShaderModule shaderModule) WGPU_FUNCTION_ATTRIBUTE; // Methods of Surface +WGPU_EXPORT void wgpuSurfaceConfigure(WGPUSurface surface, WGPUSurfaceConfiguration const * config) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuSurfaceGetCapabilities(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuSurfaceGetCurrentTexture(WGPUSurface surface, WGPUSurfaceTexture * surfaceTexture) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT WGPUTextureFormat wgpuSurfaceGetPreferredFormat(WGPUSurface surface, WGPUAdapter adapter) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuSurfacePresent(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; +WGPU_EXPORT void wgpuSurfaceUnconfigure(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceReference(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; WGPU_EXPORT void wgpuSurfaceRelease(WGPUSurface surface) WGPU_FUNCTION_ATTRIBUTE; -// Methods of SwapChain -WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuSwapChainReference(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; -WGPU_EXPORT void wgpuSwapChainRelease(WGPUSwapChain swapChain) WGPU_FUNCTION_ATTRIBUTE; +// Methods of SurfaceCapabilities +WGPU_EXPORT void wgpuSurfaceCapabilitiesFreeMembers(WGPUSurfaceCapabilities capabilities) WGPU_FUNCTION_ATTRIBUTE; // Methods of Texture WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPU_NULLABLE WGPUTextureViewDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE; @@ -1790,4 +1800,4 @@ WGPU_EXPORT void wgpuTextureViewRelease(WGPUTextureView textureView) WGPU_FUNCTI } // extern "C" #endif -#endif // WEBGPU_H_ \ No newline at end of file +#endif // WEBGPU_H_ diff --git a/BindingsGenerator/headers/wgpu.h b/BindingsGenerator/headers/wgpu.h index d5f8c78..76bdb47 100644 --- a/BindingsGenerator/headers/wgpu.h +++ b/BindingsGenerator/headers/wgpu.h @@ -1,27 +1,31 @@ #ifndef WGPU_H_ #define WGPU_H_ -#include "webgpu-headers/webgpu.h" +#include "webgpu.h" typedef enum WGPUNativeSType { - // Start at 6 to prevent collisions with webgpu STypes - WGPUSType_DeviceExtras = 0x60000001, - WGPUSType_AdapterExtras = 0x60000002, - WGPUSType_RequiredLimitsExtras = 0x60000003, - WGPUSType_PipelineLayoutExtras = 0x60000004, - WGPUSType_ShaderModuleGLSLDescriptor = 0x60000005, - WGPUSType_SupportedLimitsExtras = 0x60000003, - WGPUSType_InstanceExtras = 0x60000006, - WGPUSType_SwapChainDescriptorExtras = 0x60000007, + // Start at 0003 since that's allocated range for wgpu-native + WGPUSType_DeviceExtras = 0x00030001, + WGPUSType_RequiredLimitsExtras = 0x00030002, + WGPUSType_PipelineLayoutExtras = 0x00030003, + WGPUSType_ShaderModuleGLSLDescriptor = 0x00030004, + WGPUSType_SupportedLimitsExtras = 0x00030005, + WGPUSType_InstanceExtras = 0x00030006, + WGPUSType_BindGroupEntryExtras = 0x00030007, + WGPUSType_BindGroupLayoutEntryExtras = 0x00030008, + WGPUSType_QuerySetDescriptorExtras = 0x00030009, WGPUNativeSType_Force32 = 0x7FFFFFFF } WGPUNativeSType; typedef enum WGPUNativeFeature { - WGPUNativeFeature_PushConstants = 0x60000001, - WGPUNativeFeature_TextureAdapterSpecificFormatFeatures = 0x60000002, - WGPUNativeFeature_MultiDrawIndirect = 0x60000003, - WGPUNativeFeature_MultiDrawIndirectCount = 0x60000004, - WGPUNativeFeature_VertexWritableStorage = 0x60000005, + WGPUNativeFeature_PushConstants = 0x00030001, + WGPUNativeFeature_TextureAdapterSpecificFormatFeatures = 0x00030002, + WGPUNativeFeature_MultiDrawIndirect = 0x00030003, + WGPUNativeFeature_MultiDrawIndirectCount = 0x00030004, + WGPUNativeFeature_VertexWritableStorage = 0x00030005, + WGPUNativeFeature_TextureBindingArray = 0x00030006, + WGPUNativeFeature_SampledTextureAndStorageBufferArrayNonUniformIndexing = 0x00030007, + WGPUNativeFeature_PipelineStatisticsQuery = 0x00030008, WGPUNativeFeature_Force32 = 0x7FFFFFFF } WGPUNativeFeature; @@ -36,21 +40,30 @@ typedef enum WGPULogLevel { } WGPULogLevel; typedef enum WGPUInstanceBackend { - WGPUInstanceBackend_Vulkan = 1 << 1, - WGPUInstanceBackend_GL = 1 << 5, + WGPUInstanceBackend_All = 0x00000000, + WGPUInstanceBackend_Vulkan = 1 << 0, + WGPUInstanceBackend_GL = 1 << 1, WGPUInstanceBackend_Metal = 1 << 2, WGPUInstanceBackend_DX12 = 1 << 3, WGPUInstanceBackend_DX11 = 1 << 4, - WGPUInstanceBackend_BrowserWebGPU = 1 << 6, + WGPUInstanceBackend_BrowserWebGPU = 1 << 5, WGPUInstanceBackend_Primary = WGPUInstanceBackend_Vulkan | WGPUInstanceBackend_Metal | WGPUInstanceBackend_DX12 | WGPUInstanceBackend_BrowserWebGPU, WGPUInstanceBackend_Secondary = WGPUInstanceBackend_GL | WGPUInstanceBackend_DX11, - WGPUInstanceBackend_None = 0x00000000, WGPUInstanceBackend_Force32 = 0x7FFFFFFF } WGPUInstanceBackend; typedef WGPUFlags WGPUInstanceBackendFlags; +typedef enum WGPUInstanceFlag { + WGPUInstanceFlag_Default = 0x00000000, + WGPUInstanceFlag_Debug = 1 << 0, + WGPUInstanceFlag_Validation = 1 << 1, + WGPUInstanceFlag_DiscardHalLabels = 1 << 2, + WGPUInstanceFlag_Force32 = 0x7FFFFFFF +} WGPUInstanceFlag; +typedef WGPUFlags WGPUInstanceFlags; + typedef enum WGPUDx12Compiler { WGPUDx12Compiler_Undefined = 0x00000000, WGPUDx12Compiler_Fxc = 0x00000001, @@ -58,19 +71,34 @@ typedef enum WGPUDx12Compiler { WGPUDx12Compiler_Force32 = 0x7FFFFFFF } WGPUDx12Compiler; -typedef enum WGPUCompositeAlphaMode { - WGPUCompositeAlphaMode_Auto = 0x00000000, - WGPUCompositeAlphaMode_Opaque = 0x00000001, - WGPUCompositeAlphaMode_PreMultiplied = 0x00000002, - WGPUCompositeAlphaMode_PostMultiplied = 0x00000003, - WGPUCompositeAlphaMode_Inherit = 0x00000004, - WGPUCompositeAlphaMode_Force32 = 0x7FFFFFFF -} WGPUCompositeAlphaMode; +typedef enum WGPUGles3MinorVersion { + WGPUGles3MinorVersion_Automatic = 0x00000000, + WGPUGles3MinorVersion_Version0 = 0x00000001, + WGPUGles3MinorVersion_Version1 = 0x00000002, + WGPUGles3MinorVersion_Version2 = 0x00000003, + WGPUGles3MinorVersion_Force32 = 0x7FFFFFFF +} WGPUGles3MinorVersion; + +typedef enum WGPUPipelineStatisticName { + WGPUPipelineStatisticName_VertexShaderInvocations = 0x00000000, + WGPUPipelineStatisticName_ClipperInvocations = 0x00000001, + WGPUPipelineStatisticName_ClipperPrimitivesOut = 0x00000002, + WGPUPipelineStatisticName_FragmentShaderInvocations = 0x00000003, + WGPUPipelineStatisticName_ComputeShaderInvocations = 0x00000004, + WGPUPipelineStatisticName_Force32 = 0x7FFFFFFF +} WGPUPipelineStatisticName WGPU_ENUM_ATTRIBUTE; + +typedef enum WGPUNativeQueryType { + WGPUNativeQueryType_PipelineStatistics = 0x00030000, + WGPUNativeQueryType_Force32 = 0x7FFFFFFF +} WGPUNativeQueryType WGPU_ENUM_ATTRIBUTE; typedef struct WGPUInstanceExtras { WGPUChainedStruct chain; WGPUInstanceBackendFlags backends; + WGPUInstanceFlags flags; WGPUDx12Compiler dx12ShaderCompiler; + WGPUGles3MinorVersion gles3MinorVersion; const char * dxilPath; const char * dxcPath; } WGPUInstanceExtras; @@ -80,14 +108,19 @@ typedef struct WGPUDeviceExtras { const char * tracePath; } WGPUDeviceExtras; +typedef struct WGPUNativeLimits { + uint32_t maxPushConstantSize; + uint32_t maxNonSamplerBindings; +} WGPUNativeLimits; + typedef struct WGPURequiredLimitsExtras { WGPUChainedStruct chain; - uint32_t maxPushConstantSize; + WGPUNativeLimits limits; } WGPURequiredLimitsExtras; typedef struct WGPUSupportedLimitsExtras { WGPUChainedStructOut chain; - uint32_t maxPushConstantSize; + WGPUNativeLimits limits; } WGPUSupportedLimitsExtras; typedef struct WGPUPushConstantRange { @@ -157,27 +190,32 @@ typedef struct WGPUGlobalReport { WGPUHubReport gl; } WGPUGlobalReport; -typedef struct WGPUSurfaceCapabilities { - size_t formatCount; - WGPUTextureFormat * formats; - size_t presentModeCount; - WGPUPresentMode * presentModes; - size_t alphaModeCount; - WGPUCompositeAlphaMode * alphaModes; -} WGPUSurfaceCapabilities; - -typedef struct WGPUSwapChainDescriptorExtras { - WGPUChainedStruct chain; - WGPUCompositeAlphaMode alphaMode; - size_t viewFormatCount; - WGPUTextureFormat const * viewFormats; -} WGPUSwapChainDescriptorExtras; - typedef struct WGPUInstanceEnumerateAdapterOptions { WGPUChainedStruct const * nextInChain; WGPUInstanceBackendFlags backends; } WGPUInstanceEnumerateAdapterOptions; +typedef struct WGPUBindGroupEntryExtras { + WGPUChainedStruct chain; + WGPUBuffer const * buffers; + size_t bufferCount; + WGPUSampler const * samplers; + size_t samplerCount; + WGPUTextureView const * textureViews; + size_t textureViewCount; +} WGPUBindGroupEntryExtras; + +typedef struct WGPUBindGroupLayoutEntryExtras { + WGPUChainedStruct chain; + uint32_t count; +} WGPUBindGroupLayoutEntryExtras; + +typedef struct WGPUQuerySetDescriptorExtras { + WGPUChainedStruct chain; + WGPUPipelineStatisticName const * pipelineStatistics; + size_t pipelineStatisticCount; +} WGPUQuerySetDescriptorExtras WGPU_STRUCTURE_ATTRIBUTE; + typedef void (*WGPULogCallback)(WGPULogLevel level, char const * message, void * userdata); #ifdef __cplusplus @@ -190,7 +228,7 @@ size_t wgpuInstanceEnumerateAdapters(WGPUInstance instance, WGPUInstanceEnumerat WGPUSubmissionIndex wgpuQueueSubmitForIndex(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands); // Returns true if the queue is empty, or false if there are more queue submissions still in flight. -bool wgpuDevicePoll(WGPUDevice device, bool wait, WGPUWrappedSubmissionIndex const * wrappedSubmissionIndex); +WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPUWrappedSubmissionIndex const * wrappedSubmissionIndex); void wgpuSetLogCallback(WGPULogCallback callback, void * userdata); @@ -198,8 +236,6 @@ void wgpuSetLogLevel(WGPULogLevel level); uint32_t wgpuGetVersion(void); -void wgpuSurfaceGetCapabilities(WGPUSurface surface, WGPUAdapter adapter, WGPUSurfaceCapabilities * capabilities); - void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStageFlags stages, uint32_t offset, uint32_t sizeBytes, void* const data); void wgpuRenderPassEncoderMultiDrawIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count); @@ -208,8 +244,13 @@ void wgpuRenderPassEncoderMultiDrawIndexedIndirect(WGPURenderPassEncoder encoder void wgpuRenderPassEncoderMultiDrawIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count); void wgpuRenderPassEncoderMultiDrawIndexedIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count); +void wgpuComputePassEncoderBeginPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex); +void wgpuComputePassEncoderEndPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder); +void wgpuRenderPassEncoderBeginPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex); +void wgpuRenderPassEncoderEndPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder); + #ifdef __cplusplus } // extern "C" #endif -#endif \ No newline at end of file +#endif diff --git a/WGPU.NET/Helpers/Util.cs b/WGPU.NET/Helpers/Util.cs index 8eef7d6..06cbb48 100644 --- a/WGPU.NET/Helpers/Util.cs +++ b/WGPU.NET/Helpers/Util.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Text; namespace WGPU.NET { @@ -17,7 +16,7 @@ public static IntPtr AllocHStruct(T structure) return ptr; } - public unsafe static IntPtr AllocHArray(byte[] arr) + public static unsafe IntPtr AllocHArray(byte[] arr) { IntPtr ptr = Marshal.AllocHGlobal(arr.Length); @@ -28,7 +27,7 @@ public unsafe static IntPtr AllocHArray(byte[] arr) return ptr; } - public unsafe static IntPtr AllocHArray(T[] arr) + public static unsafe IntPtr AllocHArray(T[] arr) where T : struct { int size = sizeof(T); @@ -45,7 +44,7 @@ public unsafe static IntPtr AllocHArray(T[] arr) return ptr; } - public unsafe static IntPtr AllocHArray(int count, IEnumerable items) + public static unsafe IntPtr AllocHArray(int count, IEnumerable items) where T : struct { int size = sizeof(T); @@ -109,5 +108,37 @@ public static TValue GetOrCreate(this Dictionary sel return newVal; } - } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Wgpu.BackendType ToBackend(this Wgpu.InstanceBackend type) => type switch + { + Wgpu.InstanceBackend.All => Wgpu.BackendType.Undefined, + Wgpu.InstanceBackend.Vulkan => Wgpu.BackendType.Vulkan, + Wgpu.InstanceBackend.GL => Wgpu.BackendType.OpenGLES, + Wgpu.InstanceBackend.Metal => Wgpu.BackendType.Metal, + Wgpu.InstanceBackend.DX12 => Wgpu.BackendType.D3D12, + Wgpu.InstanceBackend.DX11 => Wgpu.BackendType.D3D11, + Wgpu.InstanceBackend.BrowserWebGPU => Wgpu.BackendType.WebGPU, + Wgpu.InstanceBackend.Primary => Wgpu.BackendType.Vulkan, + Wgpu.InstanceBackend.Secondary => Wgpu.BackendType.OpenGLES, + Wgpu.InstanceBackend.Force32 => Wgpu.BackendType.Force32, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) + }; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Wgpu.InstanceBackend ToInstanceBackend(this Wgpu.BackendType type) => type switch + { + Wgpu.BackendType.Undefined => Wgpu.InstanceBackend.All, + Wgpu.BackendType.Null => Wgpu.InstanceBackend.All, + Wgpu.BackendType.WebGPU => Wgpu.InstanceBackend.BrowserWebGPU, + Wgpu.BackendType.D3D11 => Wgpu.InstanceBackend.DX11, + Wgpu.BackendType.D3D12 => Wgpu.InstanceBackend.DX12, + Wgpu.BackendType.Metal => Wgpu.InstanceBackend.Metal, + Wgpu.BackendType.Vulkan => Wgpu.InstanceBackend.Vulkan, + Wgpu.BackendType.OpenGL => Wgpu.InstanceBackend.GL, + Wgpu.BackendType.OpenGLES => Wgpu.InstanceBackend.GL, + Wgpu.BackendType.Force32 => Wgpu.InstanceBackend.Force32, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) + }; + } } diff --git a/WGPU.NET/Helpers/WgpuStructChain.cs b/WGPU.NET/Helpers/WgpuStructChain.cs index 62d8d77..304303f 100644 --- a/WGPU.NET/Helpers/WgpuStructChain.cs +++ b/WGPU.NET/Helpers/WgpuStructChain.cs @@ -20,7 +20,7 @@ public WgpuStructChain AddPrimitiveDepthClipControl(bool unclippedDepth = defaul AddStruct(new Wgpu.PrimitiveDepthClipControl() { chain = new Wgpu.ChainedStruct { sType = Wgpu.SType.PrimitiveDepthClipControl }, - unclippedDepth = unclippedDepth + unclippedDepth = unclippedDepth ? 1u : 0u }); return this; @@ -129,6 +129,17 @@ public WgpuStructChain AddSurfaceDescriptorFromXlibWindow(IntPtr display = defau return this; } + + public WgpuStructChain AddAdapterExtras(Wgpu.BackendType backend = default) + { + AddStruct(new Wgpu.AdapterExtras + { + chain = new Wgpu.ChainedStruct { sType = (Wgpu.SType)Wgpu.NativeSType.STypeAdapterExtras }, + backend = backend + }); + + return this; + } public WgpuStructChain AddDeviceExtras(string tracePath = default) { @@ -146,7 +157,10 @@ public WgpuStructChain AddRequiredLimitsExtras(uint maxPushConstantSize = defaul AddStruct(new Wgpu.RequiredLimitsExtras() { chain = new Wgpu.ChainedStruct { sType = (Wgpu.SType)Wgpu.NativeSType.STypeRequiredLimitsExtras }, - maxPushConstantSize = maxPushConstantSize + limits = new Wgpu.NativeLimits + { + maxPushConstantSize = maxPushConstantSize + } }); return this; diff --git a/WGPU.NET/WGPU.cs b/WGPU.NET/WGPU.cs index 411908a..e1af5a6 100644 --- a/WGPU.NET/WGPU.cs +++ b/WGPU.NET/WGPU.cs @@ -201,11 +201,17 @@ public enum CompilationMessageType : int Force32 = 0x7FFFFFFF, } - public enum ComputePassTimestampLocation : int + public enum CompositeAlphaMode : int { - Beginning = 0x00000000, + Auto = 0x00000000, + + Opaque = 0x00000001, + + Premultiplied = 0x00000002, - End = 0x00000001, + Unpremultiplied = 0x00000003, + + Inherit = 0x00000004, Force32 = 0x7FFFFFFF, } @@ -285,23 +291,21 @@ public enum FeatureName : int TimestampQuery = 0x00000003, - PipelineStatisticsQuery = 0x00000004, + TextureCompressionBC = 0x00000004, - TextureCompressionBC = 0x00000005, + TextureCompressionETC2 = 0x00000005, - TextureCompressionETC2 = 0x00000006, + TextureCompressionASTC = 0x00000006, - TextureCompressionASTC = 0x00000007, + IndirectFirstInstance = 0x00000007, - IndirectFirstInstance = 0x00000008, + ShaderF16 = 0x00000008, - ShaderF16 = 0x00000009, + RG11B10UfloatRenderable = 0x00000009, - RG11B10UfloatRenderable = 0x0000000A, + BGRA8UnormStorage = 0x0000000A, - BGRA8UnormStorage = 0x0000000B, - - Float32Filterable = 0x0000000C, + Float32Filterable = 0x0000000B, Force32 = 0x7FFFFFFF, } @@ -355,21 +359,6 @@ public enum MipmapFilterMode : int Force32 = 0x7FFFFFFF, } - public enum PipelineStatisticName : int - { - VertexShaderInvocations = 0x00000000, - - ClipperInvocations = 0x00000001, - - ClipperPrimitivesOut = 0x00000002, - - FragmentShaderInvocations = 0x00000003, - - ComputeShaderInvocations = 0x00000004, - - Force32 = 0x7FFFFFFF, - } - public enum PowerPreference : int { Undefined = 0x00000000, @@ -383,11 +372,13 @@ public enum PowerPreference : int public enum PresentMode : int { - Immediate = 0x00000000, + Fifo = 0x00000000, - Mailbox = 0x00000001, + FifoRelaxed = 0x00000001, - Fifo = 0x00000002, + Immediate = 0x00000002, + + Mailbox = 0x00000003, Force32 = 0x7FFFFFFF, } @@ -411,9 +402,7 @@ public enum QueryType : int { Occlusion = 0x00000000, - PipelineStatistics = 0x00000001, - - Timestamp = 0x00000002, + Timestamp = 0x00000001, Force32 = 0x7FFFFFFF, } @@ -431,15 +420,6 @@ public enum QueueWorkDoneStatus : int Force32 = 0x7FFFFFFF, } - public enum RenderPassTimestampLocation : int - { - Beginning = 0x00000000, - - End = 0x00000001, - - Force32 = 0x7FFFFFFF, - } - public enum RequestAdapterStatus : int { Success = 0x00000000, @@ -547,6 +527,23 @@ public enum StoreOp : int Force32 = 0x7FFFFFFF, } + public enum SurfaceGetCurrentTextureStatus : int + { + Success = 0x00000000, + + Timeout = 0x00000001, + + Outdated = 0x00000002, + + Lost = 0x00000003, + + OutOfMemory = 0x00000004, + + DeviceLost = 0x00000005, + + Force32 = 0x7FFFFFFF, + } + public enum TextureAspect : int { All = 0x00000000, @@ -968,60 +965,76 @@ public enum NativeSType : int /// /// Start at 6 to prevent collisions with webgpu STypes /// - STypeDeviceExtras = 0x60000001, + STypeAdapterExtras = 0x60000002, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeAdapterExtras = 0x60000002, + STypeDeviceExtras = 0x00030001, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeRequiredLimitsExtras = 0x60000003, + STypeRequiredLimitsExtras = 0x00030002, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypePipelineLayoutExtras = 0x60000004, + STypePipelineLayoutExtras = 0x00030003, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeShaderModuleGLSLDescriptor = 0x60000005, + STypeShaderModuleGLSLDescriptor = 0x00030004, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeSupportedLimitsExtras = 0x60000003, + STypeSupportedLimitsExtras = 0x00030005, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeInstanceExtras = 0x60000006, + STypeInstanceExtras = 0x00030006, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native /// - STypeSwapChainDescriptorExtras = 0x60000007, + STypeBindGroupEntryExtras = 0x00030007, /// - /// Start at 6 to prevent collisions with webgpu STypes + /// Start at 0003 since that's allocated range for wgpu-native + /// + STypeBindGroupLayoutEntryExtras = 0x00030008, + + /// + /// Start at 0003 since that's allocated range for wgpu-native + /// + STypeQuerySetDescriptorExtras = 0x00030009, + + /// + /// Start at 0003 since that's allocated range for wgpu-native /// Force32 = 0x7FFFFFFF, } public enum NativeFeature : int { - PushConstants = 0x60000001, + PushConstants = 0x00030001, + + TextureAdapterSpecificFormatFeatures = 0x00030002, + + MultiDrawIndirect = 0x00030003, + + MultiDrawIndirectCount = 0x00030004, - TextureAdapterSpecificFormatFeatures = 0x60000002, + VertexWritableStorage = 0x00030005, - MultiDrawIndirect = 0x60000003, + TextureBindingArray = 0x00030006, - MultiDrawIndirectCount = 0x60000004, + SampledTextureAndStorageBufferArrayNonUniformIndexing = 0x00030007, - VertexWritableStorage = 0x60000005, + PipelineStatisticsQuery = 0x00030008, Force32 = 0x7FFFFFFF, } @@ -1046,9 +1059,11 @@ public enum LogLevel : int [Flags] public enum InstanceBackend : int { - Vulkan = 1 << (int) 1, + All = 0x00000000, + + Vulkan = 1 << (int) 0, - GL = 1 << (int) 5, + GL = 1 << (int) 1, Metal = 1 << (int) 2, @@ -1056,13 +1071,25 @@ public enum InstanceBackend : int DX11 = 1 << (int) 4, - BrowserWebGPU = 1 << (int) 6, + BrowserWebGPU = 1 << (int) 5, Primary = Vulkan | Metal | DX12 | BrowserWebGPU, Secondary = GL | DX11, - None = 0x00000000, + Force32 = 0x7FFFFFFF, + } + + [Flags] + public enum InstanceFlag : int + { + Default = 0x00000000, + + Debug = 1 << (int) 0, + + Validation = 1 << (int) 1, + + DiscardHalLabels = 1 << (int) 2, Force32 = 0x7FFFFFFF, } @@ -1078,17 +1105,37 @@ public enum Dx12Compiler : int Force32 = 0x7FFFFFFF, } - public enum CompositeAlphaMode : int + public enum Gles3MinorVersion : int { - Auto = 0x00000000, + Automatic = 0x00000000, - Opaque = 0x00000001, + Version0 = 0x00000001, - PreMultiplied = 0x00000002, + Version1 = 0x00000002, - PostMultiplied = 0x00000003, + Version2 = 0x00000003, - Inherit = 0x00000004, + Force32 = 0x7FFFFFFF, + } + + public enum PipelineStatisticName : int + { + VertexShaderInvocations = 0x00000000, + + ClipperInvocations = 0x00000001, + + ClipperPrimitivesOut = 0x00000002, + + FragmentShaderInvocations = 0x00000003, + + ComputeShaderInvocations = 0x00000004, + + Force32 = 0x7FFFFFFF, + } + + public enum NativeQueryType : int + { + PipelineStatistics = 0x00030000, Force32 = 0x7FFFFFFF, } @@ -1533,28 +1580,6 @@ public enum CompositeAlphaMode : int public static bool operator !=(SurfaceImpl left, SurfaceImpl right) => !left.Equals(right); } - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public readonly partial struct SwapChainImpl : IEquatable - { - private readonly IntPtr _handle; - - public SwapChainImpl(IntPtr handle) => _handle = handle; - - public IntPtr Handle => _handle; - - public bool Equals(SwapChainImpl other) => _handle.Equals(other._handle); - - public override bool Equals(object obj) => obj is SwapChainImpl other && Equals(other); - - public override int GetHashCode() => _handle.GetHashCode(); - - public override string ToString() => "0x" + (IntPtr.Size == 8 ? _handle.ToString("X16") : _handle.ToString("X8")); - - public static bool operator ==(SwapChainImpl left, SwapChainImpl right) => left.Equals(right); - - public static bool operator !=(SwapChainImpl left, SwapChainImpl right) => !left.Equals(right); - } - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public readonly partial struct TextureImpl : IEquatable { @@ -1679,8 +1704,7 @@ public partial struct BufferBindingLayout public Wgpu.BufferBindingType type; - [MarshalAs(UnmanagedType.U1)] - public bool hasDynamicOffset; + public uint hasDynamicOffset; public ulong minBindingSize; } @@ -1697,8 +1721,7 @@ public partial struct BufferDescriptor public ulong size; - [MarshalAs(UnmanagedType.U1)] - public bool mappedAtCreation; + public uint mappedAtCreation; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1757,13 +1780,13 @@ public partial struct CompilationMessage } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct ComputePassTimestampWrite + public partial struct ComputePassTimestampWrites { public Wgpu.QuerySetImpl querySet; - public uint queryIndex; + public uint beginningOfPassWriteIndex; - public Wgpu.ComputePassTimestampLocation location; + public uint endOfPassWriteIndex; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1806,6 +1829,8 @@ public partial struct Limits public uint maxBindGroups; + public uint maxBindGroupsPlusVertexBuffers; + public uint maxBindingsPerBindGroup; public uint maxDynamicUniformBuffersPerPipelineLayout; @@ -1868,8 +1893,7 @@ public partial struct MultisampleState public uint mask; - [MarshalAs(UnmanagedType.U1)] - public bool alphaToCoverageEnabled; + public uint alphaToCoverageEnabled; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1903,8 +1927,7 @@ public partial struct PrimitiveDepthClipControl { public Wgpu.ChainedStruct chain; - [MarshalAs(UnmanagedType.U1)] - public bool unclippedDepth; + public uint unclippedDepth; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1932,10 +1955,6 @@ public partial struct QuerySetDescriptor public Wgpu.QueryType type; public uint count; - - public IntPtr pipelineStatistics; - - public ulong pipelineStatisticsCount; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1964,7 +1983,7 @@ public partial struct RenderBundleEncoderDescriptor [MarshalAs(UnmanagedType.LPStr)] public string label; - public ulong colorFormatsCount; + public ulong colorFormatCount; public IntPtr colorFormats; @@ -1972,11 +1991,9 @@ public partial struct RenderBundleEncoderDescriptor public uint sampleCount; - [MarshalAs(UnmanagedType.U1)] - public bool depthReadOnly; + public uint depthReadOnly; - [MarshalAs(UnmanagedType.U1)] - public bool stencilReadOnly; + public uint stencilReadOnly; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -1990,8 +2007,7 @@ public partial struct RenderPassDepthStencilAttachment public float depthClearValue; - [MarshalAs(UnmanagedType.U1)] - public bool depthReadOnly; + public uint depthReadOnly; public Wgpu.LoadOp stencilLoadOp; @@ -1999,8 +2015,7 @@ public partial struct RenderPassDepthStencilAttachment public uint stencilClearValue; - [MarshalAs(UnmanagedType.U1)] - public bool stencilReadOnly; + public uint stencilReadOnly; } /// @@ -2015,13 +2030,13 @@ public partial struct RenderPassDescriptorMaxDrawCount } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct RenderPassTimestampWrite + public partial struct RenderPassTimestampWrites { public Wgpu.QuerySetImpl querySet; - public uint queryIndex; + public uint beginningOfPassWriteIndex; - public Wgpu.RenderPassTimestampLocation location; + public uint endOfPassWriteIndex; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2035,8 +2050,7 @@ public partial struct RequestAdapterOptions public Wgpu.BackendType backendType; - [MarshalAs(UnmanagedType.U1)] - public bool forceFallbackAdapter; + public uint forceFallbackAdapter; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2136,6 +2150,48 @@ public partial struct StorageTextureBindingLayout public Wgpu.TextureViewDimension viewDimension; } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public partial struct SurfaceCapabilities + { + public IntPtr nextInChain; + + public ulong formatCount; + + public IntPtr formats; + + public ulong presentModeCount; + + public IntPtr presentModes; + + public ulong alphaModeCount; + + public IntPtr alphaModes; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public partial struct SurfaceConfiguration + { + public IntPtr nextInChain; + + public Wgpu.DeviceImpl device; + + public Wgpu.TextureFormat format; + + public uint usage; + + public ulong viewFormatCount; + + public IntPtr viewFormats; + + public Wgpu.CompositeAlphaMode alphaMode; + + public uint width; + + public uint height; + + public Wgpu.PresentMode presentMode; + } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public partial struct SurfaceDescriptor { @@ -2232,22 +2288,13 @@ public partial struct SurfaceDescriptorFromXlibWindow } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct SwapChainDescriptor + public partial struct SurfaceTexture { - public IntPtr nextInChain; - - [MarshalAs(UnmanagedType.LPStr)] - public string label; - - public uint usage; - - public Wgpu.TextureFormat format; - - public uint width; + public Wgpu.TextureImpl texture; - public uint height; + public uint suboptimal; - public Wgpu.PresentMode presentMode; + public Wgpu.SurfaceGetCurrentTextureStatus status; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2259,8 +2306,7 @@ public partial struct TextureBindingLayout public Wgpu.TextureViewDimension viewDimension; - [MarshalAs(UnmanagedType.U1)] - public bool multisampled; + public uint multisampled; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2367,8 +2413,6 @@ public partial struct ComputePassDescriptor [MarshalAs(UnmanagedType.LPStr)] public string label; - public ulong timestampWriteCount; - public IntPtr timestampWrites; } @@ -2379,8 +2423,7 @@ public partial struct DepthStencilState public Wgpu.TextureFormat format; - [MarshalAs(UnmanagedType.U1)] - public bool depthWriteEnabled; + public uint depthWriteEnabled; public Wgpu.CompareFunction depthCompare; @@ -2441,6 +2484,8 @@ public partial struct ProgrammableStageDescriptor [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public partial struct RenderPassColorAttachment { + public IntPtr nextInChain; + public Wgpu.TextureViewImpl view; public Wgpu.TextureViewImpl resolveTarget; @@ -2564,7 +2609,7 @@ public partial struct DeviceDescriptor [MarshalAs(UnmanagedType.LPStr)] public string label; - public ulong requiredFeaturesCount; + public ulong requiredFeatureCount; public IntPtr requiredFeatures; @@ -2596,8 +2641,6 @@ public partial struct RenderPassDescriptor public Wgpu.QuerySetImpl occlusionQuerySet; - public ulong timestampWriteCount; - public IntPtr timestampWrites; } @@ -2667,8 +2710,12 @@ public partial struct InstanceExtras public uint backends; + public uint flags; + public Wgpu.Dx12Compiler dx12ShaderCompiler; + public Wgpu.Gles3MinorVersion gles3MinorVersion; + [MarshalAs(UnmanagedType.LPStr)] public string dxilPath; @@ -2676,6 +2723,14 @@ public partial struct InstanceExtras public string dxcPath; } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public partial struct AdapterExtras + { + public Wgpu.ChainedStruct chain; + + public Wgpu.BackendType backend; + } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public partial struct DeviceExtras { @@ -2685,12 +2740,20 @@ public partial struct DeviceExtras public string tracePath; } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public partial struct NativeLimits + { + public uint maxPushConstantSize; + + public uint maxNonSamplerBindings; + } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public partial struct RequiredLimitsExtras { public Wgpu.ChainedStruct chain; - public uint maxPushConstantSize; + public Wgpu.NativeLimits limits; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2698,7 +2761,7 @@ public partial struct SupportedLimitsExtras { public Wgpu.ChainedStructOut chain; - public uint maxPushConstantSize; + public Wgpu.NativeLimits limits; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] @@ -2819,39 +2882,47 @@ public partial struct GlobalReport } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct SurfaceCapabilities + public partial struct InstanceEnumerateAdapterOptions { - public ulong formatCount; + public IntPtr nextInChain; - public IntPtr formats; + public uint backends; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public partial struct BindGroupEntryExtras + { + public Wgpu.ChainedStruct chain; - public ulong presentModeCount; + public IntPtr buffers; - public IntPtr presentModes; + public ulong bufferCount; - public ulong alphaModeCount; + public IntPtr samplers; - public IntPtr alphaModes; + public ulong samplerCount; + + public IntPtr textureViews; + + public ulong textureViewCount; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct SwapChainDescriptorExtras + public partial struct BindGroupLayoutEntryExtras { public Wgpu.ChainedStruct chain; - public Wgpu.CompositeAlphaMode alphaMode; - - public ulong viewFormatCount; - - public IntPtr viewFormats; + public uint count; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] - public partial struct InstanceEnumerateAdapterOptions + public partial struct QuerySetDescriptorExtras { - public IntPtr nextInChain; + public Wgpu.ChainedStruct chain; - public uint backends; + public IntPtr pipelineStatistics; + + public ulong pipelineStatisticCount; } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -2891,15 +2962,13 @@ public partial struct InstanceEnumerateAdapterOptions public delegate ulong ProcAdapterEnumerateFeatures(Wgpu.AdapterImpl adapter, ref Wgpu.FeatureName features); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public delegate bool ProcAdapterGetLimits(Wgpu.AdapterImpl adapter, ref Wgpu.SupportedLimits limits); + public delegate uint ProcAdapterGetLimits(Wgpu.AdapterImpl adapter, ref Wgpu.SupportedLimits limits); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcAdapterGetProperties(Wgpu.AdapterImpl adapter, ref Wgpu.AdapterProperties properties); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public delegate bool ProcAdapterHasFeature(Wgpu.AdapterImpl adapter, Wgpu.FeatureName feature); + public delegate uint ProcAdapterHasFeature(Wgpu.AdapterImpl adapter, Wgpu.FeatureName feature); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcAdapterRequestDevice(Wgpu.AdapterImpl adapter, in Wgpu.DeviceDescriptor descriptor, Wgpu.RequestDeviceCallback callback, IntPtr userdata); @@ -3018,9 +3087,6 @@ public partial struct InstanceEnumerateAdapterOptions [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcCommandEncoderRelease(Wgpu.CommandEncoderImpl commandEncoder); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcComputePassEncoderBeginPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcComputePassEncoderDispatchWorkgroups(Wgpu.ComputePassEncoderImpl computePassEncoder, uint workgroupCountX, uint workgroupCountY, uint workgroupCountZ); @@ -3030,9 +3096,6 @@ public partial struct InstanceEnumerateAdapterOptions [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcComputePassEncoderEnd(Wgpu.ComputePassEncoderImpl computePassEncoder); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcComputePassEncoderEndPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcComputePassEncoderInsertDebugMarker(Wgpu.ComputePassEncoderImpl computePassEncoder, [MarshalAs(UnmanagedType.LPStr)] string markerLabel); @@ -3108,9 +3171,6 @@ public partial struct InstanceEnumerateAdapterOptions [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Wgpu.ShaderModuleImpl ProcDeviceCreateShaderModule(Wgpu.DeviceImpl device, in Wgpu.ShaderModuleDescriptor descriptor); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate Wgpu.SwapChainImpl ProcDeviceCreateSwapChain(Wgpu.DeviceImpl device, Wgpu.SurfaceImpl surface, in Wgpu.SwapChainDescriptor descriptor); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Wgpu.TextureImpl ProcDeviceCreateTexture(Wgpu.DeviceImpl device, in Wgpu.TextureDescriptor descriptor); @@ -3121,15 +3181,13 @@ public partial struct InstanceEnumerateAdapterOptions public delegate ulong ProcDeviceEnumerateFeatures(Wgpu.DeviceImpl device, ref Wgpu.FeatureName features); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public delegate bool ProcDeviceGetLimits(Wgpu.DeviceImpl device, ref Wgpu.SupportedLimits limits); + public delegate uint ProcDeviceGetLimits(Wgpu.DeviceImpl device, ref Wgpu.SupportedLimits limits); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Wgpu.QueueImpl ProcDeviceGetQueue(Wgpu.DeviceImpl device); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public delegate bool ProcDeviceHasFeature(Wgpu.DeviceImpl device, Wgpu.FeatureName feature); + public delegate uint ProcDeviceHasFeature(Wgpu.DeviceImpl device, Wgpu.FeatureName feature); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcDevicePopErrorScope(Wgpu.DeviceImpl device, Wgpu.ErrorCallback callback, IntPtr userdata); @@ -3269,9 +3327,6 @@ public partial struct InstanceEnumerateAdapterOptions [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcRenderPassEncoderBeginOcclusionQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder, uint queryIndex); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcRenderPassEncoderBeginPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcRenderPassEncoderDraw(Wgpu.RenderPassEncoderImpl renderPassEncoder, uint vertexCount, uint instanceCount, uint firstVertex, uint firstInstance); @@ -3290,9 +3345,6 @@ public partial struct InstanceEnumerateAdapterOptions [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcRenderPassEncoderEndOcclusionQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcRenderPassEncoderEndPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void ProcRenderPassEncoderExecuteBundles(Wgpu.RenderPassEncoderImpl renderPassEncoder, ulong bundleCount, ref Wgpu.RenderBundleImpl bundles); @@ -3372,25 +3424,31 @@ public partial struct InstanceEnumerateAdapterOptions public delegate void ProcShaderModuleRelease(Wgpu.ShaderModuleImpl shaderModule); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate Wgpu.TextureFormat ProcSurfaceGetPreferredFormat(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter); + public delegate void ProcSurfaceConfigure(Wgpu.SurfaceImpl surface, in Wgpu.SurfaceConfiguration config); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcSurfaceReference(Wgpu.SurfaceImpl surface); + public delegate void ProcSurfaceGetCapabilities(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter, ref Wgpu.SurfaceCapabilities capabilities); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcSurfaceRelease(Wgpu.SurfaceImpl surface); + public delegate void ProcSurfaceGetCurrentTexture(Wgpu.SurfaceImpl surface, ref Wgpu.SurfaceTexture surfaceTexture); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate Wgpu.TextureViewImpl ProcSwapChainGetCurrentTextureView(Wgpu.SwapChainImpl swapChain); + public delegate Wgpu.TextureFormat ProcSurfaceGetPreferredFormat(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcSwapChainPresent(Wgpu.SwapChainImpl swapChain); + public delegate void ProcSurfacePresent(Wgpu.SurfaceImpl surface); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcSwapChainReference(Wgpu.SwapChainImpl swapChain); + public delegate void ProcSurfaceUnconfigure(Wgpu.SurfaceImpl surface); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void ProcSwapChainRelease(Wgpu.SwapChainImpl swapChain); + public delegate void ProcSurfaceReference(Wgpu.SurfaceImpl surface); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void ProcSurfaceRelease(Wgpu.SurfaceImpl surface); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void ProcSurfaceCapabilitiesFreeMembers(Wgpu.SurfaceCapabilities capabilities); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate Wgpu.TextureViewImpl ProcTextureCreateView(Wgpu.TextureImpl texture, in Wgpu.TextureViewDescriptor descriptor); @@ -3456,15 +3514,13 @@ public partial struct InstanceEnumerateAdapterOptions public static extern ulong AdapterEnumerateFeatures(Wgpu.AdapterImpl adapter, ref Wgpu.FeatureName features); [DllImport("libwgpu_native", EntryPoint = "wgpuAdapterGetLimits", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public static extern bool AdapterGetLimits(Wgpu.AdapterImpl adapter, ref Wgpu.SupportedLimits limits); + public static extern uint AdapterGetLimits(Wgpu.AdapterImpl adapter, ref Wgpu.SupportedLimits limits); [DllImport("libwgpu_native", EntryPoint = "wgpuAdapterGetProperties", CallingConvention = CallingConvention.Cdecl)] public static extern void AdapterGetProperties(Wgpu.AdapterImpl adapter, ref Wgpu.AdapterProperties properties); [DllImport("libwgpu_native", EntryPoint = "wgpuAdapterHasFeature", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public static extern bool AdapterHasFeature(Wgpu.AdapterImpl adapter, Wgpu.FeatureName feature); + public static extern uint AdapterHasFeature(Wgpu.AdapterImpl adapter, Wgpu.FeatureName feature); [DllImport("libwgpu_native", EntryPoint = "wgpuAdapterRequestDevice", CallingConvention = CallingConvention.Cdecl)] public static extern void AdapterRequestDevice(Wgpu.AdapterImpl adapter, in Wgpu.DeviceDescriptor descriptor, Wgpu.RequestDeviceCallback callback, IntPtr userdata); @@ -3601,9 +3657,6 @@ public partial struct InstanceEnumerateAdapterOptions /// /// Methods of ComputePassEncoder /// - [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderBeginPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] - public static extern void ComputePassEncoderBeginPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); - [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderDispatchWorkgroups", CallingConvention = CallingConvention.Cdecl)] public static extern void ComputePassEncoderDispatchWorkgroups(Wgpu.ComputePassEncoderImpl computePassEncoder, uint workgroupCountX, uint workgroupCountY, uint workgroupCountZ); @@ -3613,9 +3666,6 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderEnd", CallingConvention = CallingConvention.Cdecl)] public static extern void ComputePassEncoderEnd(Wgpu.ComputePassEncoderImpl computePassEncoder); - [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderEndPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] - public static extern void ComputePassEncoderEndPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder); - [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderInsertDebugMarker", CallingConvention = CallingConvention.Cdecl)] public static extern void ComputePassEncoderInsertDebugMarker(Wgpu.ComputePassEncoderImpl computePassEncoder, [MarshalAs(UnmanagedType.LPStr)] string markerLabel); @@ -3697,9 +3747,6 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceCreateShaderModule", CallingConvention = CallingConvention.Cdecl)] public static extern Wgpu.ShaderModuleImpl DeviceCreateShaderModule(Wgpu.DeviceImpl device, in Wgpu.ShaderModuleDescriptor descriptor); - [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceCreateSwapChain", CallingConvention = CallingConvention.Cdecl)] - public static extern Wgpu.SwapChainImpl DeviceCreateSwapChain(Wgpu.DeviceImpl device, Wgpu.SurfaceImpl surface, in Wgpu.SwapChainDescriptor descriptor); - [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceCreateTexture", CallingConvention = CallingConvention.Cdecl)] public static extern Wgpu.TextureImpl DeviceCreateTexture(Wgpu.DeviceImpl device, in Wgpu.TextureDescriptor descriptor); @@ -3710,15 +3757,13 @@ public partial struct InstanceEnumerateAdapterOptions public static extern ulong DeviceEnumerateFeatures(Wgpu.DeviceImpl device, ref Wgpu.FeatureName features); [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceGetLimits", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public static extern bool DeviceGetLimits(Wgpu.DeviceImpl device, ref Wgpu.SupportedLimits limits); + public static extern uint DeviceGetLimits(Wgpu.DeviceImpl device, ref Wgpu.SupportedLimits limits); [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceGetQueue", CallingConvention = CallingConvention.Cdecl)] public static extern Wgpu.QueueImpl DeviceGetQueue(Wgpu.DeviceImpl device); [DllImport("libwgpu_native", EntryPoint = "wgpuDeviceHasFeature", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public static extern bool DeviceHasFeature(Wgpu.DeviceImpl device, Wgpu.FeatureName feature); + public static extern uint DeviceHasFeature(Wgpu.DeviceImpl device, Wgpu.FeatureName feature); [DllImport("libwgpu_native", EntryPoint = "wgpuDevicePopErrorScope", CallingConvention = CallingConvention.Cdecl)] public static extern void DevicePopErrorScope(Wgpu.DeviceImpl device, Wgpu.ErrorCallback callback, IntPtr userdata); @@ -3879,9 +3924,6 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderBeginOcclusionQuery", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderBeginOcclusionQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder, uint queryIndex); - [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderBeginPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] - public static extern void RenderPassEncoderBeginPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); - [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderDraw", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderDraw(Wgpu.RenderPassEncoderImpl renderPassEncoder, uint vertexCount, uint instanceCount, uint firstVertex, uint firstInstance); @@ -3900,9 +3942,6 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderEndOcclusionQuery", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderEndOcclusionQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder); - [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderEndPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] - public static extern void RenderPassEncoderEndPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder); - [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderExecuteBundles", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderExecuteBundles(Wgpu.RenderPassEncoderImpl renderPassEncoder, ulong bundleCount, ref Wgpu.RenderBundleImpl bundles); @@ -3993,9 +4032,24 @@ public partial struct InstanceEnumerateAdapterOptions /// /// Methods of Surface /// + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceConfigure", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfaceConfigure(Wgpu.SurfaceImpl surface, in Wgpu.SurfaceConfiguration config); + + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceGetCapabilities", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfaceGetCapabilities(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter, ref Wgpu.SurfaceCapabilities capabilities); + + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceGetCurrentTexture", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfaceGetCurrentTexture(Wgpu.SurfaceImpl surface, ref Wgpu.SurfaceTexture surfaceTexture); + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceGetPreferredFormat", CallingConvention = CallingConvention.Cdecl)] public static extern Wgpu.TextureFormat SurfaceGetPreferredFormat(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter); + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfacePresent", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfacePresent(Wgpu.SurfaceImpl surface); + + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceUnconfigure", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfaceUnconfigure(Wgpu.SurfaceImpl surface); + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceReference", CallingConvention = CallingConvention.Cdecl)] public static extern void SurfaceReference(Wgpu.SurfaceImpl surface); @@ -4003,19 +4057,10 @@ public partial struct InstanceEnumerateAdapterOptions public static extern void SurfaceRelease(Wgpu.SurfaceImpl surface); /// - /// Methods of SwapChain + /// Methods of SurfaceCapabilities /// - [DllImport("libwgpu_native", EntryPoint = "wgpuSwapChainGetCurrentTextureView", CallingConvention = CallingConvention.Cdecl)] - public static extern Wgpu.TextureViewImpl SwapChainGetCurrentTextureView(Wgpu.SwapChainImpl swapChain); - - [DllImport("libwgpu_native", EntryPoint = "wgpuSwapChainPresent", CallingConvention = CallingConvention.Cdecl)] - public static extern void SwapChainPresent(Wgpu.SwapChainImpl swapChain); - - [DllImport("libwgpu_native", EntryPoint = "wgpuSwapChainReference", CallingConvention = CallingConvention.Cdecl)] - public static extern void SwapChainReference(Wgpu.SwapChainImpl swapChain); - - [DllImport("libwgpu_native", EntryPoint = "wgpuSwapChainRelease", CallingConvention = CallingConvention.Cdecl)] - public static extern void SwapChainRelease(Wgpu.SwapChainImpl swapChain); + [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceCapabilitiesFreeMembers", CallingConvention = CallingConvention.Cdecl)] + public static extern void SurfaceCapabilitiesFreeMembers(Wgpu.SurfaceCapabilities capabilities); /// /// Methods of Texture @@ -4084,8 +4129,7 @@ public partial struct InstanceEnumerateAdapterOptions /// Returns true if the queue is empty, or false if there are more queue submissions still in flight. /// [DllImport("libwgpu_native", EntryPoint = "wgpuDevicePoll", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.U1)] - public static extern bool DevicePoll(Wgpu.DeviceImpl device, [MarshalAs(UnmanagedType.U1)] bool wait, in Wgpu.WrappedSubmissionIndex wrappedSubmissionIndex); + public static extern uint DevicePoll(Wgpu.DeviceImpl device, uint wait, in Wgpu.WrappedSubmissionIndex wrappedSubmissionIndex); [DllImport("libwgpu_native", EntryPoint = "wgpuSetLogCallback", CallingConvention = CallingConvention.Cdecl)] public static extern void SetLogCallback(Wgpu.LogCallback callback, IntPtr userdata); @@ -4096,9 +4140,6 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuGetVersion", CallingConvention = CallingConvention.Cdecl)] public static extern uint GetVersion(); - [DllImport("libwgpu_native", EntryPoint = "wgpuSurfaceGetCapabilities", CallingConvention = CallingConvention.Cdecl)] - public static extern void SurfaceGetCapabilities(Wgpu.SurfaceImpl surface, Wgpu.AdapterImpl adapter, ref Wgpu.SurfaceCapabilities capabilities); - [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderSetPushConstants", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderSetPushConstants(Wgpu.RenderPassEncoderImpl encoder, uint stages, uint offset, uint sizeBytes, IntPtr data); @@ -4113,5 +4154,17 @@ public partial struct InstanceEnumerateAdapterOptions [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderMultiDrawIndexedIndirectCount", CallingConvention = CallingConvention.Cdecl)] public static extern void RenderPassEncoderMultiDrawIndexedIndirectCount(Wgpu.RenderPassEncoderImpl encoder, Wgpu.BufferImpl buffer, ulong offset, Wgpu.BufferImpl countbuffer, ulong countbufferoffset, uint maxcount); + + [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderBeginPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] + public static extern void ComputePassEncoderBeginPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); + + [DllImport("libwgpu_native", EntryPoint = "wgpuComputePassEncoderEndPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] + public static extern void ComputePassEncoderEndPipelineStatisticsQuery(Wgpu.ComputePassEncoderImpl computePassEncoder); + + [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderBeginPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] + public static extern void RenderPassEncoderBeginPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder, Wgpu.QuerySetImpl querySet, uint queryIndex); + + [DllImport("libwgpu_native", EntryPoint = "wgpuRenderPassEncoderEndPipelineStatisticsQuery", CallingConvention = CallingConvention.Cdecl)] + public static extern void RenderPassEncoderEndPipelineStatisticsQuery(Wgpu.RenderPassEncoderImpl renderPassEncoder); } } diff --git a/WGPU.NET/Wrappers/Adapter.cs b/WGPU.NET/Wrappers/Adapter.cs index 8012092..ee682b5 100644 --- a/WGPU.NET/Wrappers/Adapter.cs +++ b/WGPU.NET/Wrappers/Adapter.cs @@ -32,18 +32,16 @@ internal Adapter(AdapterImpl impl) Impl = impl; } - - public unsafe FeatureName[] EnumerateFeatures() + public FeatureName[] EnumerateFeatures() { - FeatureName features = default; - - ulong size = AdapterEnumerateFeatures(Impl, ref features); - - var featuresSpan = new Span(Unsafe.AsPointer(ref features), (int)size); + ulong size; + unsafe + { + size = AdapterEnumerateFeatures(Impl, ref *(FeatureName*)null); + } FeatureName[] result = new FeatureName[size]; - - featuresSpan.CopyTo(result); + AdapterEnumerateFeatures(Impl, ref result[0]); return result; } @@ -52,7 +50,7 @@ public bool GetLimits(out SupportedLimits limits) { limits = new SupportedLimits(); - return AdapterGetLimits(Impl, ref limits); + return AdapterGetLimits(Impl, ref limits) == 1u; } public void GetProperties(out AdapterProperties properties) @@ -62,7 +60,7 @@ public void GetProperties(out AdapterProperties properties) AdapterGetProperties(Impl, ref properties); } - public bool HasFeature(FeatureName feature) => AdapterHasFeature(Impl, feature); + public bool HasFeature(FeatureName feature) => AdapterHasFeature(Impl, feature) == 1u; public void RequestDevice(RequestDeviceCallback callback, string label, NativeFeature[] nativeFeatures, QueueDescriptor defaultQueue = default, Limits? limits = null, RequiredLimitsExtras? limitsExtras = null, DeviceExtras? deviceExtras = null, DeviceLostCallback deviceLostCallback = null) @@ -71,14 +69,14 @@ public void RequestDevice(RequestDeviceCallback callback, string label, NativeFe WgpuStructChain limitsExtrasChain = null; WgpuStructChain deviceExtrasChain = null; - if (limitsExtras != null) + if (limitsExtras is { }) { limitsExtrasChain = new WgpuStructChain() .AddRequiredLimitsExtras( limitsExtras.Value.MaxPushConstantSize); } - if (limits != null) + if (limits is { }) { requiredLimits = new Wgpu.RequiredLimits { @@ -89,25 +87,23 @@ public void RequestDevice(RequestDeviceCallback callback, string label, NativeFe }; } - if (deviceExtras != null) + if (deviceExtras is { }) deviceExtrasChain = new WgpuStructChain().AddDeviceExtras(deviceExtras.Value.TracePath); unsafe { fixed (NativeFeature* requiredFeatures = nativeFeatures) - { - AdapterRequestDevice(Impl, new DeviceDescriptor() + AdapterRequestDevice(Impl, new DeviceDescriptor { defaultQueue = defaultQueue, - requiredLimits = limits != null ? new IntPtr(&requiredLimits) : IntPtr.Zero, - requiredFeaturesCount = (uint)nativeFeatures.Length, + requiredLimits = limits is { } ? new IntPtr(&requiredLimits) : IntPtr.Zero, + requiredFeatureCount = (uint)nativeFeatures.Length, requiredFeatures = new IntPtr(requiredFeatures), label = label, deviceLostCallback = (reason, message, _) => deviceLostCallback?.Invoke(reason, message), - nextInChain = deviceExtras==null ? IntPtr.Zero : deviceExtrasChain.GetPointer() - }, - (s,d,m,_) => callback(s,new Device(d),m), IntPtr.Zero); - } + nextInChain = deviceExtras is null ? IntPtr.Zero : deviceExtrasChain.GetPointer() + }, + (s, d, m, _) => callback(s, new Device(d), m), IntPtr.Zero); } limitsExtrasChain?.Dispose(); diff --git a/WGPU.NET/Wrappers/BindGroup.cs b/WGPU.NET/Wrappers/BindGroup.cs index 9825e83..ec378a3 100644 --- a/WGPU.NET/Wrappers/BindGroup.cs +++ b/WGPU.NET/Wrappers/BindGroup.cs @@ -29,6 +29,10 @@ internal BindGroup(BindGroupImpl impl) Impl = impl; } + + public IntPtr GetBindGroupHandle() => _impl.Handle; + + public static BindGroup FromHandle(IntPtr handle) => new BindGroup(new BindGroupImpl(handle)); public void Dispose() { diff --git a/WGPU.NET/Wrappers/CommandEncoder.cs b/WGPU.NET/Wrappers/CommandEncoder.cs index c6bd4b0..625438c 100644 --- a/WGPU.NET/Wrappers/CommandEncoder.cs +++ b/WGPU.NET/Wrappers/CommandEncoder.cs @@ -128,11 +128,11 @@ public RenderPassEncoder BeginRenderPass(string label, depthLoadOp = depthStencilAttachment.Value.DepthLoadOp, depthStoreOp = depthStencilAttachment.Value.DepthStoreOp, depthClearValue = depthStencilAttachment.Value.DepthClearValue, - depthReadOnly = depthStencilAttachment.Value.DepthReadOnly, + depthReadOnly = depthStencilAttachment.Value.DepthReadOnly ? 1u : 0u, stencilLoadOp = depthStencilAttachment.Value.StencilLoadOp, stencilStoreOp = depthStencilAttachment.Value.StencilStoreOp, stencilClearValue = depthStencilAttachment.Value.StencilClearValue, - stencilReadOnly = depthStencilAttachment.Value.StencilReadOnly + stencilReadOnly = depthStencilAttachment.Value.StencilReadOnly ? 1u : 0u }; } diff --git a/WGPU.NET/Wrappers/Device.cs b/WGPU.NET/Wrappers/Device.cs index a3f584a..24c5ae8 100644 --- a/WGPU.NET/Wrappers/Device.cs +++ b/WGPU.NET/Wrappers/Device.cs @@ -137,7 +137,7 @@ public Buffer CreateBuffer(string label, bool mappedAtCreation, ulong size, Buff var desc = new BufferDescriptor { label = label, - mappedAtCreation = mappedAtCreation, + mappedAtCreation = mappedAtCreation ? 1u : 0u, size = size, usage = (uint)usage }; @@ -218,8 +218,8 @@ public QuerySet CreateQuerySet(string label, QueryType queryType, uint count, Pi label = label, type = queryType, count = count, - pipelineStatistics = new IntPtr(pipelineStatisticsPtr), - pipelineStatisticsCount = (uint)pipelineStatistics.Length + /*pipelineStatistics = new IntPtr(pipelineStatisticsPtr), + pipelineStatisticsCount = (uint)pipelineStatistics.Length*/ }) ); } @@ -238,11 +238,11 @@ public RenderBundleEncoder CreateRenderBundleEncoder(string label, TextureFormat { label = label, colorFormats = new IntPtr(colorFormatsPtr), - colorFormatsCount = (uint)colorFormats.Length, + colorFormatCount = (uint)colorFormats.Length, depthStencilFormat = depthStencilFormat, sampleCount = sampleCount, - depthReadOnly = depthReadOnly, - stencilReadOnly = stencilReadOnly + depthReadOnly = depthReadOnly ? 1u : 0u, + stencilReadOnly = stencilReadOnly ? 1u : 0u }) ); } @@ -391,7 +391,7 @@ public ShaderModule CreateWgslShaderModule(string label, string wgslCode) ); } - public SwapChain CreateSwapChain(string label, Surface surface, TextureUsage usage, + /*public SwapChain CreateSwapChain(string label, Surface surface, TextureUsage usage, TextureFormat format, uint width, uint height, PresentMode presentMode) { return new SwapChain( @@ -413,7 +413,7 @@ public SwapChain CreateSwapChain(Surface surface, in SwapChainDescriptor descrip return new SwapChain( DeviceCreateSwapChain(Impl, surface.Impl, descriptor) ); - } + }*/ public Texture CreateTexture(string label, TextureUsage usage, TextureDimension dimension, Extent3D size, TextureFormat format, @@ -457,10 +457,12 @@ public bool GetLimits(out SupportedLimits limits) { limits = new SupportedLimits(); - return DeviceGetLimits(Impl, ref limits); + return DeviceGetLimits(Impl, ref limits) == 1u; } + + public Queue GetQueue() => Queue.For(DeviceGetQueue(Impl)); - public bool HasFeature(FeatureName feature) => DeviceHasFeature(Impl, feature); + public bool HasFeature(FeatureName feature) => DeviceHasFeature(Impl, feature) == 1u; public void PushErrorScope(ErrorFilter filter) => DevicePushErrorScope(Impl, filter); public void PopErrorScope(ErrorCallback callback) diff --git a/WGPU.NET/Wrappers/Instance.cs b/WGPU.NET/Wrappers/Instance.cs index 0201bae..510541a 100644 --- a/WGPU.NET/Wrappers/Instance.cs +++ b/WGPU.NET/Wrappers/Instance.cs @@ -18,8 +18,8 @@ public Surface CreateSurfaceFromAndroidNativeWindow(IntPtr window, string label { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromAndroidNativeWindow(window) - .GetPointer() + .AddSurfaceDescriptorFromAndroidNativeWindow(window) + .GetPointer() })); } @@ -29,8 +29,8 @@ public Surface CreateSurfaceFromCanvasHTMLSelector(string selector, string label { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromCanvasHTMLSelector(selector) - .GetPointer() + .AddSurfaceDescriptorFromCanvasHTMLSelector(selector) + .GetPointer() })); } @@ -40,8 +40,8 @@ public Surface CreateSurfaceFromMetalLayer(IntPtr layer, string label = default) { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromMetalLayer(layer) - .GetPointer() + .AddSurfaceDescriptorFromMetalLayer(layer) + .GetPointer() })); } @@ -51,8 +51,8 @@ public Surface CreateSurfaceFromWaylandSurface(IntPtr display, string label = de { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromWaylandSurface(display) - .GetPointer() + .AddSurfaceDescriptorFromWaylandSurface(display) + .GetPointer() })); } @@ -62,8 +62,8 @@ public Surface CreateSurfaceFromWindowsHWND(IntPtr hinstance, IntPtr hwnd, strin { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromWindowsHWND(hinstance, hwnd) - .GetPointer() + .AddSurfaceDescriptorFromWindowsHWND(hinstance, hwnd) + .GetPointer() })); } @@ -73,8 +73,8 @@ public Surface CreateSurfaceFromXcbWindow(IntPtr connection, uint window, string { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromXcbWindow(connection, window) - .GetPointer() + .AddSurfaceDescriptorFromXcbWindow(connection, window) + .GetPointer() })); } @@ -84,24 +84,53 @@ public Surface CreateSurfaceFromXlibWindow(IntPtr display, uint window, string l { label = label, nextInChain = new WgpuStructChain() - .AddSurfaceDescriptorFromXlibWindow(display, window) - .GetPointer() + .AddSurfaceDescriptorFromXlibWindow(display, window) + .GetPointer() })); } public void ProcessEvents() => InstanceProcessEvents(_impl); - public void RequestAdapter(Surface compatibleSurface, PowerPreference powerPreference, bool forceFallbackAdapter, RequestAdapterCallback callback, BackendType backendType) + public void RequestAdapter(Surface compatibleSurface, PowerPreference powerPreference, + bool forceFallbackAdapter, RequestAdapterCallback callback, BackendType? backendType = null) { InstanceRequestAdapter(_impl, new RequestAdapterOptions() { compatibleSurface = compatibleSurface.Impl, powerPreference = powerPreference, - forceFallbackAdapter = forceFallbackAdapter, - backendType = backendType - }, - (s,a,m,_) => callback(s, new Adapter(a), m), IntPtr.Zero); + forceFallbackAdapter = forceFallbackAdapter ? 1u : 0u, + nextInChain = backendType is null ? + IntPtr.Zero : + new WgpuStructChain().AddAdapterExtras(backendType.Value).GetPointer() + }, + (s, a, m, _) => callback(s, new Adapter(a), m), IntPtr.Zero); + } + + public ReadOnlySpan EnumerateAdapters(BackendType type) => EnumerateAdapters(type.ToInstanceBackend()); + + public ReadOnlySpan EnumerateAdapters(InstanceBackend type) + { + var options = new InstanceEnumerateAdapterOptions + { + nextInChain = IntPtr.Zero, + backends = (uint)type + }; + + ulong length; + unsafe { length = InstanceEnumerateAdapters(_impl, options, ref *(AdapterImpl*)null); } + + if(length == 0) + return ReadOnlySpan.Empty; + + var adapters = new AdapterImpl[length]; + InstanceEnumerateAdapters(_impl, options, ref adapters[0]); + + var ret = new Adapter[length]; + for (ulong i = 0; i < length; i++) + ret[i] = new Adapter(adapters[i]); + + return ret; } public void Dispose() @@ -112,4 +141,4 @@ public void Dispose() } public delegate void RequestAdapterCallback(RequestAdapterStatus status, Adapter adapter, string message); -} +} \ No newline at end of file diff --git a/WGPU.NET/Wrappers/Misc.cs b/WGPU.NET/Wrappers/Misc.cs index e7eb4d7..8520aba 100644 --- a/WGPU.NET/Wrappers/Misc.cs +++ b/WGPU.NET/Wrappers/Misc.cs @@ -223,7 +223,7 @@ public void Dispose() public delegate void CompilationInfoCallback(CompilationInfoRequestStatus status, ReadOnlySpan messages); - public class SwapChain : IDisposable + /*public class SwapChain : IDisposable { private SwapChainImpl _impl; @@ -246,7 +246,7 @@ public void Dispose() SwapChainRelease(_impl); _impl = default; } - } + }*/ public delegate void QueueWorkDoneCallback(QueueWorkDoneStatus status); diff --git a/WGPU.NET/Wrappers/Queue.cs b/WGPU.NET/Wrappers/Queue.cs index 0074a85..eb67ce4 100644 --- a/WGPU.NET/Wrappers/Queue.cs +++ b/WGPU.NET/Wrappers/Queue.cs @@ -9,6 +9,8 @@ namespace WGPU.NET { public class Queue : IDisposable { + private readonly static Dictionary instances = new Dictionary(); + private QueueImpl _impl; internal Queue(QueueImpl impl) @@ -18,6 +20,9 @@ internal Queue(QueueImpl impl) _impl = impl; } + + internal static Queue For(QueueImpl impl) + => impl.Handle == IntPtr.Zero ? null : instances.GetOrCreate(impl, () => new Queue(impl)); public void OnSubmittedWorkDone(QueueWorkDoneCallback callback) { diff --git a/WGPU.NET/Wrappers/Surface.cs b/WGPU.NET/Wrappers/Surface.cs index f7eaaba..ef401c5 100644 --- a/WGPU.NET/Wrappers/Surface.cs +++ b/WGPU.NET/Wrappers/Surface.cs @@ -15,9 +15,136 @@ internal Surface(SurfaceImpl impl) Impl = impl; } - public TextureFormat GetPreferredFormat(Adapter adapter) + public TextureFormat GetPreferredFormat(Adapter adapter) => SurfaceGetPreferredFormat(Impl, adapter.Impl); + + public SurfaceTexture GetCurrentTexture() + { + var txt = new Wgpu.SurfaceTexture(); + SurfaceGetCurrentTexture(Impl, ref txt); + + TextureDescriptor desc = new TextureDescriptor() + { + label = "", + nextInChain = IntPtr.Zero, + dimension = TextureGetDimension(txt.texture), + format = TextureGetFormat(txt.texture), + size = new Extent3D + { + height = TextureGetHeight(txt.texture), width = TextureGetWidth(txt.texture), + depthOrArrayLayers = TextureGetDepthOrArrayLayers(txt.texture) + }, + usage = TextureGetUsage(txt.texture), + sampleCount = TextureGetSampleCount(txt.texture), + mipLevelCount = TextureGetMipLevelCount(txt.texture), + viewFormats = IntPtr.Zero, + viewFormatCount = 0 + }; + + SurfaceTexture texture = new SurfaceTexture + { + texture = new Texture(txt.texture, desc), + status = txt.status, + suboptimal = txt.suboptimal + }; + + return texture; + } + + public TextureView GetCurrentTextureView() => GetCurrentTexture().texture.CreateTextureView(); + + public void Configure(Device device, SurfaceConfiguration config) + { + var surfaceConfiguration = new Wgpu.SurfaceConfiguration + { + device = device.Impl, + presentMode = config.presentMode, + viewFormatCount = config.viewFormats is { } ? (ulong)config.viewFormats.LongLength : 0, + nextInChain = config.nextInChain, + format = config.format, + height = config.height, + width = config.width, + usage = (uint)config.usage, + alphaMode = config.alphaMode + }; + + if (config.viewFormats is { }) + unsafe + { + fixed (TextureFormat* tf = &config.viewFormats[0]) + surfaceConfiguration.viewFormats = new IntPtr(tf); + } + + SurfaceConfigure(Impl, surfaceConfiguration); + } + + public void Unconfigure() => SurfaceUnconfigure(Impl); + + public void Present() => SurfacePresent(Impl); + + public SurfaceCapabilities GetCapabilities(Adapter adapter) + { + Wgpu.SurfaceCapabilities capabilities = new Wgpu.SurfaceCapabilities(); + SurfaceGetCapabilities(Impl, adapter.Impl, ref capabilities); + + SurfaceCapabilities caps = new SurfaceCapabilities + { + nextInChain = capabilities.nextInChain, + formats = new TextureFormat[capabilities.formatCount], + presentModes = new PresentMode[capabilities.presentModeCount], + alphaModes = new CompositeAlphaMode[capabilities.alphaModeCount] + }; + + TextureFormat[] formatsTemp; + PresentMode[] presentModesTemp; + CompositeAlphaMode[] alphaModesTemp; + + unsafe + { + formatsTemp = new ReadOnlySpan(capabilities.formats.ToPointer(), + (int)capabilities.formatCount).ToArray(); + + presentModesTemp = new ReadOnlySpan(capabilities.presentModes.ToPointer(), + (int)capabilities.presentModeCount).ToArray(); + + alphaModesTemp = new ReadOnlySpan(capabilities.alphaModes.ToPointer(), + (int)capabilities.alphaModeCount).ToArray(); + } + + Array.Copy(formatsTemp, caps.formats, caps.formats.Length); + Array.Copy(presentModesTemp, caps.presentModes, caps.presentModes.Length); + Array.Copy(alphaModesTemp, caps.alphaModes, caps.alphaModes.Length); + + return caps; + } + + public void FreeCapabilities(ref SurfaceCapabilities caps) { - return SurfaceGetPreferredFormat(Impl, adapter.Impl); + Wgpu.SurfaceCapabilities capabilities = new Wgpu.SurfaceCapabilities + { + nextInChain = caps.nextInChain, + formatCount = (ulong)caps.formats.LongLength, + presentModeCount = (ulong)caps.presentModes.LongLength, + alphaModeCount = (ulong)caps.alphaModes.LongLength + }; + + unsafe + { + fixed (TextureFormat* tf = &caps.formats[0]) + fixed (PresentMode* pm = &caps.presentModes[0]) + fixed (CompositeAlphaMode* am = &caps.alphaModes[0]) + { + capabilities.formats = new IntPtr(tf); + capabilities.presentModes = new IntPtr(pm); + capabilities.alphaModes = new IntPtr(am); + + SurfaceCapabilitiesFreeMembers(capabilities); + } + } + + caps.formats = null; + caps.presentModes = null; + caps.alphaModes = null; + caps.nextInChain = IntPtr.Zero; } public void Dispose() @@ -26,4 +153,4 @@ public void Dispose() Impl = default; } } -} +} \ No newline at end of file diff --git a/WGPU.NET/Wrappers/SurfaceCapabilities.cs b/WGPU.NET/Wrappers/SurfaceCapabilities.cs new file mode 100644 index 0000000..98704a9 --- /dev/null +++ b/WGPU.NET/Wrappers/SurfaceCapabilities.cs @@ -0,0 +1,15 @@ +using System; + +namespace WGPU.NET +{ + public struct SurfaceCapabilities + { + public IntPtr nextInChain; + + public Wgpu.TextureFormat[] formats; + + public Wgpu.PresentMode[] presentModes; + + public Wgpu.CompositeAlphaMode[] alphaModes; + } +} \ No newline at end of file diff --git a/WGPU.NET/Wrappers/SurfaceConfiguration.cs b/WGPU.NET/Wrappers/SurfaceConfiguration.cs new file mode 100644 index 0000000..c129588 --- /dev/null +++ b/WGPU.NET/Wrappers/SurfaceConfiguration.cs @@ -0,0 +1,23 @@ +using System; + +namespace WGPU.NET +{ + public struct SurfaceConfiguration + { + public IntPtr nextInChain; + + public Wgpu.TextureFormat format; + + public Wgpu.TextureUsage usage; + + public Wgpu.TextureFormat[] viewFormats; + + public Wgpu.CompositeAlphaMode alphaMode; + + public uint width; + + public uint height; + + public Wgpu.PresentMode presentMode; + } +} \ No newline at end of file diff --git a/WGPU.NET/Wrappers/SurfaceTexture.cs b/WGPU.NET/Wrappers/SurfaceTexture.cs new file mode 100644 index 0000000..c4f379e --- /dev/null +++ b/WGPU.NET/Wrappers/SurfaceTexture.cs @@ -0,0 +1,10 @@ +namespace WGPU.NET +{ + public class SurfaceTexture + { + public Texture texture; + public uint suboptimal; + + public Wgpu.SurfaceGetCurrentTextureStatus status; + } +} \ No newline at end of file diff --git a/WGPU.NET/Wrappers/TextureView.cs b/WGPU.NET/Wrappers/TextureView.cs index 7c94b20..d04ec29 100644 --- a/WGPU.NET/Wrappers/TextureView.cs +++ b/WGPU.NET/Wrappers/TextureView.cs @@ -1,17 +1,18 @@ using System; using System.Collections.Generic; + using static WGPU.NET.Wgpu; namespace WGPU.NET { public class TextureView : IDisposable { - private static Dictionary instances = + private static Dictionary instances = new Dictionary(); private TextureViewImpl _impl; - internal TextureViewImpl Impl + internal TextureViewImpl Impl { get { @@ -23,21 +24,22 @@ internal TextureViewImpl Impl set => _impl = value; } - + /// /// The Texture this TextureView belongs to. If this TextureView belongs to the SwapChain, then this is null. /// - public Texture Texture - { - get; - } + public Texture Texture { get; } + + public static TextureView FromHandle(IntPtr ptr) => new TextureView(new TextureViewImpl(ptr), null); + + public IntPtr GetTextureViewHandle() => new IntPtr(_impl.Handle.ToInt64()); private TextureView(TextureViewImpl impl, Texture texture) { if (impl.Handle == IntPtr.Zero) throw new ResourceCreationError(nameof(TextureView)); - Impl = impl; + Impl = impl; Texture = texture; } @@ -52,14 +54,12 @@ internal static TextureView Create(TextureViewImpl impl, Texture texture) return view; } - internal static TextureView CreateUntracked(TextureViewImpl impl) - => new TextureView(impl, null); + internal static TextureView CreateUntracked(TextureViewImpl impl) => new TextureView(impl, null); - internal static TextureView For(TextureViewImpl impl) - => impl.Handle == IntPtr.Zero ? null : instances[impl]; + internal static TextureView For(TextureViewImpl impl) => impl.Handle == IntPtr.Zero ? null : instances[impl]; internal static void Forget(TextureViewImpl impl) => instances.Remove(impl); - + /// /// This function will be called automatically when this TextureView's associated Texture is disposed. /// If you dispose the TextureView yourself, diff --git a/WGPU.Tests/Test.cs b/WGPU.Tests/Test.cs index 2f072cd..5e65457 100644 --- a/WGPU.Tests/Test.cs +++ b/WGPU.Tests/Test.cs @@ -1,580 +1,587 @@ using Silk.NET.GLFW; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using System; using System.Diagnostics; using System.IO; using System.Numerics; using System.Runtime.InteropServices; -using System.Threading; using WGPU.NET; using Image = SixLabors.ImageSharp.Image; namespace WGPU.Tests { + public static class Test + { + private const bool SelectAdapterByEnumeration = false; + + struct Vertex + { + public Vector3 Position; + public Vector4 Color; + public Vector2 UV; + + public Vertex(Vector3 position, Vector4 color, Vector2 uv) + { + Position = position; + Color = color; + UV = uv; + } + } + + struct UniformBuffer + { + public Matrix4x4 Transform; + } + + public static void ErrorCallback(Wgpu.ErrorType type, string message) + { + var _message = message.Replace("\\r\\n", "\n"); + + Console.WriteLine($"{type}: {_message}"); + + Debugger.Break(); + } + + public static unsafe void Main(string[] args) + { + Glfw glfw = GlfwProvider.GLFW.Value; + + if (!glfw.Init()) + { + Console.WriteLine("GLFW failed to initialize"); + Console.ReadKey(); + return; + } + + glfw.WindowHint(WindowHintClientApi.ClientApi, ClientApi.NoApi); + WindowHandle* window = glfw.CreateWindow(800, 600, "Hello WGPU.NET", null, null); + + if (window == null) + { + Console.WriteLine("Failed to open window"); + glfw.Terminate(); + Console.ReadKey(); + return; + } + + var instance = new Instance(); + + Surface surface; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var nativeWindow = new GlfwNativeWindow(glfw, window).Win32.Value; + surface = instance.CreateSurfaceFromWindowsHWND(nativeWindow.HInstance, nativeWindow.Hwnd); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + var nativeWindow = new GlfwNativeWindow(glfw, window).X11.Value; + surface = instance.CreateSurfaceFromXlibWindow(nativeWindow.Display, (uint)nativeWindow.Window); + } + else + { + var nativeWindow = new GlfwNativeWindow(glfw, window).Cocoa.Value; + surface = instance.CreateSurfaceFromMetalLayer(nativeWindow); + } + + Adapter adapter = default; + + if (!SelectAdapterByEnumeration) + { + instance.RequestAdapter(surface, default, default, (s, a, m) => adapter = a, Wgpu.BackendType.Vulkan); + + adapter.GetProperties(out Wgpu.AdapterProperties properties); + + Console.WriteLine($"Adapter Name: {properties.name}"); + Console.WriteLine($"Adapter Vendor: {properties.vendorName}"); + Console.WriteLine($"Adapter Driver: {properties.driverDescription}"); + Console.WriteLine($"Adapter Backend: {properties.backendType}"); + Console.WriteLine($"Adapter Architecture: {properties.architecture}"); + + Console.WriteLine("Adapter Features: " + string.Join(", ", adapter.EnumerateFeatures())); + } + else + { + Console.WriteLine("\nEnumerating all adapters that support Vulkan:"); + ReadOnlySpan adapters = instance.EnumerateAdapters(Wgpu.InstanceBackend.Primary); + foreach (var t in adapters) + { + t.GetProperties(out var p); - public static class Test - { - struct Vertex - { - public Vector3 Position; - public Vector4 Color; - public Vector2 UV; + Console.WriteLine($"\nAdapter Name: {p.name}"); + Console.WriteLine($"Adapter Vendor: {p.vendorName}"); + Console.WriteLine($"Adapter Driver: {p.driverDescription}"); + Console.WriteLine($"Adapter Backend: {p.backendType}"); + Console.WriteLine($"Adapter Architecture: {p.architecture}"); - public Vertex(Vector3 position, Vector4 color, Vector2 uv) - { - Position = position; - Color = color; - UV = uv; - } - } + Console.WriteLine("Adapter Features: " + string.Join(", ", t.EnumerateFeatures())); + } - struct UniformBuffer - { - public Matrix4x4 Transform; - } + if (adapters.Length > 0) + { + adapter = adapters[0]; + } + else + { + Console.WriteLine("Didn't find adapter for the specified backend!"); + Environment.Exit(-1); + } + } - public static void ErrorCallback(Wgpu.ErrorType type, string message) - { - var _message = message.Replace("\\r\\n", "\n"); + adapter.GetLimits(out var supportedLimits); - Console.WriteLine($"{type}: {_message}"); + Device device = default; - Debugger.Break(); - } + adapter.RequestDevice((s, d, m) => device = d, + limits: supportedLimits.limits, + label: "Device", + nativeFeatures: Array.Empty() + ); - public static unsafe void Main(string[] args) - { - Glfw glfw = GlfwProvider.GLFW.Value; + device.SetUncapturedErrorCallback(ErrorCallback); - if (!glfw.Init()) - { - Console.WriteLine("GLFW failed to initialize"); - Console.ReadKey(); - return; - } + Span vertices = new Vertex[] + { + new Vertex(new(-1, -1, 0), new(1, 1, 0, 1), new(-.2f, 1.0f)), + new Vertex(new(1, -1, 0), new(0, 1, 1, 1), new(1.2f, 1.0f)), + new Vertex(new(0, 1, 0), new(1, 0, 1, 1), new(0.5f, -.5f)), + }; - glfw.WindowHint(WindowHintClientApi.ClientApi, ClientApi.NoApi); - WindowHandle* window = glfw.CreateWindow(800, 600, "Hello WGPU.NET", null, null); + var vertexBuffer = device.CreateBuffer("VertexBuffer", true, (ulong)(vertices.Length * sizeof(Vertex)), + Wgpu.BufferUsage.Vertex); - if (window == null) - { - Console.WriteLine("Failed to open window"); - glfw.Terminate(); - Console.ReadKey(); - return; - } + { + Span mapped = vertexBuffer.GetMappedRange(0, vertices.Length); - var instance = new Instance(); + vertices.CopyTo(mapped); - Surface surface; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - var nativeWindow = new GlfwNativeWindow(glfw, window).Win32.Value; - surface = instance.CreateSurfaceFromWindowsHWND(nativeWindow.HInstance, nativeWindow.Hwnd); + vertexBuffer.Unmap(); + } - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - var nativeWindow = new GlfwNativeWindow(glfw, window).X11.Value; - surface = instance.CreateSurfaceFromXlibWindow(nativeWindow.Display, (uint)nativeWindow.Window); - } - else - { - var nativeWindow = new GlfwNativeWindow(glfw, window).Cocoa.Value; - surface = instance.CreateSurfaceFromMetalLayer(nativeWindow); - } + UniformBuffer uniformBufferData = new UniformBuffer + { + Transform = Matrix4x4.Identity + }; + var uniformBuffer = device.CreateBuffer("UniformBuffer", false, (ulong)sizeof(UniformBuffer), + Wgpu.BufferUsage.Uniform | Wgpu.BufferUsage.CopyDst); - Adapter adapter = default; + var image = Image.Load(Path.Combine("Resources", "WGPU-Logo.png")); - instance.RequestAdapter(surface, default, default, (s, a, m) => adapter = a, Wgpu.BackendType.Vulkan); + var imageSize = new Wgpu.Extent3D + { + width = (uint)image.Width, + height = (uint)image.Height, + depthOrArrayLayers = 1 + }; - adapter.GetProperties(out Wgpu.AdapterProperties properties); + var imageTexture = device.CreateTexture("Image", + usage: Wgpu.TextureUsage.TextureBinding | Wgpu.TextureUsage.CopyDst, + dimension: Wgpu.TextureDimension.TwoDimensions, + size: imageSize, + format: Wgpu.TextureFormat.RGBA8Unorm, + mipLevelCount: 1, + sampleCount: 1 + ); - adapter.GetLimits(out var supportedLimits); + { + Span pixels = new Rgba32[image.Width * image.Height]; - Device device = default; + image.CopyPixelDataTo(pixels); - adapter.RequestDevice((s, d, m) => device = d, - limits: supportedLimits.limits, - label: "Device", - nativeFeatures: Array.Empty() + device.Queue.WriteTexture( + destination: new ImageCopyTexture + { + Aspect = Wgpu.TextureAspect.All, + MipLevel = 0, + Origin = default, + Texture = imageTexture + }, + data: pixels, + dataLayout: new Wgpu.TextureDataLayout + { + bytesPerRow = (uint)(sizeof(Rgba32) * image.Width), + offset = 0, + rowsPerImage = (uint)image.Height + }, + writeSize: imageSize + ); + } + + var imageSampler = device.CreateSampler("ImageSampler", + addressModeU: Wgpu.AddressMode.ClampToEdge, + addressModeV: Wgpu.AddressMode.ClampToEdge, + addressModeW: default, + magFilter: Wgpu.FilterMode.Linear, + minFilter: Wgpu.FilterMode.Linear, + mipmapFilter: Wgpu.MipmapFilterMode.Linear, + lodMinClamp: 0, + lodMaxClamp: 1, + compare: default, + maxAnisotropy: 1 ); + var bindGroupLayout = device.CreateBindgroupLayout(null, new Wgpu.BindGroupLayoutEntry[] + { + new Wgpu.BindGroupLayoutEntry + { + binding = 0, + buffer = new Wgpu.BufferBindingLayout + { + type = Wgpu.BufferBindingType.Uniform, + minBindingSize = (ulong)sizeof(UniformBuffer) + }, + visibility = (uint)Wgpu.ShaderStage.Vertex + }, + new Wgpu.BindGroupLayoutEntry + { + binding = 1, + sampler = new Wgpu.SamplerBindingLayout + { + type = Wgpu.SamplerBindingType.Filtering, + }, + visibility = (uint)Wgpu.ShaderStage.Fragment + }, + new Wgpu.BindGroupLayoutEntry + { + binding = 2, + texture = new Wgpu.TextureBindingLayout + { + viewDimension = Wgpu.TextureViewDimension.TwoDimensions, + sampleType = Wgpu.TextureSampleType.Float, + }, + visibility = (uint)Wgpu.ShaderStage.Fragment + } + }); + + var bindGroup = device.CreateBindGroup(null, bindGroupLayout, new BindGroupEntry[] + { + new BindGroupEntry + { + Binding = 0, + Buffer = uniformBuffer, + Offset = 0, + Size = (ulong)sizeof(UniformBuffer) + }, + new BindGroupEntry + { + Binding = 1, + Sampler = imageSampler + }, + new BindGroupEntry + { + Binding = 2, + TextureView = imageTexture.CreateTextureView() + } + }); - device.SetUncapturedErrorCallback(ErrorCallback); + var shader = device.CreateWgslShaderModule( + label: "shader.wgsl", + wgslCode: File.ReadAllText("shader.wgsl") + ); - Span vertices = new Vertex[] - { - new Vertex(new ( -1,-1,0), new (1,1,0,1), new (-.2f,1.0f)), - new Vertex(new ( 1,-1,0), new (0,1,1,1), new (1.2f,1.0f)), - new Vertex(new ( 0, 1,0), new (1,0,1,1), new (0.5f,-.5f)), - }; - - - var vertexBuffer = device.CreateBuffer("VertexBuffer", true, (ulong)(vertices.Length * sizeof(Vertex)), Wgpu.BufferUsage.Vertex); - - { - Span mapped = vertexBuffer.GetMappedRange(0, vertices.Length); - - vertices.CopyTo(mapped); - - vertexBuffer.Unmap(); - } - - - UniformBuffer uniformBufferData = new UniformBuffer - { - Transform = Matrix4x4.Identity - }; - - var uniformBuffer = device.CreateBuffer("UniformBuffer", false, (ulong)sizeof(UniformBuffer), Wgpu.BufferUsage.Uniform | Wgpu.BufferUsage.CopyDst); - - - - var image = Image.Load(Path.Combine("Resources", "WGPU-Logo.png")); - - var imageSize = new Wgpu.Extent3D - { - width = (uint)image.Width, - height = (uint)image.Height, - depthOrArrayLayers = 1 - }; - - var imageTexture = device.CreateTexture("Image", - usage: Wgpu.TextureUsage.TextureBinding | Wgpu.TextureUsage.CopyDst, - dimension: Wgpu.TextureDimension.TwoDimensions, - size: imageSize, - format: Wgpu.TextureFormat.RGBA8Unorm, - mipLevelCount: 1, - sampleCount: 1 - ); - - { - Span pixels = new Rgba32[image.Width * image.Height]; - - image.CopyPixelDataTo(pixels); - - device.Queue.WriteTexture( - destination: new ImageCopyTexture - { - Aspect = Wgpu.TextureAspect.All, - MipLevel = 0, - Origin = default, - Texture = imageTexture - }, - data: pixels, - dataLayout: new Wgpu.TextureDataLayout - { - bytesPerRow = (uint)(sizeof(Rgba32) * image.Width), - offset = 0, - rowsPerImage = (uint)image.Height - }, - writeSize: imageSize - ); - } - - var imageSampler = device.CreateSampler("ImageSampler", - addressModeU: Wgpu.AddressMode.ClampToEdge, - addressModeV: Wgpu.AddressMode.ClampToEdge, - addressModeW: default, - - magFilter: Wgpu.FilterMode.Linear, - minFilter: Wgpu.FilterMode.Linear, - mipmapFilter: Wgpu.MipmapFilterMode.Linear, - - lodMinClamp: 0, - lodMaxClamp: 1, - compare: default, - - maxAnisotropy: 1 - ); - - - - var bindGroupLayout = device.CreateBindgroupLayout(null, new Wgpu.BindGroupLayoutEntry[] { - new Wgpu.BindGroupLayoutEntry - { - binding = 0, - buffer = new Wgpu.BufferBindingLayout - { - type = Wgpu.BufferBindingType.Uniform, - minBindingSize = (ulong)sizeof(UniformBuffer) - }, - visibility = (uint)Wgpu.ShaderStage.Vertex - }, - new Wgpu.BindGroupLayoutEntry - { - binding = 1, - sampler = new Wgpu.SamplerBindingLayout - { - type = Wgpu.SamplerBindingType.Filtering, - }, - visibility = (uint)Wgpu.ShaderStage.Fragment - }, - new Wgpu.BindGroupLayoutEntry - { - binding = 2, - texture = new Wgpu.TextureBindingLayout - { - viewDimension = Wgpu.TextureViewDimension.TwoDimensions, - sampleType = Wgpu.TextureSampleType.Float, - - }, - visibility = (uint)Wgpu.ShaderStage.Fragment - } - }); - - var bindGroup = device.CreateBindGroup(null, bindGroupLayout, new BindGroupEntry[] - { - new BindGroupEntry - { - Binding = 0, - Buffer = uniformBuffer, - Offset = 0, - Size = (ulong)sizeof(UniformBuffer) - }, - new BindGroupEntry - { - Binding = 1, - Sampler = imageSampler - }, - new BindGroupEntry - { - Binding = 2, - TextureView = imageTexture.CreateTextureView() - } - }); - - - - var shader = device.CreateWgslShaderModule( - label: "shader.wgsl", - wgslCode: File.ReadAllText("shader.wgsl") - ); - - var pipelineLayout = device.CreatePipelineLayout( - label: null, - new BindGroupLayout[] - { - bindGroupLayout - } - ); - - - - var vertexState = new VertexState() - { - Module = shader, - EntryPoint = "vs_main", - bufferLayouts = new VertexBufferLayout[] - { - new VertexBufferLayout - { - ArrayStride = (ulong)sizeof(Vertex), - Attributes = new Wgpu.VertexAttribute[] - { - //position - new Wgpu.VertexAttribute - { - format = Wgpu.VertexFormat.Float32x3, - offset = 0, - shaderLocation = 0 - }, - //color - new Wgpu.VertexAttribute - { - format = Wgpu.VertexFormat.Float32x4, - offset = (ulong)sizeof(Vector3), //right after positon - shaderLocation = 1 - }, - //uv - new Wgpu.VertexAttribute - { - format = Wgpu.VertexFormat.Float32x2, - offset = (ulong)(sizeof(Vector3)+sizeof(Vector4)), //right after color - shaderLocation = 2 - } - } - } - } - }; - - var swapChainFormat = surface.GetPreferredFormat(adapter); - - var colorTargets = new ColorTargetState[] - { - new ColorTargetState() - { - Format = swapChainFormat, - BlendState = new Wgpu.BlendState() - { - color = new Wgpu.BlendComponent() - { - srcFactor = Wgpu.BlendFactor.One, - dstFactor = Wgpu.BlendFactor.Zero, - operation = Wgpu.BlendOperation.Add - }, - alpha = new Wgpu.BlendComponent() - { - srcFactor = Wgpu.BlendFactor.One, - dstFactor = Wgpu.BlendFactor.Zero, - operation = Wgpu.BlendOperation.Add - } - }, - WriteMask = (uint)Wgpu.ColorWriteMask.All - } - }; - - var fragmentState = new FragmentState() - { - Module = shader, - EntryPoint = "fs_main", - colorTargets = colorTargets - }; - - var renderPipeline = device.CreateRenderPipeline( - label: "Render pipeline", - layout: pipelineLayout, - vertexState: vertexState, - primitiveState: new Wgpu.PrimitiveState() - { - topology = Wgpu.PrimitiveTopology.TriangleList, - stripIndexFormat = Wgpu.IndexFormat.Undefined, - frontFace = Wgpu.FrontFace.CCW, - cullMode = Wgpu.CullMode.None - }, - multisampleState: new Wgpu.MultisampleState() - { - count = 1, - mask = uint.MaxValue, - alphaToCoverageEnabled = false - }, - depthStencilState: new Wgpu.DepthStencilState() - { - format = Wgpu.TextureFormat.Depth32Float, - depthCompare = Wgpu.CompareFunction.Always, - stencilBack = new Wgpu.StencilFaceState - { - depthFailOp = Wgpu.StencilOperation.Keep, - failOp = Wgpu.StencilOperation.Keep, - passOp = Wgpu.StencilOperation.Keep, - compare = Wgpu.CompareFunction.Always - }, - stencilFront = new Wgpu.StencilFaceState - { - depthFailOp = Wgpu.StencilOperation.Keep, - failOp = Wgpu.StencilOperation.Keep, - passOp = Wgpu.StencilOperation.Keep, - compare = Wgpu.CompareFunction.Always - } - - }, - fragmentState: fragmentState - ); - - - - - - glfw.GetWindowSize(window, out int prevWidth, out int prevHeight); - - var swapChainDescriptor = new Wgpu.SwapChainDescriptor - { - usage = (uint)Wgpu.TextureUsage.RenderAttachment, - format = swapChainFormat, - width = (uint)prevWidth, - height = (uint)prevHeight, - presentMode = Wgpu.PresentMode.Fifo - }; - - var swapChain = device.CreateSwapChain(surface, swapChainDescriptor); - - var depthTextureDescriptor = new Wgpu.TextureDescriptor - { - label = "Depth Buffer", - usage = (uint)Wgpu.TextureUsage.RenderAttachment, - dimension = Wgpu.TextureDimension.TwoDimensions, - size = new Wgpu.Extent3D + var pipelineLayout = device.CreatePipelineLayout( + label: null, + new BindGroupLayout[] { - width = (uint)prevWidth, - height = (uint)prevHeight, - depthOrArrayLayers = 1 - }, - format = Wgpu.TextureFormat.Depth32Float, - mipLevelCount = 1, - sampleCount = 1 - }; + bindGroupLayout + } + ); - var depthTexture = device.CreateTexture(in depthTextureDescriptor); - var depthTextureView = depthTexture.CreateTextureView(); + var vertexState = new VertexState() + { + Module = shader, + EntryPoint = "vs_main", + bufferLayouts = new VertexBufferLayout[] + { + new VertexBufferLayout + { + ArrayStride = (ulong)sizeof(Vertex), + Attributes = new Wgpu.VertexAttribute[] + { + //position + new Wgpu.VertexAttribute + { + format = Wgpu.VertexFormat.Float32x3, + offset = 0, + shaderLocation = 0 + }, + //color + new Wgpu.VertexAttribute + { + format = Wgpu.VertexFormat.Float32x4, + offset = (ulong)sizeof(Vector3), //right after positon + shaderLocation = 1 + }, + //uv + new Wgpu.VertexAttribute + { + format = Wgpu.VertexFormat.Float32x2, + offset = (ulong)(sizeof(Vector3) + sizeof(Vector4)), //right after color + shaderLocation = 2 + } + } + } + } + }; + + var swapChainFormat = surface.GetPreferredFormat(adapter); - Span uniformBufferSpan = stackalloc UniformBuffer[1]; + var colorTargets = new ColorTargetState[] + { + new ColorTargetState() + { + Format = swapChainFormat, + BlendState = new Wgpu.BlendState() + { + color = new Wgpu.BlendComponent() + { + srcFactor = Wgpu.BlendFactor.One, + dstFactor = Wgpu.BlendFactor.Zero, + operation = Wgpu.BlendOperation.Add + }, + alpha = new Wgpu.BlendComponent() + { + srcFactor = Wgpu.BlendFactor.One, + dstFactor = Wgpu.BlendFactor.Zero, + operation = Wgpu.BlendOperation.Add + } + }, + WriteMask = (uint)Wgpu.ColorWriteMask.All + } + }; - var startTime = DateTime.Now; + var fragmentState = new FragmentState() + { + Module = shader, + EntryPoint = "fs_main", + colorTargets = colorTargets + }; - var lastFrameTime = startTime; + var renderPipeline = device.CreateRenderPipeline( + label: "Render pipeline", + layout: pipelineLayout, + vertexState: vertexState, + primitiveState: new Wgpu.PrimitiveState() + { + topology = Wgpu.PrimitiveTopology.TriangleList, + stripIndexFormat = Wgpu.IndexFormat.Undefined, + frontFace = Wgpu.FrontFace.CCW, + cullMode = Wgpu.CullMode.None + }, + multisampleState: new Wgpu.MultisampleState() + { + count = 1, + mask = uint.MaxValue, + alphaToCoverageEnabled = 0 + }, + depthStencilState: new Wgpu.DepthStencilState() + { + format = Wgpu.TextureFormat.Depth32Float, + depthCompare = Wgpu.CompareFunction.Always, + stencilBack = new Wgpu.StencilFaceState + { + depthFailOp = Wgpu.StencilOperation.Keep, + failOp = Wgpu.StencilOperation.Keep, + passOp = Wgpu.StencilOperation.Keep, + compare = Wgpu.CompareFunction.Always + }, + stencilFront = new Wgpu.StencilFaceState + { + depthFailOp = Wgpu.StencilOperation.Keep, + failOp = Wgpu.StencilOperation.Keep, + passOp = Wgpu.StencilOperation.Keep, + compare = Wgpu.CompareFunction.Always + } + }, + fragmentState: fragmentState + ); - while (!glfw.WindowShouldClose(window)) - { - glfw.GetCursorPos(window, out double mouseX, out double mouseY); - glfw.GetWindowSize(window, out int width, out int height); + glfw.GetWindowSize(window, out int prevWidth, out int prevHeight); - if ((width != prevWidth || height != prevHeight) && width != 0 && height != 0) - { - prevWidth = width; - prevHeight = height; - swapChainDescriptor.width = (uint)width; - swapChainDescriptor.height = (uint)height; + var surfaceConfiguration = new SurfaceConfiguration + { + usage = Wgpu.TextureUsage.RenderAttachment, + format = swapChainFormat, + width = (uint)prevWidth, + height = (uint)prevHeight, + presentMode = Wgpu.PresentMode.Fifo + }; - depthTextureDescriptor.size.width = (uint)width; - depthTextureDescriptor.size.height = (uint)height; + surface.Configure(device, surfaceConfiguration); - swapChain = device.CreateSwapChain(surface, swapChainDescriptor); + var depthTextureDescriptor = new Wgpu.TextureDescriptor + { + label = "Depth Buffer", + usage = (uint)Wgpu.TextureUsage.RenderAttachment, + dimension = Wgpu.TextureDimension.TwoDimensions, + size = new Wgpu.Extent3D + { + width = (uint)prevWidth, + height = (uint)prevHeight, + depthOrArrayLayers = 1 + }, + format = Wgpu.TextureFormat.Depth32Float, + mipLevelCount = 1, + sampleCount = 1 + }; - depthTexture.Dispose(); - depthTexture = device.CreateTexture(depthTextureDescriptor); - depthTextureView = depthTexture.CreateTextureView(); - } + var depthTexture = device.CreateTexture(in depthTextureDescriptor); + var depthTextureView = depthTexture.CreateTextureView(); + Span uniformBufferSpan = stackalloc UniformBuffer[1]; - var currentTime = DateTime.Now; + var startTime = DateTime.Now; - TimeSpan duration = currentTime - startTime; + var lastFrameTime = startTime; + while (!glfw.WindowShouldClose(window)) + { + glfw.GetCursorPos(window, out double mouseX, out double mouseY); + glfw.GetWindowSize(window, out int width, out int height); - + if ((width != prevWidth || height != prevHeight) && width != 0 && height != 0) + { + prevWidth = width; + prevHeight = height; + surfaceConfiguration.width = (uint)width; + surfaceConfiguration.height = (uint)height; - - Vector2 nrmMouseCoords = new Vector2( - (float)(mouseX * 1 - prevWidth * 0.5f) / prevWidth, - (float)(mouseY * 1 - prevHeight * 0.5f) / prevHeight - ); + depthTextureDescriptor.size.width = (uint)width; + depthTextureDescriptor.size.height = (uint)height; + surface.Configure(device, surfaceConfiguration); - uniformBufferData.Transform = - Matrix4x4.CreateRotationY( - MathF.Sign(nrmMouseCoords.X) * (MathF.Log(Math.Abs(nrmMouseCoords.X) + 1)) * 0.9f - ) * - Matrix4x4.CreateRotationX( - MathF.Sign(nrmMouseCoords.Y) * (MathF.Log(Math.Abs(nrmMouseCoords.Y) + 1)) * 0.9f - ) * - Matrix4x4.CreateScale( - (float)(1 + 0.1 * Math.Sin(duration.TotalSeconds * 2.0)) - ) * - Matrix4x4.CreateTranslation(0, 0, -3) - ; + depthTexture.Dispose(); + depthTexture = device.CreateTexture(depthTextureDescriptor); + depthTextureView = depthTexture.CreateTextureView(); + } - uniformBufferData.Transform *= CreatePerspective(MathF.PI/4f, (float)prevWidth/prevHeight, 0.01f, 1000); + var currentTime = DateTime.Now; - + TimeSpan duration = currentTime - startTime; - var nextTexture = swapChain.GetCurrentTextureView(); + Vector2 nrmMouseCoords = new Vector2( + (float)(mouseX * 1 - prevWidth * 0.5f) / prevWidth, + (float)(mouseY * 1 - prevHeight * 0.5f) / prevHeight + ); - if (nextTexture == null) - { - Console.WriteLine("Could not acquire next swap chain texture"); - return; - } + uniformBufferData.Transform = + Matrix4x4.CreateRotationY( + MathF.Sign(nrmMouseCoords.X) * (MathF.Log(Math.Abs(nrmMouseCoords.X) + 1)) * 0.9f + ) * + Matrix4x4.CreateRotationX( + MathF.Sign(nrmMouseCoords.Y) * (MathF.Log(Math.Abs(nrmMouseCoords.Y) + 1)) * 0.9f + ) * + Matrix4x4.CreateScale( + (float)(1 + 0.1 * Math.Sin(duration.TotalSeconds * 2.0)) + ) * + Matrix4x4.CreateTranslation(0, 0, -3) + ; - var encoder = device.CreateCommandEncoder("Command Encoder"); + uniformBufferData.Transform *= + CreatePerspective(MathF.PI / 4f, (float)prevWidth / prevHeight, 0.01f, 1000); - var renderPass = encoder.BeginRenderPass( - label: null, - colorAttachments: new RenderPassColorAttachment[] - { - new RenderPassColorAttachment() - { - view = nextTexture, - resolveTarget = default, - loadOp = Wgpu.LoadOp.Clear, - storeOp = Wgpu.StoreOp.Store, - clearValue = new Wgpu.Color() { r = 0, g = 0.02f, b = 0.1f, a = 1 } - } - }, - depthStencilAttachment: new RenderPassDepthStencilAttachment - { - View = depthTextureView, - DepthLoadOp = Wgpu.LoadOp.Clear, - DepthStoreOp = Wgpu.StoreOp.Store, - DepthClearValue = 0f, - StencilLoadOp = Wgpu.LoadOp.Clear, - StencilStoreOp = Wgpu.StoreOp.Discard - } - ); + var nextTexture = surface.GetCurrentTextureView(); - renderPass.SetPipeline(renderPipeline); + if (nextTexture == null) + { + Console.WriteLine("Could not acquire next swap chain texture"); + return; + } - renderPass.SetBindGroup(0, bindGroup, Array.Empty()); - renderPass.SetVertexBuffer(0, vertexBuffer, 0, (ulong)(vertices.Length * sizeof(Vertex))); - renderPass.Draw(3, 1, 0, 0); - renderPass.End(); - - nextTexture.Dispose(); + var encoder = device.CreateCommandEncoder("Command Encoder"); + var renderPass = encoder.BeginRenderPass( + label: null, + colorAttachments: new RenderPassColorAttachment[] + { + new RenderPassColorAttachment() + { + view = nextTexture, + resolveTarget = default, + loadOp = Wgpu.LoadOp.Clear, + storeOp = Wgpu.StoreOp.Store, + clearValue = new Wgpu.Color() { r = 0, g = 0.02f, b = 0.1f, a = 1 } + } + }, + depthStencilAttachment: new RenderPassDepthStencilAttachment + { + View = depthTextureView, + DepthLoadOp = Wgpu.LoadOp.Clear, + DepthStoreOp = Wgpu.StoreOp.Store, + DepthClearValue = 0f, + StencilLoadOp = Wgpu.LoadOp.Clear, + StencilStoreOp = Wgpu.StoreOp.Discard + } + ); + renderPass.SetPipeline(renderPipeline); - var queue = device.Queue; + renderPass.SetBindGroup(0, bindGroup, Array.Empty()); + renderPass.SetVertexBuffer(0, vertexBuffer, 0, (ulong)(vertices.Length * sizeof(Vertex))); + renderPass.Draw(3, 1, 0, 0); + renderPass.End(); - uniformBufferSpan[0] = uniformBufferData; + nextTexture.Dispose(); - queue.WriteBuffer(uniformBuffer, 0, uniformBufferSpan); + var queue = device.Queue; + uniformBufferSpan[0] = uniformBufferData; - var commandBuffer = encoder.Finish(null); + queue.WriteBuffer(uniformBuffer, 0, uniformBufferSpan); - queue.Submit(new CommandBuffer[] - { - commandBuffer - }); + var commandBuffer = encoder.Finish(null); - swapChain.Present(); + queue.Submit(new CommandBuffer[] + { + commandBuffer + }); + surface.Present(); - glfw.PollEvents(); - } + glfw.PollEvents(); + } - glfw.DestroyWindow(window); - glfw.Terminate(); - } + glfw.DestroyWindow(window); + glfw.Terminate(); + } - private static Matrix4x4 CreatePerspective(float fov, float aspectRatio, float near, float far) - { - if (fov <= 0.0f || fov >= MathF.PI) - throw new ArgumentOutOfRangeException(nameof(fov)); + private static Matrix4x4 CreatePerspective(float fov, float aspectRatio, float near, float far) + { + if (fov <= 0.0f || fov >= MathF.PI) + throw new ArgumentOutOfRangeException(nameof(fov)); - if (near <= 0.0f) - throw new ArgumentOutOfRangeException(nameof(near)); + if (near <= 0.0f) + throw new ArgumentOutOfRangeException(nameof(near)); - if (far <= 0.0f) - throw new ArgumentOutOfRangeException(nameof(far)); + if (far <= 0.0f) + throw new ArgumentOutOfRangeException(nameof(far)); - float yScale = 1.0f / MathF.Tan(fov * 0.5f); - float xScale = yScale / aspectRatio; + float yScale = 1.0f / MathF.Tan(fov * 0.5f); + float xScale = yScale / aspectRatio; - Matrix4x4 result; + Matrix4x4 result; - result.M11 = xScale; - result.M12 = result.M13 = result.M14 = 0.0f; + result.M11 = xScale; + result.M12 = result.M13 = result.M14 = 0.0f; - result.M22 = yScale; - result.M21 = result.M23 = result.M24 = 0.0f; + result.M22 = yScale; + result.M21 = result.M23 = result.M24 = 0.0f; - result.M31 = result.M32 = 0.0f; - var negFarRange = float.IsPositiveInfinity(far) ? -1.0f : far / (near - far); - result.M33 = negFarRange; - result.M34 = -1.0f; + result.M31 = result.M32 = 0.0f; + var negFarRange = float.IsPositiveInfinity(far) ? -1.0f : far / (near - far); + result.M33 = negFarRange; + result.M34 = -1.0f; - result.M41 = result.M42 = result.M44 = 0.0f; - result.M43 = near * negFarRange; + result.M41 = result.M42 = result.M44 = 0.0f; + result.M43 = near * negFarRange; - return result; - } - } + return result; + } + } } \ No newline at end of file diff --git a/WGPU.Tests/shader.wgsl b/WGPU.Tests/shader.wgsl index 9e50746..a6b2a3f 100644 --- a/WGPU.Tests/shader.wgsl +++ b/WGPU.Tests/shader.wgsl @@ -1,4 +1,8 @@ -struct UniformBuffer { +/* +* VERTEX SHADER +*/ + +struct UniformBuffer { mdlMat : mat4x4 }; @@ -14,12 +18,12 @@ var ub : UniformBuffer; @vertex fn vs_main(@location(0) pos: vec3, @location(1) col: vec4, @location(2) uv: vec2) -> VOut { - - - return VOut(ub.mdlMat*vec4(pos, 1.0), col, uv); + return VOut(ub.mdlMat * vec4(pos, 1.0), col, uv); } - +/* +* FRAGMENT SHADER +*/ @group(0) @binding(1) @@ -32,13 +36,13 @@ var tex : texture_2d; @fragment fn fs_main(in : VOut) -> @location(0) vec4 { let rpos = vec2( - floor(in.uv.x*10.0), - floor(in.uv.y*10.0) + floor(in.uv.x * 10.0), + floor(in.uv.y * 10.0) ); - let texCol = textureSample(tex,samp,in.uv); + let texCol = textureSample(tex,samp, in.uv); - let col = mix(in.col, vec4(texCol.rgb,1.0), texCol.a); + let col = mix(in.col, vec4(texCol.rgb, 1.0), texCol.a); - return col * mix(1.0, 0.9, f32((rpos.x%2.0+2.0)%2.0 == (rpos.y%2.0+2.0)%2.0)); + return col * mix(1.0, 0.9, f32((rpos.x % 2.0 + 2.0) % 2.0 == (rpos.y % 2.0 + 2.0) % 2.0)); } \ No newline at end of file