"$_src/gpu/GrPrimitiveProcessor.h",
"$_src/gpu/GrProgramDesc.cpp",
"$_src/gpu/GrProgramDesc.h",
- "$_src/gpu/GrProgramElement.cpp",
"$_src/gpu/GrProcessor.cpp",
"$_src/gpu/GrProcessorUnitTest.cpp",
"$_src/gpu/GrProcOptInfo.cpp",
called. */
void pendingIOComplete() const;
- friend class GrProgramElement;
+ friend class GrProcessor;
GrGpuResource* fResource;
mutable bool fOwnRef;
Dynamically allocated GrProcessors are managed by a per-thread memory pool. The ref count of an
processor must reach 0 before the thread terminates and the pool is destroyed.
*/
-class GrProcessor : public GrProgramElement {
+class GrProcessor : public GrProgramElement<GrProcessor> {
public:
class TextureSampler;
class BufferAccess;
return id;
}
+ friend class GrProgramElement<GrProcessor>;
+ void addPendingIOs() const;
+ void removeRefs() const;
+ void pendingIOComplete() const;
+
enum {
kIllegalProcessorClassID = 0,
};
class GrGpuResourceRef;
/**
+ * Note: We are converting GrProcessor from ref counting to a single owner model using move
+ * semantics. This class will be removed.
+ *
* Base class for GrProcessor. This exists to manage transitioning a GrProcessor from being owned by
* a client to being scheduled for execution. While a GrProcessor is ref'ed by drawing code its
* GrGpu resources must also be ref'ed to prevent incorrectly recycling them through the cache.
* safe to recycle a resource even though we still have buffered GrOps that read or write to the
* the resource.
*
- * To make this work all GrGpuResource objects owned by a GrProgramElement or derived classes
- * (either directly or indirectly) must be wrapped in a GrGpuResourceRef and registered with the
- * GrProgramElement using addGpuResource(). This allows the regular refs to be converted to pending
- * IO events when the program element is scheduled for deferred execution.
- *
- * Moreover, a GrProgramElement that in turn owns other GrProgramElements must convert its ownership
- * of its children to pending executions when its ref count reaches zero so that the GrGpuResources
- * owned by the children GrProgramElements are correctly converted from ownership by ref to
- * ownership by pending IO. Any GrProgramElement hierarchy is managed by subclasses which must
- * implement notifyRefCntIsZero() in order to convert refs of children to pending executions.
+ * To make this work the subclass, GrProcessor, implements addPendingIOs and pendingIOComplete. The
+ * former adds pending reads/writes as appropriate when the processor is recorded in a GrOpList. The
+ * latter removes them after the op list executes the operation. These calls must propagate to any
+ * children processors. Similarly, the subclass implements a removeRefs function in order to remove
+ * refs from resources once the processor is only owned for pending execution.
*/
-class GrProgramElement : public SkNoncopyable {
+template<typename DERIVED> class GrProgramElement : public SkNoncopyable {
public:
virtual ~GrProgramElement() {
// fRefCnt can be one when an effect is created statically using GR_CREATE_STATIC_EFFECT
delete this;
return;
} else {
- this->removeRefs();
+ static_cast<const DERIVED*>(this)->removeRefs();
}
}
this->validate();
protected:
GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {}
- /** Subclasses registers their resources using this function. It is assumed the GrProgramResouce
- is and will remain owned by the subclass and this function will retain a raw ptr. Once a
- GrGpuResourceRef is registered its setResource must not be called.
- */
- void addGpuResource(const GrGpuResourceRef* res) {
- fGpuResources.push_back(res);
- }
-
void addPendingExecution() const {
this->validate();
SkASSERT(fRefCnt > 0);
if (0 == fPendingExecutions) {
- this->addPendingIOs();
+ static_cast<const DERIVED*>(this)->addPendingIOs();
}
++fPendingExecutions;
this->validate();
delete this;
return;
} else {
- this->pendingIOComplete();
+ static_cast<const DERIVED*>(this)->pendingIOComplete();
}
}
this->validate();
executions. */
virtual void notifyRefCntIsZero() const = 0;
- void removeRefs() const;
- void addPendingIOs() const;
- void pendingIOComplete() const;
-
mutable int32_t fRefCnt;
// Count of deferred executions not yet issued to the 3D API.
mutable int32_t fPendingExecutions;
- SkSTArray<4, const GrGpuResourceRef*, true> fGpuResources;
-
// Only this class can access addPendingExecution() and completedExecution().
template <typename T> friend class GrPendingProgramElement;
void GrProcessor::addTextureSampler(const TextureSampler* access) {
fTextureSamplers.push_back(access);
- this->addGpuResource(access->programTexture());
}
void GrProcessor::addBufferAccess(const BufferAccess* access) {
fBufferAccesses.push_back(access);
- this->addGpuResource(access->programBuffer());
}
void GrProcessor::addImageStorageAccess(const ImageStorageAccess* access) {
fImageStorageAccesses.push_back(access);
- this->addGpuResource(access->programTexture());
+}
+
+void GrProcessor::addPendingIOs() const {
+ for (const auto& sampler : fTextureSamplers) {
+ sampler->programTexture()->markPendingIO();
+ }
+ for (const auto& buffer : fBufferAccesses) {
+ buffer->programBuffer()->markPendingIO();
+ }
+ for (const auto& imageStorage : fImageStorageAccesses) {
+ imageStorage->programTexture()->markPendingIO();
+ }
+}
+
+void GrProcessor::removeRefs() const {
+ for (const auto& sampler : fTextureSamplers) {
+ sampler->programTexture()->removeRef();
+ }
+ for (const auto& buffer : fBufferAccesses) {
+ buffer->programBuffer()->removeRef();
+ }
+ for (const auto& imageStorage : fImageStorageAccesses) {
+ imageStorage->programTexture()->removeRef();
+ }
+}
+
+void GrProcessor::pendingIOComplete() const {
+ for (const auto& sampler : fTextureSamplers) {
+ sampler->programTexture()->pendingIOComplete();
+ }
+ for (const auto& buffer : fBufferAccesses) {
+ buffer->programBuffer()->pendingIOComplete();
+ }
+ for (const auto& imageStorage : fImageStorageAccesses) {
+ imageStorage->programTexture()->pendingIOComplete();
+ }
}
void* GrProcessor::operator new(size_t size) {
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrProgramElement.h"
-#include "GrGpuResourceRef.h"
-#include "SkAtomics.h"
-
-void GrProgramElement::addPendingIOs() const {
- for (int i = 0; i < fGpuResources.count(); ++i) {
- fGpuResources[i]->markPendingIO();
- }
-}
-
-void GrProgramElement::removeRefs() const {
- for (int i = 0; i < fGpuResources.count(); ++i) {
- fGpuResources[i]->removeRef();
- }
-}
-
-void GrProgramElement::pendingIOComplete() const {
- for (int i = 0; i < fGpuResources.count(); ++i) {
- fGpuResources[i]->pendingIOComplete();
- }
-}