render_pipeline.zig (7298B)
1 const c = @import("c.zig").c; 2 const ChainedStruct = @import("common.zig").ChainedStruct; 3 const CompareFunction = @import("common.zig").CompareFunction; 4 const IndexFormat = @import("common.zig").IndexFormat; 5 const OptionalBool = @import("common.zig").OptionalBool; 6 const PipelineLayout = @import("pipeline_layout.zig").PipelineLayout; 7 const ShaderModule = @import("shader_module.zig").ShaderModule; 8 const StringView = @import("common.zig").StringView; 9 const Texture = @import("texture.zig").Texture; 10 11 const VertexState = extern struct { 12 next: ?*ChainedStruct = null, 13 module: *ShaderModule, 14 entry_point: StringView, 15 constant_count: usize, 16 constants: ?[*]const ConstantEntry, 17 buffer_count: usize, 18 buffers: ?[*]const VertexBufferLayout, 19 20 const VertexBufferLayout = extern struct { 21 step_mode: VertexStepMode, 22 array_stride: u64, 23 attribute_count: usize, 24 attributes: ?[*]VertexAttribute, 25 26 const VertexStepMode = enum(u32) { 27 vertex_buffer_not_used = 0x00000000, 28 undefined = 0x00000001, 29 vertex = 0x00000002, 30 instance = 0x00000003, 31 }; 32 33 const VertexAttribute = extern struct { 34 format: VertexFormat, 35 offset: u64, 36 shader_location: u32, 37 }; 38 39 const VertexFormat = enum(u32) { 40 uint8 = 0x00000001, 41 uint8x2 = 0x00000002, 42 uint8x4 = 0x00000003, 43 sint8 = 0x00000004, 44 sint8x2 = 0x00000005, 45 sint8x4 = 0x00000006, 46 unorm8 = 0x00000007, 47 unorm8x2 = 0x00000008, 48 unorm8x4 = 0x00000009, 49 snorm = 0x0000000A, 50 snorm8x2 = 0x0000000B, 51 snorm8x4 = 0x0000000C, 52 uint16 = 0x0000000D, 53 uint16x2 = 0x0000000E, 54 uint16x4 = 0x0000000F, 55 sint16 = 0x00000010, 56 sint16x2 = 0x00000011, 57 sint16x4 = 0x00000012, 58 unorm16 = 0x00000013, 59 unorm16x2 = 0x00000014, 60 unorm16x4 = 0x00000015, 61 snorm16 = 0x00000016, 62 snorm16x2 = 0x00000017, 63 snorm16x4 = 0x00000018, 64 float16 = 0x00000019, 65 float16x2 = 0x0000001A, 66 float16x4 = 0x0000001B, 67 float32 = 0x0000001C, 68 float32x2 = 0x0000001D, 69 float32x3 = 0x0000001E, 70 float32x4 = 0x0000001F, 71 uint32 = 0x00000020, 72 uint32x2 = 0x00000021, 73 uint32x3 = 0x00000022, 74 uint32x4 = 0x00000023, 75 sint32 = 0x00000024, 76 sint32x2 = 0x00000025, 77 sint32x3 = 0x00000026, 78 sint32x4 = 0x00000027, 79 unorm10_10_10_2 = 0x00000028, 80 unorm8x4_brga = 0x00000029, 81 }; 82 }; 83 }; 84 85 const FragmentState = extern struct { 86 next: ?*ChainedStruct = null, 87 module: *ShaderModule, 88 entry_point: StringView, 89 constant_count: usize, 90 constants: ?[*]const ConstantEntry, 91 target_count: usize, 92 targets: ?[*]const ColorTargetState, 93 94 const ColorTargetState = extern struct { 95 next: ?*ChainedStruct = null, 96 format: Texture.Format, 97 blend: ?*const BlendState, 98 write_mask: ColorWriteMask, 99 100 const BlendState = extern struct { 101 color: BlendComponent, 102 alpha: BlendComponent, 103 }; 104 105 const BlendComponent = extern struct { 106 operation: BlendOperation, 107 src_factor: BlendFactor, 108 dst_factor: BlendFactor, 109 }; 110 111 const BlendOperation = enum(u32) { 112 undefined = 0x00000000, 113 add = 0x00000001, 114 subtract = 0x00000002, 115 reverse_subtract = 0x00000003, 116 min = 0x00000004, 117 max = 0x00000005, 118 }; 119 120 const BlendFactor = enum(u32) { 121 undefined = 0x00000000, 122 zero = 0x00000001, 123 one = 0x00000002, 124 src = 0x00000003, 125 one_minus_src = 0x00000004, 126 src_alpha = 0x00000005, 127 one_minus_src_alpha = 0x00000006, 128 dst = 0x00000007, 129 one_minus_dst = 0x00000008, 130 dst_alpha = 0x00000009, 131 one_minus_dst_alpha = 0x0000000A, 132 src_alpha_saturated = 0x0000000B, 133 constant = 0x0000000C, 134 one_minus_constant = 0x0000000D, 135 src1 = 0x0000000E, 136 one_minus_src1 = 0x0000000F, 137 src1_alpha = 0x00000010, 138 one_minus_src1_alpha = 0x00000011, 139 }; 140 141 const ColorWriteMask = packed struct(u64) { 142 red: bool = false, 143 green: bool = false, 144 blue: bool = false, 145 alpha: bool = false, 146 _padding: u60 = 0, 147 }; 148 }; 149 }; 150 151 const ConstantEntry = extern struct { 152 next: ?*ChainedStruct = null, 153 key: StringView, 154 value: f64, 155 }; 156 157 const PrimitiveState = extern struct { 158 next: ?*ChainedStruct = null, 159 topology: PrimitiveTopology, 160 strip_index_format: IndexFormat, 161 front_face: FrontFace, 162 cull_mode: CullMode, 163 unclipped_depth: bool, 164 165 const PrimitiveTopology = enum(u32) { 166 undefined = 0x00000000, 167 point_list = 0x00000001, 168 line_list = 0x00000002, 169 line_strip = 0x00000003, 170 triangle_list = 0x00000004, 171 triangle_strip = 0x00000005, 172 }; 173 174 const FrontFace = enum(u32) { 175 undefined = 0x00000000, 176 ccw = 0x00000001, 177 cw = 0x00000002, 178 }; 179 180 const CullMode = enum(u32) { 181 undefined = 0x00000000, 182 none = 0x00000001, 183 front = 0x00000002, 184 back = 0x00000003, 185 }; 186 }; 187 188 const DepthStencilState = extern struct { 189 next: ?*ChainedStruct = null, 190 format: Texture.Format, 191 depth_write_enabled: OptionalBool, 192 depth_compare: CompareFunction, 193 stencil_front: StencilFaceState, 194 stencil_back: StencilFaceState, 195 stencil_read_mask: u32, 196 stencil_write_mask: u32, 197 depth_bias: i32, 198 depth_bias_slope_scale: f32, 199 depth_bias_clamp: f32, 200 201 const StencilFaceState = extern struct { 202 compare: CompareFunction, 203 fail_op: StencilOperation, 204 depth_fail_op: StencilOperation, 205 pass_op: StencilOperation, 206 }; 207 208 const StencilOperation = enum(u32) { 209 undefined = 0x00000000, 210 keep = 0x00000001, 211 zero = 0x00000002, 212 replace = 0x00000003, 213 invert = 0x00000004, 214 increment_clamp = 0x00000005, 215 decrement_clamp = 0x00000006, 216 increment_wrap = 0x00000007, 217 decrement_wrap = 0x00000008, 218 }; 219 }; 220 221 const MultisampleState = extern struct { 222 next: ?*ChainedStruct = null, 223 count: u32, 224 mask: u32, 225 alpha_to_coverage_enabled: bool, 226 }; 227 228 pub const RenderPipeline = opaque { 229 pub const Descriptor = extern struct { 230 next: ?*ChainedStruct = null, 231 label: StringView, 232 layout: ?*const PipelineLayout, 233 vertex: VertexState, 234 primitive: PrimitiveState, 235 depth_stencil: ?*const DepthStencilState, 236 multisample: MultisampleState, 237 fragment_state: ?*const FragmentState, 238 }; 239 240 pub fn release(pipeline: *RenderPipeline) void { 241 c.wgpuRenderPipelineRelease(@ptrCast(pipeline)); 242 } 243 244 // getBindGroupLayout 245 // setLabel 246 // reference 247 };