Vulkan: Move LineLoopHelper graph work into BufferVk.

Bug: angleproject:2828
Change-Id: Ie6bcdd10e2de415615db2bfb0b6fa17c392455b0
Reviewed-on: https://chromium-review.googlesource.com/1235655
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Jamie Madill 2018-09-27 08:24:32 -04:00 коммит произвёл Commit Bot
Родитель beb0c946de
Коммит 50e6eaaee6
5 изменённых файлов: 43 добавлений и 27 удалений

Просмотреть файл

@ -283,4 +283,15 @@ const vk::Buffer &BufferVk::getVkBuffer() const
return mBuffer; return mBuffer;
} }
angle::Result BufferVk::copyToBuffer(ContextVk *contextVk,
VkBuffer destbuffer,
uint32_t copyCount,
const VkBufferCopy *copies)
{
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
commandBuffer->copyBuffer(mBuffer.getHandle(), destbuffer, copyCount, copies);
return angle::Result::Continue();
}
} // namespace rx } // namespace rx

Просмотреть файл

@ -61,6 +61,12 @@ class BufferVk : public BufferImpl, public vk::CommandGraphResource
angle::Result mapImpl(ContextVk *contextVk, void **mapPtr); angle::Result mapImpl(ContextVk *contextVk, void **mapPtr);
angle::Result unmapImpl(ContextVk *contextVk); angle::Result unmapImpl(ContextVk *contextVk);
// Calls copyBuffer internally.
angle::Result copyToBuffer(ContextVk *contextVk,
VkBuffer destbuffer,
uint32_t copyCount,
const VkBufferCopy *copies);
private: private:
angle::Result setDataImpl(ContextVk *contextVk, angle::Result setDataImpl(ContextVk *contextVk,
const uint8_t *data, const uint8_t *data,

Просмотреть файл

@ -370,7 +370,7 @@ LineLoopHelper::LineLoopHelper(RendererVk *renderer)
LineLoopHelper::~LineLoopHelper() = default; LineLoopHelper::~LineLoopHelper() = default;
angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *context, angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *contextVk,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
VkBuffer *bufferHandleOut, VkBuffer *bufferHandleOut,
VkDeviceSize *offsetOut) VkDeviceSize *offsetOut)
@ -378,8 +378,8 @@ angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *context,
uint32_t *indices = nullptr; uint32_t *indices = nullptr;
size_t allocateBytes = sizeof(uint32_t) * (drawCallParams.vertexCount() + 1); size_t allocateBytes = sizeof(uint32_t) * (drawCallParams.vertexCount() + 1);
mDynamicIndexBuffer.releaseRetainedBuffers(context->getRenderer()); mDynamicIndexBuffer.releaseRetainedBuffers(contextVk->getRenderer());
ANGLE_TRY(mDynamicIndexBuffer.allocate(context, allocateBytes, ANGLE_TRY(mDynamicIndexBuffer.allocate(contextVk, allocateBytes,
reinterpret_cast<uint8_t **>(&indices), bufferHandleOut, reinterpret_cast<uint8_t **>(&indices), bufferHandleOut,
offsetOut, nullptr)); offsetOut, nullptr));
@ -397,12 +397,12 @@ angle::Result LineLoopHelper::getIndexBufferForDrawArrays(ContextVk *context,
// Since we are not using the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT flag when creating the // Since we are not using the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT flag when creating the
// device memory in the StreamingBuffer, we always need to make sure we flush it after // device memory in the StreamingBuffer, we always need to make sure we flush it after
// writing. // writing.
ANGLE_TRY(mDynamicIndexBuffer.flush(context)); ANGLE_TRY(mDynamicIndexBuffer.flush(contextVk));
return angle::Result::Continue(); return angle::Result::Continue();
} }
angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *context, angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *contextVk,
BufferVk *elementArrayBufferVk, BufferVk *elementArrayBufferVk,
GLenum glIndexType, GLenum glIndexType,
int indexCount, int indexCount,
@ -413,14 +413,14 @@ angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *con
if (glIndexType == GL_UNSIGNED_BYTE) if (glIndexType == GL_UNSIGNED_BYTE)
{ {
// Needed before reading buffer or we could get stale data. // Needed before reading buffer or we could get stale data.
ANGLE_TRY(context->getRenderer()->finish(context)); ANGLE_TRY(contextVk->getRenderer()->finish(contextVk));
void *srcDataMapping = nullptr; void *srcDataMapping = nullptr;
ANGLE_TRY(elementArrayBufferVk->mapImpl(context, &srcDataMapping)); ANGLE_TRY(elementArrayBufferVk->mapImpl(contextVk, &srcDataMapping));
ANGLE_TRY(streamIndices(context, glIndexType, indexCount, ANGLE_TRY(streamIndices(contextVk, glIndexType, indexCount,
static_cast<const uint8_t *>(srcDataMapping) + elementArrayOffset, static_cast<const uint8_t *>(srcDataMapping) + elementArrayOffset,
bufferHandleOut, bufferOffsetOut)); bufferHandleOut, bufferOffsetOut));
ANGLE_TRY(elementArrayBufferVk->unmapImpl(context)); ANGLE_TRY(elementArrayBufferVk->unmapImpl(contextVk));
return angle::Result::Continue(); return angle::Result::Continue();
} }
@ -431,8 +431,8 @@ angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *con
auto unitSize = (indexType == VK_INDEX_TYPE_UINT16 ? sizeof(uint16_t) : sizeof(uint32_t)); auto unitSize = (indexType == VK_INDEX_TYPE_UINT16 ? sizeof(uint16_t) : sizeof(uint32_t));
size_t allocateBytes = unitSize * (indexCount + 1) + 1; size_t allocateBytes = unitSize * (indexCount + 1) + 1;
mDynamicIndexBuffer.releaseRetainedBuffers(context->getRenderer()); mDynamicIndexBuffer.releaseRetainedBuffers(contextVk->getRenderer());
ANGLE_TRY(mDynamicIndexBuffer.allocate(context, allocateBytes, ANGLE_TRY(mDynamicIndexBuffer.allocate(contextVk, allocateBytes,
reinterpret_cast<uint8_t **>(&indices), bufferHandleOut, reinterpret_cast<uint8_t **>(&indices), bufferHandleOut,
bufferOffsetOut, nullptr)); bufferOffsetOut, nullptr));
@ -442,21 +442,16 @@ angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(ContextVk *con
{sourceOffset, *bufferOffsetOut, unitCount * unitSize}, {sourceOffset, *bufferOffsetOut, unitCount * unitSize},
{sourceOffset, *bufferOffsetOut + unitCount * unitSize, unitSize}, {sourceOffset, *bufferOffsetOut + unitCount * unitSize, unitSize},
}; };
if (context->getRenderer()->getFeatures().extraCopyBufferRegion) if (contextVk->getRenderer()->getFeatures().extraCopyBufferRegion)
copies.push_back({sourceOffset, *bufferOffsetOut + (unitCount + 1) * unitSize, 1}); copies.push_back({sourceOffset, *bufferOffsetOut + (unitCount + 1) * unitSize, 1});
vk::CommandBuffer *commandBuffer; ANGLE_TRY(elementArrayBufferVk->copyToBuffer(contextVk, *bufferHandleOut, copies.size(),
ANGLE_TRY(recordCommands(context, &commandBuffer)); copies.data()));
ANGLE_TRY(mDynamicIndexBuffer.flush(contextVk));
elementArrayBufferVk->addReadDependency(this);
commandBuffer->copyBuffer(elementArrayBufferVk->getVkBuffer().getHandle(), *bufferHandleOut,
copies.size(), copies.data());
ANGLE_TRY(mDynamicIndexBuffer.flush(context));
return angle::Result::Continue(); return angle::Result::Continue();
} }
angle::Result LineLoopHelper::streamIndices(ContextVk *context, angle::Result LineLoopHelper::streamIndices(ContextVk *contextVk,
GLenum glIndexType, GLenum glIndexType,
GLsizei indexCount, GLsizei indexCount,
const uint8_t *srcPtr, const uint8_t *srcPtr,
@ -469,7 +464,7 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *context,
auto unitSize = (indexType == VK_INDEX_TYPE_UINT16 ? sizeof(uint16_t) : sizeof(uint32_t)); auto unitSize = (indexType == VK_INDEX_TYPE_UINT16 ? sizeof(uint16_t) : sizeof(uint32_t));
size_t allocateBytes = unitSize * (indexCount + 1); size_t allocateBytes = unitSize * (indexCount + 1);
ANGLE_TRY(mDynamicIndexBuffer.allocate(context, allocateBytes, ANGLE_TRY(mDynamicIndexBuffer.allocate(contextVk, allocateBytes,
reinterpret_cast<uint8_t **>(&indices), bufferHandleOut, reinterpret_cast<uint8_t **>(&indices), bufferHandleOut,
bufferOffsetOut, nullptr)); bufferOffsetOut, nullptr));
@ -491,7 +486,7 @@ angle::Result LineLoopHelper::streamIndices(ContextVk *context,
memcpy(indices + unitSize * indexCount, srcPtr, unitSize); memcpy(indices + unitSize * indexCount, srcPtr, unitSize);
} }
ANGLE_TRY(mDynamicIndexBuffer.flush(context)); ANGLE_TRY(mDynamicIndexBuffer.flush(contextVk));
return angle::Result::Continue(); return angle::Result::Continue();
} }

