Revert "Vulkan: Allow setting multiple `MemoryKind` bits"
This reverts commit a8f733807cbf72ebab8baecbda359ca4413d00c7.
Reason for revert: Breaking CTS roll on Ci only bot. https://ci.chromium.org/ui/p/chromium/builders/try/linux-dawn-nvidia-1660-exp-rel/1157/overview
Can you please add the `Include-Ci-Only-Tests: true` footer when relanding to run on the CI only bot?
Original change's description:
> Vulkan: Allow setting multiple `MemoryKind` bits
>
> This patch allows setting multiple MemoryKind bits in one MemoryKind
> value and replaces MemoryKind::Opaque with MemoryKind::DeviceLocal as
> a preparation of the implementation of BufferMapExtendedUsage on
> Vulkan.
>
> Bug: 386255678
> Change-Id: I68f77de15d8267ae985d49f73497410fb08fbd49
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/227697
> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: 386255678
Change-Id: I218a6f8426bfae726c3cce6209f77068be66e5e8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/229454
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
diff --git a/src/dawn/native/vulkan/BufferVk.cpp b/src/dawn/native/vulkan/BufferVk.cpp
index 558a7c5..c789fd3 100644
--- a/src/dawn/native/vulkan/BufferVk.cpp
+++ b/src/dawn/native/vulkan/BufferVk.cpp
@@ -235,9 +235,9 @@
MemoryKind requestKind = MemoryKind::Linear;
if (GetInternalUsage() & wgpu::BufferUsage::MapRead) {
- requestKind |= MemoryKind::ReadMappable;
+ requestKind = MemoryKind::LinearReadMappable;
} else if (GetInternalUsage() & wgpu::BufferUsage::MapWrite) {
- requestKind |= MemoryKind::WriteMappable;
+ requestKind = MemoryKind::LinearWriteMappable;
}
DAWN_TRY_ASSIGN(mMemoryAllocation,
device->GetResourceMemoryAllocator()->Allocate(requirements, requestKind));
@@ -330,13 +330,13 @@
requirements.memoryTypeBits &= hostPointerProperties.memoryTypeBits;
}
- MemoryKind requestKind = MemoryKind::Linear;
+ MemoryKind requestKind;
if (GetInternalUsage() & wgpu::BufferUsage::MapRead) {
- requestKind |= MemoryKind::ReadMappable;
+ requestKind = MemoryKind::LinearReadMappable;
} else if (GetInternalUsage() & wgpu::BufferUsage::MapWrite) {
- requestKind |= MemoryKind::WriteMappable;
+ requestKind = MemoryKind::LinearWriteMappable;
} else {
- requestKind |= MemoryKind::DeviceLocal;
+ requestKind = MemoryKind::Linear;
}
int memoryTypeIndex =
diff --git a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp
index 48e5473..0cf9204 100644
--- a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp
+++ b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.cpp
@@ -54,7 +54,19 @@
constexpr uint64_t kBuddyHeapsSize = 2 * kMaxSizeForSubAllocation;
bool IsMemoryKindMappable(MemoryKind memoryKind) {
- return memoryKind & (MemoryKind::ReadMappable | MemoryKind::WriteMappable);
+ switch (memoryKind) {
+ case MemoryKind::LinearReadMappable:
+ case MemoryKind::LinearWriteMappable:
+ return true;
+
+ case MemoryKind::LazilyAllocated:
+ case MemoryKind::Linear:
+ case MemoryKind::Opaque:
+ return false;
+
+ default:
+ DAWN_UNREACHABLE();
+ }
}
} // anonymous namespace
@@ -280,12 +292,6 @@
continue;
}
- // DEVICE_LOCAL_BIT must be set when MemoryKind::DeviceLocal is required.
- if ((kind & MemoryKind::DeviceLocal) &&
- (info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == 0) {
- continue;
- }
-
// Found the first candidate memory type
if (bestType == -1) {
bestType = static_cast<int>(i);
@@ -326,7 +332,7 @@
info.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
bool bestHostCached =
info.memoryTypes[bestType].propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
- if ((kind & MemoryKind::ReadMappable) && currentHostCached != bestHostCached) {
+ if (kind == MemoryKind::LinearReadMappable && currentHostCached != bestHostCached) {
if (currentHostCached) {
bestType = static_cast<int>(i);
}
diff --git a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h
index 93df422..8703dc1 100644
--- a/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h
+++ b/src/dawn/native/vulkan/ResourceMemoryAllocatorVk.h
@@ -43,14 +43,14 @@
class Device;
-// Each bit of MemoryKind represents a kind of memory that influence the result of the allocation.
-// For example, to take into account mappability and Vulkan's bufferImageGranularity.
-enum class MemoryKind : uint8_t {
- LazilyAllocated = 1,
- Linear = 2,
- DeviceLocal = 4,
- ReadMappable = 8,
- WriteMappable = 16,
+// Various kinds of memory that influence the result of the allocation. For example, to take
+// into account mappability and Vulkan's bufferImageGranularity.
+enum class MemoryKind {
+ LazilyAllocated,
+ Linear,
+ LinearReadMappable,
+ LinearWriteMappable,
+ Opaque,
};
class ResourceMemoryAllocator {
@@ -80,12 +80,4 @@
} // namespace dawn::native::vulkan
-namespace wgpu {
-template <>
-struct IsWGPUBitmask<dawn::native::vulkan::MemoryKind> {
- static constexpr bool enable = true;
-};
-
-} // namespace wgpu
-
#endif // SRC_DAWN_NATIVE_VULKAN_RESOURCEMEMORYALLOCATORVK_H_
diff --git a/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp b/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
index 67e2887..4bf68bd 100644
--- a/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
+++ b/src/dawn/native/vulkan/SharedTextureMemoryVk.cpp
@@ -439,7 +439,7 @@
// import's constraint.
memoryRequirements.memoryTypeBits &= fdProperties.memoryTypeBits;
int memoryTypeIndex = device->GetResourceMemoryAllocator()->FindBestTypeIndex(
- memoryRequirements, MemoryKind::DeviceLocal);
+ memoryRequirements, MemoryKind::Opaque);
DAWN_INVALID_IF(memoryTypeIndex == -1, "Unable to find an appropriate memory type for import.");
SystemHandle memoryFD;
@@ -669,7 +669,7 @@
VkMemoryRequirements memoryRequirements;
memoryRequirements.memoryTypeBits = bufferProperties.memoryTypeBits;
int memoryTypeIndex = device->GetResourceMemoryAllocator()->FindBestTypeIndex(
- memoryRequirements, MemoryKind::DeviceLocal);
+ memoryRequirements, MemoryKind::Opaque);
DAWN_INVALID_IF(memoryTypeIndex == -1,
"Unable to find an appropriate memory type for import.");
diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp
index 9861608..2cabce5 100644
--- a/src/dawn/native/vulkan/TextureVk.cpp
+++ b/src/dawn/native/vulkan/TextureVk.cpp
@@ -1382,7 +1382,7 @@
(GetInternalUsage() & (wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::RenderAttachment));
auto memoryKind = (GetInternalUsage() & wgpu::TextureUsage::TransientAttachment)
? MemoryKind::LazilyAllocated
- : MemoryKind::DeviceLocal;
+ : MemoryKind::Opaque;
DAWN_TRY_ASSIGN(mMemoryAllocation, device->GetResourceMemoryAllocator()->Allocate(
requirements, memoryKind, forceDisableSubAllocation));
diff --git a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
index d02ebe3..9178027 100644
--- a/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
+++ b/src/dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.cpp
@@ -264,7 +264,7 @@
// import's constraint.
memoryRequirements.memoryTypeBits &= fdProperties.memoryTypeBits;
int memoryTypeIndex = mDevice->GetResourceMemoryAllocator()->FindBestTypeIndex(
- memoryRequirements, MemoryKind::DeviceLocal);
+ memoryRequirements, MemoryKind::Opaque);
DAWN_INVALID_IF(memoryTypeIndex == -1,
"Unable to find an appropriate memory type for import.");
diff --git a/src/dawn/tests/white_box/SharedTextureMemoryTests_opaquefd.cpp b/src/dawn/tests/white_box/SharedTextureMemoryTests_opaquefd.cpp
index 71d313a..407057c 100644
--- a/src/dawn/tests/white_box/SharedTextureMemoryTests_opaquefd.cpp
+++ b/src/dawn/tests/white_box/SharedTextureMemoryTests_opaquefd.cpp
@@ -84,7 +84,7 @@
deviceVk->fn.GetImageMemoryRequirements(deviceVk->GetVkDevice(), vkImage, &requirements);
int bestType = deviceVk->GetResourceMemoryAllocator()->FindBestTypeIndex(
- requirements, native::vulkan::MemoryKind::DeviceLocal);
+ requirements, native::vulkan::MemoryKind::Opaque);
EXPECT_GE(bestType, 0);
VkMemoryDedicatedAllocateInfo dedicatedInfo;
diff --git a/src/dawn/tests/white_box/VulkanImageWrappingTests_OpaqueFD.cpp b/src/dawn/tests/white_box/VulkanImageWrappingTests_OpaqueFD.cpp
index 97042cc..cd16976 100644
--- a/src/dawn/tests/white_box/VulkanImageWrappingTests_OpaqueFD.cpp
+++ b/src/dawn/tests/white_box/VulkanImageWrappingTests_OpaqueFD.cpp
@@ -230,7 +230,7 @@
deviceVk->fn.GetImageMemoryRequirements(deviceVk->GetVkDevice(), handle, &requirements);
int bestType = deviceVk->GetResourceMemoryAllocator()->FindBestTypeIndex(
- requirements, MemoryKind::DeviceLocal);
+ requirements, MemoryKind::Opaque);
VkMemoryAllocateInfo allocateInfo;
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;