Commit 253038d8 by Jamie Madill Committed by Commit Bot

Vulkan: Refactor VertexArrayVk::streamIndexData.

This enables us to use the same code for streaming client side index arrays and for translating buffers. Also includes a few more code cleanups. Bug: angleproject:2786 Change-Id: Ic615d87cb50fd0acd8ab6b63ed334da4b1c40eff Reviewed-on: https://chromium-review.googlesource.com/1188952 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 2eb54074
...@@ -156,33 +156,36 @@ void VertexArrayVk::destroy(const gl::Context *context) ...@@ -156,33 +156,36 @@ void VertexArrayVk::destroy(const gl::Context *context)
} }
angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk, angle::Result VertexArrayVk::streamIndexData(ContextVk *contextVk,
const gl::DrawCallParams &drawCallParams) GLenum indexType,
size_t indexCount,
const void *sourcePointer,
vk::DynamicBuffer *dynamicBuffer)
{ {
ASSERT(!mState.getElementArrayBuffer().get()); ASSERT(!mState.getElementArrayBuffer().get() || indexType == GL_UNSIGNED_BYTE);
mDynamicIndexData.releaseRetainedBuffers(contextVk->getRenderer()); dynamicBuffer->releaseRetainedBuffers(contextVk->getRenderer());
const GLsizei amount = sizeof(GLushort) * drawCallParams.indexCount(); const size_t amount = sizeof(GLushort) * indexCount;
GLubyte *dst = nullptr; GLubyte *dst = nullptr;
ANGLE_TRY(mDynamicIndexData.allocate(contextVk, amount, &dst, &mCurrentElementArrayBufferHandle, ANGLE_TRY(dynamicBuffer->allocate(contextVk, amount, &dst, &mCurrentElementArrayBufferHandle,
&mCurrentElementArrayBufferOffset, nullptr)); &mCurrentElementArrayBufferOffset, nullptr));
if (drawCallParams.type() == GL_UNSIGNED_BYTE) if (indexType == GL_UNSIGNED_BYTE)
{ {
// Unsigned bytes don't have direct support in Vulkan so we have to expand the // Unsigned bytes don't have direct support in Vulkan so we have to expand the
// memory to a GLushort. // memory to a GLushort.
const GLubyte *in = static_cast<const GLubyte *>(drawCallParams.indices()); const GLubyte *in = static_cast<const GLubyte *>(sourcePointer);
GLushort *expandedDst = reinterpret_cast<GLushort *>(dst); GLushort *expandedDst = reinterpret_cast<GLushort *>(dst);
for (GLsizei index = 0; index < drawCallParams.indexCount(); index++) for (size_t index = 0; index < indexCount; index++)
{ {
expandedDst[index] = static_cast<GLushort>(in[index]); expandedDst[index] = static_cast<GLushort>(in[index]);
} }
} }
else else
{ {
memcpy(dst, drawCallParams.indices(), amount); memcpy(dst, sourcePointer, amount);
} }
ANGLE_TRY(mDynamicIndexData.flush(contextVk)); ANGLE_TRY(dynamicBuffer->flush(contextVk));
return angle::Result::Continue(); return angle::Result::Continue();
} }
...@@ -670,16 +673,17 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context, ...@@ -670,16 +673,17 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
if (!glBuffer && !isLineLoop) if (!glBuffer && !isLineLoop)
{ {
ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context)); ANGLE_TRY(streamIndexData(contextVk, drawCallParams.type(), drawCallParams.indexCount(),
ANGLE_TRY(streamIndexData(contextVk, drawCallParams)); drawCallParams.indices(), &mDynamicIndexData));
commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle, commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle,
mCurrentElementArrayBufferOffset, mCurrentElementArrayBufferOffset,
gl_vk::GetIndexType(drawCallParams.type())); gl_vk::GetIndexType(drawCallParams.type()));
} }
else if (mIndexBufferDirty || newCommandBuffer || offset != mLastIndexBufferOffset) else if (mIndexBufferDirty || newCommandBuffer || offset != mLastIndexBufferOffset)
{ {
if (drawCallParams.type() == GL_UNSIGNED_BYTE && mLastIndexBufferOffset = offset;
drawCallParams.mode() != gl::PrimitiveMode::LineLoop)
if (drawCallParams.type() == GL_UNSIGNED_BYTE && !isLineLoop)
{ {
// Unsigned bytes don't have direct support in Vulkan so we have to expand the // Unsigned bytes don't have direct support in Vulkan so we have to expand the
// memory to a GLushort. // memory to a GLushort.
...@@ -691,42 +695,20 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context, ...@@ -691,42 +695,20 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
intptr_t offsetIntoSrcData = reinterpret_cast<intptr_t>(drawCallParams.indices()); intptr_t offsetIntoSrcData = reinterpret_cast<intptr_t>(drawCallParams.indices());
srcData += offsetIntoSrcData; srcData += offsetIntoSrcData;
// Allocate a new buffer that's double the size of the buffer provided by the user to ANGLE_TRY(streamIndexData(contextVk, drawCallParams.type(),
// go from unsigned byte to unsigned short. static_cast<size_t>(bufferVk->getSize()) - offsetIntoSrcData,
uint8_t *allocatedData = nullptr; srcData, &mTranslatedByteIndexData));
bool newBufferAllocated = false;
ANGLE_TRY(mTranslatedByteIndexData.allocate(
contextVk, static_cast<size_t>(bufferVk->getSize()) * 2, &allocatedData,
&mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset,
&newBufferAllocated));
// Expand the source into the destination
ASSERT(!context->getGLState().isPrimitiveRestartEnabled());
uint16_t *expandedDst = reinterpret_cast<uint16_t *>(allocatedData);
for (GLsizei index = 0; index < bufferVk->getSize() - offsetIntoSrcData; index++)
{
expandedDst[index] = static_cast<GLushort>(srcData[index]);
}
// Make sure our writes are available. ANGLE_TRY(bufferVk->unmapImpl(contextVk));
ANGLE_TRY(mTranslatedByteIndexData.flush(contextVk));
GLboolean result = false;
ANGLE_TRY(bufferVk->unmap(context, &result));
// We do not add the offset from the drawCallParams here because we've already copied // We do not add the offset from the drawCallParams here because we've already copied
// the source starting at the offset requested. // the source starting at the offset requested.
commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle, offset = 0;
mCurrentElementArrayBufferOffset,
gl_vk::GetIndexType(drawCallParams.type()));
}
else
{
commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle,
mCurrentElementArrayBufferOffset + offset,
gl_vk::GetIndexType(drawCallParams.type()));
} }
mLastIndexBufferOffset = offset; commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle,
mCurrentElementArrayBufferOffset + offset,
gl_vk::GetIndexType(drawCallParams.type()));
const gl::State &glState = context->getGLState(); const gl::State &glState = context->getGLState();
vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer()); vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer());
......
...@@ -82,7 +82,11 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -82,7 +82,11 @@ class VertexArrayVk : public VertexArrayImpl
void updateElementArrayBufferReadDependency(vk::CommandGraphResource *drawFramebuffer, void updateElementArrayBufferReadDependency(vk::CommandGraphResource *drawFramebuffer,
Serial serial); Serial serial);
angle::Result streamIndexData(ContextVk *contextVk, const gl::DrawCallParams &drawCallParams); angle::Result streamIndexData(ContextVk *contextVk,
GLenum indexType,
size_t indexCount,
const void *sourcePointer,
vk::DynamicBuffer *dynamicBuffer);
angle::Result convertVertexBuffer(ContextVk *contextVk, angle::Result convertVertexBuffer(ContextVk *contextVk,
BufferVk *srcBuffer, BufferVk *srcBuffer,
const gl::VertexBinding &binding, const gl::VertexBinding &binding,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment