1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 The Android Open Source Project
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Image load/store Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktImageLoadStoreTests.hpp"
26 #include "vktTestCaseUtil.hpp"
27 #include "vktImageTestsUtil.hpp"
28 #include "vktImageLoadStoreUtil.hpp"
29 #include "vktImageTexture.hpp"
33 #include "vkRefUtil.hpp"
34 #include "vkPlatform.hpp"
35 #include "vkPrograms.hpp"
36 #include "vkMemUtil.hpp"
37 #include "vkBarrierUtil.hpp"
38 #include "vkBuilderUtil.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkImageUtil.hpp"
41 #include "vkCmdUtil.hpp"
42 #include "vkObjUtil.hpp"
45 #include "deUniquePtr.hpp"
46 #include "deSharedPtr.hpp"
47 #include "deStringUtil.hpp"
49 #include "tcuImageCompare.hpp"
50 #include "tcuTexture.hpp"
51 #include "tcuTextureUtil.hpp"
52 #include "tcuFloat.hpp"
53 #include "tcuStringTemplate.hpp"
68 // Check for three-component (non-packed) format, i.e. pixel size is a multiple of 3.
69 bool formatHasThreeComponents(VkFormat format)
71 const tcu::TextureFormat texFormat = mapVkFormat(format);
72 return (getPixelSize(texFormat) % 3) == 0;
75 VkFormat getSingleComponentFormat(VkFormat format)
77 tcu::TextureFormat texFormat = mapVkFormat(format);
78 texFormat = tcu::TextureFormat(tcu::TextureFormat::R, texFormat.type);
79 return mapTextureFormat(texFormat);
82 inline VkBufferImageCopy makeBufferImageCopy (const Texture& texture)
84 return image::makeBufferImageCopy(makeExtent3D(texture.layerSize()), texture.numLayers());
87 tcu::ConstPixelBufferAccess getLayerOrSlice (const Texture& texture, const tcu::ConstPixelBufferAccess access, const int layer)
89 switch (texture.type())
93 case IMAGE_TYPE_BUFFER:
95 DE_ASSERT(layer == 0);
98 case IMAGE_TYPE_1D_ARRAY:
99 return tcu::getSubregion(access, 0, layer, access.getWidth(), 1);
101 case IMAGE_TYPE_2D_ARRAY:
102 case IMAGE_TYPE_CUBE:
103 case IMAGE_TYPE_CUBE_ARRAY:
104 case IMAGE_TYPE_3D: // 3d texture is treated as if depth was the layers
105 return tcu::getSubregion(access, 0, 0, layer, access.getWidth(), access.getHeight(), 1);
108 DE_FATAL("Internal test error");
109 return tcu::ConstPixelBufferAccess();
113 //! \return the size in bytes of a given level of a mipmap image, including array layers.
114 vk::VkDeviceSize getMipmapLevelImageSizeBytes (const Texture& texture, const vk::VkFormat format, const deUint32 mipmapLevel)
116 tcu::IVec3 size = texture.size(mipmapLevel);
117 return tcu::getPixelSize(vk::mapVkFormat(format)) * size.x() * size.y() * size.z();
120 //! \return the size in bytes of the whole mipmap image, including all mipmap levels and array layers
121 vk::VkDeviceSize getMipmapImageTotalSizeBytes (const Texture& texture, const vk::VkFormat format)
123 vk::VkDeviceSize size = 0u;
124 deInt32 levelCount = 0u;
128 size += getMipmapLevelImageSizeBytes(texture, format, levelCount);
130 } while (levelCount < texture.numMipmapLevels());
134 //! \return true if all layers match in both pixel buffers
135 bool comparePixelBuffers (tcu::TestLog& log,
136 const Texture& texture,
137 const VkFormat format,
138 const tcu::ConstPixelBufferAccess reference,
139 const tcu::ConstPixelBufferAccess result,
140 const deUint32 mipmapLevel = 0u)
142 DE_ASSERT(reference.getFormat() == result.getFormat());
143 DE_ASSERT(reference.getSize() == result.getSize());
145 const bool is3d = (texture.type() == IMAGE_TYPE_3D);
146 const int numLayersOrSlices = (is3d ? texture.size(mipmapLevel).z() : texture.numLayers());
147 const int numCubeFaces = 6;
149 int passedLayers = 0;
150 for (int layerNdx = 0; layerNdx < numLayersOrSlices; ++layerNdx)
152 const std::string comparisonName = "Comparison" + de::toString(layerNdx);
153 const std::string comparisonDesc = "Image Comparison, " +
154 (isCube(texture) ? "face " + de::toString(layerNdx % numCubeFaces) + ", cube " + de::toString(layerNdx / numCubeFaces) :
155 is3d ? "slice " + de::toString(layerNdx) : "layer " + de::toString(layerNdx) + " , level " + de::toString(mipmapLevel));
157 const tcu::ConstPixelBufferAccess refLayer = getLayerOrSlice(texture, reference, layerNdx);
158 const tcu::ConstPixelBufferAccess resultLayer = getLayerOrSlice(texture, result, layerNdx);
162 switch (tcu::getTextureChannelClass(mapVkFormat(format).type))
164 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
165 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
167 ok = tcu::intThresholdCompare(log, comparisonName.c_str(), comparisonDesc.c_str(), refLayer, resultLayer, tcu::UVec4(0), tcu::COMPARE_LOG_RESULT);
171 case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
173 // Allow error of minimum representable difference
174 const tcu::Vec4 threshold (1.0f / ((tcu::UVec4(1u) << tcu::getTextureFormatMantissaBitDepth(mapVkFormat(format)).cast<deUint32>()) - 1u).cast<float>());
176 ok = tcu::floatThresholdCompare(log, comparisonName.c_str(), comparisonDesc.c_str(), refLayer, resultLayer, threshold, tcu::COMPARE_LOG_RESULT);
180 case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
182 // Allow error of minimum representable difference
183 const tcu::Vec4 threshold (1.0f / ((tcu::UVec4(1u) << (tcu::getTextureFormatMantissaBitDepth(mapVkFormat(format)).cast<deUint32>() - 1u)) - 1u).cast<float>());
185 ok = tcu::floatThresholdCompare(log, comparisonName.c_str(), comparisonDesc.c_str(), refLayer, resultLayer, threshold, tcu::COMPARE_LOG_RESULT);
189 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
191 // Convert target format ulps to float ulps and allow 1 ulp difference
192 const tcu::UVec4 threshold (tcu::UVec4(1u) << (tcu::UVec4(23) - tcu::getTextureFormatMantissaBitDepth(mapVkFormat(format)).cast<deUint32>()));
194 ok = tcu::floatUlpThresholdCompare(log, comparisonName.c_str(), comparisonDesc.c_str(), refLayer, resultLayer, threshold, tcu::COMPARE_LOG_RESULT);
199 DE_FATAL("Unknown channel class");
206 return passedLayers == numLayersOrSlices;
209 //!< Zero out invalid pixels in the image (denormalized, infinite, NaN values)
210 void replaceBadFloatReinterpretValues (const tcu::PixelBufferAccess access)
212 DE_ASSERT(tcu::getTextureChannelClass(access.getFormat().type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT);
214 for (int z = 0; z < access.getDepth(); ++z)
215 for (int y = 0; y < access.getHeight(); ++y)
216 for (int x = 0; x < access.getWidth(); ++x)
218 const tcu::Vec4 color(access.getPixel(x, y, z));
219 tcu::Vec4 newColor = color;
221 for (int i = 0; i < 4; ++i)
223 if (access.getFormat().type == tcu::TextureFormat::HALF_FLOAT)
225 const tcu::Float16 f(color[i]);
226 if (f.isDenorm() || f.isInf() || f.isNaN())
231 const tcu::Float32 f(color[i]);
232 if (f.isDenorm() || f.isInf() || f.isNaN())
237 if (newColor != color)
238 access.setPixel(newColor, x, y, z);
242 //!< replace invalid pixels in the image (-128)
243 void replaceSnormReinterpretValues (const tcu::PixelBufferAccess access)
245 DE_ASSERT(tcu::getTextureChannelClass(access.getFormat().type) == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT);
247 for (int z = 0; z < access.getDepth(); ++z)
248 for (int y = 0; y < access.getHeight(); ++y)
249 for (int x = 0; x < access.getWidth(); ++x)
251 const tcu::IVec4 color(access.getPixelInt(x, y, z));
252 tcu::IVec4 newColor = color;
254 for (int i = 0; i < 4; ++i)
256 const deInt32 oldColor(color[i]);
257 if (oldColor == -128) newColor[i] = -127;
260 if (newColor != color)
261 access.setPixel(newColor, x, y, z);
265 tcu::TextureLevel generateReferenceImage (const tcu::IVec3& imageSize, const VkFormat imageFormat, const VkFormat readFormat)
267 // Generate a reference image data using the storage format
269 tcu::TextureLevel reference(mapVkFormat(imageFormat), imageSize.x(), imageSize.y(), imageSize.z());
270 const tcu::PixelBufferAccess access = reference.getAccess();
272 const float storeColorScale = computeStoreColorScale(imageFormat, imageSize);
273 const float storeColorBias = computeStoreColorBias(imageFormat);
275 const bool intFormat = isIntegerFormat(imageFormat);
276 const bool storeNegativeValues = isSignedFormat(imageFormat) && (storeColorBias == 0);
277 const int xMax = imageSize.x() - 1;
278 const int yMax = imageSize.y() - 1;
280 for (int z = 0; z < imageSize.z(); ++z)
281 for (int y = 0; y < imageSize.y(); ++y)
282 for (int x = 0; x < imageSize.x(); ++x)
284 tcu::IVec4 color(x^y^z, (xMax - x)^y^z, x^(yMax - y)^z, (xMax - x)^(yMax - y)^z);
286 if (storeNegativeValues)
287 color -= tcu::IVec4(deRoundFloatToInt32((float)de::max(xMax, yMax) / 2.0f));
290 access.setPixel(color, x, y, z);
292 access.setPixel(color.asFloat()*storeColorScale + storeColorBias, x, y, z);
295 // If the image is to be accessed as a float texture, get rid of invalid values
297 if (isFloatFormat(readFormat) && imageFormat != readFormat)
298 replaceBadFloatReinterpretValues(tcu::PixelBufferAccess(mapVkFormat(readFormat), imageSize, access.getDataPtr()));
299 if (isSnormFormat(readFormat) && imageFormat != readFormat)
300 replaceSnormReinterpretValues(tcu::PixelBufferAccess(mapVkFormat(readFormat), imageSize, access.getDataPtr()));
305 inline tcu::TextureLevel generateReferenceImage (const tcu::IVec3& imageSize, const VkFormat imageFormat)
307 return generateReferenceImage(imageSize, imageFormat, imageFormat);
310 void flipHorizontally (const tcu::PixelBufferAccess access)
312 const int xMax = access.getWidth() - 1;
313 const int halfWidth = access.getWidth() / 2;
315 if (isIntegerFormat(mapTextureFormat(access.getFormat())))
316 for (int z = 0; z < access.getDepth(); z++)
317 for (int y = 0; y < access.getHeight(); y++)
318 for (int x = 0; x < halfWidth; x++)
320 const tcu::UVec4 temp = access.getPixelUint(xMax - x, y, z);
321 access.setPixel(access.getPixelUint(x, y, z), xMax - x, y, z);
322 access.setPixel(temp, x, y, z);
325 for (int z = 0; z < access.getDepth(); z++)
326 for (int y = 0; y < access.getHeight(); y++)
327 for (int x = 0; x < halfWidth; x++)
329 const tcu::Vec4 temp = access.getPixel(xMax - x, y, z);
330 access.setPixel(access.getPixel(x, y, z), xMax - x, y, z);
331 access.setPixel(temp, x, y, z);
335 inline bool formatsAreCompatible (const VkFormat format0, const VkFormat format1)
337 return format0 == format1 || mapVkFormat(format0).getPixelSize() == mapVkFormat(format1).getPixelSize();
340 void commandImageWriteBarrierBetweenShaderInvocations (Context& context, const VkCommandBuffer cmdBuffer, const VkImage image, const Texture& texture)
342 const DeviceInterface& vk = context.getDeviceInterface();
344 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, texture.numMipmapLevels(), 0u, texture.numLayers());
345 const VkImageMemoryBarrier shaderWriteBarrier = makeImageMemoryBarrier(
346 VK_ACCESS_SHADER_WRITE_BIT, 0u,
347 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_GENERAL,
348 image, fullImageSubresourceRange);
350 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &shaderWriteBarrier);
353 void commandBufferWriteBarrierBeforeHostRead (Context& context, const VkCommandBuffer cmdBuffer, const VkBuffer buffer, const VkDeviceSize bufferSizeBytes)
355 const DeviceInterface& vk = context.getDeviceInterface();
357 const VkBufferMemoryBarrier shaderWriteBarrier = makeBufferMemoryBarrier(
358 VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT,
359 buffer, 0ull, bufferSizeBytes);
361 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &shaderWriteBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
364 //! Copy all layers of an image to a buffer.
365 void commandCopyImageToBuffer (Context& context,
366 const VkCommandBuffer cmdBuffer,
368 const VkBuffer buffer,
369 const VkDeviceSize bufferSizeBytes,
370 const Texture& texture)
372 const DeviceInterface& vk = context.getDeviceInterface();
374 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, texture.numLayers());
375 const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier(
376 VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
377 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
378 image, fullImageSubresourceRange);
380 const VkBufferImageCopy copyRegion = makeBufferImageCopy(texture);
382 const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier(
383 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT,
384 buffer, 0ull, bufferSizeBytes);
386 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, 1, &prepareForTransferBarrier);
387 vk.cmdCopyImageToBuffer(cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer, 1u, ©Region);
388 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);
391 //! Copy all layers of a mipmap image to a buffer.
392 void commandCopyMipmapImageToBuffer (Context& context,
393 const VkCommandBuffer cmdBuffer,
395 const VkFormat imageFormat,
396 const VkBuffer buffer,
397 const VkDeviceSize bufferSizeBytes,
398 const Texture& texture)
400 const DeviceInterface& vk = context.getDeviceInterface();
402 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, texture.numMipmapLevels(), 0u, texture.numLayers());
403 const VkImageMemoryBarrier prepareForTransferBarrier = makeImageMemoryBarrier(
404 VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
405 VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
406 image, fullImageSubresourceRange);
408 std::vector<VkBufferImageCopy> copyRegions;
409 VkDeviceSize bufferOffset = 0u;
410 for (deInt32 levelNdx = 0; levelNdx < texture.numMipmapLevels(); levelNdx++)
412 const VkBufferImageCopy copyParams =
414 bufferOffset, // VkDeviceSize bufferOffset;
415 0u, // deUint32 bufferRowLength;
416 0u, // deUint32 bufferImageHeight;
417 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, 0u, texture.numLayers()), // VkImageSubresourceLayers imageSubresource;
418 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
419 makeExtent3D(texture.layerSize(levelNdx)), // VkExtent3D imageExtent;
421 copyRegions.push_back(copyParams);
422 bufferOffset += getMipmapLevelImageSizeBytes(texture, imageFormat, levelNdx);
425 const VkBufferMemoryBarrier copyBarrier = makeBufferMemoryBarrier(
426 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT,
427 buffer, 0ull, bufferSizeBytes);
429 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, 1, &prepareForTransferBarrier);
430 vk.cmdCopyImageToBuffer(cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer, (deUint32) copyRegions.size(), copyRegions.data());
431 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);
434 class StoreTest : public TestCase
439 FLAG_SINGLE_LAYER_BIND = 0x1, //!< Run the shader multiple times, each time binding a different layer.
440 FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER = 0x2, //!< Declare the format of the images in the shader code
441 FLAG_MINALIGN = 0x4, //!< Use bufferview offset that matches the advertised minimum alignment
444 StoreTest (tcu::TestContext& testCtx,
445 const std::string& name,
446 const std::string& description,
447 const Texture& texture,
448 const VkFormat format,
449 const deUint32 flags = FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER);
451 virtual void checkSupport (Context& context) const;
452 void initPrograms (SourceCollections& programCollection) const;
453 TestInstance* createInstance (Context& context) const;
456 const Texture m_texture;
457 const VkFormat m_format;
458 const bool m_declareImageFormatInShader;
459 const bool m_singleLayerBind;
460 const bool m_minalign;
463 StoreTest::StoreTest (tcu::TestContext& testCtx,
464 const std::string& name,
465 const std::string& description,
466 const Texture& texture,
467 const VkFormat format,
468 const deUint32 flags)
469 : TestCase (testCtx, name, description)
470 , m_texture (texture)
472 , m_declareImageFormatInShader ((flags & FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER) != 0)
473 , m_singleLayerBind ((flags & FLAG_SINGLE_LAYER_BIND) != 0)
474 , m_minalign ((flags & FLAG_MINALIGN) != 0)
476 if (m_singleLayerBind)
477 DE_ASSERT(m_texture.numLayers() > 1);
480 void StoreTest::checkSupport (Context& context) const
482 const VkFormatProperties formatProperties (getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), m_format));
484 if (!m_declareImageFormatInShader)
485 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT);
487 if (m_texture.type() == IMAGE_TYPE_CUBE_ARRAY)
488 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_IMAGE_CUBE_ARRAY);
490 if ((m_texture.type() != IMAGE_TYPE_BUFFER) && !(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
491 TCU_THROW(NotSupportedError, "Format not supported for storage images");
493 if (m_texture.type() == IMAGE_TYPE_BUFFER && !(formatProperties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT))
494 TCU_THROW(NotSupportedError, "Format not supported for storage texel buffers");
497 void StoreTest::initPrograms (SourceCollections& programCollection) const
499 const float storeColorScale = computeStoreColorScale(m_format, m_texture.size());
500 const float storeColorBias = computeStoreColorBias(m_format);
501 DE_ASSERT(colorScaleAndBiasAreValid(m_format, storeColorScale, storeColorBias));
503 const deUint32 xMax = m_texture.size().x() - 1;
504 const deUint32 yMax = m_texture.size().y() - 1;
505 const std::string signednessPrefix = isUintFormat(m_format) ? "u" : isIntFormat(m_format) ? "i" : "";
506 const bool storeNegativeValues = isSignedFormat(m_format) && (storeColorBias == 0);
507 bool useClamp = false;
508 std::string colorBaseExpr = signednessPrefix + "vec4("
510 + "(" + de::toString(xMax) + "-gx)^gy^gz, "
511 + "gx^(" + de::toString(yMax) + "-gy)^gz, "
512 + "(" + de::toString(xMax) + "-gx)^(" + de::toString(yMax) + "-gy)^gz)";
514 // Large integer values may not be represented with formats with low bit depths
515 if (isIntegerFormat(m_format))
517 const deInt64 minStoreValue = storeNegativeValues ? 0 - deRoundFloatToInt64((float)de::max(xMax, yMax) / 2.0f) : 0;
518 const deInt64 maxStoreValue = storeNegativeValues ? deRoundFloatToInt64((float)de::max(xMax, yMax) / 2.0f) : de::max(xMax, yMax);
520 useClamp = !isRepresentableIntegerValue(tcu::Vector<deInt64, 4>(minStoreValue), mapVkFormat(m_format)) ||
521 !isRepresentableIntegerValue(tcu::Vector<deInt64, 4>(maxStoreValue), mapVkFormat(m_format));
524 // Clamp if integer value cannot be represented with the current format
527 const tcu::IVec4 bitDepths = tcu::getTextureFormatBitDepth(mapVkFormat(m_format));
528 tcu::IVec4 minRepresentableValue;
529 tcu::IVec4 maxRepresentableValue;
531 switch (tcu::getTextureChannelClass(mapVkFormat(m_format).type))
533 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
535 minRepresentableValue = tcu::IVec4(0);
536 maxRepresentableValue = (tcu::IVec4(1) << bitDepths) - tcu::IVec4(1);
540 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
542 minRepresentableValue = -(tcu::IVec4(1) << bitDepths - tcu::IVec4(1));
543 maxRepresentableValue = (tcu::IVec4(1) << (bitDepths - tcu::IVec4(1))) - tcu::IVec4(1);
548 DE_ASSERT(isIntegerFormat(m_format));
551 colorBaseExpr = "clamp(" + colorBaseExpr + ", "
552 + signednessPrefix + "vec4" + de::toString(minRepresentableValue) + ", "
553 + signednessPrefix + "vec4" + de::toString(maxRepresentableValue) + ")";
556 std::string colorExpr = colorBaseExpr + (storeColorScale == 1.0f ? "" : "*" + de::toString(storeColorScale))
557 + (storeColorBias == 0.0f ? "" : " + float(" + de::toString(storeColorBias) + ")");
559 if (storeNegativeValues)
560 colorExpr += "-" + de::toString(deRoundFloatToInt32((float)deMax32(xMax, yMax) / 2.0f));
562 const int dimension = (m_singleLayerBind ? m_texture.layerDimension() : m_texture.dimension());
563 const std::string texelCoordStr = (dimension == 1 ? "gx" : dimension == 2 ? "ivec2(gx, gy)" : dimension == 3 ? "ivec3(gx, gy, gz)" : "");
565 const ImageType usedImageType = (m_singleLayerBind ? getImageTypeForSingleLayer(m_texture.type()) : m_texture.type());
566 const std::string imageTypeStr = getShaderImageType(mapVkFormat(m_format), usedImageType);
568 std::ostringstream src;
569 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
571 << "layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n";
572 if (m_declareImageFormatInShader)
574 const std::string formatQualifierStr = getShaderImageFormatQualifier(mapVkFormat(m_format));
575 src << "layout (binding = 0, " << formatQualifierStr << ") writeonly uniform " << imageTypeStr << " u_image;\n";
578 src << "layout (binding = 0) writeonly uniform " << imageTypeStr << " u_image;\n";
580 if (m_singleLayerBind)
581 src << "layout (binding = 1) readonly uniform Constants {\n"
582 << " int u_layerNdx;\n"
586 << "void main (void)\n"
588 << " int gx = int(gl_GlobalInvocationID.x);\n"
589 << " int gy = int(gl_GlobalInvocationID.y);\n"
590 << " int gz = " << (m_singleLayerBind ? "u_layerNdx" : "int(gl_GlobalInvocationID.z)") << ";\n"
591 << " imageStore(u_image, " << texelCoordStr << ", " << colorExpr << ");\n"
594 programCollection.glslSources.add("comp") << glu::ComputeSource(src.str());
597 //! Generic test iteration algorithm for image tests
598 class BaseTestInstance : public TestInstance
601 BaseTestInstance (Context& context,
602 const Texture& texture,
603 const VkFormat format,
604 const bool declareImageFormatInShader,
605 const bool singleLayerBind,
607 const bool bufferLoadUniform);
609 tcu::TestStatus iterate (void);
611 virtual ~BaseTestInstance (void) {}
614 virtual VkDescriptorSetLayout prepareDescriptors (void) = 0;
615 virtual tcu::TestStatus verifyResult (void) = 0;
617 virtual void commandBeforeCompute (const VkCommandBuffer cmdBuffer) = 0;
618 virtual void commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer) = 0;
619 virtual void commandAfterCompute (const VkCommandBuffer cmdBuffer) = 0;
621 virtual void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
622 const VkPipelineLayout pipelineLayout,
623 const int layerNdx) = 0;
624 virtual deUint32 getViewOffset (Context& context,
625 const VkFormat format,
628 const Texture m_texture;
629 const VkFormat m_format;
630 const bool m_declareImageFormatInShader;
631 const bool m_singleLayerBind;
632 const bool m_minalign;
633 const bool m_bufferLoadUniform;
634 const deUint32 m_srcViewOffset;
635 const deUint32 m_dstViewOffset;
638 BaseTestInstance::BaseTestInstance (Context& context, const Texture& texture, const VkFormat format, const bool declareImageFormatInShader, const bool singleLayerBind, const bool minalign, const bool bufferLoadUniform)
639 : TestInstance (context)
640 , m_texture (texture)
642 , m_declareImageFormatInShader (declareImageFormatInShader)
643 , m_singleLayerBind (singleLayerBind)
644 , m_minalign (minalign)
645 , m_bufferLoadUniform (bufferLoadUniform)
646 , m_srcViewOffset (getViewOffset(context, format, m_bufferLoadUniform))
647 , m_dstViewOffset (getViewOffset(context, formatHasThreeComponents(format) ? getSingleComponentFormat(format) : format, false))
651 tcu::TestStatus BaseTestInstance::iterate (void)
653 const DeviceInterface& vk = m_context.getDeviceInterface();
654 const VkDevice device = m_context.getDevice();
655 const VkQueue queue = m_context.getUniversalQueue();
656 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
658 const Unique<VkShaderModule> shaderModule(createShaderModule(vk, device, m_context.getBinaryCollection().get("comp"), 0));
660 const VkDescriptorSetLayout descriptorSetLayout = prepareDescriptors();
661 const Unique<VkPipelineLayout> pipelineLayout(makePipelineLayout(vk, device, descriptorSetLayout));
662 const Unique<VkPipeline> pipeline(makeComputePipeline(vk, device, *pipelineLayout, *shaderModule));
664 const Unique<VkCommandPool> cmdPool(createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex));
665 const Unique<VkCommandBuffer> cmdBuffer(allocateCommandBuffer(vk, device, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY));
667 beginCommandBuffer(vk, *cmdBuffer);
669 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline);
670 commandBeforeCompute(*cmdBuffer);
672 const tcu::IVec3 workSize = (m_singleLayerBind ? m_texture.layerSize() : m_texture.size());
673 const int loopNumLayers = (m_singleLayerBind ? m_texture.numLayers() : 1);
674 for (int layerNdx = 0; layerNdx < loopNumLayers; ++layerNdx)
676 commandBindDescriptorsForLayer(*cmdBuffer, *pipelineLayout, layerNdx);
679 commandBetweenShaderInvocations(*cmdBuffer);
681 vk.cmdDispatch(*cmdBuffer, workSize.x(), workSize.y(), workSize.z());
684 commandAfterCompute(*cmdBuffer);
686 endCommandBuffer(vk, *cmdBuffer);
688 submitCommandsAndWait(vk, device, queue, *cmdBuffer);
690 return verifyResult();
693 //! Base store test implementation
694 class StoreTestInstance : public BaseTestInstance
697 StoreTestInstance (Context& context,
698 const Texture& texture,
699 const VkFormat format,
700 const bool declareImageFormatInShader,
701 const bool singleLayerBind,
702 const bool minalign);
705 virtual tcu::TestStatus verifyResult (void);
707 // Add empty implementations for functions that might be not needed
708 void commandBeforeCompute (const VkCommandBuffer) {}
709 void commandBetweenShaderInvocations (const VkCommandBuffer) {}
710 void commandAfterCompute (const VkCommandBuffer) {}
712 de::MovePtr<Buffer> m_imageBuffer;
713 const VkDeviceSize m_imageSizeBytes;
716 deUint32 BaseTestInstance::getViewOffset(Context& context,
717 const VkFormat format,
722 if (!context.getTexelBufferAlignmentFeaturesEXT().texelBufferAlignment)
723 return (deUint32)context.getDeviceProperties().limits.minTexelBufferOffsetAlignment;
725 VkPhysicalDeviceTexelBufferAlignmentPropertiesEXT alignmentProperties;
726 deMemset(&alignmentProperties, 0, sizeof(alignmentProperties));
727 alignmentProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_PROPERTIES_EXT;
729 VkPhysicalDeviceProperties2 properties2;
730 deMemset(&properties2, 0, sizeof(properties2));
731 properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
732 properties2.pNext = &alignmentProperties;
734 context.getInstanceInterface().getPhysicalDeviceProperties2(context.getPhysicalDevice(), &properties2);
736 VkBool32 singleTexelAlignment = uniform ? alignmentProperties.uniformTexelBufferOffsetSingleTexelAlignment :
737 alignmentProperties.storageTexelBufferOffsetSingleTexelAlignment;
738 VkDeviceSize align = uniform ? alignmentProperties.uniformTexelBufferOffsetAlignmentBytes :
739 alignmentProperties.storageTexelBufferOffsetAlignmentBytes;
741 VkDeviceSize texelSize = formatHasThreeComponents(format) ? tcu::getChannelSize(vk::mapVkFormat(format).type) : tcu::getPixelSize(vk::mapVkFormat(format));
743 if (singleTexelAlignment)
744 align = de::min(align, texelSize);
746 return (deUint32)align;
752 StoreTestInstance::StoreTestInstance (Context& context, const Texture& texture, const VkFormat format, const bool declareImageFormatInShader, const bool singleLayerBind, const bool minalign)
753 : BaseTestInstance (context, texture, format, declareImageFormatInShader, singleLayerBind, minalign, false)
754 , m_imageSizeBytes (getImageSizeBytes(texture.size(), format))
756 const DeviceInterface& vk = m_context.getDeviceInterface();
757 const VkDevice device = m_context.getDevice();
758 Allocator& allocator = m_context.getDefaultAllocator();
760 // A helper buffer with enough space to hold the whole image. Usage flags accommodate all derived test instances.
762 m_imageBuffer = de::MovePtr<Buffer>(new Buffer(
763 vk, device, allocator,
764 makeBufferCreateInfo(m_imageSizeBytes + m_dstViewOffset, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT),
765 MemoryRequirement::HostVisible));
768 tcu::TestStatus StoreTestInstance::verifyResult (void)
770 const DeviceInterface& vk = m_context.getDeviceInterface();
771 const VkDevice device = m_context.getDevice();
773 const tcu::IVec3 imageSize = m_texture.size();
774 const tcu::TextureLevel reference = generateReferenceImage(imageSize, m_format);
776 const Allocation& alloc = m_imageBuffer->getAllocation();
777 invalidateAlloc(vk, device, alloc);
778 const tcu::ConstPixelBufferAccess result(mapVkFormat(m_format), imageSize, (const char *)alloc.getHostPtr() + m_dstViewOffset);
780 if (comparePixelBuffers(m_context.getTestContext().getLog(), m_texture, m_format, reference.getAccess(), result))
781 return tcu::TestStatus::pass("Passed");
783 return tcu::TestStatus::fail("Image comparison failed");
786 //! Store test for images
787 class ImageStoreTestInstance : public StoreTestInstance
790 ImageStoreTestInstance (Context& context,
791 const Texture& texture,
792 const VkFormat format,
793 const bool declareImageFormatInShader,
794 const bool singleLayerBind,
795 const bool minalign);
798 VkDescriptorSetLayout prepareDescriptors (void);
799 void commandBeforeCompute (const VkCommandBuffer cmdBuffer);
800 void commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer);
801 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
803 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
804 const VkPipelineLayout pipelineLayout,
807 de::MovePtr<Image> m_image;
808 de::MovePtr<Buffer> m_constantsBuffer;
809 const VkDeviceSize m_constantsBufferChunkSizeBytes;
810 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
811 Move<VkDescriptorPool> m_descriptorPool;
812 std::vector<SharedVkDescriptorSet> m_allDescriptorSets;
813 std::vector<SharedVkImageView> m_allImageViews;
816 ImageStoreTestInstance::ImageStoreTestInstance (Context& context,
817 const Texture& texture,
818 const VkFormat format,
819 const bool declareImageFormatInShader,
820 const bool singleLayerBind,
822 : StoreTestInstance (context, texture, format, declareImageFormatInShader, singleLayerBind, minalign)
823 , m_constantsBufferChunkSizeBytes (getOptimalUniformBufferChunkSize(context.getInstanceInterface(), context.getPhysicalDevice(), sizeof(deUint32)))
824 , m_allDescriptorSets (texture.numLayers())
825 , m_allImageViews (texture.numLayers())
827 const DeviceInterface& vk = m_context.getDeviceInterface();
828 const VkDevice device = m_context.getDevice();
829 Allocator& allocator = m_context.getDefaultAllocator();
831 m_image = de::MovePtr<Image>(new Image(
832 vk, device, allocator,
833 makeImageCreateInfo(m_texture, m_format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0u),
834 MemoryRequirement::Any));
836 // This buffer will be used to pass constants to the shader
838 const int numLayers = m_texture.numLayers();
839 const VkDeviceSize constantsBufferSizeBytes = numLayers * m_constantsBufferChunkSizeBytes;
840 m_constantsBuffer = de::MovePtr<Buffer>(new Buffer(
841 vk, device, allocator,
842 makeBufferCreateInfo(constantsBufferSizeBytes, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT),
843 MemoryRequirement::HostVisible));
846 const Allocation& alloc = m_constantsBuffer->getAllocation();
847 deUint8* const basePtr = static_cast<deUint8*>(alloc.getHostPtr());
849 deMemset(alloc.getHostPtr(), 0, static_cast<size_t>(constantsBufferSizeBytes));
851 for (int layerNdx = 0; layerNdx < numLayers; ++layerNdx)
853 deUint32* valuePtr = reinterpret_cast<deUint32*>(basePtr + layerNdx * m_constantsBufferChunkSizeBytes);
854 *valuePtr = static_cast<deUint32>(layerNdx);
857 flushAlloc(vk, device, alloc);
861 VkDescriptorSetLayout ImageStoreTestInstance::prepareDescriptors (void)
863 const DeviceInterface& vk = m_context.getDeviceInterface();
864 const VkDevice device = m_context.getDevice();
866 const int numLayers = m_texture.numLayers();
867 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
868 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
869 .addSingleBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
872 m_descriptorPool = DescriptorPoolBuilder()
873 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, numLayers)
874 .addType(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, numLayers)
875 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, numLayers);
877 if (m_singleLayerBind)
879 for (int layerNdx = 0; layerNdx < numLayers; ++layerNdx)
881 m_allDescriptorSets[layerNdx] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
882 m_allImageViews[layerNdx] = makeVkSharedPtr(makeImageView(
883 vk, device, m_image->get(), mapImageViewType(getImageTypeForSingleLayer(m_texture.type())), m_format,
884 makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, layerNdx, 1u)));
887 else // bind all layers at once
889 m_allDescriptorSets[0] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
890 m_allImageViews[0] = makeVkSharedPtr(makeImageView(
891 vk, device, m_image->get(), mapImageViewType(m_texture.type()), m_format,
892 makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, numLayers)));
895 return *m_descriptorSetLayout; // not passing the ownership
898 void ImageStoreTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
900 const DeviceInterface& vk = m_context.getDeviceInterface();
901 const VkDevice device = m_context.getDevice();
903 const VkDescriptorSet descriptorSet = **m_allDescriptorSets[layerNdx];
904 const VkImageView imageView = **m_allImageViews[layerNdx];
906 const VkDescriptorImageInfo descriptorImageInfo = makeDescriptorImageInfo(DE_NULL, imageView, VK_IMAGE_LAYOUT_GENERAL);
908 // Set the next chunk of the constants buffer. Each chunk begins with layer index that we've set before.
909 const VkDescriptorBufferInfo descriptorConstantsBufferInfo = makeDescriptorBufferInfo(
910 m_constantsBuffer->get(), layerNdx*m_constantsBufferChunkSizeBytes, m_constantsBufferChunkSizeBytes);
912 DescriptorSetUpdateBuilder()
913 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorImageInfo)
914 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &descriptorConstantsBufferInfo)
916 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
919 void ImageStoreTestInstance::commandBeforeCompute (const VkCommandBuffer cmdBuffer)
921 const DeviceInterface& vk = m_context.getDeviceInterface();
923 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, m_texture.numLayers());
924 const VkImageMemoryBarrier setImageLayoutBarrier = makeImageMemoryBarrier(
925 0u, VK_ACCESS_SHADER_WRITE_BIT,
926 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL,
927 m_image->get(), fullImageSubresourceRange);
929 const VkDeviceSize constantsBufferSize = m_texture.numLayers() * m_constantsBufferChunkSizeBytes;
930 const VkBufferMemoryBarrier writeConstantsBarrier = makeBufferMemoryBarrier(
931 VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
932 m_constantsBuffer->get(), 0ull, constantsBufferSize);
934 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &writeConstantsBarrier, 1, &setImageLayoutBarrier);
937 void ImageStoreTestInstance::commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer)
939 commandImageWriteBarrierBetweenShaderInvocations(m_context, cmdBuffer, m_image->get(), m_texture);
942 void ImageStoreTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
944 commandCopyImageToBuffer(m_context, cmdBuffer, m_image->get(), m_imageBuffer->get(), m_imageSizeBytes, m_texture);
947 //! Store test for buffers
948 class BufferStoreTestInstance : public StoreTestInstance
951 BufferStoreTestInstance (Context& context,
952 const Texture& texture,
953 const VkFormat format,
954 const bool declareImageFormatInShader,
955 const bool minalign);
958 VkDescriptorSetLayout prepareDescriptors (void);
959 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
961 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
962 const VkPipelineLayout pipelineLayout,
965 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
966 Move<VkDescriptorPool> m_descriptorPool;
967 Move<VkDescriptorSet> m_descriptorSet;
968 Move<VkBufferView> m_bufferView;
971 BufferStoreTestInstance::BufferStoreTestInstance (Context& context,
972 const Texture& texture,
973 const VkFormat format,
974 const bool declareImageFormatInShader,
976 : StoreTestInstance(context, texture, format, declareImageFormatInShader, false, minalign)
980 VkDescriptorSetLayout BufferStoreTestInstance::prepareDescriptors (void)
982 const DeviceInterface& vk = m_context.getDeviceInterface();
983 const VkDevice device = m_context.getDevice();
985 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
986 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
989 m_descriptorPool = DescriptorPoolBuilder()
990 .addType(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
991 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
993 m_descriptorSet = makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout);
994 m_bufferView = makeBufferView(vk, device, m_imageBuffer->get(), m_format, m_dstViewOffset, m_imageSizeBytes);
996 return *m_descriptorSetLayout; // not passing the ownership
999 void BufferStoreTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
1001 DE_ASSERT(layerNdx == 0);
1004 const VkDevice device = m_context.getDevice();
1005 const DeviceInterface& vk = m_context.getDeviceInterface();
1007 DescriptorSetUpdateBuilder()
1008 .writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, &m_bufferView.get())
1009 .update(vk, device);
1010 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &m_descriptorSet.get(), 0u, DE_NULL);
1013 void BufferStoreTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
1015 commandBufferWriteBarrierBeforeHostRead(m_context, cmdBuffer, m_imageBuffer->get(), m_imageSizeBytes + m_dstViewOffset);
1018 class LoadStoreTest : public TestCase
1023 FLAG_SINGLE_LAYER_BIND = 1 << 0, //!< Run the shader multiple times, each time binding a different layer.
1024 FLAG_RESTRICT_IMAGES = 1 << 1, //!< If given, images in the shader will be qualified with "restrict".
1025 FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER = 1 << 2, //!< Declare the format of the images in the shader code
1026 FLAG_MINALIGN = 1 << 3, //!< Use bufferview offset that matches the advertised minimum alignment
1027 FLAG_UNIFORM_TEXEL_BUFFER = 1 << 4, //!< Load from a uniform texel buffer rather than a storage texel buffer
1030 LoadStoreTest (tcu::TestContext& testCtx,
1031 const std::string& name,
1032 const std::string& description,
1033 const Texture& texture,
1034 const VkFormat format,
1035 const VkFormat imageFormat,
1036 const deUint32 flags = FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER,
1037 const deBool imageLoadStoreLodAMD = DE_FALSE);
1039 virtual void checkSupport (Context& context) const;
1040 void initPrograms (SourceCollections& programCollection) const;
1041 TestInstance* createInstance (Context& context) const;
1044 const Texture m_texture;
1045 const VkFormat m_format; //!< Format as accessed in the shader
1046 const VkFormat m_imageFormat; //!< Storage format
1047 const bool m_declareImageFormatInShader; //!< Whether the shader will specify the format layout qualifier of the images
1048 const bool m_singleLayerBind;
1049 const bool m_restrictImages;
1050 const bool m_minalign;
1051 bool m_bufferLoadUniform;
1052 const deBool m_imageLoadStoreLodAMD;
1055 LoadStoreTest::LoadStoreTest (tcu::TestContext& testCtx,
1056 const std::string& name,
1057 const std::string& description,
1058 const Texture& texture,
1059 const VkFormat format,
1060 const VkFormat imageFormat,
1061 const deUint32 flags,
1062 const deBool imageLoadStoreLodAMD)
1063 : TestCase (testCtx, name, description)
1064 , m_texture (texture)
1066 , m_imageFormat (imageFormat)
1067 , m_declareImageFormatInShader ((flags & FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER) != 0)
1068 , m_singleLayerBind ((flags & FLAG_SINGLE_LAYER_BIND) != 0)
1069 , m_restrictImages ((flags & FLAG_RESTRICT_IMAGES) != 0)
1070 , m_minalign ((flags & FLAG_MINALIGN) != 0)
1071 , m_bufferLoadUniform ((flags & FLAG_UNIFORM_TEXEL_BUFFER) != 0)
1072 , m_imageLoadStoreLodAMD (imageLoadStoreLodAMD)
1074 if (m_singleLayerBind)
1075 DE_ASSERT(m_texture.numLayers() > 1);
1077 DE_ASSERT(formatsAreCompatible(m_format, m_imageFormat));
1080 void LoadStoreTest::checkSupport (Context& context) const
1082 const vk::VkFormatProperties formatProperties (vk::getPhysicalDeviceFormatProperties(context.getInstanceInterface(),
1083 context.getPhysicalDevice(),
1085 const vk::VkFormatProperties imageFormatProperties (vk::getPhysicalDeviceFormatProperties(context.getInstanceInterface(),
1086 context.getPhysicalDevice(),
1088 if (m_imageLoadStoreLodAMD)
1089 context.requireDeviceFunctionality("VK_AMD_shader_image_load_store_lod");
1091 if (!m_bufferLoadUniform && !m_declareImageFormatInShader)
1092 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT);
1094 if (m_texture.type() == IMAGE_TYPE_CUBE_ARRAY)
1095 context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_IMAGE_CUBE_ARRAY);
1097 if ((m_texture.type() != IMAGE_TYPE_BUFFER) && !(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
1098 TCU_THROW(NotSupportedError, "Format not supported for storage images");
1100 if (m_texture.type() == IMAGE_TYPE_BUFFER && !(formatProperties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT))
1101 TCU_THROW(NotSupportedError, "Format not supported for storage texel buffers");
1103 if ((m_texture.type() != IMAGE_TYPE_BUFFER) && !(imageFormatProperties.optimalTilingFeatures))
1104 TCU_THROW(NotSupportedError, "Underlying format not supported at all for images");
1106 if ((m_texture.type() == IMAGE_TYPE_BUFFER) && !(imageFormatProperties.bufferFeatures))
1107 TCU_THROW(NotSupportedError, "Underlying format not supported at all for buffers");
1109 if (formatHasThreeComponents(m_format))
1111 // When the source buffer is three-component, the destination buffer is single-component.
1112 VkFormat dstFormat = getSingleComponentFormat(m_format);
1113 const vk::VkFormatProperties dstFormatProperties (vk::getPhysicalDeviceFormatProperties(context.getInstanceInterface(),
1114 context.getPhysicalDevice(),
1117 if (m_texture.type() == IMAGE_TYPE_BUFFER && !(dstFormatProperties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT))
1118 TCU_THROW(NotSupportedError, "Format not supported for storage texel buffers");
1121 if (m_texture.type() == IMAGE_TYPE_BUFFER && !(formatProperties.bufferFeatures & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT))
1122 TCU_THROW(NotSupportedError, "Format not supported for storage texel buffers");
1124 if (m_bufferLoadUniform && m_texture.type() == IMAGE_TYPE_BUFFER && !(formatProperties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT))
1125 TCU_THROW(NotSupportedError, "Format not supported for uniform texel buffers");
1128 void LoadStoreTest::initPrograms (SourceCollections& programCollection) const
1130 const tcu::TextureFormat texFormat = mapVkFormat(m_format);
1131 const int dimension = (m_singleLayerBind ? m_texture.layerDimension() : m_texture.dimension());
1132 const ImageType usedImageType = (m_singleLayerBind ? getImageTypeForSingleLayer(m_texture.type()) : m_texture.type());
1133 const std::string formatQualifierStr = getShaderImageFormatQualifier(texFormat);
1134 const std::string uniformTypeStr = getFormatPrefix(texFormat) + "textureBuffer";
1135 const std::string imageTypeStr = getShaderImageType(texFormat, usedImageType);
1136 const std::string maybeRestrictStr = (m_restrictImages ? "restrict " : "");
1137 const std::string xMax = de::toString(m_texture.size().x() - 1);
1139 std::ostringstream src;
1140 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_450) << "\n"
1142 if (!m_declareImageFormatInShader)
1144 src << "#extension GL_EXT_shader_image_load_formatted : require\n";
1147 if (m_imageLoadStoreLodAMD)
1149 src << "#extension GL_AMD_shader_image_load_store_lod : require\n";
1152 src << "layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n";
1153 if (m_bufferLoadUniform)
1154 src << "layout (binding = 0) uniform " << uniformTypeStr << " u_image0;\n";
1155 else if (m_declareImageFormatInShader)
1156 src << "layout (binding = 0, " << formatQualifierStr << ") " << maybeRestrictStr << "readonly uniform " << imageTypeStr << " u_image0;\n";
1158 src << "layout (binding = 0) " << maybeRestrictStr << "readonly uniform " << imageTypeStr << " u_image0;\n";
1160 if (formatHasThreeComponents(m_format))
1161 src << "layout (binding = 1) " << maybeRestrictStr << "writeonly uniform " << imageTypeStr << " u_image1;\n";
1163 src << "layout (binding = 1, " << formatQualifierStr << ") " << maybeRestrictStr << "writeonly uniform " << imageTypeStr << " u_image1;\n";
1166 << "void main (void)\n"
1170 default: DE_ASSERT(0); // fallthrough
1172 if (m_bufferLoadUniform)
1174 // for three-component formats, the dst buffer is single-component and the shader
1175 // expands the store into 3 component-wise stores.
1176 std::string type = getFormatPrefix(texFormat) + "vec4";
1177 src << " int pos = int(gl_GlobalInvocationID.x);\n"
1178 " " << type << " t = texelFetch(u_image0, " + xMax + "-pos);\n";
1179 if (formatHasThreeComponents(m_format))
1181 src << " imageStore(u_image1, 3*pos+0, " << type << "(t.x));\n";
1182 src << " imageStore(u_image1, 3*pos+1, " << type << "(t.y));\n";
1183 src << " imageStore(u_image1, 3*pos+2, " << type << "(t.z));\n";
1186 src << " imageStore(u_image1, pos, t);\n";
1188 else if (m_imageLoadStoreLodAMD)
1191 " int pos = int(gl_GlobalInvocationID.x);\n";
1193 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1195 std::string xMaxSize = de::toString(deMax32(((m_texture.layerSize().x() >> levelNdx) - 1), 1u));
1196 src << " imageStoreLodAMD(u_image1, pos, " + de::toString(levelNdx) + ", imageLoadLodAMD(u_image0, " + xMaxSize + "-pos, " + de::toString(levelNdx) + "));\n";
1202 " int pos = int(gl_GlobalInvocationID.x);\n"
1203 " imageStore(u_image1, pos, imageLoad(u_image0, " + xMax + "-pos));\n";
1207 if (m_imageLoadStoreLodAMD)
1209 src << " ivec2 pos = ivec2(gl_GlobalInvocationID.xy);\n";
1211 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1213 std::string xMaxSize = de::toString(deMax32(((m_texture.layerSize().x() >> levelNdx) - 1), 1u));
1214 src << " imageStoreLodAMD(u_image1, pos, " + de::toString(levelNdx) + ", imageLoadLodAMD(u_image0, ivec2(" + xMaxSize + "-pos.x, pos.y), " + de::toString(levelNdx) + "));\n";
1221 " ivec2 pos = ivec2(gl_GlobalInvocationID.xy);\n"
1222 " imageStore(u_image1, pos, imageLoad(u_image0, ivec2(" + xMax + "-pos.x, pos.y)));\n";
1226 if (m_imageLoadStoreLodAMD)
1228 src << " ivec3 pos = ivec3(gl_GlobalInvocationID);\n";
1230 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1232 std::string xMaxSize = de::toString(deMax32(((m_texture.layerSize().x() >> levelNdx) - 1), 1u));
1233 src << " imageStoreLodAMD(u_image1, pos, " + de::toString(levelNdx) + ", imageLoadLodAMD(u_image0, ivec3(" + xMaxSize + "-pos.x, pos.y, pos.z), " + de::toString(levelNdx) + "));\n";
1239 " ivec3 pos = ivec3(gl_GlobalInvocationID);\n"
1240 " imageStore(u_image1, pos, imageLoad(u_image0, ivec3(" + xMax + "-pos.x, pos.y, pos.z)));\n";
1246 programCollection.glslSources.add("comp") << glu::ComputeSource(src.str());
1249 //! Load/store test base implementation
1250 class LoadStoreTestInstance : public BaseTestInstance
1253 LoadStoreTestInstance (Context& context,
1254 const Texture& texture,
1255 const VkFormat format,
1256 const VkFormat imageFormat,
1257 const bool declareImageFormatInShader,
1258 const bool singleLayerBind,
1259 const bool minalign,
1260 const bool bufferLoadUniform);
1263 virtual Buffer* getResultBuffer (void) const = 0; //!< Get the buffer that contains the result image
1265 tcu::TestStatus verifyResult (void);
1267 // Add empty implementations for functions that might be not needed
1268 void commandBeforeCompute (const VkCommandBuffer) {}
1269 void commandBetweenShaderInvocations (const VkCommandBuffer) {}
1270 void commandAfterCompute (const VkCommandBuffer) {}
1272 de::MovePtr<Buffer> m_imageBuffer; //!< Source data and helper buffer
1273 const VkDeviceSize m_imageSizeBytes;
1274 const VkFormat m_imageFormat; //!< Image format (for storage, may be different than texture format)
1275 tcu::TextureLevel m_referenceImage; //!< Used as input data and later to verify result image
1277 bool m_bufferLoadUniform;
1278 VkDescriptorType m_bufferLoadDescriptorType;
1279 VkBufferUsageFlagBits m_bufferLoadUsageBit;
1282 LoadStoreTestInstance::LoadStoreTestInstance (Context& context,
1283 const Texture& texture,
1284 const VkFormat format,
1285 const VkFormat imageFormat,
1286 const bool declareImageFormatInShader,
1287 const bool singleLayerBind,
1288 const bool minalign,
1289 const bool bufferLoadUniform)
1290 : BaseTestInstance (context, texture, format, declareImageFormatInShader, singleLayerBind, minalign, bufferLoadUniform)
1291 , m_imageSizeBytes (getImageSizeBytes(texture.size(), format))
1292 , m_imageFormat (imageFormat)
1293 , m_referenceImage (generateReferenceImage(texture.size(), imageFormat, format))
1294 , m_bufferLoadUniform (bufferLoadUniform)
1296 const DeviceInterface& vk = m_context.getDeviceInterface();
1297 const VkDevice device = m_context.getDevice();
1298 Allocator& allocator = m_context.getDefaultAllocator();
1300 m_bufferLoadDescriptorType = m_bufferLoadUniform ? VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER : VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1301 m_bufferLoadUsageBit = m_bufferLoadUniform ? VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT : VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1303 // A helper buffer with enough space to hold the whole image.
1305 m_imageBuffer = de::MovePtr<Buffer>(new Buffer(
1306 vk, device, allocator,
1307 makeBufferCreateInfo(m_imageSizeBytes + m_srcViewOffset, m_bufferLoadUsageBit | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT),
1308 MemoryRequirement::HostVisible));
1310 // Copy reference data to buffer for subsequent upload to image.
1312 const Allocation& alloc = m_imageBuffer->getAllocation();
1313 deMemcpy((char *)alloc.getHostPtr() + m_srcViewOffset, m_referenceImage.getAccess().getDataPtr(), static_cast<size_t>(m_imageSizeBytes));
1314 flushAlloc(vk, device, alloc);
1317 tcu::TestStatus LoadStoreTestInstance::verifyResult (void)
1319 const DeviceInterface& vk = m_context.getDeviceInterface();
1320 const VkDevice device = m_context.getDevice();
1322 // Apply the same transformation as done in the shader
1323 const tcu::PixelBufferAccess reference = m_referenceImage.getAccess();
1324 flipHorizontally(reference);
1326 const Allocation& alloc = getResultBuffer()->getAllocation();
1327 invalidateAlloc(vk, device, alloc);
1328 const tcu::ConstPixelBufferAccess result(mapVkFormat(m_imageFormat), m_texture.size(), (const char *)alloc.getHostPtr() + m_dstViewOffset);
1330 if (comparePixelBuffers(m_context.getTestContext().getLog(), m_texture, m_imageFormat, reference, result))
1331 return tcu::TestStatus::pass("Passed");
1333 return tcu::TestStatus::fail("Image comparison failed");
1336 //! Load/store test for images
1337 class ImageLoadStoreTestInstance : public LoadStoreTestInstance
1340 ImageLoadStoreTestInstance (Context& context,
1341 const Texture& texture,
1342 const VkFormat format,
1343 const VkFormat imageFormat,
1344 const bool declareImageFormatInShader,
1345 const bool singleLayerBind,
1346 const bool minalign,
1347 const bool bufferLoadUniform);
1350 VkDescriptorSetLayout prepareDescriptors (void);
1351 void commandBeforeCompute (const VkCommandBuffer cmdBuffer);
1352 void commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer);
1353 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
1355 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
1356 const VkPipelineLayout pipelineLayout,
1357 const int layerNdx);
1359 Buffer* getResultBuffer (void) const { return m_imageBuffer.get(); }
1361 de::MovePtr<Image> m_imageSrc;
1362 de::MovePtr<Image> m_imageDst;
1363 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1364 Move<VkDescriptorPool> m_descriptorPool;
1365 std::vector<SharedVkDescriptorSet> m_allDescriptorSets;
1366 std::vector<SharedVkImageView> m_allSrcImageViews;
1367 std::vector<SharedVkImageView> m_allDstImageViews;
1370 ImageLoadStoreTestInstance::ImageLoadStoreTestInstance (Context& context,
1371 const Texture& texture,
1372 const VkFormat format,
1373 const VkFormat imageFormat,
1374 const bool declareImageFormatInShader,
1375 const bool singleLayerBind,
1376 const bool minalign,
1377 const bool bufferLoadUniform)
1378 : LoadStoreTestInstance (context, texture, format, imageFormat, declareImageFormatInShader, singleLayerBind, minalign, bufferLoadUniform)
1379 , m_allDescriptorSets (texture.numLayers())
1380 , m_allSrcImageViews (texture.numLayers())
1381 , m_allDstImageViews (texture.numLayers())
1383 const DeviceInterface& vk = m_context.getDeviceInterface();
1384 const VkDevice device = m_context.getDevice();
1385 Allocator& allocator = m_context.getDefaultAllocator();
1386 const VkImageCreateFlags imageFlags = (m_format == m_imageFormat ? 0u : (VkImageCreateFlags)VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
1388 m_imageSrc = de::MovePtr<Image>(new Image(
1389 vk, device, allocator,
1390 makeImageCreateInfo(m_texture, m_imageFormat, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, imageFlags),
1391 MemoryRequirement::Any));
1393 m_imageDst = de::MovePtr<Image>(new Image(
1394 vk, device, allocator,
1395 makeImageCreateInfo(m_texture, m_imageFormat, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, imageFlags),
1396 MemoryRequirement::Any));
1399 VkDescriptorSetLayout ImageLoadStoreTestInstance::prepareDescriptors (void)
1401 const VkDevice device = m_context.getDevice();
1402 const DeviceInterface& vk = m_context.getDeviceInterface();
1404 const int numLayers = m_texture.numLayers();
1405 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
1406 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
1407 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
1410 m_descriptorPool = DescriptorPoolBuilder()
1411 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, numLayers)
1412 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, numLayers)
1413 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, numLayers);
1415 if (m_singleLayerBind)
1417 for (int layerNdx = 0; layerNdx < numLayers; ++layerNdx)
1419 const VkImageViewType viewType = mapImageViewType(getImageTypeForSingleLayer(m_texture.type()));
1420 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, layerNdx, 1u);
1422 m_allDescriptorSets[layerNdx] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
1423 m_allSrcImageViews[layerNdx] = makeVkSharedPtr(makeImageView(vk, device, m_imageSrc->get(), viewType, m_format, subresourceRange));
1424 m_allDstImageViews[layerNdx] = makeVkSharedPtr(makeImageView(vk, device, m_imageDst->get(), viewType, m_format, subresourceRange));
1427 else // bind all layers at once
1429 const VkImageViewType viewType = mapImageViewType(m_texture.type());
1430 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, numLayers);
1432 m_allDescriptorSets[0] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
1433 m_allSrcImageViews[0] = makeVkSharedPtr(makeImageView(vk, device, m_imageSrc->get(), viewType, m_format, subresourceRange));
1434 m_allDstImageViews[0] = makeVkSharedPtr(makeImageView(vk, device, m_imageDst->get(), viewType, m_format, subresourceRange));
1437 return *m_descriptorSetLayout; // not passing the ownership
1440 void ImageLoadStoreTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
1442 const VkDevice device = m_context.getDevice();
1443 const DeviceInterface& vk = m_context.getDeviceInterface();
1445 const VkDescriptorSet descriptorSet = **m_allDescriptorSets[layerNdx];
1446 const VkImageView srcImageView = **m_allSrcImageViews[layerNdx];
1447 const VkImageView dstImageView = **m_allDstImageViews[layerNdx];
1449 const VkDescriptorImageInfo descriptorSrcImageInfo = makeDescriptorImageInfo(DE_NULL, srcImageView, VK_IMAGE_LAYOUT_GENERAL);
1450 const VkDescriptorImageInfo descriptorDstImageInfo = makeDescriptorImageInfo(DE_NULL, dstImageView, VK_IMAGE_LAYOUT_GENERAL);
1452 DescriptorSetUpdateBuilder()
1453 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorSrcImageInfo)
1454 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorDstImageInfo)
1455 .update(vk, device);
1456 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
1459 void ImageLoadStoreTestInstance::commandBeforeCompute (const VkCommandBuffer cmdBuffer)
1461 const DeviceInterface& vk = m_context.getDeviceInterface();
1463 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, m_texture.numLayers());
1465 const VkImageMemoryBarrier preCopyImageBarriers[] =
1467 makeImageMemoryBarrier(
1468 0u, VK_ACCESS_TRANSFER_WRITE_BIT,
1469 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1470 m_imageSrc->get(), fullImageSubresourceRange),
1471 makeImageMemoryBarrier(
1472 0u, VK_ACCESS_SHADER_WRITE_BIT,
1473 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL,
1474 m_imageDst->get(), fullImageSubresourceRange)
1477 const VkBufferMemoryBarrier barrierFlushHostWriteBeforeCopy = makeBufferMemoryBarrier(
1478 VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1479 m_imageBuffer->get(), 0ull, m_imageSizeBytes + m_srcViewOffset);
1481 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
1482 (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &barrierFlushHostWriteBeforeCopy, DE_LENGTH_OF_ARRAY(preCopyImageBarriers), preCopyImageBarriers);
1485 const VkImageMemoryBarrier barrierAfterCopy = makeImageMemoryBarrier(
1486 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1487 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1488 m_imageSrc->get(), fullImageSubresourceRange);
1490 const VkBufferImageCopy copyRegion = makeBufferImageCopy(m_texture);
1492 vk.cmdCopyBufferToImage(cmdBuffer, m_imageBuffer->get(), m_imageSrc->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region);
1493 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &barrierAfterCopy);
1497 void ImageLoadStoreTestInstance::commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer)
1499 commandImageWriteBarrierBetweenShaderInvocations(m_context, cmdBuffer, m_imageDst->get(), m_texture);
1502 void ImageLoadStoreTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
1504 commandCopyImageToBuffer(m_context, cmdBuffer, m_imageDst->get(), m_imageBuffer->get(), m_imageSizeBytes, m_texture);
1507 //! Load/store Lod AMD test for images
1508 class ImageLoadStoreLodAMDTestInstance : public BaseTestInstance
1511 ImageLoadStoreLodAMDTestInstance (Context& context,
1512 const Texture& texture,
1513 const VkFormat format,
1514 const VkFormat imageFormat,
1515 const bool declareImageFormatInShader,
1516 const bool singleLayerBind,
1517 const bool minalign,
1518 const bool bufferLoadUniform);
1521 VkDescriptorSetLayout prepareDescriptors (void);
1522 void commandBeforeCompute (const VkCommandBuffer cmdBuffer);
1523 void commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer);
1524 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
1526 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
1527 const VkPipelineLayout pipelineLayout,
1528 const int layerNdx);
1530 Buffer* getResultBuffer (void) const { return m_imageBuffer.get(); }
1531 tcu::TestStatus verifyResult (void);
1533 de::MovePtr<Buffer> m_imageBuffer; //!< Source data and helper buffer
1534 const VkDeviceSize m_imageSizeBytes;
1535 const VkFormat m_imageFormat; //!< Image format (for storage, may be different than texture format)
1536 std::vector<tcu::TextureLevel> m_referenceImages; //!< Used as input data and later to verify result image
1538 bool m_bufferLoadUniform;
1539 VkDescriptorType m_bufferLoadDescriptorType;
1540 VkBufferUsageFlagBits m_bufferLoadUsageBit;
1542 de::MovePtr<Image> m_imageSrc;
1543 de::MovePtr<Image> m_imageDst;
1544 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1545 Move<VkDescriptorPool> m_descriptorPool;
1546 std::vector<SharedVkDescriptorSet> m_allDescriptorSets;
1547 std::vector<SharedVkImageView> m_allSrcImageViews;
1548 std::vector<SharedVkImageView> m_allDstImageViews;
1552 ImageLoadStoreLodAMDTestInstance::ImageLoadStoreLodAMDTestInstance (Context& context,
1553 const Texture& texture,
1554 const VkFormat format,
1555 const VkFormat imageFormat,
1556 const bool declareImageFormatInShader,
1557 const bool singleLayerBind,
1558 const bool minalign,
1559 const bool bufferLoadUniform)
1560 : BaseTestInstance (context, texture, format, declareImageFormatInShader, singleLayerBind, minalign, bufferLoadUniform)
1561 , m_imageSizeBytes (getMipmapImageTotalSizeBytes(texture, format))
1562 , m_imageFormat (imageFormat)
1563 , m_bufferLoadUniform (bufferLoadUniform)
1564 , m_allDescriptorSets (texture.numLayers())
1565 , m_allSrcImageViews (texture.numLayers())
1566 , m_allDstImageViews (texture.numLayers())
1568 const DeviceInterface& vk = m_context.getDeviceInterface();
1569 const VkDevice device = m_context.getDevice();
1570 Allocator& allocator = m_context.getDefaultAllocator();
1571 const VkImageCreateFlags imageFlags = (m_format == m_imageFormat ? 0u : (VkImageCreateFlags)VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT);
1573 const VkSampleCountFlagBits samples = static_cast<VkSampleCountFlagBits>(m_texture.numSamples()); // integer and bit mask are aligned, so we can cast like this
1575 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1577 tcu::TextureLevel referenceImage = generateReferenceImage(texture.size(levelNdx), imageFormat, format);
1578 m_referenceImages.push_back(referenceImage);
1581 m_bufferLoadDescriptorType = m_bufferLoadUniform ? VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER : VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
1582 m_bufferLoadUsageBit = m_bufferLoadUniform ? VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT : VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
1584 // A helper buffer with enough space to hold the whole image.
1585 m_imageBuffer = de::MovePtr<Buffer>(new Buffer(
1586 vk, device, allocator,
1587 makeBufferCreateInfo(m_imageSizeBytes + m_srcViewOffset, m_bufferLoadUsageBit | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT),
1588 MemoryRequirement::HostVisible));
1590 // Copy reference data to buffer for subsequent upload to image.
1592 const Allocation& alloc = m_imageBuffer->getAllocation();
1593 VkDeviceSize bufferOffset = 0u;
1594 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1596 deMemcpy((char *)alloc.getHostPtr() + m_srcViewOffset + bufferOffset, m_referenceImages[levelNdx].getAccess().getDataPtr(), static_cast<size_t>(getMipmapLevelImageSizeBytes(m_texture, m_imageFormat, levelNdx)));
1597 bufferOffset += getMipmapLevelImageSizeBytes(m_texture, m_imageFormat, levelNdx);
1599 flushAlloc(vk, device, alloc);
1603 const VkImageCreateInfo imageParamsSrc =
1605 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1606 DE_NULL, // const void* pNext;
1607 (isCube(m_texture) ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0u) | imageFlags, // VkImageCreateFlags flags;
1608 mapImageType(m_texture.type()), // VkImageType imageType;
1609 m_imageFormat, // VkFormat format;
1610 makeExtent3D(m_texture.layerSize()), // VkExtent3D extent;
1611 (deUint32)m_texture.numMipmapLevels(), // deUint32 mipLevels;
1612 (deUint32)m_texture.numLayers(), // deUint32 arrayLayers;
1613 samples, // VkSampleCountFlagBits samples;
1614 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1615 VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1616 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1617 0u, // deUint32 queueFamilyIndexCount;
1618 DE_NULL, // const deUint32* pQueueFamilyIndices;
1619 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1622 m_imageSrc = de::MovePtr<Image>(new Image(
1623 vk, device, allocator,
1625 MemoryRequirement::Any));
1629 const VkImageCreateInfo imageParamsDst =
1631 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1632 DE_NULL, // const void* pNext;
1633 (isCube(m_texture) ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0u) | imageFlags, // VkImageCreateFlags flags;
1634 mapImageType(m_texture.type()), // VkImageType imageType;
1635 m_imageFormat, // VkFormat format;
1636 makeExtent3D(m_texture.layerSize()), // VkExtent3D extent;
1637 (deUint32)m_texture.numMipmapLevels(), // deUint32 mipLevels;
1638 (deUint32)m_texture.numLayers(), // deUint32 arrayLayers;
1639 samples, // VkSampleCountFlagBits samples;
1640 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1641 VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
1642 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1643 0u, // deUint32 queueFamilyIndexCount;
1644 DE_NULL, // const deUint32* pQueueFamilyIndices;
1645 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1648 m_imageDst = de::MovePtr<Image>(new Image(
1649 vk, device, allocator,
1651 MemoryRequirement::Any));
1655 tcu::TestStatus ImageLoadStoreLodAMDTestInstance::verifyResult (void)
1657 const DeviceInterface& vk = m_context.getDeviceInterface();
1658 const VkDevice device = m_context.getDevice();
1660 const Allocation& alloc = getResultBuffer()->getAllocation();
1661 invalidateAlloc(vk, device, alloc);
1663 VkDeviceSize bufferOffset = 0;
1664 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1666 // Apply the same transformation as done in the shader
1667 const tcu::PixelBufferAccess reference = m_referenceImages[levelNdx].getAccess();
1668 flipHorizontally(reference);
1670 const tcu::ConstPixelBufferAccess result(mapVkFormat(m_imageFormat), m_texture.size(levelNdx), (const char *)alloc.getHostPtr() + m_dstViewOffset + bufferOffset);
1672 if (!comparePixelBuffers(m_context.getTestContext().getLog(), m_texture, m_imageFormat, reference, result, levelNdx))
1674 std::ostringstream errorMessage;
1675 errorMessage << "Image Level " << levelNdx << " comparison failed";
1676 return tcu::TestStatus::fail(errorMessage.str());
1678 bufferOffset += getMipmapLevelImageSizeBytes(m_texture, m_imageFormat, levelNdx);
1681 return tcu::TestStatus::pass("Passed");
1684 VkDescriptorSetLayout ImageLoadStoreLodAMDTestInstance::prepareDescriptors (void)
1686 const VkDevice device = m_context.getDevice();
1687 const DeviceInterface& vk = m_context.getDeviceInterface();
1689 const int numLayers = m_texture.numLayers();
1690 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
1691 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
1692 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
1695 m_descriptorPool = DescriptorPoolBuilder()
1696 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, numLayers)
1697 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, numLayers)
1698 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, numLayers);
1700 if (m_singleLayerBind)
1702 for (int layerNdx = 0; layerNdx < numLayers; ++layerNdx)
1704 const VkImageViewType viewType = mapImageViewType(getImageTypeForSingleLayer(m_texture.type()));
1705 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, m_texture.numMipmapLevels(), layerNdx, 1u);
1707 m_allDescriptorSets[layerNdx] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
1708 m_allSrcImageViews[layerNdx] = makeVkSharedPtr(makeImageView(vk, device, m_imageSrc->get(), viewType, m_format, subresourceRange));
1709 m_allDstImageViews[layerNdx] = makeVkSharedPtr(makeImageView(vk, device, m_imageDst->get(), viewType, m_format, subresourceRange));
1712 else // bind all layers at once
1714 const VkImageViewType viewType = mapImageViewType(m_texture.type());
1715 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, m_texture.numMipmapLevels(), 0u, numLayers);
1717 m_allDescriptorSets[0] = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
1718 m_allSrcImageViews[0] = makeVkSharedPtr(makeImageView(vk, device, m_imageSrc->get(), viewType, m_format, subresourceRange));
1719 m_allDstImageViews[0] = makeVkSharedPtr(makeImageView(vk, device, m_imageDst->get(), viewType, m_format, subresourceRange));
1722 return *m_descriptorSetLayout; // not passing the ownership
1725 void ImageLoadStoreLodAMDTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
1727 const VkDevice device = m_context.getDevice();
1728 const DeviceInterface& vk = m_context.getDeviceInterface();
1730 const VkDescriptorSet descriptorSet = **m_allDescriptorSets[layerNdx];
1731 const VkImageView srcImageView = **m_allSrcImageViews[layerNdx];
1732 const VkImageView dstImageView = **m_allDstImageViews[layerNdx];
1734 const VkDescriptorImageInfo descriptorSrcImageInfo = makeDescriptorImageInfo(DE_NULL, srcImageView, VK_IMAGE_LAYOUT_GENERAL);
1735 const VkDescriptorImageInfo descriptorDstImageInfo = makeDescriptorImageInfo(DE_NULL, dstImageView, VK_IMAGE_LAYOUT_GENERAL);
1737 DescriptorSetUpdateBuilder()
1738 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorSrcImageInfo)
1739 .writeSingle(descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorDstImageInfo)
1740 .update(vk, device);
1741 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
1744 void ImageLoadStoreLodAMDTestInstance::commandBeforeCompute (const VkCommandBuffer cmdBuffer)
1746 const DeviceInterface& vk = m_context.getDeviceInterface();
1747 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, m_texture.numMipmapLevels(), 0u, m_texture.numLayers());
1749 const VkImageMemoryBarrier preCopyImageBarriers[] =
1751 makeImageMemoryBarrier(
1752 0u, VK_ACCESS_TRANSFER_WRITE_BIT,
1753 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1754 m_imageSrc->get(), fullImageSubresourceRange),
1755 makeImageMemoryBarrier(
1756 0u, VK_ACCESS_SHADER_WRITE_BIT,
1757 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL,
1758 m_imageDst->get(), fullImageSubresourceRange)
1761 const VkBufferMemoryBarrier barrierFlushHostWriteBeforeCopy = makeBufferMemoryBarrier(
1762 VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
1763 m_imageBuffer->get(), 0ull, m_imageSizeBytes + m_srcViewOffset);
1765 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
1766 (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &barrierFlushHostWriteBeforeCopy, DE_LENGTH_OF_ARRAY(preCopyImageBarriers), preCopyImageBarriers);
1769 const VkImageMemoryBarrier barrierAfterCopy = makeImageMemoryBarrier(
1770 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
1771 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
1772 m_imageSrc->get(), fullImageSubresourceRange);
1774 std::vector<VkBufferImageCopy> copyRegions;
1775 VkDeviceSize bufferOffset = 0u;
1776 for (deInt32 levelNdx = 0; levelNdx < m_texture.numMipmapLevels(); levelNdx++)
1778 const VkBufferImageCopy copyParams =
1780 bufferOffset, // VkDeviceSize bufferOffset;
1781 0u, // deUint32 bufferRowLength;
1782 0u, // deUint32 bufferImageHeight;
1783 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, levelNdx, 0u, m_texture.numLayers()), // VkImageSubresourceLayers imageSubresource;
1784 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
1785 makeExtent3D(m_texture.layerSize(levelNdx)), // VkExtent3D imageExtent;
1787 copyRegions.push_back(copyParams);
1788 bufferOffset += getMipmapLevelImageSizeBytes(m_texture, m_imageFormat, levelNdx);
1791 vk.cmdCopyBufferToImage(cmdBuffer, m_imageBuffer->get(), m_imageSrc->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32) copyRegions.size(), copyRegions.data());
1792 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &barrierAfterCopy);
1796 void ImageLoadStoreLodAMDTestInstance::commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer)
1798 commandImageWriteBarrierBetweenShaderInvocations(m_context, cmdBuffer, m_imageDst->get(), m_texture);
1801 void ImageLoadStoreLodAMDTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
1803 commandCopyMipmapImageToBuffer(m_context, cmdBuffer, m_imageDst->get(), m_imageFormat, m_imageBuffer->get(), m_imageSizeBytes, m_texture);
1806 //! Load/store test for buffers
1807 class BufferLoadStoreTestInstance : public LoadStoreTestInstance
1810 BufferLoadStoreTestInstance (Context& context,
1811 const Texture& texture,
1812 const VkFormat format,
1813 const VkFormat imageFormat,
1814 const bool declareImageFormatInShader,
1815 const bool minalign,
1816 const bool bufferLoadUniform);
1819 VkDescriptorSetLayout prepareDescriptors (void);
1820 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
1822 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
1823 const VkPipelineLayout pipelineLayout,
1824 const int layerNdx);
1826 Buffer* getResultBuffer (void) const { return m_imageBufferDst.get(); }
1828 de::MovePtr<Buffer> m_imageBufferDst;
1829 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1830 Move<VkDescriptorPool> m_descriptorPool;
1831 Move<VkDescriptorSet> m_descriptorSet;
1832 Move<VkBufferView> m_bufferViewSrc;
1833 Move<VkBufferView> m_bufferViewDst;
1836 BufferLoadStoreTestInstance::BufferLoadStoreTestInstance (Context& context,
1837 const Texture& texture,
1838 const VkFormat format,
1839 const VkFormat imageFormat,
1840 const bool declareImageFormatInShader,
1841 const bool minalign,
1842 const bool bufferLoadUniform)
1843 : LoadStoreTestInstance(context, texture, format, imageFormat, declareImageFormatInShader, false, minalign, bufferLoadUniform)
1845 const DeviceInterface& vk = m_context.getDeviceInterface();
1846 const VkDevice device = m_context.getDevice();
1847 Allocator& allocator = m_context.getDefaultAllocator();
1849 // Create a destination buffer.
1851 m_imageBufferDst = de::MovePtr<Buffer>(new Buffer(
1852 vk, device, allocator,
1853 makeBufferCreateInfo(m_imageSizeBytes + m_dstViewOffset, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT),
1854 MemoryRequirement::HostVisible));
1857 VkDescriptorSetLayout BufferLoadStoreTestInstance::prepareDescriptors (void)
1859 const DeviceInterface& vk = m_context.getDeviceInterface();
1860 const VkDevice device = m_context.getDevice();
1862 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
1863 .addSingleBinding(m_bufferLoadDescriptorType, VK_SHADER_STAGE_COMPUTE_BIT)
1864 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT)
1867 m_descriptorPool = DescriptorPoolBuilder()
1868 .addType(m_bufferLoadDescriptorType)
1869 .addType(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)
1870 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
1872 VkFormat dstFormat = formatHasThreeComponents(m_format) ? getSingleComponentFormat(m_format) : m_format;
1874 m_descriptorSet = makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout);
1875 m_bufferViewSrc = makeBufferView(vk, device, m_imageBuffer->get(), m_format, m_srcViewOffset, m_imageSizeBytes);
1876 m_bufferViewDst = makeBufferView(vk, device, m_imageBufferDst->get(), dstFormat, m_dstViewOffset, m_imageSizeBytes);
1878 return *m_descriptorSetLayout; // not passing the ownership
1881 void BufferLoadStoreTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
1883 DE_ASSERT(layerNdx == 0);
1886 const VkDevice device = m_context.getDevice();
1887 const DeviceInterface& vk = m_context.getDeviceInterface();
1889 DescriptorSetUpdateBuilder()
1890 .writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), m_bufferLoadDescriptorType, &m_bufferViewSrc.get())
1891 .writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, &m_bufferViewDst.get())
1892 .update(vk, device);
1893 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &m_descriptorSet.get(), 0u, DE_NULL);
1896 void BufferLoadStoreTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
1898 commandBufferWriteBarrierBeforeHostRead(m_context, cmdBuffer, m_imageBufferDst->get(), m_imageSizeBytes + m_dstViewOffset);
1901 TestInstance* StoreTest::createInstance (Context& context) const
1903 if (m_texture.type() == IMAGE_TYPE_BUFFER)
1904 return new BufferStoreTestInstance(context, m_texture, m_format, m_declareImageFormatInShader, m_minalign);
1906 return new ImageStoreTestInstance(context, m_texture, m_format, m_declareImageFormatInShader, m_singleLayerBind, m_minalign);
1909 TestInstance* LoadStoreTest::createInstance (Context& context) const
1911 if (m_imageLoadStoreLodAMD)
1912 return new ImageLoadStoreLodAMDTestInstance(context, m_texture, m_format, m_imageFormat, m_declareImageFormatInShader, m_singleLayerBind, m_minalign, m_bufferLoadUniform);
1914 if (m_texture.type() == IMAGE_TYPE_BUFFER)
1915 return new BufferLoadStoreTestInstance(context, m_texture, m_format, m_imageFormat, m_declareImageFormatInShader, m_minalign, m_bufferLoadUniform);
1917 return new ImageLoadStoreTestInstance(context, m_texture, m_format, m_imageFormat, m_declareImageFormatInShader, m_singleLayerBind, m_minalign, m_bufferLoadUniform);
1920 class ImageExtendOperandTestInstance : public BaseTestInstance
1923 ImageExtendOperandTestInstance (Context& context,
1924 const Texture& texture,
1925 const VkFormat readFormat,
1926 const VkFormat writeFormat,
1927 bool relaxedPrecision);
1929 virtual ~ImageExtendOperandTestInstance (void) {}
1933 VkDescriptorSetLayout prepareDescriptors (void);
1934 void commandBeforeCompute (const VkCommandBuffer cmdBuffer);
1935 void commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer);
1936 void commandAfterCompute (const VkCommandBuffer cmdBuffer);
1938 void commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer,
1939 const VkPipelineLayout pipelineLayout,
1940 const int layerNdx);
1942 tcu::TestStatus verifyResult (void);
1947 tcu::TextureLevel m_inputImageData;
1949 de::MovePtr<Image> m_imageSrc; // source image
1950 SharedVkImageView m_imageSrcView;
1951 VkDeviceSize m_imageSrcSize;
1953 de::MovePtr<Image> m_imageDst; // dest image
1954 SharedVkImageView m_imageDstView;
1955 VkFormat m_imageDstFormat;
1956 VkDeviceSize m_imageDstSize;
1958 de::MovePtr<Buffer> m_buffer; // result buffer
1960 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
1961 Move<VkDescriptorPool> m_descriptorPool;
1962 SharedVkDescriptorSet m_descriptorSet;
1964 bool m_relaxedPrecision;
1967 ImageExtendOperandTestInstance::ImageExtendOperandTestInstance (Context& context,
1968 const Texture& texture,
1969 const VkFormat readFormat,
1970 const VkFormat writeFormat,
1971 bool relaxedPrecision)
1972 : BaseTestInstance (context, texture, readFormat, true, true, false, false)
1973 , m_imageDstFormat (writeFormat)
1974 , m_relaxedPrecision (relaxedPrecision)
1976 const DeviceInterface& vk = m_context.getDeviceInterface();
1977 const VkDevice device = m_context.getDevice();
1978 Allocator& allocator = m_context.getDefaultAllocator();
1979 const deInt32 width = texture.size().x();
1980 const deInt32 height = texture.size().y();
1981 const tcu::TextureFormat textureFormat = mapVkFormat(m_format);
1983 // Generate reference image
1984 m_isSigned = (getTextureChannelClass(textureFormat.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
1985 m_inputImageData.setStorage(textureFormat, width, height, 1);
1987 const tcu::PixelBufferAccess access = m_inputImageData.getAccess();
1988 const int valueStart = (m_isSigned ? (-width / 2) : 0);
1990 for (int x = 0; x < width; ++x)
1991 for (int y = 0; y < height; ++y)
1993 const tcu::IVec4 color(valueStart + x, valueStart + y, valueStart, valueStart);
1994 access.setPixel(color, x, y);
1997 // Create source image
1998 m_imageSrc = de::MovePtr<Image>(new Image(
1999 vk, device, allocator,
2000 makeImageCreateInfo(m_texture, m_format, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0u),
2001 MemoryRequirement::Any));
2003 // Create destination image
2004 m_imageDst = de::MovePtr<Image>(new Image(
2005 vk, device, allocator,
2006 makeImageCreateInfo(m_texture, m_imageDstFormat, VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0u),
2007 MemoryRequirement::Any));
2009 // Compute image and buffer sizes
2010 m_imageSrcSize = width * height * tcu::getPixelSize(textureFormat);
2011 m_imageDstSize = width * height * tcu::getPixelSize(mapVkFormat(m_imageDstFormat));
2012 VkDeviceSize bufferSizeBytes = de::max(m_imageSrcSize, m_imageDstSize);
2014 // Create helper buffer able to store input data and image write result
2015 m_buffer = de::MovePtr<Buffer>(new Buffer(
2016 vk, device, allocator,
2017 makeBufferCreateInfo(bufferSizeBytes, VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT),
2018 MemoryRequirement::HostVisible));
2020 const Allocation& alloc = m_buffer->getAllocation();
2021 deMemcpy(alloc.getHostPtr(), m_inputImageData.getAccess().getDataPtr(), static_cast<size_t>(m_imageSrcSize));
2022 flushAlloc(vk, device, alloc);
2025 VkDescriptorSetLayout ImageExtendOperandTestInstance::prepareDescriptors (void)
2027 const DeviceInterface& vk = m_context.getDeviceInterface();
2028 const VkDevice device = m_context.getDevice();
2030 m_descriptorSetLayout = DescriptorSetLayoutBuilder()
2031 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
2032 .addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, VK_SHADER_STAGE_COMPUTE_BIT)
2035 m_descriptorPool = DescriptorPoolBuilder()
2036 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1)
2037 .addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1)
2038 .build(vk, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1);
2040 const VkImageViewType viewType = mapImageViewType(m_texture.type());
2041 const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
2043 m_descriptorSet = makeVkSharedPtr(makeDescriptorSet(vk, device, *m_descriptorPool, *m_descriptorSetLayout));
2044 m_imageSrcView = makeVkSharedPtr(makeImageView(vk, device, m_imageSrc->get(), viewType, m_format, subresourceRange));
2045 m_imageDstView = makeVkSharedPtr(makeImageView(vk, device, m_imageDst->get(), viewType, m_imageDstFormat, subresourceRange));
2047 return *m_descriptorSetLayout; // not passing the ownership
2050 void ImageExtendOperandTestInstance::commandBindDescriptorsForLayer (const VkCommandBuffer cmdBuffer, const VkPipelineLayout pipelineLayout, const int layerNdx)
2054 const DeviceInterface& vk = m_context.getDeviceInterface();
2055 const VkDevice device = m_context.getDevice();
2056 const VkDescriptorSet descriptorSet = **m_descriptorSet;
2058 const VkDescriptorImageInfo descriptorSrcImageInfo = makeDescriptorImageInfo(DE_NULL, **m_imageSrcView, VK_IMAGE_LAYOUT_GENERAL);
2059 const VkDescriptorImageInfo descriptorDstImageInfo = makeDescriptorImageInfo(DE_NULL, **m_imageDstView, VK_IMAGE_LAYOUT_GENERAL);
2061 typedef DescriptorSetUpdateBuilder::Location DSUBL;
2062 DescriptorSetUpdateBuilder()
2063 .writeSingle(descriptorSet, DSUBL::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorSrcImageInfo)
2064 .writeSingle(descriptorSet, DSUBL::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &descriptorDstImageInfo)
2065 .update(vk, device);
2066 vk.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0u, 1u, &descriptorSet, 0u, DE_NULL);
2069 void ImageExtendOperandTestInstance::commandBeforeCompute (const VkCommandBuffer cmdBuffer)
2071 const DeviceInterface& vk = m_context.getDeviceInterface();
2073 const VkImageSubresourceRange fullImageSubresourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, m_texture.numLayers());
2075 const VkImageMemoryBarrier preCopyImageBarriers[] =
2077 makeImageMemoryBarrier(
2078 0u, VK_ACCESS_TRANSFER_WRITE_BIT,
2079 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
2080 m_imageSrc->get(), fullImageSubresourceRange),
2081 makeImageMemoryBarrier(
2082 0u, VK_ACCESS_SHADER_WRITE_BIT,
2083 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_GENERAL,
2084 m_imageDst->get(), fullImageSubresourceRange)
2087 const VkBufferMemoryBarrier barrierFlushHostWriteBeforeCopy = makeBufferMemoryBarrier(
2088 VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
2089 m_buffer->get(), 0ull, m_imageSrcSize);
2091 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
2092 (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &barrierFlushHostWriteBeforeCopy, DE_LENGTH_OF_ARRAY(preCopyImageBarriers), preCopyImageBarriers);
2095 const VkImageMemoryBarrier barrierAfterCopy = makeImageMemoryBarrier(
2096 VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT,
2097 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL,
2098 m_imageSrc->get(), fullImageSubresourceRange);
2100 const VkBufferImageCopy copyRegion = makeBufferImageCopy(m_texture);
2102 vk.cmdCopyBufferToImage(cmdBuffer, m_buffer->get(), m_imageSrc->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region);
2103 vk.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &barrierAfterCopy);
2107 void ImageExtendOperandTestInstance::commandBetweenShaderInvocations (const VkCommandBuffer cmdBuffer)
2109 commandImageWriteBarrierBetweenShaderInvocations(m_context, cmdBuffer, m_imageDst->get(), m_texture);
2112 void ImageExtendOperandTestInstance::commandAfterCompute (const VkCommandBuffer cmdBuffer)
2114 commandCopyImageToBuffer(m_context, cmdBuffer, m_imageDst->get(), m_buffer->get(), m_imageDstSize, m_texture);
2117 // Clears the high bits of every pixel in the pixel buffer, leaving only the lowest 16 bits of each component.
2118 void clearHighBits (const tcu::PixelBufferAccess& pixels, int width, int height)
2120 for (int y = 0; y < height; ++y)
2121 for (int x = 0; x < width; ++x)
2123 auto color = pixels.getPixelUint(x, y);
2124 for (int c = 0; c < decltype(color)::SIZE; ++c)
2125 color[c] &= 0xFFFFull;
2126 pixels.setPixel(color, x, y);
2130 tcu::TestStatus ImageExtendOperandTestInstance::verifyResult (void)
2132 const DeviceInterface& vk = m_context.getDeviceInterface();
2133 const VkDevice device = m_context.getDevice();
2134 const tcu::IVec3 imageSize = m_texture.size();
2135 const tcu::PixelBufferAccess inputAccess = m_inputImageData.getAccess();
2136 const deInt32 width = inputAccess.getWidth();
2137 const deInt32 height = inputAccess.getHeight();
2138 tcu::TextureLevel refImage (mapVkFormat(m_imageDstFormat), width, height);
2139 tcu::PixelBufferAccess refAccess = refImage.getAccess();
2141 for (int x = 0; x < width; ++x)
2142 for (int y = 0; y < height; ++y)
2144 tcu::IVec4 color = inputAccess.getPixelInt(x, y);
2145 refAccess.setPixel(color, x, y);
2148 const Allocation& alloc = m_buffer->getAllocation();
2149 invalidateAlloc(vk, device, alloc);
2150 const tcu::PixelBufferAccess result(mapVkFormat(m_imageDstFormat), imageSize, alloc.getHostPtr());
2152 if (m_relaxedPrecision)
2154 // Preserve the lowest 16 bits of the reference and result pixels only.
2155 clearHighBits(refAccess, width, height);
2156 clearHighBits(result, width, height);
2159 if (tcu::intThresholdCompare (m_context.getTestContext().getLog(), "Comparison", "Comparison", refAccess, result, tcu::UVec4(0), tcu::COMPARE_LOG_RESULT, true/*use64Bits*/))
2160 return tcu::TestStatus::pass("Passed");
2162 return tcu::TestStatus::fail("Image comparison failed");
2165 enum class ExtendTestType
2171 enum class ExtendOperand
2177 class ImageExtendOperandTest : public TestCase
2180 ImageExtendOperandTest (tcu::TestContext& testCtx,
2181 const std::string& name,
2182 const Texture texture,
2183 const VkFormat readFormat,
2184 const VkFormat writeFormat,
2185 const bool signedInt,
2186 const bool relaxedPrecision,
2187 ExtendTestType extendTestType);
2189 void checkSupport (Context& context) const;
2190 void initPrograms (SourceCollections& programCollection) const;
2191 TestInstance* createInstance (Context& context) const;
2194 bool isWriteTest () const { return (m_extendTestType == ExtendTestType::WRITE); }
2196 const Texture m_texture;
2197 VkFormat m_readFormat;
2198 VkFormat m_writeFormat;
2199 bool m_operandForce; // Use an operand that doesn't match SampledType?
2200 bool m_relaxedPrecision;
2201 ExtendTestType m_extendTestType;
2204 ImageExtendOperandTest::ImageExtendOperandTest (tcu::TestContext& testCtx,
2205 const std::string& name,
2206 const Texture texture,
2207 const VkFormat readFormat,
2208 const VkFormat writeFormat,
2209 const bool operandForce,
2210 const bool relaxedPrecision,
2211 ExtendTestType extendTestType)
2212 : TestCase (testCtx, name, "")
2213 , m_texture (texture)
2214 , m_readFormat (readFormat)
2215 , m_writeFormat (writeFormat)
2216 , m_operandForce (operandForce)
2217 , m_relaxedPrecision (relaxedPrecision)
2218 , m_extendTestType (extendTestType)
2222 void checkFormatProperties (const InstanceInterface& vki, VkPhysicalDevice physDev, VkFormat format)
2224 const auto formatProperties = getPhysicalDeviceFormatProperties(vki, physDev, format);
2226 if (!(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
2227 TCU_THROW(NotSupportedError, "Format not supported for storage images");
2230 void check64BitSupportIfNeeded (Context& context, VkFormat readFormat, VkFormat writeFormat)
2232 if (is64BitIntegerFormat(readFormat) || is64BitIntegerFormat(writeFormat))
2234 const auto& features = context.getDeviceFeatures();
2235 if (!features.shaderInt64)
2236 TCU_THROW(NotSupportedError, "64-bit integers not supported in shaders");
2240 void ImageExtendOperandTest::checkSupport (Context& context) const
2242 DE_ASSERT(m_texture.type() != IMAGE_TYPE_BUFFER);
2244 if (!context.requireDeviceFunctionality("VK_KHR_spirv_1_4"))
2245 TCU_THROW(NotSupportedError, "VK_KHR_spirv_1_4 not supported");
2247 check64BitSupportIfNeeded(context, m_readFormat, m_writeFormat);
2249 const auto& vki = context.getInstanceInterface();
2250 const auto physDev = context.getPhysicalDevice();
2252 checkFormatProperties(vki, physDev, m_readFormat);
2253 checkFormatProperties(vki, physDev, m_writeFormat);
2256 void ImageExtendOperandTest::initPrograms (SourceCollections& programCollection) const
2258 tcu::StringTemplate shaderTemplate(
2259 "OpCapability Shader\n"
2260 "OpCapability StorageImageExtendedFormats\n"
2265 "%std450 = OpExtInstImport \"GLSL.std.450\"\n"
2266 "OpMemoryModel Logical GLSL450\n"
2267 "OpEntryPoint GLCompute %main \"main\" %id %src_image_ptr %dst_image_ptr\n"
2268 "OpExecutionMode %main LocalSize 1 1 1\n"
2271 "OpDecorate %id BuiltIn GlobalInvocationId\n"
2273 "OpDecorate %src_image_ptr DescriptorSet 0\n"
2274 "OpDecorate %src_image_ptr Binding 0\n"
2275 "OpDecorate %src_image_ptr NonWritable\n"
2277 "${relaxed_precision}"
2279 "OpDecorate %dst_image_ptr DescriptorSet 0\n"
2280 "OpDecorate %dst_image_ptr Binding 1\n"
2281 "OpDecorate %dst_image_ptr NonReadable\n"
2284 "%type_void = OpTypeVoid\n"
2285 "%type_i32 = OpTypeInt 32 1\n"
2286 "%type_u32 = OpTypeInt 32 0\n"
2287 "%type_vec2_i32 = OpTypeVector %type_i32 2\n"
2288 "%type_vec2_u32 = OpTypeVector %type_u32 2\n"
2289 "%type_vec3_i32 = OpTypeVector %type_i32 3\n"
2290 "%type_vec3_u32 = OpTypeVector %type_u32 3\n"
2291 "%type_vec4_i32 = OpTypeVector %type_i32 4\n"
2292 "%type_vec4_u32 = OpTypeVector %type_u32 4\n"
2295 "%type_fun_void = OpTypeFunction %type_void\n"
2299 "%type_ptr_in_vec3_u32 = OpTypePointer Input %type_vec3_u32\n"
2300 "%type_ptr_in_u32 = OpTypePointer Input %type_u32\n"
2305 "%id = OpVariable %type_ptr_in_vec3_u32 Input\n"
2307 "${image_variables}"
2310 "%main = OpFunction %type_void None %type_fun_void\n"
2311 "%label = OpLabel\n"
2315 "%idvec = OpLoad %type_vec3_u32 %id\n"
2316 "%id_xy = OpVectorShuffle %type_vec2_u32 %idvec %idvec 0 1\n"
2317 "%coord = OpBitcast %type_vec2_i32 %id_xy\n"
2318 "%value = OpImageRead ${sampled_type_vec4} %src_image %coord ${read_extend_operand}\n"
2319 " OpImageWrite %dst_image %coord %value ${write_extend_operand}\n"
2321 " OpFunctionEnd\n");
2323 const auto testedFormat = mapVkFormat(isWriteTest() ? m_writeFormat : m_readFormat);
2324 const bool isSigned = (getTextureChannelClass(testedFormat.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
2326 const auto isRead64 = is64BitIntegerFormat(m_readFormat);
2327 const auto isWrite64 = is64BitIntegerFormat(m_writeFormat);
2328 DE_ASSERT(isRead64 == isWrite64);
2330 const bool using64Bits = (isRead64 || isWrite64);
2332 // Additional capabilities when needed.
2333 std::string capability;
2334 std::string extension;
2335 std::string extraTypes;
2339 extension += "OpExtension \"SPV_EXT_shader_image_int64\"\n";
2341 "OpCapability Int64\n"
2342 "OpCapability Int64ImageEXT\n"
2345 "%type_i64 = OpTypeInt 64 1\n"
2346 "%type_u64 = OpTypeInt 64 0\n"
2347 "%type_vec3_i64 = OpTypeVector %type_i64 3\n"
2348 "%type_vec3_u64 = OpTypeVector %type_u64 3\n"
2349 "%type_vec4_i64 = OpTypeVector %type_i64 4\n"
2350 "%type_vec4_u64 = OpTypeVector %type_u64 4\n"
2354 std::string relaxed = "";
2355 if (m_relaxedPrecision)
2356 relaxed += "OpDecorate %src_image_ptr RelaxedPrecision\n";
2358 // Sampled type depends on the format sign and mismatch force flag.
2359 const bool signedSampleType = ((isSigned && !m_operandForce) || (!isSigned && m_operandForce));
2360 const std::string bits = (using64Bits ? "64" : "32");
2361 const std::string sampledTypePostfix = (signedSampleType ? "i" : "u") + bits;
2362 const std::string extendOperandStr = (isSigned ? "SignExtend" : "ZeroExtend");
2364 std::map<std::string, std::string> specializations =
2366 { "image_type_id", "%type_image" },
2367 { "image_uni_ptr_type_id", "%type_ptr_uniform_const_image" },
2368 { "image_var_id", "%src_image_ptr" },
2369 { "image_id", "%src_image" },
2370 { "capability", capability },
2371 { "extension", extension },
2372 { "extra_types", extraTypes },
2373 { "relaxed_precision", relaxed },
2374 { "image_format", getSpirvFormat(m_readFormat) },
2375 { "sampled_type", (std::string("%type_") + sampledTypePostfix) },
2376 { "sampled_type_vec4", (std::string("%type_vec4_") + sampledTypePostfix) },
2377 { "read_extend_operand", (!isWriteTest() ? extendOperandStr : "") },
2378 { "write_extend_operand", (isWriteTest() ? extendOperandStr : "") },
2381 // Addidtional parametrization is needed for a case when source and destination textures have same format
2382 tcu::StringTemplate imageTypeTemplate(
2383 "${image_type_id} = OpTypeImage ${sampled_type} 2D 0 0 0 2 ${image_format}\n");
2384 tcu::StringTemplate imageUniformTypeTemplate(
2385 "${image_uni_ptr_type_id} = OpTypePointer UniformConstant ${image_type_id}\n");
2386 tcu::StringTemplate imageVariablesTemplate(
2387 "${image_var_id} = OpVariable ${image_uni_ptr_type_id} UniformConstant\n");
2388 tcu::StringTemplate imageLoadTemplate(
2389 "${image_id} = OpLoad ${image_type_id} ${image_var_id}\n");
2391 std::string imageTypes;
2392 std::string imageUniformTypes;
2393 std::string imageVariables;
2394 std::string imageLoad;
2396 // If input image format is the same as output there is less spir-v definitions
2397 if (m_readFormat == m_writeFormat)
2399 imageTypes = imageTypeTemplate.specialize(specializations);
2400 imageUniformTypes = imageUniformTypeTemplate.specialize(specializations);
2401 imageVariables = imageVariablesTemplate.specialize(specializations);
2402 imageLoad = imageLoadTemplate.specialize(specializations);
2404 specializations["image_var_id"] = "%dst_image_ptr";
2405 specializations["image_id"] = "%dst_image";
2406 imageVariables += imageVariablesTemplate.specialize(specializations);
2407 imageLoad += imageLoadTemplate.specialize(specializations);
2411 specializations["image_type_id"] = "%type_src_image";
2412 specializations["image_uni_ptr_type_id"] = "%type_ptr_uniform_const_src_image";
2413 imageTypes = imageTypeTemplate.specialize(specializations);
2414 imageUniformTypes = imageUniformTypeTemplate.specialize(specializations);
2415 imageVariables = imageVariablesTemplate.specialize(specializations);
2416 imageLoad = imageLoadTemplate.specialize(specializations);
2418 specializations["image_format"] = getSpirvFormat(m_writeFormat);
2419 specializations["image_type_id"] = "%type_dst_image";
2420 specializations["image_uni_ptr_type_id"] = "%type_ptr_uniform_const_dst_image";
2421 specializations["image_var_id"] = "%dst_image_ptr";
2422 specializations["image_id"] = "%dst_image";
2423 imageTypes += imageTypeTemplate.specialize(specializations);
2424 imageUniformTypes += imageUniformTypeTemplate.specialize(specializations);
2425 imageVariables += imageVariablesTemplate.specialize(specializations);
2426 imageLoad += imageLoadTemplate.specialize(specializations);
2429 specializations["image_types"] = imageTypes;
2430 specializations["image_uniforms"] = imageUniformTypes;
2431 specializations["image_variables"] = imageVariables;
2432 specializations["image_load"] = imageLoad;
2434 // Specialize whole shader and add it to program collection
2435 programCollection.spirvAsmSources.add("comp") << shaderTemplate.specialize(specializations)
2436 << vk::SpirVAsmBuildOptions(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, true);
2439 TestInstance* ImageExtendOperandTest::createInstance(Context& context) const
2441 return new ImageExtendOperandTestInstance(context, m_texture, m_readFormat, m_writeFormat, m_relaxedPrecision);
2444 static const Texture s_textures[] =
2446 Texture(IMAGE_TYPE_1D, tcu::IVec3(64, 1, 1), 1),
2447 Texture(IMAGE_TYPE_1D_ARRAY, tcu::IVec3(64, 1, 1), 8),
2448 Texture(IMAGE_TYPE_2D, tcu::IVec3(64, 64, 1), 1),
2449 Texture(IMAGE_TYPE_2D_ARRAY, tcu::IVec3(64, 64, 1), 8),
2450 Texture(IMAGE_TYPE_3D, tcu::IVec3(64, 64, 8), 1),
2451 Texture(IMAGE_TYPE_CUBE, tcu::IVec3(64, 64, 1), 6),
2452 Texture(IMAGE_TYPE_CUBE_ARRAY, tcu::IVec3(64, 64, 1), 2*6),
2453 Texture(IMAGE_TYPE_BUFFER, tcu::IVec3(64, 1, 1), 1),
2456 const Texture& getTestTexture (const ImageType imageType)
2458 for (int textureNdx = 0; textureNdx < DE_LENGTH_OF_ARRAY(s_textures); ++textureNdx)
2459 if (s_textures[textureNdx].type() == imageType)
2460 return s_textures[textureNdx];
2462 DE_FATAL("Internal error");
2463 return s_textures[0];
2466 static const VkFormat s_formats[] =
2468 VK_FORMAT_R32G32B32A32_SFLOAT,
2469 VK_FORMAT_R16G16B16A16_SFLOAT,
2470 VK_FORMAT_R32_SFLOAT,
2472 VK_FORMAT_R32G32B32A32_UINT,
2473 VK_FORMAT_R16G16B16A16_UINT,
2474 VK_FORMAT_R8G8B8A8_UINT,
2477 VK_FORMAT_R32G32B32A32_SINT,
2478 VK_FORMAT_R16G16B16A16_SINT,
2479 VK_FORMAT_R8G8B8A8_SINT,
2482 VK_FORMAT_R8G8B8A8_UNORM,
2484 VK_FORMAT_B8G8R8A8_UNORM,
2485 VK_FORMAT_B8G8R8A8_UINT,
2487 VK_FORMAT_R8G8B8A8_SNORM,
2489 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
2491 VK_FORMAT_R32G32_SFLOAT,
2492 VK_FORMAT_R16G16_SFLOAT,
2493 VK_FORMAT_R16_SFLOAT,
2495 VK_FORMAT_A2B10G10R10_UINT_PACK32,
2496 VK_FORMAT_R32G32_UINT,
2497 VK_FORMAT_R16G16_UINT,
2499 VK_FORMAT_R8G8_UINT,
2502 VK_FORMAT_R32G32_SINT,
2503 VK_FORMAT_R16G16_SINT,
2505 VK_FORMAT_R8G8_SINT,
2508 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
2509 VK_FORMAT_R16G16B16A16_UNORM,
2510 VK_FORMAT_R16G16B16A16_SNORM,
2511 VK_FORMAT_R16G16_UNORM,
2512 VK_FORMAT_R16_UNORM,
2513 VK_FORMAT_R8G8_UNORM,
2516 VK_FORMAT_R16G16_SNORM,
2517 VK_FORMAT_R16_SNORM,
2518 VK_FORMAT_R8G8_SNORM,
2522 static const VkFormat s_formatsThreeComponent[] =
2524 VK_FORMAT_R8G8B8_UINT,
2525 VK_FORMAT_R8G8B8_SINT,
2526 VK_FORMAT_R8G8B8_UNORM,
2527 VK_FORMAT_R8G8B8_SNORM,
2528 VK_FORMAT_R16G16B16_UINT,
2529 VK_FORMAT_R16G16B16_SINT,
2530 VK_FORMAT_R16G16B16_UNORM,
2531 VK_FORMAT_R16G16B16_SNORM,
2532 VK_FORMAT_R16G16B16_SFLOAT,
2533 VK_FORMAT_R32G32B32_UINT,
2534 VK_FORMAT_R32G32B32_SINT,
2535 VK_FORMAT_R32G32B32_SFLOAT,
2540 tcu::TestCaseGroup* createImageStoreTests (tcu::TestContext& testCtx)
2542 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "store", "Plain imageStore() cases"));
2543 de::MovePtr<tcu::TestCaseGroup> testGroupWithFormat(new tcu::TestCaseGroup(testCtx, "with_format", "Declare a format layout qualifier for write images"));
2544 de::MovePtr<tcu::TestCaseGroup> testGroupWithoutFormat(new tcu::TestCaseGroup(testCtx, "without_format", "Do not declare a format layout qualifier for write images"));
2546 for (int textureNdx = 0; textureNdx < DE_LENGTH_OF_ARRAY(s_textures); ++textureNdx)
2548 const Texture& texture = s_textures[textureNdx];
2549 de::MovePtr<tcu::TestCaseGroup> groupWithFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2550 de::MovePtr<tcu::TestCaseGroup> groupWithoutFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2551 const bool isLayered = (texture.numLayers() > 1);
2553 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_formats); ++formatNdx)
2555 const bool hasSpirvFmt = hasSpirvFormat(s_formats[formatNdx]);
2558 groupWithFormatByImageViewType->addChild(new StoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx]));
2559 groupWithoutFormatByImageViewType->addChild(new StoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx], 0));
2561 if (isLayered && hasSpirvFmt)
2562 groupWithFormatByImageViewType->addChild(new StoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_single_layer", "",
2563 texture, s_formats[formatNdx],
2564 StoreTest::FLAG_SINGLE_LAYER_BIND | StoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER));
2566 if (texture.type() == IMAGE_TYPE_BUFFER)
2569 groupWithFormatByImageViewType->addChild(new StoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign", "", texture, s_formats[formatNdx], StoreTest::FLAG_MINALIGN | StoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER));
2570 groupWithoutFormatByImageViewType->addChild(new StoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign", "", texture, s_formats[formatNdx], StoreTest::FLAG_MINALIGN));
2574 testGroupWithFormat->addChild(groupWithFormatByImageViewType.release());
2575 testGroupWithoutFormat->addChild(groupWithoutFormatByImageViewType.release());
2578 testGroup->addChild(testGroupWithFormat.release());
2579 testGroup->addChild(testGroupWithoutFormat.release());
2581 return testGroup.release();
2584 tcu::TestCaseGroup* createImageLoadStoreTests (tcu::TestContext& testCtx)
2586 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "load_store", "Cases with imageLoad() followed by imageStore()"));
2587 de::MovePtr<tcu::TestCaseGroup> testGroupWithFormat(new tcu::TestCaseGroup(testCtx, "with_format", "Declare a format layout qualifier for read images"));
2588 de::MovePtr<tcu::TestCaseGroup> testGroupWithoutFormat(new tcu::TestCaseGroup(testCtx, "without_format", "Do not declare a format layout qualifier for read images"));
2590 for (int textureNdx = 0; textureNdx < DE_LENGTH_OF_ARRAY(s_textures); ++textureNdx)
2592 const Texture& texture = s_textures[textureNdx];
2593 de::MovePtr<tcu::TestCaseGroup> groupWithFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2594 de::MovePtr<tcu::TestCaseGroup> groupWithoutFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2595 const bool isLayered = (texture.numLayers() > 1);
2597 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_formats); ++formatNdx)
2599 // These tests always require a SPIR-V format for the write image, even if the read
2600 // image is being used without a format.
2601 if (!hasSpirvFormat(s_formats[formatNdx]))
2604 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx], s_formats[formatNdx]));
2605 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx], s_formats[formatNdx], 0));
2608 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_single_layer", "",
2609 texture, s_formats[formatNdx], s_formats[formatNdx],
2610 LoadStoreTest::FLAG_SINGLE_LAYER_BIND | LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER));
2611 if (texture.type() == IMAGE_TYPE_BUFFER)
2613 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign", "", texture, s_formats[formatNdx], s_formats[formatNdx], LoadStoreTest::FLAG_MINALIGN | LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER));
2614 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign_uniform", "", texture, s_formats[formatNdx], s_formats[formatNdx], LoadStoreTest::FLAG_MINALIGN | LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER | LoadStoreTest::FLAG_UNIFORM_TEXEL_BUFFER));
2615 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign", "", texture, s_formats[formatNdx], s_formats[formatNdx], LoadStoreTest::FLAG_MINALIGN));
2616 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_minalign_uniform", "", texture, s_formats[formatNdx], s_formats[formatNdx], LoadStoreTest::FLAG_MINALIGN | LoadStoreTest::FLAG_UNIFORM_TEXEL_BUFFER));
2620 if (texture.type() == IMAGE_TYPE_BUFFER)
2622 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_formatsThreeComponent); ++formatNdx)
2624 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formatsThreeComponent[formatNdx]) + "_uniform", "", texture, s_formatsThreeComponent[formatNdx], s_formatsThreeComponent[formatNdx], LoadStoreTest::FLAG_UNIFORM_TEXEL_BUFFER));
2625 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formatsThreeComponent[formatNdx]) + "_minalign_uniform", "", texture, s_formatsThreeComponent[formatNdx], s_formatsThreeComponent[formatNdx], LoadStoreTest::FLAG_MINALIGN | LoadStoreTest::FLAG_UNIFORM_TEXEL_BUFFER));
2629 testGroupWithFormat->addChild(groupWithFormatByImageViewType.release());
2630 testGroupWithoutFormat->addChild(groupWithoutFormatByImageViewType.release());
2633 testGroup->addChild(testGroupWithFormat.release());
2634 testGroup->addChild(testGroupWithoutFormat.release());
2636 return testGroup.release();
2639 tcu::TestCaseGroup* createImageLoadStoreLodAMDTests (tcu::TestContext& testCtx)
2641 static const Texture textures[] =
2643 Texture(IMAGE_TYPE_1D_ARRAY, tcu::IVec3(64, 1, 1), 8, 1, 6),
2644 Texture(IMAGE_TYPE_1D, tcu::IVec3(64, 1, 1), 1, 1, 6),
2645 Texture(IMAGE_TYPE_2D, tcu::IVec3(64, 64, 1), 1, 1, 6),
2646 Texture(IMAGE_TYPE_2D_ARRAY, tcu::IVec3(64, 64, 1), 8, 1, 6),
2647 Texture(IMAGE_TYPE_3D, tcu::IVec3(64, 64, 8), 1, 1, 6),
2648 Texture(IMAGE_TYPE_CUBE, tcu::IVec3(64, 64, 1), 6, 1, 6),
2649 Texture(IMAGE_TYPE_CUBE_ARRAY, tcu::IVec3(64, 64, 1), 2*6, 1, 6),
2652 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "load_store_lod", "Cases with imageLoad() followed by imageStore()"));
2653 de::MovePtr<tcu::TestCaseGroup> testGroupWithFormat(new tcu::TestCaseGroup(testCtx, "with_format", "Declare a format layout qualifier for read images"));
2654 de::MovePtr<tcu::TestCaseGroup> testGroupWithoutFormat(new tcu::TestCaseGroup(testCtx, "without_format", "Do not declare a format layout qualifier for read images"));
2656 for (int textureNdx = 0; textureNdx < DE_LENGTH_OF_ARRAY(textures); ++textureNdx)
2658 const Texture& texture = textures[textureNdx];
2659 de::MovePtr<tcu::TestCaseGroup> groupWithFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2660 de::MovePtr<tcu::TestCaseGroup> groupWithoutFormatByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2661 const bool isLayered = (texture.numLayers() > 1);
2663 if (texture.type() == IMAGE_TYPE_BUFFER)
2666 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_formats); ++formatNdx)
2668 // These tests always require a SPIR-V format for the write image, even if the read
2669 // image is being used without a format.
2670 if (!hasSpirvFormat(s_formats[formatNdx]))
2673 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx], s_formats[formatNdx], LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER, DE_TRUE));
2674 groupWithoutFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]), "", texture, s_formats[formatNdx], s_formats[formatNdx], 0, DE_TRUE));
2677 groupWithFormatByImageViewType->addChild(new LoadStoreTest(testCtx, getFormatShortString(s_formats[formatNdx]) + "_single_layer", "",
2678 texture, s_formats[formatNdx], s_formats[formatNdx],
2679 LoadStoreTest::FLAG_SINGLE_LAYER_BIND | LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER, DE_TRUE));
2682 testGroupWithFormat->addChild(groupWithFormatByImageViewType.release());
2683 testGroupWithoutFormat->addChild(groupWithoutFormatByImageViewType.release());
2686 testGroup->addChild(testGroupWithFormat.release());
2687 testGroup->addChild(testGroupWithoutFormat.release());
2689 return testGroup.release();
2692 tcu::TestCaseGroup* createImageFormatReinterpretTests (tcu::TestContext& testCtx)
2694 de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "format_reinterpret", "Cases with differing texture and image formats"));
2696 for (int textureNdx = 0; textureNdx < DE_LENGTH_OF_ARRAY(s_textures); ++textureNdx)
2698 const Texture& texture = s_textures[textureNdx];
2699 de::MovePtr<tcu::TestCaseGroup> groupByImageViewType (new tcu::TestCaseGroup(testCtx, getImageTypeName(texture.type()).c_str(), ""));
2701 for (int imageFormatNdx = 0; imageFormatNdx < DE_LENGTH_OF_ARRAY(s_formats); ++imageFormatNdx)
2702 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(s_formats); ++formatNdx)
2704 if (!hasSpirvFormat(s_formats[formatNdx]))
2707 const std::string caseName = getFormatShortString(s_formats[imageFormatNdx]) + "_" + getFormatShortString(s_formats[formatNdx]);
2708 if (imageFormatNdx != formatNdx && formatsAreCompatible(s_formats[imageFormatNdx], s_formats[formatNdx]))
2709 groupByImageViewType->addChild(new LoadStoreTest(testCtx, caseName, "", texture, s_formats[formatNdx], s_formats[imageFormatNdx]));
2711 testGroup->addChild(groupByImageViewType.release());
2714 return testGroup.release();
2717 de::MovePtr<TestCase> createImageQualifierRestrictCase (tcu::TestContext& testCtx, const ImageType imageType, const std::string& name)
2719 const VkFormat format = VK_FORMAT_R32G32B32A32_UINT;
2720 const Texture& texture = getTestTexture(imageType);
2721 return de::MovePtr<TestCase>(new LoadStoreTest(testCtx, name, "", texture, format, format, LoadStoreTest::FLAG_RESTRICT_IMAGES | LoadStoreTest::FLAG_DECLARE_IMAGE_FORMAT_IN_SHADER));
2727 bool relaxedOK(VkFormat format)
2729 tcu::IVec4 bitDepth = tcu::getTextureFormatBitDepth(mapVkFormat(format));
2730 int maxBitDepth = deMax32(deMax32(bitDepth[0], bitDepth[1]), deMax32(bitDepth[2], bitDepth[3]));
2731 return maxBitDepth <= 16;
2734 // Get a format used for reading or writing in extension operand tests. These formats allow representing the shader sampled type to
2735 // verify results from read or write operations.
2736 VkFormat getShaderExtensionOperandFormat (bool isSigned, bool is64Bit)
2738 const VkFormat formats[] =
2740 VK_FORMAT_R32G32B32A32_UINT,
2741 VK_FORMAT_R32G32B32A32_SINT,
2745 return formats[2u * (is64Bit ? 1u : 0u) + (isSigned ? 1u : 0u)];
2748 // INT or UINT format?
2749 bool isIntegralFormat (VkFormat format)
2751 return (isIntFormat(format) || isUintFormat(format));
2754 // Return the list of formats used for the extension operand tests (SignExten/ZeroExtend).
2755 std::vector<VkFormat> getExtensionOperandFormatList (void)
2757 std::vector<VkFormat> formatList;
2759 for (auto format : s_formats)
2761 if (isIntegralFormat(format))
2762 formatList.push_back(format);
2765 formatList.push_back(VK_FORMAT_R64_SINT);
2766 formatList.push_back(VK_FORMAT_R64_UINT);
2773 tcu::TestCaseGroup* createImageExtendOperandsTests(tcu::TestContext& testCtx)
2775 using GroupPtr = de::MovePtr<tcu::TestCaseGroup>;
2777 GroupPtr testGroup(new tcu::TestCaseGroup(testCtx, "extend_operands_spirv1p4", "Cases with SignExtend and ZeroExtend"));
2781 ExtendTestType testType;
2785 { ExtendTestType::READ, "read" },
2786 { ExtendTestType::WRITE, "write" },
2789 const auto texture = Texture(IMAGE_TYPE_2D, tcu::IVec3(8, 8, 1), 1);
2790 const auto formatList = getExtensionOperandFormatList();
2792 for (const auto format : formatList)
2794 const auto isInt = isIntFormat(format);
2795 const auto isUint = isUintFormat(format);
2796 const auto use64Bits = is64BitIntegerFormat(format);
2798 DE_ASSERT(isInt || isUint);
2800 GroupPtr formatGroup (new tcu::TestCaseGroup(testCtx, getFormatShortString(format).c_str(), ""));
2802 for (const auto& testType : testTypes)
2804 GroupPtr testTypeGroup (new tcu::TestCaseGroup(testCtx, testType.name, ""));
2806 for (int match = 0; match < 2; ++match)
2808 const bool mismatched = (match == 1);
2809 const char* matchGroupName = (mismatched ? "mismatched_sign" : "matched_sign");
2811 // SPIR-V does not allow this kind of sampled type override.
2812 if (mismatched && isUint)
2815 GroupPtr matchGroup (new tcu::TestCaseGroup(testCtx, matchGroupName, ""));
2817 for (int prec = 0; prec < 2; prec++)
2819 const bool relaxedPrecision = (prec != 0);
2821 const char* precisionName = (relaxedPrecision ? "relaxed_precision" : "normal_precision");
2822 const auto signedOther = ((isInt && !mismatched) || (isUint && mismatched));
2823 const auto otherFormat = getShaderExtensionOperandFormat(signedOther, use64Bits);
2824 const auto readFormat = (testType.testType == ExtendTestType::READ ? format : otherFormat);
2825 const auto writeFormat = (testType.testType == ExtendTestType::WRITE ? format : otherFormat);
2827 if (relaxedPrecision && !relaxedOK(readFormat))
2830 if (!hasSpirvFormat(readFormat) || !hasSpirvFormat(writeFormat))
2833 matchGroup->addChild(new ImageExtendOperandTest(testCtx, precisionName, texture, readFormat, writeFormat, mismatched, relaxedPrecision, testType.testType));
2836 testTypeGroup->addChild(matchGroup.release());
2839 formatGroup->addChild(testTypeGroup.release());
2842 testGroup->addChild(formatGroup.release());
2845 return testGroup.release();