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

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

Issue 2018933004: Add offset to memory allocations (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix tests Created 4 years, 6 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
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 "GrVkMemory.h" 8 #include "GrVkMemory.h"
9 9
10 #include "GrVkGpu.h" 10 #include "GrVkGpu.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 memory)); 54 memory));
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 GrVkAlloc* alloc) {
65 const GrVkInterface* iface = 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(iface, GetBufferMemoryRequirements(device, buffer, &memReqs)); 69 GR_VK_CALL(iface, GetBufferMemoryRequirements(device, buffer, &memReqs));
70 70
71 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { 71 if (!alloc_device_memory(gpu, &memReqs, flags, &alloc->fMemory)) {
72 return false; 72 return false;
73 } 73 }
74 // for now, offset is always 0
75 alloc->fOffset = 0;
74 76
75 // Bind Memory to queue 77 // Bind Memory to device
76 VkResult err = GR_VK_CALL(iface, BindBufferMemory(device, buffer, *memory, 0 )); 78 VkResult err = GR_VK_CALL(iface, BindBufferMemory(device, buffer,
79 alloc->fMemory, alloc->fOf fset));
77 if (err) { 80 if (err) {
78 GR_VK_CALL(iface, FreeMemory(device, *memory, nullptr)); 81 GR_VK_CALL(iface, FreeMemory(device, alloc->fMemory, nullptr));
79 return false; 82 return false;
80 } 83 }
81 return true; 84 return true;
82 } 85 }
83 86
87 void GrVkMemory::FreeBufferMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc) {
88 const GrVkInterface* iface = gpu->vkInterface();
89 GR_VK_CALL(iface, FreeMemory(gpu->device(), alloc.fMemory, nullptr));
90 }
91
84 bool GrVkMemory::AllocAndBindImageMemory(const GrVkGpu* gpu, 92 bool GrVkMemory::AllocAndBindImageMemory(const GrVkGpu* gpu,
85 VkImage image, 93 VkImage image,
86 const VkMemoryPropertyFlags flags, 94 const VkMemoryPropertyFlags flags,
87 VkDeviceMemory* memory) { 95 GrVkAlloc* alloc) {
88 const GrVkInterface* iface = gpu->vkInterface(); 96 const GrVkInterface* iface = gpu->vkInterface();
89 VkDevice device = gpu->device(); 97 VkDevice device = gpu->device();
90 98
91 VkMemoryRequirements memReqs; 99 VkMemoryRequirements memReqs;
92 GR_VK_CALL(iface, GetImageMemoryRequirements(device, image, &memReqs)); 100 GR_VK_CALL(iface, GetImageMemoryRequirements(device, image, &memReqs));
93 101
94 if (!alloc_device_memory(gpu, &memReqs, flags, memory)) { 102 if (!alloc_device_memory(gpu, &memReqs, flags, &alloc->fMemory)) {
95 return false; 103 return false;
96 } 104 }
105 // for now, offset is always 0
106 alloc->fOffset = 0;
97 107
98 // Bind Memory to queue 108 // Bind Memory to device
99 VkResult err = GR_VK_CALL(iface, BindImageMemory(device, image, *memory, 0)) ; 109 VkResult err = GR_VK_CALL(iface, BindImageMemory(device, image,
110 alloc->fMemory, alloc->fOffset));
100 if (err) { 111 if (err) {
101 GR_VK_CALL(iface, FreeMemory(device, *memory, nullptr)); 112 GR_VK_CALL(iface, FreeMemory(device, alloc->fMemory, nullptr));
102 return false; 113 return false;
103 } 114 }
104 return true; 115 return true;
105 } 116 }
106 117
118 void GrVkMemory::FreeImageMemory(const GrVkGpu* gpu, const GrVkAlloc& alloc) {
119 const GrVkInterface* iface = gpu->vkInterface();
120 GR_VK_CALL(iface, FreeMemory(gpu->device(), alloc.fMemory, nullptr));
121 }
122
107 VkPipelineStageFlags GrVkMemory::LayoutToPipelineStageFlags(const VkImageLayout layout) { 123 VkPipelineStageFlags GrVkMemory::LayoutToPipelineStageFlags(const VkImageLayout layout) {
108 if (VK_IMAGE_LAYOUT_GENERAL == layout) { 124 if (VK_IMAGE_LAYOUT_GENERAL == layout) {
109 return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 125 return VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
110 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout || 126 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout ||
111 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { 127 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) {
112 return VK_PIPELINE_STAGE_TRANSFER_BIT; 128 return VK_PIPELINE_STAGE_TRANSFER_BIT;
113 } else if (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL == layout || 129 } else if (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL == layout ||
114 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL == layout || 130 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL == layout ||
115 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL == layout || 131 VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL == layout ||
116 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) { 132 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) {
(...skipping 29 matching lines...) Expand all
146 flags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; 162 flags = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
147 } else if (VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) { 163 } else if (VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == layout) {
148 flags = VK_ACCESS_TRANSFER_WRITE_BIT; 164 flags = VK_ACCESS_TRANSFER_WRITE_BIT;
149 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout) { 165 } else if (VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == layout) {
150 flags = VK_ACCESS_TRANSFER_READ_BIT; 166 flags = VK_ACCESS_TRANSFER_READ_BIT;
151 } else if (VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) { 167 } else if (VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == layout) {
152 flags = VK_ACCESS_SHADER_READ_BIT; 168 flags = VK_ACCESS_SHADER_READ_BIT;
153 } 169 }
154 return flags; 170 return flags;
155 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698