-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
771b15f
commit 602bf84
Showing
29 changed files
with
1,814 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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?; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Oops, something went wrong.