diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2017-12-11 05:47:18 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2017-12-11 05:47:18 +0000 |
| commit | 09b8471f2d4e0991ecaeb06394cc7492c433473a (patch) | |
| tree | bc2011dc4268f69f2ff6a4044a6aa1c1f0b0ce0c | |
| parent | CMake: Added grouping of projects in VS solution; removed VS configurations f... (diff) | |
| download | DiligentEngine-09b8471f2d4e0991ecaeb06394cc7492c433473a.tar.gz DiligentEngine-09b8471f2d4e0991ecaeb06394cc7492c433473a.zip | |
Enabled cmake build
| -rw-r--r-- | CMakeLists.txt | 13 | ||||
| m--------- | DiligentCore | 0 | ||||
| m--------- | DiligentSamples | 0 | ||||
| m--------- | DiligentTools | 0 | ||||
| -rw-r--r-- | Projects/Asteroids/CMakeLists.txt | 175 | ||||
| -rw-r--r-- | Projects/Asteroids/src/WinWrapper.cpp | 10 | ||||
| -rw-r--r-- | Projects/Asteroids/src/asteroids_DE.cpp | 3 | ||||
| -rw-r--r-- | Projects/Asteroids/src/asteroids_d3d12.cpp | 3 | ||||
| -rw-r--r-- | Projects/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | README.md | 24 |
10 files changed, 216 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 65d059c..9334eb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,11 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(DiligentEngine) -if(MSVC) - #add_compile_options(/W4) -else() - #add_compile_options(-W -Wall) -endif() - add_subdirectory(diligentcore) add_subdirectory(diligenttools) -add_subdirectory(diligentsamples)
\ No newline at end of file +add_subdirectory(diligentsamples) +add_subdirectory(projects) + +if(MSVC) + set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT Asteroids) +endif() diff --git a/DiligentCore b/DiligentCore -Subproject 20cca1f50b9e074cf2823b6769eca74d0963957 +Subproject 5a9165217b6c7b6cb06886bf641cbcea1713046 diff --git a/DiligentSamples b/DiligentSamples -Subproject 24fcb44c6199faaee4cf4d677a19175d04fdbc1 +Subproject d14ec0789810d1337b854fc1c9f9493c68a02e5 diff --git a/DiligentTools b/DiligentTools -Subproject e1a00408e79991c439e15e461cb0622e44f7a70 +Subproject b2f89015ef08af5233057e32941f2e9d952cda2 diff --git a/Projects/Asteroids/CMakeLists.txt b/Projects/Asteroids/CMakeLists.txt new file mode 100644 index 0000000..8a3be34 --- /dev/null +++ b/Projects/Asteroids/CMakeLists.txt @@ -0,0 +1,175 @@ +cmake_minimum_required (VERSION 3.8) + +project(Asteroids CXX) + +set(SOURCE + src/asteroids_d3d11.cpp + src/asteroids_d3d12.cpp + src/asteroids_DE.cpp + src/camera.cpp + src/DDSTextureLoader.cpp + src/mesh.cpp + src/simplexnoise1234.c + src/simulation.cpp + src/texture.cpp + src/WinWrapper.cpp +) + +set(INCLUDE + src/asteroids_d3d11.h + src/asteroids_d3d12.h + src/asteroids_DE.h + src/camera.h + src/dds.h + src/DDSTextureLoader.h + src/descriptor.h + src/mesh.h + src/noise.h + src/settings.h + src/simplexnoise1234.h + src/simulation.h + src/subset_d3d12.h + src/texture.h + src/upload_heap.h + src/util.h +) + +set(SHADERS + src/asteroid_ps.hlsl + src/asteroid_ps_d3d11.hlsl + src/asteroid_vs.hlsl + src/font_ps.hlsl + src/skybox_ps.hlsl + src/skybox_vs.hlsl + src/sprite_ps.hlsl + src/sprite_vs.hlsl +) + +set(GUI + src/font.h + src/gui.h + src/intel_clear_bd_50_usascii.inl + src/sprite.h + src/stb_font_consolas_bold_50_usascii.inl +) + +set(MEDIA + DiligentD3D11.dds + DiligentD3D12.dds + DiligentGL.dds + directx11.dds + directx12.dds + starbox_1024.dds +) + +if(WIN32) + add_executable(Asteroids WIN32 + ${SOURCE} + ${INCLUDE} + ${SHADERS} + ${GUI} + ${MEDIA} + SDK/Include/d3dx12.h + src/common_defines.h + readme.md + ) + set_target_properties(Asteroids PROPERTIES + LINK_FLAGS "/SUBSYSTEM:CONSOLE" + VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + ) + copy_required_dlls(Asteroids) + +else() + message(FATAL_ERROR "Unsupported platform") +endif() + + +add_custom_target(AsteroidsShaders) + +set(SHADER_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/Shaders) +file(MAKE_DIRECTORY ${SHADER_OUTPUT_DIR}) + +macro(COMPILE_SHADER FILE SHADER_MODEL) + get_filename_component(FILE_NAME_WE ${FILE} NAME_WE) + get_filename_component(FILE_NAME ${FILE} NAME) + set(OUT_FILE ${SHADER_OUTPUT_DIR}/${FILE_NAME_WE}.h) + + add_custom_command(TARGET AsteroidsShaders + # Unfortunately it is not possible to set TARGET directly to GraphicsEngineD3D12-static/shared + # because PRE_BUILD is only supported on Visual Studio 8 or later. For all other generators + # PRE_BUILD is treated as PRE_LINK. + COMMAND ${FXC} /T ${SHADER_MODEL} ${FILE_NAME} /E ${FILE_NAME_WE} /O3 /Vn g_${FILE_NAME_WE} /Fh ${OUT_FILE} /nologo + MAIN_DEPENDENCY ${FILE} # the primary input source file to the command + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src + COMMENT "Compiling shader ${FILE}" + VERBATIM + ) +endmacro() + +COMPILE_SHADER(src/asteroid_ps.hlsl ps_5_1) +COMPILE_SHADER(src/asteroid_ps_d3d11.hlsl ps_5_0) +COMPILE_SHADER(src/asteroid_vs.hlsl vs_5_0) +COMPILE_SHADER(src/font_ps.hlsl ps_5_0) +COMPILE_SHADER(src/skybox_ps.hlsl ps_5_0) +COMPILE_SHADER(src/skybox_vs.hlsl vs_5_0) +COMPILE_SHADER(src/sprite_ps.hlsl ps_5_0) +COMPILE_SHADER(src/sprite_vs.hlsl vs_5_0) + +add_dependencies(Asteroids AsteroidsShaders) + +target_compile_definitions(Asteroids PRIVATE NOMINMAX) + +target_include_directories(Asteroids +PRIVATE + Src + SDK/Include + ${CMAKE_CURRENT_BINARY_DIR}/Shaders +) + +target_link_libraries(Asteroids +PRIVATE + BuildSettings + GraphicsEngine + GraphicsEngineD3D11-shared + GraphicsEngineD3D12-shared + GraphicsEngineOpenGL-shared + TargetPlatform + TextureLoader + GraphicsTools + d3dcompiler.lib + d3d12.lib + d3d11.lib + ninput.lib + winmm.lib + dxgi.lib + shcore.lib +) + +if(MSVC) + set_header_file_only_property("${SHADERS}") + + # Disable MSVC-specific warnings + # - w4201: nonstandard extension used: nameless struct/union + # - w4324: structure was padded due to alignment specifier + # - w4238: nonstandard extension used: class rvalue used as lvalue + target_compile_options(Asteroids PRIVATE /wd4201 /wd4324 /wd4238) + # Enable link-time code generation for release builds (I was not able to + # find any way to set these settings through interface library BuildSettings) + set_target_properties(Asteroids PROPERTIES + LINK_FLAGS_RELEASE /LTCG + LINK_FLAGS_MINSIZEREL /LTCG + LINK_FLAGS_RELWITHDEBINFO /LTCG + ) +endif() + +source_group("src" FILES ${SOURCE}) +source_group("include" FILES ${INCLUDE}) +source_group("shaders" FILES + ${SHADERS} + src/common_defines.h +) +source_group("SDK" FILES SDK/Include/d3dx12.h) +source_group("GUI" FILES ${GUI}) +source_group("media" FILES ${MEDIA}) + + diff --git a/Projects/Asteroids/src/WinWrapper.cpp b/Projects/Asteroids/src/WinWrapper.cpp index 65446c5..1da3a20 100644 --- a/Projects/Asteroids/src/WinWrapper.cpp +++ b/Projects/Asteroids/src/WinWrapper.cpp @@ -473,8 +473,6 @@ int main(int argc, char** argv) // main loop double elapsedTime = 0.0; double frameTime = 0.0; - int lastMouseX = 0; - int lastMouseY = 0; POINTER_INFO pointerInfo = {}; timeBeginPeriod(1); @@ -573,15 +571,15 @@ int main(int argc, char** argv) filteredFrameTime = filteredFrameTime * (1.f - filterScale) + filterScale * (float)frameTime; char buffer[256]; - sprintf(buffer, "Asteroids %s%s (%dt) - %4.2f ms (%4.2f ms / %4.2f ms)", ModeStr, resBindModeStr, gSettings.multithreadedRendering ? gSettings.numThreads : 1, - 1000.f * filteredFrameTime, 1000.f * filteredUpdateTime, 1000.f * filteredRenderTime); + sprintf_s(buffer, "Asteroids %s%s (%dt) - %4.2f ms (%4.2f ms / %4.2f ms)", ModeStr, resBindModeStr, gSettings.multithreadedRendering ? gSettings.numThreads : 1, + 1000.f * filteredFrameTime, 1000.f * filteredUpdateTime, 1000.f * filteredRenderTime); SetWindowText(hWnd, buffer); if (gSettings.lockFrameRate) { - sprintf(buffer, "(Locked)"); + sprintf_s(buffer, "(Locked)"); } else { - sprintf(buffer, "%.0f fps", 1.0f / filteredFrameTime); + sprintf_s(buffer, "%.0f fps", 1.0f / filteredFrameTime); } gFPSControl->Text(buffer); } diff --git a/Projects/Asteroids/src/asteroids_DE.cpp b/Projects/Asteroids/src/asteroids_DE.cpp index a657881..73ba096 100644 --- a/Projects/Asteroids/src/asteroids_DE.cpp +++ b/Projects/Asteroids/src/asteroids_DE.cpp @@ -592,7 +592,6 @@ void Asteroids::CreateGUIResources() auto control = i >= 0 ? (*mGUI)[i] : mSprite.get(); if (control->TextureFile().length() > 0 && mSpriteTextures.find(control->TextureFile()) == mSpriteTextures.end()) { std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; - ID3D11ShaderResourceView* textureSRV = nullptr; auto path = NarrowString(converter.from_bytes(control->TextureFile()).c_str()); TextureLoadInfo loadInfo; loadInfo.IsSRGB = true; @@ -722,7 +721,7 @@ void Asteroids::Render(float frameTime, const OrbitCamera& camera, const Setting if( m_BindingMode == BindingMode::TextureMutable ) { - for(auto &srb=mAsteroidsSRBs.begin(); srb!=mAsteroidsSRBs.end(); ++srb) + for(auto srb=mAsteroidsSRBs.begin(); srb!=mAsteroidsSRBs.end(); ++srb) { mDeviceCtxt->TransitionShaderResources(mAsteroidsPSO, *srb); } diff --git a/Projects/Asteroids/src/asteroids_d3d12.cpp b/Projects/Asteroids/src/asteroids_d3d12.cpp index 1d6fcdd..c2ba3e5 100644 --- a/Projects/Asteroids/src/asteroids_d3d12.cpp +++ b/Projects/Asteroids/src/asteroids_d3d12.cpp @@ -548,7 +548,7 @@ void Asteroids::CreateSubsets(UINT numHeapsPerFrame) for (UINT f = 0; f < NUM_FRAMES_TO_BUFFER; f++) { // Per-frame data auto frame = &mFrame[f]; - auto dynamicUploadGPUVA = frame->mDynamicUpload->Heap()->GetGPUVirtualAddress(); + //auto dynamicUploadGPUVA = frame->mDynamicUpload->Heap()->GetGPUVirtualAddress(); for (UINT subsetIdx = 0; subsetIdx < mSubsetCount; ++subsetIdx) { void* memory = _aligned_malloc(sizeof(SubsetD3D12), 64); @@ -793,7 +793,6 @@ void Asteroids::Render(float frameTime, const OrbitCamera& camera, const Setting } else { - LONG64 SubsetUpdateTicks = 0, SubsetRenderTicks = 0; for (unsigned int subsetIdx = 0; subsetIdx < mSubsetCount; ++subsetIdx) { RenderSubset(swapChainBuffer->mRenderTargetView, mCurrentFrameIndex, frameTime, frame->mSubsets[subsetIdx], subsetIdx, camera.Eye(), camera.ViewProjection(), settings); diff --git a/Projects/CMakeLists.txt b/Projects/CMakeLists.txt new file mode 100644 index 0000000..b12529a --- /dev/null +++ b/Projects/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required (VERSION 3.3) + +if(PLATFORM_WIN32) + add_subdirectory(Asteroids) +endif() @@ -74,6 +74,30 @@ use ndk-build. For executable projects, there is also **android_build.bat** file Note that when building for Android, the engine root path must not contain white spaces. +# Building with CMake (Work in Progress) + +Reworking Diligent Engine build system with CMake is in progress. + +[CMake](https://cmake.org/) is a cross-platform build system generator. To start using cmake, download the [latest release](https://cmake.org/download/)(3.10 or later is recommended). + +## Win32 + +To generate solution files for Windows desktop platform, use either CMake GUI or command line tool. The build system uses standalone +effect compiler. The path to the compiler needs to be specified via FXC variable. For example, to generate Visual Studio 2017 +solution and project files in cmk_build folder, navigate to the engine's root folder and run the following command: + +cmake -D FXC="C:/Program Files (x86)/Windows Kits/10/bin/x86/fxc.exe" -H. -B./cmk_build -G "Visual Studio 15 2017 Win64" + +Open DiligentEngine.sln file in cmk_build folder, select the desired configuration and build the engine. + +## Universal Windows Platform + +Not yet supported + +## Android + +Not yet supported + # Samples [Sample source code](https://github.com/DiligentGraphics/DiligentSamples) |
