| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 backendCtx->fGraphicsQueueIndex, // queueFamilyIndex | 125 backendCtx->fGraphicsQueueIndex, // queueFamilyIndex |
| 126 }; | 126 }; |
| 127 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPool
Info, nullptr, | 127 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPool
Info, nullptr, |
| 128 &fCmdPool)); | 128 &fCmdPool)); |
| 129 | 129 |
| 130 // must call this after creating the CommandPool | 130 // must call this after creating the CommandPool |
| 131 fResourceProvider.init(); | 131 fResourceProvider.init(); |
| 132 fCurrentCmdBuffer = fResourceProvider.createPrimaryCommandBuffer(); | 132 fCurrentCmdBuffer = fResourceProvider.createPrimaryCommandBuffer(); |
| 133 SkASSERT(fCurrentCmdBuffer); | 133 SkASSERT(fCurrentCmdBuffer); |
| 134 fCurrentCmdBuffer->begin(this); | 134 fCurrentCmdBuffer->begin(this); |
| 135 |
| 136 // set up our heaps |
| 137 fHeaps[kLinearImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Strat
egy, 16*1024*1024)); |
| 138 fHeaps[kOptimalImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Stra
tegy, 64*1024*1024)); |
| 139 fHeaps[kSmallOptimalImage_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc
_Strategy, 2*1024*1024)); |
| 140 fHeaps[kVertexBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc_S
trategy, 0)); |
| 141 fHeaps[kIndexBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc_St
rategy, 0)); |
| 142 fHeaps[kUniformBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_Str
ategy, 64*1024)); |
| 143 fHeaps[kCopyReadBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSingleAlloc
_Strategy, 0)); |
| 144 fHeaps[kCopyWriteBuffer_Heap].reset(new GrVkHeap(this, GrVkHeap::kSubAlloc_S
trategy, 16*1024*1024)); |
| 135 } | 145 } |
| 136 | 146 |
| 137 GrVkGpu::~GrVkGpu() { | 147 GrVkGpu::~GrVkGpu() { |
| 138 fCurrentCmdBuffer->end(this); | 148 fCurrentCmdBuffer->end(this); |
| 139 fCurrentCmdBuffer->unref(this); | 149 fCurrentCmdBuffer->unref(this); |
| 140 | 150 |
| 141 // wait for all commands to finish | 151 // wait for all commands to finish |
| 142 fResourceProvider.checkCommandBuffers(); | 152 fResourceProvider.checkCommandBuffers(); |
| 143 SkDEBUGCODE(VkResult res = ) VK_CALL(QueueWaitIdle(fQueue)); | 153 SkDEBUGCODE(VkResult res = ) VK_CALL(QueueWaitIdle(fQueue)); |
| 144 // VK_ERROR_DEVICE_LOST is acceptable when tearing down (see 4.2.4 in spec) | 154 // VK_ERROR_DEVICE_LOST is acceptable when tearing down (see 4.2.4 in spec) |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 | 883 |
| 874 // Currently this is not supported since it requires a copy which has not ye
t been implemented. | 884 // Currently this is not supported since it requires a copy which has not ye
t been implemented. |
| 875 if (srcData && !linearTiling) { | 885 if (srcData && !linearTiling) { |
| 876 return 0; | 886 return 0; |
| 877 } | 887 } |
| 878 | 888 |
| 879 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; | 889 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; |
| 880 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; | 890 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
| 881 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; | 891 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 882 | 892 |
| 883 VkFlags memProps = (srcData && linearTiling) ? VK_MEMORY_PROPERTY_HOST_VISIB
LE_BIT : | |
| 884 VK_MEMORY_PROPERTY_DEVICE_LOC
AL_BIT; | |
| 885 | |
| 886 VkImage image = VK_NULL_HANDLE; | 893 VkImage image = VK_NULL_HANDLE; |
| 887 GrVkAlloc alloc = { VK_NULL_HANDLE, 0 }; | 894 GrVkAlloc alloc = { VK_NULL_HANDLE, 0, 0 }; |
| 888 | 895 |
| 889 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE
_TILING_OPTIMAL; | 896 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE
_TILING_OPTIMAL; |
| 890 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) | 897 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) |
| 891 ? VK_IMAGE_LAYOUT_PREINITIALIZED | 898 ? VK_IMAGE_LAYOUT_PREINITIALIZED |
| 892 : VK_IMAGE_LAYOUT_UNDEFINED; | 899 : VK_IMAGE_LAYOUT_UNDEFINED; |
| 893 | 900 |
| 894 // Create Image | 901 // Create Image |
| 895 VkSampleCountFlagBits vkSamples; | 902 VkSampleCountFlagBits vkSamples; |
| 896 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { | 903 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { |
| 897 return 0; | 904 return 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 910 imageTiling, // VkImageTiling | 917 imageTiling, // VkImageTiling |
| 911 usageFlags, // VkImageUsageFlags | 918 usageFlags, // VkImageUsageFlags |
| 912 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode | 919 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
| 913 0, // queueFamilyCount | 920 0, // queueFamilyCount |
| 914 0, // pQueueFamilyIndices | 921 0, // pQueueFamilyIndices |
| 915 initialLayout // initialLayout | 922 initialLayout // initialLayout |
| 916 }; | 923 }; |
| 917 | 924 |
| 918 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageC
reateInfo, nullptr, &image)); | 925 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageC
reateInfo, nullptr, &image)); |
| 919 | 926 |
| 920 if (!GrVkMemory::AllocAndBindImageMemory(this, image, memProps, &alloc)) { | 927 if (!GrVkMemory::AllocAndBindImageMemory(this, image, linearTiling, &alloc))
{ |
| 921 VK_CALL(DestroyImage(this->device(), image, nullptr)); | 928 VK_CALL(DestroyImage(this->device(), image, nullptr)); |
| 922 return 0; | 929 return 0; |
| 923 } | 930 } |
| 924 | 931 |
| 925 if (srcData) { | 932 if (srcData) { |
| 926 if (linearTiling) { | 933 if (linearTiling) { |
| 927 const VkImageSubresource subres = { | 934 const VkImageSubresource subres = { |
| 928 VK_IMAGE_ASPECT_COLOR_BIT, | 935 VK_IMAGE_ASPECT_COLOR_BIT, |
| 929 0, // mipLevel | 936 0, // mipLevel |
| 930 0, // arraySlice | 937 0, // arraySlice |
| 931 }; | 938 }; |
| 932 VkSubresourceLayout layout; | 939 VkSubresourceLayout layout; |
| 933 VkResult err; | 940 VkResult err; |
| 934 | 941 |
| 935 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout))
; | 942 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout))
; |
| 936 | 943 |
| 937 void* mapPtr; | 944 void* mapPtr; |
| 938 err = VK_CALL(MapMemory(fDevice, alloc.fMemory, alloc.fOffset, layou
t.rowPitch * h, | 945 err = VK_CALL(MapMemory(fDevice, alloc.fMemory, alloc.fOffset, layou
t.rowPitch * h, |
| 939 0, &mapPtr)); | 946 0, &mapPtr)); |
| 940 if (err) { | 947 if (err) { |
| 941 GrVkMemory::FreeImageMemory(this, alloc); | 948 GrVkMemory::FreeImageMemory(this, linearTiling, alloc); |
| 942 VK_CALL(DestroyImage(this->device(), image, nullptr)); | 949 VK_CALL(DestroyImage(this->device(), image, nullptr)); |
| 943 return 0; | 950 return 0; |
| 944 } | 951 } |
| 945 | 952 |
| 946 size_t bpp = GrBytesPerPixel(config); | 953 size_t bpp = GrBytesPerPixel(config); |
| 947 size_t rowCopyBytes = bpp * w; | 954 size_t rowCopyBytes = bpp * w; |
| 948 // If there is no padding on dst (layout.rowPitch) we can do a singl
e memcopy. | 955 // If there is no padding on dst (layout.rowPitch) we can do a singl
e memcopy. |
| 949 // This assumes the srcData comes in with no padding. | 956 // This assumes the srcData comes in with no padding. |
| 950 if (rowCopyBytes == layout.rowPitch) { | 957 if (rowCopyBytes == layout.rowPitch) { |
| 951 memcpy(mapPtr, srcData, rowCopyBytes * h); | 958 memcpy(mapPtr, srcData, rowCopyBytes * h); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 982 &req)); | 989 &req)); |
| 983 // TODO: find a better check | 990 // TODO: find a better check |
| 984 // This will probably fail with a different driver | 991 // This will probably fail with a different driver |
| 985 return (req.size > 0) && (req.size <= 8192 * 8192); | 992 return (req.size > 0) && (req.size <= 8192 * 8192); |
| 986 } | 993 } |
| 987 | 994 |
| 988 return false; | 995 return false; |
| 989 } | 996 } |
| 990 | 997 |
| 991 void GrVkGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandon)
{ | 998 void GrVkGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandon)
{ |
| 992 const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); | 999 GrVkImageInfo* backend = reinterpret_cast<GrVkImageInfo*>(id); |
| 993 | |
| 994 if (backend) { | 1000 if (backend) { |
| 995 if (!abandon) { | 1001 if (!abandon) { |
| 996 // something in the command buffer may still be using this, so force
submit | 1002 // something in the command buffer may still be using this, so force
submit |
| 997 this->submitCommandBuffer(kForce_SyncQueue); | 1003 this->submitCommandBuffer(kForce_SyncQueue); |
| 998 | 1004 GrVkImage::DestroyImageInfo(this, backend); |
| 999 GrVkMemory::FreeImageMemory(this, backend->fAlloc); | |
| 1000 VK_CALL(DestroyImage(this->device(), backend->fImage, nullptr)); | |
| 1001 } | 1005 } |
| 1002 delete backend; | 1006 delete backend; |
| 1003 } | 1007 } |
| 1004 } | 1008 } |
| 1005 | 1009 |
| 1006 //////////////////////////////////////////////////////////////////////////////// | 1010 //////////////////////////////////////////////////////////////////////////////// |
| 1007 | 1011 |
| 1008 void GrVkGpu::addMemoryBarrier(VkPipelineStageFlags srcStageMask, | 1012 void GrVkGpu::addMemoryBarrier(VkPipelineStageFlags srcStageMask, |
| 1009 VkPipelineStageFlags dstStageMask, | 1013 VkPipelineStageFlags dstStageMask, |
| 1010 bool byRegion, | 1014 bool byRegion, |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 aglSwapBuffers(aglGetCurrentContext()); | 1706 aglSwapBuffers(aglGetCurrentContext()); |
| 1703 int set_a_break_pt_here = 9; | 1707 int set_a_break_pt_here = 9; |
| 1704 aglSwapBuffers(aglGetCurrentContext()); | 1708 aglSwapBuffers(aglGetCurrentContext()); |
| 1705 #elif defined(SK_BUILD_FOR_WIN32) | 1709 #elif defined(SK_BUILD_FOR_WIN32) |
| 1706 SwapBuf(); | 1710 SwapBuf(); |
| 1707 int set_a_break_pt_here = 9; | 1711 int set_a_break_pt_here = 9; |
| 1708 SwapBuf(); | 1712 SwapBuf(); |
| 1709 #endif | 1713 #endif |
| 1710 #endif | 1714 #endif |
| 1711 } | 1715 } |
| OLD | NEW |