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

Side by Side Diff: tools/gpu/vk/VkTestContext.cpp

Issue 2383383002: Move GPU fences into sk_gpu_test (Closed)
Patch Set: Move GPU fences into sk_gpu_test Created 4 years, 2 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 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 9
10 #ifdef SK_VULKAN 10 #ifdef SK_VULKAN
11 11
12 #include "vk/GrVkInterface.h" 12 #include "vk/GrVkInterface.h"
13 #include "vk/GrVkUtil.h" 13 #include "vk/GrVkUtil.h"
14 #include <vulkan/vulkan.h> 14 #include <vulkan/vulkan.h>
15 15
16 namespace { 16 namespace sk_gpu_test {
bsalomon 2016/10/03 17:54:00 Ditto
csmartdalton 2016/10/03 19:05:40 Done.
17 /** 17 /**
18 * Implements SkGpuFenceSync for Vulkan. It creates a single command buffer with 18 * Implements FenceSync for Vulkan. It creates a single command buffer with
19 * USAGE_SIMULTANEOUS with no content . On every insertFence request it submits 19 * USAGE_SIMULTANEOUS with no content . On every insertFence request it submits
20 * the command buffer with a new fence. 20 * the command buffer with a new fence.
21 */ 21 */
22 class VkFenceSync : public SkGpuFenceSync { 22 class VkFenceSync : public FenceSync {
23 public: 23 public:
24 VkFenceSync(sk_sp<const GrVkInterface> vk, VkDevice device, VkQueue queue, 24 VkFenceSync(sk_sp<const GrVkInterface> vk, VkDevice device, VkQueue queue,
25 uint32_t queueFamilyIndex) 25 uint32_t queueFamilyIndex)
26 : fVk(std::move(vk)) 26 : fVk(std::move(vk))
27 , fDevice(device) 27 , fDevice(device)
28 , fQueue(queue) { 28 , fQueue(queue) {
29 SkDEBUGCODE(fUnfinishedSyncs = 0;) 29 SkDEBUGCODE(fUnfinishedSyncs = 0;)
30 VkCommandPoolCreateInfo createInfo; 30 VkCommandPoolCreateInfo createInfo;
egdaniel 2016/10/03 13:24:25 We don't need any of this command buffer stuff jus
31 createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; 31 createInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
32 createInfo.pNext = nullptr; 32 createInfo.pNext = nullptr;
33 createInfo.flags = 0; 33 createInfo.flags = 0;
34 createInfo.queueFamilyIndex = queueFamilyIndex; 34 createInfo.queueFamilyIndex = queueFamilyIndex;
35 GR_VK_CALL_ERRCHECK(fVk, CreateCommandPool(fDevice, &createInfo, nullptr , &fCommandPool)); 35 GR_VK_CALL_ERRCHECK(fVk, CreateCommandPool(fDevice, &createInfo, nullptr , &fCommandPool));
36 36
37 VkCommandBufferAllocateInfo allocateInfo; 37 VkCommandBufferAllocateInfo allocateInfo;
38 allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; 38 allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
39 allocateInfo.pNext = nullptr; 39 allocateInfo.pNext = nullptr;
40 allocateInfo.commandBufferCount = 1; 40 allocateInfo.commandBufferCount = 1;
(...skipping 10 matching lines...) Expand all
51 GR_VK_CALL_ERRCHECK(fVk, EndCommandBuffer(fCommandBuffer)); 51 GR_VK_CALL_ERRCHECK(fVk, EndCommandBuffer(fCommandBuffer));
52 } 52 }
53 53
54 ~VkFenceSync() override { 54 ~VkFenceSync() override {
55 SkASSERT(!fUnfinishedSyncs); 55 SkASSERT(!fUnfinishedSyncs);
56 // If the above assertion is true then the command buffer should not be in flight. 56 // If the above assertion is true then the command buffer should not be in flight.
57 GR_VK_CALL(fVk, FreeCommandBuffers(fDevice, fCommandPool, 1, &fCommandBu ffer)); 57 GR_VK_CALL(fVk, FreeCommandBuffers(fDevice, fCommandPool, 1, &fCommandBu ffer));
58 GR_VK_CALL(fVk, DestroyCommandPool(fDevice, fCommandPool, nullptr)); 58 GR_VK_CALL(fVk, DestroyCommandPool(fDevice, fCommandPool, nullptr));
59 } 59 }
60 60
61 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override { 61 PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override {
62 VkFence fence; 62 VkFence fence;
63 VkFenceCreateInfo info; 63 VkFenceCreateInfo info;
64 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; 64 info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
65 info.pNext = nullptr; 65 info.pNext = nullptr;
66 info.flags = 0; 66 info.flags = 0;
67 GR_VK_CALL_ERRCHECK(fVk, CreateFence(fDevice, &info, nullptr, &fence)); 67 GR_VK_CALL_ERRCHECK(fVk, CreateFence(fDevice, &info, nullptr, &fence));
68 VkSubmitInfo submitInfo; 68 VkSubmitInfo submitInfo;
69 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; 69 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
70 submitInfo.pNext = nullptr; 70 submitInfo.pNext = nullptr;
71 submitInfo.waitSemaphoreCount = 0; 71 submitInfo.waitSemaphoreCount = 0;
72 submitInfo.pWaitSemaphores = nullptr; 72 submitInfo.pWaitSemaphores = nullptr;
73 submitInfo.pWaitDstStageMask = nullptr; 73 submitInfo.pWaitDstStageMask = nullptr;
74 submitInfo.commandBufferCount = 1; 74 submitInfo.commandBufferCount = 1;
75 submitInfo.pCommandBuffers = &fCommandBuffer; 75 submitInfo.pCommandBuffers = &fCommandBuffer;
76 submitInfo.signalSemaphoreCount = 0; 76 submitInfo.signalSemaphoreCount = 0;
77 submitInfo.pSignalSemaphores = nullptr; 77 submitInfo.pSignalSemaphores = nullptr;
78 GR_VK_CALL_ERRCHECK(fVk, QueueSubmit(fQueue, 1, &submitInfo, fence)); 78 GR_VK_CALL_ERRCHECK(fVk, QueueSubmit(fQueue, 1, &submitInfo, fence));
egdaniel 2016/10/03 13:24:24 since we don't need a command buffer, we can pass
79 SkDEBUGCODE(++fUnfinishedSyncs;) 79 SkDEBUGCODE(++fUnfinishedSyncs;)
80 return reinterpret_cast<SkPlatformGpuFence>(fence); 80 return reinterpret_cast<PlatformFence>(fence);
81 } 81 }
82 82
83 bool waitFence(SkPlatformGpuFence opaqueFence) const override { 83 bool waitFence(PlatformFence opaqueFence) const override {
84 VkFence fence = reinterpret_cast<VkFence>(opaqueFence); 84 VkFence fence = reinterpret_cast<VkFence>(opaqueFence);
85 static constexpr uint64_t kForever = ~((uint64_t)0); 85 static constexpr uint64_t kForever = ~((uint64_t)0);
86 auto result = GR_VK_CALL(fVk, WaitForFences(fDevice, 1, &fence, true, kF orever)); 86 auto result = GR_VK_CALL(fVk, WaitForFences(fDevice, 1, &fence, true, kF orever));
87 return result != VK_TIMEOUT; 87 return result != VK_TIMEOUT;
egdaniel 2016/10/03 13:24:24 Should this assert be result == VK_SUCCESS, this w
88 } 88 }
89 89
90 void deleteFence(SkPlatformGpuFence opaqueFence) const override { 90 void deleteFence(PlatformFence opaqueFence) const override {
91 VkFence fence = reinterpret_cast<VkFence>(opaqueFence); 91 VkFence fence = reinterpret_cast<VkFence>(opaqueFence);
92 GR_VK_CALL(fVk, DestroyFence(fDevice, fence, nullptr)); 92 GR_VK_CALL(fVk, DestroyFence(fDevice, fence, nullptr));
93 SkDEBUGCODE(--fUnfinishedSyncs;) 93 SkDEBUGCODE(--fUnfinishedSyncs;)
94 } 94 }
95 95
96 private: 96 private:
97 sk_sp<const GrVkInterface> fVk; 97 sk_sp<const GrVkInterface> fVk;
98 VkDevice fDevice; 98 VkDevice fDevice;
99 VkQueue fQueue; 99 VkQueue fQueue;
100 VkCommandPool fCommandPool; 100 VkCommandPool fCommandPool;
101 VkCommandBuffer fCommandBuffer; 101 VkCommandBuffer fCommandBuffer;
102 SkDEBUGCODE(mutable int fUnfinishedSyncs;) 102 SkDEBUGCODE(mutable int fUnfinishedSyncs;)
103 typedef SkGpuFenceSync INHERITED; 103 typedef FenceSync INHERITED;
104 }; 104 };
105 105
106 // TODO: Implement swap buffers and finish 106 // TODO: Implement swap buffers and finish
107 class VkTestContextImpl : public sk_gpu_test::VkTestContext { 107 class VkTestContextImpl : public VkTestContext {
108 public: 108 public:
109 static VkTestContext* Create() { 109 static VkTestContext* Create() {
110 sk_sp<const GrVkBackendContext> backendContext(GrVkBackendContext::Creat e()); 110 sk_sp<const GrVkBackendContext> backendContext(GrVkBackendContext::Creat e());
111 if (!backendContext) { 111 if (!backendContext) {
112 return nullptr; 112 return nullptr;
113 } 113 }
114 return new VkTestContextImpl(std::move(backendContext)); 114 return new VkTestContextImpl(std::move(backendContext));
115 } 115 }
116 116
117 ~VkTestContextImpl() override { this->teardown(); } 117 ~VkTestContextImpl() override { this->teardown(); }
(...skipping 14 matching lines...) Expand all
132 private: 132 private:
133 VkTestContextImpl(sk_sp<const GrVkBackendContext> backendContext) 133 VkTestContextImpl(sk_sp<const GrVkBackendContext> backendContext)
134 : VkTestContext(std::move(backendContext)) { 134 : VkTestContext(std::move(backendContext)) {
135 fFenceSync = new VkFenceSync(sk_ref_sp(fVk->fInterface.get()), fVk->fDev ice, fVk->fQueue, 135 fFenceSync = new VkFenceSync(sk_ref_sp(fVk->fInterface.get()), fVk->fDev ice, fVk->fQueue,
136 fVk->fGraphicsQueueIndex); 136 fVk->fGraphicsQueueIndex);
137 } 137 }
138 138
139 void onPlatformMakeCurrent() const override {} 139 void onPlatformMakeCurrent() const override {}
140 void onPlatformSwapBuffers() const override {} 140 void onPlatformSwapBuffers() const override {}
141 141
142 typedef sk_gpu_test::VkTestContext INHERITED; 142 typedef VkTestContext INHERITED;
143 }; 143 };
144 }
145 144
146 namespace sk_gpu_test {
147 VkTestContext* CreatePlatformVkTestContext() { return VkTestContextImpl::Create( ); } 145 VkTestContext* CreatePlatformVkTestContext() { return VkTestContextImpl::Create( ); }
148 } // namespace sk_gpu_test 146 } // namespace sk_gpu_test
149 147
150 #endif 148 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698