softpipe: remove the 32bits limitation on depth(-stencil) formats

This patch remove the 32bits limitation. As a side effect, it bring the support for the GL_ARB_depth_buffer_float extension.
No regression have been found on piglit, and all tests for GL_ARB_depth_buffer_float pass successfully.

Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Morgan Armand
2011-12-07 21:30:48 +01:00
committed by Dave Airlie
parent 2ae591bdf1
commit e763b6e788
6 changed files with 91 additions and 21 deletions

View File

@@ -344,6 +344,31 @@ z32f_x24s8_get_tile_rgba(const float *src,
}
}
/*** PIPE_FORMAT_X32_S8X24_UINT ***/
/**
* Return S component as four uint32_t in [0..255]. Z part ignored.
*/
static void
x32_s8_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
float *p,
unsigned dst_stride)
{
unsigned i, j;
for (i = 0; i < h; i++) {
float *pRow = p;
for (j = 0; j < w; j++, pRow += 4) {
src++;
pRow[0] =
pRow[1] =
pRow[2] =
pRow[3] = (float)(*src++ & 0xff);
}
p += dst_stride;
}
}
void
pipe_tile_raw_to_rgba(enum pipe_format format,
@@ -381,6 +406,9 @@ pipe_tile_raw_to_rgba(enum pipe_format format,
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
z32f_x24s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
break;
case PIPE_FORMAT_X32_S8X24_UINT:
x32_s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
break;
default:
util_format_read_4f(format,
dst, dst_stride * sizeof(float),

View File

@@ -50,7 +50,7 @@ softpipe_clear(struct pipe_context *pipe, unsigned buffers,
double depth, unsigned stencil)
{
struct softpipe_context *softpipe = softpipe_context(pipe);
unsigned cv;
uint64_t cv;
uint i;
if (softpipe->no_rast)
@@ -73,7 +73,7 @@ softpipe_clear(struct pipe_context *pipe, unsigned buffers,
static const union pipe_color_union zero;
struct pipe_surface *ps = softpipe->framebuffer.zsbuf;
cv = util_pack_z_stencil(ps->format, depth, stencil);
cv = util_pack64_z_stencil(ps->format, depth, stencil);
sp_tile_cache_clear(softpipe->zsbuf_cache, &zero, cv);
}

View File

@@ -32,6 +32,7 @@
#include "pipe/p_defines.h"
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "tgsi/tgsi_scan.h"
#include "sp_context.h"
@@ -102,6 +103,21 @@ get_depth_stencil_values( struct depth_data *data,
data->stencilVals[j] = tile->data.stencil8[y][x];
}
break;
case PIPE_FORMAT_Z32_FLOAT:
for (j = 0; j < QUAD_SIZE; j++) {
int x = quad->input.x0 % TILE_SIZE + (j & 1);
int y = quad->input.y0 % TILE_SIZE + (j >> 1);
data->bzzzz[j] = tile->data.depth32[y][x];
}
break;
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
for (j = 0; j < QUAD_SIZE; j++) {
int x = quad->input.x0 % TILE_SIZE + (j & 1);
int y = quad->input.y0 % TILE_SIZE + (j >> 1);
data->bzzzz[j] = tile->data.depth64[y][x] & 0xffffffff;
data->stencilVals[j] = (tile->data.depth64[y][x] >> 32) & 0xff;
}
break;
default:
assert(0);
}
@@ -182,6 +198,17 @@ convert_quad_depth( struct depth_data *data,
}
}
break;
case PIPE_FORMAT_Z32_FLOAT:
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
{
union fi fui;
for (j = 0; j < QUAD_SIZE; j++) {
fui.f = quad->output.depth[j];
data->qzzzz[j] = fui.ui;
}
}
break;
default:
assert(0);
}
@@ -207,6 +234,8 @@ convert_quad_stencil( struct depth_data *data,
case PIPE_FORMAT_X8Z24_UNORM:
case PIPE_FORMAT_S8_UINT_Z24_UNORM:
case PIPE_FORMAT_S8_UINT:
case PIPE_FORMAT_Z32_FLOAT:
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
for (j = 0; j < QUAD_SIZE; j++) {
data->shader_stencil_refs[j] = ((unsigned)(quad->output.stencil[j]));
}
@@ -272,7 +301,20 @@ write_depth_stencil_values( struct depth_data *data,
tile->data.stencil8[y][x] = data->stencilVals[j];
}
break;
case PIPE_FORMAT_Z32_FLOAT:
for (j = 0; j < QUAD_SIZE; j++) {
int x = quad->input.x0 % TILE_SIZE + (j & 1);
int y = quad->input.y0 % TILE_SIZE + (j >> 1);
tile->data.depth32[y][x] = data->bzzzz[j];
}
break;
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
for (j = 0; j < QUAD_SIZE; j++) {
int x = quad->input.x0 % TILE_SIZE + (j & 1);
int y = quad->input.y0 % TILE_SIZE + (j >> 1);
tile->data.depth64[y][x] = (uint64_t)data->bzzzz[j] | ((uint64_t)data->stencilVals[j] << 32);
}
break;
default:
assert(0);
}

View File

@@ -250,19 +250,6 @@ softpipe_is_format_supported( struct pipe_screen *screen,
if (bind & PIPE_BIND_DEPTH_STENCIL) {
if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
return FALSE;
/*
* TODO: Unfortunately we cannot render into anything more than 32 bits
* because we encode depth and stencil clear values into a 32bit word.
*/
if (format_desc->block.bits > 32)
return FALSE;
/*
* TODO: eliminate this restriction
*/
if (format == PIPE_FORMAT_Z32_FLOAT)
return FALSE;
}
/*

View File

@@ -268,7 +268,7 @@ clear_tile_rgba(struct softpipe_cached_tile *tile,
static void
clear_tile(struct softpipe_cached_tile *tile,
enum pipe_format format,
uint clear_value)
uint64_t clear_value)
{
uint i, j;
@@ -295,7 +295,19 @@ clear_tile(struct softpipe_cached_tile *tile,
else {
for (i = 0; i < TILE_SIZE; i++) {
for (j = 0; j < TILE_SIZE; j++) {
tile->data.color32[i][j] = clear_value;
tile->data.depth32[i][j] = clear_value;
}
}
}
break;
case 8:
if (clear_value == 0) {
memset(tile->data.any, 0, 8 * TILE_SIZE * TILE_SIZE);
}
else {
for (i = 0; i < TILE_SIZE; i++) {
for (j = 0; j < TILE_SIZE; j++) {
tile->data.depth64[i][j] = clear_value;
}
}
}
@@ -601,7 +613,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
void
sp_tile_cache_clear(struct softpipe_tile_cache *tc,
const union pipe_color_union *color,
uint clearValue)
uint64_t clearValue)
{
uint pos;

View File

@@ -70,6 +70,7 @@ struct softpipe_cached_tile
ubyte stencil8[TILE_SIZE][TILE_SIZE];
uint colorui128[TILE_SIZE][TILE_SIZE][4];
int colori128[TILE_SIZE][TILE_SIZE][4];
uint64_t depth64[TILE_SIZE][TILE_SIZE];
ubyte any[1];
} data;
};
@@ -88,7 +89,7 @@ struct softpipe_tile_cache
struct softpipe_cached_tile *entries[NUM_ENTRIES];
uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
union pipe_color_union clear_color; /**< for color bufs */
uint clear_val; /**< for z+stencil */
uint64_t clear_val; /**< for z+stencil */
boolean depth_stencil; /**< Is the surface a depth/stencil format? */
struct softpipe_cached_tile *tile; /**< scratch tile for clears */
@@ -123,7 +124,7 @@ sp_flush_tile_cache(struct softpipe_tile_cache *tc);
extern void
sp_tile_cache_clear(struct softpipe_tile_cache *tc,
const union pipe_color_union *color,
uint clearValue);
uint64_t clearValue);
extern struct softpipe_cached_tile *
sp_find_cached_tile(struct softpipe_tile_cache *tc,