Skip to content

Commit 9acb37f

Browse files
committed
Enable C++ 20
1 parent 459c781 commit 9acb37f

File tree

9 files changed

+72
-52
lines changed

9 files changed

+72
-52
lines changed

cmake/3rdparty/dxc.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ target_include_directories(dxc INTERFACE "${get_include}")
1919
if (NOT WIN32)
2020
target_compile_definitions(dxc INTERFACE __EMULATE_UUID)
2121
endif()
22+
23+
if (CMAKE_SIZEOF_VOID_P STREQUAL "4" AND NOT CMAKE_CROSSCOMPILING)
24+
message(FATAL_ERROR "x86 build is not supported due to lack of dxc binaries for this platform")
25+
endif()

cmake/compiler_settings.cmake

+46-32
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
set(CMAKE_CXX_STANDARD 17)
1+
set(CMAKE_CXX_STANDARD 20)
22
set(CMAKE_CXX_STANDARD_REQUIRED ON)
33
set(CMAKE_CXX_EXTENSIONS OFF)
44
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
55

6-
if (MSVC)
7-
add_compile_definitions(
8-
UNICODE
9-
_UNICODE
10-
_CRT_SECURE_NO_WARNINGS
11-
NOMINMAX
12-
)
13-
add_compile_options(
14-
/MP
15-
/wd4005
16-
/wd4838
17-
/wd5051
18-
)
19-
else()
20-
add_compile_options(
21-
$<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-declarations>
22-
$<$<COMPILE_LANGUAGE:CXX>:-Wno-shorten-64-to-32>
23-
$<$<COMPILE_LANGUAGE:CXX>:-Wno-unguarded-availability-new>
24-
)
25-
endif()
6+
set(appleclang_clang_compile_options
7+
-Wno-deprecated-anon-enum-enum-conversion
8+
)
9+
set(appleclang_compile_options
10+
-Wno-deprecated-declarations
11+
-Wno-deprecated-volatile
12+
-Wno-shorten-64-to-32
13+
-Wno-unguarded-availability-new
14+
)
15+
set(gpu_compile_options
16+
-Wno-deprecated-enum-enum-conversion
17+
)
18+
set(msvc_compile_options
19+
/MP
20+
/wd4005
21+
/wd4838
22+
/wd5051
23+
)
24+
add_compile_options(
25+
"$<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:${appleclang_clang_compile_options}>"
26+
"$<$<COMPILE_LANG_AND_ID:CXX,AppleClang>:${appleclang_compile_options}>"
27+
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:${gpu_compile_options}>"
28+
"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${msvc_compile_options}>"
29+
)
2630

27-
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
28-
add_compile_definitions(TARGET_IOS=1)
29-
elseif (CMAKE_SYSTEM_NAME STREQUAL "tvOS")
30-
add_compile_definitions(TARGET_TVOS=1)
31-
else()
32-
add_compile_definitions(TARGET_MACOS=1)
33-
endif()
34-
35-
if (CMAKE_SIZEOF_VOID_P STREQUAL "4" AND NOT CMAKE_CROSSCOMPILING)
36-
message(FATAL_ERROR "x86 build is not supported")
37-
endif()
31+
set(msvc_compile_definitions
32+
_CRT_SECURE_NO_WARNINGS
33+
_UNICODE
34+
NOMINMAX
35+
UNICODE
36+
)
37+
set(darwin_compile_definitions
38+
TARGET_MACOS=1
39+
)
40+
set(ios_compile_definitions
41+
TARGET_IOS=1
42+
)
43+
set(tvos_compile_definitions
44+
TARGET_TVOS=1
45+
)
46+
add_compile_definitions(
47+
"$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:${msvc_compile_definitions}>"
48+
"$<$<PLATFORM_ID:Darwin>:${darwin_compile_definitions}>"
49+
"$<$<PLATFORM_ID:iOS>:${ios_compile_definitions}>"
50+
"$<$<PLATFORM_ID:tvOS>:${tvos_compile_definitions}>"
51+
)

src/FlyCube/CommandList/DXCommandList.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,14 @@ void DXCommandList::ResolveQueryData(const std::shared_ptr<QueryHeap>& query_hea
722722

723723
decltype(auto) dx_query_heap = query_heap->As<DXRayTracingQueryHeap>();
724724
decltype(auto) dx_dst_buffer = dst_buffer->As<DXResource>();
725-
m_command_list->ResourceBarrier(
726-
1, &CD3DX12_RESOURCE_BARRIER::Transition(dx_query_heap.GetResource().Get(), D3D12_RESOURCE_STATE_COMMON,
727-
D3D12_RESOURCE_STATE_COPY_SOURCE, 0));
725+
auto common_to_copy_barrier = CD3DX12_RESOURCE_BARRIER::Transition(
726+
dx_query_heap.GetResource().Get(), D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_SOURCE, 0);
727+
m_command_list->ResourceBarrier(1, &common_to_copy_barrier);
728728
m_command_list->CopyBufferRegion(dx_dst_buffer.resource.Get(), dst_offset, dx_query_heap.GetResource().Get(),
729729
first_query * sizeof(uint64_t), query_count * sizeof(uint64_t));
730-
m_command_list->ResourceBarrier(
731-
1, &CD3DX12_RESOURCE_BARRIER::Transition(dx_query_heap.GetResource().Get(), D3D12_RESOURCE_STATE_COPY_SOURCE,
732-
D3D12_RESOURCE_STATE_COMMON, 0));
730+
auto copy_to_common_barrier = CD3DX12_RESOURCE_BARRIER::Transition(
731+
dx_query_heap.GetResource().Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON, 0);
732+
m_command_list->ResourceBarrier(1, &copy_to_common_barrier);
733733
}
734734

