Commit b8e39660 by Jamie Madill Committed by Commit Bot

Vulkan: Remove Observer from LineLoopHandler.

This can now use the VertexArrayVk dirty bits. It also seems as though there are a couple caching bugs with the LineLoopHandler. Bug: angleproject:2389 Change-Id: I8af73f4acf56768ed9c68395349ba96acfbe9666 Reviewed-on: https://chromium-review.googlesource.com/989259 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarLuc Ferron <lucferron@google.com>
parent c3755fc5
......@@ -36,6 +36,7 @@ VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state)
mCurrentElementArrayBufferResource(nullptr),
mDynamicVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, kDynamicVertexDataSize),
mDynamicIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize),
mDirtyLineLoopTranslation(true),
mVertexBuffersDirty(false),
mIndexBufferDirty(false)
{
......@@ -76,7 +77,7 @@ gl::Error VertexArrayVk::streamVertexData(RendererVk *renderer,
// TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up
// un-interleaved, wasting space and copying time. Consider improving on that.
for (auto attribIndex : attribsToStream)
for (size_t attribIndex : attribsToStream)
{
const gl::VertexAttribute &attrib = attribs[attribIndex];
const gl::VertexBinding &binding = bindings[attrib.bindingIndex];
......@@ -181,13 +182,15 @@ gl::Error VertexArrayVk::syncState(const gl::Context *context,
mCurrentElementArrayBufferHandle = VK_NULL_HANDLE;
mCurrentElementArrayBufferOffset = 0;
}
mIndexBufferDirty = true;
mIndexBufferDirty = true;
mDirtyLineLoopTranslation = true;
break;
}
case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA:
mLineLoopBufferFirstIndex.reset();
mLineLoopBufferLastIndex.reset();
mDirtyLineLoopTranslation = true;
break;
default:
......@@ -348,6 +351,7 @@ gl::Error VertexArrayVk::drawArrays(const gl::Context *context,
}
// Handle GL_LINE_LOOP drawArrays.
// This test may be incorrect if the draw call switches from DrawArrays/DrawElements.
int lastVertex = drawCallParams.firstVertex() + drawCallParams.vertexCount();
if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() ||
mLineLoopBufferFirstIndex != drawCallParams.firstVertex() ||
......@@ -397,9 +401,13 @@ gl::Error VertexArrayVk::drawElements(const gl::Context *context,
VkIndexType indexType = gl_vk::GetIndexType(drawCallParams.type());
ANGLE_TRY(mLineLoopHandler.createIndexBufferFromElementArrayBuffer(
renderer, elementArrayBufferVk, indexType, drawCallParams.indexCount(),
&mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset));
// This also doesn't check if the element type changed, which should trigger translation.
if (mDirtyLineLoopTranslation)
{
ANGLE_TRY(mLineLoopHandler.createIndexBufferFromElementArrayBuffer(
renderer, elementArrayBufferVk, indexType, drawCallParams.indexCount(),
&mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset));
}
ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
vk::LineLoopHandler::Draw(drawCallParams.indexCount(), commandBuffer);
......@@ -480,5 +488,4 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
return gl::NoError();
}
} // namespace rx
......@@ -111,6 +111,7 @@ class VertexArrayVk : public VertexArrayImpl
vk::LineLoopHandler mLineLoopHandler;
Optional<int> mLineLoopBufferFirstIndex;
Optional<int> mLineLoopBufferLastIndex;
bool mDirtyLineLoopTranslation;
// Cache variable for determining whether or not to store new dependencies in the node.
bool mVertexBuffersDirty;
......
......@@ -1176,8 +1176,7 @@ void GarbageObject::destroy(VkDevice device)
}
LineLoopHandler::LineLoopHandler()
: mObserverBinding(this, 0u),
mDynamicLineLoopIndicesData(
: mDynamicLineLoopIndicesData(
new DynamicBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
kLineLoopDynamicBufferMinSize))
{
......@@ -1224,15 +1223,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r
{
ASSERT(indexType == VK_INDEX_TYPE_UINT16 || indexType == VK_INDEX_TYPE_UINT32);
if (elementArrayBufferVk == mObserverBinding.getSubject())
{
return gl::NoError();
}
// We want to know if the bufferVk changes at any point in time, because if it does we need to
// recopy our data on the next call.
mObserverBinding.bind(elementArrayBufferVk);
uint32_t *indices = nullptr;
uint32_t offset = 0;
......@@ -1262,7 +1252,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r
void LineLoopHandler::destroy(VkDevice device)
{
mObserverBinding.reset();
mDynamicLineLoopIndicesData->destroy(device);
}
......@@ -1278,17 +1267,6 @@ ResourceVk *LineLoopHandler::getLineLoopBufferResource()
return mDynamicLineLoopIndicesData.get();
}
void LineLoopHandler::onSubjectStateChange(const gl::Context *context,
angle::SubjectIndex index,
angle::SubjectMessage message)
{
// Indicate we want to recopy on next draw since something changed in the buffer.
if (message == angle::SubjectMessage::CONTENTS_CHANGED)
{
mObserverBinding.reset();
}
}
// ImageHelper implementation.
ImageHelper::ImageHelper()
: mFormat(nullptr),
......
......@@ -649,7 +649,7 @@ Error AllocateImageMemory(RendererVk *renderer,
//
// If the user wants to draw a loop between [v1, v2, v3], we will create an indexed buffer with
// these indexes: [0, 1, 2, 3, 0] to emulate the loop.
class LineLoopHandler final : angle::NonCopyable, angle::ObserverInterface
class LineLoopHandler final : angle::NonCopyable
{
public:
LineLoopHandler();
......@@ -671,13 +671,7 @@ class LineLoopHandler final : angle::NonCopyable, angle::ObserverInterface
ResourceVk *getLineLoopBufferResource();
// Observer interface implementation.
void onSubjectStateChange(const gl::Context *context,
angle::SubjectIndex index,
angle::SubjectMessage message) override;
private:
angle::ObserverBinding mObserverBinding;
std::unique_ptr<DynamicBuffer> mDynamicLineLoopIndicesData;
};
......@@ -763,7 +757,6 @@ class ImageHelper final : angle::NonCopyable
// Current state.
VkImageLayout mCurrentLayout;
};
} // namespace vk
namespace gl_vk
......
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