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

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

Issue 2348523002: Support use of non-coherent memory allocations in Vulkan. (Closed)
Patch Set: Fix viewer init 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
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 // make sure the unmap has finished 606 // make sure the unmap has finished
605 transferBuffer->addMemoryBarrier(this, 607 transferBuffer->addMemoryBarrier(this,
606 VK_ACCESS_HOST_WRITE_BIT, 608 VK_ACCESS_HOST_WRITE_BIT,
607 VK_ACCESS_TRANSFER_READ_BIT, 609 VK_ACCESS_TRANSFER_READ_BIT,
608 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 610 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
609 VK_PIPELINE_STAGE_TRANSFER_BIT, 611 VK_PIPELINE_STAGE_TRANSFER_BIT,
610 false); 612 false);
611 613
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 width, 959 width,
958 height, 960 height,
959 samples, 961 samples,
960 sFmt)); 962 sFmt));
961 fStats.incStencilAttachmentCreates(); 963 fStats.incStencilAttachmentCreates();
962 return stencil; 964 return stencil;
963 } 965 }
964 966
965 //////////////////////////////////////////////////////////////////////////////// 967 ////////////////////////////////////////////////////////////////////////////////
966 968
967 bool copy_testing_data(GrVkGpu* gpu, void* srcData, GrVkAlloc* alloc, 969 bool copy_testing_data(GrVkGpu* gpu, void* srcData, const GrVkAlloc& alloc,
968 size_t srcRowBytes, size_t dstRowBytes, int h) { 970 size_t srcRowBytes, size_t dstRowBytes, int h) {
969 void* mapPtr; 971 void* mapPtr;
970 VkResult err = GR_VK_CALL(gpu->vkInterface(), MapMemory(gpu->device(), 972 VkResult err = GR_VK_CALL(gpu->vkInterface(), MapMemory(gpu->device(),
971 alloc->fMemory, 973 alloc.fMemory,
972 alloc->fOffset, 974 alloc.fOffset,
973 dstRowBytes * h, 975 dstRowBytes * h,
974 0, 976 0,
975 &mapPtr)); 977 &mapPtr));
976 if (err) { 978 if (err) {
977 return false; 979 return false;
978 } 980 }
979 981
980 // If there is no padding on dst we can do a single memcopy. 982 // If there is no padding on dst we can do a single memcopy.
981 // This assumes the srcData comes in with no padding. 983 // This assumes the srcData comes in with no padding.
982 if (srcRowBytes == dstRowBytes) { 984 if (srcRowBytes == dstRowBytes) {
983 memcpy(mapPtr, srcData, srcRowBytes * h); 985 memcpy(mapPtr, srcData, srcRowBytes * h);
984 } else { 986 } else {
985 SkRectMemcpy(mapPtr, static_cast<size_t>(dstRowBytes), srcData, srcRowBy tes, 987 SkRectMemcpy(mapPtr, static_cast<size_t>(dstRowBytes), srcData, srcRowBy tes,
986 srcRowBytes, h); 988 srcRowBytes, h);
987 } 989 }
988 GR_VK_CALL(gpu->vkInterface(), UnmapMemory(gpu->device(), alloc->fMemory)); 990 GrVkMemory::FlushMappedAlloc(gpu, alloc);
991 GR_VK_CALL(gpu->vkInterface(), UnmapMemory(gpu->device(), alloc.fMemory));
989 return true; 992 return true;
990 } 993 }
991 994
992 GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i nt h, 995 GrBackendObject GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w, i nt h,
993 GrPixelConfig config, 996 GrPixelConfig config,
994 bool isRenderTarget) { 997 bool isRenderTarget) {
995 998
996 VkFormat pixelFormat; 999 VkFormat pixelFormat;
997 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { 1000 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
998 return 0; 1001 return 0;
(...skipping 14 matching lines...) Expand all
1013 } 1016 }
1014 1017
1015 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; 1018 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
1016 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 1019 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1017 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; 1020 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1018 if (isRenderTarget) { 1021 if (isRenderTarget) {
1019 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; 1022 usageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1020 } 1023 }
1021 1024
1022 VkImage image = VK_NULL_HANDLE; 1025 VkImage image = VK_NULL_HANDLE;
1023 GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0 }; 1026 GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0, 0 };
1024 1027
1025 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL; 1028 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL;
1026 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) 1029 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling)
1027 ? VK_IMAGE_LAYOUT_PREINITIALIZED 1030 ? VK_IMAGE_LAYOUT_PREINITIALIZED
1028 : VK_IMAGE_LAYOUT_UNDEFINED; 1031 : VK_IMAGE_LAYOUT_UNDEFINED;
1029 1032
1030 // Create Image 1033 // Create Image
1031 VkSampleCountFlagBits vkSamples; 1034 VkSampleCountFlagBits vkSamples;
1032 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { 1035 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) {
1033 return 0; 1036 return 0;
(...skipping 30 matching lines...) Expand all
1064 if (linearTiling) { 1067 if (linearTiling) {
1065 const VkImageSubresource subres = { 1068 const VkImageSubresource subres = {
1066 VK_IMAGE_ASPECT_COLOR_BIT, 1069 VK_IMAGE_ASPECT_COLOR_BIT,
1067 0, // mipLevel 1070 0, // mipLevel
1068 0, // arraySlice 1071 0, // arraySlice
1069 }; 1072 };
1070 VkSubresourceLayout layout; 1073 VkSubresourceLayout layout;
1071 1074
1072 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ; 1075 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ;
1073 1076
1074 if (!copy_testing_data(this, srcData, &alloc, rowCopyBytes, 1077 if (!copy_testing_data(this, srcData, alloc, rowCopyBytes,
1075 static_cast<size_t>(layout.rowPitch), h)) { 1078 static_cast<size_t>(layout.rowPitch), h)) {
1076 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1079 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1077 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1080 VK_CALL(DestroyImage(fDevice, image, nullptr));
1078 return 0; 1081 return 0;
1079 } 1082 }
1080 } else { 1083 } else {
1081 SkASSERT(w && h); 1084 SkASSERT(w && h);
1082 1085
1083 VkBuffer buffer; 1086 VkBuffer buffer;
1084 VkBufferCreateInfo bufInfo; 1087 VkBufferCreateInfo bufInfo;
1085 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo)); 1088 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo));
1086 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 1089 bufInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1087 bufInfo.flags = 0; 1090 bufInfo.flags = 0;
1088 bufInfo.size = rowCopyBytes * h; 1091 bufInfo.size = rowCopyBytes * h;
1089 bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; 1092 bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1090 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 1093 bufInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1091 bufInfo.queueFamilyIndexCount = 0; 1094 bufInfo.queueFamilyIndexCount = 0;
1092 bufInfo.pQueueFamilyIndices = nullptr; 1095 bufInfo.pQueueFamilyIndices = nullptr;
1093 VkResult err; 1096 VkResult err;
1094 err = VK_CALL(CreateBuffer(fDevice, &bufInfo, nullptr, &buffer)); 1097 err = VK_CALL(CreateBuffer(fDevice, &bufInfo, nullptr, &buffer));
1095 1098
1096 if (err) { 1099 if (err) {
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 return 0; 1102 return 0;
1100 } 1103 }
1101 1104
1102 GrVkAlloc bufferAlloc = { VK_NULL_HANDLE, 0, 0 }; 1105 GrVkAlloc bufferAlloc = { VK_NULL_HANDLE, 0, 0, 0 };
1103 if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer:: kCopyRead_Type, 1106 if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer:: kCopyRead_Type,
1104 true, &bufferAlloc)) { 1107 true, &bufferAlloc)) {
1105 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1108 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1106 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1109 VK_CALL(DestroyImage(fDevice, image, nullptr));
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 if (!copy_testing_data(this, srcData, &bufferAlloc, rowCopyBytes, ro wCopyBytes, h)) { 1114 if (!copy_testing_data(this, srcData, bufferAlloc, rowCopyBytes, row CopyBytes, h)) {
1112 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); 1115 GrVkMemory::FreeImageMemory(this, linearTiling, alloc);
1113 VK_CALL(DestroyImage(fDevice, image, nullptr)); 1116 VK_CALL(DestroyImage(fDevice, image, nullptr));
1114 GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, b ufferAlloc); 1117 GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, b ufferAlloc);
1115 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr)); 1118 VK_CALL(DestroyBuffer(fDevice, buffer, nullptr));
1116 return 0; 1119 return 0;
1117 } 1120 }
1118 1121
1119 const VkCommandBufferAllocateInfo cmdInfo = { 1122 const VkCommandBufferAllocateInfo cmdInfo = {
1120 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType 1123 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType
1121 NULL, // pNext 1124 NULL, // pNext
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 transferBuffer->addMemoryBarrier(this, 1753 transferBuffer->addMemoryBarrier(this,
1751 VK_ACCESS_TRANSFER_WRITE_BIT, 1754 VK_ACCESS_TRANSFER_WRITE_BIT,
1752 VK_ACCESS_HOST_READ_BIT, 1755 VK_ACCESS_HOST_READ_BIT,
1753 VK_PIPELINE_STAGE_TRANSFER_BIT, 1756 VK_PIPELINE_STAGE_TRANSFER_BIT,
1754 VK_PIPELINE_STAGE_HOST_BIT, 1757 VK_PIPELINE_STAGE_HOST_BIT,
1755 false); 1758 false);
1756 1759
1757 // We need to submit the current command buffer to the Queue and make sure i t finishes before 1760 // We need to submit the current command buffer to the Queue and make sure i t finishes before
1758 // we can copy the data out of the buffer. 1761 // we can copy the data out of the buffer.
1759 this->submitCommandBuffer(kForce_SyncQueue); 1762 this->submitCommandBuffer(kForce_SyncQueue);
1760 1763 GrVkMemory::InvalidateMappedAlloc(this, transferBuffer->alloc());
1761 void* mappedMemory = transferBuffer->map(); 1764 void* mappedMemory = transferBuffer->map();
1762 1765
1763 if (copyFromOrigin) { 1766 if (copyFromOrigin) {
1764 uint32_t skipRows = region.imageExtent.height - height; 1767 uint32_t skipRows = region.imageExtent.height - height;
1765 mappedMemory = (char*)mappedMemory + transBufferRowBytes * skipRows + bp p * left; 1768 mappedMemory = (char*)mappedMemory + transBufferRowBytes * skipRows + bp p * left;
1766 } 1769 }
1767 1770
1768 if (flipY) { 1771 if (flipY) {
1769 const char* srcRow = reinterpret_cast<const char*>(mappedMemory); 1772 const char* srcRow = reinterpret_cast<const char*>(mappedMemory);
1770 char* dstRow = reinterpret_cast<char*>(buffer)+(height - 1) * rowBytes; 1773 char* dstRow = reinterpret_cast<char*>(buffer)+(height - 1) * rowBytes;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment 1852 // Currently it is fine for us to always pass in 1 for the clear count even if no attachment
1850 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment 1853 // uses it. In the current state, we also only use the LOAD_OP_CLEAR for the color attachment
1851 // which is always at the first attachment. 1854 // which is always at the first attachment.
1852 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true); 1855 fCurrentCmdBuffer->beginRenderPass(this, renderPass, 1, colorClear, *target, *pBounds, true);
1853 fCurrentCmdBuffer->executeCommands(this, buffer); 1856 fCurrentCmdBuffer->executeCommands(this, buffer);
1854 fCurrentCmdBuffer->endRenderPass(this); 1857 fCurrentCmdBuffer->endRenderPass(this);
1855 1858
1856 this->didWriteToSurface(target, &bounds); 1859 this->didWriteToSurface(target, &bounds);
1857 } 1860 }
1858 1861
OLDNEW
« no previous file with comments | « src/gpu/vk/GrVkBuffer.cpp ('k') | src/gpu/vk/GrVkMemory.h » ('j') | src/gpu/vk/GrVkMemory.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698