sp_tex_sample.c revision e2329f2795d48d11131e9ac105e7aa3fd2c229c1
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 370dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "pipe/p_context.h" 380dc4eea64f56cc93e5359372b08b99a2d600273cBrian#include "pipe/p_defines.h" 3900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell#include "pipe/p_shader_tokens.h" 401a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul#include "util/u_math.h" 414f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 42d204659c8c725c02212ad4a49275c7447f2d02a6Brian Paul#include "sp_quad.h" /* only for #define QUAD_* tokens */ 43d204659c8c725c02212ad4a49275c7447f2d02a6Brian Paul#include "sp_tex_sample.h" 447670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell#include "sp_tex_tile_cache.h" 450dc4eea64f56cc93e5359372b08b99a2d600273cBrian 460dc4eea64f56cc93e5359372b08b99a2d600273cBrian 473ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 4808f33a025100dea2d951e6d628891fe294b18082Brian/* 4908f33a025100dea2d951e6d628891fe294b18082Brian * Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes 5008f33a025100dea2d951e6d628891fe294b18082Brian * see 1-pixel bands of improperly weighted linear-filtered textures. 5108f33a025100dea2d951e6d628891fe294b18082Brian * The tests/texwrap.c demo is a good test. 5208f33a025100dea2d951e6d628891fe294b18082Brian * Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0. 5308f33a025100dea2d951e6d628891fe294b18082Brian * Instead, if x < 0 then FRAC(x) = 1 - true_frac(x). 5408f33a025100dea2d951e6d628891fe294b18082Brian */ 559935e3b7303da656e258d4bd5bc799ffbfbc737bBrian Paul#define FRAC(f) ((f) - util_ifloor(f)) 5608f33a025100dea2d951e6d628891fe294b18082Brian 5708f33a025100dea2d951e6d628891fe294b18082Brian 5808f33a025100dea2d951e6d628891fe294b18082Brian/** 5908f33a025100dea2d951e6d628891fe294b18082Brian * Linear interpolation macro 6008f33a025100dea2d951e6d628891fe294b18082Brian */ 6138bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 6238bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp(float a, float v0, float v1) 6338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 6438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return v0 + a * (v1 - v0); 6538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 660dc4eea64f56cc93e5359372b08b99a2d600273cBrian 670dc4eea64f56cc93e5359372b08b99a2d600273cBrian 680dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 690dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Do 2D/biliner interpolation of float values. 700dc4eea64f56cc93e5359372b08b99a2d600273cBrian * v00, v10, v01 and v11 are typically four texture samples in a square/box. 710dc4eea64f56cc93e5359372b08b99a2d600273cBrian * a and b are the horizontal and vertical interpolants. 720dc4eea64f56cc93e5359372b08b99a2d600273cBrian * It's important that this function is inlined when compiled with 730dc4eea64f56cc93e5359372b08b99a2d600273cBrian * optimization! If we find that's not true on some systems, convert 740dc4eea64f56cc93e5359372b08b99a2d600273cBrian * to a macro. 750dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 76b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic INLINE float 77b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianlerp_2d(float a, float b, 78b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float v00, float v10, float v01, float v11) 790dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 8038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp(a, v00, v10); 8138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp(a, v01, v11); 8238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(b, temp0, temp1); 8338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 8438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 8538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 8638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian/** 8738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * As above, but 3D interpolation of 8 values. 8838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian */ 8938bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 9038bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp_3d(float a, float b, float c, 9138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v000, float v100, float v010, float v110, 9238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v001, float v101, float v011, float v111) 9338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 9438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp_2d(a, b, v000, v100, v010, v110); 9538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp_2d(a, b, v001, v101, v011, v111); 9638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(c, temp0, temp1); 970dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 980dc4eea64f56cc93e5359372b08b99a2d600273cBrian 990dc4eea64f56cc93e5359372b08b99a2d600273cBrian 10038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 1010dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 102906768316d9521a32d9a7eebc9edaf76c06a98a7Brian * If A is a signed integer, A % B doesn't give the right value for A < 0 103906768316d9521a32d9a7eebc9edaf76c06a98a7Brian * (in terms of texture repeat). Just casting to unsigned fixes that. 1040dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 105906768316d9521a32d9a7eebc9edaf76c06a98a7Brian#define REMAINDER(A, B) ((unsigned) (A) % (unsigned) (B)) 10608f33a025100dea2d951e6d628891fe294b18082Brian 10708f33a025100dea2d951e6d628891fe294b18082Brian 10808f33a025100dea2d951e6d628891fe294b18082Brian/** 10938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Apply texture coord wrapping mode and return integer texture indexes 11038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * for a vector of four texcoords (S or T or P). 11108f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 11238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the incoming texcoords 11308f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 11438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the integer texcoords 11508f33a025100dea2d951e6d628891fe294b18082Brian * \return integer texture index 11608f33a025100dea2d951e6d628891fe294b18082Brian */ 1174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 118e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_repeat(const float s[4], unsigned size, int icoord[4]) 1194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1) */ 1224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch] * size); 1254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = REMAINDER(i, size); 1264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 131e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp(const float s[4], unsigned size, int icoord[4]) 1320dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 13338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 1344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1] */ 1354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= 0.0F) 1384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= 1.0F) 1404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 148e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_edge(const float s[4], unsigned size, int icoord[4]) 1494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 1534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] < min) 1574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] > max) 1594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 167e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_border(const float s[4], unsigned size, int icoord[4]) 1684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [-1, size] */ 1724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 1734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= min) 1764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 1774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= max) 1784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 1794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 184e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 186e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4]) 1874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 1934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 1944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 1954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 1964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 1984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 1994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 207e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 209e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_clamp(const float s[4], unsigned size, int icoord[4]) 2104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 21308f33a025100dea2d951e6d628891fe294b18082Brian /* s limited to [0,1] */ 21408f33a025100dea2d951e6d628891fe294b18082Brian /* i limited to [0,size-1] */ 2154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= 0.0F) 2174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= 1.0F) 2194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 225e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, 228e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 2294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, 2494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 2554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 2604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 2624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2640dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 2650dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 2660dc4eea64f56cc93e5359372b08b99a2d600273cBrian 26708f33a025100dea2d951e6d628891fe294b18082Brian 26808f33a025100dea2d951e6d628891fe294b18082Brian/** 26938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Used to compute texel locations for linear sampling for four texcoords. 27008f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 27138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the texcoords 27208f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 27338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord0 returns first texture indexes 27438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord1 returns second texture indexes (usually icoord0 + 1) 27538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param w returns blend factor/weight between texture indexes 27638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the computed integer texture coords 27708f33a025100dea2d951e6d628891fe294b18082Brian */ 2784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_repeat(const float s[4], unsigned size, 2804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 2814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = s[ch] * size - 0.5F; 2854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = REMAINDER(util_ifloor(u), size); 2864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = REMAINDER(icoord0[ch] + 1, size); 2874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 2884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 291e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp(const float s[4], unsigned size, 29438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 2950dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 29638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 2974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 2994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 30538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 306e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_edge(const float s[4], unsigned size, 3094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 325e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_border(const float s[4], unsigned size, 3284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 3314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 3324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], min, max); 3354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_repeat(const float s[4], unsigned size, 3454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 3504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 3514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 3524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 3534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 3554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5F; 3564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 366e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp(const float s[4], unsigned size, 3694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 385e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size, 3884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 4014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 4024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 4034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 4044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 4054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 408e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 4094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, 4114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 4124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 4144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 4154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= min) 4194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = min * size; 4204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= max) 4214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = max * size; 4224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 4280dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 4290dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 4300dc4eea64f56cc93e5359372b08b99a2d600273cBrian 4310dc4eea64f56cc93e5359372b08b99a2d600273cBrian 432b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 433b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords 434b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 435b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 437e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) 438b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 43938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch]); 4424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= CLAMP(i, 0, (int) size-1); 4434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 446e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 447e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 448e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Handles clamp_to_edge and clamp_to_border: 4494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 4504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, 452e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 4534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); 457b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 458b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 459b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 460b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 461b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 462b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords. 463b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 464b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp(const float s[4], unsigned size, 467e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord0[4], int icoord1[4], float w[4]) 468b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 46938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Not exactly what the spec says, but it matches NVIDIA output */ 4724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); 4734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 476b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 477b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 478b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 479e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 4804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 481e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_linear_unorm_clamp_to_border(const float s[4], unsigned size, 482e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 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 498b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian/** 499b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * Examine the quad's texture coordinates to compute the partial 500b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * derivatives w.r.t X and Y, then compute lambda (level of detail). 501b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 502b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic float 5034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_1d(const struct sp_sampler_varient *samp, 5044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 508b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 50900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 51000c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(dsdx, dsdy) * texture->width[0]; 5144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 515b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5161a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul lambda = util_fast_log2(rho); 5170b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda += lodbias + sampler->lod_bias; 5180b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 519b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 520b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian return lambda; 521b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 522b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 523e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 5244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_2d(const struct sp_sampler_varient *samp, 5264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 53009a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 5314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 5324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 5404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 541c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5421a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul lambda = util_fast_log2(rho); 5430b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda += lodbias + sampler->lod_bias; 5440b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 545c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 546b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian return lambda; 54709a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 54809a1b912605ff48c8782dcc5aae55ac77e27037bBrian 54908f33a025100dea2d951e6d628891fe294b18082Brian 5504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_3d(const struct sp_sampler_varient *samp, 5524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 55609a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 55700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 55800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 5644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 5654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxz = MAX2(dpdx, dpdy) * texture->depth[0]; 5684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho, lambda; 56900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 5714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 572c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = util_fast_log2(rho); 5744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda += lodbias + sampler->lod_bias; 5754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 5764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lambda; 57809a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 57909a1b912605ff48c8782dcc5aae55ac77e27037bBrian 58008f33a025100dea2d951e6d628891fe294b18082Brian 581e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 582e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Compute lambda for a vertex texture sampler. 583e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Since there aren't derivatives to use, just return the LOD bias. 584e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul */ 5854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_vert(const struct sp_sampler_varient *samp, 5874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 5914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 5924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lodbias; 5934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 5944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 5984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 5994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 60081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell * \param addr the template tex address containing cube, z, face info. 6014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 602b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param y the y coord of texel within 2D image 603b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param rgba the quad to put the texel/color into 60470eb7996f265f3634dabda078f13d1be3533cc65Brian * 60580c78472ad43f4288c9ef5076074ba9d31a39885Keith Whitwell * XXX maybe move this into sp_tex_tile_cache.c and merge with the 60670eb7996f265f3634dabda078f13d1be3533cc65Brian * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 607b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 60881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 60981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 61381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d_no_border(const struct sp_sampler_varient *samp, 61481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 615b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 61681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 61781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 61981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 62081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y %= TILE_SIZE; 62181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell x %= TILE_SIZE; 62281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 62481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return &tile->data.color[y][x][0]; 62681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 62781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 63081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d(const struct sp_sampler_varient *samp, 63181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 63281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 63381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct pipe_texture *texture = samp->texture; 63481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 63581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell if (x < 0 || x >= (int) texture->width[level] || 63781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y < 0 || y >= (int) texture->height[level]) { 63881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 63981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 64081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell else { 64181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_2d_no_border( samp, addr, x, y ); 64281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 64381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 6446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 64681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of adjacent texels within a tile: 64781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 64881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 64981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border_single_tile(const struct sp_sampler_varient *samp, 65081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 65181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned x, unsigned y, 65281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 65381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 65481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 65581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 65781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 6586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 66081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 6626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 6646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 6656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 6666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 6676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 66981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 67081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of potentially non-adjacent texels: 67181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 67281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 67381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border(const struct sp_sampler_varient *samp, 67481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 67581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 67681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 67781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 67881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 67981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); 68081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); 68181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); 68281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); 68381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 68481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 68581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Can involve a lot of unnecessary checks for border color: 68681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 68781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 68881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d(const struct sp_sampler_varient *samp, 68981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 69081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 69181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 69281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 69381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 69481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d( samp, addr, x0, y0 ); 69581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d( samp, addr, x1, y0 ); 69681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d( samp, addr, x1, y1 ); 69781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d( samp, addr, x0, y1 ); 69881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 69981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 70081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 70181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 70281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* 3d varients: 70381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 7046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 70581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d_no_border(const struct sp_sampler_varient *samp, 706e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 7076142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 708153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const struct softpipe_tex_cached_tile *tile; 7096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 710153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.x = x / TILE_SIZE; 711153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.y = y / TILE_SIZE; 71281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.z = z; 7136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 7146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 7156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 716153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 717153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 7196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 72281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 72381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d(const struct sp_sampler_varient *samp, 724e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 725b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 726aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 72781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 7280b9e96fae9493d5d58f046e01c983a3c4267090eBrian 7290b9e96fae9493d5d58f046e01c983a3c4267090eBrian if (x < 0 || x >= (int) texture->width[level] || 7300b9e96fae9493d5d58f046e01c983a3c4267090eBrian y < 0 || y >= (int) texture->height[level] || 7310b9e96fae9493d5d58f046e01c983a3c4267090eBrian z < 0 || z >= (int) texture->depth[level]) { 73281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 733ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 734ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 73581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_3d_no_border( samp, addr, x, y, z ); 736ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 737b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 738b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 739b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 74075276ea316610a5737f2115326482024aa09d02aroot/** 74175276ea316610a5737f2115326482024aa09d02aroot * Given the logbase2 of a mipmap's base level size and a mipmap level, 74275276ea316610a5737f2115326482024aa09d02aroot * return the size (in texels) of that mipmap level. 74375276ea316610a5737f2115326482024aa09d02aroot * For example, if level[0].width = 256 then base_pot will be 8. 74475276ea316610a5737f2115326482024aa09d02aroot * If level = 2, then we'll return 64 (the width at level=2). 74575276ea316610a5737f2115326482024aa09d02aroot * Return 1 if level > base_pot. 74675276ea316610a5737f2115326482024aa09d02aroot */ 74775276ea316610a5737f2115326482024aa09d02arootstatic INLINE unsigned 74875276ea316610a5737f2115326482024aa09d02arootpot_level_size(unsigned base_pot, unsigned level) 74975276ea316610a5737f2115326482024aa09d02aroot{ 75075276ea316610a5737f2115326482024aa09d02aroot return (base_pot >= level) ? (1 << (base_pot - level)) : 1; 75175276ea316610a5737f2115326482024aa09d02aroot} 75275276ea316610a5737f2115326482024aa09d02aroot 75375276ea316610a5737f2115326482024aa09d02aroot 75481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Some image-filter fastpaths: 75581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 756efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 7574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 758e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 759e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 760e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 761e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float lodbias, 762e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 7636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 7644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 7656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 7666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 76775276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 76875276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 7691fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 7701fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 771153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 772153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 773153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 774153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 775153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 7776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 7786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 7806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 7816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 7836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 7846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 7866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 7876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 7896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 7906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 791153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const float *tx[4]; 7926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 7946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 795e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul if (x0 < xmax && y0 < ymax) { 79681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); 7976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 798e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul else { 7994f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 8004f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 80181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); 8026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8036142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 8056142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8066142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 8076142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 8086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 8096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 8164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 82575276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 82675276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 827153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 828153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 829153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 830153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8355fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8365fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 84481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d_no_border(samp, addr, x0, y0); 8456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 8554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 86475276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 86575276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 866153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 867153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 868153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 869153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8745fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8755fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 8786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 8796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 8816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 8826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 8836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 8846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 8856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 8876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 8886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 8896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 8906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 8916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 89281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out = get_texel_2d_no_border(samp, addr, x0, y0); 8936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 900e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 9016142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 9024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 9034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 9074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 9094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 9106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const struct pipe_texture *texture = samp->texture; 9114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 9124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 9134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 91481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 9156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 9186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 9204f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 92181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 92281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 92381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 9244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9254f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 9264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 92781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, addr, x[j], 0); 92881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 92981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 93081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 93181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 9324f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 9336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 93660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 93760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 93860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 93960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 94060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 94160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float lodbias, 94260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 94360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 94460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 94560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct pipe_texture *texture = samp->texture; 94660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 94760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 94860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x[4], y[4]; 94960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 95081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 95181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 95260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 95360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell width = texture->width[level0]; 95460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell height = texture->height[level0]; 95560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 95660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 9575dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 95860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 95960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 96060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 96160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 96260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_s(s, width, x); 96360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_t(t, height, y); 96460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 96560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 96660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *out = get_texel_2d(samp, addr, x[j], y[j]); 96760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 96860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 96960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = out[c]; 97060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 97160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 97260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 97360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 974e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 975e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic inline union tex_tile_address 976e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulface(union tex_tile_address addr, unsigned face ) 97781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 97881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.face = face; 97981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return addr; 98081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 98181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 982e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 983e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 98460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, 985e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 986e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 987e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 988e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float lodbias, 989e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 9900dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 9914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 992aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 9934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 9944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 995f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian int width, height; 9964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 99781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 99881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 9994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10000b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 10010b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 100209a1b912605ff48c8782dcc5aae55ac77e27037bBrian 1003b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian assert(width > 0); 10045dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 100581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 100681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 100781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 1008612cfb749c3526eeb446bbc631bf24716522f373Brian 10094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 1011f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian 10124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 101381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); 101481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 101581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 101681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 101781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10180dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 10190dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 102034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 102134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 10224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 10244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 102934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 10304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1031aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 10324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10333d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian int width, height, depth; 10344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 103581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1036b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 10374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10380b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 10390b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 10400b9e96fae9493d5d58f046e01c983a3c4267090eBrian depth = texture->depth[level0]; 10413d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 10423d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(width > 0); 10433d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(height > 0); 10443d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(depth > 0); 10453d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 10464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 10484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 10493d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 105081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 105181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 105281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 105481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); 105581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 105681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 105781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 105881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10593d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 106034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 106134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 106234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 106334a48abd5ff82ce9748fc29191e35a0985d47c5fBrianstatic void 10644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 10654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 107034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 10714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 10724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 10734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 10754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 10764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 107781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 10784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 10814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 10834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 108481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 108581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 108681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 10884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1089b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian for (j = 0; j < QUAD_SIZE; j++) { 109081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); 109181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); 10924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 10934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 10954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 109681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 10974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1098b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 109934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 110034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 110181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 110260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 110360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 110460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 110560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 110660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 110760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float lodbias, 110860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 110960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 111060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 111160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct pipe_texture *texture = samp->texture; 111260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 111360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 111460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 111560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float xw[4], yw[4]; /* weights */ 111660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 111760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 111860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 111960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell width = texture->width[level0]; 112060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell height = texture->height[level0]; 112160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 112260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 11235dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 112460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 112560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 112660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 112760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 112860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 112960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_t(t, height, y0, y1, yw); 113060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 113160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 113260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); 113360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); 113460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); 113560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); 113660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 113760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 113860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* interpolate R, G, B, A */ 113960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 114060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 114160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx0[c], tx1[c], 114260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx2[c], tx3[c]); 114360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 114460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 114560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 114681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 114781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1148b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrianstatic void 114960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, 1150e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1151e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1152e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 1153e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float lodbias, 1154e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1155b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 11564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1157aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 11584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 11594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1160b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian int width, height; 11614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 11624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 116381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1164b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 11654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 11660b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 11670b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 1168b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1169b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(width > 0); 11705dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 1171b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 117281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 117381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 117481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 11764e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 11774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 117981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addrj = face(addr, faces[j]); 118081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); 118181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); 118281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); 118381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); 11844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 11854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 11874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 11884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 118981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx0[c], tx1[c], 119081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx2[c], tx3[c]); 1191b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 11924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 11944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 11974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 11984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 12024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 12034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 12044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 12054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 12064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 12074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 12084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 12094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 121081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 12114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 12134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 12144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell height = texture->height[level0]; 12154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell depth = texture->depth[level0]; 12164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 121781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 121881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = level0; 121981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 12214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 12224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 12234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12254e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12264e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 12274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 123181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); 123281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); 123381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); 123481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); 123581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 123681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); 123781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); 123881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); 123981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); 124081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 124481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx00[c], tx01[c], 124581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx02[c], tx03[c], 124681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx10[c], tx11[c], 124781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx12[c], tx13[c]); 12484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 1255e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1256e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1257e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 1258e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float lodbias, 1259e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 12604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 12614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 12624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 12634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 12644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 12654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 12674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 12684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 12704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 12714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 12724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 12744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 12754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 12764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 12784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 12794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 12804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 12814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 12824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 12844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba0 ); 12854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 12874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba1 ); 12884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1292b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1293b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1294b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1295b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1296b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1297b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 12984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 13004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 13054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 13084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 13094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 13114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = (int)(lambda + 0.5) ; 13184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 13194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 132175276ea316610a5737f2115326482024aa09d02aroot 132275276ea316610a5737f2115326482024aa09d02aroot#if 0 132375276ea316610a5737f2115326482024aa09d02aroot printf("RGBA %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n", 132475276ea316610a5737f2115326482024aa09d02aroot rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0], 132575276ea316610a5737f2115326482024aa09d02aroot rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1], 132675276ea316610a5737f2115326482024aa09d02aroot rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2], 132775276ea316610a5737f2115326482024aa09d02aroot rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]); 132875276ea316610a5737f2115326482024aa09d02aroot#endif 13294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 13344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 13394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda = samp->compute_lambda(samp, s, t, p, lodbias); 13424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1353e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1354e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Specialized version of mip_filter_linear with hard-wired calls to 13554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1356a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 13574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 13594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 13604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 136500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 13664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 13684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 13694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 137000c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 13714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = compute_lambda_2d(samp, s, t, p, lodbias); 13724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 13734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 13754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 13764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 13774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 13784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 13804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 13814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba ); 13834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 13864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 13874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 13884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 13894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 13914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba0 ); 13924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 13944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba1 ); 13954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 13984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 13994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1400b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul } 1401ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 1402b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 1403b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 1404b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 14054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1406e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1407e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Do shadow/depth comparisons. 14083d8c05f7320151898dd224c1daaf3118e1f7ea34Brian */ 14094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1411b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float s[QUAD_SIZE], 1412b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float t[QUAD_SIZE], 14133d8c05f7320151898dd224c1daaf3118e1f7ea34Brian const float p[QUAD_SIZE], 1414f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian float lodbias, 1415b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float rgba[NUM_CHANNELS][QUAD_SIZE]) 14163d8c05f7320151898dd224c1daaf3118e1f7ea34Brian{ 14174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1418aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 14194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 14204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 14213d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 14224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter( tgsi_sampler, s, t, p, lodbias, rgba ); 14233d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 14244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 14254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 14264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 14274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 14284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 1429efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1430efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* compare four texcoords vs. four texture samples */ 1431efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul switch (sampler->compare_func) { 1432efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LESS: 1433efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] < rgba[0][0]; 1434efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] < rgba[0][1]; 1435efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] < rgba[0][2]; 1436efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] < rgba[0][3]; 1437efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1438efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LEQUAL: 1439efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] <= rgba[0][0]; 1440efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] <= rgba[0][1]; 1441efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] <= rgba[0][2]; 1442efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] <= rgba[0][3]; 1443efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1444efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GREATER: 1445efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] > rgba[0][0]; 1446efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] > rgba[0][1]; 1447efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] > rgba[0][2]; 1448efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] > rgba[0][3]; 1449efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1450efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GEQUAL: 1451efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] >= rgba[0][0]; 1452efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] >= rgba[0][1]; 1453efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] >= rgba[0][2]; 1454efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] >= rgba[0][3]; 1455efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1456efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_EQUAL: 1457efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] == rgba[0][0]; 1458efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] == rgba[0][1]; 1459efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] == rgba[0][2]; 1460efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] == rgba[0][3]; 1461efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1462efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NOTEQUAL: 1463efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] != rgba[0][0]; 1464efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] != rgba[0][1]; 1465efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] != rgba[0][2]; 1466efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] != rgba[0][3]; 1467efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1468efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_ALWAYS: 1469efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 1; 1470efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1471efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NEVER: 1472efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1473efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1474efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul default: 1475efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1476efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul assert(0); 1477efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1478efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1479efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1480efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* convert four pass/fail values to an intensity in [0,1] */ 1481efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul val = 0.25F * (k0 + k1 + k2 + k3); 1482efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1483efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 1484efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul for (j = 0; j < 4; j++) { 1485efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 1486efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[3][j] = 1.0F; 1487efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1488efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul} 1489efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1490e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1491e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1492e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Compute which cube face is referenced by each texcoord and put that 1493e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * info into the sampler faces[] array. Then sample the cube faces 14940dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 1495e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 14964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 15004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 15014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 15020dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 15034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 15044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 15054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 150609a1b912605ff48c8782dcc5aae55ac77e27037bBrian 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 15084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 15094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell direction target sc tc ma 15104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ---------- ------------------------------- --- --- --- 15114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 15124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 15134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 15144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 15154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 15164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 15174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 15194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rx = s[j]; 15204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ry = t[j]; 15214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rz = p[j]; 15224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 15234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned face; 15244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float sc, tc, ma; 15254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1526890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell if (arx >= ary && arx >= arz) { 15274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rx >= 0.0F) { 15284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_X; 15294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rz; 15304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 15324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_X; 15354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rz; 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1540890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell else if (ary >= arx && ary >= arz) { 15414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (ry >= 0.0F) { 15424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Y; 15434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = rz; 15454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 15464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Y; 15494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -rz; 15514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 15524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rz > 0.0F) { 15564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Z; 15574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 15604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Z; 15634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rx; 15644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 15664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1568b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1569fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell { 1570fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell const float ima = 1.0 / ma; 1571fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell ssss[j] = ( sc * ima + 1.0F ) * 0.5F; 1572fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell tttt[j] = ( tc * ima + 1.0F ) * 0.5F; 1573fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell samp->faces[j] = face; 1574fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell } 15754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 157609a1b912605ff48c8782dcc5aae55ac77e27037bBrian 15774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 15784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 15794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 15806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 15814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare(tgsi_sampler, ssss, tttt, NULL, lodbias, rgba); 15824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1583612cfb749c3526eeb446bbc631bf24716522f373Brian 15843d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 15853d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 1586e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1587e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_unorm_wrap(unsigned mode) 15884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 15894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 15904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 15914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 15924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 15934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 15944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 15950dc4eea64f56cc93e5359372b08b99a2d600273cBrian default: 15960dc4eea64f56cc93e5359372b08b99a2d600273cBrian assert(0); 15974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 15980dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 15990dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 160034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 160134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1602e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1603e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_wrap(unsigned mode) 1604a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 16054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 16074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 16084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 16104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 16114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 16124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 16144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 16154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 16164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 16174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 16184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 16194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 16204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 16214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 16224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 16254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1626a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 1627a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 1628e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1629e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1630e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_unorm_wrap(unsigned mode) 1631a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 16324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 16354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 16364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 16384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 16414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1642a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 1643a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 1644e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1645e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1646e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_wrap(unsigned mode) 164734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 16484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 16504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 16514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 16534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 16544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 16554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 16574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 16584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 16594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 16604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 16614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 16624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 16634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 16644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 16653d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian default: 16663d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(0); 16674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 16683d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 166934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 167034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1671e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1672e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic compute_lambda_func 1673e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_lambda_func(const union sp_sampler_key key) 167434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 16754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 16764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 16774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 16794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 16804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 16814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 168287ec83afd58536c31bf02c307f1d5488abc84861Brian Paul case PIPE_TEXTURE_CUBE: 16834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 16844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 16854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 16864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 1689b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 169034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 169134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1692e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1693e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic filter_func 1694e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_img_filter(const union sp_sampler_key key, 1695e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul unsigned filter, 1696e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const struct pipe_sampler_state *sampler) 1697b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 16984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 16994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 17004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 17014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 17024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 1704b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 17054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 17064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 17074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 17094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 17104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 171138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian { 17124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 17134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 17144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 17156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 17164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 17176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 17184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 17196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 17206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 172138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 17224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 17234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 17244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 17256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 17264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 17276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 17286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 172938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 1730b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1731b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 173260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* Otherwise use default versions: 17334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 17354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 17364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 17384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 173960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell case PIPE_TEXTURE_CUBE: 174060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 174160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_nearest; 174260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell else 174360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_linear; 174460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell break; 17454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 17464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 17474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 17484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 1750b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 1751b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian default: 1752b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(0); 17534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 1754b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1755b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1756b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1757b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1758a34b8594b7b2d00404bb639621ec1ce918ba0786Brian/** 1759a29447c33d44b3427e0c40a761067c0cc6e71c39Brian Paul * Bind the given texture object and texture cache to the sampler varient. 1760a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 17614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 17624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, 17637670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell struct softpipe_tex_tile_cache *tex_cache, 17644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture ) 176534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 17664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 17674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->texture = texture; 17694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 17704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->xpot = util_unsigned_logbase2( texture->width[0] ); 17714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->ypot = util_unsigned_logbase2( texture->height[0] ); 17724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); 17734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 17740b9e96fae9493d5d58f046e01c983a3c4267090eBrian 17754f23468bd0d14b8ed687a641003d587b91ad39a7Brian 1776ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellvoid 1777ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellsp_sampler_varient_destroy( struct sp_sampler_varient *samp ) 1778ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell{ 1779ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell FREE(samp); 1780ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell} 1781ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1782ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1783e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1784e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Create a sampler varient for a given set of non-orthogonal state. 17854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstruct sp_sampler_varient * 17874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_create_sampler_varient( const struct pipe_sampler_state *sampler, 17884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 17894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 17904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient); 17914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 17924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 17934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 17954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 17964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 17984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 17994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 18004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 18024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 18034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 18044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 18054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 18074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 18084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 18094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 18114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 18124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 18134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 18144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 18164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 18174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 18184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 18214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 182341483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 18244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 18264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 18274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 18284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 1829b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian else 18304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 183134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 18324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 18344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 183534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 18364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 18384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 18394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 18404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 18414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 1842cf102b031e7ef33c8e3ffce2f9dcd064f44e8190Brian Paul sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && 18434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 18444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 18454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 18464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 18484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 18494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 18506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 185134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 185234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 18533d53d38d5e35386de4793162b9dd32e171927059Brian Paul 18544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->compare_mode != FALSE) { 18554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 18563d53d38d5e35386de4793162b9dd32e171927059Brian Paul } 18574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 18584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 18594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 18604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 18624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 18654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = sample_cube; 18664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 18684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 18694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 18704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 18714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 18724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 18744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 18754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = samp->compare; 18776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 18786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 18794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 188034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 1881