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

Side by Side Diff: tools/viewer/sk_app/VulkanWindowContext.cpp

Issue 1990893002: Revert of Add OpenGL context to Viewer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 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 | « tools/viewer/sk_app/VulkanWindowContext.h ('k') | tools/viewer/sk_app/Window.h » ('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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrRenderTarget.h"
11 #include "SkSurface.h" 10 #include "SkSurface.h"
12 #include "VulkanWindowContext.h" 11 #include "VulkanWindowContext.h"
13 12
14 #include "vk/GrVkInterface.h" 13 #include "vk/GrVkInterface.h"
15 #include "vk/GrVkUtil.h" 14 #include "vk/GrVkUtil.h"
16 #include "vk/GrVkTypes.h" 15 #include "vk/GrVkTypes.h"
17 16
18 #ifdef VK_USE_PLATFORM_WIN32_KHR 17 #ifdef VK_USE_PLATFORM_WIN32_KHR
19 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW 18 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW
20 #undef CreateSemaphore 19 #undef CreateSemaphore
21 #endif 20 #endif
22 21
23 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F) 22 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F)
24 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F) 23 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F)
25 24
26 namespace sk_app { 25 namespace sk_app {
27 26
28 VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams & params) 27 VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams & params)
29 : WindowContext() 28 : fSurface(VK_NULL_HANDLE)
30 , fSurface(VK_NULL_HANDLE)
31 , fSwapchain(VK_NULL_HANDLE) 29 , fSwapchain(VK_NULL_HANDLE)
32 , fImages(nullptr)
33 , fImageLayouts(nullptr)
34 , fSurfaces(nullptr)
35 , fCommandPool(VK_NULL_HANDLE) 30 , fCommandPool(VK_NULL_HANDLE)
36 , fBackbuffers(nullptr) { 31 , fBackbuffers(nullptr) {
37 32
38 // any config code here (particularly for msaa)? 33 // any config code here (particularly for msaa)?
39 34
40 this->initializeContext(platformData, params); 35 this->initializeContext(platformData, params);
41 } 36 }
42 37
43 void VulkanWindowContext::initializeContext(void* platformData, const DisplayPar ams& params) { 38 void VulkanWindowContext::initializeContext(void* platformData, const DisplayPar ams& params) {
44 39
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void VulkanWindowContext::createBuffers(VkFormat format) { 243 void VulkanWindowContext::createBuffers(VkFormat format) {
249 GrVkFormatToPixelConfig(format, &fPixelConfig); 244 GrVkFormatToPixelConfig(format, &fPixelConfig);
250 245
251 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, n ullptr); 246 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, n ullptr);
252 SkASSERT(fImageCount); 247 SkASSERT(fImageCount);
253 fImages = new VkImage[fImageCount]; 248 fImages = new VkImage[fImageCount];
254 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, f Images); 249 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, f Images);
255 250
256 // set up initial image layouts and create surfaces 251 // set up initial image layouts and create surfaces
257 fImageLayouts = new VkImageLayout[fImageCount]; 252 fImageLayouts = new VkImageLayout[fImageCount];
258 fRenderTargets = new sk_sp<GrRenderTarget>[fImageCount];
259 fSurfaces = new sk_sp<SkSurface>[fImageCount]; 253 fSurfaces = new sk_sp<SkSurface>[fImageCount];
260 for (uint32_t i = 0; i < fImageCount; ++i) { 254 for (uint32_t i = 0; i < fImageCount; ++i) {
261 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; 255 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED;
262 256
263 GrBackendRenderTargetDesc desc; 257 GrBackendRenderTargetDesc desc;
264 GrVkImageInfo info; 258 GrVkImageInfo info;
265 info.fImage = fImages[i]; 259 info.fImage = fImages[i];
266 info.fAlloc = VK_NULL_HANDLE; 260 info.fAlloc = VK_NULL_HANDLE;
267 info.fImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 261 info.fImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
268 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; 262 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
269 info.fFormat = format; 263 info.fFormat = format;
270 info.fLevelCount = 1; 264 info.fLevelCount = 1;
271 desc.fWidth = fWidth; 265 desc.fWidth = fWidth;
272 desc.fHeight = fHeight; 266 desc.fHeight = fHeight;
273 desc.fConfig = fPixelConfig; 267 desc.fConfig = fPixelConfig;
274 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 268 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
275 desc.fSampleCnt = 0; 269 desc.fSampleCnt = 0;
276 desc.fStencilBits = 0; 270 desc.fStencilBits = 0;
277 desc.fRenderTargetHandle = (GrBackendObject) &info; 271 desc.fRenderTargetHandle = (GrBackendObject) &info;
278 fRenderTargets[i].reset(fContext->textureProvider()->wrapBackendRenderTa rget(desc)); 272 SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig)
279 273 ? SkSurfaceProps::kGammaCorrect_Flag : 0,
280 fSurfaces[i] = this->createRenderSurface(fRenderTargets[i], 24); 274 kUnknown_SkPixelGeometry);
275 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p rops);
281 } 276 }
282 277
283 // create the command pool for the command buffers 278 // create the command pool for the command buffers
284 if (VK_NULL_HANDLE == fCommandPool) { 279 if (VK_NULL_HANDLE == fCommandPool) {
285 VkCommandPoolCreateInfo commandPoolInfo; 280 VkCommandPoolCreateInfo commandPoolInfo;
286 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); 281 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo));
287 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; 282 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
288 // this needs to be on the render queue 283 // this needs to be on the render queue
289 commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex; 284 commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex;
290 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; 285 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 GR_VK_CALL(fBackendContext->fInterface, 354 GR_VK_CALL(fBackendContext->fInterface,
360 DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fU sageFences[0], 0)); 355 DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fU sageFences[0], 0));
361 GR_VK_CALL(fBackendContext->fInterface, 356 GR_VK_CALL(fBackendContext->fInterface,
362 DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fU sageFences[1], 0)); 357 DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fU sageFences[1], 0));
363 } 358 }
364 } 359 }
365 360
366 delete[] fBackbuffers; 361 delete[] fBackbuffers;
367 fBackbuffers = nullptr; 362 fBackbuffers = nullptr;
368 363
369 // Does this actually free the surfaces?
370 delete[] fSurfaces; 364 delete[] fSurfaces;
371 fSurfaces = nullptr; 365 fSurfaces = nullptr;
372 delete[] fRenderTargets;
373 fRenderTargets = nullptr;
374 delete[] fImageLayouts; 366 delete[] fImageLayouts;
375 fImageLayouts = nullptr; 367 fImageLayouts = nullptr;
376 delete[] fImages; 368 delete[] fImages;
377 fImages = nullptr; 369 fImages = nullptr;
378 } 370 }
379 371
380 VulkanWindowContext::~VulkanWindowContext() { 372 VulkanWindowContext::~VulkanWindowContext() {
381 this->destroyContext(); 373 this->destroyContext();
382 } 374 }
383 375
(...skipping 15 matching lines...) Expand all
399 if (VK_NULL_HANDLE != fSwapchain) { 391 if (VK_NULL_HANDLE != fSwapchain) {
400 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); 392 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr);
401 fSwapchain = VK_NULL_HANDLE; 393 fSwapchain = VK_NULL_HANDLE;
402 } 394 }
403 395
404 if (VK_NULL_HANDLE != fSurface) { 396 if (VK_NULL_HANDLE != fSurface) {
405 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); 397 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr);
406 fSurface = VK_NULL_HANDLE; 398 fSurface = VK_NULL_HANDLE;
407 } 399 }
408 400
409 fContext->abandonContext(); 401 delete fContext;
410 fContext->unref();
411 402
412 fBackendContext.reset(nullptr); 403 fBackendContext.reset(nullptr);
413 } 404 }
414 405
415 VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer () { 406 VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer () {
416 SkASSERT(fBackbuffers); 407 SkASSERT(fBackbuffers);
417 408
418 ++fCurrentBackbufferIndex; 409 ++fCurrentBackbufferIndex;
419 if (fCurrentBackbufferIndex > fImageCount) { 410 if (fCurrentBackbufferIndex > fImageCount) {
420 fCurrentBackbufferIndex = 0; 411 fCurrentBackbufferIndex = 0;
421 } 412 }
422 413
423 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; 414 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex;
424 415
425 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 416 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
426 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f UsageFences, 417 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f UsageFences,
427 true, UINT64_MAX)); 418 true, UINT64_MAX));
428 return backbuffer; 419 return backbuffer;
429 } 420 }
430 421
431 sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { 422 SkSurface* VulkanWindowContext::getBackbufferSurface() {
432 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); 423 BackbufferInfo* backbuffer = this->getAvailableBackbuffer();
433 SkASSERT(backbuffer); 424 SkASSERT(backbuffer);
434 425
435 // reset the fence 426 // reset the fence
436 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 427 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
437 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs ageFences)); 428 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs ageFences));
438 // semaphores should be in unsignaled state 429 // semaphores should be in unsignaled state
439 430
440 // acquire the image 431 // acquire the image
441 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI NT64_MAX, 432 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI NT64_MAX,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; 503 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore;
513 submitInfo.pWaitDstStageMask = &waitDstStageFlags; 504 submitInfo.pWaitDstStageMask = &waitDstStageFlags;
514 submitInfo.commandBufferCount = 1; 505 submitInfo.commandBufferCount = 1;
515 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; 506 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0];
516 submitInfo.signalSemaphoreCount = 0; 507 submitInfo.signalSemaphoreCount = 0;
517 508
518 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 509 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
519 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, 510 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo,
520 backbuffer->fUsageFences[0])); 511 backbuffer->fUsageFences[0]));
521 512
522 return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); 513 return fSurfaces[backbuffer->fImageIndex].get();
523 } 514 }
524 515
516
525 void VulkanWindowContext::swapBuffers() { 517 void VulkanWindowContext::swapBuffers() {
526 518
527 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; 519 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex;
528 520
529 this->presentRenderSurface(fSurfaces[backbuffer->fImageIndex],
530 fRenderTargets[backbuffer->fImageIndex], 24);
531
532 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 521 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
533 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT; 522 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT;
534 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; 523 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
535 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; 524 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
536 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; 525 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
537 526
538 VkImageMemoryBarrier imageMemoryBarrier = { 527 VkImageMemoryBarrier imageMemoryBarrier = {
539 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType 528 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
540 NULL, // pNext 529 NULL, // pNext
541 srcAccessMask, // outputMask 530 srcAccessMask, // outputMask
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 &fSwapchain, // pSwapchains 581 &fSwapchain, // pSwapchains
593 &backbuffer->fImageIndex, // pImageIndices 582 &backbuffer->fImageIndex, // pImageIndices
594 NULL // pResults 583 NULL // pResults
595 }; 584 };
596 585
597 fQueuePresentKHR(fPresentQueue, &presentInfo); 586 fQueuePresentKHR(fPresentQueue, &presentInfo);
598 587
599 } 588 }
600 589
601 } //namespace sk_app 590 } //namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/VulkanWindowContext.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698