sp_tex_sample.c revision f3955f6fcdd1a3106a6538642131ccea5ef1cef0
10dc4eea64f56cc93e5359372b08b99a2d600273cBrian/************************************************************************** 20dc4eea64f56cc93e5359372b08b99a2d600273cBrian * 30dc4eea64f56cc93e5359372b08b99a2d600273cBrian * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 40dc4eea64f56cc93e5359372b08b99a2d600273cBrian * All Rights Reserved. 54bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Copyright 2008-2010 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 474250882ccf8326ba9074c671110370534489caa6Brian Paul/** Set to one to help debug texture sampling */ 484250882ccf8326ba9074c671110370534489caa6Brian Paul#define DEBUG_TEX 0 494250882ccf8326ba9074c671110370534489caa6Brian Paul 503ffd529ff19bf8dd7b022a267bf2afe44c7f0f65Brian Paul 5108f33a025100dea2d951e6d628891fe294b18082Brian/* 52b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Return fractional part of 'f'. Used for computing interpolation weights. 53b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Need to be careful with negative values. 54b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Note, if this function isn't perfect you'll sometimes see 1-pixel bands 55b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * of improperly weighted linear-filtered textures. 5608f33a025100dea2d951e6d628891fe294b18082Brian * The tests/texwrap.c demo is a good test. 5708f33a025100dea2d951e6d628891fe294b18082Brian */ 58b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulstatic INLINE float 59b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulfrac(float f) 60b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul{ 61b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul return f - floorf(f); 62b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul} 63b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul 6408f33a025100dea2d951e6d628891fe294b18082Brian 6508f33a025100dea2d951e6d628891fe294b18082Brian 6608f33a025100dea2d951e6d628891fe294b18082Brian/** 6708f33a025100dea2d951e6d628891fe294b18082Brian * Linear interpolation macro 6808f33a025100dea2d951e6d628891fe294b18082Brian */ 6938bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 7038bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp(float a, float v0, float v1) 7138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 7238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return v0 + a * (v1 - v0); 7338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 740dc4eea64f56cc93e5359372b08b99a2d600273cBrian 750dc4eea64f56cc93e5359372b08b99a2d600273cBrian 760dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 77fd60bf8e33bbcba7b7749ae5a4285bad60769b9bBrian Paul * Do 2D/bilinear interpolation of float values. 780dc4eea64f56cc93e5359372b08b99a2d600273cBrian * v00, v10, v01 and v11 are typically four texture samples in a square/box. 790dc4eea64f56cc93e5359372b08b99a2d600273cBrian * a and b are the horizontal and vertical interpolants. 800dc4eea64f56cc93e5359372b08b99a2d600273cBrian * It's important that this function is inlined when compiled with 810dc4eea64f56cc93e5359372b08b99a2d600273cBrian * optimization! If we find that's not true on some systems, convert 820dc4eea64f56cc93e5359372b08b99a2d600273cBrian * to a macro. 830dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 84b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic INLINE float 85b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianlerp_2d(float a, float b, 86b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float v00, float v10, float v01, float v11) 870dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 8838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp(a, v00, v10); 8938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp(a, v01, v11); 9038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(b, temp0, temp1); 9138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian} 9238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 9338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 9438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian/** 9538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * As above, but 3D interpolation of 8 values. 9638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian */ 9738bee46e83b18ff4ad42d340b507b1a15b4326c7Brianstatic INLINE float 9838bee46e83b18ff4ad42d340b507b1a15b4326c7Brianlerp_3d(float a, float b, float c, 9938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v000, float v100, float v010, float v110, 10038bee46e83b18ff4ad42d340b507b1a15b4326c7Brian float v001, float v101, float v011, float v111) 10138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian{ 10238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp0 = lerp_2d(a, b, v000, v100, v010, v110); 10338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian const float temp1 = lerp_2d(a, b, v001, v101, v011, v111); 10438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian return lerp(c, temp0, temp1); 1050dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 1060dc4eea64f56cc93e5359372b08b99a2d600273cBrian 1070dc4eea64f56cc93e5359372b08b99a2d600273cBrian 10838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 1090dc4eea64f56cc93e5359372b08b99a2d600273cBrian/** 110b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul * Compute coord % size for repeat wrap modes. 111e31f0f996537046228602a251706613ca4163209Brian Paul * Note that if coord is negative, coord % size doesn't give the right 112e31f0f996537046228602a251706613ca4163209Brian Paul * value. To avoid that problem we add a large multiple of the size 113e31f0f996537046228602a251706613ca4163209Brian Paul * (rather than using a conditional). 1140dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 115b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulstatic INLINE int 116b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paulrepeat(int coord, unsigned size) 117b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul{ 118e31f0f996537046228602a251706613ca4163209Brian Paul return (coord + size * 1024) % size; 119b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul} 12008f33a025100dea2d951e6d628891fe294b18082Brian 12108f33a025100dea2d951e6d628891fe294b18082Brian 12208f33a025100dea2d951e6d628891fe294b18082Brian/** 12338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Apply texture coord wrapping mode and return integer texture indexes 12438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * for a vector of four texcoords (S or T or P). 12508f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 12638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the incoming texcoords 12708f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 12838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the integer texcoords 12908f33a025100dea2d951e6d628891fe294b18082Brian * \return integer texture index 13008f33a025100dea2d951e6d628891fe294b18082Brian */ 1314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 132e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_repeat(const float s[4], unsigned size, int icoord[4]) 1334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1) */ 1364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch] * size); 139b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord[ch] = repeat(i, size); 1404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 145e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp(const float s[4], unsigned size, int icoord[4]) 1460dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 14738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 1484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [0,1] */ 1494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0,size-1] */ 1504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= 0.0F) 1524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= 1.0F) 1544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 162e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_edge(const float s[4], unsigned size, int icoord[4]) 1634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 1674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 1684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] < min) 1714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 1724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] > max) 1734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 1744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 181e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_clamp_to_border(const float s[4], unsigned size, int icoord[4]) 1824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 1844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 1854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [-1, size] */ 1864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 1874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 1884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 1894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (s[ch] <= min) 1904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 1914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (s[ch] >= max) 1924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 1934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 1944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(s[ch] * size); 1954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 198e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 200e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4]) 2014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 207b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul float u = frac(s[ch]); 2084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 209b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul u = 1.0F - u; 2104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 219e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 221e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_mirror_clamp(const float s[4], unsigned size, int icoord[4]) 2224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 22508f33a025100dea2d951e6d628891fe294b18082Brian /* s limited to [0,1] */ 22608f33a025100dea2d951e6d628891fe294b18082Brian /* i limited to [0,size-1] */ 2274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= 0.0F) 2294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= 1.0F) 2314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 237e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_edge(const float s[4], unsigned size, 240e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 2414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = 1.0F / (2.0F * size); 2464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = 0; 2514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size - 1; 2534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 2574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 2594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_mirror_clamp_to_border(const float s[4], unsigned size, 2614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord[4]) 2624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* s limited to [min,max] */ 2654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* i limited to [0, size-1] */ 2664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 2674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 2684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float u = fabsf(s[ch]); 2704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u < min) 2714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = -1; 2724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u > max) 2734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = size; 2744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 2754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch] = util_ifloor(u * size); 2760dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 2770dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 2780dc4eea64f56cc93e5359372b08b99a2d600273cBrian 27908f33a025100dea2d951e6d628891fe294b18082Brian 28008f33a025100dea2d951e6d628891fe294b18082Brian/** 28138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * Used to compute texel locations for linear sampling for four texcoords. 28208f33a025100dea2d951e6d628891fe294b18082Brian * \param wrapMode PIPE_TEX_WRAP_x 28338bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param s the texcoords 28408f33a025100dea2d951e6d628891fe294b18082Brian * \param size the texture image size 28538bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord0 returns first texture indexes 28638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord1 returns second texture indexes (usually icoord0 + 1) 28738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param w returns blend factor/weight between texture indexes 28838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian * \param icoord returns the computed integer texture coords 28908f33a025100dea2d951e6d628891fe294b18082Brian */ 2904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 2914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_repeat(const float s[4], unsigned size, 2924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 2934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 2954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 2964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = s[ch] * size - 0.5F; 297b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord0[ch] = repeat(util_ifloor(u), size); 298b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul icoord1[ch] = repeat(icoord0[ch] + 1, size); 299b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 303e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp(const float s[4], unsigned size, 30638bee46e83b18ff4ad42d340b507b1a15b4326c7Brian int icoord0[4], int icoord1[4], float w[4]) 3070dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 30838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 3094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 314b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 31738bee46e83b18ff4ad42d340b507b1a15b4326c7Brian 318e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_edge(const float s[4], unsigned size, 3214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], 0.0F, 1.0F); 3264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 333b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 337e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_clamp_to_border(const float s[4], unsigned size, 3404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 3434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 3444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch], min, max); 3474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5f; 3484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 350b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 3554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_repeat(const float s[4], unsigned size, 3574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const int flr = util_ifloor(s[ch]); 362b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul float u = frac(s[ch]); 3634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (flr & 1) 364b37c54150058c07ab2d3db2d7e5891a457b51e76Brian Paul u = 1.0F - u; 3654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = u * size - 0.5F; 3664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 3684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 3694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 3704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 3714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 372b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 376e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp(const float s[4], unsigned size, 3794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 3814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 3824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 3834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 3844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 3854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 3864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 3874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 3884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 3894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 3904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 391b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 3924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 3934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 3944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 395e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 3964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 3974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_edge(const float s[4], unsigned size, 3984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 3994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u >= 1.0F) 4044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = (float) size; 4054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 4104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord0[ch] < 0) 4114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = 0; 4124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] >= (int) size) 4134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 414b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 4154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 418e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 4194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, 4214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int icoord0[4], int icoord1[4], float w[4]) 4224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float min = -1.0F / (2.0F * size); 4244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float max = 1.0F - min; 4254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = fabsf(s[ch]); 4284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (u <= min) 4294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = min * size; 4304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (u >= max) 4314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u = max * size; 4324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 4334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u *= size; 4344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 4354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 437b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 4380dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 4390dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 4400dc4eea64f56cc93e5359372b08b99a2d600273cBrian 4410dc4eea64f56cc93e5359372b08b99a2d600273cBrian 442b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 443b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords. 444b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 446e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) 447b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 44838bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int i = util_ifloor(s[ch]); 4514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= CLAMP(i, 0, (int) size-1); 4524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 4534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 4544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 455e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 456e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 457b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords. 4584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 4594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, 461e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord[4]) 4624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 4634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 4644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 465b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord[ch]= util_ifloor( CLAMP(s[ch], -0.5F, (float) size + 0.5F) ); 466b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul } 467b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul} 468b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 469b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 470b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 471b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords. 472b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 473b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulstatic void 474b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulwrap_nearest_unorm_clamp_to_edge(const float s[4], unsigned size, 475b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul int icoord[4]) 476b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul{ 477b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul uint ch; 478b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul for (ch = 0; ch < 4; ch++) { 4794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); 480b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 481b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 482b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 483b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 484b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian/** 485b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords. 486b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian */ 4874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 4884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellwrap_linear_unorm_clamp(const float s[4], unsigned size, 489e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord0[4], int icoord1[4], float w[4]) 490b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 49138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian uint ch; 4924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 4934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Not exactly what the spec says, but it matches NVIDIA output */ 4944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); 4954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 4964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 497b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 498b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 499b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 500b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 501e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 502b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 503b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords. 504b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 5054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 506e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulwrap_linear_unorm_clamp_to_border(const float s[4], unsigned size, 507e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul int icoord0[4], int icoord1[4], float w[4]) 50834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 5094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell uint ch; 5104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (ch = 0; ch < 4; ch++) { 511b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul float u = CLAMP(s[ch], -0.5F, (float) size + 0.5F); 512b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul u -= 0.5F; 513b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord0[ch] = util_ifloor(u); 514b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord1[ch] = icoord0[ch] + 1; 515b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul if (icoord1[ch] > (int) size - 1) 516b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul icoord1[ch] = size - 1; 517b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul w[ch] = frac(u); 518b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul } 519b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul} 520b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 521b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul 522b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul/** 523b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords. 524b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul */ 525b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulstatic void 526b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paulwrap_linear_unorm_clamp_to_edge(const float s[4], unsigned size, 527b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul int icoord0[4], int icoord1[4], float w[4]) 528b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul{ 529b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul uint ch; 530b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul for (ch = 0; ch < 4; ch++) { 531b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul float u = CLAMP(s[ch], +0.5F, (float) size - 0.5F); 5324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell u -= 0.5F; 5334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord0[ch] = util_ifloor(u); 5344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = icoord0[ch] + 1; 5354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (icoord1[ch] > (int) size - 1) 5364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell icoord1[ch] = size - 1; 537b4a40d10524a4be6a59805589ee4209ebdb1de4fBrian Paul w[ch] = frac(u); 53834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 5394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 5404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 54134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 54234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 543b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian/** 544b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * Examine the quad's texture coordinates to compute the partial 545b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * derivatives w.r.t X and Y, then compute lambda (level of detail). 546b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 547b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic float 548f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_1d(const struct sp_sampler_variant *samp, 5494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5514bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 552b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 553287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 556683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float rho = MAX2(dsdx, dsdy) * texture->width0; 557b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5584bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 559b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 560b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 561e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 563f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_2d(const struct sp_sampler_variant *samp, 5644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5664bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 56709a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 568287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 573683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width0; 574683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height0; 5754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 576c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5774bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 57809a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 57909a1b912605ff48c8782dcc5aae55ac77e27037bBrian 58008f33a025100dea2d951e6d628891fe294b18082Brian 5814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 582f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_3d(const struct sp_sampler_variant *samp, 5834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5854bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 58609a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 587287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 5934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 594683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxx = MAX2(dsdx, dsdy) * texture->width0; 595683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxy = MAX2(dtdx, dtdy) * texture->height0; 596683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell float maxz = MAX2(dpdx, dpdy) * texture->depth0; 5974bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float rho; 59800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 5994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 6004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 601c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 6024bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 60309a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 60409a1b912605ff48c8782dcc5aae55ac77e27037bBrian 60508f33a025100dea2d951e6d628891fe294b18082Brian 606e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 607e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Compute lambda for a vertex texture sampler. 6084bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Since there aren't derivatives to use, just return 0. 609e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul */ 6104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 611f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_vert(const struct sp_sampler_variant *samp, 6124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 6134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 6144bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 6154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 6164bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return 0.0f; 6174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 6184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 6224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 6234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 62481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell * \param addr the template tex address containing cube, z, face info. 6254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 626b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param y the y coord of texel within 2D image 627b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param rgba the quad to put the texel/color into 62870eb7996f265f3634dabda078f13d1be3533cc65Brian * 62980c78472ad43f4288c9ef5076074ba9d31a39885Keith Whitwell * XXX maybe move this into sp_tex_tile_cache.c and merge with the 63070eb7996f265f3634dabda078f13d1be3533cc65Brian * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 631b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 63281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 63681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 637f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_2d_no_border(const struct sp_sampler_variant *samp, 63881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 639b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 64081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 64181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 64381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 64481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y %= TILE_SIZE; 64581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell x %= TILE_SIZE; 64681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 64881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return &tile->data.color[y][x][0]; 65081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 65181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 654f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_2d(const struct sp_sampler_variant *samp, 65581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 65681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 657287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 65881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 65981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 660683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 661683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level)) { 662de2dfce0d97aca1b6242eb4db5d6e4b78301bb49Brian Paul return sp_tex_tile_cache_border_color(samp->cache, 663de2dfce0d97aca1b6242eb4db5d6e4b78301bb49Brian Paul samp->sampler->border_color); 66481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 66581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell else { 66681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_2d_no_border( samp, addr, x, y ); 66781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 66881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 6696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 67181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of adjacent texels within a tile: 67281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 67381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 674f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d_no_border_single_tile(const struct sp_sampler_variant *samp, 67581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 67681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned x, unsigned y, 67781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 67881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 67981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 68081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 68181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 68281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 6836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 68581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 68681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 6876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 6896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 6906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 6916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 6926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 6936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 69481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of potentially non-adjacent texels: 69681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 69781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 698f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d_no_border(const struct sp_sampler_variant *samp, 69981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 70081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 70181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 70281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 70381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 70481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); 70581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); 70681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); 70781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); 70881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 70981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 71081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Can involve a lot of unnecessary checks for border color: 71181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 71281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 713f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d(const struct sp_sampler_variant *samp, 71481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 71581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 71681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 71781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 71881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 71981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d( samp, addr, x0, y0 ); 72081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d( samp, addr, x1, y0 ); 72181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d( samp, addr, x1, y1 ); 72281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d( samp, addr, x0, y1 ); 72381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 72481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 727f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul/* 3d variants: 72881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 7296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 730f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_3d_no_border(const struct sp_sampler_variant *samp, 731e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 7326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 733153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const struct softpipe_tex_cached_tile *tile; 7346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 735153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.x = x / TILE_SIZE; 736153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.y = y / TILE_SIZE; 73781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.z = z; 7386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 7396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 7406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 741153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 742153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 7446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 74781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 748f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_3d(const struct sp_sampler_variant *samp, 749e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 750b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 751287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 75281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 7530b9e96fae9493d5d58f046e01c983a3c4267090eBrian 754683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 755683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level) || 756683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell z < 0 || z >= (int) u_minify(texture->depth0, level)) { 757de2dfce0d97aca1b6242eb4db5d6e4b78301bb49Brian Paul return sp_tex_tile_cache_border_color(samp->cache, 758de2dfce0d97aca1b6242eb4db5d6e4b78301bb49Brian Paul samp->sampler->border_color); 759ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 760ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 76181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_3d_no_border( samp, addr, x, y, z ); 762ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 763b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 764b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 765b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 76675276ea316610a5737f2115326482024aa09d02aroot/** 76775276ea316610a5737f2115326482024aa09d02aroot * Given the logbase2 of a mipmap's base level size and a mipmap level, 76875276ea316610a5737f2115326482024aa09d02aroot * return the size (in texels) of that mipmap level. 76975276ea316610a5737f2115326482024aa09d02aroot * For example, if level[0].width = 256 then base_pot will be 8. 77075276ea316610a5737f2115326482024aa09d02aroot * If level = 2, then we'll return 64 (the width at level=2). 77175276ea316610a5737f2115326482024aa09d02aroot * Return 1 if level > base_pot. 77275276ea316610a5737f2115326482024aa09d02aroot */ 77375276ea316610a5737f2115326482024aa09d02arootstatic INLINE unsigned 77475276ea316610a5737f2115326482024aa09d02arootpot_level_size(unsigned base_pot, unsigned level) 77575276ea316610a5737f2115326482024aa09d02aroot{ 77675276ea316610a5737f2115326482024aa09d02aroot return (base_pot >= level) ? (1 << (base_pot - level)) : 1; 77775276ea316610a5737f2115326482024aa09d02aroot} 77875276ea316610a5737f2115326482024aa09d02aroot 77975276ea316610a5737f2115326482024aa09d02aroot 7804250882ccf8326ba9074c671110370534489caa6Brian Paulstatic void 7814250882ccf8326ba9074c671110370534489caa6Brian Paulprint_sample(const char *function, float rgba[NUM_CHANNELS][QUAD_SIZE]) 7824250882ccf8326ba9074c671110370534489caa6Brian Paul{ 7834250882ccf8326ba9074c671110370534489caa6Brian Paul debug_printf("%s %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n", 7844250882ccf8326ba9074c671110370534489caa6Brian Paul function, 7854250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0], 7864250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1], 7874250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2], 7884250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]); 7894250882ccf8326ba9074c671110370534489caa6Brian Paul} 7904250882ccf8326ba9074c671110370534489caa6Brian Paul 7914250882ccf8326ba9074c671110370534489caa6Brian Paul 79281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Some image-filter fastpaths: 79381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 794efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 7954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 796e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 797e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 798e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 7994440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 8004440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 801e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 8026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 803f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 8046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8056142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 80675276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 80775276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 8081fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 8091fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 810153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 811153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 812153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 813153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 814153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 8156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8186142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 8196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 8206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 8256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 8266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 830153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const float *tx[4]; 8316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 8336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 834e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul if (x0 < xmax && y0 < ymax) { 83581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); 8366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 837e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul else { 8384f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 8394f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 84081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); 8416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 8446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 8466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 8476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 8486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8496142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8504250882ccf8326ba9074c671110370534489caa6Brian Paul 8514250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 8524250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 8534250882ccf8326ba9074c671110370534489caa6Brian Paul } 8546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 8584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 8594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 8604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 8614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 8624440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 8634440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 8644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 8656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 866f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 8676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 86975276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 87075276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 871153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 872153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 873153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 874153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 8756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8795fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 8805fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 8816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 88881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d_no_border(samp, addr, x0, y0); 8896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 8926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8944250882ccf8326ba9074c671110370534489caa6Brian Paul 8954250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 8964250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 8974250882ccf8326ba9074c671110370534489caa6Brian Paul } 8986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 8996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9006142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 9024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 9034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9064440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9074440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 9084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9096142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 910f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 9116142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 9126142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 91375276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 91475276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 915153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 916153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 917153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 918153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 9196142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 9216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 9226142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9235fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 9245fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 9256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 9276142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 9286142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 9306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 9316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 9326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 9336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 9346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 9366142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 9376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 9386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 9396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 9406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 94181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out = get_texel_2d_no_border(samp, addr, x0, y0); 9426142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9436142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 9446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 9456142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9474250882ccf8326ba9074c671110370534489caa6Brian Paul 9484250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 9494250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 9504250882ccf8326ba9074c671110370534489caa6Brian Paul } 9516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 953e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 9546142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 9554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 9564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9594440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9604440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 9614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9626142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 963f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 964287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 9654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 9664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 9674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 96881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 9696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 971683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 9726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 9744f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 97581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 97681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 97781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 9784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 9794f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 9804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 98181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, addr, x[j], 0); 98281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 98381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 98481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 98581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 9864f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 9874250882ccf8326ba9074c671110370534489caa6Brian Paul 9884250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 9894250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 9904250882ccf8326ba9074c671110370534489caa6Brian Paul } 9916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 99460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 99560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 99660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 99760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 99860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 9994440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10004440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 100160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 100260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 1003f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1004287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 100560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 100660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 100760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x[4], y[4]; 100860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 100981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 101081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 101160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 1012683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1013683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 101460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 101560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 10165dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 101760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 101860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 101960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 102060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 102160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_s(s, width, x); 102260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_t(t, height, y); 102360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 102460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 102560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *out = get_texel_2d(samp, addr, x[j], y[j]); 102660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 102760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 102860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = out[c]; 102960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 103060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 10314250882ccf8326ba9074c671110370534489caa6Brian Paul 10324250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 10334250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 10344250882ccf8326ba9074c671110370534489caa6Brian Paul } 103560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 103660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 1037e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 10389659aa6482291d1530c74450612bcd952f542e01José Fonsecastatic INLINE union tex_tile_address 1039e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulface(union tex_tile_address addr, unsigned face ) 104081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 104181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.face = face; 104281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return addr; 104381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 104481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1045e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1046e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 104760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, 1048e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1049e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1050e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 10514440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10524440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1053e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 10540dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 1055f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1056287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 10574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 10584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1059f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian int width, height; 10604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 106181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 106281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1064683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1065683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 106609a1b912605ff48c8782dcc5aae55ac77e27037bBrian 1067b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian assert(width > 0); 10685dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 106981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 107081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 107181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 1072612cfb749c3526eeb446bbc631bf24716522f373Brian 10734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 1075f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian 10764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 107781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); 107881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 107981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 108081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 108181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10820dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 10834250882ccf8326ba9074c671110370534489caa6Brian Paul 10844250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 10854250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 10864250882ccf8326ba9074c671110370534489caa6Brian Paul } 10870dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 108834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 108934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 10904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 10914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 10924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10954440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10964440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 10974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 109834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 1099f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1100287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 11014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 11023d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian int width, height, depth; 11034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 110481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1105b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 11064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1107683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1108683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1109683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 11103d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 11113d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(width > 0); 11123d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(height > 0); 11133d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(depth > 0); 11143d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 11154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 11164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 11174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 11183d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 111981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 112081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 112181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 112381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); 112481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 112581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 112681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 112781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 11283d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 112934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 113034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 113134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 113234a48abd5ff82ce9748fc29191e35a0985d47c5fBrianstatic void 11334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 11344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 11354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 11364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 11374440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 11384440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 11394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 114034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 1141f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1142287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 11434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 11444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 11454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 11464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 114781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 11484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1150683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 11514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 11534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 115481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 115581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 115681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 11584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1159b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian for (j = 0; j < QUAD_SIZE; j++) { 116081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); 116181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); 11624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 11634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 11644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 11654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 116681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 11674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1168b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 116934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 117034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 117181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 117260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 117360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 117460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 117560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 117660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 11774440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 11784440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 117960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 118060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 1181f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1182287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 118360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 118460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 118560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 118660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float xw[4], yw[4]; /* weights */ 118760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 118860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 118960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 1190683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1191683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 119260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 119360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 11945dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 119560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 119660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 119760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 119860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 119960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 120060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_t(t, height, y0, y1, yw); 120160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 120260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 120360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); 120460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); 120560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); 120660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); 120760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 120860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 120960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* interpolate R, G, B, A */ 121060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 121160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 121260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx0[c], tx1[c], 121360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx2[c], tx3[c]); 121460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 121560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 121660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 121781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 121881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1219b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrianstatic void 122060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, 1221e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1222e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1223e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 12244440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 12254440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1226e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1227b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 1228f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1229287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 12304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 12314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1232b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian int width, height; 12334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 12344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 123581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1236b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 12374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1238683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1239683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1240b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1241b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(width > 0); 12425dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 1243b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 124481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 124581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 124681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12484e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 125181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addrj = face(addr, faces[j]); 125281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); 125381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); 125481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); 125581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); 12564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 12604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 126181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx0[c], tx1[c], 126281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx2[c], tx3[c]); 1263b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 12644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 12654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 12664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 12704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12734440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 12744440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 12754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 12764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1277f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1278287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 12794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 12804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 12814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 12824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 128381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 12844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1286683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1287683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1288683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 12894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 129081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 129181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = level0; 129281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 12944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 12954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 12964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12984e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 12994e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 13004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 13034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 130481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); 130581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); 130681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); 130781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); 130881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 130981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); 131081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); 131181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); 131281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); 131381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 13144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 13154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 13164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 131781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx00[c], tx01[c], 131881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx02[c], tx03[c], 131981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx10[c], tx11[c], 132081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx12[c], tx13[c]); 13214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 13244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13264bfe1c955fe679547c8a03119d1681e33593c768Michal Krol/* Calculate level of detail for every fragment. 13274bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Note that lambda has already been biased by global LOD bias. 13284bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 13294bfe1c955fe679547c8a03119d1681e33593c768Michal Krolstatic INLINE void 13304bfe1c955fe679547c8a03119d1681e33593c768Michal Krolcompute_lod(const struct pipe_sampler_state *sampler, 13314bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float biased_lambda, 13324bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float lodbias[QUAD_SIZE], 13334bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]) 13344bfe1c955fe679547c8a03119d1681e33593c768Michal Krol{ 13354bfe1c955fe679547c8a03119d1681e33593c768Michal Krol uint i; 13364bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13374bfe1c955fe679547c8a03119d1681e33593c768Michal Krol for (i = 0; i < QUAD_SIZE; i++) { 13384bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = biased_lambda + lodbias[i]; 13394bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = CLAMP(lod[i], sampler->min_lod, sampler->max_lod); 13404bfe1c955fe679547c8a03119d1681e33593c768Michal Krol } 13414bfe1c955fe679547c8a03119d1681e33593c768Michal Krol} 13424bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13434bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 13454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 1346e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1347e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1348e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 13494440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 13504440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1351e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 13524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1353f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1354287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 13554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 13564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 13574bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 13584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13594440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 13604440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 13614440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 13624440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 13634440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 13644bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13654440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 13664440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 13674bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 13684bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 13694bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 13704bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 13714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 13724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 13744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 13754440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 13764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 13784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 13794440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 13804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 13814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 13824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 13834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 13844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 13854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 13864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 13884440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 13894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 13914440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 13924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 13934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 13944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 13954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1396b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1397b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1398b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 13994250882ccf8326ba9074c671110370534489caa6Brian Paul 14004250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 14014250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 14024250882ccf8326ba9074c671110370534489caa6Brian Paul } 1403b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1404b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1405b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 140685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul/** 140785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Compute nearest mipmap level from texcoords. 140885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Then sample the texture level for four elements of a quad. 140985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * \param c0 the LOD bias factors, or absolute LODs (depending on control) 141085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 14114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 14134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14164440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14174440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 14184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 14194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1420f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1421287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 14224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 14234bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 14244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14254440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 14264440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 14274440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 14284440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 14294440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 14304bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14314440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 14324440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 14334bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14344bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 14354bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 14364bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 14374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 14394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 14404440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 14434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = (int)(lambda + 0.5) ; 14444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 14454440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 144775276ea316610a5737f2115326482024aa09d02aroot 14484250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 14494250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 14504250882ccf8326ba9074c671110370534489caa6Brian Paul } 14514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 14564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14594440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14604440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 14614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 14624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1463f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 14644bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lambda; 14654bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 14664bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14674440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 14684440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 14694440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 14704440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 14714440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 14724bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14734440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 14744440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 14754bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 14764bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 14774bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 14784bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 14794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 14814440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 14844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 14854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1490e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1491e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Specialized version of mip_filter_linear with hard-wired calls to 14924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1493a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 14944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 14964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 15004440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 15014440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 15024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 150300c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 1504f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1505287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture = samp->texture; 15064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 15084bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 15094bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15104440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 15114440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 15124440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 15134440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 15144440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 151500c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 15164440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 15174440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 15184bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15194bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 15204bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 15214bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 15224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = (int)lambda; 15234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 15254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 15264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 15274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 15284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = 0; 15294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 15304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 15314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15324440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 15334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 15354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float levelBlend = lambda - level0; 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 15394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 15414440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 15424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 15444440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 15454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 15474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 15484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 15494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1550b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul } 1551ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 15524250882ccf8326ba9074c671110370534489caa6Brian Paul 15534250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 15544250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 15554250882ccf8326ba9074c671110370534489caa6Brian Paul } 1556b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 1557b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 1558b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 15594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1560e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1561e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Do shadow/depth comparisons. 15623d8c05f7320151898dd224c1daaf3118e1f7ea34Brian */ 15634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 15644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1565b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float s[QUAD_SIZE], 1566b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float t[QUAD_SIZE], 15673d8c05f7320151898dd224c1daaf3118e1f7ea34Brian const float p[QUAD_SIZE], 15684440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 15694440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1570b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float rgba[NUM_CHANNELS][QUAD_SIZE]) 15713d8c05f7320151898dd224c1daaf3118e1f7ea34Brian{ 1572f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1573aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 15744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 15754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 15763d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 15774440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mip_filter(tgsi_sampler, s, t, p, c0, control, rgba); 15783d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 15794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 15804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 15814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 15824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 15834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 1584efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1585efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* compare four texcoords vs. four texture samples */ 1586efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul switch (sampler->compare_func) { 1587efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LESS: 1588efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] < rgba[0][0]; 1589efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] < rgba[0][1]; 1590efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] < rgba[0][2]; 1591efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] < rgba[0][3]; 1592efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1593efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LEQUAL: 1594efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] <= rgba[0][0]; 1595efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] <= rgba[0][1]; 1596efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] <= rgba[0][2]; 1597efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] <= rgba[0][3]; 1598efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1599efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GREATER: 1600efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] > rgba[0][0]; 1601efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] > rgba[0][1]; 1602efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] > rgba[0][2]; 1603efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] > rgba[0][3]; 1604efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1605efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GEQUAL: 1606efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] >= rgba[0][0]; 1607efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] >= rgba[0][1]; 1608efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] >= rgba[0][2]; 1609efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] >= rgba[0][3]; 1610efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1611efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_EQUAL: 1612efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] == rgba[0][0]; 1613efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] == rgba[0][1]; 1614efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] == rgba[0][2]; 1615efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] == rgba[0][3]; 1616efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1617efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NOTEQUAL: 1618efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = p[0] != rgba[0][0]; 1619efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k1 = p[1] != rgba[0][1]; 1620efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k2 = p[2] != rgba[0][2]; 1621efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k3 = p[3] != rgba[0][3]; 1622efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1623efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_ALWAYS: 1624efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 1; 1625efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1626efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NEVER: 1627efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1628efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1629efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul default: 1630efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1631efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul assert(0); 1632efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1633efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1634efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1635efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* convert four pass/fail values to an intensity in [0,1] */ 1636efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul val = 0.25F * (k0 + k1 + k2 + k3); 1637efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1638efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 1639efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul for (j = 0; j < 4; j++) { 1640efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 1641efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[3][j] = 1.0F; 1642efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1643efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul} 1644efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1645e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1646e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 164785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use 3D texcoords to choose a cube face, then sample the 2D cube faces. 164885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Put face info into the sampler faces[] array. 16490dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 1650e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 16514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 16524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 16534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 16544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 16554440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 16564440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 16574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 16580dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 1659f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 16604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 16614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 166209a1b912605ff48c8782dcc5aae55ac77e27037bBrian 16634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 16644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 166585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul direction target sc tc ma 166685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul ---------- ------------------------------- --- --- --- 16674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 16684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 16694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 16704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 16714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 16724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 16734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 167485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 16759ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul /* Choose the cube face and compute new s/t coords for the 2D face. 16769ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul * 167785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use the same cube face for all four pixels in the quad. 167885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * 167985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * This isn't ideal, but if we want to use a different cube face 168085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per pixel in the quad, we'd have to also compute the per-face 168185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * LOD here too. That's because the four post-face-selection 168285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * texcoords are no longer related to each other (they're 168385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per-face!) so we can't use subtraction to compute the partial 168485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * deriviates to compute the LOD. Doing so (near cube edges 168585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * anyway) gives us pretty much random values. 168685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 168785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul { 168885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul /* use the average of the four pixel's texcoords to choose the face */ 168985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]); 169085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]); 169185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]); 16924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 16934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1694890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell if (arx >= ary && arx >= arz) { 1695c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rx >= 0.0F) ? 1.0F : -1.0F; 1696c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rx >= 0.0F) ? PIPE_TEX_FACE_POS_X : PIPE_TEX_FACE_NEG_X; 1697c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1698c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(s[j]); 1699c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * p[j] * ima + 0.5F; 1700c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1701c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 17024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1704890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell else if (ary >= arx && ary >= arz) { 1705c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (ry >= 0.0F) ? 1.0F : -1.0F; 1706c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (ry >= 0.0F) ? PIPE_TEX_FACE_POS_Y : PIPE_TEX_FACE_NEG_Y; 1707c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1708c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(t[j]); 1709c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = -s[j] * ima + 0.5F; 1710c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = sign * -p[j] * ima + 0.5F; 1711c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 17124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 1715c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rz >= 0.0F) ? 1.0F : -1.0F; 1716c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rz >= 0.0F) ? PIPE_TEX_FACE_POS_Z : PIPE_TEX_FACE_NEG_Z; 1717c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1718c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5 / fabsf(p[j]); 1719c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * -s[j] * ima + 0.5F; 1720c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1721c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 17224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 172485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul } 172585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 17264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 17274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 17284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 17296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 17304440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba); 17314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1732612cfb749c3526eeb446bbc631bf24716522f373Brian 17333d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 1734c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paulstatic void 1735c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paulsample_swizzle(struct tgsi_sampler *tgsi_sampler, 1736c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float s[QUAD_SIZE], 1737c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float t[QUAD_SIZE], 1738c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float p[QUAD_SIZE], 1739c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float c0[QUAD_SIZE], 1740c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul enum tgsi_sampler_control control, 1741c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1742c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul{ 1743f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1744c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul float rgba_temp[NUM_CHANNELS][QUAD_SIZE]; 1745c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_r = samp->key.bits.swizzle_r; 1746c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_g = samp->key.bits.swizzle_g; 1747c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_b = samp->key.bits.swizzle_b; 1748c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_a = samp->key.bits.swizzle_a; 1749c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul unsigned j; 1750c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1751c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target(tgsi_sampler, s, t, p, c0, control, rgba_temp); 1752c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1753c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_r) { 1754c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1755c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1756c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = 0.0f; 1757c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1758c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 1759c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1760c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = 1.0f; 1761c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1762c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 1763c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_r < 4); 1764c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1765c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = rgba_temp[swizzle_r][j]; 1766c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 1767c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1768c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_g) { 1769c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1770c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1771c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = 0.0f; 1772c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1773c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 1774c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1775c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = 1.0f; 1776c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1777c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 1778c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_g < 4); 1779c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1780c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = rgba_temp[swizzle_g][j]; 1781c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 1782c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1783c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_b) { 1784c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1785c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1786c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = 0.0f; 1787c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1788c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 1789c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1790c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = 1.0f; 1791c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1792c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 1793c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_b < 4); 1794c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1795c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = rgba_temp[swizzle_b][j]; 1796c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 1797c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1798c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_a) { 1799c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1800c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1801c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = 0.0f; 1802c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1803c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 1804c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1805c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = 1.0f; 1806c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1807c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 1808c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_a < 4); 1809c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1810c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = rgba_temp[swizzle_a][j]; 1811c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 1812c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul} 1813c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 18143d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 1815e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1816e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_unorm_wrap(unsigned mode) 18174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 18184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 18194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 18204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 18214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 1822b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_nearest_unorm_clamp_to_edge; 18234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 18244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 18250dc4eea64f56cc93e5359372b08b99a2d600273cBrian default: 18260dc4eea64f56cc93e5359372b08b99a2d600273cBrian assert(0); 18274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 18280dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 18290dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 183034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 183134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1832e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 1833e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_wrap(unsigned mode) 1834a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 18354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 18364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 18374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 18384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 18394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 18404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 18414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 18424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 18434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 18444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 18454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 18464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 18474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 18484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 18494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 18504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 18514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 18524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 18534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 18544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 18554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1856a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 1857a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 1858e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1859e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1860e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_unorm_wrap(unsigned mode) 1861a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 18624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 18634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 18644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 18654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 1866b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_linear_unorm_clamp_to_edge; 18674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 18684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 18694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 18704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 18714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 18724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1873a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 1874a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 1875e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1876e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 1877e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_wrap(unsigned mode) 187834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 18794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 18804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 18814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 18824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 18834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 18844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 18854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 18864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 18874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 18884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 18894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 18904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 18914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 18924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 18934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 18944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 18954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 18963d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian default: 18973d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(0); 18984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 18993d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 190034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 190134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1902e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1903e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic compute_lambda_func 1904e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_lambda_func(const union sp_sampler_key key) 190534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 19064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 19074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 19084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 19094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 19104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 19114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 19124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 1913ae0ef6f69f351cacdc7eaa9b21097a7c1b414e44Luca Barbieri case PIPE_TEXTURE_RECT: 191487ec83afd58536c31bf02c307f1d5488abc84861Brian Paul case PIPE_TEXTURE_CUBE: 19154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 19164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 19174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 19184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 19194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 19204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 1921b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 192234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 192334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 1924e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1925e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic filter_func 1926e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_img_filter(const union sp_sampler_key key, 1927e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul unsigned filter, 1928e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const struct pipe_sampler_state *sampler) 1929b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 19304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 19314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 19324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 19334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 19344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 19354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 1936b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 19374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 1938ae0ef6f69f351cacdc7eaa9b21097a7c1b414e44Luca Barbieri case PIPE_TEXTURE_RECT: 19394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 19404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 19414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 19424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 19434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 194438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian { 19454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 19464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 19474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 19486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 19494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 19506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 19514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 19526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 19536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 195438bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 19554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 19564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 19574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 19586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 19594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 19606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 19616142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 196238bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 1963b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1964b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 196560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* Otherwise use default versions: 19664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 19674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 19684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 19694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 19704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 19714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 197260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell case PIPE_TEXTURE_CUBE: 197360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 197460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_nearest; 197560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell else 197660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_linear; 197760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell break; 19784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 19794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 19804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 19814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 19824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 1983b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 1984b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian default: 1985b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(0); 19864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 1987b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1988b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1989b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1990b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1991a34b8594b7b2d00404bb639621ec1ce918ba0786Brian/** 1992f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul * Bind the given texture object and texture cache to the sampler variant. 1993a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 19944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 1995f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulsp_sampler_variant_bind_texture( struct sp_sampler_variant *samp, 19967670102468a55de50cf0cfa0b938d36aaf212f1fKeith Whitwell struct softpipe_tex_tile_cache *tex_cache, 1997287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const struct pipe_resource *texture ) 199834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 19994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 20004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->texture = texture; 20024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 2003683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->xpot = util_unsigned_logbase2( texture->width0 ); 2004683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->ypot = util_unsigned_logbase2( texture->height0 ); 20054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); 20064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 20070b9e96fae9493d5d58f046e01c983a3c4267090eBrian 20084f23468bd0d14b8ed687a641003d587b91ad39a7Brian 2009ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellvoid 2010f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulsp_sampler_variant_destroy( struct sp_sampler_variant *samp ) 2011ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell{ 2012ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell FREE(samp); 2013ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell} 2014ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 2015ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 2016e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 2017f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul * Create a sampler variant for a given set of non-orthogonal state. 20184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 2019f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulstruct sp_sampler_variant * 2020f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulsp_create_sampler_variant( const struct pipe_sampler_state *sampler, 20214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 20224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2023f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = CALLOC_STRUCT(sp_sampler_variant); 20244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 20254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 20264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 20284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 20294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 20314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 20324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 20334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 20344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 20354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 20364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 20374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 20384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 20404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 20414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 20424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 20434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 20444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 20454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 20464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 20474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 20494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 20504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 20514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 20524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 20544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 205641483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 20574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20584fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 20594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 20604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 20614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 2062b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian else 20634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 206434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 20654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 20674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 206834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 20694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 20714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 20724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 20734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 20744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 2075cf102b031e7ef33c8e3ffce2f9dcd064f44e8190Brian Paul sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && 20764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 20774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 20784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 20794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 20804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 20814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 20824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 20836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 208434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 208534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 20863d53d38d5e35386de4793162b9dd32e171927059Brian Paul 20874e014c0a148ba3ac015d0e83dcf975ca6e814e1fMichal Krol if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { 20884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 20893d53d38d5e35386de4793162b9dd32e171927059Brian Paul } 20904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 20914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 20924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 20934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 20944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 20954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 20964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 20974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 2098c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target = sample_cube; 20994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 21004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 21014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 21024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 21034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 21044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 21054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 21064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 21074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 21084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 2109c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target = samp->compare; 2110c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2111c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 2112c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul if (key.bits.swizzle_r != PIPE_SWIZZLE_RED || 2113c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_g != PIPE_SWIZZLE_GREEN || 2114c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_b != PIPE_SWIZZLE_BLUE || 2115c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_a != PIPE_SWIZZLE_ALPHA) { 2116c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->base.get_samples = sample_swizzle; 2117c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2118c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul else { 2119c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->base.get_samples = samp->sample_target; 21206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 21216142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 21224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 212334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 2124