Skip to content

Updated to latest version. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 116 additions & 106 deletions BindingsGenerator/headers/webgpu-headers/webgpu.h

Large diffs are not rendered by default.

139 changes: 90 additions & 49 deletions BindingsGenerator/headers/wgpu.h
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -36,41 +40,65 @@ 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,
WGPUDx12Compiler_Dxc = 0x00000002,
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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -190,16 +228,14 @@ 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);

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);
Expand All @@ -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
#endif
41 changes: 36 additions & 5 deletions WGPU.NET/Helpers/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace WGPU.NET
{
Expand All @@ -17,7 +16,7 @@ public static IntPtr AllocHStruct<T>(T structure)
return ptr;
}

public unsafe static IntPtr AllocHArray(byte[] arr)
public static unsafe IntPtr AllocHArray(byte[] arr)
{
IntPtr ptr = Marshal.AllocHGlobal(arr.Length);

Expand All @@ -28,7 +27,7 @@ public unsafe static IntPtr AllocHArray(byte[] arr)
return ptr;
}

public unsafe static IntPtr AllocHArray<T>(T[] arr)
public static unsafe IntPtr AllocHArray<T>(T[] arr)
where T : struct
{
int size = sizeof(T);
Expand All @@ -45,7 +44,7 @@ public unsafe static IntPtr AllocHArray<T>(T[] arr)
return ptr;
}

public unsafe static IntPtr AllocHArray<T>(int count, IEnumerable<T> items)
public static unsafe IntPtr AllocHArray<T>(int count, IEnumerable<T> items)
where T : struct
{
int size = sizeof(T);
Expand Down Expand Up @@ -109,5 +108,37 @@ public static TValue GetOrCreate<TKey, TValue>(this Dictionary<TKey, TValue> 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)
};
}
}
18 changes: 16 additions & 2 deletions WGPU.NET/Helpers/WgpuStructChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
Loading