r300g: There is no such thing as "texture stride"
Individual texture images have a stride, but textures as a whole do not. There are still pieces of code which are confused about this, but the core of the confusion is hopefully gone. Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
This commit is contained in:
parent
57d16c4cc3
commit
3cb30e55e4
|
@ -184,8 +184,15 @@ struct r300_texture {
|
||||||
/* Offsets into the buffer. */
|
/* Offsets into the buffer. */
|
||||||
unsigned offset[PIPE_MAX_TEXTURE_LEVELS];
|
unsigned offset[PIPE_MAX_TEXTURE_LEVELS];
|
||||||
|
|
||||||
/* Stride (pitch?) of this texture in bytes */
|
/**
|
||||||
unsigned stride;
|
* If non-zero, override the natural texture layout with
|
||||||
|
* a custom stride (in bytes).
|
||||||
|
*
|
||||||
|
* \note Mipmapping fails for textures with a non-natural layout!
|
||||||
|
*
|
||||||
|
* \sa r300_texture_get_stride
|
||||||
|
*/
|
||||||
|
unsigned stride_override;
|
||||||
|
|
||||||
/* Total size of this texture, in bytes. */
|
/* Total size of this texture, in bytes. */
|
||||||
unsigned size;
|
unsigned size;
|
||||||
|
|
|
@ -283,7 +283,7 @@ void r300_emit_fb_state(struct r300_context* r300,
|
||||||
for (i = 0; i < fb->nr_cbufs; i++) {
|
for (i = 0; i < fb->nr_cbufs; i++) {
|
||||||
tex = (struct r300_texture*)fb->cbufs[i]->texture;
|
tex = (struct r300_texture*)fb->cbufs[i]->texture;
|
||||||
assert(tex && tex->buffer && "cbuf is marked, but NULL!");
|
assert(tex && tex->buffer && "cbuf is marked, but NULL!");
|
||||||
pixpitch = tex->stride / tex->tex.block.size;
|
pixpitch = r300_texture_get_stride(tex, 0) / tex->tex.block.size;
|
||||||
|
|
||||||
OUT_CS_REG_SEQ(R300_RB3D_COLOROFFSET0 + (4 * i), 1);
|
OUT_CS_REG_SEQ(R300_RB3D_COLOROFFSET0 + (4 * i), 1);
|
||||||
OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
|
OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
|
||||||
|
@ -300,7 +300,7 @@ void r300_emit_fb_state(struct r300_context* r300,
|
||||||
if (fb->zsbuf) {
|
if (fb->zsbuf) {
|
||||||
tex = (struct r300_texture*)fb->zsbuf->texture;
|
tex = (struct r300_texture*)fb->zsbuf->texture;
|
||||||
assert(tex && tex->buffer && "zsbuf is marked, but NULL!");
|
assert(tex && tex->buffer && "zsbuf is marked, but NULL!");
|
||||||
pixpitch = tex->stride / tex->tex.block.size;
|
pixpitch = r300_texture_get_stride(tex, 0) / tex->tex.block.size;
|
||||||
|
|
||||||
OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1);
|
OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1);
|
||||||
OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
|
OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_VRAM, 0);
|
||||||
|
|
|
@ -323,13 +323,14 @@ r300_get_tex_transfer(struct pipe_screen *screen,
|
||||||
if (trans) {
|
if (trans) {
|
||||||
pipe_texture_reference(&trans->transfer.texture, texture);
|
pipe_texture_reference(&trans->transfer.texture, texture);
|
||||||
trans->transfer.format = texture->format;
|
trans->transfer.format = texture->format;
|
||||||
|
trans->transfer.x = x;
|
||||||
|
trans->transfer.y = y;
|
||||||
trans->transfer.width = w;
|
trans->transfer.width = w;
|
||||||
trans->transfer.height = h;
|
trans->transfer.height = h;
|
||||||
trans->transfer.block = texture->block;
|
trans->transfer.block = texture->block;
|
||||||
trans->transfer.nblocksx = texture->nblocksx[level];
|
trans->transfer.nblocksx = texture->nblocksx[level];
|
||||||
trans->transfer.nblocksy = texture->nblocksy[level];
|
trans->transfer.nblocksy = texture->nblocksy[level];
|
||||||
trans->transfer.stride = align(pf_get_stride(&trans->transfer.block,
|
trans->transfer.stride = r300_texture_get_stride(tex, level);
|
||||||
texture->width[level]), 32);
|
|
||||||
trans->transfer.usage = usage;
|
trans->transfer.usage = usage;
|
||||||
trans->offset = offset;
|
trans->offset = offset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ static void r300_surface_setup(struct r300_context* r300,
|
||||||
unsigned w, unsigned h)
|
unsigned w, unsigned h)
|
||||||
{
|
{
|
||||||
struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps;
|
struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps;
|
||||||
unsigned pixpitch = dest->stride / dest->tex.block.size;
|
unsigned pixpitch = r300_texture_get_stride(dest, 0) / dest->tex.block.size;
|
||||||
CS_LOCALS(r300);
|
CS_LOCALS(r300);
|
||||||
|
|
||||||
r300_emit_blend_state(r300, &blend_clear_state);
|
r300_emit_blend_state(r300, &blend_clear_state);
|
||||||
|
@ -100,7 +100,7 @@ static void r300_surface_fill(struct pipe_context* pipe,
|
||||||
struct r300_context* r300 = r300_context(pipe);
|
struct r300_context* r300 = r300_context(pipe);
|
||||||
struct r300_capabilities* caps = r300_screen(pipe->screen)->caps;
|
struct r300_capabilities* caps = r300_screen(pipe->screen)->caps;
|
||||||
struct r300_texture* tex = (struct r300_texture*)dest->texture;
|
struct r300_texture* tex = (struct r300_texture*)dest->texture;
|
||||||
unsigned pixpitch = tex->stride / tex->tex.block.size;
|
unsigned pixpitch = r300_texture_get_stride(tex, 0) / tex->tex.block.size;
|
||||||
boolean invalid = FALSE;
|
boolean invalid = FALSE;
|
||||||
CS_LOCALS(r300);
|
CS_LOCALS(r300);
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ static void r300_surface_copy(struct pipe_context* pipe,
|
||||||
struct r300_capabilities* caps = r300_screen(pipe->screen)->caps;
|
struct r300_capabilities* caps = r300_screen(pipe->screen)->caps;
|
||||||
struct r300_texture* srctex = (struct r300_texture*)src->texture;
|
struct r300_texture* srctex = (struct r300_texture*)src->texture;
|
||||||
struct r300_texture* desttex = (struct r300_texture*)dest->texture;
|
struct r300_texture* desttex = (struct r300_texture*)dest->texture;
|
||||||
unsigned pixpitch = srctex->stride / srctex->tex.block.size;
|
unsigned pixpitch = r300_texture_get_stride(srctex, 0) / srctex->tex.block.size;
|
||||||
boolean invalid = FALSE;
|
boolean invalid = FALSE;
|
||||||
float fsrcx = srcx, fsrcy = srcy, fdestx = destx, fdesty = desty;
|
float fsrcx = srcx, fsrcy = srcy, fdestx = destx, fdesty = desty;
|
||||||
CS_LOCALS(r300);
|
CS_LOCALS(r300);
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
static void r300_setup_texture_state(struct r300_texture* tex,
|
static void r300_setup_texture_state(struct r300_texture* tex,
|
||||||
unsigned width,
|
unsigned width,
|
||||||
unsigned height,
|
unsigned height,
|
||||||
unsigned pitch,
|
|
||||||
unsigned levels)
|
unsigned levels)
|
||||||
{
|
{
|
||||||
struct r300_texture_state* state = &tex->state;
|
struct r300_texture_state* state = &tex->state;
|
||||||
|
@ -38,7 +37,7 @@ static void r300_setup_texture_state(struct r300_texture* tex,
|
||||||
/* XXX */
|
/* XXX */
|
||||||
state->format1 = r300_translate_texformat(tex->tex.format);
|
state->format1 = r300_translate_texformat(tex->tex.format);
|
||||||
|
|
||||||
state->format2 = pitch - 1;
|
state->format2 = r300_texture_get_stride(tex, 0);
|
||||||
|
|
||||||
/* Assume (somewhat foolishly) that oversized textures will
|
/* Assume (somewhat foolishly) that oversized textures will
|
||||||
* not be permitted by the state tracker. */
|
* not be permitted by the state tracker. */
|
||||||
|
@ -50,13 +49,30 @@ static void r300_setup_texture_state(struct r300_texture* tex,
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf("r300: Set texture state (%dx%d, pitch %d, %d levels)\n",
|
debug_printf("r300: Set texture state (%dx%d, pitch %d, %d levels)\n",
|
||||||
width, height, pitch, levels);
|
width, height, levels);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the stride, in bytes, of the texture images of the given texture
|
||||||
|
* at the given level.
|
||||||
|
*/
|
||||||
|
unsigned r300_texture_get_stride(struct r300_texture* tex, unsigned level)
|
||||||
|
{
|
||||||
|
if (tex->stride_override)
|
||||||
|
return tex->stride_override;
|
||||||
|
|
||||||
|
if (level > tex->tex.last_level) {
|
||||||
|
debug_printf("%s: level (%u) > last_level (%u)\n", level, tex->tex.last_level);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return align(pf_get_stride(&tex->tex.block, tex->tex.width[level]), 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void r300_setup_miptree(struct r300_texture* tex)
|
static void r300_setup_miptree(struct r300_texture* tex)
|
||||||
{
|
{
|
||||||
struct pipe_texture* base = &tex->tex;
|
struct pipe_texture* base = &tex->tex;
|
||||||
int stride, size, offset;
|
int stride, size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i <= base->last_level; i++) {
|
for (i = 0; i <= base->last_level; i++) {
|
||||||
|
@ -74,7 +90,7 @@ static void r300_setup_miptree(struct r300_texture* tex)
|
||||||
* XXX
|
* XXX
|
||||||
* POT, uncompressed, unmippmapped textures can be aligned to 32,
|
* POT, uncompressed, unmippmapped textures can be aligned to 32,
|
||||||
* instead of 64. */
|
* instead of 64. */
|
||||||
stride = align(pf_get_stride(&base->block, base->width[i]), 32);
|
stride = r300_texture_get_stride(tex, i);
|
||||||
size = stride * base->nblocksy[i] * base->depth[i];
|
size = stride * base->nblocksy[i] * base->depth[i];
|
||||||
|
|
||||||
tex->offset[i] = align(tex->size, 32);
|
tex->offset[i] = align(tex->size, 32);
|
||||||
|
@ -84,10 +100,6 @@ static void r300_setup_miptree(struct r300_texture* tex)
|
||||||
"(%dx%dx%d px, pitch %d bytes)\n",
|
"(%dx%dx%d px, pitch %d bytes)\n",
|
||||||
i, base->width[i], base->height[i], base->depth[i],
|
i, base->width[i], base->height[i], base->depth[i],
|
||||||
stride);
|
stride);
|
||||||
/* Save stride of first level to the texture. */
|
|
||||||
if (i == 0) {
|
|
||||||
tex->stride = stride;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +121,7 @@ static struct pipe_texture*
|
||||||
r300_setup_miptree(tex);
|
r300_setup_miptree(tex);
|
||||||
|
|
||||||
r300_setup_texture_state(tex, template->width[0], template->height[0],
|
r300_setup_texture_state(tex, template->width[0], template->height[0],
|
||||||
template->width[0], template->last_level);
|
template->last_level);
|
||||||
|
|
||||||
tex->buffer = screen->buffer_create(screen, 1024,
|
tex->buffer = screen->buffer_create(screen, 1024,
|
||||||
PIPE_BUFFER_USAGE_PIXEL,
|
PIPE_BUFFER_USAGE_PIXEL,
|
||||||
|
@ -189,11 +201,10 @@ static struct pipe_texture*
|
||||||
pipe_reference_init(&tex->tex.reference, 1);
|
pipe_reference_init(&tex->tex.reference, 1);
|
||||||
tex->tex.screen = screen;
|
tex->tex.screen = screen;
|
||||||
|
|
||||||
tex->stride = *stride;
|
tex->stride_override = *stride;
|
||||||
|
|
||||||
/* XXX */
|
/* XXX */
|
||||||
r300_setup_texture_state(tex, tex->tex.width[0], tex->tex.height[0],
|
r300_setup_texture_state(tex, tex->tex.width[0], tex->tex.height[0], 0);
|
||||||
tex->stride, 0);
|
|
||||||
|
|
||||||
pipe_buffer_reference(&tex->buffer, buffer);
|
pipe_buffer_reference(&tex->buffer, buffer);
|
||||||
|
|
||||||
|
@ -221,7 +232,7 @@ boolean r300_get_texture_buffer(struct pipe_texture* texture,
|
||||||
pipe_buffer_reference(buffer, tex->buffer);
|
pipe_buffer_reference(buffer, tex->buffer);
|
||||||
|
|
||||||
if (stride) {
|
if (stride) {
|
||||||
*stride = tex->stride;
|
*stride = r300_texture_get_stride(tex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -30,8 +30,12 @@
|
||||||
#include "r300_context.h"
|
#include "r300_context.h"
|
||||||
#include "r300_reg.h"
|
#include "r300_reg.h"
|
||||||
|
|
||||||
|
struct r300_texture;
|
||||||
|
|
||||||
void r300_init_screen_texture_functions(struct pipe_screen* screen);
|
void r300_init_screen_texture_functions(struct pipe_screen* screen);
|
||||||
|
|
||||||
|
unsigned r300_texture_get_stride(struct r300_texture* tex, unsigned level);
|
||||||
|
|
||||||
/* Note the signature of R300_EASY_TX_FORMAT(A, R, G, B, FORMAT)... */
|
/* Note the signature of R300_EASY_TX_FORMAT(A, R, G, B, FORMAT)... */
|
||||||
static INLINE uint32_t r300_translate_texformat(enum pipe_format format)
|
static INLINE uint32_t r300_translate_texformat(enum pipe_format format)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue