Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Unified Diff: src/gpu/vk/GrVkCommandBuffer.h

Issue 2019723002: Subclass GrVkCommandBuffer into Primary and Secondary CommandBuffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@renderPass2
Patch Set: Add executeCommands impl Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/gpu/vk/GrVkCommandBuffer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkCommandBuffer.h
diff --git a/src/gpu/vk/GrVkCommandBuffer.h b/src/gpu/vk/GrVkCommandBuffer.h
index b513a47f29b6aef935a002ad28fd9d69aacd5778..709e4c6044e7b99dc6479ca402810636257fb97d 100644
--- a/src/gpu/vk/GrVkCommandBuffer.h
+++ b/src/gpu/vk/GrVkCommandBuffer.h
@@ -13,6 +13,7 @@
#include "GrVkUtil.h"
#include "vk/GrVkDefines.h"
+class GrVkFramebuffer;
class GrVkPipeline;
class GrVkRenderPass;
class GrVkRenderTarget;
@@ -20,24 +21,10 @@ class GrVkTransferBuffer;
class GrVkCommandBuffer : public GrVkResource {
public:
- static GrVkCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cmdPool);
~GrVkCommandBuffer() override;
- void begin(const GrVkGpu* gpu);
- void end(const GrVkGpu* gpu);
-
void invalidateState();
- // Begins render pass on this command buffer. The framebuffer from GrVkRenderTarget will be used
- // in the render pass.
- void beginRenderPass(const GrVkGpu* gpu,
- const GrVkRenderPass* renderPass,
- const GrVkRenderTarget& target);
- void endRenderPass(const GrVkGpu* gpu);
-
- void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue sync);
- bool finished(const GrVkGpu* gpu) const;
-
////////////////////////////////////////////////////////////////////////////
// CommandBuffer commands
////////////////////////////////////////////////////////////////////////////
@@ -105,6 +92,98 @@ public:
void setBlendConstants(const GrVkGpu* gpu, const float blendConstants[4]);
+ // Commands that only work inside of a render pass
+ void clearAttachments(const GrVkGpu* gpu,
+ int numAttachments,
+ const VkClearAttachment* attachments,
+ int numRects,
+ const VkClearRect* clearRects) const;
+
+ void drawIndexed(const GrVkGpu* gpu,
+ uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t vertexOffset,
+ uint32_t firstInstance) const;
+
+ void draw(const GrVkGpu* gpu,
+ uint32_t vertexCount,
+ uint32_t instanceCount,
+ uint32_t firstVertex,
+ uint32_t firstInstance) const;
+
+ // Add ref-counted resource that will be tracked and released when this
+ // command buffer finishes execution
+ void addResource(const GrVkResource* resource) {
+ resource->ref();
+ fTrackedResources.push_back(resource);
+ }
+
+protected:
+ GrVkCommandBuffer(VkCommandBuffer cmdBuffer, const GrVkRenderPass* rp = VK_NULL_HANDLE)
+ : fTrackedResources(kInitialTrackedResourcesCount)
+ , fIsActive(false)
+ , fActiveRenderPass(rp)
+ , fCmdBuffer(cmdBuffer)
+ , fSubmitFence(VK_NULL_HANDLE)
+ , fBoundVertexBufferIsValid(false)
+ , fBoundIndexBufferIsValid(false) {
+ this->invalidateState();
+ }
+ SkTArray<const GrVkResource*, true> fTrackedResources;
+
+ // Tracks whether we are in the middle of a command buffer begin/end calls and thus can add
+ // new commands to the buffer;
+ bool fIsActive;
+
+ // Stores a pointer to the current active render pass (i.e. begin has been called but not
+ // end). A nullptr means there is no active render pass. The GrVKCommandBuffer does not own
+ // the render pass.
+ const GrVkRenderPass* fActiveRenderPass;
+
+ VkCommandBuffer fCmdBuffer;
+ VkFence fSubmitFence;
+
+private:
+ static const int kInitialTrackedResourcesCount = 32;
+
+ void freeGPUData(const GrVkGpu* gpu) const override;
+ void abandonSubResources() const override;
+
+ VkBuffer fBoundVertexBuffer;
+ bool fBoundVertexBufferIsValid;
+
+ VkBuffer fBoundIndexBuffer;
+ bool fBoundIndexBufferIsValid;
+
+ // Cached values used for dynamic state updates
+ VkViewport fCachedViewport;
+ VkRect2D fCachedScissor;
+ float fCachedBlendConstant[4];
+};
+
+class GrVkSecondaryCommandBuffer;
+
+class GrVkPrimaryCommandBuffer : public GrVkCommandBuffer {
+public:
+ static GrVkPrimaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cmdPool);
+
+ void begin(const GrVkGpu* gpu);
+ void end(const GrVkGpu* gpu);
+
+ // Begins render pass on this command buffer. The framebuffer from GrVkRenderTarget will be used
+ // in the render pass.
+ void beginRenderPass(const GrVkGpu* gpu,
+ const GrVkRenderPass* renderPass,
+ const GrVkRenderTarget& target);
+ void endRenderPass(const GrVkGpu* gpu);
+
+ // Submits the SecondaryCommandBuffer into this command buffer. It is required that we are
+ // currently inside a render pass that is compatible with the one used to create the
+ // SecondaryCommandBuffer.
+ void executeCommands(const GrVkGpu* gpu,
+ const GrVkSecondaryCommandBuffer* secondaryBuffer);
+
// Commands that only work outside of a render pass
void clearColorImage(const GrVkGpu* gpu,
GrVkImage* image,
@@ -169,75 +248,32 @@ public:
uint32_t copyRegionCount,
const VkBufferImageCopy* copyRegions);
- // Commands that only work inside of a render pass
- void clearAttachments(const GrVkGpu* gpu,
- int numAttachments,
- const VkClearAttachment* attachments,
- int numRects,
- const VkClearRect* clearRects) const;
-
- void drawIndexed(const GrVkGpu* gpu,
- uint32_t indexCount,
- uint32_t instanceCount,
- uint32_t firstIndex,
- int32_t vertexOffset,
- uint32_t firstInstance) const;
-
- void draw(const GrVkGpu* gpu,
- uint32_t vertexCount,
- uint32_t instanceCount,
- uint32_t firstVertex,
- uint32_t firstInstance) const;
-
- // Add ref-counted resource that will be tracked and released when this
- // command buffer finishes execution
- void addResource(const GrVkResource* resource) {
- resource->ref();
- fTrackedResources.push_back(resource);
- }
+ void submitToQueue(const GrVkGpu* gpu, VkQueue queue, GrVkGpu::SyncQueue sync);
+ bool finished(const GrVkGpu* gpu) const;
private:
- static const int kInitialTrackedResourcesCount = 32;
-
- explicit GrVkCommandBuffer(VkCommandBuffer cmdBuffer)
- : fTrackedResources(kInitialTrackedResourcesCount)
- , fCmdBuffer(cmdBuffer)
- , fSubmitFence(VK_NULL_HANDLE)
- , fBoundVertexBufferIsValid(false)
- , fBoundIndexBufferIsValid(false)
- , fIsActive(false)
- , fActiveRenderPass(nullptr) {
- this->invalidateState();
- }
-
- void freeGPUData(const GrVkGpu* gpu) const override;
- void abandonSubResources() const override;
+ explicit GrVkPrimaryCommandBuffer(VkCommandBuffer cmdBuffer) : INHERITED(cmdBuffer) {}
- SkTArray<const GrVkResource*, true> fTrackedResources;
-
- VkCommandBuffer fCmdBuffer;
- VkFence fSubmitFence;
+ typedef GrVkCommandBuffer INHERITED;
+};
- VkBuffer fBoundVertexBuffer;
- bool fBoundVertexBufferIsValid;
+class GrVkSecondaryCommandBuffer : public GrVkCommandBuffer {
+public:
+ static GrVkSecondaryCommandBuffer* Create(const GrVkGpu* gpu, VkCommandPool cmdPool,
+ const GrVkRenderPass* compatibleRenderPass);
- VkBuffer fBoundIndexBuffer;
- bool fBoundIndexBufferIsValid;
+ void begin(const GrVkGpu* gpu, const GrVkFramebuffer* framebuffer);
+ void end(const GrVkGpu* gpu);
- // Tracks whether we are in the middle of a command buffer begin/end calls and thus can add new
- // commands to the buffer;
- bool fIsActive;
+private:
+ explicit GrVkSecondaryCommandBuffer(VkCommandBuffer cmdBuffer,
+ const GrVkRenderPass* compatibleRenderPass)
+ : INHERITED(cmdBuffer, compatibleRenderPass) {
+ }
- // Stores a pointer to the current active render pass (i.e. begin has been called but not end).
- // A nullptr means there is no active render pass. The GrVKCommandBuffer does not own the render
- // pass.
- const GrVkRenderPass* fActiveRenderPass;
+ friend class GrVkPrimaryCommandBuffer;
- // Cached values used for dynamic state updates
- VkViewport fCachedViewport;
- VkRect2D fCachedScissor;
- float fCachedBlendConstant[4];
+ typedef GrVkCommandBuffer INHERITED;
};
-
#endif
« no previous file with comments | « no previous file | src/gpu/vk/GrVkCommandBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698