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

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

Issue 1899213002: Revise WSI setup. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Updated for comments Created 4 years, 8 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 | « include/gpu/vk/GrVkInterface.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('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 "vk/GrVkBackendContext.h" 8 #include "vk/GrVkBackendContext.h"
9 #include "vk/GrVkExtensions.h" 9 #include "vk/GrVkExtensions.h"
10 #include "vk/GrVkInterface.h" 10 #include "vk/GrVkInterface.h"
(...skipping 17 matching lines...) Expand all
28 //"VK_LAYER_LUNARG_api_dump", 28 //"VK_LAYER_LUNARG_api_dump",
29 //"VK_LAYER_LUNARG_vktrace", 29 //"VK_LAYER_LUNARG_vktrace",
30 //"VK_LAYER_LUNARG_screenshot", 30 //"VK_LAYER_LUNARG_screenshot",
31 }; 31 };
32 #endif 32 #endif
33 33
34 // the minimum version of Vulkan supported 34 // the minimum version of Vulkan supported
35 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8); 35 const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8);
36 36
37 // Create the base Vulkan objects needed by the GrVkGpu object 37 // Create the base Vulkan objects needed by the GrVkGpu object
38 const GrVkBackendContext* GrVkBackendContext::Create() { 38 const GrVkBackendContext* GrVkBackendContext::Create(uint32_t* presentQueueIndex Ptr,
39 bool(*canPresent)(VkInstance, VkPhysicalDevice, uin t32_t queueIndex)) {
39 VkPhysicalDevice physDev; 40 VkPhysicalDevice physDev;
40 VkDevice device; 41 VkDevice device;
41 VkInstance inst; 42 VkInstance inst;
42 VkResult err; 43 VkResult err;
43 44
44 const VkApplicationInfo app_info = { 45 const VkApplicationInfo app_info = {
45 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType 46 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
46 nullptr, // pNext 47 nullptr, // pNext
47 "vktest", // pApplicationName 48 "vktest", // pApplicationName
48 0, // applicationVersion 49 0, // applicationVersion
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr); 135 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
135 SkASSERT(queueCount >= 1); 136 SkASSERT(queueCount >= 1);
136 137
137 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); 138 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties));
138 // now get the actual queue props 139 // now get the actual queue props
139 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl loc.get(); 140 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl loc.get();
140 141
141 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps); 142 vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueProps);
142 143
143 // iterate to find the graphics queue 144 // iterate to find the graphics queue
144 uint32_t graphicsQueueIndex = -1; 145 uint32_t graphicsQueueIndex = queueCount;
145 for (uint32_t i = 0; i < queueCount; i++) { 146 for (uint32_t i = 0; i < queueCount; i++) {
146 if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { 147 if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
147 graphicsQueueIndex = i; 148 graphicsQueueIndex = i;
148 break; 149 break;
149 } 150 }
150 } 151 }
151 SkASSERT(graphicsQueueIndex < queueCount); 152 SkASSERT(graphicsQueueIndex < queueCount);
152 153
154 // iterate to find the present queue, if needed
155 uint32_t presentQueueIndex = graphicsQueueIndex;
156 if (presentQueueIndexPtr && canPresent) {
157 for (uint32_t i = 0; i < queueCount; i++) {
158 if (canPresent(inst, physDev, i)) {
159 presentQueueIndex = i;
160 break;
161 }
162 }
163 SkASSERT(presentQueueIndex < queueCount);
164 *presentQueueIndexPtr = presentQueueIndex;
165 }
166
153 extensions.initDevice(kGrVkMinimumVersion, inst, physDev); 167 extensions.initDevice(kGrVkMinimumVersion, inst, physDev);
154 168
155 SkTArray<const char*> deviceLayerNames; 169 SkTArray<const char*> deviceLayerNames;
156 SkTArray<const char*> deviceExtensionNames; 170 SkTArray<const char*> deviceExtensionNames;
157 #ifdef ENABLE_VK_LAYERS 171 #ifdef ENABLE_VK_LAYERS
158 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) { 172 for (size_t i = 0; i < SK_ARRAY_COUNT(kDebugLayerNames); ++i) {
159 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) { 173 if (extensions.hasDeviceLayer(kDebugLayerNames[i])) {
160 deviceLayerNames.push_back(kDebugLayerNames[i]); 174 deviceLayerNames.push_back(kDebugLayerNames[i]);
161 } 175 }
162 } 176 }
(...skipping 21 matching lines...) Expand all
184 if (deviceFeatures.dualSrcBlend) { 198 if (deviceFeatures.dualSrcBlend) {
185 featureFlags |= kDualSrcBlend_GrVkFeatureFlag; 199 featureFlags |= kDualSrcBlend_GrVkFeatureFlag;
186 } 200 }
187 if (deviceFeatures.sampleRateShading) { 201 if (deviceFeatures.sampleRateShading) {
188 featureFlags |= kSampleRateShading_GrVkFeatureFlag; 202 featureFlags |= kSampleRateShading_GrVkFeatureFlag;
189 } 203 }
190 204
191 float queuePriorities[1] = { 0.0 }; 205 float queuePriorities[1] = { 0.0 };
192 // Here we assume no need for swapchain queue 206 // Here we assume no need for swapchain queue
193 // If one is needed, the client will need its own setup code 207 // If one is needed, the client will need its own setup code
194 const VkDeviceQueueCreateInfo queueInfo = { 208 const VkDeviceQueueCreateInfo queueInfo[2] = {
195 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType 209 {
196 nullptr, // pNext 210 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
197 0, // VkDeviceQueueCreateFlags 211 nullptr, // pNext
198 graphicsQueueIndex, // queueFamilyIndex 212 0, // VkDeviceQueueCreateFl ags
199 1, // queueCount 213 graphicsQueueIndex, // queueFamilyIndex
200 queuePriorities, // pQueuePriorities 214 1, // queueCount
215 queuePriorities, // pQueuePriorities
216 },
217 {
218 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
219 nullptr, // pNext
220 0, // VkDeviceQueueCreateFl ags
221 presentQueueIndex, // queueFamilyIndex
222 1, // queueCount
223 queuePriorities, // pQueuePriorities
224 }
201 }; 225 };
226 uint32_t queueInfoCount = (presentQueueIndex != graphicsQueueIndex) ? 2 : 1;
227
202 const VkDeviceCreateInfo deviceInfo = { 228 const VkDeviceCreateInfo deviceInfo = {
203 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType 229 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
204 nullptr, // pNext 230 nullptr, // pNext
205 0, // VkDeviceCreateFlags 231 0, // VkDeviceCreateFlags
206 1, // queueCreateInfoCount 232 queueInfoCount, // queueCreateInfoCount
207 &queueInfo, // pQueueCreateInfos 233 queueInfo, // pQueueCreateInfos
208 (uint32_t) deviceLayerNames.count(), // layerCount 234 (uint32_t) deviceLayerNames.count(), // layerCount
209 deviceLayerNames.begin(), // ppEnabledLayerNames 235 deviceLayerNames.begin(), // ppEnabledLayerNames
210 (uint32_t) deviceExtensionNames.count(), // extensionCount 236 (uint32_t) deviceExtensionNames.count(), // extensionCount
211 deviceExtensionNames.begin(), // ppEnabledExtensionNames 237 deviceExtensionNames.begin(), // ppEnabledExtensionNames
212 &deviceFeatures // ppEnabledFeatures 238 &deviceFeatures // ppEnabledFeatures
213 }; 239 };
214 240
215 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device); 241 err = vkCreateDevice(physDev, &deviceInfo, nullptr, &device);
216 if (err) { 242 if (err) {
217 SkDebugf("CreateDevice failed: %d\n", err); 243 SkDebugf("CreateDevice failed: %d\n", err);
218 vkDestroyInstance(inst, nullptr); 244 vkDestroyInstance(inst, nullptr);
219 return nullptr; 245 return nullptr;
220 } 246 }
221 247
222 VkQueue queue; 248 VkQueue queue;
223 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue); 249 vkGetDeviceQueue(device, graphicsQueueIndex, 0, &queue);
224 250
225 GrVkBackendContext* ctx = new GrVkBackendContext(); 251 GrVkBackendContext* ctx = new GrVkBackendContext();
226 ctx->fInstance = inst; 252 ctx->fInstance = inst;
227 ctx->fPhysicalDevice = physDev; 253 ctx->fPhysicalDevice = physDev;
228 ctx->fDevice = device; 254 ctx->fDevice = device;
229 ctx->fQueue = queue; 255 ctx->fQueue = queue;
230 ctx->fQueueFamilyIndex = graphicsQueueIndex; 256 ctx->fGraphicsQueueIndex = graphicsQueueIndex;
231 ctx->fMinAPIVersion = kGrVkMinimumVersion; 257 ctx->fMinAPIVersion = kGrVkMinimumVersion;
232 ctx->fExtensions = extensionFlags; 258 ctx->fExtensions = extensionFlags;
233 ctx->fFeatures = featureFlags; 259 ctx->fFeatures = featureFlags;
234 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags)); 260 ctx->fInterface.reset(GrVkCreateInterface(inst, device, extensionFlags));
235 261
236 return ctx; 262 return ctx;
237 } 263 }
238 264
239 GrVkBackendContext::~GrVkBackendContext() { 265 GrVkBackendContext::~GrVkBackendContext() {
240 vkDeviceWaitIdle(fDevice); 266 vkDeviceWaitIdle(fDevice);
241 vkDestroyDevice(fDevice, nullptr); 267 vkDestroyDevice(fDevice, nullptr);
242 fDevice = VK_NULL_HANDLE; 268 fDevice = VK_NULL_HANDLE;
243 vkDestroyInstance(fInstance, nullptr); 269 vkDestroyInstance(fInstance, nullptr);
244 fInstance = VK_NULL_HANDLE; 270 fInstance = VK_NULL_HANDLE;
245 } 271 }
OLDNEW
« no previous file with comments | « include/gpu/vk/GrVkInterface.h ('k') | src/gpu/vk/GrVkGpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698