dEQP-VK: Fix and inline the Image::getPixelOffset helper
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
diff --git a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp
index 22315d5..0499dfd 100644
--- a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp
+++ b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp
@@ -402,7 +402,10 @@
vk::VkImageAspectFlagBits aspect,
void * data)
{
- vk::VkImageSubresource imageSubResource = { aspect, mipLevel, arrayElement };
+ 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 @@
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 @@
vk::VkImageAspectFlagBits aspect,
const void * data)
{
+ DE_ASSERT(mipLevel < m_levelCount);
+ DE_ASSERT(arrayElement < m_layerCount);
+
vk::VkSubresourceLayout imageLayout;
vk::VkImageSubresource imageSubResource = {aspect, mipLevel, arrayElement};
@@ -801,49 +810,15 @@
&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);
diff --git a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp
index 8c80f4d..befdc32 100644
--- a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp
+++ b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp
@@ -229,12 +229,6 @@
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,