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

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

Issue 1945823002: Set barriers and image layout changes between mipmap blits. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 dstAccessMask, 279 dstAccessMask,
280 srcStageMask, 280 srcStageMask,
281 dstStageMask, 281 dstStageMask,
282 false); 282 false);
283 this->submitCommandBuffer(kForce_SyncQueue); 283 this->submitCommandBuffer(kForce_SyncQueue);
284 } 284 }
285 success = this->uploadTexDataLinear(vkTex, left, top, width, height, config, 285 success = this->uploadTexDataLinear(vkTex, left, top, width, height, config,
286 texels.begin()->fPixels, texels. begin()->fRowBytes); 286 texels.begin()->fPixels, texels. begin()->fRowBytes);
287 } else { 287 } else {
288 int newMipLevels = texels.count(); 288 int newMipLevels = texels.count();
289 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel(); 289 int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1;
290 if ((currentMipLevels || newMipLevels != 1) && newMipLevels != curre ntMipLevels) { 290 if (newMipLevels != currentMipLevels) {
291 if (!vkTex->reallocForMipmap(this, newMipLevels)) { 291 if (!vkTex->reallocForMipmap(this, newMipLevels)) {
292 return false; 292 return false;
293 } 293 }
294 } 294 }
295 success = this->uploadTexDataOptimal(vkTex, left, top, width, height , config, texels); 295 success = this->uploadTexDataOptimal(vkTex, left, top, width, height , config, texels);
296 } 296 }
297 } 297 }
298 298
299 return success; 299 return success;
300 } 300 }
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origSrcLayou t); 727 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origSrcLayou t);
728 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; 728 VkAccessFlags dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
729 729
730 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 730 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
731 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false); 731 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false);
732 732
733 // grab handle to the original image resource 733 // grab handle to the original image resource
734 const GrVkImage::Resource* oldResource = tex->resource(); 734 const GrVkImage::Resource* oldResource = tex->resource();
735 oldResource->ref(); 735 oldResource->ref();
736 736
737 uint32_t mipLevels = SkMipMap::ComputeLevelCount(tex->width(), tex->height() ); 737 // SkMipMap doesn't include the base level in the level count so we have to add 1
738 if (!tex->reallocForMipmap(this, mipLevels)) { 738 uint32_t levelCount = SkMipMap::ComputeLevelCount(tex->width(), tex->height( )) + 1;
739 if (!tex->reallocForMipmap(this, levelCount)) {
739 oldResource->unref(this); 740 oldResource->unref(this);
740 return; 741 return;
741 } 742 }
742 743
743 // change the new image's layout 744 // change the new image's layout
744 VkImageLayout origDstLayout = tex->currentLayout(); 745 VkImageLayout origDstLayout = tex->currentLayout();
745 746
746 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origDstLayout); 747 srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(origDstLayout);
747 dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; 748 dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
748 749
749 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayout); 750 srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(origDstLayout);
750 dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; 751 dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
751 752
752 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 753 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
753 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false); 754 srcAccessMask, dstAccessMask, srcStageMask, dstStageMask , false);
754 755
755 // Blit original image 756 // Blit original image
756 int width = tex->width(); 757 int width = tex->width();
757 int height = tex->height(); 758 int height = tex->height();
758 uint32_t mipLevel = 0;
759 759
760 VkImageBlit blitRegion; 760 VkImageBlit blitRegion;
761 memset(&blitRegion, 0, sizeof(VkImageBlit)); 761 memset(&blitRegion, 0, sizeof(VkImageBlit));
762 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 }; 762 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
763 blitRegion.srcOffsets[0] = { 0, 0, 0 }; 763 blitRegion.srcOffsets[0] = { 0, 0, 0 };
764 blitRegion.srcOffsets[1] = { width, height, 0 }; 764 blitRegion.srcOffsets[1] = { width, height, 0 };
765 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 }; 765 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1 };
766 blitRegion.dstOffsets[0] = { 0, 0, 0 }; 766 blitRegion.dstOffsets[0] = { 0, 0, 0 };
767 blitRegion.dstOffsets[1] = { width, height, 0 }; 767 blitRegion.dstOffsets[1] = { width, height, 0 };
768 768
769 fCurrentCmdBuffer->blitImage(this, 769 fCurrentCmdBuffer->blitImage(this,
770 oldResource, 770 oldResource,
771 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 771 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
772 tex->resource(), 772 tex->resource(),
773 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 773 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
774 1, 774 1,
775 &blitRegion, 775 &blitRegion,
776 VK_FILTER_LINEAR); 776 VK_FILTER_LINEAR);
777 // Blit the miplevels 777 // Blit the miplevels
778 while (width/2 > 0 && height/2 > 0) { 778 uint32_t mipLevel = 1;
779 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 }; 779 while (mipLevel < levelCount) {
780 int prevWidth = width;
781 int prevHeight = height;
782 width = SkTMax(1, width / 2);
783 height = SkTMax(1, height / 2);
784
785 blitRegion.srcSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel-1, 0, 1 };
780 blitRegion.srcOffsets[0] = { 0, 0, 0 }; 786 blitRegion.srcOffsets[0] = { 0, 0, 0 };
781 blitRegion.srcOffsets[1] = { width, height, 0 }; 787 blitRegion.srcOffsets[1] = { prevWidth, prevHeight, 0 };
782 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel+1, 0, 1 }; 788 blitRegion.dstSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, mipLevel, 0, 1 };
783 blitRegion.dstOffsets[0] = { 0, 0, 0 }; 789 blitRegion.dstOffsets[0] = { 0, 0, 0 };
784 blitRegion.dstOffsets[1] = { width/2, height/2, 0 }; 790 blitRegion.dstOffsets[1] = { width, height, 0 };
785 791
786 // TODO: insert image barrier to wait on previous blit 792 tex->setImageLayout(this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
787 // TODO: change layout of src subresource to TRANSFER_SRC_OPTIMAL 793 srcAccessMask, dstAccessMask, srcStageMask, dstStage Mask,
794 mipLevel-1, 1, false);
788 795
789 fCurrentCmdBuffer->blitImage(this, 796 fCurrentCmdBuffer->blitImage(this,
790 tex->resource(), 797 tex->resource(),
791 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 798 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
792 tex->resource(), 799 tex->resource(),
793 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 800 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
794 1, 801 1,
795 &blitRegion, 802 &blitRegion,
796 VK_FILTER_LINEAR); 803 VK_FILTER_LINEAR);
797 804 ++mipLevel;
798 width /= 2;
799 height /= 2;
800 mipLevel++;
801 } 805 }
802 806
803 oldResource->unref(this); 807 oldResource->unref(this);
804 } 808 }
805 809
806 810
807
808 //////////////////////////////////////////////////////////////////////////////// 811 ////////////////////////////////////////////////////////////////////////////////
809 812
810 void GrVkGpu::bindGeometry(const GrPrimitiveProcessor& primProc, 813 void GrVkGpu::bindGeometry(const GrPrimitiveProcessor& primProc,
811 const GrNonInstancedMesh& mesh) { 814 const GrNonInstancedMesh& mesh) {
812 // There is no need to put any memory barriers to make sure host writes have finished here. 815 // There is no need to put any memory barriers to make sure host writes have finished here.
813 // When a command buffer is submitted to a queue, there is an implicit memor y barrier that 816 // When a command buffer is submitted to a queue, there is an implicit memor y barrier that
814 // occurs for all host writes. Additionally, BufferMemoryBarriers are not al lowed inside of 817 // occurs for all host writes. Additionally, BufferMemoryBarriers are not al lowed inside of
815 // an active RenderPass. 818 // an active RenderPass.
816 GrVkVertexBuffer* vbuf; 819 GrVkVertexBuffer* vbuf;
817 vbuf = (GrVkVertexBuffer*)mesh.vertexBuffer(); 820 vbuf = (GrVkVertexBuffer*)mesh.vertexBuffer();
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 aglSwapBuffers(aglGetCurrentContext()); 1807 aglSwapBuffers(aglGetCurrentContext());
1805 int set_a_break_pt_here = 9; 1808 int set_a_break_pt_here = 9;
1806 aglSwapBuffers(aglGetCurrentContext()); 1809 aglSwapBuffers(aglGetCurrentContext());
1807 #elif defined(SK_BUILD_FOR_WIN32) 1810 #elif defined(SK_BUILD_FOR_WIN32)
1808 SwapBuf(); 1811 SwapBuf();
1809 int set_a_break_pt_here = 9; 1812 int set_a_break_pt_here = 9;
1810 SwapBuf(); 1813 SwapBuf();
1811 #endif 1814 #endif
1812 #endif 1815 #endif
1813 } 1816 }
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