2019-08-27 23:36:26 +00:00
|
|
|
// Copyright 2019 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "dawn_native/ResourceMemoryAllocation.h"
|
|
|
|
#include "common/Assert.h"
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
namespace dawn_native {
|
|
|
|
|
2019-09-05 17:36:47 +00:00
|
|
|
static constexpr uint64_t kInvalidOffset = std::numeric_limits<uint64_t>::max();
|
2019-08-27 23:36:26 +00:00
|
|
|
|
|
|
|
ResourceMemoryAllocation::ResourceMemoryAllocation()
|
2019-09-05 17:36:47 +00:00
|
|
|
: mMethod(AllocationMethod::kInvalid),
|
|
|
|
mOffset(0),
|
|
|
|
mResourceHeap(nullptr),
|
|
|
|
mMappedPointer(nullptr) {
|
2019-08-27 23:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceMemoryAllocation::ResourceMemoryAllocation(uint64_t offset,
|
|
|
|
ResourceHeapBase* resourceHeap,
|
2019-09-05 17:36:47 +00:00
|
|
|
AllocationMethod method,
|
|
|
|
uint8_t* mappedPointer)
|
|
|
|
: mMethod(method),
|
|
|
|
mOffset(offset),
|
|
|
|
mResourceHeap(resourceHeap),
|
|
|
|
mMappedPointer(mappedPointer) {
|
2019-08-27 23:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResourceHeapBase* ResourceMemoryAllocation::GetResourceHeap() const {
|
|
|
|
ASSERT(mMethod != AllocationMethod::kInvalid);
|
|
|
|
return mResourceHeap;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ResourceMemoryAllocation::GetOffset() const {
|
|
|
|
ASSERT(mMethod != AllocationMethod::kInvalid);
|
|
|
|
return mOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
AllocationMethod ResourceMemoryAllocation::GetAllocationMethod() const {
|
|
|
|
return mMethod;
|
|
|
|
}
|
|
|
|
|
2019-09-05 17:36:47 +00:00
|
|
|
uint8_t* ResourceMemoryAllocation::GetMappedPointer() const {
|
|
|
|
return mMappedPointer;
|
|
|
|
}
|
|
|
|
|
2019-08-27 23:36:26 +00:00
|
|
|
void ResourceMemoryAllocation::Invalidate() {
|
|
|
|
mResourceHeap = nullptr;
|
|
|
|
mMethod = AllocationMethod::kInvalid;
|
2019-09-05 17:36:47 +00:00
|
|
|
mOffset = kInvalidOffset;
|
2019-08-27 23:36:26 +00:00
|
|
|
}
|
|
|
|
} // namespace dawn_native
|