1 /*
2 Copyright (c) 2019-2024 Timur Gafarov.
3 
4 Boost Software License - Version 1.0 - August 17th, 2003
5 
6 Permission is hereby granted, free of charge, to any person or organization
7 obtaining a copy of the software and accompanying documentation covered by
8 this license (the "Software") to use, reproduce, display, distribute,
9 execute, and transmit the Software, and to prepare derivative works of the
10 Software, and to permit third-parties to whom the Software is furnished to
11 do so, all subject to the following:
12 
13 The copyright notices in the Software and this entire statement, including
14 the above license grant, this restriction and the following disclaimer,
15 must be included in all copies of the Software, in whole or in part, and
16 all derivative works of the Software, unless such copies or derivative
17 works are solely in the form of machine-executable object code generated by
18 a source language processor.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
23 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
24 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 DEALINGS IN THE SOFTWARE.
27 */
28 module bindbc.wgpu.types2;
29 
30 import bindbc.wgpu.types;
31 
32 /*
33  * Type definitions from wgpu.h
34  */
35 
36 enum WGPUNativeSType
37 {
38     // Start at 6 to prevent collisions with webgpu STypes
39     DeviceExtras = 0x00030001,
40     RequiredLimitsExtras = 0x00030002,
41     PipelineLayoutExtras = 0x00030003,
42     ShaderModuleGLSLDescriptor = 0x00030004,
43     SupportedLimitsExtras = 0x00030005,
44     InstanceExtras = 0x00030006,
45     BindGroupEntryExtras = 0x00030007,
46     BindGroupLayoutEntryExtras = 0x00030008,
47     QuerySetDescriptorExtras = 0x00030009,
48     SurfaceConfigurationExtras = 0x0003000A,
49     Force32 = 0x7FFFFFFF
50 }
51 
52 enum WGPUNativeFeature
53 {
54     PushConstants = 0x00030001,
55     TextureAdapterSpecificFormatFeatures = 0x00030002,
56     MultiDrawIndirect = 0x00030003,
57     MultiDrawIndirectCount = 0x00030004,
58     VertexWritableStorage = 0x00030005,
59     TextureBindingArray = 0x00030006,
60     SampledTextureAndStorageBufferArrayNonUniformIndexing = 0x00030007,
61     PipelineStatisticsQuery = 0x00030008,
62     StorageResourceBindingArray = 0x00030009,
63     PartiallyBoundBindingArray = 0x0003000A,
64     TextureFormat16bitNorm = 0x0003000B,
65     TextureCompressionAstcHdr = 0x0003000C,
66     // TODO: requires wgpu.h api change
67     // TimestampQueryInsidePasses = 0x0003000D,
68     MappablePrimaryBuffers = 0x0003000E,
69     BufferBindingArray = 0x0003000F,
70     UniformBufferAndStorageTextureArrayNonUniformIndexing = 0x00030010,
71     // TODO: requires wgpu.h api change
72     // AddressModeClampToZero = 0x00030011,
73     // AddressModeClampToBorder = 0x00030012,
74     // PolygonModeLine = 0x00030013,
75     // PolygonModePoint = 0x00030014,
76     // ConservativeRasterization = 0x00030015,
77     // ClearTexture = 0x00030016,
78     // SpirvShaderPassthrough = 0x00030017,
79     // Multiview = 0x00030018,
80     VertexAttribute64bit = 0x00030019,
81     TextureFormatNv12 = 0x0003001A,
82     RayTracingAccelerationStructure = 0x0003001B,
83     RayQuery = 0x0003001C,
84     ShaderF64 = 0x0003001D,
85     ShaderI16 = 0x0003001E,
86     ShaderPrimitiveIndex = 0x0003001F,
87     ShaderEarlyDepthTest = 0x00030020,
88     Force32 = 0x7FFFFFFF
89 }
90 
91 enum WGPULogLevel
92 {
93     Off = 0x00000000,
94     Error = 0x00000001,
95     Warn = 0x00000002,
96     Info = 0x00000003,
97     Debug = 0x00000004,
98     Trace = 0x00000005,
99     Force32 = 0x7FFFFFFF
100 }
101 
102 enum WGPUInstanceBackend
103 {
104     All = 0x00000000,
105     Vulkan = 1 << 0,
106     GL = 1 << 1,
107     Metal = 1 << 2,
108     DX12 = 1 << 3,
109     DX11 = 1 << 4,
110     BrowserWebGPU = 1 << 5,
111     Primary = Vulkan | Metal | DX12 | BrowserWebGPU,
112     Secondary = GL | DX11,
113     Force32 = 0x7FFFFFFF
114 }
115 
116 alias WGPUInstanceBackendFlags = WGPUFlags;
117 
118 enum WGPUInstanceFlag 
119 {
120     Default = 0x00000000,
121     Debug = 1 << 0,
122     Validation = 1 << 1,
123     DiscardHalLabels = 1 << 2,
124     Force32 = 0x7FFFFFFF
125 }
126 
127 alias WGPUInstanceFlags = WGPUFlags;
128 
129 enum WGPUDx12Compiler
130 {
131     Undefined = 0x00000000,
132     Fxc = 0x00000001,
133     Dxc = 0x00000002,
134     Force32 = 0x7FFFFFFF
135 }
136 
137 enum WGPUGles3MinorVersion {
138     Automatic = 0x00000000,
139     Version0 = 0x00000001,
140     Version1 = 0x00000002,
141     Version2 = 0x00000003,
142     Force32 = 0x7FFFFFFF
143 }
144 
145 enum WGPUPipelineStatisticName
146 {
147     VertexShaderInvocations = 0x00000000,
148     ClipperInvocations = 0x00000001,
149     ClipperPrimitivesOut = 0x00000002,
150     FragmentShaderInvocations = 0x00000003,
151     ComputeShaderInvocations = 0x00000004,
152     Force32 = 0x7FFFFFFF
153 }
154 
155 enum WGPUNativeQueryType
156 {
157     PipelineStatistics = 0x00030000,
158     Force32 = 0x7FFFFFFF
159 }
160 
161 struct WGPUInstanceExtras
162 {
163     WGPUChainedStruct chain;
164     WGPUInstanceBackendFlags backends;
165     WGPUInstanceFlags flags;
166     WGPUDx12Compiler dx12ShaderCompiler;
167     WGPUGles3MinorVersion gles3MinorVersion;
168     const char * dxilPath;
169     const char * dxcPath;
170 }
171 
172 struct WGPUDeviceExtras
173 {
174     WGPUChainedStruct chain;
175     const(char)* tracePath;
176 }
177 
178 struct WGPUNativeLimits {
179     uint maxPushConstantSize;
180     uint maxNonSamplerBindings;
181 }
182 
183 struct WGPURequiredLimitsExtras
184 {
185     WGPUChainedStruct chain;
186     WGPUNativeLimits limits;
187 }
188 
189 struct WGPUSupportedLimitsExtras
190 {
191     WGPUChainedStructOut chain;
192     WGPUNativeLimits limits;
193 }
194 
195 struct WGPUPushConstantRange
196 {
197     alias WGPUShaderStageFlags = uint;
198     WGPUShaderStageFlags stages;
199     uint start;
200     uint end;
201 }
202 
203 struct WGPUPipelineLayoutExtras
204 {
205     WGPUChainedStruct chain;
206     size_t pushConstantRangeCount;
207     const(WGPUPushConstantRange)* pushConstantRanges;
208 }
209 
210 alias WGPUSubmissionIndex = ulong;
211 
212 struct WGPUWrappedSubmissionIndex
213 {
214     WGPUQueue queue;
215     WGPUSubmissionIndex submissionIndex;
216 }
217 
218 struct WGPUShaderDefine
219 {
220     const(char)* name;
221     const(char)* value;
222 }
223 
224 struct WGPUShaderModuleGLSLDescriptor
225 {
226     WGPUChainedStruct chain;
227     WGPUShaderStage stage;
228     const(char)* code;
229     uint defineCount;
230     WGPUShaderDefine* defines;
231 }
232 
233 struct WGPURegistryReport
234 {
235    size_t numAllocated;
236    size_t numKeptFromUser;
237    size_t numReleasedFromUser;
238    size_t numError;
239    size_t elementSize;
240 }
241 
242 struct WGPUHubReport
243 {
244     WGPURegistryReport adapters;
245     WGPURegistryReport devices;
246     WGPURegistryReport queues;
247     WGPURegistryReport pipelineLayouts;
248     WGPURegistryReport shaderModules;
249     WGPURegistryReport bindGroupLayouts;
250     WGPURegistryReport bindGroups;
251     WGPURegistryReport commandBuffers;
252     WGPURegistryReport renderBundles;
253     WGPURegistryReport renderPipelines;
254     WGPURegistryReport computePipelines;
255     WGPURegistryReport querySets;
256     WGPURegistryReport buffers;
257     WGPURegistryReport textures;
258     WGPURegistryReport textureViews;
259     WGPURegistryReport samplers;
260 }
261 
262 struct WGPUGlobalReport
263 {
264     WGPURegistryReport surfaces;
265     WGPUBackendType backendType;
266     WGPUHubReport vulkan;
267     WGPUHubReport metal;
268     WGPUHubReport dx12;
269     WGPUHubReport gl;
270 }
271 
272 struct WGPUInstanceEnumerateAdapterOptions
273 {
274     const(WGPUChainedStruct)* nextInChain;
275     WGPUInstanceBackendFlags backends;
276 }
277 
278 struct WGPUBindGroupEntryExtras
279 {
280     WGPUChainedStruct chain;
281     const(WGPUBuffer)* buffers;
282     size_t bufferCount;
283     const(WGPUSampler)* samplers;
284     size_t samplerCount;
285     const(WGPUTextureView)* textureViews;
286     size_t textureViewCount;
287 }
288 
289 struct WGPUBindGroupLayoutEntryExtras
290 {
291     WGPUChainedStruct chain;
292     uint count;
293 }
294 
295 struct WGPUQuerySetDescriptorExtras
296 {
297     WGPUChainedStruct chain;
298     const(WGPUPipelineStatisticName)* pipelineStatistics;
299     size_t pipelineStatisticCount;
300 }
301 
302 struct WGPUSurfaceConfigurationExtras
303 {
304     WGPUChainedStruct chain;
305     uint desiredMaximumFrameLatency;
306 }
307 
308 enum WGPUNativeTextureFormat
309 {
310     // From Features::TEXTURE_FORMAT_16BIT_NORM
311     R16Unorm = 0x00030001,
312     R16Snorm = 0x00030002,
313     Rg16Unorm = 0x00030003,
314     Rg16Snorm = 0x00030004,
315     Rgba16Unorm = 0x00030005,
316     Rgba16Snorm = 0x00030006,
317     // From Features::TEXTURE_FORMAT_NV12
318     NV12 = 0x00030007,
319 }
320 
321 extern(C):
322 
323 alias WGPULogCallback = void function (WGPULogLevel level, const(char)* message, void* userdata);
324 
325 extern(C) @nogc nothrow:
326 
327 alias WGPUProcGenerateReport = void function(WGPUInstance instance, WGPUGlobalReport* report);
328 alias WGPUProcInstanceEnumerateAdapters = size_t function(WGPUInstance instance, const(WGPUInstanceEnumerateAdapterOptions)* options, WGPUAdapter* adapters);
329 
330 alias WGPUProcQueueSubmitForIndex = WGPUSubmissionIndex function(WGPUQueue queue, size_t commandCount, const(WGPUCommandBuffer)* commands);
331 
332 // Returns true if the queue is empty, or false if there are more queue submissions still in flight.
333 alias WGPUProcDevicePoll = WGPUBool function(WGPUDevice device, WGPUBool wait, const(WGPUWrappedSubmissionIndex)* wrappedSubmissionIndex);
334 
335 alias WGPUProcSetLogCallback = void function(WGPULogCallback callback, void* userdata);
336 
337 alias WGPUProcSetLogLevel = void function(WGPULogLevel level);
338 
339 alias WGPUProcGetVersion = uint function();
340 
341 alias WGPUProcRenderPassEncoderSetPushConstants = void function(WGPURenderPassEncoder encoder, WGPUShaderStageFlags stages, uint offset, uint sizeBytes, const(void)* data);
342 
343 alias WGPUProcRenderPassEncoderMultiDrawIndirect = void function(WGPURenderPassEncoder encoder, WGPUBuffer buffer, ulong offset, uint count);
344 alias WGPUProcRenderPassEncoderMultiDrawIndexedIndirect = void function(WGPURenderPassEncoder encoder, WGPUBuffer buffer, ulong offset, uint count);
345 
346 alias WGPUProcRenderPassEncoderMultiDrawIndirectCount = void function(WGPURenderPassEncoder encoder, WGPUBuffer buffer, ulong offset, WGPUBuffer count_buffer, ulong count_buffer_offset, uint max_count);
347 alias WGPUProcRenderPassEncoderMultiDrawIndexedIndirectCount = void function(WGPURenderPassEncoder encoder, WGPUBuffer buffer, ulong offset, WGPUBuffer count_buffer, ulong count_buffer_offset, uint max_count);
348 
349 alias WGPUProcComputePassEncoderBeginPipelineStatisticsQuery = void function(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint queryIndex);
350 alias WGPUProcComputePassEncoderEndPipelineStatisticsQuery = void function(WGPUComputePassEncoder computePassEncoder);
351 alias WGPUProcRenderPassEncoderBeginPipelineStatisticsQuery = void function(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint queryIndex);
352 alias WGPUProcRenderPassEncoderEndPipelineStatisticsQuery = void function(WGPURenderPassEncoder renderPassEncoder);