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

Unified Diff: src/gpu/vk/GrVkResourceProvider.cpp

Issue 1718693002: Add vulkan files into skia repo. (Closed) Base URL: https://skia.googlesource.com/skia.git@merge
Patch Set: fix path Created 4 years, 10 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 | « src/gpu/vk/GrVkResourceProvider.h ('k') | src/gpu/vk/GrVkSampler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkResourceProvider.cpp
diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f4cfa27224d16e908244c72015698373f9e981f2
--- /dev/null
+++ b/src/gpu/vk/GrVkResourceProvider.cpp
@@ -0,0 +1,118 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "GrVkResourceProvider.h"
+
+#include "GrVkCommandBuffer.h"
+#include "GrVkPipeline.h"
+#include "GrVkRenderPass.h"
+#include "GrVkUtil.h"
+
+#ifdef SK_TRACE_VK_RESOURCES
+SkTDynamicHash<GrVkResource, uint32_t> GrVkResource::fTrace;
+SkRandom GrVkResource::fRandom;
+#endif
+
+GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu) : fGpu(gpu) {
+}
+
+GrVkResourceProvider::~GrVkResourceProvider() {
+ SkASSERT(0 == fSimpleRenderPasses.count());
+}
+
+GrVkPipeline* GrVkResourceProvider::createPipeline(const GrPipeline& pipeline,
+ const GrPrimitiveProcessor& primProc,
+ VkPipelineShaderStageCreateInfo* shaderStageInfo,
+ int shaderStageCount,
+ GrPrimitiveType primitiveType,
+ const GrVkRenderPass& renderPass,
+ VkPipelineLayout layout) {
+
+ return GrVkPipeline::Create(fGpu, pipeline, primProc, shaderStageInfo, shaderStageCount,
+ primitiveType, renderPass, layout);
+}
+
+
+// To create framebuffers, we first need to create a simple RenderPass that is
+// only used for framebuffer creation. When we actually render we will create
+// RenderPasses as needed that are compatible with the framebuffer.
+const GrVkRenderPass*
+GrVkResourceProvider::findOrCreateCompatibleRenderPass(const GrVkRenderTarget& target) {
+ for (int i = 0; i < fSimpleRenderPasses.count(); ++i) {
+ GrVkRenderPass* renderPass = fSimpleRenderPasses[i];
+ if (renderPass->isCompatible(target)) {
+ renderPass->ref();
+ return renderPass;
+ }
+ }
+
+ GrVkRenderPass* renderPass = new GrVkRenderPass();
+ renderPass->initSimple(fGpu, target);
+ fSimpleRenderPasses.push_back(renderPass);
+ renderPass->ref();
+ return renderPass;
+}
+
+GrVkDescriptorPool* GrVkResourceProvider::findOrCreateCompatibleDescriptorPool(
+ const GrVkDescriptorPool::DescriptorTypeCounts& typeCounts) {
+ return new GrVkDescriptorPool(fGpu, typeCounts);
+}
+
+GrVkCommandBuffer* GrVkResourceProvider::createCommandBuffer() {
+ GrVkCommandBuffer* cmdBuffer = GrVkCommandBuffer::Create(fGpu, fGpu->cmdPool());
+ fActiveCommandBuffers.push_back(cmdBuffer);
+ cmdBuffer->ref();
+ return cmdBuffer;
+}
+
+void GrVkResourceProvider::checkCommandBuffers() {
+ for (int i = fActiveCommandBuffers.count()-1; i >= 0; --i) {
+ if (fActiveCommandBuffers[i]->finished(fGpu)) {
+ fActiveCommandBuffers[i]->unref(fGpu);
+ fActiveCommandBuffers.removeShuffle(i);
+ }
+ }
+}
+
+void GrVkResourceProvider::destroyResources() {
+ // release our current command buffers
+ for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
+ SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
+ SkASSERT(fActiveCommandBuffers[i]->unique());
+ fActiveCommandBuffers[i]->unref(fGpu);
+ }
+ fActiveCommandBuffers.reset();
+
+ // loop over all render passes to make sure we destroy all the internal VkRenderPasses
+ for (int i = 0; i < fSimpleRenderPasses.count(); ++i) {
+ fSimpleRenderPasses[i]->unref(fGpu);
+ }
+ fSimpleRenderPasses.reset();
+
+#ifdef SK_TRACE_VK_RESOURCES
+ SkASSERT(0 == GrVkResource::fTrace.count());
+#endif
+
+}
+
+void GrVkResourceProvider::abandonResources() {
+ // release our current command buffers
+ for (int i = 0; i < fActiveCommandBuffers.count(); ++i) {
+ SkASSERT(fActiveCommandBuffers[i]->finished(fGpu));
+ fActiveCommandBuffers[i]->unrefAndAbandon();
+ }
+ fActiveCommandBuffers.reset();
+
+ for (int i = 0; i < fSimpleRenderPasses.count(); ++i) {
+ fSimpleRenderPasses[i]->unrefAndAbandon();
+ }
+ fSimpleRenderPasses.reset();
+
+#ifdef SK_TRACE_VK_RESOURCES
+ SkASSERT(0 == GrVkResource::fTrace.count());
+#endif
+}
« no previous file with comments | « src/gpu/vk/GrVkResourceProvider.h ('k') | src/gpu/vk/GrVkSampler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698