CommandAllocator: Default initalize allocated data.

BUG=dawn:21

Change-Id: I98499385d7397ab431e1bbe00add7ef01941cca6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7160
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2019-05-14 03:53:26 +00:00
committed by Commit Bot service account
parent 97f08fa2e6
commit 2e56970932
6 changed files with 61 additions and 24 deletions

View File

@@ -113,14 +113,26 @@ namespace dawn_native {
static_assert(sizeof(E) == sizeof(uint32_t), "");
static_assert(alignof(E) == alignof(uint32_t), "");
static_assert(alignof(T) <= kMaxSupportedAlignment, "");
return reinterpret_cast<T*>(
T* result = reinterpret_cast<T*>(
Allocate(static_cast<uint32_t>(commandId), sizeof(T), alignof(T)));
if (!result) {
return nullptr;
}
new (result) T;
return result;
}
template <typename T>
T* AllocateData(size_t count) {
static_assert(alignof(T) <= kMaxSupportedAlignment, "");
return reinterpret_cast<T*>(AllocateData(sizeof(T) * count, alignof(T)));
T* result = reinterpret_cast<T*>(AllocateData(sizeof(T) * count, alignof(T)));
if (!result) {
return nullptr;
}
for (size_t i = 0; i < count; i++) {
new (result + i) T;
}
return result;
}
private: