brw_wm_sampler_state.c File Reference

Include dependency graph for brw_wm_sampler_state.c:

Go to the source code of this file.

Defines

#define COMPAREFUNC_ALWAYS   0
#define COMPAREFUNC_NEVER   0x1
#define COMPAREFUNC_LESS   0x2
#define COMPAREFUNC_EQUAL   0x3
#define COMPAREFUNC_LEQUAL   0x4
#define COMPAREFUNC_GREATER   0x5
#define COMPAREFUNC_NOTEQUAL   0x6
#define COMPAREFUNC_GEQUAL   0x7

Functions

static int intel_translate_shadow_compare_func (unsigned func)
static unsigned translate_wrap_mode (int wrap)
static unsigned U_FIXED (float value, unsigned frac_bits)
static int S_FIXED (float value, unsigned frac_bits)
static unsigned upload_default_color (struct brw_context *brw, const float *color)
static void brw_update_sampler_state (const struct pipe_sampler_state *pipe_sampler, unsigned sdc_gs_offset, struct brw_sampler_state *sampler)
static void upload_wm_samplers (struct brw_context *brw)

Variables

struct brw_tracked_state brw_wm_samplers


Define Documentation

#define COMPAREFUNC_ALWAYS   0

Definition at line 41 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_EQUAL   0x3

Definition at line 44 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_GEQUAL   0x7

Definition at line 48 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_GREATER   0x5

Definition at line 46 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_LEQUAL   0x4

Definition at line 45 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_LESS   0x2

Definition at line 43 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_NEVER   0x1

Definition at line 42 of file brw_wm_sampler_state.c.

#define COMPAREFUNC_NOTEQUAL   0x6

Definition at line 47 of file brw_wm_sampler_state.c.


Function Documentation

static void brw_update_sampler_state ( const struct pipe_sampler_state pipe_sampler,
unsigned  sdc_gs_offset,
struct brw_sampler_state sampler 
) [static]

Definition at line 127 of file brw_wm_sampler_state.c.

References brw_sampler_state::base_level, BRW_ANISORATIO_16, BRW_MAPFILTER_ANISOTROPIC, BRW_MAPFILTER_LINEAR, BRW_MAPFILTER_NEAREST, BRW_MIPFILTER_LINEAR, BRW_MIPFILTER_NEAREST, BRW_MIPFILTER_NONE, BRW_TEXCOORDMODE_CUBE, CLAMP, pipe_sampler_state::compare_func, pipe_sampler_state::compare_mode, brw_sampler_state::default_color_mode, brw_sampler_state::default_color_pointer, intel_translate_shadow_compare_func(), pipe_sampler_state::lod_bias, brw_sampler_state::lod_bias, brw_sampler_state::lod_preclamp, brw_sampler_state::mag_filter, pipe_sampler_state::mag_img_filter, MAX2, brw_sampler_state::max_aniso, pipe_sampler_state::max_anisotropy, pipe_sampler_state::max_lod, brw_sampler_state::max_lod, MIN2, brw_sampler_state::min_filter, pipe_sampler_state::min_lod, brw_sampler_state::min_lod, pipe_sampler_state::min_mip_filter, brw_sampler_state::mip_filter, PIPE_TEX_COMPARE_R_TO_TEXTURE, PIPE_TEX_FILTER_ANISO, PIPE_TEX_FILTER_LINEAR, PIPE_TEX_FILTER_NEAREST, PIPE_TEX_MIPFILTER_LINEAR, PIPE_TEX_MIPFILTER_NEAREST, PIPE_TEX_MIPFILTER_NONE, brw_sampler_state::r_wrap_mode, S_FIXED(), brw_sampler_state::s_wrap_mode, brw_sampler_state::shadow_function, brw_sampler_state::ss0, brw_sampler_state::ss1, brw_sampler_state::ss2, brw_sampler_state::ss3, brw_sampler_state::t_wrap_mode, translate_wrap_mode(), U_FIXED(), pipe_sampler_state::wrap_r, pipe_sampler_state::wrap_s, and pipe_sampler_state::wrap_t.

