if (!fResource->unique()) {
// in use by the command buffer, so we need to create a new one
- fResource->unref(gpu);
- fResource = Create(gpu, fDesc);
+ fResource->recycle(gpu);
+ fResource = this->createResource(gpu, fDesc);
if (createdNewBuffer) {
*createdNewBuffer = true;
}
SkASSERT(!fResource);
}
- VkBuffer buffer() const { return fResource->fBuffer; }
- const GrVkAlloc& alloc() const { return fResource->fAlloc; }
- const GrVkResource* resource() const { return fResource; }
- size_t size() const { return fDesc.fSizeInBytes; }
- VkDeviceSize offset() const { return fOffset; }
+ VkBuffer buffer() const { return fResource->fBuffer; }
+ const GrVkAlloc& alloc() const { return fResource->fAlloc; }
+ const GrVkRecycledResource* resource() const { return fResource; }
+ size_t size() const { return fDesc.fSizeInBytes; }
+ VkDeviceSize offset() const { return fOffset; }
void addMemoryBarrier(const GrVkGpu* gpu,
VkAccessFlags srcAccessMask,
void vkRelease(const GrVkGpu* gpu);
private:
+ virtual const Resource* createResource(GrVkGpu* gpu,
+ const Desc& descriptor) {
+ return Create(gpu, descriptor);
+ }
+
void validate() const;
bool vkIsMapped() const;
commandBuffer.addRecycledResource(fSamplerDescriptorSet);
}
-
if (fVertexUniformBuffer.get()) {
- commandBuffer.addResource(fVertexUniformBuffer->resource());
+ commandBuffer.addRecycledResource(fVertexUniformBuffer->resource());
}
if (fFragmentUniformBuffer.get()) {
- commandBuffer.addResource(fFragmentUniformBuffer->resource());
+ commandBuffer.addRecycledResource(fFragmentUniformBuffer->resource());
}
+
for (int i = 0; i < fSamplers.count(); ++i) {
commandBuffer.addResource(fSamplers[i]);
}
return resource;
}
+const GrVkBuffer::Resource* GrVkUniformBuffer::createResource(GrVkGpu* gpu,
+ const GrVkBuffer::Desc& descriptor) {
+ const GrVkResource* vkResource;
+ if (descriptor.fSizeInBytes <= GrVkUniformBuffer::kStandardSize) {
+ GrVkResourceProvider& provider = gpu->resourceProvider();
+ vkResource = provider.findOrCreateStandardUniformBufferResource();
+ } else {
+ vkResource = CreateResource(gpu, descriptor.fSizeInBytes);
+ }
+ return (const GrVkBuffer::Resource*) vkResource;
+}
+
void GrVkUniformBuffer::Resource::onRecycle(GrVkGpu* gpu) const {
if (fAlloc.fSize <= GrVkUniformBuffer::kStandardSize) {
gpu->resourceProvider().recycleStandardUniformBufferResource(this);
typedef GrVkBuffer::Resource INHERITED;
};
+ const GrVkBuffer::Resource* createResource(GrVkGpu* gpu,
+ const GrVkBuffer::Desc& descriptor) override;
+
GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
const GrVkUniformBuffer::Resource* resource)
: INHERITED(desc, resource)