| 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 "GrVkMemory.h" | 8 #include "GrVkMemory.h" |
| 9 | 9 |
| 10 #include "GrVkGpu.h" | 10 #include "GrVkGpu.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 if (err) { | 55 if (err) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool GrVkMemory::AllocAndBindBufferMemory(const GrVkGpu* gpu, | 61 bool GrVkMemory::AllocAndBindBufferMemory(const GrVkGpu* gpu, |
| 62 VkBuffer buffer, | 62 VkBuffer buffer, |
| 63 const VkMemoryPropertyFlags flags, | 63 const VkMemoryPropertyFlags flags, |
| 64 VkDeviceMemory* memory) { | 64 VkDeviceMemory* memory) { |
| 65 const GrVkInterface* interface = gpu->vkInterface(); | 65 const GrVkInterface* iface = gpu->vkInterface(); |
| 66 VkDevice device = gpu->device(); | 66 VkDevice device = gpu->device(); |
| 67 | 67 |
| 68 VkMemoryRequirements memReqs; | 68 VkMemoryRequirements memReqs; |
| 69 GR_VK_CALL(interface, GetBufferMemoryRequirements(device, buffer, &memReqs))
; | 69 GR_VK_CALL(iface, GetBufferMemoryRequirements(device, buffer, &memReqs)); |
| 70 | 70 |
| 71 | 71 |
| 72 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { | 72 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Bind Memory to queue | 76 // Bind Memory to queue |
| 77 VkResult err = GR_VK_CALL(interface, BindBufferMemory(device, buffer, *memor
y, 0)); | 77 VkResult err = GR_VK_CALL(iface, BindBufferMemory(device, buffer, *memory, 0
)); |
| 78 if (err) { | 78 if (err) { |
| 79 GR_VK_CALL(interface, FreeMemory(device, *memory, nullptr)); | 79 GR_VK_CALL(iface, FreeMemory(device, *memory, nullptr)); |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool GrVkMemory::AllocAndBindImageMemory(const GrVkGpu* gpu, | 85 bool GrVkMemory::AllocAndBindImageMemory(const GrVkGpu* gpu, |
| 86 VkImage image, | 86 VkImage image, |
| 87 const VkMemoryPropertyFlags flags, | 87 const VkMemoryPropertyFlags flags, |
| 88 VkDeviceMemory* memory) { | 88 VkDeviceMemory* memory) { |
| 89 const GrVkInterface* interface = gpu->vkInterface(); | 89 const GrVkInterface* iface = gpu->vkInterface(); |
| 90 VkDevice device = gpu->device(); | 90 VkDevice device = gpu->device(); |
| 91 | 91 |
| 92 VkMemoryRequirements memReqs; | 92 VkMemoryRequirements memReqs; |
| 93 GR_VK_CALL(interface, GetImageMemoryRequirements(device, image, &memReqs)); | 93 GR_VK_CALL(iface, GetImageMemoryRequirements(device, image, &memReqs)); |
| 94 | 94 |
| 95 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { | 95 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Bind Memory to queue | 99 // Bind Memory to queue |
| 100 VkResult err = GR_VK_CALL(interface, BindImageMemory(device, image, *memory,
0)); | 100 VkResult err = GR_VK_CALL(iface, BindImageMemory(device, image, *memory, 0))
; |
| 101 if (err) { | 101 if (err) { |
| 102 GR_VK_CALL(interface, FreeMemory(device, *memory, nullptr)); | 102 GR_VK_CALL(iface, FreeMemory(device, *memory, nullptr)); |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 VkPipelineStageFlags GrVkMemory::LayoutToPipelineStageFlags(const VkImageLayout
layout) { | 108 VkPipelineStageFlags GrVkMemory::LayoutToPipelineStageFlags(const VkImageLayout
layout) { |
| 109 if (VK_IMAGE_LAYOUT_GENERAL == layout) { | 109 if (VK_IMAGE_LAYOUT_GENERAL == layout) { |
| 110 return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; | 110 return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 111 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout || | 111 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout || |
| 112 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { | 112 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } else if (VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { | 148 } else if (VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { |
| 149 flags = VK_ACCESS_TRANSFER_WRITE_BIT; | 149 flags = VK_ACCESS_TRANSFER_WRITE_BIT; |
| 150 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout) { | 150 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout) { |
| 151 flags = VK_ACCESS_TRANSFER_READ_BIT; | 151 flags = VK_ACCESS_TRANSFER_READ_BIT; |
| 152 } else if (VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) { | 152 } else if (VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) { |
| 153 flags = VK_ACCESS_SHADER_READ_BIT; | 153 flags = VK_ACCESS_SHADER_READ_BIT; |
| 154 } | 154 } |
| 155 return flags; | 155 return flags; |
| 156 } | 156 } |
| 157 | 157 |
| OLD | NEW |