Removed macro D3D12MA_OPTIONS16_SUPPORTED from the public interface Also removed it from the Cmake script. It is now automatically determined based on D3D12_SDK_VERSION macro. Also made fixes in tests. Cherry-picked from branch "feature/resource-tight-alignment".
diff --git a/include/D3D12MemAlloc.h b/include/D3D12MemAlloc.h index 2dc31c7..4e5e3f9 100644 --- a/include/D3D12MemAlloc.h +++ b/include/D3D12MemAlloc.h
@@ -1123,8 +1123,6 @@ When true, you can use `D3D12_HEAP_TYPE_GPU_UPLOAD`. This flag is fetched from `D3D12_FEATURE_D3D12_OPTIONS16::GPUUploadHeapSupported`. - - `#define D3D12MA_OPTIONS16_SUPPORTED 1` is needed for the compilation of this library. Otherwise the flag is always false. */ BOOL IsGPUUploadHeapSupported() const; /** \brief Returns total amount of memory of specific segment group, in bytes.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23e0941..34fcecd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt
@@ -1,200 +1,192 @@ -cmake_minimum_required(VERSION 3.25) - -set(D3D12MA_LIBRARY_SOURCE_FILES - D3D12MemAlloc.cpp - "${PROJECT_SOURCE_DIR}/include/D3D12MemAlloc.h" -) - -if(WIN32 AND ${CMAKE_GENERATOR} MATCHES "Visual Studio.*") - set(D3D12MA_LIBRARY_SOURCE_FILES ${D3D12MA_LIBRARY_SOURCE_FILES} D3D12MemAlloc.natvis) -endif() - -add_library(D3D12MemoryAllocator ${D3D12MA_LIBRARY_SOURCE_FILES}) - -set_target_properties( - D3D12MemoryAllocator PROPERTIES - - CXX_EXTENSIONS OFF - # Use C++14 - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - - OUTPUT_NAME "D3D12MA" - # Postfix for different profiles - DEBUG_POSTFIX "d" - RELWITHDEBINFO_POSTFIX "rd" - MINSIZEREL_POSTFIX "s" -) - -target_include_directories(D3D12MemoryAllocator PUBLIC - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:./include> -) - -target_link_libraries(D3D12MemoryAllocator PUBLIC - d3d12.lib - dxgi.lib - dxguid.lib -) - -if(BUILD_SHARED_LIBS) - target_compile_definitions(D3D12MemoryAllocator PRIVATE - D3D12MA_EXPORTS - ) - - target_compile_definitions(D3D12MemoryAllocator INTERFACE - D3D12MA_IMPORTS - ) -endif() - -set(D3D12MA_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") -set(D3D12MA_VERSION_CONFIG "${D3D12MA_GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake") -set(D3D12MA_PROJECT_CONFIG "${D3D12MA_GENERATED_DIR}/${PROJECT_NAME}Config.cmake") -set(D3D12MA_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") -set(D3D12MA_CONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}") -set(D3D12MA_NAMESPACE "GPUOpen::") -set(D3D12MA_VERSION ${PROJECT_VERSION}) - -include(CMakePackageConfigHelpers) -write_basic_package_version_file( - "${D3D12MA_VERSION_CONFIG}" VERSION ${D3D12MA_VERSION} COMPATIBILITY SameMajorVersion -) -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in" "${D3D12MA_PROJECT_CONFIG}" @ONLY) - -# Install cmake config files -install( - FILES "${D3D12MA_PROJECT_CONFIG}" "${D3D12MA_VERSION_CONFIG}" - DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") - -install( - EXPORT "${D3D12MA_TARGETS_EXPORT_NAME}" - NAMESPACE "${D3D12MA_NAMESPACE}" - DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") - -install(TARGETS D3D12MemoryAllocator - EXPORT ${D3D12MA_TARGETS_EXPORT_NAME} - RUNTIME DESTINATION "bin" - ARCHIVE DESTINATION "lib" - LIBRARY DESTINATION "lib") -install(FILES "${PROJECT_SOURCE_DIR}/include/D3D12MemAlloc.h" DESTINATION "include") - -if(D3D12MA_BUILD_SAMPLE) - if(WIN32) - set(SHADER_DIR "Shaders") - - set(D3D12_SAMPLE_SOURCE_FILES - Common.cpp - Common.h - Tests.cpp - Tests.h - D3D12Sample.cpp - ) - - set(VERTEX_SHADERS - "${SHADER_DIR}/VS.hlsl" - ) - - set(PIXEL_SHADERS - "${SHADER_DIR}/PS.hlsl" - ) - - set( SHADERS - ${VERTEX_SHADERS} - ${PIXEL_SHADERS} - ) - - source_group("Resources\\Shaders" FILES ${SHADERS}) - - set_source_files_properties(${VERTEX_SHADERS} - PROPERTIES - VS_SHADER_TYPE Vertex - VS_SETTINGS "ExcludedFromBuild=true" - ) - - set_source_files_properties( ${PIXEL_SHADERS} - PROPERTIES - VS_SHADER_TYPE Pixel - VS_SETTINGS "ExcludedFromBuild=true" - ) - - add_executable(D3D12Sample ${D3D12_SAMPLE_SOURCE_FILES} ${SHADERS}) - - add_dependencies(D3D12Sample D3D12MemoryAllocator) - - # Visual Studio specific settings - if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") - # Use Unicode instead of multibyte set - add_compile_definitions(UNICODE _UNICODE) - - # Set VmaSample as startup project - set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "D3D12Sample") - - # Enable multithreaded compiling - target_compile_options(D3D12Sample PRIVATE "/MP") - - # Set working directory for Visual Studio debugger - set_target_properties( - D3D12Sample - PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin" - ) - endif() - - set_target_properties( - D3D12Sample PROPERTIES - - CXX_EXTENSIONS OFF - # Use C++14 - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - ) - - target_link_libraries( - D3D12Sample - - PRIVATE D3D12MemoryAllocator - PUBLIC d3d12.lib - PUBLIC dxgi.lib - PUBLIC dxguid.lib - PUBLIC Shlwapi.lib - ) - else() - message(STATUS "D3D12Sample application is not supported to Linux") - endif() -endif() - -set(D3D12MA_AGILITY_SDK_DIRECTORY "" CACHE STRING "Path to unpacked DX12 Agility SDK. Leave empty to compile without it.") -option(D3D12MA_AGILITY_SDK_PREVIEW "Set if DX12 Agility SDK is preview version." OFF) -if(D3D12MA_AGILITY_SDK_DIRECTORY) - if(EXISTS "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include/d3d12.h") - message(STATUS "DX12 Agility SDK used from \"${D3D12MA_AGILITY_SDK_DIRECTORY}\".") - target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_USE_AGILITY_SDK=1) - target_include_directories(D3D12MemoryAllocator BEFORE PRIVATE "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include") - if(D3D12MA_AGILITY_SDK_PREVIEW) - target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_USE_AGILITY_SDK_PREVIEW=1) - endif() - if(${D3D12MA_BUILD_SAMPLE} AND ${WIN32}) - target_compile_definitions(D3D12Sample PRIVATE D3D12MA_USE_AGILITY_SDK=1) - target_include_directories(D3D12Sample BEFORE PRIVATE "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include") - if(D3D12MA_AGILITY_SDK_PREVIEW) - target_compile_definitions(D3D12Sample PRIVATE D3D12MA_USE_AGILITY_SDK_PREVIEW=1) - endif() - add_custom_command(TARGET D3D12Sample POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:D3D12Sample>/D3D12" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/bin/x64/D3D12Core.dll" - "$<TARGET_FILE_DIR:D3D12Sample>/D3D12/" - COMMAND ${CMAKE_COMMAND} -E copy_if_different "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/bin/x64/d3d12SDKLayers.dll" - "$<TARGET_FILE_DIR:D3D12Sample>/D3D12/") - endif() - else() - message(FATAL_ERROR "DX12 Agility SDK not found - cannot find file \"${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include/d3d12.h\".") - endif() -else() - message(STATUS "DX12 Agility SDK not used.") -endif() - -option(D3D12MA_OPTIONS16_SUPPORTED "Set if using Agility SDK 1.710.0-preview or newer that defines D3D12_FEATURE_DATA_D3D12_OPTIONS16." OFF) -if(D3D12MA_OPTIONS16_SUPPORTED) - target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_OPTIONS16_SUPPORTED=1) - if(${D3D12MA_BUILD_SAMPLE} AND ${WIN32}) - target_compile_definitions(D3D12Sample PRIVATE D3D12MA_OPTIONS16_SUPPORTED=1) - endif() -endif() +cmake_minimum_required(VERSION 3.25) + +set(D3D12MA_LIBRARY_SOURCE_FILES + D3D12MemAlloc.cpp + "${PROJECT_SOURCE_DIR}/include/D3D12MemAlloc.h" +) + +if(WIN32 AND ${CMAKE_GENERATOR} MATCHES "Visual Studio.*") + set(D3D12MA_LIBRARY_SOURCE_FILES ${D3D12MA_LIBRARY_SOURCE_FILES} D3D12MemAlloc.natvis) +endif() + +add_library(D3D12MemoryAllocator ${D3D12MA_LIBRARY_SOURCE_FILES}) + +set_target_properties( + D3D12MemoryAllocator PROPERTIES + + CXX_EXTENSIONS OFF + # Use C++14 + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + + OUTPUT_NAME "D3D12MA" + # Postfix for different profiles + DEBUG_POSTFIX "d" + RELWITHDEBINFO_POSTFIX "rd" + MINSIZEREL_POSTFIX "s" +) + +target_include_directories(D3D12MemoryAllocator PUBLIC + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:./include> +) + +target_link_libraries(D3D12MemoryAllocator PUBLIC + d3d12.lib + dxgi.lib + dxguid.lib +) + +if(BUILD_SHARED_LIBS) + target_compile_definitions(D3D12MemoryAllocator PRIVATE + D3D12MA_EXPORTS + ) + + target_compile_definitions(D3D12MemoryAllocator INTERFACE + D3D12MA_IMPORTS + ) +endif() + +set(D3D12MA_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +set(D3D12MA_VERSION_CONFIG "${D3D12MA_GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake") +set(D3D12MA_PROJECT_CONFIG "${D3D12MA_GENERATED_DIR}/${PROJECT_NAME}Config.cmake") +set(D3D12MA_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets") +set(D3D12MA_CONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}") +set(D3D12MA_NAMESPACE "GPUOpen::") +set(D3D12MA_VERSION ${PROJECT_VERSION}) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${D3D12MA_VERSION_CONFIG}" VERSION ${D3D12MA_VERSION} COMPATIBILITY SameMajorVersion +) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in" "${D3D12MA_PROJECT_CONFIG}" @ONLY) + +# Install cmake config files +install( + FILES "${D3D12MA_PROJECT_CONFIG}" "${D3D12MA_VERSION_CONFIG}" + DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") + +install( + EXPORT "${D3D12MA_TARGETS_EXPORT_NAME}" + NAMESPACE "${D3D12MA_NAMESPACE}" + DESTINATION "${D3D12MA_CONFIG_INSTALL_DIR}") + +install(TARGETS D3D12MemoryAllocator + EXPORT ${D3D12MA_TARGETS_EXPORT_NAME} + RUNTIME DESTINATION "bin" + ARCHIVE DESTINATION "lib" + LIBRARY DESTINATION "lib") +install(FILES "${PROJECT_SOURCE_DIR}/include/D3D12MemAlloc.h" DESTINATION "include") + +if(D3D12MA_BUILD_SAMPLE) + if(WIN32) + set(SHADER_DIR "Shaders") + + set(D3D12_SAMPLE_SOURCE_FILES + Common.cpp + Common.h + Tests.cpp + Tests.h + D3D12Sample.cpp + ) + + set(VERTEX_SHADERS + "${SHADER_DIR}/VS.hlsl" + ) + + set(PIXEL_SHADERS + "${SHADER_DIR}/PS.hlsl" + ) + + set( SHADERS + ${VERTEX_SHADERS} + ${PIXEL_SHADERS} + ) + + source_group("Resources\\Shaders" FILES ${SHADERS}) + + set_source_files_properties(${VERTEX_SHADERS} + PROPERTIES + VS_SHADER_TYPE Vertex + VS_SETTINGS "ExcludedFromBuild=true" + ) + + set_source_files_properties( ${PIXEL_SHADERS} + PROPERTIES + VS_SHADER_TYPE Pixel + VS_SETTINGS "ExcludedFromBuild=true" + ) + + add_executable(D3D12Sample ${D3D12_SAMPLE_SOURCE_FILES} ${SHADERS}) + + add_dependencies(D3D12Sample D3D12MemoryAllocator) + + # Visual Studio specific settings + if(${CMAKE_GENERATOR} MATCHES "Visual Studio.*") + # Use Unicode instead of multibyte set + add_compile_definitions(UNICODE _UNICODE) + + # Set VmaSample as startup project + set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "D3D12Sample") + + # Enable multithreaded compiling + target_compile_options(D3D12Sample PRIVATE "/MP") + + # Set working directory for Visual Studio debugger + set_target_properties( + D3D12Sample + PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin" + ) + endif() + + set_target_properties( + D3D12Sample PROPERTIES + + CXX_EXTENSIONS OFF + # Use C++14 + CXX_STANDARD 14 + CXX_STANDARD_REQUIRED ON + ) + + target_link_libraries( + D3D12Sample + + PRIVATE D3D12MemoryAllocator + PUBLIC d3d12.lib + PUBLIC dxgi.lib + PUBLIC dxguid.lib + PUBLIC Shlwapi.lib + ) + else() + message(STATUS "D3D12Sample application is not supported to Linux") + endif() +endif() + +set(D3D12MA_AGILITY_SDK_DIRECTORY "" CACHE STRING "Path to unpacked DX12 Agility SDK. Leave empty to compile without it.") +option(D3D12MA_AGILITY_SDK_PREVIEW "Set if DX12 Agility SDK is preview version." OFF) +if(D3D12MA_AGILITY_SDK_DIRECTORY) + if(EXISTS "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include/d3d12.h") + message(STATUS "DX12 Agility SDK used from \"${D3D12MA_AGILITY_SDK_DIRECTORY}\".") + target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_USE_AGILITY_SDK=1) + target_include_directories(D3D12MemoryAllocator BEFORE PRIVATE "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include") + if(D3D12MA_AGILITY_SDK_PREVIEW) + target_compile_definitions(D3D12MemoryAllocator PRIVATE D3D12MA_USE_AGILITY_SDK_PREVIEW=1) + endif() + if(${D3D12MA_BUILD_SAMPLE} AND ${WIN32}) + target_compile_definitions(D3D12Sample PRIVATE D3D12MA_USE_AGILITY_SDK=1) + target_include_directories(D3D12Sample BEFORE PRIVATE "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include") + if(D3D12MA_AGILITY_SDK_PREVIEW) + target_compile_definitions(D3D12Sample PRIVATE D3D12MA_USE_AGILITY_SDK_PREVIEW=1) + endif() + add_custom_command(TARGET D3D12Sample POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:D3D12Sample>/D3D12" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/bin/x64/D3D12Core.dll" + "$<TARGET_FILE_DIR:D3D12Sample>/D3D12/" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/bin/x64/d3d12SDKLayers.dll" + "$<TARGET_FILE_DIR:D3D12Sample>/D3D12/") + endif() + else() + message(FATAL_ERROR "DX12 Agility SDK not found - cannot find file \"${D3D12MA_AGILITY_SDK_DIRECTORY}/build/native/include/d3d12.h\".") + endif() +else() + message(STATUS "DX12 Agility SDK not used.") +endif()
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp index 6962f0b..0696578 100644 --- a/src/D3D12MemAlloc.cpp +++ b/src/D3D12MemAlloc.cpp
@@ -107,6 +107,14 @@ #define D3D12MA_DEFAULT_BLOCK_SIZE (64ull * 1024 * 1024) #endif +#ifndef D3D12MA_OPTIONS16_SUPPORTED + #if D3D12_SDK_VERSION >= 610 + #define D3D12MA_OPTIONS16_SUPPORTED 1 + #else + #define D3D12MA_OPTIONS16_SUPPORTED 0 + #endif +#endif + #ifndef D3D12MA_DEBUG_LOG #define D3D12MA_DEBUG_LOG(format, ...) /* @@ -6163,9 +6171,6 @@ m_D3D12Options.ResourceHeapTier = (D3D12MA_FORCE_RESOURCE_HEAP_TIER); #endif -// You must define this macro to like `#define D3D12MA_OPTIONS16_SUPPORTED 1` to enable GPU Upload Heaps! -// Unfortunately there is no way to programmatically check if the included <d3d12.h> defines D3D12_FEATURE_DATA_D3D12_OPTIONS16 or not. -// Main interfaces have respective macros like __ID3D12Device4_INTERFACE_DEFINED__, but structures like this do not. #if D3D12MA_OPTIONS16_SUPPORTED { D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16 = {}; @@ -6175,7 +6180,7 @@ m_GPUUploadHeapSupported = options16.GPUUploadHeapSupported; } } -#endif +#endif // #if D3D12MA_OPTIONS16_SUPPORTED hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &m_D3D12Architecture, sizeof(m_D3D12Architecture)); if (FAILED(hr)) @@ -7397,7 +7402,7 @@ outPreferCommitted = false; D3D12MA_ASSERT((allocDesc.HeapType != D3D12_HEAP_TYPE_GPU_UPLOAD_COPY || IsGPUUploadHeapSupported()) && - "Trying to allocate from D3D12_HEAP_TYPE_GPU_UPLOAD while GPUUploadHeapSupported == FALSE or D3D12MA_OPTIONS16_SUPPORTED macro was not defined when compiling D3D12MA library."); + "Trying to allocate from D3D12_HEAP_TYPE_GPU_UPLOAD while GPUUploadHeapSupported == FALSE."); bool msaaAlwaysCommitted; if (allocDesc.CustomPool != NULL)
diff --git a/src/Doxyfile b/src/Doxyfile index a93bdbb..e9cc11b 100644 --- a/src/Doxyfile +++ b/src/Doxyfile
@@ -42,7 +42,7 @@ # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "Direct3D 12 Memory Allocator" +PROJECT_NAME = "D3D12 Memory Allocator" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -2372,6 +2372,8 @@ __ID3D12Device4_INTERFACE_DEFINED__ \ __ID3D12Device8_INTERFACE_DEFINED__ \ __ID3D12Device10_INTERFACE_DEFINED__ \ + D3D12_PREVIEW_SDK_VERSION=716 \ + D3D12_SDK_VERSION=716 \ protected=private # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
diff --git a/src/Tests.cpp b/src/Tests.cpp index 90a1f52..48cfbac 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp
@@ -762,7 +762,13 @@ CHECK_HR(ctx.allocator->CreateResource(&allocDesc, &resDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &resWithAlloc.allocation, IID_PPV_ARGS(&resWithAlloc.resource))); CHECK_BOOL(resWithAlloc.allocation && resWithAlloc.allocation->GetResource()); - CHECK_BOOL(!resWithAlloc.allocation->GetHeap()); // Expected to be committed. + // May or may not be committed, depending on the PREFER_SMALL_BUFFERS_COMMITTED + // and TIGHT_ALIGNMENT settings. + const bool isCommitted = resWithAlloc.allocation->GetHeap() == NULL; + if (isCommitted) + wprintf(L" Small buffer %llu B inside a custom pool was created as committed.\n", resDesc.Width); + else + wprintf(L" Small buffer %llu B inside a custom pool was created as placed.\n", resDesc.Width); } // Test 3: NEVER_ALLOCATE. @@ -2857,7 +2863,7 @@ static void TestGPUUploadHeap(const TestContext& ctx) { -#if D3D12MA_OPTIONS16_SUPPORTED +#if D3D12_SDK_VERSION >= 610 using namespace D3D12MA; wprintf(L"Test GPU Upload Heap\n");