Move z-test code into do_depth_test().
Add ZSIZE symbol to support 2 or 4-byte Z values.
/* how much vertex data */
vertex_bytes = render->num_verts * vertex_size;
index_bytes = render->num_indexes * sizeof(ushort);
- if (index_bytes < 8)
- index_bytes = 8;
+ if (index_bytes < 16)
+ index_bytes = 16;
else
index_bytes = (index_bytes + 15) & ~0xf; /* multiple of 16 */
/* Start fetching color/z tiles. We'll wait for completion when
* we need read/write to them later in triangle rasterization.
*/
- if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) {
+ if (spu.depth_stencil.depth.enabled) {
if (tile_status_z[ty][tx] != TILE_STATUS_CLEAR) {
get_tile(tx, ty, (uint *) ztile, TAG_READ_TILE_Z, 1);
}
put_tile(tx, ty, (uint *) ctile, TAG_WRITE_TILE_COLOR, 0);
tile_status[ty][tx] = TILE_STATUS_DEFINED;
}
- if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) {
+ if (spu.depth_stencil.depth.enabled) {
if (tile_status_z[ty][tx] == TILE_STATUS_DIRTY) {
put_tile(tx, ty, (uint *) ztile, TAG_WRITE_TILE_Z, 1);
tile_status_z[ty][tx] = TILE_STATUS_DEFINED;
/* XXX move these... */
wait_on_mask(1 << TAG_WRITE_TILE_COLOR);
- if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) {
+ if (spu.depth_stencil.depth.enabled) {
wait_on_mask(1 << TAG_WRITE_TILE_Z);
}
}
spu.fb.height = cmd->height;
spu.fb.width_tiles = (spu.fb.width + TILE_SIZE - 1) / TILE_SIZE;
spu.fb.height_tiles = (spu.fb.height + TILE_SIZE - 1) / TILE_SIZE;
+
+ if (cmd->depth_format == PIPE_FORMAT_Z16_UNORM) {
+ ASSERT(ZSIZE == 2);
+ }
+ else if (cmd->depth_format == PIPE_FORMAT_Z32_UNORM) {
+ ASSERT(ZSIZE == 4);
+ }
+
}
printf("SPU %u: DEPTH_STENCIL: ztest %d\n",
spu.init.id,
state->depth.enabled);
- /*
+
memcpy(&spu.depth_stencil, state, sizeof(*state));
- */
+
}
#include "pipe/cell/common.h"
#include "pipe/p_state.h"
+/** XXX temp bytes/z value */
+#define ZSIZE 2
struct spu_framebuffer {
void *color_start; /**< addr of color surface in main memory */
uint ctile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#if ZSIZE == 2
ushort ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#else
+uint ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#endif
ubyte tile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
ubyte tile_status_z[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
get_tile(uint tx, uint ty, uint *tile, int tag, int zBuf)
{
const uint offset = ty * spu.fb.width_tiles + tx;
- const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? 2 : 4);
+ const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? ZSIZE : 4);
const ubyte *src = zBuf ? spu.fb.depth_start : spu.fb.color_start;
src += offset * bytesPerTile;
put_tile(uint tx, uint ty, const uint *tile, int tag, int zBuf)
{
const uint offset = ty * spu.fb.width_tiles + tx;
- const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? 2 : 4);
+ const uint bytesPerTile = TILE_SIZE * TILE_SIZE * (zBuf ? ZSIZE : 4);
ubyte *dst = zBuf ? spu.fb.depth_start : spu.fb.color_start;
dst += offset * bytesPerTile;
spu.init.id,
tile, (unsigned int) dst, bytesPerTile);
*/
-
mfc_put((void *) tile, /* src in local memory */
(unsigned int) dst, /* dst in main memory */
bytesPerTile,
}
void
-clear_tile_z(ushort tile[TILE_SIZE][TILE_SIZE], uint value)
+clear_tile_z(
+#if ZSIZE == 2
+ ushort tile[TILE_SIZE][TILE_SIZE],
+#else
+ uint tile[TILE_SIZE][TILE_SIZE],
+#endif
+ uint value)
{
uint i, j;
for (i = 0; i < TILE_SIZE; i++) {
extern uint ctile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#if ZSIZE == 2
extern ushort ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#else
+extern uint ztile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+#endif
#define TILE_STATUS_CLEAR 1
clear_tile(uint tile[TILE_SIZE][TILE_SIZE], uint value);
void
-clear_tile_z(ushort tile[TILE_SIZE][TILE_SIZE], uint value);
+clear_tile_z(
+#if ZSIZE == 2
+ ushort tile[TILE_SIZE][TILE_SIZE],
+#else
+ uint tile[TILE_SIZE][TILE_SIZE],
+#endif
+ uint value);
#endif /* SPU_TILE_H */
eval_z( struct setup_stage *setup,
float x, float y, float result[4])
{
- uint slot = 0;
- uint i = 2;
+ const uint slot = 0;
+ const uint i = 2;
const float *dadx = setup->coef[slot].dadx;
const float *dady = setup->coef[slot].dady;
}
+static uint
+do_depth_test(struct setup_stage *setup, int x, int y, unsigned mask)
+{
+ int ix = x - setup->cliprect_minx;
+ int iy = y - setup->cliprect_miny;
+ float zvals[4];
+ float zscale = 65535.0;
+
+ if (ZSIZE == 2) {
+ ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM);
+ }
+ else {
+ ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z32_UNORM);
+ }
+ ASSERT(sizeof(ztile[0][0]) == ZSIZE);
+
+
+ eval_z(setup, (float) x, (float) y, zvals);
+
+ if (tile_status_z[setup->ty][setup->tx] == TILE_STATUS_CLEAR) {
+ /* now, _really_ clear the tile */
+ clear_tile_z(ztile, spu.fb.depth_clear_value);
+ }
+ else {
+ /* make sure we've got the tile from main mem */
+ wait_on_mask(1 << TAG_READ_TILE_Z);
+ }
+ tile_status_z[setup->ty][setup->tx] = TILE_STATUS_DIRTY;
+
+
+ if (mask & MASK_TOP_LEFT) {
+ uint z = (uint) (zvals[0] * zscale);
+ if (z < ztile[iy][ix])
+ ztile[iy][ix] = z;
+ else
+ mask &= ~MASK_TOP_LEFT;
+ }
+
+ if (mask & MASK_TOP_RIGHT) {
+ uint z = (uint) (zvals[1] * zscale);
+ if (z < ztile[iy][ix+1])
+ ztile[iy][ix+1] = z;
+ else
+ mask &= ~MASK_TOP_RIGHT;
+ }
+
+ if (mask & MASK_BOTTOM_LEFT) {
+ uint z = (uint) (zvals[2] * zscale);
+ if (z < ztile[iy+1][ix])
+ ztile[iy+1][ix] = z;
+ else
+ mask &= ~MASK_BOTTOM_LEFT;
+ }
+
+ if (mask & MASK_BOTTOM_RIGHT) {
+ uint z = (uint) (zvals[3] * zscale);
+ if (z < ztile[iy+1][ix+1])
+ ztile[iy+1][ix+1] = z;
+ else
+ mask &= ~MASK_BOTTOM_RIGHT;
+ }
+
+ return mask;
+}
+
+
/**
* Emit a quad (pass to next stage). No clipping is done.
*/
sp->quad.first->run(sp->quad.first, &setup->quad);
#else
/* Cell: "write" quad fragments to the tile by setting prim color */
- int ix = x - setup->cliprect_minx;
- int iy = y - setup->cliprect_miny;
+ const int ix = x - setup->cliprect_minx;
+ const int iy = y - setup->cliprect_miny;
float colors[4][4];
- uint z;
eval_coeff(setup, 1, (float) x, (float) y, colors);
- if (spu.fb.depth_format == PIPE_FORMAT_Z16_UNORM) {
- float zvals[4];
- eval_z(setup, (float) x, (float) y, zvals);
-
- if (tile_status_z[setup->ty][setup->tx] == TILE_STATUS_CLEAR) {
- /* now, _really_ clear the tile */
- clear_tile_z(ztile, spu.fb.depth_clear_value);
- }
- else {
- /* make sure we've got the tile from main mem */
- wait_on_mask(1 << TAG_READ_TILE_Z);
- }
- tile_status_z[setup->ty][setup->tx] = TILE_STATUS_DIRTY;
-
- if (mask & MASK_TOP_LEFT) {
- z = (uint) (zvals[0] * 65535.0);
- if (z < ztile[iy][ix])
- ztile[iy][ix] = z;
- else
- mask &= ~MASK_TOP_LEFT;
- }
-
- if (mask & MASK_TOP_RIGHT) {
- z = (uint) (zvals[1] * 65535.0);
- if (z < ztile[iy][ix+1])
- ztile[iy][ix+1] = z;
- else
- mask &= ~MASK_TOP_RIGHT;
- }
-
- if (mask & MASK_BOTTOM_LEFT) {
- z = (uint) (zvals[2] * 65535.0);
- if (z < ztile[iy+1][ix])
- ztile[iy+1][ix] = z;
- else
- mask &= ~MASK_BOTTOM_LEFT;
- }
-
- if (mask & MASK_BOTTOM_RIGHT) {
- z = (uint) (zvals[3] * 65535.0);
- if (z < ztile[iy+1][ix+1])
- ztile[iy+1][ix+1] = z;
- else
- mask &= ~MASK_BOTTOM_RIGHT;
- }
+ if (spu.depth_stencil.depth.enabled) {
+ mask &= do_depth_test(setup, x, y, mask);
}
if (mask) {