From 02653538896522490976132e04c95d078b2d22f6 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Tue, 22 Aug 2023 14:29:22 -0400 Subject: [PATCH] Change C++ standard to C++17. C++20 is not well support with all our compilation environments. --- CMakeLists.txt | 6 +++--- build.gradle | 4 ++-- include/ppx/application.h | 2 +- include/ppx/command_line_parser.h | 2 +- include/ppx/window.h | 2 +- include/ppx/xr_component.h | 4 +--- src/ppx/application.cpp | 13 ++++++------ src/ppx/grfx/vk/vk_device.cpp | 8 ++++---- src/ppx/xr_component.cpp | 34 +++++++++++++++---------------- 9 files changed, 36 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d50024d6..2f1f750e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,10 +110,10 @@ if(MSVC) # 26812: unscoped enums are widely used by the project and dependencies. set(MSVC_DISABLED_WARNINGS "/wd26812") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MSVC_DISABLED_WARNINGS} /MP") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DISABLED_WARNINGS} /MP /Zc:__cplusplus /std:c++20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVC_DISABLED_WARNINGS} /MP /Zc:__cplusplus /std:c++17") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ - -std=c++20 \ + -std=c++17 \ -fdiagnostics-color=always \ -Wno-nullability-completeness \ -Wno-deprecated-anon-enum-enum-conversion \ @@ -133,7 +133,7 @@ else() endif () endif() -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) # ------------------------------------------------------------------------------ # Configure PPX directories. diff --git a/build.gradle b/build.gradle index 988e79de5..ed73f506a 100644 --- a/build.gradle +++ b/build.gradle @@ -105,11 +105,11 @@ subprojects { '-DPPX_BUILD_TESTS=FALSE' } if (project.name.contains("_xr")) { - cppFlags '-std=c++20', + cppFlags '-std=c++17', '-DXR_USE_PLATFORM_ANDROID' } else { - cppFlags '-std=c++20' + cppFlags '-std=c++17' } if (project.hasProperty('DXC_PATH')) { diff --git a/include/ppx/application.h b/include/ppx/application.h index 71a2d8ed3..686c8ae76 100644 --- a/include/ppx/application.h +++ b/include/ppx/application.h @@ -229,7 +229,7 @@ struct StandardOptions // Flags std::shared_ptr> pListGpus; std::shared_ptr> pUseSoftwareRenderer; -#if not defined(PPX_LINUX_HEADLESS) +#if !defined(PPX_LINUX_HEADLESS) std::shared_ptr> pHeadless; #endif std::shared_ptr> pDeterministic; diff --git a/include/ppx/command_line_parser.h b/include/ppx/command_line_parser.h index 8a54bd6c4..637183753 100644 --- a/include/ppx/command_line_parser.h +++ b/include/ppx/command_line_parser.h @@ -46,7 +46,7 @@ class CliOptions public: CliOptions() = default; - bool HasExtraOption(const std::string& option) const { return mAllOptions.contains(option); } + bool HasExtraOption(const std::string& option) const { return mAllOptions.find(option) != mAllOptions.end(); } // Returns the number of unique options and flags that were specified on the commandline, // not counting multiple appearances of the same flag such as: --assets-path a --assets-path b diff --git a/include/ppx/window.h b/include/ppx/window.h index 7e3fabe06..83289e7ca 100644 --- a/include/ppx/window.h +++ b/include/ppx/window.h @@ -43,7 +43,7 @@ struct WindowSize WindowSize(uint32_t width_, uint32_t height_) : width(width_), height(height_) {} - bool operator==(const WindowSize&) const = default; + bool operator==(const WindowSize& other) const { return width == other.width && height == other.height; }; }; class Window diff --git a/include/ppx/xr_component.h b/include/ppx/xr_component.h index 73e6026a9..924f25cd7 100644 --- a/include/ppx/xr_component.h +++ b/include/ppx/xr_component.h @@ -188,9 +188,7 @@ class XrComponent std::optional mFarPlaneForFrame = std::nullopt; bool mShouldSubmitDepthInfo = false; - XrFrameState mFrameState = { - .type = XR_TYPE_FRAME_STATE, - }; + XrFrameState mFrameState = {XR_TYPE_FRAME_STATE}; XrEventDataBuffer mEventDataBuffer; diff --git a/src/ppx/application.cpp b/src/ppx/application.cpp index 5045c9c00..8b0f259ec 100644 --- a/src/ppx/application.cpp +++ b/src/ppx/application.cpp @@ -842,7 +842,7 @@ void Application::InitStandardKnobs() "Select the gpu with the given index. To determine the set of valid " "indices use --list-gpus."); -#if not defined(PPX_LINUX_HEADLESS) +#if !defined(PPX_LINUX_HEADLESS) mStandardOpts.pHeadless = mKnobManager.CreateKnob>("headless", false); mStandardOpts.pHeadless->SetFlagDescription( @@ -1760,11 +1760,12 @@ bool Application::RecordMetricData(metrics::MetricID id, const metrics::MetricDa void Application::UpdateAppMetrics() { // This data is the same for every call to increase the frame count. - static const metrics::MetricData frameCountData = { - .type = metrics::MetricType::COUNTER, - .counter = { - .increment = 1}, - }; + static const metrics::MetricData frameCountData = []() { + metrics::MetricData data = {}; + data.type = metrics::MetricType::COUNTER; + data.counter.increment = 1; + return data; + }(); if (!HasActiveMetricsRun()) { return; diff --git a/src/ppx/grfx/vk/vk_device.cpp b/src/ppx/grfx/vk/vk_device.cpp index e5b789425..7ca00f4f2 100644 --- a/src/ppx/grfx/vk/vk_device.cpp +++ b/src/ppx/grfx/vk/vk_device.cpp @@ -72,7 +72,7 @@ Result Device::ConfigureQueueInfo(const grfx::DeviceCreateInfo* pCreateInfo, std createdQueues.insert(mGraphicsQueueFamilyIndex); } // Compute - if (mComputeQueueFamilyIndex != PPX_VALUE_IGNORED && !createdQueues.contains(mComputeQueueFamilyIndex)) { + if (mComputeQueueFamilyIndex != PPX_VALUE_IGNORED && createdQueues.find(mComputeQueueFamilyIndex) == createdQueues.end()) { VkDeviceQueueCreateInfo vkci = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; vkci.queueFamilyIndex = mComputeQueueFamilyIndex; vkci.queueCount = pCreateInfo->pGpu->GetComputeQueueCount(); @@ -80,11 +80,11 @@ Result Device::ConfigureQueueInfo(const grfx::DeviceCreateInfo* pCreateInfo, std queueCreateInfos.push_back(vkci); createdQueues.insert(mComputeQueueFamilyIndex); } - else if (createdQueues.contains(mComputeQueueFamilyIndex)) { + else if (createdQueues.find(mComputeQueueFamilyIndex) != createdQueues.end()) { PPX_LOG_WARN("Graphics queue will be shared with compute queue."); } // Transfer - if (mTransferQueueFamilyIndex != PPX_VALUE_IGNORED && !createdQueues.contains(mTransferQueueFamilyIndex)) { + if (mTransferQueueFamilyIndex != PPX_VALUE_IGNORED && createdQueues.find(mTransferQueueFamilyIndex) == createdQueues.end()) { VkDeviceQueueCreateInfo vkci = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; vkci.queueFamilyIndex = mTransferQueueFamilyIndex; vkci.queueCount = pCreateInfo->pGpu->GetTransferQueueCount(); @@ -92,7 +92,7 @@ Result Device::ConfigureQueueInfo(const grfx::DeviceCreateInfo* pCreateInfo, std queueCreateInfos.push_back(vkci); createdQueues.insert(mTransferQueueFamilyIndex); } - else if (createdQueues.contains(mTransferQueueFamilyIndex)) { + else if (createdQueues.find(mTransferQueueFamilyIndex) != createdQueues.end()) { PPX_LOG_WARN("Transfer queue will be shared with graphics or compute queue."); } } diff --git a/src/ppx/xr_component.cpp b/src/ppx/xr_component.cpp index 4e8e13f4a..966a37751 100644 --- a/src/ppx/xr_component.cpp +++ b/src/ppx/xr_component.cpp @@ -453,9 +453,7 @@ void XrComponent::HandleSessionStateChangedEvent(const XrEventDataSessionStateCh void XrComponent::BeginFrame() { - XrFrameWaitInfo frameWaitInfo = { - .type = XR_TYPE_FRAME_WAIT_INFO, - }; + XrFrameWaitInfo frameWaitInfo = {XR_TYPE_FRAME_WAIT_INFO}; CHECK_XR_CALL(xrWaitFrame(mSession, &frameWaitInfo, &mFrameState)); mShouldRender = mFrameState.shouldRender; @@ -465,16 +463,17 @@ void XrComponent::BeginFrame() mFarPlaneForFrame = std::nullopt; // Create projection matrices and view matrices for each eye. + XrViewLocateInfo viewLocateInfo = { - .type = XR_TYPE_VIEW_LOCATE_INFO, - .viewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, - .displayTime = mFrameState.predictedDisplayTime, - .space = mRefSpace, + XR_TYPE_VIEW_LOCATE_INFO, // type + nullptr, // next + XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, // viewConfigurationType + mFrameState.predictedDisplayTime, // displayTime + mRefSpace, // space }; - XrViewState viewState = { - .type = XR_TYPE_VIEW_STATE, - }; + XrViewState viewState = {XR_TYPE_VIEW_STATE}; + uint32_t viewCount = 0; CHECK_XR_CALL(xrLocateViews(mSession, &viewLocateInfo, &viewState, (uint32_t)mViews.size(), &viewCount, mViews.data())); @@ -484,9 +483,7 @@ void XrComponent::BeginFrame() } // Begin frame. - XrFrameBeginInfo frameBeginInfo = { - .type = XR_TYPE_FRAME_BEGIN_INFO, - }; + XrFrameBeginInfo frameBeginInfo = {XR_TYPE_FRAME_BEGIN_INFO}; XrResult result = xrBeginFrame(mSession, &frameBeginInfo); if (result != XR_SUCCESS) { @@ -590,11 +587,12 @@ void XrComponent::EndFrame(const std::vector& swapchains, ui // Submit layers and end frame. XrFrameEndInfo frameEndInfo = { - .type = XR_TYPE_FRAME_END_INFO, - .displayTime = mFrameState.predictedDisplayTime, - .environmentBlendMode = blendMode, - .layerCount = static_cast(layers.size()), - .layers = layers.data(), + XR_TYPE_FRAME_END_INFO, // type + nullptr, // next + mFrameState.predictedDisplayTime, // displayTime + blendMode, // environmentBlendMode + static_cast(layers.size()), // layerCount + layers.data(), // layers }; CHECK_XR_CALL(xrEndFrame(mSession, &frameEndInfo));