mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 10:25:28 +00:00
Typeify VertexBufferSlot and VertexAttributeLocation
Bug: dawn:442 Change-Id: Ic4c29eed51984d367dc7fd6055e33d26bfc7faed Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28041 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
6419bddd9b
commit
4099f65525
@@ -142,13 +142,10 @@ namespace dawn_native { namespace opengl {
|
||||
mIndexBuffer = ToBackend(buffer);
|
||||
}
|
||||
|
||||
void OnSetVertexBuffer(uint32_t slot, BufferBase* buffer, uint64_t offset) {
|
||||
void OnSetVertexBuffer(VertexBufferSlot slot, BufferBase* buffer, uint64_t offset) {
|
||||
mVertexBuffers[slot] = ToBackend(buffer);
|
||||
mVertexBufferOffsets[slot] = offset;
|
||||
|
||||
// Use 64 bit masks and make sure there are no shift UB
|
||||
static_assert(kMaxVertexBuffers <= 8 * sizeof(unsigned long long) - 1, "");
|
||||
mDirtyVertexBuffers |= 1ull << slot;
|
||||
mDirtyVertexBuffers.set(slot);
|
||||
}
|
||||
|
||||
void OnSetPipeline(RenderPipelineBase* pipeline) {
|
||||
@@ -168,13 +165,14 @@ namespace dawn_native { namespace opengl {
|
||||
mIndexBufferDirty = false;
|
||||
}
|
||||
|
||||
for (uint32_t slot : IterateBitSet(mDirtyVertexBuffers &
|
||||
mLastPipeline->GetVertexBufferSlotsUsed())) {
|
||||
for (uint32_t location :
|
||||
IterateBitSet(mLastPipeline->GetAttributesUsingVertexBuffer(slot))) {
|
||||
for (VertexBufferSlot slot : IterateBitSet(
|
||||
mDirtyVertexBuffers & mLastPipeline->GetVertexBufferSlotsUsed())) {
|
||||
for (VertexAttributeLocation location : IterateBitSet(
|
||||
ToBackend(mLastPipeline)->GetAttributesUsingVertexBuffer(slot))) {
|
||||
const VertexAttributeInfo& attribute =
|
||||
mLastPipeline->GetAttribute(location);
|
||||
|
||||
GLuint attribIndex = static_cast<GLuint>(static_cast<uint8_t>(location));
|
||||
GLuint buffer = mVertexBuffers[slot]->GetHandle();
|
||||
uint64_t offset = mVertexBufferOffsets[slot];
|
||||
|
||||
@@ -186,11 +184,11 @@ namespace dawn_native { namespace opengl {
|
||||
gl.BindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
if (VertexFormatIsInt(attribute.format)) {
|
||||
gl.VertexAttribIPointer(
|
||||
location, components, formatType, vertexBuffer.arrayStride,
|
||||
attribIndex, components, formatType, vertexBuffer.arrayStride,
|
||||
reinterpret_cast<void*>(
|
||||
static_cast<intptr_t>(offset + attribute.offset)));
|
||||
} else {
|
||||
gl.VertexAttribPointer(location, components, formatType, normalized,
|
||||
gl.VertexAttribPointer(attribIndex, components, formatType, normalized,
|
||||
vertexBuffer.arrayStride,
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(
|
||||
offset + attribute.offset)));
|
||||
@@ -205,9 +203,9 @@ namespace dawn_native { namespace opengl {
|
||||
bool mIndexBufferDirty = false;
|
||||
Buffer* mIndexBuffer = nullptr;
|
||||
|
||||
std::bitset<kMaxVertexBuffers> mDirtyVertexBuffers;
|
||||
std::array<Buffer*, kMaxVertexBuffers> mVertexBuffers;
|
||||
std::array<uint64_t, kMaxVertexBuffers> mVertexBufferOffsets;
|
||||
ityp::bitset<VertexBufferSlot, kMaxVertexBuffers> mDirtyVertexBuffers;
|
||||
ityp::array<VertexBufferSlot, Buffer*, kMaxVertexBuffers> mVertexBuffers;
|
||||
ityp::array<VertexBufferSlot, uint64_t, kMaxVertexBuffers> mVertexBufferOffsets;
|
||||
|
||||
RenderPipelineBase* mLastPipeline = nullptr;
|
||||
};
|
||||
|
||||
@@ -218,29 +218,36 @@ namespace dawn_native { namespace opengl {
|
||||
return mGlPrimitiveTopology;
|
||||
}
|
||||
|
||||
ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes>
|
||||
RenderPipeline::GetAttributesUsingVertexBuffer(VertexBufferSlot slot) const {
|
||||
ASSERT(!IsError());
|
||||
return mAttributesUsingVertexBuffer[slot];
|
||||
}
|
||||
|
||||
void RenderPipeline::CreateVAOForVertexState(const VertexStateDescriptor* vertexState) {
|
||||
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||
|
||||
gl.GenVertexArrays(1, &mVertexArrayObject);
|
||||
gl.BindVertexArray(mVertexArrayObject);
|
||||
|
||||
for (uint32_t location : IterateBitSet(GetAttributeLocationsUsed())) {
|
||||
for (VertexAttributeLocation location : IterateBitSet(GetAttributeLocationsUsed())) {
|
||||
const auto& attribute = GetAttribute(location);
|
||||
gl.EnableVertexAttribArray(location);
|
||||
GLuint glAttrib = static_cast<GLuint>(static_cast<uint8_t>(location));
|
||||
gl.EnableVertexAttribArray(glAttrib);
|
||||
|
||||
attributesUsingVertexBuffer[attribute.vertexBufferSlot][location] = true;
|
||||
mAttributesUsingVertexBuffer[attribute.vertexBufferSlot][location] = true;
|
||||
const VertexBufferInfo& vertexBuffer = GetVertexBuffer(attribute.vertexBufferSlot);
|
||||
|
||||
if (vertexBuffer.arrayStride == 0) {
|
||||
// Emulate a stride of zero (constant vertex attribute) by
|
||||
// setting the attribute instance divisor to a huge number.
|
||||
gl.VertexAttribDivisor(location, 0xffffffff);
|
||||
gl.VertexAttribDivisor(glAttrib, 0xffffffff);
|
||||
} else {
|
||||
switch (vertexBuffer.stepMode) {
|
||||
case wgpu::InputStepMode::Vertex:
|
||||
break;
|
||||
case wgpu::InputStepMode::Instance:
|
||||
gl.VertexAttribDivisor(location, 1);
|
||||
gl.VertexAttribDivisor(glAttrib, 1);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace dawn_native { namespace opengl {
|
||||
RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor);
|
||||
|
||||
GLenum GetGLPrimitiveTopology() const;
|
||||
ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes> GetAttributesUsingVertexBuffer(
|
||||
VertexBufferSlot slot) const;
|
||||
|
||||
void ApplyNow(PersistentPipelineState& persistentPipelineState);
|
||||
|
||||
@@ -42,6 +44,11 @@ namespace dawn_native { namespace opengl {
|
||||
// TODO(yunchao.he@intel.com): vao need to be deduplicated between pipelines.
|
||||
GLuint mVertexArrayObject;
|
||||
GLenum mGlPrimitiveTopology;
|
||||
|
||||
ityp::array<VertexBufferSlot,
|
||||
ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes>,
|
||||
kMaxVertexBuffers>
|
||||
mAttributesUsingVertexBuffer;
|
||||
};
|
||||
|
||||
}} // namespace dawn_native::opengl
|
||||
|
||||
Reference in New Issue
Block a user