3939#include " mozilla/dom/VideoFrame.h"
4040#include " mozilla/dom/WebGPUBinding.h"
4141#include " mozilla/gfx/gfxVars.h"
42+ #include " mozilla/webgpu/ffi/wgpu.h"
4243#include " nsGlobalWindowInner.h"
4344
4445namespace mozilla ::webgpu {
@@ -749,7 +750,7 @@ RawId CreateRenderPipelineImpl(RawId deviceId, WebGPUChild* aChild,
749750 const dom::GPURenderPipelineDescriptor& aDesc,
750751 bool isAsync) {
751752 // A bunch of stack locals that we can have pointers into
752- nsTArray<ffi::WGPUVertexBufferLayout > vertexBuffers;
753+ nsTArray<ffi::WGPUFfiOption_VertexBufferLayout > vertexBuffers;
753754 nsTArray<ffi::WGPUVertexAttribute> vertexAttributes;
754755 ffi::WGPURenderPipelineDescriptor desc = {};
755756 nsCString vsEntry, fsEntry;
@@ -798,8 +799,12 @@ RawId CreateRenderPipelineImpl(RawId deviceId, WebGPUChild* aChild,
798799 }
799800
800801 for (const auto & vertex_desc : stage.mBuffers ) {
801- ffi::WGPUVertexBufferLayout vb_desc = {};
802- if (!vertex_desc.IsNull ()) {
802+ ffi::WGPUFfiOption_VertexBufferLayout opt_vb_desc = {};
803+ if (vertex_desc.IsNull ()) {
804+ opt_vb_desc.tag =
805+ ffi::WGPUFfiOption_VertexBufferLayout_None_VertexBufferLayout;
806+ } else {
807+ ffi::WGPUVertexBufferLayout vb_desc = {};
803808 const auto & vd = vertex_desc.Value ();
804809 vb_desc.array_stride = vd.mArrayStride ;
805810 vb_desc.step_mode = ffi::WGPUVertexStepMode (vd.mStepMode );
@@ -812,14 +817,21 @@ RawId CreateRenderPipelineImpl(RawId deviceId, WebGPUChild* aChild,
812817 ad.shader_location = vat.mShaderLocation ;
813818 vertexAttributes.AppendElement (ad);
814819 }
820+ opt_vb_desc.tag =
821+ ffi::WGPUFfiOption_VertexBufferLayout_Some_VertexBufferLayout;
822+ opt_vb_desc.some = vb_desc;
815823 }
816- vertexBuffers.AppendElement (vb_desc );
824+ vertexBuffers.AppendElement (opt_vb_desc );
817825 }
818826 // Now patch up all the pointers to attribute lists.
819827 size_t numAttributes = 0 ;
820828 for (auto & vb_desc : vertexBuffers) {
821- vb_desc.attributes .data = vertexAttributes.Elements () + numAttributes;
822- numAttributes += vb_desc.attributes .length ;
829+ if (vb_desc.tag ==
830+ ffi::WGPUFfiOption_VertexBufferLayout_Some_VertexBufferLayout) {
831+ vb_desc.some .attributes .data =
832+ vertexAttributes.Elements () + numAttributes;
833+ numAttributes += vb_desc.some .attributes .length ;
834+ }
823835 }
824836
825837 vertexState.buffers = {vertexBuffers.Elements (), vertexBuffers.Length ()};
0 commit comments