Only zero-initialize device memory for non-MSan GN builds

Chromium might still be susceptible to information disclosure issues if
we don't clear Vulkan "device" memory allocations, so we keep the
previous behavior of zeroing the memory except for MSan builds through
the SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY flag.

All other builds now leave the memory uninitialized.

sw::allocateUninitialized() was renamed to sw::allocate().

Bug: b/140991626
Change-Id: I05275fca454481107b75fffbca1d37afd757937d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/66009
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/System/Memory.cpp b/src/System/Memory.cpp
index 0333afb..3565914 100644
--- a/src/System/Memory.cpp
+++ b/src/System/Memory.cpp
@@ -98,8 +98,7 @@
 	return aligned;
 }
 
-// TODO(b/140991626): Rename to allocate().
-void *allocateUninitialized(size_t bytes, size_t alignment)
+void *allocate(size_t bytes, size_t alignment)
 {
 	return allocate(bytes, alignment, false);
 }
diff --git a/src/System/Memory.hpp b/src/System/Memory.hpp
index 9a12a4f..99e4374 100644
--- a/src/System/Memory.hpp
+++ b/src/System/Memory.hpp
@@ -22,9 +22,9 @@
 
 size_t memoryPageSize();
 
-void *allocateUninitialized(size_t bytes, size_t alignment = 16);  // Never initialized.
-void *allocateZero(size_t bytes, size_t alignment = 16);           // Always initialized to zero.
-void *allocateZeroOrPoison(size_t bytes, size_t alignment = 16);   // Initialized to zero, except in MemorySanitizer builds.
+void *allocate(size_t bytes, size_t alignment = 16);              // Never initialized.
+void *allocateZero(size_t bytes, size_t alignment = 16);          // Always initialized to zero.
+void *allocateZeroOrPoison(size_t bytes, size_t alignment = 16);  // Initialized to zero, except in MemorySanitizer builds.
 
 void freeMemory(void *memory);
 
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn
index 1bb14a8..a8afc99 100644
--- a/src/Vulkan/BUILD.gn
+++ b/src/Vulkan/BUILD.gn
@@ -57,6 +57,7 @@
   defines += [
      "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
      "SWIFTSHADER_LEGACY_PRECISION=true",  # TODO(chromium:1299047)
+     "SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY",
   ]
 }
 
diff --git a/src/Vulkan/VkMemory.cpp b/src/Vulkan/VkMemory.cpp
index 2789bdf..c522e5f 100644
--- a/src/Vulkan/VkMemory.cpp
+++ b/src/Vulkan/VkMemory.cpp
@@ -21,12 +21,10 @@
 
 void *allocateDeviceMemory(size_t bytes, size_t alignment)
 {
-	// TODO(b/140991626): Use allocateZeroOrPoison() instead of allocateZero() to detect MemorySanitizer errors.
 #if defined(SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY)
-	return sw::allocateZero(bytes, alignment);
-#else
-	// TODO(b/140991626): Use allocateUninitialized() instead of allocateZeroOrPoison() to improve startup peformance.
 	return sw::allocateZeroOrPoison(bytes, alignment);
+#else
+	return sw::allocate(bytes, alignment);
 #endif
 }
 
@@ -43,7 +41,7 @@
 	}
 	else
 	{
-		// TODO(b/140991626): Use allocateUninitialized() instead of allocateZeroOrPoison() to improve startup peformance.
+		// TODO(b/140991626): Use allocate() instead of allocateZeroOrPoison() to improve startup performance.
 		return sw::allocateZeroOrPoison(bytes, alignment);
 	}
 }
diff --git a/src/Vulkan/VkSpecializationInfo.cpp b/src/Vulkan/VkSpecializationInfo.cpp
index ff8cf8b..ec0ce3f 100644
--- a/src/Vulkan/VkSpecializationInfo.cpp
+++ b/src/Vulkan/VkSpecializationInfo.cpp
@@ -26,12 +26,12 @@
 	{
 		info.mapEntryCount = specializationInfo->mapEntryCount;
 		size_t entriesSize = specializationInfo->mapEntryCount * sizeof(VkSpecializationMapEntry);
-		void *mapEntries = sw::allocateUninitialized(entriesSize);
+		void *mapEntries = sw::allocate(entriesSize);
 		memcpy(mapEntries, specializationInfo->pMapEntries, entriesSize);
 		info.pMapEntries = reinterpret_cast<VkSpecializationMapEntry *>(mapEntries);
 
 		info.dataSize = specializationInfo->dataSize;
-		void *data = sw::allocateUninitialized(specializationInfo->dataSize);
+		void *data = sw::allocate(specializationInfo->dataSize);
 		memcpy(data, specializationInfo->pData, specializationInfo->dataSize);
 		info.pData = data;
 	}