sp_tex_sample.c revision fd19e8adcd82e88d0fc8d187360b528100fed244
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 1184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_repeat(const float s[4], unsigned size, 1194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1) */ 1244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch] * size); 1274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = REMAINDER(i, size); 1284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp(const float s[4], unsigned size, 13438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord[4]) 1350dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 13638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 1374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1] */ 1384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= 0.0F) 1414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= 1.0F) 1434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp_to_edge(const float s[4], unsigned size, 1524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 1574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] < min) 1614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] > max) 1634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_clamp_to_border(const float s[4], unsigned size, 1724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [-1, size] */ 1774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 1784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= min) 1814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 1824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= max) 1834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 1844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 1904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_repeat(const float s[4], unsigned size, 1914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 1924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 1984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 1994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 2004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 2014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 2034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp(const float s[4], unsigned size, 2144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 21808f33a025100dea2d951e6d628891fe294b18082Brian /* s limited to [0,1] */ 21908f33a025100dea2d951e6d628891fe294b18082Brian /* i limited to [0,size-1] */ 2204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= 0.0F) 2224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= 1.0F) 2244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, 2324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, 2534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 2594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 2644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 2664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2680dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 2690dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 2700dc4eea64f56cc93e5359372b08b99a2d600273cBrian 27108f33a025100dea2d951e6d628891fe294b18082Brian 27208f33a025100dea2d951e6d628891fe294b18082Brian/** 27338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Used to compute texel locations for linear sampling for four texcoords. 27408f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 27538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the texcoords 27608f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 27738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord0 returns first texture indexes 27838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord1 returns second texture indexes (usually icoord0 + 1) 27938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param w returns blend factor/weight between texture indexes 28038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the computed integer texture coords 28108f33a025100dea2d951e6d628891fe294b18082Brian */ 2824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_repeat(const float s[4], unsigned size, 2844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 2854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = s[ch] * size - 0.5F; 2904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = REMAINDER(util_ifloor(u), size); 2914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = REMAINDER(icoord0[ch] + 1, size); 2924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 2934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp(const float s[4], unsigned size, 29838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 2990dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 30038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 3014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 30938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 3104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_edge(const float s[4], unsigned size, 3124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_border(const float s[4], unsigned size, 3304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 3334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 3344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], min, max); 3374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_repeat(const float s[4], unsigned size, 3474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 3524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u; 3534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 3544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = 1.0F - (s[ch] - (float) flr); 3554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = s[ch] - (float) flr; 3574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5F; 3584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 3644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp(const float s[4], unsigned size, 3704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 3834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 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 4084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, 4104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 4114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 4134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 4144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= min) 4184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = min * size; 4194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= max) 4204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = max * size; 4214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 4270dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 4280dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 4290dc4eea64f56cc93e5359372b08b99a2d600273cBrian 4300dc4eea64f56cc93e5359372b08b99a2d600273cBrian 431b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 432b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords 433b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 434b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp(const float s[4], unsigned size, 43738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 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 4464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Handles clamp_to_edge and clamp_to_border: 4474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 4484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, 4504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 4514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); 455b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 456b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 457b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 458b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 459b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 460b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * For RECT textures / unnormalized texcoords. 461b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian * Only a subset of wrap modes supported. 462b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp(const float s[4], unsigned size, 46538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 466b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 46738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Not exactly what the spec says, but it matches NVIDIA output */ 4704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); 4714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 474b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 475b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 476b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 4774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp_to_border( const float s[4], unsigned size, 4794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 48034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 4814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F); 4844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] > (int) size - 1) 4884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 4894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell w[ch] = FRAC(u); 49034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 4914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 49334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 49634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 497b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian/** 498b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * Examine the quad's texture coordinates to compute the partial 499b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * derivatives w.r.t X and Y, then compute lambda (level of detail). 500b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 501b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic float 5024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_1d(const struct sp_sampler_varient *samp, 5034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 507b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 50800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 50900c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(dsdx, dsdy) * texture->width[0]; 5134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 514b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = util_fast_log2(rho); 5164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda += lodbias + sampler->lod_bias; 5174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 51800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lambda; 5204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 521b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 5224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_2d(const struct sp_sampler_varient *samp, 5244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 5284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 5294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 5304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 5384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 539b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5401a46dcc8a927dfb38ca1381e7b3dafb789f8257cBrian Paul lambda = util_fast_log2(rho); 5410b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda += lodbias + sampler->lod_bias; 5420b9e96fae9493d5d58f046e01c983a3c4267090eBrian lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 543b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 544b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian return lambda; 545b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 546b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 547b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_3d(const struct sp_sampler_varient *samp, 5504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 55409a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 55500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_texture *texture = samp->texture; 55600c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 5574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 5634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width[0]; 5644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height[0]; 5654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float maxz = MAX2(dpdx, dpdy) * texture->depth[0]; 5664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho, lambda; 56700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 5694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 570c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = util_fast_log2(rho); 5724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda += lodbias + sampler->lod_bias; 5734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = CLAMP(lambda, sampler->min_lod, sampler->max_lod); 5744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lambda; 57609a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 57709a1b912605ff48c8782dcc5aae55ac77e27037bBrian 57808f33a025100dea2d951e6d628891fe294b18082Brian 5794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 5814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellcompute_lambda_vert(const struct sp_sampler_varient *samp, 5824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 5854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias) 5864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 5874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return lodbias; 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 5894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 5924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 5934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 5944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 59581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell * \param addr the template tex address containing cube, z, face info. 5964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 597b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param y the y coord of texel within 2D image 598b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param rgba the quad to put the texel/color into 59970eb7996f265f3634dabda078f13d1be3533cc65Brian * 60080c78472ad43f4288c9ef5076074ba9d31a39885Keith Whitwell * XXX maybe move this into sp_tex_tile_cache.c and merge with the 60170eb7996f265f3634dabda078f13d1be3533cc65Brian * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 602b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 60381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 60481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 60581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 60681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 60781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 60881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d_no_border(const struct sp_sampler_varient *samp, 60981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 6106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 61181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 61281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 61481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 61581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y %= TILE_SIZE; 61681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell x %= TILE_SIZE; 61781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 61881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 61981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return &tile->data.color[y][x][0]; 62181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 62281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 62481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 62581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_2d(const struct sp_sampler_varient *samp, 62681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 62781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 62881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct pipe_texture *texture = samp->texture; 62981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 63081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell if (x < 0 || x >= (int) texture->width[level] || 63281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y < 0 || y >= (int) texture->height[level]) { 63381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 63481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 63581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell else { 63681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_2d_no_border( samp, addr, x, y ); 63781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 63881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 6396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 64181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of adjacent texels within a tile: 64281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 64381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 64481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border_single_tile(const struct sp_sampler_varient *samp, 64581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 64681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned x, unsigned y, 64781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 64881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 64981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 65081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 65281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 6536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 65581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 6576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 6596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 6606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 6616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 6626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 66481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of potentially non-adjacent texels: 66681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 66781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 66881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d_no_border(const struct sp_sampler_varient *samp, 66981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 67081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 67181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 67281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 67381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 67481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); 67581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); 67681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); 67781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); 67881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 67981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 68081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Can involve a lot of unnecessary checks for border color: 68181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 68281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 68381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_quad_2d(const struct sp_sampler_varient *samp, 68481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 68581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 68681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 68781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 68881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 68981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d( samp, addr, x0, y0 ); 69081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d( samp, addr, x1, y0 ); 69181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d( samp, addr, x1, y1 ); 69281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d( samp, addr, x0, y1 ); 69381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 69481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* 3d varients: 69881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 6996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 70081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d_no_border(const struct sp_sampler_varient *samp, 70181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y, int z) 7026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 703153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const struct softpipe_tex_cached_tile *tile; 7046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 705153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.x = x / TILE_SIZE; 706153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.y = y / TILE_SIZE; 70781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.z = z; 7086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 7096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 7106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 711153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 712153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 7146142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 71781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 71881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellget_texel_3d(const struct sp_sampler_varient *samp, 71981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y, int z ) 720b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 721aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 72281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 7230b9e96fae9493d5d58f046e01c983a3c4267090eBrian 7240b9e96fae9493d5d58f046e01c983a3c4267090eBrian if (x < 0 || x >= (int) texture->width[level] || 7250b9e96fae9493d5d58f046e01c983a3c4267090eBrian y < 0 || y >= (int) texture->height[level] || 7260b9e96fae9493d5d58f046e01c983a3c4267090eBrian z < 0 || z >= (int) texture->depth[level]) { 72781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return samp->sampler->border_color; 728ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 729ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 73081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_3d_no_border( samp, addr, x, y, z ); 731ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 732b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 733b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 734b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 73581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Some image-filter fastpaths: 73681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 737efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 7384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 7394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 7404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 7414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 7424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 7434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 7446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 7454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 7466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 7476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 7486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned xpot = 1 << (samp->xpot - level); 7496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned ypot = 1 << (samp->ypot - level); 7501fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 7511fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 752153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 753153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 754153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 755153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 756153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 757153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 7596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 7606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 7626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 7636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 7656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 7666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 7686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 7696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 7716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 7726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 773153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const float *tx[4]; 7746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 7766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 77779a7ddb57a04cde5a4a0c27eb4a9b6889d12622aKeith Whitwell if (x0 < xmax && y0 < ymax) 7786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell { 77981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); 7806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else 7826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell { 7834f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 7844f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 78581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); 7866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 7906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 7916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 7926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 7936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 7946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 7966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 8014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8066142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8086142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 8106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned xpot = 1 << (samp->xpot - level); 8116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned ypot = 1 << (samp->ypot - level); 812153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 813153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 814153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 815153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8205fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8215fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 82981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d_no_border(samp, addr, x0, y0); 8306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 8404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 8490d9979d9ec5b931856d29c4ec44edb1f4931d1acKeith Whitwell unsigned xpot = 1 << (samp->xpot - level); 8500d9979d9ec5b931856d29c4ec44edb1f4931d1acKeith Whitwell unsigned ypot = 1 << (samp->ypot - level); 851153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 852153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 853153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 854153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8595fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8605fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 8636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 8646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 8666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 8676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 8686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 8696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 8706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 8726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 8736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 8746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 8756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 8766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 87781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out = get_texel_2d_no_border(samp, addr, x0, y0); 8786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 8864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 8874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 8914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 8934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 8946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const struct pipe_texture *texture = samp->texture; 8954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 8964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 8974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 89881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 8996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 9026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 9044f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 90581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 90681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 90781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 9084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9094f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 9104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 91181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, addr, x[j], 0); 91281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 91381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 91481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 91581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 9164f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 9176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 92060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 92160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 92260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 92360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 92460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 92560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float lodbias, 92660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 92760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 92860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 92960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct pipe_texture *texture = samp->texture; 93060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 93160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 93260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x[4], y[4]; 93360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 93481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 93581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 93660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 93760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell width = texture->width[level0]; 93860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell height = texture->height[level0]; 93960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 94060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 94160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 94260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 94360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 94460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 94560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_s(s, width, x); 94660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_t(t, height, y); 94760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 94860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 94960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *out = get_texel_2d(samp, addr, x[j], y[j]); 95060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 95160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 95260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = out[c]; 95360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 95460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 95560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 95660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 95781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic inline union tex_tile_address face( union tex_tile_address addr, 95881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned face ) 95981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 96081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.face = face; 96181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return addr; 96281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 96381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 964e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 96560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, 9664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 9704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9710dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 9724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 973aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 9744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 9754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 976f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian int width, height; 9774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 97881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 97981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 980b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 9814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 9820b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 9830b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 98409a1b912605ff48c8782dcc5aae55ac77e27037bBrian 985b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian assert(width > 0); 98681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 98781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 98881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 989612cfb749c3526eeb446bbc631bf24716522f373Brian 9904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 992f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian 9934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 99481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); 99581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 99681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 99781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 99881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 9990dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 10000dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 100134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 100234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 10034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 10054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 101034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 10114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1012aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 10134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10143d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian int width, height, depth; 10154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 101681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1017b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 10184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10190b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 10200b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 10210b9e96fae9493d5d58f046e01c983a3c4267090eBrian depth = texture->depth[level0]; 10223d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 10233d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(width > 0); 10243d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(height > 0); 10253d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(depth > 0); 10263d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 10274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 10294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 10303d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 103181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 103281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 103381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 103581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); 103681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 103781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 103881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 103981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10403d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 104134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 104234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 104334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 104434a48abd5ff82ce9748fc29191e35a0985d47c5fBrianstatic void 10454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 10464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 10504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 105134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 10524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 10534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 10544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 10564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 10574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 105881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 10594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 10624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 10634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 10654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 106681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 106781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 106881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 10704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1072b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian for (j = 0; j < QUAD_SIZE; j++) { 107381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); 107481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); 10754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 10764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 10774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 10784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 107981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 10804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1081b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 108234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 108334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 108481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 108560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 108660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 108760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 108860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 108960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 109060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float lodbias, 109160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 109260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 109360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 109460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const struct pipe_texture *texture = samp->texture; 109560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 109660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 109760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 109860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float xw[4], yw[4]; /* weights */ 109960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 110060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 110360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell width = texture->width[level0]; 110460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell height = texture->height[level0]; 110560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 110760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 110960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 111060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 111160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 111260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_t(t, height, y0, y1, yw); 111360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 111460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 111560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); 111660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); 111760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); 111860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); 111960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 112060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 112160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* interpolate R, G, B, A */ 112260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 112360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 112460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx0[c], tx1[c], 112560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx2[c], tx3[c]); 112660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 112760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 112860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 112981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 113081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1131b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrianstatic void 113260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, 11334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 11374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 1138b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 11394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1140aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_texture *texture = samp->texture; 11414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 11424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1143b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian int width, height; 11444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 11454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 114681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1147b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1148b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 11494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 11500b9e96fae9493d5d58f046e01c983a3c4267090eBrian width = texture->width[level0]; 11510b9e96fae9493d5d58f046e01c983a3c4267090eBrian height = texture->height[level0]; 1152b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1153b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(width > 0); 1154b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 115581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 115681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 115781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 11594e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 11604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 116281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addrj = face(addr, faces[j]); 116381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); 116481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); 116581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); 116681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); 11674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 11684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 11704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 11714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 117281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx0[c], tx1[c], 117381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx2[c], tx3[c]); 1174b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 11754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 11764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 11774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 11804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 11814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 11854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 11864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 11874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 11884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 11894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 11904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 11914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 11924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 119381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 11944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 11964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell width = texture->width[level0]; 11974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell height = texture->height[level0]; 11984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell depth = texture->depth[level0]; 11994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 120081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 120181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = level0; 120281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 12044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 12054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 12064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12084e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12094e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 12104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 121481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); 121581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); 121681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); 121781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); 121881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 121981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); 122081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); 122181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); 122281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); 122381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 122781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx00[c], tx01[c], 122881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx02[c], tx03[c], 122981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx10[c], tx11[c], 123081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx12[c], tx13[c]); 12314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 12434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 12474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 12484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 12494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 12504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 12514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 12524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 12534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 12554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 12564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 12584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 12594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 12604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 12624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 12634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 12644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 12664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 12674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 12684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 12694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 12704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 12724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba0 ); 12734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 12754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba1 ); 12764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 12784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1280b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1281b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1282b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1283b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1284b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1285b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 12864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 12894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 12934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 12944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 12954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 12964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 12974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 12984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = samp->compute_lambda(samp, s, t, p, lodbias); 13004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = (int)(lambda + 0.5) ; 13074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 13084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 13154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 13204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 13214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda = samp->compute_lambda(samp, s, t, p, lodbias); 13234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mag_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter( tgsi_sampler, s, t, p, 0, rgba ); 13294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Specialized version of mip_filter_linear with hard-wired calls to 13354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1336a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 13374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 13394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 13404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 13414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 13424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 13434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 13444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 134500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 13464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 13474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture = samp->texture; 13484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 13494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 135000c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 13514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell lambda = compute_lambda_2d(samp, s, t, p, lodbias); 13524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 13534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 13554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 13564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 13574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 13584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 13604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 13614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba ); 13634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 13664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 13674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 13684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 13694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 13714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba0 ); 13724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 13744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell img_filter_2d_linear_repeat_POT( tgsi_sampler, s, t, p, 0, rgba1 ); 13754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 13784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 13794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 138200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell} 138300c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 13844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Compare stage in the little sampling pipeline. 138700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell */ 13884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1390b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float s[QUAD_SIZE], 1391b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float t[QUAD_SIZE], 1392b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float p[QUAD_SIZE], 1393f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian float lodbias, 1394b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float rgba[NUM_CHANNELS][QUAD_SIZE]) 139534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 13964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 1397aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 13984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 13994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 14000b9e96fae9493d5d58f046e01c983a3c4267090eBrian 14014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter( tgsi_sampler, s, t, p, lodbias, rgba ); 140200c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 140300c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 14044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 14054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 14064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 14074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 14084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 14094f23468bd0d14b8ed687a641003d587b91ad39a7Brian 14104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* compare four texcoords vs. four texture samples */ 14114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->compare_func) { 14124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_LESS: 14134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] < rgba[0][0]; 14144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] < rgba[0][1]; 14154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] < rgba[0][2]; 14164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] < rgba[0][3]; 141734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 14184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_LEQUAL: 14194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] <= rgba[0][0]; 14204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] <= rgba[0][1]; 14214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] <= rgba[0][2]; 14224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] <= rgba[0][3]; 142334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 14244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_GREATER: 14254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] > rgba[0][0]; 14264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] > rgba[0][1]; 14274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] > rgba[0][2]; 14284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] > rgba[0][3]; 142934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 14304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_GEQUAL: 14314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] >= rgba[0][0]; 14324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] >= rgba[0][1]; 14334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] >= rgba[0][2]; 14344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] >= rgba[0][3]; 14354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 14364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_EQUAL: 14374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] == rgba[0][0]; 14384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] == rgba[0][1]; 14394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] == rgba[0][2]; 14404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] == rgba[0][3]; 14414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 14424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_NOTEQUAL: 14434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = p[0] != rgba[0][0]; 14444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k1 = p[1] != rgba[0][1]; 14454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k2 = p[2] != rgba[0][2]; 14464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k3 = p[3] != rgba[0][3]; 14474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 14484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_ALWAYS: 14494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 1; 14504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 14514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_FUNC_NEVER: 14524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 0; 145334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 145434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian default: 14554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell k0 = k1 = k2 = k3 = 0; 145634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian assert(0); 145700c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell break; 145834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 14593d53d38d5e35386de4793162b9dd32e171927059Brian Paul 14604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* convert four pass/fail values to an intensity in [0,1] */ 14614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell val = 0.25F * (k0 + k1 + k2 + k3); 14624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 14644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < 4; j++) { 14654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 14664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[3][j] = 1.0F; 14674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Calculate cube faces. 14714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 14724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 14744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lodbias, 14784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 14794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 14804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = sp_sampler_varient(tgsi_sampler); 14814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 14824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 14834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 14854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 14864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell direction target sc tc ma 14874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ---------- ------------------------------- --- --- --- 14884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 14894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 14904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 14914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 14924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 14934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 14944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 14954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 14964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rx = s[j]; 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ry = t[j]; 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rz = p[j]; 14994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 15004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned face; 15014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float sc, tc, ma; 15024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (arx > ary && arx > arz) { 15044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rx >= 0.0F) { 15054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_X; 15064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rz; 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 15094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_X; 15124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rz; 15134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arx; 15154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (ary > arx && ary > arz) { 15184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (ry >= 0.0F) { 15194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Y; 15204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = rz; 15224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 15234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Y; 15264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -rz; 15284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = ary; 15294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (rz > 0.0F) { 15334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_POS_Z; 15344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = rx; 15354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell face = PIPE_TEX_FACE_NEG_Z; 15404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sc = -rx; 15414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell tc = -ry; 15424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell ma = arz; 15434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1546fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell { 1547fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell const float ima = 1.0 / ma; 1548fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell ssss[j] = ( sc * ima + 1.0F ) * 0.5F; 1549fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell tttt[j] = ( tc * ima + 1.0F ) * 0.5F; 1550fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell samp->faces[j] = face; 1551fd19e8adcd82e88d0fc8d187360b528100fed244Keith Whitwell } 15524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 15544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 15554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 15564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 15576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 15584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare(tgsi_sampler, ssss, tttt, NULL, lodbias, rgba); 15594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 15604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_nearest_func get_nearest_unorm_wrap( unsigned mode ) 15654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 15664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 15674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 15684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 15694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 15704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 15714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 15724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 15734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 15744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 15754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 15774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_nearest_func get_nearest_wrap( unsigned mode ) 15804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 15814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 15824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 15834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 15844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 15854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 15864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 15874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 15884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 15894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 15904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 15914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 15924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 15934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 15944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 15954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 15964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 15974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 15984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 15994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 16014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 16034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_linear_func get_linear_unorm_wrap( unsigned mode ) 16054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 16064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 16094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 16104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 16124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 16154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 16174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic wrap_linear_func get_linear_wrap( unsigned mode ) 16194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 16204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 16214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 16224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 16234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 16254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 16264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 16274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 16284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 16294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 16304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 16314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 16324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 16334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 16344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 16354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 16364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 16374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 16404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 16424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic compute_lambda_func get_lambda_func( const union sp_sampler_key key ) 16444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 16454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 16464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 16474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 16494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 16504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 16514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 165287ec83afd58536c31bf02c307f1d5488abc84861Brian Paul case PIPE_TEXTURE_CUBE: 16534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 16544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 16554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 16564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 16574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 16584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 16594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 16614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic filter_func get_img_filter( const union sp_sampler_key key, 16634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned filter, 16644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler ) 16654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 16664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 16674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 16684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 16694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 16704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 16714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 16724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 16734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 16744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 16754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 16764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 16774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 16784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 16794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 16804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 16814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 16824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 16836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 16844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 16856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 16864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 16876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 16886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 16896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 16914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 16924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 16936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 16944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 16956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 16966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 16976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 16996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 170060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* Otherwise use default versions: 17014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 17034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 17044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 17064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 170760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell case PIPE_TEXTURE_CUBE: 170860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 170960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_nearest; 171060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell else 171160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_linear; 171260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell break; 17134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 17144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 17154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 17164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 17184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 17194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 17204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 17214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 17224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 17244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1726a29447c33d44b3427e0c40a761067c0cc6e71c39Brian Paul/** 1727a29447c33d44b3427e0c40a761067c0cc6e71c39Brian Paul * Bind the given texture object and texture cache to the sampler varient. 1728a29447c33d44b3427e0c40a761067c0cc6e71c39Brian Paul */ 17294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 17304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_sampler_varient_bind_texture( struct sp_sampler_varient *samp, 17317670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell struct softpipe_tex_tile_cache *tex_cache, 17324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_texture *texture ) 17334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 17344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 17354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->texture = texture; 17374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 17384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->xpot = util_unsigned_logbase2( texture->width[0] ); 17394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->ypot = util_unsigned_logbase2( texture->height[0] ); 17404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); 17414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 17424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1743ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1744ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellvoid 1745ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellsp_sampler_varient_destroy( struct sp_sampler_varient *samp ) 1746ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell{ 1747ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell FREE(samp); 1748ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell} 1749ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 1750ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 17514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/* Create a sampler varient for a given set of non-orthogonal state. Currently the 17524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstruct sp_sampler_varient * 17544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsp_create_sampler_varient( const struct pipe_sampler_state *sampler, 17554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 17564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 17574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct sp_sampler_varient *samp = CALLOC_STRUCT(sp_sampler_varient); 17584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 17594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 17604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 17624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 17634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 17654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 17664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 17674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 17694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 17704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 17714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 17724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 17744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 17754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 17764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 17784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 17794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 17804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 17814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 17834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 17844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 17854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 17884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 179041483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 17914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 17934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 17944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 17954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 17964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 17984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 17994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 18014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 18024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 18034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 18054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 18064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 18074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 18084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 1809cf102b031e7ef33c8e3ffce2f9dcd064f44e8190Brian Paul sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && 18104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 18114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 18124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 18134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 18154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 18164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 18176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 18184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 18194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->compare_mode != FALSE) { 18224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 18236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 18244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 18254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 18264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 18274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 18294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 18324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = sample_cube; 18334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 18344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 18354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 18364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 18374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 18384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 18394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 18414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 18424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 18434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->base.get_samples = samp->compare; 18446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 18456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 18464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 18473ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul} 18483ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 18494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 18534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1854