Commit 1f48854d by Nicolas Capens Committed by Nicolas Capens

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: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 3b5f0b41
......@@ -1743,10 +1743,10 @@ Blitter::CornerUpdateRoutineType Blitter::getCornerUpdateRoutine(const State &st
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;
......
......@@ -82,6 +82,7 @@ public:
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;
......
......@@ -147,7 +147,7 @@ VkResult MetalSurface::present(PresentImage* image) API_AVAILABLE(macosx(10.11))
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)
{
......
......@@ -70,7 +70,7 @@ void WaylandSurfaceKHR::attachImage(PresentImage *image)
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 @@ void WaylandSurfaceKHR::detachImage(PresentImage *image)
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 @@ VkResult WaylandSurfaceKHR::present(PresentImage *image)
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);
......
......@@ -88,7 +88,7 @@ VkResult Win32SurfaceKHR::present(PresentImage *image)
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)
{
......
......@@ -161,7 +161,7 @@ VkResult XcbSurfaceKHR::present(PresentImage *image)
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)
{
......
......@@ -59,7 +59,7 @@ void XlibSurfaceKHR::attachImage(PresentImage *image)
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 @@ VkResult XlibSurfaceKHR::present(PresentImage *image)
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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment