1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------ 2e5c31af7Sopenharmony_ci * Vulkan Conformance Tests 3e5c31af7Sopenharmony_ci * ------------------------ 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright (c) 2017 The Khronos Group Inc. 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 17e5c31af7Sopenharmony_ci * limitations under the License. 18e5c31af7Sopenharmony_ci * 19e5c31af7Sopenharmony_ci *//*! 20e5c31af7Sopenharmony_ci * \file vktImageCompressionTranscodingSupport.cpp 21e5c31af7Sopenharmony_ci * \brief Compression transcoding support 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "vktImageCompressionTranscodingSupport.hpp" 25e5c31af7Sopenharmony_ci#include "vktImageLoadStoreUtil.hpp" 26e5c31af7Sopenharmony_ci 27e5c31af7Sopenharmony_ci#include "deUniquePtr.hpp" 28e5c31af7Sopenharmony_ci#include "deStringUtil.hpp" 29e5c31af7Sopenharmony_ci#include "deSharedPtr.hpp" 30e5c31af7Sopenharmony_ci#include "deRandom.hpp" 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ci#include "vktTestCaseUtil.hpp" 33e5c31af7Sopenharmony_ci#include "vkPrograms.hpp" 34e5c31af7Sopenharmony_ci#include "vkImageUtil.hpp" 35e5c31af7Sopenharmony_ci#include "vkBarrierUtil.hpp" 36e5c31af7Sopenharmony_ci#include "vktImageTestsUtil.hpp" 37e5c31af7Sopenharmony_ci#include "vkBuilderUtil.hpp" 38e5c31af7Sopenharmony_ci#include "vkRef.hpp" 39e5c31af7Sopenharmony_ci#include "vkRefUtil.hpp" 40e5c31af7Sopenharmony_ci#include "vkTypeUtil.hpp" 41e5c31af7Sopenharmony_ci#include "vkQueryUtil.hpp" 42e5c31af7Sopenharmony_ci#include "vkCmdUtil.hpp" 43e5c31af7Sopenharmony_ci#include "vkObjUtil.hpp" 44e5c31af7Sopenharmony_ci#include "vkBufferWithMemory.hpp" 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci#include "tcuTextureUtil.hpp" 47e5c31af7Sopenharmony_ci#include "tcuTexture.hpp" 48e5c31af7Sopenharmony_ci#include "tcuCompressedTexture.hpp" 49e5c31af7Sopenharmony_ci#include "tcuVectorType.hpp" 50e5c31af7Sopenharmony_ci#include "tcuResource.hpp" 51e5c31af7Sopenharmony_ci#include "tcuImageIO.hpp" 52e5c31af7Sopenharmony_ci#include "tcuImageCompare.hpp" 53e5c31af7Sopenharmony_ci#include "tcuTestLog.hpp" 54e5c31af7Sopenharmony_ci#include "tcuRGBA.hpp" 55e5c31af7Sopenharmony_ci#include "tcuSurface.hpp" 56e5c31af7Sopenharmony_ci 57e5c31af7Sopenharmony_ci#include <vector> 58e5c31af7Sopenharmony_ci 59e5c31af7Sopenharmony_ciusing namespace vk; 60e5c31af7Sopenharmony_cinamespace vkt 61e5c31af7Sopenharmony_ci{ 62e5c31af7Sopenharmony_cinamespace image 63e5c31af7Sopenharmony_ci{ 64e5c31af7Sopenharmony_cinamespace 65e5c31af7Sopenharmony_ci{ 66e5c31af7Sopenharmony_ciusing std::string; 67e5c31af7Sopenharmony_ciusing std::vector; 68e5c31af7Sopenharmony_ciusing tcu::TestContext; 69e5c31af7Sopenharmony_ciusing tcu::TestStatus; 70e5c31af7Sopenharmony_ciusing tcu::UVec3; 71e5c31af7Sopenharmony_ciusing tcu::IVec3; 72e5c31af7Sopenharmony_ciusing tcu::CompressedTexFormat; 73e5c31af7Sopenharmony_ciusing tcu::CompressedTexture; 74e5c31af7Sopenharmony_ciusing tcu::Resource; 75e5c31af7Sopenharmony_ciusing tcu::Archive; 76e5c31af7Sopenharmony_ciusing tcu::ConstPixelBufferAccess; 77e5c31af7Sopenharmony_ciusing de::MovePtr; 78e5c31af7Sopenharmony_ciusing de::SharedPtr; 79e5c31af7Sopenharmony_ciusing de::Random; 80e5c31af7Sopenharmony_ci 81e5c31af7Sopenharmony_citypedef SharedPtr<MovePtr<Image> > ImageSp; 82e5c31af7Sopenharmony_citypedef SharedPtr<Move<VkImageView> > ImageViewSp; 83e5c31af7Sopenharmony_citypedef SharedPtr<Move<VkDescriptorSet> > SharedVkDescriptorSet; 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_cienum ShaderType 86e5c31af7Sopenharmony_ci{ 87e5c31af7Sopenharmony_ci SHADER_TYPE_COMPUTE, 88e5c31af7Sopenharmony_ci SHADER_TYPE_FRAGMENT, 89e5c31af7Sopenharmony_ci SHADER_TYPE_LAST 90e5c31af7Sopenharmony_ci}; 91e5c31af7Sopenharmony_ci 92e5c31af7Sopenharmony_cienum Operation 93e5c31af7Sopenharmony_ci{ 94e5c31af7Sopenharmony_ci OPERATION_IMAGE_LOAD, 95e5c31af7Sopenharmony_ci OPERATION_TEXEL_FETCH, 96e5c31af7Sopenharmony_ci OPERATION_TEXTURE, 97e5c31af7Sopenharmony_ci OPERATION_IMAGE_STORE, 98e5c31af7Sopenharmony_ci OPERATION_ATTACHMENT_READ, 99e5c31af7Sopenharmony_ci OPERATION_ATTACHMENT_WRITE, 100e5c31af7Sopenharmony_ci OPERATION_TEXTURE_READ, 101e5c31af7Sopenharmony_ci OPERATION_TEXTURE_WRITE, 102e5c31af7Sopenharmony_ci OPERATION_LAST 103e5c31af7Sopenharmony_ci}; 104e5c31af7Sopenharmony_ci 105e5c31af7Sopenharmony_cistruct TestParameters 106e5c31af7Sopenharmony_ci{ 107e5c31af7Sopenharmony_ci Operation operation; 108e5c31af7Sopenharmony_ci ShaderType shader; 109e5c31af7Sopenharmony_ci UVec3 size; 110e5c31af7Sopenharmony_ci deUint32 layers; 111e5c31af7Sopenharmony_ci ImageType imageType; 112e5c31af7Sopenharmony_ci VkFormat formatCompressed; 113e5c31af7Sopenharmony_ci VkFormat formatUncompressed; 114e5c31af7Sopenharmony_ci deUint32 imagesCount; 115e5c31af7Sopenharmony_ci VkImageUsageFlags compressedImageUsage; 116e5c31af7Sopenharmony_ci VkImageUsageFlags compressedImageViewUsage; 117e5c31af7Sopenharmony_ci VkImageUsageFlags uncompressedImageUsage; 118e5c31af7Sopenharmony_ci bool useMipmaps; 119e5c31af7Sopenharmony_ci VkFormat formatForVerify; 120e5c31af7Sopenharmony_ci bool formatIsASTC; 121e5c31af7Sopenharmony_ci}; 122e5c31af7Sopenharmony_ci 123e5c31af7Sopenharmony_citemplate<typename T> 124e5c31af7Sopenharmony_ciinline SharedPtr<Move<T> > makeVkSharedPtr (Move<T> move) 125e5c31af7Sopenharmony_ci{ 126e5c31af7Sopenharmony_ci return SharedPtr<Move<T> >(new Move<T>(move)); 127e5c31af7Sopenharmony_ci} 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_citemplate<typename T> 130e5c31af7Sopenharmony_ciinline SharedPtr<MovePtr<T> > makeVkSharedPtr (MovePtr<T> movePtr) 131e5c31af7Sopenharmony_ci{ 132e5c31af7Sopenharmony_ci return SharedPtr<MovePtr<T> >(new MovePtr<T>(movePtr)); 133e5c31af7Sopenharmony_ci} 134e5c31af7Sopenharmony_ci 135e5c31af7Sopenharmony_ciconst deUint32 SINGLE_LEVEL = 1u; 136e5c31af7Sopenharmony_ciconst deUint32 SINGLE_LAYER = 1u; 137e5c31af7Sopenharmony_ci 138e5c31af7Sopenharmony_cienum BinaryCompareMode 139e5c31af7Sopenharmony_ci{ 140e5c31af7Sopenharmony_ci COMPARE_MODE_NORMAL, 141e5c31af7Sopenharmony_ci COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING, 142e5c31af7Sopenharmony_ci}; 143e5c31af7Sopenharmony_ci 144e5c31af7Sopenharmony_cienum BinaryCompareResult 145e5c31af7Sopenharmony_ci{ 146e5c31af7Sopenharmony_ci COMPARE_RESULT_OK, 147e5c31af7Sopenharmony_ci COMPARE_RESULT_ASTC_QUALITY_WARNING, 148e5c31af7Sopenharmony_ci COMPARE_RESULT_FAILED, 149e5c31af7Sopenharmony_ci}; 150e5c31af7Sopenharmony_ci 151e5c31af7Sopenharmony_ciconst deUint32 ASTC_LDR_ERROR_COLOUR = 0xFFFF00FF; 152e5c31af7Sopenharmony_ciconst deUint32 ASTC_HDR_ERROR_COLOUR = 0x00000000; 153e5c31af7Sopenharmony_ci 154e5c31af7Sopenharmony_cistatic BinaryCompareResult BinaryCompare(const void *reference, 155e5c31af7Sopenharmony_ci const void *result, 156e5c31af7Sopenharmony_ci VkDeviceSize sizeInBytes, 157e5c31af7Sopenharmony_ci VkFormat formatForVerify, 158e5c31af7Sopenharmony_ci BinaryCompareMode mode) 159e5c31af7Sopenharmony_ci{ 160e5c31af7Sopenharmony_ci DE_UNREF(formatForVerify); 161e5c31af7Sopenharmony_ci 162e5c31af7Sopenharmony_ci // Compare quickly using deMemCmp 163e5c31af7Sopenharmony_ci if (deMemCmp(reference, result, (size_t)sizeInBytes) == 0) 164e5c31af7Sopenharmony_ci { 165e5c31af7Sopenharmony_ci return COMPARE_RESULT_OK; 166e5c31af7Sopenharmony_ci } 167e5c31af7Sopenharmony_ci // If deMemCmp indicated a mismatch, we can re-check with a manual comparison of 168e5c31af7Sopenharmony_ci // the ref and res images that allows for ASTC error colour mismatches if the ASTC 169e5c31af7Sopenharmony_ci // comparison mode was selected. This slows down the affected ASTC tests if you 170e5c31af7Sopenharmony_ci // didn't pass in the first comparison, but means in the general case the 171e5c31af7Sopenharmony_ci // comparion is still fast. 172e5c31af7Sopenharmony_ci else if (mode == COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING) 173e5c31af7Sopenharmony_ci { 174e5c31af7Sopenharmony_ci bool bWarn = false; 175e5c31af7Sopenharmony_ci bool bFail = false; 176e5c31af7Sopenharmony_ci const deUint32 *pui32RefVal = (deUint32*)reference; 177e5c31af7Sopenharmony_ci const deUint32 *pui32ResVal = (deUint32*)result; 178e5c31af7Sopenharmony_ci 179e5c31af7Sopenharmony_ci DE_ASSERT(formatForVerify == VK_FORMAT_R8G8B8A8_UNORM); 180e5c31af7Sopenharmony_ci size_t numPixels = (size_t)(sizeInBytes / 4) /* bytes */; 181e5c31af7Sopenharmony_ci for (size_t i = 0; i < numPixels; i++) 182e5c31af7Sopenharmony_ci { 183e5c31af7Sopenharmony_ci const deUint32 ref = *pui32RefVal++; 184e5c31af7Sopenharmony_ci const deUint32 res = *pui32ResVal++; 185e5c31af7Sopenharmony_ci 186e5c31af7Sopenharmony_ci if (ref != res) 187e5c31af7Sopenharmony_ci { 188e5c31af7Sopenharmony_ci // QualityWarning !1231: If the astc pixel was the ASTC LDR error colour 189e5c31af7Sopenharmony_ci // and the result image has the HDR error colour (or vice versa as the test 190e5c31af7Sopenharmony_ci // cases below sometimes reverse the operands) then issue a quality warning 191e5c31af7Sopenharmony_ci // instead of a failure. 192e5c31af7Sopenharmony_ci if ((ref == ASTC_LDR_ERROR_COLOUR && res == ASTC_HDR_ERROR_COLOUR) || 193e5c31af7Sopenharmony_ci (ref == ASTC_HDR_ERROR_COLOUR && res == ASTC_LDR_ERROR_COLOUR)) 194e5c31af7Sopenharmony_ci { 195e5c31af7Sopenharmony_ci bWarn = true; 196e5c31af7Sopenharmony_ci } 197e5c31af7Sopenharmony_ci else 198e5c31af7Sopenharmony_ci { 199e5c31af7Sopenharmony_ci bFail = true; 200e5c31af7Sopenharmony_ci } 201e5c31af7Sopenharmony_ci } 202e5c31af7Sopenharmony_ci } 203e5c31af7Sopenharmony_ci 204e5c31af7Sopenharmony_ci if (!bFail) 205e5c31af7Sopenharmony_ci { 206e5c31af7Sopenharmony_ci return (bWarn) 207e5c31af7Sopenharmony_ci ? (COMPARE_RESULT_ASTC_QUALITY_WARNING) 208e5c31af7Sopenharmony_ci : (COMPARE_RESULT_OK); 209e5c31af7Sopenharmony_ci } 210e5c31af7Sopenharmony_ci } 211e5c31af7Sopenharmony_ci 212e5c31af7Sopenharmony_ci return COMPARE_RESULT_FAILED; 213e5c31af7Sopenharmony_ci} 214e5c31af7Sopenharmony_ci 215e5c31af7Sopenharmony_cistatic bool FormatIsASTC(VkFormat format) 216e5c31af7Sopenharmony_ci{ 217e5c31af7Sopenharmony_ci return deInRange32(format, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK); 218e5c31af7Sopenharmony_ci} 219e5c31af7Sopenharmony_ci 220e5c31af7Sopenharmony_cistatic TestStatus TestStatusASTCQualityWarning() 221e5c31af7Sopenharmony_ci{ 222e5c31af7Sopenharmony_ci return TestStatus(QP_TEST_RESULT_QUALITY_WARNING, "ASTC HDR error colour output instead of LDR error colour"); 223e5c31af7Sopenharmony_ci} 224e5c31af7Sopenharmony_ci 225e5c31af7Sopenharmony_ciclass BasicTranscodingTestInstance : public TestInstance 226e5c31af7Sopenharmony_ci{ 227e5c31af7Sopenharmony_cipublic: 228e5c31af7Sopenharmony_ci BasicTranscodingTestInstance (Context& context, 229e5c31af7Sopenharmony_ci const TestParameters& parameters); 230e5c31af7Sopenharmony_ci virtual TestStatus iterate (void) = 0; 231e5c31af7Sopenharmony_ciprotected: 232e5c31af7Sopenharmony_ci void generateData (deUint8* toFill, 233e5c31af7Sopenharmony_ci const size_t size, 234e5c31af7Sopenharmony_ci const VkFormat format, 235e5c31af7Sopenharmony_ci const deUint32 layer = 0u, 236e5c31af7Sopenharmony_ci const deUint32 level = 0u); 237e5c31af7Sopenharmony_ci deUint32 getLevelCount (); 238e5c31af7Sopenharmony_ci deUint32 getLayerCount (); 239e5c31af7Sopenharmony_ci UVec3 getLayerDims (); 240e5c31af7Sopenharmony_ci vector<UVec3> getMipLevelSizes (UVec3 baseSize); 241e5c31af7Sopenharmony_ci vector<UVec3> getCompressedMipLevelSizes (const VkFormat compressedFormat, 242e5c31af7Sopenharmony_ci const vector<UVec3>& uncompressedSizes); 243e5c31af7Sopenharmony_ci 244e5c31af7Sopenharmony_ci const TestParameters m_parameters; 245e5c31af7Sopenharmony_ci const deUint32 m_blockWidth; 246e5c31af7Sopenharmony_ci const deUint32 m_blockHeight; 247e5c31af7Sopenharmony_ci const deUint32 m_levelCount; 248e5c31af7Sopenharmony_ci const UVec3 m_layerSize; 249e5c31af7Sopenharmony_ci 250e5c31af7Sopenharmony_ci // Detected error colour mismatch while verifying image. Output 251e5c31af7Sopenharmony_ci // the ASTC quality warning instead of a pass 252e5c31af7Sopenharmony_ci bool m_bASTCErrorColourMismatch; 253e5c31af7Sopenharmony_ci 254e5c31af7Sopenharmony_ciprivate: 255e5c31af7Sopenharmony_ci deUint32 findMipMapLevelCount (); 256e5c31af7Sopenharmony_ci}; 257e5c31af7Sopenharmony_ci 258e5c31af7Sopenharmony_cideUint32 BasicTranscodingTestInstance::findMipMapLevelCount () 259e5c31af7Sopenharmony_ci{ 260e5c31af7Sopenharmony_ci deUint32 levelCount = 1; 261e5c31af7Sopenharmony_ci 262e5c31af7Sopenharmony_ci // We cannot use mipmap levels which have resolution below block size. 263e5c31af7Sopenharmony_ci // Reduce number of mipmap levels 264e5c31af7Sopenharmony_ci if (m_parameters.useMipmaps) 265e5c31af7Sopenharmony_ci { 266e5c31af7Sopenharmony_ci deUint32 w = m_parameters.size.x(); 267e5c31af7Sopenharmony_ci deUint32 h = m_parameters.size.y(); 268e5c31af7Sopenharmony_ci 269e5c31af7Sopenharmony_ci DE_ASSERT(m_blockWidth > 0u && m_blockHeight > 0u); 270e5c31af7Sopenharmony_ci 271e5c31af7Sopenharmony_ci while (w > m_blockWidth && h > m_blockHeight) 272e5c31af7Sopenharmony_ci { 273e5c31af7Sopenharmony_ci w >>= 1; 274e5c31af7Sopenharmony_ci h >>= 1; 275e5c31af7Sopenharmony_ci 276e5c31af7Sopenharmony_ci if (w > m_blockWidth && h > m_blockHeight) 277e5c31af7Sopenharmony_ci levelCount++; 278e5c31af7Sopenharmony_ci } 279e5c31af7Sopenharmony_ci 280e5c31af7Sopenharmony_ci DE_ASSERT((m_parameters.size.x() >> (levelCount - 1u)) >= m_blockWidth); 281e5c31af7Sopenharmony_ci DE_ASSERT((m_parameters.size.y() >> (levelCount - 1u)) >= m_blockHeight); 282e5c31af7Sopenharmony_ci } 283e5c31af7Sopenharmony_ci 284e5c31af7Sopenharmony_ci return levelCount; 285e5c31af7Sopenharmony_ci} 286e5c31af7Sopenharmony_ci 287e5c31af7Sopenharmony_ciBasicTranscodingTestInstance::BasicTranscodingTestInstance (Context& context, const TestParameters& parameters) 288e5c31af7Sopenharmony_ci : TestInstance (context) 289e5c31af7Sopenharmony_ci , m_parameters (parameters) 290e5c31af7Sopenharmony_ci , m_blockWidth (getBlockWidth(m_parameters.formatCompressed)) 291e5c31af7Sopenharmony_ci , m_blockHeight (getBlockHeight(m_parameters.formatCompressed)) 292e5c31af7Sopenharmony_ci , m_levelCount (findMipMapLevelCount()) 293e5c31af7Sopenharmony_ci , m_layerSize (getLayerSize(m_parameters.imageType, m_parameters.size)) 294e5c31af7Sopenharmony_ci , m_bASTCErrorColourMismatch(false) 295e5c31af7Sopenharmony_ci{ 296e5c31af7Sopenharmony_ci DE_ASSERT(deLog2Floor32(m_parameters.size.x()) == deLog2Floor32(m_parameters.size.y())); 297e5c31af7Sopenharmony_ci} 298e5c31af7Sopenharmony_ci 299e5c31af7Sopenharmony_cideUint32 BasicTranscodingTestInstance::getLevelCount() 300e5c31af7Sopenharmony_ci{ 301e5c31af7Sopenharmony_ci return m_levelCount; 302e5c31af7Sopenharmony_ci} 303e5c31af7Sopenharmony_ci 304e5c31af7Sopenharmony_cideUint32 BasicTranscodingTestInstance::getLayerCount() 305e5c31af7Sopenharmony_ci{ 306e5c31af7Sopenharmony_ci return m_parameters.layers; 307e5c31af7Sopenharmony_ci} 308e5c31af7Sopenharmony_ci 309e5c31af7Sopenharmony_ciUVec3 BasicTranscodingTestInstance::getLayerDims() 310e5c31af7Sopenharmony_ci{ 311e5c31af7Sopenharmony_ci return m_layerSize; 312e5c31af7Sopenharmony_ci} 313e5c31af7Sopenharmony_ci 314e5c31af7Sopenharmony_civector<UVec3> BasicTranscodingTestInstance::getMipLevelSizes (UVec3 baseSize) 315e5c31af7Sopenharmony_ci{ 316e5c31af7Sopenharmony_ci vector<UVec3> levelSizes; 317e5c31af7Sopenharmony_ci const deUint32 levelCount = getLevelCount(); 318e5c31af7Sopenharmony_ci 319e5c31af7Sopenharmony_ci baseSize.z() = 1u; 320e5c31af7Sopenharmony_ci 321e5c31af7Sopenharmony_ci levelSizes.push_back(baseSize); 322e5c31af7Sopenharmony_ci 323e5c31af7Sopenharmony_ci if (m_parameters.imageType == IMAGE_TYPE_1D) 324e5c31af7Sopenharmony_ci { 325e5c31af7Sopenharmony_ci baseSize.y() = 1u; 326e5c31af7Sopenharmony_ci 327e5c31af7Sopenharmony_ci while (levelSizes.size() < levelCount && (baseSize.x() != 1)) 328e5c31af7Sopenharmony_ci { 329e5c31af7Sopenharmony_ci baseSize.x() = deMax32(baseSize.x() >> 1, 1); 330e5c31af7Sopenharmony_ci levelSizes.push_back(baseSize); 331e5c31af7Sopenharmony_ci } 332e5c31af7Sopenharmony_ci } 333e5c31af7Sopenharmony_ci else 334e5c31af7Sopenharmony_ci { 335e5c31af7Sopenharmony_ci while (levelSizes.size() < levelCount && (baseSize.x() != 1 || baseSize.y() != 1)) 336e5c31af7Sopenharmony_ci { 337e5c31af7Sopenharmony_ci baseSize.x() = deMax32(baseSize.x() >> 1, 1); 338e5c31af7Sopenharmony_ci baseSize.y() = deMax32(baseSize.y() >> 1, 1); 339e5c31af7Sopenharmony_ci levelSizes.push_back(baseSize); 340e5c31af7Sopenharmony_ci } 341e5c31af7Sopenharmony_ci } 342e5c31af7Sopenharmony_ci 343e5c31af7Sopenharmony_ci DE_ASSERT(levelSizes.size() == getLevelCount()); 344e5c31af7Sopenharmony_ci 345e5c31af7Sopenharmony_ci return levelSizes; 346e5c31af7Sopenharmony_ci} 347e5c31af7Sopenharmony_ci 348e5c31af7Sopenharmony_civector<UVec3> BasicTranscodingTestInstance::getCompressedMipLevelSizes (const VkFormat compressedFormat, const vector<UVec3>& uncompressedSizes) 349e5c31af7Sopenharmony_ci{ 350e5c31af7Sopenharmony_ci vector<UVec3> levelSizes; 351e5c31af7Sopenharmony_ci vector<UVec3>::const_iterator it; 352e5c31af7Sopenharmony_ci 353e5c31af7Sopenharmony_ci for (it = uncompressedSizes.begin(); it != uncompressedSizes.end(); it++) 354e5c31af7Sopenharmony_ci levelSizes.push_back(getCompressedImageResolutionInBlocks(compressedFormat, *it)); 355e5c31af7Sopenharmony_ci 356e5c31af7Sopenharmony_ci return levelSizes; 357e5c31af7Sopenharmony_ci} 358e5c31af7Sopenharmony_ci 359e5c31af7Sopenharmony_civoid BasicTranscodingTestInstance::generateData (deUint8* toFill, 360e5c31af7Sopenharmony_ci const size_t size, 361e5c31af7Sopenharmony_ci const VkFormat format, 362e5c31af7Sopenharmony_ci const deUint32 layer, 363e5c31af7Sopenharmony_ci const deUint32 level) 364e5c31af7Sopenharmony_ci{ 365e5c31af7Sopenharmony_ci const deUint8 pattern[] = 366e5c31af7Sopenharmony_ci { 367e5c31af7Sopenharmony_ci // 64-bit values 368e5c31af7Sopenharmony_ci 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x22, 369e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 370e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 371e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 372e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 373e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 374e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 375e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 376e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 377e5c31af7Sopenharmony_ci 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 378e5c31af7Sopenharmony_ci 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Positive infinity 379e5c31af7Sopenharmony_ci 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Negative infinity 380e5c31af7Sopenharmony_ci 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // Start of a signalling NaN (NANS) 381e5c31af7Sopenharmony_ci 0x7F, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // End of a signalling NaN (NANS) 382e5c31af7Sopenharmony_ci 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // Start of a signalling NaN (NANS) 383e5c31af7Sopenharmony_ci 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // End of a signalling NaN (NANS) 384e5c31af7Sopenharmony_ci 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Start of a quiet NaN (NANQ) 385e5c31af7Sopenharmony_ci 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // End of of a quiet NaN (NANQ) 386e5c31af7Sopenharmony_ci 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Start of a quiet NaN (NANQ) 387e5c31af7Sopenharmony_ci 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // End of a quiet NaN (NANQ) 388e5c31af7Sopenharmony_ci // 32-bit values 389e5c31af7Sopenharmony_ci 0x7F, 0x80, 0x00, 0x00, // Positive infinity 390e5c31af7Sopenharmony_ci 0xFF, 0x80, 0x00, 0x00, // Negative infinity 391e5c31af7Sopenharmony_ci 0x7F, 0x80, 0x00, 0x01, // Start of a signalling NaN (NANS) 392e5c31af7Sopenharmony_ci 0x7F, 0xBF, 0xFF, 0xFF, // End of a signalling NaN (NANS) 393e5c31af7Sopenharmony_ci 0xFF, 0x80, 0x00, 0x01, // Start of a signalling NaN (NANS) 394e5c31af7Sopenharmony_ci 0xFF, 0xBF, 0xFF, 0xFF, // End of a signalling NaN (NANS) 395e5c31af7Sopenharmony_ci 0x7F, 0xC0, 0x00, 0x00, // Start of a quiet NaN (NANQ) 396e5c31af7Sopenharmony_ci 0x7F, 0xFF, 0xFF, 0xFF, // End of of a quiet NaN (NANQ) 397e5c31af7Sopenharmony_ci 0xFF, 0xC0, 0x00, 0x00, // Start of a quiet NaN (NANQ) 398e5c31af7Sopenharmony_ci 0xFF, 0xFF, 0xFF, 0xFF, // End of a quiet NaN (NANQ) 399e5c31af7Sopenharmony_ci 0xAA, 0xAA, 0xAA, 0xAA, 400e5c31af7Sopenharmony_ci 0x55, 0x55, 0x55, 0x55, 401e5c31af7Sopenharmony_ci }; 402e5c31af7Sopenharmony_ci 403e5c31af7Sopenharmony_ci deUint8* start = toFill; 404e5c31af7Sopenharmony_ci size_t sizeToRnd = size; 405e5c31af7Sopenharmony_ci 406e5c31af7Sopenharmony_ci // Pattern part 407e5c31af7Sopenharmony_ci if (layer == 0 && level == 0 && size >= 2 * sizeof(pattern)) 408e5c31af7Sopenharmony_ci { 409e5c31af7Sopenharmony_ci // Rotated pattern 410e5c31af7Sopenharmony_ci for (size_t i = 0; i < sizeof(pattern); i++) 411e5c31af7Sopenharmony_ci start[sizeof(pattern) - i - 1] = pattern[i]; 412e5c31af7Sopenharmony_ci 413e5c31af7Sopenharmony_ci start += sizeof(pattern); 414e5c31af7Sopenharmony_ci sizeToRnd -= sizeof(pattern); 415e5c31af7Sopenharmony_ci 416e5c31af7Sopenharmony_ci // Direct pattern 417e5c31af7Sopenharmony_ci deMemcpy(start, pattern, sizeof(pattern)); 418e5c31af7Sopenharmony_ci 419e5c31af7Sopenharmony_ci start += sizeof(pattern); 420e5c31af7Sopenharmony_ci sizeToRnd -= sizeof(pattern); 421e5c31af7Sopenharmony_ci } 422e5c31af7Sopenharmony_ci 423e5c31af7Sopenharmony_ci // Random part 424e5c31af7Sopenharmony_ci { 425e5c31af7Sopenharmony_ci DE_ASSERT(sizeToRnd % sizeof(deUint32) == 0); 426e5c31af7Sopenharmony_ci 427e5c31af7Sopenharmony_ci deUint32* start32 = reinterpret_cast<deUint32*>(start); 428e5c31af7Sopenharmony_ci size_t sizeToRnd32 = sizeToRnd / sizeof(deUint32); 429e5c31af7Sopenharmony_ci deUint32 seed = (layer << 24) ^ (level << 16) ^ static_cast<deUint32>(format); 430e5c31af7Sopenharmony_ci Random rnd (seed); 431e5c31af7Sopenharmony_ci 432e5c31af7Sopenharmony_ci for (size_t i = 0; i < sizeToRnd32; i++) 433e5c31af7Sopenharmony_ci start32[i] = rnd.getUint32(); 434e5c31af7Sopenharmony_ci } 435e5c31af7Sopenharmony_ci 436e5c31af7Sopenharmony_ci { 437e5c31af7Sopenharmony_ci // Remove certain values that may not be preserved based on the uncompressed view format 438e5c31af7Sopenharmony_ci if (isSnormFormat(m_parameters.formatUncompressed)) 439e5c31af7Sopenharmony_ci { 440e5c31af7Sopenharmony_ci for (size_t i = 0; i < size; i += 2) 441e5c31af7Sopenharmony_ci { 442e5c31af7Sopenharmony_ci // SNORM fix: due to write operation in SNORM format 443e5c31af7Sopenharmony_ci // replaces 0x00 0x80 to 0x01 0x80 444e5c31af7Sopenharmony_ci if (toFill[i] == 0x00 && toFill[i+1] == 0x80) 445e5c31af7Sopenharmony_ci toFill[i+1] = 0x81; 446e5c31af7Sopenharmony_ci } 447e5c31af7Sopenharmony_ci } 448e5c31af7Sopenharmony_ci else if (isFloatFormat(m_parameters.formatUncompressed)) 449e5c31af7Sopenharmony_ci { 450e5c31af7Sopenharmony_ci tcu::TextureFormat textureFormat = mapVkFormat(m_parameters.formatUncompressed); 451e5c31af7Sopenharmony_ci 452e5c31af7Sopenharmony_ci if (textureFormat.type == tcu::TextureFormat::HALF_FLOAT) 453e5c31af7Sopenharmony_ci { 454e5c31af7Sopenharmony_ci for (size_t i = 0; i < size; i += 2) 455e5c31af7Sopenharmony_ci { 456e5c31af7Sopenharmony_ci // HALF_FLOAT fix: remove INF and NaN 457e5c31af7Sopenharmony_ci if ((toFill[i+1] & 0x7C) == 0x7C) 458e5c31af7Sopenharmony_ci toFill[i+1] = 0x00; 459e5c31af7Sopenharmony_ci } 460e5c31af7Sopenharmony_ci } 461e5c31af7Sopenharmony_ci else if (textureFormat.type == tcu::TextureFormat::FLOAT) 462e5c31af7Sopenharmony_ci { 463e5c31af7Sopenharmony_ci for (size_t i = 0; i < size; i += 4) 464e5c31af7Sopenharmony_ci { 465e5c31af7Sopenharmony_ci // HALF_FLOAT fix: remove INF and NaN 466e5c31af7Sopenharmony_ci if ((toFill[i+1] & 0x7C) == 0x7C) 467e5c31af7Sopenharmony_ci toFill[i+1] = 0x00; 468e5c31af7Sopenharmony_ci } 469e5c31af7Sopenharmony_ci 470e5c31af7Sopenharmony_ci for (size_t i = 0; i < size; i += 4) 471e5c31af7Sopenharmony_ci { 472e5c31af7Sopenharmony_ci // FLOAT fix: remove INF, NaN, and denorm 473e5c31af7Sopenharmony_ci // Little endian fix 474e5c31af7Sopenharmony_ci if (((toFill[i+3] & 0x7F) == 0x7F && (toFill[i+2] & 0x80) == 0x80) || ((toFill[i+3] & 0x7F) == 0x00 && (toFill[i+2] & 0x80) == 0x00)) 475e5c31af7Sopenharmony_ci toFill[i+3] = 0x01; 476e5c31af7Sopenharmony_ci // Big endian fix 477e5c31af7Sopenharmony_ci if (((toFill[i+0] & 0x7F) == 0x7F && (toFill[i+1] & 0x80) == 0x80) || ((toFill[i+0] & 0x7F) == 0x00 && (toFill[i+1] & 0x80) == 0x00)) 478e5c31af7Sopenharmony_ci toFill[i+0] = 0x01; 479e5c31af7Sopenharmony_ci } 480e5c31af7Sopenharmony_ci } 481e5c31af7Sopenharmony_ci } 482e5c31af7Sopenharmony_ci } 483e5c31af7Sopenharmony_ci} 484e5c31af7Sopenharmony_ci 485e5c31af7Sopenharmony_ciclass BasicComputeTestInstance : public BasicTranscodingTestInstance 486e5c31af7Sopenharmony_ci{ 487e5c31af7Sopenharmony_cipublic: 488e5c31af7Sopenharmony_ci BasicComputeTestInstance (Context& context, 489e5c31af7Sopenharmony_ci const TestParameters& parameters); 490e5c31af7Sopenharmony_ci TestStatus iterate (void); 491e5c31af7Sopenharmony_ciprotected: 492e5c31af7Sopenharmony_ci struct ImageData 493e5c31af7Sopenharmony_ci { 494e5c31af7Sopenharmony_ci deUint32 getImagesCount (void) { return static_cast<deUint32>(images.size()); } 495e5c31af7Sopenharmony_ci deUint32 getImageViewCount (void) { return static_cast<deUint32>(imagesViews.size()); } 496e5c31af7Sopenharmony_ci deUint32 getImageInfoCount (void) { return static_cast<deUint32>(imagesInfos.size()); } 497e5c31af7Sopenharmony_ci VkImage getImage (const deUint32 ndx) { return **images[ndx]->get(); } 498e5c31af7Sopenharmony_ci VkImageView getImageView (const deUint32 ndx) { return **imagesViews[ndx]; } 499e5c31af7Sopenharmony_ci VkImageCreateInfo getImageInfo (const deUint32 ndx) { return imagesInfos[ndx]; } 500e5c31af7Sopenharmony_ci void addImage (MovePtr<Image> image) { images.push_back(makeVkSharedPtr(image)); } 501e5c31af7Sopenharmony_ci void addImageView (Move<VkImageView> imageView) { imagesViews.push_back(makeVkSharedPtr(imageView));} 502e5c31af7Sopenharmony_ci void addImageInfo (const VkImageCreateInfo imageInfo) { imagesInfos.push_back(imageInfo); } 503e5c31af7Sopenharmony_ci void resetViews () { imagesViews.clear(); } 504e5c31af7Sopenharmony_ci private: 505e5c31af7Sopenharmony_ci vector<ImageSp> images; 506e5c31af7Sopenharmony_ci vector<ImageViewSp> imagesViews; 507e5c31af7Sopenharmony_ci vector<VkImageCreateInfo> imagesInfos; 508e5c31af7Sopenharmony_ci }; 509e5c31af7Sopenharmony_ci void copyDataToImage (const VkCommandPool& cmdPool, 510e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 511e5c31af7Sopenharmony_ci ImageData& imageData, 512e5c31af7Sopenharmony_ci const vector<UVec3>& mipMapSizes, 513e5c31af7Sopenharmony_ci const bool isCompressed); 514e5c31af7Sopenharmony_ci virtual void executeShader (const VkCommandPool& cmdPool, 515e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 516e5c31af7Sopenharmony_ci const VkDescriptorSetLayout& descriptorSetLayout, 517e5c31af7Sopenharmony_ci const VkDescriptorPool& descriptorPool, 518e5c31af7Sopenharmony_ci vector<ImageData>& imageData); 519e5c31af7Sopenharmony_ci bool copyResultAndCompare (const VkCommandPool& cmdPool, 520e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 521e5c31af7Sopenharmony_ci const VkImage& uncompressed, 522e5c31af7Sopenharmony_ci const VkDeviceSize offset, 523e5c31af7Sopenharmony_ci const UVec3& size); 524e5c31af7Sopenharmony_ci void descriptorSetUpdate (VkDescriptorSet descriptorSet, 525e5c31af7Sopenharmony_ci const VkDescriptorImageInfo* descriptorImageInfos); 526e5c31af7Sopenharmony_ci void createImageInfos (ImageData& imageData, 527e5c31af7Sopenharmony_ci const vector<UVec3>& mipMapSizes, 528e5c31af7Sopenharmony_ci const bool isCompressed); 529e5c31af7Sopenharmony_ci bool decompressImage (const VkCommandPool& cmdPool, 530e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 531e5c31af7Sopenharmony_ci vector<ImageData>& imageData, 532e5c31af7Sopenharmony_ci const vector<UVec3>& mipMapSizes); 533e5c31af7Sopenharmony_ci vector<deUint8> m_data; 534e5c31af7Sopenharmony_ci}; 535e5c31af7Sopenharmony_ci 536e5c31af7Sopenharmony_ci 537e5c31af7Sopenharmony_ciBasicComputeTestInstance::BasicComputeTestInstance (Context& context, const TestParameters& parameters) 538e5c31af7Sopenharmony_ci :BasicTranscodingTestInstance (context, parameters) 539e5c31af7Sopenharmony_ci{ 540e5c31af7Sopenharmony_ci} 541e5c31af7Sopenharmony_ci 542e5c31af7Sopenharmony_ciTestStatus BasicComputeTestInstance::iterate (void) 543e5c31af7Sopenharmony_ci{ 544e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 545e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 546e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex(); 547e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 548e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex)); 549e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 550e5c31af7Sopenharmony_ci const UVec3 fullSize (m_parameters.size.x(), m_parameters.imageType == IMAGE_TYPE_1D ? 1 : m_parameters.size.y(), 1); 551e5c31af7Sopenharmony_ci const vector<UVec3> mipMapSizes = m_parameters.useMipmaps ? getMipLevelSizes (getLayerDims()) : vector<UVec3>(1, fullSize); 552e5c31af7Sopenharmony_ci vector<ImageData> imageData (m_parameters.imagesCount); 553e5c31af7Sopenharmony_ci const deUint32 compressedNdx = 0u; 554e5c31af7Sopenharmony_ci const deUint32 resultImageNdx = m_parameters.imagesCount -1u; 555e5c31af7Sopenharmony_ci 556e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < m_parameters.imagesCount; ++imageNdx) 557e5c31af7Sopenharmony_ci { 558e5c31af7Sopenharmony_ci const bool isCompressed = compressedNdx == imageNdx ? true : false; 559e5c31af7Sopenharmony_ci createImageInfos(imageData[imageNdx], mipMapSizes, isCompressed); 560e5c31af7Sopenharmony_ci for (deUint32 infoNdx = 0u; infoNdx < imageData[imageNdx].getImageInfoCount(); ++infoNdx) 561e5c31af7Sopenharmony_ci { 562e5c31af7Sopenharmony_ci imageData[imageNdx].addImage(MovePtr<Image>(new Image(vk, device, allocator, imageData[imageNdx].getImageInfo(infoNdx), MemoryRequirement::Any))); 563e5c31af7Sopenharmony_ci if (isCompressed) 564e5c31af7Sopenharmony_ci { 565e5c31af7Sopenharmony_ci const VkImageViewUsageCreateInfo imageViewUsageKHR = 566e5c31af7Sopenharmony_ci { 567e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO, //VkStructureType sType; 568e5c31af7Sopenharmony_ci DE_NULL, //const void* pNext; 569e5c31af7Sopenharmony_ci m_parameters.compressedImageUsage, //VkImageUsageFlags usage; 570e5c31af7Sopenharmony_ci }; 571e5c31af7Sopenharmony_ci for (deUint32 mipNdx = 0u; mipNdx < mipMapSizes.size(); ++mipNdx) 572e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0u; layerNdx < getLayerCount(); ++layerNdx) 573e5c31af7Sopenharmony_ci { 574e5c31af7Sopenharmony_ci imageData[imageNdx].addImageView(makeImageView(vk, device, imageData[imageNdx].getImage(infoNdx), 575e5c31af7Sopenharmony_ci mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, 576e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, mipNdx, 1u, layerNdx, 1u), 577e5c31af7Sopenharmony_ci &imageViewUsageKHR)); 578e5c31af7Sopenharmony_ci } 579e5c31af7Sopenharmony_ci } 580e5c31af7Sopenharmony_ci else 581e5c31af7Sopenharmony_ci { 582e5c31af7Sopenharmony_ci imageData[imageNdx].addImageView(makeImageView(vk, device, imageData[imageNdx].getImage(infoNdx), 583e5c31af7Sopenharmony_ci mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, 584e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u))); 585e5c31af7Sopenharmony_ci } 586e5c31af7Sopenharmony_ci } 587e5c31af7Sopenharmony_ci } 588e5c31af7Sopenharmony_ci 589e5c31af7Sopenharmony_ci { 590e5c31af7Sopenharmony_ci size_t size = 0ull; 591e5c31af7Sopenharmony_ci for(deUint32 mipNdx = 0u; mipNdx < mipMapSizes.size(); ++mipNdx) 592e5c31af7Sopenharmony_ci { 593e5c31af7Sopenharmony_ci size += static_cast<size_t>(getCompressedImageSizeInBytes(m_parameters.formatCompressed, mipMapSizes[mipNdx]) * getLayerCount()); 594e5c31af7Sopenharmony_ci } 595e5c31af7Sopenharmony_ci m_data.resize(size); 596e5c31af7Sopenharmony_ci generateData (&m_data[0], m_data.size(), m_parameters.formatCompressed); 597e5c31af7Sopenharmony_ci } 598e5c31af7Sopenharmony_ci 599e5c31af7Sopenharmony_ci switch(m_parameters.operation) 600e5c31af7Sopenharmony_ci { 601e5c31af7Sopenharmony_ci case OPERATION_IMAGE_LOAD: 602e5c31af7Sopenharmony_ci case OPERATION_TEXEL_FETCH: 603e5c31af7Sopenharmony_ci case OPERATION_TEXTURE: 604e5c31af7Sopenharmony_ci copyDataToImage(*cmdPool, *cmdBuffer, imageData[compressedNdx], mipMapSizes, true); 605e5c31af7Sopenharmony_ci break; 606e5c31af7Sopenharmony_ci case OPERATION_IMAGE_STORE: 607e5c31af7Sopenharmony_ci copyDataToImage(*cmdPool, *cmdBuffer, imageData[1], mipMapSizes, false); 608e5c31af7Sopenharmony_ci break; 609e5c31af7Sopenharmony_ci default: 610e5c31af7Sopenharmony_ci DE_ASSERT(false); 611e5c31af7Sopenharmony_ci break; 612e5c31af7Sopenharmony_ci } 613e5c31af7Sopenharmony_ci 614e5c31af7Sopenharmony_ci bool pass = true; 615e5c31af7Sopenharmony_ci std::string failString; 616e5c31af7Sopenharmony_ci { 617e5c31af7Sopenharmony_ci Move<VkDescriptorSetLayout> descriptorSetLayout; 618e5c31af7Sopenharmony_ci Move<VkDescriptorPool> descriptorPool; 619e5c31af7Sopenharmony_ci 620e5c31af7Sopenharmony_ci DescriptorSetLayoutBuilder descriptorSetLayoutBuilder; 621e5c31af7Sopenharmony_ci DescriptorPoolBuilder descriptorPoolBuilder; 622e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < m_parameters.imagesCount; ++imageNdx) 623e5c31af7Sopenharmony_ci { 624e5c31af7Sopenharmony_ci switch(m_parameters.operation) 625e5c31af7Sopenharmony_ci { 626e5c31af7Sopenharmony_ci case OPERATION_IMAGE_LOAD: 627e5c31af7Sopenharmony_ci case OPERATION_IMAGE_STORE: 628e5c31af7Sopenharmony_ci descriptorSetLayoutBuilder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT); 629e5c31af7Sopenharmony_ci descriptorPoolBuilder.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, imageData[0].getImageViewCount()); 630e5c31af7Sopenharmony_ci break; 631e5c31af7Sopenharmony_ci case OPERATION_TEXEL_FETCH: 632e5c31af7Sopenharmony_ci case OPERATION_TEXTURE: 633e5c31af7Sopenharmony_ci descriptorSetLayoutBuilder.addSingleBinding((compressedNdx == imageNdx) ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT); 634e5c31af7Sopenharmony_ci descriptorPoolBuilder.addType((compressedNdx == imageNdx) ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, imageData[0].getImageViewCount()); 635e5c31af7Sopenharmony_ci break; 636e5c31af7Sopenharmony_ci default: 637e5c31af7Sopenharmony_ci DE_ASSERT(false); 638e5c31af7Sopenharmony_ci break; 639e5c31af7Sopenharmony_ci } 640e5c31af7Sopenharmony_ci } 641e5c31af7Sopenharmony_ci descriptorSetLayout = descriptorSetLayoutBuilder.build(vk, device); 642e5c31af7Sopenharmony_ci descriptorPool = descriptorPoolBuilder.build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, imageData[0].getImageViewCount()); 643e5c31af7Sopenharmony_ci executeShader(*cmdPool, *cmdBuffer, *descriptorSetLayout, *descriptorPool, imageData); 644e5c31af7Sopenharmony_ci 645e5c31af7Sopenharmony_ci { 646e5c31af7Sopenharmony_ci VkDeviceSize offset = 0ull; 647e5c31af7Sopenharmony_ci for (deUint32 mipNdx = 0u; mipNdx < mipMapSizes.size(); ++mipNdx) 648e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0u; layerNdx < getLayerCount(); ++layerNdx) 649e5c31af7Sopenharmony_ci { 650e5c31af7Sopenharmony_ci const deUint32 imageNdx = layerNdx + mipNdx * getLayerCount(); 651e5c31af7Sopenharmony_ci const UVec3 size = UVec3(imageData[resultImageNdx].getImageInfo(imageNdx).extent.width, 652e5c31af7Sopenharmony_ci imageData[resultImageNdx].getImageInfo(imageNdx).extent.height, 653e5c31af7Sopenharmony_ci imageData[resultImageNdx].getImageInfo(imageNdx).extent.depth); 654e5c31af7Sopenharmony_ci if (!copyResultAndCompare(*cmdPool, *cmdBuffer, imageData[resultImageNdx].getImage(imageNdx), offset, size)) 655e5c31af7Sopenharmony_ci { 656e5c31af7Sopenharmony_ci pass = false; 657e5c31af7Sopenharmony_ci failString = std::string("Uncompressed output mismatch at offset ") + de::toString(offset) + " even before executing decompression"; 658e5c31af7Sopenharmony_ci } 659e5c31af7Sopenharmony_ci offset += getCompressedImageSizeInBytes(m_parameters.formatCompressed, mipMapSizes[mipNdx]); 660e5c31af7Sopenharmony_ci } 661e5c31af7Sopenharmony_ci } 662e5c31af7Sopenharmony_ci } 663e5c31af7Sopenharmony_ci if (!decompressImage(*cmdPool, *cmdBuffer, imageData, mipMapSizes)) 664e5c31af7Sopenharmony_ci { 665e5c31af7Sopenharmony_ci pass = false; 666e5c31af7Sopenharmony_ci failString = "Decompression failed"; 667e5c31af7Sopenharmony_ci } 668e5c31af7Sopenharmony_ci 669e5c31af7Sopenharmony_ci if (!pass) 670e5c31af7Sopenharmony_ci return TestStatus::fail(failString); 671e5c31af7Sopenharmony_ci 672e5c31af7Sopenharmony_ci if (m_bASTCErrorColourMismatch) 673e5c31af7Sopenharmony_ci { 674e5c31af7Sopenharmony_ci DE_ASSERT(m_parameters.formatIsASTC); 675e5c31af7Sopenharmony_ci return TestStatusASTCQualityWarning(); 676e5c31af7Sopenharmony_ci } 677e5c31af7Sopenharmony_ci 678e5c31af7Sopenharmony_ci return TestStatus::pass("Pass"); 679e5c31af7Sopenharmony_ci} 680e5c31af7Sopenharmony_ci 681e5c31af7Sopenharmony_civoid BasicComputeTestInstance::copyDataToImage (const VkCommandPool& cmdPool, 682e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 683e5c31af7Sopenharmony_ci ImageData& imageData, 684e5c31af7Sopenharmony_ci const vector<UVec3>& mipMapSizes, 685e5c31af7Sopenharmony_ci const bool isCompressed) 686e5c31af7Sopenharmony_ci{ 687e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 688e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 689e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 690e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 691e5c31af7Sopenharmony_ci 692e5c31af7Sopenharmony_ci BufferWithMemory imageBuffer (vk, device, allocator, 693e5c31af7Sopenharmony_ci makeBufferCreateInfo(m_data.size(), VK_BUFFER_USAGE_TRANSFER_SRC_BIT), 694e5c31af7Sopenharmony_ci MemoryRequirement::HostVisible); 695e5c31af7Sopenharmony_ci VkDeviceSize offset = 0ull; 696e5c31af7Sopenharmony_ci { 697e5c31af7Sopenharmony_ci const Allocation& alloc = imageBuffer.getAllocation(); 698e5c31af7Sopenharmony_ci deMemcpy(alloc.getHostPtr(), &m_data[0], m_data.size()); 699e5c31af7Sopenharmony_ci flushAlloc(vk, device, alloc); 700e5c31af7Sopenharmony_ci } 701e5c31af7Sopenharmony_ci 702e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer); 703e5c31af7Sopenharmony_ci const VkImageSubresourceRange subresourceRange = 704e5c31af7Sopenharmony_ci { 705e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 706e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 707e5c31af7Sopenharmony_ci imageData.getImageInfo(0u).mipLevels, //deUint32 levelCount 708e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 709e5c31af7Sopenharmony_ci imageData.getImageInfo(0u).arrayLayers //deUint32 layerCount 710e5c31af7Sopenharmony_ci }; 711e5c31af7Sopenharmony_ci 712e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < imageData.getImagesCount(); ++imageNdx) 713e5c31af7Sopenharmony_ci { 714e5c31af7Sopenharmony_ci const VkImageMemoryBarrier preCopyImageBarrier = makeImageMemoryBarrier( 715e5c31af7Sopenharmony_ci 0u, VK_ACCESS_TRANSFER_WRITE_BIT, 716e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 717e5c31af7Sopenharmony_ci imageData.getImage(imageNdx), subresourceRange); 718e5c31af7Sopenharmony_ci 719e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier FlushHostCopyBarrier = makeBufferMemoryBarrier( 720e5c31af7Sopenharmony_ci VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 721e5c31af7Sopenharmony_ci imageBuffer.get(), 0ull, m_data.size()); 722e5c31af7Sopenharmony_ci 723e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 724e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &FlushHostCopyBarrier, 1u, &preCopyImageBarrier); 725e5c31af7Sopenharmony_ci 726e5c31af7Sopenharmony_ci for (deUint32 mipNdx = 0u; mipNdx < imageData.getImageInfo(imageNdx).mipLevels; ++mipNdx) 727e5c31af7Sopenharmony_ci { 728e5c31af7Sopenharmony_ci const VkExtent3D imageExtent = isCompressed ? 729e5c31af7Sopenharmony_ci makeExtent3D(mipMapSizes[mipNdx]) : 730e5c31af7Sopenharmony_ci imageData.getImageInfo(imageNdx).extent; 731e5c31af7Sopenharmony_ci const VkBufferImageCopy copyRegion = 732e5c31af7Sopenharmony_ci { 733e5c31af7Sopenharmony_ci offset, //VkDeviceSize bufferOffset; 734e5c31af7Sopenharmony_ci 0u, //deUint32 bufferRowLength; 735e5c31af7Sopenharmony_ci 0u, //deUint32 bufferImageHeight; 736e5c31af7Sopenharmony_ci makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, mipNdx, 0u, imageData.getImageInfo(imageNdx).arrayLayers), //VkImageSubresourceLayers imageSubresource; 737e5c31af7Sopenharmony_ci makeOffset3D(0, 0, 0), //VkOffset3D imageOffset; 738e5c31af7Sopenharmony_ci imageExtent, //VkExtent3D imageExtent; 739e5c31af7Sopenharmony_ci }; 740e5c31af7Sopenharmony_ci 741e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(cmdBuffer, imageBuffer.get(), imageData.getImage(imageNdx), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region); 742e5c31af7Sopenharmony_ci offset += getCompressedImageSizeInBytes(m_parameters.formatCompressed, 743e5c31af7Sopenharmony_ci UVec3(isCompressed ? imageExtent.width : imageExtent.width * m_blockWidth, isCompressed? imageExtent.height :imageExtent.height * m_blockHeight,imageExtent.depth)) * 744e5c31af7Sopenharmony_ci imageData.getImageInfo(imageNdx).arrayLayers; 745e5c31af7Sopenharmony_ci } 746e5c31af7Sopenharmony_ci } 747e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer); 748e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmdBuffer); 749e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 750e5c31af7Sopenharmony_ci} 751e5c31af7Sopenharmony_ci 752e5c31af7Sopenharmony_civoid BasicComputeTestInstance::executeShader (const VkCommandPool& cmdPool, 753e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 754e5c31af7Sopenharmony_ci const VkDescriptorSetLayout& descriptorSetLayout, 755e5c31af7Sopenharmony_ci const VkDescriptorPool& descriptorPool, 756e5c31af7Sopenharmony_ci vector<ImageData>& imageData) 757e5c31af7Sopenharmony_ci{ 758e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 759e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 760e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 761e5c31af7Sopenharmony_ci const Unique<VkShaderModule> shaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("comp"), 0)); 762e5c31af7Sopenharmony_ci vector<SharedVkDescriptorSet> descriptorSets (imageData[0].getImageViewCount()); 763e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, descriptorSetLayout)); 764e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeComputePipeline(vk, device, *pipelineLayout, *shaderModule)); 765e5c31af7Sopenharmony_ci Move<VkSampler> sampler; 766e5c31af7Sopenharmony_ci { 767e5c31af7Sopenharmony_ci const VkSamplerCreateInfo createInfo = 768e5c31af7Sopenharmony_ci { 769e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, //VkStructureType sType; 770e5c31af7Sopenharmony_ci DE_NULL, //const void* pNext; 771e5c31af7Sopenharmony_ci 0u, //VkSamplerCreateFlags flags; 772e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter magFilter; 773e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter minFilter; 774e5c31af7Sopenharmony_ci VK_SAMPLER_MIPMAP_MODE_NEAREST, //VkSamplerMipmapMode mipmapMode; 775e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeU; 776e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeV; 777e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeW; 778e5c31af7Sopenharmony_ci 0.0f, //float mipLodBias; 779e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 anisotropyEnable; 780e5c31af7Sopenharmony_ci 1.0f, //float maxAnisotropy; 781e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 compareEnable; 782e5c31af7Sopenharmony_ci VK_COMPARE_OP_EQUAL, //VkCompareOp compareOp; 783e5c31af7Sopenharmony_ci 0.0f, //float minLod; 784e5c31af7Sopenharmony_ci 0.0f, //float maxLod; 785e5c31af7Sopenharmony_ci VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, //VkBorderColor borderColor; 786e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 unnormalizedCoordinates; 787e5c31af7Sopenharmony_ci }; 788e5c31af7Sopenharmony_ci sampler = createSampler(vk, device, &createInfo); 789e5c31af7Sopenharmony_ci } 790e5c31af7Sopenharmony_ci 791e5c31af7Sopenharmony_ci vector<VkDescriptorImageInfo> descriptorImageInfos (descriptorSets.size() * m_parameters.imagesCount); 792e5c31af7Sopenharmony_ci for (deUint32 viewNdx = 0u; viewNdx < descriptorSets.size(); ++viewNdx) 793e5c31af7Sopenharmony_ci { 794e5c31af7Sopenharmony_ci const deUint32 descriptorNdx = viewNdx * m_parameters.imagesCount; 795e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0; imageNdx < m_parameters.imagesCount; ++imageNdx) 796e5c31af7Sopenharmony_ci { 797e5c31af7Sopenharmony_ci descriptorImageInfos[descriptorNdx+imageNdx] = makeDescriptorImageInfo(*sampler, 798e5c31af7Sopenharmony_ci imageData[imageNdx].getImageView(viewNdx), VK_IMAGE_LAYOUT_GENERAL); 799e5c31af7Sopenharmony_ci } 800e5c31af7Sopenharmony_ci } 801e5c31af7Sopenharmony_ci 802e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx < descriptorSets.size(); ++ndx) 803e5c31af7Sopenharmony_ci descriptorSets[ndx] = makeVkSharedPtr(makeDescriptorSet(vk, device, descriptorPool, descriptorSetLayout)); 804e5c31af7Sopenharmony_ci 805e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer); 806e5c31af7Sopenharmony_ci { 807e5c31af7Sopenharmony_ci const VkImageSubresourceRange compressedRange = 808e5c31af7Sopenharmony_ci { 809e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 810e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 811e5c31af7Sopenharmony_ci imageData[0].getImageInfo(0u).mipLevels, //deUint32 levelCount 812e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 813e5c31af7Sopenharmony_ci imageData[0].getImageInfo(0u).arrayLayers //deUint32 layerCount 814e5c31af7Sopenharmony_ci }; 815e5c31af7Sopenharmony_ci const VkImageSubresourceRange uncompressedRange = 816e5c31af7Sopenharmony_ci { 817e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 818e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 819e5c31af7Sopenharmony_ci 1u, //deUint32 levelCount 820e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 821e5c31af7Sopenharmony_ci 1u //deUint32 layerCount 822e5c31af7Sopenharmony_ci }; 823e5c31af7Sopenharmony_ci 824e5c31af7Sopenharmony_ci vk.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 825e5c31af7Sopenharmony_ci 826e5c31af7Sopenharmony_ci vector<VkImageMemoryBarrier> preShaderImageBarriers; 827e5c31af7Sopenharmony_ci preShaderImageBarriers.resize(descriptorSets.size() + 1u); 828e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < imageData[1].getImagesCount(); ++imageNdx) 829e5c31af7Sopenharmony_ci { 830e5c31af7Sopenharmony_ci preShaderImageBarriers[imageNdx]= makeImageMemoryBarrier( 831e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT, 832e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 833e5c31af7Sopenharmony_ci imageData[1].getImage(imageNdx), uncompressedRange); 834e5c31af7Sopenharmony_ci } 835e5c31af7Sopenharmony_ci 836e5c31af7Sopenharmony_ci preShaderImageBarriers[descriptorSets.size()] = makeImageMemoryBarrier( 837e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, 838e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 839e5c31af7Sopenharmony_ci imageData[0].getImage(0), compressedRange); 840e5c31af7Sopenharmony_ci 841e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 842e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 0u, (const VkBufferMemoryBarrier*)DE_NULL, 843e5c31af7Sopenharmony_ci static_cast<deUint32>(preShaderImageBarriers.size()), &preShaderImageBarriers[0]); 844e5c31af7Sopenharmony_ci 845e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx <descriptorSets.size(); ++ndx) 846e5c31af7Sopenharmony_ci { 847e5c31af7Sopenharmony_ci descriptorSetUpdate (**descriptorSets[ndx], &descriptorImageInfos[ndx* m_parameters.imagesCount]); 848e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0u, 1u, &(**descriptorSets[ndx]), 0u, DE_NULL); 849e5c31af7Sopenharmony_ci vk.cmdDispatch(cmdBuffer, imageData[1].getImageInfo(ndx).extent.width, 850e5c31af7Sopenharmony_ci imageData[1].getImageInfo(ndx).extent.height, 851e5c31af7Sopenharmony_ci imageData[1].getImageInfo(ndx).extent.depth); 852e5c31af7Sopenharmony_ci } 853e5c31af7Sopenharmony_ci } 854e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer); 855e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmdBuffer); 856e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 857e5c31af7Sopenharmony_ci} 858e5c31af7Sopenharmony_ci 859e5c31af7Sopenharmony_cibool BasicComputeTestInstance::copyResultAndCompare (const VkCommandPool& cmdPool, 860e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 861e5c31af7Sopenharmony_ci const VkImage& uncompressed, 862e5c31af7Sopenharmony_ci const VkDeviceSize offset, 863e5c31af7Sopenharmony_ci const UVec3& size) 864e5c31af7Sopenharmony_ci{ 865e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 866e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 867e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 868e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 869e5c31af7Sopenharmony_ci 870e5c31af7Sopenharmony_ci VkDeviceSize imageResultSize = getImageSizeBytes (tcu::IVec3(size.x(), size.y(), size.z()), m_parameters.formatUncompressed); 871e5c31af7Sopenharmony_ci BufferWithMemory imageBufferResult (vk, device, allocator, 872e5c31af7Sopenharmony_ci makeBufferCreateInfo(imageResultSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT), 873e5c31af7Sopenharmony_ci MemoryRequirement::HostVisible); 874e5c31af7Sopenharmony_ci 875e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer); 876e5c31af7Sopenharmony_ci { 877e5c31af7Sopenharmony_ci const VkImageSubresourceRange subresourceRange = 878e5c31af7Sopenharmony_ci { 879e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 880e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 881e5c31af7Sopenharmony_ci 1u, //deUint32 levelCount 882e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 883e5c31af7Sopenharmony_ci 1u //deUint32 layerCount 884e5c31af7Sopenharmony_ci }; 885e5c31af7Sopenharmony_ci 886e5c31af7Sopenharmony_ci const VkBufferImageCopy copyRegion = 887e5c31af7Sopenharmony_ci { 888e5c31af7Sopenharmony_ci 0ull, // VkDeviceSize bufferOffset; 889e5c31af7Sopenharmony_ci 0u, // deUint32 bufferRowLength; 890e5c31af7Sopenharmony_ci 0u, // deUint32 bufferImageHeight; 891e5c31af7Sopenharmony_ci makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u), // VkImageSubresourceLayers imageSubresource; 892e5c31af7Sopenharmony_ci makeOffset3D(0, 0, 0), // VkOffset3D imageOffset; 893e5c31af7Sopenharmony_ci makeExtent3D(size), // VkExtent3D imageExtent; 894e5c31af7Sopenharmony_ci }; 895e5c31af7Sopenharmony_ci 896e5c31af7Sopenharmony_ci const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier( 897e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 898e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 899e5c31af7Sopenharmony_ci uncompressed, subresourceRange); 900e5c31af7Sopenharmony_ci 901e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier( 902e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 903e5c31af7Sopenharmony_ci imageBufferResult.get(), 0ull, imageResultSize); 904e5c31af7Sopenharmony_ci 905e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1u, &prepareForTransferBarrier); 906e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(cmdBuffer, uncompressed, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, imageBufferResult.get(), 1u, ©Region); 907e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 1, ©Barrier, 0u, (const VkImageMemoryBarrier*)DE_NULL); 908e5c31af7Sopenharmony_ci } 909e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer); 910e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmdBuffer); 911e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 912e5c31af7Sopenharmony_ci 913e5c31af7Sopenharmony_ci const Allocation& allocResult = imageBufferResult.getAllocation(); 914e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, allocResult); 915e5c31af7Sopenharmony_ci if (deMemCmp((const void *)allocResult.getHostPtr(), (const void *)&m_data[static_cast<size_t>(offset)], static_cast<size_t>(imageResultSize)) == 0ull) 916e5c31af7Sopenharmony_ci return true; 917e5c31af7Sopenharmony_ci return false; 918e5c31af7Sopenharmony_ci} 919e5c31af7Sopenharmony_ci 920e5c31af7Sopenharmony_civoid BasicComputeTestInstance::descriptorSetUpdate (VkDescriptorSet descriptorSet, const VkDescriptorImageInfo* descriptorImageInfos) 921e5c31af7Sopenharmony_ci{ 922e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 923e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 924e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder descriptorSetUpdateBuilder; 925e5c31af7Sopenharmony_ci 926e5c31af7Sopenharmony_ci switch(m_parameters.operation) 927e5c31af7Sopenharmony_ci { 928e5c31af7Sopenharmony_ci case OPERATION_IMAGE_LOAD: 929e5c31af7Sopenharmony_ci case OPERATION_IMAGE_STORE: 930e5c31af7Sopenharmony_ci { 931e5c31af7Sopenharmony_ci for (deUint32 bindingNdx = 0u; bindingNdx < m_parameters.imagesCount; ++bindingNdx) 932e5c31af7Sopenharmony_ci descriptorSetUpdateBuilder.writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(bindingNdx), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfos[bindingNdx]); 933e5c31af7Sopenharmony_ci 934e5c31af7Sopenharmony_ci break; 935e5c31af7Sopenharmony_ci } 936e5c31af7Sopenharmony_ci 937e5c31af7Sopenharmony_ci case OPERATION_TEXEL_FETCH: 938e5c31af7Sopenharmony_ci case OPERATION_TEXTURE: 939e5c31af7Sopenharmony_ci { 940e5c31af7Sopenharmony_ci for (deUint32 bindingNdx = 0u; bindingNdx < m_parameters.imagesCount; ++bindingNdx) 941e5c31af7Sopenharmony_ci { 942e5c31af7Sopenharmony_ci descriptorSetUpdateBuilder.writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(bindingNdx), 943e5c31af7Sopenharmony_ci bindingNdx == 0u ? VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfos[bindingNdx]); 944e5c31af7Sopenharmony_ci } 945e5c31af7Sopenharmony_ci 946e5c31af7Sopenharmony_ci break; 947e5c31af7Sopenharmony_ci } 948e5c31af7Sopenharmony_ci 949e5c31af7Sopenharmony_ci default: 950e5c31af7Sopenharmony_ci DE_ASSERT(false); 951e5c31af7Sopenharmony_ci } 952e5c31af7Sopenharmony_ci descriptorSetUpdateBuilder.update(vk, device); 953e5c31af7Sopenharmony_ci} 954e5c31af7Sopenharmony_ci 955e5c31af7Sopenharmony_civoid BasicComputeTestInstance::createImageInfos (ImageData& imageData, const vector<UVec3>& mipMapSizes, const bool isCompressed) 956e5c31af7Sopenharmony_ci{ 957e5c31af7Sopenharmony_ci const VkImageType imageType = mapImageType(m_parameters.imageType); 958e5c31af7Sopenharmony_ci 959e5c31af7Sopenharmony_ci if (isCompressed) 960e5c31af7Sopenharmony_ci { 961e5c31af7Sopenharmony_ci const VkExtent3D extentCompressed = makeExtent3D(getLayerSize(m_parameters.imageType, m_parameters.size)); 962e5c31af7Sopenharmony_ci const VkImageCreateInfo compressedInfo = 963e5c31af7Sopenharmony_ci { 964e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 965e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 966e5c31af7Sopenharmony_ci VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | 967e5c31af7Sopenharmony_ci VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT | 968e5c31af7Sopenharmony_ci VK_IMAGE_CREATE_EXTENDED_USAGE_BIT, // VkImageCreateFlags flags; 969e5c31af7Sopenharmony_ci imageType, // VkImageType imageType; 970e5c31af7Sopenharmony_ci m_parameters.formatCompressed, // VkFormat format; 971e5c31af7Sopenharmony_ci extentCompressed, // VkExtent3D extent; 972e5c31af7Sopenharmony_ci static_cast<deUint32>(mipMapSizes.size()), // deUint32 mipLevels; 973e5c31af7Sopenharmony_ci getLayerCount(), // deUint32 arrayLayers; 974e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 975e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 976e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_SAMPLED_BIT | 977e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT | 978e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_SRC_BIT | 979e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage; 980e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 981e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 982e5c31af7Sopenharmony_ci DE_NULL, // const deUint32* pQueueFamilyIndices; 983e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 984e5c31af7Sopenharmony_ci }; 985e5c31af7Sopenharmony_ci 986e5c31af7Sopenharmony_ci VkImageFormatProperties imageFormatProperties; 987e5c31af7Sopenharmony_ci if (m_context.getInstanceInterface().getPhysicalDeviceImageFormatProperties(m_context.getPhysicalDevice(), compressedInfo.format, compressedInfo.imageType, compressedInfo.tiling, compressedInfo.usage, compressedInfo.flags, &imageFormatProperties) != VK_SUCCESS) 988e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Image parameters not supported"); 989e5c31af7Sopenharmony_ci 990e5c31af7Sopenharmony_ci imageData.addImageInfo(compressedInfo); 991e5c31af7Sopenharmony_ci } 992e5c31af7Sopenharmony_ci else 993e5c31af7Sopenharmony_ci { 994e5c31af7Sopenharmony_ci UVec3 size = m_parameters.size; 995e5c31af7Sopenharmony_ci if (m_parameters.imageType == IMAGE_TYPE_1D) { 996e5c31af7Sopenharmony_ci size.y() = 1; 997e5c31af7Sopenharmony_ci } 998e5c31af7Sopenharmony_ci size.z() = 1; 999e5c31af7Sopenharmony_ci const VkExtent3D originalResolutionInBlocks = makeExtent3D(getCompressedImageResolutionInBlocks(m_parameters.formatCompressed, size)); 1000e5c31af7Sopenharmony_ci 1001e5c31af7Sopenharmony_ci for (size_t mipNdx = 0ull; mipNdx < mipMapSizes.size(); ++mipNdx) 1002e5c31af7Sopenharmony_ci for (size_t layerNdx = 0ull; layerNdx < getLayerCount(); ++layerNdx) 1003e5c31af7Sopenharmony_ci { 1004e5c31af7Sopenharmony_ci const VkExtent3D extentUncompressed = m_parameters.useMipmaps ? 1005e5c31af7Sopenharmony_ci makeExtent3D(getCompressedImageResolutionInBlocks(m_parameters.formatCompressed, mipMapSizes[mipNdx])) : 1006e5c31af7Sopenharmony_ci originalResolutionInBlocks; 1007e5c31af7Sopenharmony_ci const VkImageCreateInfo uncompressedInfo = 1008e5c31af7Sopenharmony_ci { 1009e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 1010e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1011e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 1012e5c31af7Sopenharmony_ci imageType, // VkImageType imageType; 1013e5c31af7Sopenharmony_ci m_parameters.formatUncompressed, // VkFormat format; 1014e5c31af7Sopenharmony_ci extentUncompressed, // VkExtent3D extent; 1015e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 1016e5c31af7Sopenharmony_ci 1u, // deUint32 arrayLayers; 1017e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 1018e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 1019e5c31af7Sopenharmony_ci m_parameters.uncompressedImageUsage | 1020e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_SAMPLED_BIT, // VkImageUsageFlags usage; 1021e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 1022e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 1023e5c31af7Sopenharmony_ci DE_NULL, // const deUint32* pQueueFamilyIndices; 1024e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 1025e5c31af7Sopenharmony_ci }; 1026e5c31af7Sopenharmony_ci imageData.addImageInfo(uncompressedInfo); 1027e5c31af7Sopenharmony_ci } 1028e5c31af7Sopenharmony_ci } 1029e5c31af7Sopenharmony_ci} 1030e5c31af7Sopenharmony_ci 1031e5c31af7Sopenharmony_cibool BasicComputeTestInstance::decompressImage (const VkCommandPool& cmdPool, 1032e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 1033e5c31af7Sopenharmony_ci vector<ImageData>& imageData, 1034e5c31af7Sopenharmony_ci const vector<UVec3>& mipMapSizes) 1035e5c31af7Sopenharmony_ci{ 1036e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1037e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1038e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 1039e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 1040e5c31af7Sopenharmony_ci const Unique<VkShaderModule> shaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("decompress"), 0)); 1041e5c31af7Sopenharmony_ci const VkImage& compressed = imageData[0].getImage(0); 1042e5c31af7Sopenharmony_ci const VkImageType imageType = mapImageType(m_parameters.imageType); 1043e5c31af7Sopenharmony_ci 1044e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx < imageData.size(); ndx++) 1045e5c31af7Sopenharmony_ci imageData[ndx].resetViews(); 1046e5c31af7Sopenharmony_ci 1047e5c31af7Sopenharmony_ci for (deUint32 mipNdx = 0u; mipNdx < mipMapSizes.size(); ++mipNdx) 1048e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0u; layerNdx < getLayerCount(); ++layerNdx) 1049e5c31af7Sopenharmony_ci { 1050e5c31af7Sopenharmony_ci const bool layoutShaderReadOnly = (layerNdx % 2u) == 1; 1051e5c31af7Sopenharmony_ci const deUint32 imageNdx = layerNdx + mipNdx * getLayerCount(); 1052e5c31af7Sopenharmony_ci const VkExtent3D extentCompressed = makeExtent3D(mipMapSizes[mipNdx]); 1053e5c31af7Sopenharmony_ci const VkImage& uncompressed = imageData[m_parameters.imagesCount -1].getImage(imageNdx); 1054e5c31af7Sopenharmony_ci const VkExtent3D extentUncompressed = imageData[m_parameters.imagesCount -1].getImageInfo(imageNdx).extent; 1055e5c31af7Sopenharmony_ci const VkDeviceSize bufferSizeComp = getCompressedImageSizeInBytes(m_parameters.formatCompressed, mipMapSizes[mipNdx]); 1056e5c31af7Sopenharmony_ci 1057e5c31af7Sopenharmony_ci VkFormatProperties properties; 1058e5c31af7Sopenharmony_ci m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), m_parameters.formatForVerify, &properties); 1059e5c31af7Sopenharmony_ci if (!(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) 1060e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Format storage feature not supported"); 1061e5c31af7Sopenharmony_ci 1062e5c31af7Sopenharmony_ci const VkImageCreateInfo decompressedImageInfo = 1063e5c31af7Sopenharmony_ci { 1064e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 1065e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1066e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 1067e5c31af7Sopenharmony_ci imageType, // VkImageType imageType; 1068e5c31af7Sopenharmony_ci m_parameters.formatForVerify, // VkFormat format; 1069e5c31af7Sopenharmony_ci extentCompressed, // VkExtent3D extent; 1070e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 1071e5c31af7Sopenharmony_ci 1u, // deUint32 arrayLayers; 1072e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 1073e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 1074e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_SAMPLED_BIT | 1075e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_STORAGE_BIT | 1076e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_SRC_BIT | 1077e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage; 1078e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 1079e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 1080e5c31af7Sopenharmony_ci DE_NULL, // const deUint32* pQueueFamilyIndices; 1081e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 1082e5c31af7Sopenharmony_ci }; 1083e5c31af7Sopenharmony_ci 1084e5c31af7Sopenharmony_ci const VkImageCreateInfo compressedImageInfo = 1085e5c31af7Sopenharmony_ci { 1086e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 1087e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1088e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 1089e5c31af7Sopenharmony_ci imageType, // VkImageType imageType; 1090e5c31af7Sopenharmony_ci m_parameters.formatCompressed, // VkFormat format; 1091e5c31af7Sopenharmony_ci extentCompressed, // VkExtent3D extent; 1092e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 1093e5c31af7Sopenharmony_ci 1u, // deUint32 arrayLayers; 1094e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 1095e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 1096e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_SAMPLED_BIT | 1097e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage; 1098e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 1099e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 1100e5c31af7Sopenharmony_ci DE_NULL, // const deUint32* pQueueFamilyIndices; 1101e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 1102e5c31af7Sopenharmony_ci }; 1103e5c31af7Sopenharmony_ci const VkImageUsageFlags compressedViewUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; 1104e5c31af7Sopenharmony_ci const VkImageViewUsageCreateInfo compressedViewUsageCI = 1105e5c31af7Sopenharmony_ci { 1106e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO, //VkStructureType sType; 1107e5c31af7Sopenharmony_ci DE_NULL, //const void* pNext; 1108e5c31af7Sopenharmony_ci compressedViewUsageFlags, //VkImageUsageFlags usage; 1109e5c31af7Sopenharmony_ci }; 1110e5c31af7Sopenharmony_ci const VkImageViewType imageViewType (mapImageViewType(m_parameters.imageType)); 1111e5c31af7Sopenharmony_ci Image resultImage (vk, device, allocator, decompressedImageInfo, MemoryRequirement::Any); 1112e5c31af7Sopenharmony_ci Image referenceImage (vk, device, allocator, decompressedImageInfo, MemoryRequirement::Any); 1113e5c31af7Sopenharmony_ci Image uncompressedImage (vk, device, allocator, compressedImageInfo, MemoryRequirement::Any); 1114e5c31af7Sopenharmony_ci Move<VkImageView> resultView = makeImageView(vk, device, resultImage.get(), imageViewType, decompressedImageInfo.format, 1115e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, decompressedImageInfo.extent.depth, 0u, decompressedImageInfo.arrayLayers)); 1116e5c31af7Sopenharmony_ci Move<VkImageView> referenceView = makeImageView(vk, device, referenceImage.get(), imageViewType, decompressedImageInfo.format, 1117e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, decompressedImageInfo.extent.depth, 0u, decompressedImageInfo.arrayLayers)); 1118e5c31af7Sopenharmony_ci Move<VkImageView> uncompressedView = makeImageView(vk, device, uncompressedImage.get(), imageViewType, m_parameters.formatCompressed, 1119e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, compressedImageInfo.extent.depth, 0u, compressedImageInfo.arrayLayers)); 1120e5c31af7Sopenharmony_ci bool const useMultiLayer = m_parameters.imageType == IMAGE_TYPE_2D && m_parameters.layers > 1u; 1121e5c31af7Sopenharmony_ci Move<VkImageView> compressedView = (useMultiLayer) ? 1122e5c31af7Sopenharmony_ci makeImageView(vk, device, compressed, VK_IMAGE_VIEW_TYPE_2D_ARRAY, m_parameters.formatCompressed, 1123e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, static_cast<uint32_t>(mipMapSizes.size()), 0u, m_parameters.layers), &compressedViewUsageCI) : 1124e5c31af7Sopenharmony_ci makeImageView(vk, device, compressed, imageViewType, m_parameters.formatCompressed, 1125e5c31af7Sopenharmony_ci makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, mipNdx, 1u, layerNdx, 1u), &compressedViewUsageCI); 1126e5c31af7Sopenharmony_ci Move<VkDescriptorSetLayout> descriptorSetLayout = DescriptorSetLayoutBuilder() 1127e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_COMPUTE_BIT) 1128e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_COMPUTE_BIT) 1129e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT) 1130e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT) 1131e5c31af7Sopenharmony_ci .build(vk, device); 1132e5c31af7Sopenharmony_ci Move<VkDescriptorPool> descriptorPool = DescriptorPoolBuilder() 1133e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, decompressedImageInfo.arrayLayers) 1134e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, decompressedImageInfo.arrayLayers) 1135e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, decompressedImageInfo.arrayLayers) 1136e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, decompressedImageInfo.arrayLayers) 1137e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, decompressedImageInfo.arrayLayers); 1138e5c31af7Sopenharmony_ci 1139e5c31af7Sopenharmony_ci Move<VkDescriptorSet> descriptorSet = makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout); 1140e5c31af7Sopenharmony_ci const struct PushData { uint32_t layer; uint32_t level; } pushData 1141e5c31af7Sopenharmony_ci = { layerNdx, mipNdx }; 1142e5c31af7Sopenharmony_ci const VkPushConstantRange pushConstantRange = { VK_SHADER_STAGE_COMPUTE_BIT, 0u, static_cast<uint32_t>(sizeof pushData) }; 1143e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, 1u, &descriptorSetLayout.get(), 1u, &pushConstantRange)); 1144e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeComputePipeline(vk, device, *pipelineLayout, *shaderModule)); 1145e5c31af7Sopenharmony_ci const VkDeviceSize bufferSize = getImageSizeBytes(IVec3((int)extentCompressed.width, (int)extentCompressed.height, (int)extentCompressed.depth), m_parameters.formatForVerify); 1146e5c31af7Sopenharmony_ci BufferWithMemory resultBuffer (vk, device, allocator, 1147e5c31af7Sopenharmony_ci makeBufferCreateInfo(bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible); 1148e5c31af7Sopenharmony_ci BufferWithMemory referenceBuffer (vk, device, allocator, 1149e5c31af7Sopenharmony_ci makeBufferCreateInfo(bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible); 1150e5c31af7Sopenharmony_ci BufferWithMemory transferBuffer (vk, device, allocator, 1151e5c31af7Sopenharmony_ci makeBufferCreateInfo(bufferSizeComp, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible); 1152e5c31af7Sopenharmony_ci Move<VkSampler> sampler; 1153e5c31af7Sopenharmony_ci { 1154e5c31af7Sopenharmony_ci const VkSamplerCreateInfo createInfo = 1155e5c31af7Sopenharmony_ci { 1156e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, //VkStructureType sType; 1157e5c31af7Sopenharmony_ci DE_NULL, //const void* pNext; 1158e5c31af7Sopenharmony_ci 0u, //VkSamplerCreateFlags flags; 1159e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter magFilter; 1160e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter minFilter; 1161e5c31af7Sopenharmony_ci VK_SAMPLER_MIPMAP_MODE_NEAREST, //VkSamplerMipmapMode mipmapMode; 1162e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeU; 1163e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeV; 1164e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeW; 1165e5c31af7Sopenharmony_ci 0.0f, //float mipLodBias; 1166e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 anisotropyEnable; 1167e5c31af7Sopenharmony_ci 1.0f, //float maxAnisotropy; 1168e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 compareEnable; 1169e5c31af7Sopenharmony_ci VK_COMPARE_OP_EQUAL, //VkCompareOp compareOp; 1170e5c31af7Sopenharmony_ci 0.0f, //float minLod; 1171e5c31af7Sopenharmony_ci (float)mipMapSizes.size(), //float maxLod; 1172e5c31af7Sopenharmony_ci VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, //VkBorderColor borderColor; 1173e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 unnormalizedCoordinates; 1174e5c31af7Sopenharmony_ci }; 1175e5c31af7Sopenharmony_ci sampler = createSampler(vk, device, &createInfo); 1176e5c31af7Sopenharmony_ci } 1177e5c31af7Sopenharmony_ci 1178e5c31af7Sopenharmony_ci VkDescriptorImageInfo descriptorImageInfos[] = 1179e5c31af7Sopenharmony_ci { 1180e5c31af7Sopenharmony_ci makeDescriptorImageInfo(*sampler, *uncompressedView, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL), 1181e5c31af7Sopenharmony_ci makeDescriptorImageInfo(*sampler, *compressedView, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL), 1182e5c31af7Sopenharmony_ci makeDescriptorImageInfo(DE_NULL, *resultView, VK_IMAGE_LAYOUT_GENERAL), 1183e5c31af7Sopenharmony_ci makeDescriptorImageInfo(DE_NULL, *referenceView, VK_IMAGE_LAYOUT_GENERAL) 1184e5c31af7Sopenharmony_ci }; 1185e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 1186e5c31af7Sopenharmony_ci .writeSingle(descriptorSet.get(), DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorImageInfos[0]) 1187e5c31af7Sopenharmony_ci .writeSingle(descriptorSet.get(), DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorImageInfos[1]) 1188e5c31af7Sopenharmony_ci .writeSingle(descriptorSet.get(), DescriptorSetUpdateBuilder::Location::binding(2u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfos[2]) 1189e5c31af7Sopenharmony_ci .writeSingle(descriptorSet.get(), DescriptorSetUpdateBuilder::Location::binding(3u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfos[3]) 1190e5c31af7Sopenharmony_ci .update(vk, device); 1191e5c31af7Sopenharmony_ci 1192e5c31af7Sopenharmony_ci 1193e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer); 1194e5c31af7Sopenharmony_ci { 1195e5c31af7Sopenharmony_ci const VkImageSubresourceRange subresourceRange = 1196e5c31af7Sopenharmony_ci { 1197e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 1198e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 1199e5c31af7Sopenharmony_ci 1u, //deUint32 levelCount 1200e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 1201e5c31af7Sopenharmony_ci 1u //deUint32 layerCount 1202e5c31af7Sopenharmony_ci }; 1203e5c31af7Sopenharmony_ci 1204e5c31af7Sopenharmony_ci const VkImageSubresourceRange subresourceRangeComp = 1205e5c31af7Sopenharmony_ci { 1206e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 1207e5c31af7Sopenharmony_ci (useMultiLayer) ? 0u : mipNdx, //deUint32 baseMipLevel 1208e5c31af7Sopenharmony_ci (useMultiLayer) ? static_cast<uint32_t>(mipMapSizes.size()) : 1u, //deUint32 levelCount 1209e5c31af7Sopenharmony_ci (useMultiLayer) ? 0u : layerNdx, //deUint32 baseArrayLayer 1210e5c31af7Sopenharmony_ci (useMultiLayer) ? m_parameters.layers : 1u //deUint32 layerCount 1211e5c31af7Sopenharmony_ci }; 1212e5c31af7Sopenharmony_ci 1213e5c31af7Sopenharmony_ci const VkBufferImageCopy copyRegion = 1214e5c31af7Sopenharmony_ci { 1215e5c31af7Sopenharmony_ci 0ull, // VkDeviceSize bufferOffset; 1216e5c31af7Sopenharmony_ci 0u, // deUint32 bufferRowLength; 1217e5c31af7Sopenharmony_ci 0u, // deUint32 bufferImageHeight; 1218e5c31af7Sopenharmony_ci makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u), // VkImageSubresourceLayers imageSubresource; 1219e5c31af7Sopenharmony_ci makeOffset3D(0, 0, 0), // VkOffset3D imageOffset; 1220e5c31af7Sopenharmony_ci decompressedImageInfo.extent, // VkExtent3D imageExtent; 1221e5c31af7Sopenharmony_ci }; 1222e5c31af7Sopenharmony_ci 1223e5c31af7Sopenharmony_ci const VkBufferImageCopy compressedCopyRegion = 1224e5c31af7Sopenharmony_ci { 1225e5c31af7Sopenharmony_ci 0ull, // VkDeviceSize bufferOffset; 1226e5c31af7Sopenharmony_ci 0u, // deUint32 bufferRowLength; 1227e5c31af7Sopenharmony_ci 0u, // deUint32 bufferImageHeight; 1228e5c31af7Sopenharmony_ci makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u), // VkImageSubresourceLayers imageSubresource; 1229e5c31af7Sopenharmony_ci makeOffset3D(0, 0, 0), // VkOffset3D imageOffset; 1230e5c31af7Sopenharmony_ci extentUncompressed, // VkExtent3D imageExtent; 1231e5c31af7Sopenharmony_ci }; 1232e5c31af7Sopenharmony_ci 1233e5c31af7Sopenharmony_ci { 1234e5c31af7Sopenharmony_ci 1235e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier preCopyBufferBarriers = makeBufferMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, 1236e5c31af7Sopenharmony_ci transferBuffer.get(), 0ull, bufferSizeComp); 1237e5c31af7Sopenharmony_ci 1238e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 1239e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &preCopyBufferBarriers, 0u, (const VkImageMemoryBarrier*)DE_NULL); 1240e5c31af7Sopenharmony_ci } 1241e5c31af7Sopenharmony_ci 1242e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(cmdBuffer, uncompressed, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, transferBuffer.get(), 1u, &compressedCopyRegion); 1243e5c31af7Sopenharmony_ci 1244e5c31af7Sopenharmony_ci { 1245e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier postCopyBufferBarriers = makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 1246e5c31af7Sopenharmony_ci transferBuffer.get(), 0ull, bufferSizeComp); 1247e5c31af7Sopenharmony_ci 1248e5c31af7Sopenharmony_ci const VkImageMemoryBarrier preCopyImageBarriers = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, 1249e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, uncompressedImage.get(), subresourceRange); 1250e5c31af7Sopenharmony_ci 1251e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 1252e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 1u, &postCopyBufferBarriers, 1u, &preCopyImageBarriers); 1253e5c31af7Sopenharmony_ci } 1254e5c31af7Sopenharmony_ci 1255e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(cmdBuffer, transferBuffer.get(), uncompressedImage.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region); 1256e5c31af7Sopenharmony_ci 1257e5c31af7Sopenharmony_ci vk.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 1258e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 1259e5c31af7Sopenharmony_ci 1260e5c31af7Sopenharmony_ci { 1261e5c31af7Sopenharmony_ci const VkImageMemoryBarrier preShaderImageBarriers[] = 1262e5c31af7Sopenharmony_ci { 1263e5c31af7Sopenharmony_ci 1264e5c31af7Sopenharmony_ci makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, 1265e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, 1266e5c31af7Sopenharmony_ci uncompressedImage.get(), subresourceRange), 1267e5c31af7Sopenharmony_ci 1268e5c31af7Sopenharmony_ci makeImageMemoryBarrier(0, VK_ACCESS_SHADER_READ_BIT, 1269e5c31af7Sopenharmony_ci (useMultiLayer && !layoutShaderReadOnly && layerNdx) ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, 1270e5c31af7Sopenharmony_ci compressed, subresourceRangeComp), 1271e5c31af7Sopenharmony_ci 1272e5c31af7Sopenharmony_ci makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_WRITE_BIT, 1273e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 1274e5c31af7Sopenharmony_ci resultImage.get(), subresourceRange), 1275e5c31af7Sopenharmony_ci 1276e5c31af7Sopenharmony_ci makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_WRITE_BIT, 1277e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 1278e5c31af7Sopenharmony_ci referenceImage.get(), subresourceRange) 1279e5c31af7Sopenharmony_ci }; 1280e5c31af7Sopenharmony_ci 1281e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 1282e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, (const VkBufferMemoryBarrier*)DE_NULL, 1283e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(preShaderImageBarriers), preShaderImageBarriers); 1284e5c31af7Sopenharmony_ci } 1285e5c31af7Sopenharmony_ci 1286e5c31af7Sopenharmony_ci vk.cmdPushConstants(cmdBuffer, *pipelineLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0u, sizeof pushData, &pushData); 1287e5c31af7Sopenharmony_ci vk.cmdDispatch(cmdBuffer, extentCompressed.width, extentCompressed.height, extentCompressed.depth); 1288e5c31af7Sopenharmony_ci 1289e5c31af7Sopenharmony_ci { 1290e5c31af7Sopenharmony_ci const VkImageMemoryBarrier postShaderImageBarriers[] = 1291e5c31af7Sopenharmony_ci { 1292e5c31af7Sopenharmony_ci makeImageMemoryBarrier(VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 1293e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1294e5c31af7Sopenharmony_ci resultImage.get(), subresourceRange), 1295e5c31af7Sopenharmony_ci 1296e5c31af7Sopenharmony_ci makeImageMemoryBarrier(VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 1297e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1298e5c31af7Sopenharmony_ci referenceImage.get(), subresourceRange) 1299e5c31af7Sopenharmony_ci }; 1300e5c31af7Sopenharmony_ci 1301e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 1302e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 0u, (const VkBufferMemoryBarrier*)DE_NULL, 1303e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(postShaderImageBarriers), postShaderImageBarriers); 1304e5c31af7Sopenharmony_ci } 1305e5c31af7Sopenharmony_ci 1306e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(cmdBuffer, resultImage.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, resultBuffer.get(), 1u, ©Region); 1307e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(cmdBuffer, referenceImage.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, referenceBuffer.get(), 1u, ©Region); 1308e5c31af7Sopenharmony_ci 1309e5c31af7Sopenharmony_ci { 1310e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier postCopyBufferBarrier[] = 1311e5c31af7Sopenharmony_ci { 1312e5c31af7Sopenharmony_ci makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 1313e5c31af7Sopenharmony_ci resultBuffer.get(), 0ull, bufferSize), 1314e5c31af7Sopenharmony_ci 1315e5c31af7Sopenharmony_ci makeBufferMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 1316e5c31af7Sopenharmony_ci referenceBuffer.get(), 0ull, bufferSize), 1317e5c31af7Sopenharmony_ci }; 1318e5c31af7Sopenharmony_ci 1319e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 1320e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, DE_LENGTH_OF_ARRAY(postCopyBufferBarrier), postCopyBufferBarrier, 1321e5c31af7Sopenharmony_ci 0u, (const VkImageMemoryBarrier*)DE_NULL); 1322e5c31af7Sopenharmony_ci } 1323e5c31af7Sopenharmony_ci } 1324e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer); 1325e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmdBuffer); 1326e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 1327e5c31af7Sopenharmony_ci 1328e5c31af7Sopenharmony_ci const Allocation& resultAlloc = resultBuffer.getAllocation(); 1329e5c31af7Sopenharmony_ci const Allocation& referenceAlloc = referenceBuffer.getAllocation(); 1330e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, resultAlloc); 1331e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, referenceAlloc); 1332e5c31af7Sopenharmony_ci 1333e5c31af7Sopenharmony_ci BinaryCompareMode compareMode = 1334e5c31af7Sopenharmony_ci (m_parameters.formatIsASTC) 1335e5c31af7Sopenharmony_ci ?(COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING) 1336e5c31af7Sopenharmony_ci :(COMPARE_MODE_NORMAL); 1337e5c31af7Sopenharmony_ci 1338e5c31af7Sopenharmony_ci BinaryCompareResult res = BinaryCompare(referenceAlloc.getHostPtr(), 1339e5c31af7Sopenharmony_ci resultAlloc.getHostPtr(), 1340e5c31af7Sopenharmony_ci (size_t)bufferSize, 1341e5c31af7Sopenharmony_ci m_parameters.formatForVerify, 1342e5c31af7Sopenharmony_ci compareMode); 1343e5c31af7Sopenharmony_ci 1344e5c31af7Sopenharmony_ci if (res == COMPARE_RESULT_FAILED) 1345e5c31af7Sopenharmony_ci { 1346e5c31af7Sopenharmony_ci ConstPixelBufferAccess resultPixels (mapVkFormat(decompressedImageInfo.format), decompressedImageInfo.extent.width, decompressedImageInfo.extent.height, decompressedImageInfo.extent.depth, resultAlloc.getHostPtr()); 1347e5c31af7Sopenharmony_ci ConstPixelBufferAccess referencePixels (mapVkFormat(decompressedImageInfo.format), decompressedImageInfo.extent.width, decompressedImageInfo.extent.height, decompressedImageInfo.extent.depth, referenceAlloc.getHostPtr()); 1348e5c31af7Sopenharmony_ci 1349e5c31af7Sopenharmony_ci if(!fuzzyCompare(m_context.getTestContext().getLog(), "Image Comparison", "Image Comparison", resultPixels, referencePixels, 0.001f, tcu::COMPARE_LOG_EVERYTHING)) 1350e5c31af7Sopenharmony_ci return false; 1351e5c31af7Sopenharmony_ci } 1352e5c31af7Sopenharmony_ci else if (res == COMPARE_RESULT_ASTC_QUALITY_WARNING) 1353e5c31af7Sopenharmony_ci { 1354e5c31af7Sopenharmony_ci m_bASTCErrorColourMismatch = true; 1355e5c31af7Sopenharmony_ci } 1356e5c31af7Sopenharmony_ci } 1357e5c31af7Sopenharmony_ci 1358e5c31af7Sopenharmony_ci return true; 1359e5c31af7Sopenharmony_ci} 1360e5c31af7Sopenharmony_ci 1361e5c31af7Sopenharmony_ciclass ImageStoreComputeTestInstance : public BasicComputeTestInstance 1362e5c31af7Sopenharmony_ci{ 1363e5c31af7Sopenharmony_cipublic: 1364e5c31af7Sopenharmony_ci ImageStoreComputeTestInstance (Context& context, 1365e5c31af7Sopenharmony_ci const TestParameters& parameters); 1366e5c31af7Sopenharmony_ciprotected: 1367e5c31af7Sopenharmony_ci virtual void executeShader (const VkCommandPool& cmdPool, 1368e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 1369e5c31af7Sopenharmony_ci const VkDescriptorSetLayout& descriptorSetLayout, 1370e5c31af7Sopenharmony_ci const VkDescriptorPool& descriptorPool, 1371e5c31af7Sopenharmony_ci vector<ImageData>& imageData); 1372e5c31af7Sopenharmony_ciprivate: 1373e5c31af7Sopenharmony_ci}; 1374e5c31af7Sopenharmony_ci 1375e5c31af7Sopenharmony_ciImageStoreComputeTestInstance::ImageStoreComputeTestInstance (Context& context, const TestParameters& parameters) 1376e5c31af7Sopenharmony_ci :BasicComputeTestInstance (context, parameters) 1377e5c31af7Sopenharmony_ci{ 1378e5c31af7Sopenharmony_ci} 1379e5c31af7Sopenharmony_ci 1380e5c31af7Sopenharmony_civoid ImageStoreComputeTestInstance::executeShader (const VkCommandPool& cmdPool, 1381e5c31af7Sopenharmony_ci const VkCommandBuffer& cmdBuffer, 1382e5c31af7Sopenharmony_ci const VkDescriptorSetLayout& descriptorSetLayout, 1383e5c31af7Sopenharmony_ci const VkDescriptorPool& descriptorPool, 1384e5c31af7Sopenharmony_ci vector<ImageData>& imageData) 1385e5c31af7Sopenharmony_ci{ 1386e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1387e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1388e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 1389e5c31af7Sopenharmony_ci const Unique<VkShaderModule> shaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("comp"), 0)); 1390e5c31af7Sopenharmony_ci vector<SharedVkDescriptorSet> descriptorSets (imageData[0].getImageViewCount()); 1391e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, descriptorSetLayout)); 1392e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeComputePipeline(vk, device, *pipelineLayout, *shaderModule)); 1393e5c31af7Sopenharmony_ci Move<VkSampler> sampler; 1394e5c31af7Sopenharmony_ci { 1395e5c31af7Sopenharmony_ci const VkSamplerCreateInfo createInfo = 1396e5c31af7Sopenharmony_ci { 1397e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, //VkStructureType sType; 1398e5c31af7Sopenharmony_ci DE_NULL, //const void* pNext; 1399e5c31af7Sopenharmony_ci 0u, //VkSamplerCreateFlags flags; 1400e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter magFilter; 1401e5c31af7Sopenharmony_ci VK_FILTER_NEAREST, //VkFilter minFilter; 1402e5c31af7Sopenharmony_ci VK_SAMPLER_MIPMAP_MODE_NEAREST, //VkSamplerMipmapMode mipmapMode; 1403e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeU; 1404e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeV; 1405e5c31af7Sopenharmony_ci VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, //VkSamplerAddressMode addressModeW; 1406e5c31af7Sopenharmony_ci 0.0f, //float mipLodBias; 1407e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 anisotropyEnable; 1408e5c31af7Sopenharmony_ci 1.0f, //float maxAnisotropy; 1409e5c31af7Sopenharmony_ci VK_FALSE, //VkBool32 compareEnable; 1410e5c31af7Sopenharmony_ci VK_COMPARE_OP_EQUAL, //VkCompareOp compareOp; 1411e5c31af7Sopenharmony_ci 0.0f, //float minLod; 1412e5c31af7Sopenharmony_ci 0.0f, //float maxLod; 1413e5c31af7Sopenharmony_ci VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK, //VkBorderColor borderColor; 1414e5c31af7Sopenharmony_ci VK_TRUE, //VkBool32 unnormalizedCoordinates; 1415e5c31af7Sopenharmony_ci }; 1416e5c31af7Sopenharmony_ci sampler = createSampler(vk, device, &createInfo); 1417e5c31af7Sopenharmony_ci } 1418e5c31af7Sopenharmony_ci 1419e5c31af7Sopenharmony_ci vector<VkDescriptorImageInfo> descriptorImageInfos (descriptorSets.size() * m_parameters.imagesCount); 1420e5c31af7Sopenharmony_ci for (deUint32 viewNdx = 0u; viewNdx < descriptorSets.size(); ++viewNdx) 1421e5c31af7Sopenharmony_ci { 1422e5c31af7Sopenharmony_ci const deUint32 descriptorNdx = viewNdx * m_parameters.imagesCount; 1423e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < m_parameters.imagesCount; ++imageNdx) 1424e5c31af7Sopenharmony_ci { 1425e5c31af7Sopenharmony_ci descriptorImageInfos[descriptorNdx+imageNdx] = makeDescriptorImageInfo(*sampler, 1426e5c31af7Sopenharmony_ci imageData[imageNdx].getImageView(viewNdx), VK_IMAGE_LAYOUT_GENERAL); 1427e5c31af7Sopenharmony_ci } 1428e5c31af7Sopenharmony_ci } 1429e5c31af7Sopenharmony_ci 1430e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx < descriptorSets.size(); ++ndx) 1431e5c31af7Sopenharmony_ci descriptorSets[ndx] = makeVkSharedPtr(makeDescriptorSet(vk, device, descriptorPool, descriptorSetLayout)); 1432e5c31af7Sopenharmony_ci 1433e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer); 1434e5c31af7Sopenharmony_ci { 1435e5c31af7Sopenharmony_ci const VkImageSubresourceRange compressedRange = 1436e5c31af7Sopenharmony_ci { 1437e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 1438e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 1439e5c31af7Sopenharmony_ci imageData[0].getImageInfo(0).mipLevels, //deUint32 levelCount 1440e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 1441e5c31af7Sopenharmony_ci imageData[0].getImageInfo(0).arrayLayers //deUint32 layerCount 1442e5c31af7Sopenharmony_ci }; 1443e5c31af7Sopenharmony_ci 1444e5c31af7Sopenharmony_ci const VkImageSubresourceRange uncompressedRange = 1445e5c31af7Sopenharmony_ci { 1446e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, //VkImageAspectFlags aspectMask 1447e5c31af7Sopenharmony_ci 0u, //deUint32 baseMipLevel 1448e5c31af7Sopenharmony_ci 1u, //deUint32 levelCount 1449e5c31af7Sopenharmony_ci 0u, //deUint32 baseArrayLayer 1450e5c31af7Sopenharmony_ci 1u //deUint32 layerCount 1451e5c31af7Sopenharmony_ci }; 1452e5c31af7Sopenharmony_ci 1453e5c31af7Sopenharmony_ci vk.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 1454e5c31af7Sopenharmony_ci 1455e5c31af7Sopenharmony_ci vector<VkImageMemoryBarrier> preShaderImageBarriers (descriptorSets.size() * 2u + 1u); 1456e5c31af7Sopenharmony_ci for (deUint32 imageNdx = 0u; imageNdx < imageData[1].getImagesCount(); ++imageNdx) 1457e5c31af7Sopenharmony_ci { 1458e5c31af7Sopenharmony_ci preShaderImageBarriers[imageNdx] = makeImageMemoryBarrier( 1459e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, (VK_ACCESS_SHADER_READ_BIT|VK_ACCESS_SHADER_WRITE_BIT), 1460e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, 1461e5c31af7Sopenharmony_ci imageData[1].getImage(imageNdx), uncompressedRange); 1462e5c31af7Sopenharmony_ci 1463e5c31af7Sopenharmony_ci preShaderImageBarriers[imageNdx + imageData[1].getImagesCount()] = makeImageMemoryBarrier( 1464e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT, 1465e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 1466e5c31af7Sopenharmony_ci imageData[2].getImage(imageNdx), uncompressedRange); 1467e5c31af7Sopenharmony_ci } 1468e5c31af7Sopenharmony_ci 1469e5c31af7Sopenharmony_ci preShaderImageBarriers[preShaderImageBarriers.size()-1] = makeImageMemoryBarrier( 1470e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, (VK_ACCESS_SHADER_READ_BIT|VK_ACCESS_SHADER_WRITE_BIT), 1471e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, 1472e5c31af7Sopenharmony_ci imageData[0].getImage(0u), compressedRange); 1473e5c31af7Sopenharmony_ci 1474e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 1475e5c31af7Sopenharmony_ci (VkDependencyFlags)0, 0u, (const VkMemoryBarrier*)DE_NULL, 0u, (const VkBufferMemoryBarrier*)DE_NULL, 1476e5c31af7Sopenharmony_ci static_cast<deUint32>(preShaderImageBarriers.size()), &preShaderImageBarriers[0]); 1477e5c31af7Sopenharmony_ci 1478e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx <descriptorSets.size(); ++ndx) 1479e5c31af7Sopenharmony_ci { 1480e5c31af7Sopenharmony_ci descriptorSetUpdate (**descriptorSets[ndx], &descriptorImageInfos[ndx* m_parameters.imagesCount]); 1481e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0u, 1u, &(**descriptorSets[ndx]), 0u, DE_NULL); 1482e5c31af7Sopenharmony_ci vk.cmdDispatch(cmdBuffer, imageData[1].getImageInfo(ndx).extent.width, 1483e5c31af7Sopenharmony_ci imageData[1].getImageInfo(ndx).extent.height, 1484e5c31af7Sopenharmony_ci imageData[1].getImageInfo(ndx).extent.depth); 1485e5c31af7Sopenharmony_ci } 1486e5c31af7Sopenharmony_ci } 1487e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer); 1488e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmdBuffer); 1489e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 1490e5c31af7Sopenharmony_ci} 1491e5c31af7Sopenharmony_ci 1492e5c31af7Sopenharmony_ciclass GraphicsAttachmentsTestInstance : public BasicTranscodingTestInstance 1493e5c31af7Sopenharmony_ci{ 1494e5c31af7Sopenharmony_cipublic: 1495e5c31af7Sopenharmony_ci GraphicsAttachmentsTestInstance (Context& context, const TestParameters& parameters); 1496e5c31af7Sopenharmony_ci virtual TestStatus iterate (void); 1497e5c31af7Sopenharmony_ci 1498e5c31af7Sopenharmony_ciprotected: 1499e5c31af7Sopenharmony_ci virtual bool isWriteToCompressedOperation (); 1500e5c31af7Sopenharmony_ci VkImageCreateInfo makeCreateImageInfo (const VkFormat format, 1501e5c31af7Sopenharmony_ci const ImageType type, 1502e5c31af7Sopenharmony_ci const UVec3& size, 1503e5c31af7Sopenharmony_ci const VkImageUsageFlags usageFlags, 1504e5c31af7Sopenharmony_ci const VkImageCreateFlags* createFlags, 1505e5c31af7Sopenharmony_ci const deUint32 levels, 1506e5c31af7Sopenharmony_ci const deUint32 layers); 1507e5c31af7Sopenharmony_ci VkDeviceSize getCompressedImageData (const VkFormat format, 1508e5c31af7Sopenharmony_ci const UVec3& size, 1509e5c31af7Sopenharmony_ci std::vector<deUint8>& data, 1510e5c31af7Sopenharmony_ci const deUint32 layer, 1511e5c31af7Sopenharmony_ci const deUint32 level); 1512e5c31af7Sopenharmony_ci VkDeviceSize getUncompressedImageData (const VkFormat format, 1513e5c31af7Sopenharmony_ci const UVec3& size, 1514e5c31af7Sopenharmony_ci std::vector<deUint8>& data, 1515e5c31af7Sopenharmony_ci const deUint32 layer, 1516e5c31af7Sopenharmony_ci const deUint32 level); 1517e5c31af7Sopenharmony_ci virtual void prepareData (); 1518e5c31af7Sopenharmony_ci virtual void prepareVertexBuffer (); 1519e5c31af7Sopenharmony_ci virtual void transcodeRead (const VkCommandPool& cmdPool); 1520e5c31af7Sopenharmony_ci virtual void transcodeWrite (const VkCommandPool& cmdPool); 1521e5c31af7Sopenharmony_ci bool verifyDecompression (const VkCommandPool& cmdPool, 1522e5c31af7Sopenharmony_ci const std::vector<deUint8>& refCompressedData, 1523e5c31af7Sopenharmony_ci const de::MovePtr<Image>& resCompressedImage, 1524e5c31af7Sopenharmony_ci const deUint32 layer, 1525e5c31af7Sopenharmony_ci const deUint32 level, 1526e5c31af7Sopenharmony_ci const UVec3& mipmapDims); 1527e5c31af7Sopenharmony_ci 1528e5c31af7Sopenharmony_ci typedef std::vector<deUint8> RawDataVector; 1529e5c31af7Sopenharmony_ci typedef SharedPtr<RawDataVector> RawDataPtr; 1530e5c31af7Sopenharmony_ci typedef std::vector<RawDataPtr> LevelData; 1531e5c31af7Sopenharmony_ci typedef std::vector<LevelData> FullImageData; 1532e5c31af7Sopenharmony_ci 1533e5c31af7Sopenharmony_ci FullImageData m_srcData; 1534e5c31af7Sopenharmony_ci FullImageData m_dstData; 1535e5c31af7Sopenharmony_ci 1536e5c31af7Sopenharmony_ci typedef SharedPtr<Image> ImagePtr; 1537e5c31af7Sopenharmony_ci typedef std::vector<ImagePtr> LevelImages; 1538e5c31af7Sopenharmony_ci typedef std::vector<LevelImages> ImagesArray; 1539e5c31af7Sopenharmony_ci 1540e5c31af7Sopenharmony_ci ImagesArray m_uncompressedImages; 1541e5c31af7Sopenharmony_ci MovePtr<Image> m_compressedImage; 1542e5c31af7Sopenharmony_ci 1543e5c31af7Sopenharmony_ci VkImageViewUsageCreateInfo m_imageViewUsageKHR; 1544e5c31af7Sopenharmony_ci VkImageViewUsageCreateInfo* m_srcImageViewUsageKHR; 1545e5c31af7Sopenharmony_ci VkImageViewUsageCreateInfo* m_dstImageViewUsageKHR; 1546e5c31af7Sopenharmony_ci std::vector<tcu::UVec3> m_compressedImageResVec; 1547e5c31af7Sopenharmony_ci std::vector<tcu::UVec3> m_uncompressedImageResVec; 1548e5c31af7Sopenharmony_ci VkFormat m_srcFormat; 1549e5c31af7Sopenharmony_ci VkFormat m_dstFormat; 1550e5c31af7Sopenharmony_ci VkImageUsageFlags m_srcImageUsageFlags; 1551e5c31af7Sopenharmony_ci VkImageUsageFlags m_dstImageUsageFlags; 1552e5c31af7Sopenharmony_ci std::vector<tcu::UVec3> m_srcImageResolutions; 1553e5c31af7Sopenharmony_ci std::vector<tcu::UVec3> m_dstImageResolutions; 1554e5c31af7Sopenharmony_ci 1555e5c31af7Sopenharmony_ci MovePtr<BufferWithMemory> m_vertexBuffer; 1556e5c31af7Sopenharmony_ci deUint32 m_vertexCount; 1557e5c31af7Sopenharmony_ci VkDeviceSize m_vertexBufferOffset; 1558e5c31af7Sopenharmony_ci}; 1559e5c31af7Sopenharmony_ci 1560e5c31af7Sopenharmony_ciGraphicsAttachmentsTestInstance::GraphicsAttachmentsTestInstance (Context& context, const TestParameters& parameters) 1561e5c31af7Sopenharmony_ci : BasicTranscodingTestInstance(context, parameters) 1562e5c31af7Sopenharmony_ci , m_srcData() 1563e5c31af7Sopenharmony_ci , m_dstData() 1564e5c31af7Sopenharmony_ci , m_uncompressedImages() 1565e5c31af7Sopenharmony_ci , m_compressedImage() 1566e5c31af7Sopenharmony_ci , m_imageViewUsageKHR() 1567e5c31af7Sopenharmony_ci , m_srcImageViewUsageKHR() 1568e5c31af7Sopenharmony_ci , m_dstImageViewUsageKHR() 1569e5c31af7Sopenharmony_ci , m_compressedImageResVec() 1570e5c31af7Sopenharmony_ci , m_uncompressedImageResVec() 1571e5c31af7Sopenharmony_ci , m_srcFormat() 1572e5c31af7Sopenharmony_ci , m_dstFormat() 1573e5c31af7Sopenharmony_ci , m_srcImageUsageFlags() 1574e5c31af7Sopenharmony_ci , m_dstImageUsageFlags() 1575e5c31af7Sopenharmony_ci , m_srcImageResolutions() 1576e5c31af7Sopenharmony_ci , m_dstImageResolutions() 1577e5c31af7Sopenharmony_ci , m_vertexBuffer() 1578e5c31af7Sopenharmony_ci , m_vertexCount(0u) 1579e5c31af7Sopenharmony_ci , m_vertexBufferOffset(0ull) 1580e5c31af7Sopenharmony_ci{ 1581e5c31af7Sopenharmony_ci} 1582e5c31af7Sopenharmony_ci 1583e5c31af7Sopenharmony_ciTestStatus GraphicsAttachmentsTestInstance::iterate (void) 1584e5c31af7Sopenharmony_ci{ 1585e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1586e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1587e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex(); 1588e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex)); 1589e5c31af7Sopenharmony_ci 1590e5c31af7Sopenharmony_ci prepareData(); 1591e5c31af7Sopenharmony_ci prepareVertexBuffer(); 1592e5c31af7Sopenharmony_ci 1593e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 1594e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 1595e5c31af7Sopenharmony_ci DE_ASSERT(m_srcData[levelNdx][layerNdx]->size() == m_dstData[levelNdx][layerNdx]->size()); 1596e5c31af7Sopenharmony_ci 1597e5c31af7Sopenharmony_ci if (isWriteToCompressedOperation()) 1598e5c31af7Sopenharmony_ci transcodeWrite(*cmdPool); 1599e5c31af7Sopenharmony_ci else 1600e5c31af7Sopenharmony_ci transcodeRead(*cmdPool); 1601e5c31af7Sopenharmony_ci 1602e5c31af7Sopenharmony_ci bool pass = true; 1603e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 1604e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 1605e5c31af7Sopenharmony_ci if (isWriteToCompressedOperation()) 1606e5c31af7Sopenharmony_ci { 1607e5c31af7Sopenharmony_ci if (!verifyDecompression(*cmdPool, *m_srcData[levelNdx][layerNdx], m_compressedImage, levelNdx, layerNdx, m_compressedImageResVec[levelNdx])) 1608e5c31af7Sopenharmony_ci pass = false; 1609e5c31af7Sopenharmony_ci } 1610e5c31af7Sopenharmony_ci else 1611e5c31af7Sopenharmony_ci { 1612e5c31af7Sopenharmony_ci if (!verifyDecompression(*cmdPool, *m_dstData[levelNdx][layerNdx], m_compressedImage, levelNdx, layerNdx, m_compressedImageResVec[levelNdx])) 1613e5c31af7Sopenharmony_ci pass = false; 1614e5c31af7Sopenharmony_ci } 1615e5c31af7Sopenharmony_ci 1616e5c31af7Sopenharmony_ci if (!pass) 1617e5c31af7Sopenharmony_ci return TestStatus::fail("Images difference detected");; 1618e5c31af7Sopenharmony_ci 1619e5c31af7Sopenharmony_ci if (m_bASTCErrorColourMismatch) 1620e5c31af7Sopenharmony_ci { 1621e5c31af7Sopenharmony_ci DE_ASSERT(m_parameters.formatIsASTC); 1622e5c31af7Sopenharmony_ci return TestStatusASTCQualityWarning(); 1623e5c31af7Sopenharmony_ci } 1624e5c31af7Sopenharmony_ci 1625e5c31af7Sopenharmony_ci return TestStatus::pass("Pass"); 1626e5c31af7Sopenharmony_ci} 1627e5c31af7Sopenharmony_ci 1628e5c31af7Sopenharmony_civoid GraphicsAttachmentsTestInstance::prepareData () 1629e5c31af7Sopenharmony_ci{ 1630e5c31af7Sopenharmony_ci VkImageViewUsageCreateInfo* imageViewUsageKHRNull = (VkImageViewUsageCreateInfo*)DE_NULL; 1631e5c31af7Sopenharmony_ci 1632e5c31af7Sopenharmony_ci m_imageViewUsageKHR = makeImageViewUsageCreateInfo(m_parameters.compressedImageViewUsage); 1633e5c31af7Sopenharmony_ci 1634e5c31af7Sopenharmony_ci m_srcImageViewUsageKHR = isWriteToCompressedOperation() ? imageViewUsageKHRNull : &m_imageViewUsageKHR; 1635e5c31af7Sopenharmony_ci m_dstImageViewUsageKHR = isWriteToCompressedOperation() ? &m_imageViewUsageKHR : imageViewUsageKHRNull; 1636e5c31af7Sopenharmony_ci 1637e5c31af7Sopenharmony_ci m_srcFormat = isWriteToCompressedOperation() ? m_parameters.formatUncompressed : m_parameters.formatCompressed; 1638e5c31af7Sopenharmony_ci m_dstFormat = isWriteToCompressedOperation() ? m_parameters.formatCompressed : m_parameters.formatUncompressed; 1639e5c31af7Sopenharmony_ci 1640e5c31af7Sopenharmony_ci m_srcImageUsageFlags = isWriteToCompressedOperation() ? m_parameters.uncompressedImageUsage : m_parameters.compressedImageUsage; 1641e5c31af7Sopenharmony_ci m_dstImageUsageFlags = isWriteToCompressedOperation() ? m_parameters.compressedImageUsage : m_parameters.uncompressedImageUsage; 1642e5c31af7Sopenharmony_ci 1643e5c31af7Sopenharmony_ci m_compressedImageResVec = getMipLevelSizes(getLayerDims()); 1644e5c31af7Sopenharmony_ci m_uncompressedImageResVec = getCompressedMipLevelSizes(m_parameters.formatCompressed, m_compressedImageResVec); 1645e5c31af7Sopenharmony_ci 1646e5c31af7Sopenharmony_ci m_srcImageResolutions = isWriteToCompressedOperation() ? m_uncompressedImageResVec : m_compressedImageResVec; 1647e5c31af7Sopenharmony_ci m_dstImageResolutions = isWriteToCompressedOperation() ? m_compressedImageResVec : m_uncompressedImageResVec; 1648e5c31af7Sopenharmony_ci 1649e5c31af7Sopenharmony_ci m_srcData.resize(getLevelCount()); 1650e5c31af7Sopenharmony_ci m_dstData.resize(getLevelCount()); 1651e5c31af7Sopenharmony_ci m_uncompressedImages.resize(getLevelCount()); 1652e5c31af7Sopenharmony_ci 1653e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 1654e5c31af7Sopenharmony_ci { 1655e5c31af7Sopenharmony_ci m_srcData[levelNdx].resize(getLayerCount()); 1656e5c31af7Sopenharmony_ci m_dstData[levelNdx].resize(getLayerCount()); 1657e5c31af7Sopenharmony_ci m_uncompressedImages[levelNdx].resize(getLayerCount()); 1658e5c31af7Sopenharmony_ci 1659e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 1660e5c31af7Sopenharmony_ci { 1661e5c31af7Sopenharmony_ci m_srcData[levelNdx][layerNdx] = SharedPtr<RawDataVector>(new RawDataVector); 1662e5c31af7Sopenharmony_ci m_dstData[levelNdx][layerNdx] = SharedPtr<RawDataVector>(new RawDataVector); 1663e5c31af7Sopenharmony_ci 1664e5c31af7Sopenharmony_ci if (isWriteToCompressedOperation()) 1665e5c31af7Sopenharmony_ci { 1666e5c31af7Sopenharmony_ci getUncompressedImageData(m_srcFormat, m_srcImageResolutions[levelNdx], *m_srcData[levelNdx][layerNdx], layerNdx, levelNdx); 1667e5c31af7Sopenharmony_ci 1668e5c31af7Sopenharmony_ci m_dstData[levelNdx][layerNdx]->resize((size_t)getCompressedImageSizeInBytes(m_dstFormat, m_dstImageResolutions[levelNdx])); 1669e5c31af7Sopenharmony_ci } 1670e5c31af7Sopenharmony_ci else 1671e5c31af7Sopenharmony_ci { 1672e5c31af7Sopenharmony_ci getCompressedImageData(m_srcFormat, m_srcImageResolutions[levelNdx], *m_srcData[levelNdx][layerNdx], layerNdx, levelNdx); 1673e5c31af7Sopenharmony_ci 1674e5c31af7Sopenharmony_ci m_dstData[levelNdx][layerNdx]->resize((size_t)getUncompressedImageSizeInBytes(m_dstFormat, m_dstImageResolutions[levelNdx])); 1675e5c31af7Sopenharmony_ci } 1676e5c31af7Sopenharmony_ci 1677e5c31af7Sopenharmony_ci DE_ASSERT(m_srcData[levelNdx][layerNdx]->size() == m_dstData[levelNdx][layerNdx]->size()); 1678e5c31af7Sopenharmony_ci } 1679e5c31af7Sopenharmony_ci } 1680e5c31af7Sopenharmony_ci} 1681e5c31af7Sopenharmony_ci 1682e5c31af7Sopenharmony_civoid GraphicsAttachmentsTestInstance::prepareVertexBuffer () 1683e5c31af7Sopenharmony_ci{ 1684e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1685e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1686e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 1687e5c31af7Sopenharmony_ci 1688e5c31af7Sopenharmony_ci const std::vector<tcu::Vec4> vertexArray = createFullscreenQuad(); 1689e5c31af7Sopenharmony_ci const size_t vertexBufferSizeInBytes = vertexArray.size() * sizeof(vertexArray[0]); 1690e5c31af7Sopenharmony_ci 1691e5c31af7Sopenharmony_ci m_vertexCount = static_cast<deUint32>(vertexArray.size()); 1692e5c31af7Sopenharmony_ci m_vertexBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, makeBufferCreateInfo(vertexBufferSizeInBytes, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), MemoryRequirement::HostVisible)); 1693e5c31af7Sopenharmony_ci 1694e5c31af7Sopenharmony_ci // Upload vertex data 1695e5c31af7Sopenharmony_ci const Allocation& vertexBufferAlloc = m_vertexBuffer->getAllocation(); 1696e5c31af7Sopenharmony_ci deMemcpy(vertexBufferAlloc.getHostPtr(), &vertexArray[0], vertexBufferSizeInBytes); 1697e5c31af7Sopenharmony_ci flushAlloc(vk, device, vertexBufferAlloc); 1698e5c31af7Sopenharmony_ci} 1699e5c31af7Sopenharmony_ci 1700e5c31af7Sopenharmony_civoid GraphicsAttachmentsTestInstance::transcodeRead (const VkCommandPool& cmdPool) 1701e5c31af7Sopenharmony_ci{ 1702e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1703e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1704e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 1705e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 1706e5c31af7Sopenharmony_ci 1707e5c31af7Sopenharmony_ci const VkImageCreateFlags* imgCreateFlagsOverride = DE_NULL; 1708e5c31af7Sopenharmony_ci 1709e5c31af7Sopenharmony_ci const VkImageCreateInfo srcImageCreateInfo = makeCreateImageInfo(m_srcFormat, m_parameters.imageType, m_srcImageResolutions[0], m_srcImageUsageFlags, imgCreateFlagsOverride, getLevelCount(), getLayerCount()); 1710e5c31af7Sopenharmony_ci MovePtr<Image> srcImage (new Image(vk, device, allocator, srcImageCreateInfo, MemoryRequirement::Any)); 1711e5c31af7Sopenharmony_ci 1712e5c31af7Sopenharmony_ci const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0)); 1713e5c31af7Sopenharmony_ci const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0)); 1714e5c31af7Sopenharmony_ci 1715e5c31af7Sopenharmony_ci const Unique<VkRenderPass> renderPass (vkt::image::makeRenderPass(vk, device, m_parameters.formatUncompressed, m_parameters.formatUncompressed)); 1716e5c31af7Sopenharmony_ci 1717e5c31af7Sopenharmony_ci const Move<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder() 1718e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, VK_SHADER_STAGE_FRAGMENT_BIT) 1719e5c31af7Sopenharmony_ci .build(vk, device)); 1720e5c31af7Sopenharmony_ci const Move<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder() 1721e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) 1722e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u)); 1723e5c31af7Sopenharmony_ci const Move<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout)); 1724e5c31af7Sopenharmony_ci 1725e5c31af7Sopenharmony_ci const VkExtent2D renderSizeUnused (makeExtent2D(1u, 1u)); 1726e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, *descriptorSetLayout)); 1727e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, device, *pipelineLayout, *renderPass, *vertShaderModule, *fragShaderModule, renderSizeUnused, 1u, true)); 1728e5c31af7Sopenharmony_ci 1729e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 1730e5c31af7Sopenharmony_ci 1731e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 1732e5c31af7Sopenharmony_ci { 1733e5c31af7Sopenharmony_ci const UVec3& uncompressedImageRes = m_uncompressedImageResVec[levelNdx]; 1734e5c31af7Sopenharmony_ci const UVec3& srcImageResolution = m_srcImageResolutions[levelNdx]; 1735e5c31af7Sopenharmony_ci const UVec3& dstImageResolution = m_dstImageResolutions[levelNdx]; 1736e5c31af7Sopenharmony_ci const size_t srcImageSizeInBytes = m_srcData[levelNdx][0]->size(); 1737e5c31af7Sopenharmony_ci const size_t dstImageSizeInBytes = m_dstData[levelNdx][0]->size(); 1738e5c31af7Sopenharmony_ci const UVec3 srcImageResBlocked = getCompressedImageResolutionBlockCeil(m_parameters.formatCompressed, srcImageResolution); 1739e5c31af7Sopenharmony_ci 1740e5c31af7Sopenharmony_ci const VkImageCreateInfo dstImageCreateInfo = makeCreateImageInfo(m_dstFormat, m_parameters.imageType, dstImageResolution, m_dstImageUsageFlags, imgCreateFlagsOverride, SINGLE_LEVEL, SINGLE_LAYER); 1741e5c31af7Sopenharmony_ci 1742e5c31af7Sopenharmony_ci const VkBufferCreateInfo srcImageBufferInfo = makeBufferCreateInfo(srcImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); 1743e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> srcImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, srcImageBufferInfo, MemoryRequirement::HostVisible)); 1744e5c31af7Sopenharmony_ci 1745e5c31af7Sopenharmony_ci const VkBufferCreateInfo dstImageBufferInfo = makeBufferCreateInfo(dstImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 1746e5c31af7Sopenharmony_ci MovePtr<BufferWithMemory> dstImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, dstImageBufferInfo, MemoryRequirement::HostVisible)); 1747e5c31af7Sopenharmony_ci 1748e5c31af7Sopenharmony_ci const VkExtent2D renderSize (makeExtent2D(uncompressedImageRes.x(), uncompressedImageRes.y())); 1749e5c31af7Sopenharmony_ci const VkViewport viewport = makeViewport(renderSize); 1750e5c31af7Sopenharmony_ci const VkRect2D scissor = makeRect2D(renderSize); 1751e5c31af7Sopenharmony_ci 1752e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 1753e5c31af7Sopenharmony_ci { 1754e5c31af7Sopenharmony_ci const VkImageSubresourceRange srcSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, SINGLE_LEVEL, layerNdx, SINGLE_LAYER); 1755e5c31af7Sopenharmony_ci const VkImageSubresourceRange dstSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, SINGLE_LEVEL, 0u, SINGLE_LAYER); 1756e5c31af7Sopenharmony_ci 1757e5c31af7Sopenharmony_ci Move<VkImageView> srcImageView (makeImageView(vk, device, srcImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, srcSubresourceRange, m_srcImageViewUsageKHR)); 1758e5c31af7Sopenharmony_ci 1759e5c31af7Sopenharmony_ci de::MovePtr<Image> dstImage (new Image(vk, device, allocator, dstImageCreateInfo, MemoryRequirement::Any)); 1760e5c31af7Sopenharmony_ci Move<VkImageView> dstImageView (makeImageView(vk, device, dstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, dstSubresourceRange, m_dstImageViewUsageKHR)); 1761e5c31af7Sopenharmony_ci 1762e5c31af7Sopenharmony_ci const VkBufferImageCopy srcCopyRegion = makeBufferImageCopy(srcImageResolution.x(), srcImageResolution.y(), levelNdx, layerNdx, srcImageResBlocked.x(), srcImageResBlocked.y()); 1763e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier srcCopyBufferBarrierPre = makeBufferMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, srcImageBuffer->get(), 0ull, srcImageSizeInBytes); 1764e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPre = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, srcImage->get(), srcSubresourceRange); 1765e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPost = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, srcImage->get(), srcSubresourceRange); 1766e5c31af7Sopenharmony_ci const VkBufferImageCopy dstCopyRegion = makeBufferImageCopy(dstImageResolution.x(), dstImageResolution.y()); 1767e5c31af7Sopenharmony_ci const VkImageMemoryBarrier dstInitImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, dstImage->get(), dstSubresourceRange); 1768e5c31af7Sopenharmony_ci 1769e5c31af7Sopenharmony_ci const VkImageView attachmentBindInfos[] = { *srcImageView, *dstImageView }; 1770e5c31af7Sopenharmony_ci const VkExtent2D framebufferSize (makeExtent2D(dstImageResolution[0], dstImageResolution[1])); 1771e5c31af7Sopenharmony_ci const Move<VkFramebuffer> framebuffer (makeFramebuffer(vk, device, *renderPass, DE_LENGTH_OF_ARRAY(attachmentBindInfos), attachmentBindInfos, framebufferSize.width, framebufferSize.height, SINGLE_LAYER)); 1772e5c31af7Sopenharmony_ci 1773e5c31af7Sopenharmony_ci // Upload source image data 1774e5c31af7Sopenharmony_ci const Allocation& alloc = srcImageBuffer->getAllocation(); 1775e5c31af7Sopenharmony_ci deMemcpy(alloc.getHostPtr(), &m_srcData[levelNdx][layerNdx]->at(0), srcImageSizeInBytes); 1776e5c31af7Sopenharmony_ci flushAlloc(vk, device, alloc); 1777e5c31af7Sopenharmony_ci 1778e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer); 1779e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 1780e5c31af7Sopenharmony_ci 1781e5c31af7Sopenharmony_ci // Copy buffer to image 1782e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &srcCopyBufferBarrierPre, 1u, &srcCopyImageBarrierPre); 1783e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(*cmdBuffer, srcImageBuffer->get(), srcImage->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &srcCopyRegion); 1784e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &srcCopyImageBarrierPost); 1785e5c31af7Sopenharmony_ci 1786e5c31af7Sopenharmony_ci // Define destination image layout 1787e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &dstInitImageBarrier); 1788e5c31af7Sopenharmony_ci 1789e5c31af7Sopenharmony_ci beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderSize); 1790e5c31af7Sopenharmony_ci 1791e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorSrcImageInfo(makeDescriptorImageInfo(DE_NULL, *srcImageView, VK_IMAGE_LAYOUT_GENERAL)); 1792e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 1793e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, &descriptorSrcImageInfo) 1794e5c31af7Sopenharmony_ci .update(vk, device); 1795e5c31af7Sopenharmony_ci 1796e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 1797e5c31af7Sopenharmony_ci vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &m_vertexBuffer->get(), &m_vertexBufferOffset); 1798e5c31af7Sopenharmony_ci 1799e5c31af7Sopenharmony_ci vk.cmdSetViewport(*cmdBuffer, 0u, 1u, &viewport); 1800e5c31af7Sopenharmony_ci vk.cmdSetScissor(*cmdBuffer, 0u, 1u, &scissor); 1801e5c31af7Sopenharmony_ci 1802e5c31af7Sopenharmony_ci vk.cmdDraw(*cmdBuffer, (deUint32)m_vertexCount, 1, 0, 0); 1803e5c31af7Sopenharmony_ci 1804e5c31af7Sopenharmony_ci endRenderPass(vk, *cmdBuffer); 1805e5c31af7Sopenharmony_ci 1806e5c31af7Sopenharmony_ci const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier( 1807e5c31af7Sopenharmony_ci VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 1808e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 1809e5c31af7Sopenharmony_ci dstImage->get(), dstSubresourceRange); 1810e5c31af7Sopenharmony_ci 1811e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier( 1812e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 1813e5c31af7Sopenharmony_ci dstImageBuffer->get(), 0ull, dstImageSizeInBytes); 1814e5c31af7Sopenharmony_ci 1815e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &prepareForTransferBarrier); 1816e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, dstImage->get(), VK_IMAGE_LAYOUT_GENERAL, dstImageBuffer->get(), 1u, &dstCopyRegion); 1817e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©Barrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 1818e5c31af7Sopenharmony_ci 1819e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 1820e5c31af7Sopenharmony_ci 1821e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, *cmdBuffer); 1822e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 1823e5c31af7Sopenharmony_ci 1824e5c31af7Sopenharmony_ci const Allocation& dstImageBufferAlloc = dstImageBuffer->getAllocation(); 1825e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, dstImageBufferAlloc); 1826e5c31af7Sopenharmony_ci deMemcpy(&m_dstData[levelNdx][layerNdx]->at(0), dstImageBufferAlloc.getHostPtr(), dstImageSizeInBytes); 1827e5c31af7Sopenharmony_ci } 1828e5c31af7Sopenharmony_ci } 1829e5c31af7Sopenharmony_ci 1830e5c31af7Sopenharmony_ci m_compressedImage = srcImage; 1831e5c31af7Sopenharmony_ci} 1832e5c31af7Sopenharmony_ci 1833e5c31af7Sopenharmony_civoid GraphicsAttachmentsTestInstance::transcodeWrite (const VkCommandPool& cmdPool) 1834e5c31af7Sopenharmony_ci{ 1835e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 1836e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 1837e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 1838e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 1839e5c31af7Sopenharmony_ci 1840e5c31af7Sopenharmony_ci const VkImageCreateFlags* imgCreateFlagsOverride = DE_NULL; 1841e5c31af7Sopenharmony_ci 1842e5c31af7Sopenharmony_ci const VkImageCreateInfo dstImageCreateInfo = makeCreateImageInfo(m_dstFormat, m_parameters.imageType, m_dstImageResolutions[0], m_dstImageUsageFlags, imgCreateFlagsOverride, getLevelCount(), getLayerCount()); 1843e5c31af7Sopenharmony_ci MovePtr<Image> dstImage (new Image(vk, device, allocator, dstImageCreateInfo, MemoryRequirement::Any)); 1844e5c31af7Sopenharmony_ci 1845e5c31af7Sopenharmony_ci const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0)); 1846e5c31af7Sopenharmony_ci const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0)); 1847e5c31af7Sopenharmony_ci 1848e5c31af7Sopenharmony_ci const Unique<VkRenderPass> renderPass (vkt::image::makeRenderPass(vk, device, m_parameters.formatUncompressed, m_parameters.formatUncompressed)); 1849e5c31af7Sopenharmony_ci 1850e5c31af7Sopenharmony_ci const Move<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder() 1851e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, VK_SHADER_STAGE_FRAGMENT_BIT) 1852e5c31af7Sopenharmony_ci .build(vk, device)); 1853e5c31af7Sopenharmony_ci const Move<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder() 1854e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) 1855e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u)); 1856e5c31af7Sopenharmony_ci const Move<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout)); 1857e5c31af7Sopenharmony_ci 1858e5c31af7Sopenharmony_ci const VkExtent2D renderSizeUnused (makeExtent2D(1u, 1u)); 1859e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, *descriptorSetLayout)); 1860e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, device, *pipelineLayout, *renderPass, *vertShaderModule, *fragShaderModule, renderSizeUnused, 1u, true)); 1861e5c31af7Sopenharmony_ci 1862e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 1863e5c31af7Sopenharmony_ci 1864e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 1865e5c31af7Sopenharmony_ci { 1866e5c31af7Sopenharmony_ci const UVec3& uncompressedImageRes = m_uncompressedImageResVec[levelNdx]; 1867e5c31af7Sopenharmony_ci const UVec3& srcImageResolution = m_srcImageResolutions[levelNdx]; 1868e5c31af7Sopenharmony_ci const UVec3& dstImageResolution = m_dstImageResolutions[levelNdx]; 1869e5c31af7Sopenharmony_ci const UVec3 dstImageResBlocked = getCompressedImageResolutionBlockCeil(m_parameters.formatCompressed, dstImageResolution); 1870e5c31af7Sopenharmony_ci const size_t srcImageSizeInBytes = m_srcData[levelNdx][0]->size(); 1871e5c31af7Sopenharmony_ci const size_t dstImageSizeInBytes = m_dstData[levelNdx][0]->size(); 1872e5c31af7Sopenharmony_ci 1873e5c31af7Sopenharmony_ci const VkImageCreateInfo srcImageCreateInfo = makeCreateImageInfo(m_srcFormat, m_parameters.imageType, srcImageResolution, m_srcImageUsageFlags, imgCreateFlagsOverride, SINGLE_LEVEL, SINGLE_LAYER); 1874e5c31af7Sopenharmony_ci 1875e5c31af7Sopenharmony_ci const VkExtent2D renderSize (makeExtent2D(uncompressedImageRes.x(), uncompressedImageRes.y())); 1876e5c31af7Sopenharmony_ci const VkViewport viewport = makeViewport(renderSize); 1877e5c31af7Sopenharmony_ci const VkRect2D scissor = makeRect2D(renderSize); 1878e5c31af7Sopenharmony_ci 1879e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 1880e5c31af7Sopenharmony_ci { 1881e5c31af7Sopenharmony_ci const VkBufferCreateInfo srcImageBufferInfo = makeBufferCreateInfo(srcImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); 1882e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> srcImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, srcImageBufferInfo, MemoryRequirement::HostVisible)); 1883e5c31af7Sopenharmony_ci 1884e5c31af7Sopenharmony_ci const VkBufferCreateInfo dstImageBufferInfo = makeBufferCreateInfo(dstImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 1885e5c31af7Sopenharmony_ci MovePtr<BufferWithMemory> dstImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, dstImageBufferInfo, MemoryRequirement::HostVisible)); 1886e5c31af7Sopenharmony_ci 1887e5c31af7Sopenharmony_ci const VkImageSubresourceRange srcSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, SINGLE_LEVEL, 0u, SINGLE_LAYER); 1888e5c31af7Sopenharmony_ci const VkImageSubresourceRange dstSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, SINGLE_LEVEL, layerNdx, SINGLE_LAYER); 1889e5c31af7Sopenharmony_ci 1890e5c31af7Sopenharmony_ci Move<VkImageView> dstImageView (makeImageView(vk, device, dstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, dstSubresourceRange, m_dstImageViewUsageKHR)); 1891e5c31af7Sopenharmony_ci 1892e5c31af7Sopenharmony_ci de::MovePtr<Image> srcImage (new Image(vk, device, allocator, srcImageCreateInfo, MemoryRequirement::Any)); 1893e5c31af7Sopenharmony_ci Move<VkImageView> srcImageView (makeImageView(vk, device, srcImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, srcSubresourceRange, m_srcImageViewUsageKHR)); 1894e5c31af7Sopenharmony_ci 1895e5c31af7Sopenharmony_ci const VkBufferImageCopy srcCopyRegion = makeBufferImageCopy(srcImageResolution.x(), srcImageResolution.y(), 0u, 0u); 1896e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier srcCopyBufferBarrierPre = makeBufferMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, srcImageBuffer->get(), 0ull, srcImageSizeInBytes); 1897e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPre = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, srcImage->get(), srcSubresourceRange); 1898e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPost = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_INPUT_ATTACHMENT_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, srcImage->get(), srcSubresourceRange); 1899e5c31af7Sopenharmony_ci const VkBufferImageCopy dstCopyRegion = makeBufferImageCopy(dstImageResolution.x(), dstImageResolution.y(), levelNdx, layerNdx, dstImageResBlocked.x(), dstImageResBlocked.y()); 1900e5c31af7Sopenharmony_ci const VkImageMemoryBarrier dstInitImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, dstImage->get(), dstSubresourceRange); 1901e5c31af7Sopenharmony_ci 1902e5c31af7Sopenharmony_ci const VkImageView attachmentBindInfos[] = { *srcImageView, *dstImageView }; 1903e5c31af7Sopenharmony_ci const VkExtent2D framebufferSize (renderSize); 1904e5c31af7Sopenharmony_ci const Move<VkFramebuffer> framebuffer (makeFramebuffer(vk, device, *renderPass, DE_LENGTH_OF_ARRAY(attachmentBindInfos), attachmentBindInfos, framebufferSize.width, framebufferSize.height, SINGLE_LAYER)); 1905e5c31af7Sopenharmony_ci 1906e5c31af7Sopenharmony_ci // Upload source image data 1907e5c31af7Sopenharmony_ci const Allocation& alloc = srcImageBuffer->getAllocation(); 1908e5c31af7Sopenharmony_ci deMemcpy(alloc.getHostPtr(), &m_srcData[levelNdx][layerNdx]->at(0), srcImageSizeInBytes); 1909e5c31af7Sopenharmony_ci flushAlloc(vk, device, alloc); 1910e5c31af7Sopenharmony_ci 1911e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer); 1912e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 1913e5c31af7Sopenharmony_ci 1914e5c31af7Sopenharmony_ci // Copy buffer to image 1915e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &srcCopyBufferBarrierPre, 1u, &srcCopyImageBarrierPre); 1916e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(*cmdBuffer, srcImageBuffer->get(), srcImage->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &srcCopyRegion); 1917e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &srcCopyImageBarrierPost); 1918e5c31af7Sopenharmony_ci 1919e5c31af7Sopenharmony_ci // Define destination image layout 1920e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &dstInitImageBarrier); 1921e5c31af7Sopenharmony_ci 1922e5c31af7Sopenharmony_ci beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderSize); 1923e5c31af7Sopenharmony_ci 1924e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorSrcImageInfo(makeDescriptorImageInfo(DE_NULL, *srcImageView, VK_IMAGE_LAYOUT_GENERAL)); 1925e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 1926e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, &descriptorSrcImageInfo) 1927e5c31af7Sopenharmony_ci .update(vk, device); 1928e5c31af7Sopenharmony_ci 1929e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 1930e5c31af7Sopenharmony_ci vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &m_vertexBuffer->get(), &m_vertexBufferOffset); 1931e5c31af7Sopenharmony_ci 1932e5c31af7Sopenharmony_ci vk.cmdSetViewport(*cmdBuffer, 0u, 1u, &viewport); 1933e5c31af7Sopenharmony_ci vk.cmdSetScissor(*cmdBuffer, 0u, 1u, &scissor); 1934e5c31af7Sopenharmony_ci 1935e5c31af7Sopenharmony_ci vk.cmdDraw(*cmdBuffer, (deUint32)m_vertexCount, 1, 0, 0); 1936e5c31af7Sopenharmony_ci 1937e5c31af7Sopenharmony_ci endRenderPass(vk, *cmdBuffer); 1938e5c31af7Sopenharmony_ci 1939e5c31af7Sopenharmony_ci const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier( 1940e5c31af7Sopenharmony_ci VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 1941e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 1942e5c31af7Sopenharmony_ci dstImage->get(), dstSubresourceRange); 1943e5c31af7Sopenharmony_ci 1944e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier( 1945e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 1946e5c31af7Sopenharmony_ci dstImageBuffer->get(), 0ull, dstImageSizeInBytes); 1947e5c31af7Sopenharmony_ci 1948e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &prepareForTransferBarrier); 1949e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, dstImage->get(), VK_IMAGE_LAYOUT_GENERAL, dstImageBuffer->get(), 1u, &dstCopyRegion); 1950e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©Barrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 1951e5c31af7Sopenharmony_ci 1952e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 1953e5c31af7Sopenharmony_ci 1954e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, *cmdBuffer); 1955e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 1956e5c31af7Sopenharmony_ci 1957e5c31af7Sopenharmony_ci const Allocation& dstImageBufferAlloc = dstImageBuffer->getAllocation(); 1958e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, dstImageBufferAlloc); 1959e5c31af7Sopenharmony_ci deMemcpy(&m_dstData[levelNdx][layerNdx]->at(0), dstImageBufferAlloc.getHostPtr(), dstImageSizeInBytes); 1960e5c31af7Sopenharmony_ci } 1961e5c31af7Sopenharmony_ci } 1962e5c31af7Sopenharmony_ci 1963e5c31af7Sopenharmony_ci m_compressedImage = dstImage; 1964e5c31af7Sopenharmony_ci} 1965e5c31af7Sopenharmony_ci 1966e5c31af7Sopenharmony_cibool GraphicsAttachmentsTestInstance::isWriteToCompressedOperation () 1967e5c31af7Sopenharmony_ci{ 1968e5c31af7Sopenharmony_ci return (m_parameters.operation == OPERATION_ATTACHMENT_WRITE); 1969e5c31af7Sopenharmony_ci} 1970e5c31af7Sopenharmony_ci 1971e5c31af7Sopenharmony_ciVkImageCreateInfo GraphicsAttachmentsTestInstance::makeCreateImageInfo (const VkFormat format, 1972e5c31af7Sopenharmony_ci const ImageType type, 1973e5c31af7Sopenharmony_ci const UVec3& size, 1974e5c31af7Sopenharmony_ci const VkImageUsageFlags usageFlags, 1975e5c31af7Sopenharmony_ci const VkImageCreateFlags* createFlags, 1976e5c31af7Sopenharmony_ci const deUint32 levels, 1977e5c31af7Sopenharmony_ci const deUint32 layers) 1978e5c31af7Sopenharmony_ci{ 1979e5c31af7Sopenharmony_ci const VkImageType imageType = mapImageType(type); 1980e5c31af7Sopenharmony_ci const VkImageCreateFlags imageCreateFlagsBase = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; 1981e5c31af7Sopenharmony_ci const VkImageCreateFlags imageCreateFlagsAddOn = isCompressedFormat(format) ? VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT : 0; 1982e5c31af7Sopenharmony_ci const VkImageCreateFlags imageCreateFlags = (createFlags != DE_NULL) ? *createFlags : (imageCreateFlagsBase | imageCreateFlagsAddOn); 1983e5c31af7Sopenharmony_ci 1984e5c31af7Sopenharmony_ci VkFormatProperties properties; 1985e5c31af7Sopenharmony_ci m_context.getInstanceInterface().getPhysicalDeviceFormatProperties(m_context.getPhysicalDevice(), format, &properties); 1986e5c31af7Sopenharmony_ci if ((usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) && !(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) 1987e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Format storage feature not supported"); 1988e5c31af7Sopenharmony_ci if ((usageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && !(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) 1989e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Format color attachment feature not supported"); 1990e5c31af7Sopenharmony_ci if ((usageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && !(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) && 1991e5c31af7Sopenharmony_ci !(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) 1992e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Format color/depth/stencil attachment feature not supported for input attachment usage"); 1993e5c31af7Sopenharmony_ci 1994e5c31af7Sopenharmony_ci const VkImageCreateInfo createImageInfo = 1995e5c31af7Sopenharmony_ci { 1996e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 1997e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1998e5c31af7Sopenharmony_ci imageCreateFlags, // VkImageCreateFlags flags; 1999e5c31af7Sopenharmony_ci imageType, // VkImageType imageType; 2000e5c31af7Sopenharmony_ci format, // VkFormat format; 2001e5c31af7Sopenharmony_ci makeExtent3D(getLayerSize(type, size)), // VkExtent3D extent; 2002e5c31af7Sopenharmony_ci levels, // deUint32 mipLevels; 2003e5c31af7Sopenharmony_ci layers, // deUint32 arrayLayers; 2004e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 2005e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 2006e5c31af7Sopenharmony_ci usageFlags, // VkImageUsageFlags usage; 2007e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 2008e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 2009e5c31af7Sopenharmony_ci DE_NULL, // const deUint32* pQueueFamilyIndices; 2010e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 2011e5c31af7Sopenharmony_ci }; 2012e5c31af7Sopenharmony_ci 2013e5c31af7Sopenharmony_ci return createImageInfo; 2014e5c31af7Sopenharmony_ci} 2015e5c31af7Sopenharmony_ci 2016e5c31af7Sopenharmony_ciVkDeviceSize GraphicsAttachmentsTestInstance::getCompressedImageData (const VkFormat format, 2017e5c31af7Sopenharmony_ci const UVec3& size, 2018e5c31af7Sopenharmony_ci std::vector<deUint8>& data, 2019e5c31af7Sopenharmony_ci const deUint32 layer, 2020e5c31af7Sopenharmony_ci const deUint32 level) 2021e5c31af7Sopenharmony_ci{ 2022e5c31af7Sopenharmony_ci VkDeviceSize sizeBytes = getCompressedImageSizeInBytes(format, size); 2023e5c31af7Sopenharmony_ci 2024e5c31af7Sopenharmony_ci data.resize((size_t)sizeBytes); 2025e5c31af7Sopenharmony_ci generateData(&data[0], data.size(), format, layer, level); 2026e5c31af7Sopenharmony_ci 2027e5c31af7Sopenharmony_ci return sizeBytes; 2028e5c31af7Sopenharmony_ci} 2029e5c31af7Sopenharmony_ci 2030e5c31af7Sopenharmony_ciVkDeviceSize GraphicsAttachmentsTestInstance::getUncompressedImageData (const VkFormat format, 2031e5c31af7Sopenharmony_ci const UVec3& size, 2032e5c31af7Sopenharmony_ci std::vector<deUint8>& data, 2033e5c31af7Sopenharmony_ci const deUint32 layer, 2034e5c31af7Sopenharmony_ci const deUint32 level) 2035e5c31af7Sopenharmony_ci{ 2036e5c31af7Sopenharmony_ci tcu::IVec3 sizeAsIVec3 = tcu::IVec3(static_cast<int>(size[0]), static_cast<int>(size[1]), static_cast<int>(size[2])); 2037e5c31af7Sopenharmony_ci VkDeviceSize sizeBytes = getImageSizeBytes(sizeAsIVec3, format); 2038e5c31af7Sopenharmony_ci 2039e5c31af7Sopenharmony_ci data.resize((size_t)sizeBytes); 2040e5c31af7Sopenharmony_ci generateData(&data[0], data.size(), format, layer, level); 2041e5c31af7Sopenharmony_ci 2042e5c31af7Sopenharmony_ci return sizeBytes; 2043e5c31af7Sopenharmony_ci} 2044e5c31af7Sopenharmony_ci 2045e5c31af7Sopenharmony_cibool GraphicsAttachmentsTestInstance::verifyDecompression (const VkCommandPool& cmdPool, 2046e5c31af7Sopenharmony_ci const std::vector<deUint8>& refCompressedData, 2047e5c31af7Sopenharmony_ci const de::MovePtr<Image>& resCompressedImage, 2048e5c31af7Sopenharmony_ci const deUint32 level, 2049e5c31af7Sopenharmony_ci const deUint32 layer, 2050e5c31af7Sopenharmony_ci const UVec3& mipmapDims) 2051e5c31af7Sopenharmony_ci{ 2052e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 2053e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 2054e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 2055e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 2056e5c31af7Sopenharmony_ci 2057e5c31af7Sopenharmony_ci const bool layoutShaderReadOnly = (layer % 2u) == 1; 2058e5c31af7Sopenharmony_ci const UVec3 mipmapDimsBlocked = getCompressedImageResolutionBlockCeil(m_parameters.formatCompressed, mipmapDims); 2059e5c31af7Sopenharmony_ci 2060e5c31af7Sopenharmony_ci const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, SINGLE_LEVEL, 0u, SINGLE_LAYER); 2061e5c31af7Sopenharmony_ci const VkImageSubresourceRange resSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, level, SINGLE_LEVEL, layer, SINGLE_LAYER); 2062e5c31af7Sopenharmony_ci 2063e5c31af7Sopenharmony_ci const VkDeviceSize dstBufferSize = getUncompressedImageSizeInBytes(m_parameters.formatForVerify, mipmapDims); 2064e5c31af7Sopenharmony_ci const VkImageUsageFlags refSrcImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; 2065e5c31af7Sopenharmony_ci 2066e5c31af7Sopenharmony_ci const VkBufferCreateInfo refSrcImageBufferInfo (makeBufferCreateInfo(refCompressedData.size(), VK_BUFFER_USAGE_TRANSFER_SRC_BIT)); 2067e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> refSrcImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, refSrcImageBufferInfo, MemoryRequirement::HostVisible)); 2068e5c31af7Sopenharmony_ci 2069e5c31af7Sopenharmony_ci const VkImageCreateFlags refSrcImageCreateFlags = 0; 2070e5c31af7Sopenharmony_ci const VkImageCreateInfo refSrcImageCreateInfo = makeCreateImageInfo(m_parameters.formatCompressed, m_parameters.imageType, mipmapDimsBlocked, refSrcImageUsageFlags, &refSrcImageCreateFlags, SINGLE_LEVEL, SINGLE_LAYER); 2071e5c31af7Sopenharmony_ci const MovePtr<Image> refSrcImage (new Image(vk, device, allocator, refSrcImageCreateInfo, MemoryRequirement::Any)); 2072e5c31af7Sopenharmony_ci Move<VkImageView> refSrcImageView (makeImageView(vk, device, refSrcImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatCompressed, subresourceRange)); 2073e5c31af7Sopenharmony_ci 2074e5c31af7Sopenharmony_ci const VkImageUsageFlags resSrcImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; 2075e5c31af7Sopenharmony_ci const VkImageViewUsageCreateInfo resSrcImageViewUsageKHR = makeImageViewUsageCreateInfo(resSrcImageUsageFlags); 2076e5c31af7Sopenharmony_ci Move<VkImageView> resSrcImageView (makeImageView(vk, device, resCompressedImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatCompressed, resSubresourceRange, &resSrcImageViewUsageKHR)); 2077e5c31af7Sopenharmony_ci 2078e5c31af7Sopenharmony_ci const VkImageCreateFlags refDstImageCreateFlags = 0; 2079e5c31af7Sopenharmony_ci const VkImageUsageFlags refDstImageUsageFlags = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 2080e5c31af7Sopenharmony_ci const VkImageCreateInfo refDstImageCreateInfo = makeCreateImageInfo(m_parameters.formatForVerify, m_parameters.imageType, mipmapDims, refDstImageUsageFlags, &refDstImageCreateFlags, SINGLE_LEVEL, SINGLE_LAYER); 2081e5c31af7Sopenharmony_ci const MovePtr<Image> refDstImage (new Image(vk, device, allocator, refDstImageCreateInfo, MemoryRequirement::Any)); 2082e5c31af7Sopenharmony_ci const Move<VkImageView> refDstImageView (makeImageView(vk, device, refDstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatForVerify, subresourceRange)); 2083e5c31af7Sopenharmony_ci const VkImageMemoryBarrier refDstInitImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, refDstImage->get(), subresourceRange); 2084e5c31af7Sopenharmony_ci const VkBufferCreateInfo refDstBufferInfo (makeBufferCreateInfo(dstBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT)); 2085e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> refDstBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, refDstBufferInfo, MemoryRequirement::HostVisible)); 2086e5c31af7Sopenharmony_ci 2087e5c31af7Sopenharmony_ci const VkImageCreateFlags resDstImageCreateFlags = 0; 2088e5c31af7Sopenharmony_ci const VkImageUsageFlags resDstImageUsageFlags = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 2089e5c31af7Sopenharmony_ci const VkImageCreateInfo resDstImageCreateInfo = makeCreateImageInfo(m_parameters.formatForVerify, m_parameters.imageType, mipmapDims, resDstImageUsageFlags, &resDstImageCreateFlags, SINGLE_LEVEL, SINGLE_LAYER); 2090e5c31af7Sopenharmony_ci const MovePtr<Image> resDstImage (new Image(vk, device, allocator, resDstImageCreateInfo, MemoryRequirement::Any)); 2091e5c31af7Sopenharmony_ci const Move<VkImageView> resDstImageView (makeImageView(vk, device, resDstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatForVerify, subresourceRange)); 2092e5c31af7Sopenharmony_ci const VkImageMemoryBarrier resDstInitImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, resDstImage->get(), subresourceRange); 2093e5c31af7Sopenharmony_ci const VkBufferCreateInfo resDstBufferInfo (makeBufferCreateInfo(dstBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT)); 2094e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> resDstBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, resDstBufferInfo, MemoryRequirement::HostVisible)); 2095e5c31af7Sopenharmony_ci 2096e5c31af7Sopenharmony_ci const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0)); 2097e5c31af7Sopenharmony_ci const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("frag_verify"), 0)); 2098e5c31af7Sopenharmony_ci 2099e5c31af7Sopenharmony_ci const Unique<VkRenderPass> renderPass (vk::makeRenderPass(vk, device)); 2100e5c31af7Sopenharmony_ci 2101e5c31af7Sopenharmony_ci const Move<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder() 2102e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT) 2103e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT) 2104e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT) 2105e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT) 2106e5c31af7Sopenharmony_ci .build(vk, device)); 2107e5c31af7Sopenharmony_ci const Move<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder() 2108e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) 2109e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) 2110e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) 2111e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) 2112e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u)); 2113e5c31af7Sopenharmony_ci const Move<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout)); 2114e5c31af7Sopenharmony_ci const VkSamplerCreateInfo refSrcSamplerInfo (makeSamplerCreateInfo()); 2115e5c31af7Sopenharmony_ci const Move<VkSampler> refSrcSampler = vk::createSampler(vk, device, &refSrcSamplerInfo); 2116e5c31af7Sopenharmony_ci const VkSamplerCreateInfo resSrcSamplerInfo (makeSamplerCreateInfo()); 2117e5c31af7Sopenharmony_ci const Move<VkSampler> resSrcSampler = vk::createSampler(vk, device, &resSrcSamplerInfo); 2118e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorRefSrcImage (makeDescriptorImageInfo(*refSrcSampler, *refSrcImageView, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL)); 2119e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorResSrcImage (makeDescriptorImageInfo(*resSrcSampler, *resSrcImageView, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL)); 2120e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorRefDstImage (makeDescriptorImageInfo(DE_NULL, *refDstImageView, VK_IMAGE_LAYOUT_GENERAL)); 2121e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorResDstImage (makeDescriptorImageInfo(DE_NULL, *resDstImageView, VK_IMAGE_LAYOUT_GENERAL)); 2122e5c31af7Sopenharmony_ci 2123e5c31af7Sopenharmony_ci const VkExtent2D renderSize (makeExtent2D(mipmapDims.x(), mipmapDims.y())); 2124e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, *descriptorSetLayout)); 2125e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, device, *pipelineLayout, *renderPass, *vertShaderModule, *fragShaderModule, renderSize, 0u)); 2126e5c31af7Sopenharmony_ci 2127e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 2128e5c31af7Sopenharmony_ci 2129e5c31af7Sopenharmony_ci const VkBufferImageCopy copyBufferToImageRegion = makeBufferImageCopy(mipmapDimsBlocked.x(), mipmapDimsBlocked.y(), 0u, 0u, mipmapDimsBlocked.x(), mipmapDimsBlocked.y()); 2130e5c31af7Sopenharmony_ci const VkBufferImageCopy copyRegion = makeBufferImageCopy(mipmapDims.x(), mipmapDims.y(), 0u, 0u); 2131e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier refSrcCopyBufferBarrierPre = makeBufferMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, refSrcImageBuffer->get(), 0ull, refCompressedData.size()); 2132e5c31af7Sopenharmony_ci const VkImageMemoryBarrier refSrcCopyImageBarrierPre = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, refSrcImage->get(), subresourceRange); 2133e5c31af7Sopenharmony_ci const VkImageMemoryBarrier refSrcCopyImageBarrierPost = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, refSrcImage->get(), subresourceRange); 2134e5c31af7Sopenharmony_ci const VkImageMemoryBarrier resCompressedImageBarrier = makeImageMemoryBarrier(0, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_GENERAL, layoutShaderReadOnly ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL, resCompressedImage->get(), resSubresourceRange); 2135e5c31af7Sopenharmony_ci 2136e5c31af7Sopenharmony_ci const Move<VkFramebuffer> framebuffer (makeFramebuffer(vk, device, *renderPass, 0, DE_NULL, renderSize.width, renderSize.height, getLayerCount())); 2137e5c31af7Sopenharmony_ci 2138e5c31af7Sopenharmony_ci // Upload source image data 2139e5c31af7Sopenharmony_ci { 2140e5c31af7Sopenharmony_ci const Allocation& refSrcImageBufferAlloc = refSrcImageBuffer->getAllocation(); 2141e5c31af7Sopenharmony_ci deMemcpy(refSrcImageBufferAlloc.getHostPtr(), &refCompressedData[0], refCompressedData.size()); 2142e5c31af7Sopenharmony_ci flushAlloc(vk, device, refSrcImageBufferAlloc); 2143e5c31af7Sopenharmony_ci } 2144e5c31af7Sopenharmony_ci 2145e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer); 2146e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 2147e5c31af7Sopenharmony_ci 2148e5c31af7Sopenharmony_ci // Copy buffer to image 2149e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &refSrcCopyBufferBarrierPre, 1u, &refSrcCopyImageBarrierPre); 2150e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(*cmdBuffer, refSrcImageBuffer->get(), refSrcImage->get(), VK_IMAGE_LAYOUT_GENERAL, 1u, ©BufferToImageRegion); 2151e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, DE_NULL, 1u, &refSrcCopyImageBarrierPost); 2152e5c31af7Sopenharmony_ci 2153e5c31af7Sopenharmony_ci // Make reference and result images readable 2154e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &refDstInitImageBarrier); 2155e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &resDstInitImageBarrier); 2156e5c31af7Sopenharmony_ci { 2157e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &resCompressedImageBarrier); 2158e5c31af7Sopenharmony_ci } 2159e5c31af7Sopenharmony_ci 2160e5c31af7Sopenharmony_ci beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderSize); 2161e5c31af7Sopenharmony_ci { 2162e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 2163e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorRefSrcImage) 2164e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorResSrcImage) 2165e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(2u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorRefDstImage) 2166e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(3u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorResDstImage) 2167e5c31af7Sopenharmony_ci .update(vk, device); 2168e5c31af7Sopenharmony_ci 2169e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 2170e5c31af7Sopenharmony_ci vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &m_vertexBuffer->get(), &m_vertexBufferOffset); 2171e5c31af7Sopenharmony_ci vk.cmdDraw(*cmdBuffer, m_vertexCount, 1, 0, 0); 2172e5c31af7Sopenharmony_ci } 2173e5c31af7Sopenharmony_ci endRenderPass(vk, *cmdBuffer); 2174e5c31af7Sopenharmony_ci 2175e5c31af7Sopenharmony_ci // Decompress reference image 2176e5c31af7Sopenharmony_ci { 2177e5c31af7Sopenharmony_ci const VkImageMemoryBarrier refDstImageBarrier = makeImageMemoryBarrier( 2178e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 2179e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 2180e5c31af7Sopenharmony_ci refDstImage->get(), subresourceRange); 2181e5c31af7Sopenharmony_ci 2182e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier refDstBufferBarrier = makeBufferMemoryBarrier( 2183e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 2184e5c31af7Sopenharmony_ci refDstBuffer->get(), 0ull, dstBufferSize); 2185e5c31af7Sopenharmony_ci 2186e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &refDstImageBarrier); 2187e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, refDstImage->get(), VK_IMAGE_LAYOUT_GENERAL, refDstBuffer->get(), 1u, ©Region); 2188e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &refDstBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 2189e5c31af7Sopenharmony_ci } 2190e5c31af7Sopenharmony_ci 2191e5c31af7Sopenharmony_ci // Decompress result image 2192e5c31af7Sopenharmony_ci { 2193e5c31af7Sopenharmony_ci const VkImageMemoryBarrier resDstImageBarrier = makeImageMemoryBarrier( 2194e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 2195e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 2196e5c31af7Sopenharmony_ci resDstImage->get(), subresourceRange); 2197e5c31af7Sopenharmony_ci 2198e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier resDstBufferBarrier = makeBufferMemoryBarrier( 2199e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 2200e5c31af7Sopenharmony_ci resDstBuffer->get(), 0ull, dstBufferSize); 2201e5c31af7Sopenharmony_ci 2202e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &resDstImageBarrier); 2203e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, resDstImage->get(), VK_IMAGE_LAYOUT_GENERAL, resDstBuffer->get(), 1u, ©Region); 2204e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &resDstBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 2205e5c31af7Sopenharmony_ci } 2206e5c31af7Sopenharmony_ci 2207e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 2208e5c31af7Sopenharmony_ci 2209e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, *cmdBuffer); 2210e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 2211e5c31af7Sopenharmony_ci 2212e5c31af7Sopenharmony_ci // Compare decompressed pixel data in reference and result images 2213e5c31af7Sopenharmony_ci { 2214e5c31af7Sopenharmony_ci const Allocation& refDstBufferAlloc = refDstBuffer->getAllocation(); 2215e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, refDstBufferAlloc); 2216e5c31af7Sopenharmony_ci 2217e5c31af7Sopenharmony_ci const Allocation& resDstBufferAlloc = resDstBuffer->getAllocation(); 2218e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, resDstBufferAlloc); 2219e5c31af7Sopenharmony_ci 2220e5c31af7Sopenharmony_ci BinaryCompareMode compareMode = 2221e5c31af7Sopenharmony_ci (m_parameters.formatIsASTC) 2222e5c31af7Sopenharmony_ci ?(COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING) 2223e5c31af7Sopenharmony_ci :(COMPARE_MODE_NORMAL); 2224e5c31af7Sopenharmony_ci 2225e5c31af7Sopenharmony_ci BinaryCompareResult res = BinaryCompare(refDstBufferAlloc.getHostPtr(), 2226e5c31af7Sopenharmony_ci resDstBufferAlloc.getHostPtr(), 2227e5c31af7Sopenharmony_ci dstBufferSize, 2228e5c31af7Sopenharmony_ci m_parameters.formatForVerify, 2229e5c31af7Sopenharmony_ci compareMode); 2230e5c31af7Sopenharmony_ci 2231e5c31af7Sopenharmony_ci if (res == COMPARE_RESULT_FAILED) 2232e5c31af7Sopenharmony_ci { 2233e5c31af7Sopenharmony_ci // Do fuzzy to log error mask 2234e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, resDstBufferAlloc); 2235e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, refDstBufferAlloc); 2236e5c31af7Sopenharmony_ci 2237e5c31af7Sopenharmony_ci tcu::ConstPixelBufferAccess resPixels (mapVkFormat(m_parameters.formatForVerify), renderSize.width, renderSize.height, 1u, resDstBufferAlloc.getHostPtr()); 2238e5c31af7Sopenharmony_ci tcu::ConstPixelBufferAccess refPixels (mapVkFormat(m_parameters.formatForVerify), renderSize.width, renderSize.height, 1u, refDstBufferAlloc.getHostPtr()); 2239e5c31af7Sopenharmony_ci 2240e5c31af7Sopenharmony_ci string comment = string("Image Comparison (level=") + de::toString(level) + string(", layer=") + de::toString(layer) + string(")"); 2241e5c31af7Sopenharmony_ci 2242e5c31af7Sopenharmony_ci if (isWriteToCompressedOperation()) 2243e5c31af7Sopenharmony_ci tcu::fuzzyCompare(m_context.getTestContext().getLog(), "ImageComparison", comment.c_str(), refPixels, resPixels, 0.001f, tcu::COMPARE_LOG_EVERYTHING); 2244e5c31af7Sopenharmony_ci else 2245e5c31af7Sopenharmony_ci tcu::fuzzyCompare(m_context.getTestContext().getLog(), "ImageComparison", comment.c_str(), resPixels, refPixels, 0.001f, tcu::COMPARE_LOG_EVERYTHING); 2246e5c31af7Sopenharmony_ci 2247e5c31af7Sopenharmony_ci return false; 2248e5c31af7Sopenharmony_ci } 2249e5c31af7Sopenharmony_ci else if (res == COMPARE_RESULT_ASTC_QUALITY_WARNING) 2250e5c31af7Sopenharmony_ci { 2251e5c31af7Sopenharmony_ci m_bASTCErrorColourMismatch = true; 2252e5c31af7Sopenharmony_ci } 2253e5c31af7Sopenharmony_ci } 2254e5c31af7Sopenharmony_ci 2255e5c31af7Sopenharmony_ci return true; 2256e5c31af7Sopenharmony_ci} 2257e5c31af7Sopenharmony_ci 2258e5c31af7Sopenharmony_ci 2259e5c31af7Sopenharmony_ciclass GraphicsTextureTestInstance : public GraphicsAttachmentsTestInstance 2260e5c31af7Sopenharmony_ci{ 2261e5c31af7Sopenharmony_cipublic: 2262e5c31af7Sopenharmony_ci GraphicsTextureTestInstance (Context& context, const TestParameters& parameters); 2263e5c31af7Sopenharmony_ci 2264e5c31af7Sopenharmony_ciprotected: 2265e5c31af7Sopenharmony_ci virtual bool isWriteToCompressedOperation (); 2266e5c31af7Sopenharmony_ci virtual void transcodeRead (const VkCommandPool& cmdPool); 2267e5c31af7Sopenharmony_ci virtual void transcodeWrite (const VkCommandPool& cmdPool); 2268e5c31af7Sopenharmony_ci}; 2269e5c31af7Sopenharmony_ci 2270e5c31af7Sopenharmony_ciGraphicsTextureTestInstance::GraphicsTextureTestInstance (Context& context, const TestParameters& parameters) 2271e5c31af7Sopenharmony_ci : GraphicsAttachmentsTestInstance(context, parameters) 2272e5c31af7Sopenharmony_ci{ 2273e5c31af7Sopenharmony_ci} 2274e5c31af7Sopenharmony_ci 2275e5c31af7Sopenharmony_cibool GraphicsTextureTestInstance::isWriteToCompressedOperation () 2276e5c31af7Sopenharmony_ci{ 2277e5c31af7Sopenharmony_ci return (m_parameters.operation == OPERATION_TEXTURE_WRITE); 2278e5c31af7Sopenharmony_ci} 2279e5c31af7Sopenharmony_ci 2280e5c31af7Sopenharmony_civoid GraphicsTextureTestInstance::transcodeRead (const VkCommandPool& cmdPool) 2281e5c31af7Sopenharmony_ci{ 2282e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 2283e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 2284e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 2285e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 2286e5c31af7Sopenharmony_ci 2287e5c31af7Sopenharmony_ci const VkImageCreateFlags* imgCreateFlagsOverride = DE_NULL; 2288e5c31af7Sopenharmony_ci 2289e5c31af7Sopenharmony_ci const VkImageCreateInfo srcImageCreateInfo = makeCreateImageInfo(m_srcFormat, m_parameters.imageType, m_srcImageResolutions[0], m_srcImageUsageFlags, imgCreateFlagsOverride, getLevelCount(), getLayerCount()); 2290e5c31af7Sopenharmony_ci MovePtr<Image> srcImage (new Image(vk, device, allocator, srcImageCreateInfo, MemoryRequirement::Any)); 2291e5c31af7Sopenharmony_ci 2292e5c31af7Sopenharmony_ci const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0)); 2293e5c31af7Sopenharmony_ci const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0)); 2294e5c31af7Sopenharmony_ci 2295e5c31af7Sopenharmony_ci const Unique<VkRenderPass> renderPass (vk::makeRenderPass(vk, device)); 2296e5c31af7Sopenharmony_ci 2297e5c31af7Sopenharmony_ci const Move<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder() 2298e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT) 2299e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT) 2300e5c31af7Sopenharmony_ci .build(vk, device)); 2301e5c31af7Sopenharmony_ci const Move<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder() 2302e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) 2303e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) 2304e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u)); 2305e5c31af7Sopenharmony_ci const Move<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout)); 2306e5c31af7Sopenharmony_ci 2307e5c31af7Sopenharmony_ci const VkExtent2D renderSizeUnused (makeExtent2D(1u, 1u)); 2308e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, *descriptorSetLayout)); 2309e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, device, *pipelineLayout, *renderPass, *vertShaderModule, *fragShaderModule, renderSizeUnused, 0u, true)); 2310e5c31af7Sopenharmony_ci 2311e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 2312e5c31af7Sopenharmony_ci 2313e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 2314e5c31af7Sopenharmony_ci { 2315e5c31af7Sopenharmony_ci const UVec3& uncompressedImageRes = m_uncompressedImageResVec[levelNdx]; 2316e5c31af7Sopenharmony_ci const UVec3& srcImageResolution = m_srcImageResolutions[levelNdx]; 2317e5c31af7Sopenharmony_ci const UVec3& dstImageResolution = m_dstImageResolutions[levelNdx]; 2318e5c31af7Sopenharmony_ci const size_t srcImageSizeInBytes = m_srcData[levelNdx][0]->size(); 2319e5c31af7Sopenharmony_ci const size_t dstImageSizeInBytes = m_dstData[levelNdx][0]->size(); 2320e5c31af7Sopenharmony_ci const UVec3 srcImageResBlocked = getCompressedImageResolutionBlockCeil(m_parameters.formatCompressed, srcImageResolution); 2321e5c31af7Sopenharmony_ci 2322e5c31af7Sopenharmony_ci const VkImageCreateInfo dstImageCreateInfo = makeCreateImageInfo(m_dstFormat, m_parameters.imageType, dstImageResolution, m_dstImageUsageFlags, imgCreateFlagsOverride, SINGLE_LEVEL, SINGLE_LAYER); 2323e5c31af7Sopenharmony_ci 2324e5c31af7Sopenharmony_ci const VkBufferCreateInfo srcImageBufferInfo = makeBufferCreateInfo(srcImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); 2325e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> srcImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, srcImageBufferInfo, MemoryRequirement::HostVisible)); 2326e5c31af7Sopenharmony_ci 2327e5c31af7Sopenharmony_ci const VkBufferCreateInfo dstImageBufferInfo = makeBufferCreateInfo(dstImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 2328e5c31af7Sopenharmony_ci MovePtr<BufferWithMemory> dstImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, dstImageBufferInfo, MemoryRequirement::HostVisible)); 2329e5c31af7Sopenharmony_ci 2330e5c31af7Sopenharmony_ci const VkExtent2D renderSize (makeExtent2D(uncompressedImageRes.x(), uncompressedImageRes.y())); 2331e5c31af7Sopenharmony_ci const VkViewport viewport = makeViewport(renderSize); 2332e5c31af7Sopenharmony_ci const VkRect2D scissor = makeRect2D(renderSize); 2333e5c31af7Sopenharmony_ci 2334e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 2335e5c31af7Sopenharmony_ci { 2336e5c31af7Sopenharmony_ci const VkImageSubresourceRange srcSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, SINGLE_LEVEL, layerNdx, SINGLE_LAYER); 2337e5c31af7Sopenharmony_ci const VkImageSubresourceRange dstSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, SINGLE_LEVEL, 0u, SINGLE_LAYER); 2338e5c31af7Sopenharmony_ci 2339e5c31af7Sopenharmony_ci Move<VkImageView> srcImageView (makeImageView(vk, device, srcImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, srcSubresourceRange, m_srcImageViewUsageKHR)); 2340e5c31af7Sopenharmony_ci 2341e5c31af7Sopenharmony_ci de::MovePtr<Image> dstImage (new Image(vk, device, allocator, dstImageCreateInfo, MemoryRequirement::Any)); 2342e5c31af7Sopenharmony_ci Move<VkImageView> dstImageView (makeImageView(vk, device, dstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, dstSubresourceRange, m_dstImageViewUsageKHR)); 2343e5c31af7Sopenharmony_ci 2344e5c31af7Sopenharmony_ci const VkSamplerCreateInfo srcSamplerInfo (makeSamplerCreateInfo()); 2345e5c31af7Sopenharmony_ci const Move<VkSampler> srcSampler = vk::createSampler(vk, device, &srcSamplerInfo); 2346e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorSrcImage (makeDescriptorImageInfo(*srcSampler, *srcImageView, VK_IMAGE_LAYOUT_GENERAL)); 2347e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorDstImage (makeDescriptorImageInfo(DE_NULL, *dstImageView, VK_IMAGE_LAYOUT_GENERAL)); 2348e5c31af7Sopenharmony_ci 2349e5c31af7Sopenharmony_ci const VkBufferImageCopy srcCopyRegion = makeBufferImageCopy(srcImageResolution.x(), srcImageResolution.y(), levelNdx, layerNdx, srcImageResBlocked.x(), srcImageResBlocked.y()); 2350e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier srcCopyBufferBarrierPre = makeBufferMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, srcImageBuffer->get(), 0ull, srcImageSizeInBytes); 2351e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPre = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, srcImage->get(), srcSubresourceRange); 2352e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPost = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, srcImage->get(), srcSubresourceRange); 2353e5c31af7Sopenharmony_ci const VkBufferImageCopy dstCopyRegion = makeBufferImageCopy(dstImageResolution.x(), dstImageResolution.y()); 2354e5c31af7Sopenharmony_ci const VkImageMemoryBarrier dstInitImageBarrier = makeImageMemoryBarrier(0u, (VK_ACCESS_SHADER_READ_BIT|VK_ACCESS_SHADER_WRITE_BIT), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, dstImage->get(), dstSubresourceRange); 2355e5c31af7Sopenharmony_ci 2356e5c31af7Sopenharmony_ci const VkExtent2D framebufferSize (makeExtent2D(dstImageResolution[0], dstImageResolution[1])); 2357e5c31af7Sopenharmony_ci const Move<VkFramebuffer> framebuffer (makeFramebuffer(vk, device, *renderPass, 0, DE_NULL, framebufferSize.width, framebufferSize.height, SINGLE_LAYER)); 2358e5c31af7Sopenharmony_ci 2359e5c31af7Sopenharmony_ci // Upload source image data 2360e5c31af7Sopenharmony_ci const Allocation& alloc = srcImageBuffer->getAllocation(); 2361e5c31af7Sopenharmony_ci deMemcpy(alloc.getHostPtr(), &m_srcData[levelNdx][layerNdx]->at(0), srcImageSizeInBytes); 2362e5c31af7Sopenharmony_ci flushAlloc(vk, device, alloc); 2363e5c31af7Sopenharmony_ci 2364e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer); 2365e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 2366e5c31af7Sopenharmony_ci 2367e5c31af7Sopenharmony_ci // Copy buffer to image 2368e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &srcCopyBufferBarrierPre, 1u, &srcCopyImageBarrierPre); 2369e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(*cmdBuffer, srcImageBuffer->get(), srcImage->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &srcCopyRegion); 2370e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &srcCopyImageBarrierPost); 2371e5c31af7Sopenharmony_ci 2372e5c31af7Sopenharmony_ci // Define destination image layout 2373e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &dstInitImageBarrier); 2374e5c31af7Sopenharmony_ci 2375e5c31af7Sopenharmony_ci beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderSize); 2376e5c31af7Sopenharmony_ci 2377e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 2378e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorSrcImage) 2379e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorDstImage) 2380e5c31af7Sopenharmony_ci .update(vk, device); 2381e5c31af7Sopenharmony_ci 2382e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 2383e5c31af7Sopenharmony_ci vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &m_vertexBuffer->get(), &m_vertexBufferOffset); 2384e5c31af7Sopenharmony_ci 2385e5c31af7Sopenharmony_ci vk.cmdSetViewport(*cmdBuffer, 0u, 1u, &viewport); 2386e5c31af7Sopenharmony_ci vk.cmdSetScissor(*cmdBuffer, 0u, 1u, &scissor); 2387e5c31af7Sopenharmony_ci 2388e5c31af7Sopenharmony_ci vk.cmdDraw(*cmdBuffer, (deUint32)m_vertexCount, 1, 0, 0); 2389e5c31af7Sopenharmony_ci 2390e5c31af7Sopenharmony_ci endRenderPass(vk, *cmdBuffer); 2391e5c31af7Sopenharmony_ci 2392e5c31af7Sopenharmony_ci const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier( 2393e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 2394e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 2395e5c31af7Sopenharmony_ci dstImage->get(), dstSubresourceRange); 2396e5c31af7Sopenharmony_ci 2397e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier( 2398e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 2399e5c31af7Sopenharmony_ci dstImageBuffer->get(), 0ull, dstImageSizeInBytes); 2400e5c31af7Sopenharmony_ci 2401e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &prepareForTransferBarrier); 2402e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, dstImage->get(), VK_IMAGE_LAYOUT_GENERAL, dstImageBuffer->get(), 1u, &dstCopyRegion); 2403e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©Barrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 2404e5c31af7Sopenharmony_ci 2405e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 2406e5c31af7Sopenharmony_ci 2407e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, *cmdBuffer); 2408e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 2409e5c31af7Sopenharmony_ci 2410e5c31af7Sopenharmony_ci const Allocation& dstImageBufferAlloc = dstImageBuffer->getAllocation(); 2411e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, dstImageBufferAlloc); 2412e5c31af7Sopenharmony_ci deMemcpy(&m_dstData[levelNdx][layerNdx]->at(0), dstImageBufferAlloc.getHostPtr(), dstImageSizeInBytes); 2413e5c31af7Sopenharmony_ci } 2414e5c31af7Sopenharmony_ci } 2415e5c31af7Sopenharmony_ci 2416e5c31af7Sopenharmony_ci m_compressedImage = srcImage; 2417e5c31af7Sopenharmony_ci} 2418e5c31af7Sopenharmony_ci 2419e5c31af7Sopenharmony_civoid GraphicsTextureTestInstance::transcodeWrite (const VkCommandPool& cmdPool) 2420e5c31af7Sopenharmony_ci{ 2421e5c31af7Sopenharmony_ci const DeviceInterface& vk = m_context.getDeviceInterface(); 2422e5c31af7Sopenharmony_ci const VkDevice device = m_context.getDevice(); 2423e5c31af7Sopenharmony_ci const VkQueue queue = m_context.getUniversalQueue(); 2424e5c31af7Sopenharmony_ci Allocator& allocator = m_context.getDefaultAllocator(); 2425e5c31af7Sopenharmony_ci 2426e5c31af7Sopenharmony_ci const VkImageCreateFlags* imgCreateFlagsOverride = DE_NULL; 2427e5c31af7Sopenharmony_ci 2428e5c31af7Sopenharmony_ci const VkImageCreateInfo dstImageCreateInfo = makeCreateImageInfo(m_dstFormat, m_parameters.imageType, m_dstImageResolutions[0], m_dstImageUsageFlags, imgCreateFlagsOverride, getLevelCount(), getLayerCount()); 2429e5c31af7Sopenharmony_ci MovePtr<Image> dstImage (new Image(vk, device, allocator, dstImageCreateInfo, MemoryRequirement::Any)); 2430e5c31af7Sopenharmony_ci 2431e5c31af7Sopenharmony_ci const Unique<VkShaderModule> vertShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0)); 2432e5c31af7Sopenharmony_ci const Unique<VkShaderModule> fragShaderModule (createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0)); 2433e5c31af7Sopenharmony_ci 2434e5c31af7Sopenharmony_ci const Unique<VkRenderPass> renderPass (vk::makeRenderPass(vk, device)); 2435e5c31af7Sopenharmony_ci 2436e5c31af7Sopenharmony_ci const Move<VkDescriptorSetLayout> descriptorSetLayout (DescriptorSetLayoutBuilder() 2437e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT) 2438e5c31af7Sopenharmony_ci .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_FRAGMENT_BIT) 2439e5c31af7Sopenharmony_ci .build(vk, device)); 2440e5c31af7Sopenharmony_ci const Move<VkDescriptorPool> descriptorPool (DescriptorPoolBuilder() 2441e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) 2442e5c31af7Sopenharmony_ci .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) 2443e5c31af7Sopenharmony_ci .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u)); 2444e5c31af7Sopenharmony_ci const Move<VkDescriptorSet> descriptorSet (makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout)); 2445e5c31af7Sopenharmony_ci 2446e5c31af7Sopenharmony_ci const VkExtent2D renderSizeUnused (makeExtent2D(1u, 1u)); 2447e5c31af7Sopenharmony_ci const Unique<VkPipelineLayout> pipelineLayout (makePipelineLayout(vk, device, *descriptorSetLayout)); 2448e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (makeGraphicsPipeline(vk, device, *pipelineLayout, *renderPass, *vertShaderModule, *fragShaderModule, renderSizeUnused, 0u, true)); 2449e5c31af7Sopenharmony_ci 2450e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, device, cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 2451e5c31af7Sopenharmony_ci 2452e5c31af7Sopenharmony_ci for (deUint32 levelNdx = 0; levelNdx < getLevelCount(); ++levelNdx) 2453e5c31af7Sopenharmony_ci { 2454e5c31af7Sopenharmony_ci const UVec3& uncompressedImageRes = m_uncompressedImageResVec[levelNdx]; 2455e5c31af7Sopenharmony_ci const UVec3& srcImageResolution = m_srcImageResolutions[levelNdx]; 2456e5c31af7Sopenharmony_ci const UVec3& dstImageResolution = m_dstImageResolutions[levelNdx]; 2457e5c31af7Sopenharmony_ci const size_t srcImageSizeInBytes = m_srcData[levelNdx][0]->size(); 2458e5c31af7Sopenharmony_ci const size_t dstImageSizeInBytes = m_dstData[levelNdx][0]->size(); 2459e5c31af7Sopenharmony_ci const UVec3 dstImageResBlocked = getCompressedImageResolutionBlockCeil(m_parameters.formatCompressed, dstImageResolution); 2460e5c31af7Sopenharmony_ci 2461e5c31af7Sopenharmony_ci const VkImageCreateInfo srcImageCreateInfo = makeCreateImageInfo(m_srcFormat, m_parameters.imageType, srcImageResolution, m_srcImageUsageFlags, imgCreateFlagsOverride, SINGLE_LEVEL, SINGLE_LAYER); 2462e5c31af7Sopenharmony_ci 2463e5c31af7Sopenharmony_ci const VkExtent2D renderSize (makeExtent2D(uncompressedImageRes.x(), uncompressedImageRes.y())); 2464e5c31af7Sopenharmony_ci const VkViewport viewport = makeViewport(renderSize); 2465e5c31af7Sopenharmony_ci const VkRect2D scissor = makeRect2D(renderSize); 2466e5c31af7Sopenharmony_ci 2467e5c31af7Sopenharmony_ci for (deUint32 layerNdx = 0; layerNdx < getLayerCount(); ++layerNdx) 2468e5c31af7Sopenharmony_ci { 2469e5c31af7Sopenharmony_ci const VkBufferCreateInfo srcImageBufferInfo = makeBufferCreateInfo(srcImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); 2470e5c31af7Sopenharmony_ci const MovePtr<BufferWithMemory> srcImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, srcImageBufferInfo, MemoryRequirement::HostVisible)); 2471e5c31af7Sopenharmony_ci 2472e5c31af7Sopenharmony_ci const VkBufferCreateInfo dstImageBufferInfo = makeBufferCreateInfo(dstImageSizeInBytes, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 2473e5c31af7Sopenharmony_ci MovePtr<BufferWithMemory> dstImageBuffer = MovePtr<BufferWithMemory>(new BufferWithMemory(vk, device, allocator, dstImageBufferInfo, MemoryRequirement::HostVisible)); 2474e5c31af7Sopenharmony_ci 2475e5c31af7Sopenharmony_ci const VkImageSubresourceRange srcSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, SINGLE_LEVEL, 0u, SINGLE_LAYER); 2476e5c31af7Sopenharmony_ci const VkImageSubresourceRange dstSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, SINGLE_LEVEL, layerNdx, SINGLE_LAYER); 2477e5c31af7Sopenharmony_ci 2478e5c31af7Sopenharmony_ci Move<VkImageView> dstImageView (makeImageView(vk, device, dstImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, dstSubresourceRange, m_dstImageViewUsageKHR)); 2479e5c31af7Sopenharmony_ci 2480e5c31af7Sopenharmony_ci de::MovePtr<Image> srcImage (new Image(vk, device, allocator, srcImageCreateInfo, MemoryRequirement::Any)); 2481e5c31af7Sopenharmony_ci Move<VkImageView> srcImageView (makeImageView(vk, device, srcImage->get(), mapImageViewType(m_parameters.imageType), m_parameters.formatUncompressed, srcSubresourceRange, m_srcImageViewUsageKHR)); 2482e5c31af7Sopenharmony_ci 2483e5c31af7Sopenharmony_ci const VkSamplerCreateInfo srcSamplerInfo (makeSamplerCreateInfo()); 2484e5c31af7Sopenharmony_ci const Move<VkSampler> srcSampler = vk::createSampler(vk, device, &srcSamplerInfo); 2485e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorSrcImage (makeDescriptorImageInfo(*srcSampler, *srcImageView, VK_IMAGE_LAYOUT_GENERAL)); 2486e5c31af7Sopenharmony_ci const VkDescriptorImageInfo descriptorDstImage (makeDescriptorImageInfo(DE_NULL, *dstImageView, VK_IMAGE_LAYOUT_GENERAL)); 2487e5c31af7Sopenharmony_ci 2488e5c31af7Sopenharmony_ci const VkBufferImageCopy srcCopyRegion = makeBufferImageCopy(srcImageResolution.x(), srcImageResolution.y(), 0u, 0u); 2489e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier srcCopyBufferBarrierPre = makeBufferMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, srcImageBuffer->get(), 0ull, srcImageSizeInBytes); 2490e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPre = makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, srcImage->get(), srcSubresourceRange); 2491e5c31af7Sopenharmony_ci const VkImageMemoryBarrier srcCopyImageBarrierPost = makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, srcImage->get(), srcSubresourceRange); 2492e5c31af7Sopenharmony_ci const VkBufferImageCopy dstCopyRegion = makeBufferImageCopy(dstImageResolution.x(), dstImageResolution.y(), levelNdx, layerNdx, dstImageResBlocked.x(), dstImageResBlocked.y()); 2493e5c31af7Sopenharmony_ci const VkImageMemoryBarrier dstInitImageBarrier = makeImageMemoryBarrier(0u, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL, dstImage->get(), dstSubresourceRange); 2494e5c31af7Sopenharmony_ci 2495e5c31af7Sopenharmony_ci const VkExtent2D framebufferSize (makeExtent2D(dstImageResolution[0], dstImageResolution[1])); 2496e5c31af7Sopenharmony_ci const Move<VkFramebuffer> framebuffer (makeFramebuffer(vk, device, *renderPass, 0, DE_NULL, framebufferSize.width, framebufferSize.height, SINGLE_LAYER)); 2497e5c31af7Sopenharmony_ci 2498e5c31af7Sopenharmony_ci // Upload source image data 2499e5c31af7Sopenharmony_ci const Allocation& alloc = srcImageBuffer->getAllocation(); 2500e5c31af7Sopenharmony_ci deMemcpy(alloc.getHostPtr(), &m_srcData[levelNdx][layerNdx]->at(0), srcImageSizeInBytes); 2501e5c31af7Sopenharmony_ci flushAlloc(vk, device, alloc); 2502e5c31af7Sopenharmony_ci 2503e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer); 2504e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline); 2505e5c31af7Sopenharmony_ci 2506e5c31af7Sopenharmony_ci // Copy buffer to image 2507e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1u, &srcCopyBufferBarrierPre, 1u, &srcCopyImageBarrierPre); 2508e5c31af7Sopenharmony_ci vk.cmdCopyBufferToImage(*cmdBuffer, srcImageBuffer->get(), srcImage->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &srcCopyRegion); 2509e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &srcCopyImageBarrierPost); 2510e5c31af7Sopenharmony_ci 2511e5c31af7Sopenharmony_ci // Define destination image layout 2512e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0u, DE_NULL, 1u, &dstInitImageBarrier); 2513e5c31af7Sopenharmony_ci 2514e5c31af7Sopenharmony_ci beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer, renderSize); 2515e5c31af7Sopenharmony_ci 2516e5c31af7Sopenharmony_ci DescriptorSetUpdateBuilder() 2517e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, &descriptorSrcImage) 2518e5c31af7Sopenharmony_ci .writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorDstImage) 2519e5c31af7Sopenharmony_ci .update(vk, device); 2520e5c31af7Sopenharmony_ci 2521e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *pipelineLayout, 0u, 1u, &descriptorSet.get(), 0u, DE_NULL); 2522e5c31af7Sopenharmony_ci vk.cmdBindVertexBuffers(*cmdBuffer, 0u, 1u, &m_vertexBuffer->get(), &m_vertexBufferOffset); 2523e5c31af7Sopenharmony_ci 2524e5c31af7Sopenharmony_ci vk.cmdSetViewport(*cmdBuffer, 0u, 1u, &viewport); 2525e5c31af7Sopenharmony_ci vk.cmdSetScissor(*cmdBuffer, 0u, 1u, &scissor); 2526e5c31af7Sopenharmony_ci 2527e5c31af7Sopenharmony_ci vk.cmdDraw(*cmdBuffer, (deUint32)m_vertexCount, 1, 0, 0); 2528e5c31af7Sopenharmony_ci 2529e5c31af7Sopenharmony_ci endRenderPass(vk, *cmdBuffer); 2530e5c31af7Sopenharmony_ci 2531e5c31af7Sopenharmony_ci const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier( 2532e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, 2533e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL, 2534e5c31af7Sopenharmony_ci dstImage->get(), dstSubresourceRange); 2535e5c31af7Sopenharmony_ci 2536e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier( 2537e5c31af7Sopenharmony_ci VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT, 2538e5c31af7Sopenharmony_ci dstImageBuffer->get(), 0ull, dstImageSizeInBytes); 2539e5c31af7Sopenharmony_ci 2540e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &prepareForTransferBarrier); 2541e5c31af7Sopenharmony_ci vk.cmdCopyImageToBuffer(*cmdBuffer, dstImage->get(), VK_IMAGE_LAYOUT_GENERAL, dstImageBuffer->get(), 1u, &dstCopyRegion); 2542e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, ©Barrier, 0, (const VkImageMemoryBarrier*)DE_NULL); 2543e5c31af7Sopenharmony_ci 2544e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 2545e5c31af7Sopenharmony_ci 2546e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, *cmdBuffer); 2547e5c31af7Sopenharmony_ci m_context.resetCommandPoolForVKSC(device, cmdPool); 2548e5c31af7Sopenharmony_ci 2549e5c31af7Sopenharmony_ci const Allocation& dstImageBufferAlloc = dstImageBuffer->getAllocation(); 2550e5c31af7Sopenharmony_ci invalidateAlloc(vk, device, dstImageBufferAlloc); 2551e5c31af7Sopenharmony_ci deMemcpy(&m_dstData[levelNdx][layerNdx]->at(0), dstImageBufferAlloc.getHostPtr(), dstImageSizeInBytes); 2552e5c31af7Sopenharmony_ci } 2553e5c31af7Sopenharmony_ci } 2554e5c31af7Sopenharmony_ci 2555e5c31af7Sopenharmony_ci m_compressedImage = dstImage; 2556e5c31af7Sopenharmony_ci} 2557e5c31af7Sopenharmony_ci 2558e5c31af7Sopenharmony_ciclass TexelViewCompatibleCase : public TestCase 2559e5c31af7Sopenharmony_ci{ 2560e5c31af7Sopenharmony_cipublic: 2561e5c31af7Sopenharmony_ci TexelViewCompatibleCase (TestContext& testCtx, 2562e5c31af7Sopenharmony_ci const std::string& name, 2563e5c31af7Sopenharmony_ci const TestParameters& parameters); 2564e5c31af7Sopenharmony_ci void initPrograms (SourceCollections& programCollection) const; 2565e5c31af7Sopenharmony_ci TestInstance* createInstance (Context& context) const; 2566e5c31af7Sopenharmony_ci virtual void checkSupport (Context& context) const; 2567e5c31af7Sopenharmony_ciprotected: 2568e5c31af7Sopenharmony_ci const TestParameters m_parameters; 2569e5c31af7Sopenharmony_ci}; 2570e5c31af7Sopenharmony_ci 2571e5c31af7Sopenharmony_ciTexelViewCompatibleCase::TexelViewCompatibleCase (TestContext& testCtx, const std::string& name, const TestParameters& parameters) 2572e5c31af7Sopenharmony_ci : TestCase (testCtx, name) 2573e5c31af7Sopenharmony_ci , m_parameters (parameters) 2574e5c31af7Sopenharmony_ci{ 2575e5c31af7Sopenharmony_ci} 2576e5c31af7Sopenharmony_ci 2577e5c31af7Sopenharmony_civoid TexelViewCompatibleCase::initPrograms (vk::SourceCollections& programCollection) const 2578e5c31af7Sopenharmony_ci{ 2579e5c31af7Sopenharmony_ci DE_ASSERT(m_parameters.size.x() > 0); 2580e5c31af7Sopenharmony_ci DE_ASSERT(m_parameters.size.y() > 0); 2581e5c31af7Sopenharmony_ci 2582e5c31af7Sopenharmony_ci const unsigned int imageTypeIndex = 2583e5c31af7Sopenharmony_ci (m_parameters.imageType == IMAGE_TYPE_2D) + 2584e5c31af7Sopenharmony_ci (m_parameters.imageType == IMAGE_TYPE_3D) * 2; 2585e5c31af7Sopenharmony_ci 2586e5c31af7Sopenharmony_ci switch (m_parameters.shader) 2587e5c31af7Sopenharmony_ci { 2588e5c31af7Sopenharmony_ci case SHADER_TYPE_COMPUTE: 2589e5c31af7Sopenharmony_ci { 2590e5c31af7Sopenharmony_ci const std::string imageTypeStr = getShaderImageType(mapVkFormat(m_parameters.formatUncompressed), m_parameters.imageType); 2591e5c31af7Sopenharmony_ci const std::string formatQualifierStr = getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatUncompressed)); 2592e5c31af7Sopenharmony_ci std::ostringstream src; 2593e5c31af7Sopenharmony_ci std::ostringstream src_decompress; 2594e5c31af7Sopenharmony_ci 2595e5c31af7Sopenharmony_ci src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n" 2596e5c31af7Sopenharmony_ci << "layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n\n"; 2597e5c31af7Sopenharmony_ci src_decompress << src.str(); 2598e5c31af7Sopenharmony_ci 2599e5c31af7Sopenharmony_ci switch(m_parameters.operation) 2600e5c31af7Sopenharmony_ci { 2601e5c31af7Sopenharmony_ci case OPERATION_IMAGE_LOAD: 2602e5c31af7Sopenharmony_ci { 2603e5c31af7Sopenharmony_ci const char* posDefinitions[3] = 2604e5c31af7Sopenharmony_ci { 2605e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2606e5c31af7Sopenharmony_ci " highp int pos = int(gl_GlobalInvocationID.x);\n", 2607e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2608e5c31af7Sopenharmony_ci " ivec2 pos = ivec2(gl_GlobalInvocationID.xy);\n", 2609e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2610e5c31af7Sopenharmony_ci " ivec3 pos = ivec3(gl_GlobalInvocationID);\n", 2611e5c31af7Sopenharmony_ci }; 2612e5c31af7Sopenharmony_ci 2613e5c31af7Sopenharmony_ci src << "layout (binding = 0, "<<formatQualifierStr<<") readonly uniform "<<imageTypeStr<<" u_image0;\n" 2614e5c31af7Sopenharmony_ci << "layout (binding = 1, "<<formatQualifierStr<<") writeonly uniform "<<imageTypeStr<<" u_image1;\n\n" 2615e5c31af7Sopenharmony_ci << "void main (void)\n" 2616e5c31af7Sopenharmony_ci << "{\n" 2617e5c31af7Sopenharmony_ci << posDefinitions[imageTypeIndex] 2618e5c31af7Sopenharmony_ci << " imageStore(u_image1, pos, imageLoad(u_image0, pos));\n" 2619e5c31af7Sopenharmony_ci << "}\n"; 2620e5c31af7Sopenharmony_ci 2621e5c31af7Sopenharmony_ci break; 2622e5c31af7Sopenharmony_ci } 2623e5c31af7Sopenharmony_ci 2624e5c31af7Sopenharmony_ci case OPERATION_TEXEL_FETCH: 2625e5c31af7Sopenharmony_ci { 2626e5c31af7Sopenharmony_ci const char* storeDefinitions[3] = 2627e5c31af7Sopenharmony_ci { 2628e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2629e5c31af7Sopenharmony_ci " imageStore(u_image1, pos.x, texelFetch(u_image0, pos.x, pos.z));\n", 2630e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2631e5c31af7Sopenharmony_ci " imageStore(u_image1, pos.xy, texelFetch(u_image0, pos.xy, pos.z));\n", 2632e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2633e5c31af7Sopenharmony_ci " imageStore(u_image1, pos, texelFetch(u_image0, pos, pos.z));\n", 2634e5c31af7Sopenharmony_ci }; 2635e5c31af7Sopenharmony_ci 2636e5c31af7Sopenharmony_ci src << "layout (binding = 0) uniform "<<getGlslSamplerType(mapVkFormat(m_parameters.formatUncompressed), mapImageViewType(m_parameters.imageType))<<" u_image0;\n" 2637e5c31af7Sopenharmony_ci << "layout (binding = 1, "<<formatQualifierStr<<") writeonly uniform "<<imageTypeStr<<" u_image1;\n\n" 2638e5c31af7Sopenharmony_ci << "void main (void)\n" 2639e5c31af7Sopenharmony_ci << "{\n" 2640e5c31af7Sopenharmony_ci << " ivec3 pos = ivec3(gl_GlobalInvocationID.xyz);\n" 2641e5c31af7Sopenharmony_ci << storeDefinitions[imageTypeIndex] 2642e5c31af7Sopenharmony_ci << "}\n"; 2643e5c31af7Sopenharmony_ci 2644e5c31af7Sopenharmony_ci break; 2645e5c31af7Sopenharmony_ci } 2646e5c31af7Sopenharmony_ci 2647e5c31af7Sopenharmony_ci case OPERATION_TEXTURE: 2648e5c31af7Sopenharmony_ci { 2649e5c31af7Sopenharmony_ci const char* coordDefinitions[3] = 2650e5c31af7Sopenharmony_ci { 2651e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2652e5c31af7Sopenharmony_ci " const int pos = int(gl_GlobalInvocationID.x);\n" 2653e5c31af7Sopenharmony_ci " const float coord = (float(gl_GlobalInvocationID.x) + 0.5) / pixels_resolution.x;\n", 2654e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2655e5c31af7Sopenharmony_ci " const ivec2 pos = ivec2(gl_GlobalInvocationID.xy);\n" 2656e5c31af7Sopenharmony_ci " const vec2 coord = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(pixels_resolution);\n", 2657e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2658e5c31af7Sopenharmony_ci " const ivec3 pos = ivec3(gl_GlobalInvocationID.xy, 0);\n" 2659e5c31af7Sopenharmony_ci " const vec2 v2 = (vec2(gl_GlobalInvocationID.xy) + 0.5) / vec2(pixels_resolution);\n" 2660e5c31af7Sopenharmony_ci " const vec3 coord = vec3(v2, 0.0);\n", 2661e5c31af7Sopenharmony_ci }; 2662e5c31af7Sopenharmony_ci 2663e5c31af7Sopenharmony_ci src << "layout (binding = 0) uniform "<<getGlslSamplerType(mapVkFormat(m_parameters.formatUncompressed), mapImageViewType(m_parameters.imageType))<<" u_image0;\n" 2664e5c31af7Sopenharmony_ci << "layout (binding = 1, "<<formatQualifierStr<<") writeonly uniform "<<imageTypeStr<<" u_image1;\n\n" 2665e5c31af7Sopenharmony_ci << "void main (void)\n" 2666e5c31af7Sopenharmony_ci << "{\n" 2667e5c31af7Sopenharmony_ci << " const vec2 pixels_resolution = vec2(gl_NumWorkGroups.x, gl_NumWorkGroups.y);\n" 2668e5c31af7Sopenharmony_ci << coordDefinitions[imageTypeIndex] 2669e5c31af7Sopenharmony_ci << " imageStore(u_image1, pos, texture(u_image0, coord));\n" 2670e5c31af7Sopenharmony_ci << "}\n"; 2671e5c31af7Sopenharmony_ci 2672e5c31af7Sopenharmony_ci break; 2673e5c31af7Sopenharmony_ci } 2674e5c31af7Sopenharmony_ci 2675e5c31af7Sopenharmony_ci case OPERATION_IMAGE_STORE: 2676e5c31af7Sopenharmony_ci { 2677e5c31af7Sopenharmony_ci const char* posDefinitions[3] = 2678e5c31af7Sopenharmony_ci { 2679e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2680e5c31af7Sopenharmony_ci " highp int pos = int(gl_GlobalInvocationID.x);\n", 2681e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2682e5c31af7Sopenharmony_ci " ivec2 pos = ivec2(gl_GlobalInvocationID.xy);\n", 2683e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2684e5c31af7Sopenharmony_ci " ivec3 pos = ivec3(gl_GlobalInvocationID);\n", 2685e5c31af7Sopenharmony_ci }; 2686e5c31af7Sopenharmony_ci 2687e5c31af7Sopenharmony_ci src << "layout (binding = 0, "<<formatQualifierStr<<") uniform "<<imageTypeStr<<" u_image0;\n" 2688e5c31af7Sopenharmony_ci << "layout (binding = 1, "<<formatQualifierStr<<") readonly uniform "<<imageTypeStr<<" u_image1;\n" 2689e5c31af7Sopenharmony_ci << "layout (binding = 2, "<<formatQualifierStr<<") writeonly uniform "<<imageTypeStr<<" u_image2;\n\n" 2690e5c31af7Sopenharmony_ci << "void main (void)\n" 2691e5c31af7Sopenharmony_ci << "{\n" 2692e5c31af7Sopenharmony_ci << posDefinitions[imageTypeIndex] 2693e5c31af7Sopenharmony_ci << " imageStore(u_image0, pos, imageLoad(u_image1, pos));\n" 2694e5c31af7Sopenharmony_ci << " imageStore(u_image2, pos, imageLoad(u_image0, pos));\n" 2695e5c31af7Sopenharmony_ci << "}\n"; 2696e5c31af7Sopenharmony_ci 2697e5c31af7Sopenharmony_ci break; 2698e5c31af7Sopenharmony_ci } 2699e5c31af7Sopenharmony_ci 2700e5c31af7Sopenharmony_ci default: 2701e5c31af7Sopenharmony_ci DE_ASSERT(false); 2702e5c31af7Sopenharmony_ci } 2703e5c31af7Sopenharmony_ci 2704e5c31af7Sopenharmony_ci const ImageType compressedReferenceImageType = (m_parameters.imageType == IMAGE_TYPE_2D && m_parameters.layers > 1u) ? IMAGE_TYPE_2D_ARRAY : m_parameters.imageType; 2705e5c31af7Sopenharmony_ci const char* cordDefinitions[3] = 2706e5c31af7Sopenharmony_ci { 2707e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2708e5c31af7Sopenharmony_ci " const highp float cord = float(gl_GlobalInvocationID.x) / pixels_resolution.x;\n" 2709e5c31af7Sopenharmony_ci " const highp int pos = int(gl_GlobalInvocationID.x); \n", 2710e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2711e5c31af7Sopenharmony_ci " const vec2 cord = vec2(gl_GlobalInvocationID.xy) / vec2(pixels_resolution);\n" 2712e5c31af7Sopenharmony_ci " const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); \n", 2713e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2714e5c31af7Sopenharmony_ci " const vec2 v2 = vec2(gl_GlobalInvocationID.xy) / vec2(pixels_resolution);\n" 2715e5c31af7Sopenharmony_ci " const vec3 cord = vec3(v2, 0.0);\n" 2716e5c31af7Sopenharmony_ci " const ivec3 pos = ivec3(gl_GlobalInvocationID); \n", 2717e5c31af7Sopenharmony_ci }; 2718e5c31af7Sopenharmony_ci src_decompress << "layout (binding = 0) uniform "<<getGlslSamplerType(mapVkFormat(m_parameters.formatForVerify), mapImageViewType(m_parameters.imageType))<<" compressed_result;\n" 2719e5c31af7Sopenharmony_ci << "layout (binding = 1) uniform "<<getGlslSamplerType(mapVkFormat(m_parameters.formatForVerify), mapImageViewType(compressedReferenceImageType))<<" compressed_reference;\n" 2720e5c31af7Sopenharmony_ci << "layout (binding = 2, "<<getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatForVerify))<<") writeonly uniform "<<getShaderImageType(mapVkFormat(m_parameters.formatForVerify), m_parameters.imageType)<<" decompressed_result;\n" 2721e5c31af7Sopenharmony_ci << "layout (binding = 3, "<<getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatForVerify))<<") writeonly uniform "<<getShaderImageType(mapVkFormat(m_parameters.formatForVerify), m_parameters.imageType)<<" decompressed_reference;\n" 2722e5c31af7Sopenharmony_ci << "layout (push_constant, std430) uniform PushConstants { uint layer; uint level; };\n\n" 2723e5c31af7Sopenharmony_ci << "void main (void)\n" 2724e5c31af7Sopenharmony_ci << "{\n" 2725e5c31af7Sopenharmony_ci << " const vec2 pixels_resolution = vec2(gl_NumWorkGroups.xy);\n" 2726e5c31af7Sopenharmony_ci << cordDefinitions[imageTypeIndex] 2727e5c31af7Sopenharmony_ci << " imageStore(decompressed_result, pos, texture(compressed_result, cord));\n"; 2728e5c31af7Sopenharmony_ci if (compressedReferenceImageType == IMAGE_TYPE_2D_ARRAY) 2729e5c31af7Sopenharmony_ci src_decompress << " imageStore(decompressed_reference, pos, textureLod(compressed_reference, vec3(cord, layer), level));\n"; 2730e5c31af7Sopenharmony_ci else 2731e5c31af7Sopenharmony_ci src_decompress << " imageStore(decompressed_reference, pos, texture(compressed_reference, cord));\n"; 2732e5c31af7Sopenharmony_ci src_decompress << "}\n"; 2733e5c31af7Sopenharmony_ci programCollection.glslSources.add("comp") << glu::ComputeSource(src.str()); 2734e5c31af7Sopenharmony_ci programCollection.glslSources.add("decompress") << glu::ComputeSource(src_decompress.str()); 2735e5c31af7Sopenharmony_ci 2736e5c31af7Sopenharmony_ci break; 2737e5c31af7Sopenharmony_ci } 2738e5c31af7Sopenharmony_ci 2739e5c31af7Sopenharmony_ci case SHADER_TYPE_FRAGMENT: 2740e5c31af7Sopenharmony_ci { 2741e5c31af7Sopenharmony_ci ImageType imageTypeForFS = (m_parameters.imageType == IMAGE_TYPE_2D_ARRAY) ? IMAGE_TYPE_2D : m_parameters.imageType; 2742e5c31af7Sopenharmony_ci 2743e5c31af7Sopenharmony_ci // Vertex shader 2744e5c31af7Sopenharmony_ci { 2745e5c31af7Sopenharmony_ci std::ostringstream src; 2746e5c31af7Sopenharmony_ci src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n\n" 2747e5c31af7Sopenharmony_ci << "layout(location = 0) in vec4 v_in_position;\n" 2748e5c31af7Sopenharmony_ci << "\n" 2749e5c31af7Sopenharmony_ci << "void main (void)\n" 2750e5c31af7Sopenharmony_ci << "{\n" 2751e5c31af7Sopenharmony_ci << " gl_Position = v_in_position;\n" 2752e5c31af7Sopenharmony_ci << "}\n"; 2753e5c31af7Sopenharmony_ci 2754e5c31af7Sopenharmony_ci programCollection.glslSources.add("vert") << glu::VertexSource(src.str()); 2755e5c31af7Sopenharmony_ci } 2756e5c31af7Sopenharmony_ci 2757e5c31af7Sopenharmony_ci // Fragment shader 2758e5c31af7Sopenharmony_ci { 2759e5c31af7Sopenharmony_ci switch(m_parameters.operation) 2760e5c31af7Sopenharmony_ci { 2761e5c31af7Sopenharmony_ci case OPERATION_ATTACHMENT_READ: 2762e5c31af7Sopenharmony_ci case OPERATION_ATTACHMENT_WRITE: 2763e5c31af7Sopenharmony_ci { 2764e5c31af7Sopenharmony_ci std::ostringstream src; 2765e5c31af7Sopenharmony_ci 2766e5c31af7Sopenharmony_ci const std::string dstTypeStr = getGlslFormatType(m_parameters.formatUncompressed); 2767e5c31af7Sopenharmony_ci const std::string srcTypeStr = getGlslInputFormatType(m_parameters.formatUncompressed); 2768e5c31af7Sopenharmony_ci 2769e5c31af7Sopenharmony_ci src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n\n" 2770e5c31af7Sopenharmony_ci << "precision highp int;\n" 2771e5c31af7Sopenharmony_ci << "precision highp float;\n" 2772e5c31af7Sopenharmony_ci << "\n" 2773e5c31af7Sopenharmony_ci << "layout (location = 0) out highp " << dstTypeStr << " o_color;\n" 2774e5c31af7Sopenharmony_ci << "layout (input_attachment_index = 0, set = 0, binding = 0) uniform highp " << srcTypeStr << " inputImage1;\n" 2775e5c31af7Sopenharmony_ci << "\n" 2776e5c31af7Sopenharmony_ci << "void main (void)\n" 2777e5c31af7Sopenharmony_ci << "{\n" 2778e5c31af7Sopenharmony_ci << " o_color = " << dstTypeStr << "(subpassLoad(inputImage1));\n" 2779e5c31af7Sopenharmony_ci << "}\n"; 2780e5c31af7Sopenharmony_ci 2781e5c31af7Sopenharmony_ci programCollection.glslSources.add("frag") << glu::FragmentSource(src.str()); 2782e5c31af7Sopenharmony_ci 2783e5c31af7Sopenharmony_ci break; 2784e5c31af7Sopenharmony_ci } 2785e5c31af7Sopenharmony_ci 2786e5c31af7Sopenharmony_ci case OPERATION_TEXTURE_READ: 2787e5c31af7Sopenharmony_ci case OPERATION_TEXTURE_WRITE: 2788e5c31af7Sopenharmony_ci { 2789e5c31af7Sopenharmony_ci std::ostringstream src; 2790e5c31af7Sopenharmony_ci 2791e5c31af7Sopenharmony_ci const std::string srcSamplerTypeStr = getGlslSamplerType(mapVkFormat(m_parameters.formatUncompressed), mapImageViewType(imageTypeForFS)); 2792e5c31af7Sopenharmony_ci const std::string dstImageTypeStr = getShaderImageType(mapVkFormat(m_parameters.formatUncompressed), imageTypeForFS); 2793e5c31af7Sopenharmony_ci const std::string dstFormatQualifierStr = getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatUncompressed)); 2794e5c31af7Sopenharmony_ci 2795e5c31af7Sopenharmony_ci const char* inDefinitions[3] = 2796e5c31af7Sopenharmony_ci { 2797e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2798e5c31af7Sopenharmony_ci " const highp int out_pos = int(gl_FragCoord.x);\n" 2799e5c31af7Sopenharmony_ci " const highp float pixels_resolution = textureSize(u_imageIn, 0);\n" 2800e5c31af7Sopenharmony_ci " const highp float in_pos = gl_FragCoord.x / pixels_resolution;\n", 2801e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2802e5c31af7Sopenharmony_ci " const ivec2 out_pos = ivec2(gl_FragCoord.xy);\n" 2803e5c31af7Sopenharmony_ci " const vec2 pixels_resolution = vec2(textureSize(u_imageIn, 0));\n" 2804e5c31af7Sopenharmony_ci " const vec2 in_pos = vec2(gl_FragCoord.xy) / vec2(pixels_resolution);\n", 2805e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2806e5c31af7Sopenharmony_ci " const ivec3 out_pos = ivec3(gl_FragCoord.xy, 0);\n" 2807e5c31af7Sopenharmony_ci " const vec3 pixels_resolution = vec3(textureSize(u_imageIn, 0));\n" 2808e5c31af7Sopenharmony_ci " const vec3 in_pos = vec3(gl_FragCoord.xy, 0) / vec3(pixels_resolution.xy, 1.0);\n", 2809e5c31af7Sopenharmony_ci }; 2810e5c31af7Sopenharmony_ci 2811e5c31af7Sopenharmony_ci src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n\n" 2812e5c31af7Sopenharmony_ci << "layout (binding = 0) uniform " << srcSamplerTypeStr << " u_imageIn;\n" 2813e5c31af7Sopenharmony_ci << "layout (binding = 1, " << dstFormatQualifierStr << ") writeonly uniform " << dstImageTypeStr << " u_imageOut;\n" 2814e5c31af7Sopenharmony_ci << "\n" 2815e5c31af7Sopenharmony_ci << "void main (void)\n" 2816e5c31af7Sopenharmony_ci << "{\n" 2817e5c31af7Sopenharmony_ci << inDefinitions[imageTypeIndex] 2818e5c31af7Sopenharmony_ci << " imageStore(u_imageOut, out_pos, texture(u_imageIn, in_pos));\n" 2819e5c31af7Sopenharmony_ci << "}\n"; 2820e5c31af7Sopenharmony_ci 2821e5c31af7Sopenharmony_ci programCollection.glslSources.add("frag") << glu::FragmentSource(src.str()); 2822e5c31af7Sopenharmony_ci 2823e5c31af7Sopenharmony_ci break; 2824e5c31af7Sopenharmony_ci } 2825e5c31af7Sopenharmony_ci 2826e5c31af7Sopenharmony_ci default: 2827e5c31af7Sopenharmony_ci DE_ASSERT(false); 2828e5c31af7Sopenharmony_ci } 2829e5c31af7Sopenharmony_ci } 2830e5c31af7Sopenharmony_ci 2831e5c31af7Sopenharmony_ci // Verification fragment shader 2832e5c31af7Sopenharmony_ci { 2833e5c31af7Sopenharmony_ci std::ostringstream src; 2834e5c31af7Sopenharmony_ci 2835e5c31af7Sopenharmony_ci const std::string samplerType = getGlslSamplerType(mapVkFormat(m_parameters.formatForVerify), mapImageViewType(imageTypeForFS)); 2836e5c31af7Sopenharmony_ci const std::string imageTypeStr = getShaderImageType(mapVkFormat(m_parameters.formatForVerify), imageTypeForFS); 2837e5c31af7Sopenharmony_ci const std::string formatQualifierStr = getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatForVerify)); 2838e5c31af7Sopenharmony_ci 2839e5c31af7Sopenharmony_ci const char* pos0Definitions[3] = 2840e5c31af7Sopenharmony_ci { 2841e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2842e5c31af7Sopenharmony_ci " const highp int out_pos = int(gl_FragCoord.x);\n" 2843e5c31af7Sopenharmony_ci " const highp float pixels_resolution0 = textureSize(u_imageIn0, 0);\n" 2844e5c31af7Sopenharmony_ci " const highp float in_pos0 = gl_FragCoord.x / pixels_resolution0;\n", 2845e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2846e5c31af7Sopenharmony_ci " const ivec2 out_pos = ivec2(gl_FragCoord.xy);\n" 2847e5c31af7Sopenharmony_ci " const vec2 pixels_resolution0 = vec2(textureSize(u_imageIn0, 0));\n" 2848e5c31af7Sopenharmony_ci " const vec2 in_pos0 = vec2(gl_FragCoord.xy) / vec2(pixels_resolution0);\n", 2849e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2850e5c31af7Sopenharmony_ci " const ivec3 out_pos = ivec3(ivec2(gl_FragCoord.xy), 0);\n" 2851e5c31af7Sopenharmony_ci " const vec3 pixels_resolution0 = vec3(textureSize(u_imageIn0, 0));\n" 2852e5c31af7Sopenharmony_ci " const vec3 in_pos0 = vec3(gl_FragCoord.xy, 0) / vec3(pixels_resolution0.xy, 1.0);\n", 2853e5c31af7Sopenharmony_ci }; 2854e5c31af7Sopenharmony_ci const char* pos1Definitions[3] = 2855e5c31af7Sopenharmony_ci { 2856e5c31af7Sopenharmony_ci // IMAGE_TYPE_1D 2857e5c31af7Sopenharmony_ci " const highp float pixels_resolution1 = textureSize(u_imageIn1, 0);\n" 2858e5c31af7Sopenharmony_ci " const highp float in_pos1 = gl_FragCoord.x / pixels_resolution1;\n", 2859e5c31af7Sopenharmony_ci // IMAGE_TYPE_2D 2860e5c31af7Sopenharmony_ci " const vec2 pixels_resolution1 = vec2(textureSize(u_imageIn1, 0));\n" 2861e5c31af7Sopenharmony_ci " const vec2 in_pos1 = vec2(gl_FragCoord.xy) / vec2(pixels_resolution1);\n", 2862e5c31af7Sopenharmony_ci // IMAGE_TYPE_3D 2863e5c31af7Sopenharmony_ci " const vec3 pixels_resolution1 = vec3(textureSize(u_imageIn1, 0));\n" 2864e5c31af7Sopenharmony_ci " const vec3 in_pos1 = vec3(gl_FragCoord.xy, 0) / vec3(pixels_resolution1.xy, 1.0);\n", 2865e5c31af7Sopenharmony_ci }; 2866e5c31af7Sopenharmony_ci 2867e5c31af7Sopenharmony_ci src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n\n" 2868e5c31af7Sopenharmony_ci << "layout (binding = 0) uniform " << getGlslSamplerType(mapVkFormat(m_parameters.formatForVerify), mapImageViewType(m_parameters.imageType)) << " u_imageIn0;\n" 2869e5c31af7Sopenharmony_ci << "layout (binding = 1) uniform " << getGlslSamplerType(mapVkFormat(m_parameters.formatForVerify), mapImageViewType(m_parameters.imageType)) << " u_imageIn1;\n" 2870e5c31af7Sopenharmony_ci << "layout (binding = 2, " << getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatForVerify)) << ") writeonly uniform " << getShaderImageType(mapVkFormat(m_parameters.formatForVerify), m_parameters.imageType) << " u_imageOut0;\n" 2871e5c31af7Sopenharmony_ci << "layout (binding = 3, " << getShaderImageFormatQualifier(mapVkFormat(m_parameters.formatForVerify)) << ") writeonly uniform " << getShaderImageType(mapVkFormat(m_parameters.formatForVerify), m_parameters.imageType) << " u_imageOut1;\n" 2872e5c31af7Sopenharmony_ci << "\n" 2873e5c31af7Sopenharmony_ci << "void main (void)\n" 2874e5c31af7Sopenharmony_ci << "{\n" 2875e5c31af7Sopenharmony_ci << pos0Definitions[imageTypeIndex] 2876e5c31af7Sopenharmony_ci << " imageStore(u_imageOut0, out_pos, texture(u_imageIn0, in_pos0));\n" 2877e5c31af7Sopenharmony_ci << "\n" 2878e5c31af7Sopenharmony_ci << pos1Definitions[imageTypeIndex] 2879e5c31af7Sopenharmony_ci << " imageStore(u_imageOut1, out_pos, texture(u_imageIn1, in_pos1));\n" 2880e5c31af7Sopenharmony_ci << "}\n"; 2881e5c31af7Sopenharmony_ci 2882e5c31af7Sopenharmony_ci programCollection.glslSources.add("frag_verify") << glu::FragmentSource(src.str()); 2883e5c31af7Sopenharmony_ci } 2884e5c31af7Sopenharmony_ci 2885e5c31af7Sopenharmony_ci break; 2886e5c31af7Sopenharmony_ci } 2887e5c31af7Sopenharmony_ci 2888e5c31af7Sopenharmony_ci default: 2889e5c31af7Sopenharmony_ci DE_ASSERT(false); 2890e5c31af7Sopenharmony_ci } 2891e5c31af7Sopenharmony_ci} 2892e5c31af7Sopenharmony_ci 2893e5c31af7Sopenharmony_civoid TexelViewCompatibleCase::checkSupport (Context& context) const 2894e5c31af7Sopenharmony_ci{ 2895e5c31af7Sopenharmony_ci const VkPhysicalDevice physicalDevice = context.getPhysicalDevice(); 2896e5c31af7Sopenharmony_ci const InstanceInterface& vk = context.getInstanceInterface(); 2897e5c31af7Sopenharmony_ci 2898e5c31af7Sopenharmony_ci context.requireDeviceFunctionality("VK_KHR_maintenance2"); 2899e5c31af7Sopenharmony_ci 2900e5c31af7Sopenharmony_ci { 2901e5c31af7Sopenharmony_ci VkImageFormatProperties imageFormatProperties; 2902e5c31af7Sopenharmony_ci 2903e5c31af7Sopenharmony_ci if (vk.getPhysicalDeviceImageFormatProperties(physicalDevice, m_parameters.formatUncompressed, 2904e5c31af7Sopenharmony_ci mapImageType(m_parameters.imageType), VK_IMAGE_TILING_OPTIMAL, 2905e5c31af7Sopenharmony_ci m_parameters.uncompressedImageUsage, 0u, &imageFormatProperties) == VK_ERROR_FORMAT_NOT_SUPPORTED) 2906e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Operation not supported with this image format"); 2907e5c31af7Sopenharmony_ci 2908e5c31af7Sopenharmony_ci if (VK_ERROR_FORMAT_NOT_SUPPORTED == vk.getPhysicalDeviceImageFormatProperties(physicalDevice, m_parameters.formatCompressed, 2909e5c31af7Sopenharmony_ci mapImageType(m_parameters.imageType), VK_IMAGE_TILING_OPTIMAL, 2910e5c31af7Sopenharmony_ci m_parameters.compressedImageUsage, 2911e5c31af7Sopenharmony_ci VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT, 2912e5c31af7Sopenharmony_ci &imageFormatProperties)) 2913e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Operation not supported with this image format"); 2914e5c31af7Sopenharmony_ci } 2915e5c31af7Sopenharmony_ci 2916e5c31af7Sopenharmony_ci { 2917e5c31af7Sopenharmony_ci const VkPhysicalDeviceFeatures physicalDeviceFeatures = getPhysicalDeviceFeatures(vk, physicalDevice); 2918e5c31af7Sopenharmony_ci 2919e5c31af7Sopenharmony_ci if (deInRange32(m_parameters.formatCompressed, VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_BC7_SRGB_BLOCK) && 2920e5c31af7Sopenharmony_ci !physicalDeviceFeatures.textureCompressionBC) 2921e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "textureCompressionBC not supported"); 2922e5c31af7Sopenharmony_ci 2923e5c31af7Sopenharmony_ci if (deInRange32(m_parameters.formatCompressed, VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, VK_FORMAT_EAC_R11G11_SNORM_BLOCK) && 2924e5c31af7Sopenharmony_ci !physicalDeviceFeatures.textureCompressionETC2) 2925e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "textureCompressionETC2 not supported"); 2926e5c31af7Sopenharmony_ci 2927e5c31af7Sopenharmony_ci if (m_parameters.formatIsASTC && 2928e5c31af7Sopenharmony_ci !physicalDeviceFeatures.textureCompressionASTC_LDR) 2929e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "textureCompressionASTC_LDR not supported"); 2930e5c31af7Sopenharmony_ci 2931e5c31af7Sopenharmony_ci if (m_parameters.uncompressedImageUsage & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) 2932e5c31af7Sopenharmony_ci { 2933e5c31af7Sopenharmony_ci const VkFormatProperties p = getPhysicalDeviceFormatProperties(vk, physicalDevice, m_parameters.formatUncompressed); 2934e5c31af7Sopenharmony_ci if ((p.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) == 0) 2935e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Storage view format not supported"); 2936e5c31af7Sopenharmony_ci } 2937e5c31af7Sopenharmony_ci } 2938e5c31af7Sopenharmony_ci} 2939e5c31af7Sopenharmony_ci 2940e5c31af7Sopenharmony_ciTestInstance* TexelViewCompatibleCase::createInstance (Context& context) const 2941e5c31af7Sopenharmony_ci{ 2942e5c31af7Sopenharmony_ci if (!m_parameters.useMipmaps) 2943e5c31af7Sopenharmony_ci DE_ASSERT(getNumLayers(m_parameters.imageType, m_parameters.size) == 1u); 2944e5c31af7Sopenharmony_ci 2945e5c31af7Sopenharmony_ci DE_ASSERT(getLayerSize(m_parameters.imageType, m_parameters.size).x() > 0u); 2946e5c31af7Sopenharmony_ci DE_ASSERT(getLayerSize(m_parameters.imageType, m_parameters.size).y() > 0u); 2947e5c31af7Sopenharmony_ci 2948e5c31af7Sopenharmony_ci switch (m_parameters.shader) 2949e5c31af7Sopenharmony_ci { 2950e5c31af7Sopenharmony_ci case SHADER_TYPE_COMPUTE: 2951e5c31af7Sopenharmony_ci { 2952e5c31af7Sopenharmony_ci switch (m_parameters.operation) 2953e5c31af7Sopenharmony_ci { 2954e5c31af7Sopenharmony_ci case OPERATION_IMAGE_LOAD: 2955e5c31af7Sopenharmony_ci case OPERATION_TEXEL_FETCH: 2956e5c31af7Sopenharmony_ci case OPERATION_TEXTURE: 2957e5c31af7Sopenharmony_ci return new BasicComputeTestInstance(context, m_parameters); 2958e5c31af7Sopenharmony_ci case OPERATION_IMAGE_STORE: 2959e5c31af7Sopenharmony_ci return new ImageStoreComputeTestInstance(context, m_parameters); 2960e5c31af7Sopenharmony_ci default: 2961e5c31af7Sopenharmony_ci TCU_THROW(InternalError, "Impossible"); 2962e5c31af7Sopenharmony_ci } 2963e5c31af7Sopenharmony_ci } 2964e5c31af7Sopenharmony_ci 2965e5c31af7Sopenharmony_ci case SHADER_TYPE_FRAGMENT: 2966e5c31af7Sopenharmony_ci { 2967e5c31af7Sopenharmony_ci switch (m_parameters.operation) 2968e5c31af7Sopenharmony_ci { 2969e5c31af7Sopenharmony_ci case OPERATION_ATTACHMENT_READ: 2970e5c31af7Sopenharmony_ci case OPERATION_ATTACHMENT_WRITE: 2971e5c31af7Sopenharmony_ci return new GraphicsAttachmentsTestInstance(context, m_parameters); 2972e5c31af7Sopenharmony_ci 2973e5c31af7Sopenharmony_ci case OPERATION_TEXTURE_READ: 2974e5c31af7Sopenharmony_ci case OPERATION_TEXTURE_WRITE: 2975e5c31af7Sopenharmony_ci return new GraphicsTextureTestInstance(context, m_parameters); 2976e5c31af7Sopenharmony_ci 2977e5c31af7Sopenharmony_ci default: 2978e5c31af7Sopenharmony_ci TCU_THROW(InternalError, "Impossible"); 2979e5c31af7Sopenharmony_ci } 2980e5c31af7Sopenharmony_ci } 2981e5c31af7Sopenharmony_ci 2982e5c31af7Sopenharmony_ci default: 2983e5c31af7Sopenharmony_ci TCU_THROW(InternalError, "Impossible"); 2984e5c31af7Sopenharmony_ci } 2985e5c31af7Sopenharmony_ci} 2986e5c31af7Sopenharmony_ci 2987e5c31af7Sopenharmony_ci} // anonymous ns 2988e5c31af7Sopenharmony_ci 2989e5c31af7Sopenharmony_cistatic tcu::UVec3 getUnniceResolution (const VkFormat format, const deUint32 layers) 2990e5c31af7Sopenharmony_ci{ 2991e5c31af7Sopenharmony_ci const deUint32 unniceMipmapTextureSize[] = { 1, 1, 1, 8, 22, 48, 117, 275, 604, 208, 611, 274, 1211 }; 2992e5c31af7Sopenharmony_ci const deUint32 baseTextureWidth = unniceMipmapTextureSize[getBlockWidth(format)]; 2993e5c31af7Sopenharmony_ci const deUint32 baseTextureHeight = unniceMipmapTextureSize[getBlockHeight(format)]; 2994e5c31af7Sopenharmony_ci const deUint32 baseTextureWidthLevels = deLog2Floor32(baseTextureWidth); 2995e5c31af7Sopenharmony_ci const deUint32 baseTextureHeightLevels = deLog2Floor32(baseTextureHeight); 2996e5c31af7Sopenharmony_ci const deUint32 widthMultiplier = (baseTextureHeightLevels > baseTextureWidthLevels) ? 1u << (baseTextureHeightLevels - baseTextureWidthLevels) : 1u; 2997e5c31af7Sopenharmony_ci const deUint32 heightMultiplier = (baseTextureWidthLevels > baseTextureHeightLevels) ? 1u << (baseTextureWidthLevels - baseTextureHeightLevels) : 1u; 2998e5c31af7Sopenharmony_ci const deUint32 width = baseTextureWidth * widthMultiplier; 2999e5c31af7Sopenharmony_ci const deUint32 height = baseTextureHeight * heightMultiplier; 3000e5c31af7Sopenharmony_ci 3001e5c31af7Sopenharmony_ci // Number of levels should be same on both axises 3002e5c31af7Sopenharmony_ci DE_ASSERT(deLog2Floor32(width) == deLog2Floor32(height)); 3003e5c31af7Sopenharmony_ci 3004e5c31af7Sopenharmony_ci return tcu::UVec3(width, height, layers); 3005e5c31af7Sopenharmony_ci} 3006e5c31af7Sopenharmony_ci 3007e5c31af7Sopenharmony_citcu::TestCaseGroup* createImageCompressionTranscodingTests (tcu::TestContext& testCtx) 3008e5c31af7Sopenharmony_ci{ 3009e5c31af7Sopenharmony_ci struct FormatsArray 3010e5c31af7Sopenharmony_ci { 3011e5c31af7Sopenharmony_ci const VkFormat* formats; 3012e5c31af7Sopenharmony_ci deUint32 count; 3013e5c31af7Sopenharmony_ci }; 3014e5c31af7Sopenharmony_ci 3015e5c31af7Sopenharmony_ci const bool mipmapness[] = 3016e5c31af7Sopenharmony_ci { 3017e5c31af7Sopenharmony_ci false, 3018e5c31af7Sopenharmony_ci true, 3019e5c31af7Sopenharmony_ci }; 3020e5c31af7Sopenharmony_ci 3021e5c31af7Sopenharmony_ci const std::string pipelineName[SHADER_TYPE_LAST] = 3022e5c31af7Sopenharmony_ci { 3023e5c31af7Sopenharmony_ci "compute", 3024e5c31af7Sopenharmony_ci "graphic", 3025e5c31af7Sopenharmony_ci }; 3026e5c31af7Sopenharmony_ci 3027e5c31af7Sopenharmony_ci const std::string mipmanpnessName[DE_LENGTH_OF_ARRAY(mipmapness)] = 3028e5c31af7Sopenharmony_ci { 3029e5c31af7Sopenharmony_ci "basic", 3030e5c31af7Sopenharmony_ci "extended", 3031e5c31af7Sopenharmony_ci }; 3032e5c31af7Sopenharmony_ci 3033e5c31af7Sopenharmony_ci const std::string operationName[OPERATION_LAST] = 3034e5c31af7Sopenharmony_ci { 3035e5c31af7Sopenharmony_ci "image_load", 3036e5c31af7Sopenharmony_ci "texel_fetch", 3037e5c31af7Sopenharmony_ci "texture", 3038e5c31af7Sopenharmony_ci "image_store", 3039e5c31af7Sopenharmony_ci "attachment_read", 3040e5c31af7Sopenharmony_ci "attachment_write", 3041e5c31af7Sopenharmony_ci "texture_read", 3042e5c31af7Sopenharmony_ci "texture_write", 3043e5c31af7Sopenharmony_ci }; 3044e5c31af7Sopenharmony_ci 3045e5c31af7Sopenharmony_ci struct ImageTypeName 3046e5c31af7Sopenharmony_ci { 3047e5c31af7Sopenharmony_ci ImageType type; 3048e5c31af7Sopenharmony_ci std::string name; 3049e5c31af7Sopenharmony_ci }; 3050e5c31af7Sopenharmony_ci ImageTypeName imageTypes[] = 3051e5c31af7Sopenharmony_ci { 3052e5c31af7Sopenharmony_ci { IMAGE_TYPE_1D, "1d_image" }, 3053e5c31af7Sopenharmony_ci { IMAGE_TYPE_2D, "2d_image" }, 3054e5c31af7Sopenharmony_ci { IMAGE_TYPE_3D, "3d_image" }, 3055e5c31af7Sopenharmony_ci }; 3056e5c31af7Sopenharmony_ci 3057e5c31af7Sopenharmony_ci const VkImageUsageFlags baseImageUsageFlagSet = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; 3058e5c31af7Sopenharmony_ci const VkImageUsageFlags compressedImageUsageFlags[OPERATION_LAST] = 3059e5c31af7Sopenharmony_ci { 3060e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_STORAGE_BIT), // "image_load" 3061e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), // "texel_fetch" 3062e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), // "texture" 3063e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), // "image_store" 3064e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), // "attachment_read" 3065e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), // "attachment_write" 3066e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT), // "texture_read" 3067e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), // "texture_write" 3068e5c31af7Sopenharmony_ci }; 3069e5c31af7Sopenharmony_ci 3070e5c31af7Sopenharmony_ci const VkImageUsageFlags compressedImageViewUsageFlags[OPERATION_LAST] = 3071e5c31af7Sopenharmony_ci { 3072e5c31af7Sopenharmony_ci compressedImageUsageFlags[0], //"image_load" 3073e5c31af7Sopenharmony_ci compressedImageUsageFlags[1], //"texel_fetch" 3074e5c31af7Sopenharmony_ci compressedImageUsageFlags[2], //"texture" 3075e5c31af7Sopenharmony_ci compressedImageUsageFlags[3], //"image_store" 3076e5c31af7Sopenharmony_ci compressedImageUsageFlags[4], //"attachment_read" 3077e5c31af7Sopenharmony_ci compressedImageUsageFlags[5] | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, //"attachment_write" 3078e5c31af7Sopenharmony_ci compressedImageUsageFlags[6], //"texture_read" 3079e5c31af7Sopenharmony_ci compressedImageUsageFlags[7], //"texture_write" 3080e5c31af7Sopenharmony_ci }; 3081e5c31af7Sopenharmony_ci 3082e5c31af7Sopenharmony_ci const VkImageUsageFlags uncompressedImageUsageFlags[OPERATION_LAST] = 3083e5c31af7Sopenharmony_ci { 3084e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_STORAGE_BIT), //"image_load" 3085e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), //"texel_fetch" 3086e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), //"texture" 3087e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT), //"image_store" 3088e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), //"attachment_read" 3089e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT), //"attachment_write" 3090e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT), //"texture_read" 3091e5c31af7Sopenharmony_ci baseImageUsageFlagSet | static_cast<VkImageUsageFlagBits>(VK_IMAGE_USAGE_SAMPLED_BIT), //"texture_write" 3092e5c31af7Sopenharmony_ci }; 3093e5c31af7Sopenharmony_ci 3094e5c31af7Sopenharmony_ci const VkFormat compressedFormats64bit[] = 3095e5c31af7Sopenharmony_ci { 3096e5c31af7Sopenharmony_ci VK_FORMAT_BC1_RGB_UNORM_BLOCK, 3097e5c31af7Sopenharmony_ci VK_FORMAT_BC1_RGB_SRGB_BLOCK, 3098e5c31af7Sopenharmony_ci VK_FORMAT_BC1_RGBA_UNORM_BLOCK, 3099e5c31af7Sopenharmony_ci VK_FORMAT_BC1_RGBA_SRGB_BLOCK, 3100e5c31af7Sopenharmony_ci VK_FORMAT_BC4_UNORM_BLOCK, 3101e5c31af7Sopenharmony_ci VK_FORMAT_BC4_SNORM_BLOCK, 3102e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, 3103e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, 3104e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, 3105e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, 3106e5c31af7Sopenharmony_ci VK_FORMAT_EAC_R11_UNORM_BLOCK, 3107e5c31af7Sopenharmony_ci VK_FORMAT_EAC_R11_SNORM_BLOCK, 3108e5c31af7Sopenharmony_ci }; 3109e5c31af7Sopenharmony_ci 3110e5c31af7Sopenharmony_ci const VkFormat compressedFormats128bit[] = 3111e5c31af7Sopenharmony_ci { 3112e5c31af7Sopenharmony_ci VK_FORMAT_BC2_UNORM_BLOCK, 3113e5c31af7Sopenharmony_ci VK_FORMAT_BC2_SRGB_BLOCK, 3114e5c31af7Sopenharmony_ci VK_FORMAT_BC3_UNORM_BLOCK, 3115e5c31af7Sopenharmony_ci VK_FORMAT_BC3_SRGB_BLOCK, 3116e5c31af7Sopenharmony_ci VK_FORMAT_BC5_UNORM_BLOCK, 3117e5c31af7Sopenharmony_ci VK_FORMAT_BC5_SNORM_BLOCK, 3118e5c31af7Sopenharmony_ci VK_FORMAT_BC6H_UFLOAT_BLOCK, 3119e5c31af7Sopenharmony_ci VK_FORMAT_BC6H_SFLOAT_BLOCK, 3120e5c31af7Sopenharmony_ci VK_FORMAT_BC7_UNORM_BLOCK, 3121e5c31af7Sopenharmony_ci VK_FORMAT_BC7_SRGB_BLOCK, 3122e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, 3123e5c31af7Sopenharmony_ci VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, 3124e5c31af7Sopenharmony_ci VK_FORMAT_EAC_R11G11_UNORM_BLOCK, 3125e5c31af7Sopenharmony_ci VK_FORMAT_EAC_R11G11_SNORM_BLOCK, 3126e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_4x4_UNORM_BLOCK, 3127e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_4x4_SRGB_BLOCK, 3128e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_5x4_UNORM_BLOCK, 3129e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_5x4_SRGB_BLOCK, 3130e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_5x5_UNORM_BLOCK, 3131e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_5x5_SRGB_BLOCK, 3132e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_6x5_UNORM_BLOCK, 3133e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_6x5_SRGB_BLOCK, 3134e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_6x6_UNORM_BLOCK, 3135e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_6x6_SRGB_BLOCK, 3136e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x5_UNORM_BLOCK, 3137e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x5_SRGB_BLOCK, 3138e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x6_UNORM_BLOCK, 3139e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x6_SRGB_BLOCK, 3140e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x8_UNORM_BLOCK, 3141e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_8x8_SRGB_BLOCK, 3142e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x5_UNORM_BLOCK, 3143e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x5_SRGB_BLOCK, 3144e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x6_UNORM_BLOCK, 3145e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x6_SRGB_BLOCK, 3146e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x8_UNORM_BLOCK, 3147e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x8_SRGB_BLOCK, 3148e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x10_UNORM_BLOCK, 3149e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_10x10_SRGB_BLOCK, 3150e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_12x10_UNORM_BLOCK, 3151e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_12x10_SRGB_BLOCK, 3152e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_12x12_UNORM_BLOCK, 3153e5c31af7Sopenharmony_ci VK_FORMAT_ASTC_12x12_SRGB_BLOCK, 3154e5c31af7Sopenharmony_ci }; 3155e5c31af7Sopenharmony_ci 3156e5c31af7Sopenharmony_ci const VkFormat uncompressedFormats64bit[] = 3157e5c31af7Sopenharmony_ci { 3158e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_UNORM, 3159e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_SNORM, 3160e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_USCALED, 3161e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_SSCALED, 3162e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_UINT, 3163e5c31af7Sopenharmony_ci VK_FORMAT_R16G16B16A16_SINT, 3164e5c31af7Sopenharmony_ci //VK_FORMAT_R16G16B16A16_SFLOAT, removed as float views can't preserve NAN/INF/Denorm values 3165e5c31af7Sopenharmony_ci VK_FORMAT_R32G32_UINT, 3166e5c31af7Sopenharmony_ci VK_FORMAT_R32G32_SINT, 3167e5c31af7Sopenharmony_ci //VK_FORMAT_R32G32_SFLOAT, removed as float views can't preserve NAN/INF/Denorm values 3168e5c31af7Sopenharmony_ci //VK_FORMAT_R64_UINT, remove from the test it couldn't be used 3169e5c31af7Sopenharmony_ci //VK_FORMAT_R64_SINT, remove from the test it couldn't be used 3170e5c31af7Sopenharmony_ci //VK_FORMAT_R64_SFLOAT, remove from the test it couldn't be used 3171e5c31af7Sopenharmony_ci }; 3172e5c31af7Sopenharmony_ci 3173e5c31af7Sopenharmony_ci const VkFormat uncompressedFormats128bit[] = 3174e5c31af7Sopenharmony_ci { 3175e5c31af7Sopenharmony_ci VK_FORMAT_R32G32B32A32_UINT, 3176e5c31af7Sopenharmony_ci VK_FORMAT_R32G32B32A32_SINT, 3177e5c31af7Sopenharmony_ci //VK_FORMAT_R32G32B32A32_SFLOAT, removed as float views can't preserve NAN/INF/Denorm values 3178e5c31af7Sopenharmony_ci //VK_FORMAT_R64G64_UINT, remove from the test it couldn't be used 3179e5c31af7Sopenharmony_ci //VK_FORMAT_R64G64_SINT, remove from the test it couldn't be used 3180e5c31af7Sopenharmony_ci //VK_FORMAT_R64G64_SFLOAT, remove from the test it couldn't be used 3181e5c31af7Sopenharmony_ci }; 3182e5c31af7Sopenharmony_ci 3183e5c31af7Sopenharmony_ci const FormatsArray formatsCompressedSets[] = 3184e5c31af7Sopenharmony_ci { 3185e5c31af7Sopenharmony_ci { 3186e5c31af7Sopenharmony_ci compressedFormats64bit, 3187e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(compressedFormats64bit) 3188e5c31af7Sopenharmony_ci }, 3189e5c31af7Sopenharmony_ci { 3190e5c31af7Sopenharmony_ci compressedFormats128bit, 3191e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(compressedFormats128bit) 3192e5c31af7Sopenharmony_ci }, 3193e5c31af7Sopenharmony_ci }; 3194e5c31af7Sopenharmony_ci 3195e5c31af7Sopenharmony_ci // Uncompressed formats - floating point formats should not be used in these 3196e5c31af7Sopenharmony_ci // tests as they cannot be relied upon to preserve all possible values in the 3197e5c31af7Sopenharmony_ci // underlying texture data. Refer to the note under the 'VkImageViewCreateInfo' 3198e5c31af7Sopenharmony_ci // section of the specification. 3199e5c31af7Sopenharmony_ci const FormatsArray formatsUncompressedSets[] = 3200e5c31af7Sopenharmony_ci { 3201e5c31af7Sopenharmony_ci { 3202e5c31af7Sopenharmony_ci uncompressedFormats64bit, 3203e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(uncompressedFormats64bit) 3204e5c31af7Sopenharmony_ci }, 3205e5c31af7Sopenharmony_ci { 3206e5c31af7Sopenharmony_ci uncompressedFormats128bit, 3207e5c31af7Sopenharmony_ci DE_LENGTH_OF_ARRAY(uncompressedFormats128bit) 3208e5c31af7Sopenharmony_ci }, 3209e5c31af7Sopenharmony_ci }; 3210e5c31af7Sopenharmony_ci 3211e5c31af7Sopenharmony_ci DE_ASSERT(DE_LENGTH_OF_ARRAY(formatsCompressedSets) == DE_LENGTH_OF_ARRAY(formatsUncompressedSets)); 3212e5c31af7Sopenharmony_ci 3213e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> texelViewCompatibleTests (new tcu::TestCaseGroup(testCtx, "texel_view_compatible")); 3214e5c31af7Sopenharmony_ci 3215e5c31af7Sopenharmony_ci for (int shaderType = SHADER_TYPE_COMPUTE; shaderType < SHADER_TYPE_LAST; ++shaderType) 3216e5c31af7Sopenharmony_ci { 3217e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> pipelineTypeGroup (new tcu::TestCaseGroup(testCtx, pipelineName[shaderType].c_str())); 3218e5c31af7Sopenharmony_ci 3219e5c31af7Sopenharmony_ci for (int mipmapTestNdx = 0; mipmapTestNdx < DE_LENGTH_OF_ARRAY(mipmapness); mipmapTestNdx++) 3220e5c31af7Sopenharmony_ci { 3221e5c31af7Sopenharmony_ci const bool mipmapTest = mipmapness[mipmapTestNdx]; 3222e5c31af7Sopenharmony_ci 3223e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> mipmapTypeGroup (new tcu::TestCaseGroup(testCtx, mipmanpnessName[mipmapTestNdx].c_str())); 3224e5c31af7Sopenharmony_ci 3225e5c31af7Sopenharmony_ci for (int imageTypeNdx = 0; imageTypeNdx < DE_LENGTH_OF_ARRAY(imageTypes); imageTypeNdx++) 3226e5c31af7Sopenharmony_ci { 3227e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> imageTypeGroup (new tcu::TestCaseGroup(testCtx, imageTypes[imageTypeNdx].name.c_str())); 3228e5c31af7Sopenharmony_ci ImageType imageType = imageTypes[imageTypeNdx].type; 3229e5c31af7Sopenharmony_ci 3230e5c31af7Sopenharmony_ci for (int operationNdx = OPERATION_IMAGE_LOAD; operationNdx < OPERATION_LAST; ++operationNdx) 3231e5c31af7Sopenharmony_ci { 3232e5c31af7Sopenharmony_ci if (shaderType != SHADER_TYPE_FRAGMENT && deInRange32(operationNdx, OPERATION_ATTACHMENT_READ, OPERATION_TEXTURE_WRITE)) 3233e5c31af7Sopenharmony_ci continue; 3234e5c31af7Sopenharmony_ci 3235e5c31af7Sopenharmony_ci if (shaderType != SHADER_TYPE_COMPUTE && deInRange32(operationNdx, OPERATION_IMAGE_LOAD, OPERATION_IMAGE_STORE)) 3236e5c31af7Sopenharmony_ci continue; 3237e5c31af7Sopenharmony_ci 3238e5c31af7Sopenharmony_ci if (imageType == IMAGE_TYPE_3D && 3239e5c31af7Sopenharmony_ci (operationNdx == OPERATION_ATTACHMENT_READ || operationNdx == OPERATION_ATTACHMENT_WRITE)) 3240e5c31af7Sopenharmony_ci continue; 3241e5c31af7Sopenharmony_ci 3242e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> imageOperationGroup (new tcu::TestCaseGroup(testCtx, operationName[operationNdx].c_str())); 3243e5c31af7Sopenharmony_ci 3244e5c31af7Sopenharmony_ci deUint32 depth = 1u + 2 * (imageType == IMAGE_TYPE_3D); 3245e5c31af7Sopenharmony_ci deUint32 imageCount = 2u + (operationNdx == OPERATION_IMAGE_STORE); 3246e5c31af7Sopenharmony_ci 3247e5c31af7Sopenharmony_ci // Iterate through bitness groups (64 bit, 128 bit, etc) 3248e5c31af7Sopenharmony_ci for (deUint32 formatBitnessGroup = 0; formatBitnessGroup < DE_LENGTH_OF_ARRAY(formatsCompressedSets); ++formatBitnessGroup) 3249e5c31af7Sopenharmony_ci { 3250e5c31af7Sopenharmony_ci for (deUint32 formatCompressedNdx = 0; formatCompressedNdx < formatsCompressedSets[formatBitnessGroup].count; ++formatCompressedNdx) 3251e5c31af7Sopenharmony_ci { 3252e5c31af7Sopenharmony_ci const VkFormat formatCompressed = formatsCompressedSets[formatBitnessGroup].formats[formatCompressedNdx]; 3253e5c31af7Sopenharmony_ci const std::string compressedFormatGroupName = getFormatShortString(formatCompressed); 3254e5c31af7Sopenharmony_ci MovePtr<tcu::TestCaseGroup> compressedFormatGroup (new tcu::TestCaseGroup(testCtx, compressedFormatGroupName.c_str())); 3255e5c31af7Sopenharmony_ci 3256e5c31af7Sopenharmony_ci for (deUint32 formatUncompressedNdx = 0; formatUncompressedNdx < formatsUncompressedSets[formatBitnessGroup].count; ++formatUncompressedNdx) 3257e5c31af7Sopenharmony_ci { 3258e5c31af7Sopenharmony_ci const VkFormat formatUncompressed = formatsUncompressedSets[formatBitnessGroup].formats[formatUncompressedNdx]; 3259e5c31af7Sopenharmony_ci const std::string uncompressedFormatGroupName = getFormatShortString(formatUncompressed); 3260e5c31af7Sopenharmony_ci 3261e5c31af7Sopenharmony_ci const TestParameters parameters = 3262e5c31af7Sopenharmony_ci { 3263e5c31af7Sopenharmony_ci static_cast<Operation>(operationNdx), 3264e5c31af7Sopenharmony_ci static_cast<ShaderType>(shaderType), 3265e5c31af7Sopenharmony_ci mipmapTest ? getUnniceResolution(formatCompressed, 1u) : UVec3(64u, 64u, depth), 3266e5c31af7Sopenharmony_ci 1u + 2u * mipmapTest * (imageType != IMAGE_TYPE_3D), // 1 or 3 if mipmapTest is true but image is not 3d 3267e5c31af7Sopenharmony_ci imageType, 3268e5c31af7Sopenharmony_ci formatCompressed, 3269e5c31af7Sopenharmony_ci formatUncompressed, 3270e5c31af7Sopenharmony_ci imageCount, 3271e5c31af7Sopenharmony_ci compressedImageUsageFlags[operationNdx], 3272e5c31af7Sopenharmony_ci compressedImageViewUsageFlags[operationNdx], 3273e5c31af7Sopenharmony_ci uncompressedImageUsageFlags[operationNdx], 3274e5c31af7Sopenharmony_ci mipmapTest, 3275e5c31af7Sopenharmony_ci VK_FORMAT_R8G8B8A8_UNORM, 3276e5c31af7Sopenharmony_ci FormatIsASTC(formatCompressed) 3277e5c31af7Sopenharmony_ci }; 3278e5c31af7Sopenharmony_ci 3279e5c31af7Sopenharmony_ci compressedFormatGroup->addChild(new TexelViewCompatibleCase(testCtx, uncompressedFormatGroupName, parameters)); 3280e5c31af7Sopenharmony_ci } 3281e5c31af7Sopenharmony_ci 3282e5c31af7Sopenharmony_ci imageOperationGroup->addChild(compressedFormatGroup.release()); 3283e5c31af7Sopenharmony_ci } 3284e5c31af7Sopenharmony_ci } 3285e5c31af7Sopenharmony_ci 3286e5c31af7Sopenharmony_ci imageTypeGroup->addChild(imageOperationGroup.release()); 3287e5c31af7Sopenharmony_ci } 3288e5c31af7Sopenharmony_ci 3289e5c31af7Sopenharmony_ci mipmapTypeGroup->addChild(imageTypeGroup.release()); 3290e5c31af7Sopenharmony_ci } 3291e5c31af7Sopenharmony_ci 3292e5c31af7Sopenharmony_ci pipelineTypeGroup->addChild(mipmapTypeGroup.release()); 3293e5c31af7Sopenharmony_ci } 3294e5c31af7Sopenharmony_ci 3295e5c31af7Sopenharmony_ci texelViewCompatibleTests->addChild(pipelineTypeGroup.release()); 3296e5c31af7Sopenharmony_ci } 3297e5c31af7Sopenharmony_ci 3298e5c31af7Sopenharmony_ci return texelViewCompatibleTests.release(); 3299e5c31af7Sopenharmony_ci} 3300e5c31af7Sopenharmony_ci 3301e5c31af7Sopenharmony_ci} // image 3302e5c31af7Sopenharmony_ci} // vkt 3303