1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * Copyright 2010 VMware, Inc. All rights reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 9bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 10bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 11bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 12bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 13bf215546Sopenharmony_ci * the following conditions: 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 16bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 17bf215546Sopenharmony_ci * of the Software. 18bf215546Sopenharmony_ci * 19bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 23bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26bf215546Sopenharmony_ci * 27bf215546Sopenharmony_ci **************************************************************************/ 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#ifndef SP_TEX_SAMPLE_H 30bf215546Sopenharmony_ci#define SP_TEX_SAMPLE_H 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "tgsi/tgsi_exec.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_cistruct sp_sampler_view; 37bf215546Sopenharmony_cistruct sp_sampler; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_citypedef void (*wrap_nearest_func)(float s, 40bf215546Sopenharmony_ci unsigned size, 41bf215546Sopenharmony_ci int offset, 42bf215546Sopenharmony_ci int *icoord); 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_citypedef void (*wrap_linear_func)(float s, 45bf215546Sopenharmony_ci unsigned size, 46bf215546Sopenharmony_ci int offset, 47bf215546Sopenharmony_ci int *icoord0, 48bf215546Sopenharmony_ci int *icoord1, 49bf215546Sopenharmony_ci float *w); 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_citypedef float (*compute_lambda_func)(const struct sp_sampler_view *sp_sview, 52bf215546Sopenharmony_ci const float s[TGSI_QUAD_SIZE], 53bf215546Sopenharmony_ci const float t[TGSI_QUAD_SIZE], 54bf215546Sopenharmony_ci const float p[TGSI_QUAD_SIZE]); 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_citypedef float (*compute_lambda_from_grad_func)(const struct sp_sampler_view *sp_sview, 57bf215546Sopenharmony_ci const float derivs[3][2][TGSI_QUAD_SIZE], 58bf215546Sopenharmony_ci uint quad); 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_cistruct img_filter_args { 61bf215546Sopenharmony_ci float s; 62bf215546Sopenharmony_ci float t; 63bf215546Sopenharmony_ci float p; 64bf215546Sopenharmony_ci unsigned level; 65bf215546Sopenharmony_ci unsigned face_id; 66bf215546Sopenharmony_ci const int8_t *offset; 67bf215546Sopenharmony_ci bool gather_only; 68bf215546Sopenharmony_ci int gather_comp; 69bf215546Sopenharmony_ci}; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_citypedef void (*img_filter_func)(const struct sp_sampler_view *sp_sview, 72bf215546Sopenharmony_ci const struct sp_sampler *sp_samp, 73bf215546Sopenharmony_ci const struct img_filter_args *args, 74bf215546Sopenharmony_ci float *rgba); 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_cistruct filter_args { 77bf215546Sopenharmony_ci enum tgsi_sampler_control control; 78bf215546Sopenharmony_ci const int8_t *offset; 79bf215546Sopenharmony_ci const uint *faces; 80bf215546Sopenharmony_ci}; 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_citypedef void (*mip_filter_func)(const struct sp_sampler_view *sp_sview, 83bf215546Sopenharmony_ci const struct sp_sampler *sp_samp, 84bf215546Sopenharmony_ci img_filter_func min_filter, 85bf215546Sopenharmony_ci img_filter_func mag_filter, 86bf215546Sopenharmony_ci const float s[TGSI_QUAD_SIZE], 87bf215546Sopenharmony_ci const float t[TGSI_QUAD_SIZE], 88bf215546Sopenharmony_ci const float p[TGSI_QUAD_SIZE], 89bf215546Sopenharmony_ci int gather_comp, 90bf215546Sopenharmony_ci const float lod[TGSI_QUAD_SIZE], 91bf215546Sopenharmony_ci const struct filter_args *args, 92bf215546Sopenharmony_ci float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]); 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_citypedef void (*mip_level_func)(const struct sp_sampler_view *sp_sview, 96bf215546Sopenharmony_ci const struct sp_sampler *sp_samp, 97bf215546Sopenharmony_ci const float lod[TGSI_QUAD_SIZE], 98bf215546Sopenharmony_ci float level[TGSI_QUAD_SIZE]); 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_citypedef void (*fetch_func)(struct sp_sampler_view *sp_sview, 101bf215546Sopenharmony_ci const int i[TGSI_QUAD_SIZE], 102bf215546Sopenharmony_ci const int j[TGSI_QUAD_SIZE], const int k[TGSI_QUAD_SIZE], 103bf215546Sopenharmony_ci const int lod[TGSI_QUAD_SIZE], const int8_t offset[3], 104bf215546Sopenharmony_ci float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_cistruct sp_sampler_view 108bf215546Sopenharmony_ci{ 109bf215546Sopenharmony_ci struct pipe_sampler_view base; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci /* For sp_get_samples_2d_linear_POT: 112bf215546Sopenharmony_ci */ 113bf215546Sopenharmony_ci unsigned xpot; 114bf215546Sopenharmony_ci unsigned ypot; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci boolean need_swizzle; 117bf215546Sopenharmony_ci boolean pot2d; 118bf215546Sopenharmony_ci boolean need_cube_convert; 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci /* these are different per shader type */ 121bf215546Sopenharmony_ci struct softpipe_tex_tile_cache *cache; 122bf215546Sopenharmony_ci compute_lambda_func compute_lambda; 123bf215546Sopenharmony_ci compute_lambda_from_grad_func compute_lambda_from_grad; 124bf215546Sopenharmony_ci union pipe_color_union border_color; 125bf215546Sopenharmony_ci /* Value to use for PIPE_SWIZZLE_1 (integer vs float) */ 126bf215546Sopenharmony_ci float oneval; 127bf215546Sopenharmony_ci}; 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_cistruct sp_filter_funcs { 130bf215546Sopenharmony_ci mip_level_func relative_level; 131bf215546Sopenharmony_ci mip_filter_func filter; 132bf215546Sopenharmony_ci}; 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_cistruct sp_sampler { 135bf215546Sopenharmony_ci struct pipe_sampler_state base; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci boolean min_mag_equal_repeat_linear; 138bf215546Sopenharmony_ci boolean min_mag_equal; 139bf215546Sopenharmony_ci unsigned min_img_filter; 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci wrap_nearest_func nearest_texcoord_s; 142bf215546Sopenharmony_ci wrap_nearest_func nearest_texcoord_t; 143bf215546Sopenharmony_ci wrap_nearest_func nearest_texcoord_p; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci wrap_linear_func linear_texcoord_s; 146bf215546Sopenharmony_ci wrap_linear_func linear_texcoord_t; 147bf215546Sopenharmony_ci wrap_linear_func linear_texcoord_p; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci const struct sp_filter_funcs *filter_funcs; 150bf215546Sopenharmony_ci}; 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci/** 154bf215546Sopenharmony_ci * Subclass of tgsi_sampler 155bf215546Sopenharmony_ci */ 156bf215546Sopenharmony_cistruct sp_tgsi_sampler 157bf215546Sopenharmony_ci{ 158bf215546Sopenharmony_ci struct tgsi_sampler base; /**< base class */ 159bf215546Sopenharmony_ci struct sp_sampler *sp_sampler[PIPE_MAX_SAMPLERS]; 160bf215546Sopenharmony_ci struct sp_sampler_view sp_sview[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci}; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_cicompute_lambda_func 165bf215546Sopenharmony_cisoftpipe_get_lambda_func(const struct pipe_sampler_view *view, 166bf215546Sopenharmony_ci enum pipe_shader_type shader); 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_cicompute_lambda_from_grad_func 169bf215546Sopenharmony_cisoftpipe_get_lambda_from_grad_func(const struct pipe_sampler_view *view, 170bf215546Sopenharmony_ci enum pipe_shader_type shader); 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_civoid * 173bf215546Sopenharmony_cisoftpipe_create_sampler_state(struct pipe_context *pipe, 174bf215546Sopenharmony_ci const struct pipe_sampler_state *sampler); 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_cistruct pipe_sampler_view * 178bf215546Sopenharmony_cisoftpipe_create_sampler_view(struct pipe_context *pipe, 179bf215546Sopenharmony_ci struct pipe_resource *resource, 180bf215546Sopenharmony_ci const struct pipe_sampler_view *templ); 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_cistruct sp_tgsi_sampler * 184bf215546Sopenharmony_cisp_create_tgsi_sampler(void); 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci#endif /* SP_TEX_SAMPLE_H */ 188