Hash :
84492ff3
Author :
Date :
2024-09-10T13:11:07
Sync vertex attributs in VertexArrayWgpu. This change only sets vertex attributes within VertexArrayWgpu and sets them in the render pipeline description owned by the context. It does not yet set attributes in the output pipeline created in CreatePipeline, as vertex buffers are also not set yet. Bug: angleproject:359823692 Change-Id: I1c3848e15d790026d53d4ab5614b1125f773e06a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5781788 Commit-Queue: Liza Burakova <liza@chromium.org> Reviewed-by: Matthew Denton <mpdenton@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// VertexArrayWgpu.cpp:
// Implements the class methods for VertexArrayWgpu.
//
#include "libANGLE/renderer/wgpu/VertexArrayWgpu.h"
#include "common/debug.h"
#include "libANGLE/renderer/wgpu/ContextWgpu.h"
namespace rx
{
VertexArrayWgpu::VertexArrayWgpu(const gl::VertexArrayState &data) : VertexArrayImpl(data) {}
angle::Result VertexArrayWgpu::syncState(const gl::Context *context,
const gl::VertexArray::DirtyBits &dirtyBits,
gl::VertexArray::DirtyAttribBitsArray *attribBits,
gl::VertexArray::DirtyBindingBitsArray *bindingBits)
{
ASSERT(dirtyBits.any());
ContextWgpu *contextWgpu = GetImplAs<ContextWgpu>(context);
const std::vector<gl::VertexAttribute> &attribs = mState.getVertexAttributes();
const std::vector<gl::VertexBinding> &bindings = mState.getVertexBindings();
bool syncedAttribs = false;
for (auto iter = dirtyBits.begin(), endIter = dirtyBits.end(); iter != endIter; ++iter)
{
size_t dirtyBit = *iter;
switch (dirtyBit)
{
case gl::VertexArray::DIRTY_BIT_LOST_OBSERVATION:
case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER:
case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA:
break;
#define ANGLE_VERTEX_DIRTY_ATTRIB_FUNC(INDEX) \
case gl::VertexArray::DIRTY_BIT_ATTRIB_0 + INDEX: \
ANGLE_TRY(syncDirtyAttrib(contextWgpu, attribs[INDEX], \
bindings[attribs[INDEX].bindingIndex], INDEX)); \
(*attribBits)[INDEX].reset(); \
syncedAttribs = true; \
break;
ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_ATTRIB_FUNC)
#define ANGLE_VERTEX_DIRTY_BINDING_FUNC(INDEX) \
case gl::VertexArray::DIRTY_BIT_BINDING_0 + INDEX: \
ANGLE_TRY(syncDirtyAttrib(contextWgpu, attribs[INDEX], \
bindings[attribs[INDEX].bindingIndex], INDEX)); \
(*bindingBits)[INDEX].reset(); \
syncedAttribs = true; \
break;
ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BINDING_FUNC)
#define ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC(INDEX) \
case gl::VertexArray::DIRTY_BIT_BUFFER_DATA_0 + INDEX: \
ANGLE_TRY(syncDirtyAttrib(contextWgpu, attribs[INDEX], \
bindings[attribs[INDEX].bindingIndex], INDEX)); \
syncedAttribs = true; \
break;
ANGLE_VERTEX_INDEX_CASES(ANGLE_VERTEX_DIRTY_BUFFER_DATA_FUNC)
default:
break;
}
}
if (syncedAttribs)
{
contextWgpu->setVertexAttributes(mCurrentAttribs);
}
return angle::Result::Continue;
}
angle::Result VertexArrayWgpu::syncDirtyAttrib(ContextWgpu *contextWgpu,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t attribIndex)
{
if (attrib.enabled)
{
const webgpu::Format &webgpuFormat =
contextWgpu->getFormat(attrib.format->glInternalFormat);
SetBitField(mCurrentAttribs[attribIndex].format, webgpuFormat.getActualWgpuVertexFormat());
gl::Buffer *bufferGl = binding.getBuffer().get();
mCurrentAttribs[attribIndex].enabled = true;
SetBitField(mCurrentAttribs[attribIndex].shaderLocation, attribIndex);
SetBitField(mCurrentAttribs[attribIndex].stride, binding.getStride());
if (bufferGl && bufferGl->getSize() > 0)
{
SetBitField(mCurrentAttribs[attribIndex].offset,
reinterpret_cast<uintptr_t>(attrib.pointer));
}
else
{
SetBitField(mCurrentAttribs[attribIndex].offset, binding.getOffset());
}
}
else
{
memset(&mCurrentAttribs[attribIndex], 0, sizeof(mCurrentAttribs[attribIndex]));
}
return angle::Result::Continue;
}
} // namespace rx