From 5e1fb53c166f5145e8a68aa96da9d16fcde7a30d Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 27 Apr 2017 08:02:22 -0700 Subject: [PATCH] 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 --- .../modules/vulkan/draw/vktDrawImageObjectUtil.cpp | 53 ++++++---------------- .../modules/vulkan/draw/vktDrawImageObjectUtil.hpp | 6 --- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp index cd0b0eb..b825e08 100644 --- a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp +++ b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.cpp @@ -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(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(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 allocation) { DE_ASSERT(allocation); diff --git a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp index dcfa56b..1a96796 100644 --- a/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp +++ b/external/vulkancts/modules/vulkan/draw/vktDrawImageObjectUtil.hpp @@ -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, -- 2.7.4