Fix a bunch of memory issues in Vulkan

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1867883002

Review URL: https://codereview.chromium.org/1867883002
This commit is contained in:
egdaniel 2016-04-07 10:17:47 -07:00 committed by Commit bot
parent 93dc33972c
commit 8af936d304
5 changed files with 18 additions and 2 deletions

View File

@ -116,6 +116,7 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
err = vkEnumeratePhysicalDevices(inst, &gpuCount, nullptr);
if (err) {
SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err);
vkDestroyInstance(inst, nullptr);
SkFAIL("failing");
}
SkASSERT(gpuCount > 0);
@ -125,6 +126,7 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
err = vkEnumeratePhysicalDevices(inst, &gpuCount, &physDev);
if (err) {
SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err);
vkDestroyInstance(inst, nullptr);
SkFAIL("failing");
}
@ -214,6 +216,7 @@ const GrVkBackendContext* GrVkBackendContext::Create() {
err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device);
if (err) {
SkDebugf("CreateDevice failed: %d\n", err);
vkDestroyInstance(inst, nullptr);
return nullptr;
}

View File

@ -53,6 +53,7 @@ bool GrVkExtensions::initInstance(uint32_t specVersion) {
VkLayerProperties* layers = new VkLayerProperties[layerCount];
res = EnumerateInstanceLayerProperties(&layerCount, layers);
if (VK_SUCCESS != res) {
delete[] layers;
return false;
}
for (uint32_t i = 0; i < layerCount; ++i) {
@ -75,6 +76,7 @@ bool GrVkExtensions::initInstance(uint32_t specVersion) {
VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions);
if (VK_SUCCESS != res) {
delete[] extensions;
return false;
}
for (uint32_t i = 0; i < extensionCount; ++i) {
@ -100,6 +102,7 @@ bool GrVkExtensions::initInstance(uint32_t specVersion) {
res = EnumerateInstanceExtensionProperties((*fInstanceLayerStrings)[layerIndex].c_str(),
&extensionCount, extensions);
if (VK_SUCCESS != res) {
delete[] extensions;
return false;
}
for (uint32_t i = 0; i < extensionCount; ++i) {
@ -138,6 +141,7 @@ bool GrVkExtensions::initDevice(uint32_t specVersion, VkInstance inst, VkPhysica
VkLayerProperties* layers = new VkLayerProperties[layerCount];
res = EnumerateDeviceLayerProperties(physDev, &layerCount, layers);
if (VK_SUCCESS != res) {
delete[] layers;
return false;
}
for (uint32_t i = 0; i < layerCount; ++i) {
@ -161,6 +165,7 @@ bool GrVkExtensions::initDevice(uint32_t specVersion, VkInstance inst, VkPhysica
VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
res = EnumerateDeviceExtensionProperties(physDev, nullptr, &extensionCount, extensions);
if (VK_SUCCESS != res) {
delete[] extensions;
return false;
}
for (uint32_t i = 0; i < extensionCount; ++i) {
@ -188,6 +193,7 @@ bool GrVkExtensions::initDevice(uint32_t specVersion, VkInstance inst, VkPhysica
(*fDeviceLayerStrings)[layerIndex].c_str(),
&extensionCount, extensions);
if (VK_SUCCESS != res) {
delete[] extensions;
return false;
}
for (uint32_t i = 0; i < extensionCount; ++i) {

View File

@ -1209,15 +1209,18 @@ void GrVkGpu::copySurfaceAsBlit(GrSurface* dst,
// Flip rect if necessary
SkIRect srcVkRect;
srcVkRect.fLeft = srcRect.fLeft;
srcVkRect.fRight = srcRect.fRight;
SkIRect dstRect;
dstRect.fLeft = dstPoint.fX;
dstRect.fRight = dstPoint.fX + srcVkRect.width();
dstRect.fRight = dstPoint.fX + srcRect.width();
if (kBottomLeft_GrSurfaceOrigin == src->origin()) {
srcVkRect.fTop = src->height() - srcRect.fBottom;
srcVkRect.fBottom = src->height() - srcRect.fTop;
} else {
srcVkRect = srcRect;
srcVkRect.fTop = srcRect.fTop;
srcVkRect.fBottom = srcRect.fBottom;
}
if (kBottomLeft_GrSurfaceOrigin == dst->origin()) {

View File

@ -80,6 +80,9 @@ GrVkPipelineState::~GrVkPipelineState() {
SkASSERT(!fSamplers.count());
SkASSERT(!fTextureViews.count());
SkASSERT(!fTextures.count());
for (int i = 0; i < fFragmentProcessors.count(); ++i) {
delete fFragmentProcessors[i];
}
}
void GrVkPipelineState::freeTempResources(const GrVkGpu* gpu) {

View File

@ -284,6 +284,7 @@ GrVkPipelineState* GrVkPipelineStateBuilder::finalize(GrPrimitiveType primitiveT
nullptr));
GR_VK_CALL(fGpu->vkInterface(), DestroyDescriptorSetLayout(fGpu->device(), dsLayout[1],
nullptr));
this->cleanupFragmentProcessors();
return nullptr;
}