Chromium Code Reviews| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 switch (type) { | 176 switch (type) { |
| 177 case kVertex_GrBufferType: | 177 case kVertex_GrBufferType: |
| 178 SkASSERT(kDynamic_GrAccessPattern == accessPattern || | 178 SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 179 kStatic_GrAccessPattern == accessPattern); | 179 kStatic_GrAccessPattern == accessPattern); |
| 180 return GrVkVertexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); | 180 return GrVkVertexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); |
| 181 case kIndex_GrBufferType: | 181 case kIndex_GrBufferType: |
| 182 SkASSERT(kDynamic_GrAccessPattern == accessPattern || | 182 SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 183 kStatic_GrAccessPattern == accessPattern); | 183 kStatic_GrAccessPattern == accessPattern); |
| 184 return GrVkIndexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); | 184 return GrVkIndexBuffer::Create(this, size, kDynamic_GrAccessPattern == accessPattern); |
| 185 case kXferCpuToGpu_GrBufferType: | 185 case kXferCpuToGpu_GrBufferType: |
| 186 SkASSERT(kStream_GrAccessPattern == accessPattern); | 186 SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 187 kStream_GrAccessPattern == accessPattern); | |
| 187 return GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyRead_ Type); | 188 return GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyRead_ Type); |
| 188 case kXferGpuToCpu_GrBufferType: | 189 case kXferGpuToCpu_GrBufferType: |
| 189 SkASSERT(kStream_GrAccessPattern == accessPattern); | 190 SkASSERT(kDynamic_GrAccessPattern == accessPattern || |
| 191 kStream_GrAccessPattern == accessPattern); | |
| 190 return GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyWrite _Type); | 192 return GrVkTransferBuffer::Create(this, size, GrVkBuffer::kCopyWrite _Type); |
| 191 default: | 193 default: |
| 192 SkFAIL("Unknown buffer type."); | 194 SkFAIL("Unknown buffer type."); |
| 193 return nullptr; | 195 return nullptr; |
| 194 } | 196 } |
| 195 } | 197 } |
| 196 | 198 |
| 197 //////////////////////////////////////////////////////////////////////////////// | 199 //////////////////////////////////////////////////////////////////////////////// |
| 198 bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | 200 bool GrVkGpu::onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, |
| 199 GrPixelConfig srcConfig, DrawPreference* draw Preference, | 201 GrPixelConfig srcConfig, DrawPreference* draw Preference, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 269 } |
| 268 | 270 |
| 269 if (success) { | 271 if (success) { |
| 270 vkTex->texturePriv().dirtyMipMaps(true); | 272 vkTex->texturePriv().dirtyMipMaps(true); |
| 271 return true; | 273 return true; |
| 272 } | 274 } |
| 273 | 275 |
| 274 return false; | 276 return false; |
| 275 } | 277 } |
| 276 | 278 |
| 279 | |
| 280 bool GrVkGpu::onTransferPixels(GrSurface* surface, | |
| 281 int left, int top, int width, int height, | |
| 282 GrPixelConfig config, GrBuffer* transferBuffer, | |
| 283 size_t bufferOffset, size_t rowBytes) { | |
| 284 GrVkTexture* vkTex = static_cast<GrVkTexture*>(surface->asTexture()); | |
| 285 if (!vkTex) { | |
|
egdaniel
2016/04/18 16:46:34
why do you require that this is a texture for vulk
jvanverth1
2016/04/19 17:14:27
The expected use case for this is to transfer CPU-
egdaniel
2016/04/19 17:22:18
Well if we don't want to OpenGL and Vulkan be diff
bsalomon
2016/04/19 18:19:26
If we are only planning to use it with textures an
| |
| 286 return false; | |
| 287 } | |
| 288 GrVkTransferBuffer* vkBuffer = static_cast<GrVkTransferBuffer*>(transferBuff er); | |
| 289 if (!vkBuffer) { | |
| 290 return false; | |
| 291 } | |
| 292 | |
| 293 // We assume Vulkan doesn't do sRGB <-> linear conversions when reading and writing pixels. | |
| 294 if (GrPixelConfigIsSRGB(surface->config()) != GrPixelConfigIsSRGB(config)) { | |
| 295 return false; | |
| 296 } | |
| 297 | |
| 298 // TODO: Not clear how to handle y axis flip | |
|
egdaniel
2016/04/18 16:46:34
well I guess there are two options here. First wou
jvanverth1
2016/04/19 17:14:27
The temp image seems like the best bet -- I'm goin
| |
| 299 if (kBottomLeft_GrSurfaceOrigin == vkTex->origin()) { | |
| 300 return false; | |
| 301 } | |
| 302 | |
| 303 bool success = false; | |
| 304 if (GrPixelConfigIsCompressed(vkTex->desc().fConfig)) { | |
| 305 // We check that config == desc.fConfig in GrGpu::getWritePixelsInfo() | |
| 306 SkASSERT(config == vkTex->desc().fConfig); | |
| 307 // TODO: add compressed texture support | |
| 308 // delete the following two lines and uncomment the two after that when ready | |
| 309 vkTex->unref(); | |
| 310 return false; | |
| 311 //success = this->uploadCompressedTexData(vkTex->desc(), buffer, false, left, top, width, | |
| 312 // height); | |
| 313 } else { | |
| 314 // make sure the unmap has finished | |
| 315 vkBuffer->addMemoryBarrier(this, | |
| 316 VK_ACCESS_HOST_WRITE_BIT, | |
| 317 VK_ACCESS_TRANSFER_READ_BIT, | |
| 318 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, | |
| 319 VK_PIPELINE_STAGE_TRANSFER_BIT, | |
| 320 false); | |
| 321 | |
| 322 // Set up copy region | |
| 323 VkOffset3D offset = { | |
|
egdaniel
2016/04/18 16:46:34
why not just inline this like subresource or exten
jvanverth1
2016/04/19 17:14:27
Done.
| |
| 324 left, | |
| 325 top, | |
| 326 0 | |
| 327 }; | |
| 328 size_t bpp = GrBytesPerPixel(config); | |
| 329 | |
| 330 VkBufferImageCopy region; | |
| 331 memset(®ion, 0, sizeof(VkBufferImageCopy)); | |
| 332 region.bufferOffset = bufferOffset; | |
| 333 region.bufferRowLength = (uint32_t)(rowBytes/bpp); | |
| 334 region.bufferImageHeight = 0; | |
| 335 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; | |
| 336 region.imageOffset = offset; | |
| 337 region.imageExtent = { (uint32_t)width, (uint32_t)height, 1 }; | |
| 338 | |
| 339 // Change layout of our target so it can be copied to | |
| 340 VkImageLayout layout = vkTex->currentLayout(); | |
| 341 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFla gs(layout); | |
| 342 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; | |
| 343 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); | |
| 344 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; | |
| 345 vkTex->setImageLayout(this, | |
| 346 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, | |
| 347 srcAccessMask, | |
| 348 dstAccessMask, | |
| 349 srcStageMask, | |
| 350 dstStageMask, | |
| 351 false); | |
| 352 | |
| 353 // Copy the buffer to the image | |
| 354 fCurrentCmdBuffer->copyBufferToImage(this, | |
|
egdaniel
2016/04/18 16:46:34
if the surface is linearly tiled should we not jus
jvanverth1
2016/04/19 17:14:27
That would copy the data from the GPU to the CPU,
egdaniel
2016/04/19 17:22:18
unless it is cached :), but we can punt on this fo
| |
| 355 vkBuffer, | |
| 356 vkTex, | |
| 357 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMA L, | |
| 358 1, | |
| 359 ®ion); | |
| 360 | |
| 361 // Submit the current command buffer to the Queue | |
| 362 this->submitCommandBuffer(kSkip_SyncQueue); | |
| 363 } | |
| 364 | |
| 365 if (success) { | |
| 366 vkTex->texturePriv().dirtyMipMaps(true); | |
| 367 return true; | |
| 368 } | |
| 369 | |
| 370 return false; | |
| 371 } | |
| 372 | |
| 277 bool GrVkGpu::uploadTexData(GrVkTexture* tex, | 373 bool GrVkGpu::uploadTexData(GrVkTexture* tex, |
| 278 int left, int top, int width, int height, | 374 int left, int top, int width, int height, |
| 279 GrPixelConfig dataConfig, | 375 GrPixelConfig dataConfig, |
| 280 const void* data, | 376 const void* data, |
| 281 size_t rowBytes) { | 377 size_t rowBytes) { |
| 282 SkASSERT(data); | 378 SkASSERT(data); |
| 283 | 379 |
| 284 // If we're uploading compressed data then we should be using uploadCompress edTexData | 380 // If we're uploading compressed data then we should be using uploadCompress edTexData |
| 285 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 381 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 286 | 382 |
| (...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1580 aglSwapBuffers(aglGetCurrentContext()); | 1676 aglSwapBuffers(aglGetCurrentContext()); |
| 1581 int set_a_break_pt_here = 9; | 1677 int set_a_break_pt_here = 9; |
| 1582 aglSwapBuffers(aglGetCurrentContext()); | 1678 aglSwapBuffers(aglGetCurrentContext()); |
| 1583 #elif defined(SK_BUILD_FOR_WIN32) | 1679 #elif defined(SK_BUILD_FOR_WIN32) |
| 1584 SwapBuf(); | 1680 SwapBuf(); |
| 1585 int set_a_break_pt_here = 9; | 1681 int set_a_break_pt_here = 9; |
| 1586 SwapBuf(); | 1682 SwapBuf(); |
| 1587 #endif | 1683 #endif |
| 1588 #endif | 1684 #endif |
| 1589 } | 1685 } |
| OLD | NEW |