sp_tex_sample.c revision 41483627f0fd3dc9df2cc55dfd5f3e5987fcfd22
10dc4eea64f56cc93e5359372b08b99a2d600273cBrian/************************************************************************** 20dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 30dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 40dc4eea64f56cc93e5359372b08b99a2d600273cBrian * All Rights Reserved. 53ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul * Copyright 2008 VMware, Inc. All rights reserved. 60dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 70dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Permission is hereby granted, free of charge, to any person obtaining a 80dc4eea64f56cc93e5359372b08b99a2d600273cBrian * copy of this software and associated documentation files (the 90dc4eea64f56cc93e5359372b08b99a2d600273cBrian * "Software"), to deal in the Software without restriction, including 100dc4eea64f56cc93e5359372b08b99a2d600273cBrian * without limitation the rights to use, copy, modify, merge, publish, 110dc4eea64f56cc93e5359372b08b99a2d600273cBrian * distribute, sub license, and/or sell copies of the Software, and to 120dc4eea64f56cc93e5359372b08b99a2d600273cBrian * permit persons to whom the Software is furnished to do so, subject to 130dc4eea64f56cc93e5359372b08b99a2d600273cBrian * the following conditions: 140dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 150dc4eea64f56cc93e5359372b08b99a2d600273cBrian * The above copyright notice and this permission notice (including the 160dc4eea64f56cc93e5359372b08b99a2d600273cBrian * next paragraph) shall be included in all copies or substantial portions 170dc4eea64f56cc93e5359372b08b99a2d600273cBrian * of the Software. 180dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 190dc4eea64f56cc93e5359372b08b99a2d600273cBrian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 200dc4eea64f56cc93e5359372b08b99a2d600273cBrian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 210dc4eea64f56cc93e5359372b08b99a2d600273cBrian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 220dc4eea64f56cc93e5359372b08b99a2d600273cBrian * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 230dc4eea64f56cc93e5359372b08b99a2d600273cBrian * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 240dc4eea64f56cc93e5359372b08b99a2d600273cBrian * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 250dc4eea64f56cc93e5359372b08b99a2d600273cBrian * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 260dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 270dc4eea64f56cc93e5359372b08b99a2d600273cBrian **************************************************************************/ 280dc4eea64f56cc93e5359372b08b99a2d600273cBrian 290dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 300dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Texture sampling 310dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 320dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Authors: 330dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Brian Paul 344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Keith Whitwell 350dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 360dc4eea64f56cc93e5359372b08b99a2d600273cBrian 3708f33a025100dea2d951e6d628891fe294b18082Brian#include "sp_context.h" 387925274da323d5a896b557181d4016e0391f026fBrian#include "sp_quad.h" 390dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "sp_surface.h" 400b9e96fae9493d5d58f046e01c983a3c4267090eBrian#include "sp_texture.h" 410dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "sp_tex_sample.h" 4270eb7996f265f3634dabda078f13d1be3533cc65Brian#include "sp_tile_cache.h" 430dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "pipe/p_context.h" 440dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "pipe/p_defines.h" 4500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell#include "pipe/p_shader_tokens.h" 461a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul#include "util/u_math.h" 474f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 480dc4eea64f56cc93e5359372b08b99a2d600273cBrian 490dc4eea64f56cc93e5359372b08b99a2d600273cBrian 503ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 5108f33a025100dea2d951e6d628891fe294b18082Brian/* 5208f33a025100dea2d951e6d628891fe294b18082Brian * Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes 5308f33a025100dea2d951e6d628891fe294b18082Brian * see 1-pixel bands of improperly weighted linear-filtered textures. 5408f33a025100dea2d951e6d628891fe294b18082Brian * The tests/texwrap.c demo is a good test. 5508f33a025100dea2d951e6d628891fe294b18082Brian * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0. 5608f33a025100dea2d951e6d628891fe294b18082Brian * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x). 5708f33a025100dea2d951e6d628891fe294b18082Brian */ 589935e3b7303da656e258d4bd5bc799ffbfbc737bBrian Paul#define FRAC(f) ((f) - util_ifloor(f)) 5908f33a025100dea2d951e6d628891fe294b18082Brian 6008f33a025100dea2d951e6d628891fe294b18082Brian 6108f33a025100dea2d951e6d628891fe294b18082Brian/** 6208f33a025100dea2d951e6d628891fe294b18082Brian * Linear interpolation macro 6308f33a025100dea2d951e6d628891fe294b18082Brian */ 6438bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 6538bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp(float a, float v0, float v1) 6638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 6738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return v0 + a * (v1 - v0); 6838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 690dc4eea64f56cc93e5359372b08b99a2d600273cBrian 700dc4eea64f56cc93e5359372b08b99a2d600273cBrian 710dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 720dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Do 2D/biliner interpolation of float values. 730dc4eea64f56cc93e5359372b08b99a2d600273cBrian * v00, v10, v01 and v11 are typically four texture samples in a square/box. 740dc4eea64f56cc93e5359372b08b99a2d600273cBrian * a and b are the horizontal and vertical interpolants. 750dc4eea64f56cc93e5359372b08b99a2d600273cBrian * It's important that this function is inlined when compiled with 760dc4eea64f56cc93e5359372b08b99a2d600273cBrian * optimization! If we find that's not true on some systems, convert 770dc4eea64f56cc93e5359372b08b99a2d600273cBrian * to a macro. 780dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 79b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic INLINE float 80b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianlerp_2d(float a, float b, 81b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float v00, float v10, float v01, float v11) 820dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 8338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp(a, v00, v10); 8438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp(a, v01, v11); 8538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(b, temp0, temp1); 8638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 8738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 8838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 8938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian/** 9038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * As above, but 3D interpolation of 8 values. 9138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian */ 9238bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 9338bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp_3d(float a, float b, float c, 9438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v000, float v100, float v010, float v110, 9538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v001, float v101, float v011, float v111) 9638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 9738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp_2d(a, b, v000, v100, v010, v110); 9838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp_2d(a, b, v001, v101, v011, v111); 9938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(c, temp0, temp1); 1000dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 1010dc4eea64f56cc93e5359372b08b99a2d600273cBrian 1020dc4eea64f56cc93e5359372b08b99a2d600273cBrian 10338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 1040dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 105906768316d9521a32d9a7eebc9edaf76c06a98a7Brian * If A is a signed integer, A % B doesn't give the right value for A < 0 106906768316d9521a32d9a7eebc9edaf76c06a98a7Brian * (in terms of texture repeat). Just casting to unsigned fixes that. 1070dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 108906768316d9521a32d9a7eebc9edaf76c06a98a7Brian#define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B)) 10908f33a025100dea2d951e6d628891fe294b18082Brian 11008f33a025100dea2d951e6d628891fe294b18082Brian 11108f33a025100dea2d951e6d628891fe294b18082Brian/** 11238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Apply texture coord wrapping mode and return integer texture indexes 11338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * for a vector of four texcoords (S or T or P). 11408f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 11538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the incoming texcoords 11608f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 11738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the integer texcoords 11808f33a025100dea2d951e6d628891fe294b18082Brian * \return integer texture index 11908f33a025100dea2d951e6d628891fe294b18082Brian */ 1204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_repeat(const float s[4], unsigned size, 1224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1) */ 1274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch] * size); 1304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = REMAINDER(i, size); 1314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp(const float s[4], unsigned size, 13738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord[4]) 1380dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 13938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 1404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1] */ 1414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= 0.0F) 1444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= 1.0F) 1464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp_to_edge(const float s[4], unsigned size, 1554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 1604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] < min) 1644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] > max) 1664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp_to_border(const float s[4], unsigned size, 1754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [-1, size] */ 1804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 1814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= min) 1844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 1854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= max) 1864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 1874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_repeat(const float s[4], unsigned size, 1944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 2014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 2024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 2034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 2044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 2064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp(const float s[4], unsigned size, 2174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 22108f33a025100dea2d951e6d628891fe294b18082Brian /* s limited to [0,1] */ 22208f33a025100dea2d951e6d628891fe294b18082Brian /* i limited to [0,size-1] */ 2234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= 0.0F) 2254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= 1.0F) 2274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, 2354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, 2564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 2624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 2674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 2694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2710dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 2720dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 2730dc4eea64f56cc93e5359372b08b99a2d600273cBrian 27408f33a025100dea2d951e6d628891fe294b18082Brian 27508f33a025100dea2d951e6d628891fe294b18082Brian/** 27638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Used to compute texel locations for linear sampling for four texcoords. 27708f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 27838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the texcoords 27908f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 28038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord0 returns first texture indexes 28138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord1 returns second texture indexes (usually icoord0 + 1) 28238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param w returns blend factor/weight between texture indexes 28338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the computed integer texture coords 28408f33a025100dea2d951e6d628891fe294b18082Brian */ 2854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_repeat(const float s[4], unsigned size, 2874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 2884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = s[ch] * size - 0.5F; 2934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = REMAINDER(util_ifloor(u), size); 2944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = REMAINDER(icoord0[ch] + 1, size); 2954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 2964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp(const float s[4], unsigned size, 30138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 3020dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 30338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 3044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 31238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 3134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_edge(const float s[4], unsigned size, 3154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_border(const float s[4], unsigned size, 3334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 3364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 3374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], min, max); 3404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_repeat(const float s[4], unsigned size, 3504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 3554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 3564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 3574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 3584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 3604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5F; 3614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp(const float s[4], unsigned size, 3734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size, 3914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 4044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 4054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 4064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 4074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 4084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 4114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, 4134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 4144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 4164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 4174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= min) 4214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = min * size; 4224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= max) 4234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = max * size; 4244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 4300dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 4310dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 4320dc4eea64f56cc93e5359372b08b99a2d600273cBrian 4330dc4eea64f56cc93e5359372b08b99a2d600273cBrian 434b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 435b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords 436b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 437b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp(const float s[4], unsigned size, 44038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord[4]) 441b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 44238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch]); 4454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= CLAMP(i, 0, (int) size-1); 4464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 4494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Handles clamp_to_edge and clamp_to_border: 4504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 4514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, 4534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 4544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); 458b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 459b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 460b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 461b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 462b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 463b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords. 464b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 465b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp(const float s[4], unsigned size, 46838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 469b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 47038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Not exactly what the spec says, but it matches NVIDIA output */ 4734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); 4744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 477b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 478b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 479b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 4804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp_to_border( const float s[4], unsigned size, 4824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 48334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 4844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F); 4874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] > (int) size - 1) 4914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 4924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 49334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 4944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 49634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 500b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian/** 501b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * Examine the quad's texture coordinates to compute the partial 502b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * derivatives w.r.t X and Y, then compute lambda (level of detail). 503b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 504b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic float 5054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_1d(const struct sp_sampler_varient *samp, 5064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 510b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 51100c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 51200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(dsdx, dsdy) * texture->width[0]; 5164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 517b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = util_fast_log2(rho); 5194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda += lodbias + sampler->lod_bias; 5204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 52100c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lambda; 5234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 524b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 5254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_2d(const struct sp_sampler_varient *samp, 5274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 5314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 5324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 5334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 5414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 542b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5431a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul lambda = util_fast_log2(rho); 5440b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda += lodbias + sampler->lod_bias; 5450b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 546b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 547b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian return lambda; 548b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 549b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 550b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_3d(const struct sp_sampler_varient *samp, 5534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 55709a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 55800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 55900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 5654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 5664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxz = MAX2(dpdx, dpdy) * texture->depth[0]; 5694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho, lambda; 57000c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 5724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 573c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = util_fast_log2(rho); 5754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda += lodbias + sampler->lod_bias; 5764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 5774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lambda; 57909a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 58009a1b912605ff48c8782dcc5aae55ac77e27037bBrian 58108f33a025100dea2d951e6d628891fe294b18082Brian 5824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_vert(const struct sp_sampler_varient *samp, 5854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 5894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 5904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lodbias; 5914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 5924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 5964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 5974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 5984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param face the cube face in 0..5 5994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param level the mipmap level 6004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 601b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param y the y coord of texel within 2D image 60270eb7996f265f3634dabda078f13d1be3533cc65Brian * \param z which slice of a 3D texture 603b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param rgba the quad to put the texel/color into 604b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param j which element of the rgba quad to write to 60570eb7996f265f3634dabda078f13d1be3533cc65Brian * 60670eb7996f265f3634dabda078f13d1be3533cc65Brian * XXX maybe move this into sp_tile_cache.c and merge with the 60770eb7996f265f3634dabda078f13d1be3533cc65Brian * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 608b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 6094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 6106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellget_texel_quad_2d(const struct tgsi_sampler *tgsi_sampler, 6116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned face, unsigned level, int x, int y, 6126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out[4]) 6136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 6144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 6156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const struct softpipe_cached_tile *tile 6176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell = sp_get_cached_tile_tex(samp->cache, 6186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tile_address(x, y, 0, face, level)); 6196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 6226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 6246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 6256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 6266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 6276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 6306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellget_texel_2d_ptr(const struct tgsi_sampler *tgsi_sampler, 6316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned face, unsigned level, int x, int y) 6326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 6334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 6346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const struct softpipe_cached_tile *tile 6366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell = sp_get_cached_tile_tex(samp->cache, 6376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tile_address(x, y, 0, face, level)); 6386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 6416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 6436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 6476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellget_texel_quad_2d_mt(const struct tgsi_sampler *tgsi_sampler, 6486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned face, unsigned level, 6496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, int y0, 6506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x1, int y1, 6516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out[4]) 6526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 6536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned i; 6546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (i = 0; i < 4; i++) { 6566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned tx = (i & 1) ? x1 : x0; 6576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned ty = (i >> 1) ? y1 : y0; 6586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[i] = get_texel_2d_ptr( tgsi_sampler, face, level, tx, ty ); 6606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 6616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 664dd55083ac1c13723dba6be71f161e2ca7cac7c66Brianget_texel(const struct tgsi_sampler *tgsi_sampler, 6656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned face, unsigned level, int x, int y, int z, 6666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE], unsigned j) 667b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 6684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 669aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 670aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 6710b9e96fae9493d5d58f046e01c983a3c4267090eBrian 6720b9e96fae9493d5d58f046e01c983a3c4267090eBrian if (x < 0 || x >= (int) texture->width[level] || 6730b9e96fae9493d5d58f046e01c983a3c4267090eBrian y < 0 || y >= (int) texture->height[level] || 6740b9e96fae9493d5d58f046e01c983a3c4267090eBrian z < 0 || z >= (int) texture->depth[level]) { 6750b9e96fae9493d5d58f046e01c983a3c4267090eBrian rgba[0][j] = sampler->border_color[0]; 6760b9e96fae9493d5d58f046e01c983a3c4267090eBrian rgba[1][j] = sampler->border_color[1]; 6770b9e96fae9493d5d58f046e01c983a3c4267090eBrian rgba[2][j] = sampler->border_color[2]; 6780b9e96fae9493d5d58f046e01c983a3c4267090eBrian rgba[3][j] = sampler->border_color[3]; 679ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 680ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 681f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell const unsigned tx = x % TILE_SIZE; 682f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell const unsigned ty = y % TILE_SIZE; 683f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell const struct softpipe_cached_tile *tile; 684f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell 685f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, 686f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell tile_address(x, y, z, face, level)); 687f911c3b9897b90132c8621a72bfeb824eb3b01e5Keith Whitwell 688ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul rgba[0][j] = tile->data.color[ty][tx][0]; 689ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul rgba[1][j] = tile->data.color[ty][tx][1]; 690ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul rgba[2][j] = tile->data.color[ty][tx][2]; 691ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul rgba[3][j] = tile->data.color[ty][tx][3]; 692b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul if (0) 693b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul { 694ae2195caf56d2eb782475254c68858a25ee7c857Brian Paul debug_printf("Get texel %f %f %f %f from %s\n", 6958fb55dab783f2de5111e7440093e1458fce5fb3dBrian Paul rgba[0][j], rgba[1][j], rgba[2][j], rgba[3][j], 6960b9e96fae9493d5d58f046e01c983a3c4267090eBrian pf_name(texture->format)); 697b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul } 698ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 699b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 700b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 701b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 7023d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 7033d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 704b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 705efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 7064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 7074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 7084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 7094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 7104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 7114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 7126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 7134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 7146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 7156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 7166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned xpot = 1 << (samp->xpot - level); 7176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned ypot = 1 << (samp->ypot - level); 7181fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 7191fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 72079a7ddb57a04cde5a4a0c27eb4a9b6889d12622aKeith Whitwell 7216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 7226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 7236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 7256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 7266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 7286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 7296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 7316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 7326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 7346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 7356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *tx[4]; 7376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 7406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 74179a7ddb57a04cde5a4a0c27eb4a9b6889d12622aKeith Whitwell if (x0 < xmax && y0 < ymax) 7426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell { 7436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell get_texel_quad_2d(tgsi_sampler, 0, level, x0, y0, tx); 7446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else 7466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell { 7474f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 7484f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 7496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell get_texel_quad_2d_mt(tgsi_sampler, 0, level, 7506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0, y0, x1, y1, tx); 7516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 7556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 7566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 7576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 7586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 7596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 7654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 7664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 7674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 7684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 7694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 7704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 7716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 7724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 7736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 7746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 7756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned xpot = 1 << (samp->xpot - level); 7766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned ypot = 1 << (samp->ypot - level); 7776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 7796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 7806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7815fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 7825fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 7836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 7856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 7866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 7886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 7896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out = get_texel_2d_ptr(tgsi_sampler, 0, level, x0, y0); 7916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 7936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 7946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 8014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8066142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 8100d9979d9ec5b931856d29c4ec44edb1f4931d1acKeith Whitwell unsigned xpot = 1 << (samp->xpot - level); 8110d9979d9ec5b931856d29c4ec44edb1f4931d1acKeith Whitwell unsigned ypot = 1 << (samp->ypot - level); 8126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8165fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8175fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 8206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 8216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 8236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 8246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 8256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 8266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 8276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 8296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 8306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 8316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 8326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 8336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out = get_texel_2d_ptr(tgsi_sampler, 0, level, x0, y0); 8356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 8434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 8444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const struct pipe_texture *texture = samp->texture; 8524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 8534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 8544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 8556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 8574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 8586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 8604f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 8614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 8624f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 8634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x[j], 0, 0, rgba, j); 8654f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 8666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 869e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 8704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 8714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8760dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 8774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 878aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 8794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 8804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 881f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian int width, height; 8824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 883b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 8844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 8850b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 8860b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 88709a1b912605ff48c8782dcc5aae55ac77e27037bBrian 888b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian assert(width > 0); 889612cfb749c3526eeb446bbc631bf24716522f373Brian 8904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 8914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 892f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian 8934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, faces[j], level0, x[j], y[j], 0, rgba, j); 8950dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 8960dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 89734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 89834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 8994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 9004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 9014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 9054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 90634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 9074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 908aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 9094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 9103d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian int width, height, depth; 9114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 912b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 9134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9140b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 9150b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 9160b9e96fae9493d5d58f046e01c983a3c4267090eBrian depth = texture->depth[level0]; 9173d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 9183d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(width > 0); 9193d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(height > 0); 9203d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(depth > 0); 9213d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 9224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 9244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 9253d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 9264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 9274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x[j], y[j], z[j], rgba, j); 9283d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 92934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 93034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 93134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 93234a48abd5ff82ce9748fc29191e35a0985d47c5fBrianstatic void 9334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 9344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 9384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 93934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 9404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 9414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 9424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 9434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 9444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 9454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 9464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 9504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 9524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 9544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 956b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian for (j = 0; j < QUAD_SIZE; j++) { 9574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float tx[4][4]; /* texels */ 9584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 9594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x0[j], 0, 0, tx, 0); 9604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x1[j], 0, 0, tx, 1); 9614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 9634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 9644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(xw[j], tx[c][0], tx[c][1]); 9654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 966b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 96734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 96834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 969b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrianstatic void 9704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 9714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 9754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 976b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 9774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 978aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 9794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 9804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 981b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian int width, height; 9824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 9834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 984b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 985b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 9864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9870b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 9880b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 989b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 990b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(width > 0); 991b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 9924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 9934e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 9944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 9954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 9964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float tx[4][4]; /* texels */ 9974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 9984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, faces[j], level0, x0[j], y0[j], 0, tx, 0); 9994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, faces[j], level0, x1[j], y0[j], 0, tx, 1); 10004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, faces[j], level0, x0[j], y1[j], 0, tx, 2); 10014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, faces[j], level0, x1[j], y1[j], 0, tx, 3); 10024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 10044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 10054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 10064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx[c][0], tx[c][1], 10074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx[c][2], tx[c][3]); 1008b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 10094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 10104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 10114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 10154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 10204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 10214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 10224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 10234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 10254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 10264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 10274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 10304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell height = texture->height[level0]; 10314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell depth = texture->depth[level0]; 10324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 10344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 10354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 10364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 10384e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 10394e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 10404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 10424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float tx0[4][4], tx1[4][4]; 10434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 10444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x0[j], y0[j], z0[j], tx0, 0); 10464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x1[j], y0[j], z0[j], tx0, 1); 10474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x0[j], y1[j], z0[j], tx0, 2); 10484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x1[j], y1[j], z0[j], tx0, 3); 10494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x0[j], y0[j], z1[j], tx1, 0); 10504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x1[j], y0[j], z1[j], tx1, 1); 10514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x0[j], y1[j], z1[j], tx1, 2); 10524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell get_texel(tgsi_sampler, 0, level0, x1[j], y1[j], z1[j], tx1, 3); 10534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 10554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 10564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 10574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx0[c][0], tx0[c][1], 10584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx0[c][2], tx0[c][3], 10594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx1[c][0], tx1[c][1], 10604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tx1[c][2], tx1[c][3]); 10614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 10624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 10634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 10644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 10734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 10784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 10794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 10804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 10814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 10824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 10834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 10854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 10864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 10884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 10894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 10904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 10914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 10924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 10934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 10944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 10954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 10964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 10974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 10984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 10994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 11004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 11024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba0 ); 11034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 11054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba1 ); 11064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 11084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 11094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1110b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1111b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1112b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1113b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1114b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1115b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 11164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 11184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 11194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 11234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 11244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 11254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 11264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 11274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 11284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 11304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 11324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 11334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 11344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 11364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = (int)(lambda + 0.5) ; 11374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 11384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 11394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 11414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 11444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 11454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 11494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 11504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 11514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 11524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda = samp->compute_lambda(samp, s, t, p, lodbias); 11534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 11554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 11564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 11584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 11594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 11614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Specialized version of mip_filter_linear with hard-wired calls to 11654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1166a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 11674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 11684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 11694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 11704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 11744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 117500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 11764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 11774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 11784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 11794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 118000c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 11814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = compute_lambda_2d(samp, s, t, p, lodbias); 11824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 11834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 11854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 11864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 11874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 11884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 11894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 11904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 11914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba ); 11934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 11954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 11964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 11974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 11984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 11994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 12014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba0 ); 12024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 12044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba1 ); 12054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 12094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 121200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell} 121300c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 12144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Compare stage in the little sampling pipeline. 121700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell */ 12184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1220b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float s[QUAD_SIZE], 1221b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float t[QUAD_SIZE], 1222b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float p[QUAD_SIZE], 1223f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian float lodbias, 1224b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float rgba[NUM_CHANNELS][QUAD_SIZE]) 122534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 12264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1227aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 12284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 12294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 12300b9e96fae9493d5d58f046e01c983a3c4267090eBrian 12314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter( tgsi_sampler, s, t, p, lodbias, rgba ); 123200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 123300c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 12344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 12354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 12364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 12374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 12384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 12394f23468bd0d14b8ed687a641003d587b91ad39a7Brian 12404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* compare four texcoords vs. four texture samples */ 12414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->compare_func) { 12424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_LESS: 12434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] < rgba[0][0]; 12444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] < rgba[0][1]; 12454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] < rgba[0][2]; 12464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] < rgba[0][3]; 124734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 12484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_LEQUAL: 12494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] <= rgba[0][0]; 12504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] <= rgba[0][1]; 12514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] <= rgba[0][2]; 12524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] <= rgba[0][3]; 125334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 12544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_GREATER: 12554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] > rgba[0][0]; 12564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] > rgba[0][1]; 12574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] > rgba[0][2]; 12584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] > rgba[0][3]; 125934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 12604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_GEQUAL: 12614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] >= rgba[0][0]; 12624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] >= rgba[0][1]; 12634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] >= rgba[0][2]; 12644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] >= rgba[0][3]; 12654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 12664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_EQUAL: 12674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] == rgba[0][0]; 12684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] == rgba[0][1]; 12694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] == rgba[0][2]; 12704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] == rgba[0][3]; 12714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 12724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_NOTEQUAL: 12734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] != rgba[0][0]; 12744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] != rgba[0][1]; 12754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] != rgba[0][2]; 12764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] != rgba[0][3]; 12774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 12784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_ALWAYS: 12794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 1; 12804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 12814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_NEVER: 12824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 0; 128334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 128434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian default: 12854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 0; 128634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian assert(0); 128700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell break; 128834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 12893d53d38d5e35386de4793162b9dd32e171927059Brian Paul 12904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* convert four pass/fail values to an intensity in [0,1] */ 12914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell val = 0.25F * (k0 + k1 + k2 + k3); 12924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 12944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < 4; j++) { 12954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 12964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[3][j] = 1.0F; 12974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Calculate cube faces. 13014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 13024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 13044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 13094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 13124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 13134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 13154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 13164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell direction target sc tc ma 13174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ---------- ------------------------------- --- --- --- 13184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 13194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 13204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 13214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 13224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 13234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 13244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 13254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rx = s[j]; 13274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ry = t[j]; 13284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rz = p[j]; 13294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 13304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned face; 13314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float sc, tc, ma; 13324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (arx > ary && arx > arz) { 13344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rx >= 0.0F) { 13354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_X; 13364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rz; 13374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 13384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 13394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_X; 13424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rz; 13434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 13444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 13454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (ary > arx && ary > arz) { 13484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (ry >= 0.0F) { 13494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Y; 13504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 13514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = rz; 13524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 13534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Y; 13564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 13574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -rz; 13584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 13594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rz > 0.0F) { 13634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Z; 13644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 13654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 13664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 13674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Z; 13704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rx; 13714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 13724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 13734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ssss[j] = ( sc / ma + 1.0F ) * 0.5F; 13774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tttt[j] = ( tc / ma + 1.0F ) * 0.5F; 13784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[j] = face; 13794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 13814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 13824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 13834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 13846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 13854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare(tgsi_sampler, ssss, tttt, NULL, lodbias, rgba); 13864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_nearest_func get_nearest_unorm_wrap( unsigned mode ) 13924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 13944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 13954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 13964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 13974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 13984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 13994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 14004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 14014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 14024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_nearest_func get_nearest_wrap( unsigned mode ) 14074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 14094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 14104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 14114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 14124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 14134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 14144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 14154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 14164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 14174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 14184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 14194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 14204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 14214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 14224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 14234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 14244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 14254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 14264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 14274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 14284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_linear_func get_linear_unorm_wrap( unsigned mode ) 14324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 14344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 14354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 14364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 14374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 14384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 14394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 14404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 14414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 14424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_linear_func get_linear_wrap( unsigned mode ) 14464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 14484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 14494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 14504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 14514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 14524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 14534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 14544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 14554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 14564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 14574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 14584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 14594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 14604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 14614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 14624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 14634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 14644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 14654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 14664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 14674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic compute_lambda_func get_lambda_func( const union sp_sampler_key key ) 14714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 14734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 14744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 14764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 14774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 14784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 14794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 14804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 14814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 14824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 14834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 14844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 14854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic filter_func get_img_filter( const union sp_sampler_key key, 14894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned filter, 14904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler ) 14914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 14934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 14944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 14954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 14964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 14994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 15004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 15014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 15034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 15044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 15054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 15064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 15084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 15096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 15104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 15116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 15124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 15136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 15146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 15156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 15164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 15174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 15184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 15196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 15204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 15216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 15226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 15236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 15246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 15256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 15264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Fallthrough to default versions: 15274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_CUBE: 15294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 15304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 15314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 15324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 15334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 15344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 15354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 15394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 15404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 15414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 15424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 15434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 15454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 15484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, 15494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct softpipe_tile_cache *tex_cache, 15504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture ) 15514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 15524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 15534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->texture = texture; 15554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 15564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->xpot = util_unsigned_logbase2( texture->width[0] ); 15574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->ypot = util_unsigned_logbase2( texture->height[0] ); 15584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); 15594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 15604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Create a sampler varient for a given set of non-orthogonal state. Currently the 15624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstruct sp_sampler_varient * 15644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_create_sampler_varient( const struct pipe_sampler_state *sampler, 15654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 15664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 15674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient); 15684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 15694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 15704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 15724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 15734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 15754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 15764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 15774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 15794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 15804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 15814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 15824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 15844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 15854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 15864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 15894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 15904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 15914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 15934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 15944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 15954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 15984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 160041483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 16014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 16034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 16044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 16054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 16064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 16074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 16084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 16094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 16114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 16124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 16134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 16154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 16164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 16174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 16184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 16194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 16204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 16214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 16224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 16234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 16244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 16264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 16274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 16286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 16304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->compare_mode != FALSE) { 16334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 16346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 16364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 16374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 16384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 16394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 16404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 16434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = sample_cube; 16444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 16464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 16474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 16484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 16494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 16504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 16524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 16534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 16544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = samp->compare; 16556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 16574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 16583ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul} 16593ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 16604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1665