const VkImageSubresourceRange& subresource)
{
MovePtr<Program> program;
- const VkImageType imageType = getCompatibleImageType(viewType);
+ const VkImageType imageType = getCompatibleImageType(viewType);
+ tcu::Vec4 lookupScale (1.0f);
+ tcu::Vec4 lookupBias (0.0f);
+
+ if (!testTexture.isCompressed())
+ {
+ const tcu::TextureFormatInfo fmtInfo = tcu::getTextureFormatInfo(testTexture.getLevel(0, 0).getFormat());
+
+ // Needed to normalize various formats to 0..1 range for writing into RT
+ lookupScale = fmtInfo.lookupScale;
+ lookupBias = fmtInfo.lookupBias;
+ }
+ // else: All supported compressed formats are fine with no normalization.
+ // ASTC LDR blocks decompress to f16 so querying normalization parameters
+ // based on uncompressed formats would actually lead to massive precision loss
+ // and complete lack of coverage in case of R8G8B8A8_UNORM RT.
switch (imageType)
{
if (layerCount == 1)
{
const tcu::Texture1D& texture = dynamic_cast<const TestTexture1D&>(testTexture).getTexture();
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture1D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture1D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
copySubresourceRange(textureView, texture, subresource);
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
}
break;
if (layerCount == 1)
{
const tcu::Texture2D& texture = dynamic_cast<const TestTexture2D&>(testTexture).getTexture();
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture2D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture2D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
if (layerCount == tcu::CUBEFACE_LAST)
{
const tcu::TextureCube& texture = dynamic_cast<const TestTextureCube&>(testTexture).getTexture();
- program = MovePtr<Program>(new SamplerProgram<tcu::TextureCube>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::TextureCube>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
copySubresourceRange(textureView, texture, subresource);
- program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
// Use all array layers
- program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
}
}
copySubresourceRange(textureView, texture, subresource);
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
// Use all array layers
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
}
}
copySubresourceRange(textureView, texture, subresource);
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
else
{
- program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+ program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
}
}
break;
const char* texCoordSwizzle = DE_NULL;
const tcu::TextureFormat format = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
: mapVkFormat(m_imageFormat);
- const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
+
+ // \note We don't want to perform normalization on any compressed formats.
+ // In case of non-sRGB LDR ASTC it would lead to lack of coverage
+ // as uncompressed format for that is f16 but values will be in range
+ // 0..1 already.
+ const tcu::TextureFormatInfo formatInfo = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+ : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
switch (m_imageViewType)
{
#include "vkQueryUtil.hpp"
#include "vkRefUtil.hpp"
#include "tcuTextureUtil.hpp"
+#include "tcuAstcUtil.hpp"
#include "deRandom.hpp"
namespace vkt
TestTexture::fillWithGradient(levels[levelNdx]);
}
-void TestTexture::populateCompressedLevels (const tcu::CompressedTexFormat& format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels)
+void TestTexture::populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels)
{
// Generate random compressed data and update decompressed data
tcu::CompressedTexture* compressedLevel = new tcu::CompressedTexture(format, level.getWidth(), level.getHeight(), level.getDepth());
deUint8* const compressedData = (deUint8*)compressedLevel->getData();
- // Generate random compressed data
- for (int byteNdx = 0; byteNdx < compressedLevel->getDataSize(); byteNdx++)
- compressedData[byteNdx] = 0xFF & random.getUint32();
+ if (tcu::isAstcFormat(format))
+ {
+ // \todo [2016-01-20 pyry] Comparison doesn't currently handle invalid blocks correctly so we use only valid blocks
+ tcu::astc::generateRandomValidBlocks(compressedData, compressedLevel->getDataSize()/tcu::astc::BLOCK_SIZE_BYTES,
+ format, tcu::TexDecompressionParams::ASTCMODE_LDR, random.getUint32());
+ }
+ else
+ {
+ // Generate random compressed data
+ for (int byteNdx = 0; byteNdx < compressedLevel->getDataSize(); byteNdx++)
+ compressedData[byteNdx] = 0xFF & random.getUint32();
+ }
m_compressedLevels.push_back(compressedLevel);
// Store decompressed data
- compressedLevel->decompress(level, tcu::TexDecompressionParams::ASTCMODE_LDR);
+ compressedLevel->decompress(level, tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR));
}
}
protected:
void populateLevels (const std::vector<tcu::PixelBufferAccess>& levels);
- void populateCompressedLevels (const tcu::CompressedTexFormat& format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
+ void populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
static void fillWithGradient (const tcu::PixelBufferAccess& levelAccess);
const char* texCoordSwizzle = DE_NULL;
const tcu::TextureFormat format = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
: mapVkFormat(m_imageFormat);
- const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
+
+ // \note We don't want to perform normalization on any compressed formats.
+ // In case of non-sRGB LDR ASTC it would lead to lack of coverage
+ // as uncompressed format for that is f16 but values will be in range
+ // 0..1 already.
+ const tcu::TextureFormatInfo formatInfo = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+ : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
tcu::Vec4 swizzledScale = swizzle(formatInfo.lookupScale, m_componentMapping);
tcu::Vec4 swizzledBias = swizzle(formatInfo.lookupBias, m_componentMapping);
const tcu::TextureFormat m_colorFormat;
const tcu::TextureFormatInfo m_colorFormatInfo;
const TextureType m_texture;
- const tcu::TextureFormatInfo m_textureFormatInfo;
const tcu::Sampler m_sampler;
const float m_lod;
+ const tcu::Vec4 m_lookupScale;
+ const tcu::Vec4 m_lookupBias;
const tcu::UVec4 m_swizzle;
public:
- SamplerFragmentShader (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::UVec4& swizzle)
+ SamplerFragmentShader (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::Vec4& lookupScale, const tcu::Vec4& lookupBias, const tcu::UVec4& swizzle)
: rr::FragmentShader (2, 1)
, m_colorFormat (colorFormat)
, m_colorFormatInfo (tcu::getTextureFormatInfo(m_colorFormat))
, m_texture (texture)
- , m_textureFormatInfo (tcu::getTextureFormatInfo(m_texture.getFormat()))
, m_sampler (sampler)
, m_lod (lod)
+ , m_lookupScale (lookupScale)
+ , m_lookupBias (lookupBias)
, m_swizzle (swizzle)
{
const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(m_colorFormat.type);
{
const tcu::Vec4 vtxTexCoord = rr::readVarying<float>(packet, context, 1, fragNdx);
const tcu::Vec4 texColor = sampleTexture(m_texture, m_sampler, vtxTexCoord, m_lod);
- const tcu::Vec4 swizColor = swizzle(texColor, m_swizzle);
- const tcu::Vec4 normColor = swizColor * swizzle(m_textureFormatInfo.lookupScale, m_swizzle) + swizzle(m_textureFormatInfo.lookupBias, m_swizzle);
- const tcu::Vec4 color = (normColor - m_colorFormatInfo.lookupBias) / m_colorFormatInfo.lookupScale;
+ const tcu::Vec4 normColor = texColor * m_lookupScale + m_lookupBias;
+ const tcu::Vec4 swizColor = swizzle(normColor, m_swizzle);
+ const tcu::Vec4 color = (swizColor + m_colorFormatInfo.lookupBias) / m_colorFormatInfo.lookupScale;
rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
}
}
TexCoordVertexShader m_vertexShader;
SamplerFragmentShader<TextureType> m_fragmentShader;
public:
- SamplerProgram (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::UVec4& swizzle)
+ SamplerProgram (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::Vec4& lookupScale, const tcu::Vec4& lookupBias, const tcu::UVec4& swizzle)
: m_vertexShader ()
- , m_fragmentShader (colorFormat, texture, sampler, lod, swizzle)
+ , m_fragmentShader (colorFormat, texture, sampler, lod, lookupScale, lookupBias, swizzle)
{
}
const char* texCoordSwizzle = DE_NULL;
tcu::TextureFormat format = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
: mapVkFormat(m_imageFormat);
- const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
+
+ // \note We don't want to perform normalization on any compressed formats.
+ // In case of non-sRGB LDR ASTC it would lead to lack of coverage
+ // as uncompressed format for that is f16 but values will be in range
+ // 0..1 already.
+ const tcu::TextureFormatInfo formatInfo = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+ : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
switch (m_imageViewType)
{