Skip to content

Commit eb4b171

Browse files
Prepare initial release
1 parent e359baf commit eb4b171

23 files changed

Lines changed: 9698 additions & 2 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/
2+
docs/html/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 1.0.0</b> (2019-07-23)
2+
3+
First published version.

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

NOTICES.txt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Notices and licenses file
2+
_________________________
3+
4+
AMD copyrighted code (MIT)
5+
Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
8+
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
9+
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
10+
Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
13+
Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
16+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
20+
21+
Dependecnies on microsoft-directx-graphics-samples v-u (MIT)
22+
23+
Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
24+
Copyright (c) Microsoft. All rights reserved.
25+
26+
This code is licensed under the MIT License (MIT).
27+
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
28+
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
29+
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
30+
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
31+
32+
33+
gpuopen-librariesandsdks-vulkanmemoryallocator v-u (MIT)
34+
Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved.
35+
36+
Permission is hereby granted, free of charge, to any person obtaining a copy
37+
of this software and associated documentation files (the "Software"), to deal
38+
in the Software without restriction, including without limitation the rights
39+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40+
copies of the Software, and to permit persons to whom the Software is
41+
furnished to do so, subject to the following conditions:
42+
43+
The above copyright notice and this permission notice shall be included in
44+
all copies or substantial portions of the Software.
45+
46+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
52+
THE SOFTWARE.
53+
54+
55+
premake-premake-core v-u (BSD3)
56+
Copyright (c) 2003-2016 Jason Perkins and individual contributors.
57+
All rights reserved.
58+
59+
Redistribution and use in source and binary forms, with or without modification,
60+
are permitted provided that the following conditions are met:
61+
62+
1. Redistributions of source code must retain the above copyright notice,
63+
this list of conditions and the following disclaimer.
64+
65+
2. Redistributions in binary form must reproduce the above copyright notice,
66+
this list of conditions and the following disclaimer in the documentation
67+
and/or other materials provided with the distribution.
68+
69+
3. Neither the name of Premake nor the names of its contributors may be
70+
used to endorse or promote products derived from this software without
71+
specific prior written permission.
72+
73+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
74+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
75+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
77+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
78+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
79+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
80+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
81+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
82+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,106 @@
1-
# Direct3D 12 Memory Allocator
1+
# D3D12 Memory Allocator
22

