Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions .github/workflows/.patches/dawn.diff
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From be80c6e52d951647f7f501ad665ab6506acae698 Mon Sep 17 00:00:00 2001
From 8ef270d881c9f8d91a3acbaa7f8fbc572baa3d57 Mon Sep 17 00:00:00 2001
From: Bryan Bernhart <bryan.bernhart@intel.com>
Date: Tue, 15 Feb 2022 17:25:29 -0800
Subject: [PATCH] Use GPGMM for D3D12 backend.
Expand All @@ -22,7 +22,7 @@ Change-Id: I47708462a1d9dd0166120c3a6af93451aae54a07
src/dawn/native/d3d12/D3D12Backend.cpp | 17 ++-
src/dawn/native/d3d12/DeviceD3D12.cpp | 114 +++++++++++++++---
src/dawn/native/d3d12/DeviceD3D12.h | 20 +--
.../ShaderVisibleDescriptorAllocatorD3D12.cpp | 80 +++++++-----
.../ShaderVisibleDescriptorAllocatorD3D12.cpp | 79 +++++++-----
.../ShaderVisibleDescriptorAllocatorD3D12.h | 11 +-
src/dawn/native/d3d12/StagingBufferD3D12.cpp | 22 +---
src/dawn/native/d3d12/StagingBufferD3D12.h | 4 +-
Expand All @@ -31,7 +31,7 @@ Change-Id: I47708462a1d9dd0166120c3a6af93451aae54a07
src/dawn/native/d3d12/UtilsD3D12.cpp | 11 ++
src/dawn/native/d3d12/UtilsD3D12.h | 2 +
.../tests/white_box/D3D12ResidencyTests.cpp | 17 +--
26 files changed, 326 insertions(+), 162 deletions(-)
26 files changed, 325 insertions(+), 162 deletions(-)
create mode 100644 build_overrides/gpgmm.gni

