};
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
#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
/* Pipe buffer backing this texture. */
struct pipe_buffer* buffer;
+
+ /* Registers carrying texture format data. */
+ struct r300_texture_state state;
};
struct r300_vertex_format {
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];
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)
{
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);
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;
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;
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;
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;
}
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);
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;
#include "util/u_math.h"
#include "r300_context.h"
+#include "r300_reg.h"
void r300_init_screen_texture_functions(struct pipe_screen* screen);