lp_bld_sample.h revision 438390418d27838bcfcb5bbb4c486db45dbaa44d
1de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca/************************************************************************** 2de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 3de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Copyright 2009 VMware, Inc. 4de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * All Rights Reserved. 5de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 6de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Permission is hereby granted, free of charge, to any person obtaining a 7de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * copy of this software and associated documentation files (the 8de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * "Software"), to deal in the Software without restriction, including 9de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * without limitation the rights to use, copy, modify, merge, publish, 10de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * distribute, sub license, and/or sell copies of the Software, and to 11de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * permit persons to whom the Software is furnished to do so, subject to 12de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * the following conditions: 13de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 14de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * The above copyright notice and this permission notice (including the 15de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * next paragraph) shall be included in all copies or substantial portions 16de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * of the Software. 17de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 18de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 26de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca **************************************************************************/ 27de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 28de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca/** 29de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * @file 30de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Texture sampling. 31de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 32de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * @author Jose Fonseca <jfonseca@vmware.com> 33de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca */ 34de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 35de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca#ifndef LP_BLD_SAMPLE_H 36de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca#define LP_BLD_SAMPLE_H 37de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 38de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 39deffeba17204c249cac698a516a210e364d2cf55Vinson Lee#include "pipe/p_format.h" 400a7824862eb753878fa79b153b2a111884ff1197Brian Paul#include "util/u_debug.h" 410d71ba46e613230c84165106c1fcc9027dec4cd3Brian Paul#include "gallivm/lp_bld.h" 420a7824862eb753878fa79b153b2a111884ff1197Brian Paul#include "gallivm/lp_bld_type.h" 430a7824862eb753878fa79b153b2a111884ff1197Brian Paul#include "gallivm/lp_bld_swizzle.h" 440a7824862eb753878fa79b153b2a111884ff1197Brian Paul 45de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 46287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstruct pipe_resource; 47d67e3487ac4c678892d0aea535cacfd5f1d86a27José Fonsecastruct pipe_sampler_view; 48de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecastruct pipe_sampler_state; 49bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonsecastruct util_format_description; 50b4835ea03d64261da5a892f9590c9977b06920e8José Fonsecastruct lp_type; 51bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonsecastruct lp_build_context; 52de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 53de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 54de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca/** 55de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Sampler static state. 56de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 57287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell * These are the bits of state from pipe_resource and pipe_sampler_state that 58de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * are embedded in the generated code. 59de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca */ 60de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecastruct lp_sampler_static_state 61de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca{ 6281ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca /* pipe_sampler_view's state */ 63de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca enum pipe_format format; 640a0d17616382948092adeb652701681a2ea7753eBrian Paul unsigned swizzle_r:3; /**< PIPE_SWIZZLE_* */ 6581ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca unsigned swizzle_g:3; 6681ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca unsigned swizzle_b:3; 6781ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca unsigned swizzle_a:3; 6881ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca 6981ab19de04e623d24cb65ad1ed3b240bce78235bJosé Fonseca /* pipe_texture's state */ 700a0d17616382948092adeb652701681a2ea7753eBrian Paul unsigned target:3; /**< PIPE_TEXTURE_* */ 710a0d17616382948092adeb652701681a2ea7753eBrian Paul unsigned pot_width:1; /**< is the width a power of two? */ 72de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned pot_height:1; 73de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned pot_depth:1; 74de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 75de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca /* pipe_sampler_state's state */ 76de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned wrap_s:3; 77de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned wrap_t:3; 78de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned wrap_r:3; 79de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned min_img_filter:2; 80de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned min_mip_filter:2; 81de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned mag_img_filter:2; 82de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned compare_mode:1; 83de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned compare_func:3; 84de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned normalized_coords:1; 8561b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul unsigned min_max_lod_equal:1; /**< min_lod == max_lod ? */ 865849a6ab6412eddd4552329178e6edb0bea92977Keith Whitwell unsigned lod_bias_non_zero:1; 871c32583581ef5aee59901d9dd8e56cc1a125f0d4José Fonseca unsigned apply_min_lod:1; /**< min_lod > 0 ? */ 881c32583581ef5aee59901d9dd8e56cc1a125f0d4José Fonseca unsigned apply_max_lod:1; /**< max_lod < last_level ? */ 89de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca}; 90de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 91de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 92de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca/** 93de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Sampler dynamic state. 94de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 95287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell * These are the bits of state from pipe_resource and pipe_sampler_state that 96de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * are computed in runtime. 97de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * 98de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * There are obtained through callbacks, as we don't want to tie the texture 99de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * sampling code generation logic to any particular texture layout or pipe 100de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * driver. 101de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca */ 102de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecastruct lp_sampler_dynamic_state 103de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca{ 104de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 105542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain the base texture width (returns int32) */ 106de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMValueRef 1073f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*width)( const struct lp_sampler_dynamic_state *state, 108de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMBuilderRef builder, 109de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned unit); 110de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 111542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain the base texture height (returns int32) */ 112de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMValueRef 1133f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*height)( const struct lp_sampler_dynamic_state *state, 114de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMBuilderRef builder, 115de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned unit); 116de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 117542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain the base texture depth (returns int32) */ 1187f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul LLVMValueRef 1193f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*depth)( const struct lp_sampler_dynamic_state *state, 1207f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul LLVMBuilderRef builder, 1217f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul unsigned unit); 1227f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul 123542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain the number of mipmap levels minus one (returns int32) */ 1247f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul LLVMValueRef 1253f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*last_level)( const struct lp_sampler_dynamic_state *state, 1267f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul LLVMBuilderRef builder, 1277f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul unsigned unit); 1287f4b5c5387a3a8e3c5f31f0badc943c43857683aBrian Paul 129542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain stride in bytes between image rows/blocks (returns int32) */ 130de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMValueRef 1313f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*row_stride)( const struct lp_sampler_dynamic_state *state, 13253efb634a0c134feebb5a3e47fc33660694be9c3Brian Paul LLVMBuilderRef builder, 13353efb634a0c134feebb5a3e47fc33660694be9c3Brian Paul unsigned unit); 134de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 135542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain stride in bytes between image slices (returns int32) */ 136de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMValueRef 1373f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*img_stride)( const struct lp_sampler_dynamic_state *state, 138079081222a6881655e112351a57e0a07b0c7b031Brian Paul LLVMBuilderRef builder, 139079081222a6881655e112351a57e0a07b0c7b031Brian Paul unsigned unit); 140079081222a6881655e112351a57e0a07b0c7b031Brian Paul 141542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain pointer to array of pointers to mimpap levels */ 142079081222a6881655e112351a57e0a07b0c7b031Brian Paul LLVMValueRef 1433f6dc8e79d918283a6dfcf9c8937a6d52f3bb4f5Brian Paul (*data_ptr)( const struct lp_sampler_dynamic_state *state, 144de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca LLVMBuilderRef builder, 145de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned unit); 146de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 147542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain texture min lod (returns float) */ 14861b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMValueRef 14961b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul (*min_lod)(const struct lp_sampler_dynamic_state *state, 15061b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMBuilderRef builder, unsigned unit); 15161b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul 152542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain texture max lod (returns float) */ 15361b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMValueRef 15461b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul (*max_lod)(const struct lp_sampler_dynamic_state *state, 15561b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMBuilderRef builder, unsigned unit); 15661b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul 157542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain texture lod bias (returns float) */ 15861b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMValueRef 15961b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul (*lod_bias)(const struct lp_sampler_dynamic_state *state, 16061b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul LLVMBuilderRef builder, unsigned unit); 161d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul 162542d6cb1b8a87615b4c4498ce1fcbf39d743f963Brian Paul /** Obtain texture border color (returns ptr to float[4]) */ 163d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul LLVMValueRef 164d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul (*border_color)(const struct lp_sampler_dynamic_state *state, 165d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul LLVMBuilderRef builder, unsigned unit); 166de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca}; 167de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 168de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 169de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca/** 1700a7824862eb753878fa79b153b2a111884ff1197Brian Paul * Keep all information for sampling code generation in a single place. 1710a7824862eb753878fa79b153b2a111884ff1197Brian Paul */ 1720a7824862eb753878fa79b153b2a111884ff1197Brian Paulstruct lp_build_sample_context 1730a7824862eb753878fa79b153b2a111884ff1197Brian Paul{ 1740a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMBuilderRef builder; 1750a7824862eb753878fa79b153b2a111884ff1197Brian Paul 1760a7824862eb753878fa79b153b2a111884ff1197Brian Paul const struct lp_sampler_static_state *static_state; 1770a7824862eb753878fa79b153b2a111884ff1197Brian Paul 1780a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_sampler_dynamic_state *dynamic_state; 1790a7824862eb753878fa79b153b2a111884ff1197Brian Paul 1800a7824862eb753878fa79b153b2a111884ff1197Brian Paul const struct util_format_description *format_desc; 1810a7824862eb753878fa79b153b2a111884ff1197Brian Paul 182f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca /* See texture_dims() */ 183f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca unsigned dims; 184f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca 1850a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** regular scalar float type */ 1860a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type float_type; 1870a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context float_bld; 1880a7824862eb753878fa79b153b2a111884ff1197Brian Paul 189d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul /** float vector type */ 190d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul struct lp_build_context float_vec_bld; 191d1a4dd4217a4b8b018d4d9a161afece640d75694Brian Paul 1920a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** regular scalar float type */ 1930a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type int_type; 1940a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context int_bld; 1950a7824862eb753878fa79b153b2a111884ff1197Brian Paul 1960a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** Incoming coordinates type and build context */ 1970a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type coord_type; 1980a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context coord_bld; 1990a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2000a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** Unsigned integer coordinates */ 2010a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type uint_coord_type; 2020a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context uint_coord_bld; 2030a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2040a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** Signed integer coordinates */ 2050a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type int_coord_type; 2060a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context int_coord_bld; 2070a7824862eb753878fa79b153b2a111884ff1197Brian Paul 208321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca /** Unsigned integer texture size */ 209438390418d27838bcfcb5bbb4c486db45dbaa44dJosé Fonseca struct lp_type int_size_type; 210438390418d27838bcfcb5bbb4c486db45dbaa44dJosé Fonseca struct lp_build_context int_size_bld; 211321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca 212321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca /** Unsigned integer texture size */ 213321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca struct lp_type float_size_type; 214321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca struct lp_build_context float_size_bld; 215321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca 2160a7824862eb753878fa79b153b2a111884ff1197Brian Paul /** Output texels type and build context */ 2170a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_type texel_type; 2180a7824862eb753878fa79b153b2a111884ff1197Brian Paul struct lp_build_context texel_bld; 219321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonseca 220f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca /* Common dynamic state values */ 221f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef width; 222f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef height; 223f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef depth; 224f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef row_stride_array; 225f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef img_stride_array; 226f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef data_array; 227f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca 228438390418d27838bcfcb5bbb4c486db45dbaa44dJosé Fonseca /** Integer vector with texture width, height, depth */ 229438390418d27838bcfcb5bbb4c486db45dbaa44dJosé Fonseca LLVMValueRef int_size; 2300a7824862eb753878fa79b153b2a111884ff1197Brian Paul}; 2310a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2320a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2330a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2340a7824862eb753878fa79b153b2a111884ff1197Brian Paul/** 2350a7824862eb753878fa79b153b2a111884ff1197Brian Paul * We only support a few wrap modes in lp_build_sample_wrap_linear_int() at 2360a7824862eb753878fa79b153b2a111884ff1197Brian Paul * this time. Return whether the given mode is supported by that function. 2370a7824862eb753878fa79b153b2a111884ff1197Brian Paul */ 2380a7824862eb753878fa79b153b2a111884ff1197Brian Paulstatic INLINE boolean 2390a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_is_simple_wrap_mode(unsigned mode) 2400a7824862eb753878fa79b153b2a111884ff1197Brian Paul{ 2410a7824862eb753878fa79b153b2a111884ff1197Brian Paul switch (mode) { 2420a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEX_WRAP_REPEAT: 2430a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEX_WRAP_CLAMP_TO_EDGE: 2440a7824862eb753878fa79b153b2a111884ff1197Brian Paul return TRUE; 2450a7824862eb753878fa79b153b2a111884ff1197Brian Paul default: 2460a7824862eb753878fa79b153b2a111884ff1197Brian Paul return FALSE; 2470a7824862eb753878fa79b153b2a111884ff1197Brian Paul } 2480a7824862eb753878fa79b153b2a111884ff1197Brian Paul} 2490a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2500a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2510a7824862eb753878fa79b153b2a111884ff1197Brian Paulstatic INLINE void 2520a7824862eb753878fa79b153b2a111884ff1197Brian Paulapply_sampler_swizzle(struct lp_build_sample_context *bld, 2530a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *texel) 2540a7824862eb753878fa79b153b2a111884ff1197Brian Paul{ 2550a7824862eb753878fa79b153b2a111884ff1197Brian Paul unsigned char swizzles[4]; 2560a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2570a7824862eb753878fa79b153b2a111884ff1197Brian Paul swizzles[0] = bld->static_state->swizzle_r; 2580a7824862eb753878fa79b153b2a111884ff1197Brian Paul swizzles[1] = bld->static_state->swizzle_g; 2590a7824862eb753878fa79b153b2a111884ff1197Brian Paul swizzles[2] = bld->static_state->swizzle_b; 2600a7824862eb753878fa79b153b2a111884ff1197Brian Paul swizzles[3] = bld->static_state->swizzle_a; 2610a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2620a7824862eb753878fa79b153b2a111884ff1197Brian Paul lp_build_swizzle_soa_inplace(&bld->texel_bld, texel, swizzles); 2630a7824862eb753878fa79b153b2a111884ff1197Brian Paul} 2640a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2650a7824862eb753878fa79b153b2a111884ff1197Brian Paul 266321ec1a22468c1f23bbbf7d5c9de53d4687fec0cJosé Fonsecastatic INLINE unsigned 2670a7824862eb753878fa79b153b2a111884ff1197Brian Paultexture_dims(enum pipe_texture_target tex) 2680a7824862eb753878fa79b153b2a111884ff1197Brian Paul{ 2690a7824862eb753878fa79b153b2a111884ff1197Brian Paul switch (tex) { 2700a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEXTURE_1D: 2710a7824862eb753878fa79b153b2a111884ff1197Brian Paul return 1; 2720a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEXTURE_2D: 273c70d539e24c901c54f427b91997f8ca566847f33Brian Paul case PIPE_TEXTURE_RECT: 2740a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEXTURE_CUBE: 2750a7824862eb753878fa79b153b2a111884ff1197Brian Paul return 2; 2760a7824862eb753878fa79b153b2a111884ff1197Brian Paul case PIPE_TEXTURE_3D: 2770a7824862eb753878fa79b153b2a111884ff1197Brian Paul return 3; 2780a7824862eb753878fa79b153b2a111884ff1197Brian Paul default: 2790a7824862eb753878fa79b153b2a111884ff1197Brian Paul assert(0 && "bad texture target in texture_dims()"); 2800a7824862eb753878fa79b153b2a111884ff1197Brian Paul return 2; 2810a7824862eb753878fa79b153b2a111884ff1197Brian Paul } 2820a7824862eb753878fa79b153b2a111884ff1197Brian Paul} 2830a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2840a7824862eb753878fa79b153b2a111884ff1197Brian Paul 2854e6f5e8d43ee87c6f8cdc75de2eeb96f70beb013José Fonsecaboolean 2864e6f5e8d43ee87c6f8cdc75de2eeb96f70beb013José Fonsecalp_sampler_wrap_mode_uses_border_color(unsigned mode, 2874e6f5e8d43ee87c6f8cdc75de2eeb96f70beb013José Fonseca unsigned min_img_filter, 2884e6f5e8d43ee87c6f8cdc75de2eeb96f70beb013José Fonseca unsigned mag_img_filter); 2894e6f5e8d43ee87c6f8cdc75de2eeb96f70beb013José Fonseca 2900a7824862eb753878fa79b153b2a111884ff1197Brian Paul/** 291de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca * Derive the sampler static state. 292de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca */ 293de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecavoid 294de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecalp_sampler_static_state(struct lp_sampler_static_state *state, 295d67e3487ac4c678892d0aea535cacfd5f1d86a27José Fonseca const struct pipe_sampler_view *view, 296de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca const struct pipe_sampler_state *sampler); 297de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 298de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 29987dd859b342b844add906358810445da21b6b092José Fonsecavoid 3000a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_lod_selector(struct lp_build_sample_context *bld, 30161b7da074e2faebf03d3dfc30e910ee1367bcd5aBrian Paul unsigned unit, 3020a7824862eb753878fa79b153b2a111884ff1197Brian Paul const LLVMValueRef ddx[4], 3030a7824862eb753878fa79b153b2a111884ff1197Brian Paul const LLVMValueRef ddy[4], 3040a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef lod_bias, /* optional */ 3050a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef explicit_lod, /* optional */ 30687dd859b342b844add906358810445da21b6b092José Fonseca unsigned mip_filter, 30787dd859b342b844add906358810445da21b6b092José Fonseca LLVMValueRef *out_lod_ipart, 30887dd859b342b844add906358810445da21b6b092José Fonseca LLVMValueRef *out_lod_fpart); 3090a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3100a7824862eb753878fa79b153b2a111884ff1197Brian Paulvoid 3110a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_nearest_mip_level(struct lp_build_sample_context *bld, 3120a7824862eb753878fa79b153b2a111884ff1197Brian Paul unsigned unit, 3130a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef lod, 3140a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *level_out); 3150a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3160a7824862eb753878fa79b153b2a111884ff1197Brian Paulvoid 3170a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_linear_mip_levels(struct lp_build_sample_context *bld, 3180a7824862eb753878fa79b153b2a111884ff1197Brian Paul unsigned unit, 31987dd859b342b844add906358810445da21b6b092José Fonseca LLVMValueRef lod_ipart, 320df7a2451b1a7b9ce8cc389b20bb707cf951f8d4eJosé Fonseca LLVMValueRef *lod_fpart_inout, 3210a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *level0_out, 32287dd859b342b844add906358810445da21b6b092José Fonseca LLVMValueRef *level1_out); 3230a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3240a7824862eb753878fa79b153b2a111884ff1197Brian PaulLLVMValueRef 3250a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_get_mipmap_level(struct lp_build_sample_context *bld, 326f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca LLVMValueRef level); 3270a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3280a7824862eb753878fa79b153b2a111884ff1197Brian PaulLLVMValueRef 3290a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_get_const_mipmap_level(struct lp_build_sample_context *bld, 330f5b5fb32d3a9eb8667f91907bcf065fe8bd4988dJosé Fonseca int level); 3310a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3320a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3330a7824862eb753878fa79b153b2a111884ff1197Brian Paulvoid 3340a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_mipmap_level_sizes(struct lp_build_sample_context *bld, 33505fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef ilevel, 33605fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef *out_width_vec, 33705fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef *out_height_vec, 33805fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef *out_depth_vec, 33905fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef *row_stride_vec, 34005fe33b71cd913876184d1aa4086e4e3f8636eb1José Fonseca LLVMValueRef *img_stride_vec); 3410a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3420a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3430a7824862eb753878fa79b153b2a111884ff1197Brian Paulvoid 3440a7824862eb753878fa79b153b2a111884ff1197Brian Paullp_build_cube_lookup(struct lp_build_sample_context *bld, 3450a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef s, 3460a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef t, 3470a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef r, 3480a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *face, 3490a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *face_s, 3500a7824862eb753878fa79b153b2a111884ff1197Brian Paul LLVMValueRef *face_t); 3510a7824862eb753878fa79b153b2a111884ff1197Brian Paul 3520a7824862eb753878fa79b153b2a111884ff1197Brian Paul 353d981bde38472d8d3bb74dab67eccd7c82915a566José Fonsecavoid 3540a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonsecalp_build_sample_partial_offset(struct lp_build_context *bld, 3550a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca unsigned block_length, 3560a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca LLVMValueRef coord, 3570a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca LLVMValueRef stride, 3580a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca LLVMValueRef *out_offset, 3590a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca LLVMValueRef *out_i); 3600a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca 3610a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonseca 3620a6c908e0d2d1721421f7b26d73975f4f61e24a2José Fonsecavoid 363bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonsecalp_build_sample_offset(struct lp_build_context *bld, 364bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonseca const struct util_format_description *format_desc, 365bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonseca LLVMValueRef x, 366bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonseca LLVMValueRef y, 36767a2f98be79b368c316ebe6731112734d306b3f6Brian Paul LLVMValueRef z, 36867a2f98be79b368c316ebe6731112734d306b3f6Brian Paul LLVMValueRef y_stride, 369d981bde38472d8d3bb74dab67eccd7c82915a566José Fonseca LLVMValueRef z_stride, 370d981bde38472d8d3bb74dab67eccd7c82915a566José Fonseca LLVMValueRef *out_offset, 371d981bde38472d8d3bb74dab67eccd7c82915a566José Fonseca LLVMValueRef *out_i, 372d981bde38472d8d3bb74dab67eccd7c82915a566José Fonseca LLVMValueRef *out_j); 373bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonseca 374bc93e9181cf179a797679d30cd1a3a563e1756c0José Fonseca 375de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecavoid 376de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonsecalp_build_sample_soa(LLVMBuilderRef builder, 377de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca const struct lp_sampler_static_state *static_state, 378de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca struct lp_sampler_dynamic_state *dynamic_state, 379b4835ea03d64261da5a892f9590c9977b06920e8José Fonseca struct lp_type fp_type, 380de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned unit, 381de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca unsigned num_coords, 382de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca const LLVMValueRef *coords, 383962558daaed43b0111cd062e32821aad106869d7José Fonseca const LLVMValueRef *ddx, 384962558daaed43b0111cd062e32821aad106869d7José Fonseca const LLVMValueRef *ddy, 385ec43b2eb45a1b2e33f328f76624c987484e329f3José Fonseca LLVMValueRef lod_bias, 386ec43b2eb45a1b2e33f328f76624c987484e329f3José Fonseca LLVMValueRef explicit_lod, 3871cd31459afa7ea859a7c1e6abb1fc4ae2f0060edBrian Paul LLVMValueRef texel_out[4]); 388de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 389045ee4601179c44f815ce3842ef900b36d54c914Keith Whitwellvoid 390045ee4601179c44f815ce3842ef900b36d54c914Keith Whitwelllp_build_sample_nop(struct lp_type type, 391045ee4601179c44f815ce3842ef900b36d54c914Keith Whitwell LLVMValueRef texel_out[4]); 392de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 393de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca 394de8376e2f22a59a0bc18bb7ddab88ee3153678b8José Fonseca#endif /* LP_BLD_SAMPLE_H */ 395