Просмотреть файл

@ -132,18 +132,18 @@ class DynamicDescriptorPool final : angle::NonCopyable
// //
// 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 LineLoopHelper final : public vk::CommandGraphResource class LineLoopHelper final : angle::NonCopyable
{ {
public: public:
LineLoopHelper(RendererVk *renderer); LineLoopHelper(RendererVk *renderer);
~LineLoopHelper(); ~LineLoopHelper();
angle::Result getIndexBufferForDrawArrays(ContextVk *context, angle::Result getIndexBufferForDrawArrays(ContextVk *contextVk,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
VkBuffer *bufferHandleOut, VkBuffer *bufferHandleOut,
VkDeviceSize *offsetOut); VkDeviceSize *offsetOut);
angle::Result getIndexBufferForElementArrayBuffer(ContextVk *context, angle::Result getIndexBufferForElementArrayBuffer(ContextVk *contextVk,
BufferVk *elementArrayBufferVk, BufferVk *elementArrayBufferVk,
GLenum glIndexType, GLenum glIndexType,
int indexCount, int indexCount,
@ -151,7 +151,7 @@ class LineLoopHelper final : public vk::CommandGraphResource
VkBuffer *bufferHandleOut, VkBuffer *bufferHandleOut,
VkDeviceSize *bufferOffsetOut); VkDeviceSize *bufferOffsetOut);
angle::Result streamIndices(ContextVk *context, angle::Result streamIndices(ContextVk *contextVk,
GLenum glIndexType, GLenum glIndexType,
GLsizei indexCount, GLsizei indexCount,
const uint8_t *srcPtr, const uint8_t *srcPtr,

Просмотреть файл

@ -1096,6 +1096,10 @@ TEST_P(LineLoopStateChangeTest, DrawElementsThenDrawArrays)
// Draw line loop using a drawArrays followed by an hourglass with drawElements. // Draw line loop using a drawArrays followed by an hourglass with drawElements.
TEST_P(LineLoopStateChangeTest, DrawArraysThenDrawElements) TEST_P(LineLoopStateChangeTest, DrawArraysThenDrawElements)
{ {
// http://anglebug.com/2856: Seems to fail on older drivers and pass on newer.
// Tested failing on 18.3.3 and passing on 18.9.2.
ANGLE_SKIP_TEST_IF(IsAMD() && IsVulkan() && IsWindows());
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue()); ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
glUseProgram(program); glUseProgram(program);