Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "VkTestContext.h" | 8 #include "VkTestContext.h" |
| 9 #include "vk/GrVkInterface.h" | |
| 10 #include "vk/GrVkUtil.h" | |
| 11 #include <vulkan/vulkan.h> | |
|
egdaniel
2016/05/16 17:19:41
would need to include third_party in gyp includes?
bsalomon
2016/05/16 20:37:08
I'm not sure I understand this comment. I moved al
egdaniel
2016/05/16 20:45:41
Oh it was just asking if vulkan/vulkan.h would be
| |
| 9 | 12 |
| 10 #ifdef SK_VULKAN | 13 #ifdef SK_VULKAN |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 // TODO: Implement fence syncs, swap buffers, submit, and flush | 16 /** |
| 17 * Implements SkGpuFenceSync for Vulkan. It creates a single command buffer with | |
| 18 * USAGE_SIMULTANEOUS with no content . On every insertFence request it submits | |
| 19 * the command buffer with a new fence. | |
| 20 */ | |
| 21 class VkFenceSync : public SkGpuFenceSync { | |
| 22 public: | |
| 23 VkFenceSync(sk_sp<const GrVkInterface> vk, VkDevice device, VkQueue queue, | |
| 24 uint32_t queueFamilyIndex) | |
| 25 : fVk(std::move(vk)) | |
| 26 , fDevice(device) | |
| 27 , fQueue(queue) { | |
| 28 SkDEBUGCODE(fUnfinishedSyncs = 0;) | |
| 29 VkCommandPoolCreateInfo createInfo; | |
| 30 createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; | |
| 31 createInfo.pNext = nullptr; | |
| 32 createInfo.flags = 0; | |
| 33 createInfo.queueFamilyIndex = queueFamilyIndex; | |
| 34 GR_VK_CALL_ERRCHECK(fVk, CreateCommandPool(fDevice, &createInfo, nullptr , &fCommandPool)); | |
| 35 | |
| 36 VkCommandBufferAllocateInfo allocateInfo; | |
| 37 allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; | |
| 38 allocateInfo.pNext = nullptr; | |
| 39 allocateInfo.commandBufferCount = 1; | |
| 40 allocateInfo.commandPool = fCommandPool; | |
| 41 allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; | |
| 42 GR_VK_CALL_ERRCHECK(fVk, AllocateCommandBuffers(fDevice, &allocateInfo, &fCommandBuffer)); | |
| 43 | |
| 44 VkCommandBufferBeginInfo beginInfo; | |
| 45 beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | |
| 46 beginInfo.pNext = nullptr; | |
| 47 beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; | |
| 48 beginInfo.pInheritanceInfo = nullptr; | |
| 49 GR_VK_CALL_ERRCHECK(fVk, BeginCommandBuffer(fCommandBuffer, &beginInfo)) ; | |
| 50 GR_VK_CALL_ERRCHECK(fVk, EndCommandBuffer(fCommandBuffer)); | |
| 51 } | |
| 52 | |
| 53 ~VkFenceSync() override { | |
| 54 SkASSERT(!fUnfinishedSyncs); | |
| 55 // If the above assertion is true then the command buffer should not be in flight. | |
|
egdaniel
2016/05/16 17:19:41
For the above assertion and comment to be true it
bsalomon
2016/05/16 20:37:08
Right, the assertion only checks that deleteFence
egdaniel
2016/05/16 20:45:41
Sounds good, any way we can require that both have
| |
| 56 GR_VK_CALL(fVk, FreeCommandBuffers(fDevice, fCommandPool, 1, &fCommandBu ffer)); | |
| 57 GR_VK_CALL(fVk, DestroyCommandPool(fDevice, fCommandPool, nullptr)); | |
| 58 } | |
| 59 | |
| 60 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override { | |
| 61 VkFence fence; | |
| 62 VkFenceCreateInfo info; | |
| 63 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; | |
| 64 info.pNext = nullptr; | |
| 65 info.flags = 0; | |
| 66 GR_VK_CALL_ERRCHECK(fVk, CreateFence(fDevice, &info, nullptr, &fence)); | |
| 67 VkSubmitInfo submitInfo; | |
| 68 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; | |
| 69 submitInfo.pNext = nullptr; | |
| 70 submitInfo.waitSemaphoreCount = 0; | |
| 71 submitInfo.pWaitSemaphores = nullptr; | |
| 72 submitInfo.pWaitDstStageMask = nullptr; | |
| 73 submitInfo.commandBufferCount = 1; | |
| 74 submitInfo.pCommandBuffers = &fCommandBuffer; | |
| 75 submitInfo.signalSemaphoreCount = 0; | |
| 76 submitInfo.pSignalSemaphores = nullptr; | |
| 77 GR_VK_CALL_ERRCHECK(fVk, QueueSubmit(fQueue, 1, &submitInfo, fence)); | |
| 78 SkDEBUGCODE(++fUnfinishedSyncs;) | |
| 79 return reinterpret_cast<SkPlatformGpuFence>(fence); | |
|
egdaniel
2016/05/16 17:19:41
nit: remove tab
bsalomon
2016/05/16 20:37:08
Done.
| |
| 80 } | |
| 81 | |
| 82 bool waitFence(SkPlatformGpuFence opaqueFence) const override { | |
| 83 VkFence fence = reinterpret_cast<VkFence>(opaqueFence); | |
| 84 static constexpr uint64_t kForever = ~((uint64_t)0); | |
| 85 auto result = GR_VK_CALL(fVk, WaitForFences(fDevice, 1, &fence, true, kF orever)); | |
| 86 return result != VK_TIMEOUT; | |
| 87 } | |
| 88 | |
| 89 void deleteFence(SkPlatformGpuFence opaqueFence) const override { | |
| 90 VkFence fence = reinterpret_cast<VkFence>(opaqueFence); | |
| 91 GR_VK_CALL(fVk, DestroyFence(fDevice, fence, nullptr)); | |
| 92 SkDEBUGCODE(--fUnfinishedSyncs;) | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 sk_sp<const GrVkInterface> fVk; | |
| 97 VkDevice fDevice; | |
| 98 VkQueue fQueue; | |
| 99 VkCommandPool fCommandPool; | |
| 100 VkCommandBuffer fCommandBuffer; | |
| 101 SkDEBUGCODE(mutable int fUnfinishedSyncs;) | |
| 102 typedef SkGpuFenceSync INHERITED; | |
| 103 }; | |
| 104 | |
| 105 // TODO: Implement swap buffers and finish | |
| 14 class VkTestContextImpl : public sk_gpu_test::VkTestContext { | 106 class VkTestContextImpl : public sk_gpu_test::VkTestContext { |
| 15 public: | 107 public: |
| 16 VkTestContextImpl() | 108 static VkTestContext* Create() { |
| 17 : VkTestContext(sk_sp<const GrVkBackendContext>(GrVkBackendContext::Crea te())) {} | 109 sk_sp<const GrVkBackendContext> backendContext(GrVkBackendContext::Creat e()); |
| 110 if (!backendContext) { | |
| 111 return nullptr; | |
| 112 } | |
| 113 return new VkTestContextImpl(std::move(backendContext)); | |
| 114 } | |
| 18 | 115 |
| 19 ~VkTestContextImpl() override { this->teardown(); } | 116 ~VkTestContextImpl() override { this->teardown(); } |
| 20 | 117 |
| 21 void testAbandon() override {} | 118 void testAbandon() override {} |
| 22 | 119 |
| 120 // There is really nothing to here since we don't own any unqueued command b uffers here. | |
| 23 void submit() override {} | 121 void submit() override {} |
| 122 | |
| 24 void finish() override {} | 123 void finish() override {} |
| 25 | 124 |
| 26 protected: | 125 protected: |
| 27 void teardown() override { fVk.reset(nullptr); } | 126 void teardown() override { |
| 127 INHERITED::teardown(); fVk.reset(nullptr); | |
|
egdaniel
2016/05/16 17:19:41
put these on two lines?
bsalomon
2016/05/16 20:37:08
Done.
| |
| 128 } | |
| 28 | 129 |
| 29 private: | 130 private: |
| 131 VkTestContextImpl(sk_sp<const GrVkBackendContext> backendContext) | |
| 132 : VkTestContext(std::move(backendContext)) { | |
| 133 fFenceSync = new VkFenceSync(sk_ref_sp(fVk->fInterface.get()), fVk->fDev ice, fVk->fQueue, | |
| 134 fVk->fGraphicsQueueIndex); | |
| 135 } | |
| 136 | |
| 30 void onPlatformMakeCurrent() const override {} | 137 void onPlatformMakeCurrent() const override {} |
| 31 void onPlatformSwapBuffers() const override {} | 138 void onPlatformSwapBuffers() const override {} |
| 32 | 139 |
| 33 typedef sk_gpu_test::VkTestContext INHERITED; | 140 typedef sk_gpu_test::VkTestContext INHERITED; |
| 34 }; | 141 }; |
| 35 } | 142 } |
| 36 | 143 |
| 37 namespace sk_gpu_test { | 144 namespace sk_gpu_test { |
| 38 VkTestContext* CreatePlatformVkTestContext() { | 145 VkTestContext* CreatePlatformVkTestContext() { return VkTestContextImpl::Create( ); } |
| 39 return new VkTestContextImpl; | |
| 40 } | |
| 41 } // namespace sk_gpu_test | 146 } // namespace sk_gpu_test |
| 42 | 147 |
| 43 #endif | 148 #endif |
| OLD | NEW |