Type fType;
private:
- void freeGPUData(const GrVkGpu* gpu) const;
+ void freeGPUData(const GrVkGpu* gpu) const override;
typedef GrVkResource INHERITED;
};
return tgt;
}
-void GrVkGpu::generateMipmap(GrVkTexture* tex) const {
+void GrVkGpu::generateMipmap(GrVkTexture* tex) {
// don't do anything for linearly tiled textures (can't have mipmaps)
if (tex->isLinearTiled()) {
SkDebugf("Trying to create mipmap for linear tiled texture");
void finishDrawTarget() override;
- void generateMipmap(GrVkTexture* tex) const;
+ void generateMipmap(GrVkTexture* tex);
bool updateBuffer(GrVkBuffer* buffer, const void* src, VkDeviceSize offset, VkDeviceSize size);
}
static void append_sampled_images(const GrProcessor& processor,
- const GrVkGpu* gpu,
+ GrVkGpu* gpu,
SkTArray<GrVkImage*>* sampledImages) {
if (int numTextures = processor.numTextures()) {
GrVkImage** images = sampledImages->push_back_n(numTextures);
, GrVkImage(info, wrapped)
// for the moment we only support 1:1 color to stencil
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
- , fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImage(new GrVkImage(msaaInfo, GrVkImage::kNot_Wrapped))
, fResolveAttachmentView(resolveAttachmentView)
+ , fFramebuffer(nullptr)
, fCachedSimpleRenderPass(nullptr) {
SkASSERT(desc.fSampleCnt);
// The plus 1 is to account for the resolve texture.
, GrVkImage(info, wrapped)
// for the moment we only support 1:1 color to stencil
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
- , fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImage(new GrVkImage(msaaInfo, GrVkImage::kNot_Wrapped))
, fResolveAttachmentView(resolveAttachmentView)
+ , fFramebuffer(nullptr)
, fCachedSimpleRenderPass(nullptr) {
SkASSERT(desc.fSampleCnt);
// The plus 1 is to account for the resolve texture.
: GrSurface(gpu, desc)
, GrVkImage(info, wrapped)
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
- , fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImage(nullptr)
, fResolveAttachmentView(nullptr)
+ , fFramebuffer(nullptr)
, fCachedSimpleRenderPass(nullptr) {
SkASSERT(!desc.fSampleCnt);
fColorValuesPerPixel = 1;
: GrSurface(gpu, desc)
, GrVkImage(info, wrapped)
, GrRenderTarget(gpu, desc, kUnified_SampleConfig)
- , fFramebuffer(nullptr)
, fColorAttachmentView(colorAttachmentView)
, fMSAAImage(nullptr)
, fResolveAttachmentView(nullptr)
+ , fFramebuffer(nullptr)
, fCachedSimpleRenderPass(nullptr) {
SkASSERT(!desc.fSampleCnt);
fColorValuesPerPixel = 1;
const GrSurfaceDesc& desc,
const GrVkImageInfo& info,
GrVkImage::Wrapped wrapped) {
+ SkASSERT(1 == info.fLevelCount);
VkFormat pixelFormat;
GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
return fColorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorBytes;
}
+ void createFramebuffer(GrVkGpu* gpu);
+
+ const GrVkImageView* fColorAttachmentView;
+ GrVkImage* fMSAAImage;
+ const GrVkImageView* fResolveAttachmentView;
+
private:
GrVkRenderTarget(GrVkGpu* gpu,
SkBudgeted,
bool completeStencilAttachment() override;
- void createFramebuffer(GrVkGpu* gpu);
-
void releaseInternalObjects();
void abandonInternalObjects();
const GrVkFramebuffer* fFramebuffer;
- const GrVkImageView* fColorAttachmentView;
- GrVkImage* fMSAAImage;
- const GrVkImageView* fResolveAttachmentView;
int fColorValuesPerPixel;
// This is a cached pointer to a simple render pass. The render target should unref it
};
static Trace fTrace;
- static SkRandom fRandom;
+ static uint32_t fKeyCounter;
#endif
/** Default construct, initializing the reference count to 1.
*/
GrVkResource() : fRefCnt(1) {
#ifdef SK_TRACE_VK_RESOURCES
- fKey = fRandom.nextU();
+ fKey = sk_atomic_fetch_add(&fKeyCounter, 1u, sk_memory_order_relaxed);
fTrace.add(this);
#endif
}
#ifdef SK_TRACE_VK_RESOURCES
GrVkResource::Trace GrVkResource::fTrace;
-SkRandom GrVkResource::fRandom;
+uint32_t GrVkResource::fKeyCounter = 0;
#endif
GrVkResourceProvider::GrVkResourceProvider(GrVkGpu* gpu)
#include "GrVkGpu.h"
#include "GrVkImageView.h"
#include "GrTexturePriv.h"
+#include "GrVkTextureRenderTarget.h"
#include "GrVkUtil.h"
#include "vk/GrVkTypes.h"
return fLinearTextureView;
}
-bool GrVkTexture::reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels) {
+bool GrVkTexture::reallocForMipmap(GrVkGpu* gpu, uint32_t mipLevels) {
if (mipLevels == 1) {
// don't need to do anything for a 1x1 texture
return false;
return false;
}
- // Does this even make sense for rendertargets?
bool renderTarget = SkToBool(fDesc.fFlags & kRenderTarget_GrSurfaceFlag);
VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
return false;
}
+ if (renderTarget) {
+ GrVkTextureRenderTarget* texRT = static_cast<GrVkTextureRenderTarget*>(this);
+ if (!texRT->updateForMipmap(gpu, info)) {
+ GrVkImage::DestroyImageInfo(gpu, &info);
+ return false;
+ }
+ }
+
oldResource->unref(gpu);
oldView->unref(gpu);
if (fLinearTextureView) {
const GrVkImageView* textureView(bool allowSRGB);
- bool reallocForMipmap(const GrVkGpu* gpu, uint32_t mipLevels);
+ bool reallocForMipmap(GrVkGpu* gpu, uint32_t mipLevels);
protected:
GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, const GrVkImageView*,
GrVkImage::Wrapped wrapped) {
VkImage image = info.fImage;
// Create the texture ImageView
- uint32_t mipLevels = 1;
- //TODO: does a mipmapped textureRenderTarget make sense?
- //if (desc.fIsMipMapped) {
- // mipLevels = SkMipMap::ComputeLevelCount(this->width(), this->height()) + 1;
- //}
const GrVkImageView* imageView = GrVkImageView::Create(gpu, image, info.fFormat,
- GrVkImageView::kColor_Type, mipLevels);
+ GrVkImageView::kColor_Type,
+ info.fLevelCount);
if (!imageView) {
return nullptr;
}
// Set color attachment image
colorImage = msInfo.fImage;
- // Create resolve attachment view if necessary.
- // If the format matches, this is the same as the texture imageView.
- if (pixelFormat == info.fFormat) {
- resolveAttachmentView = imageView;
- resolveAttachmentView->ref();
- } else {
- resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelFormat,
- GrVkImageView::kColor_Type, 1);
- if (!resolveAttachmentView) {
- GrVkImage::DestroyImageInfo(gpu, &msInfo);
- imageView->unref(gpu);
- return nullptr;
- }
+ // Create resolve attachment view.
+ resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelFormat,
+ GrVkImageView::kColor_Type,
+ info.fLevelCount);
+ if (!resolveAttachmentView) {
+ GrVkImage::DestroyImageInfo(gpu, &msInfo);
+ imageView->unref(gpu);
+ return nullptr;
}
} else {
// Set color attachment image
colorImage = info.fImage;
}
- const GrVkImageView* colorAttachmentView;
- // Get color attachment view.
- // If the format matches and there's no multisampling,
- // this is the same as the texture imageView
- if (pixelFormat == info.fFormat && !resolveAttachmentView) {
- colorAttachmentView = imageView;
- colorAttachmentView->ref();
- } else {
- colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat,
- GrVkImageView::kColor_Type, 1);
- if (!colorAttachmentView) {
- if (desc.fSampleCnt) {
- resolveAttachmentView->unref(gpu);
- GrVkImage::DestroyImageInfo(gpu, &msInfo);
- }
- imageView->unref(gpu);
- return nullptr;
+ const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat,
+ GrVkImageView::kColor_Type, 1);
+ if (!colorAttachmentView) {
+ if (desc.fSampleCnt) {
+ resolveAttachmentView->unref(gpu);
+ GrVkImage::DestroyImageInfo(gpu, &msInfo);
}
+ imageView->unref(gpu);
+ return nullptr;
}
+
GrVkTextureRenderTarget* texRT;
if (desc.fSampleCnt) {
if (GrVkImage::kNot_Wrapped == wrapped) {
return trt;
}
+
+bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) {
+ VkFormat pixelFormat;
+ GrPixelConfigToVkFormat(fDesc.fConfig, &pixelFormat);
+ if (fDesc.fSampleCnt) {
+ const GrVkImageView* resolveAttachmentView =
+ GrVkImageView::Create(gpu,
+ newInfo.fImage,
+ pixelFormat,
+ GrVkImageView::kColor_Type,
+ newInfo.fLevelCount);
+ if (!resolveAttachmentView) {
+ return false;
+ }
+ fResolveAttachmentView->unref(gpu);
+ fResolveAttachmentView = resolveAttachmentView;
+ } else {
+ const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu,
+ newInfo.fImage,
+ pixelFormat,
+ GrVkImageView::kColor_Type,
+ 1);
+ if (!colorAttachmentView) {
+ return false;
+ }
+ fColorAttachmentView->unref(gpu);
+ fColorAttachmentView = colorAttachmentView;
+ }
+
+ this->createFramebuffer(gpu);
+ return true;
+}
+
GrWrapOwnership,
const GrVkImageInfo*);
+ bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo);
+
protected:
void onAbandon() override {
GrVkRenderTarget::onAbandon();