1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef WEBGPU_SERIALIZE_H_ 7 #define WEBGPU_SERIALIZE_H_ 8 9 #include "WebGPUTypes.h" 10 #include "ipc/IPCMessageUtils.h" 11 #include "mozilla/dom/WebGPUBinding.h" 12 #include "mozilla/webgpu/ffi/wgpu.h" 13 14 namespace IPC { 15 16 // Special handling of the raw strings serialization. 17 // We are carrying the strings through IPC separately from the containing 18 // structs. So this implementation always reads nullptr for the char pointer. 19 template <> 20 struct ParamTraits<mozilla::webgpu::ffi::WGPURawString> { 21 typedef mozilla::webgpu::ffi::WGPURawString paramType; 22 23 static void Write(Message* aMsg, const paramType& aParam) { 24 mozilla::Unused << aMsg; 25 mozilla::Unused << aParam; 26 } 27 28 static bool Read(const Message* aMsg, PickleIterator* aIter, 29 paramType* aResult) { 30 mozilla::Unused << aMsg; 31 mozilla::Unused << aIter; 32 *aResult = nullptr; 33 return true; 34 } 35 }; 36 37 #define DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, guard) \ 38 template <> \ 39 struct ParamTraits<something> \ 40 : public ContiguousEnumSerializer<something, something(0), guard> {} 41 42 #define DEFINE_IPC_SERIALIZER_DOM_ENUM(something) \ 43 DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something::EndGuard_) 44 #define DEFINE_IPC_SERIALIZER_FFI_ENUM(something) \ 45 DEFINE_IPC_SERIALIZER_ENUM_GUARD(something, something##_Sentinel) 46 47 DEFINE_IPC_SERIALIZER_DOM_ENUM(mozilla::dom::GPUPowerPreference); 48 DEFINE_IPC_SERIALIZER_DOM_ENUM(mozilla::webgpu::SerialBindGroupEntryType); 49 50 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUAddressMode); 51 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUBindingType); 52 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUBlendFactor); 53 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUBlendOperation); 54 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUCompareFunction); 55 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUCullMode); 56 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUFilterMode); 57 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUFrontFace); 58 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUIndexFormat); 59 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUInputStepMode); 60 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUPrimitiveTopology); 61 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUStencilOperation); 62 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUTextureAspect); 63 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUTextureComponentType); 64 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUTextureDimension); 65 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUTextureFormat); 66 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUTextureViewDimension); 67 DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUVertexFormat); 68 69 DEFINE_IPC_SERIALIZER_WITHOUT_FIELDS(mozilla::dom::GPUCommandEncoderDescriptor); 70 DEFINE_IPC_SERIALIZER_WITHOUT_FIELDS(mozilla::dom::GPUCommandBufferDescriptor); 71 72 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPURequestAdapterOptions, 73 mPowerPreference); 74 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPUExtensions, 75 mAnisotropicFiltering); 76 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPULimits, mMaxBindGroups); 77 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPUDeviceDescriptor, 78 mExtensions, mLimits); 79 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUBufferDescriptor, 80 label, size, usage); 81 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUTextureDescriptor, 82 label, size, mip_level_count, sample_count, 83 dimension, format, usage); 84 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUSamplerDescriptor, 85 label, address_mode_u, address_mode_v, 86 address_mode_w, mag_filter, min_filter, 87 mipmap_filter, lod_min_clamp, lod_max_clamp, 88 compare); 89 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUExtent3d, width, 90 height, depth); 91 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUOrigin3d, x, y, z); 92 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 93 mozilla::webgpu::ffi::WGPUTextureViewDescriptor, label, format, dimension, 94 aspect, base_mip_level, level_count, base_array_layer, array_layer_count); 95 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUBlendDescriptor, 96 src_factor, dst_factor, operation); 97 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 98 mozilla::webgpu::ffi::WGPURasterizationStateDescriptor, front_face, 99 cull_mode, depth_bias, depth_bias_slope_scale, depth_bias_clamp); 100 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 101 mozilla::webgpu::ffi::WGPUColorStateDescriptor, format, alpha_blend, 102 color_blend, write_mask); 103 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 104 mozilla::webgpu::ffi::WGPUStencilStateFaceDescriptor, compare, fail_op, 105 depth_fail_op, pass_op); 106 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 107 mozilla::webgpu::ffi::WGPUDepthStencilStateDescriptor, format, 108 depth_write_enabled, depth_compare, stencil_front, stencil_back, 109 stencil_read_mask, stencil_write_mask); 110 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 111 mozilla::webgpu::ffi::WGPUVertexAttributeDescriptor, offset, format, 112 shader_location); 113 114 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUBufferCopyView, 115 buffer, offset, bytes_per_row, 116 rows_per_image); 117 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ffi::WGPUTextureCopyView, 118 texture, mip_level, array_layer, origin); 119 120 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 121 mozilla::webgpu::ffi::WGPUBindGroupLayoutEntry, binding, visibility, ty, 122 multisampled, has_dynamic_offset, view_dimension, texture_component_type, 123 storage_texture_format); 124 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 125 mozilla::webgpu::SerialBindGroupLayoutDescriptor, mLabel, mEntries); 126 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 127 mozilla::webgpu::SerialPipelineLayoutDescriptor, mBindGroupLayouts); 128 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::SerialBindGroupEntry, 129 mBinding, mType, mValue, mBufferOffset, 130 mBufferSize); 131 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::SerialBindGroupDescriptor, 132 mLabel, mLayout, mEntries); 133 134 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 135 mozilla::webgpu::SerialProgrammableStageDescriptor, mModule, mEntryPoint); 136 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 137 mozilla::webgpu::SerialVertexBufferLayoutDescriptor, mArrayStride, 138 mStepMode, mAttributes); 139 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::SerialVertexStateDescriptor, 140 mIndexFormat, mVertexBuffers); 141 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 142 mozilla::webgpu::SerialComputePipelineDescriptor, mLayout, mComputeStage); 143 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 144 mozilla::webgpu::SerialRenderPipelineDescriptor, mLayout, mVertexStage, 145 mFragmentStage, mPrimitiveTopology, mRasterizationState, mColorStates, 146 mDepthStencilState, mVertexState, mSampleCount, mSampleMask, 147 mAlphaToCoverageEnabled); 148 149 #undef DEFINE_IPC_SERIALIZER_FFI_ENUM 150 #undef DEFINE_IPC_SERIALIZER_DOM_ENUM 151 #undef DEFINE_IPC_SERIALIZER_ENUM_GUARD 152 153 } // namespace IPC 154 #endif // WEBGPU_SERIALIZE_H_ 155