Skip to content

Commit

Permalink
Change C++ standard to C++17.
Browse files Browse the repository at this point in the history
C++20 is not well support with all our compilation environments.
  • Loading branch information
hysw committed Aug 23, 2023
1 parent 0913b6e commit 0265353
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 39 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -133,7 +133,7 @@ else()
endif ()
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)

# ------------------------------------------------------------------------------
# Configure PPX directories.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion include/ppx/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct StandardOptions
// Flags
std::shared_ptr<KnobFlag<bool>> pListGpus;
std::shared_ptr<KnobFlag<bool>> pUseSoftwareRenderer;
#if not defined(PPX_LINUX_HEADLESS)
#if !defined(PPX_LINUX_HEADLESS)
std::shared_ptr<KnobFlag<bool>> pHeadless;
#endif
std::shared_ptr<KnobFlag<bool>> pDeterministic;
Expand Down
2 changes: 1 addition & 1 deletion include/ppx/command_line_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/ppx/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions include/ppx/xr_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ class XrComponent
std::optional<float> mFarPlaneForFrame = std::nullopt;
bool mShouldSubmitDepthInfo = false;

XrFrameState mFrameState = {
.type = XR_TYPE_FRAME_STATE,
};
XrFrameState mFrameState = {XR_TYPE_FRAME_STATE};

XrEventDataBuffer mEventDataBuffer;

Expand Down
13 changes: 7 additions & 6 deletions src/ppx/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnobFlag<bool>>("headless", false);
mStandardOpts.pHeadless->SetFlagDescription(
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/ppx/grfx/vk/vk_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,27 @@ 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();
vkci.pQueuePriorities = DataPtr(queuePriorities);
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();
vkci.pQueuePriorities = DataPtr(queuePriorities);
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.");
}
}
Expand Down
34 changes: 16 additions & 18 deletions src/ppx/xr_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));

Expand All @@ -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) {
Expand Down Expand Up @@ -590,11 +587,12 @@ void XrComponent::EndFrame(const std::vector<grfx::SwapchainPtr>& swapchains, ui

// Submit layers and end frame.
XrFrameEndInfo frameEndInfo = {
.type = XR_TYPE_FRAME_END_INFO,
.displayTime = mFrameState.predictedDisplayTime,
.environmentBlendMode = blendMode,
.layerCount = static_cast<uint32_t>(layers.size()),
.layers = layers.data(),
XR_TYPE_FRAME_END_INFO, // type
nullptr, // next
mFrameState.predictedDisplayTime, // displayTime
blendMode, // environmentBlendMode
static_cast<uint32_t>(layers.size()), // layerCount
layers.data(), // layers
};

CHECK_XR_CALL(xrEndFrame(mSession, &frameEndInfo));
Expand Down

0 comments on commit 0265353

Please sign in to comment.