Commit 32fd63bc by Jamie Madill Committed by Commit Bot

Vulkan: Use DrawCallParams in draw methods.

This cleans up some of the vertex streaming logic. Bug: angleproject:2389 Change-Id: I8ed2f8acd06bbdd97db40acac35e5692112a3efe Reviewed-on: https://chromium-review.googlesource.com/989257 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 0946393d
...@@ -148,17 +148,14 @@ gl::Error ContextVk::initPipeline(const gl::Context *context) ...@@ -148,17 +148,14 @@ gl::Error ContextVk::initPipeline(const gl::Context *context)
} }
gl::Error ContextVk::setupDraw(const gl::Context *context, gl::Error ContextVk::setupDraw(const gl::Context *context,
GLenum mode, const gl::DrawCallParams &drawCallParams,
DrawType drawType,
size_t firstVertex,
size_t lastVertex,
ResourceVk *elementArrayBufferOverride, ResourceVk *elementArrayBufferOverride,
vk::CommandBuffer **commandBuffer) vk::CommandBuffer **commandBufferOut)
{ {
if (mode != mCurrentDrawMode) if (drawCallParams.mode() != mCurrentDrawMode)
{ {
invalidateCurrentPipeline(); invalidateCurrentPipeline();
mCurrentDrawMode = mode; mCurrentDrawMode = drawCallParams.mode();
} }
if (!mCurrentPipeline) if (!mCurrentPipeline)
...@@ -179,15 +176,17 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, ...@@ -179,15 +176,17 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
vk::CommandGraphNode *graphNode = nullptr; vk::CommandGraphNode *graphNode = nullptr;
ANGLE_TRY(vkFBO->getCommandGraphNodeForDraw(context, &graphNode)); ANGLE_TRY(vkFBO->getCommandGraphNodeForDraw(context, &graphNode));
vk::CommandBuffer *commandBuffer = nullptr;
if (!graphNode->getInsideRenderPassCommands()->valid()) if (!graphNode->getInsideRenderPassCommands()->valid())
{ {
mVertexArrayDirty = true; mVertexArrayDirty = true;
mTexturesDirty = true; mTexturesDirty = true;
ANGLE_TRY(graphNode->beginInsideRenderPassRecording(mRenderer, commandBuffer)); ANGLE_TRY(graphNode->beginInsideRenderPassRecording(mRenderer, &commandBuffer));
} }
else else
{ {
*commandBuffer = graphNode->getInsideRenderPassCommands(); commandBuffer = graphNode->getInsideRenderPassCommands();
} }
// Ensure any writes to the VAO buffers are flushed before we read from them. // Ensure any writes to the VAO buffers are flushed before we read from them.
...@@ -196,7 +195,8 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, ...@@ -196,7 +195,8 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
mVertexArrayDirty = false; mVertexArrayDirty = false;
vkVAO->updateDrawDependencies(graphNode, programGL->getActiveAttribLocationsMask(), vkVAO->updateDrawDependencies(graphNode, programGL->getActiveAttribLocationsMask(),
elementArrayBufferOverride, queueSerial, drawType); elementArrayBufferOverride, queueSerial,
drawCallParams.isDrawElements());
} }
// Ensure any writes to the textures are flushed before we read from them. // Ensure any writes to the textures are flushed before we read from them.
...@@ -223,11 +223,9 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, ...@@ -223,11 +223,9 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
} }
} }
(*commandBuffer)->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->get()); commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->get());
ContextVk *contextVk = vk::GetImpl(context); ANGLE_TRY(vkVAO->streamVertexData(context, &mStreamingVertexData, drawCallParams));
ANGLE_TRY(vkVAO->streamVertexData(contextVk, &mStreamingVertexData, firstVertex, lastVertex)); commandBuffer->bindVertexBuffers(0, maxAttrib, vkVAO->getCurrentArrayBufferHandles().data(),
(*commandBuffer)
->bindVertexBuffers(0, maxAttrib, vkVAO->getCurrentArrayBufferHandles().data(),
vkVAO->getCurrentArrayBufferOffsets().data()); vkVAO->getCurrentArrayBufferOffsets().data());
// Update the queue serial for the pipeline object. // Update the queue serial for the pipeline object.
...@@ -247,21 +245,22 @@ gl::Error ContextVk::setupDraw(const gl::Context *context, ...@@ -247,21 +245,22 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
ASSERT(!descriptorSets.empty()); ASSERT(!descriptorSets.empty());
const vk::PipelineLayout &pipelineLayout = mRenderer->getGraphicsPipelineLayout(); const vk::PipelineLayout &pipelineLayout = mRenderer->getGraphicsPipelineLayout();
(*commandBuffer) commandBuffer->bindDescriptorSets(
->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, usedRange.low(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, usedRange.low(), usedRange.length(),
usedRange.length(), &descriptorSets[usedRange.low()], &descriptorSets[usedRange.low()], programVk->getDynamicOffsetsCount(),
programVk->getDynamicOffsetsCount(),
programVk->getDynamicOffsets()); programVk->getDynamicOffsets());
} }
*commandBufferOut = commandBuffer;
return gl::NoError(); return gl::NoError();
} }
gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count) gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
{ {
const gl::DrawCallParams &drawCallParams = context->getParams<gl::DrawCallParams>();
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(setupDraw(context, mode, DrawType::Arrays, first, first + count - 1, nullptr, ANGLE_TRY(setupDraw(context, drawCallParams, nullptr, &commandBuffer));
&commandBuffer));
if (mode == GL_LINE_LOOP) if (mode == GL_LINE_LOOP)
{ {
...@@ -293,6 +292,8 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -293,6 +292,8 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
GLenum type, GLenum type,
const void *indices) const void *indices)
{ {
const gl::DrawCallParams &drawCallParams = context->getParams<gl::DrawCallParams>();
gl::VertexArray *vao = mState.getState().getVertexArray(); gl::VertexArray *vao = mState.getState().getVertexArray();
const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get();
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
...@@ -311,8 +312,8 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -311,8 +312,8 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
this, elementArrayBufferVk, GetVkIndexType(type), count)); this, elementArrayBufferVk, GetVkIndexType(type), count));
// TODO(fjhenigman): calculate the index range and pass to setupDraw() // TODO(fjhenigman): calculate the index range and pass to setupDraw()
ANGLE_TRY(setupDraw(context, mode, DrawType::Elements, 0, 0, ANGLE_TRY(setupDraw(context, drawCallParams, mLineLoopHandler.getLineLoopBufferResource(),
mLineLoopHandler.getLineLoopBufferResource(), &commandBuffer)); &commandBuffer));
mLineLoopHandler.bindIndexBuffer(GetVkIndexType(type), &commandBuffer); mLineLoopHandler.bindIndexBuffer(GetVkIndexType(type), &commandBuffer);
commandBuffer->drawIndexed(count + 1, 1, 0, 0, 0); commandBuffer->drawIndexed(count + 1, 1, 0, 0, 0);
...@@ -320,7 +321,6 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -320,7 +321,6 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
else else
{ {
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
const bool computeIndexRange = vk::GetImpl(vao)->attribsToStream(contextVk).any();
gl::IndexRange range; gl::IndexRange range;
VkBuffer buffer = VK_NULL_HANDLE; VkBuffer buffer = VK_NULL_HANDLE;
uint32_t offset = 0; uint32_t offset = 0;
...@@ -338,12 +338,6 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -338,12 +338,6 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer); BufferVk *elementArrayBufferVk = vk::GetImpl(elementArrayBuffer);
buffer = elementArrayBufferVk->getVkBuffer().getHandle(); buffer = elementArrayBufferVk->getVkBuffer().getHandle();
offset = 0; offset = 0;
if (computeIndexRange)
{
ANGLE_TRY(elementArrayBufferVk->getIndexRange(
context, type, 0, count, false /*primitiveRestartEnabled*/, &range));
}
} }
else else
{ {
...@@ -368,16 +362,9 @@ gl::Error ContextVk::drawElements(const gl::Context *context, ...@@ -368,16 +362,9 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
memcpy(dst, indices, amount); memcpy(dst, indices, amount);
} }
ANGLE_TRY(mStreamingIndexData.flush(contextVk)); ANGLE_TRY(mStreamingIndexData.flush(contextVk));
if (computeIndexRange)
{
range =
gl::ComputeIndexRange(type, indices, count, false /*primitiveRestartEnabled*/);
}
} }
ANGLE_TRY(setupDraw(context, mode, DrawType::Elements, range.start, range.end, nullptr, ANGLE_TRY(setupDraw(context, drawCallParams, nullptr, &commandBuffer));
&commandBuffer));
commandBuffer->bindIndexBuffer(buffer, offset, GetVkIndexType(type)); commandBuffer->bindIndexBuffer(buffer, offset, GetVkIndexType(type));
commandBuffer->drawIndexed(count, 1, 0, 0, 0); commandBuffer->drawIndexed(count, 1, 0, 0, 0);
} }
......
...@@ -166,12 +166,9 @@ class ContextVk : public ContextImpl ...@@ -166,12 +166,9 @@ class ContextVk : public ContextImpl
private: private:
gl::Error initPipeline(const gl::Context *context); gl::Error initPipeline(const gl::Context *context);
gl::Error setupDraw(const gl::Context *context, gl::Error setupDraw(const gl::Context *context,
GLenum mode, const gl::DrawCallParams &drawCallParams,
DrawType drawType,
size_t firstVertex,
size_t lastVertex,
ResourceVk *elementArrayBufferOverride, ResourceVk *elementArrayBufferOverride,
vk::CommandBuffer **commandBuffer); vk::CommandBuffer **commandBufferOut);
RendererVk *mRenderer; RendererVk *mRenderer;
vk::PipelineAndSerial *mCurrentPipeline; vk::PipelineAndSerial *mCurrentPipeline;
......
...@@ -43,23 +43,27 @@ void VertexArrayVk::destroy(const gl::Context *context) ...@@ -43,23 +43,27 @@ void VertexArrayVk::destroy(const gl::Context *context)
{ {
} }
gl::AttributesMask VertexArrayVk::attribsToStream(ContextVk *context) const gl::AttributesMask VertexArrayVk::getAttribsToStream(const gl::Context *context) const
{ {
const gl::Program *programGL = context->getGLState().getProgram(); const gl::Program *programGL = context->getGLState().getProgram();
return mClientMemoryAttribs & programGL->getActiveAttribLocationsMask(); return mClientMemoryAttribs & programGL->getActiveAttribLocationsMask();
} }
gl::Error VertexArrayVk::streamVertexData(ContextVk *context, gl::Error VertexArrayVk::streamVertexData(const gl::Context *context,
StreamingBuffer *stream, StreamingBuffer *stream,
size_t firstVertex, const gl::DrawCallParams &drawCallParams)
size_t lastVertex)
{ {
ContextVk *contextVk = vk::GetImpl(context);
const auto &attribs = mState.getVertexAttributes(); const auto &attribs = mState.getVertexAttributes();
const auto &bindings = mState.getVertexBindings(); const auto &bindings = mState.getVertexBindings();
ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context));
const size_t lastVertex = drawCallParams.firstVertex() + drawCallParams.vertexCount();
// 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(context)) for (auto attribIndex : getAttribsToStream(context))
{ {
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];
...@@ -77,19 +81,19 @@ gl::Error VertexArrayVk::streamVertexData(ContextVk *context, ...@@ -77,19 +81,19 @@ gl::Error VertexArrayVk::streamVertexData(ContextVk *context,
// will work. If we don't start at zero all the indices will be off. // will work. If we don't start at zero all the indices will be off.
// TODO(fjhenigman): See if we can account for indices being off by adjusting // TODO(fjhenigman): See if we can account for indices being off by adjusting
// the offset, thus avoiding wasted memory. // the offset, thus avoiding wasted memory.
const size_t firstByte = firstVertex * binding.getStride(); const size_t firstByte = drawCallParams.firstVertex() * binding.getStride();
const size_t lastByte = const size_t lastByte =
lastVertex * binding.getStride() + gl::ComputeVertexAttributeTypeSize(attrib); lastVertex * binding.getStride() + gl::ComputeVertexAttributeTypeSize(attrib);
uint8_t *dst = nullptr; uint8_t *dst = nullptr;
uint32_t offset = 0; uint32_t offset = 0;
ANGLE_TRY(stream->allocate(context, lastByte, &dst, ANGLE_TRY(stream->allocate(contextVk, lastByte, &dst,
&mCurrentArrayBufferHandles[attribIndex], &offset, nullptr)); &mCurrentArrayBufferHandles[attribIndex], &offset, nullptr));
mCurrentArrayBufferOffsets[attribIndex] = static_cast<VkDeviceSize>(offset); mCurrentArrayBufferOffsets[attribIndex] = static_cast<VkDeviceSize>(offset);
memcpy(dst + firstByte, static_cast<const uint8_t *>(attrib.pointer) + firstByte, memcpy(dst + firstByte, static_cast<const uint8_t *>(attrib.pointer) + firstByte,
lastByte - firstByte); lastByte - firstByte);
} }
ANGLE_TRY(stream->flush(context)); ANGLE_TRY(stream->flush(contextVk));
return gl::NoError(); return gl::NoError();
} }
...@@ -188,7 +192,7 @@ void VertexArrayVk::updateDrawDependencies(vk::CommandGraphNode *readNode, ...@@ -188,7 +192,7 @@ void VertexArrayVk::updateDrawDependencies(vk::CommandGraphNode *readNode,
const gl::AttributesMask &activeAttribsMask, const gl::AttributesMask &activeAttribsMask,
ResourceVk *elementArrayBufferOverride, ResourceVk *elementArrayBufferOverride,
Serial serial, Serial serial,
DrawType drawType) bool isDrawElements)
{ {
// Handle the bound array buffers. // Handle the bound array buffers.
for (auto attribIndex : activeAttribsMask) for (auto attribIndex : activeAttribsMask)
...@@ -198,7 +202,7 @@ void VertexArrayVk::updateDrawDependencies(vk::CommandGraphNode *readNode, ...@@ -198,7 +202,7 @@ void VertexArrayVk::updateDrawDependencies(vk::CommandGraphNode *readNode,
} }
// Handle the bound element array buffer. // Handle the bound element array buffer.
if (drawType == DrawType::Elements) if (isDrawElements)
{ {
if (elementArrayBufferOverride != nullptr) if (elementArrayBufferOverride != nullptr)
{ {
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
#include "libANGLE/renderer/VertexArrayImpl.h" #include "libANGLE/renderer/VertexArrayImpl.h"
#include "libANGLE/renderer/vulkan/vk_cache_utils.h" #include "libANGLE/renderer/vulkan/vk_cache_utils.h"
namespace gl
{
class DrawCallParams;
} // namespace gl
namespace rx namespace rx
{ {
class BufferVk; class BufferVk;
...@@ -26,11 +31,9 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -26,11 +31,9 @@ class VertexArrayVk : public VertexArrayImpl
void destroy(const gl::Context *context) override; void destroy(const gl::Context *context) override;
gl::AttributesMask attribsToStream(ContextVk *context) const; gl::Error streamVertexData(const gl::Context *context,
gl::Error streamVertexData(ContextVk *context,
StreamingBuffer *stream, StreamingBuffer *stream,
size_t firstVertex, const gl::DrawCallParams &drawCallParams);
size_t lastVertex);
gl::Error syncState(const gl::Context *context, gl::Error syncState(const gl::Context *context,
const gl::VertexArray::DirtyBits &dirtyBits, const gl::VertexArray::DirtyBits &dirtyBits,
const gl::VertexArray::DirtyAttribBitsArray &attribBits, const gl::VertexArray::DirtyAttribBitsArray &attribBits,
...@@ -43,7 +46,7 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -43,7 +46,7 @@ class VertexArrayVk : public VertexArrayImpl
const gl::AttributesMask &activeAttribsMask, const gl::AttributesMask &activeAttribsMask,
ResourceVk *elementArrayBufferOverride, ResourceVk *elementArrayBufferOverride,
Serial serial, Serial serial,
DrawType drawType); bool isDrawElements);
void getPackedInputDescriptions(vk::PipelineDesc *pipelineDesc); void getPackedInputDescriptions(vk::PipelineDesc *pipelineDesc);
...@@ -58,6 +61,8 @@ class VertexArrayVk : public VertexArrayImpl ...@@ -58,6 +61,8 @@ class VertexArrayVk : public VertexArrayImpl
const gl::VertexBinding &binding, const gl::VertexBinding &binding,
const gl::VertexAttribute &attrib); const gl::VertexAttribute &attrib);
gl::AttributesMask getAttribsToStream(const gl::Context *context) const;
gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles; gl::AttribArray<VkBuffer> mCurrentArrayBufferHandles;
gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets; gl::AttribArray<VkDeviceSize> mCurrentArrayBufferOffsets;
gl::AttribArray<ResourceVk *> mCurrentArrayBufferResources; gl::AttribArray<ResourceVk *> mCurrentArrayBufferResources;
......
...@@ -59,12 +59,6 @@ class ResourceVk; ...@@ -59,12 +59,6 @@ class ResourceVk;
class RenderPassCache; class RenderPassCache;
class StreamingBuffer; class StreamingBuffer;
enum class DrawType
{
Arrays,
Elements,
};
ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_VK_OBJECT); ANGLE_GL_OBJECTS_X(ANGLE_PRE_DECLARE_VK_OBJECT);
const char *VulkanResultString(VkResult result); const char *VulkanResultString(VkResult result);
......
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