3-
Easy to integrate Direct3D 12 memory allocation library
3+
Easy to integrate memory allocation library for Direct3D 12.
4+
5+
**License:** MIT. See [LICENSE.txt](LICENSE.txt)
6+
7+
**Changelog:** See [CHANGELOG.md](CHANGELOG.md)
8+
9+
**Product page:** [Vulkan Memory Allocator on GPUOpen](https://gpuopen.com/gaming-product/D3D12MemoryAllocator/) (TODO)
10+
11+
**Build status:**
12+
13+
TODO
14+
15+
# Problem
16+
17+
Memory allocation and resource (buffer and texture) creation in new, explicit graphics APIs (Vulkan and Direct3D 12) is difficult comparing to older graphics APIs like Direct3D 11 or OpenGL because it is recommended to allocate bigger blocks of memory and assign parts of them to resources. [Vulkan Memory Allocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/) is a library that implements this functionality for Vulkan. It is available online since 2017 and it is successfully used in many software projects, including some AAA game studios. This is an equivalent library for D3D12.
18+
19+
# Features
20+
21+
This library can help developers to manage memory allocations and resource creation by offering function `Allocator::CreateResource` similar to the standard `ID3D12Device::CreateCommittedResource`. It internally:
22+
23+
- Allocates and keeps track of bigger memory heaps, used and unused ranges inside them, finds best matching unused ranges to create new resources there as placed resources.
24+
- Automatically respects aligment requirements for created resources.
25+
- Automatically handles resource heap tier - whether it's `D3D12_RESOURCE_HEAP_TIER_1` that requires to keep certain classes of resources separate or `D3D12_RESOURCE_HEAP_TIER_2` that allows to keep them all together.
26+
27+
Additional features:
28+
29+
- Well-documented - description of all classes and functions provided, along with chapters that contain general description and example code.
30+
- Thread-safety: Library is designed to be used in multithreaded code.
31+
- Configuration: Fill optional members of `ALLOCATOR_DESC` structure to provide custom CPU memory allocator and other parameters.
32+
- Customization: Predefine appropriate macros to provide your own implementation of external facilities used by the library, like assert, mutex, and atomic.
33+
34+
# Prequisites
35+
36+
- Self-contained C++ library in single pair of H + CPP files. No external dependencies other than standard C, C++ library and Windows SDK. STL containers, C++ exceptions, and RTTI are not used.
37+
- Object-oriented interface in a convention similar to D3D12.
38+
- Error handling implemented by returning `HRESULT` error codes - same way as in D3D12.
39+
- Interface documented using Doxygen-style comments.
40+
41+
# Example
42+
43+
Basic usage of this library is very simple. Advanced features are optional. After you created global `Allocator` object, a complete code needed to create a texture may look like this:
44+
45+
```cpp
46+
D3D12_RESOURCE_DESC resourceDesc = {};
47+
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
48+
resourceDesc.Alignment = 0;
49+
resourceDesc.Width = 1024;
50+
resourceDesc.Height = 1024;
51+
resourceDesc.DepthOrArraySize = 1;
52+
resourceDesc.MipLevels = 1;
53+
resourceDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
54+
resourceDesc.SampleDesc.Count = 1;
55+
resourceDesc.SampleDesc.Quality = 0;
56+
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
57+
resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
58+
59+
D3D12MA::ALLOCATION_DESC allocationDesc = {};
60+
allocDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;
61+
62+
D3D12Resource* resource;
63+
D3D12MA::Allocation* allocation;
64+
HRESULT hr = allocator->CreateResource(
65+
&allocationDesc,
66+
&resourceDesc,
67+
D3D12_RESOURCE_STATE_COPY_DEST,
68+
NULL,
69+
&allocation,
70+
IID_PPV_ARGS(&resource));
71+
```
72+
73+
With this one function call:
74+
75+
1. `ID3D12Heap` memory block is allocated if needed.
76+
2. An unused region of the memory block assigned.
77+
3. `ID3D12Resource` is created as placed resource, bound to this region.
78+
79+
`Allocation` is an object that represents memory assigned to this texture. It can be queried for parameters like offset and size.
80+
81+
# Documentation
82+
83+
Documentation is provided together with the library in form of Doxygen-style comments inside the code, in file "src/D3D12MemAlloc.h". They can be read directly or turned into HTML and other convenient to read formats. Unfortunately we can't provide pregenerated version browseable online. You can generate it on your own by following these steps:
84+
85+
1. Install [Doxygen](http://www.doxygen.nl/).
86+
2. Open command line and enter "src" directory.
87+
3. Type command: `doxygen`
88+
4. Open following file in a web browser: "docs/html/index.html".
89+
90+
# Copyright notice
91+
92+
This software package uses third party software:
93+
94+
- Parts of the code of [Vulkan Memory Allocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/) by AMD, license: MIT
95+
- Parts of the code of [DirectX-Graphics-Samples](https://github.com/microsoft/DirectX-Graphics-Samples) by Microsoft, license: MIT
96+
- [Premake 5](https://premake.github.io/) binary, license: BSD
97+
98+
For more information see [NOTICES.txt](NOTICES.txt).
99+
100+
# Software using this library
101+
102+
Place for the link to your project :)
103+
104+
# See also
105+
106+
- **[Vulkan Memory Allocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/)** - equivalent library for Vulkan. License: MIT.

bin/D3D12Sample_Release_vs2019.exe

83.5 KB
Binary file not shown.

premake/LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2003-2016 Jason Perkins and individual contributors.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
3. Neither the name of Premake nor the names of its contributors may be
15+
used to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

premake/premake5.exe

1.3 MB
Binary file not shown.

premake/premake5.lua

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- _ACTION is a premake global variable and for our usage will be vs2012, vs2013, etc.
2+
-- Strip "vs" from this string to make a suffix for solution and project files.
3+
_SUFFIX = _ACTION
4+
5+
workspace "D3D12Sample"
6+
configurations { "Debug", "Release" }
7+
platforms { "x64" }
8+
location "../build"
9+
filename ("D3D12Sample_" .. _SUFFIX)
10+
startproject "D3D12Sample"
11+
12+
filter "platforms:x64"
13+
system "Windows"
14+
architecture "x64"
15+
includedirs { }
16+
libdirs { }
17+
18+
19+
project "D3D12Sample"
20+
kind "ConsoleApp"
21+
language "C++"
22+
location "../build"
23+
filename ("D3D12Sample_" .. _SUFFIX)
24+
targetdir "../bin"
25+
objdir "../build/Desktop_%{_SUFFIX}/%{cfg.platform}/%{cfg.buildcfg}"
26+
floatingpoint "Fast"
27+
files { "../src/*.h", "../src/*.cpp" }
28+
flags { "NoPCH", "FatalWarnings" }
29+
characterset "Unicode"
30+
31+
filter "configurations:Debug"
32+
defines { "_DEBUG", "DEBUG" }
33+
flags { }
34+
targetsuffix ("_Debug_" .. _SUFFIX)
35+
36+
filter "configurations:Release"
37+
defines { "NDEBUG" }
38+
optimize "On"
39+
flags { "LinkTimeOptimization" }
40+
targetsuffix ("_Release_" .. _SUFFIX)
41+
42+
filter { "platforms:x64" }
43+
defines { "WIN32", "_CONSOLE", "PROFILE", "_WINDOWS", "_WIN32_WINNT=0x0601" }
44+
links { "d3d12.lib", "dxgi.lib" }
45+
46+
filter { "configurations:Debug", "platforms:x64" }
47+
buildoptions { "/MDd" }
48+
49+
filter { "configurations:Release", "platforms:Windows-x64" }
50+
buildoptions { "/MD" }

0 commit comments

Comments
 (0)