13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUTEXTUREUTIL_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUTEXTUREUTIL_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Texture utilities. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// PixelBufferAccess utilities. 3341920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 3441920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int z, int width, int height, int depth); 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3641920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryPixelBufferAccess getSubregion (const PixelBufferAccess& access, int x, int y, int width, int height); 3741920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryConstPixelBufferAccess getSubregion (const ConstPixelBufferAccess& access, int x, int y, int width, int height); 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3941920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryPixelBufferAccess flipYAccess (const PixelBufferAccess& access); 4041920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryConstPixelBufferAccess flipYAccess (const ConstPixelBufferAccess& access); 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4209037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyrybool isCombinedDepthStencilType (TextureFormat::ChannelType type); 4343b3c7468cee6a00bb75470ed5386b2c54b88874Mika Isojärvibool hasStencilComponent (TextureFormat::ChannelOrder order); 4443b3c7468cee6a00bb75470ed5386b2c54b88874Mika Isojärvibool hasDepthComponent (TextureFormat::ChannelOrder order); 4509037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// sRGB - linear conversion. 4741920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryVec4 sRGBToLinear (const Vec4& cs); 48a99421e9ede7fac9c1ea832038e2b6dfe4231845Mika IsojärviVec4 sRGB8ToLinear (const UVec4& cs); 49a99421e9ede7fac9c1ea832038e2b6dfe4231845Mika IsojärviVec4 sRGBA8ToLinear (const UVec4& cs); 5041920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryVec4 linearToSRGB (const Vec4& cl); 5141920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyrybool isSRGB (TextureFormat format); 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Color channel storage type 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TextureChannelClass 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_SIGNED_FIXED_POINT = 0, 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT, 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_SIGNED_INTEGER, 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_UNSIGNED_INTEGER, 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_FLOATING_POINT, 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TEXTURECHANNELCLASS_LAST 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 6725977694b814e285649d6a60c148cb3b5a04ef30Pyry HaulosTextureChannelClass getTextureChannelClass (TextureFormat::ChannelType channelType); 6825977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos 6925977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos/*--------------------------------------------------------------------*//*! 7025977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos * \brief Texture access type 7125977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos *//*--------------------------------------------------------------------*/ 7225977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulosenum TextureAccessType 7325977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos{ 7425977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos TEXTUREACCESSTYPE_FLOAT = 0, //!< Read (getPixel) or write as floating-point data 7525977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos TEXTUREACCESSTYPE_SIGNED_INT, //!< Read (getPixelInt) or write as signed integer data 7625977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos TEXTUREACCESSTYPE_UNSIGNED_INT, //!< Read (getPixelUint) or write as unsigned integer data 7725977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos 7825977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos TEXTUREACCESSTYPE_LAST 7925977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos}; 8025977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulos 8125977694b814e285649d6a60c148cb3b5a04ef30Pyry Haulosbool isAccessValid (TextureFormat format, TextureAccessType type); 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Standard parameters for texture format testing 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct TextureFormatInfo 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 valueMin; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 valueMax; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 lookupScale; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Vec4 lookupBias; 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TextureFormatInfo (const Vec4& valueMin_, const Vec4& valueMax_, const Vec4& lookupScale_, const Vec4& lookupBias_) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : valueMin (valueMin_) 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , valueMax (valueMax_) 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , lookupScale (lookupScale_) 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , lookupBias (lookupBias_) 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 10093df37596ea66700965094b3aa2830cf4f2ca5aaJarkko Pöyry} DE_WARN_UNUSED_TYPE; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 102ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryTextureFormatInfo getTextureFormatInfo (const TextureFormat& format); 103ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryIVec4 getTextureFormatBitDepth (const TextureFormat& format); 104ade588f3b2b1b6d007b9681e95434dc4a4bd46caJarkko PöyryIVec4 getTextureFormatMantissaBitDepth (const TextureFormat& format); 10566ff4f4209ef24ee7216925c15c4acc5ced88c3eJarkko PöyryBVec4 getTextureFormatChannelMask (const TextureFormat& format); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1074356bb5b4e9a1559ecea41265ee242d37aacaa38Mika IsojärviIVec4 getFormatMinIntValue (const TextureFormat& format); 1084356bb5b4e9a1559ecea41265ee242d37aacaa38Mika IsojärviIVec4 getFormatMaxIntValue (const TextureFormat& format); 1094356bb5b4e9a1559ecea41265ee242d37aacaa38Mika Isojärvi 1104356bb5b4e9a1559ecea41265ee242d37aacaa38Mika IsojärviUVec4 getFormatMaxUintValue (const TextureFormat& format); 1114356bb5b4e9a1559ecea41265ee242d37aacaa38Mika Isojärvi 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Texture fill. 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const PixelBufferAccess& access, const Vec4& color); 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clear (const PixelBufferAccess& access, const IVec4& color); 115cd7a989d6ad7df86bd4288eabbe66720625c4607Mika Isojärvivoid clear (const PixelBufferAccess& access, const UVec4& color); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearDepth (const PixelBufferAccess& access, float depth); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid clearStencil (const PixelBufferAccess& access, int stencil); 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithComponentGradients (const PixelBufferAccess& access, const Vec4& minVal, const Vec4& maxVal); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithGrid (const PixelBufferAccess& access, int cellSize, const Vec4& colorA, const Vec4& colorB); 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithRepeatableGradient (const PixelBufferAccess& access, const Vec4& colorA, const Vec4& colorB); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithMetaballs (const PixelBufferAccess& access, int numMetaballs, deUint32 seed); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid fillWithRGBAQuads (const PixelBufferAccess& access); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1246c307165131fb7249bb044fc79ff0c2747263b3dJarkko Pöyry//! Copies contents of src to dst. If formats of dst and src are equal, a bit-exact copy is made. 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid copy (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1276c307165131fb7249bb044fc79ff0c2747263b3dJarkko Pöyryvoid scale (const PixelBufferAccess& dst, const ConstPixelBufferAccess& src, Sampler::FilterMode filter); 128becd5d53015521acf7536ba754de326d8b1da2f3Mika Isojärvi 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid estimatePixelValueRange (const ConstPixelBufferAccess& access, Vec4& minVal, Vec4& maxVal); 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid computePixelScaleBias (const ConstPixelBufferAccess& access, Vec4& scale, Vec4& bias); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1328852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyryint getCubeArrayFaceIndex (CubeFace face); 1338852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! FP32->U8 with RTE rounding (extremely fast, always accurate). 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline deUint8 floatToU8 (float fv) 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry union { float fv; deUint32 uv; deInt32 iv; } v; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry v.fv = fv; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 e = (deUint32)(126-(v.iv>>23)); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m = v.uv; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m &= 0x00ffffffu; 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m |= 0x00800000u; 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m = (m << 8) - m; 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m = 0x00800000u + (m >> e); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (e > 8) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m = e; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return (deUint8)(m>>24); 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1542925635ad62614cb6c5f824c22e31e8ca6bbb03eMika IsojärvideUint32 packRGB999E5 (const tcu::Vec4& color); 1552925635ad62614cb6c5f824c22e31e8ca6bbb03eMika Isojärvi 15641920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry/*--------------------------------------------------------------------*//*! 15741920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry * \brief Depth-stencil utilities 15841920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry *//*--------------------------------------------------------------------*/ 15941920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry 16041920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryTextureFormat getEffectiveDepthStencilTextureFormat (const TextureFormat& baseFormat, Sampler::DepthStencilMode mode); 16141920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry 16241920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry//! returns the currently effective access to an access with a given sampler mode, e.g. 16341920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry//! for combined depth stencil accesses and for sampler set to sample stencil returns 16441920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry//! stencil access. Identity for non-combined formats. 16541920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryPixelBufferAccess getEffectiveDepthStencilAccess (const PixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 16641920d7e0d1833907249009d156f6eb2361df97eJarkko PöyryConstPixelBufferAccess getEffectiveDepthStencilAccess (const ConstPixelBufferAccess& baseAccess, Sampler::DepthStencilMode mode); 16741920d7e0d1833907249009d156f6eb2361df97eJarkko Pöyry 1680d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyry//! returns the currently effective view to an texture with a given sampler mode. Uses 1690d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyry//! storage for access storage storage 1700d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyry 1710d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::Texture1DView getEffectiveTextureView (const tcu::Texture1DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1720d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::Texture2DView getEffectiveTextureView (const tcu::Texture2DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1730d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::Texture3DView getEffectiveTextureView (const tcu::Texture3DView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1740d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::Texture1DArrayView getEffectiveTextureView (const tcu::Texture1DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1750d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::Texture2DArrayView getEffectiveTextureView (const tcu::Texture2DArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1760d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::TextureCubeView getEffectiveTextureView (const tcu::TextureCubeView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1770d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyrytcu::TextureCubeArrayView getEffectiveTextureView (const tcu::TextureCubeArrayView& src, std::vector<tcu::ConstPixelBufferAccess>& storage, const tcu::Sampler& sampler); 1780d61ad28c122cede72a061c4b8346a176b245b69Jarkko Pöyry 179222c1cfbf44db3a0bd251ef230e55c3602e518ccJarkko Pöyrytemplate <typename ScalarType> 180222c1cfbf44db3a0bd251ef230e55c3602e518ccJarkko Pöyrytcu::Vector<ScalarType, 4> sampleTextureBorder (const TextureFormat& format, const Sampler& sampler); 181222c1cfbf44db3a0bd251ef230e55c3602e518ccJarkko Pöyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUTEXTUREUTIL_HPP 185