zgpu

git clone git://git.electrosoup.com/zgpu
Log | Files | Refs | Submodules | README

wgpu.h (13173B)


      1 #ifndef WGPU_H_
      2 #define WGPU_H_
      3 
      4 #include "webgpu.h"
      5 
      6 typedef enum WGPUNativeSType {
      7     // Start at 0003 since that's allocated range for wgpu-native
      8     WGPUSType_DeviceExtras = 0x00030001,
      9     WGPUSType_NativeLimits = 0x00030002,
     10     WGPUSType_PipelineLayoutExtras = 0x00030003,
     11     WGPUSType_ShaderSourceGLSL = 0x00030004,
     12     WGPUSType_InstanceExtras = 0x00030006,
     13     WGPUSType_BindGroupEntryExtras = 0x00030007,
     14     WGPUSType_BindGroupLayoutEntryExtras = 0x00030008,
     15     WGPUSType_QuerySetDescriptorExtras = 0x00030009,
     16     WGPUSType_SurfaceConfigurationExtras = 0x0003000A,
     17     WGPUNativeSType_Force32 = 0x7FFFFFFF
     18 } WGPUNativeSType;
     19 
     20 typedef enum WGPUNativeFeature {
     21     WGPUNativeFeature_PushConstants = 0x00030001,
     22     WGPUNativeFeature_TextureAdapterSpecificFormatFeatures = 0x00030002,
     23     WGPUNativeFeature_MultiDrawIndirect = 0x00030003,
     24     WGPUNativeFeature_MultiDrawIndirectCount = 0x00030004,
     25     WGPUNativeFeature_VertexWritableStorage = 0x00030005,
     26     WGPUNativeFeature_TextureBindingArray = 0x00030006,
     27     WGPUNativeFeature_SampledTextureAndStorageBufferArrayNonUniformIndexing = 0x00030007,
     28     WGPUNativeFeature_PipelineStatisticsQuery = 0x00030008,
     29     WGPUNativeFeature_StorageResourceBindingArray = 0x00030009,
     30     WGPUNativeFeature_PartiallyBoundBindingArray = 0x0003000A,
     31     WGPUNativeFeature_TextureFormat16bitNorm = 0x0003000B,
     32     WGPUNativeFeature_TextureCompressionAstcHdr = 0x0003000C,
     33     WGPUNativeFeature_MappablePrimaryBuffers = 0x0003000E,
     34     WGPUNativeFeature_BufferBindingArray = 0x0003000F,
     35     WGPUNativeFeature_UniformBufferAndStorageTextureArrayNonUniformIndexing = 0x00030010,
     36     // TODO: requires wgpu.h api change
     37     // WGPUNativeFeature_AddressModeClampToZero = 0x00030011,
     38     // WGPUNativeFeature_AddressModeClampToBorder = 0x00030012,
     39     // WGPUNativeFeature_PolygonModeLine = 0x00030013,
     40     // WGPUNativeFeature_PolygonModePoint = 0x00030014,
     41     // WGPUNativeFeature_ConservativeRasterization = 0x00030015,
     42     // WGPUNativeFeature_ClearTexture = 0x00030016,
     43     WGPUNativeFeature_SpirvShaderPassthrough = 0x00030017,
     44     // WGPUNativeFeature_Multiview = 0x00030018,
     45     WGPUNativeFeature_VertexAttribute64bit = 0x00030019,
     46     WGPUNativeFeature_TextureFormatNv12 = 0x0003001A,
     47     WGPUNativeFeature_RayTracingAccelerationStructure = 0x0003001B,
     48     WGPUNativeFeature_RayQuery = 0x0003001C,
     49     WGPUNativeFeature_ShaderF64 = 0x0003001D,
     50     WGPUNativeFeature_ShaderI16 = 0x0003001E,
     51     WGPUNativeFeature_ShaderPrimitiveIndex = 0x0003001F,
     52     WGPUNativeFeature_ShaderEarlyDepthTest = 0x00030020,
     53     WGPUNativeFeature_Subgroup = 0x00030021,
     54     WGPUNativeFeature_SubgroupVertex = 0x00030022,
     55     WGPUNativeFeature_SubgroupBarrier = 0x00030023,
     56     WGPUNativeFeature_TimestampQueryInsideEncoders = 0x00030024,
     57     WGPUNativeFeature_TimestampQueryInsidePasses = 0x00030025,
     58     WGPUNativeFeature_Force32 = 0x7FFFFFFF
     59 } WGPUNativeFeature;
     60 
     61 typedef enum WGPULogLevel {
     62     WGPULogLevel_Off = 0x00000000,
     63     WGPULogLevel_Error = 0x00000001,
     64     WGPULogLevel_Warn = 0x00000002,
     65     WGPULogLevel_Info = 0x00000003,
     66     WGPULogLevel_Debug = 0x00000004,
     67     WGPULogLevel_Trace = 0x00000005,
     68     WGPULogLevel_Force32 = 0x7FFFFFFF
     69 } WGPULogLevel;
     70 
     71 typedef WGPUFlags WGPUInstanceBackend;
     72 static const WGPUInstanceBackend WGPUInstanceBackend_All = 0x00000000;
     73 static const WGPUInstanceBackend WGPUInstanceBackend_Vulkan = 1 << 0;
     74 static const WGPUInstanceBackend WGPUInstanceBackend_GL = 1 << 1;
     75 static const WGPUInstanceBackend WGPUInstanceBackend_Metal = 1 << 2;
     76 static const WGPUInstanceBackend WGPUInstanceBackend_DX12 = 1 << 3;
     77 static const WGPUInstanceBackend WGPUInstanceBackend_DX11 = 1 << 4;
     78 static const WGPUInstanceBackend WGPUInstanceBackend_BrowserWebGPU = 1 << 5;
     79 // Vulkan, Metal, DX12 and BrowserWebGPU
     80 static const WGPUInstanceBackend WGPUInstanceBackend_Primary = (1 << 0) | (1 << 2) | (1 << 3) | (1 << 5);
     81 // GL and DX11
     82 static const WGPUInstanceBackend WGPUInstanceBackend_Secondary = (1 << 1) | (1 << 4);
     83 static const WGPUInstanceBackend WGPUInstanceBackend_Force32 = 0x7FFFFFFF;
     84 
     85 typedef WGPUFlags WGPUInstanceFlag;
     86 static const WGPUInstanceFlag WGPUInstanceFlag_Default = 0x00000000;
     87 static const WGPUInstanceFlag WGPUInstanceFlag_Debug = 1 << 0;
     88 static const WGPUInstanceFlag WGPUInstanceFlag_Validation = 1 << 1;
     89 static const WGPUInstanceFlag WGPUInstanceFlag_DiscardHalLabels = 1 << 2;
     90 static const WGPUInstanceFlag WGPUInstanceFlag_Force32 = 0x7FFFFFFF;
     91 
     92 typedef enum WGPUDx12Compiler {
     93     WGPUDx12Compiler_Undefined = 0x00000000,
     94     WGPUDx12Compiler_Fxc = 0x00000001,
     95     WGPUDx12Compiler_Dxc = 0x00000002,
     96     WGPUDx12Compiler_Force32 = 0x7FFFFFFF
     97 } WGPUDx12Compiler;
     98 
     99 typedef enum WGPUGles3MinorVersion {
    100     WGPUGles3MinorVersion_Automatic = 0x00000000,
    101     WGPUGles3MinorVersion_Version0 = 0x00000001,
    102     WGPUGles3MinorVersion_Version1 = 0x00000002,
    103     WGPUGles3MinorVersion_Version2 = 0x00000003,
    104     WGPUGles3MinorVersion_Force32 = 0x7FFFFFFF
    105 } WGPUGles3MinorVersion;
    106 
    107 typedef enum WGPUPipelineStatisticName {
    108     WGPUPipelineStatisticName_VertexShaderInvocations = 0x00000000,
    109     WGPUPipelineStatisticName_ClipperInvocations = 0x00000001,
    110     WGPUPipelineStatisticName_ClipperPrimitivesOut = 0x00000002,
    111     WGPUPipelineStatisticName_FragmentShaderInvocations = 0x00000003,
    112     WGPUPipelineStatisticName_ComputeShaderInvocations = 0x00000004,
    113     WGPUPipelineStatisticName_Force32 = 0x7FFFFFFF
    114 } WGPUPipelineStatisticName WGPU_ENUM_ATTRIBUTE;
    115 
    116 typedef enum WGPUNativeQueryType {
    117     WGPUNativeQueryType_PipelineStatistics = 0x00030000,
    118     WGPUNativeQueryType_Force32 = 0x7FFFFFFF
    119 } WGPUNativeQueryType WGPU_ENUM_ATTRIBUTE;
    120 
    121 typedef enum WGPUDxcMaxShaderModel {
    122     WGPUDxcMaxShaderModel_V6_0 = 0x00000000,
    123     WGPUDxcMaxShaderModel_V6_1 = 0x00000001,
    124     WGPUDxcMaxShaderModel_V6_2 = 0x00000002,
    125     WGPUDxcMaxShaderModel_V6_3 = 0x00000003,
    126     WGPUDxcMaxShaderModel_V6_4 = 0x00000004,
    127     WGPUDxcMaxShaderModel_V6_5 = 0x00000005,
    128     WGPUDxcMaxShaderModel_V6_6 = 0x00000006,
    129     WGPUDxcMaxShaderModel_V6_7 = 0x00000007,
    130     WGPUDxcMaxShaderModel_Force32 = 0x7FFFFFFF
    131 } WGPUDxcMaxShaderModel;
    132 
    133 typedef enum WGPUGLFenceBehaviour {
    134     WGPUGLFenceBehaviour_Normal = 0x00000000,
    135     WGPUGLFenceBehaviour_AutoFinish = 0x00000001,
    136     WGPUGLFenceBehaviour_Force32 = 0x7FFFFFFF
    137 } WGPUGLFenceBehaviour;
    138 
    139 typedef struct WGPUInstanceExtras {
    140     WGPUChainedStruct chain;
    141     WGPUInstanceBackend backends;
    142     WGPUInstanceFlag flags;
    143     WGPUDx12Compiler dx12ShaderCompiler;
    144     WGPUGles3MinorVersion gles3MinorVersion;
    145     WGPUGLFenceBehaviour glFenceBehaviour;
    146     WGPUStringView dxilPath;
    147     WGPUStringView dxcPath;
    148     WGPUDxcMaxShaderModel dxcMaxShaderModel;
    149 } WGPUInstanceExtras;
    150 
    151 typedef struct WGPUDeviceExtras {
    152     WGPUChainedStruct chain;
    153     WGPUStringView tracePath;
    154 } WGPUDeviceExtras;
    155 
    156 typedef struct WGPUNativeLimits {
    157     /** This struct chain is used as mutable in some places and immutable in others. */
    158     WGPUChainedStructOut chain;
    159     uint32_t maxPushConstantSize;
    160     uint32_t maxNonSamplerBindings;
    161 } WGPUNativeLimits;
    162 
    163 typedef struct WGPUPushConstantRange {
    164     WGPUShaderStage stages;
    165     uint32_t start;
    166     uint32_t end;
    167 } WGPUPushConstantRange;
    168 
    169 typedef struct WGPUPipelineLayoutExtras {
    170     WGPUChainedStruct chain;
    171     size_t pushConstantRangeCount;
    172     WGPUPushConstantRange const * pushConstantRanges;
    173 } WGPUPipelineLayoutExtras;
    174 
    175 typedef uint64_t WGPUSubmissionIndex;
    176 
    177 typedef struct WGPUShaderDefine {
    178     WGPUStringView name;
    179     WGPUStringView value;
    180 } WGPUShaderDefine;
    181 
    182 typedef struct WGPUShaderSourceGLSL {
    183     WGPUChainedStruct chain;
    184     WGPUShaderStage stage;
    185     WGPUStringView code;
    186     uint32_t defineCount;
    187     WGPUShaderDefine * defines;
    188 } WGPUShaderSourceGLSL;
    189 
    190 typedef struct WGPUShaderModuleDescriptorSpirV {
    191     WGPUStringView label;
    192     uint32_t sourceSize;
    193     uint32_t const * source;
    194 } WGPUShaderModuleDescriptorSpirV;
    195 
    196 typedef struct WGPURegistryReport {
    197    size_t numAllocated;
    198    size_t numKeptFromUser;
    199    size_t numReleasedFromUser;
    200    size_t elementSize;
    201 } WGPURegistryReport;
    202 
    203 typedef struct WGPUHubReport {
    204     WGPURegistryReport adapters;
    205     WGPURegistryReport devices;
    206     WGPURegistryReport queues;
    207     WGPURegistryReport pipelineLayouts;
    208     WGPURegistryReport shaderModules;
    209     WGPURegistryReport bindGroupLayouts;
    210     WGPURegistryReport bindGroups;
    211     WGPURegistryReport commandBuffers;
    212     WGPURegistryReport renderBundles;
    213     WGPURegistryReport renderPipelines;
    214     WGPURegistryReport computePipelines;
    215     WGPURegistryReport pipelineCaches;
    216     WGPURegistryReport querySets;
    217     WGPURegistryReport buffers;
    218     WGPURegistryReport textures;
    219     WGPURegistryReport textureViews;
    220     WGPURegistryReport samplers;
    221 } WGPUHubReport;
    222 
    223 typedef struct WGPUGlobalReport {
    224     WGPURegistryReport surfaces;
    225     WGPUHubReport hub;
    226 } WGPUGlobalReport;
    227 
    228 typedef struct WGPUInstanceEnumerateAdapterOptions {
    229     WGPUChainedStruct const * nextInChain;
    230     WGPUInstanceBackend backends;
    231 } WGPUInstanceEnumerateAdapterOptions;
    232 
    233 typedef struct WGPUBindGroupEntryExtras {
    234     WGPUChainedStruct chain;
    235     WGPUBuffer const * buffers;
    236     size_t bufferCount;
    237     WGPUSampler const * samplers;
    238     size_t samplerCount;
    239     WGPUTextureView const * textureViews;
    240     size_t textureViewCount;
    241 } WGPUBindGroupEntryExtras;
    242 
    243 typedef struct WGPUBindGroupLayoutEntryExtras {
    244     WGPUChainedStruct chain;
    245     uint32_t count;
    246 } WGPUBindGroupLayoutEntryExtras;
    247 
    248 typedef struct WGPUQuerySetDescriptorExtras {
    249     WGPUChainedStruct chain;
    250     WGPUPipelineStatisticName const * pipelineStatistics;
    251     size_t pipelineStatisticCount;
    252 } WGPUQuerySetDescriptorExtras WGPU_STRUCTURE_ATTRIBUTE;
    253 
    254 typedef struct WGPUSurfaceConfigurationExtras {
    255     WGPUChainedStruct chain;
    256     uint32_t desiredMaximumFrameLatency;
    257 } WGPUSurfaceConfigurationExtras WGPU_STRUCTURE_ATTRIBUTE;
    258 
    259 typedef void (*WGPULogCallback)(WGPULogLevel level, WGPUStringView message, void * userdata);
    260 
    261 typedef enum WGPUNativeTextureFormat {
    262     // From Features::TEXTURE_FORMAT_16BIT_NORM
    263     WGPUNativeTextureFormat_R16Unorm = 0x00030001,
    264     WGPUNativeTextureFormat_R16Snorm = 0x00030002,
    265     WGPUNativeTextureFormat_Rg16Unorm = 0x00030003,
    266     WGPUNativeTextureFormat_Rg16Snorm = 0x00030004,
    267     WGPUNativeTextureFormat_Rgba16Unorm = 0x00030005,
    268     WGPUNativeTextureFormat_Rgba16Snorm = 0x00030006,
    269     // From Features::TEXTURE_FORMAT_NV12
    270     WGPUNativeTextureFormat_NV12 = 0x00030007,
    271 } WGPUNativeTextureFormat;
    272 
    273 #ifdef __cplusplus
    274 extern "C" {
    275 #endif
    276 
    277 void wgpuGenerateReport(WGPUInstance instance, WGPUGlobalReport * report);
    278 size_t wgpuInstanceEnumerateAdapters(WGPUInstance instance, WGPU_NULLABLE WGPUInstanceEnumerateAdapterOptions const * options, WGPUAdapter * adapters);
    279 
    280 WGPUSubmissionIndex wgpuQueueSubmitForIndex(WGPUQueue queue, size_t commandCount, WGPUCommandBuffer const * commands);
    281 
    282 // Returns true if the queue is empty, or false if there are more queue submissions still in flight.
    283 WGPUBool wgpuDevicePoll(WGPUDevice device, WGPUBool wait, WGPU_NULLABLE WGPUSubmissionIndex const * submissionIndex);
    284 WGPUShaderModule wgpuDeviceCreateShaderModuleSpirV(WGPUDevice device, WGPUShaderModuleDescriptorSpirV const * descriptor);
    285 
    286 void wgpuSetLogCallback(WGPULogCallback callback, void * userdata);
    287 
    288 void wgpuSetLogLevel(WGPULogLevel level);
    289 
    290 uint32_t wgpuGetVersion(void);
    291 
    292 void wgpuRenderPassEncoderSetPushConstants(WGPURenderPassEncoder encoder, WGPUShaderStage stages, uint32_t offset, uint32_t sizeBytes, void const * data);
    293 void wgpuComputePassEncoderSetPushConstants(WGPUComputePassEncoder encoder, uint32_t offset, uint32_t sizeBytes, void const * data);
    294 void wgpuRenderBundleEncoderSetPushConstants(WGPURenderBundleEncoder encoder, WGPUShaderStage stages, uint32_t offset, uint32_t sizeBytes, void const * data);
    295 
    296 void wgpuRenderPassEncoderMultiDrawIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
    297 void wgpuRenderPassEncoderMultiDrawIndexedIndirect(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, uint32_t count);
    298 
    299 void wgpuRenderPassEncoderMultiDrawIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count);
    300 void wgpuRenderPassEncoderMultiDrawIndexedIndirectCount(WGPURenderPassEncoder encoder, WGPUBuffer buffer, uint64_t offset, WGPUBuffer count_buffer, uint64_t count_buffer_offset, uint32_t max_count);
    301 
    302 void wgpuComputePassEncoderBeginPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
    303 void wgpuComputePassEncoderEndPipelineStatisticsQuery(WGPUComputePassEncoder computePassEncoder);
    304 void wgpuRenderPassEncoderBeginPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
    305 void wgpuRenderPassEncoderEndPipelineStatisticsQuery(WGPURenderPassEncoder renderPassEncoder);
    306 
    307 void wgpuComputePassEncoderWriteTimestamp(WGPUComputePassEncoder computePassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
    308 void wgpuRenderPassEncoderWriteTimestamp(WGPURenderPassEncoder renderPassEncoder, WGPUQuerySet querySet, uint32_t queryIndex);
    309 
    310 #ifdef __cplusplus
    311 } // extern "C"
    312 #endif
    313 
    314 #endif