diff --git a/libraries/webgpu.c3l/README.md b/libraries/webgpu.c3l/README.md new file mode 100644 index 0000000..2057c9a --- /dev/null +++ b/libraries/webgpu.c3l/README.md @@ -0,0 +1,4 @@ +Bindings for the WebGPU native headers: https://github.com/webgpu-native/webgpu-headers + +Applications require linking a WebGPU implementation like wgpu-native or Dawn. + diff --git a/libraries/webgpu.c3l/adapter.c3 b/libraries/webgpu.c3l/adapter.c3 new file mode 100644 index 0000000..5ed73b4 --- /dev/null +++ b/libraries/webgpu.c3l/adapter.c3 @@ -0,0 +1,22 @@ +module webgpu; + +fn Device! Adapter.requestDevice(Adapter adapter, DeviceDescriptor* descriptor = null) { + + Device device = null; + + RequestDeviceCallback callback = fn void (RequestDeviceStatus status, + Device device, ZString message, UserData result) { + + if(status == SUCCESS) { + *(Device*) result = device; + } + }; + + adapter.requestDeviceAsync(descriptor, callback, &device); + + if(device) { + return device; + } else { + return DeviceError.REQUEST_FAILED?; + } +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/adapter.c3i b/libraries/webgpu.c3l/adapter.c3i new file mode 100644 index 0000000..5147b6a --- /dev/null +++ b/libraries/webgpu.c3l/adapter.c3i @@ -0,0 +1,84 @@ +module webgpu; + +distinct Adapter = void*; + +fault AdapterError { + REQUEST_FAILED +} + +fn usz Adapter.enumerateFeatures(Adapter adapter, FeatureName* features) @extern("wgpuAdapterEnumerateFeatures"); + +fn CBool Adapter.getLimits(Adapter adapter, SupportedLimits* limits) @extern("wgpuAdapterGetLimits"); + +fn void Adapter.getProperties(Adapter adapter, AdapterProperties* properties) @extern("wgpuAdapterGetProperties"); + +fn CBool Adapter.hasFeature(Adapter adapter, FeatureName feature) @extern("wgpuAdapterHasFeature"); + +fn void Adapter.requestAdapterInfo(Adapter adapter, RequestAdapterInfoCallback callback, UserData data) @extern("wgpuAdapterRequestAdapterInfo"); + +fn void Adapter.requestDeviceAsync(Adapter adapter, + DeviceDescriptor* descriptor, RequestDeviceCallback callback, + UserData data) @extern("wgpuAdapterRequestDevice"); + +fn void Adapter.reference(Adapter adapter) @extern("wgpuAdapterReference"); + +fn void Adapter.release(Adapter adapter) @extern("wgpuAdapterRelease"); + + +def RequestAdapterInfoCallback = fn void(AdapterInfo info, UserData data); + +def RequestDeviceCallback = fn void (RequestDeviceStatus status, + Device device, ZString message, UserData data); + +enum AdapterType { + DISCRETE_GPU, + INTEGRATED_GPU, + CPU, + UNKNOWN +} + +struct AdapterInfo { + ZString vendor; + ZString architecture; + ZString device; + ZString description; +} + +struct AdapterProperties { + ChainedStructOut* next; + CUInt vendorID; + ZString vendorName; + ZString architecture; + CUInt deviceID; + ZString name; + ZString driverDescription; + AdapterType adapterType; + BackendType backendType; +} + +struct RequestAdapterOptions { + ChainedStruct* next; + Surface compatibleSurface; + PowerPreference powerPreference; + BackendType backendType; + CBool forceFallbackAdapter; +} + + +enum PowerPreference { + UNDEFINED, + LOW_POWER, + HIGH_PERFORMANCE +} + +enum BackendType { + UNDEFINED, + NULL, + WEBGPU, + D3_D11, + D3_D12, + METAL, + VULKAN, + OPENGL, + OPENGL_ES +} diff --git a/libraries/webgpu.c3l/bindgroup.c3i b/libraries/webgpu.c3l/bindgroup.c3i new file mode 100644 index 0000000..2e68257 --- /dev/null +++ b/libraries/webgpu.c3l/bindgroup.c3i @@ -0,0 +1,28 @@ +module webgpu; + +distinct BindGroup = void*; + +fn void BindGroup.setLabel(BindGroup bindGroup, ZString label) @extern("wgpuBindGroupSetLabel"); + +fn void BindGroup.reference(BindGroup bindGroup) @extern("wgpuBindGroupReference"); + +fn void BindGroup.release(BindGroup bindGroup) @extern("wgpuBindGroupRelease"); + + +struct BindGroupDescriptor { + ChainedStruct* next; + ZString label; + BindGroupLayout layout; + usz entryCount; + BindGroupEntry* entries; +} + +struct BindGroupEntry { + ChainedStruct* next; + CUInt binding; + Buffer buffer; + CULong offset; + CULong size; + Sampler sampler; + TextureView textureView; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/bindgroup_layout.c3i b/libraries/webgpu.c3l/bindgroup_layout.c3i new file mode 100644 index 0000000..da69e27 --- /dev/null +++ b/libraries/webgpu.c3l/bindgroup_layout.c3i @@ -0,0 +1,76 @@ +module webgpu; + +distinct BindGroupLayout = inline void*; + +fn void BindGroupLayout.setLabel(BindGroupLayout layout, ZString label) @extern("wgpuBindGroupLayoutSetLabel"); + +fn void BindGroupLayout.reference(BindGroupLayout layout) @extern("wgpuBindGroupLayoutReference"); + +fn void BindGroupLayout.release(BindGroupLayout layout) @extern("wgpuBindGroupLayoutRelease"); + + +struct BindGroupLayoutDescriptor { + ChainedStruct* next; + ZString label; + usz entryCount; + BindGroupLayoutEntry* entries; +} + +struct BindGroupLayoutEntry { + ChainedStruct* next; + CUInt binding; + ShaderStage visibility; + BufferBindingLayout buffer; + SamplerBindingLayout sampler; + TextureBindingLayout texture; + StorageTextureBindingLayout storageTexture; +} + +struct BufferBindingLayout { + ChainedStruct* next; + BufferBindingType type; + CBool hasDynamicOffset; + CULong minBindingSize; +} + +struct TextureBindingLayout { + ChainedStruct* next; + TextureSampleType sampleType; + TextureViewDimension viewDimension; + CBool multisampled; +} + +struct SamplerBindingLayout { + ChainedStruct* next; + SamplerBindingType type; +} + +bitstruct ShaderStage: CInt { + bool vertex; + bool fragment; + bool compute; +} + + +enum BufferBindingType { + UNDEFINED, + UNIFORM, + STORAGE, + READONLY_STORAGE +} + +enum TextureSampleType { + UNDEFINED, + FLOAT, + UNFILTERABLE_FLOAT, + DEPTH, + SINT, + UINT +} + +enum SamplerBindingType { + UNDEFINED, + FILTERING, + NON_FILTERING, + COMPARISON +} diff --git a/libraries/webgpu.c3l/buffer.c3i b/libraries/webgpu.c3l/buffer.c3i new file mode 100644 index 0000000..2b38b43 --- /dev/null +++ b/libraries/webgpu.c3l/buffer.c3i @@ -0,0 +1,84 @@ +module webgpu; + +distinct Buffer = void*; + +fn void Buffer.destroy(Buffer buffer) @extern("wgpuBufferDestroy"); + +// wgpuBufferGetConstMappedRange left out, since C3 has no void const * + +fn BufferMapState Buffer.getMapState(Buffer buffer, usz offset, usz size) @extern("wgpuBufferGetMapState"); + +fn BufferMappedRange Buffer.getMappedRange(Buffer buffer) @extern("wgpuBufferGetMappedRange"); + +fn CULong Buffer.getSize(Buffer buffer) @extern("wgpuBufferGetSize"); + +fn BufferUsage Buffer.getUsage(Buffer buffer) @extern("wgpuBufferGetUsage"); + +fn void Buffer.mapAsync(Buffer buffer, MapMode mode, usz offset, usz size, + BufferMapAsyncCallback callback, UserData data) @extern("wgpuBufferMapAsync"); + +fn void Buffer.setLabel(Buffer buffer, ZString label) @extern("wgpuBufferSetLabel"); + +fn void Buffer.unmap(Buffer buffer) @extern("wgpuBufferUnmap"); + +fn void Buffer.reference(Buffer buffer) @extern("wgpuBufferReference"); + +fn void Buffer.release(Buffer buffer) @extern("wgpuBufferRelease"); + + +def BufferMapAsyncCallback = fn void(BufferMapAsyncStatus status, UserData data); + +distinct BufferMappedRange = void*; + + +struct BufferDescriptor { + ChainedStruct* next; + ZString label; + BufferUsage usage; + CULong size; + CBool mappedAtCreation; +} + +struct ImageCopyBuffer { + ChainedStruct* next; + TextureDataLayout layout; + Buffer buffer; +} + +bitstruct BufferUsage : CInt { + bool mapRead; + bool mapWrite; + bool copySource; + bool copyDestination; + bool index; + bool vertex; + bool uniform; + bool storage; + bool indirect; + bool queryResolve; +} + + +enum BufferMapAsyncStatus { + SUCCESS, + VALIDATION_ERROR, + UNKNOWN, + DEVICE_LOST, + DESTROYED_BEFORE_CALLBACK, + UNMAPPED_BEFORE_CALLBACK, + MAPPING_ALREADY_PENDING, + OFFSET_OUT_OF_RANGE, + SIZE_OUT_OF_RANGE +} + +enum BufferMapState { + UNMAPPED, + PENDING, + MAPPED +} + +enum MapMode { + NONE, + READ, + WRITE +} diff --git a/libraries/webgpu.c3l/chain.c3i b/libraries/webgpu.c3l/chain.c3i new file mode 100644 index 0000000..e163f83 --- /dev/null +++ b/libraries/webgpu.c3l/chain.c3i @@ -0,0 +1,26 @@ +module webgpu; + +enum SType { + INVALID, + SURFACE_DESCRIPTOR_FROM_METAL_LAYER, + SURFACE_DESCRIPTOR_FROM_WINDOWS_HWND, + SURFACE_DESCRIPTOR_FROM_XLIB_WINDOW, + SURFACE_DESCRIPTOR_FROM_CANVAS_HTML_SELECTOR, + SHADER_MODULE_SPIRV_DESCRIPTOR, + SHADER_MODULE_WGSL_DESCRIPTOR, + PRIMITIVE_DEPTH_CLIP_CONTROL, + SURFACE_DESCRIPTOR_FROM_WAYLAND_SURFACE, + SURFACE_DESCRIPTOR_FROM_ANDROID_NATIVE_WINDOW, + SURFACE_DESCRIPTOR_FROM_XCB_WINDOW, + RENDER_PASS_DESCRIPTOR_MAX_DRAW_COUNT +} + +struct ChainedStruct { + ChainedStruct* next; + SType sType; +} + +struct ChainedStructOut { + ChainedStructOut* next; + SType sType; +} diff --git a/libraries/webgpu.c3l/command_buffer.c3i b/libraries/webgpu.c3l/command_buffer.c3i new file mode 100644 index 0000000..a45e401 --- /dev/null +++ b/libraries/webgpu.c3l/command_buffer.c3i @@ -0,0 +1,15 @@ +module webgpu; + +distinct CommandBuffer = void*; + +fn void CommandBuffer.setLabel(CommandBuffer buffer, ZString label) @extern("wgpuCommandBufferSetLabel"); + +fn void CommandBuffer.reference(CommandBuffer buffer) @extern("wgpuCommandBufferReference"); + +fn void CommandBuffer.release(CommandBuffer buffer) @extern("wgpuCommandBufferRelease"); + + +struct CommandBufferDescriptor { + ChainedStruct* next; + ZString label; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/command_encoder.c3i b/libraries/webgpu.c3l/command_encoder.c3i new file mode 100644 index 0000000..e1f7a4e --- /dev/null +++ b/libraries/webgpu.c3l/command_encoder.c3i @@ -0,0 +1,60 @@ +module webgpu; + +distinct CommandEncoder = void*; + +fn ComputePassEncoder CommandEncoder.beginComputePass(CommandEncoder encoder, + ComputePassDescriptor* descriptor) @extern("wgpuCommandEncoderBeginComputePass"); + +fn RenderPassEncoder CommandEncoder.beginRenderPass(CommandEncoder encoder, + RenderPassDescriptor* descriptor) @extern("wgpuCommandEncoderBeginRenderPass"); + +fn void CommandEncoder.clearBuffer(CommandEncoder encoder, + Buffer buffer, CULong offset, CULong size) @extern("wgpuCommandEncoderClearBuffer"); + +fn void CommandEncoder.copyBufferToBuffer(CommandEncoder encoder, + Buffer source, CULong sourceOffset, Buffer destination, CULong destinationOffset, CULong size) + @extern("wgpuCommandEncoderCopyBufferToBuffer"); + +fn void CommandEncoder.copyBufferToTexture(CommandEncoder encoder, + ImageCopyBuffer* source, ImageCopyTexture* destination, Extent3D size) + @extern("wgpuCommandEncoderCopyBufferToTexture"); + +fn void CommandEncoder.copyTextureToBuffer(CommandEncoder encoder, + ImageCopyTexture* source, ImageCopyBuffer* destination, Extent3D size) + @extern("wgpuCommandEncoderCopyTextureToBuffer"); + +fn void CommandEncoder.copyTextureToTexture(CommandEncoder encoder, + ImageCopyTexture* source, ImageCopyTexture* destination, Extent3D size) + @extern("wgpuCommandEncoderCopyTextureToTexture"); + +fn CommandBuffer CommandEncoder.finish(CommandEncoder encoder, + CommandBufferDescriptor* descriptor = null) @extern("wgpuCommandEncoderFinish"); + +fn void CommandEncoder.insertDebugMarker(CommandEncoder encoder, + ZString label) @extern("wgpuCommandEncoderInsertDebugMarker"); + +fn void CommandEncoder.popDebugGroup(CommandEncoder encoder) + @extern("wgpuCommandEncoderPopDebugGroup"); + +fn void CommandEncoder.pushDebugGroup(CommandEncoder encoder, ZString label) + @extern("wgpuCommandEncoderPushDebugGroup"); + +fn void CommandEncoder.resolveQuerySet(CommandEncoder encoder, + QuerySet querySet, CUInt first, CUInt count, Buffer destination, usz offset) + @extern("wgpuCommandEncoderResolveQuerySet"); + +fn void CommandEncoder.setLabel(CommandEncoder encoder, ZString label) + @extern("wgpuCommandEncoderSetLabel"); + +fn void CommandEncoder.writeTimestamp(CommandEncoder encoder, QuerySet querySet, CUInt index) + @extern("wgpuCommandEncoderWriteTimestamp"); + +fn void CommandEncoder.reference(CommandEncoder encoder) @extern("wgpuCommandEncoderReference"); + +fn void CommandEncoder.release(CommandEncoder encoder) @extern("wgpuCommandEncoderRelease"); + + +struct CommandEncoderDescriptor { + ChainedStruct* next; + ZString label; +} diff --git a/libraries/webgpu.c3l/compute_pass_encoder.c3i b/libraries/webgpu.c3l/compute_pass_encoder.c3i new file mode 100644 index 0000000..22703c8 --- /dev/null +++ b/libraries/webgpu.c3l/compute_pass_encoder.c3i @@ -0,0 +1,46 @@ +module webgpu; + +distinct ComputePassEncoder = void*; + +fn void ComputePassEncoder.dispatchWorkgroups(ComputePassEncoder encoder, + CUInt countX, CUInt countY, CUInt countZ) @extern("wgpuComputePassEncoderDispatchWorkgroups"); + +fn void ComputePassEncoder.dispatchWorkgroupsIndirect(ComputePassEncoder encoder, + Buffer buffer, CULong offset) @extern("wgpuComputePassEncoderDispatchWorkgroupsIndirect"); + +fn void ComputePassEncoder.end(ComputePassEncoder encoder) @extern("wgpuComputePassEncoderEnd"); + +fn void ComputePassEncoder.insertDebugMarker(ComputePassEncoder encoder, + ZString label) @extern("wgpuComputePassEncoderInsertDebugMarker"); + +fn void ComputePassEncoder.popDebugGroup(ComputePassEncoder encoder) + @extern("wgpuComputePassEncoderPopDebugGroup"); + +fn void ComputePassEncoder.pushDebugGroup(ComputePassEncoder encoder, ZString label) + @extern("wgpuComputePassEncoderPushDebugGroup"); + +fn void ComputePassEncoder.setBindGroup(ComputePassEncoder encoder, CUInt groupIndex) + @extern("wgpuComputePassEncoderSetBindGroup"); + +fn void ComputePassEncoder.setLabel(ComputePassEncoder encoder, ZString label) + @extern("wgpuComputePassEncoderSetLabel"); + +fn void ComputePassEncoder.setPipeline(ComputePassEncoder encoder, ComputePipeline pipeline) + @extern("wgpuComputePassEncoderSetPipeline"); + +fn void ComputePassEncoder.reference(ComputePassEncoder encoder) @extern("wgpuComputePassEncoderReference"); + +fn void ComputePassEncoder.release(ComputePassEncoder encoder) @extern("wgpuComputePassEncoderRelease"); + + +struct ComputePassTimestampWrites { + QuerySet querySet; + CUInt beginningOfPassWriteIndex; + CUInt endOfPassWriteIndex; +} + +struct ComputePassDescriptor { + ChainedStruct* next; + ZString label; + ComputePassTimestampWrites* timestampWrites; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/compute_pipeline.c3i b/libraries/webgpu.c3l/compute_pipeline.c3i new file mode 100644 index 0000000..d4bf328 --- /dev/null +++ b/libraries/webgpu.c3l/compute_pipeline.c3i @@ -0,0 +1,28 @@ +module webgpu; + +distinct ComputePipeline = void*; + +fn void ComputePipeline.setBindGroupLayout(ComputePipeline pipeline, CUInt groupIndex) + @extern("wgpuComputePipelineSetBindGroup"); + +fn void ComputePipeline.setLabel(ComputePipeline pipeline, ZString label) + @extern("wgpuComputePipelineSetLabel"); + +fn void ComputePipeline.reference(ComputePipeline pipeline) @extern("wgpuComputePipelineReference"); + +fn void ComputePipeline.release(ComputePipeline pipeline) @extern("wgpuComputePipelineRelease"); + +struct ComputePipelineDescriptor { + ChainedStruct* next; + ZString label; + PipelineLayout layout; + ProgrammableStageDescriptor compute; +} + +struct ProgrammableStageDescriptor { + ChainedStruct* next; + ShaderModule shader; + ZString entryPoint; + usz constantCount; + ConstantEntry* constants; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/device.c3i b/libraries/webgpu.c3l/device.c3i new file mode 100644 index 0000000..da594a4 --- /dev/null +++ b/libraries/webgpu.c3l/device.c3i @@ -0,0 +1,189 @@ +module webgpu; + +distinct Device = void*; + +fault DeviceError { + REQUEST_FAILED +} + +fn void* getProcAddress(Device device, ZString name) @extern("wgpuGetProcAddress"); + +fn BindGroup Device.createBindGroup(Device device, BindGroupDescriptor* descriptor) @extern("wgpuDeviceCreateBindGroup"); + +fn BindGroupLayout Device.createBindGroupLayout(Device device, BindGroupLayoutDescriptor* descriptor) @extern("wgpuDeviceCreateBindGroupLayout"); + +fn Buffer Device.createBuffer(Device device, BufferDescriptor* descriptor) @extern("wgpuDeviceCreateBuffer"); + +fn CommandEncoder Device.createCommandEncoder(Device device, CommandEncoderDescriptor* descriptor = null) @extern("wgpuDeviceCreateCommandEncoder"); + +fn ComputePipeline Device.createComputePipeline(Device device, ComputePipelineDescriptor* descriptor) @extern("wgpuDeviceCreateComputePipeline"); + +fn void Device.createComputePipelineAsync(Device device, ComputePipelineDescriptor* descriptor, + CreateComputePipelineAsyncCallback callback) @extern("wgpuDeviceCreateComputePipelineAsync"); + +fn PipelineLayout Device.createPipelineLayout(Device device, PipelineLayoutDescriptor* descriptor) @extern("wgpuDeviceCreatePipelineLayout"); + +fn QuerySet Device.createQuerySet(Device device, QuerySetDescriptor* descriptor) @extern("wgpuDeviceCreateQuerySet"); + +fn RenderBundleEncoder Device.createRenderBundleEncoder(Device device, RenderBundleEncoderDescriptor* descriptor) @extern("wgpuDeviceCreateRenderBundleEncoder"); + +fn RenderPipeline Device.createRenderPipeline(Device device, RenderPipelineDescriptor* descriptor) @extern("wgpuDeviceCreateRenderPipeline"); + +fn void Device.createRenderPipelineAsync(Device device, RenderPipelineDescriptor* descriptor, + CreateRenderPipelineAsyncCallback callback) @extern("wgpuDeviceCreateRenderPipelineAsync"); + +fn Sampler Device.createSampler(Device device, SamplerDescriptor* descriptor) @extern("wgpuDeviceCreateSampler"); + +fn ShaderModule Device.createShaderModule(Device device, ShaderModuleDescriptor* descriptor) @extern("wgpuDeviceCreateShaderModule"); + +fn Texture Device.createTexture(Device device, TextureDescriptor* descriptor) @extern("wgpuDeviceCreateTexture"); + +fn void Device.destroy(Device device) @extern("wgpuDeviceDestroy"); + +fn usz Device.enumerateFeatures(Device device, FeatureName* features) @extern("wgpuDeviceEnumerateFeatures"); + +fn CBool Device.getLimits(Device device, SupportedLimits* limits) @extern("wgpuDeviceGetLimits"); + +fn Queue Device.getQueue(Device device) @extern("wgpuDeviceGetQueue"); + +fn CBool Device.hasFeature(Device device, FeatureName feature) @extern("wgpuDeviceHasFeature"); + +fn void Device.popErrorScope(Device device, ErrorCallback callback) @extern("wgpuDevicePopErrorScope"); + +fn void Device.pushErrorScope(Device device, ErrorFilter filter) @extern("wgpuDevicePushErrorScope"); + +fn void Device.setLabel(Device device, ZString label) @extern("wgpuDeviceSetLabel"); + +fn void Device.setUncapturedErrorCallback(Device device, ErrorCallback callback) @extern("wgpuDeviceSetUncapturedErrorCallback"); + +fn void Device.reference(Device device) @extern("wgpuDeviceReference"); + +fn void Device.release(Device device) @extern("wgpuDeviceRelease"); + + +def DeviceLostCallback = fn void (DeviceLostReason reason, ZString message, UserData data); + +def ErrorCallback = fn void(ErrorType type, ZString message, UserData data); + +def CreateDeviceAsyncCallback = fn void(CreatePipelineAsyncStatus status, + Device device, ZString message, UserData data); + +def CreateRenderPipelineAsyncCallback = fn void(CreatePipelineAsyncStatus status, + RenderPipeline pipeline, ZString message, UserData data); + +def CreateComputePipelineAsyncCallback = fn void(CreatePipelineAsyncStatus status, + ComputePipeline pipeline, ZString message, UserData data); + +struct DeviceDescriptor { + ChainedStruct* next; + ZString label; + usz requiredFeatureCount; + FeatureName* requiredFeatures; + RequiredLimits* requiredLimits; + QueueDescriptor defaultQueue; + DeviceLostCallback deviceLostCallback; + UserData deviceLostUserdata; + UncapturedErrorCallbackInfo uncapturedErrorCallbackInfo; +} + +struct RequiredLimits { + ChainedStruct* next; + Limits limits; +} + +struct SupportedLimits { + ChainedStruct* next; + Limits limits; +} + +struct Limits { + CUInt maxTextureDimension1D; + CUInt maxTextureDimension2D; + CUInt maxTextureDimension3D; + CUInt maxTextureArrayLayers; + CUInt maxBindGroups; + CUInt maxBindGroupsPlusVertexBuffers; + CUInt maxBindingsPerBindGroup; + CUInt maxDynamicUniformBuffersPerPipelineLayout; + CUInt maxDynamicStorageBuffersPerPipelineLayout; + CUInt maxSampledTexturesPerShaderStage; + CUInt maxSamplersPerShaderStage; + CUInt maxStorageBuffersPerShaderStage; + CUInt maxStorageTexturesPerShaderStage; + CUInt maxUniformBuffersPerShaderStage; + CULong maxUniformBufferBindingSize; + CULong maxStorageBufferBindingSize; + CUInt minUniformBufferOffsetAlignment; + CUInt minStorageBufferOffsetAlignment; + CUInt maxVertexBuffers; + CULong maxBufferSize; + CUInt maxVertexAttributes; + CUInt maxVertexBufferArrayStride; + CUInt maxInterStageShaderComponents; + CUInt maxInterStageShaderVariables; + CUInt maxColorAttachments; + CUInt maxColorAttachmentBytesPerSample; + CUInt maxComputeWorkgroupStorageSize; + CUInt maxComputeInvocationsPerWorkgroup; + CUInt maxComputeWorkgroupSizeX; + CUInt maxComputeWorkgroupSizeY; + CUInt maxComputeWorkgroupSizeZ; + CUInt maxComputeWorkgroupsPerDimension; +} + +struct UncapturedErrorCallbackInfo { + ChainedStruct* next; + ErrorCallback callback; + UserData userData; +} + + +enum FeatureName { + UNDEFINED, + DEPTH_CLIP_CONTROL, + DEPTH_32FLOAT_STENCIL_8, + TIMESTAMP_QUERY, + TEXTURE_COMPRESSION_BC, + TEXTURE_COMPRESSION_ETC2, + TEXTURE_COMPRESSION_ASTC, + INDIRECT_FIRST_INSTANCE, + SHADER_F16, + RG11_B10_UFLOAT_RENDERABLE, + BGRA_8UNORM_STORAGE, + FLOAT32_FILTERABLE +} + +enum CreatePipelineAsyncStatus { + SUCCESS, + VALIDATION_ERROR, + INTERNAL_ERROR, + DEVICE_LOST, + DEVICE_DESTROYED, + UNKNOWN +} + +enum RequestDeviceStatus { + SUCCESS, + ERROR, + UNKNOWN +} + +enum DeviceLostReason { + UNDEFINED, + DESTROYED +} + +enum ErrorFilter { + VALIDATION, + OUT_OF_MEMORY, + INTERNAL +} + +enum ErrorType { + NO_ERROR, + VALIDATION, + OUT_OF_MEMORY, + INTERNAL, + UNKNOWN, + DEVICE_LOST +} diff --git a/libraries/webgpu.c3l/instance.c3 b/libraries/webgpu.c3l/instance.c3 new file mode 100644 index 0000000..14fc64b --- /dev/null +++ b/libraries/webgpu.c3l/instance.c3 @@ -0,0 +1,23 @@ +module webgpu; +import std::io; + +fn Adapter! Instance.requestAdapter(Instance instance, RequestAdapterOptions* options) { + + Adapter adapter = null; + + RequestAdapterCallback callback = fn void(RequestAdapterStatus status, + Adapter adapter, ZString message, UserData result) { + + if(status == SUCCESS) { + *(Adapter*) result = adapter; + } + }; + + instance.requestAdapterAsync(options, callback, &adapter); + + if(adapter) { + return adapter; + } else { + return AdapterError.REQUEST_FAILED?; + } +} diff --git a/libraries/webgpu.c3l/instance.c3i b/libraries/webgpu.c3l/instance.c3i new file mode 100644 index 0000000..1355a7c --- /dev/null +++ b/libraries/webgpu.c3l/instance.c3i @@ -0,0 +1,44 @@ +module webgpu; + +distinct Instance = void*; + +fn Surface Instance.createSurface(Instance instance, + SurfaceDescriptor* descriptor) @extern("wgpuInstanceCreateSurface"); + +fn Instance createInstance(InstanceDescriptor* descriptor = null) @extern("wgpuCreateInstance"); + +fn void Instance.hasWGSLLanguageFeature(Instance instance, WgslFeatureName feature) @extern("wgpuInstanceHasWGSLLanguageFeature"); + +fn void Instance.processEvents(Instance instance) @extern("wgpuInstanceProcessEvents"); + +fn void Instance.requestAdapterAsync(Instance instance, RequestAdapterOptions* options, + RequestAdapterCallback callback, UserData data) @extern("wgpuInstanceRequestAdapter"); + +fn void Instance.reference(Instance instance) @extern("wgpuInstanceReference"); + +fn void Instance.release(Instance instance) @extern("wgpuInstanceRelease"); + + +def RequestAdapterCallback = fn void(RequestAdapterStatus status, + Adapter adapter, ZString message, UserData result); + + +struct InstanceDescriptor { + ChainedStruct* next; +} + + +enum RequestAdapterStatus { + SUCCESS, + UNAVAILABLE, + ERROR, + UNKNOWN +} + +enum WgslFeatureName { + UNDEFINED, + READONLY_AND_READWRITE_STORAGE_TEXTURES, + PACKED_4X8_INTEGER_DOT_PRODUCT, + UNRESTRICTED_POINTER_PARAMETERS, + POINTER_COMPOSITE_ACCESS +} diff --git a/libraries/webgpu.c3l/manifest.json b/libraries/webgpu.c3l/manifest.json new file mode 100644 index 0000000..ebda960 --- /dev/null +++ b/libraries/webgpu.c3l/manifest.json @@ -0,0 +1,38 @@ +{ + "provides" : "webgpu", + "targets" : { + "android-aarch64" : { + "linked-libraries" : ["wgpu_native"] + }, + "ios-aarch64" : { + "linked-libraries" : ["wgpu_native"] + }, + "linux-aarch64" : { + "linked-libraries" : ["wgpu_native"] + }, + "linux-x86" : { + "linked-libraries" : ["wgpu_native"] + }, + "linux-x64" : { + "linked-libraries" : ["wgpu_native"] + }, + "macos-aarch64" : { + "linked-libraries" : ["wgpu_native"] + }, + "macos-x64" : { + "linked-libraries" : ["wgpu_native"] + }, + "windows-aarch64" : { + "linked-libraries" : ["wgpu_native"] + }, + "windows-x64" : { + "linked-libraries" : ["wgpu_native"] + }, + "wasm32" : { + "linked-libraries" : ["wgpu_native"] + }, + "wasm64" : { + "linked-libraries" : ["wgpu_native"] + } + } +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/pipeline_layout.c3i b/libraries/webgpu.c3l/pipeline_layout.c3i new file mode 100644 index 0000000..f3173ec --- /dev/null +++ b/libraries/webgpu.c3l/pipeline_layout.c3i @@ -0,0 +1,17 @@ +module webgpu; + +distinct PipelineLayout = void*; + +fn void PipelineLayout.setLabel(PipelineLayout layout, ZString label) @extern("wgpuPipelineLayoutSetLabel"); + +fn void PipelineLayout.reference(PipelineLayout layout) @extern("wgpuPipelineLayoutReference"); + +fn void PipelineLayout.release(PipelineLayout layout) @extern("wgpuPipelineLayoutRelease"); + + +struct PipelineLayoutDescriptor { + ChainedStruct* next; + ZString label; + usz bindGroupLayoutCount; + BindGroupLayout* bindGroupLayouts; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/queryset.c3i b/libraries/webgpu.c3l/queryset.c3i new file mode 100644 index 0000000..0021c5f --- /dev/null +++ b/libraries/webgpu.c3l/queryset.c3i @@ -0,0 +1,29 @@ +module webgpu; + +distinct QuerySet = void*; + + +fn void QuerySet.destroy(QuerySet querySet) @extern("wgpuQuerySetDestroy"); + +fn CUInt QuerySet.getCount(QuerySet querySet) @extern("wgpuQuerySetGetCount"); + +fn QueryType QuerySet.getType(QuerySet querySet) @extern("wgpuQuerySetGetType"); + +fn void QuerySet.setLabel(QuerySet querySet, ZString label) @extern("wgpuQuerySetSetLabel"); + +fn void QuerySet.reference(QuerySet querySet) @extern("wgpuQuerySetReference"); + +fn void QuerySet.release(QuerySet querySet) @extern("wgpuQuerySetRelease"); + + +struct QuerySetDescriptor { + ChainedStruct next; + ZString label; + QueryType type; + CUInt count; +} + +enum QueryType { + OCCLUSION, + TIMESTAMP +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/queue.c3i b/libraries/webgpu.c3l/queue.c3i new file mode 100644 index 0000000..f8d3657 --- /dev/null +++ b/libraries/webgpu.c3l/queue.c3i @@ -0,0 +1,38 @@ +module webgpu; + +distinct Queue = void*; + +def BufferData = void*; + +fn void Queue.onSubmittedWorkDone(Queue queue, SubmittedWorkDoneCallback callback, + UserData data) @extern("wgpuQueueOnSubmittedWorkDone"); + +fn void Queue.setLabel(Queue queue, ZString label) @extern("wgpuQueueSetLabel"); + +fn void Queue.submit(Queue queue, usz count, CommandBuffer* commands) @extern("wgpuQueueSubmit"); + +fn void Queue.writeBuffer(Queue queue, Buffer buffer, CULong bufferOffset, BufferData data, usz dataSize) @extern("wgpuQueueWriteBuffer"); + +fn void Queue.writeTexture(Queue queue, ImageCopyTexture* destination, BufferData data, usz dataSize, + TextureDataLayout* layout, Extent3D* writeSize) @extern("wgpuQueueWriteTexture"); + +fn void Queue.reference(Queue queue) @extern("wgpuQueueReference"); + +fn void Queue.release(Queue queue) @extern("wgpuQueueRelease"); + + +def SubmittedWorkDoneCallback = fn void(QueueWorkDoneStatus status, UserData data); + +struct QueueDescriptor { + ChainedStruct* next; + ZString label; +} + + +enum QueueWorkDoneStatus { + SUCCESS, + ERROR, + UNKNOWN, + DEVICE_LOST +} + diff --git a/libraries/webgpu.c3l/render_bundle.c3i b/libraries/webgpu.c3l/render_bundle.c3i new file mode 100644 index 0000000..3794e2d --- /dev/null +++ b/libraries/webgpu.c3l/render_bundle.c3i @@ -0,0 +1,15 @@ +module webgpu; + +distinct RenderBundle = void*; + +fn void RenderBundle.setLabel(RenderBundle bundle, ZString label) @extern("wgpuRenderBundleSetLabel"); + +fn void RenderBundle.reference(RenderBundle bundle) @extern("wgpuRenderBundleReference"); + +fn void RenderBundle.release(RenderBundle bundle) @extern("wgpuRenderBundleRelease"); + + +struct RenderBundleDescriptor { + ChainedStruct* next; + ZString label; +} diff --git a/libraries/webgpu.c3l/render_bundle_encoder.c3i b/libraries/webgpu.c3l/render_bundle_encoder.c3i new file mode 100644 index 0000000..b486849 --- /dev/null +++ b/libraries/webgpu.c3l/render_bundle_encoder.c3i @@ -0,0 +1,63 @@ +module webgpu; + +distinct RenderBundleEncoder = void*; + + +fn void RenderBundleEncoder.draw(RenderBundleEncoder encoder, + CUInt vertexCount, CUInt instanceCount, CUInt firstVertex = 0, CUInt firstInstance = 0) + @extern("wgpuRenderBundleEncoderDraw"); + +fn void RenderBundleEncoder.drawIndexed(RenderBundleEncoder encoder, + CUInt indexCount, CUInt instanceCount, CUInt firstIndex = 0, CInt baseVertex = 0, CUInt firstInstance = 0) + @extern("wgpuRenderBundleEncoderDrawIndexed"); + +fn void RenderBundleEncoder.drawIndexedIndirect(RenderBundleEncoder encoder, + Buffer buffer, CULong offset) @extern("wgpuRenderBundleEncoderDrawIndexedIndirect"); + +fn void RenderBundleEncoder.drawIndirect(RenderBundleEncoder encoder, + Buffer buffer, CULong offset) @extern("wgpuRenderBundleEncoderDrawIndirect"); + +fn RenderBundle RenderBundleEncoder.finish(RenderBundleEncoder encoder, + RenderBundleDescriptor* descriptor) @extern("wgpuRenderBundleEncoderFinish"); + +fn void RenderBundleEncoder.insertDebugMarker(RenderBundleEncoder encoder, + ZString label) @extern("wgpuRenderBundleEncoderInsertDebugMarker"); + +fn void RenderBundleEncoder.popDebugGroup(RenderBundleEncoder encoder) + @extern("wgpuRenderBundleEncoderPopDebugGroup"); + +fn void RenderBundleEncoder.pushDebugGroup(RenderBundleEncoder encoder, ZString label) + @extern("wgpuRenderBundleEncoderPushDebugGroup"); + +fn void RenderBundleEncoder.setBindGroup(RenderBundleEncoder encoder, CUInt index) + @extern("wgpuRenderBundleEncoderSetBindGroup"); + +fn void RenderBundleEncoder.setIndexBuffer(RenderBundleEncoder encoder, + Buffer buffer, IndexFormat format, CULong offset, CULong size) + @extern("wgpuRenderBundleEncoderSetIndexBuffer"); + +fn void RenderBundleEncoder.setLabel(RenderBundleEncoder encoder, ZString label) + @extern("wgpuRenderBundleEncoderSetLabel"); + +fn void RenderBundleEncoder.setPipeline(RenderBundleEncoder encoder, ComputePipeline pipeline) + @extern("wgpuRenderBundleEncoderSetPipeline"); + +fn void RenderBundleEncoder.setVertexBuffer(RenderBundleEncoder encoder, + CUInt slot, Buffer buffer, IndexFormat format, CULong offset, CULong size) + @extern("wgpuRenderBundleEncoderSetVertexBuffer"); + +fn void RenderBundleEncoder.reference(RenderBundleEncoder encoder) @extern("wgpuRenderBundleEncoderReference"); + +fn void RenderBundleEncoder.release(RenderBundleEncoder encoder) @extern("wgpuRenderBundleEncoderRelease"); + + +struct RenderBundleEncoderDescriptor { + ChainedStruct* next; + ZString label; + usz colorFormatCount; + TextureFormat* colorFormats; + TextureFormat depthStencilFormat; + CUInt sampleCount; + CBool depthReadOnly; + CBool stencilReadOnly; +} \ No newline at end of file diff --git a/libraries/webgpu.c3l/render_pass.c3i b/libraries/webgpu.c3l/render_pass.c3i new file mode 100644 index 0000000..dedcfca --- /dev/null +++ b/libraries/webgpu.c3l/render_pass.c3i @@ -0,0 +1,127 @@ +module webgpu; + +distinct RenderPassEncoder = void*; + + +fn void RenderPassEncoder.beginOcclusionQuery(RenderPassEncoder encoder, + CUInt queryIndex) @extern("wgpuRenderPassEncoderBeginOcclusionQuery"); + +fn void RenderPassEncoder.draw(RenderPassEncoder encoder, + CUInt vertexCount, CUInt instanceCount, CUInt firstVertex = 0, CUInt firstInstance = 0) + @extern("wgpuRenderPassEncoderDraw"); + +fn void RenderPassEncoder.drawIndexed(RenderPassEncoder encoder, + CUInt indexCount, CUInt instanceCount, CUInt firstIndex = 0, CInt baseVertex = 0, CUInt firstInstance = 0) + @extern("wgpuRenderPassEncoderDrawIndexed"); + +fn void RenderPassEncoder.drawIndexedIndirect(RenderPassEncoder encoder, + Buffer buffer, CULong offset) @extern("wgpuRenderPassEncoderDrawIndexedIndirect"); + +fn void RenderPassEncoder.drawIndirect(RenderPassEncoder encoder, + Buffer buffer, CULong offset) @extern("wgpuRenderPassEncoderDrawIndirect"); + +fn RenderBundle RenderPassEncoder.end(RenderPassEncoder encoder) @extern("wgpuRenderPassEncoderEnd"); + +fn void RenderPassEncoder.endOcclusionQuery(RenderPassEncoder encoder) @extern("wgpuRenderPassEncoderEndOcclusionQuery"); + +fn void RenderPassEncoder.executeBundles(RenderPassEncoder encoder, + usz count, RenderBundle* bundles) @extern("wgpuRenderPassEncoderExecuteBundles"); + +fn void RenderPassEncoder.insertDebugMarker(RenderPassEncoder encoder, + ZString label) @extern("wgpuRenderPassEncoderInsertDebugMarker"); + +fn void RenderPassEncoder.popDebugGroup(RenderPassEncoder encoder) + @extern("wgpuRenderPassEncoderPopDebugGroup"); + +fn void RenderPassEncoder.pushDebugGroup(RenderPassEncoder encoder, ZString label) + @extern("wgpuRenderPassEncoderPushDebugGroup"); + +fn void RenderPassEncoder.setBlendConstant(RenderPassEncoder encoder, Color* color) + @extern("wgpuRenderPassEncoderSetBlendConstant"); + +fn void RenderPassEncoder.setBindGroup(RenderPassEncoder encoder, CUInt groupIndex, BindGroup bindGroup, + usz dynamicOffsetCount = 0, CUInt* dynamicOffsets = null) @extern("wgpuRenderPassEncoderSetBindGroup"); + +fn void RenderPassEncoder.setIndexBuffer(RenderPassEncoder encoder, + Buffer buffer, IndexFormat format, CULong offset, CULong size) + @extern("wgpuRenderPassEncoderSetIndexBuffer"); + +fn void RenderPassEncoder.setLabel(RenderPassEncoder encoder, ZString label) + @extern("wgpuRenderPassEncoderSetLabel"); + +fn void RenderPassEncoder.setPipeline(RenderPassEncoder encoder, RenderPipeline pipeline) + @extern("wgpuRenderPassEncoderSetPipeline"); + +fn void RenderPassEncoder.setScissorRect(RenderPassEncoder encoder, + CUInt x, CUInt y, CUInt width, CUInt height) @extern("wgpuRenderPassEncoderSetScissorRect"); + +fn void RenderPassEncoder.setStencilReference(RenderPassEncoder encoder, + CUInt reference) @extern("wgpuRenderPassEncoderSetStencilReference"); + +fn void RenderPassEncoder.setVertexBuffer(RenderPassEncoder encoder, + CUInt slot, Buffer buffer, CULong offset, CULong size) + @extern("wgpuRenderPassEncoderSetVertexBuffer"); + +fn void RenderPassEncoder.setViewport(RenderPassEncoder encoder, + float x, float y, float width, float height, float minDepth, float maxDepth) + @extern("wgpuRenderPassEncoderSetViewport"); + +fn void RenderPassEncoder.reference(RenderPassEncoder encoder) @extern("wgpuRenderPassEncoderReference"); + +fn void RenderPassEncoder.release(RenderPassEncoder encoder) @extern("wgpuRenderPassEncoderRelease"); + + +struct RenderPassDescriptor { + ChainedStruct* next; + ZString label; + usz colorAttachmentCount; + RenderPassColorAttachment* colorAttachments; + RenderPassDepthStencilAttachment* depthStencilAttachment; + QuerySet occlusionQuerySet; + RenderPassTimestampWrites* timestampWrites; +} + +struct RenderPassDepthStencilAttachment { + TextureView view; + LoadOperation depthLoadOperation; + StoreOperation depthStoreOperation; + float depthClearValue; + CBool depthReadOnly; + LoadOperation stencilLoadOperation; + StoreOperation stencilStoreOperation; + CUInt stencilClearValue; + CBool stencilReadOnly; +} + +struct RenderPassDescriptorMaxDrawCount { + ChainedStruct chain; + CULong maxDrawCount; +} + +struct RenderPassTimestampWrites { + QuerySet querySet; + CUInt beginningOfPassWriteIndex; + CUInt endOfPassWriteIndex; +} + +struct RenderPassColorAttachment { + ChainedStruct* next; + TextureView view; + CUInt depthSlice; + TextureView resolveTarget; + LoadOperation loadOperation; + StoreOperation storeOperation; + Color clearValue; +} + +enum LoadOperation { + UNDEFINED, + CLEAR, + LOAD +} + +enum StoreOperation { + UNDEFINED, + STORE, + DISCARD +} diff --git a/libraries/webgpu.c3l/render_pipeline.c3i b/libraries/webgpu.c3l/render_pipeline.c3i new file mode 100644 index 0000000..f222442 --- /dev/null +++ b/libraries/webgpu.c3l/render_pipeline.c3i @@ -0,0 +1,220 @@ +module webgpu; + +distinct RenderPipeline = void*; + + +fn BindGroupLayout RenderPipeline.getBindGroupLayout(RenderPipeline pipeline, + CUInt groupIndex) @extern("wgpuRenderPipelineGetBindGroupLayout"); + +fn void RenderPipeline.setLabel(RenderPipeline pipeline, + ZString label) @extern("wgpuRenderPipelineSetLabel"); + +fn void RenderPipeline.reference(RenderPipeline pipeline) @extern("wgpuRenderPipelineReference"); + +fn void RenderPipeline.release(RenderPipeline pipeline) @extern("wgpuRenderPipelineRelease"); + + + +struct RenderPipelineDescriptor { + ChainedStruct* next; + ZString label; + PipelineLayout layout; + VertexState vertex; + PrimitiveState primitive; + DepthStencilState* depthStencil; + MultisampleState multisample; + FragmentState* fragment; +} + +struct VertexState { + ChainedStruct* next; + ShaderModule shaderModule; + ZString entryPoint; + usz constantCount; + ConstantEntry* constants; + usz bufferCount; + VertexBufferLayout* buffers; +} + +struct VertexBufferLayout { + CULong arrayStride; + VertexStepMode stepMode; + usz attributeCount; + VertexAttribute* attributes; +} + +struct VertexAttribute { + VertexFormat format; + CULong offset; + CUInt shaderLocation; +} + +struct FragmentState { + ChainedStruct* next; + ShaderModule shaderModule; + ZString entryPoint; + usz constantCount; + ConstantEntry* constants; + usz targetCount; + ColorTargetState* targets; +} + +struct MultisampleState { + ChainedStruct* next; + CUInt count; + CUInt mask; + CBool alphaToCoverageEnabled; +} + +struct DepthStencilState { + ChainedStruct* next; + TextureFormat format; + CBool depthWriteEnabled; + CompareFunction depthCompare; + StencilFaceState stencilFront; + StencilFaceState stencilBack; + CUInt stencilReadMask; + CUInt stencilWriteMask; + CInt depthBias; + float depthBiasSlopeScale; + float depthBiasClamp; +} + +struct StencilFaceState { + CompareFunction compare; + StencilOperation failOperation; + StencilOperation depthFailOperation; + StencilOperation passOperation; +} + +struct ColorTargetState { + ChainedStruct* next; + TextureFormat format; + BlendState* blend; + ColorWriteMask writeMask; +} + +bitstruct ColorWriteMask: CInt { + bool red; + bool green; + bool blue; + bool alpha; +} + +struct BlendState { + BlendComponent color; + BlendComponent alpha; +} + +struct BlendComponent { + BlendOperation operation; + BlendFactor sourceFactor; + BlendFactor destinationFactor; +} + +struct PrimitiveDepthClipControl { + ChainedStruct chain; + CBool unclippedDepth; +} + +struct PrimitiveState { + ChainedStruct* next; + PrimitiveTopology topology; + IndexFormat stripIndexFormat; + FrontFace frontFace; + CullMode cullMode; +} + +enum VertexFormat { + UNDEFINED, + UINT_8X2, + UINT_8X4, + SINT_8X2, + SINT_8X4, + UNORM_8X2, + UNORM_8X4, + SNORM_8X2, + SNORM_8X4, + UINT_16X2, + UINT_16X4, + SINT_16X2, + SINT_16X4, + UNORM_16X2, + UNORM_16X4, + SNORM_16X2, + SNORM_16X4, + FLOAT_16X2, + FLOAT_16X4, + FLOAT_32, + FLOAT_32X2, + FLOAT_32X3, + FLOAT_32X4, + UINT_32, + UINT_32X2, + UINT_32X3, + UINT_32X4, + SINT_32, + SINT_32X2, + SINT_32X3, + SINT_32X4 +} + +enum VertexStepMode { + VERTEX, + INSTANCE, + VERTEX_BUFFER_NOT_USED +} + +enum BlendFactor { + ZERO, + ONE, + SRC, + ONE_MINUS_SRC, + SRC_ALPHA, + ONE_MINUS_SRC_ALPHA, + DST, + ONE_MINUS_DST, + DST_ALPHA, + ONE_MINUS_DST_ALPHA, + SRC_ALPHA_SATURATED, + CONSTANT, + ONE_MINUS_CONSTANT +} + +enum BlendOperation { + ADD, + SUBTRACT, + REVERSE_SUBTRACT, + MIN, + MAX +} + +enum FrontFace { + COUNTER_CLOCKWISE, + CLOCKWISE +} + +enum CullMode { + NONE, + FRONT, + BACK +} + +enum PrimitiveTopology { + POINT_LIST, + LINE_LIST, + LINE_STRIP, + TRIANGLE_LIST, + TRIANGLE_STRIP +} + +enum StencilOperation { + KEEP, + ZERO, + REPLACE, + INVERT, + INCREMENT_CLAMP, + DECREMENT_CLAMP, + INCREMENT_WRAP, + DECREMENT_WRAP +} diff --git a/libraries/webgpu.c3l/sampler.c3i b/libraries/webgpu.c3l/sampler.c3i new file mode 100644 index 0000000..24fc705 --- /dev/null +++ b/libraries/webgpu.c3l/sampler.c3i @@ -0,0 +1,42 @@ +module webgpu; + +distinct Sampler = void*; + +fn void Sampler.setLabel(Sampler sampler, ZString label) @extern("wgpuSamplerSetLabel"); + +fn void Sampler.reference(Sampler sampler) @extern("wgpuSamplerReference"); + +fn void Sampler.release(Sampler sampler) @extern("wgpuSamplerRelease"); + + +struct SamplerDescriptor { + ChainedStruct* next; + ZString label; + AddressMode addressModeU; + AddressMode addressModeV; + AddressMode addressModeW; + FilterMode magFilter; + FilterMode minFilter; + MipmapFilterMode mipmapFilter; + float lodMinClamp; + float lodMaxClamp; + CompareFunction compare; + CUShort maxAnisotropy; +} + + +enum AddressMode { + REPEAT, + MIRROR_REPEAT, + CLAMP_TO_EDGE, +} + +enum FilterMode { + NEAREST, + LINEAR +} + +enum MipmapFilterMode { + NEAREST, + LINEAR +} diff --git a/libraries/webgpu.c3l/shader_module.c3i b/libraries/webgpu.c3l/shader_module.c3i new file mode 100644 index 0000000..cd848da --- /dev/null +++ b/libraries/webgpu.c3l/shader_module.c3i @@ -0,0 +1,83 @@ +module webgpu; + +distinct ShaderModule = void*; + +fn void ShaderModule.getCompilationInfo(ShaderModule shaderModule, + CompilationInfoCallback callback, UserData userData) @extern("wgpuShaderModuleGetCompilationInfo"); + +fn void ShaderModule.setLabel(ShaderModule shaderModule, + ZString label) @extern("wgpuShaderModuleSetLabel"); + +fn void ShaderModule.reference(ShaderModule shaderModule) @extern("wgpuShaderModuleReference"); + +fn void ShaderModule.release(ShaderModule shaderModule) @extern("wgpuShaderModuleRelease"); + + +def CompilationInfoCallback = fn void(CompilationInfoRequestStatus status, + CompilationInfo* info, UserData data); + +def ShaderStageFlags = CUInt; + +struct CompilationMessage { + ChainedStruct* next; + ZString message; + CompilationMessageType type; + CULong lineNumber; + CULong linePosition; + CULong offset; + CULong length; + CULong utf16LinePosition; + CULong utf16Offset; + CULong utf16Length; +} + +struct CompilationInfo { + ChainedStruct* next; + usz messageCount; + CompilationMessage* messages; +} + +struct ConstantEntry { + ChainedStruct* next; + ZString key; + double value; +} + +struct ShaderModuleCompilationHint { + ChainedStruct* next; + ZString entryPoint; + PipelineLayout layout; +} + +struct ShaderModuleDescriptor { + ChainedStruct* next; + ZString label; + usz hintCount; + ShaderModuleCompilationHint* hints; +} + +struct ShaderModuleSPIRVDescriptor { + ChainedStruct chain; + CUInt codeSize; + CUInt* code; +} + +struct ShaderModuleWGSLDescriptor { + ChainedStruct chain; + ZString code; +} + + +enum CompilationInfoRequestStatus { + SUCCESS, + ERROR, + DEVICE_LOST, + UNKNOWN +} + +enum CompilationMessageType { + ERROR, + WARNING, + INFO +} + diff --git a/libraries/webgpu.c3l/shared.c3i b/libraries/webgpu.c3l/shared.c3i new file mode 100644 index 0000000..7a47871 --- /dev/null +++ b/libraries/webgpu.c3l/shared.c3i @@ -0,0 +1,38 @@ +module webgpu; + +def UserData = void*; + +const UNDEFINED = ~0u; + +struct Color { + double red; + double green; + double blue; + double alpha; +} + +struct Extent3D { + CUInt width; + CUInt height; + CUInt depthOrArrayLayers; +} + + +enum CompareFunction { + UNDEFINED, + NEVER, + LESS, + LESS_EQUAL, + GREATER, + GREATER_EQUAL, + EQUAL, + NOT_EQUAL, + ALWAYS +} + +enum IndexFormat { + UNDEFINED, + UINT16, + UINT32 +} + diff --git a/libraries/webgpu.c3l/surface.c3i b/libraries/webgpu.c3l/surface.c3i new file mode 100644 index 0000000..8bef5ec --- /dev/null +++ b/libraries/webgpu.c3l/surface.c3i @@ -0,0 +1,88 @@ +module webgpu; + +distinct Surface = void*; + +fn void Surface.configure(Surface surface, + SurfaceConfiguration* configuration) @extern("wgpuSurfaceConfigure"); + +fn void Surface.getCapabilities(Surface surface, + Adapter adapter, SurfaceCapabilities* capabilities) @extern("wgpuSurfaceGetCapabilities"); + +fn Texture Surface.getCurrentTexture(Surface surface, SurfaceTexture* texture) @extern("wgpuSurfaceGetCurrentTexture"); + +fn TextureFormat Surface.getPreferredFormat(Surface surface, + Adapter adapter) @extern("wgpuSurfaceGetPreferredFormat"); + +fn void Surface.present(Surface surface) @extern("wgpuSurfacePresent"); + +fn void Surface.setLabel(Surface surface, + ZString label) @extern("wgpuSurfaceSetLabel"); + +fn void Surface.unconfigure(Surface surface) @extern("wgpuSurfaceUnconfigure"); + +fn void Surface.reference(Surface surface) @extern("wgpuSurfaceReference"); + +fn void Surface.release(Surface surface) @extern("wgpuSurfaceRelease"); + +fn void SurfaceCapabilities.freeMembers(SurfaceCapabilities* capabilities) + @extern("wgpuSurfaceCapabilitiesFreeMembers"); + + +struct SurfaceDescriptor { + ChainedStruct* next; + ZString label; +} + +struct SurfaceCapabilities { + ChainedStructOut* next; + TextureUsage usages; + usz formatCount; + TextureFormat* formats; + usz presentModeCount; + PresentMode* presentModes; + usz alphaModeCount; + CompositeAlphaMode* alphaModes; +} + +struct SurfaceConfiguration { + ChainedStruct* next; + Device device; + TextureFormat format; + TextureUsage usage; + usz viewFormatCount; + TextureFormat* viewFormats; + CompositeAlphaMode alphaMode; + CUInt width; + CUInt height; + PresentMode presentMode; +} + +struct SurfaceTexture { + Texture texture; + CBool suboptimal; + CurrentTextureStatus status; +} + +enum CurrentTextureStatus { + SUCCESS, + TIMEOUT, + OUTDATED, + LOST, + OUT_OF_MEMORY, + DEVICE_LOST +} + +enum CompositeAlphaMode { + AUTO, + OPAQUE, + PREMULTIPLIED, + UNPREMULTIPLIED, + INHERIT +} + +enum PresentMode { + FIFO, + FIFO_RELAXED, + IMMEDIATE, + MAILBOX +} diff --git a/libraries/webgpu.c3l/surface_system.c3i b/libraries/webgpu.c3l/surface_system.c3i new file mode 100644 index 0000000..a291291 --- /dev/null +++ b/libraries/webgpu.c3l/surface_system.c3i @@ -0,0 +1,56 @@ +module webgpu; + +distinct AndroidNativeWindow = void*; + +struct SurfaceDescriptorFromAndroidNativeWindow { + ChainedStruct chain; + AndroidNativeWindow window; +} + +struct SurfaceDescriptorFromCanvasHTMLSelector { + ChainedStruct chain; + ZString selector; +} + +distinct MetalLayer = void*; + +struct SurfaceDescriptorFromMetalLayer { + ChainedStruct chain; + MetalLayer layer; +} + +distinct WaylandDisplay = void*; +distinct WaylandSurface = void*; + +struct SurfaceSourceWaylandSurface { + ChainedStruct chain; + WaylandDisplay display; + WaylandSurface surface; +} + +distinct HInstance = void*; +distinct WindowsHWND = void*; + +struct SurfaceDescriptorFromWindowsHWND { + ChainedStruct chain; + HInstance hinstance; + WindowsHWND hwnd; +} + +distinct XcbConnection = void*; +distinct XcbWindow = CUInt; + +struct SurfaceDescriptorFromXcbWindow { + ChainedStruct chain; + XcbConnection connection; + XcbWindow window; +} + +distinct X11Display = void*; +distinct X11Window = CULong; + +struct SurfaceDescriptorFromXlibWindow { + ChainedStruct chain; + X11Display display; + X11Window window; +} diff --git a/libraries/webgpu.c3l/texture.c3i b/libraries/webgpu.c3l/texture.c3i new file mode 100644 index 0000000..948d60d --- /dev/null +++ b/libraries/webgpu.c3l/texture.c3i @@ -0,0 +1,183 @@ +module webgpu; + +distinct Texture = void*; + +fn TextureView Texture.createView(Texture texture, TextureViewDescriptor* descriptor = null) @extern("wgpuTextureCreateView"); + +fn void Texture.destroy(Texture texture) @extern("wgpuTextureDestroy"); + +fn CUInt Texture.getDepthOrArrayLayers(Texture texture) @extern("wgpuTextureGetDepthOrArrayLayers"); + +fn TextureDimension Texture.getDimension(Texture texture) @extern("wgpuTextureGetDimension"); + +fn TextureFormat Texture.getFormat(Texture texture) @extern("wgpuTextureGetFormat"); + +fn CUInt Texture.getHeight(Texture texture) @extern("wgpuTextureGetHeight"); + +fn CUInt Texture.getMipLevelCount(Texture texture) @extern("wgpuTextureGetMipLevelCount"); + +fn CUInt Texture.getSampleCount(Texture texture) @extern("wgpuTextureGetSampleCount"); + +fn CUInt Texture.getWidth(Texture texture) @extern("wgpuTextureGetWidth"); + +fn void Texture.setLabel(Texture texture, ZString label) @extern("wgpuTextureSetLabel"); + +fn void Texture.reference(Texture texture) @extern("wgpuTextureReference"); + +fn void Texture.release(Texture texture) @extern("wgpuTextureRelease"); + + +struct TextureDescriptor { + ChainedStruct* next; + ZString label; + TextureUsage usage; + TextureDimension dimension; + Extent3D size; + TextureFormat format; + CUInt mipLevelCount; + CUInt sampleCount; + usz viewFormatCount; + TextureFormat* viewFormats; +} + +struct ImageCopyTexture { + ChainedStruct* next; + Texture texture; + CUInt mipLevel; + Origin3D origin; + TextureAspect aspect; +} + + +struct Origin3D { + CUInt x; + CUInt y; + CUInt z; +} + +struct TextureDataLayout { + ChainedStruct* next; + CULong offset; + CUInt bytesPerRow; + CUInt rowsPerImage; +} + +bitstruct TextureUsage: CInt { + bool copySource; + bool copyDestination; + bool textureBinding; + bool storageBinding; + bool renderAttachment; +} + + +enum TextureDimension { + DIMENSION_1D, + DIMENSION_2D, + DIMENSION_3D +} + +enum TextureFormat { + UNDEFINED, + R8_UNORM, + R8_SNORM, + R8_UINT, + R8_SINT, + R16_UINT, + R16_SINT, + R16_FLOAT, + RG8_UNORM, + RG8_SNORM, + RG8_UINT, + RG8_SINT, + R32_FLOAT, + R32_UINT, + R32_SINT, + RG16_UINT, + RG16_SINT, + RG16_FLOAT, + RGBA8_UNORM, + RGBA8_UNORM_SRGB, + RGBA8_SNORM, + RGBA8_UINT, + RGBA8_SINT, + BGRA8_UNORM, + BGRA8_UNORM_SRGB, + RGB10_A2_UINT, + RGB10_A2_UNORM, + RG11_B10_UFLOAT, + RGB9_E5_UFLOAT, + RG32_FLOAT, + RG32_UINT, + RG32_SINT, + RGBA16_UINT, + RGBA16_SINT, + RGBA16_FLOAT, + RGBA32_FLOAT, + RGBA32_UINT, + RGBA32_SINT, + STENCIL8, + DEPTH16_UNORM, + DEPTH24_PLUS, + DEPTH24_PLUS_STENCIL8, + DEPTH32_FLOAT, + DEPTH32_FLOAT_STENCIL8, + BC1_RGBAUNORM, + BC1_RGBAUNORM_SRGB, + BC2_RGBAUNORM, + BC2_RGBAUNORM_SRGB, + BC3_RGBAUNORM, + B3_RGBAUNORM_SRGB, + BC4_RUNORM, + BC4_RSNORM, + BC5_RGUNORM, + BC5_RGSNORM, + BC6_HRGBUFLOAT, + BC6_HRGBFLOAT, + BC7_RGBAUNORM, + BC7_RGBAUNORM_SRGB, + ETC2_RGB8_UNORM, + ETC2_RGB8_UNORM_SRGB, + ETC2_RGB8_A1_UNORM, + ETC2_RGB8_A1_UNORM_SRGB, + ETC2_RGBA8_UNORM, + ETC2_RGBA8_UNORM_SRGB, + EACR11_UNORM, + EACR11_SNORM, + EACRG11_UNORM, + EACRG11_SNORM, + ASTC4X4_UNORM, + ASTC4X4_UNORM_SRGB, + ASTC5X4_UNORM, + ASTC5X4_UNORM_SRGB, + ASTC5X5_UNORM, + ASTC5X5_UNORM_SRGB, + ASTC6X5_UNORM, + ASTC6X5_UNORM_SRGB, + ASTC6X6_UNORM, + ASTC6X6_UNORM_SRGB, + ASTC8X5_UNORM, + ASTC8X5_UNORM_SRGB, + ASTC8X6_UNORM, + ASTC8X6_UNORM_SRGB, + ASTC8X8_UNORM, + ASTC8X8_UNORM_SRGB, + ASTC10X5_UNORM, + ASTC10X5_UNORM_SRGB, + ASTC10X6_UNORM, + ASTC10X6_UNORM_SRGB, + ASTC10X8_UNORM, + ASTC10X8_UNORM_SRGB, + ASTC10X10_UNORM, + ASTC10X10_UNORM_SRGB, + ASTC12X10_UNORM, + ASTC12X10_UNORM_SRGB, + ASTC12X12_UNORM, + ASTC12X12_UNORM_SRGB +} + +enum TextureAspect { + ALL, + STENCIL_ONLY, + DEPTH_ONLY +} diff --git a/libraries/webgpu.c3l/texture_view.c3i b/libraries/webgpu.c3l/texture_view.c3i new file mode 100644 index 0000000..584c051 --- /dev/null +++ b/libraries/webgpu.c3l/texture_view.c3i @@ -0,0 +1,48 @@ +module webgpu; + +distinct TextureView = void*; + + +fn void TextureView.setLabel(TextureView texture, ZString label) @extern("wgpuTextureViewSetLabel"); + +fn void TextureView.reference(TextureView texture) @extern("wgpuTextureViewReference"); + +fn void TextureView.release(TextureView texture) @extern("wgpuTextureViewRelease"); + + +struct TextureViewDescriptor { + ChainedStruct* next; + ZString label; + TextureFormat format; + TextureViewDimension dimension; + CUInt baseMipLevel; + CUInt mipLevelCount; + CUInt baseArrayLayer; + CUInt arrayLayerCount; + TextureAspect aspect; +} + +struct StorageTextureBindingLayout { + ChainedStruct* next; + StorageTextureAccess access; + TextureFormat format; + TextureViewDimension viewDimension; +} + + +enum StorageTextureAccess { + UNDEFINED, + WRITE_ONLY, + READ_ONLY, + READ_WRITE +} + +enum TextureViewDimension { + UNDEFINED, + SINGLE_1D, + SINGLE_2D, + ARRAY_2D, + CUBE, + CUBE_ARRAY, + SINGLE_3D +}