1e5c31af7Sopenharmony_ci#ifndef _TCUTEXTUREUTIL_HPP 2e5c31af7Sopenharmony_ci#define _TCUTEXTUREUTIL_HPP 3e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci * drawElements Quality Program Tester Core 5e5c31af7Sopenharmony_ci * ---------------------------------------- 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 8e5c31af7Sopenharmony_ci * 9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci * 15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci * limitations under the License. 20e5c31af7Sopenharmony_ci * 21e5c31af7Sopenharmony_ci *//*! 22e5c31af7Sopenharmony_ci * \file 23e5c31af7Sopenharmony_ci * \brief Texture utilities. 24e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 25e5c31af7Sopenharmony_ci 26e5c31af7Sopenharmony_ci#include "tcuDefs.hpp" 27e5c31af7Sopenharmony_ci#include "tcuTexture.hpp" 28e5c31af7Sopenharmony_ci 29e5c31af7Sopenharmony_cinamespace tcu 30e5c31af7Sopenharmony_ci{ 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ci// PixelBufferAccess utilities. 33e5c31af7Sopenharmony_ciPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 34e5c31af7Sopenharmony_ciConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_ciPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height); 37e5c31af7Sopenharmony_ciConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height); 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_ciPixelBufferAccess flipYAccess (const PixelBufferAccess& access); 40e5c31af7Sopenharmony_ciConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access); 41e5c31af7Sopenharmony_ci 42e5c31af7Sopenharmony_cibool isCombinedDepthStencilType (TextureFormat::ChannelType type); 43e5c31af7Sopenharmony_cibool hasStencilComponent (TextureFormat::ChannelOrder order); 44e5c31af7Sopenharmony_cibool hasDepthComponent (TextureFormat::ChannelOrder order); 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci// sRGB - linear conversion. 47e5c31af7Sopenharmony_cifloat linearChannelToSRGB (float cl); 48e5c31af7Sopenharmony_cifloat sRGBChannelToLinear (float cl); 49e5c31af7Sopenharmony_ciVec4 sRGBToLinear (const Vec4& cs); 50e5c31af7Sopenharmony_ciVec4 sRGB8ToLinear (const UVec4& cs); 51e5c31af7Sopenharmony_ciVec4 sRGBA8ToLinear (const UVec4& cs); 52e5c31af7Sopenharmony_ciVec4 linearToSRGB (const Vec4& cl); 53e5c31af7Sopenharmony_cibool isSRGB (TextureFormat format); 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 56e5c31af7Sopenharmony_ci * \brief Color channel storage type 57e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 58e5c31af7Sopenharmony_cienum TextureChannelClass 59e5c31af7Sopenharmony_ci{ 60e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0, 61e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT, 62e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_SIGNED_INTEGER, 63e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_UNSIGNED_INTEGER, 64e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_FLOATING_POINT, 65e5c31af7Sopenharmony_ci 66e5c31af7Sopenharmony_ci TEXTURECHANNELCLASS_LAST 67e5c31af7Sopenharmony_ci}; 68e5c31af7Sopenharmony_ci 69e5c31af7Sopenharmony_ciTextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType); 70e5c31af7Sopenharmony_ci 71e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 72e5c31af7Sopenharmony_ci * \brief Texture access type 73e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 74e5c31af7Sopenharmony_cienum TextureAccessType 75e5c31af7Sopenharmony_ci{ 76e5c31af7Sopenharmony_ci TEXTUREACCESSTYPE_FLOAT = 0, //!< Read (getPixel) or write as floating-point data 77e5c31af7Sopenharmony_ci TEXTUREACCESSTYPE_SIGNED_INT, //!< Read (getPixelInt) or write as signed integer data 78e5c31af7Sopenharmony_ci TEXTUREACCESSTYPE_UNSIGNED_INT, //!< Read (getPixelUint) or write as unsigned integer data 79e5c31af7Sopenharmony_ci 80e5c31af7Sopenharmony_ci TEXTUREACCESSTYPE_LAST 81e5c31af7Sopenharmony_ci}; 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_cibool isAccessValid (TextureFormat format, TextureAccessType type); 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 86e5c31af7Sopenharmony_ci * \brief Standard parameters for texture format testing 87e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 88e5c31af7Sopenharmony_cistruct TextureFormatInfo 89e5c31af7Sopenharmony_ci{ 90e5c31af7Sopenharmony_ci Vec4 valueMin; 91e5c31af7Sopenharmony_ci Vec4 valueMax; 92e5c31af7Sopenharmony_ci Vec4 lookupScale; 93e5c31af7Sopenharmony_ci Vec4 lookupBias; 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ci TextureFormatInfo (const Vec4& valueMin_, const Vec4& valueMax_, const Vec4& lookupScale_, const Vec4& lookupBias_) 96e5c31af7Sopenharmony_ci : valueMin (valueMin_) 97e5c31af7Sopenharmony_ci , valueMax (valueMax_) 98e5c31af7Sopenharmony_ci , lookupScale (lookupScale_) 99e5c31af7Sopenharmony_ci , lookupBias (lookupBias_) 100e5c31af7Sopenharmony_ci { 101e5c31af7Sopenharmony_ci } 102e5c31af7Sopenharmony_ci} DE_WARN_UNUSED_TYPE; 103e5c31af7Sopenharmony_ci 104e5c31af7Sopenharmony_ciTextureFormatInfo getTextureFormatInfo (const TextureFormat& format); 105e5c31af7Sopenharmony_ciIVec4 getTextureFormatBitDepth (const TextureFormat& format); 106e5c31af7Sopenharmony_ciIVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format); 107e5c31af7Sopenharmony_ciBVec4 getTextureFormatChannelMask (const TextureFormat& format); 108e5c31af7Sopenharmony_ci 109e5c31af7Sopenharmony_ciIVec4 getFormatMinIntValue (const TextureFormat& format); 110e5c31af7Sopenharmony_ciIVec4 getFormatMaxIntValue (const TextureFormat& format); 111e5c31af7Sopenharmony_ci 112e5c31af7Sopenharmony_ciUVec4 getFormatMaxUintValue (const TextureFormat& format); 113e5c31af7Sopenharmony_ci 114e5c31af7Sopenharmony_ci// Texture fill. 115e5c31af7Sopenharmony_civoid clear (const PixelBufferAccess& access, const Vec4& color); 116e5c31af7Sopenharmony_civoid clear (const PixelBufferAccess& access, const IVec4& color); 117e5c31af7Sopenharmony_civoid clear (const PixelBufferAccess& access, const UVec4& color); 118e5c31af7Sopenharmony_civoid clearDepth (const PixelBufferAccess& access, float depth); 119e5c31af7Sopenharmony_civoid clearStencil (const PixelBufferAccess& access, int stencil); 120e5c31af7Sopenharmony_civoid fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 121e5c31af7Sopenharmony_civoid fillWithComponentGradients2 (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 122e5c31af7Sopenharmony_civoid fillWithComponentGradients3 (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 123e5c31af7Sopenharmony_civoid fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB); 124e5c31af7Sopenharmony_civoid fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB); 125e5c31af7Sopenharmony_civoid fillWithMetaballs (const PixelBufferAccess& access, int numMetaballs, deUint32 seed); 126e5c31af7Sopenharmony_civoid fillWithRGBAQuads (const PixelBufferAccess& access); 127e5c31af7Sopenharmony_ci 128e5c31af7Sopenharmony_ci//! Copies contents of src to dst. If formats of dst and src are equal, a bit-exact copy is made. 129e5c31af7Sopenharmony_civoid copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, const bool clearUnused = DE_TRUE); 130e5c31af7Sopenharmony_ci 131e5c31af7Sopenharmony_civoid scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter); 132e5c31af7Sopenharmony_ci 133e5c31af7Sopenharmony_civoid estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal); 134e5c31af7Sopenharmony_civoid computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias); 135e5c31af7Sopenharmony_ci 136e5c31af7Sopenharmony_ciint getCubeArrayFaceIndex (CubeFace face); 137e5c31af7Sopenharmony_ci 138e5c31af7Sopenharmony_ci//! FP32->U8 with RTE rounding (extremely fast, always accurate). 139e5c31af7Sopenharmony_ciinline deUint8 floatToU8 (float fv) 140e5c31af7Sopenharmony_ci{ 141e5c31af7Sopenharmony_ci union { float fv; deUint32 uv; deInt32 iv; } v; 142e5c31af7Sopenharmony_ci v.fv = fv; 143e5c31af7Sopenharmony_ci 144e5c31af7Sopenharmony_ci const deUint32 e = (deUint32)(126-(v.iv>>23)); 145e5c31af7Sopenharmony_ci deUint32 m = v.uv; 146e5c31af7Sopenharmony_ci 147e5c31af7Sopenharmony_ci m &= 0x00ffffffu; 148e5c31af7Sopenharmony_ci m |= 0x00800000u; 149e5c31af7Sopenharmony_ci m = (m << 8) - m; 150e5c31af7Sopenharmony_ci m = (e > 8) ? e : (0x00800000u + (m >> e)); 151e5c31af7Sopenharmony_ci 152e5c31af7Sopenharmony_ci return (deUint8)(m>>24); 153e5c31af7Sopenharmony_ci} 154e5c31af7Sopenharmony_ci 155e5c31af7Sopenharmony_cideUint32 packRGB999E5 (const tcu::Vec4& color); 156e5c31af7Sopenharmony_ci 157e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 158e5c31af7Sopenharmony_ci * \brief Depth-stencil utilities 159e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 160e5c31af7Sopenharmony_ci 161e5c31af7Sopenharmony_ciTextureFormat getEffectiveDepthStencilTextureFormat (const TextureFormat& baseFormat, Sampler::DepthStencilMode mode); 162e5c31af7Sopenharmony_ci 163e5c31af7Sopenharmony_ci//! returns the currently effective access to an access with a given sampler mode, e.g. 164e5c31af7Sopenharmony_ci//! for combined depth stencil accesses and for sampler set to sample stencil returns 165e5c31af7Sopenharmony_ci//! stencil access. Identity for non-combined formats. 166e5c31af7Sopenharmony_ciPixelBufferAccess getEffectiveDepthStencilAccess (const PixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 167e5c31af7Sopenharmony_ciConstPixelBufferAccess getEffectiveDepthStencilAccess (const ConstPixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 168e5c31af7Sopenharmony_ci 169e5c31af7Sopenharmony_ci//! returns the currently effective view to an texture with a given sampler mode. Uses 170e5c31af7Sopenharmony_ci//! storage for access storage storage 171e5c31af7Sopenharmony_ci 172e5c31af7Sopenharmony_citcu::Texture1DView getEffectiveTextureView (const tcu::Texture1DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 173e5c31af7Sopenharmony_citcu::Texture2DView getEffectiveTextureView (const tcu::Texture2DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 174e5c31af7Sopenharmony_citcu::Texture3DView getEffectiveTextureView (const tcu::Texture3DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 175e5c31af7Sopenharmony_citcu::Texture1DArrayView getEffectiveTextureView (const tcu::Texture1DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 176e5c31af7Sopenharmony_citcu::Texture2DArrayView getEffectiveTextureView (const tcu::Texture2DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 177e5c31af7Sopenharmony_citcu::TextureCubeView getEffectiveTextureView (const tcu::TextureCubeView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 178e5c31af7Sopenharmony_citcu::TextureCubeArrayView getEffectiveTextureView (const tcu::TextureCubeArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 179e5c31af7Sopenharmony_ci 180e5c31af7Sopenharmony_citemplate <typename ScalarType> 181e5c31af7Sopenharmony_citcu::Vector<ScalarType, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); 182e5c31af7Sopenharmony_ci 183e5c31af7Sopenharmony_ci} // tcu 184e5c31af7Sopenharmony_ci 185e5c31af7Sopenharmony_ci#endif // _TCUTEXTUREUTIL_HPP 186