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) ...@@ -36,6 +36,7 @@ VertexArrayVk::VertexArrayVk(const gl::VertexArrayState &state)
mCurrentElementArrayBufferResource(nullptr), mCurrentElementArrayBufferResource(nullptr),
mDynamicVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, kDynamicVertexDataSize), mDynamicVertexData(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, kDynamicVertexDataSize),
mDynamicIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize), mDynamicIndexData(VK_BUFFER_USAGE_INDEX_BUFFER_BIT, kDynamicIndexDataSize),
mDirtyLineLoopTranslation(true),
mVertexBuffersDirty(false), mVertexBuffersDirty(false),
mIndexBufferDirty(false) mIndexBufferDirty(false)
{ {
...@@ -76,7 +77,7 @@ gl::Error VertexArrayVk::streamVertexData(RendererVk *renderer, ...@@ -76,7 +77,7 @@ gl::Error VertexArrayVk::streamVertexData(RendererVk *renderer,
// TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up // TODO(fjhenigman): When we have a bunch of interleaved attributes, they end up
// un-interleaved, wasting space and copying time. Consider improving on that. // 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::VertexAttribute &attrib = attribs[attribIndex];
const gl::VertexBinding &binding = bindings[attrib.bindingIndex]; const gl::VertexBinding &binding = bindings[attrib.bindingIndex];
...@@ -181,13 +182,15 @@ gl::Error VertexArrayVk::syncState(const gl::Context *context, ...@@ -181,13 +182,15 @@ gl::Error VertexArrayVk::syncState(const gl::Context *context,
mCurrentElementArrayBufferHandle = VK_NULL_HANDLE; mCurrentElementArrayBufferHandle = VK_NULL_HANDLE;
mCurrentElementArrayBufferOffset = 0; mCurrentElementArrayBufferOffset = 0;
} }
mIndexBufferDirty = true; mIndexBufferDirty = true;
mDirtyLineLoopTranslation = true;
break; break;
} }
case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA: case gl::VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA:
mLineLoopBufferFirstIndex.reset(); mLineLoopBufferFirstIndex.reset();
mLineLoopBufferLastIndex.reset(); mLineLoopBufferLastIndex.reset();
mDirtyLineLoopTranslation = true;
break; break;
default: default:
...@@ -348,6 +351,7 @@ gl::Error VertexArrayVk::drawArrays(const gl::Context *context, ...@@ -348,6 +351,7 @@ gl::Error VertexArrayVk::drawArrays(const gl::Context *context,
} }
// Handle GL_LINE_LOOP drawArrays. // Handle GL_LINE_LOOP drawArrays.
// This test may be incorrect if the draw call switches from DrawArrays/DrawElements.
int lastVertex = drawCallParams.firstVertex() + drawCallParams.vertexCount(); int lastVertex = drawCallParams.firstVertex() + drawCallParams.vertexCount();
if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() || if (!mLineLoopBufferFirstIndex.valid() || !mLineLoopBufferLastIndex.valid() ||
mLineLoopBufferFirstIndex != drawCallParams.firstVertex() || mLineLoopBufferFirstIndex != drawCallParams.firstVertex() ||
...@@ -397,9 +401,13 @@ gl::Error VertexArrayVk::drawElements(const gl::Context *context, ...@@ -397,9 +401,13 @@ gl::Error VertexArrayVk::drawElements(const gl::Context *context,
VkIndexType indexType = gl_vk::GetIndexType(drawCallParams.type()); VkIndexType indexType = gl_vk::GetIndexType(drawCallParams.type());
ANGLE_TRY(mLineLoopHandler.createIndexBufferFromElementArrayBuffer( // This also doesn't check if the element type changed, which should trigger translation.
renderer, elementArrayBufferVk, indexType, drawCallParams.indexCount(), if (mDirtyLineLoopTranslation)
&mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset)); {
ANGLE_TRY(mLineLoopHandler.createIndexBufferFromElementArrayBuffer(
renderer, elementArrayBufferVk, indexType, drawCallParams.indexCount(),
&mCurrentElementArrayBufferHandle, &mCurrentElementArrayBufferOffset));
}
ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer)); ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
vk::LineLoopHandler::Draw(drawCallParams.indexCount(), commandBuffer); vk::LineLoopHandler::Draw(drawCallParams.indexCount(), commandBuffer);
...@@ -480,5 +488,4 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context, ...@@ -480,5 +488,4 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
} // namespace rx } // namespace rx
...@@ -111,6 +111,7 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -111,6 +111,7 @@ class VertexArrayVk : public VertexArrayImpl
vk::LineLoopHandler mLineLoopHandler; vk::LineLoopHandler mLineLoopHandler;
Optional<int> mLineLoopBufferFirstIndex; Optional<int> mLineLoopBufferFirstIndex;
Optional<int> mLineLoopBufferLastIndex; Optional<int> mLineLoopBufferLastIndex;
bool mDirtyLineLoopTranslation;
// Cache variable for determining whether or not to store new dependencies in the node. // Cache variable for determining whether or not to store new dependencies in the node.
bool mVertexBuffersDirty; bool mVertexBuffersDirty;
......
...@@ -1176,8 +1176,7 @@ void GarbageObject::destroy(VkDevice device) ...@@ -1176,8 +1176,7 @@ void GarbageObject::destroy(VkDevice device)
} }
LineLoopHandler::LineLoopHandler() LineLoopHandler::LineLoopHandler()
: mObserverBinding(this, 0u), : mDynamicLineLoopIndicesData(
mDynamicLineLoopIndicesData(
new DynamicBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, new DynamicBuffer(VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
kLineLoopDynamicBufferMinSize)) kLineLoopDynamicBufferMinSize))
{ {
...@@ -1224,15 +1223,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r ...@@ -1224,15 +1223,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r
{ {
ASSERT(indexType == VK_INDEX_TYPE_UINT16 || indexType == VK_INDEX_TYPE_UINT32); 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 *indices = nullptr;
uint32_t offset = 0; uint32_t offset = 0;
...@@ -1262,7 +1252,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r ...@@ -1262,7 +1252,6 @@ gl::Error LineLoopHandler::createIndexBufferFromElementArrayBuffer(RendererVk *r
void LineLoopHandler::destroy(VkDevice device) void LineLoopHandler::destroy(VkDevice device)
{ {
mObserverBinding.reset();
mDynamicLineLoopIndicesData->destroy(device); mDynamicLineLoopIndicesData->destroy(device);
} }
...@@ -1278,17 +1267,6 @@ ResourceVk *LineLoopHandler::getLineLoopBufferResource() ...@@ -1278,17 +1267,6 @@ ResourceVk *LineLoopHandler::getLineLoopBufferResource()
return mDynamicLineLoopIndicesData.get(); 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 implementation.
ImageHelper::ImageHelper() ImageHelper::ImageHelper()
: mFormat(nullptr), : mFormat(nullptr),
......
...@@ -649,7 +649,7 @@ Error AllocateImageMemory(RendererVk *renderer, ...@@ -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 // 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. // these indexes: [0, 1, 2, 3, 0] to emulate the loop.
class LineLoopHandler final : angle::NonCopyable, angle::ObserverInterface class LineLoopHandler final : angle::NonCopyable
{ {
public: public:
LineLoopHandler(); LineLoopHandler();
...@@ -671,13 +671,7 @@ class LineLoopHandler final : angle::NonCopyable, angle::ObserverInterface ...@@ -671,13 +671,7 @@ class LineLoopHandler final : angle::NonCopyable, angle::ObserverInterface
ResourceVk *getLineLoopBufferResource(); ResourceVk *getLineLoopBufferResource();
// Observer interface implementation.
void onSubjectStateChange(const gl::Context *context,
angle::SubjectIndex index,
angle::SubjectMessage message) override;
private: private:
angle::ObserverBinding mObserverBinding;
std::unique_ptr<DynamicBuffer> mDynamicLineLoopIndicesData; std::unique_ptr<DynamicBuffer> mDynamicLineLoopIndicesData;
}; };
...@@ -763,7 +757,6 @@ class ImageHelper final : angle::NonCopyable ...@@ -763,7 +757,6 @@ class ImageHelper final : angle::NonCopyable
// Current state. // Current state.
VkImageLayout mCurrentLayout; VkImageLayout mCurrentLayout;
}; };
} // namespace vk } // namespace vk
namespace gl_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