sp_tex_sample.c revision 9acdd7739b729375444f8669fc2419d9eb57acc5
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 542779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul/** 543779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul * Do coordinate to array index conversion. For array textures. 544779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul */ 545779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulstatic INLINE void 546779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulwrap_array_layer(const float coord[4], unsigned size, int layer[4]) 547779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul{ 548779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul uint ch; 549779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (ch = 0; ch < 4; ch++) { 550779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int c = util_ifloor(coord[ch] + 0.5F); 551779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul layer[ch] = CLAMP(c, 0, size - 1); 552779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 553779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul} 554779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 55534a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 556b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian/** 557b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * Examine the quad's texture coordinates to compute the partial 558b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * derivatives w.r.t X and Y, then compute lambda (level of detail). 559b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 560b4480285ed5098f1c862690ee105dd46f5e6cd1eBrianstatic float 561f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_1d(const struct sp_sampler_variant *samp, 5624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5644bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 565b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 56621148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 5674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5699acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float rho = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); 570b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 5714bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 572b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 573b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 574e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 5754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 576f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_2d(const struct sp_sampler_variant *samp, 5774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5794bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 58009a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 58121148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 5824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 5834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 5844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 5854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 5869acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float maxx = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); 5879acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float maxy = MAX2(dtdx, dtdy) * u_minify(texture->height0, samp->view->u.tex.first_level); 5884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rho = MAX2(maxx, maxy); 589c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 5904bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 59109a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 59209a1b912605ff48c8782dcc5aae55ac77e27037bBrian 59308f33a025100dea2d951e6d628891fe294b18082Brian 5944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 595f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_3d(const struct sp_sampler_variant *samp, 5964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 5974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 5984bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 59909a1b912605ff48c8782dcc5aae55ac77e27037bBrian{ 60021148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 6014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); 6024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); 6034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); 6044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); 6054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); 6064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); 6079acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float maxx = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); 6089acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float maxy = MAX2(dtdx, dtdy) * u_minify(texture->height0, samp->view->u.tex.first_level); 6099acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float maxz = MAX2(dpdx, dpdy) * u_minify(texture->depth0, samp->view->u.tex.first_level); 6104bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float rho; 61100c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 6124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(maxx, maxy); 6134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rho = MAX2(rho, maxz); 614c7722edcfdf36e0d0bfdc51013ecb199fc7fa9f6Brian 6154bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return util_fast_log2(rho); 61609a1b912605ff48c8782dcc5aae55ac77e27037bBrian} 61709a1b912605ff48c8782dcc5aae55ac77e27037bBrian 61808f33a025100dea2d951e6d628891fe294b18082Brian 619e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 620e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Compute lambda for a vertex texture sampler. 6214bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Since there aren't derivatives to use, just return 0. 622e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul */ 6234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic float 624f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulcompute_lambda_vert(const struct sp_sampler_variant *samp, 6254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 6264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 6274bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float p[QUAD_SIZE]) 6284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 6294bfe1c955fe679547c8a03119d1681e33593c768Michal Krol return 0.0f; 6304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 6314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 6344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell/** 6354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Get a texel from a texture, using the texture tile cache. 6364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 63781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell * \param addr the template tex address containing cube, z, face info. 6384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * \param x the x coord of texel within 2D image 639b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param y the y coord of texel within 2D image 640b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian * \param rgba the quad to put the texel/color into 64170eb7996f265f3634dabda078f13d1be3533cc65Brian * 64280c78472ad43f4288c9ef5076074ba9d31a39885Keith Whitwell * XXX maybe move this into sp_tex_tile_cache.c and merge with the 64370eb7996f265f3634dabda078f13d1be3533cc65Brian * sp_get_cached_tile_tex() function. Also, get 4 texels instead of 1... 644b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian */ 64581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 64981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 650f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_2d_no_border(const struct sp_sampler_variant *samp, 65181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 652b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 65381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 65481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 65581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 65681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 65781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell y %= TILE_SIZE; 65881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell x %= TILE_SIZE; 65981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 66181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return &tile->data.color[y][x][0]; 66381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 66481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 66681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 667f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_2d(const struct sp_sampler_variant *samp, 66881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, int x, int y) 66981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 67021148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 67181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 67281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 673683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 674683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level)) { 67542a0967a36ff3331de96289125243e6afeb5d560Brian Paul return samp->sampler->border_color; 67681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 67781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell else { 67881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_2d_no_border( samp, addr, x, y ); 67981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 68081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 6816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 6826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 68381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of adjacent texels within a tile: 68481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 68581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 686f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d_no_border_single_tile(const struct sp_sampler_variant *samp, 68781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 68881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned x, unsigned y, 68981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 69081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 69181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const struct softpipe_tex_cached_tile *tile; 69281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.x = x / TILE_SIZE; 69481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.y = y / TILE_SIZE; 6956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 6966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 69781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 69881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 6996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7006142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[0] = &tile->data.color[y ][x ][0]; 7016142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[1] = &tile->data.color[y ][x+1][0]; 7026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[2] = &tile->data.color[y+1][x ][0]; 7036142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell out[3] = &tile->data.color[y+1][x+1][0]; 7046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7056142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 70681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 70781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Gather a quad of potentially non-adjacent texels: 70881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 70981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 710f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d_no_border(const struct sp_sampler_variant *samp, 71181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 71281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 71381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 71481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 71581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 71681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d_no_border( samp, addr, x0, y0 ); 71781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d_no_border( samp, addr, x1, y0 ); 71881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d_no_border( samp, addr, x0, y1 ); 71981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d_no_border( samp, addr, x1, y1 ); 72081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 72181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 72281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Can involve a lot of unnecessary checks for border color: 72381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 72481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE void 725f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_quad_2d(const struct sp_sampler_variant *samp, 72681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr, 72781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x0, int y0, 72881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int x1, int y1, 72981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out[4]) 73081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 73181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[0] = get_texel_2d( samp, addr, x0, y0 ); 73281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[1] = get_texel_2d( samp, addr, x1, y0 ); 73381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[3] = get_texel_2d( samp, addr, x1, y1 ); 73481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out[2] = get_texel_2d( samp, addr, x0, y1 ); 73581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 73681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 73781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 73881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 739f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul/* 3d variants: 74081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 7416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic INLINE const float * 742f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_3d_no_border(const struct sp_sampler_variant *samp, 743e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 7446142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 745153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const struct softpipe_tex_cached_tile *tile; 7466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 747153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.x = x / TILE_SIZE; 748153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.y = y / TILE_SIZE; 74981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.z = z; 7506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y %= TILE_SIZE; 7516142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x %= TILE_SIZE; 7526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 753153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell tile = sp_get_cached_tile_tex(samp->cache, addr); 754153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 7556142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell return &tile->data.color[y][x][0]; 7566142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 7576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 7586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 75981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwellstatic INLINE const float * 760f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulget_texel_3d(const struct sp_sampler_variant *samp, 761e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul union tex_tile_address addr, int x, int y, int z) 762b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian{ 76321148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 76481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell unsigned level = addr.bits.level; 7650b9e96fae9493d5d58f046e01c983a3c4267090eBrian 766683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell if (x < 0 || x >= (int) u_minify(texture->width0, level) || 767683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell y < 0 || y >= (int) u_minify(texture->height0, level) || 768683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell z < 0 || z >= (int) u_minify(texture->depth0, level)) { 76942a0967a36ff3331de96289125243e6afeb5d560Brian Paul return samp->sampler->border_color; 770ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 771ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul else { 77281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return get_texel_3d_no_border( samp, addr, x, y, z ); 773ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 774b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 775b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 776b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 77780777743b7b6238f034b8cb81d8d907d74929334Brian Paul/* Get texel pointer for 1D array texture */ 77880777743b7b6238f034b8cb81d8d907d74929334Brian Paulstatic INLINE const float * 77980777743b7b6238f034b8cb81d8d907d74929334Brian Paulget_texel_1d_array(const struct sp_sampler_variant *samp, 78080777743b7b6238f034b8cb81d8d907d74929334Brian Paul union tex_tile_address addr, int x, int y) 78180777743b7b6238f034b8cb81d8d907d74929334Brian Paul{ 78280777743b7b6238f034b8cb81d8d907d74929334Brian Paul const struct pipe_resource *texture = samp->view->texture; 78380777743b7b6238f034b8cb81d8d907d74929334Brian Paul unsigned level = addr.bits.level; 78480777743b7b6238f034b8cb81d8d907d74929334Brian Paul 78580777743b7b6238f034b8cb81d8d907d74929334Brian Paul if (x < 0 || x >= (int) u_minify(texture->width0, level)) { 78680777743b7b6238f034b8cb81d8d907d74929334Brian Paul return samp->sampler->border_color; 78780777743b7b6238f034b8cb81d8d907d74929334Brian Paul } 78880777743b7b6238f034b8cb81d8d907d74929334Brian Paul else { 78980777743b7b6238f034b8cb81d8d907d74929334Brian Paul return get_texel_2d_no_border(samp, addr, x, y); 79080777743b7b6238f034b8cb81d8d907d74929334Brian Paul } 79180777743b7b6238f034b8cb81d8d907d74929334Brian Paul} 79280777743b7b6238f034b8cb81d8d907d74929334Brian Paul 79380777743b7b6238f034b8cb81d8d907d74929334Brian Paul 79480777743b7b6238f034b8cb81d8d907d74929334Brian Paul/* Get texel pointer for 2D array texture */ 79580777743b7b6238f034b8cb81d8d907d74929334Brian Paulstatic INLINE const float * 79680777743b7b6238f034b8cb81d8d907d74929334Brian Paulget_texel_2d_array(const struct sp_sampler_variant *samp, 79780777743b7b6238f034b8cb81d8d907d74929334Brian Paul union tex_tile_address addr, int x, int y, int layer) 79880777743b7b6238f034b8cb81d8d907d74929334Brian Paul{ 79980777743b7b6238f034b8cb81d8d907d74929334Brian Paul const struct pipe_resource *texture = samp->view->texture; 80080777743b7b6238f034b8cb81d8d907d74929334Brian Paul unsigned level = addr.bits.level; 80180777743b7b6238f034b8cb81d8d907d74929334Brian Paul 80280777743b7b6238f034b8cb81d8d907d74929334Brian Paul assert(layer < texture->array_size); 80380777743b7b6238f034b8cb81d8d907d74929334Brian Paul 80480777743b7b6238f034b8cb81d8d907d74929334Brian Paul if (x < 0 || x >= (int) u_minify(texture->width0, level) || 80580777743b7b6238f034b8cb81d8d907d74929334Brian Paul y < 0 || y >= (int) u_minify(texture->height0, level)) { 80680777743b7b6238f034b8cb81d8d907d74929334Brian Paul return samp->sampler->border_color; 80780777743b7b6238f034b8cb81d8d907d74929334Brian Paul } 80880777743b7b6238f034b8cb81d8d907d74929334Brian Paul else { 80980777743b7b6238f034b8cb81d8d907d74929334Brian Paul return get_texel_3d_no_border(samp, addr, x, y, layer); 81080777743b7b6238f034b8cb81d8d907d74929334Brian Paul } 81180777743b7b6238f034b8cb81d8d907d74929334Brian Paul} 81280777743b7b6238f034b8cb81d8d907d74929334Brian Paul 81380777743b7b6238f034b8cb81d8d907d74929334Brian Paul 81475276ea316610a5737f2115326482024aa09d02aroot/** 81575276ea316610a5737f2115326482024aa09d02aroot * Given the logbase2 of a mipmap's base level size and a mipmap level, 81675276ea316610a5737f2115326482024aa09d02aroot * return the size (in texels) of that mipmap level. 81775276ea316610a5737f2115326482024aa09d02aroot * For example, if level[0].width = 256 then base_pot will be 8. 81875276ea316610a5737f2115326482024aa09d02aroot * If level = 2, then we'll return 64 (the width at level=2). 81975276ea316610a5737f2115326482024aa09d02aroot * Return 1 if level > base_pot. 82075276ea316610a5737f2115326482024aa09d02aroot */ 82175276ea316610a5737f2115326482024aa09d02arootstatic INLINE unsigned 82275276ea316610a5737f2115326482024aa09d02arootpot_level_size(unsigned base_pot, unsigned level) 82375276ea316610a5737f2115326482024aa09d02aroot{ 82475276ea316610a5737f2115326482024aa09d02aroot return (base_pot >= level) ? (1 << (base_pot - level)) : 1; 82575276ea316610a5737f2115326482024aa09d02aroot} 82675276ea316610a5737f2115326482024aa09d02aroot 82775276ea316610a5737f2115326482024aa09d02aroot 8284250882ccf8326ba9074c671110370534489caa6Brian Paulstatic void 8294250882ccf8326ba9074c671110370534489caa6Brian Paulprint_sample(const char *function, float rgba[NUM_CHANNELS][QUAD_SIZE]) 8304250882ccf8326ba9074c671110370534489caa6Brian Paul{ 8314250882ccf8326ba9074c671110370534489caa6Brian Paul debug_printf("%s %g %g %g %g, %g %g %g %g, %g %g %g %g, %g %g %g %g\n", 8324250882ccf8326ba9074c671110370534489caa6Brian Paul function, 8334250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][0], rgba[1][0], rgba[2][0], rgba[3][0], 8344250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][1], rgba[1][1], rgba[2][1], rgba[3][1], 8354250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][2], rgba[1][2], rgba[2][2], rgba[3][2], 8364250882ccf8326ba9074c671110370534489caa6Brian Paul rgba[0][3], rgba[1][3], rgba[2][3], rgba[3][3]); 8374250882ccf8326ba9074c671110370534489caa6Brian Paul} 8384250882ccf8326ba9074c671110370534489caa6Brian Paul 8394250882ccf8326ba9074c671110370534489caa6Brian Paul 84081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell/* Some image-filter fastpaths: 84181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell */ 842efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paulstatic INLINE void 8434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_linear_repeat_POT(struct tgsi_sampler *tgsi_sampler, 844e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 845e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 846e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 8474440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 8484440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 849e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 8506142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 851f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 8526142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 8536142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 85475276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 85575276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 8561fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned xmax = (xpot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, xpot) - 1; */ 8571fd40e506c2207664f0c3f435e4614472ea4c540Keith Whitwell unsigned ymax = (ypot - 1) & (TILE_SIZE - 1); /* MIN2(TILE_SIZE, ypot) - 1; */ 858153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 859153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 860153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 861153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 862153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 8636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 8646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 8656142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8666142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float u = s[j] * xpot - 0.5F; 8676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float v = t[j] * ypot - 0.5F; 8686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 8706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 8716142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8726142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float xw = u - (float)uflr; 8736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell float yw = v - (float)vflr; 8746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 8766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 8776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 878153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell const float *tx[4]; 8796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* Can we fetch all four at once: 8816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 882e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul if (x0 < xmax && y0 < ymax) { 88381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border_single_tile(samp, addr, x0, y0, tx); 8846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 885e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul else { 8864f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned x1 = (x0 + 1) & (xpot - 1); 8874f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell unsigned y1 = (y0 + 1) & (ypot - 1); 88881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell get_texel_quad_2d_no_border(samp, addr, x0, y0, x1, y1, tx); 8896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 8916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell /* interpolate R, G, B, A */ 8926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 8936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = lerp_2d(xw, yw, 8946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[0][c], tx[1][c], 8956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell tx[2][c], tx[3][c]); 8966142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 8984250882ccf8326ba9074c671110370534489caa6Brian Paul 8994250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 9004250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 9014250882ccf8326ba9074c671110370534489caa6Brian Paul } 9026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9036142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9046142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 9064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_repeat_POT(struct tgsi_sampler *tgsi_sampler, 9074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9104440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9114440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 9124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9136142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 914f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 9156142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 9166142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 91775276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 91875276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 919153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 920153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 921153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 922153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 9236142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9246142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 9256142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 9266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9275fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 9285fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 9296142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9306142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int uflr = util_ifloor(u); 9316142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int vflr = util_ifloor(v); 9326142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9336142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0 = uflr & (xpot - 1); 9346142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int y0 = vflr & (ypot - 1); 9356142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 93681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d_no_border(samp, addr, x0, y0); 9376142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9386142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 9396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 9406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9416142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9424250882ccf8326ba9074c671110370534489caa6Brian Paul 9434250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 9444250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 9454250882ccf8326ba9074c671110370534489caa6Brian Paul } 9466142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 9476142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9486142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic INLINE void 9504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_2d_nearest_clamp_POT(struct tgsi_sampler *tgsi_sampler, 9514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 9524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 9534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 9544440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 9554440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 9564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 9576142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 958f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 9596142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned j; 9606142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell unsigned level = samp->level; 96175276ea316610a5737f2115326482024aa09d02aroot unsigned xpot = pot_level_size(samp->xpot, level); 96275276ea316610a5737f2115326482024aa09d02aroot unsigned ypot = pot_level_size(samp->ypot, level); 963153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell union tex_tile_address addr; 964153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell 965153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.value = 0; 966153e474d22d1b440bb6bd7b04dabf244d7455582Keith Whitwell addr.bits.level = samp->level; 9676142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9686142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 9696142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int c; 9706142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9715fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float u = s[j] * xpot; 9725fdac2dcea09c654725666b3cab5f59dfc9e31a5Keith Whitwell float v = t[j] * ypot; 9736142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9746142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell int x0, y0; 9756142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell const float *out; 9766142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9776142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = util_ifloor(u); 9786142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (x0 < 0) 9796142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = 0; 9806142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (x0 > xpot - 1) 9816142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell x0 = xpot - 1; 9826142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9836142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = util_ifloor(v); 9846142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell if (y0 < 0) 9856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = 0; 9866142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell else if (y0 > ypot - 1) 9876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell y0 = ypot - 1; 9886142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 98981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell out = get_texel_2d_no_border(samp, addr, x0, y0); 9906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 9916142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell for (c = 0; c < 4; c++) { 9926142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell rgba[c][j] = out[c]; 9936142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9946142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 9954250882ccf8326ba9074c671110370534489caa6Brian Paul 9964250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 9974250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 9984250882ccf8326ba9074c671110370534489caa6Brian Paul } 9996142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 10006142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 1001e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 10026142de393fe34ff0866f8489f1292eb473276f11Keith Whitwellstatic void 10034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_nearest(struct tgsi_sampler *tgsi_sampler, 10044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 10054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 10064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 10074440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10084440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 10094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 10106142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell{ 1011f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 101221148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 10134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 10144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 10154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4]; 101681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 10176142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 10184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1019683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 10206142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 10214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 10224f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 102381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 102481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 102581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 10264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 10274f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell 10284fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 102981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, addr, x[j], 0); 103081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 103181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 103281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 103381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 10344f409da3456070946eda2d8ff5153b3b4306bb46Keith Whitwell } 10354250882ccf8326ba9074c671110370534489caa6Brian Paul 10364250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 10374250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 10384250882ccf8326ba9074c671110370534489caa6Brian Paul } 10396142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell} 10406142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 10414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 104260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 1043779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulimg_filter_1d_array_nearest(struct tgsi_sampler *tgsi_sampler, 1044779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float s[QUAD_SIZE], 1045779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float t[QUAD_SIZE], 1046779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float p[QUAD_SIZE], 1047779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float c0[QUAD_SIZE], 1048779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul enum tgsi_sampler_control control, 1049779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1050779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul{ 1051779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1052779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct pipe_resource *texture = samp->view->texture; 1053779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul unsigned level0, j; 1054779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int width; 1055779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int x[4], layer[4]; 1056779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul union tex_tile_address addr; 1057779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1058779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul level0 = samp->level; 1059779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul width = u_minify(texture->width0, level0); 1060779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1061779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(width > 0); 1062779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1063779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.value = 0; 1064779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.bits.level = samp->level; 1065779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1066779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->nearest_texcoord_s(s, width, x); 106780777743b7b6238f034b8cb81d8d907d74929334Brian Paul wrap_array_layer(t, texture->array_size, layer); 1068779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1069779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 107080777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *out = get_texel_1d_array(samp, addr, x[j], layer[j]); 1071779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int c; 1072779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (c = 0; c < 4; c++) { 1073779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul rgba[c][j] = out[c]; 1074779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1075779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1076779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1077779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul if (DEBUG_TEX) { 1078779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul print_sample(__FUNCTION__, rgba); 1079779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1080779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul} 1081779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1082779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1083779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulstatic void 108460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_nearest(struct tgsi_sampler *tgsi_sampler, 108560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 108660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 108760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 10884440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 10894440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 109060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 109160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 1092f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 109321148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 109460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 109560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 109660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x[4], y[4]; 109760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 109881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 109981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 110060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 1101683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1102683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 110360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 11055dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 110660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 110760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 110860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 110960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 111060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_s(s, width, x); 111160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->nearest_texcoord_t(t, height, y); 111260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 111360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 111460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *out = get_texel_2d(samp, addr, x[j], y[j]); 111560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 111660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 111760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = out[c]; 111860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 111960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 11204250882ccf8326ba9074c671110370534489caa6Brian Paul 11214250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 11224250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 11234250882ccf8326ba9074c671110370534489caa6Brian Paul } 112460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 112560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 1126e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1127779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulstatic void 1128779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulimg_filter_2d_array_nearest(struct tgsi_sampler *tgsi_sampler, 1129779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float s[QUAD_SIZE], 1130779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float t[QUAD_SIZE], 1131779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float p[QUAD_SIZE], 1132779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float c0[QUAD_SIZE], 1133779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul enum tgsi_sampler_control control, 1134779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1135779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul{ 1136779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1137779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct pipe_resource *texture = samp->view->texture; 1138779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul unsigned level0, j; 1139779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int width, height; 1140779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int x[4], y[4], layer[4]; 1141779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul union tex_tile_address addr; 1142779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1143779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul level0 = samp->level; 1144779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul width = u_minify(texture->width0, level0); 1145779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul height = u_minify(texture->height0, level0); 1146779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1147779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(width > 0); 1148779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(height > 0); 1149779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1150779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.value = 0; 1151779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.bits.level = samp->level; 1152779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1153779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->nearest_texcoord_s(s, width, x); 1154779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->nearest_texcoord_t(t, height, y); 115580777743b7b6238f034b8cb81d8d907d74929334Brian Paul wrap_array_layer(p, texture->array_size, layer); 1156779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1157779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 115880777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *out = get_texel_2d_array(samp, addr, x[j], y[j], layer[j]); 1159779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int c; 1160779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (c = 0; c < 4; c++) { 1161779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul rgba[c][j] = out[c]; 1162779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1163779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1164779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1165779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul if (DEBUG_TEX) { 1166779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul print_sample(__FUNCTION__, rgba); 1167779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1168779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul} 1169779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1170779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 11719659aa6482291d1530c74450612bcd952f542e01José Fonsecastatic INLINE union tex_tile_address 1172e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulface(union tex_tile_address addr, unsigned face ) 117381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell{ 117481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.face = face; 117581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell return addr; 117681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell} 117781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1178e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1179e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 118060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_nearest(struct tgsi_sampler *tgsi_sampler, 1181e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1182e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1183e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 11844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 11854440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1186e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 11870dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 1188f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 118921148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 11904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 11914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1192f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian int width, height; 11934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4]; 119481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 119581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 11964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1197683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1198683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 119909a1b912605ff48c8782dcc5aae55ac77e27037bBrian 1200b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian assert(width > 0); 12015dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 120281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 120381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 120481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 1205612cfb749c3526eeb446bbc631bf24716522f373Brian 12064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 12074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 1208f9e331a574cc4eba60e0de5a29a4aed4bb40520cBrian 12094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 121081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_2d(samp, face(addr, faces[j]), x[j], y[j]); 121181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 121281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 121381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 121481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 12150dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 12164250882ccf8326ba9074c671110370534489caa6Brian Paul 12174250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 12184250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 12194250882ccf8326ba9074c671110370534489caa6Brian Paul } 12200dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 122134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 122234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 12234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 12244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_nearest(struct tgsi_sampler *tgsi_sampler, 12254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12264fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12284440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 12294440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 12304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 123134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 1232f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 123321148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 12344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 12353d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian int width, height, depth; 12364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x[4], y[4], z[4]; 123781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1238b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 12394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1240683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1241683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1242683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 12433d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 12443d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(width > 0); 12453d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(height > 0); 12463d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(depth > 0); 12473d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 12484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s(s, width, x); 12494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t(t, height, y); 12504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p(p, depth, z); 12513d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian 125281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 125381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 125481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 125681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *out = get_texel_3d(samp, addr, x[j], y[j], z[j]); 125781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell int c; 125881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell for (c = 0; c < 4; c++) { 125981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = out[c]; 126081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell } 12613d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 126234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 126334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 126434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 126534a48abd5ff82ce9748fc29191e35a0985d47c5fBrianstatic void 12664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_1d_linear(struct tgsi_sampler *tgsi_sampler, 12674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 12684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 12694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 12704440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 12714440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 12724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 127334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 1274f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 127521148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 12764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 12774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width; 12784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4]; 12794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4]; /* weights */ 128081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 12814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1283683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 12844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 12864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 128781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 128881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 128981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 12904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 12914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1292b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian for (j = 0; j < QUAD_SIZE; j++) { 129381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], 0); 129481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], 0); 12954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 12964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 12974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 12984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 129981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 13004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1301b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 130234a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 130334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 130481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 130560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellstatic void 1306779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulimg_filter_1d_array_linear(struct tgsi_sampler *tgsi_sampler, 1307779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float s[QUAD_SIZE], 1308779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float t[QUAD_SIZE], 1309779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float p[QUAD_SIZE], 1310779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float c0[QUAD_SIZE], 1311779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul enum tgsi_sampler_control control, 1312779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1313779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul{ 1314779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1315779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct pipe_resource *texture = samp->view->texture; 1316779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul unsigned level0, j; 1317779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int width; 1318779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int x0[4], x1[4], layer[4]; 1319779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float xw[4]; /* weights */ 1320779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul union tex_tile_address addr; 1321779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1322779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul level0 = samp->level; 1323779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul width = u_minify(texture->width0, level0); 1324779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1325779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(width > 0); 1326779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1327779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.value = 0; 1328779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.bits.level = samp->level; 1329779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1330779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->linear_texcoord_s(s, width, x0, x1, xw); 133180777743b7b6238f034b8cb81d8d907d74929334Brian Paul wrap_array_layer(t, texture->array_size, layer); 1332779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1333779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 133480777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx0 = get_texel_1d_array(samp, addr, x0[j], layer[j]); 133580777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx1 = get_texel_1d_array(samp, addr, x1[j], layer[j]); 1336779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int c; 1337779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1338779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul /* interpolate R, G, B, A */ 1339779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (c = 0; c < 4; c++) { 1340779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul rgba[c][j] = lerp(xw[j], tx0[c], tx1[c]); 1341779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1342779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1343779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul} 1344779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1345779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1346779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulstatic void 134760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_2d_linear(struct tgsi_sampler *tgsi_sampler, 134860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float s[QUAD_SIZE], 134960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float t[QUAD_SIZE], 135060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float p[QUAD_SIZE], 13514440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 13524440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 135360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 135460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell{ 1355f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 135621148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 135760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell unsigned level0, j; 135860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int width, height; 135960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 136060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell float xw[4], yw[4]; /* weights */ 136160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell union tex_tile_address addr; 136260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 136360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell level0 = samp->level; 1364683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1365683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 136660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 136760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell assert(width > 0); 13685dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 136960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 137060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.value = 0; 137160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell addr.bits.level = samp->level; 137260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 137360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 137460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell samp->linear_texcoord_t(t, height, y0, y1, yw); 137560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 137660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 137760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx0 = get_texel_2d(samp, addr, x0[j], y0[j]); 137860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx1 = get_texel_2d(samp, addr, x1[j], y0[j]); 137960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx2 = get_texel_2d(samp, addr, x0[j], y1[j]); 138060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell const float *tx3 = get_texel_2d(samp, addr, x1[j], y1[j]); 138160adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell int c; 138260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell 138360adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* interpolate R, G, B, A */ 138460adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell for (c = 0; c < 4; c++) { 138560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 138660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx0[c], tx1[c], 138760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell tx2[c], tx3[c]); 138860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 138960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell } 139060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell} 139181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 139281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 1393b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrianstatic void 1394779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulimg_filter_2d_array_linear(struct tgsi_sampler *tgsi_sampler, 1395779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float s[QUAD_SIZE], 1396779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float t[QUAD_SIZE], 1397779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float p[QUAD_SIZE], 1398779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const float c0[QUAD_SIZE], 1399779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul enum tgsi_sampler_control control, 1400779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1401779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul{ 1402779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1403779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul const struct pipe_resource *texture = samp->view->texture; 1404779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul unsigned level0, j; 1405779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int width, height; 1406779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int x0[4], y0[4], x1[4], y1[4], layer[4]; 1407779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul float xw[4], yw[4]; /* weights */ 1408779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul union tex_tile_address addr; 1409779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1410779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul level0 = samp->level; 1411779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul width = u_minify(texture->width0, level0); 1412779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul height = u_minify(texture->height0, level0); 1413779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1414779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(width > 0); 1415779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul assert(height > 0); 1416779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1417779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.value = 0; 1418779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul addr.bits.level = samp->level; 1419779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1420779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->linear_texcoord_s(s, width, x0, x1, xw); 1421779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 142280777743b7b6238f034b8cb81d8d907d74929334Brian Paul wrap_array_layer(p, texture->array_size, layer); 1423779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1424779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 142580777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx0 = get_texel_2d_array(samp, addr, x0[j], y0[j], layer[j]); 142680777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx1 = get_texel_2d_array(samp, addr, x1[j], y0[j], layer[j]); 142780777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx2 = get_texel_2d_array(samp, addr, x0[j], y1[j], layer[j]); 142880777743b7b6238f034b8cb81d8d907d74929334Brian Paul const float *tx3 = get_texel_2d_array(samp, addr, x1[j], y1[j], layer[j]); 1429779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul int c; 1430779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1431779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul /* interpolate R, G, B, A */ 1432779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul for (c = 0; c < 4; c++) { 1433779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul rgba[c][j] = lerp_2d(xw[j], yw[j], 1434779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul tx0[c], tx1[c], 1435779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul tx2[c], tx3[c]); 1436779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1437779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul } 1438779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul} 1439779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1440779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul 1441779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paulstatic void 144260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwellimg_filter_cube_linear(struct tgsi_sampler *tgsi_sampler, 1443e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1444e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1445e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 14464440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14474440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1448e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1449b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 1450f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 145121148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 14524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const unsigned *faces = samp->faces; /* zero when not cube-mapping */ 14534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 1454b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian int width, height; 14554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], y0[4], x1[4], y1[4]; 14564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4]; /* weights */ 145781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 1458b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 14594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1460683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1461683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1462b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1463b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(width > 0); 14645dbedf3d7e99efe35fad308d382670e44cd60e25Brian Paul assert(height > 0); 1465b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 146681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 146781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = samp->level; 146881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 14694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 14704e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 14714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 147381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addrj = face(addr, faces[j]); 147481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx0 = get_texel_2d(samp, addrj, x0[j], y0[j]); 147581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx1 = get_texel_2d(samp, addrj, x1[j], y0[j]); 147681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx2 = get_texel_2d(samp, addrj, x0[j], y1[j]); 147781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx3 = get_texel_2d(samp, addrj, x1[j], y1[j]); 14784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 14794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 14814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 14824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_2d(xw[j], yw[j], 148381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx0[c], tx1[c], 148481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx2[c], tx3[c]); 1485b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 14864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 14874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 14884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 14904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 14914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellimg_filter_3d_linear(struct tgsi_sampler *tgsi_sampler, 14924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 14934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 14944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 14954440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 14964440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 14974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 14984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1499f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul const struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 150021148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 15014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned level0, j; 15024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int width, height, depth; 15034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int x0[4], x1[4], y0[4], y1[4], z0[4], z1[4]; 15044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float xw[4], yw[4], zw[4]; /* interpolation weights */ 150581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell union tex_tile_address addr; 15064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell level0 = samp->level; 1508683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell width = u_minify(texture->width0, level0); 1509683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell height = u_minify(texture->height0, level0); 1510683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell depth = u_minify(texture->depth0, level0); 15114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 151281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.value = 0; 151381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell addr.bits.level = level0; 151481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 15154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(width > 0); 15164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(height > 0); 15174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(depth > 0); 15184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s(s, width, x0, x1, xw); 15204e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_t(t, height, y0, y1, yw); 15214e5c385d2183e7006c9d7ac0823919156bd4b8e6Brian Paul samp->linear_texcoord_p(p, depth, z0, z1, zw); 15224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 15244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c; 15254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 152681601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx00 = get_texel_3d(samp, addr, x0[j], y0[j], z0[j]); 152781601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx01 = get_texel_3d(samp, addr, x1[j], y0[j], z0[j]); 152881601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx02 = get_texel_3d(samp, addr, x0[j], y1[j], z0[j]); 152981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx03 = get_texel_3d(samp, addr, x1[j], y1[j], z0[j]); 153081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 153181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx10 = get_texel_3d(samp, addr, x0[j], y0[j], z1[j]); 153281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx11 = get_texel_3d(samp, addr, x1[j], y0[j], z1[j]); 153381601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx12 = get_texel_3d(samp, addr, x0[j], y1[j], z1[j]); 153481601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell const float *tx13 = get_texel_3d(samp, addr, x1[j], y1[j], z1[j]); 153581601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell 15364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* interpolate R, G, B, A */ 15374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 15384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp_3d(xw[j], yw[j], zw[j], 153981601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx00[c], tx01[c], 154081601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx02[c], tx03[c], 154181601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx10[c], tx11[c], 154281601d85ef6b82297b046d5aab1b70e75168c2faKeith Whitwell tx12[c], tx13[c]); 15434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 15464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15484bfe1c955fe679547c8a03119d1681e33593c768Michal Krol/* Calculate level of detail for every fragment. 15494bfe1c955fe679547c8a03119d1681e33593c768Michal Krol * Note that lambda has already been biased by global LOD bias. 15504bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 15514bfe1c955fe679547c8a03119d1681e33593c768Michal Krolstatic INLINE void 15524bfe1c955fe679547c8a03119d1681e33593c768Michal Krolcompute_lod(const struct pipe_sampler_state *sampler, 15534bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float biased_lambda, 15544bfe1c955fe679547c8a03119d1681e33593c768Michal Krol const float lodbias[QUAD_SIZE], 15554bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]) 15564bfe1c955fe679547c8a03119d1681e33593c768Michal Krol{ 15574bfe1c955fe679547c8a03119d1681e33593c768Michal Krol uint i; 15584bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15594bfe1c955fe679547c8a03119d1681e33593c768Michal Krol for (i = 0; i < QUAD_SIZE; i++) { 15604bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = biased_lambda + lodbias[i]; 15614bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lod[i] = CLAMP(lod[i], sampler->min_lod, sampler->max_lod); 15624bfe1c955fe679547c8a03119d1681e33593c768Michal Krol } 15634bfe1c955fe679547c8a03119d1681e33593c768Michal Krol} 15644bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15654bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 15674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear(struct tgsi_sampler *tgsi_sampler, 1568e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float s[QUAD_SIZE], 1569e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float t[QUAD_SIZE], 1570e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const float p[QUAD_SIZE], 15714440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 15724440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1573e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 15744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1575f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 157621148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 15774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 15784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 15794bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 15804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15814440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 15824440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 15834440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 15844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 15854440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 15864bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15874440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 15884440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 15894bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 15904bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 15914bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 15924bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 15939acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet level0 = samp->view->u.tex.first_level + (int)lambda; 15944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 15954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 15969acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = samp->view->u.tex.first_level; 15974440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 15984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 15994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else if (level0 >= texture->last_level) { 16004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 16014440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 16024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 16049acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float levelBlend = frac(lambda); 16054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 16064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 16074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 16084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 16104440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 16114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 16134440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 16144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 16164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 16174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 1618b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1619b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 1620b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 16214250882ccf8326ba9074c671110370534489caa6Brian Paul 16224250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 16234250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 16244250882ccf8326ba9074c671110370534489caa6Brian Paul } 1625b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 1626b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 1627b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 162885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul/** 162985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Compute nearest mipmap level from texcoords. 163085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Then sample the texture level for four elements of a quad. 163185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * \param c0 the LOD bias factors, or absolute LODs (depending on control) 163285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 16334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 16344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_nearest(struct tgsi_sampler *tgsi_sampler, 16354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 16364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 16374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 16384440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 16394440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 16404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 16414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1642f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 164321148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 16444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 16454bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 16464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16474440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 16484440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 16494440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 16504440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 16514440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 16524bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 16534440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 16544440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 16554bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 16564bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 16574bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 16584bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 16594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 16619acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = samp->view->u.tex.first_level; 16624440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 16634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 16644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 16659acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = samp->view->u.tex.first_level + (int)(lambda + 0.5) ; 16664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = MIN2(samp->level, (int)texture->last_level); 16674440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 16684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 166975276ea316610a5737f2115326482024aa09d02aroot 16704250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 16714250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 16724250882ccf8326ba9074c671110370534489caa6Brian Paul } 16734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 16744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 16764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 16774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_none(struct tgsi_sampler *tgsi_sampler, 16784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 16794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 16804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 16814440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 16824440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 16834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 16844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 1685f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 16864bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lambda; 16874bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 16884bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 16894440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 16904440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 16914440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 16924440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 16934440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 16944bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 16954440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 16964440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 16974bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 16984bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 16994bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 17004bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 17014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17029acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = samp->view->u.tex.first_level; 17034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (lambda < 0.0) { 17044440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 17054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 17074440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 17084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 17104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1713e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1714e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Specialized version of mip_filter_linear with hard-wired calls to 17154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * 2d lambda calculation and 2d_linear_repeat_POT img filters. 1716a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 17174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 17184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellmip_filter_linear_2d_linear_repeat_POT( 17194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell struct tgsi_sampler *tgsi_sampler, 17204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 17214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 17224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 17234440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 17244440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 17254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 172600c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell{ 1727f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 172821148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = samp->view->texture; 17294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int level0; 17304fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float lambda; 17314bfe1c955fe679547c8a03119d1681e33593c768Michal Krol float lod[QUAD_SIZE]; 17324bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 17334440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol if (control == tgsi_sampler_lod_bias) { 17344440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol lambda = samp->compute_lambda(samp, s, t, p) + samp->sampler->lod_bias; 17354440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol compute_lod(samp->sampler, lambda, c0, lod); 17364440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } else { 17374440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol assert(control == tgsi_sampler_lod_explicit); 173800c835918259f8d41c3f74eca679a972713b11b2Keith Whitwell 17394440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol memcpy(lod, c0, sizeof(lod)); 17404440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol } 17414bfe1c955fe679547c8a03119d1681e33593c768Michal Krol 17424bfe1c955fe679547c8a03119d1681e33593c768Michal Krol /* XXX: Take into account all lod values. 17434bfe1c955fe679547c8a03119d1681e33593c768Michal Krol */ 17444bfe1c955fe679547c8a03119d1681e33593c768Michal Krol lambda = lod[0]; 17459acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet level0 = samp->view->u.tex.first_level + (int)lambda; 17464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Catches both negative and large values of level0: 17484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 17494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if ((unsigned)level0 >= texture->last_level) { 17504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (level0 < 0) 17519acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = samp->view->u.tex.first_level; 17524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 17534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = texture->last_level; 17544fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17554440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); 17564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 17574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 17589acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet float levelBlend = frac(lambda); 17594fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba0[4][4]; 17604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba1[4][4]; 17614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int c,j; 17624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0; 17644440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba0); 17654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->level = level0+1; 17674440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba1); 17684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 17694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (j = 0; j < QUAD_SIZE; j++) { 17704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell for (c = 0; c < 4; c++) { 17714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell rgba[c][j] = lerp(levelBlend, rgba0[c][j], rgba1[c][j]); 17724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1773b1ff7dac537947d412bf423a73e7eacd76f90d84Brian Paul } 1774ea0007cc4ca077c7e3951c4fda122bd242728d70Brian Paul } 17754250882ccf8326ba9074c671110370534489caa6Brian Paul 17764250882ccf8326ba9074c671110370534489caa6Brian Paul if (DEBUG_TEX) { 17774250882ccf8326ba9074c671110370534489caa6Brian Paul print_sample(__FUNCTION__, rgba); 17784250882ccf8326ba9074c671110370534489caa6Brian Paul } 1779b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian} 1780b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 1781b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian 17824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1783e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 1784e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul * Do shadow/depth comparisons. 17853d8c05f7320151898dd224c1daaf3118e1f7ea34Brian */ 17864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellstatic void 17874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_compare(struct tgsi_sampler *tgsi_sampler, 1788b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float s[QUAD_SIZE], 1789b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian const float t[QUAD_SIZE], 17903d8c05f7320151898dd224c1daaf3118e1f7ea34Brian const float p[QUAD_SIZE], 17914440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 17924440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 1793b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian float rgba[NUM_CHANNELS][QUAD_SIZE]) 17943d8c05f7320151898dd224c1daaf3118e1f7ea34Brian{ 1795f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1796aa5db684382bd8662a83ca09ed000e4a5a1013f9Keith Whitwell const struct pipe_sampler_state *sampler = samp->sampler; 17974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell int j, k0, k1, k2, k3; 17984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float val; 17990eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor float pc0, pc1, pc2, pc3; 18003d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 18014440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->mip_filter(tgsi_sampler, s, t, p, c0, control, rgba); 18023d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 18034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /** 18044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * Compare texcoord 'p' (aka R) against texture value 'rgba[0]' 18054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * When we sampled the depth texture, the depth value was put into all 18064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * RGBA channels. We look at the red channel here. 18074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 1808efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 18090eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor pc0 = CLAMP(p[0], 0.0F, 1.0F); 18100eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor pc1 = CLAMP(p[1], 0.0F, 1.0F); 18110eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor pc2 = CLAMP(p[2], 0.0F, 1.0F); 18120eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor pc3 = CLAMP(p[3], 0.0F, 1.0F); 18130eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor 1814efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* compare four texcoords vs. four texture samples */ 1815efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul switch (sampler->compare_func) { 1816efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LESS: 18170eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 < rgba[0][0]; 18180eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 < rgba[0][1]; 18190eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 < rgba[0][2]; 18200eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 < rgba[0][3]; 1821efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1822efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_LEQUAL: 18230eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 <= rgba[0][0]; 18240eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 <= rgba[0][1]; 18250eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 <= rgba[0][2]; 18260eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 <= rgba[0][3]; 1827efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1828efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GREATER: 18290eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 > rgba[0][0]; 18300eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 > rgba[0][1]; 18310eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 > rgba[0][2]; 18320eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 > rgba[0][3]; 1833efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1834efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_GEQUAL: 18350eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 >= rgba[0][0]; 18360eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 >= rgba[0][1]; 18370eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 >= rgba[0][2]; 18380eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 >= rgba[0][3]; 1839efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1840efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_EQUAL: 18410eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 == rgba[0][0]; 18420eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 == rgba[0][1]; 18430eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 == rgba[0][2]; 18440eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 == rgba[0][3]; 1845efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1846efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NOTEQUAL: 18470eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k0 = pc0 != rgba[0][0]; 18480eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k1 = pc1 != rgba[0][1]; 18490eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k2 = pc2 != rgba[0][2]; 18500eef561a5bb10df343837d58d37d5c0d5b708243Philip Taylor k3 = pc3 != rgba[0][3]; 1851efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1852efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_ALWAYS: 1853efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 1; 1854efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1855efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul case PIPE_FUNC_NEVER: 1856efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1857efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1858efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul default: 1859efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul k0 = k1 = k2 = k3 = 0; 1860efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul assert(0); 1861efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul break; 1862efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1863efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1864efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* convert four pass/fail values to an intensity in [0,1] */ 1865efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul val = 0.25F * (k0 + k1 + k2 + k3); 1866efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1867efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ 1868efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul for (j = 0; j < 4; j++) { 1869efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[0][j] = rgba[1][j] = rgba[2][j] = val; 1870efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul rgba[3][j] = 1.0F; 1871efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul } 1872efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul} 1873efe9faf0612778db2423a4f8835b318b95d9efd7Brian Paul 1874e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 1875e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 187685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use 3D texcoords to choose a cube face, then sample the 2D cube faces. 187785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Put face info into the sampler faces[] array. 18780dc4eea64f56cc93e5359372b08b99a2d600273cBrian */ 1879e12810d92ffb3547680b227bf88937c03018112bBrianstatic void 18804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellsample_cube(struct tgsi_sampler *tgsi_sampler, 18814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float s[QUAD_SIZE], 18824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float t[QUAD_SIZE], 18834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float p[QUAD_SIZE], 18844440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol const float c0[QUAD_SIZE], 18854440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol enum tgsi_sampler_control control, 18864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float rgba[NUM_CHANNELS][QUAD_SIZE]) 18870dc4eea64f56cc93e5359372b08b99a2d600273cBrian{ 1888f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 18894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell unsigned j; 18904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell float ssss[4], tttt[4]; 189109a1b912605ff48c8782dcc5aae55ac77e27037bBrian 18924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* 18934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell major axis 189485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul direction target sc tc ma 189585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul ---------- ------------------------------- --- --- --- 18964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rx TEXTURE_CUBE_MAP_POSITIVE_X_EXT -rz -ry rx 18974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rx TEXTURE_CUBE_MAP_NEGATIVE_X_EXT +rz -ry rx 18984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +ry TEXTURE_CUBE_MAP_POSITIVE_Y_EXT +rx +rz ry 18994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -ry TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT +rx -rz ry 19004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell +rz TEXTURE_CUBE_MAP_POSITIVE_Z_EXT +rx -ry rz 19014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell -rz TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT -rx -ry rz 19024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 190385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 19049ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul /* Choose the cube face and compute new s/t coords for the 2D face. 19059ffdc78d1a308bb21a8627abb7bfc9da8abd2f81Brian Paul * 190685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * Use the same cube face for all four pixels in the quad. 190785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * 190885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * This isn't ideal, but if we want to use a different cube face 190985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per pixel in the quad, we'd have to also compute the per-face 191085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * LOD here too. That's because the four post-face-selection 191185425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * texcoords are no longer related to each other (they're 191285425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * per-face!) so we can't use subtraction to compute the partial 191385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * deriviates to compute the LOD. Doing so (near cube edges 191485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul * anyway) gives us pretty much random values. 191585425b3b609c480cd024b217b1efd0b9153bed58Brian Paul */ 191685425b3b609c480cd024b217b1efd0b9153bed58Brian Paul { 191785425b3b609c480cd024b217b1efd0b9153bed58Brian Paul /* use the average of the four pixel's texcoords to choose the face */ 191885425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rx = 0.25 * (s[0] + s[1] + s[2] + s[3]); 191985425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float ry = 0.25 * (t[0] + t[1] + t[2] + t[3]); 192085425b3b609c480cd024b217b1efd0b9153bed58Brian Paul const float rz = 0.25 * (p[0] + p[1] + p[2] + p[3]); 19214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const float arx = fabsf(rx), ary = fabsf(ry), arz = fabsf(rz); 19224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 1923890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell if (arx >= ary && arx >= arz) { 1924c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rx >= 0.0F) ? 1.0F : -1.0F; 1925c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rx >= 0.0F) ? PIPE_TEX_FACE_POS_X : PIPE_TEX_FACE_NEG_X; 1926c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1927c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(s[j]); 1928c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * p[j] * ima + 0.5F; 1929c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1930c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 19314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19324fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 1933890679d4322e7ba4f12f32532a3fdd277edff886Keith Whitwell else if (ary >= arx && ary >= arz) { 1934c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (ry >= 0.0F) ? 1.0F : -1.0F; 1935c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (ry >= 0.0F) ? PIPE_TEX_FACE_POS_Y : PIPE_TEX_FACE_NEG_Y; 1936c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1937c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5F / fabsf(t[j]); 1938c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = -s[j] * ima + 0.5F; 1939c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = sign * -p[j] * ima + 0.5F; 1940c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 19414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 1944c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul float sign = (rz >= 0.0F) ? 1.0F : -1.0F; 1945c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul uint face = (rz >= 0.0F) ? PIPE_TEX_FACE_POS_Z : PIPE_TEX_FACE_NEG_Z; 1946c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul for (j = 0; j < QUAD_SIZE; j++) { 1947c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul const float ima = -0.5 / fabsf(p[j]); 1948c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul ssss[j] = sign * -s[j] * ima + 0.5F; 1949c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul tttt[j] = t[j] * ima + 0.5F; 1950c72a3b4f2ffe0673e753ad144d1b5557a42c670fBrian Paul samp->faces[j] = face; 19514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 19524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 195385425b3b609c480cd024b217b1efd0b9153bed58Brian Paul } 195485425b3b609c480cd024b217b1efd0b9153bed58Brian Paul 19554fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* In our little pipeline, the compare stage is next. If compare 19564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * is not active, this will point somewhere deeper into the 19574fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pipeline, eg. to mip_filter or even img_filter. 19586142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell */ 19594440428faa82f01b4dfb4be89618be2aaf153abdMichal Krol samp->compare(tgsi_sampler, ssss, tttt, NULL, c0, control, rgba); 19604fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 1961612cfb749c3526eeb446bbc631bf24716522f373Brian 19623d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 1963c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paulstatic void 1964c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paulsample_swizzle(struct tgsi_sampler *tgsi_sampler, 1965c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float s[QUAD_SIZE], 1966c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float t[QUAD_SIZE], 1967c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float p[QUAD_SIZE], 1968c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const float c0[QUAD_SIZE], 1969c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul enum tgsi_sampler_control control, 1970c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul float rgba[NUM_CHANNELS][QUAD_SIZE]) 1971c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul{ 1972f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = sp_sampler_variant(tgsi_sampler); 1973c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul float rgba_temp[NUM_CHANNELS][QUAD_SIZE]; 1974c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_r = samp->key.bits.swizzle_r; 1975c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_g = samp->key.bits.swizzle_g; 1976c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_b = samp->key.bits.swizzle_b; 1977c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul const unsigned swizzle_a = samp->key.bits.swizzle_a; 1978c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul unsigned j; 1979c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1980c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target(tgsi_sampler, s, t, p, c0, control, rgba_temp); 1981c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1982c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_r) { 1983c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1984c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1985c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = 0.0f; 1986c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1987c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 1988c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1989c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = 1.0f; 1990c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 1991c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 1992c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_r < 4); 1993c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 1994c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[0][j] = rgba_temp[swizzle_r][j]; 1995c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 1996c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 1997c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_g) { 1998c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 1999c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2000c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = 0.0f; 2001c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2002c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 2003c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2004c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = 1.0f; 2005c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2006c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 2007c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_g < 4); 2008c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2009c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[1][j] = rgba_temp[swizzle_g][j]; 2010c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2011c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 2012c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_b) { 2013c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 2014c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2015c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = 0.0f; 2016c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2017c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 2018c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2019c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = 1.0f; 2020c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2021c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 2022c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_b < 4); 2023c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2024c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[2][j] = rgba_temp[swizzle_b][j]; 2025c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2026c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 2027c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul switch (swizzle_a) { 2028c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ZERO: 2029c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2030c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = 0.0f; 2031c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2032c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul case PIPE_SWIZZLE_ONE: 2033c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2034c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = 1.0f; 2035c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul break; 2036c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul default: 2037c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul assert(swizzle_a < 4); 2038c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul for (j = 0; j < 4; j++) 2039c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul rgba[3][j] = rgba_temp[swizzle_a][j]; 2040c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2041c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul} 2042c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 20433d8c05f7320151898dd224c1daaf3118e1f7ea34Brian 2044e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 2045e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_unorm_wrap(unsigned mode) 20464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 20474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 20484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 20494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 20504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 2051b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_nearest_unorm_clamp_to_edge; 20524fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 20534fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp_to_border; 20540dc4eea64f56cc93e5359372b08b99a2d600273cBrian default: 20550dc4eea64f56cc93e5359372b08b99a2d600273cBrian assert(0); 20564fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_unorm_clamp; 20570dc4eea64f56cc93e5359372b08b99a2d600273cBrian } 20580dc4eea64f56cc93e5359372b08b99a2d600273cBrian} 205934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 206034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 2061e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_nearest_func 2062e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_nearest_wrap(unsigned mode) 2063a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 20644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 20654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 20664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 20674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 20684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp; 20694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 20704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_edge; 20714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 20724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_clamp_to_border; 20734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 20744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_repeat; 20754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 20764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp; 20774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 20784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_edge; 20794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 20804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_mirror_clamp_to_border; 20814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 20824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 20834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_nearest_repeat; 20844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2085a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 2086a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 2087e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2088e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 2089e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_unorm_wrap(unsigned mode) 2090a34b8594b7b2d00404bb639621ec1ce918ba0786Brian{ 20914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 20924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 20934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 20944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 2095b5b128b26841e7f947edd8f0cbcc91a530d6bb8fBrian Paul return wrap_linear_unorm_clamp_to_edge; 20964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 20974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp_to_border; 20984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 20994fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 21004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_unorm_clamp; 21014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 2102a34b8594b7b2d00404bb639621ec1ce918ba0786Brian} 2103a34b8594b7b2d00404bb639621ec1ce918ba0786Brian 2104e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2105e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic wrap_linear_func 2106e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_linear_wrap(unsigned mode) 210734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 21084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (mode) { 21094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 21104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 21114fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 21124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp; 21134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 21144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_edge; 21154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP_TO_BORDER: 21164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_clamp_to_border; 21174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_REPEAT: 21184fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_repeat; 21194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP: 21204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp; 21214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: 21224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_edge; 21234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: 21244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_mirror_clamp_to_border; 21253d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian default: 21263d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian assert(0); 21274fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return wrap_linear_repeat; 21283d6f9d904f07b7676cc971eb3faf9dd8e7c58e50Brian } 212934a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 213034a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 2131e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2132e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic compute_lambda_func 2133e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_lambda_func(const union sp_sampler_key key) 213434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 21354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.processor == TGSI_PROCESSOR_VERTEX) 21364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_vert; 21374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 21384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 21394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 2140779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul case PIPE_TEXTURE_1D_ARRAY: 21414fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 21424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 2143779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul case PIPE_TEXTURE_2D_ARRAY: 2144ae0ef6f69f351cacdc7eaa9b21097a7c1b414e44Luca Barbieri case PIPE_TEXTURE_RECT: 214587ec83afd58536c31bf02c307f1d5488abc84861Brian Paul case PIPE_TEXTURE_CUBE: 21464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_2d; 21474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 21484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_3d; 21494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell default: 21504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell assert(0); 21514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return compute_lambda_1d; 2152b4480285ed5098f1c862690ee105dd46f5e6cd1eBrian } 215334a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 215434a48abd5ff82ce9748fc29191e35a0985d47c5fBrian 2155e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul 2156e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulstatic filter_func 2157e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paulget_img_filter(const union sp_sampler_key key, 2158e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul unsigned filter, 2159e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul const struct pipe_sampler_state *sampler) 2160b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian{ 21614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (key.bits.target) { 21624fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_1D: 21634fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 21644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 21654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 21664fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_linear; 2167b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 2168779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul case PIPE_TEXTURE_1D_ARRAY: 2169779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul if (filter == PIPE_TEX_FILTER_NEAREST) 2170779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul return img_filter_1d_array_nearest; 2171779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul else 2172779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul return img_filter_1d_array_linear; 2173779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul break; 21744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_2D: 2175ae0ef6f69f351cacdc7eaa9b21097a7c1b414e44Luca Barbieri case PIPE_TEXTURE_RECT: 21764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Try for fast path: 21774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 21784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 21794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == sampler->wrap_t && 21804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords) 218138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian { 21824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->wrap_s) { 21834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_REPEAT: 21844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 21856142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 21864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_repeat_POT; 21876142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_LINEAR: 21884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear_repeat_POT; 21896142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 21906142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 219138bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 21924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 21934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_WRAP_CLAMP: 21944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (filter) { 21956142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell case PIPE_TEX_FILTER_NEAREST: 21964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest_clamp_POT; 21976142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell default: 21986142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell break; 219938bee46e83b18ff4ad42d340b507b1a15b4326c7Brian } 2200b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 2201b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 220260adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell /* Otherwise use default versions: 22034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 22044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 22054fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_nearest; 22064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 22074fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_2d_linear; 22084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell break; 2209779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul case PIPE_TEXTURE_2D_ARRAY: 2210779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul if (filter == PIPE_TEX_FILTER_NEAREST) 2211779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul return img_filter_2d_array_nearest; 2212779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul else 2213779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul return img_filter_2d_array_linear; 2214779e9cb658dba4ef44fae7e8aa62409f7227f46cBrian Paul break; 221560adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell case PIPE_TEXTURE_CUBE: 221660adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 221760adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_nearest; 221860adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell else 221960adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell return img_filter_cube_linear; 222060adc15ba5633190fc8a68e7c182f06dc7909df4Keith Whitwell break; 22214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEXTURE_3D: 22224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (filter == PIPE_TEX_FILTER_NEAREST) 22234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_nearest; 22244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 22254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_3d_linear; 2226b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian break; 2227b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian default: 2228b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian assert(0); 22294fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return img_filter_1d_nearest; 2230b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian } 2231b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian} 2232b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 2233b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian 2234a34b8594b7b2d00404bb639621ec1ce918ba0786Brian/** 2235f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul * Bind the given texture object and texture cache to the sampler variant. 2236a34b8594b7b2d00404bb639621ec1ce918ba0786Brian */ 22374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwellvoid 223821148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeetsp_sampler_variant_bind_view( struct sp_sampler_variant *samp, 223921148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet struct softpipe_tex_tile_cache *tex_cache, 224021148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_sampler_view *view ) 224134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian{ 224221148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet const struct pipe_resource *texture = view->texture; 22434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 224421148e6a8806736b4487da41b01e2d3c01cbc743Henri Verbeet samp->view = view; 22454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->cache = tex_cache; 2246683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->xpot = util_unsigned_logbase2( texture->width0 ); 2247683e35f726a182ed9fc6b6d5cb07146eebe14deaKeith Whitwell samp->ypot = util_unsigned_logbase2( texture->height0 ); 22489acdd7739b729375444f8669fc2419d9eb57acc5Henri Verbeet samp->level = view->u.tex.first_level; 22494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell} 22500b9e96fae9493d5d58f046e01c983a3c4267090eBrian 22514f23468bd0d14b8ed687a641003d587b91ad39a7Brian 2252ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwellvoid 2253f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulsp_sampler_variant_destroy( struct sp_sampler_variant *samp ) 2254ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell{ 2255ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell FREE(samp); 2256ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell} 2257ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 2258ecfa8be150ed276af816467b467e76e026f5b541Keith Whitwell 2259e2329f2795d48d11131e9ac105e7aa3fd2c229c1Brian Paul/** 2260f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul * Create a sampler variant for a given set of non-orthogonal state. 22614fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 2262f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulstruct sp_sampler_variant * 2263f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paulsp_create_sampler_variant( const struct pipe_sampler_state *sampler, 22644fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell const union sp_sampler_key key ) 22654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell{ 2266f3955f6fcdd1a3106a6538642131ccea5ef1cef0Brian Paul struct sp_sampler_variant *samp = CALLOC_STRUCT(sp_sampler_variant); 22674fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (!samp) 22684fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return NULL; 22694fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22704fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->sampler = sampler; 22714fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->key = key; 22724fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22734fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Note that (for instance) linear_texcoord_s and 22744fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * nearest_texcoord_s may be active at the same time, if the 22754fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * sampler min_img_filter differs from its mag_img_filter. 22764fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 22774fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->normalized_coords) { 22784fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_wrap( sampler->wrap_s ); 22794fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_wrap( sampler->wrap_t ); 22804fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_wrap( sampler->wrap_r ); 22814fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22824fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_wrap( sampler->wrap_s ); 22834fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_wrap( sampler->wrap_t ); 22844fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_wrap( sampler->wrap_r ); 22854fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 22864fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 22874fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_s = get_linear_unorm_wrap( sampler->wrap_s ); 22884fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_t = get_linear_unorm_wrap( sampler->wrap_t ); 22894fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->linear_texcoord_p = get_linear_unorm_wrap( sampler->wrap_r ); 22904fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22914fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_s = get_nearest_unorm_wrap( sampler->wrap_s ); 22924fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_t = get_nearest_unorm_wrap( sampler->wrap_t ); 22934fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->nearest_texcoord_p = get_nearest_unorm_wrap( sampler->wrap_r ); 22944fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 22954fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22964fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compute_lambda = get_lambda_func( key ); 22974fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 22984fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->min_img_filter = get_img_filter(key, sampler->min_img_filter, sampler); 229941483627f0fd3dc9df2cc55dfd5f3e5987fcfd22Brian Paul samp->mag_img_filter = get_img_filter(key, sampler->mag_img_filter, sampler); 23004fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 23014fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell switch (sampler->min_mip_filter) { 23024fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NONE: 23034fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (sampler->min_img_filter == sampler->mag_img_filter) 23044fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = samp->min_img_filter; 2305b1c8fa5b6002296d9abe21c06d5cb81a3f70828aBrian else 23064fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_none; 230734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 23084fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 23094fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_NEAREST: 23104fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_nearest; 231134a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 23124fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 23134fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell case PIPE_TEX_MIPFILTER_LINEAR: 23144fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.is_pot && 23154fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == sampler->mag_img_filter && 23164fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->normalized_coords && 23174fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->wrap_s == PIPE_TEX_WRAP_REPEAT && 2318cf102b031e7ef33c8e3ffce2f9dcd064f44e8190Brian Paul sampler->wrap_t == PIPE_TEX_WRAP_REPEAT && 23194fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell sampler->min_img_filter == PIPE_TEX_FILTER_LINEAR) 23204fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 23214fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear_2d_linear_repeat_POT; 23224fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 23234fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else 23244fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell { 23254fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->mip_filter = mip_filter_linear; 23266142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 232734a48abd5ff82ce9748fc29191e35a0985d47c5fBrian break; 232834a48abd5ff82ce9748fc29191e35a0985d47c5fBrian } 23293d53d38d5e35386de4793162b9dd32e171927059Brian Paul 23304e014c0a148ba3ac015d0e83dcf975ca6e814e1fMichal Krol if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { 23314fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = sample_compare; 23323d53d38d5e35386de4793162b9dd32e171927059Brian Paul } 23334fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 23344fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip compare operation by promoting the mip_filter function 23354fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * pointer: 23364fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 23374fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->compare = samp->mip_filter; 23384fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 23394fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 23404fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell if (key.bits.target == PIPE_TEXTURE_CUBE) { 2341c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target = sample_cube; 23424fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell } 23434fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell else { 23444fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[0] = 0; 23454fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[1] = 0; 23464fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[2] = 0; 23474fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell samp->faces[3] = 0; 23484fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell 23494fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell /* Skip cube face determination by promoting the compare 23504fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell * function pointer: 23514fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell */ 2352c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->sample_target = samp->compare; 2353c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2354c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul 2355c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul if (key.bits.swizzle_r != PIPE_SWIZZLE_RED || 2356c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_g != PIPE_SWIZZLE_GREEN || 2357c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_b != PIPE_SWIZZLE_BLUE || 2358c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul key.bits.swizzle_a != PIPE_SWIZZLE_ALPHA) { 2359c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->base.get_samples = sample_swizzle; 2360c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul } 2361c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul else { 2362c62bb90d6a864468fe1a717aebb9c1a9c43bf3c8Brian Paul samp->base.get_samples = samp->sample_target; 23636142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell } 23646142de393fe34ff0866f8489f1292eb473276f11Keith Whitwell 23654fc7d0345a18042a79686940fb7cc4e698cc9192Keith Whitwell return samp; 236634a48abd5ff82ce9748fc29191e35a0985d47c5fBrian} 2367