1 // 2 // Copyright 2024 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // VertexArrayWgpu.h: 7 // Defines the class interface for VertexArrayWgpu, implementing VertexArrayImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_WGPU_VERTEXARRAYWGPU_H_ 11 #define LIBANGLE_RENDERER_WGPU_VERTEXARRAYWGPU_H_ 12 13 #include "libANGLE/renderer/VertexArrayImpl.h" 14 #include "libANGLE/renderer/wgpu/BufferWgpu.h" 15 #include "libANGLE/renderer/wgpu/wgpu_pipeline_state.h" 16 #include "libANGLE/renderer/wgpu/wgpu_utils.h" 17 18 namespace rx 19 { 20 21 enum class BufferType 22 { 23 IndexBuffer, 24 ArrayBuffer, 25 }; 26 27 enum class IndexDataNeedsStreaming 28 { 29 Yes, 30 No, 31 }; 32 33 struct VertexBufferWithOffset 34 { 35 webgpu::BufferHelper *buffer = nullptr; 36 size_t offset = 0; 37 }; 38 39 class VertexArrayWgpu : public VertexArrayImpl 40 { 41 public: 42 VertexArrayWgpu(const gl::VertexArrayState &data); 43 44 angle::Result syncState(const gl::Context *context, 45 const gl::VertexArray::DirtyBits &dirtyBits, 46 gl::VertexArray::DirtyAttribBitsArray *attribBits, 47 gl::VertexArray::DirtyBindingBitsArray *bindingBits) override; 48 getVertexBuffer(size_t slot)49 const VertexBufferWithOffset &getVertexBuffer(size_t slot) const 50 { 51 return mCurrentArrayBuffers[slot]; 52 } getIndexBuffer()53 webgpu::BufferHelper *getIndexBuffer() const { return mCurrentIndexBuffer; } 54 55 angle::Result syncClientArrays(const gl::Context *context, 56 const gl::AttributesMask &activeAttributesMask, 57 gl::PrimitiveMode mode, 58 GLint first, 59 GLsizei count, 60 GLsizei instanceCount, 61 gl::DrawElementsType drawElementsTypeOrInvalid, 62 const void *indices, 63 GLint baseVertex, 64 bool primitiveRestartEnabled, 65 const void **adjustedIndicesPtr, 66 uint32_t *indexCountOut); 67 68 private: 69 angle::Result syncDirtyAttrib(ContextWgpu *contextWgpu, 70 const gl::VertexAttribute &attrib, 71 const gl::VertexBinding &binding, 72 size_t attribIndex); 73 angle::Result syncDirtyElementArrayBuffer(ContextWgpu *contextWgpu); 74 75 angle::Result ensureBufferCreated(const gl::Context *context, 76 webgpu::BufferHelper &buffer, 77 size_t size, 78 size_t attribIndex, 79 wgpu::BufferUsage usage, 80 BufferType bufferType); 81 82 gl::AttribArray<webgpu::PackedVertexAttribute> mCurrentAttribs; 83 gl::AttribArray<webgpu::BufferHelper> mStreamingArrayBuffers; 84 gl::AttribArray<VertexBufferWithOffset> mCurrentArrayBuffers; 85 86 // Attributes that need to be streamed due to incompatibilities 87 gl::AttributesMask mForcedStreamingAttributes; 88 89 webgpu::BufferHelper mStreamingIndexBuffer; 90 webgpu::BufferHelper *mCurrentIndexBuffer = nullptr; 91 }; 92 93 } // namespace rx 94 95 #endif // LIBANGLE_RENDERER_WGPU_VERTEXARRAYWGPU_H_ 96