webgpu/wgpu/wgpu.h
  1#ifndef WGPU_H_
  2#define WGPU_H_
  3
  4#include "webgpu.h"
  5
  6typedef enum WGPUNativeSType {
  7    // Start at 0003 since that's allocated range for wgpu-native
  8    WGPUSType_DeviceExtras = 0x00030001,
  9    WGPUSType_RequiredLimitsExtras = 0x00030002,
 10    WGPUSType_PipelineLayoutExtras = 0x00030003,
 11    WGPUSType_ShaderModuleGLSLDescriptor = 0x00030004,
 12    WGPUSType_SupportedLimitsExtras = 0x00030005,
 13    WGPUSType_InstanceExtras = 0x00030006,
 14    WGPUSType_BindGroupEntryExtras = 0x00030007,
 15    WGPUSType_BindGroupLayoutEntryExtras = 0x00030008,
 16    WGPUSType_QuerySetDescriptorExtras = 0x00030009,
 17    WGPUSType_SurfaceConfigurationExtras = 0x0003000A,
 18    WGPUNativeSType_Force32 = 0x7FFFFFFF
 19} WGPUNativeSType;
 20
 21typedef enum WGPUNativeFeature {
 22    WGPUNativeFeature_PushConstants = 0x00030001,
 23    WGPUNativeFeature_TextureAdapterSpecificFormatFeatures = 0x00030002,
 24    WGPUNativeFeature_MultiDrawIndirect = 0x00030003,
 25    WGPUNativeFeature_MultiDrawIndirectCount = 0x00030004,
 26    WGPUNativeFeature_VertexWritableStorage = 0x00030005,
 27    WGPUNativeFeature_TextureBindingArray = 0x00030006,
 28    WGPUNativeFeature_SampledTextureAndStorageBufferArrayNonUniformIndexing = 0x00030007,
 29    WGPUNativeFeature_PipelineStatisticsQuery = 0x00030008,
 30    WGPUNativeFeature_StorageResourceBindingArray = 0x00030009,
 31    WGPUNativeFeature_PartiallyBoundBindingArray = 0x0003000A,
 32    WGPUNativeFeature_Force32 = 0x7FFFFFFF
 33} WGPUNativeFeature;
 34
 35typedef enum WGPULogLevel {
 36    WGPULogLevel_Off = 0x00000000,
 37    WGPULogLevel_Error = 0x00000001,
 38    WGPULogLevel_Warn = 0x00000002,
 39    WGPULogLevel_Info = 0x00000003,
 40    WGPULogLevel_Debug = 0x00000004,
 41    WGPULogLevel_Trace = 0x00000005,
 42    WGPULogLevel_Force32 = 0x7FFFFFFF
 43} WGPULogLevel;
 44
 45typedef enum WGPUInstanceBackend {
 46    WGPUInstanceBackend_All = 0x00000000,
 47    WGPUInstanceBackend_Vulkan = 1 << 0,
 48    WGPUInstanceBackend_GL = 1 << 1,
 49    WGPUInstanceBackend_Metal = 1 << 2,
 50    WGPUInstanceBackend_DX12 = 1 << 3,
 51    WGPUInstanceBackend_DX11 = 1 << 4,
 52    WGPUInstanceBackend_BrowserWebGPU = 1 << 5,
 53    WGPUInstanceBackend_Primary = WGPUInstanceBackend_Vulkan | WGPUInstanceBackend_Metal |
 54        WGPUInstanceBackend_DX12 |
 55        WGPUInstanceBackend_BrowserWebGPU,
 56    WGPUInstanceBackend_Secondary = WGPUInstanceBackend_GL | WGPUInstanceBackend_DX11,
 57    WGPUInstanceBackend_Force32 = 0x7FFFFFFF
 58} WGPUInstanceBackend;
 59typedef WGPUFlags WGPUInstanceBackendFlags;
 60
 61typedef enum WGPUInstanceFlag {
 62    WGPUInstanceFlag_Default = 0x00000000,
 63    WGPUInstanceFlag_Debug = 1 << 0,
 64    WGPUInstanceFlag_Validation = 1 << 1,
 65    WGPUInstanceFlag_DiscardHalLabels = 1 << 2,
 66    WGPUInstanceFlag_Force32 = 0x7FFFFFFF
 67} WGPUInstanceFlag;
 68typedef WGPUFlags WGPUInstanceFlags;
 69
 70typedef enum WGPUDx12Compiler {
 71    WGPUDx12Compiler_Undefined = 0x00000000,
 72    WGPUDx12Compiler_Fxc = 0x00000001,
 73    WGPUDx12Compiler_Dxc = 0x00000002,
 74    WGPUDx12Compiler_Force32 = 0x7FFFFFFF
 75} WGPUDx12Compiler;
 76
 77typedef enum WGPUGles3MinorVersion {
 78    WGPUGles3MinorVersion_Automatic = 0x00000000,
 79    WGPUGles3MinorVersion_Version0 = 0x00000001,
 80    WGPUGles3MinorVersion_Version1 = 0x00000002,
 81    WGPUGles3MinorVersion_Version2 = 0x00000003,
 82    WGPUGles3MinorVersion_Force32 = 0x7FFFFFFF
 83} WGPUGles3MinorVersion;
 84
 85typedef enum WGPUPipelineStatisticName {
 86    WGPUPipelineStatisticName_VertexShaderInvocations = 0x00000000,
 87    WGPUPipelineStatisticName_ClipperInvocations = 0x00000001,
 88    WGPUPipelineStatisticName_ClipperPrimitivesOut = 0x00000002,
 89    WGPUPipelineStatisticName_FragmentShaderInvocations = 0x00000003,
 90    WGPUPipelineStatisticName_ComputeShaderInvocations = 0x00000004,
 91    WGPUPipelineStatisticName_Force32 = 0x7FFFFFFF
 92} WGPUPipelineStatisticName WGPU_ENUM_ATTRIBUTE;
 93
 94typedef enum WGPUNativeQueryType {
 95    WGPUNativeQueryType_PipelineStatistics = 0x00030000,
 96    WGPUNativeQueryType_Force32 = 0x7FFFFFFF
 97} WGPUNativeQueryType WGPU_ENUM_ATTRIBUTE;
 98
 99typedef struct WGPUInstanceExtras {
100    WGPUChainedStruct chain;
101    WGPUInstanceBackendFlags backends;
102    WGPUInstanceFlags flags;
103    WGPUDx12Compiler dx12ShaderCompiler;
104    WGPUGles3MinorVersion gles3MinorVersion;
105    const char * dxilPath;
106    const char * dxcPath;
107} WGPUInstanceExtras;
108
109typedef struct WGPUDeviceExtras {
110    WGPUChainedStruct chain;
111    const char * tracePath;
112} WGPUDeviceExtras;
113
114typedef struct WGPUNativeLimits {
115    uint32_t maxPushConstantSize;
116    uint32_t maxNonSamplerBindings;
117} WGPUNativeLimits;
118
119typedef struct WGPURequiredLimitsExtras {
120    WGPUChainedStruct chain;
121    WGPUNativeLimits limits;
122} WGPURequiredLimitsExtras;
123
124typedef struct WGPUSupportedLimitsExtras {
125    WGPUChainedStructOut chain;
126    WGPUNativeLimits limits;
127} WGPUSupportedLimitsExtras;
128
129typedef struct WGPUPushConstantRange {
130    WGPUShaderStageFlags stages;
131    uint32_t start;
132    uint32_t end;
133} WGPUPushConstantRange;
134
135typedef struct WGPUPipelineLayoutExtras {
136    WGPUChainedStruct chain;
137    size_t pushConstantRangeCount;
138    WGPUPushConstantRange const * pushConstantRanges;
139} WGPUPipelineLayoutExtras;
140
141typedef uint64_t WGPUSubmissionIndex;
142
143typedef struct WGPUWrappedSubmissionIndex {
144    WGPUQueue queue;
145    WGPUSubmissionIndex submissionIndex;
146} WGPUWrappedSubmissionIndex;
147
148typedef struct WGPUShaderDefine {
149    char const * name;
150    char const * value;
151} WGPUShaderDefine;
152
153typedef struct WGPUShaderModuleGLSLDescriptor {
154    WGPUChainedStruct chain;
155    WGPUShaderStage stage;
156    char const * code;
157    uint32_t defineCount;
158    WGPUShaderDefine * defines;
159} WGPUShaderModuleGLSLDescriptor;
160
161typedef struct WGPURegistryReport {
162   size_t numAllocated;
163   size_t numKeptFromUser;
164   size_t numReleasedFromUser;
165   size_t numError;
166   size_t elementSize;
167} WGPURegistryReport;
168
169typedef struct WGPUHubReport {
170    WGPURegistryReport adapters;
171    WGPURegistryReport devices;
172    WGPURegistryReport queues;
173    WGPURegistryReport pipelineLayouts;
174    WGPURegistryReport shaderModules;
175    WGPURegistryReport bindGroupLayouts;
176    WGPURegistryReport bindGroups;
177    WGPURegistryReport commandBuffers;
178    WGPURegistryReport renderBundles;
179    WGPURegistryReport renderPipelines;
180    WGPURegistryReport computePipelines;
181    WGPURegistryReport querySets;
182    WGPURegistryReport buffers;
183    WGPURegistryReport textures;
184    WGPURegistryReport textureViews;
185    WGPURegistryReport samplers;
186} WGPUHubReport;
187
188typedef struct WGPUGlobalReport {
189    WGPURegistryReport surfaces;
190    WGPUBackendType backendType;
191    WGPUHubReport vulkan;
192    WGPUHubReport metal;
193    WGPUHubReport dx12;
194    WGPUHubReport gl;
195} WGPUGlobalReport;
196
197typedef struct WGPUInstanceEnumerateAdapterOptions {
198    WGPUChainedStruct const * nextInChain;
199    WGPUInstanceBackendFlags backends;
200} WGPUInstanceEnumerateAdapterOptions;
201
202typedef struct WGPUBindGroupEntryExtras {
203    WGPUChainedStruct chain;
204    WGPUBuffer const * buffers;
205    size_t bufferCount;
206    WGPUSampler const * samplers;
207    size_t samplerCount;
208    WGPUTextureView const * textureViews;
209    size_t textureViewCount;
210} WGPUBindGroupEntryExtras;
211
212typedef struct WGPUBindGroupLayoutEntryExtras {
213    WGPUChainedStruct chain;
214    uint32_t count;
215} WGPUBindGroupLayoutEntryExtras;
216
217typedef struct WGPUQuerySetDescriptorExtras {
218    WGPUChainedStruct chain;
219    WGPUPipelineStatisticName const * pipelineStatistics;
220    size_t pipelineStatisticCount;
221} WGPUQuerySetDescriptorExtras WGPU_STRUCTURE_ATTRIBUTE;
222
223typedef struct WGPUSurfaceConfigurationExtras {
224    WGPUChainedStruct chain;
225    WGPUBool desiredMaximumFrameLatency;
226} WGPUSurfaceConfigurationExtras WGPU_STRUCTURE_ATTRIBUTE;
227
228typedef void (*WGPULogCallback)(WGPULogLevel level, char const * message, void * userdata);
229
230#ifdef __cplusplus
231extern "C" {
232#endif
233
234void wgpuGenerateReport(WGPUInstance instance, WGPUGlobalReport * report);
235size_t wgpuInstanceEnumerateAdapters(WGPUInstance instance, WGPU_NULLABLE WGPUInstanceEnumerateAdapterOptions const * options, WGPUAdapter * adapters);
236
237WGPUSubmissionIndex wgpuQueueSubmitForIndex(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands);
238
239// Returns true if the queue is empty, or false if there are more queue submissions still in flight.
240WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPU_NULLABLE WGPUWrappedSubmissionIndex const * wrappedSubmissionIndex);
241
242void wgpuSetLogCallback(WGPULogCallback callback, void * userdata);
243
244void wgpuSetLogLevel(WGPULogLevel level);
245
246uint32_t wgpuGetVersion(void);
247
248void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStageFlags stages, uint32_t offset, uint32_t sizeBytes, void const * data);
249
250void wgpuRenderPassEncoderMultiDrawIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
251void wgpuRenderPassEncoderMultiDrawIndexedIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
252
253void wgpuRenderPassEncoderMultiDrawIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count);
254void wgpuRenderPassEncoderMultiDrawIndexedIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count);
255
256void wgpuComputePassEncoderBeginPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
257void wgpuComputePassEncoderEndPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder);
258void wgpuRenderPassEncoderBeginPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
259void wgpuRenderPassEncoderEndPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder);
260
261#ifdef __cplusplus
262} // extern "C"
263#endif
264
265#endif