00130 {
00131    memset(sampler, 0, sizeof(*sampler));
00132 
00133    switch (pipe_sampler->min_mip_filter) {
00134    case PIPE_TEX_FILTER_NEAREST:
00135       sampler->ss0.min_filter = BRW_MAPFILTER_NEAREST;
00136       break;
00137    case PIPE_TEX_FILTER_LINEAR:
00138       sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
00139       break;
00140    case PIPE_TEX_FILTER_ANISO:
00141       sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC;
00142       break;
00143    default:
00144       break;
00145    }
00146 
00147    switch (pipe_sampler->min_mip_filter) {
00148    case PIPE_TEX_MIPFILTER_NEAREST:
00149       sampler->ss0.mip_filter = BRW_MIPFILTER_NEAREST;
00150       break;
00151    case PIPE_TEX_MIPFILTER_LINEAR:
00152       sampler->ss0.mip_filter = BRW_MIPFILTER_LINEAR;
00153       break;
00154    case PIPE_TEX_MIPFILTER_NONE:
00155       sampler->ss0.mip_filter = BRW_MIPFILTER_NONE;
00156       break;
00157    default:
00158       break;
00159    }
00160    /* Set Anisotropy:
00161     */
00162    switch (pipe_sampler->mag_img_filter) {
00163    case PIPE_TEX_FILTER_NEAREST:
00164       sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
00165       break;
00166    case PIPE_TEX_FILTER_LINEAR:
00167       sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
00168       break;
00169    case PIPE_TEX_FILTER_ANISO:
00170       sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
00171       break;
00172    default:
00173       break;
00174    }
00175 
00176    if (pipe_sampler->max_anisotropy > 2.0) {
00177       sampler->ss3.max_aniso = MAX2((pipe_sampler->max_anisotropy - 2) / 2,
00178                                     BRW_ANISORATIO_16);
00179    }
00180 
00181    sampler->ss1.s_wrap_mode = translate_wrap_mode(pipe_sampler->wrap_s);
00182    sampler->ss1.r_wrap_mode = translate_wrap_mode(pipe_sampler->wrap_r);
00183    sampler->ss1.t_wrap_mode = translate_wrap_mode(pipe_sampler->wrap_t);
00184 
00185    /* Fulsim complains if I don't do this.  Hardware doesn't mind:
00186     */
00187 #if 0
00188    if (texObj->Target == GL_TEXTURE_CUBE_MAP_ARB) {
00189       sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CUBE;
00190       sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CUBE;
00191       sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CUBE;
00192    }
00193 #endif
00194 
00195    /* Set shadow function:
00196     */
00197    if (pipe_sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
00198       /* Shadowing is "enabled" by emitting a particular sampler
00199        * message (sample_c).  So need to recompile WM program when
00200        * shadow comparison is enabled on each/any texture unit.
00201        */
00202       sampler->ss0.shadow_function = intel_translate_shadow_compare_func(pipe_sampler->compare_func);
00203    }
00204 
00205    /* Set LOD bias:
00206     */
00207    sampler->ss0.lod_bias = S_FIXED(CLAMP(pipe_sampler->lod_bias, -16, 15), 6);
00208 
00209    sampler->ss0.lod_preclamp = 1; /* OpenGL mode */
00210    sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */
00211 
00212    /* Set BaseMipLevel, MaxLOD, MinLOD:
00213     *
00214     * XXX: I don't think that using firstLevel, lastLevel works,
00215     * because we always setup the surface state as if firstLevel ==
00216     * level zero.  Probably have to subtract firstLevel from each of
00217     * these:
00218     */
00219    sampler->ss0.base_level = U_FIXED(0, 1);
00220 
00221    sampler->ss1.max_lod = U_FIXED(MIN2(MAX2(pipe_sampler->max_lod, 0), 13), 6);
00222    sampler->ss1.min_lod = U_FIXED(MIN2(MAX2(pipe_sampler->min_lod, 0), 13), 6);
00223 
00224    sampler->ss2.default_color_pointer = sdc_gs_offset >> 5;
00225 }

static int intel_translate_shadow_compare_func ( unsigned  func  )  [static]

Definition at line 54 of file brw_wm_sampler_state.c.

References COMPAREFUNC_ALWAYS, COMPAREFUNC_EQUAL, COMPAREFUNC_GEQUAL, COMPAREFUNC_GREATER, COMPAREFUNC_LEQUAL, COMPAREFUNC_LESS, COMPAREFUNC_NEVER, COMPAREFUNC_NOTEQUAL, debug_printf(), PIPE_FUNC_ALWAYS, PIPE_FUNC_EQUAL, PIPE_FUNC_GEQUAL, PIPE_FUNC_GREATER, PIPE_FUNC_LEQUAL, PIPE_FUNC_LESS, PIPE_FUNC_NEVER, and PIPE_FUNC_NOTEQUAL.

00055 {
00056    switch(func) {
00057    case PIPE_FUNC_NEVER:
00058        return COMPAREFUNC_ALWAYS;
00059    case PIPE_FUNC_LESS:
00060        return COMPAREFUNC_LEQUAL;
00061    case PIPE_FUNC_LEQUAL:
00062        return COMPAREFUNC_LESS;
00063    case PIPE_FUNC_GREATER:
00064        return COMPAREFUNC_GEQUAL;
00065    case PIPE_FUNC_GEQUAL:
00066       return COMPAREFUNC_GREATER;
00067    case PIPE_FUNC_NOTEQUAL:
00068       return COMPAREFUNC_EQUAL;
00069    case PIPE_FUNC_EQUAL:
00070       return COMPAREFUNC_NOTEQUAL;
00071    case PIPE_FUNC_ALWAYS:
00072        return COMPAREFUNC_NEVER;
00073    }
00074 
00075    debug_printf("Unknown value in %s: %x\n", __FUNCTION__, func);
00076    return COMPAREFUNC_NEVER;
00077 }

