Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: src/gpu/vk/GrVkGpu.cpp

Issue 2348523002: Support use of non-coherent memory allocations in Vulkan. (Closed)
Patch Set: Some more clean up Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/vk/GrVkBuffer.cpp ('k') | src/gpu/vk/GrVkMemory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } else { 480 } else {
481 // If there is no padding on the src (rowBytes) or dst (layout.rowPitch) we can memcpy 481 // If there is no padding on the src (rowBytes) or dst (layout.rowPitch) we can memcpy
482 if (trimRowBytes == rowBytes && trimRowBytes == layout.rowPitch) { 482 if (trimRowBytes == rowBytes && trimRowBytes == layout.rowPitch) {
483 memcpy(mapPtr, data, trimRowBytes * height); 483 memcpy(mapPtr, data, trimRowBytes * height);
484 } else { 484 } else {
485 SkRectMemcpy(mapPtr, static_cast<size_t>(layout.rowPitch), data, row Bytes, trimRowBytes, 485 SkRectMemcpy(mapPtr, static_cast<size_t>(layout.rowPitch), data, row Bytes, trimRowBytes,
486 height); 486 height);
487 } 487 }
488 } 488 }
489 489
490 GrVkMemory::FlushMappedAlloc(this, alloc);
490 GR_VK_CALL(interface, UnmapMemory(fDevice, alloc.fMemory)); 491 GR_VK_CALL(interface, UnmapMemory(fDevice, alloc.fMemory));
491 492
492 return true; 493 return true;
493 } 494 }
494 495
495 bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, 496 bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
496 int left, int top, int width, int height, 497 int left, int top, int width, int height,
497 GrPixelConfig dataConfig, 498 GrPixelConfig dataConfig,
498 const SkTArray<GrMipLevel>& texels) { 499 const SkTArray<GrMipLevel>& texels) {
499 SkASSERT(!tex->isLinearTiled()); 500 SkASSERT(!tex->isLinearTiled());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 region.bufferRowLength = currentWidth; 593 region.bufferRowLength = currentWidth;
593 region.bufferImageHeight = currentHeight; 594 region.bufferImageHeight = currentHeight;
594 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMi pLevel), 0, 1 }; 595 region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMi pLevel), 0, 1 };
595 region.imageOffset = { left, flipY ? tex->height() - top - currentHeight : top, 0 }; 596 region.imageOffset = { left, flipY ? tex->height() - top - currentHeight : top, 0 };
596 region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 }; 597 region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 };
597 598
598 currentWidth = SkTMax(1, currentWidth/2); 599 currentWidth = SkTMax(1, currentWidth/2);
599 currentHeight = SkTMax(1, currentHeight/2); 600 currentHeight = SkTMax(1, currentHeight/2);
600 } 601 }
601 602
603 // no need to flush non-coherent memory, unmap will do that for us
602 transferBuffer->unmap(); 604 transferBuffer->unmap();
603 605
604 // Change layout of our target so it can be copied to 606 // Change layout of our target so it can be copied to
605 tex->setImageLayout(this, 607 tex->setImageLayout(this,
606 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 608 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
607 VK_ACCESS_TRANSFER_WRITE_BIT, 609 VK_ACCESS_TRANSFER_WRITE_BIT,
608 VK_PIPELINE_STAGE_TRANSFER_BIT, 610 VK_PIPELINE_STAGE_TRANSFER_BIT,
609 false); 611 false);
610 612
611 // Copy the buffer to the image 613 // Copy the buffer to the image
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 width, 951 width,
950 height, 952 height,
951 samples, 953 samples,
952 sFmt)); 954 sFmt));
953 fStats.incStencilAttachmentCreates(); 955 fStats.incStencilAttachmentCreates();
954 return stencil; 956 return stencil;
955 } 957 }
956 958
957 //////////////////////////////////////////////////////////////////////////////// 959 ////////////////////////////////////////////////////////////////////////////////
958 960
959 bool copy_testing_data(GrVkGpu* gpu, void* srcData, GrVkAlloc* alloc, 961 bool copy_testing_data(GrVkGpu* gpu, void* srcData, const GrVkAlloc& alloc,
960 size_t srcRowBytes, size_t dstRowBytes, int h) { 962 size_t srcRowBytes, size_t dstRowBytes, int h) {
961 void* mapPtr; 963 void* mapPtr;
962 VkResult err = GR_VK_CALL(gpu->vkInterface(), MapMemory(gpu->device(), 964 VkResult err = GR_VK_CALL(gpu->vkInterface(), MapMemory(gpu->device(),
963 alloc->fMemory, 965 alloc.fMemory,
964 alloc->fOffset, 966 alloc.fOffset,
965 dstRowBytes * h, 967 dstRowBytes * h,
966 0, 968 0,
967 &mapPtr)); 969 &mapPtr));
968 if (err) { 970 if (err) {
969 return false; 971 return false;
970 } 972 }
971 973
972 // If there is no padding on dst we can do a single memcopy. 974 // If there is no padding on dst we can do a single memcopy.
973 // This assumes the srcData comes in with no padding. 975 // This assumes the srcData comes in with no padding.
974 if (srcRowBytes == dstRowBytes) { 976 if (srcRowBytes == dstRowBytes) {
975 memcpy(mapPtr, srcData, srcRowBytes * h); 977 memcpy(mapPtr, srcData, srcRowBytes * h);
976 } else { 978 } else {
977 SkRectMemcpy(mapPtr, static_cast<size_t>(dstRowBytes), srcData, srcRowBy tes, 979 SkRectMemcpy(mapPtr, static_cast<size_t>(dstRowBytes), srcData, srcRowBy tes,
978 srcRowBytes, h); 980 srcRowBytes, h);
979 } 981 }
980 GR_VK_CALL(gpu->vkInterface(), UnmapMemory(gpu->device(), alloc->fMemory)); 982 GrVkMemory::FlushMappedAlloc(gpu, alloc);
983 GR_VK_CALL(gpu->vkInterface(), UnmapMemory(gpu->device(), alloc.fMemory));
981 return true; 984 return true;
982 } 985 }
983 986
984 GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i nt h, 987 GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i nt h,
985 GrPixelConfig config, 988 GrPixelConfig config,
986 bool isRenderTarget) { 989 bool isRenderTarget) {
987 990
988 VkFormat pixelFormat; 991 VkFormat pixelFormat;
989 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { 992 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
990 return 0; 993 return 0;
(...skipping 14 matching lines...) Expand all
1005 } 1008 }
1006 1009
1007 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; 1010 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
1008 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 1011 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1009 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; 1012 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1010 if (isRenderTarget) { 1013 if (isRenderTarget) {
1011 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; 1014 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1012 } 1015 }
1013 1016
1014 VkImage image = VK_NULL_HANDLE; 1017 VkImage image = VK_NULL_HANDLE;
1015 GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0 }; 1018 GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0, 0 };
1016 1019
1017 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL; 1020 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL;
1018 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) 1021 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling)
1019 ? VK_IMAGE_LAYOUT_PREINITIALIZED 1022 ? VK_IMAGE_LAYOUT_PREINITIALIZED
1020 : VK_IMAGE_LAYOUT_UNDEFINED; 1023 : VK_IMAGE_LAYOUT_UNDEFINED;
1021 1024
1022 // Create Image 1025 // Create Image
1023 VkSampleCountFlagBits vkSamples; 1026 VkSampleCountFlagBits vkSamples;
1024 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { 1027 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) {
1025 return 0; 1028 return 0;
(...skipping 30 matching lines...) Expand all
1056 if (linearTiling) { 1059 if (linearTiling) {
1057 const VkImageSubresource subres = { 1060 const VkImageSubresource subres = {
1058 VK_IMAGE_ASPECT_COLOR_BIT, 1061 VK_IMAGE_ASPECT_COLOR_BIT,
1059 0, // mipLevel 1062 0, // mipLevel
1060 0, // arraySlice 1063 0, // arraySlice
1061 }; 1064 };
1062 VkSubresourceLayout layout; 1065 VkSubresourceLayout layout;
1063 1066
1064 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ; 1067 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ;
1065 1068
1066 if (!copy_testing_data(this, srcData, &alloc, rowCopyBytes, 1069 if (!copy_testing_data(this, srcData, alloc, rowCopyBytes,
1067 static_cast<size_t>(layout.rowPitch), h)) { 1070 static_cast<size_t>(layout.rowPitch), h)) {
1068 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1071 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1069 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1072 VK_CALL(DestroyImage(fDevice, image, nullptr));
1070 return 0; 1073 return 0;
1071 } 1074 }
1072 } else { 1075 } else {
1073 SkASSERT(w && h); 1076 SkASSERT(w && h);
1074 1077
1075 VkBuffer buffer; 1078 VkBuffer buffer;
1076 VkBufferCreateInfo bufInfo; 1079 VkBufferCreateInfo bufInfo;
1077 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo)); 1080 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo));
1078 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 1081 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1079 bufInfo.flags = 0; 1082 bufInfo.flags = 0;
1080 bufInfo.size = rowCopyBytes * h; 1083 bufInfo.size = rowCopyBytes * h;
1081 bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; 1084 bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1082 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 1085 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1083 bufInfo.queueFamilyIndexCount = 0; 1086 bufInfo.queueFamilyIndexCount = 0;
1084 bufInfo.pQueueFamilyIndices = nullptr; 1087 bufInfo.pQueueFamilyIndices = nullptr;
1085 VkResult err; 1088 VkResult err;
1086 err = VK_CALL(CreateBuffer(fDevice, &bufInfo, nullptr, &buffer)); 1089 err = VK_CALL(CreateBuffer(fDevice, &bufInfo, nullptr, &buffer));
1087 1090
1088 if (err) { 1091 if (err) {
1089 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1092 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1090 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1093 VK_CALL(DestroyImage(fDevice, image, nullptr));
1091 return 0; 1094 return 0;
1092 } 1095 }
1093 1096
1094 GrVkAlloc bufferAlloc = { VK_NULL_HANDLE, 0, 0 }; 1097 GrVkAlloc bufferAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
1095 if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer:: kCopyRead_Type, 1098 if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer:: kCopyRead_Type,
1096 true, &bufferAlloc)) { 1099 true, &bufferAlloc)) {
1097 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1100 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1098 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1101 VK_CALL(DestroyImage(fDevice, image, nullptr));
1099 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); 1102 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr));
1100 return 0; 1103 return 0;
1101 } 1104 }
1102 1105
1103 if (!copy_testing_data(this, srcData, &bufferAlloc, rowCopyBytes, ro wCopyBytes, h)) { 1106 if (!copy_testing_data(this, srcData, bufferAlloc, rowCopyBytes, row CopyBytes, h)) {
1104 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1107 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1105 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1108 VK_CALL(DestroyImage(fDevice, image, nullptr));
1106 GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, b ufferAlloc); 1109 GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, b ufferAlloc);
1107 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); 1110 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr));
1108 return 0; 1111 return 0;
1109 } 1112 }
1110 1113
1111 const VkCommandBufferAllocateInfo cmdInfo = { 1114 const VkCommandBufferAllocateInfo cmdInfo = {
1112 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType 1115 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
1113 NULL, // pNext 1116 NULL, // pNext
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 transferBuffer->addMemoryBarrier(this, 1745 transferBuffer->addMemoryBarrier(this,
1743 VK_ACCESS_TRANSFER_WRITE_BIT, 1746 VK_ACCESS_TRANSFER_WRITE_BIT,
1744 VK_ACCESS_HOST_READ_BIT, 1747 VK_ACCESS_HOST_READ_BIT,
1745 VK_PIPELINE_STAGE_TRANSFER_BIT, 1748 VK_PIPELINE_STAGE_TRANSFER_BIT,
1746 VK_PIPELINE_STAGE_HOST_BIT, 1749 VK_PIPELINE_STAGE_HOST_BIT,
1747 false); 1750 false);
1748 1751
1749 // We need to submit the current command buffer to the Queue and make sure i t finishes before 1752 // We need to submit the current command buffer to the Queue and make sure i t finishes before
1750 // we can copy the data out of the buffer. 1753 // we can copy the data out of the buffer.
1751 this->submitCommandBuffer(kForce_SyncQueue); 1754 this->submitCommandBuffer(kForce_SyncQueue);
1752 1755 GrVkMemory::InvalidateMappedAlloc(this, transferBuffer->alloc());
egdaniel 2016/09/20 15:23:22 Is this a call we can put into map similar to Flus
jvanverth1 2016/09/20 15:30:54 I left it outside because we often map to write, a
1753 void* mappedMemory = transferBuffer->map(); 1756 void* mappedMemory = transferBuffer->map();
1754 1757
1755 if (copyFromOrigin) { 1758 if (copyFromOrigin) {
1756 uint32_t skipRows = region.imageExtent.height - height; 1759 uint32_t skipRows = region.imageExtent.height - height;
1757 mappedMemory = (char*)mappedMemory + transBufferRowBytes * skipRows + bp p * left; 1760 mappedMemory = (char*)mappedMemory + transBufferRowBytes * skipRows + bp p * left;
1758 } 1761 }
1759 1762
1760 if (flipY) { 1763 if (flipY) {
1761 const char* srcRow = reinterpret_cast<const char*>(mappedMemory); 1764 const char* srcRow = reinterpret_cast<const char*>(mappedMemory);
1762 char* dstRow = reinterpret_cast<char*>(buffer)+(height - 1) * rowBytes; 1765 char* dstRow = reinterpret_cast<char*>(buffer)+(height - 1) * rowBytes;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment 1844 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment
1842 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment 1845 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment
1843 // which is always at the first attachment. 1846 // which is always at the first attachment.
1844 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true); 1847 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true);
1845 fCurrentCmdBuffer->executeCommands(this, buffer); 1848 fCurrentCmdBuffer->executeCommands(this, buffer);
1846 fCurrentCmdBuffer->endRenderPass(this); 1849 fCurrentCmdBuffer->endRenderPass(this);
1847 1850
1848 this->didWriteToSurface(target, &bounds); 1851 this->didWriteToSurface(target, &bounds);
1849 } 1852 }
1850 1853
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkBuffer.cpp ('k') | src/gpu/vk/GrVkMemory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698