• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "dawn_native/d3d12/PageableD3D12.h"
16 
17 namespace dawn_native { namespace d3d12 {
Pageable(ComPtr<ID3D12Pageable> d3d12Pageable,MemorySegment memorySegment,uint64_t size)18     Pageable::Pageable(ComPtr<ID3D12Pageable> d3d12Pageable,
19                        MemorySegment memorySegment,
20                        uint64_t size)
21         : mD3d12Pageable(std::move(d3d12Pageable)), mMemorySegment(memorySegment), mSize(size) {
22     }
23 
24     // When a pageable is destroyed, it no longer resides in resident memory, so we must evict
25     // it from the LRU cache. If this heap is not manually removed from the LRU-cache, the
26     // ResidencyManager will attempt to use it after it has been deallocated.
~Pageable()27     Pageable::~Pageable() {
28         if (IsInResidencyLRUCache()) {
29             RemoveFromList();
30         }
31     }
32 
GetD3D12Pageable() const33     ID3D12Pageable* Pageable::GetD3D12Pageable() const {
34         return mD3d12Pageable.Get();
35     }
36 
GetLastUsage() const37     ExecutionSerial Pageable::GetLastUsage() const {
38         return mLastUsage;
39     }
40 
SetLastUsage(ExecutionSerial serial)41     void Pageable::SetLastUsage(ExecutionSerial serial) {
42         mLastUsage = serial;
43     }
44 
GetLastSubmission() const45     ExecutionSerial Pageable::GetLastSubmission() const {
46         return mLastSubmission;
47     }
48 
SetLastSubmission(ExecutionSerial serial)49     void Pageable::SetLastSubmission(ExecutionSerial serial) {
50         mLastSubmission = serial;
51     }
52 
GetMemorySegment() const53     MemorySegment Pageable::GetMemorySegment() const {
54         return mMemorySegment;
55     }
56 
GetSize() const57     uint64_t Pageable::GetSize() const {
58         return mSize;
59     }
60 
IsInResidencyLRUCache() const61     bool Pageable::IsInResidencyLRUCache() const {
62         return IsInList();
63     }
64 
IncrementResidencyLock()65     void Pageable::IncrementResidencyLock() {
66         mResidencyLockRefCount++;
67     }
68 
DecrementResidencyLock()69     void Pageable::DecrementResidencyLock() {
70         mResidencyLockRefCount--;
71     }
72 
IsResidencyLocked() const73     bool Pageable::IsResidencyLocked() const {
74         return mResidencyLockRefCount != 0;
75     }
76 }}  // namespace dawn_native::d3d12
77