dEQP-VK: Fix and inline the Image::getPixelOffset helper
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 27 Apr 2017 15:02:22 +0000 (08:02 -0700)
committerPyry Haulos <phaulos@google.com>
Wed, 3 May 2017 17:47:06 +0000 (10:47 -0700)
The helper was wrong in a number of ways.  First, it tries to calculate
an offset to the particular mip level and array layer requested even
though the driver already provides that as part of the offset returned
by getImageSubresourceLayout.  If someone tried to use this with a
non-zero mip level or array layer they would get the wrong offset
because it would be added in twice.  Second, the calculation depended on
an array called mipLevelRectSizes array which was used but never
initialized.  This commit gets rid of the helper and just does the right
calculation inside MemoryOp::readLinear and MemoryOp::uploadLinear.

This affects the following groups of tests:

 - dEQP-VK.draw.*
 - dEQP-VK.dynamic_state.*
 - dEQP-VK.query_pool.*

Change-Id: If0da72023cbc437d2a13d60f83e1230f0f90ba39

external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp
external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp

index cd0b0eb..b825e08 100644 (file)
@@ -402,6 +402,9 @@ void Image::readLinear (vk::VkOffset3D                              offset,
                                                vk::VkImageAspectFlagBits       aspect,
                                                void *                                          data)
 {
+       DE_ASSERT(mipLevel < m_levelCount);
+       DE_ASSERT(arrayElement < m_layerCount);
+
        vk::VkImageSubresource imageSubResource = { (vk::VkImageAspectFlags)aspect, mipLevel, arrayElement };
 
        vk::VkSubresourceLayout imageLayout;
@@ -410,7 +413,10 @@ void Image::readLinear (vk::VkOffset3D                             offset,
        m_vk.getImageSubresourceLayout(m_device, object(), &imageSubResource, &imageLayout);
 
        const deUint8* srcPtr = reinterpret_cast<const deUint8*>(getBoundMemory().getHostPtr());
-       srcPtr += imageLayout.offset + getPixelOffset(offset, imageLayout.rowPitch, imageLayout.depthPitch, mipLevel, arrayElement);
+       srcPtr += imageLayout.offset;
+       srcPtr += offset.z * imageLayout.depthPitch;
+       srcPtr += offset.y * imageLayout.rowPitch;
+       srcPtr += offset.x;
 
        MemoryOp::unpack(vk::mapVkFormat(m_format).getPixelSize(), width, height, depth,
                imageLayout.rowPitch, imageLayout.depthPitch, srcPtr, data);
@@ -793,6 +799,9 @@ void Image::uploadLinear (vk::VkOffset3D                    offset,
                                                  vk::VkImageAspectFlagBits     aspect,
                                                  const void *                          data)
 {
+       DE_ASSERT(mipLevel < m_levelCount);
+       DE_ASSERT(arrayElement < m_layerCount);
+
        vk::VkSubresourceLayout imageLayout;
 
        vk::VkImageSubresource imageSubResource = { (vk::VkImageAspectFlags)aspect, mipLevel, arrayElement};
@@ -801,49 +810,15 @@ void Image::uploadLinear (vk::VkOffset3D                  offset,
                                                                                                        &imageLayout);
 
        deUint8* destPtr = reinterpret_cast<deUint8*>(getBoundMemory().getHostPtr());
-
-       destPtr += imageLayout.offset + getPixelOffset(offset, imageLayout.rowPitch, imageLayout.depthPitch, mipLevel, arrayElement);
+       destPtr += imageLayout.offset;
+       destPtr += offset.z * imageLayout.depthPitch;
+       destPtr += offset.y * imageLayout.rowPitch;
+       destPtr += offset.x;
 
        MemoryOp::pack(vk::mapVkFormat(m_format).getPixelSize(), width, height, depth,
                imageLayout.rowPitch, imageLayout.depthPitch, data, destPtr);
 }
 
-vk::VkDeviceSize Image::getPixelOffset (vk::VkOffset3D         offset,
-                                                                               vk::VkDeviceSize        rowPitch,
-                                                                               vk::VkDeviceSize        depthPitch,
-                                                                               unsigned int            level,
-                                                                               unsigned int            layer)
-{
-       DE_ASSERT(level < m_levelCount);
-       DE_ASSERT(layer < m_layerCount);
-
-       vk::VkDeviceSize mipLevelSizes[32];
-       vk::VkDeviceSize mipLevelRectSizes[32];
-       tcu::IVec3 mipExtend
-       = tcu::IVec3(m_extent.width, m_extent.height, m_extent.depth);
-
-       vk::VkDeviceSize arrayElemSize = 0;
-       for (unsigned int i = 0; i < m_levelCount && (mipExtend[0] > 1 || mipExtend[1] > 1 || mipExtend[2] > 1); ++i)
-       {
-               // Rect size is just a 3D image size;
-               mipLevelSizes[i] = mipExtend[2] * depthPitch;
-
-               arrayElemSize += mipLevelSizes[0];
-
-               mipExtend = tcu::max(mipExtend / 2, tcu::IVec3(1));
-       }
-
-       vk::VkDeviceSize pixelOffset = layer * arrayElemSize;
-       for (size_t i = 0; i < level; ++i) {
-               pixelOffset += mipLevelSizes[i];
-       }
-       pixelOffset += offset.z * mipLevelRectSizes[level];
-       pixelOffset += offset.y * rowPitch;
-       pixelOffset += offset.x;
-
-       return pixelOffset;
-}
-
 void Image::bindMemory (de::MovePtr<vk::Allocation> allocation)
 {
        DE_ASSERT(allocation);
index dcfa56b..1a96796 100644 (file)
@@ -230,12 +230,6 @@ public:
        vk::Allocation                          getBoundMemory          (void) const                                                                                    { return *m_allocation; }
 
 private:
-       vk::VkDeviceSize                        getPixelOffset          (vk::VkOffset3D                                                 offset,
-                                                                                                        vk::VkDeviceSize                                               rowPitch,
-                                                                                                        vk::VkDeviceSize                                               depthPitch,
-                                                                                                        unsigned int                                                   mipLevel,
-                                                                                                        unsigned int                                                   arrayElement);
-
                                                                Image                           (const vk::DeviceInterface&                             vk,
                                                                                                         vk::VkDevice                                                   device,
                                                                                                         vk::VkFormat                                                   format,