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 | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 18 | #include "common/Log.h" |
Corentin Wallez | 0b186b1 | 2017-07-12 12:56:05 -0400 | [diff] [blame] | 19 | #include "common/Platform.h" |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 20 | #include "utils/BackendBinding.h" |
Corentin Wallez | 3a1746e | 2020-01-15 13:14:12 +0000 | [diff] [blame] | 21 | #include "utils/GLFWUtils.h" |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 22 | #include "utils/TerribleCommandBuffer.h" |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 23 | |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 24 | #include <dawn/dawn_proc.h> |
Corentin Wallez | 3e371b1 | 2018-07-18 14:32:45 +0200 | [diff] [blame] | 25 | #include <dawn/dawn_wsi.h> |
Corentin Wallez | dcb71a1 | 2018-08-02 22:27:57 +0200 | [diff] [blame] | 26 | #include <dawn_native/DawnNative.h> |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 27 | #include <dawn_wire/WireClient.h> |
| 28 | #include <dawn_wire/WireServer.h> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 29 | #include "GLFW/glfw3.h" |
| 30 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 31 | #include <algorithm> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 32 | #include <cstring> |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 33 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 34 | void PrintDeviceError(WGPUErrorType errorType, const char* message, void*) { |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 35 | const char* errorTypeName = ""; |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 36 | switch (errorType) { |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 37 | case WGPUErrorType_Validation: |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 38 | errorTypeName = "Validation"; |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 39 | break; |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 40 | case WGPUErrorType_OutOfMemory: |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 41 | errorTypeName = "Out of memory"; |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 42 | break; |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 43 | case WGPUErrorType_Unknown: |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 44 | errorTypeName = "Unknown"; |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 45 | break; |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 46 | case WGPUErrorType_DeviceLost: |
Corentin Wallez | 95586ff | 2019-12-05 11:13:01 +0000 | [diff] [blame] | 47 | errorTypeName = "Device lost"; |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 48 | break; |
| 49 | default: |
| 50 | UNREACHABLE(); |
| 51 | return; |
| 52 | } |
Corentin Wallez | dc3317d | 2019-12-06 18:21:39 +0000 | [diff] [blame] | 53 | dawn::ErrorLog() << errorTypeName << " error: " << message; |
Corentin Wallez | 4b410a3 | 2017-04-20 14:42:36 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Corentin Wallez | 52cbcb4 | 2018-01-19 12:52:03 -0500 | [diff] [blame] | 56 | void PrintGLFWError(int code, const char* message) { |
Corentin Wallez | dc3317d | 2019-12-06 18:21:39 +0000 | [diff] [blame] | 57 | dawn::ErrorLog() << "GLFW error: " << code << " - " << message; |
Corentin Wallez | 52cbcb4 | 2018-01-19 12:52:03 -0500 | [diff] [blame] | 58 | } |
| 59 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 60 | enum class CmdBufType { |
| 61 | None, |
| 62 | Terrible, |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 63 | // TODO(cwallez@chromium.org): double terrible cmdbuf |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 64 | }; |
| 65 | |
Corentin Wallez | 275817a | 2017-07-12 12:43:24 -0400 | [diff] [blame] | 66 | // Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on |
| 67 | // their respective platforms, and Vulkan is preferred to OpenGL |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 68 | #if defined(DAWN_ENABLE_BACKEND_D3D12) |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 69 | static wgpu::BackendType backendType = wgpu::BackendType::D3D12; |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 70 | #elif defined(DAWN_ENABLE_BACKEND_METAL) |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 71 | static wgpu::BackendType backendType = wgpu::BackendType::Metal; |
Corentin Wallez | f1ded9b | 2018-07-18 13:52:46 +0200 | [diff] [blame] | 72 | #elif defined(DAWN_ENABLE_BACKEND_VULKAN) |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 73 | static wgpu::BackendType backendType = wgpu::BackendType::Vulkan; |
| 74 | #elif defined(DAWN_ENABLE_BACKEND_OPENGL) |
| 75 | static wgpu::BackendType backendType = wgpu::BackendType::OpenGL; |
Austin Eng | fc2bac7 | 2017-06-05 17:08:55 -0400 | [diff] [blame] | 76 | #else |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 77 | # error |
Austin Eng | fc2bac7 | 2017-06-05 17:08:55 -0400 | [diff] [blame] | 78 | #endif |
| 79 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 80 | static CmdBufType cmdBufType = CmdBufType::Terrible; |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 81 | static std::unique_ptr<dawn_native::Instance> instance; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 82 | static utils::BackendBinding* binding = nullptr; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 83 | |
| 84 | static GLFWwindow* window = nullptr; |
| 85 | |
Austin Eng | e2c8513 | 2019-02-11 21:50:16 +0000 | [diff] [blame] | 86 | static dawn_wire::WireServer* wireServer = nullptr; |
| 87 | static dawn_wire::WireClient* wireClient = nullptr; |
Corentin Wallez | bdc8677 | 2018-07-26 15:07:57 +0200 | [diff] [blame] | 88 | static utils::TerribleCommandBuffer* c2sBuf = nullptr; |
| 89 | static utils::TerribleCommandBuffer* s2cBuf = nullptr; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 90 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 91 | wgpu::Device CreateCppDawnDevice() { |
Corentin Wallez | 52cbcb4 | 2018-01-19 12:52:03 -0500 | [diff] [blame] | 92 | glfwSetErrorCallback(PrintGLFWError); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 93 | if (!glfwInit()) { |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 94 | return wgpu::Device(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 97 | // Create the test window and discover adapters using it (esp. for OpenGL) |
| 98 | utils::SetupGLFWWindowHintsForBackend(backendType); |
Corentin Wallez | 47a6a94 | 2020-10-17 23:31:37 +0000 | [diff] [blame^] | 99 | glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); |
Corentin Wallez | 6ed9cbf | 2018-07-18 15:32:04 +0200 | [diff] [blame] | 100 | window = glfwCreateWindow(640, 480, "Dawn window", nullptr, nullptr); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 101 | if (!window) { |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 102 | return wgpu::Device(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 105 | instance = std::make_unique<dawn_native::Instance>(); |
| 106 | utils::DiscoverAdapter(instance.get(), window, backendType); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 107 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 108 | // Get an adapter for the backend to use, and create the device. |
| 109 | dawn_native::Adapter backendAdapter; |
| 110 | { |
| 111 | std::vector<dawn_native::Adapter> adapters = instance->GetAdapters(); |
| 112 | auto adapterIt = std::find_if(adapters.begin(), adapters.end(), |
| 113 | [](const dawn_native::Adapter adapter) -> bool { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 114 | wgpu::AdapterProperties properties; |
| 115 | adapter.GetProperties(&properties); |
| 116 | return properties.backendType == backendType; |
| 117 | }); |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 118 | ASSERT(adapterIt != adapters.end()); |
| 119 | backendAdapter = *adapterIt; |
| 120 | } |
| 121 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 122 | WGPUDevice backendDevice = backendAdapter.CreateDevice(); |
Austin Eng | 45f9730 | 2019-03-11 16:52:42 +0000 | [diff] [blame] | 123 | DawnProcTable backendProcs = dawn_native::GetProcs(); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 124 | |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 125 | binding = utils::CreateBinding(backendType, window, backendDevice); |
| 126 | if (binding == nullptr) { |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 127 | return wgpu::Device(); |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | // Choose whether to use the backend procs and devices directly, or set up the wire. |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 131 | WGPUDevice cDevice = nullptr; |
Austin Eng | 45f9730 | 2019-03-11 16:52:42 +0000 | [diff] [blame] | 132 | DawnProcTable procs; |
Corentin Wallez | bb5696b | 2019-02-12 15:48:15 +0000 | [diff] [blame] | 133 | |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 134 | switch (cmdBufType) { |
| 135 | case CmdBufType::None: |
Corentin Wallez | 583e9a8 | 2017-05-29 11:30:29 -0700 | [diff] [blame] | 136 | procs = backendProcs; |
| 137 | cDevice = backendDevice; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 138 | break; |
| 139 | |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 140 | case CmdBufType::Terrible: { |
| 141 | c2sBuf = new utils::TerribleCommandBuffer(); |
| 142 | s2cBuf = new utils::TerribleCommandBuffer(); |
Corentin Wallez | 682a825 | 2017-05-09 15:34:13 +0200 | [diff] [blame] | 143 | |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 144 | dawn_wire::WireServerDescriptor serverDesc = {}; |
| 145 | serverDesc.device = backendDevice; |
| 146 | serverDesc.procs = &backendProcs; |
| 147 | serverDesc.serializer = s2cBuf; |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 148 | |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 149 | wireServer = new dawn_wire::WireServer(serverDesc); |
| 150 | c2sBuf->SetHandler(wireServer); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 151 | |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 152 | dawn_wire::WireClientDescriptor clientDesc = {}; |
| 153 | clientDesc.serializer = c2sBuf; |
Austin Eng | 6a5418a | 2019-07-19 16:01:48 +0000 | [diff] [blame] | 154 | |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 155 | wireClient = new dawn_wire::WireClient(clientDesc); |
Austin Eng | 8750913 | 2020-10-16 15:21:16 +0000 | [diff] [blame] | 156 | cDevice = wireClient->GetDevice(); |
| 157 | procs = dawn_wire::client::GetProcs(); |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 158 | s2cBuf->SetHandler(wireClient); |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 159 | } break; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 160 | } |
| 161 | |
Corentin Wallez | 9649682 | 2019-10-15 11:44:38 +0000 | [diff] [blame] | 162 | dawnProcSetProcs(&procs); |
Austin Eng | 45ea7e6 | 2019-08-27 21:43:56 +0000 | [diff] [blame] | 163 | procs.deviceSetUncapturedErrorCallback(cDevice, PrintDeviceError, nullptr); |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 164 | return wgpu::Device::Acquire(cDevice); |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 167 | uint64_t GetSwapChainImplementation() { |
| 168 | return binding->GetSwapChainImplementation(); |
| 169 | } |
| 170 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 171 | wgpu::TextureFormat GetPreferredSwapChainTextureFormat() { |
Corentin Wallez | b91022d | 2018-01-19 12:52:25 -0500 | [diff] [blame] | 172 | DoFlush(); |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 173 | return static_cast<wgpu::TextureFormat>(binding->GetPreferredSwapChainTextureFormat()); |
Corentin Wallez | 2e31e8f | 2017-09-21 12:54:53 -0400 | [diff] [blame] | 174 | } |
| 175 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 176 | wgpu::SwapChain GetSwapChain(const wgpu::Device& device) { |
| 177 | wgpu::SwapChainDescriptor swapChainDesc; |
Corentin Wallez | 7be2a71 | 2019-02-15 11:15:58 +0000 | [diff] [blame] | 178 | swapChainDesc.implementation = GetSwapChainImplementation(); |
Corentin Wallez | d87e676 | 2020-01-23 17:20:38 +0000 | [diff] [blame] | 179 | return device.CreateSwapChain(nullptr, &swapChainDesc); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 182 | wgpu::TextureView CreateDefaultDepthStencilView(const wgpu::Device& device) { |
| 183 | wgpu::TextureDescriptor descriptor; |
| 184 | descriptor.dimension = wgpu::TextureDimension::e2D; |
Corentin Wallez | 29353d6 | 2018-09-18 12:49:22 +0000 | [diff] [blame] | 185 | descriptor.size.width = 640; |
| 186 | descriptor.size.height = 480; |
| 187 | descriptor.size.depth = 1; |
Jiawei Shao | 8bff3b2 | 2018-12-12 09:27:16 +0000 | [diff] [blame] | 188 | descriptor.sampleCount = 1; |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 189 | descriptor.format = wgpu::TextureFormat::Depth24PlusStencil8; |
Jiawei Shao | 2030166 | 2019-02-21 00:45:19 +0000 | [diff] [blame] | 190 | descriptor.mipLevelCount = 1; |
Corentin Wallez | 04863c4 | 2019-10-25 11:36:47 +0000 | [diff] [blame] | 191 | descriptor.usage = wgpu::TextureUsage::OutputAttachment; |
Jiawei Shao | 425428f | 2018-08-27 08:44:48 +0800 | [diff] [blame] | 192 | auto depthStencilTexture = device.CreateTexture(&descriptor); |
Kai Ninomiya | 4078ed8 | 2019-08-27 17:56:23 +0000 | [diff] [blame] | 193 | return depthStencilTexture.CreateView(); |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Corentin Wallez | 9347e8f | 2017-06-19 13:15:13 -0400 | [diff] [blame] | 196 | bool InitSample(int argc, const char** argv) { |
Corentin Wallez | 862f884 | 2018-06-07 13:03:29 +0200 | [diff] [blame] | 197 | for (int i = 1; i < argc; i++) { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 198 | if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) { |
| 199 | i++; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 200 | if (i < argc && std::string("d3d12") == argv[i]) { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 201 | backendType = wgpu::BackendType::D3D12; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 202 | continue; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 203 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 204 | if (i < argc && std::string("metal") == argv[i]) { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 205 | backendType = wgpu::BackendType::Metal; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 206 | continue; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 207 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 208 | if (i < argc && std::string("null") == argv[i]) { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 209 | backendType = wgpu::BackendType::Null; |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 210 | continue; |
| 211 | } |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 212 | if (i < argc && std::string("opengl") == argv[i]) { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 213 | backendType = wgpu::BackendType::OpenGL; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 214 | continue; |
| 215 | } |
| 216 | if (i < argc && std::string("vulkan") == argv[i]) { |
Corentin Wallez | f12c9db | 2020-01-10 13:28:18 +0000 | [diff] [blame] | 217 | backendType = wgpu::BackendType::Vulkan; |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 218 | continue; |
| 219 | } |
Kai Ninomiya | 2afea0c | 2020-07-10 20:33:08 +0000 | [diff] [blame] | 220 | fprintf(stderr, |
| 221 | "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n"); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 222 | return false; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 223 | } |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 224 | if (std::string("-c") == argv[i] || std::string("--command-buffer") == argv[i]) { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 225 | i++; |
| 226 | if (i < argc && std::string("none") == argv[i]) { |
| 227 | cmdBufType = CmdBufType::None; |
| 228 | continue; |
| 229 | } |
| 230 | if (i < argc && std::string("terrible") == argv[i]) { |
| 231 | cmdBufType = CmdBufType::Terrible; |
| 232 | continue; |
| 233 | } |
| 234 | fprintf(stderr, "--command-buffer expects a command buffer name (none, terrible)\n"); |
| 235 | return false; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 236 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 237 | if (std::string("-h") == argv[i] || std::string("--help") == argv[i]) { |
| 238 | printf("Usage: %s [-b BACKEND] [-c COMMAND_BUFFER]\n", argv[0]); |
Corentin Wallez | 1bd219d | 2017-06-19 12:53:38 -0400 | [diff] [blame] | 239 | printf(" BACKEND is one of: d3d12, metal, null, opengl, vulkan\n"); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 240 | printf(" COMMAND_BUFFER is one of: none, terrible\n"); |
| 241 | return false; |
| 242 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 243 | } |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 244 | return true; |
| 245 | } |
| 246 | |
Kai Ninomiya | c16a67a | 2017-07-27 18:30:57 -0700 | [diff] [blame] | 247 | void DoFlush() { |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 248 | if (cmdBufType == CmdBufType::Terrible) { |
Corentin Wallez | a5696c7 | 2018-08-13 08:24:01 +0200 | [diff] [blame] | 249 | bool c2sSuccess = c2sBuf->Flush(); |
| 250 | bool s2cSuccess = s2cBuf->Flush(); |
| 251 | |
| 252 | ASSERT(c2sSuccess && s2cSuccess); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 253 | } |
| 254 | glfwPollEvents(); |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 255 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 256 | |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 257 | bool ShouldQuit() { |
| 258 | return glfwWindowShouldClose(window); |
| 259 | } |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 260 | |
Corentin Wallez | 931e6e8 | 2017-06-16 18:51:14 -0400 | [diff] [blame] | 261 | GLFWwindow* GetGLFWWindow() { |
| 262 | return window; |
Corentin Wallez | f07e3bd | 2017-04-20 14:38:20 -0400 | [diff] [blame] | 263 | } |