Distinguish among texture targets in codegen.
progs/demos/cubemap.c runs correctly now too.
static boolean
-emit_TXP(struct codegen *gen, const struct tgsi_full_instruction *inst)
+emit_TEX(struct codegen *gen, const struct tgsi_full_instruction *inst)
{
- const uint addr = lookup_function(gen->cell, "spu_txp");
+ const uint target = inst->InstructionExtTexture.Texture;
const uint unit = inst->FullSrcRegisters[1].SrcRegister.Index;
+ uint addr;
int ch;
int coord_regs[4], d_regs[4];
+ switch (target) {
+ case TGSI_TEXTURE_1D:
+ case TGSI_TEXTURE_2D:
+ addr = lookup_function(gen->cell, "spu_tex_2d");
+ break;
+ case TGSI_TEXTURE_3D:
+ addr = lookup_function(gen->cell, "spu_tex_3d");
+ break;
+ case TGSI_TEXTURE_CUBE:
+ addr = lookup_function(gen->cell, "spu_tex_cube");
+ break;
+ default:
+ ASSERT(0 && "unsupported texture target");
+ return FALSE;
+ }
+
assert(inst->FullSrcRegisters[1].SrcRegister.File == TGSI_FILE_SAMPLER);
- spe_comment(gen->f, -4, "CALL txp:");
+ spe_comment(gen->f, -4, "CALL tex:");
/* get src/dst reg info */
for (ch = 0; ch < 4; ch++) {
spe_stqd(gen->f, reg, SPE_REG_SP, 16 * offset);
}
- /* setup function arguments */
+ /* setup function arguments (XXX depends on target) */
for (i = 0; i < 4; i++) {
spe_move(gen->f, 3 + i, coord_regs[i]);
}
/* fall-through for now */
case TGSI_OPCODE_TXB:
/* fall-through for now */
+ case TGSI_OPCODE_TXL:
+ /* fall-through for now */
case TGSI_OPCODE_TXP:
- return emit_TXP(gen, inst);
+ return emit_TEX(gen, inst);
case TGSI_OPCODE_IF:
return emit_IF(gen, inst);
*/
static void
update_tex_masks(struct spu_texture *texture,
- const struct pipe_sampler_state *sampler,
- uint unit)
+ const struct pipe_sampler_state *sampler)
{
uint i;
texture->level[i].scale_t = spu_splats(1.0f);
}
}
-
- /* XXX temporary hack */
- if (texture->target == PIPE_TEXTURE_CUBE) {
- spu.sample_texture4[unit] = sample_texture4_cube;
- }
}
switch (spu.sampler[unit].min_img_filter) {
case PIPE_TEX_FILTER_LINEAR:
- spu.min_sample_texture4[unit] = sample_texture4_bilinear;
+ spu.min_sample_texture_2d[unit] = sample_texture_2d_bilinear;
break;
case PIPE_TEX_FILTER_ANISO:
/* fall-through, for now */
case PIPE_TEX_FILTER_NEAREST:
- spu.min_sample_texture4[unit] = sample_texture4_nearest;
+ spu.min_sample_texture_2d[unit] = sample_texture_2d_nearest;
break;
default:
ASSERT(0);
switch (spu.sampler[sampler->unit].mag_img_filter) {
case PIPE_TEX_FILTER_LINEAR:
- spu.mag_sample_texture4[unit] = sample_texture4_bilinear;
+ spu.mag_sample_texture_2d[unit] = sample_texture_2d_bilinear;
break;
case PIPE_TEX_FILTER_ANISO:
/* fall-through, for now */
case PIPE_TEX_FILTER_NEAREST:
- spu.mag_sample_texture4[unit] = sample_texture4_nearest;
+ spu.mag_sample_texture_2d[unit] = sample_texture_2d_nearest;
break;
default:
ASSERT(0);
switch (spu.sampler[sampler->unit].min_mip_filter) {
case PIPE_TEX_MIPFILTER_NEAREST:
case PIPE_TEX_MIPFILTER_LINEAR:
- spu.sample_texture4[unit] = sample_texture4_lod;
+ spu.sample_texture_2d[unit] = sample_texture_2d_lod;
break;
case PIPE_TEX_MIPFILTER_NONE:
- spu.sample_texture4[unit] = spu.mag_sample_texture4[unit];
+ spu.sample_texture_2d[unit] = spu.mag_sample_texture_2d[unit];
break;
default:
ASSERT(0);
}
- update_tex_masks(&spu.texture[unit], &spu.sampler[unit], unit);
+ update_tex_masks(&spu.texture[unit], &spu.sampler[unit]);
}
spu.texture[unit].max_level = i;
}
- update_tex_masks(&spu.texture[unit], &spu.sampler[unit], unit);
+ update_tex_masks(&spu.texture[unit], &spu.sampler[unit]);
}
#include "cell/common.h"
#include "spu_main.h"
#include "spu_funcs.h"
+#include "spu_texture.h"
/** For "return"-ing four vectors */
static struct vec_4x4
-spu_txp(vector float s, vector float t, vector float r, vector float q,
- unsigned unit)
+spu_tex_2d(vector float s, vector float t, vector float r, vector float q,
+ unsigned unit)
{
struct vec_4x4 colors;
- spu.sample_texture4[unit](s, t, r, q, unit, 0, 0, colors.v);
+ (void) r;
+ (void) q;
+ spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v);
+ return colors;
+}
+
+static struct vec_4x4
+spu_tex_3d(vector float s, vector float t, vector float r, vector float q,
+ unsigned unit)
+{
+ struct vec_4x4 colors;
+ (void) r;
+ (void) q;
+ spu.sample_texture_2d[unit](s, t, unit, 0, 0, colors.v);
+ return colors;
+}
+
+static struct vec_4x4
+spu_tex_cube(vector float s, vector float t, vector float r, vector float q,
+ unsigned unit)
+{
+ struct vec_4x4 colors;
+ (void) q;
+ sample_texture_cube(s, t, r, unit, colors.v);
return colors;
}
export_func(&funcs, "spu_pow", &spu_pow);
export_func(&funcs, "spu_exp2", &spu_exp2);
export_func(&funcs, "spu_log2", &spu_log2);
- export_func(&funcs, "spu_txp", &spu_txp);
+ export_func(&funcs, "spu_tex_2d", &spu_tex_2d);
+ export_func(&funcs, "spu_tex_3d", &spu_tex_3d);
+ export_func(&funcs, "spu_tex_cube", &spu_tex_cube);
/* Send the function info back to the PPU / main memory */
mfc_put((void *) &funcs, /* src in local store */
/** Function for sampling textures */
-typedef void (*spu_sample_texture4_func)(vector float s,
- vector float t,
- vector float r,
- vector float q,
- uint unit, uint level, uint face,
- vector float colors[4]);
+typedef void (*spu_sample_texture_2d_func)(vector float s,
+ vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4]);
/** Function for performing per-fragment ops */
spu_fragment_program_func fragment_program;
/** Current texture sampler function */
- spu_sample_texture4_func sample_texture4[CELL_MAX_SAMPLERS];
- spu_sample_texture4_func min_sample_texture4[CELL_MAX_SAMPLERS];
- spu_sample_texture4_func mag_sample_texture4[CELL_MAX_SAMPLERS];
+ spu_sample_texture_2d_func sample_texture_2d[CELL_MAX_SAMPLERS];
+ spu_sample_texture_2d_func min_sample_texture_2d[CELL_MAX_SAMPLERS];
+ spu_sample_texture_2d_func mag_sample_texture_2d[CELL_MAX_SAMPLERS];
/** Fragment program constants */
vector float constants[4 * CELL_MAX_CONSTANTS];
* \param colors returned colors in SOA format (rrrr, gggg, bbbb, aaaa).
*/
void
-sample_texture4_nearest(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4])
+sample_texture_2d_nearest(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4])
{
const struct spu_texture_level *tlevel = &spu.texture[unit].level[level];
vector float ss = spu_mul(s, tlevel->scale_s);
* \param colors returned colors in SOA format (rrrr, gggg, bbbb, aaaa).
*/
void
-sample_texture4_bilinear(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4])
+sample_texture_2d_bilinear(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4])
{
const struct spu_texture_level *tlevel = &spu.texture[unit].level[level];
static const vector float half = {-0.5f, -0.5f, -0.5f, -0.5f};
* Bilinear filtering, using int intead of float arithmetic
*/
void
-sample_texture4_bilinear_2(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4])
+sample_texture_2d_bilinear_int(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4])
{
const struct spu_texture_level *tlevel = &spu.texture[unit].level[level];
static const vector float half = {-0.5f, -0.5f, -0.5f, -0.5f};
* Texture sampling with level of detail selection.
*/
void
-sample_texture4_lod(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level_ignored, uint face,
- vector float colors[4])
+sample_texture_2d_lod(vector float s, vector float t,
+ uint unit, uint level_ignored, uint face,
+ vector float colors[4])
{
/*
* Note that we're computing a lambda/lod here that's used for all
*/
float lambda = compute_lambda(unit, s, t);
+ (void) face;
+ (void) level_ignored;
+
/* apply lod bias */
lambda += spu.sampler[unit].lod_bias;
if (lambda <= 0.0f) {
/* magnify */
- spu.mag_sample_texture4[unit](s, t, r, q, unit, 0, 0, colors);
+ spu.mag_sample_texture_2d[unit](s, t, unit, 0, 0, colors);
}
else {
/* minify */
int level = (int) (lambda + 0.5f);
if (level > (int) spu.texture[unit].max_level)
level = spu.texture[unit].max_level;
- spu.min_sample_texture4[unit](s, t, r, q, unit, level, 0, colors);
+ spu.min_sample_texture_2d[unit](s, t, unit, level, 0, colors);
/* XXX to do: mipmap level interpolation */
}
}
void
-sample_texture4_cube(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face_ignored,
- vector float colors[4])
+sample_texture_cube(vector float s, vector float t, vector float r,
+ uint unit, vector float colors[4])
{
- static const vector float zero = {0.0f, 0.0f, 0.0f, 0.0f};
- uint p, faces[4];
+ uint p, faces[4], level = 0;
float newS[4], newT[4];
/* Compute cube face referenced by the four sets of texcoords.
/* GOOD! All four texcoords refer to the same cube face */
s = (vector float) {newS[0], newS[1], newS[2], newS[3]};
t = (vector float) {newT[0], newT[1], newT[2], newT[3]};
- sample_texture4_nearest(s, t, zero, zero, unit, level, faces[0], colors);
+ sample_texture_2d_nearest(s, t, unit, level, faces[0], colors);
}
else {
/* BAD! The four texcoords refer to different faces */
for (p = 0; p < 4; p++) {
vector float c[4];
- sample_texture4_nearest(spu_splats(newS[p]), spu_splats(newT[p]),
- zero, zero, unit, level, faces[p], c);
+ sample_texture_2d_nearest(spu_splats(newS[p]), spu_splats(newT[p]),
+ unit, level, faces[p], c);
float red = spu_extract(c[0], p);
float green = spu_extract(c[1], p);
extern void
-sample_texture4_nearest(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4]);
+sample_texture_2d_nearest(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4]);
extern void
-sample_texture4_bilinear(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4]);
-
-extern void
-sample_texture4_bilinear_2(vector float s, vector float t,
- vector float r, vector float q,
+sample_texture_2d_bilinear(vector float s, vector float t,
uint unit, uint level, uint face,
vector float colors[4]);
+extern void
+sample_texture_2d_bilinear_int(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4]);
+
extern void
-sample_texture4_lod(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level, uint face,
- vector float colors[4]);
+sample_texture_2d_lod(vector float s, vector float t,
+ uint unit, uint level, uint face,
+ vector float colors[4]);
extern void
-sample_texture4_cube(vector float s, vector float t,
- vector float r, vector float q,
- uint unit, uint level_ignored, uint face_ignored,
- vector float colors[4]);
+sample_texture_cube(vector float s, vector float t, vector float r,
+ uint unit, vector float colors[4]);
#endif /* SPU_TEXTURE_H */