static int S_FIXED ( float  value,
unsigned  frac_bits 
) [static]

Definition at line 108 of file brw_wm_sampler_state.c.

00109 {
00110    return value * (1<<frac_bits);
00111 }

static unsigned translate_wrap_mode ( int  wrap  )  [static]

Definition at line 83 of file brw_wm_sampler_state.c.

References BRW_TEXCOORDMODE_CLAMP, BRW_TEXCOORDMODE_CLAMP_BORDER, BRW_TEXCOORDMODE_MIRROR, BRW_TEXCOORDMODE_WRAP, PIPE_TEX_WRAP_CLAMP, PIPE_TEX_WRAP_CLAMP_TO_BORDER, PIPE_TEX_WRAP_CLAMP_TO_EDGE, PIPE_TEX_WRAP_MIRROR_REPEAT, and PIPE_TEX_WRAP_REPEAT.

00084 {
00085    switch( wrap ) {
00086    case PIPE_TEX_WRAP_REPEAT:
00087       return BRW_TEXCOORDMODE_WRAP;
00088    case PIPE_TEX_WRAP_CLAMP:
00089       return BRW_TEXCOORDMODE_CLAMP;
00090    case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
00091       return BRW_TEXCOORDMODE_CLAMP; /* conform likes it this way */
00092    case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
00093       return BRW_TEXCOORDMODE_CLAMP_BORDER;
00094    case PIPE_TEX_WRAP_MIRROR_REPEAT:
00095       return BRW_TEXCOORDMODE_MIRROR;
00096    default:
00097       return BRW_TEXCOORDMODE_WRAP;
00098    }
00099 }

static unsigned U_FIXED ( float  value,
unsigned  frac_bits 
) [static]

Definition at line 102 of file brw_wm_sampler_state.c.

00103 {
00104    value *= (1<<frac_bits);
00105    return value < 0 ? 0 : value;
00106 }

static unsigned upload_default_color ( struct brw_context brw,
const float *  color 
) [static]

Definition at line 114 of file brw_wm_sampler_state.c.

References brw_cache_data(), BRW_SAMPLER_DEFAULT_COLOR, brw_context::cache, brw_sampler_default_color::color, and COPY_4V.

00116 {
00117    struct brw_sampler_default_color sdc;
00118 
00119    COPY_4V(sdc.color, color);
00120 
00121    return brw_cache_data( &brw->cache[BRW_SAMPLER_DEFAULT_COLOR], &sdc );
00122 }

static void upload_wm_samplers ( struct brw_context brw  )  [static]

Definition at line 233 of file brw_wm_sampler_state.c.

References brw_context::attribs, pipe_sampler_state::border_color, brw_cache_data_sz(), BRW_SAMPLER, brw_update_sampler_state(), brw_context::cache, brw_state_flags::cache, CACHE_NEW_SAMPLER, brw_context::dirty, brw_context::num_samplers, brw_context::num_textures, brw_context::sampler, brw_context::sampler_count, brw_context::sampler_gs_offset, brw_context::Samplers, brw_context::state, brw_context::Texture, upload_default_color(), and brw_context::wm.

00234 {
00235    unsigned unit;
00236    unsigned sampler_count = 0;
00237 
00238    /* BRW_NEW_SAMPLER */
00239    for (unit = 0; unit < brw->num_textures && unit < brw->num_samplers;
00240         unit++) {
00241       /* determine unit enable/disable by looking for a bound texture */
00242       if (brw->attribs.Texture[unit]) {
00243          const struct pipe_sampler_state *sampler = brw->attribs.Samplers[unit];
00244          unsigned sdc_gs_offset = upload_default_color(brw, sampler->border_color);
00245 
00246          brw_update_sampler_state(sampler,
00247                                   sdc_gs_offset,
00248                                   &brw->wm.sampler[unit]);
00249 
00250          sampler_count = unit + 1;
00251       }
00252    }
00253 
00254    if (brw->wm.sampler_count != sampler_count) {
00255       brw->wm.sampler_count = sampler_count;
00256       brw->state.dirty.cache |= CACHE_NEW_SAMPLER;
00257    }
00258 
00259    brw->wm.sampler_gs_offset = 0;
00260 
00261    if (brw->wm.sampler_count)
00262       brw->wm.sampler_gs_offset =
00263          brw_cache_data_sz(&brw->cache[BRW_SAMPLER],
00264                            brw->wm.sampler,
00265                            sizeof(struct brw_sampler_state) * brw->wm.sampler_count);
00266 }


Variable Documentation

struct brw_tracked_state brw_wm_samplers

Initial value:

 {
   .dirty = {
      .brw =  0x400 ,
      .cache = 0
   },
   .update = upload_wm_samplers
}

Definition at line 268 of file brw_wm_sampler_state.c.


Generated on Tue Sep 29 06:25:39 2009 for Gallium3D by  doxygen 1.5.4