Commit 316c6065 by Jamie Madill Committed by Commit Bot

Vulkan: Call GraphResource instead of GraphNode.

We don't need to use the CommandGraphNode class directly. This CL consolidates our code so we never call the GraphNodes class directly. Instead we call operations on GraphResource. This should simplify the interaction with APIs from the various graph and dependency management classes in the Vulkan back-end. A new concept of 'starting' vs 'appending' commands is introduced. Appending tries to avoid starting new command buffers when possible. Should not change how the graphs are constructed, and mostly be a refactoring change. There may be minor behaviour changes to some commands. Bug: angleproject:2539 Change-Id: Ia971e5cacb1164b9b3b22fa4a0a55b954d81f10e Reviewed-on: https://chromium-review.googlesource.com/1052068 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent b26ab825
......@@ -57,9 +57,7 @@ CommandGraphResource::CommandGraphResource() : mCurrentWritingNode(nullptr)
{
}
CommandGraphResource::~CommandGraphResource()
{
}
CommandGraphResource::~CommandGraphResource() = default;
void CommandGraphResource::updateQueueSerial(Serial queueSerial)
{
......@@ -83,18 +81,19 @@ bool CommandGraphResource::hasChildlessWritingNode() const
return (mCurrentWritingNode != nullptr && !mCurrentWritingNode->hasChildren());
}
CommandGraphNode *CommandGraphResource::getCurrentWritingNode()
{
return mCurrentWritingNode;
}
CommandGraphNode *CommandGraphResource::getNewWritingNode(RendererVk *renderer)
{
CommandGraphNode *newCommands = renderer->allocateCommandNode();
onWriteResource(newCommands, renderer->getCurrentQueueSerial());
onWriteImpl(newCommands, renderer->getCurrentQueueSerial());
return newCommands;
}
bool CommandGraphResource::hasStartedWriteResource() const
{
return hasChildlessWritingNode() &&
mCurrentWritingNode->getOutsideRenderPassCommands()->valid();
}
Error CommandGraphResource::beginWriteResource(RendererVk *renderer,
CommandBuffer **commandBufferOut)
{
......@@ -106,9 +105,75 @@ Error CommandGraphResource::beginWriteResource(RendererVk *renderer,
return NoError();
}
void CommandGraphResource::onWriteResource(CommandGraphNode *writingNode, Serial serial)
Error CommandGraphResource::appendWriteResource(RendererVk *renderer,
CommandBuffer **commandBufferOut)
{
updateQueueSerial(serial);
if (!hasChildlessWritingNode())
{
return beginWriteResource(renderer, commandBufferOut);
}
CommandBuffer *outsideRenderPassCommands = mCurrentWritingNode->getOutsideRenderPassCommands();
if (!outsideRenderPassCommands->valid())
{
ANGLE_TRY(mCurrentWritingNode->beginOutsideRenderPassRecording(
renderer->getDevice(), renderer->getCommandPool(), commandBufferOut));
}
else
{
*commandBufferOut = outsideRenderPassCommands;
}
return NoError();
}
void CommandGraphResource::appendToRenderPass(class CommandBuffer **commandBufferOut) const
{
ASSERT(hasStartedRenderPass());
*commandBufferOut = mCurrentWritingNode->getInsideRenderPassCommands();
}
bool CommandGraphResource::hasStartedRenderPass() const
{
return hasChildlessWritingNode() && mCurrentWritingNode->getInsideRenderPassCommands()->valid();
}
const gl::Rectangle &CommandGraphResource::getRenderPassRenderArea() const
{
ASSERT(hasStartedRenderPass());
return mCurrentWritingNode->getRenderPassRenderArea();
}
Error CommandGraphResource::beginRenderPass(RendererVk *renderer,
const Framebuffer &framebuffer,
const gl::Rectangle &renderArea,
const RenderPassDesc &renderPassDesc,
const std::vector<VkClearValue> &clearValues,
CommandBuffer **commandBufferOut) const
{
// Hard-code RenderPass to clear the first render target to the current clear value.
// TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361
mCurrentWritingNode->storeRenderPassInfo(framebuffer, renderArea, renderPassDesc, clearValues);
return mCurrentWritingNode->beginInsideRenderPassRecording(renderer, commandBufferOut);
}
void CommandGraphResource::onResourceChanged(RendererVk *renderer)
{
getNewWritingNode(renderer);
}
void CommandGraphResource::addWriteDependency(CommandGraphResource *writingResource)
{
CommandGraphNode *writingNode = writingResource->mCurrentWritingNode;
ASSERT(writingNode);
onWriteImpl(writingNode, writingResource->getQueueSerial());
}
void CommandGraphResource::onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial)
{
updateQueueSerial(currentSerial);
// Make sure any open reads and writes finish before we execute 'writingNode'.
if (!mCurrentReadingNodes.empty())
......@@ -125,14 +190,15 @@ void CommandGraphResource::onWriteResource(CommandGraphNode *writingNode, Serial
mCurrentWritingNode = writingNode;
}
void CommandGraphResource::onReadResource(CommandGraphNode *readingNode, Serial serial)
void CommandGraphResource::addReadDependency(CommandGraphResource *readingResource)
{
updateQueueSerial(serial);
updateQueueSerial(readingResource->getQueueSerial());
CommandGraphNode *readingNode = readingResource->mCurrentWritingNode;
ASSERT(readingNode);
if (hasChildlessWritingNode())
{
ASSERT(mStoredQueueSerial == serial);
// Ensure 'readingNode' happens after the current writing node.
CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, readingNode);
}
......@@ -158,7 +224,8 @@ bool CommandGraphResource::checkResourceInUseAndRefreshDeps(RendererVk *renderer
// CommandGraphNode implementation.
CommandGraphNode::CommandGraphNode() : mHasChildren(false), mVisitedState(VisitedState::Unvisited)
CommandGraphNode::CommandGraphNode()
: mRenderPassClearValues{}, mHasChildren(false), mVisitedState(VisitedState::Unvisited)
{
}
......@@ -370,9 +437,7 @@ const gl::Rectangle &CommandGraphNode::getRenderPassRenderArea() const
}
// CommandGraph implementation.
CommandGraph::CommandGraph()
{
}
CommandGraph::CommandGraph() = default;
CommandGraph::~CommandGraph()
{
......
......@@ -33,29 +33,58 @@ class CommandGraphResource
void updateQueueSerial(Serial queueSerial);
Serial getQueueSerial() const;
// Returns true if this node has a current writing node with no children.
bool hasChildlessWritingNode() const;
// Returns the active write node.
CommandGraphNode *getCurrentWritingNode();
// Allocates a new write node and calls onWriteResource internally.
CommandGraphNode *getNewWritingNode(RendererVk *renderer);
// Allocates a write node via getNewWriteNode and returns a started command buffer.
// The started command buffer will render outside of a RenderPass.
Error beginWriteResource(RendererVk *renderer, CommandBuffer **commandBufferOut);
// Sets up dependency relations. 'writingNode' will modify 'this' ResourceVk.
void onWriteResource(CommandGraphNode *writingNode, Serial serial);
// Check if we have started writing outside a RenderPass.
bool hasStartedWriteResource() const;
// Starts rendering to an existing command buffer for the resource.
// The started command buffer will render outside of a RenderPass.
// Calls beginWriteResource if we have not yet started writing.
Error appendWriteResource(RendererVk *renderer, CommandBuffer **commandBufferOut);
// Begins a command buffer on the current graph node for in-RenderPass rendering.
// Currently only called from FramebufferVk::getCommandBufferForDraw.
Error beginRenderPass(RendererVk *renderer,
const Framebuffer &framebuffer,
const gl::Rectangle &renderArea,
const RenderPassDesc &renderPassDesc,
const std::vector<VkClearValue> &clearValues,
CommandBuffer **commandBufferOut) const;
// Checks if we're in a RenderPass.
bool hasStartedRenderPass() const;
// Sets up dependency relations. 'readingNode' will read from 'this' ResourceVk.
void onReadResource(CommandGraphNode *readingNode, Serial serial);
// Returns a started command buffer if we've already called beginRenderPass.
void appendToRenderPass(CommandBuffer **commandBufferOut) const;
// Accessor for RenderPass RenderArea.
const gl::Rectangle &getRenderPassRenderArea() const;
// Called when 'this' object changes, but we'd like to start a new command buffer later.
void onResourceChanged(RendererVk *renderer);
// Sets up dependency relations. 'this' resource is the resource being written to.
void addWriteDependency(CommandGraphResource *writingResource);
// Sets up dependency relations. 'this' resource is the resource being read.
void addReadDependency(CommandGraphResource *readingResource);
// Returns false if the resource is not in use, and clears any current read/write nodes.
// TODO(jmadill): Remove this. http://anglebug.com/2539
bool checkResourceInUseAndRefreshDeps(RendererVk *renderer);
private:
void onWriteImpl(CommandGraphNode *writingNode, Serial currentSerial);
// Returns true if this node has a current writing node with no children.
bool hasChildlessWritingNode() const;
// Allocates a new write node and calls onWriteResource internally.
CommandGraphNode *getNewWritingNode(RendererVk *renderer);
Serial mStoredQueueSerial;
std::vector<CommandGraphNode *> mCurrentReadingNodes;
CommandGraphNode *mCurrentWritingNode;
......
......@@ -17,11 +17,8 @@
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/CompilerVk.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/DeviceVk.h"
#include "libANGLE/renderer/vulkan/FenceNVVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/ImageVk.h"
#include "libANGLE/renderer/vulkan/ProgramPipelineVk.h"
#include "libANGLE/renderer/vulkan/ProgramVk.h"
#include "libANGLE/renderer/vulkan/QueryVk.h"
......@@ -33,7 +30,6 @@
#include "libANGLE/renderer/vulkan/TextureVk.h"
#include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
#include "libANGLE/renderer/vulkan/VertexArrayVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
namespace rx
{
......@@ -139,8 +135,8 @@ gl::Error ContextVk::initPipeline()
gl::Error ContextVk::setupDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode **drawNodeOut,
bool *newCommandBufferOut)
vk::CommandBuffer **commandBufferOut,
bool *shouldApplyVertexArrayOut)
{
if (drawCallParams.mode() != mCurrentDrawMode)
{
......@@ -156,26 +152,22 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
const auto &state = mState.getState();
const gl::Program *programGL = state.getProgram();
ProgramVk *programVk = vk::GetImpl(programGL);
const auto *drawFBO = state.getDrawFramebuffer();
FramebufferVk *vkFBO = vk::GetImpl(drawFBO);
const gl::Framebuffer *framebuffer = state.getDrawFramebuffer();
FramebufferVk *framebufferVk = vk::GetImpl(framebuffer);
Serial queueSerial = mRenderer->getCurrentQueueSerial();
vk::CommandGraphNode *graphNode = nullptr;
ANGLE_TRY(vkFBO->getCommandGraphNodeForDraw(this, &graphNode));
vk::CommandBuffer *commandBuffer = nullptr;
vk::RecordingMode mode = vk::RecordingMode::Start;
ANGLE_TRY(framebufferVk->getCommandBufferForDraw(this, commandBufferOut, &mode));
if (!graphNode->getInsideRenderPassCommands()->valid())
if (mode == vk::RecordingMode::Start)
{
mTexturesDirty = true;
*newCommandBufferOut = true;
ANGLE_TRY(graphNode->beginInsideRenderPassRecording(mRenderer, &commandBuffer));
mTexturesDirty = true;
*shouldApplyVertexArrayOut = true;
}
else
{
*newCommandBufferOut = mVertexArrayBindingHasChanged;
*shouldApplyVertexArrayOut = mVertexArrayBindingHasChanged;
mVertexArrayBindingHasChanged = false;
commandBuffer = graphNode->getInsideRenderPassCommands();
}
// Ensure any writes to the textures are flushed before we read from them.
......@@ -202,11 +194,11 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
TextureVk *textureVk = vk::GetImpl(texture);
ANGLE_TRY(textureVk->ensureImageInitialized(mRenderer));
textureVk->onReadResource(graphNode, mRenderer->getCurrentQueueSerial());
textureVk->addReadDependency(framebufferVk);
}
}
commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->get());
(*commandBufferOut)->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline->get());
// Update the queue serial for the pipeline object.
ASSERT(mCurrentPipeline && mCurrentPipeline->valid());
......@@ -225,13 +217,13 @@ gl::Error ContextVk::setupDraw(const gl::Context *context,
ASSERT(!descriptorSets.empty());
const vk::PipelineLayout &pipelineLayout = mRenderer->getGraphicsPipelineLayout();
commandBuffer->bindDescriptorSets(
VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, usedRange.low(), usedRange.length(),
&descriptorSets[usedRange.low()], programVk->getDynamicOffsetsCount(),
programVk->getDynamicOffsets());
(*commandBufferOut)
->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, usedRange.low(),
usedRange.length(), &descriptorSets[usedRange.low()],
programVk->getDynamicOffsetsCount(),
programVk->getDynamicOffsets());
}
*drawNodeOut = graphNode;
return gl::NoError();
}
......@@ -242,13 +234,14 @@ gl::Error ContextVk::drawArrays(const gl::Context *context,
{
const gl::DrawCallParams &drawCallParams = context->getParams<gl::DrawCallParams>();
vk::CommandGraphNode *drawNode = nullptr;
bool newCommands = false;
ANGLE_TRY(setupDraw(context, drawCallParams, &drawNode, &newCommands));
vk::CommandBuffer *commandBuffer = nullptr;
bool shouldApplyVertexArray = false;
ANGLE_TRY(setupDraw(context, drawCallParams, &commandBuffer, &shouldApplyVertexArray));
const gl::VertexArray *vertexArray = context->getGLState().getVertexArray();
VertexArrayVk *vertexArrayVk = vk::GetImpl(vertexArray);
ANGLE_TRY(vertexArrayVk->drawArrays(context, mRenderer, drawCallParams, drawNode, newCommands));
ANGLE_TRY(vertexArrayVk->drawArrays(context, mRenderer, drawCallParams, commandBuffer,
shouldApplyVertexArray));
return gl::NoError();
}
......@@ -271,14 +264,14 @@ gl::Error ContextVk::drawElements(const gl::Context *context,
{
const gl::DrawCallParams &drawCallParams = context->getParams<gl::DrawCallParams>();
vk::CommandGraphNode *drawNode = nullptr;
bool newCommands = false;
ANGLE_TRY(setupDraw(context, drawCallParams, &drawNode, &newCommands));
vk::CommandBuffer *commandBuffer = nullptr;
bool shouldApplyVertexArray = false;
ANGLE_TRY(setupDraw(context, drawCallParams, &commandBuffer, &shouldApplyVertexArray));
gl::VertexArray *vao = mState.getState().getVertexArray();
VertexArrayVk *vertexArrayVk = vk::GetImpl(vao);
ANGLE_TRY(
vertexArrayVk->drawElements(context, mRenderer, drawCallParams, drawNode, newCommands));
ANGLE_TRY(vertexArrayVk->drawElements(context, mRenderer, drawCallParams, commandBuffer,
shouldApplyVertexArray));
return gl::NoError();
}
......
......@@ -168,8 +168,8 @@ class ContextVk : public ContextImpl
gl::Error initPipeline();
gl::Error setupDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode **drawNodeOut,
bool *newCommandBufferOut);
vk::CommandBuffer **commandBufferOut,
bool *shouldApplyVertexArrayOut);
void updateScissor(const gl::State &glState);
......
......@@ -88,7 +88,9 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
GLfloat *xy) const override;
const vk::RenderPassDesc &getRenderPassDesc();
gl::Error getCommandGraphNodeForDraw(ContextVk *contextVk, vk::CommandGraphNode **nodeOut);
gl::Error getCommandBufferForDraw(ContextVk *contextVk,
vk::CommandBuffer **commandBufferOut,
vk::RecordingMode *modeOut);
// Internal helper function for readPixels operations.
gl::Error readPixelsImpl(const gl::Context *context,
......
......@@ -26,30 +26,31 @@ RenderTargetVk::~RenderTargetVk()
{
}
void RenderTargetVk::onColorDraw(Serial currentSerial,
vk::CommandGraphNode *writingNode,
void RenderTargetVk::onColorDraw(vk::CommandGraphResource *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc)
{
ASSERT(writingNode->getOutsideRenderPassCommands()->valid());
ASSERT(commandBuffer->valid());
ASSERT(!mImage->getFormat().textureFormat().hasDepthOrStencilBits());
// Store the attachment info in the renderPassDesc.
renderPassDesc->packColorAttachment(*mImage);
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
mImage->changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
writingNode->getOutsideRenderPassCommands());
mImage->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, commandBuffer);
// Set up dependencies between the new graph node and other current nodes in the resource.
mResource->onWriteResource(writingNode, currentSerial);
// Set up dependencies between the RT resource and the Framebuffer.
mResource->addWriteDependency(framebufferVk);
}
void RenderTargetVk::onDepthStencilDraw(Serial currentSerial,
vk::CommandGraphNode *writingNode,
void RenderTargetVk::onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc)
{
ASSERT(writingNode->getOutsideRenderPassCommands()->valid());
ASSERT(commandBuffer->valid());
ASSERT(mImage->getFormat().textureFormat().hasDepthOrStencilBits());
// Store the attachment info in the renderPassDesc.
......@@ -62,11 +63,10 @@ void RenderTargetVk::onDepthStencilDraw(Serial currentSerial,
mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
writingNode->getOutsideRenderPassCommands());
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
// Set up dependencies between the new graph node and other current nodes in the resource.
mResource->onWriteResource(writingNode, currentSerial);
// Set up dependencies between the RT resource and the Framebuffer.
mResource->addWriteDependency(framebufferVk);
}
const vk::ImageHelper &RenderTargetVk::getImage() const
......@@ -106,10 +106,10 @@ void RenderTargetVk::updateSwapchainImage(vk::ImageHelper *image, vk::ImageView
}
vk::ImageHelper *RenderTargetVk::getImageForWrite(Serial currentSerial,
vk::CommandGraphNode *writingNode) const
vk::CommandGraphResource *writingResource) const
{
ASSERT(mImage && mImage->valid());
mResource->onWriteResource(writingNode, currentSerial);
mResource->addWriteDependency(writingResource);
return mImage;
}
......
......@@ -19,6 +19,7 @@ namespace rx
{
namespace vk
{
class CommandBuffer;
class CommandGraphNode;
class CommandGraphResource;
struct Format;
......@@ -39,17 +40,17 @@ class RenderTargetVk final : public FramebufferAttachmentRenderTarget
~RenderTargetVk();
// Note: RenderTargets should be called in order, with the depth/stencil onRender last.
void onColorDraw(Serial currentSerial,
vk::CommandGraphNode *writingNode,
void onColorDraw(vk::CommandGraphResource *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc);
void onDepthStencilDraw(Serial currentSerial,
vk::CommandGraphNode *writingNode,
void onDepthStencilDraw(vk::CommandGraphResource *framebufferVk,
vk::CommandBuffer *commandBuffer,
vk::RenderPassDesc *renderPassDesc);
const vk::ImageHelper &getImage() const;
vk::ImageHelper *getImageForWrite(Serial currentSerial,
vk::CommandGraphNode *writingNode) const;
vk::CommandGraphResource *writingResource) const;
vk::ImageView *getImageView() const;
vk::CommandGraphResource *getResource() const;
......
......@@ -342,7 +342,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
}
// Create a new graph node to store image initialization commands.
getNewWritingNode(renderer);
onResourceChanged(renderer);
// Handle initial data.
if (pixels)
......@@ -369,7 +369,7 @@ gl::Error TextureVk::setSubImage(const gl::Context *context,
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, pixels));
// Create a new graph node to store image initialization commands.
getNewWritingNode(contextVk->getRenderer());
onResourceChanged(contextVk->getRenderer());
return gl::NoError();
}
......@@ -442,7 +442,7 @@ gl::Error TextureVk::copySubImageImpl(const gl::Context *context,
destOffset.y + sourceArea.y - sourceArea.y, 0);
ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer();
FramebufferVk *framebufferVk = vk::GetImpl(source);
// For now, favor conformance. We do a CPU readback that does the conversion, and then stage the
......@@ -454,30 +454,16 @@ gl::Error TextureVk::copySubImageImpl(const gl::Context *context,
gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat,
framebufferVk));
vk::CommandGraphNode *writingNode = getNewWritingNode(contextVk->getRenderer());
framebufferVk->onReadResource(writingNode, contextVk->getRenderer()->getCurrentQueueSerial());
onResourceChanged(renderer);
framebufferVk->addReadDependency(this);
return gl::NoError();
}
vk::Error TextureVk::getCommandBufferForWrite(RendererVk *renderer,
vk::CommandBuffer **outCommandBuffer)
vk::CommandBuffer **commandBufferOut)
{
const VkDevice device = renderer->getDevice();
updateQueueSerial(renderer->getCurrentQueueSerial());
if (!hasChildlessWritingNode())
{
beginWriteResource(renderer, outCommandBuffer);
}
else
{
vk::CommandGraphNode *node = getCurrentWritingNode();
*outCommandBuffer = node->getOutsideRenderPassCommands();
if (!(*outCommandBuffer)->valid())
{
ANGLE_TRY(node->beginOutsideRenderPassRecording(device, renderer->getCommandPool(),
outCommandBuffer));
}
}
ANGLE_TRY(beginWriteResource(renderer, commandBufferOut));
return vk::NoError();
}
......
......@@ -171,7 +171,7 @@ class TextureVk : public TextureImpl, public vk::CommandGraphResource
const uint32_t levelCount,
vk::CommandBuffer *commandBuffer);
void releaseImage(const gl::Context *context, RendererVk *renderer);
vk::Error getCommandBufferForWrite(RendererVk *renderer, vk::CommandBuffer **outCommandBuffer);
vk::Error getCommandBufferForWrite(RendererVk *renderer, vk::CommandBuffer **commandBufferOut);
uint32_t getLevelCount() const;
vk::ImageHelper mImage;
......
......@@ -15,6 +15,7 @@
#include "libANGLE/renderer/vulkan/BufferVk.h"
#include "libANGLE/renderer/vulkan/CommandGraph.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/FramebufferVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_format_utils.h"
......@@ -269,7 +270,7 @@ const gl::AttribArray<VkDeviceSize> &VertexArrayVk::getCurrentArrayBufferOffsets
return mCurrentArrayBufferOffsets;
}
void VertexArrayVk::updateArrayBufferReadDependencies(vk::CommandGraphNode *readingNode,
void VertexArrayVk::updateArrayBufferReadDependencies(vk::CommandGraphResource *drawFramebuffer,
const gl::AttributesMask &activeAttribsMask,
Serial serial)
{
......@@ -277,17 +278,18 @@ void VertexArrayVk::updateArrayBufferReadDependencies(vk::CommandGraphNode *read
for (size_t attribIndex : activeAttribsMask)
{
if (mCurrentArrayBufferResources[attribIndex])
mCurrentArrayBufferResources[attribIndex]->onReadResource(readingNode, serial);
mCurrentArrayBufferResources[attribIndex]->addReadDependency(drawFramebuffer);
}
}
void VertexArrayVk::updateElementArrayBufferReadDependency(vk::CommandGraphNode *readingNode,
Serial serial)
void VertexArrayVk::updateElementArrayBufferReadDependency(
vk::CommandGraphResource *drawFramebuffer,
Serial serial)
{
// Handle the bound element array buffer.
if (mCurrentElementArrayBufferResource)
{
mCurrentElementArrayBufferResource->onReadResource(readingNode, serial);
mCurrentElementArrayBufferResource->addReadDependency(drawFramebuffer);
}
}
......@@ -350,13 +352,12 @@ void VertexArrayVk::updatePackedInputInfo(uint32_t attribIndex,
gl::Error VertexArrayVk::drawArrays(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer)
{
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
ASSERT(commandBuffer->valid());
ANGLE_TRY(onDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
ANGLE_TRY(onDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer));
// Note: Vertex indexes can be arbitrarily large.
uint32_t clampedVertexCount = drawCallParams.getClampedVertexCount<uint32_t>();
......@@ -392,15 +393,15 @@ gl::Error VertexArrayVk::drawArrays(const gl::Context *context,
gl::Error VertexArrayVk::drawElements(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer)
{
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
ASSERT(commandBuffer->valid());
if (drawCallParams.mode() != gl::PrimitiveMode::LineLoop)
{
ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
ANGLE_TRY(
onIndexedDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer));
commandBuffer->drawIndexed(drawCallParams.indexCount(), 1, 0, 0, 0);
return gl::NoError();
}
......@@ -428,7 +429,7 @@ gl::Error VertexArrayVk::drawElements(const gl::Context *context,
}
}
ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
ANGLE_TRY(onIndexedDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer));
vk::LineLoopHelper::Draw(drawCallParams.indexCount(), commandBuffer);
return gl::NoError();
......@@ -437,7 +438,7 @@ gl::Error VertexArrayVk::drawElements(const gl::Context *context,
gl::Error VertexArrayVk::onDraw(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer)
{
const gl::State &state = context->getGLState();
......@@ -453,7 +454,6 @@ gl::Error VertexArrayVk::onDraw(const gl::Context *context,
{
ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context));
ANGLE_TRY(streamVertexData(renderer, attribsToStream, drawCallParams));
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
commandBuffer->bindVertexBuffers(0, maxAttrib, mCurrentArrayBufferHandles.data(),
mCurrentArrayBufferOffsets.data());
}
......@@ -462,10 +462,11 @@ gl::Error VertexArrayVk::onDraw(const gl::Context *context,
{
if (maxAttrib > 0)
{
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
commandBuffer->bindVertexBuffers(0, maxAttrib, mCurrentArrayBufferHandles.data(),
mCurrentArrayBufferOffsets.data());
updateArrayBufferReadDependencies(drawNode, activeAttribs,
vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(state.getDrawFramebuffer());
updateArrayBufferReadDependencies(drawFramebuffer, activeAttribs,
renderer->getCurrentQueueSerial());
}
......@@ -486,17 +487,16 @@ gl::Error VertexArrayVk::onDraw(const gl::Context *context,
gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer)
{
ANGLE_TRY(onDraw(context, renderer, drawCallParams, drawNode, newCommandBuffer));
ANGLE_TRY(onDraw(context, renderer, drawCallParams, commandBuffer, newCommandBuffer));
if (!mState.getElementArrayBuffer().get() &&
drawCallParams.mode() != gl::PrimitiveMode::LineLoop)
{
ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context));
ANGLE_TRY(streamIndexData(renderer, drawCallParams));
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle,
mCurrentElementArrayBufferOffset,
gl_vk::GetIndexType(drawCallParams.type()));
......@@ -511,11 +511,13 @@ gl::Error VertexArrayVk::onIndexedDraw(const gl::Context *context,
<< "Unsigned byte translation is not implemented for indices in a buffer object";
}
vk::CommandBuffer *commandBuffer = drawNode->getInsideRenderPassCommands();
commandBuffer->bindIndexBuffer(mCurrentElementArrayBufferHandle,
mCurrentElementArrayBufferOffset,
gl_vk::GetIndexType(drawCallParams.type()));
updateElementArrayBufferReadDependency(drawNode, renderer->getCurrentQueueSerial());
const gl::State &glState = context->getGLState();
vk::CommandGraphResource *drawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer());
updateElementArrayBufferReadDependency(drawFramebuffer, renderer->getCurrentQueueSerial());
mIndexBufferDirty = false;
// If we've had a drawArrays call with a line loop before, we want to make sure this is
......
......@@ -45,7 +45,7 @@ class VertexArrayVk : public VertexArrayImpl
const gl::AttribArray<VkBuffer> &getCurrentArrayBufferHandles() const;
const gl::AttribArray<VkDeviceSize> &getCurrentArrayBufferOffsets() const;
void updateDrawDependencies(vk::CommandGraphNode *readingNode,
void updateDrawDependencies(vk::CommandGraphResource *drawFramebuffer,
const gl::AttributesMask &activeAttribsMask,
vk::CommandGraphResource *elementArrayBufferOverride,
Serial serial,
......@@ -57,13 +57,13 @@ class VertexArrayVk : public VertexArrayImpl
gl::Error drawArrays(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
bool newCommandBuffer);
vk::CommandBuffer *commandBuffer,
bool shouldApplyVertexArray);
gl::Error drawElements(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
bool newCommandBuffer);
vk::CommandBuffer *commandBuffer,
bool shouldApplyVertexArray);
private:
// This will update any dirty packed input descriptions, regardless if they're used by the
......@@ -76,11 +76,12 @@ class VertexArrayVk : public VertexArrayImpl
const gl::VertexBinding &binding,
const gl::VertexAttribute &attrib);
void updateArrayBufferReadDependencies(vk::CommandGraphNode *drawNode,
void updateArrayBufferReadDependencies(vk::CommandGraphResource *drawFramebuffer,
const gl::AttributesMask &activeAttribsMask,
Serial serial);
void updateElementArrayBufferReadDependency(vk::CommandGraphNode *drawNode, Serial serial);
void updateElementArrayBufferReadDependency(vk::CommandGraphResource *drawFramebuffer,
Serial serial);
gl::Error streamVertexData(RendererVk *renderer,
const gl::AttributesMask &attribsToStream,
......@@ -91,12 +92,12 @@ class VertexArrayVk : public VertexArrayImpl
gl::Error onDraw(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer);
gl::Error onIndexedDraw(const gl::Context *context,
RendererVk *renderer,
const gl::DrawCallParams &drawCallParams,
vk::CommandGraphNode *drawNode,
vk::CommandBuffer *commandBuffer,
bool newCommandBuffer);
void syncDirtyAttrib(const gl::VertexAttribute &attrib,
......
......@@ -448,8 +448,7 @@ gl::Error LineLoopHelper::getIndexBufferForElementArrayBuffer(RendererVk *render
vk::CommandBuffer *commandBuffer;
beginWriteResource(renderer, &commandBuffer);
Serial currentSerial = renderer->getCurrentQueueSerial();
elementArrayBufferVk->onReadResource(getCurrentWritingNode(), currentSerial);
elementArrayBufferVk->addReadDependency(this);
commandBuffer->copyBuffer(elementArrayBufferVk->getVkBuffer().getHandle(), *bufferHandleOut, 2,
copies.data());
......
......@@ -682,6 +682,12 @@ template <typename T>
using ShaderMap = angle::PackedEnumMap<ShaderType, T>;
using AllShaderTypes = angle::AllEnums<vk::ShaderType>;
enum class RecordingMode
{
Start,
Append,
};
} // 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