Corentin Wallez | 4a9ef4e | 2018-07-18 11:40:26 +0200 | [diff] [blame] | 1 | // Copyright 2017 The Dawn Authors |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Corentin Wallez | b91022d | 2018-01-19 12:52:25 -0500 | [diff] [blame] | 15 | #include "SampleUtils.h" |
| 16 | |
Kai Ninomiya | 21006bb | 2018-06-20 18:54:18 -0700 | [diff] [blame] | 17 | #include "common/Assert.h" |
Corentin Wallez | 0b186b1 | 2017-07-12 12:56:05 -0400 | [diff] [blame] | 18 | #include "common/Platform.h" |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 19 | #include "utils/BackendBinding.h" |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 20 | #include "utils/TerribleCommandBuffer.h" |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 21 | |
Corentin Wallez | 046cb46 | 2018-07-18 14:28:38 +0200 | [diff] [blame] | 22 | #include <dawn/dawn.h> |
Corentin Wallez | 3e371b1 | 2018-07-18 14:32:45 +0200 | [diff] [blame] | 23 | #include <dawn/dawn_wsi.h> |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 24 | #include <dawn/dawncpp.h> |
Corentin Wallez | dcb71a1 | 2018-08-02 22:27:57 +0200 | [diff] [blame] | 25 | #include <dawn_native/DawnNative.h> |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 26 | #include <dawn_wire/WireClient.h> |
| 27 | #include <dawn_wire/WireServer.h> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 28 | #include "GLFW/glfw3.h" |
| 29 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 30 | #include <algorithm> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 31 | #include <cstring> |
| 32 | #include <iostream> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 33 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 34 | void PrintDeviceError(const char* message, dawn::CallbackUserdata) { |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 35 | std::cout << "Device error: " << message << std::endl; |
| 36 | } |
| 37 | |
Corentin Wallez | 52cbcb4 | 2018-01-19 12:52:03 -0500 | [diff] [blame] | 38 | void PrintGLFWError(int code, const char* message) { |
| 39 | std::cout << "GLFW error: " << code << " - " << message << std::endl; |
| 40 | } |
| 41 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 42 | enum class CmdBufType { |
| 43 | None, |
| 44 | Terrible, |
Corentin Wallez | 682a825 | 2017-05-09 15:34:13 +0200 | [diff] [blame] | 45 | //TODO(cwallez@chromium.org) double terrible cmdbuf |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 46 | }; |
| 47 | |
Corentin Wallez | 275817a | 2017-07-12 12:43:24 -0400 | [diff] [blame] | 48 | // Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on |
| 49 | // their respective platforms, and Vulkan is preferred to OpenGL |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 50 | #if defined(DAWN_ENABLE_BACKEND_D3D12) |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 51 | static dawn_native::BackendType backendType = dawn_native::BackendType::D3D12; |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 52 | #elif defined(DAWN_ENABLE_BACKEND_METAL) |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 53 | static dawn_native::BackendType backendType = dawn_native::BackendType::Metal; |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 54 | #elif defined(DAWN_ENABLE_BACKEND_OPENGL) |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 55 | static dawn_native::BackendType backendType = dawn_native::BackendType::OpenGL; |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 56 | #elif defined(DAWN_ENABLE_BACKEND_VULKAN) |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 57 | static dawn_native::BackendType backendType = dawn_native::BackendType::Vulkan; |
Austin Eng | fc2bac7 | 2017-06-05 17:08:55 -0400 | [diff] [blame] | 58 | #else |
Corentin Wallez | 275817a | 2017-07-12 12:43:24 -0400 | [diff] [blame] | 59 | #error |
Austin Eng | fc2bac7 | 2017-06-05 17:08:55 -0400 | [diff] [blame] | 60 | #endif |
| 61 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 62 | static CmdBufType cmdBufType = CmdBufType::Terrible; |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 63 | static std::unique_ptr<dawn_native::Instance> instance; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 64 | static utils::BackendBinding* binding = nullptr; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 65 | |
| 66 | static GLFWwindow* window = nullptr; |
| 67 | |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 68 | static dawn_wire::WireServer* wireServer = nullptr; |
| 69 | static dawn_wire::WireClient* wireClient = nullptr; |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 70 | static utils::TerribleCommandBuffer* c2sBuf = nullptr; |
| 71 | static utils::TerribleCommandBuffer* s2cBuf = nullptr; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 72 | |
Corentin Wallez | 39039fa | 2018-07-18 14:06:10 +0200 | [diff] [blame] | 73 | dawn::Device CreateCppDawnDevice() { |
Corentin Wallez | 52cbcb4 | 2018-01-19 12:52:03 -0500 | [diff] [blame] | 74 | glfwSetErrorCallback(PrintGLFWError); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 75 | if (!glfwInit()) { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 76 | return dawn::Device(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 79 | // Create the test window and discover adapters using it (esp. for OpenGL) |
| 80 | utils::SetupGLFWWindowHintsForBackend(backendType); |
Corentin Wallez | 6ed9cbf | 2018-07-18 15:32:04 +0200 | [diff] [blame] | 81 | window = glfwCreateWindow(640, 480, "Dawn window", nullptr, nullptr); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 82 | if (!window) { |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 83 | return dawn::Device(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 86 | instance = std::make_unique<dawn_native::Instance>(); |
| 87 | utils::DiscoverAdapter(instance.get(), window, backendType); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 88 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 89 | // Get an adapter for the backend to use, and create the device. |
| 90 | dawn_native::Adapter backendAdapter; |
| 91 | { |
| 92 | std::vector<dawn_native::Adapter> adapters = instance->GetAdapters(); |
| 93 | auto adapterIt = std::find_if(adapters.begin(), adapters.end(), |
| 94 | [](const dawn_native::Adapter adapter) -> bool { |
| 95 | return adapter.GetBackendType() == backendType; |
| 96 | }); |
| 97 | ASSERT(adapterIt != adapters.end()); |
| 98 | backendAdapter = *adapterIt; |
| 99 | } |
| 100 | |
| 101 | dawnDevice backendDevice = backendAdapter.CreateDevice(); |
Corentin Wallez | dcb71a1 | 2018-08-02 22:27:57 +0200 | [diff] [blame] | 102 | dawnProcTable backendProcs = dawn_native::GetProcs(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 103 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 104 | binding = utils::CreateBinding(backendType, window, backendDevice); |
| 105 | if (binding == nullptr) { |
| 106 | return dawn::Device(); |
| 107 | } |
| 108 | |
| 109 | // Choose whether to use the backend procs and devices directly, or set up the wire. |
Corentin Wallez | b1669e3 | 2018-07-18 15:12:52 +0200 | [diff] [blame] | 110 | dawnDevice cDevice = nullptr; |
Corentin Wallez | be5ca38 | 2018-07-18 15:15:07 +0200 | [diff] [blame] | 111 | dawnProcTable procs; |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame^] | 112 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 113 | switch (cmdBufType) { |
| 114 | case CmdBufType::None: |
Corentin Wallez | 583e9a8 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 115 | procs = backendProcs; |
| 116 | cDevice = backendDevice; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 117 | break; |
| 118 | |
| 119 | case CmdBufType::Terrible: |
| 120 | { |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 121 | c2sBuf = new utils::TerribleCommandBuffer(); |
| 122 | s2cBuf = new utils::TerribleCommandBuffer(); |
Corentin Wallez | 682a825 | 2017-05-09 15:34:13 +0200 | [diff] [blame] | 123 | |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 124 | wireServer = new dawn_wire::WireServer(backendDevice, backendProcs, s2cBuf); |
Corentin Wallez | 682a825 | 2017-05-09 15:34:13 +0200 | [diff] [blame] | 125 | c2sBuf->SetHandler(wireServer); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 126 | |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 127 | wireClient = new dawn_wire::WireClient(c2sBuf); |
| 128 | dawnDevice clientDevice = wireClient->GetDevice(); |
| 129 | dawnProcTable clientProcs = wireClient->GetProcs(); |
Corentin Wallez | 682a825 | 2017-05-09 15:34:13 +0200 | [diff] [blame] | 130 | s2cBuf->SetHandler(wireClient); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 131 | |
Corentin Wallez | 583e9a8 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 132 | procs = clientProcs; |
| 133 | cDevice = clientDevice; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 134 | } |
| 135 | break; |
| 136 | } |
| 137 | |
Corentin Wallez | be5ca38 | 2018-07-18 15:15:07 +0200 | [diff] [blame] | 138 | dawnSetProcs(&procs); |
Corentin Wallez | 583e9a8 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 139 | procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0); |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 140 | return dawn::Device::Acquire(cDevice); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 143 | uint64_t GetSwapChainImplementation() { |
| 144 | return binding->GetSwapChainImplementation(); |
| 145 | } |
| 146 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 147 | dawn::TextureFormat GetPreferredSwapChainTextureFormat() { |
Corentin Wallez | b91022d | 2018-01-19 12:52:25 -0500 | [diff] [blame] | 148 | DoFlush(); |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 149 | return static_cast<dawn::TextureFormat>(binding->GetPreferredSwapChainTextureFormat()); |
Corentin Wallez | 2e31e8f | 2017-09-21 12:54:53 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 152 | dawn::SwapChain GetSwapChain(const dawn::Device &device) { |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 153 | return device.CreateSwapChainBuilder() |
| 154 | .SetImplementation(GetSwapChainImplementation()) |
| 155 | .GetResult(); |
| 156 | } |
| 157 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 158 | dawn::TextureView CreateDefaultDepthStencilView(const dawn::Device& device) { |
Jiawei Shao | 425428f | 2018-08-27 08:44:48 +0800 | [diff] [blame] | 159 | dawn::TextureDescriptor descriptor; |
| 160 | descriptor.dimension = dawn::TextureDimension::e2D; |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 161 | descriptor.size.width = 640; |
| 162 | descriptor.size.height = 480; |
| 163 | descriptor.size.depth = 1; |
Jiawei Shao | 8bff3b2 | 2018-12-12 09:27:16 +0000 | [diff] [blame] | 164 | descriptor.arraySize = 1; |
| 165 | descriptor.sampleCount = 1; |
Jiawei Shao | 425428f | 2018-08-27 08:44:48 +0800 | [diff] [blame] | 166 | descriptor.format = dawn::TextureFormat::D32FloatS8Uint; |
Jiawei Shao | 84cde51 | 2018-10-31 10:51:11 +0000 | [diff] [blame] | 167 | descriptor.levelCount = 1; |
Jiawei Shao | 425428f | 2018-08-27 08:44:48 +0800 | [diff] [blame] | 168 | descriptor.usage = dawn::TextureUsageBit::OutputAttachment; |
| 169 | auto depthStencilTexture = device.CreateTexture(&descriptor); |
Jiawei Shao | 3d67050 | 2018-09-18 00:31:57 +0000 | [diff] [blame] | 170 | return depthStencilTexture.CreateDefaultTextureView(); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Corentin Wallez | 4828d92 | 2018-07-18 13:45:46 +0200 | [diff] [blame] | 173 | void GetNextRenderPassDescriptor(const dawn::Device& device, |
| 174 | const dawn::SwapChain& swapchain, |
| 175 | const dawn::TextureView& depthStencilView, |
| 176 | dawn::Texture* backbuffer, |
| 177 | dawn::RenderPassDescriptor* info) { |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 178 | *backbuffer = swapchain.GetNextTexture(); |
Jiawei Shao | 3d67050 | 2018-09-18 00:31:57 +0000 | [diff] [blame] | 179 | auto backbufferView = backbuffer->CreateDefaultTextureView(); |
Jiawei Shao | 5e811ae | 2018-12-19 08:21:13 +0000 | [diff] [blame] | 180 | dawn::RenderPassColorAttachmentDescriptor colorAttachment; |
| 181 | colorAttachment.attachment = backbufferView; |
| 182 | colorAttachment.resolveTarget = nullptr; |
| 183 | colorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 184 | colorAttachment.loadOp = dawn::LoadOp::Clear; |
| 185 | colorAttachment.storeOp = dawn::StoreOp::Store; |
| 186 | |
| 187 | dawn::RenderPassDepthStencilAttachmentDescriptor depthStencilAttachment; |
| 188 | depthStencilAttachment.attachment = depthStencilView; |
| 189 | depthStencilAttachment.depthLoadOp = dawn::LoadOp::Clear; |
| 190 | depthStencilAttachment.stencilLoadOp = dawn::LoadOp::Clear; |
| 191 | depthStencilAttachment.clearDepth = 1.0f; |
| 192 | depthStencilAttachment.clearStencil = 0; |
| 193 | depthStencilAttachment.depthStoreOp = dawn::StoreOp::Store; |
| 194 | depthStencilAttachment.stencilStoreOp = dawn::StoreOp::Store; |
| 195 | |
Corentin Wallez | 8d6b5d2 | 2018-05-11 13:04:44 -0400 | [diff] [blame] | 196 | *info = device.CreateRenderPassDescriptorBuilder() |
Jiawei Shao | 5e811ae | 2018-12-19 08:21:13 +0000 | [diff] [blame] | 197 | .SetColorAttachments(1, &colorAttachment) |
| 198 | .SetDepthStencilAttachment(&depthStencilAttachment) |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 199 | .GetResult(); |
| 200 | } |
| 201 | |
Corentin Wallez | 9347e8f | 2017-06-19 13:15:13 -0400 | [diff] [blame] | 202 | bool InitSample(int argc, const char** argv) { |
Corentin Wallez | 862f884 | 2018-06-07 13:03:29 +0200 | [diff] [blame] | 203 | for (int i = 1; i < argc; i++) { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 204 | if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) { |
| 205 | i++; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 206 | if (i < argc && std::string("d3d12") == argv[i]) { |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 207 | backendType = dawn_native::BackendType::D3D12; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 208 | continue; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 209 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 210 | if (i < argc && std::string("metal") == argv[i]) { |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 211 | backendType = dawn_native::BackendType::Metal; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 212 | continue; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 213 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 214 | if (i < argc && std::string("null") == argv[i]) { |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 215 | backendType = dawn_native::BackendType::Null; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 216 | continue; |
| 217 | } |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 218 | if (i < argc && std::string("opengl") == argv[i]) { |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 219 | backendType = dawn_native::BackendType::OpenGL; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 220 | continue; |
| 221 | } |
| 222 | if (i < argc && std::string("vulkan") == argv[i]) { |
Corentin Wallez | 8c88e1d | 2019-02-05 12:17:20 +0000 | [diff] [blame] | 223 | backendType = dawn_native::BackendType::Vulkan; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 224 | continue; |
| 225 | } |
| 226 | fprintf(stderr, "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n"); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 227 | return false; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 228 | } |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 229 | if (std::string("-c") == argv[i] || std::string("--command-buffer") == argv[i]) { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 230 | i++; |
| 231 | if (i < argc && std::string("none") == argv[i]) { |
| 232 | cmdBufType = CmdBufType::None; |
| 233 | continue; |
| 234 | } |
| 235 | if (i < argc && std::string("terrible") == argv[i]) { |
| 236 | cmdBufType = CmdBufType::Terrible; |
| 237 | continue; |
| 238 | } |
| 239 | fprintf(stderr, "--command-buffer expects a command buffer name (none, terrible)\n"); |
| 240 | return false; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 241 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 242 | if (std::string("-h") == argv[i] || std::string("--help") == argv[i]) { |
| 243 | printf("Usage: %s [-b BACKEND] [-c COMMAND_BUFFER]\n", argv[0]); |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 244 | printf(" BACKEND is one of: d3d12, metal, null, opengl, vulkan\n"); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 245 | printf(" COMMAND_BUFFER is one of: none, terrible\n"); |
| 246 | return false; |
| 247 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 248 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 249 | return true; |
| 250 | } |
| 251 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 252 | void DoFlush() { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 253 | if (cmdBufType == CmdBufType::Terrible) { |
Corentin Wallez | a5696c7 | 2018-08-13 08:24:01 +0200 | [diff] [blame] | 254 | bool c2sSuccess = c2sBuf->Flush(); |
| 255 | bool s2cSuccess = s2cBuf->Flush(); |
| 256 | |
| 257 | ASSERT(c2sSuccess && s2cSuccess); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 258 | } |
| 259 | glfwPollEvents(); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 260 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 261 | |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 262 | bool ShouldQuit() { |
| 263 | return glfwWindowShouldClose(window); |
| 264 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 265 | |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 266 | GLFWwindow* GetGLFWWindow() { |
| 267 | return window; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 268 | } |