diff --git a/.gitignore b/.gitignore
Expand Down Expand Up @@ -725,7 +725,7 @@ index 99b03e396..b1cf46fd0 100644
static constexpr uint32_t kMaxSamplerDescriptorsPerBindGroup = 3 * kMaxSamplersPerShaderStage;
static constexpr uint32_t kMaxViewDescriptorsPerBindGroup =
diff --git a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp
index fe99a63ac..40ce7b4a7 100644
index fe99a63ac..e169435f9 100644
--- a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp
+++ b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.cpp
@@ -93,7 +93,8 @@ ShaderVisibleDescriptorAllocator::ShaderVisibleDescriptorAllocator(
Expand All @@ -738,7 +738,7 @@ index fe99a63ac..40ce7b4a7 100644
ASSERT(heapType == D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV ||
heapType == D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
}
@@ -140,31 +141,41 @@ void ShaderVisibleDescriptorAllocator::Tick(ExecutionSerial completedSerial) {
@@ -140,31 +141,40 @@ void ShaderVisibleDescriptorAllocator::Tick(ExecutionSerial completedSerial) {

ResultOrError<std::unique_ptr<ShaderVisibleDescriptorHeap>>
ShaderVisibleDescriptorAllocator::AllocateHeap(uint32_t descriptorCount) const {
Expand Down Expand Up @@ -787,19 +787,18 @@ index fe99a63ac..40ce7b4a7 100644
- // We must track the allocation in the LRU when it is created, otherwise the residency
- // manager will see the allocation as non-resident in the later call to LockAllocation.
- mDevice->GetResidencyManager()->TrackResidentAllocation(descriptorHeap.get());
+ gpgmm::d3d12::Heap* descriptorHeapPtr = nullptr;
+ ComPtr<gpgmm::d3d12::Heap> descriptorHeap;
+ DAWN_TRY(CheckOutOfMemoryHRESULT(
+ gpgmm::d3d12::Heap::CreateHeap(heapDesc, mDevice->GetResidencyManager(), createHeapFn,
+ &descriptorHeapPtr),
+ &descriptorHeap),
+ "Unable to create descriptor heap"));

- return std::move(descriptorHeap);
+ return std::make_unique<ShaderVisibleDescriptorHeap>(
+ std::unique_ptr<gpgmm::d3d12::Heap>(descriptorHeapPtr));
+ return std::make_unique<ShaderVisibleDescriptorHeap>(std::move(descriptorHeap));
}

// Creates a GPU descriptor heap that manages descriptors in a FIFO queue.
@@ -174,7 +185,9 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap(
@@ -174,7 +184,9 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap(
// The first phase increasingly grows a small heap in binary sizes for light users while the
// second phase pool-allocates largest sized heaps for heavy users.
if (mHeap != nullptr) {
Expand All @@ -810,7 +809,7 @@ index fe99a63ac..40ce7b4a7 100644

const uint32_t maxDescriptorCount = GetD3D12ShaderVisibleHeapMaxSize(
mHeapType, mDevice->IsToggleEnabled(Toggle::UseD3D12SmallShaderVisibleHeapForTesting));
@@ -200,7 +213,10 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap(
@@ -200,7 +212,10 @@ MaybeError ShaderVisibleDescriptorAllocator::AllocateAndSwitchShaderVisibleHeap(
DAWN_TRY_ASSIGN(descriptorHeap, AllocateHeap(mDescriptorCount));
}

Expand All @@ -822,7 +821,7 @@ index fe99a63ac..40ce7b4a7 100644

// Create a FIFO buffer from the recently created heap.
mHeap = std::move(descriptorHeap);
@@ -227,12 +243,12 @@ uint64_t ShaderVisibleDescriptorAllocator::GetShaderVisiblePoolSizeForTesting()
@@ -227,12 +242,12 @@ uint64_t ShaderVisibleDescriptorAllocator::GetShaderVisiblePoolSizeForTesting()
}

bool ShaderVisibleDescriptorAllocator::IsShaderVisibleHeapLockedResidentForTesting() const {
Expand All @@ -837,32 +836,32 @@ index fe99a63ac..40ce7b4a7 100644
}

bool ShaderVisibleDescriptorAllocator::IsAllocationStillValid(
@@ -244,12 +260,18 @@ bool ShaderVisibleDescriptorAllocator::IsAllocationStillValid(
@@ -244,12 +259,18 @@ bool ShaderVisibleDescriptorAllocator::IsAllocationStillValid(
}

ShaderVisibleDescriptorHeap::ShaderVisibleDescriptorHeap(
- ComPtr<ID3D12DescriptorHeap> d3d12DescriptorHeap,
- uint64_t size)
- : Pageable(d3d12DescriptorHeap, MemorySegment::Local, size),
- mD3d12DescriptorHeap(std::move(d3d12DescriptorHeap)) {}
+ std::unique_ptr<gpgmm::d3d12::Heap> descriptorHeap)
+ ComPtr<gpgmm::d3d12::Heap> descriptorHeap)
+ : mDescriptorHeap(std::move(descriptorHeap)) {}

ID3D12DescriptorHeap* ShaderVisibleDescriptorHeap::GetD3D12DescriptorHeap() const {
- return mD3d12DescriptorHeap.Get();
+ ComPtr<ID3D12DescriptorHeap> descriptorHeap;
+ HRESULT hr = mDescriptorHeap->As(&descriptorHeap);
+ HRESULT hr = mDescriptorHeap.As(&descriptorHeap);
+ ASSERT(SUCCEEDED(hr));
+ return descriptorHeap.Get();
+}
+
+gpgmm::d3d12::Heap* ShaderVisibleDescriptorHeap::GetHeap() const {
+ return mDescriptorHeap.get();
+ return mDescriptorHeap.Get();
}
+
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
index cf09f9d50..008b54818 100644
index cf09f9d50..86a661c4a 100644
--- a/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
+++ b/src/dawn/native/d3d12/ShaderVisibleDescriptorAllocatorD3D12.h
@@ -24,6 +24,8 @@
Expand All @@ -882,13 +881,13 @@ index cf09f9d50..008b54818 100644
+class ShaderVisibleDescriptorHeap {
public:
- ShaderVisibleDescriptorHeap(ComPtr<ID3D12DescriptorHeap> d3d12DescriptorHeap, uint64_t size);
+ ShaderVisibleDescriptorHeap(std::unique_ptr<gpgmm::d3d12::Heap> descriptorHeap);
+ ShaderVisibleDescriptorHeap(ComPtr<gpgmm::d3d12::Heap> descriptorHeap);
ID3D12DescriptorHeap* GetD3D12DescriptorHeap() const;
+ gpgmm::d3d12::Heap* GetHeap() const;

private:
- ComPtr<ID3D12DescriptorHeap> mD3d12DescriptorHeap;
+ std::unique_ptr<gpgmm::d3d12::Heap> mDescriptorHeap;
+ ComPtr<gpgmm::d3d12::Heap> mDescriptorHeap;
};

class ShaderVisibleDescriptorAllocator {
Expand Down
2 changes: 1 addition & 1 deletion scripts/webnn.deps
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ deps = {
},

'third_party/webnn_native': {
'url': '{github_git}/webmachinelearning/webnn-native.git@bcbc5217cc92d7a0cc1c18f0809a16d6d0722e96',
'url': '{github_git}/webmachinelearning/webnn-native.git@294de6bca89094ede3f7693bb7d0c7edf44e5141',
'condition': 'checkout_webnn',
},

Expand Down
7 changes: 0 additions & 7 deletions src/gpgmm/d3d12/HeapD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,7 @@ namespace gpgmm::d3d12 {

\return Error HRESULT if the specified interface was not represented by the
heap.

\deprecated Use ComPtr<Heap::As instead of Heap::As.
*/
template <typename T>
HRESULT As(Microsoft::WRL::Details::ComPtrRef<ComPtr<T>> ptr) const {
return mPageable.As(ptr);
}

HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override;

/** \brief Determine if the heap is resident or not.
Expand Down
35 changes: 0 additions & 35 deletions src/gpgmm/d3d12/ResidencyListD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,4 @@ namespace gpgmm::d3d12 {
return "ResidencyList";
}

ResidencySet::ResidencySet() {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);
}

ResidencySet::~ResidencySet() {
GPGMM_TRACE_EVENT_OBJECT_DESTROY(this);
}

HRESULT ResidencySet::Insert(Heap* pHeap) {
if (pHeap == nullptr) {
return E_INVALIDARG;
}
if (mSet.insert(pHeap).second) {
return S_OK;
}
return S_FALSE;
}

HRESULT ResidencySet::Reset() {
mSet.clear();
return S_OK;
}

ResidencySet::UnderlyingType::iterator ResidencySet::begin() const {
return mSet.begin();
}

ResidencySet::UnderlyingType::iterator ResidencySet::end() const {
return mSet.end();
}

const char* ResidencySet::GetTypename() const {
return "ResidencySet";
}

} // namespace gpgmm::d3d12
56 changes: 3 additions & 53 deletions src/gpgmm/d3d12/ResidencyListD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "gpgmm/d3d12/d3d12_platform.h"
#include "include/gpgmm_export.h"

#include <set>
#include <vector>

namespace gpgmm::d3d12 {
Expand All @@ -28,7 +27,7 @@ namespace gpgmm::d3d12 {
/** \brief Represents a list of heaps which will be "made resident" when executing a
command-list.

A residency set helps track heaps for residency which will be referenced together by a
A residency list helps track heaps for residency which will be referenced together by a
command-list. The application uses a ResidencyList by inserting heaps, by calling
ResourceAllocation::GetMemory, into the list. Once ResidencyManager::ExecuteCommandLists is
called, the list can be reset or cleared for the next frame.
Expand All @@ -55,9 +54,9 @@ namespace gpgmm::d3d12 {
*/
HRESULT Add(Heap* pHeap);

/** \brief Reset this residency set.
/** \brief Reset this residency list.

Removes all heaps from the set so the set can be re-used.
Removes all heaps from the list so the list can be re-used.
*/
HRESULT Reset();

Expand All @@ -72,55 +71,6 @@ namespace gpgmm::d3d12 {
UnderlyingType mList;
};

/** \brief Represents a set of heaps which will be "made resident" when executing a
command-list.

A residency set helps track heaps for residency which will be referenced together by a
command-list. The application uses a ResidencySet by inserting heaps, by calling
ResourceAllocation::GetMemory, into the set. Once ResidencyManager::ExecuteCommandLists is
called, the set can be reset or cleared for the next frame.

Without a ResidencySet, the application would need to manually ResidencyManager::LockHeap and
ResidencyManager::UnlockHeap each heap before and after ResidencyManager::ExecuteCommandLists,
respectively.

\deprecated Use ResidencyList instead of ResidencySet.
*/
class GPGMM_EXPORT ResidencySet final {
public:
/** \brief Create a residency set or collection of heaps to manage together for residency.
*/
ResidencySet();
~ResidencySet();

ResidencySet(const ResidencySet&) = default;
ResidencySet& operator=(const ResidencySet&) = default;

/** \brief Insert heap into this residency set.

@param pHeap A pointer to Heap about to be inserted.

\return S_OK if heap was inserted or S_FALSE if heap was already inserted, else error.
*/
HRESULT Insert(Heap* pHeap);

/** \brief Reset this residency set.

Removes all heaps from the set so the set can be re-used.
*/
HRESULT Reset();

using UnderlyingType = std::set<Heap*>;

UnderlyingType::iterator begin() const;
UnderlyingType::iterator end() const;

private:
const char* GetTypename() const;

UnderlyingType mSet;
};

} // namespace gpgmm::d3d12

#endif
24 changes: 0 additions & 24 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,30 +565,6 @@ namespace gpgmm::d3d12 {
return S_OK;
}

/** \brief Execute command lists using residency managed heaps.
*
\deprecated use ResidencyList instead of ResidencySet
*/
HRESULT ResidencyManager::ExecuteCommandLists(ID3D12CommandQueue* pQueue,
ID3D12CommandList* const* ppCommandLists,
ResidencySet* const* ppResidencySets,
uint32_t count) {
ResidencyList residencyList;

// TODO: support multiple command lists.
if (count > 1) {
return E_NOTIMPL;
}

for (Heap* heap : *ppResidencySets[0]) {
residencyList.Add(heap);
}

ResidencyList* residencyListPtr = &residencyList;

return ExecuteCommandLists(pQueue, ppCommandLists, &residencyListPtr, count);
}

// Given a list of heaps that are pending usage, this function will estimate memory needed,
// evict resources until enough space is available, then make resident any heaps scheduled for
// usage.
Expand Down
17 changes: 0 additions & 17 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace gpgmm::d3d12 {
class Fence;
class Heap;
class ResidencyList;
class ResidencySet;
class ResourceAllocator;

/** \struct RESIDENCY_DESC
Expand Down Expand Up @@ -193,22 +192,6 @@ namespace gpgmm::d3d12 {
ResidencyList* const* ppResidencyLists,
uint32_t count);

/** \brief Execute command lists using residency managed heaps.

Submits an array of command lists and residency sets for the specified command queue.

@param pQueue The command queue to submit to.
@param ppCommandLists The array of ID3D12CommandList command lists to be executed.
@param ppResidencySets The array of ResidencySet residency sets to make resident.
@param count The size of commandLists and residencyLists arrays.

\deprecated Use ResidencyList instead of ResidencySet.
*/
HRESULT ExecuteCommandLists(ID3D12CommandQueue* pQueue,
ID3D12CommandList* const* ppCommandLists,
ResidencySet* const* ppResidencySets,
uint32_t count);

/** \brief Sets video memory reservation.

A reservation is the lowest amount of physical memory the application need to continue
Expand Down