common.zig (3186B)
1 const std = @import("std"); 2 3 const c = @import("c.zig").c; 4 5 pub const SType = enum(u32) { 6 invalid = 0x00000000, 7 shader_source_spirv = 0x00000001, 8 shader_source_wgsl = 0x00000002, 9 render_pass_max_draw_count = 0x00000003, 10 surface_source_metal_layer = 0x00000004, 11 surface_source_windows_hwnd = 0x00000005, 12 surface_source_xlib_window = 0x00000006, 13 surface_source_wayland_surface = 0x00000007, 14 surface_source_android_native_window = 0x00000008, 15 surface_source_xcb_window = 0x00000009, 16 // native 17 device_extras = 0x00030001, 18 native_limits = 0x00030002, 19 pipeline_layout_extras = 0x00030003, 20 shader_source_glsl = 0x00030004, 21 instance_extras = 0x00030006, 22 bind_group_entry_extras = 0x00030007, 23 bind_group_layout_entry_extras = 0x00030008, 24 query_set_descriptor_extras = 0x00030009, 25 surface_configuration_extras = 0x0003000A, 26 }; 27 28 pub const ChainedStruct = extern struct { 29 next: ?*const ChainedStruct, 30 struct_type: SType, 31 }; 32 33 //* Values are encoded as follows: 34 //* - `{NULL, WGPU_STRLEN}`: the null value. 35 //* - `{non_null_pointer, WGPU_STRLEN}`: a null-terminated string view. 36 //* - `{any, 0}`: the empty string. 37 //* - `{NULL, non_zero_length}`: not allowed (null dereference). 38 //* - `{non_null_pointer, non_zero_length}`: an explictly-sized string view with 39 //* size `non_zero_length` (in bytes). 40 pub const StringView = extern struct { 41 data: ?[*]const u8, 42 length: usize, 43 44 const null_terminated = std.math.maxInt(usize); 45 46 pub fn fromSlice(slice: []const u8) StringView { 47 return .{ 48 .data = slice.ptr, 49 .length = slice.len, 50 }; 51 } 52 53 pub fn toSlice(string: StringView) []const u8 { 54 if (string.data == null) { 55 return ""; 56 } 57 if (string.length == 0) { 58 return ""; 59 } 60 if (string.length == null_terminated) { 61 const slice = std.mem.span( 62 @as([*:0]const u8, @ptrCast(string.data.?)), 63 ); 64 return slice[0..slice.len]; 65 } 66 return string.data.?[0..string.length]; 67 } 68 }; 69 70 pub const OptionalBool = enum(u32) { 71 false = 0x00000000, 72 true = 0x00000001, 73 undefined = 0x00000002, 74 }; 75 76 pub const CallbackMode = enum(u32) { 77 wait_any_only = 0x00000001, 78 allow_process_events = 0x00000002, 79 allow_spontaneous = 0x00000003, 80 }; 81 82 pub const LoadOp = enum(u32) { 83 undefined = 0x00000000, 84 load = 0x00000001, 85 clear = 0x00000002, 86 }; 87 88 pub const StoreOp = enum(u32) { 89 undefined = 0x00000000, 90 store = 0x00000001, 91 discard = 0x00000002, 92 }; 93 94 pub const Status = enum(u32) { 95 success = 0x00000001, 96 @"error" = 0x00000002, 97 }; 98 99 pub const Color = extern struct { 100 r: f64, 101 g: f64, 102 b: f64, 103 a: f64, 104 }; 105 106 pub const IndexFormat = enum(u32) { 107 undefined = 0x00000000, 108 uint16 = 0x00000001, 109 uint32 = 0x00000002, 110 }; 111 112 pub const CompareFunction = enum(u32) { 113 undefined = 0x00000000, 114 never = 0x00000001, 115 less = 0x00000002, 116 equal = 0x00000003, 117 less_equal = 0x00000004, 118 greater = 0x00000005, 119 not_equal = 0x00000006, 120 greater_equal = 0x00000007, 121 always = 0x00000008, 122 };