735735
ComPtr<ID3D12GraphicsCommandList> DXCommandList::GetCommandList()

src/FlyCube/HLSLCompiler/DXCLoader.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ HRESULT Test(dxc::DxcDllSupport& dll_support, ShaderBlobType target)
4545

4646
std::unique_ptr<dxc::DxcDllSupport> Load(const std::string& path, ShaderBlobType target)
4747
{
48+
std::u8string u8path(path.begin(), path.end());
4849
#if defined(_WIN32)
49-
auto dxcompiler_path = std::filesystem::u8path(path) / "dxcompiler.dll";
50+
auto dxcompiler_path = std::filesystem::path(u8path) / "dxcompiler.dll";
5051
#elif defined(__APPLE__)
51-
auto dxcompiler_path = std::filesystem::u8path(path) / "libdxcompiler.dylib";
52+
auto dxcompiler_path = std::filesystem::path(u8path) / "libdxcompiler.dylib";
5253
#else
53-
auto dxcompiler_path = std::filesystem::u8path(path) / "libdxcompiler.so";
54+
auto dxcompiler_path = std::filesystem::path(u8path) / "libdxcompiler.so";
5455
#endif
5556
if (!std::filesystem::exists(dxcompiler_path)) {
5657
return {};
5758
}
5859

5960
#if defined(_WIN32)
60-
auto dxil_path = std::filesystem::u8path(path) / "dxil.dll";
61+
auto dxil_path = std::filesystem::path(u8path) / "dxil.dll";
6162
std::unique_ptr<dxc::DxcDllSupport> dll_support_dxil;
6263
if (target == ShaderBlobType::kDXIL) {
6364
dll_support_dxil = std::make_unique<dxc::DxcDllSupport>();

src/FlyCube/Instance/DXInstance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool EnableAgilitySDKIfExist(uint32_t version, const std::string_view& path)
4444
#endif
4545

4646
EXPORT_AGILITY_SDK const UINT D3D12SDKVersion = 4;
47-
EXPORT_AGILITY_SDK const char* D3D12SDKPath = u8".\\D3D12\\";
47+
EXPORT_AGILITY_SDK const char* D3D12SDKPath = ".\\D3D12\\";
4848

4949
#ifndef AGILITY_SDK_REQUIRED
5050
static bool optional_agility_sdk = EnableAgilitySDKIfExist(D3D12SDKVersion, D3D12SDKPath);

src/FlyCube/Pipeline/DXComputePipeline.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ DXComputePipeline::DXComputePipeline(DXDevice& device, const ComputePipelineDesc
3535

3636
ComPtr<ID3D12Device2> device2;
3737
m_device.GetDevice().As(&device2);
38-
ASSERT_SUCCEEDED(device2->CreatePipelineState(&compute_state_builder.GetDesc(), IID_PPV_ARGS(&m_pipeline_state)));
38+
auto pipeline_desc = compute_state_builder.GetDesc();
39+
ASSERT_SUCCEEDED(device2->CreatePipelineState(&pipeline_desc, IID_PPV_ARGS(&m_pipeline_state)));
3940
}
4041

4142
PipelineType DXComputePipeline::GetPipelineType() const

src/FlyCube/Pipeline/DXGraphicsPipeline.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ DXGraphicsPipeline::DXGraphicsPipeline(DXDevice& device, const GraphicsPipelineD
236236

237237
ComPtr<ID3D12Device2> device2;
238238
m_device.GetDevice().As(&device2);
239-
ASSERT_SUCCEEDED(device2->CreatePipelineState(&graphics_state_builder.GetDesc(), IID_PPV_ARGS(&m_pipeline_state)));
239+
auto pipeline_desc = graphics_state_builder.GetDesc();
240+
ASSERT_SUCCEEDED(device2->CreatePipelineState(&pipeline_desc, IID_PPV_ARGS(&m_pipeline_state)));
240241
}
241242

242243
void DXGraphicsPipeline::ParseInputLayout(const std::shared_ptr<Shader>& shader)

src/FlyCube/QueryHeap/DXRayTracingQueryHeap.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ DXRayTracingQueryHeap::DXRayTracingQueryHeap(DXDevice& device, QueryHeapType typ
1313
{
1414
auto desc = CD3DX12_RESOURCE_DESC::Buffer(count * sizeof(uint64_t));
1515
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
16-
m_device.GetDevice()->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
17-
D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr,
18-
IID_PPV_ARGS(&m_resource));
16+
auto heap_properties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
17+
m_device.GetDevice()->CreateCommittedResource(&heap_properties, D3D12_HEAP_FLAG_NONE, &desc,
18+
D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&m_resource));
1919
}
2020

2121
QueryHeapType DXRayTracingQueryHeap::GetType() const

src/FlyCube/Resource/DXResource.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ void DXResource::CommitMemory(MemoryType memory_type)
5656
if (m_device.IsCreateNotZeroedAvailable()) {
5757
flags |= D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
5858
}
59-
60-
m_device.GetDevice()->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(GetHeapType(m_memory_type)), flags, &desc,
61-
ConvertState(GetInitialState()), p_clear_value,
62-
IID_PPV_ARGS(&resource));
59+
auto heap_properties = CD3DX12_HEAP_PROPERTIES(GetHeapType(m_memory_type));
60+
m_device.GetDevice()->CreateCommittedResource(&heap_properties, flags, &desc, ConvertState(GetInitialState()),
61+
p_clear_value, IID_PPV_ARGS(&resource));
6362
}
6463

6564
void DXResource::BindMemory(const std::shared_ptr<Memory>& memory, uint64_t offset)

0 commit comments

Comments
 (0)