diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/r300/r300_context.h | 9 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_emit.c | 47 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_texture.c | 34 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_texture.h | 1 |
4 files changed, 87 insertions, 4 deletions
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index f22569e6fee..e032a309063 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -96,6 +96,9 @@ struct r300_scissor_state { }; struct r300_texture_state { + uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */ + uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */ + uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */ }; #define R300_NEW_BLEND 0x0000001 @@ -107,8 +110,10 @@ struct r300_texture_state { #define R300_NEW_RASTERIZER 0x0000040 #define R300_NEW_RS_BLOCK 0x0000080 #define R300_NEW_SAMPLER 0x0000100 +#define R300_ANY_NEW_SAMPLERS 0x000ff00 #define R300_NEW_SCISSOR 0x0010000 #define R300_NEW_TEXTURE 0x0020000 +#define R300_ANY_NEW_TEXTURES 0x1fe0000 #define R300_NEW_VERTEX_FORMAT 0x2000000 #define R300_NEW_VERTEX_SHADER 0x4000000 #define R300_NEW_KITCHEN_SINK 0x7ffffff @@ -199,6 +204,9 @@ struct r300_texture { /* Pipe buffer backing this texture. */ struct pipe_buffer* buffer; + + /* Registers carrying texture format data. */ + struct r300_texture_state state; }; struct r300_vertex_format { @@ -247,7 +255,6 @@ struct r300_context { struct r300_scissor_state* scissor_state; /* Texture states. */ struct r300_texture* textures[8]; - struct r300_texture_state* texture_states[8]; int texture_count; /* Vertex buffers. */ struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index da5f2058c50..1c4a7d9aa09 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -248,6 +248,18 @@ void r300_emit_rs_block_state(struct r300_context* r300, END_CS; } +void r300_emit_sampler(struct r300_context* r300, + struct r300_sampler_state* sampler, unsigned offset) +{ + CS_LOCALS(r300); + + BEGIN_CS(6); + OUT_CS_REG(R300_TX_FILTER0_0 + (offset * 4), sampler->filter0); + OUT_CS_REG(R300_TX_FILTER1_0 + (offset * 4), sampler->filter1); + OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (offset * 4), sampler->border_color); + END_CS; +} + void r300_emit_scissor_state(struct r300_context* r300, struct r300_scissor_state* scissor) { @@ -260,6 +272,21 @@ void r300_emit_scissor_state(struct r300_context* r300, END_CS; } +void r300_emit_texture(struct r300_context* r300, + struct r300_texture* tex, unsigned offset) +{ + CS_LOCALS(r300); + + BEGIN_CS(8); + OUT_CS_REG(R300_TX_FORMAT0_0 + (offset * 4), tex->state.format0); + OUT_CS_REG(R300_TX_FORMAT1_0 + (offset * 4), tex->state.format1); + OUT_CS_REG(R300_TX_FORMAT2_0 + (offset * 4), tex->state.format2); + OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (offset * 4), 1); + OUT_CS_RELOC(tex->buffer, 0, 0, RADEON_GEM_DOMAIN_GTT | + RADEON_GEM_DOMAIN_VRAM, 0); + END_CS; +} + void r300_emit_vertex_format_state(struct r300_context* r300) { CS_LOCALS(r300); @@ -290,7 +317,7 @@ void r300_emit_vertex_format_state(struct r300_context* r300) void r300_emit_dirty_state(struct r300_context* r300) { struct r300_screen* r300screen = r300_screen(r300->context.screen); - CS_LOCALS(r300); + int i; if (!(r300->dirty_state) && !(r300->dirty_hw)) { return; @@ -341,11 +368,29 @@ void r300_emit_dirty_state(struct r300_context* r300) r300->dirty_state &= ~R300_NEW_RS_BLOCK; } + if (r300->dirty_state & R300_ANY_NEW_SAMPLERS) { + for (i = 0; i < r300->sampler_count; i++) { + if (r300->dirty_state & (R300_NEW_SAMPLER << i)) { + r300_emit_sampler(r300, r300->sampler_states[i], i); + r300->dirty_state &= ~(R300_NEW_SAMPLER << i); + } + } + } + if (r300->dirty_state & R300_NEW_SCISSOR) { r300_emit_scissor_state(r300, r300->scissor_state); r300->dirty_state &= ~R300_NEW_SCISSOR; } + if (r300->dirty_state & R300_ANY_NEW_TEXTURES) { + for (i = 0; i < r300->texture_count; i++) { + if (r300->dirty_state & (R300_NEW_TEXTURE << i)) { + r300_emit_texture(r300, r300->textures[i], i); + r300->dirty_state &= ~(R300_NEW_TEXTURE << i); + } + } + } + if (r300->dirty_state & R300_NEW_VERTEX_FORMAT) { r300_emit_vertex_format_state(r300); r300->dirty_state &= ~R300_NEW_VERTEX_FORMAT; diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index b7027553b57..ae388c73606 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -27,6 +27,30 @@ static int minify(int i) return MAX2(1, i >> 1); } +static void r300_setup_texture_state(struct r300_texture* tex, + unsigned width, + unsigned height, + unsigned pitch) +{ + struct r300_texture_state* state = &tex->state; + + state->format0 = R300_TX_WIDTH((width - 1) & 0x7ff) | + R300_TX_HEIGHT((height - 1) & 0x7ff) | R300_TX_PITCH_EN; + + /* XXX */ + state->format1 = R300_TX_FORMAT_A8R8G8B8; + + state->format2 = pitch - 1; + + /* XXX + if (width > 2048) { + state->pitch |= R300_TXWIDTH_11; + } + if (height > 2048) { + state->pitch |= R300_TXHEIGHT_11; + } */ +} + static void r300_setup_miptree(struct r300_texture* tex) { struct pipe_texture* base = &tex->tex; @@ -44,11 +68,10 @@ static void r300_setup_miptree(struct r300_texture* tex) base->nblocksy[i] = pf_get_nblocksy(&base->block, base->width[i]); /* Radeons enjoy things in multiples of 32. */ - /* XXX NPOT -> 64, not 32 */ + /* XXX this can be 32 when POT */ stride = (base->nblocksx[i] * base->block.size + 63) & ~63; size = stride * base->nblocksy[i] * base->depth[i]; - /* XXX 64 for NPOT */ tex->offset[i] = (tex->size + 63) & ~63; tex->size = tex->offset[i] + size; } @@ -73,6 +96,10 @@ static struct pipe_texture* r300_setup_miptree(tex); + /* XXX */ + r300_setup_texture_state(tex, tex->tex.width[0], tex->tex.height[0], + tex->tex.width[0]); + tex->buffer = screen->buffer_create(screen, 64, PIPE_BUFFER_USAGE_PIXEL, tex->size); @@ -153,6 +180,9 @@ static struct pipe_texture* tex->stride = *stride; + r300_setup_texture_state(tex, tex->tex.width[0], tex->tex.height[0], + tex->stride); + pipe_buffer_reference(&tex->buffer, buffer); return (struct pipe_texture*)tex; diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index 27f5ea1eb7b..98fb5c9a08f 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -28,6 +28,7 @@ #include "util/u_math.h" #include "r300_context.h" +#include "r300_reg.h" void r300_init_screen_texture_functions(struct pipe_screen* screen); |