sp_tex_sample.c revision fd60bf8e33bbcba7b7749ae5a4285bad60769b9b
10dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul/************************************************************************** 20dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 30dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 40dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * All Rights Reserved. 54bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Copyright 2008-2010 VMware, Inc. All rights reserved. 60dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 70dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * Permission is hereby granted, free of charge, to any person obtaining a 80dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * copy of this software and associated documentation files (the 90dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * "Software"), to deal in the Software without restriction, including 100dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * without limitation the rights to use, copy, modify, merge, publish, 110dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * distribute, sub license, and/or sell copies of the Software, and to 120dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * permit persons to whom the Software is furnished to do so, subject to 130dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * the following conditions: 140dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 150dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * The above copyright notice and this permission notice (including the 160dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * next paragraph) shall be included in all copies or substantial portions 170dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * of the Software. 180dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 190dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 200dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 210dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 220dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 230dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 240dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 250dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 260dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 270dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul **************************************************************************/ 280dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 290dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul/** 300dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * Texture sampling 310dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * 320dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * Authors: 330dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * Brian Paul 344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Keith Whitwell 350dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul */ 360dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 370dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul#include "pipe/p_context.h" 380dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul#include "pipe/p_defines.h" 3900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell#include "pipe/p_shader_tokens.h" 401a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul#include "util/u_math.h" 414f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 42d204659c8c725c02212ad4a49275c7447f2d02a6Brian Paul#include "sp_quad.h" /* only for #define QUAD_* tokens */ 43d204659c8c725c02212ad4a49275c7447f2d02a6Brian Paul#include "sp_tex_sample.h" 447670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell#include "sp_tex_tile_cache.h" 450dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 460dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 473ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 4808f33a025100dea2d951e6d628891fe294b18082Brian Paul/* 49b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Return fractional part of 'f'. Used for computing interpolation weights. 50b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Need to be careful with negative values. 51b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Note, if this function isn't perfect you'll sometimes see 1-pixel bands 52b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * of improperly weighted linear-filtered textures. 5308f33a025100dea2d951e6d628891fe294b18082Brian Paul * The tests/texwrap.c demo is a good test. 5408f33a025100dea2d951e6d628891fe294b18082Brian Paul */ 55b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulstatic INLINE float 56b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulfrac(float f) 57b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul{ 58b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul return f - floorf(f); 59b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul} 60b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul 6108f33a025100dea2d951e6d628891fe294b18082Brian Paul 6208f33a025100dea2d951e6d628891fe294b18082Brian Paul 6308f33a025100dea2d951e6d628891fe294b18082Brian Paul/** 6408f33a025100dea2d951e6d628891fe294b18082Brian Paul * Linear interpolation macro 6508f33a025100dea2d951e6d628891fe294b18082Brian Paul */ 6638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paulstatic INLINE float 6738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paullerp(float a, float v0, float v1) 6838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul{ 6938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul return v0 + a * (v1 - v0); 7038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul} 710dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 720dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 730dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul/** 74fd60bf8e33bbcba7b7749ae5a4285bad60769b9bBrian Paul * Do 2D/bilinear interpolation of float values. 750dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * v00, v10, v01 and v11 are typically four texture samples in a square/box. 760dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * a and b are the horizontal and vertical interpolants. 770dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * It's important that this function is inlined when compiled with 780dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * optimization! If we find that's not true on some systems, convert 790dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul * to a macro. 800dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul */ 81b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paulstatic INLINE float 82b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paullerp_2d(float a, float b, 83b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul float v00, float v10, float v01, float v11) 840dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul{ 8538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul const float temp0 = lerp(a, v00, v10); 8638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul const float temp1 = lerp(a, v01, v11); 8738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul return lerp(b, temp0, temp1); 8838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul} 8938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul 9038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul 9138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul/** 9238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * As above, but 3D interpolation of 8 values. 9338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul */ 9438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paulstatic INLINE float 9538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paullerp_3d(float a, float b, float c, 9638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul float v000, float v100, float v010, float v110, 9738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul float v001, float v101, float v011, float v111) 9838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul{ 9938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul const float temp0 = lerp_2d(a, b, v000, v100, v010, v110); 10038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul const float temp1 = lerp_2d(a, b, v001, v101, v011, v111); 10138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul return lerp(c, temp0, temp1); 1020dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul} 1030dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 1040dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 10538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul 1060dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul/** 107b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Compute coord % size for repeat wrap modes. 108b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Note that if coord is a signed integer, coord % size doesn't give 109b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * the right value for coord < 0 (in terms of texture repeat). Just 110b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * casting to unsigned fixes that. 1110dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul */ 112b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulstatic INLINE int 113b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulrepeat(int coord, unsigned size) 114b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul{ 115b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul return (int) ((unsigned) coord % size); 116b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul} 11708f33a025100dea2d951e6d628891fe294b18082Brian Paul 11808f33a025100dea2d951e6d628891fe294b18082Brian Paul 11908f33a025100dea2d951e6d628891fe294b18082Brian Paul/** 12038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * Apply texture coord wrapping mode and return integer texture indexes 12138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * for a vector of four texcoords (S or T or P). 12208f33a025100dea2d951e6d628891fe294b18082Brian Paul * \param wrapMode PIPE_TEX_WRAP_x 12338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param s the incoming texcoords 12408f33a025100dea2d951e6d628891fe294b18082Brian Paul * \param size the texture image size 12538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param icoord returns the integer texcoords 12608f33a025100dea2d951e6d628891fe294b18082Brian Paul * \return integer texture index 12708f33a025100dea2d951e6d628891fe294b18082Brian Paul */ 1284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 129e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_repeat(const float s[4], unsigned size, int icoord[4]) 1304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1) */ 1334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch] * size); 136b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord[ch] = repeat(i, size); 1374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 142e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp(const float s[4], unsigned size, int icoord[4]) 1430dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul{ 14438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul uint ch; 1454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1] */ 1464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= 0.0F) 1494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= 1.0F) 1514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 159e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_edge(const float s[4], unsigned size, int icoord[4]) 1604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 1644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] < min) 1684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] > max) 1704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 178e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_border(const float s[4], unsigned size, int icoord[4]) 1794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [-1, size] */ 1834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 1844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= min) 1874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 1884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= max) 1894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 1904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 195e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 197e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4]) 1984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 204b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul float u = frac(s[ch]); 2054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 206b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul u = 1.0F - u; 2074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 216e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 218e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_clamp(const float s[4], unsigned size, int icoord[4]) 2194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 22208f33a025100dea2d951e6d628891fe294b18082Brian Paul /* s limited to [0,1] */ 22308f33a025100dea2d951e6d628891fe294b18082Brian Paul /* i limited to [0,size-1] */ 2244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= 0.0F) 2264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= 1.0F) 2284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 234e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, 237e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 2384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, 2584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 2644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 2694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 2714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2730dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul } 2740dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul} 2750dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 27608f33a025100dea2d951e6d628891fe294b18082Brian Paul 27708f33a025100dea2d951e6d628891fe294b18082Brian Paul/** 27838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * Used to compute texel locations for linear sampling for four texcoords. 27908f33a025100dea2d951e6d628891fe294b18082Brian Paul * \param wrapMode PIPE_TEX_WRAP_x 28038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param s the texcoords 28108f33a025100dea2d951e6d628891fe294b18082Brian Paul * \param size the texture image size 28238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param icoord0 returns first texture indexes 28338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param icoord1 returns second texture indexes (usually icoord0 + 1) 28438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param w returns blend factor/weight between texture indexes 28538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul * \param icoord returns the computed integer texture coords 28608f33a025100dea2d951e6d628891fe294b18082Brian Paul */ 2874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_repeat(const float s[4], unsigned size, 2894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 2904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = s[ch] * size - 0.5F; 294b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord0[ch] = repeat(util_ifloor(u), size); 295b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord1[ch] = repeat(icoord0[ch] + 1, size); 296b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 2974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 300e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp(const float s[4], unsigned size, 30338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul int icoord0[4], int icoord1[4], float w[4]) 3040dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul{ 30538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul uint ch; 3064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 311b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 31438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul 315e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_edge(const float s[4], unsigned size, 3184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 330b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 334e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_border(const float s[4], unsigned size, 3374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 3404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 3414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], min, max); 3444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 347b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_repeat(const float s[4], unsigned size, 3544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 359b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul float u = frac(s[ch]); 3604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 361b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul u = 1.0F - u; 3624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5F; 3634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 369b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 373e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp(const float s[4], unsigned size, 3764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 388b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 392e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size, 3954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 4014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 4024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 4084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 4094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 4104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 411b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 4124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 415e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 4164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, 4184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 4194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 4214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 4224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= min) 4264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = min * size; 4274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= max) 4284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = max * size; 4294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 434b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 4350dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul } 4360dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul} 4370dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 4380dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul 439b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul/** 440b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords. 441b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul */ 4424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 443e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) 444b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul{ 44538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul uint ch; 4464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch]); 4484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= CLAMP(i, 0, (int) size-1); 4494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 452e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 453e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 454b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords. 4554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 4564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, 458e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 4594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 462b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord[ch]= util_ifloor( CLAMP(s[ch], -0.5F, (float) size + 0.5F) ); 463b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul } 464b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul} 465b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 466b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 467b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 468b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords. 469b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 470b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulstatic void 471b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulwrap_nearest_unorm_clamp_to_edge(const float s[4], unsigned size, 472b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul int icoord[4]) 473b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul{ 474b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul uint ch; 475b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul for (ch = 0; ch < 4; ch++) { 4764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); 477b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 478b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul} 479b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 480b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 481b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul/** 482b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords. 483b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul */ 4844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp(const float s[4], unsigned size, 486e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord0[4], int icoord1[4], float w[4]) 487b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul{ 48838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul uint ch; 4894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Not exactly what the spec says, but it matches NVIDIA output */ 4914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); 4924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 494b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 495b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 496b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul} 497b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 498e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 499b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 500b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords. 501b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 5024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 503e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_linear_unorm_clamp_to_border(const float s[4], unsigned size, 504e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord0[4], int icoord1[4], float w[4]) 50534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 5064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 5074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 508b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul float u = CLAMP(s[ch], -0.5F, (float) size + 0.5F); 509b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul u -= 0.5F; 510b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord0[ch] = util_ifloor(u); 511b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord1[ch] = icoord0[ch] + 1; 512b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul if (icoord1[ch] > (int) size - 1) 513b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord1[ch] = size - 1; 514b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul w[ch] = frac(u); 515b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul } 516b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul} 517b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 518b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 519b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 520b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords. 521b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 522b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulstatic void 523b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulwrap_linear_unorm_clamp_to_edge(const float s[4], unsigned size, 524b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul int icoord0[4], int icoord1[4], float w[4]) 525b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul{ 526b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul uint ch; 527b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul for (ch = 0; ch < 4; ch++) { 528b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul float u = CLAMP(s[ch], +0.5F, (float) size - 0.5F); 5294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 5304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 5314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 5324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] > (int) size - 1) 5334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 534b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 53534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul } 5364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 5374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 53834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 53934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 540b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul/** 541b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul * Examine the quad's texture coordinates to compute the partial 542b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul * derivatives w.r.t X and Y, then compute lambda (level of detail). 543b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul */ 544b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paulstatic float 5454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_1d(const struct sp_sampler_varient *samp, 5464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5484bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 549b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul{ 550287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 553683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float rho = MAX2(dsdx, dsdy) * texture->width0; 554b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 5554bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 556b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul} 557b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 558e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 5594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_2d(const struct sp_sampler_varient *samp, 5614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5634bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 56409a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul{ 565287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 570683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width0; 571683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height0; 5724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 573c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian Paul 5744bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 57509a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul} 57609a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul 57708f33a025100dea2d951e6d628891fe294b18082Brian Paul 5784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_3d(const struct sp_sampler_varient *samp, 5804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5824bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 58309a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul{ 584287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 5904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 591683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width0; 592683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height0; 593683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxz = MAX2(dpdx, dpdy) * texture->depth0; 5944bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float rho; 59500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 5974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 598c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian Paul 5994bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 60009a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul} 60109a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul 60208f33a025100dea2d951e6d628891fe294b18082Brian Paul 603e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 604e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Compute lambda for a vertex texture sampler. 6054bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Since there aren't derivatives to use, just return 0. 606e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul */ 6074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 6084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_vert(const struct sp_sampler_varient *samp, 6094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 6104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 6114bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 6124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 6134bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return 0.0f; 6144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 6154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 6194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 6204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 62181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell * \param addr the template tex address containing cube, z, face info. 6224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 623b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul * \param y the y coord of texel within 2D image 624b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul * \param rgba the quad to put the texel/color into 62570eb7996f265f3634dabda078f13d1be3533cc65Brian Paul * 62680c78472ad43f4288c9ef5076074ba9d31a39885Keith Whitwell * XXX maybe move this into sp_tex_tile_cache.c and merge with the 62770eb7996f265f3634dabda078f13d1be3533cc65Brian Paul * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 628b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul */ 62981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 63481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d_no_border(const struct sp_sampler_varient *samp, 63581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 636b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul{ 63781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 63881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 64081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 64181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y %= TILE_SIZE; 64281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell x %= TILE_SIZE; 64381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 64581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return &tile->data.color[y][x][0]; 64781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 64881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 65181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d(const struct sp_sampler_varient *samp, 65281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 65381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 654287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 65581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 65681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 657683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 658683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level)) { 65981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 66081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 66181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell else { 66281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_2d_no_border( samp, addr, x, y ); 66381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 66481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 6656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 66781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of adjacent texels within a tile: 66881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 66981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 67081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border_single_tile(const struct sp_sampler_varient *samp, 67181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 67281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned x, unsigned y, 67381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 67481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 67581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 67681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 67781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 67881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 6796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 68181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 68281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 6836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 6856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 6866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 6876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 6886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 69081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of potentially non-adjacent texels: 69281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 69381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 69481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border(const struct sp_sampler_varient *samp, 69581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 69681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 69781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 69881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 69981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 70081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); 70181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); 70281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); 70381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); 70481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 70581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 70681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Can involve a lot of unnecessary checks for border color: 70781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 70881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 70981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d(const struct sp_sampler_varient *samp, 71081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 71181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 71281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 71381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 71481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 71581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d( samp, addr, x0, y0 ); 71681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d( samp, addr, x1, y0 ); 71781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d( samp, addr, x1, y1 ); 71881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d( samp, addr, x0, y1 ); 71981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 72081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* 3d varients: 72481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 7256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 72681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d_no_border(const struct sp_sampler_varient *samp, 727e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 7286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 729153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const struct softpipe_tex_cached_tile *tile; 7306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 731153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.x = x / TILE_SIZE; 732153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.y = y / TILE_SIZE; 73381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.z = z; 7346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 7356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 7366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 737153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 738153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 7406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 74381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 74481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d(const struct sp_sampler_varient *samp, 745e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 746b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul{ 747287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 74881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 7490b9e96fae9493d5d58f046e01c983a3c4267090eBrian Paul 750683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 751683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level) || 752683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell z < 0 || z >= (int) u_minify(texture->depth0, level)) { 75381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 754ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 755ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 75681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_3d_no_border( samp, addr, x, y, z ); 757ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 758b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul} 759b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 760b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 76175276ea316610a5737f2115326482024aa09d02aBrian Paul/** 76275276ea316610a5737f2115326482024aa09d02aBrian Paul * Given the logbase2 of a mipmap's base level size and a mipmap level, 76375276ea316610a5737f2115326482024aa09d02aBrian Paul * return the size (in texels) of that mipmap level. 76475276ea316610a5737f2115326482024aa09d02aBrian Paul * For example, if level[0].width = 256 then base_pot will be 8. 76575276ea316610a5737f2115326482024aa09d02aBrian Paul * If level = 2, then we'll return 64 (the width at level=2). 76675276ea316610a5737f2115326482024aa09d02aBrian Paul * Return 1 if level > base_pot. 76775276ea316610a5737f2115326482024aa09d02aBrian Paul */ 76875276ea316610a5737f2115326482024aa09d02aBrian Paulstatic INLINE unsigned 76975276ea316610a5737f2115326482024aa09d02aBrian Paulpot_level_size(unsigned base_pot, unsigned level) 77075276ea316610a5737f2115326482024aa09d02aBrian Paul{ 77175276ea316610a5737f2115326482024aa09d02aBrian Paul return (base_pot >= level) ? (1 << (base_pot - level)) : 1; 77275276ea316610a5737f2115326482024aa09d02aBrian Paul} 77375276ea316610a5737f2115326482024aa09d02aBrian Paul 77475276ea316610a5737f2115326482024aa09d02aBrian Paul 77581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Some image-filter fastpaths: 77681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 777efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 7784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 779e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 780e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 781e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 7824440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 7834440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 784e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 7856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 7864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 7876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 7886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 78975276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned xpot = pot_level_size(samp->xpot, level); 79075276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned ypot = pot_level_size(samp->ypot, level); 7911fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 7921fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 793153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 794153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 795153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 796153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 797153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 7996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8006142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8016142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 8026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 8036142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8056142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8066142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8076142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 8086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 8096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 813153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const float *tx[4]; 8146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 8166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 817e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul if (x0 < xmax && y0 < ymax) { 81881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); 8196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 820e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul else { 8214f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 8224f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 82381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); 8246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 8276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 8296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 8306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 8316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 8384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8414440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 8424440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 8434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 84875276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned xpot = pot_level_size(samp->xpot, level); 84975276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned ypot = pot_level_size(samp->ypot, level); 850153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 851153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 852153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 853153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8585fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8595fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 86781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d_no_border(samp, addr, x0, y0); 8686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 8784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8814440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 8824440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 8834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 88875276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned xpot = pot_level_size(samp->xpot, level); 88975276ea316610a5737f2115326482024aa09d02aBrian Paul unsigned ypot = pot_level_size(samp->ypot, level); 890153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 891153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 892153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 893153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8985fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8995fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 9006142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9016142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 9026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 9036142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 9056142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 9066142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 9076142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 9086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 9096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 9116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 9126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 9136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 9146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 9156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 91681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out = get_texel_2d_no_border(samp, addr, x0, y0); 9176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 9196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 9206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 924e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 9256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 9264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 9274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9304440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9314440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 9324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 9344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 935287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 9364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 9374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 9384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 93981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 9406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 942683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 9436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 9454f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 94681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 94781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 94881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 9494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9504f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 9514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 95281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, addr, x[j], 0); 95381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 95481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 95581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 95681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 9574f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 9586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 96160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 96260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 96360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 96460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 96560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 9664440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9674440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 96860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 96960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 97060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 971287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 97260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 97360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 97460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x[4], y[4]; 97560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 97681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 97781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 97860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 979683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 980683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 98160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 98260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 9835dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 98460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 98560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 98660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 98760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 98860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_s(s, width, x); 98960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_t(t, height, y); 99060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 99160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 99260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *out = get_texel_2d(samp, addr, x[j], y[j]); 99360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 99460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 99560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = out[c]; 99660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 99760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 99860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 99960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 1000e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 10019659aa6482291d1530c74450612bcd952f542e01José Fonsecastatic INLINE union tex_tile_address 1002e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulface(union tex_tile_address addr, unsigned face ) 100381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 100481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.face = face; 100581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return addr; 100681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 100781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1008e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1009e12810d92ffb3547680b227bf88937c03018112bBrian Paulstatic void 101060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, 1011e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1012e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1013e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 10144440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10154440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1016e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 10170dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul{ 10184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1019287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 10204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 10214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1022f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian Paul int width, height; 10234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 102481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 102581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1027683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1028683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 102909a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul 1030b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul assert(width > 0); 10315dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 103281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 103381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 103481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 1035612cfb749c3526eeb446bbc631bf24716522f373Brian Paul 10364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 1038f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian Paul 10394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 104081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); 104181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 104281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 104381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 104481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10450dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul } 10460dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul} 104734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 104834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 10494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 10514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10544440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10554440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 10564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 105734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 10584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1059287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 10604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10613d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul int width, height, depth; 10624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 106381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1064b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 10654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1066683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1067683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1068683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 10693d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul 10703d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul assert(width > 0); 10713d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul assert(height > 0); 10723d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul assert(depth > 0); 10733d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul 10744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 10764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 10773d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul 107881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 107981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 108081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 108281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); 108381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 108481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 108581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 108681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10873d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul } 108834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul} 108934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 109034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 109134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paulstatic void 10924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 10934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10964440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10974440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 10984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 109934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 11004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1101287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 11024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 11034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 11044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 11054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 110681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 11074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1109683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 11104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 11124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 111381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 111481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 111581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 11174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1118b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 111981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); 112081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); 11214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 11224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 11244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 112581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 11264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1127b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul } 112834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul} 112934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 113081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 113160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 113260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 113360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 113460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 113560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 11364440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 11374440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 113860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 113960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 114060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1141287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 114260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 114360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 114460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 114560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float xw[4], yw[4]; /* weights */ 114660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 114760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 114860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 1149683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1150683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 115160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 115260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 11535dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 115460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 115560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 115660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 115760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 115860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 115960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_t(t, height, y0, y1, yw); 116060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 116160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 116260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); 116360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); 116460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); 116560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); 116660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 116760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 116860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* interpolate R, G, B, A */ 116960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 117060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 117160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx0[c], tx1[c], 117260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx2[c], tx3[c]); 117360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 117460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 117560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 117681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 117781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1178b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paulstatic void 117960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, 1180e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1181e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1182e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 11834440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 11844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1185e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1186b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul{ 11874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1188287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 11894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 11904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1191b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul int width, height; 11924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 11934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 119481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1195b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 11964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1197683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1198683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1199b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 1200b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul assert(width > 0); 12015dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 1202b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 120381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 120481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 120581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12074e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 121081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addrj = face(addr, faces[j]); 121181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); 121281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); 121381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); 121481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); 12154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 122081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx0[c], tx1[c], 122181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx2[c], tx3[c]); 1222b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 12234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 12294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12324440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 12334440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 12344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 12354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 12364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1237287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 12384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 12394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 12404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 12414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 124281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 12434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1245683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1246683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1247683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 12484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 124981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 125081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = level0; 125181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 12534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 12544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 12554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12574e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12584e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 12594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 126381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); 126481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); 126581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); 126681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); 126781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 126881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); 126981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); 127081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); 127181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); 127281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 127681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx00[c], tx01[c], 127781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx02[c], tx03[c], 127881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx10[c], tx11[c], 127981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx12[c], tx13[c]); 12804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12854bfe1c955fe679547c8a03119d1681e33593c768Michal Krol/* Calculate level of detail for every fragment. 12864bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Note that lambda has already been biased by global LOD bias. 12874bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 12884bfe1c955fe679547c8a03119d1681e33593c768Michal Krolstatic INLINE void 12894bfe1c955fe679547c8a03119d1681e33593c768Michal Krolcompute_lod(const struct pipe_sampler_state *sampler, 12904bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float biased_lambda, 12914bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float lodbias[QUAD_SIZE], 12924bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]) 12934bfe1c955fe679547c8a03119d1681e33593c768Michal Krol{ 12944bfe1c955fe679547c8a03119d1681e33593c768Michal Krol uint i; 12954bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 12964bfe1c955fe679547c8a03119d1681e33593c768Michal Krol for (i = 0; i < QUAD_SIZE; i++) { 12974bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = biased_lambda + lodbias[i]; 12984bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = CLAMP(lod[i], sampler->min_lod, sampler->max_lod); 12994bfe1c955fe679547c8a03119d1681e33593c768Michal Krol } 13004bfe1c955fe679547c8a03119d1681e33593c768Michal Krol} 13014bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13024bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 1305e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1306e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1307e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 13084440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 13094440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1310e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 13114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1313287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 13144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 13154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 13164bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 13174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13184440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 13194440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 13204440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 13214440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 13224440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 13234bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13244440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 13254440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 13264bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13274bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 13284bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 13294bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 13304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 13314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13344440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 13354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 13374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 13384440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 13394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 13424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 13434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 13444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 13454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 13474440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 13484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 13504440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 13514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 13544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1355b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 1356b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 1357b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 1358b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul} 1359b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 1360b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 136185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul/** 136285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Compute nearest mipmap level from texcoords. 136385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Then sample the texture level for four elements of a quad. 136485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * \param c0 the LOD bias factors, or absolute LODs (depending on control) 136585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 13664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 13684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13714440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 13724440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 13734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 13744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1376287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 13774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 13784bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 13794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13804440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 13814440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 13824440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 13834440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 13844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 13854bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13864440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 13874440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 13884bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13894bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 13904bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 13914bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 13924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13954440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 13964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = (int)(lambda + 0.5) ; 13994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 14004440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 140275276ea316610a5737f2115326482024aa09d02aBrian Paul 140375276ea316610a5737f2115326482024aa09d02aBrian Paul#if 0 140475276ea316610a5737f2115326482024aa09d02aBrian Paul printf("RGBA %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n", 140575276ea316610a5737f2115326482024aa09d02aBrian Paul rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0], 140675276ea316610a5737f2115326482024aa09d02aBrian Paul rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1], 140775276ea316610a5737f2115326482024aa09d02aBrian Paul rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2], 140875276ea316610a5737f2115326482024aa09d02aBrian Paul rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]); 140975276ea316610a5737f2115326482024aa09d02aBrian Paul#endif 14104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 14154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14184440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14194440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 14204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 14214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 14234bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lambda; 14244bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 14254bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14264440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 14274440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 14284440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 14294440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 14304440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 14314bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14324440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 14334440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 14344bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14354bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 14364bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 14374bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 14384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 14404440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 14434440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1449e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1450e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Specialized version of mip_filter_linear with hard-wired calls to 14514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1452a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul */ 14534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 14554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 14564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14594440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14604440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 14614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 146200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 14634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1464287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 14654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 14664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 14674bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 14684bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14694440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 14704440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 14714440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 14724440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 14734440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 147400c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 14754440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 14764440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 14774bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14784bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 14794bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 14804bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 14814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 14824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 14844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 14854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 14864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 14874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 14884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 14894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 14904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14914440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 14944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 14954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 14964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 15004440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 15014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 15034440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 15044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 15064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 15084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1509b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul } 1510ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 1511b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul} 1512b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 1513b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul 15144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1515e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1516e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Do shadow/depth comparisons. 15173d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul */ 15184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 15194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1520b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul const float s[QUAD_SIZE], 1521b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul const float t[QUAD_SIZE], 15223d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul const float p[QUAD_SIZE], 15234440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 15244440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1525b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 15263d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul{ 15274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1528aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 15294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 15304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 15313d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul 15324440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mip_filter(tgsi_sampler, s, t, p, c0, control, rgba); 15333d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul 15344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 15354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 1539efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1540efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* compare four texcoords vs. four texture samples */ 1541efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul switch (sampler->compare_func) { 1542efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LESS: 1543efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] < rgba[0][0]; 1544efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] < rgba[0][1]; 1545efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] < rgba[0][2]; 1546efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] < rgba[0][3]; 1547efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1548efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LEQUAL: 1549efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] <= rgba[0][0]; 1550efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] <= rgba[0][1]; 1551efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] <= rgba[0][2]; 1552efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] <= rgba[0][3]; 1553efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1554efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GREATER: 1555efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] > rgba[0][0]; 1556efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] > rgba[0][1]; 1557efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] > rgba[0][2]; 1558efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] > rgba[0][3]; 1559efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1560efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GEQUAL: 1561efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] >= rgba[0][0]; 1562efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] >= rgba[0][1]; 1563efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] >= rgba[0][2]; 1564efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] >= rgba[0][3]; 1565efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1566efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_EQUAL: 1567efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] == rgba[0][0]; 1568efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] == rgba[0][1]; 1569efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] == rgba[0][2]; 1570efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] == rgba[0][3]; 1571efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1572efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NOTEQUAL: 1573efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] != rgba[0][0]; 1574efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] != rgba[0][1]; 1575efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] != rgba[0][2]; 1576efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] != rgba[0][3]; 1577efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1578efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_ALWAYS: 1579efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 1; 1580efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1581efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NEVER: 1582efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1583efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1584efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul default: 1585efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1586efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul assert(0); 1587efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1588efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1589efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1590efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* convert four pass/fail values to an intensity in [0,1] */ 1591efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul val = 0.25F * (k0 + k1 + k2 + k3); 1592efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1593efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 1594efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul for (j = 0; j < 4; j++) { 1595efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 1596efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[3][j] = 1.0F; 1597efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1598efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul} 1599efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1600e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1601e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 160285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use 3D texcoords to choose a cube face, then sample the 2D cube faces. 160385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Put face info into the sampler faces[] array. 16040dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul */ 1605e12810d92ffb3547680b227bf88937c03018112bBrian Paulstatic void 16064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 16074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 16084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 16094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 16104440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 16114440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 16124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 16130dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul{ 16144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 16154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 16164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 161709a1b912605ff48c8782dcc5aae55ac77e27037bBrian Paul 16184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 16194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 162085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul direction target sc tc ma 162185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul ---------- ------------------------------- --- --- --- 16224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 16234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 16244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 16254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 16264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 16274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 16284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 162985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 16309ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul /* Choose the cube face and compute new s/t coords for the 2D face. 16319ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul * 163285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use the same cube face for all four pixels in the quad. 163385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * 163485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * This isn't ideal, but if we want to use a different cube face 163585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per pixel in the quad, we'd have to also compute the per-face 163685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * LOD here too. That's because the four post-face-selection 163785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * texcoords are no longer related to each other (they're 163885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per-face!) so we can't use subtraction to compute the partial 163985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * deriviates to compute the LOD. Doing so (near cube edges 164085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * anyway) gives us pretty much random values. 164185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 164285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul { 164385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul /* use the average of the four pixel's texcoords to choose the face */ 164485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]); 164585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]); 164685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]); 16474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 16484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1649890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell if (arx >= ary && arx >= arz) { 1650c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rx >= 0.0F) ? 1.0F : -1.0F; 1651c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rx >= 0.0F) ? PIPE_TEX_FACE_POS_X : PIPE_TEX_FACE_NEG_X; 1652c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1653c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(s[j]); 1654c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * p[j] * ima + 0.5F; 1655c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1656c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 16574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1659890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell else if (ary >= arx && ary >= arz) { 1660c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (ry >= 0.0F) ? 1.0F : -1.0F; 1661c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (ry >= 0.0F) ? PIPE_TEX_FACE_POS_Y : PIPE_TEX_FACE_NEG_Y; 1662c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1663c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(t[j]); 1664c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = -s[j] * ima + 0.5F; 1665c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = sign * -p[j] * ima + 0.5F; 1666c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 16674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 1670c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rz >= 0.0F) ? 1.0F : -1.0F; 1671c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rz >= 0.0F) ? PIPE_TEX_FACE_POS_Z : PIPE_TEX_FACE_NEG_Z; 1672c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1673c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5 / fabsf(p[j]); 1674c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * -s[j] * ima + 0.5F; 1675c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1676c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 16774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 167985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul } 168085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 16814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 16824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 16834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 16846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 16854440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba); 16864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1687612cfb749c3526eeb446bbc631bf24716522f373Brian Paul 16883d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul 16893d8c05f7320151898dd224c1daaf3118e1f7ea34Brian Paul 1690e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1691e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_unorm_wrap(unsigned mode) 16924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 16934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 16964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 1697b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_nearest_unorm_clamp_to_edge; 16984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 17000dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul default: 17010dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul assert(0); 17024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 17030dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul } 17040dc4eea64f56cc93e5359372b08b99a2d600273cBrian Paul} 170534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 170634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 1707e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1708e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_wrap(unsigned mode) 1709a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul{ 17104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 17114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 17124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 17134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 17144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 17154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 17164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 17174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 17184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 17194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 17204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 17214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 17224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 17234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 17244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 17254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 17264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 17274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 17284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 17294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 17304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1731a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul} 1732a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul 1733e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1734e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1735e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_unorm_wrap(unsigned mode) 1736a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul{ 17374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 17384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 17394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 17404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 1741b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_linear_unorm_clamp_to_edge; 17424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 17434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 17444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 17454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 17464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 17474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1748a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul} 1749a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul 1750e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1751e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1752e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_wrap(unsigned mode) 175334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 17544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 17554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 17564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 17574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 17584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 17594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 17604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 17614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 17624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 17634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 17644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 17654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 17664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 17674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 17684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 17694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 17704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 17713d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul default: 17723d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul assert(0); 17734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 17743d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian Paul } 177534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul} 177634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 1777e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1778e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic compute_lambda_func 1779e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_lambda_func(const union sp_sampler_key key) 178034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 17814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 17824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 17834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 17854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 17864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 17874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 178887ec83afd58536c31bf02c307f1d5488abc84861Brian Paul case PIPE_TEXTURE_CUBE: 17894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 17904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 17914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 17924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 17934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 17944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 1795b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian Paul } 179634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul} 179734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul 1798e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1799e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic filter_func 1800e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_img_filter(const union sp_sampler_key key, 1801e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul unsigned filter, 1802e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const struct pipe_sampler_state *sampler) 1803b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul{ 18044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 18054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 18064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 18074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 18084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 18094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 1810b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul break; 18114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 18124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 18134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 18154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 18164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 181738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul { 18184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 18194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 18204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 18216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 18224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 18236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 18244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 18256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 18266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 182738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul } 18284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 18294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 18304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 18316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 18324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 18336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 18346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 183538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian Paul } 1836b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 1837b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 183860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* Otherwise use default versions: 18394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 18414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 18424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 18434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 18444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 184560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell case PIPE_TEXTURE_CUBE: 184660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 184760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_nearest; 184860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell else 184960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_linear; 185060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell break; 18514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 18524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 18534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 18544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 18554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 1856b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul break; 1857b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul default: 1858b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul assert(0); 18594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 1860b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul } 1861b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul} 1862b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 1863b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul 1864a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul/** 1865a29447c33d44b3427e0c40a761067c0cc6e71c39Brian Paul * Bind the given texture object and texture cache to the sampler varient. 1866a34b8594b7b2d00404bb639621ec1ce918ba0786Brian Paul */ 18674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 18684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, 18697670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell struct softpipe_tex_tile_cache *tex_cache, 1870287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture ) 187134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul{ 18724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 18734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->texture = texture; 18754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 1876683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->xpot = util_unsigned_logbase2( texture->width0 ); 1877683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->ypot = util_unsigned_logbase2( texture->height0 ); 18784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); 18794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 18800b9e96fae9493d5d58f046e01c983a3c4267090eBrian Paul 18814f23468bd0d14b8ed687a641003d587b91ad39a7Brian Paul 1882ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellvoid 1883ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellsp_sampler_varient_destroy( struct sp_sampler_varient *samp ) 1884ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell{ 1885ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell FREE(samp); 1886ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell} 1887ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1888ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1889e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1890e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Create a sampler varient for a given set of non-orthogonal state. 18914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstruct sp_sampler_varient * 18934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_create_sampler_varient( const struct pipe_sampler_state *sampler, 18944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 18954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 18964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient); 18974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 18984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 18994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 19014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 19024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 19044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 19054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 19064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 19074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 19084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 19094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 19104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 19114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 19134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 19144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 19154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 19174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 19184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 19194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 19204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 19224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 19234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 19244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 19274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 192941483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 19304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 19324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 19334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 19344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 1935b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian Paul else 19364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 193734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul break; 19384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 19404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 194134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul break; 19424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 19444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 19454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 19464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 19474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 1948cf102b031e7ef33c8e3ffce2f9dcd064f44e8190Brian Paul sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && 19494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 19504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 19514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 19524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 19544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 19554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 19566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 195734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul break; 195834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul } 19593d53d38d5e35386de4793162b9dd32e171927059Brian Paul 19604e014c0a148ba3ac015d0e83dcf975ca6e814e1fMichal Krol if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { 19614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 19623d53d38d5e35386de4793162b9dd32e171927059Brian Paul } 19634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 19644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 19654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 19664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 19674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 19684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 19714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = sample_cube; 19724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 19744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 19754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 19764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 19774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 19784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 19804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 19814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 19824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = samp->compare; 19836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 19846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 19854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 198634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian Paul} 1987