*/
static void
lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned sampler_unit,
LLVMValueRef width,
LLVMValueRef height,
LLVMValueRef depth,
LLVMValueRef mipoffsets,
LLVMValueRef texel_out[4])
{
- const struct lp_sampler_static_state *static_state = bld->static_state;
+ const struct lp_static_sampler_state *static_state = bld->static_sampler_state;
const unsigned dims = bld->dims;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
/* select texel color or border color depending on use_border */
LLVMValueRef border_color_ptr =
bld->dynamic_state->border_color(bld->dynamic_state,
- bld->gallivm, unit);
+ bld->gallivm, sampler_unit);
int chan;
for (chan = 0; chan < 4; chan++) {
LLVMValueRef border_chan =
lp_build_const_int32(bld->gallivm, chan));
LLVMValueRef border_chan_vec =
lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan);
+
+ if (!bld->texel_type.floating) {
+ border_chan_vec = LLVMBuildBitCast(builder, border_chan_vec,
+ bld->texel_bld.vec_type, "");
+ }
texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
border_chan_vec, texel_out[chan]);
}
break;
case PIPE_TEX_WRAP_CLAMP:
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
struct lp_build_context abs_coord_bld = bld->coord_bld;
abs_coord_bld.type.sign = FALSE;
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* mul by tex size */
coord = lp_build_mul(coord_bld, coord, length_f);
}
}
case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
- {
- LLVMValueRef min;
- if (bld->static_state->normalized_coords) {
- /* scale coord to length */
- coord = lp_build_mul(coord_bld, coord, length_f);
- }
- /* was: clamp to [-0.5, length + 0.5], then sub 0.5 */
- coord = lp_build_sub(coord_bld, coord, half);
- min = lp_build_const_vec(bld->gallivm, coord_bld->type, -1.0F);
- coord = lp_build_clamp(coord_bld, coord, min, length_f);
- /* convert to int, compute lerp weight */
- lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
- coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
+ if (bld->static_sampler_state->normalized_coords) {
+ /* scale coord to length */
+ coord = lp_build_mul(coord_bld, coord, length_f);
}
+ /* was: clamp to [-0.5, length + 0.5], then sub 0.5 */
+ /* can skip clamp (though might not work for very large coord values */
+ coord = lp_build_sub(coord_bld, coord, half);
+ /* convert to int, compute lerp weight */
+ lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
+ coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
break;
case PIPE_TEX_WRAP_MIRROR_REPEAT:
case PIPE_TEX_WRAP_MIRROR_CLAMP:
coord = lp_build_abs(coord_bld, coord);
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
abs_coord_bld.type.sign = FALSE;
coord = lp_build_abs(coord_bld, coord);
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
{
coord = lp_build_abs(coord_bld, coord);
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
/* was: clamp to [-0.5, length + 0.5] then sub 0.5 */
- /* skip -0.5 clamp (always positive), do sub first */
+ /* skip clamp - always positive, and other side
+ only potentially matters for very large coords */
coord = lp_build_sub(coord_bld, coord, half);
- coord = lp_build_min(coord_bld, coord, length_f);
/* convert to int, compute lerp weight */
lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
case PIPE_TEX_WRAP_CLAMP:
case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
break;
case PIPE_TEX_WRAP_CLAMP_TO_BORDER:
- /* Note: this is the same as CLAMP_TO_EDGE, except min = -1 */
- {
- LLVMValueRef min, max;
-
- if (bld->static_state->normalized_coords) {
- /* scale coord to length */
- coord = lp_build_mul(coord_bld, coord, length_f);
- }
-
- icoord = lp_build_ifloor(coord_bld, coord);
-
- /* clamp to [-1, length] */
- min = lp_build_negate(int_coord_bld, int_coord_bld->one);
- max = length;
- icoord = lp_build_clamp(int_coord_bld, icoord, min, max);
+ if (bld->static_sampler_state->normalized_coords) {
+ /* scale coord to length */
+ coord = lp_build_mul(coord_bld, coord, length_f);
}
+ /* no clamp necessary, border masking will handle this */
+ icoord = lp_build_ifloor(coord_bld, coord);
break;
case PIPE_TEX_WRAP_MIRROR_REPEAT:
coord = lp_build_coord_mirror(bld, coord);
/* scale coord to length */
- assert(bld->static_state->normalized_coords);
+ assert(bld->static_sampler_state->normalized_coords);
coord = lp_build_mul(coord_bld, coord, length_f);
/* itrunc == ifloor here */
case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE:
coord = lp_build_abs(coord_bld, coord);
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER:
coord = lp_build_abs(coord_bld, coord);
- if (bld->static_state->normalized_coords) {
+ if (bld->static_sampler_state->normalized_coords) {
/* scale coord to length */
coord = lp_build_mul(coord_bld, coord, length_f);
}
/* itrunc == ifloor here */
icoord = lp_build_itrunc(coord_bld, coord);
-
- /* clamp to [0, length] */
- icoord = lp_build_min(int_coord_bld, icoord, length);
break;
default:
*/
static void
lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned sampler_unit,
LLVMValueRef size,
LLVMValueRef row_stride_vec,
LLVMValueRef img_stride_vec,
* Compute integer texcoords.
*/
x = lp_build_sample_wrap_nearest(bld, s, width_vec, flt_width_vec,
- bld->static_state->pot_width,
- bld->static_state->wrap_s);
+ bld->static_texture_state->pot_width,
+ bld->static_sampler_state->wrap_s);
lp_build_name(x, "tex.x.wrapped");
if (dims >= 2) {
y = lp_build_sample_wrap_nearest(bld, t, height_vec, flt_height_vec,
- bld->static_state->pot_height,
- bld->static_state->wrap_t);
+ bld->static_texture_state->pot_height,
+ bld->static_sampler_state->wrap_t);
lp_build_name(y, "tex.y.wrapped");
if (dims == 3) {
z = lp_build_sample_wrap_nearest(bld, r, depth_vec, flt_depth_vec,
- bld->static_state->pot_depth,
- bld->static_state->wrap_r);
+ bld->static_texture_state->pot_depth,
+ bld->static_sampler_state->wrap_r);
lp_build_name(z, "tex.z.wrapped");
}
}
- if (bld->static_state->target == PIPE_TEXTURE_CUBE ||
- bld->static_state->target == PIPE_TEXTURE_1D_ARRAY ||
- bld->static_state->target == PIPE_TEXTURE_2D_ARRAY) {
+ if (bld->static_texture_state->target == PIPE_TEXTURE_CUBE ||
+ bld->static_texture_state->target == PIPE_TEXTURE_1D_ARRAY ||
+ bld->static_texture_state->target == PIPE_TEXTURE_2D_ARRAY) {
z = r;
lp_build_name(z, "tex.z.layer");
}
/*
* Get texture colors.
*/
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x, y, z,
row_stride_vec, img_stride_vec,
*/
static void
lp_build_sample_image_linear(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned sampler_unit,
LLVMValueRef size,
LLVMValueRef row_stride_vec,
LLVMValueRef img_stride_vec,
* Compute integer texcoords.
*/
lp_build_sample_wrap_linear(bld, s, width_vec, flt_width_vec,
- bld->static_state->pot_width,
- bld->static_state->wrap_s,
+ bld->static_texture_state->pot_width,
+ bld->static_sampler_state->wrap_s,
&x0, &x1, &s_fpart);
lp_build_name(x0, "tex.x0.wrapped");
lp_build_name(x1, "tex.x1.wrapped");
if (dims >= 2) {
lp_build_sample_wrap_linear(bld, t, height_vec, flt_height_vec,
- bld->static_state->pot_height,
- bld->static_state->wrap_t,
+ bld->static_texture_state->pot_height,
+ bld->static_sampler_state->wrap_t,
&y0, &y1, &t_fpart);
lp_build_name(y0, "tex.y0.wrapped");
lp_build_name(y1, "tex.y1.wrapped");
if (dims == 3) {
lp_build_sample_wrap_linear(bld, r, depth_vec, flt_depth_vec,
- bld->static_state->pot_depth,
- bld->static_state->wrap_r,
+ bld->static_texture_state->pot_depth,
+ bld->static_sampler_state->wrap_r,
&z0, &z1, &r_fpart);
lp_build_name(z0, "tex.z0.wrapped");
lp_build_name(z1, "tex.z1.wrapped");
}
}
- if (bld->static_state->target == PIPE_TEXTURE_CUBE ||
- bld->static_state->target == PIPE_TEXTURE_1D_ARRAY ||
- bld->static_state->target == PIPE_TEXTURE_2D_ARRAY) {
+ if (bld->static_texture_state->target == PIPE_TEXTURE_CUBE ||
+ bld->static_texture_state->target == PIPE_TEXTURE_1D_ARRAY ||
+ bld->static_texture_state->target == PIPE_TEXTURE_2D_ARRAY) {
z0 = z1 = r; /* cube face or array layer */
lp_build_name(z0, "tex.z0.layer");
lp_build_name(z1, "tex.z1.layer");
* Get texture colors.
*/
/* get x0/x1 texels */
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x0, y0, z0,
row_stride_vec, img_stride_vec,
data_ptr, mipoffsets, neighbors[0][0]);
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x1, y0, z0,
row_stride_vec, img_stride_vec,
LLVMValueRef colors0[4];
/* get x0/x1 texels at y1 */
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x0, y1, z0,
row_stride_vec, img_stride_vec,
data_ptr, mipoffsets, neighbors[1][0]);
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x1, y1, z0,
row_stride_vec, img_stride_vec,
LLVMValueRef colors1[4];
/* get x0/x1/y0/y1 texels at z1 */
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x0, y0, z1,
row_stride_vec, img_stride_vec,
data_ptr, mipoffsets, neighbors1[0][0]);
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x1, y0, z1,
row_stride_vec, img_stride_vec,
data_ptr, mipoffsets, neighbors1[0][1]);
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x0, y1, z1,
row_stride_vec, img_stride_vec,
data_ptr, mipoffsets, neighbors1[1][0]);
- lp_build_sample_texel_soa(bld, unit,
+ lp_build_sample_texel_soa(bld, sampler_unit,
width_vec, height_vec, depth_vec,
x1, y1, z1,
row_stride_vec, img_stride_vec,
*/
static void
lp_build_sample_mipmap(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned sampler_unit,
unsigned img_filter,
unsigned mip_filter,
LLVMValueRef s,
mipoff0 = lp_build_get_mip_offsets(bld, ilevel0);
}
if (img_filter == PIPE_TEX_FILTER_NEAREST) {
- lp_build_sample_image_nearest(bld, unit,
+ lp_build_sample_image_nearest(bld, sampler_unit,
size0,
row_stride0_vec, img_stride0_vec,
data_ptr0, mipoff0, s, t, r,
}
else {
assert(img_filter == PIPE_TEX_FILTER_LINEAR);
- lp_build_sample_image_linear(bld, unit,
+ lp_build_sample_image_linear(bld, sampler_unit,
size0,
row_stride0_vec, img_stride0_vec,
data_ptr0, mipoff0, s, t, r,
mipoff1 = lp_build_get_mip_offsets(bld, ilevel1);
}
if (img_filter == PIPE_TEX_FILTER_NEAREST) {
- lp_build_sample_image_nearest(bld, unit,
+ lp_build_sample_image_nearest(bld, sampler_unit,
size1,
row_stride1_vec, img_stride1_vec,
data_ptr1, mipoff1, s, t, r,
colors1);
}
else {
- lp_build_sample_image_linear(bld, unit,
+ lp_build_sample_image_linear(bld, sampler_unit,
size1,
row_stride1_vec, img_stride1_vec,
data_ptr1, mipoff1, s, t, r,
}
}
+
+/**
+ * Clamp layer coord to valid values.
+ */
+static LLVMValueRef
+lp_build_layer_coord(struct lp_build_sample_context *bld,
+ unsigned texture_unit,
+ LLVMValueRef layer)
+{
+ LLVMValueRef maxlayer;
+
+ maxlayer = bld->dynamic_state->depth(bld->dynamic_state,
+ bld->gallivm, texture_unit);
+ maxlayer = lp_build_sub(&bld->int_bld, maxlayer, bld->int_bld.one);
+ maxlayer = lp_build_broadcast_scalar(&bld->int_coord_bld, maxlayer);
+ return lp_build_clamp(&bld->int_coord_bld, layer,
+ bld->int_coord_bld.zero, maxlayer);
+
+}
+
+
/**
* Calculate cube face, lod, mip levels.
*/
static void
lp_build_sample_common(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned texture_index,
+ unsigned sampler_index,
LLVMValueRef *s,
LLVMValueRef *t,
LLVMValueRef *r,
LLVMValueRef *ilevel0,
LLVMValueRef *ilevel1)
{
- const unsigned mip_filter = bld->static_state->min_mip_filter;
- const unsigned min_filter = bld->static_state->min_img_filter;
- const unsigned mag_filter = bld->static_state->mag_img_filter;
- const unsigned target = bld->static_state->target;
+ const unsigned mip_filter = bld->static_sampler_state->min_mip_filter;
+ const unsigned min_filter = bld->static_sampler_state->min_img_filter;
+ const unsigned mag_filter = bld->static_sampler_state->mag_img_filter;
+ const unsigned target = bld->static_texture_state->target;
LLVMValueRef first_level;
struct lp_derivatives face_derivs;
face_derivs.ddx_ddy[1] = NULL;
derivs = &face_derivs;
}
- else if (target == PIPE_TEXTURE_1D_ARRAY ||
- target == PIPE_TEXTURE_2D_ARRAY) {
- LLVMValueRef layer, maxlayer;
-
- if (target == PIPE_TEXTURE_1D_ARRAY) {
- layer = *t;
- }
- else {
- layer = *r;
- }
- layer = lp_build_iround(&bld->coord_bld, layer);
- maxlayer = bld->dynamic_state->depth(bld->dynamic_state,
- bld->gallivm, unit);
- maxlayer = lp_build_sub(&bld->int_bld, maxlayer, bld->int_bld.one);
- maxlayer = lp_build_broadcast_scalar(&bld->int_coord_bld, maxlayer);
- *r = lp_build_clamp(&bld->int_coord_bld, layer,
- bld->int_coord_bld.zero, maxlayer);
+ else if (target == PIPE_TEXTURE_1D_ARRAY) {
+ *r = lp_build_iround(&bld->coord_bld, *t);
+ *r = lp_build_layer_coord(bld, texture_index, *r);
+ }
+ else if (target == PIPE_TEXTURE_2D_ARRAY) {
+ *r = lp_build_iround(&bld->coord_bld, *r);
+ *r = lp_build_layer_coord(bld, texture_index, *r);
}
/*
/* Need to compute lod either to choose mipmap levels or to
* distinguish between minification/magnification with one mipmap level.
*/
- lp_build_lod_selector(bld, unit, derivs,
- lod_bias, explicit_lod,
+ lp_build_lod_selector(bld, texture_index, sampler_index,
+ derivs, lod_bias, explicit_lod,
mip_filter,
lod_ipart, lod_fpart);
} else {
* XXX should probably disable that on other llvm versions.
*/
assert(*lod_ipart);
- lp_build_nearest_mip_level(bld, unit, *lod_ipart, ilevel0);
+ lp_build_nearest_mip_level(bld, texture_index, *lod_ipart, ilevel0);
}
else {
first_level = bld->dynamic_state->first_level(bld->dynamic_state,
- bld->gallivm, unit);
+ bld->gallivm, texture_index);
first_level = lp_build_broadcast_scalar(&bld->perquadi_bld, first_level);
*ilevel0 = first_level;
}
break;
case PIPE_TEX_MIPFILTER_NEAREST:
assert(*lod_ipart);
- lp_build_nearest_mip_level(bld, unit, *lod_ipart, ilevel0);
+ lp_build_nearest_mip_level(bld, texture_index, *lod_ipart, ilevel0);
break;
case PIPE_TEX_MIPFILTER_LINEAR:
assert(*lod_ipart);
assert(*lod_fpart);
- lp_build_linear_mip_levels(bld, unit,
+ lp_build_linear_mip_levels(bld, texture_index,
*lod_ipart, lod_fpart,
ilevel0, ilevel1);
break;
*/
static void
lp_build_sample_general(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned sampler_unit,
LLVMValueRef s,
LLVMValueRef t,
LLVMValueRef r,
{
struct lp_build_context *int_bld = &bld->int_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
- const unsigned mip_filter = bld->static_state->min_mip_filter;
- const unsigned min_filter = bld->static_state->min_img_filter;
- const unsigned mag_filter = bld->static_state->mag_img_filter;
+ const unsigned mip_filter = bld->static_sampler_state->min_mip_filter;
+ const unsigned min_filter = bld->static_sampler_state->min_img_filter;
+ const unsigned mag_filter = bld->static_sampler_state->mag_img_filter;
LLVMValueRef texels[4];
unsigned chan;
for (chan = 0; chan < 4; ++chan) {
texels[chan] = lp_build_alloca(bld->gallivm, bld->texel_bld.vec_type, "");
- lp_build_name(texels[chan], "sampler%u_texel_%c_var", unit, "xyzw"[chan]);
+ lp_build_name(texels[chan], "sampler%u_texel_%c_var", sampler_unit, "xyzw"[chan]);
}
if (min_filter == mag_filter) {
/* no need to distinguish between minification and magnification */
- lp_build_sample_mipmap(bld, unit,
+ lp_build_sample_mipmap(bld, sampler_unit,
min_filter, mip_filter,
s, t, r,
ilevel0, ilevel1, lod_fpart,
lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
- lp_build_sample_mipmap(bld, unit,
+ lp_build_sample_mipmap(bld, sampler_unit,
min_filter, mip_filter,
s, t, r,
ilevel0, ilevel1, lod_fpart,
lp_build_else(&if_ctx);
{
/* Use the magnification filter */
- lp_build_sample_mipmap(bld, unit,
+ lp_build_sample_mipmap(bld, sampler_unit,
mag_filter, PIPE_TEX_MIPFILTER_NONE,
s, t, r,
ilevel0, NULL, NULL,
for (chan = 0; chan < 4; ++chan) {
colors_out[chan] = LLVMBuildLoad(builder, texels[chan], "");
- lp_build_name(colors_out[chan], "sampler%u_texel_%c", unit, "xyzw"[chan]);
+ lp_build_name(colors_out[chan], "sampler%u_texel_%c", sampler_unit, "xyzw"[chan]);
}
}
*/
static void
lp_build_fetch_texel(struct lp_build_sample_context *bld,
- unsigned unit,
+ unsigned texture_unit,
const LLVMValueRef *coords,
LLVMValueRef explicit_lod,
const LLVMValueRef *offsets,
struct lp_build_context *perquadi_bld = &bld->perquadi_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
unsigned dims = bld->dims, chan;
+ unsigned target = bld->static_texture_state->target;
LLVMValueRef size, ilevel;
LLVMValueRef row_stride_vec = NULL, img_stride_vec = NULL;
LLVMValueRef x = coords[0], y = coords[1], z = coords[2];
LLVMValueRef offset, out_of_bounds, out1;
/* XXX just like ordinary sampling, we don't handle per-pixel lod (yet). */
- if (explicit_lod && bld->static_state->target != PIPE_BUFFER) {
+ if (explicit_lod && bld->static_texture_state->target != PIPE_BUFFER) {
ilevel = lp_build_pack_aos_scalars(bld->gallivm, int_coord_bld->type,
perquadi_bld->type, explicit_lod, 0);
- lp_build_nearest_mip_level(bld, unit, ilevel, &ilevel);
+ lp_build_nearest_mip_level(bld, texture_unit, ilevel, &ilevel);
}
else {
bld->num_lods = 1;
lp_build_extract_image_sizes(bld, &bld->int_size_bld, int_coord_bld->type,
size, &width, &height, &depth);
+ if (target == PIPE_TEXTURE_1D_ARRAY ||
+ target == PIPE_TEXTURE_2D_ARRAY) {
+ if (target == PIPE_TEXTURE_1D_ARRAY) {
+ z = lp_build_layer_coord(bld, texture_unit, y);
+ }
+ else {
+ z = lp_build_layer_coord(bld, texture_unit, z);
+ }
+ }
+
/* This is a lot like border sampling */
if (offsets[0]) {
/* XXX coords are really unsigned, offsets are signed */
x, y, z, row_stride_vec, img_stride_vec,
&offset, &i, &j);
- if (bld->static_state->target != PIPE_BUFFER) {
+ if (bld->static_texture_state->target != PIPE_BUFFER) {
offset = lp_build_add(int_coord_bld, offset,
lp_build_get_mip_offsets(bld, ilevel));
}
LLVMValueRef res, p;
const unsigned chan = 0;
- if (bld->static_state->compare_mode == PIPE_TEX_COMPARE_NONE)
+ if (bld->static_sampler_state->compare_mode == PIPE_TEX_COMPARE_NONE)
return;
- if (bld->static_state->target == PIPE_TEXTURE_2D_ARRAY ||
- bld->static_state->target == PIPE_TEXTURE_CUBE) {
+ if (bld->static_texture_state->target == PIPE_TEXTURE_2D_ARRAY ||
+ bld->static_texture_state->target == PIPE_TEXTURE_CUBE) {
p = coords[3];
}
else {
bld->coord_bld.one);
/* result = (p FUNC texel) ? 1 : 0 */
- res = lp_build_cmp(texel_bld, bld->static_state->compare_func,
+ res = lp_build_cmp(texel_bld, bld->static_sampler_state->compare_func,
p, texel[chan]);
res = lp_build_select(texel_bld, res, texel_bld->one, texel_bld->zero);
*/
void
lp_build_sample_soa(struct gallivm_state *gallivm,
- const struct lp_sampler_static_state *static_state,
+ const struct lp_static_texture_state *static_texture_state,
+ const struct lp_static_sampler_state *static_sampler_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type type,
boolean is_fetch,
- unsigned unit,
+ unsigned texture_index,
+ unsigned sampler_index,
const LLVMValueRef *coords,
const LLVMValueRef *offsets,
const struct lp_derivatives *derivs,
LLVMValueRef explicit_lod, /* optional */
LLVMValueRef texel_out[4])
{
- unsigned dims = texture_dims(static_state->target);
+ unsigned dims = texture_dims(static_texture_state->target);
unsigned num_quads = type.length / 4;
- unsigned mip_filter = static_state->min_mip_filter;
+ unsigned mip_filter;
struct lp_build_sample_context bld;
+ struct lp_static_sampler_state derived_sampler_state = *static_sampler_state;
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef tex_width, tex_height, tex_depth;
LLVMValueRef r;
if (0) {
- enum pipe_format fmt = static_state->format;
+ enum pipe_format fmt = static_texture_state->format;
debug_printf("Sample from %s\n", util_format_name(fmt));
}
/* Setup our build context */
memset(&bld, 0, sizeof bld);
bld.gallivm = gallivm;
- bld.static_state = static_state;
+ bld.static_sampler_state = &derived_sampler_state;
+ bld.static_texture_state = static_texture_state;
bld.dynamic_state = dynamic_state;
- bld.format_desc = util_format_description(static_state->format);
+ bld.format_desc = util_format_description(static_texture_state->format);
bld.dims = dims;
bld.vector_width = lp_type_width(type);
bld.perquadf_type.length = type.length > 4 ? ((type.length + 15) / 16) * 4 : 1;
bld.perquadi_type = lp_int_type(bld.perquadf_type);
+ /* always using the first channel hopefully should be safe,
+ * if not things WILL break in other places anyway.
+ */
+ if (bld.format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB &&
+ bld.format_desc->channel[0].pure_integer) {
+ if (bld.format_desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+ bld.texel_type = lp_type_int_vec(type.width, type.width * type.length);
+ }
+ else if (bld.format_desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED) {
+ bld.texel_type = lp_type_uint_vec(type.width, type.width * type.length);
+ }
+ }
+
+ if (!static_texture_state->level_zero_only) {
+ derived_sampler_state.min_mip_filter = static_sampler_state->min_mip_filter;
+ } else {
+ derived_sampler_state.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ }
+ mip_filter = derived_sampler_state.min_mip_filter;
+
+ if (0) {
+ debug_printf(" .min_mip_filter = %u\n", derived_sampler_state.min_mip_filter);
+ }
+
/*
* There are other situations where at least the multiple int lods could be
* avoided like min and max lod being equal.
*/
- if ((is_fetch && explicit_lod && bld.static_state->target != PIPE_BUFFER) ||
+ if ((is_fetch && explicit_lod && bld.static_texture_state->target != PIPE_BUFFER) ||
(!is_fetch && mip_filter != PIPE_TEX_MIPFILTER_NONE)) {
bld.num_lods = num_quads;
}
lp_build_context_init(&bld.perquadi_bld, gallivm, bld.perquadi_type);
/* Get the dynamic state */
- tex_width = dynamic_state->width(dynamic_state, gallivm, unit);
- tex_height = dynamic_state->height(dynamic_state, gallivm, unit);
- tex_depth = dynamic_state->depth(dynamic_state, gallivm, unit);
- bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit);
- bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit);
- bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm, unit);
- bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm, unit);
+ tex_width = dynamic_state->width(dynamic_state, gallivm, texture_index);
+ tex_height = dynamic_state->height(dynamic_state, gallivm, texture_index);
+ tex_depth = dynamic_state->depth(dynamic_state, gallivm, texture_index);
+ bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, texture_index);
+ bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, texture_index);
+ bld.base_ptr = dynamic_state->base_ptr(dynamic_state, gallivm, texture_index);
+ bld.mip_offsets = dynamic_state->mip_offsets(dynamic_state, gallivm, texture_index);
/* Note that mip_offsets is an array[level] of offsets to texture images */
s = coords[0];
coords,
texel_out);
}
+
+ else if (is_fetch) {
+ lp_build_fetch_texel(&bld, texture_index, coords,
+ explicit_lod, offsets,
+ texel_out);
+ }
+
else {
LLVMValueRef lod_ipart = NULL, lod_fpart = NULL;
LLVMValueRef ilevel0 = NULL, ilevel1 = NULL;
boolean use_aos = util_format_fits_8unorm(bld.format_desc) &&
- lp_is_simple_wrap_mode(static_state->wrap_s) &&
- lp_is_simple_wrap_mode(static_state->wrap_t);
+ lp_is_simple_wrap_mode(static_sampler_state->wrap_s) &&
+ lp_is_simple_wrap_mode(static_sampler_state->wrap_t);
if ((gallivm_debug & GALLIVM_DEBUG_PERF) &&
!use_aos && util_format_fits_8unorm(bld.format_desc)) {
debug_printf("%s: using floating point linear filtering for %s\n",
__FUNCTION__, bld.format_desc->short_name);
debug_printf(" min_img %d mag_img %d mip %d wraps %d wrapt %d\n",
- static_state->min_img_filter,
- static_state->mag_img_filter,
- static_state->min_mip_filter,
- static_state->wrap_s,
- static_state->wrap_t);
- }
-
- if (is_fetch) {
- lp_build_fetch_texel(&bld, unit, coords,
- explicit_lod, offsets,
- texel_out);
-
- if (static_state->target != PIPE_BUFFER) {
- apply_sampler_swizzle(&bld, texel_out);
- }
-
- return;
+ static_sampler_state->min_img_filter,
+ static_sampler_state->mag_img_filter,
+ static_sampler_state->min_mip_filter,
+ static_sampler_state->wrap_s,
+ static_sampler_state->wrap_t);
}
- lp_build_sample_common(&bld, unit,
+ lp_build_sample_common(&bld, texture_index, sampler_index,
&s, &t, &r,
derivs, lod_bias, explicit_lod,
&lod_ipart, &lod_fpart,
}
if (use_aos) {
/* do sampling/filtering with fixed pt arithmetic */
- lp_build_sample_aos(&bld, unit,
+ lp_build_sample_aos(&bld, sampler_index,
s, t, r,
lod_ipart, lod_fpart,
ilevel0, ilevel1,
}
else {
- lp_build_sample_general(&bld, unit,
+ lp_build_sample_general(&bld, sampler_index,
s, t, r,
lod_ipart, lod_fpart,
ilevel0, ilevel1,
/* Setup our build context */
memset(&bld4, 0, sizeof bld4);
bld4.gallivm = bld.gallivm;
- bld4.static_state = bld.static_state;
+ bld4.static_texture_state = bld.static_texture_state;
+ bld4.static_sampler_state = bld.static_sampler_state;
bld4.dynamic_state = bld.dynamic_state;
bld4.format_desc = bld.format_desc;
bld4.dims = bld.dims;
bld4.float_size_in_type = lp_type_float(32);
bld4.float_size_in_type.length = dims > 1 ? 4 : 1;
bld4.int_size_in_type = lp_int_type(bld4.float_size_in_type);
- bld4.texel_type = type4;
+ bld4.texel_type = bld.texel_type;
+ bld4.texel_type.length = 4;
bld4.perquadf_type = type4;
/* we want native vector size to be able to use our intrinsics */
bld4.perquadf_type.length = 1;
if (use_aos) {
/* do sampling/filtering with fixed pt arithmetic */
- lp_build_sample_aos(&bld4, unit,
+ lp_build_sample_aos(&bld4, sampler_index,
s4, t4, r4,
lod_iparts, lod_fparts,
ilevel0s, ilevel1s,
}
else {
- lp_build_sample_general(&bld4, unit,
+ lp_build_sample_general(&bld4, sampler_index,
s4, t4, r4,
lod_iparts, lod_fparts,
ilevel0s, ilevel1s,
texel_out[j] = lp_build_concat(gallivm, texelouttmp[j], type4, num_quads);
}
}
+
+ lp_build_sample_compare(&bld, coords, texel_out);
}
- lp_build_sample_compare(&bld, coords, texel_out);
+ if (static_texture_state->target != PIPE_BUFFER) {
+ apply_sampler_swizzle(&bld, texel_out);
+ }
- apply_sampler_swizzle(&bld, texel_out);
+ /*
+ * texel type can be a (32bit) int/uint (for pure int formats only),
+ * however we are expected to always return floats (storage is untyped).
+ */
+ if (!bld.texel_type.floating) {
+ unsigned chan;
+ for (chan = 0; chan < 4; chan++) {
+ texel_out[chan] = LLVMBuildBitCast(builder, texel_out[chan],
+ lp_build_vec_type(gallivm, type), "");
+ }
+ }
}
void
lp_build_size_query_soa(struct gallivm_state *gallivm,
- const struct lp_sampler_static_state *static_state,
+ const struct lp_static_texture_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type int_type,
- unsigned unit,
+ unsigned texture_unit,
+ boolean need_nr_mips,
LLVMValueRef explicit_lod,
LLVMValueRef *sizes_out)
{
LLVMValueRef lod;
LLVMValueRef size;
+ LLVMValueRef first_level = NULL;
int dims, i;
+ boolean has_array;
struct lp_build_context bld_int_vec;
+ dims = texture_dims(static_state->target);
+
switch (static_state->target) {
- case PIPE_TEXTURE_1D:
- case PIPE_BUFFER:
- dims = 1;
- break;
- case PIPE_TEXTURE_2D:
- case PIPE_TEXTURE_CUBE:
- case PIPE_TEXTURE_RECT:
- dims = 2;
- break;
- case PIPE_TEXTURE_3D:
- dims = 3;
+ case PIPE_TEXTURE_1D_ARRAY:
+ case PIPE_TEXTURE_2D_ARRAY:
+ has_array = TRUE;
break;
-
default:
- assert(0);
- return;
+ has_array = FALSE;
+ break;
}
assert(!int_type.floating);
lp_build_context_init(&bld_int_vec, gallivm, lp_type_int_vec(32, 128));
if (explicit_lod) {
- LLVMValueRef first_level;
lod = LLVMBuildExtractElement(gallivm->builder, explicit_lod, lp_build_const_int32(gallivm, 0), "");
- first_level = dynamic_state->first_level(dynamic_state, gallivm, unit);
+ first_level = dynamic_state->first_level(dynamic_state, gallivm, texture_unit);
lod = lp_build_broadcast_scalar(&bld_int_vec,
LLVMBuildAdd(gallivm->builder, lod, first_level, "lod"));
lod = bld_int_vec.zero;
}
- size = bld_int_vec.undef;
+ if (need_nr_mips) {
+ size = bld_int_vec.zero;
+ }
+ else {
+ size = bld_int_vec.undef;
+ }
size = LLVMBuildInsertElement(gallivm->builder, size,
- dynamic_state->width(dynamic_state, gallivm, unit),
+ dynamic_state->width(dynamic_state, gallivm, texture_unit),
lp_build_const_int32(gallivm, 0), "");
if (dims >= 2) {
size = LLVMBuildInsertElement(gallivm->builder, size,
- dynamic_state->height(dynamic_state, gallivm, unit),
+ dynamic_state->height(dynamic_state, gallivm, texture_unit),
lp_build_const_int32(gallivm, 1), "");
}
if (dims >= 3) {
size = LLVMBuildInsertElement(gallivm->builder, size,
- dynamic_state->depth(dynamic_state, gallivm, unit),
+ dynamic_state->depth(dynamic_state, gallivm, texture_unit),
lp_build_const_int32(gallivm, 2), "");
}
size = lp_build_minify(&bld_int_vec, size, lod);
- for (i=0; i < dims; i++) {
+ if (has_array)
+ size = LLVMBuildInsertElement(gallivm->builder, size,
+ dynamic_state->depth(dynamic_state, gallivm, texture_unit),
+ lp_build_const_int32(gallivm, dims), "");
+
+ /*
+ * XXX for out-of-bounds lod, should set size to zero vector here
+ * (for dx10-style only, i.e. need_nr_mips)
+ */
+
+ for (i = 0; i < dims + (has_array ? 1 : 0); i++) {
sizes_out[i] = lp_build_extract_broadcast(gallivm, bld_int_vec.type, int_type,
size,
lp_build_const_int32(gallivm, i));
}
+
+ /*
+ * if there's no explicit_lod (buffers, rects) queries requiring nr of
+ * mips would be illegal.
+ */
+ if (need_nr_mips && explicit_lod) {
+ struct lp_build_context bld_int_scalar;
+ LLVMValueRef num_levels;
+ lp_build_context_init(&bld_int_scalar, gallivm, lp_type_int(32));
+
+ if (static_state->level_zero_only) {
+ num_levels = bld_int_scalar.one;
+ }
+ else {
+ LLVMValueRef last_level;
+
+ last_level = dynamic_state->last_level(dynamic_state, gallivm, texture_unit);
+ num_levels = lp_build_sub(&bld_int_scalar, last_level, first_level);
+ num_levels = lp_build_add(&bld_int_scalar, num_levels, bld_int_scalar.one);
+ }
+ sizes_out[3] = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm, int_type),
+ num_levels);
+ }
}