| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkGpu.h" | 8 #include "GrVkGpu.h" |
| 9 | 9 |
| 10 #include "GrContextOptions.h" | 10 #include "GrContextOptions.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // TODO: This should fall back to drawing or copying to change config of
dstSurface to | 252 // TODO: This should fall back to drawing or copying to change config of
dstSurface to |
| 253 // match that of srcConfig. | 253 // match that of srcConfig. |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool GrVkGpu::onWritePixels(GrSurface* surface, | 260 bool GrVkGpu::onWritePixels(GrSurface* surface, |
| 261 int left, int top, int width, int height, | 261 int left, int top, int width, int height, |
| 262 GrPixelConfig config, const void* buffer, | 262 GrPixelConfig config, |
| 263 size_t rowBytes) { | 263 const SkTArray<GrMipLevel>& texels) { |
| 264 GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture()); | 264 GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture()); |
| 265 if (!vkTex) { | 265 if (!vkTex) { |
| 266 return false; | 266 return false; |
| 267 } | 267 } |
| 268 | 268 |
| 269 // TODO: We're ignoring MIP levels here. |
| 270 |
| 269 // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and
writing pixels. | 271 // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and
writing pixels. |
| 270 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | 272 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { |
| 271 return false; | 273 return false; |
| 272 } | 274 } |
| 273 | 275 |
| 274 bool success = false; | 276 bool success = false; |
| 275 if (GrPixelConfigIsCompressed(vkTex->desc().fConfig)) { | 277 if (GrPixelConfigIsCompressed(vkTex->desc().fConfig)) { |
| 276 // We check that config == desc.fConfig in GrGpu::getWritePixelsInfo() | 278 // We check that config == desc.fConfig in GrGpu::getWritePixelsInfo() |
| 277 SkASSERT(config == vkTex->desc().fConfig); | 279 SkASSERT(config == vkTex->desc().fConfig); |
| 278 // TODO: add compressed texture support | 280 // TODO: add compressed texture support |
| (...skipping 13 matching lines...) Expand all Loading... |
| 292 VkAccessFlags dstAccessMask = VK_ACCESS_HOST_WRITE_BIT; | 294 VkAccessFlags dstAccessMask = VK_ACCESS_HOST_WRITE_BIT; |
| 293 vkTex->setImageLayout(this, | 295 vkTex->setImageLayout(this, |
| 294 VK_IMAGE_LAYOUT_GENERAL, | 296 VK_IMAGE_LAYOUT_GENERAL, |
| 295 srcAccessMask, | 297 srcAccessMask, |
| 296 dstAccessMask, | 298 dstAccessMask, |
| 297 srcStageMask, | 299 srcStageMask, |
| 298 dstStageMask, | 300 dstStageMask, |
| 299 false); | 301 false); |
| 300 } | 302 } |
| 301 success = this->uploadTexData(vkTex, left, top, width, height, config, | 303 success = this->uploadTexData(vkTex, left, top, width, height, config, |
| 302 buffer, rowBytes); | 304 texels.begin()->fPixels, texels.begin()->f
RowBytes); |
| 303 } | 305 } |
| 304 | 306 |
| 305 if (success) { | 307 if (success) { |
| 306 vkTex->texturePriv().dirtyMipMaps(true); | 308 vkTex->texturePriv().dirtyMipMaps(true); |
| 307 return true; | 309 return true; |
| 308 } | 310 } |
| 309 | 311 |
| 310 return false; | 312 return false; |
| 311 } | 313 } |
| 312 | 314 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 this->submitCommandBuffer(kSkip_SyncQueue); | 459 this->submitCommandBuffer(kSkip_SyncQueue); |
| 458 | 460 |
| 459 transferBuffer->unref(); | 461 transferBuffer->unref(); |
| 460 } | 462 } |
| 461 | 463 |
| 462 return true; | 464 return true; |
| 463 } | 465 } |
| 464 | 466 |
| 465 //////////////////////////////////////////////////////////////////////////////// | 467 //////////////////////////////////////////////////////////////////////////////// |
| 466 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::Li
feCycle lifeCycle, | 468 GrTexture* GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::Li
feCycle lifeCycle, |
| 467 const void* srcData, size_t rowBytes) { | 469 const SkTArray<GrMipLevel>& texels) { |
| 468 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 470 bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 469 | 471 |
| 470 VkFormat pixelFormat; | 472 VkFormat pixelFormat; |
| 471 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { | 473 if (!GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat)) { |
| 472 return nullptr; | 474 return nullptr; |
| 473 } | 475 } |
| 474 | 476 |
| 475 if (!fVkCaps->isConfigTexturable(desc.fConfig)) { | 477 if (!fVkCaps->isConfigTexturable(desc.fConfig)) { |
| 476 return nullptr; | 478 return nullptr; |
| 477 } | 479 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 492 } | 494 } |
| 493 | 495 |
| 494 // For now we will set the VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT and | 496 // For now we will set the VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT and |
| 495 // VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT on every texture since we do not know
whether or not we | 497 // VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT on every texture since we do not know
whether or not we |
| 496 // will be using this texture in some copy or not. Also this assumes, as is
the current case, | 498 // will be using this texture in some copy or not. Also this assumes, as is
the current case, |
| 497 // that all render targets in vulkan are also texutres. If we change this pr
actice of setting | 499 // that all render targets in vulkan are also texutres. If we change this pr
actice of setting |
| 498 // both bits, we must make sure to set the destination bit if we are uploadi
ng srcData to the | 500 // both bits, we must make sure to set the destination bit if we are uploadi
ng srcData to the |
| 499 // texture. | 501 // texture. |
| 500 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_
BIT; | 502 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_
BIT; |
| 501 | 503 |
| 502 VkFlags memProps = (srcData && linearTiling) ? VK_MEMORY_PROPERTY_HOST_VISIB
LE_BIT : | 504 VkFlags memProps = (!texels.empty() && linearTiling) ? VK_MEMORY_PROPERTY_HO
ST_VISIBLE_BIT : |
| 503 VK_MEMORY_PROPERTY_DEVICE_LOC
AL_BIT; | 505 VK_MEMORY_PROPERTY_DE
VICE_LOCAL_BIT; |
| 504 | 506 |
| 505 // This ImageDesc refers to the texture that will be read by the client. Thu
s even if msaa is | 507 // This ImageDesc refers to the texture that will be read by the client. Thu
s even if msaa is |
| 506 // requested, this ImageDesc describes the resolved texutre. Therefore we al
ways have samples set | 508 // requested, this ImageDesc describes the resolved texutre. Therefore we al
ways have samples set |
| 507 // to 1. | 509 // to 1. |
| 508 GrVkImage::ImageDesc imageDesc; | 510 GrVkImage::ImageDesc imageDesc; |
| 509 imageDesc.fImageType = VK_IMAGE_TYPE_2D; | 511 imageDesc.fImageType = VK_IMAGE_TYPE_2D; |
| 510 imageDesc.fFormat = pixelFormat; | 512 imageDesc.fFormat = pixelFormat; |
| 511 imageDesc.fWidth = desc.fWidth; | 513 imageDesc.fWidth = desc.fWidth; |
| 512 imageDesc.fHeight = desc.fHeight; | 514 imageDesc.fHeight = desc.fHeight; |
| 513 imageDesc.fLevels = 1; | 515 imageDesc.fLevels = 1; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 527 this->clear(rect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget()); | 529 this->clear(rect, GrColor_TRANSPARENT_BLACK, tex->asRenderTarget()); |
| 528 #endif | 530 #endif |
| 529 } else { | 531 } else { |
| 530 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); | 532 tex = GrVkTexture::CreateNewTexture(this, desc, lifeCycle, imageDesc); |
| 531 } | 533 } |
| 532 | 534 |
| 533 if (!tex) { | 535 if (!tex) { |
| 534 return nullptr; | 536 return nullptr; |
| 535 } | 537 } |
| 536 | 538 |
| 537 if (srcData) { | 539 // TODO: We're ignoring MIP levels here. |
| 538 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon
fig, srcData, | 540 if (!texels.empty()) { |
| 539 rowBytes)) { | 541 if (!this->uploadTexData(tex, 0, 0, desc.fWidth, desc.fHeight, desc.fCon
fig, |
| 542 texels.begin()->fPixels, texels.begin()->fRowBy
tes)) { |
| 540 tex->unref(); | 543 tex->unref(); |
| 541 return nullptr; | 544 return nullptr; |
| 542 } | 545 } |
| 543 } | 546 } |
| 544 | 547 |
| 545 return tex; | 548 return tex; |
| 546 } | 549 } |
| 547 | 550 |
| 548 //////////////////////////////////////////////////////////////////////////////// | 551 //////////////////////////////////////////////////////////////////////////////// |
| 549 | 552 |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 int set_a_break_pt_here = 9; | 1405 int set_a_break_pt_here = 9; |
| 1403 aglSwapBuffers(aglGetCurrentContext()); | 1406 aglSwapBuffers(aglGetCurrentContext()); |
| 1404 #elif defined(SK_BUILD_FOR_WIN32) | 1407 #elif defined(SK_BUILD_FOR_WIN32) |
| 1405 SwapBuf(); | 1408 SwapBuf(); |
| 1406 int set_a_break_pt_here = 9; | 1409 int set_a_break_pt_here = 9; |
| 1407 SwapBuf(); | 1410 SwapBuf(); |
| 1408 #endif | 1411 #endif |
| 1409 #endif | 1412 #endif |
| 1410 } | 1413 } |
| 1411 | 1414 |
| OLD | NEW |