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

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

Issue 1950713006: Clean up GrVkImage::setLayout() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix one set of flags Created 4 years, 7 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 | « no previous file | src/gpu/vk/GrVkImage.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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // height); 261 // height);
262 } else { 262 } else {
263 bool linearTiling = vkTex->isLinearTiled(); 263 bool linearTiling = vkTex->isLinearTiled();
264 if (linearTiling) { 264 if (linearTiling) {
265 if (texels.count() > 1) { 265 if (texels.count() > 1) {
266 SkDebugf("Can't upload mipmap data to linear tiled texture"); 266 SkDebugf("Can't upload mipmap data to linear tiled texture");
267 return false; 267 return false;
268 } 268 }
269 if (VK_IMAGE_LAYOUT_PREINITIALIZED != vkTex->currentLayout()) { 269 if (VK_IMAGE_LAYOUT_PREINITIALIZED != vkTex->currentLayout()) {
270 // Need to change the layout to general in order to perform a ho st write 270 // Need to change the layout to general in order to perform a ho st write
271 VkImageLayout layout = vkTex->currentLayout();
272 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipeline StageFlags(layout);
273 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_HOST_BIT;
274 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask( layout);
275 VkAccessFlags dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
276 vkTex->setImageLayout(this, 271 vkTex->setImageLayout(this,
277 VK_IMAGE_LAYOUT_GENERAL, 272 VK_IMAGE_LAYOUT_GENERAL,
278 srcAccessMask, 273 VK_ACCESS_HOST_WRITE_BIT,
279 dstAccessMask, 274 VK_PIPELINE_STAGE_HOST_BIT,
280 srcStageMask,
281 dstStageMask,
282 false); 275 false);
283 this->submitCommandBuffer(kForce_SyncQueue); 276 this->submitCommandBuffer(kForce_SyncQueue);
284 } 277 }
285 success = this->uploadTexDataLinear(vkTex, left, top, width, height, config, 278 success = this->uploadTexDataLinear(vkTex, left, top, width, height, config,
286 texels.begin()->fPixels, texels. begin()->fRowBytes); 279 texels.begin()->fPixels, texels. begin()->fRowBytes);
287 } else { 280 } else {
288 int newMipLevels = texels.count(); 281 int newMipLevels = texels.count();
289 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1; 282 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1;
290 if (newMipLevels != currentMipLevels) { 283 if (newMipLevels != currentMipLevels) {
291 if (!vkTex->reallocForMipmap(this, newMipLevels)) { 284 if (!vkTex->reallocForMipmap(this, newMipLevels)) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 475
483 // make sure the unmap has finished 476 // make sure the unmap has finished
484 transferBuffer->addMemoryBarrier(this, 477 transferBuffer->addMemoryBarrier(this,
485 VK_ACCESS_HOST_WRITE_BIT, 478 VK_ACCESS_HOST_WRITE_BIT,
486 VK_ACCESS_TRANSFER_READ_BIT, 479 VK_ACCESS_TRANSFER_READ_BIT,
487 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 480 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
488 VK_PIPELINE_STAGE_TRANSFER_BIT, 481 VK_PIPELINE_STAGE_TRANSFER_BIT,
489 false); 482 false);
490 483
491 // Change layout of our target so it can be copied to 484 // Change layout of our target so it can be copied to
492 VkImageLayout layout = tex->currentLayout();
493 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l ayout);
494 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
495 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout);
496 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
497 tex->setImageLayout(this, 485 tex->setImageLayout(this,
498 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 486 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
499 srcAccessMask, 487 VK_ACCESS_TRANSFER_WRITE_BIT,
500 dstAccessMask, 488 VK_PIPELINE_STAGE_TRANSFER_BIT,
501 srcStageMask,
502 dstStageMask,
503 false); 489 false);
504 490
505 // Copy the buffer to the image 491 // Copy the buffer to the image
506 fCurrentCmdBuffer->copyBufferToImage(this, 492 fCurrentCmdBuffer->copyBufferToImage(this,
507 transferBuffer, 493 transferBuffer,
508 tex, 494 tex,
509 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 495 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
510 regions.count(), 496 regions.count(),
511 regions.begin()); 497 regions.begin());
512 498
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 699 }
714 700
715 // determine if we can blit to and from this format 701 // determine if we can blit to and from this format
716 const GrVkCaps& caps = this->vkCaps(); 702 const GrVkCaps& caps = this->vkCaps();
717 if (!caps.configCanBeDstofBlit(tex->config(), false) || 703 if (!caps.configCanBeDstofBlit(tex->config(), false) ||
718 !caps.configCanBeSrcofBlit(tex->config(), false)) { 704 !caps.configCanBeSrcofBlit(tex->config(), false)) {
719 return; 705 return;
720 } 706 }
721 707
722 // change the original image's layout 708 // change the original image's layout
723 VkImageLayout origSrcLayout = tex->currentLayout();
724 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigSrcLayout);
725 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
726
727 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origSrcLayou t);
728 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
729
730 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 709 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
731 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false); 710 VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_ BIT, false);
732 711
733 // grab handle to the original image resource 712 // grab handle to the original image resource
734 const GrVkImage::Resource* oldResource = tex->resource(); 713 const GrVkImage::Resource* oldResource = tex->resource();
735 oldResource->ref(); 714 oldResource->ref();
736 715
737 // SkMipMap doesn't include the base level in the level count so we have to add 1 716 // SkMipMap doesn't include the base level in the level count so we have to add 1
738 uint32_t levelCount = SkMipMap::ComputeLevelCount(tex->width(), tex->height( )) + 1; 717 uint32_t levelCount = SkMipMap::ComputeLevelCount(tex->width(), tex->height( )) + 1;
739 if (!tex->reallocForMipmap(this, levelCount)) { 718 if (!tex->reallocForMipmap(this, levelCount)) {
740 oldResource->unref(this); 719 oldResource->unref(this);
741 return; 720 return;
742 } 721 }
743 722
744 // change the new image's layout 723 // change the new image's layout
745 VkImageLayout origDstLayout = tex->currentLayout(); 724 tex->setImageLayout(this, VK_IMAGE_LAYOUT_GENERAL,
746 725 VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER _BIT, false);
747 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origDstLayout);
748 dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
749
750 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayout);
751 dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
752
753 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
754 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false);
755 726
756 // Blit original image 727 // Blit original image
757 int width = tex->width(); 728 int width = tex->width();
758 int height = tex->height(); 729 int height = tex->height();
759 730
760 VkImageBlit blitRegion; 731 VkImageBlit blitRegion;
761 memset(&blitRegion, 0, sizeof(VkImageBlit)); 732 memset(&blitRegion, 0, sizeof(VkImageBlit));
762 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; 733 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
763 blitRegion.srcOffsets[0] = { 0, 0, 0 }; 734 blitRegion.srcOffsets[0] = { 0, 0, 0 };
764 blitRegion.srcOffsets[1] = { width, height, 0 }; 735 blitRegion.srcOffsets[1] = { width, height, 0 };
765 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; 736 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
766 blitRegion.dstOffsets[0] = { 0, 0, 0 }; 737 blitRegion.dstOffsets[0] = { 0, 0, 0 };
767 blitRegion.dstOffsets[1] = { width, height, 0 }; 738 blitRegion.dstOffsets[1] = { width, height, 0 };
768 739
769 fCurrentCmdBuffer->blitImage(this, 740 fCurrentCmdBuffer->blitImage(this,
770 oldResource, 741 oldResource,
771 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 742 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
772 tex->resource(), 743 tex->resource(),
773 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 744 VK_IMAGE_LAYOUT_GENERAL,
774 1, 745 1,
775 &blitRegion, 746 &blitRegion,
776 VK_FILTER_LINEAR); 747 VK_FILTER_LINEAR);
748
749 // setup memory barrier
750 SkASSERT(GrVkFormatToPixelConfig(tex->resource()->fFormat, nullptr));
751 VkImageAspectFlags aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
752 VkImageMemoryBarrier imageMemoryBarrier = {
753 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
754 NULL, // pNext
755 VK_ACCESS_TRANSFER_WRITE_BIT, // outputMask
756 VK_ACCESS_TRANSFER_READ_BIT, // inputMask
757 VK_IMAGE_LAYOUT_GENERAL, // oldLayout
758 VK_IMAGE_LAYOUT_GENERAL, // newLayout
759 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
760 VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex
761 tex->resource()->fImage, // image
762 { aspectFlags, 0, 1, 0, 1 } // subresourceRange
763 };
764
777 // Blit the miplevels 765 // Blit the miplevels
778 uint32_t mipLevel = 1; 766 uint32_t mipLevel = 1;
779 while (mipLevel < levelCount) { 767 while (mipLevel < levelCount) {
780 int prevWidth = width; 768 int prevWidth = width;
781 int prevHeight = height; 769 int prevHeight = height;
782 width = SkTMax(1, width / 2); 770 width = SkTMax(1, width / 2);
783 height = SkTMax(1, height / 2); 771 height = SkTMax(1, height / 2);
784 772
785 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel-1, 0, 1 }; 773 imageMemoryBarrier.subresourceRange.baseMipLevel = mipLevel - 1;
774 this->addImageMemoryBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_ STAGE_TRANSFER_BIT,
775 false, &imageMemoryBarrier);
776
777 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel - 1, 0 , 1 };
786 blitRegion.srcOffsets[0] = { 0, 0, 0 }; 778 blitRegion.srcOffsets[0] = { 0, 0, 0 };
787 blitRegion.srcOffsets[1] = { prevWidth, prevHeight, 0 }; 779 blitRegion.srcOffsets[1] = { prevWidth, prevHeight, 0 };
788 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 }; 780 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 };
789 blitRegion.dstOffsets[0] = { 0, 0, 0 }; 781 blitRegion.dstOffsets[0] = { 0, 0, 0 };
790 blitRegion.dstOffsets[1] = { width, height, 0 }; 782 blitRegion.dstOffsets[1] = { width, height, 0 };
791
792 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
793 srcAccessMask, dstAccessMask, srcStageMask, dstStage Mask,
794 mipLevel-1, 1, false);
795
796 fCurrentCmdBuffer->blitImage(this, 783 fCurrentCmdBuffer->blitImage(this,
797 tex->resource(), 784 tex->resource(),
798 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 785 VK_IMAGE_LAYOUT_GENERAL,
799 tex->resource(), 786 tex->resource(),
800 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 787 VK_IMAGE_LAYOUT_GENERAL,
801 1, 788 1,
802 &blitRegion, 789 &blitRegion,
803 VK_FILTER_LINEAR); 790 VK_FILTER_LINEAR);
804 ++mipLevel; 791 ++mipLevel;
805 } 792 }
806 793
807 oldResource->unref(this); 794 oldResource->unref(this);
808 } 795 }
809 796
810 797
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 if (nullptr == target) { 1040 if (nullptr == target) {
1054 return; 1041 return;
1055 } 1042 }
1056 GrStencilAttachment* stencil = target->renderTargetPriv().getStencilAttachme nt(); 1043 GrStencilAttachment* stencil = target->renderTargetPriv().getStencilAttachme nt();
1057 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; 1044 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil;
1058 1045
1059 1046
1060 VkClearDepthStencilValue vkStencilColor; 1047 VkClearDepthStencilValue vkStencilColor;
1061 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); 1048 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue));
1062 1049
1063 VkImageLayout origDstLayout = vkStencil->currentLayout();
1064
1065 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigDstLayout);
1066 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1067
1068 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayou t);;
1069 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
1070
1071 vkStencil->setImageLayout(this, 1050 vkStencil->setImageLayout(this,
1072 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1051 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1073 srcAccessMask, 1052 VK_ACCESS_TRANSFER_WRITE_BIT,
1074 dstAccessMask, 1053 VK_PIPELINE_STAGE_TRANSFER_BIT,
1075 srcStageMask,
1076 dstStageMask,
1077 false); 1054 false);
1078 1055
1079
1080 VkImageSubresourceRange subRange; 1056 VkImageSubresourceRange subRange;
1081 memset(&subRange, 0, sizeof(VkImageSubresourceRange)); 1057 memset(&subRange, 0, sizeof(VkImageSubresourceRange));
1082 subRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; 1058 subRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
1083 subRange.baseMipLevel = 0; 1059 subRange.baseMipLevel = 0;
1084 subRange.levelCount = 1; 1060 subRange.levelCount = 1;
1085 subRange.baseArrayLayer = 0; 1061 subRange.baseArrayLayer = 0;
1086 subRange.layerCount = 1; 1062 subRange.layerCount = 1;
1087 1063
1088 // TODO: I imagine that most times we want to clear a stencil it will be at the beginning of a 1064 // TODO: I imagine that most times we want to clear a stencil it will be at the beginning of a
1089 // draw. Thus we should look into using the load op functions on the render pass to clear out 1065 // draw. Thus we should look into using the load op functions on the render pass to clear out
(...skipping 17 matching lines...) Expand all
1107 // during this clear. Thus we will clear the entire stencil to the desired v alue. 1083 // during this clear. Thus we will clear the entire stencil to the desired v alue.
1108 1084
1109 VkClearDepthStencilValue vkStencilColor; 1085 VkClearDepthStencilValue vkStencilColor;
1110 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); 1086 memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue));
1111 if (insideClip) { 1087 if (insideClip) {
1112 vkStencilColor.stencil = (1 << (stencilBitCount - 1)); 1088 vkStencilColor.stencil = (1 << (stencilBitCount - 1));
1113 } else { 1089 } else {
1114 vkStencilColor.stencil = 0; 1090 vkStencilColor.stencil = 0;
1115 } 1091 }
1116 1092
1117 VkImageLayout origDstLayout = vkStencil->currentLayout();
1118 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayou t);
1119 VkAccessFlags dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
1120 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigDstLayout);
1121 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1122 vkStencil->setImageLayout(this, 1093 vkStencil->setImageLayout(this,
1123 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, 1094 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
1124 srcAccessMask, 1095 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
1125 dstAccessMask, 1096 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1126 srcStageMask,
1127 dstStageMask,
1128 false); 1097 false);
1129 1098
1130 // Change layout of our render target so it can be used as the color attachm ent. This is what 1099 // Change layout of our render target so it can be used as the color attachm ent. This is what
1131 // the render pass expects when it begins. 1100 // the render pass expects when it begins.
1132 VkImageLayout layout = vkRT->currentLayout();
1133 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(layout);
1134 dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1135 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout);
1136 dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
1137 vkRT->setImageLayout(this, 1101 vkRT->setImageLayout(this,
1138 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1102 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1139 srcAccessMask, 1103 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1140 dstAccessMask, 1104 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1141 srcStageMask,
1142 dstStageMask,
1143 false); 1105 false);
1144 1106
1145 VkClearRect clearRect; 1107 VkClearRect clearRect;
1146 // Flip rect if necessary 1108 // Flip rect if necessary
1147 SkIRect vkRect = rect; 1109 SkIRect vkRect = rect;
1148 1110
1149 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { 1111 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) {
1150 vkRect.fTop = vkRT->height() - rect.fBottom; 1112 vkRect.fTop = vkRT->height() - rect.fBottom;
1151 vkRect.fBottom = vkRT->height() - rect.fTop; 1113 vkRect.fBottom = vkRT->height() - rect.fTop;
1152 } 1114 }
(...skipping 23 matching lines...) Expand all
1176 } 1138 }
1177 1139
1178 void GrVkGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) { 1140 void GrVkGpu::onClear(GrRenderTarget* target, const SkIRect& rect, GrColor color ) {
1179 // parent class should never let us get here with no RT 1141 // parent class should never let us get here with no RT
1180 SkASSERT(target); 1142 SkASSERT(target);
1181 1143
1182 VkClearColorValue vkColor; 1144 VkClearColorValue vkColor;
1183 GrColorToRGBAFloat(color, vkColor.float32); 1145 GrColorToRGBAFloat(color, vkColor.float32);
1184 1146
1185 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target); 1147 GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(target);
1186 VkImageLayout origDstLayout = vkRT->currentLayout();
1187 1148
1188 if (rect.width() != target->width() || rect.height() != target->height()) { 1149 if (rect.width() != target->width() || rect.height() != target->height()) {
1189 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstL ayout);
1190 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
1191 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFla gs(origDstLayout);
1192 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1193 vkRT->setImageLayout(this, 1150 vkRT->setImageLayout(this,
1194 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1151 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1195 srcAccessMask, 1152 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1196 dstAccessMask, 1153 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1197 srcStageMask,
1198 dstStageMask,
1199 false); 1154 false);
1200 1155
1201 // If we are using a stencil attachment we also need to change its layou t to what the render 1156 // If we are using a stencil attachment we also need to change its layou t to what the render
1202 // pass is expecting. 1157 // pass is expecting.
1203 if (GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAt tachment()) { 1158 if (GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAt tachment()) {
1204 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; 1159 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil;
1205 origDstLayout = vkStencil->currentLayout();
1206 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayout);
1207 dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1208 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
1209 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origDstLayout) ;
1210 dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1211 vkStencil->setImageLayout(this, 1160 vkStencil->setImageLayout(this,
1212 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_O PTIMAL, 1161 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_O PTIMAL,
1213 srcAccessMask, 1162 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_B IT |
1214 dstAccessMask, 1163 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BI T,
1215 srcStageMask, 1164 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1216 dstStageMask,
1217 false); 1165 false);
1218 } 1166 }
1219 1167
1220 VkClearRect clearRect; 1168 VkClearRect clearRect;
1221 // Flip rect if necessary 1169 // Flip rect if necessary
1222 SkIRect vkRect = rect; 1170 SkIRect vkRect = rect;
1223 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) { 1171 if (kBottomLeft_GrSurfaceOrigin == vkRT->origin()) {
1224 vkRect.fTop = vkRT->height() - rect.fBottom; 1172 vkRect.fTop = vkRT->height() - rect.fBottom;
1225 vkRect.fBottom = vkRT->height() - rect.fTop; 1173 vkRect.fBottom = vkRT->height() - rect.fTop;
1226 } 1174 }
(...skipping 12 matching lines...) Expand all
1239 VkClearAttachment attachment; 1187 VkClearAttachment attachment;
1240 attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; 1188 attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1241 attachment.colorAttachment = colorIndex; 1189 attachment.colorAttachment = colorIndex;
1242 attachment.clearValue.color = vkColor; 1190 attachment.clearValue.color = vkColor;
1243 1191
1244 fCurrentCmdBuffer->clearAttachments(this, 1, &attachment, 1, &clearRect) ; 1192 fCurrentCmdBuffer->clearAttachments(this, 1, &attachment, 1, &clearRect) ;
1245 fCurrentCmdBuffer->endRenderPass(this); 1193 fCurrentCmdBuffer->endRenderPass(this);
1246 return; 1194 return;
1247 } 1195 }
1248 1196
1249 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigDstLayout);
1250 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1251
1252 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayou t);;
1253 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
1254
1255 vkRT->setImageLayout(this, 1197 vkRT->setImageLayout(this,
1256 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1198 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1257 srcAccessMask, 1199 VK_ACCESS_TRANSFER_WRITE_BIT,
1258 dstAccessMask, 1200 VK_PIPELINE_STAGE_TRANSFER_BIT,
1259 srcStageMask,
1260 dstStageMask,
1261 false); 1201 false);
1262 1202
1263
1264 VkImageSubresourceRange subRange; 1203 VkImageSubresourceRange subRange;
1265 memset(&subRange, 0, sizeof(VkImageSubresourceRange)); 1204 memset(&subRange, 0, sizeof(VkImageSubresourceRange));
1266 subRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; 1205 subRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
1267 subRange.baseMipLevel = 0; 1206 subRange.baseMipLevel = 0;
1268 subRange.levelCount = 1; 1207 subRange.levelCount = 1;
1269 subRange.baseArrayLayer = 0; 1208 subRange.baseArrayLayer = 0;
1270 subRange.layerCount = 1; 1209 subRange.layerCount = 1;
1271 1210
1272 // In the future we may not actually be doing this type of clear at all. If we are inside a 1211 // In the future we may not actually be doing this type of clear at all. If we are inside a
1273 // render pass or doing a non full clear then we will use CmdClearColorAttac hment. The more 1212 // render pass or doing a non full clear then we will use CmdClearColorAttac hment. The more
(...skipping 28 matching lines...) Expand all
1302 } 1241 }
1303 1242
1304 void GrVkGpu::copySurfaceAsCopyImage(GrSurface* dst, 1243 void GrVkGpu::copySurfaceAsCopyImage(GrSurface* dst,
1305 GrSurface* src, 1244 GrSurface* src,
1306 GrVkImage* dstImage, 1245 GrVkImage* dstImage,
1307 GrVkImage* srcImage, 1246 GrVkImage* srcImage,
1308 const SkIRect& srcRect, 1247 const SkIRect& srcRect,
1309 const SkIPoint& dstPoint) { 1248 const SkIPoint& dstPoint) {
1310 SkASSERT(can_copy_image(dst, src, this)); 1249 SkASSERT(can_copy_image(dst, src, this));
1311 1250
1312 VkImageLayout origDstLayout = dstImage->currentLayout();
1313 VkImageLayout origSrcLayout = srcImage->currentLayout();
1314
1315 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigDstLayout);
1316 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1317
1318 // These flags are for flushing/invalidating caches and for the dst image it doesn't matter if 1251 // These flags are for flushing/invalidating caches and for the dst image it doesn't matter if
1319 // the cache is flushed since it is only being written to. 1252 // the cache is flushed since it is only being written to.
1320 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayou t);;
1321 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
1322
1323 dstImage->setImageLayout(this, 1253 dstImage->setImageLayout(this,
1324 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1254 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1325 srcAccessMask, 1255 VK_ACCESS_TRANSFER_WRITE_BIT,
1326 dstAccessMask, 1256 VK_PIPELINE_STAGE_TRANSFER_BIT,
1327 srcStageMask, 1257 false);
1328 dstStageMask,
1329 false);
1330
1331 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origSrcLayout);
1332 dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1333
1334 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origSrcLayout);
1335 dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
1336 1258
1337 srcImage->setImageLayout(this, 1259 srcImage->setImageLayout(this,
1338 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1260 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1339 srcAccessMask, 1261 VK_ACCESS_TRANSFER_READ_BIT,
1340 dstAccessMask, 1262 VK_PIPELINE_STAGE_TRANSFER_BIT,
1341 srcStageMask,
1342 dstStageMask,
1343 false); 1263 false);
1344 1264
1345 // Flip rect if necessary 1265 // Flip rect if necessary
1346 SkIRect srcVkRect = srcRect; 1266 SkIRect srcVkRect = srcRect;
1347 int32_t dstY = dstPoint.fY; 1267 int32_t dstY = dstPoint.fY;
1348 1268
1349 if (kBottomLeft_GrSurfaceOrigin == src->origin()) { 1269 if (kBottomLeft_GrSurfaceOrigin == src->origin()) {
1350 SkASSERT(kBottomLeft_GrSurfaceOrigin == dst->origin()); 1270 SkASSERT(kBottomLeft_GrSurfaceOrigin == dst->origin());
1351 srcVkRect.fTop = src->height() - srcRect.fBottom; 1271 srcVkRect.fTop = src->height() - srcRect.fBottom;
1352 srcVkRect.fBottom = src->height() - srcRect.fTop; 1272 srcVkRect.fBottom = src->height() - srcRect.fTop;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 } 1321 }
1402 1322
1403 void GrVkGpu::copySurfaceAsBlit(GrSurface* dst, 1323 void GrVkGpu::copySurfaceAsBlit(GrSurface* dst,
1404 GrSurface* src, 1324 GrSurface* src,
1405 GrVkImage* dstImage, 1325 GrVkImage* dstImage,
1406 GrVkImage* srcImage, 1326 GrVkImage* srcImage,
1407 const SkIRect& srcRect, 1327 const SkIRect& srcRect,
1408 const SkIPoint& dstPoint) { 1328 const SkIPoint& dstPoint) {
1409 SkASSERT(can_copy_as_blit(dst, src, dstImage, srcImage, this)); 1329 SkASSERT(can_copy_as_blit(dst, src, dstImage, srcImage, this));
1410 1330
1411 VkImageLayout origDstLayout = dstImage->currentLayout();
1412 VkImageLayout origSrcLayout = srcImage->currentLayout();
1413
1414 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(o rigDstLayout);
1415 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1416
1417 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayou t);;
1418 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
1419
1420 dstImage->setImageLayout(this, 1331 dstImage->setImageLayout(this,
1421 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1332 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1422 srcAccessMask, 1333 VK_ACCESS_TRANSFER_WRITE_BIT,
1423 dstAccessMask, 1334 VK_PIPELINE_STAGE_TRANSFER_BIT,
1424 srcStageMask,
1425 dstStageMask,
1426 false); 1335 false);
1427 1336
1428 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origSrcLayout);
1429 dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1430
1431 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origSrcLayout);
1432 dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
1433
1434 srcImage->setImageLayout(this, 1337 srcImage->setImageLayout(this,
1435 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1338 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1436 srcAccessMask, 1339 VK_ACCESS_TRANSFER_READ_BIT,
1437 dstAccessMask, 1340 VK_PIPELINE_STAGE_TRANSFER_BIT,
1438 srcStageMask,
1439 dstStageMask,
1440 false); 1341 false);
1441 1342
1442 // Flip rect if necessary 1343 // Flip rect if necessary
1443 SkIRect srcVkRect; 1344 SkIRect srcVkRect;
1444 srcVkRect.fLeft = srcRect.fLeft; 1345 srcVkRect.fLeft = srcRect.fLeft;
1445 srcVkRect.fRight = srcRect.fRight; 1346 srcVkRect.fRight = srcRect.fRight;
1446 SkIRect dstRect; 1347 SkIRect dstRect;
1447 dstRect.fLeft = dstPoint.fX; 1348 dstRect.fLeft = dstPoint.fX;
1448 dstRect.fRight = dstPoint.fX + srcRect.width(); 1349 dstRect.fRight = dstPoint.fX + srcRect.width();
1449 1350
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) { 1487 if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
1587 return false; 1488 return false;
1588 } 1489 }
1589 1490
1590 GrVkTexture* tgt = static_cast<GrVkTexture*>(surface->asTexture()); 1491 GrVkTexture* tgt = static_cast<GrVkTexture*>(surface->asTexture());
1591 if (!tgt) { 1492 if (!tgt) {
1592 return false; 1493 return false;
1593 } 1494 }
1594 1495
1595 // Change layout of our target so it can be used as copy 1496 // Change layout of our target so it can be used as copy
1596 VkImageLayout layout = tgt->currentLayout();
1597 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l ayout);
1598 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
1599 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout);
1600 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
1601 tgt->setImageLayout(this, 1497 tgt->setImageLayout(this,
1602 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1498 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1603 srcAccessMask, 1499 VK_ACCESS_TRANSFER_READ_BIT,
1604 dstAccessMask, 1500 VK_PIPELINE_STAGE_TRANSFER_BIT,
1605 srcStageMask,
1606 dstStageMask,
1607 false); 1501 false);
1608 1502
1609 GrVkTransferBuffer* transferBuffer = 1503 GrVkTransferBuffer* transferBuffer =
1610 static_cast<GrVkTransferBuffer*>(this->createBuffer(rowBytes * height, 1504 static_cast<GrVkTransferBuffer*>(this->createBuffer(rowBytes * height,
1611 kXferGpuToCpu_GrBuff erType, 1505 kXferGpuToCpu_GrBuff erType,
1612 kStream_GrAccessPatt ern)); 1506 kStream_GrAccessPatt ern));
1613 1507
1614 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin(); 1508 bool flipY = kBottomLeft_GrSurfaceOrigin == surface->origin();
1615 VkOffset3D offset = { 1509 VkOffset3D offset = {
1616 left, 1510 left,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 GrPrimitiveType primitiveType = meshes[0].primitiveType(); 1605 GrPrimitiveType primitiveType = meshes[0].primitiveType();
1712 sk_sp<GrVkPipelineState> pipelineState = this->prepareDrawState(pipeline, 1606 sk_sp<GrVkPipelineState> pipelineState = this->prepareDrawState(pipeline,
1713 primProc, 1607 primProc,
1714 primitiveTyp e, 1608 primitiveTyp e,
1715 *renderPass) ; 1609 *renderPass) ;
1716 if (!pipelineState) { 1610 if (!pipelineState) {
1717 return; 1611 return;
1718 } 1612 }
1719 1613
1720 // Change layout of our render target so it can be used as the color attachm ent 1614 // Change layout of our render target so it can be used as the color attachm ent
1721 VkImageLayout layout = vkRT->currentLayout();
1722 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l ayout);
1723 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1724 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout);
1725 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
1726 vkRT->setImageLayout(this, 1615 vkRT->setImageLayout(this,
1727 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1616 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1728 srcAccessMask, 1617 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
1729 dstAccessMask, 1618 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1730 srcStageMask,
1731 dstStageMask,
1732 false); 1619 false);
1733 1620
1734 // If we are using a stencil attachment we also need to update its layout 1621 // If we are using a stencil attachment we also need to update its layout
1735 if (GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAttach ment()) { 1622 if (GrStencilAttachment* stencil = vkRT->renderTargetPriv().getStencilAttach ment()) {
1736 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil; 1623 GrVkStencilAttachment* vkStencil = (GrVkStencilAttachment*)stencil;
1737 VkImageLayout origDstLayout = vkStencil->currentLayout();
1738 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstL ayout);
1739 VkAccessFlags dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_B IT |
1740 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
1741 VkPipelineStageFlags srcStageMask =
1742 GrVkMemory::LayoutToPipelineStageFlags(origDstLayout);
1743 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1744 vkStencil->setImageLayout(this, 1624 vkStencil->setImageLayout(this,
1745 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIM AL, 1625 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIM AL,
1746 srcAccessMask, 1626 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1747 dstAccessMask, 1627 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT,
1748 srcStageMask, 1628 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
1749 dstStageMask,
1750 false); 1629 false);
1751 } 1630 }
1752 1631
1753 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT); 1632 fCurrentCmdBuffer->beginRenderPass(this, renderPass, *vkRT);
1754 1633
1755 for (int i = 0; i < meshCount; ++i) { 1634 for (int i = 0; i < meshCount; ++i) {
1756 const GrMesh& mesh = meshes[i]; 1635 const GrMesh& mesh = meshes[i];
1757 GrMesh::Iterator iter; 1636 GrMesh::Iterator iter;
1758 const GrNonInstancedMesh* nonIdxMesh = iter.init(mesh); 1637 const GrNonInstancedMesh* nonIdxMesh = iter.init(mesh);
1759 do { 1638 do {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 aglSwapBuffers(aglGetCurrentContext()); 1686 aglSwapBuffers(aglGetCurrentContext());
1808 int set_a_break_pt_here = 9; 1687 int set_a_break_pt_here = 9;
1809 aglSwapBuffers(aglGetCurrentContext()); 1688 aglSwapBuffers(aglGetCurrentContext());
1810 #elif defined(SK_BUILD_FOR_WIN32) 1689 #elif defined(SK_BUILD_FOR_WIN32)
1811 SwapBuf(); 1690 SwapBuf();
1812 int set_a_break_pt_here = 9; 1691 int set_a_break_pt_here = 9;
1813 SwapBuf(); 1692 SwapBuf();
1814 #endif 1693 #endif
1815 #endif 1694 #endif
1816 } 1695 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/vk/GrVkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698