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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 VkResult err; | 324 VkResult err; |
325 | 325 |
326 const GrVkInterface* interface = this->vkInterface(); | 326 const GrVkInterface* interface = this->vkInterface(); |
327 | 327 |
328 GR_VK_CALL(interface, GetImageSubresourceLayout(fDevice, | 328 GR_VK_CALL(interface, GetImageSubresourceLayout(fDevice, |
329 tex->image(), | 329 tex->image(), |
330 &subres, | 330 &subres, |
331 &layout)); | 331 &layout)); |
332 | 332 |
333 int texTop = kBottomLeft_GrSurfaceOrigin == desc.fOrigin ? tex->height() - t op - height : top; | 333 int texTop = kBottomLeft_GrSurfaceOrigin == desc.fOrigin ? tex->height() - t op - height : top; |
334 VkDeviceSize offset = texTop*layout.rowPitch + left*bpp; | 334 VkDeviceSize offset = tex->offset() + texTop*layout.rowPitch + left*bpp; |
egdaniel
2016/05/31 13:22:14
is the offset actually needed here? If the image i
jvanverth1
2016/05/31 22:05:57
There's no reference to the image in MapMemory, so
| |
335 VkDeviceSize size = height*layout.rowPitch; | 335 VkDeviceSize size = height*layout.rowPitch; |
336 void* mapPtr; | 336 void* mapPtr; |
337 err = GR_VK_CALL(interface, MapMemory(fDevice, tex->memory(), offset, size, 0, &mapPtr)); | 337 err = GR_VK_CALL(interface, MapMemory(fDevice, tex->memory(), offset, size, 0, &mapPtr)); |
338 if (err) { | 338 if (err) { |
339 return false; | 339 return false; |
340 } | 340 } |
341 | 341 |
342 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { | 342 if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
343 // copy into buffer by rows | 343 // copy into buffer by rows |
344 const char* srcRow = reinterpret_cast<const char*>(data); | 344 const char* srcRow = reinterpret_cast<const char*>(data); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 | 867 |
868 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; | 868 VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT; |
869 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; | 869 usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; |
870 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; | 870 usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
871 | 871 |
872 VkFlags memProps = (srcData && linearTiling) ? VK_MEMORY_PROPERTY_HOST_VISIB LE_BIT : | 872 VkFlags memProps = (srcData && linearTiling) ? VK_MEMORY_PROPERTY_HOST_VISIB LE_BIT : |
873 VK_MEMORY_PROPERTY_DEVICE_LOC AL_BIT; | 873 VK_MEMORY_PROPERTY_DEVICE_LOC AL_BIT; |
874 | 874 |
875 VkImage image = VK_NULL_HANDLE; | 875 VkImage image = VK_NULL_HANDLE; |
876 VkDeviceMemory alloc = VK_NULL_HANDLE; | 876 VkDeviceMemory alloc = VK_NULL_HANDLE; |
877 VkDeviceSize offset = 0; | |
877 | 878 |
878 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL; | 879 VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE _TILING_OPTIMAL; |
879 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) | 880 VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling) |
880 ? VK_IMAGE_LAYOUT_PREINITIALIZED | 881 ? VK_IMAGE_LAYOUT_PREINITIALIZED |
881 : VK_IMAGE_LAYOUT_UNDEFINED; | 882 : VK_IMAGE_LAYOUT_UNDEFINED; |
882 | 883 |
883 // Create Image | 884 // Create Image |
884 VkSampleCountFlagBits vkSamples; | 885 VkSampleCountFlagBits vkSamples; |
885 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { | 886 if (!GrSampleCountToVkSampleCount(1, &vkSamples)) { |
886 return 0; | 887 return 0; |
(...skipping 12 matching lines...) Expand all Loading... | |
899 imageTiling, // VkImageTiling | 900 imageTiling, // VkImageTiling |
900 usageFlags, // VkImageUsageFlags | 901 usageFlags, // VkImageUsageFlags |
901 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode | 902 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode |
902 0, // queueFamilyCount | 903 0, // queueFamilyCount |
903 0, // pQueueFamilyIndices | 904 0, // pQueueFamilyIndices |
904 initialLayout // initialLayout | 905 initialLayout // initialLayout |
905 }; | 906 }; |
906 | 907 |
907 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageC reateInfo, nullptr, &image)); | 908 GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageC reateInfo, nullptr, &image)); |
908 | 909 |
909 if (!GrVkMemory::AllocAndBindImageMemory(this, image, memProps, &alloc)) { | 910 if (!GrVkMemory::AllocAndBindImageMemory(this, image, memProps, &alloc, &off set)) { |
910 VK_CALL(DestroyImage(this->device(), image, nullptr)); | 911 VK_CALL(DestroyImage(this->device(), image, nullptr)); |
911 return 0; | 912 return 0; |
912 } | 913 } |
913 | 914 |
914 if (srcData) { | 915 if (srcData) { |
915 if (linearTiling) { | 916 if (linearTiling) { |
916 const VkImageSubresource subres = { | 917 const VkImageSubresource subres = { |
917 VK_IMAGE_ASPECT_COLOR_BIT, | 918 VK_IMAGE_ASPECT_COLOR_BIT, |
918 0, // mipLevel | 919 0, // mipLevel |
919 0, // arraySlice | 920 0, // arraySlice |
920 }; | 921 }; |
921 VkSubresourceLayout layout; | 922 VkSubresourceLayout layout; |
922 VkResult err; | 923 VkResult err; |
923 | 924 |
924 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ; | 925 VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout)) ; |
925 | 926 |
926 void* mapPtr; | 927 void* mapPtr; |
927 err = VK_CALL(MapMemory(fDevice, alloc, 0, layout.rowPitch * h, 0, & mapPtr)); | 928 err = VK_CALL(MapMemory(fDevice, alloc, 0, layout.rowPitch * h, 0, & mapPtr)); |
928 if (err) { | 929 if (err) { |
929 VK_CALL(FreeMemory(this->device(), alloc, nullptr)); | 930 GrVkMemory::FreeImageMemory(this, alloc, offset); |
930 VK_CALL(DestroyImage(this->device(), image, nullptr)); | 931 VK_CALL(DestroyImage(this->device(), image, nullptr)); |
931 return 0; | 932 return 0; |
932 } | 933 } |
933 | 934 |
934 size_t bpp = GrBytesPerPixel(config); | 935 size_t bpp = GrBytesPerPixel(config); |
935 size_t rowCopyBytes = bpp * w; | 936 size_t rowCopyBytes = bpp * w; |
936 // If there is no padding on dst (layout.rowPitch) we can do a singl e memcopy. | 937 // If there is no padding on dst (layout.rowPitch) we can do a singl e memcopy. |
937 // This assumes the srcData comes in with no padding. | 938 // This assumes the srcData comes in with no padding. |
938 if (rowCopyBytes == layout.rowPitch) { | 939 if (rowCopyBytes == layout.rowPitch) { |
939 memcpy(mapPtr, srcData, rowCopyBytes * h); | 940 memcpy(mapPtr, srcData, rowCopyBytes * h); |
940 } else { | 941 } else { |
941 SkRectMemcpy(mapPtr, static_cast<size_t>(layout.rowPitch), srcDa ta, rowCopyBytes, | 942 SkRectMemcpy(mapPtr, static_cast<size_t>(layout.rowPitch), srcDa ta, rowCopyBytes, |
942 rowCopyBytes, h); | 943 rowCopyBytes, h); |
943 } | 944 } |
944 VK_CALL(UnmapMemory(fDevice, alloc)); | 945 VK_CALL(UnmapMemory(fDevice, alloc)); |
945 } else { | 946 } else { |
946 // TODO: Add support for copying to optimal tiling | 947 // TODO: Add support for copying to optimal tiling |
947 SkASSERT(false); | 948 SkASSERT(false); |
948 } | 949 } |
949 } | 950 } |
950 | 951 |
951 GrVkImageInfo* info = new GrVkImageInfo; | 952 GrVkImageInfo* info = new GrVkImageInfo; |
952 info->fImage = image; | 953 info->fImage = image; |
953 info->fAlloc = alloc; | 954 info->fAlloc = alloc; |
955 info->fOffset = offset; | |
954 info->fImageTiling = imageTiling; | 956 info->fImageTiling = imageTiling; |
955 info->fImageLayout = initialLayout; | 957 info->fImageLayout = initialLayout; |
956 info->fFormat = pixelFormat; | 958 info->fFormat = pixelFormat; |
957 info->fLevelCount = 1; | 959 info->fLevelCount = 1; |
958 | 960 |
959 return (GrBackendObject)info; | 961 return (GrBackendObject)info; |
960 } | 962 } |
961 | 963 |
962 bool GrVkGpu::isTestingOnlyBackendTexture(GrBackendObject id) const { | 964 bool GrVkGpu::isTestingOnlyBackendTexture(GrBackendObject id) const { |
963 const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); | 965 const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); |
(...skipping 13 matching lines...) Expand all Loading... | |
977 } | 979 } |
978 | 980 |
979 void GrVkGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandon) { | 981 void GrVkGpu::deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandon) { |
980 const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); | 982 const GrVkImageInfo* backend = reinterpret_cast<const GrVkImageInfo*>(id); |
981 | 983 |
982 if (backend) { | 984 if (backend) { |
983 if (!abandon) { | 985 if (!abandon) { |
984 // something in the command buffer may still be using this, so force submit | 986 // something in the command buffer may still be using this, so force submit |
985 this->submitCommandBuffer(kForce_SyncQueue); | 987 this->submitCommandBuffer(kForce_SyncQueue); |
986 | 988 |
987 VK_CALL(FreeMemory(this->device(), backend->fAlloc, nullptr)); | 989 GrVkMemory::FreeImageMemory(this, backend->fAlloc, backend->fOffset) ; |
988 VK_CALL(DestroyImage(this->device(), backend->fImage, nullptr)); | 990 VK_CALL(DestroyImage(this->device(), backend->fImage, nullptr)); |
989 } | 991 } |
990 delete backend; | 992 delete backend; |
991 } | 993 } |
992 } | 994 } |
993 | 995 |
994 //////////////////////////////////////////////////////////////////////////////// | 996 //////////////////////////////////////////////////////////////////////////////// |
995 | 997 |
996 void GrVkGpu::addMemoryBarrier(VkPipelineStageFlags srcStageMask, | 998 void GrVkGpu::addMemoryBarrier(VkPipelineStageFlags srcStageMask, |
997 VkPipelineStageFlags dstStageMask, | 999 VkPipelineStageFlags dstStageMask, |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1685 aglSwapBuffers(aglGetCurrentContext()); | 1687 aglSwapBuffers(aglGetCurrentContext()); |
1686 int set_a_break_pt_here = 9; | 1688 int set_a_break_pt_here = 9; |
1687 aglSwapBuffers(aglGetCurrentContext()); | 1689 aglSwapBuffers(aglGetCurrentContext()); |
1688 #elif defined(SK_BUILD_FOR_WIN32) | 1690 #elif defined(SK_BUILD_FOR_WIN32) |
1689 SwapBuf(); | 1691 SwapBuf(); |
1690 int set_a_break_pt_here = 9; | 1692 int set_a_break_pt_here = 9; |
1691 SwapBuf(); | 1693 SwapBuf(); |
1692 #endif | 1694 #endif |
1693 #endif | 1695 #endif |
1694 } | 1696 } |
OLD | NEW |