Refactor image extent retrieval

Previously Image::getMipLevelExtent() was the only way to retrieve the
extent of an image, which didn't make sense for images for which we're
not accessing the mipmaps, like framebuffer attachments. A getExtent()
method was added for these cases where we only need the full extent.

Bug: b/162315264
Change-Id: I9c2b8ed42cbbd573e5a08f4bfafc4653ad377f7f
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/47928
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index 97b91f6..72f07d3 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -1743,10 +1743,10 @@
 
 void Blitter::copy(const vk::Image *src, uint8_t *dst, unsigned int dstPitch)
 {
-	VkExtent3D extent = src->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+	const VkExtent3D &extent = src->getExtent();
 	size_t rowBytes = src->getFormat(VK_IMAGE_ASPECT_COLOR_BIT).bytes() * extent.width;
 	unsigned int srcPitch = src->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
-	ASSERT(dstPitch >= rowBytes && srcPitch >= rowBytes && src->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0).height >= extent.height);
+	ASSERT(dstPitch >= rowBytes && srcPitch >= rowBytes);
 
 	const uint8_t *s = (uint8_t *)src->getTexelPointer({ 0, 0, 0 }, { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 });
 	uint8_t *d = dst;
diff --git a/src/Vulkan/VkImage.hpp b/src/Vulkan/VkImage.hpp
index d19b467..5af8790 100644
--- a/src/Vulkan/VkImage.hpp
+++ b/src/Vulkan/VkImage.hpp
@@ -82,6 +82,7 @@
 	uint32_t getMipLevels() const { return mipLevels; }
 	VkImageUsageFlags getUsage() const { return usage; }
 	VkSampleCountFlagBits getSampleCountFlagBits() const { return samples; }
+	const VkExtent3D &getExtent() const { return extent; }
 	VkExtent3D getMipLevelExtent(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
 	int rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
 	int slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
diff --git a/src/WSI/MetalSurface.mm b/src/WSI/MetalSurface.mm
index c4d5977..af5a4ae 100644
--- a/src/WSI/MetalSurface.mm
+++ b/src/WSI/MetalSurface.mm
@@ -147,7 +147,7 @@
         if(drawable)
         {
             VkExtent2D windowExtent = metalLayer->getExtent();
-            VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+            const VkExtent3D &extent = image->getImage()->getExtent();
 
             if(windowExtent.width != extent.width || windowExtent.height != extent.height)
             {
diff --git a/src/WSI/WaylandSurfaceKHR.cpp b/src/WSI/WaylandSurfaceKHR.cpp
index 2431673..ac7f2fc 100644
--- a/src/WSI/WaylandSurfaceKHR.cpp
+++ b/src/WSI/WaylandSurfaceKHR.cpp
@@ -70,7 +70,7 @@
 	WaylandImage *wlImage = new WaylandImage;
 	char path[] = "/tmp/XXXXXX";
 	int fd = mkstemp(path);
-	VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+	const VkExtent3D &extent = image->getImage()->getExtent();
 	int stride = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
 	ftruncate(fd, extent.height * stride);
 	struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, extent.height * stride);
@@ -87,7 +87,7 @@
 	if(it != imageMap.end())
 	{
 		WaylandImage *wlImage = it->second;
-		VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+		const VkExtent3D &extent = image->getImage()->getExtent();
 		int stride = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
 		munmap(wlImage->data, extent.height * stride);
 		wl_buffer_destroy(wlImage->buffer);
@@ -102,7 +102,7 @@
 	if(it != imageMap.end())
 	{
 		WaylandImage *wlImage = it->second;
-		VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+		const VkExtent3D &extent = image->getImage()->getExtent();
 		int bufferRowPitch = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
 		image->getImage()->copyTo(reinterpret_cast<uint8_t *>(wlImage->data), bufferRowPitch);
 		wl_surface_attach(surface, wlImage->buffer, 0, 0);
diff --git a/src/WSI/Win32SurfaceKHR.cpp b/src/WSI/Win32SurfaceKHR.cpp
index 6e067b3..8e4e8f3 100644
--- a/src/WSI/Win32SurfaceKHR.cpp
+++ b/src/WSI/Win32SurfaceKHR.cpp
@@ -88,7 +88,7 @@
 		return VK_SUCCESS;
 	}
 
-	VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+	const VkExtent3D &extent = image->getImage()->getExtent();
 
 	if(windowExtent.width != extent.width || windowExtent.height != extent.height)
 	{
diff --git a/src/WSI/XcbSurfaceKHR.cpp b/src/WSI/XcbSurfaceKHR.cpp
index 6f2f27f..a8ce43f 100644
--- a/src/WSI/XcbSurfaceKHR.cpp
+++ b/src/WSI/XcbSurfaceKHR.cpp
@@ -161,7 +161,7 @@
 	if(it != graphicsContexts.end())
 	{
 		VkExtent2D windowExtent = getWindowSize(connection, window);
-		VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+		const VkExtent3D &extent = image->getImage()->getExtent();
 
 		if(windowExtent.width != extent.width || windowExtent.height != extent.height)
 		{
diff --git a/src/WSI/XlibSurfaceKHR.cpp b/src/WSI/XlibSurfaceKHR.cpp
index cdbb2ca..9885e3c 100644
--- a/src/WSI/XlibSurfaceKHR.cpp
+++ b/src/WSI/XlibSurfaceKHR.cpp
@@ -59,7 +59,7 @@
 	XWindowAttributes attr;
 	libX11->XGetWindowAttributes(pDisplay, window, &attr);
 
-	VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+	const VkExtent3D &extent = image->getImage()->getExtent();
 
 	int bytes_per_line = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
 	char *buffer = static_cast<char *>(image->getImageMemory()->getOffsetPointer(0));
@@ -93,7 +93,7 @@
 			XWindowAttributes attr;
 			libX11->XGetWindowAttributes(pDisplay, window, &attr);
 			VkExtent2D windowExtent = { static_cast<uint32_t>(attr.width), static_cast<uint32_t>(attr.height) };
-			VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+			const VkExtent3D &extent = image->getImage()->getExtent();
 
 			if(windowExtent.width != extent.width || windowExtent.height != extent.height)
 			{