summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r300
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/r300')
-rw-r--r--src/gallium/drivers/r300/Makefile5
-rw-r--r--src/gallium/drivers/r300/SConscript1
-rw-r--r--src/gallium/drivers/r300/r300_blit.c13
-rw-r--r--src/gallium/drivers/r300/r300_context.c87
-rw-r--r--src/gallium/drivers/r300/r300_context.h105
-rw-r--r--src/gallium/drivers/r300/r300_emit.c455
-rw-r--r--src/gallium/drivers/r300/r300_emit.h54
-rw-r--r--src/gallium/drivers/r300/r300_flush.c6
-rw-r--r--src/gallium/drivers/r300/r300_fs.c8
-rw-r--r--src/gallium/drivers/r300/r300_reg.h3
-rw-r--r--src/gallium/drivers/r300/r300_render.c243
-rw-r--r--src/gallium/drivers/r300/r300_screen.c137
-rw-r--r--src/gallium/drivers/r300/r300_screen.h22
-rw-r--r--src/gallium/drivers/r300/r300_state.c435
-rw-r--r--src/gallium/drivers/r300/r300_state_derived.c262
-rw-r--r--src/gallium/drivers/r300/r300_state_inlines.h170
-rw-r--r--src/gallium/drivers/r300/r300_state_invariant.c3
-rw-r--r--src/gallium/drivers/r300/r300_state_invariant.h3
-rw-r--r--src/gallium/drivers/r300/r300_texture.c614
-rw-r--r--src/gallium/drivers/r300/r300_texture.h240
-rw-r--r--src/gallium/drivers/r300/r300_transfer.c270
-rw-r--r--src/gallium/drivers/r300/r300_transfer.h31
-rw-r--r--src/gallium/drivers/r300/r300_vs.c167
-rw-r--r--src/gallium/drivers/r300/r300_vs.h13
-rw-r--r--src/gallium/drivers/r300/r300_winsys.h5
25 files changed, 1935 insertions, 1417 deletions
diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile
index afddcb161fa..61b54af4ddf 100644
--- a/src/gallium/drivers/r300/Makefile
+++ b/src/gallium/drivers/r300/Makefile
@@ -19,7 +19,8 @@ C_SOURCES = \
r300_state_invariant.c \
r300_vs.c \
r300_texture.c \
- r300_tgsi_to_rc.c
+ r300_tgsi_to_rc.c \
+ r300_transfer.c
LIBRARY_INCLUDES = \
-I$(TOP)/src/mesa/drivers/dri/r300/compiler \
@@ -32,7 +33,5 @@ EXTRA_OBJECTS = \
include ../../Makefile.template
-.PHONY : $(COMPILER_ARCHIVE)
-
$(COMPILER_ARCHIVE):
$(MAKE) -C $(TOP)/src/mesa/drivers/dri/r300/compiler
diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript
index 183aa17f9b3..27b2e309932 100644
--- a/src/gallium/drivers/r300/SConscript
+++ b/src/gallium/drivers/r300/SConscript
@@ -30,6 +30,7 @@ r300 = env.ConvenienceLibrary(
'r300_vs.c',
'r300_texture.c',
'r300_tgsi_to_rc.c',
+ 'r300_transfer.c',
] + r300compiler) + r300compiler
Export('r300')
diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c
index c48684fe51f..a60b12844d6 100644
--- a/src/gallium/drivers/r300/r300_blit.c
+++ b/src/gallium/drivers/r300/r300_blit.c
@@ -33,7 +33,10 @@ static void r300_blitter_save_states(struct r300_context* r300)
util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref));
util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
util_blitter_save_fragment_shader(r300->blitter, r300->fs);
- util_blitter_save_vertex_shader(r300->blitter, r300->vs);
+ util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state);
+ util_blitter_save_viewport(r300->blitter, &r300->viewport);
+ util_blitter_save_clip(r300->blitter, &r300->clip);
+ util_blitter_save_vertex_elements(r300->blitter, r300->velems);
}
/* Clear currently bound buffers. */
@@ -98,6 +101,8 @@ static void r300_hw_copy(struct pipe_context* pipe,
unsigned width, unsigned height)
{
struct r300_context* r300 = r300_context(pipe);
+ struct r300_textures_state* state =
+ (struct r300_textures_state*)r300->textures_state.state;
/* Yeah we have to save all those states to ensure this blitter operation
* is really transparent. The states will be restored by the blitter once
@@ -106,7 +111,7 @@ static void r300_hw_copy(struct pipe_context* pipe,
util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
util_blitter_save_fragment_sampler_states(
- r300->blitter, r300->sampler_count, (void**)r300->sampler_states);
+ r300->blitter, state->sampler_count, (void**)state->sampler_states);
util_blitter_save_fragment_sampler_views(
r300->blitter, r300->fragment_sampler_view_count,
@@ -139,10 +144,10 @@ void r300_surface_copy(struct pipe_context* pipe,
new_format = PIPE_FORMAT_I8_UNORM;
break;
case 2:
- new_format = PIPE_FORMAT_A4R4G4B4_UNORM;
+ new_format = PIPE_FORMAT_B4G4R4A4_UNORM;
break;
case 4:
- new_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ new_format = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
default:
debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n"
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index f631b4ed27f..923e1e541ff 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -59,7 +59,8 @@ static void r300_destroy_context(struct pipe_context* context)
FREE(r300->fb_state.state);
FREE(r300->rs_block_state.state);
FREE(r300->scissor_state.state);
- FREE(r300->vertex_format_state.state);
+ FREE(r300->textures_state.state);
+ FREE(r300->vap_output_state.state);
FREE(r300->viewport_state.state);
FREE(r300->ztop_state.state);
FREE(r300);
@@ -70,11 +71,8 @@ r300_is_texture_referenced(struct pipe_context *pipe,
struct pipe_texture *texture,
unsigned face, unsigned level)
{
- struct pipe_buffer* buf = 0;
-
- r300_get_texture_buffer(pipe->screen, texture, &buf, NULL);
-
- return pipe->is_buffer_referenced(pipe, buf);
+ return pipe->is_buffer_referenced(pipe,
+ ((struct r300_texture *)texture)->buffer);
}
static unsigned int
@@ -84,7 +82,14 @@ r300_is_buffer_referenced(struct pipe_context *pipe,
/* This only checks to see whether actual hardware buffers are
* referenced. Since we use managed BOs and transfers, it's actually not
* possible for pipe_buffers to ever reference the actual hardware, so
- * buffers are never referenced. */
+ * buffers are never referenced.
+ */
+
+ /* XXX: that doesn't make sense given that
+ * r300_is_texture_referenced is implemented on top of this
+ * function and hardware can certainly refer to textures
+ * directly...
+ */
return 0;
}
@@ -96,39 +101,54 @@ static void r300_flush_cb(void *data)
}
#define R300_INIT_ATOM(atomname, atomsize) \
- r300->atomname##_state.name = #atomname; \
- r300->atomname##_state.state = NULL; \
- r300->atomname##_state.size = atomsize; \
- r300->atomname##_state.emit = r300_emit_##atomname##_state; \
- r300->atomname##_state.dirty = FALSE; \
- insert_at_tail(&r300->atom_list, &r300->atomname##_state);
+ r300->atomname.name = #atomname; \
+ r300->atomname.state = NULL; \
+ r300->atomname.size = atomsize; \
+ r300->atomname.emit = r300_emit_##atomname; \
+ r300->atomname.dirty = FALSE; \
+ insert_at_tail(&r300->atom_list, &r300->atomname);
static void r300_setup_atoms(struct r300_context* r300)
{
+ boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500;
+ boolean has_tcl = r300_screen(r300->context.screen)->caps->has_tcl;
+
/* Create the actual atom list.
*
* Each atom is examined and emitted in the order it appears here, which
* can affect performance and conformance if not handled with care.
*
- * Some atoms never change size, others change every emit. This is just
- * an upper bound on each atom, to keep the emission machinery from
- * underallocating space. */
+ * Some atoms never change size, others change every emit - those have
+ * the size of 0 here. */
make_empty_list(&r300->atom_list);
- R300_INIT_ATOM(invariant, 71);
- R300_INIT_ATOM(ztop, 2);
- R300_INIT_ATOM(blend, 8);
- R300_INIT_ATOM(blend_color, 3);
- R300_INIT_ATOM(clip, 29);
- R300_INIT_ATOM(dsa, 8);
- R300_INIT_ATOM(fb, 56);
- R300_INIT_ATOM(rs, 25);
- R300_INIT_ATOM(scissor, 3);
- R300_INIT_ATOM(viewport, 9);
- R300_INIT_ATOM(rs_block, 21);
- R300_INIT_ATOM(vertex_format, 26);
+ R300_INIT_ATOM(invariant_state, 71);
+ R300_INIT_ATOM(ztop_state, 2);
+ R300_INIT_ATOM(blend_state, 8);
+ R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2);
+ R300_INIT_ATOM(clip_state, has_tcl ? 5 + (6 * 4) : 2);
+ R300_INIT_ATOM(dsa_state, is_r500 ? 8 : 6);
+ R300_INIT_ATOM(fb_state, 0);
+ R300_INIT_ATOM(rs_state, 0);
+ R300_INIT_ATOM(scissor_state, 3);
+ R300_INIT_ATOM(viewport_state, 9);
+ R300_INIT_ATOM(rs_block_state, 0);
+ R300_INIT_ATOM(vertex_stream_state, 0);
+ R300_INIT_ATOM(vap_output_state, 6);
+ R300_INIT_ATOM(pvs_flush, 2);
+ R300_INIT_ATOM(vs_state, 0);
+ R300_INIT_ATOM(texture_cache_inval, 2);
+ R300_INIT_ATOM(textures_state, 0);
/* Some non-CSO atoms need explicit space to store the state locally. */
+ r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state);
+ r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state);
r300->fb_state.state = CALLOC_STRUCT(pipe_framebuffer_state);
+ r300->rs_block_state.state = CALLOC_STRUCT(r300_rs_block);
+ r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state);
+ r300->textures_state.state = CALLOC_STRUCT(r300_textures_state);
+ r300->vap_output_state.state = CALLOC_STRUCT(r300_vap_output_state);
+ r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
+ r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
}
struct pipe_context* r300_create_context(struct pipe_screen* screen,
@@ -141,6 +161,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
if (!r300)
return NULL;
+ r300screen->ctx = (struct pipe_context*)r300;
+
r300->winsys = radeon_winsys;
r300->context.winsys = (struct pipe_winsys*)radeon_winsys;
@@ -178,14 +200,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
r300_setup_atoms(r300);
- r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state);
- r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state);
- r300->rs_block_state.state = CALLOC_STRUCT(r300_rs_block);
- r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state);
- r300->vertex_format_state.state = CALLOC_STRUCT(r300_vertex_info);
- r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
- r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
-
/* Open up the OQ BO. */
r300->oqbo = screen->buffer_create(screen, 4096,
PIPE_BUFFER_USAGE_VERTEX, 4096);
@@ -202,7 +216,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
r300->invariant_state.dirty = TRUE;
r300->winsys->set_flush_cb(r300->winsys, r300_flush_cb, r300);
- r300->dirty_state = R300_NEW_KITCHEN_SINK;
r300->dirty_hw++;
r300->blitter = util_blitter_create(&r300->context);
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index 2edf65797a2..3b70bcda827 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -45,7 +45,7 @@ struct r300_atom {
/* Opaque state. */
void* state;
/* Emit the state to the context. */
- void (*emit)(struct r300_context*, void*);
+ void (*emit)(struct r300_context*, unsigned, void*);
/* Upper bound on number of dwords to emit. */
unsigned size;
/* Whether this atom should be emitted. */
@@ -86,7 +86,6 @@ struct r300_rs_state {
uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */
uint32_t antialiasing_config; /* R300_GB_AA_CONFIG: 0x4020 */
uint32_t point_size; /* R300_GA_POINT_SIZE: 0x421c */
- uint32_t point_minmax; /* R300_GA_POINT_MINMAX: 0x4230 */
uint32_t line_control; /* R300_GA_LINE_CNTL: 0x4234 */
float depth_scale; /* R300_SU_POLY_OFFSET_FRONT_SCALE: 0x42a4 */
/* R300_SU_POLY_OFFSET_BACK_SCALE: 0x42ac */
@@ -119,12 +118,58 @@ struct r300_sampler_state {
unsigned min_lod, max_lod;
};
-struct r300_texture_state {
+struct r300_texture_format_state {
uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */
uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */
uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */
};
+#define R300_MAX_TEXTURE_LEVELS 13
+
+struct r300_texture_fb_state {
+ /* Colorbuffer. */
+ uint32_t colorpitch[R300_MAX_TEXTURE_LEVELS]; /* R300_RB3D_COLORPITCH[0-3]*/
+ uint32_t us_out_fmt; /* R300_US_OUT_FMT[0-3] */
+
+ /* Zbuffer. */
+ uint32_t depthpitch[R300_MAX_TEXTURE_LEVELS]; /* R300_RB3D_DEPTHPITCH */
+ uint32_t zb_format; /* R300_ZB_FORMAT */
+};
+
+struct r300_textures_state {
+ /* Textures. */
+ struct r300_texture *textures[8];
+ int texture_count;
+ /* Sampler states. */
+ struct r300_sampler_state *sampler_states[8];
+ int sampler_count;
+
+ /* These is the merge of the texture and sampler states. */
+ unsigned count;
+ uint32_t tx_enable; /* R300_TX_ENABLE: 0x4101 */
+ struct r300_texture_sampler_state {
+ uint32_t format[3]; /* R300_TX_FORMAT[0-2] */
+ uint32_t filter[2]; /* R300_TX_FILTER[0-1] */
+ uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */
+ uint32_t tile_config; /* R300_TX_OFFSET (subset thereof) */
+ } regs[8];
+};
+
+struct r300_vertex_stream_state {
+ /* R300_VAP_PROG_STREAK_CNTL_[0-7] */
+ uint32_t vap_prog_stream_cntl[8];
+ /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */
+ uint32_t vap_prog_stream_cntl_ext[8];
+
+ unsigned count;
+};
+
+struct r300_vap_output_state {
+ uint32_t vap_vtx_state_cntl; /* R300_VAP_VTX_STATE_CNTL: 0x2180 */
+ uint32_t vap_vsm_vtx_assm; /* R300_VAP_VSM_VTX_ASSM: 0x2184 */
+ uint32_t vap_out_vtx_fmt[2]; /* R300_VAP_OUTPUT_VTX_FMT_[0-1]: 0x2090 */
+};
+
struct r300_viewport_state {
float xscale; /* R300_VAP_VPORT_XSCALE: 0x2098 */
float xoffset; /* R300_VAP_VPORT_XOFFSET: 0x209c */
@@ -141,11 +186,6 @@ struct r300_ztop_state {
#define R300_NEW_FRAGMENT_SHADER 0x00000020
#define R300_NEW_FRAGMENT_SHADER_CONSTANTS 0x00000040
-#define R300_NEW_SAMPLER 0x00000200
-#define R300_ANY_NEW_SAMPLERS 0x0001fe00
-#define R300_NEW_TEXTURE 0x00040000
-#define R300_ANY_NEW_TEXTURES 0x03fc0000
-#define R300_NEW_VERTEX_SHADER 0x08000000
#define R300_NEW_VERTEX_SHADER_CONSTANTS 0x10000000
#define R300_NEW_QUERY 0x40000000
#define R300_NEW_KITCHEN_SINK 0x7fffffff
@@ -198,16 +238,16 @@ struct r300_texture {
struct pipe_texture tex;
/* Offsets into the buffer. */
- unsigned offset[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned offset[R300_MAX_TEXTURE_LEVELS];
/* A pitch for each mip-level */
- unsigned pitch[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned pitch[R300_MAX_TEXTURE_LEVELS];
/* Size of one zslice or face based on the texture target */
- unsigned layer_size[PIPE_MAX_TEXTURE_LEVELS];
+ unsigned layer_size[R300_MAX_TEXTURE_LEVELS];
/* Whether the mipmap level is macrotiled. */
- enum r300_buffer_tiling mip_macrotile[PIPE_MAX_TEXTURE_LEVELS];
+ enum r300_buffer_tiling mip_macrotile[R300_MAX_TEXTURE_LEVELS];
/**
* If non-zero, override the natural texture layout with
@@ -231,7 +271,8 @@ struct r300_texture {
struct pipe_buffer* buffer;
/* Registers carrying texture format data. */
- struct r300_texture_state state;
+ struct r300_texture_format_state state;
+ struct r300_texture_fb_state fb_state;
/* Buffer tiling */
enum r300_buffer_tiling microtile, macrotile;
@@ -247,6 +288,13 @@ struct r300_vertex_info {
uint32_t vap_prog_stream_cntl_ext[8];
};
+struct r300_vertex_element_state {
+ unsigned count;
+ struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
+
+ struct r300_vertex_stream_state vertex_stream;
+};
+
extern struct pipe_viewport_state r300_viewport_identity;
struct r300_context {
@@ -271,9 +319,6 @@ struct r300_context {
struct r300_query *query_current;
struct r300_query query_list;
- /* Vertex formatting information. */
- struct r300_atom vertex_format_state;
-
/* Various CSO state objects. */
/* Beginning of atom list. */
struct r300_atom atom_list;
@@ -295,20 +340,25 @@ struct r300_context {
struct r300_atom rs_state;
/* RS block state. */
struct r300_atom rs_block_state;
- /* Sampler states. */
- struct r300_sampler_state* sampler_states[8];
- int sampler_count;
/* Scissor state. */
struct r300_atom scissor_state;
/* Sampler view states. */
struct pipe_sampler_view* fragment_sampler_views[8];
int fragment_sampler_view_count;
+ /* Vertex stream formatting state. */
+ struct r300_atom vertex_stream_state;
+ /* VAP (vertex shader) output mapping state. */
+ struct r300_atom vap_output_state;
/* Vertex shader. */
- struct r300_vertex_shader* vs;
+ struct r300_atom vs_state;
/* Viewport state. */
struct r300_atom viewport_state;
/* ZTOP state. */
struct r300_atom ztop_state;
+ /* PVS flush. */
+ struct r300_atom pvs_flush;
+ /* Texture cache invalidate. */
+ struct r300_atom texture_cache_inval;
/* Invariant state. This must be emitted to get the engine started. */
struct r300_atom invariant_state;
@@ -316,22 +366,29 @@ struct r300_context {
/* Vertex buffers for Gallium. */
struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
int vertex_buffer_count;
+ int vertex_buffer_max_index;
/* Vertex elements for Gallium. */
- struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
- int vertex_element_count;
+ struct r300_vertex_element_state *velems;
+
+ /* Vertex info for Draw. */
+ struct vertex_info vertex_info;
struct pipe_stencil_ref stencil_ref;
+ struct pipe_clip_state clip;
+
+ struct pipe_viewport_state viewport;
+
/* Bitmask of dirty state objects. */
uint32_t dirty_state;
/* Flag indicating whether or not the HW is dirty. */
uint32_t dirty_hw;
- /* Whether the TCL engine should be in bypass mode. */
- boolean tcl_bypass;
/* Whether polygon offset is enabled. */
boolean polygon_offset_enabled;
/* Z buffer bit depth. */
uint32_t zbuffer_bpp;
+ /* Whether scissor is enabled. */
+ boolean scissor_enabled;
};
/* Convenience cast wrapper. */
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 4310ff1411d..fc8a8a27738 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -32,17 +32,17 @@
#include "r300_emit.h"
#include "r300_fs.h"
#include "r300_screen.h"
-#include "r300_state_inlines.h"
#include "r300_vs.h"
-void r300_emit_blend_state(struct r300_context* r300, void* state)
+void r300_emit_blend_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_blend_state* blend = (struct r300_blend_state*)state;
struct pipe_framebuffer_state* fb =
(struct pipe_framebuffer_state*)r300->fb_state.state;
CS_LOCALS(r300);
- BEGIN_CS(8);
+ BEGIN_CS(size);
OUT_CS_REG(R300_RB3D_ROPCNTL, blend->rop);
OUT_CS_REG_SEQ(R300_RB3D_CBLEND, 3);
if (fb->nr_cbufs) {
@@ -59,26 +59,28 @@ void r300_emit_blend_state(struct r300_context* r300, void* state)
END_CS;
}
-void r300_emit_blend_color_state(struct r300_context* r300, void* state)
+void r300_emit_blend_color_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_blend_color_state* bc = (struct r300_blend_color_state*)state;
struct r300_screen* r300screen = r300_screen(r300->context.screen);
CS_LOCALS(r300);
if (r300screen->caps->is_r500) {
- BEGIN_CS(3);
+ BEGIN_CS(size);
OUT_CS_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
OUT_CS(bc->blend_color_red_alpha);
OUT_CS(bc->blend_color_green_blue);
END_CS;
} else {
- BEGIN_CS(2);
+ BEGIN_CS(size);
OUT_CS_REG(R300_RB3D_BLEND_COLOR, bc->blend_color);
END_CS;
}
}
-void r300_emit_clip_state(struct r300_context* r300, void* state)
+void r300_emit_clip_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct pipe_clip_state* clip = (struct pipe_clip_state*)state;
int i;
@@ -86,7 +88,7 @@ void r300_emit_clip_state(struct r300_context* r300, void* state)
CS_LOCALS(r300);
if (r300screen->caps->has_tcl) {
- BEGIN_CS(5 + (6 * 4));
+ BEGIN_CS(size);
OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG,
(r300screen->caps->is_r500 ?
R500_PVS_UCP_START : R300_PVS_UCP_START));
@@ -101,14 +103,14 @@ void r300_emit_clip_state(struct r300_context* r300, void* state)
R300_PS_UCP_MODE_CLIP_AS_TRIFAN);
END_CS;
} else {
- BEGIN_CS(2);
+ BEGIN_CS(size);
OUT_CS_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE);
END_CS;
}
}
-void r300_emit_dsa_state(struct r300_context* r300, void* state)
+void r300_emit_dsa_state(struct r300_context* r300, unsigned size, void* state)
{
struct r300_dsa_state* dsa = (struct r300_dsa_state*)state;
struct r300_screen* r300screen = r300_screen(r300->context.screen);
@@ -117,7 +119,7 @@ void r300_emit_dsa_state(struct r300_context* r300, void* state)
struct pipe_stencil_ref stencil_ref = r300->stencil_ref;
CS_LOCALS(r300);
- BEGIN_CS(r300screen->caps->is_r500 ? 8 : 6);
+ BEGIN_CS(size);
OUT_CS_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function);
OUT_CS_REG_SEQ(R300_ZB_CNTL, 3);
@@ -144,6 +146,8 @@ static const float * get_shader_constant(
{
struct r300_viewport_state* viewport =
(struct r300_viewport_state*)r300->viewport_state.state;
+ struct r300_textures_state* texstate =
+ (struct r300_textures_state*)r300->textures_state.state;
static float vec[4] = { 0.0, 0.0, 0.0, 1.0 };
struct pipe_texture *tex;
@@ -171,23 +175,15 @@ static const float * get_shader_constant(
break;
case RC_STATE_R300_VIEWPORT_SCALE:
- if (r300->tcl_bypass) {
- vec[0] = 1;
- vec[1] = 1;
- vec[2] = 1;
- } else {
- vec[0] = viewport->xscale;
- vec[1] = viewport->yscale;
- vec[2] = viewport->zscale;
- }
+ vec[0] = viewport->xscale;
+ vec[1] = viewport->yscale;
+ vec[2] = viewport->zscale;
break;
case RC_STATE_R300_VIEWPORT_OFFSET:
- if (!r300->tcl_bypass) {
- vec[0] = viewport->xoffset;
- vec[1] = viewport->yoffset;
- vec[2] = viewport->zoffset;
- }
+ vec[0] = viewport->xoffset;
+ vec[1] = viewport->yoffset;
+ vec[2] = viewport->zoffset;
break;
default:
@@ -379,7 +375,7 @@ void r500_emit_fs_constant_buffer(struct r300_context* r300,
END_CS;
}
-void r300_emit_fb_state(struct r300_context* r300, void* state)
+void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state)
{
struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)state;
struct r300_screen* r300screen = r300_screen(r300->context.screen);
@@ -388,7 +384,7 @@ void r300_emit_fb_state(struct r300_context* r300, void* state)
int i;
CS_LOCALS(r300);
- BEGIN_CS((10 * fb->nr_cbufs) + (fb->zsbuf ? 10 : 0) + 6);
+ BEGIN_CS(size);
/* Flush and free renderbuffer caches. */
OUT_CS_REG(R300_RB3D_DSTCACHE_CTLSTAT,
@@ -422,14 +418,13 @@ void r300_emit_fb_state(struct r300_context* r300, void* state)
OUT_CS_RELOC(tex->buffer, surf->offset, 0, RADEON_GEM_DOMAIN_VRAM, 0);
OUT_CS_REG_SEQ(R300_RB3D_COLORPITCH0 + (4 * i), 1);
- OUT_CS_RELOC(tex->buffer, tex->pitch[surf->level] |
- r300_translate_colorformat(tex->tex.format) |
- R300_COLOR_TILE(tex->mip_macrotile[surf->level]) |
- R300_COLOR_MICROTILE(tex->microtile),
+ OUT_CS_RELOC(tex->buffer, tex->fb_state.colorpitch[surf->level],
0, RADEON_GEM_DOMAIN_VRAM, 0);
- OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i),
- r300_translate_out_fmt(surf->format));
+ OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i), tex->fb_state.us_out_fmt);
+ }
+ for (; i < 4; i++) {
+ OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i), R300_US_OUT_FMT_UNUSED);
}
/* Set up a zbuffer. */
@@ -441,15 +436,15 @@ void r300_emit_fb_state(struct r300_context* r300, void* state)
OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1);
OUT_CS_RELOC(tex->buffer, surf->offset, 0, RADEON_GEM_DOMAIN_VRAM, 0);
- OUT_CS_REG(R300_ZB_FORMAT, r300_translate_zsformat(tex->tex.format));
+ OUT_CS_REG(R300_ZB_FORMAT, tex->fb_state.zb_format);
OUT_CS_REG_SEQ(R300_ZB_DEPTHPITCH, 1);
- OUT_CS_RELOC(tex->buffer, tex->pitch[surf->level] |
- R300_DEPTHMACROTILE(tex->mip_macrotile[surf->level]) |
- R300_DEPTHMICROTILE(tex->microtile),
+ OUT_CS_RELOC(tex->buffer, tex->fb_state.depthpitch[surf->level],
0, RADEON_GEM_DOMAIN_VRAM, 0);
}
+ OUT_CS_REG(R300_GA_POINT_MINMAX,
+ (MAX2(fb->width, fb->height) * 6) << R300_GA_POINT_MINMAX_MAX_SHIFT);
END_CS;
}
@@ -579,21 +574,19 @@ void r300_emit_query_end(struct r300_context* r300)
r300_emit_query_finish(r300, query);
}
-void r300_emit_rs_state(struct r300_context* r300, void* state)
+void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state)
{
struct r300_rs_state* rs = (struct r300_rs_state*)state;
float scale, offset;
CS_LOCALS(r300);
- BEGIN_CS(18 + (rs->polygon_offset_enable ? 5 : 0));
+ BEGIN_CS(size);
OUT_CS_REG(R300_VAP_CNTL_STATUS, rs->vap_control_status);
OUT_CS_REG(R300_GB_AA_CONFIG, rs->antialiasing_config);
OUT_CS_REG(R300_GA_POINT_SIZE, rs->point_size);
- OUT_CS_REG_SEQ(R300_GA_POINT_MINMAX, 2);
- OUT_CS(rs->point_minmax);
- OUT_CS(rs->line_control);
+ OUT_CS_REG(R300_GA_LINE_CNTL, rs->line_control);
if (rs->polygon_offset_enable) {
scale = rs->depth_scale * 12;
@@ -624,7 +617,8 @@ void r300_emit_rs_state(struct r300_context* r300, void* state)
END_CS;
}
-void r300_emit_rs_block_state(struct r300_context* r300, void* state)
+void r300_emit_rs_block_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_rs_block* rs = (struct r300_rs_block*)state;
unsigned i;
@@ -635,7 +629,7 @@ void r300_emit_rs_block_state(struct r300_context* r300, void* state)
DBG(r300, DBG_DRAW, "r300: RS emit:\n");
- BEGIN_CS(5 + count*2);
+ BEGIN_CS(size);
if (r300screen->caps->is_r500) {
OUT_CS_REG_SEQ(R500_RS_IP_0, count);
} else {
@@ -666,7 +660,8 @@ void r300_emit_rs_block_state(struct r300_context* r300, void* state)
END_CS;
}
-void r300_emit_scissor_state(struct r300_context* r300, void* state)
+void r300_emit_scissor_state(struct r300_context* r300,
+ unsigned size, void* state)
{
unsigned minx, miny, maxx, maxy;
uint32_t top_left, bottom_right;
@@ -680,7 +675,7 @@ void r300_emit_scissor_state(struct r300_context* r300, void* state)
maxx = fb->width;
maxy = fb->height;
- if (((struct r300_rs_state*)r300->rs_state.state)->rs.scissor) {
+ if (r300->scissor_enabled) {
minx = MAX2(minx, scissor->minx);
miny = MAX2(miny, scissor->miny);
maxx = MIN2(maxx, scissor->maxx);
@@ -720,65 +715,51 @@ void r300_emit_scissor_state(struct r300_context* r300, void* state)
(((maxy - 1) + 1440) << R300_SCISSORS_Y_SHIFT);
}
- BEGIN_CS(3);
+ BEGIN_CS(size);
OUT_CS_REG_SEQ(R300_SC_SCISSORS_TL, 2);
OUT_CS(top_left);
OUT_CS(bottom_right);
END_CS;
}
-void r300_emit_texture(struct r300_context* r300,
- struct r300_sampler_state* sampler,
- struct r300_texture* tex,
- unsigned offset)
+void r300_emit_textures_state(struct r300_context *r300,
+ unsigned size, void *state)
{
- uint32_t filter0 = sampler->filter0;
- uint32_t format0 = tex->state.format0;
- unsigned min_level, max_level;
+ struct r300_textures_state *allstate = (struct r300_textures_state*)state;
+ struct r300_texture_sampler_state *texstate;
+ unsigned i;
CS_LOCALS(r300);
- /* to emulate 1D textures through 2D ones correctly */
- if (tex->tex.target == PIPE_TEXTURE_1D) {
- filter0 &= ~R300_TX_WRAP_T_MASK;
- filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
- }
+ BEGIN_CS(size);
+ OUT_CS_REG(R300_TX_ENABLE, allstate->tx_enable);
- if (tex->is_npot) {
- /* NPOT textures don't support mip filter, unfortunately.
- * This prevents incorrect rendering. */
- filter0 &= ~R300_TX_MIN_FILTER_MIP_MASK;
- } else {
- /* determine min/max levels */
- /* the MAX_MIP level is the largest (finest) one */
- max_level = MIN2(sampler->max_lod, tex->tex.last_level);
- min_level = MIN2(sampler->min_lod, max_level);
- format0 |= R300_TX_NUM_LEVELS(max_level);
- filter0 |= R300_TX_MAX_MIP_LEVEL(min_level);
- }
+ for (i = 0; i < allstate->count; i++) {
+ if ((1 << i) & allstate->tx_enable) {
+ texstate = &allstate->regs[i];
+
+ OUT_CS_REG(R300_TX_FILTER0_0 + (i * 4), texstate->filter[0]);
+ OUT_CS_REG(R300_TX_FILTER1_0 + (i * 4), texstate->filter[1]);
+ OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (i * 4),
+ texstate->border_color);
- BEGIN_CS(16);
- OUT_CS_REG(R300_TX_FILTER0_0 + (offset * 4), filter0 |
- (offset << 28));
- OUT_CS_REG(R300_TX_FILTER1_0 + (offset * 4), sampler->filter1);
- OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (offset * 4), sampler->border_color);
-
- OUT_CS_REG(R300_TX_FORMAT0_0 + (offset * 4), 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,
- R300_TXO_MACRO_TILE(tex->macrotile) |
- R300_TXO_MICRO_TILE(tex->microtile),
- RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0);
+ OUT_CS_REG(R300_TX_FORMAT0_0 + (i * 4), texstate->format[0]);
+ OUT_CS_REG(R300_TX_FORMAT1_0 + (i * 4), texstate->format[1]);
+ OUT_CS_REG(R300_TX_FORMAT2_0 + (i * 4), texstate->format[2]);
+
+ OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (i * 4), 1);
+ OUT_CS_RELOC(allstate->textures[i]->buffer, texstate->tile_config,
+ RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0);
+ }
+ }
END_CS;
}
void r300_emit_aos(struct r300_context* r300, unsigned offset)
{
struct pipe_vertex_buffer *vb1, *vb2, *vbuf = r300->vertex_buffer;
- struct pipe_vertex_element *velem = r300->vertex_element;
+ struct pipe_vertex_element *velem = r300->velems->velem;
int i;
- unsigned size1, size2, aos_count = r300->vertex_element_count;
+ unsigned size1, size2, aos_count = r300->velems->count;
unsigned packet_size = (aos_count * 3 + 1) / 2;
CS_LOCALS(r300);
@@ -813,68 +794,110 @@ void r300_emit_aos(struct r300_context* r300, unsigned offset)
END_CS;
}
-void r300_emit_vertex_format_state(struct r300_context* r300, void* state)
+void r300_emit_vertex_buffer(struct r300_context* r300)
{
- struct r300_vertex_info* vertex_info = (struct r300_vertex_info*)state;
- unsigned i;
CS_LOCALS(r300);
- DBG(r300, DBG_DRAW, "r300: VAP/PSC emit:\n");
+ DBG(r300, DBG_DRAW, "r300: Preparing vertex buffer %p for render, "
+ "vertex size %d\n", r300->vbo,
+ r300->vertex_info.size);
+ /* Set the pointer to our vertex buffer. The emitted values are this:
+ * PACKET3 [3D_LOAD_VBPNTR]
+ * COUNT [1]
+ * FORMAT [size | stride << 8]
+ * OFFSET [offset into BO]
+ * VBPNTR [relocated BO]
+ */
+ BEGIN_CS(7);
+ OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, 3);
+ OUT_CS(1);
+ OUT_CS(r300->vertex_info.size |
+ (r300->vertex_info.size << 8));
+ OUT_CS(r300->vbo_offset);
+ OUT_CS_RELOC(r300->vbo, 0, RADEON_GEM_DOMAIN_GTT, 0, 0);
+ END_CS;
+}
- BEGIN_CS(26);
- OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_info->vinfo.size);
+void r300_emit_vertex_stream_state(struct r300_context* r300,
+ unsigned size, void* state)
+{
+ struct r300_vertex_stream_state *streams =
+ (struct r300_vertex_stream_state*)state;
+ unsigned i;
+ CS_LOCALS(r300);
- OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2);
- OUT_CS(vertex_info->vinfo.hwfmt[0]);
- OUT_CS(vertex_info->vinfo.hwfmt[1]);
- OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
- OUT_CS(vertex_info->vinfo.hwfmt[2]);
- OUT_CS(vertex_info->vinfo.hwfmt[3]);
- for (i = 0; i < 4; i++) {
- DBG(r300, DBG_DRAW, " : hwfmt%d: 0x%08x\n", i,
- vertex_info->vinfo.hwfmt[i]);
- }
+ DBG(r300, DBG_DRAW, "r300: PSC emit:\n");
- OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, 8);
- for (i = 0; i < 8; i++) {
- OUT_CS(vertex_info->vap_prog_stream_cntl[i]);
+ BEGIN_CS(size);
+ OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, streams->count);
+ for (i = 0; i < streams->count; i++) {
+ OUT_CS(streams->vap_prog_stream_cntl[i]);
DBG(r300, DBG_DRAW, " : prog_stream_cntl%d: 0x%08x\n", i,
- vertex_info->vap_prog_stream_cntl[i]);
+ streams->vap_prog_stream_cntl[i]);
}
- OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, 8);
- for (i = 0; i < 8; i++) {
- OUT_CS(vertex_info->vap_prog_stream_cntl_ext[i]);
+ OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, streams->count);
+ for (i = 0; i < streams->count; i++) {
+ OUT_CS(streams->vap_prog_stream_cntl_ext[i]);
DBG(r300, DBG_DRAW, " : prog_stream_cntl_ext%d: 0x%08x\n", i,
- vertex_info->vap_prog_stream_cntl_ext[i]);
+ streams->vap_prog_stream_cntl_ext[i]);
}
END_CS;
}
+void r300_emit_vap_output_state(struct r300_context* r300,
+ unsigned size, void* state)
+{
+ struct r300_vap_output_state *vap_out_state =
+ (struct r300_vap_output_state*)state;
+ CS_LOCALS(r300);
+
+ DBG(r300, DBG_DRAW, "r300: VAP emit:\n");
-void r300_emit_vertex_program_code(struct r300_context* r300,
- struct r300_vertex_program_code* code)
+ BEGIN_CS(size);
+ OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2);
+ OUT_CS(vap_out_state->vap_vtx_state_cntl);
+ OUT_CS(vap_out_state->vap_vsm_vtx_assm);
+ OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
+ OUT_CS(vap_out_state->vap_out_vtx_fmt[0]);
+ OUT_CS(vap_out_state->vap_out_vtx_fmt[1]);
+ END_CS;
+}
+
+void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state)
{
- int i;
+ CS_LOCALS(r300);
+
+ BEGIN_CS(size);
+ OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0x0);
+ END_CS;
+}
+
+void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state)
+{
+ struct r300_vertex_shader* vs = (struct r300_vertex_shader*)state;
+ struct r300_vertex_program_code* code = &vs->code;
struct r300_screen* r300screen = r300_screen(r300->context.screen);
unsigned instruction_count = code->length / 4;
+ unsigned i;
+
+ unsigned vtx_mem_size = r300screen->caps->is_r500 ? 128 : 72;
+ unsigned input_count = MAX2(util_bitcount(code->InputsRead), 1);
+ unsigned output_count = MAX2(util_bitcount(code->OutputsWritten), 1);
+ unsigned temp_count = MAX2(code->num_temporaries, 1);
- int vtx_mem_size = r300screen->caps->is_r500 ? 128 : 72;
- int input_count = MAX2(util_bitcount(code->InputsRead), 1);
- int output_count = MAX2(util_bitcount(code->OutputsWritten), 1);
- int temp_count = MAX2(code->num_temporaries, 1);
- int pvs_num_slots = MIN3(vtx_mem_size / input_count,
- vtx_mem_size / output_count, 10);
- int pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 6);
+ unsigned pvs_num_slots = MIN3(vtx_mem_size / input_count,
+ vtx_mem_size / output_count, 10);
+ unsigned pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 6);
CS_LOCALS(r300);
if (!r300screen->caps->has_tcl) {
- debug_printf("r300: Implementation error: emit_vertex_shader called,"
+ debug_printf("r300: Implementation error: emit_vs_state called,"
" but has_tcl is FALSE!\n");
return;
}
- BEGIN_CS(9 + code->length);
+ BEGIN_CS(size);
/* R300_VAP_PVS_CODE_CNTL_0
* R300_VAP_PVS_CONST_CNTL
* R300_VAP_PVS_CODE_CNTL_1
@@ -888,8 +911,9 @@ void r300_emit_vertex_program_code(struct r300_context* r300,
OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, 0);
OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, code->length);
- for (i = 0; i < code->length; i++)
+ for (i = 0; i < code->length; i++) {
OUT_CS(code->body.d[i]);
+ }
OUT_CS_REG(R300_VAP_CNTL, R300_PVS_NUM_SLOTS(pvs_num_slots) |
R300_PVS_NUM_CNTLRS(pvs_num_controllers) |
@@ -899,12 +923,6 @@ void r300_emit_vertex_program_code(struct r300_context* r300,
END_CS;
}
-void r300_emit_vertex_shader(struct r300_context* r300,
- struct r300_vertex_shader* vs)
-{
- r300_emit_vertex_program_code(r300, &vs->code);
-}
-
void r300_emit_vs_constant_buffer(struct r300_context* r300,
struct rc_constant_list* constants)
{
@@ -913,7 +931,7 @@ void r300_emit_vs_constant_buffer(struct r300_context* r300,
CS_LOCALS(r300);
if (!r300screen->caps->has_tcl) {
- debug_printf("r300: Implementation error: emit_vertex_shader called,"
+ debug_printf("r300: Implementation error: emit_vs_constant_buffer called,"
" but has_tcl is FALSE!\n");
return;
}
@@ -938,83 +956,56 @@ void r300_emit_vs_constant_buffer(struct r300_context* r300,
END_CS;
}
-void r300_emit_viewport_state(struct r300_context* r300, void* state)
+void r300_emit_viewport_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_viewport_state* viewport = (struct r300_viewport_state*)state;
CS_LOCALS(r300);
- if (r300->tcl_bypass) {
- BEGIN_CS(2);
- OUT_CS_REG(R300_VAP_VTE_CNTL, 0);
- END_CS;
- } else {
- BEGIN_CS(9);
- OUT_CS_REG_SEQ(R300_SE_VPORT_XSCALE, 6);
- OUT_CS_32F(viewport->xscale);
- OUT_CS_32F(viewport->xoffset);
- OUT_CS_32F(viewport->yscale);
- OUT_CS_32F(viewport->yoffset);
- OUT_CS_32F(viewport->zscale);
- OUT_CS_32F(viewport->zoffset);
- OUT_CS_REG(R300_VAP_VTE_CNTL, viewport->vte_control);
- END_CS;
- }
-}
-
-void r300_emit_texture_count(struct r300_context* r300)
-{
- uint32_t tx_enable = 0;
- int i;
- CS_LOCALS(r300);
-
- /* Notice that fragment_sampler_view_count and sampler_count are just sizes
- * of the respective arrays. We still have to check for the individual
- * elements. */
- for (i = 0; i < MIN2(r300->sampler_count, r300->fragment_sampler_view_count); i++) {
- if (r300->fragment_sampler_views[i]) {
- tx_enable |= 1 << i;
- }
- }
-
- BEGIN_CS(2);
- OUT_CS_REG(R300_TX_ENABLE, tx_enable);
- END_CS;
-
+ BEGIN_CS(size);
+ OUT_CS_REG_SEQ(R300_SE_VPORT_XSCALE, 6);
+ OUT_CS_32F(viewport->xscale);
+ OUT_CS_32F(viewport->xoffset);
+ OUT_CS_32F(viewport->yscale);
+ OUT_CS_32F(viewport->yoffset);
+ OUT_CS_32F(viewport->zscale);
+ OUT_CS_32F(viewport->zoffset);
+ OUT_CS_REG(R300_VAP_VTE_CNTL, viewport->vte_control);
+ END_CS;
}
-void r300_emit_ztop_state(struct r300_context* r300, void* state)
+void r300_emit_ztop_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_ztop_state* ztop = (struct r300_ztop_state*)state;
CS_LOCALS(r300);
- BEGIN_CS(2);
+ BEGIN_CS(size);
OUT_CS_REG(R300_ZB_ZTOP, ztop->z_buffer_top);
END_CS;
}
-void r300_flush_textures(struct r300_context* r300)
+void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state)
{
CS_LOCALS(r300);
- BEGIN_CS(2);
+ BEGIN_CS(size);
OUT_CS_REG(R300_TX_INVALTAGS, 0);
END_CS;
}
-static void r300_flush_pvs(struct r300_context* r300)
-{
- CS_LOCALS(r300);
-
- BEGIN_CS(2);
- OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0x0);
- END_CS;
-}
-
-void r300_emit_buffer_validate(struct r300_context *r300)
+void r300_emit_buffer_validate(struct r300_context *r300,
+ boolean do_validate_vertex_buffers,
+ struct pipe_buffer *index_buffer)
{
struct pipe_framebuffer_state* fb =
(struct pipe_framebuffer_state*)r300->fb_state.state;
+ struct r300_textures_state *texstate =
+ (struct r300_textures_state*)r300->textures_state.state;
struct r300_texture* tex;
+ struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
+ struct pipe_vertex_element *velem = r300->velems->velem;
+ struct pipe_buffer *pbuf;
unsigned i;
boolean invalid = FALSE;
@@ -1061,16 +1052,35 @@ validate:
goto validate;
}
}
- /* ...and vertex buffer. */
+ /* ...vertex buffer for SWTCL path... */
if (r300->vbo) {
if (!r300->winsys->add_buffer(r300->winsys, r300->vbo,
RADEON_GEM_DOMAIN_GTT, 0)) {
r300->context.flush(&r300->context, 0, NULL);
goto validate;
}
- } else {
- /* debug_printf("No VBO while emitting dirty state!\n"); */
}
+ /* ...vertex buffers for HWTCL path... */
+ if (do_validate_vertex_buffers) {
+ for (i = 0; i < r300->velems->count; i++) {
+ pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
+
+ if (!r300->winsys->add_buffer(r300->winsys, pbuf,
+ RADEON_GEM_DOMAIN_GTT, 0)) {
+ r300->context.flush(&r300->context, 0, NULL);
+ goto validate;
+ }
+ }
+ }
+ /* ...and index buffer for HWTCL path. */
+ if (index_buffer) {
+ if (!r300->winsys->add_buffer(r300->winsys, index_buffer,
+ RADEON_GEM_DOMAIN_GTT, 0)) {
+ r300->context.flush(&r300->context, 0, NULL);
+ goto validate;
+ }
+ }
+
if (!r300->winsys->validate(r300->winsys)) {
r300->context.flush(&r300->context, 0, NULL);
if (invalid) {
@@ -1083,16 +1093,10 @@ validate:
}
}
-/* Emit all dirty state. */
-void r300_emit_dirty_state(struct r300_context* r300)
+unsigned r300_get_num_dirty_dwords(struct r300_context *r300)
{
- struct r300_screen* r300screen = r300_screen(r300->context.screen);
struct r300_atom* atom;
- unsigned i, dwords = 1024;
- int dirty_tex = 0;
-
- /* Check the required number of dwords against the space remaining in the
- * current CS object. If we need more, then flush. */
+ unsigned dwords = 0;
foreach(atom, &r300->atom_list) {
if (atom->dirty || atom->always_dirty) {
@@ -1100,12 +1104,17 @@ void r300_emit_dirty_state(struct r300_context* r300)
}
}
- /* Make sure we have at least 2*1024 spare dwords. */
- /* XXX It would be nice to know the number of dwords we really need to
- * XXX emit. */
- while (!r300->winsys->check_cs(r300->winsys, dwords)) {
- r300->context.flush(&r300->context, 0, NULL);
- }
+ /* XXX This is the compensation for the non-atomized states. */
+ dwords += 1024;
+
+ return dwords;
+}
+
+/* Emit all dirty state. */
+void r300_emit_dirty_state(struct r300_context* r300)
+{
+ struct r300_screen* r300screen = r300_screen(r300->context.screen);
+ struct r300_atom* atom;
if (r300->dirty_state & R300_NEW_QUERY) {
r300_emit_query_start(r300);
@@ -1114,7 +1123,7 @@ void r300_emit_dirty_state(struct r300_context* r300)
foreach(atom, &r300->atom_list) {
if (atom->dirty || atom->always_dirty) {
- atom->emit(r300, atom->state);
+ atom->emit(r300, atom->size, atom->state);
atom->dirty = FALSE;
}
}
@@ -1140,43 +1149,9 @@ void r300_emit_dirty_state(struct r300_context* r300)
r300->dirty_state &= ~R300_NEW_FRAGMENT_SHADER_CONSTANTS;
}
- /* Samplers and textures are tracked separately but emitted together. */
- if (r300->dirty_state &
- (R300_ANY_NEW_SAMPLERS | R300_ANY_NEW_TEXTURES)) {
- r300_emit_texture_count(r300);
-
- for (i = 0; i < MIN2(r300->sampler_count, r300->fragment_sampler_view_count); i++) {
- if (r300->dirty_state &
- ((R300_NEW_SAMPLER << i) | (R300_NEW_TEXTURE << i))) {
- if (r300->fragment_sampler_views[i]) {
- r300_emit_texture(r300,
- r300->sampler_states[i],
- (struct r300_texture *)r300->fragment_sampler_views[i]->texture,
- i);
- dirty_tex |= r300->dirty_state & (R300_NEW_TEXTURE << i);
- }
- r300->dirty_state &=
- ~((R300_NEW_SAMPLER << i) | (R300_NEW_TEXTURE << i));
- }
- }
- r300->dirty_state &= ~(R300_ANY_NEW_SAMPLERS | R300_ANY_NEW_TEXTURES);
- }
-
- if (dirty_tex) {
- r300_flush_textures(r300);
- }
-
- if (r300->dirty_state & (R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS)) {
- r300_flush_pvs(r300);
- }
-
- if (r300->dirty_state & R300_NEW_VERTEX_SHADER) {
- r300_emit_vertex_shader(r300, r300->vs);
- r300->dirty_state &= ~R300_NEW_VERTEX_SHADER;
- }
-
if (r300->dirty_state & R300_NEW_VERTEX_SHADER_CONSTANTS) {
- r300_emit_vs_constant_buffer(r300, &r300->vs->code.constants);
+ struct r300_vertex_shader* vs = r300->vs_state.state;
+ r300_emit_vs_constant_buffer(r300, &vs->code.constants);
r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS;
}
@@ -1184,8 +1159,10 @@ void r300_emit_dirty_state(struct r300_context* r300)
assert(r300->dirty_state == 0);
*/
- /* Finally, emit the VBO. */
- /* r300_emit_vertex_buffer(r300); */
+ /* Emit the VBO for SWTCL. */
+ if (!r300screen->caps->has_tcl) {
+ r300_emit_vertex_buffer(r300);
+ }
r300->dirty_hw++;
}
diff --git a/src/gallium/drivers/r300/r300_emit.h b/src/gallium/drivers/r300/r300_emit.h
index 6b96d9b57c0..449e640a884 100644
--- a/src/gallium/drivers/r300/r300_emit.h
+++ b/src/gallium/drivers/r300/r300_emit.h
@@ -31,13 +31,17 @@ struct r300_vertex_program_code;
void r300_emit_aos(struct r300_context* r300, unsigned offset);
-void r300_emit_blend_state(struct r300_context* r300, void* state);
+void r300_emit_blend_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_blend_color_state(struct r300_context* r300, void* state);
+void r300_emit_blend_color_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_clip_state(struct r300_context* r300, void* state);
+void r300_emit_clip_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_dsa_state(struct r300_context* r300, void* state);
+void r300_emit_dsa_state(struct r300_context* r300,
+ unsigned size, void* state);
void r300_emit_fragment_program_code(struct r300_context* r300,
struct rX00_fragment_program_code* generic_code);
@@ -51,48 +55,54 @@ void r500_emit_fragment_program_code(struct r300_context* r300,
void r500_emit_fs_constant_buffer(struct r300_context* r300,
struct rc_constant_list* constants);
-void r300_emit_fb_state(struct r300_context* r300, void* state);
+void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state);
void r300_emit_query_begin(struct r300_context* r300,
struct r300_query* query);
void r300_emit_query_end(struct r300_context* r300);
-void r300_emit_rs_state(struct r300_context* r300, void* state);
+void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state);
-void r300_emit_rs_block_state(struct r300_context* r300, void* state);
+void r300_emit_rs_block_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_scissor_state(struct r300_context* r300, void* state);
+void r300_emit_scissor_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_texture(struct r300_context* r300,
- struct r300_sampler_state* sampler,
- struct r300_texture* tex,
- unsigned offset);
+void r300_emit_textures_state(struct r300_context *r300,
+ unsigned size, void *state);
void r300_emit_vertex_buffer(struct r300_context* r300);
-void r300_emit_vertex_format_state(struct r300_context* r300, void* state);
+void r300_emit_vertex_stream_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_vertex_program_code(struct r300_context* r300,
- struct r300_vertex_program_code* code);
+void r300_emit_vap_output_state(struct r300_context* r300,
+ unsigned size, void* state);
void r300_emit_vs_constant_buffer(struct r300_context* r300,
struct rc_constant_list* constants);
-void r300_emit_vertex_shader(struct r300_context* r300,
- struct r300_vertex_shader* vs);
+void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state);
-void r300_emit_viewport_state(struct r300_context* r300, void* state);
+void r300_emit_viewport_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_texture_count(struct r300_context* r300);
+void r300_emit_ztop_state(struct r300_context* r300,
+ unsigned size, void* state);
-void r300_emit_ztop_state(struct r300_context* r300, void* state);
+void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state);
-void r300_flush_textures(struct r300_context* r300);
+void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state);
+
+unsigned r300_get_num_dirty_dwords(struct r300_context *r300);
/* Emit all dirty state. */
void r300_emit_dirty_state(struct r300_context* r300);
-void r300_emit_buffer_validate(struct r300_context *r300);
+void r300_emit_buffer_validate(struct r300_context *r300,
+ boolean do_validate_vertex_buffers,
+ struct pipe_buffer *index_buffer);
#endif /* R300_EMIT_H */
diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c
index e37d3092703..70de152713d 100644
--- a/src/gallium/drivers/r300/r300_flush.c
+++ b/src/gallium/drivers/r300/r300_flush.c
@@ -61,6 +61,12 @@ static void r300_flush(struct pipe_context* pipe,
atom->dirty = TRUE;
}
}
+
+ /* Unmark HWTCL state for SWTCL. */
+ if (!r300_screen(pipe->screen)->caps->has_tcl) {
+ r300->vs_state.dirty = FALSE;
+ r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS;
+ }
}
/* reset flushed query */
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index ae4c62b2f1d..9e71e61c303 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -133,10 +133,13 @@ static void get_compare_state(
struct r300_fragment_program_external_state* state,
unsigned shadow_samplers)
{
+ struct r300_textures_state *texstate =
+ (struct r300_textures_state*)r300->textures_state.state;
+
memset(state, 0, sizeof(*state));
- for (int i = 0; i < r300->sampler_count; i++) {
- struct r300_sampler_state* s = r300->sampler_states[i];
+ for (int i = 0; i < texstate->sampler_count; i++) {
+ struct r300_sampler_state* s = texstate->sampler_states[i];
if (s && s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) {
/* XXX Gallium doesn't provide us with any information regarding
@@ -204,6 +207,7 @@ static void r300_translate_fragment_shader(
DBG(r300, DBG_FP, "r300: Error compiling fragment program: %s\n",
compiler.Base.ErrorMsg);
assert(0);
+ abort();
}
/* And, finally... */
diff --git a/src/gallium/drivers/r300/r300_reg.h b/src/gallium/drivers/r300/r300_reg.h
index a049da69e2e..a249e8b36be 100644
--- a/src/gallium/drivers/r300/r300_reg.h
+++ b/src/gallium/drivers/r300/r300_reg.h
@@ -113,11 +113,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
/* index size - when not set the indices are assumed to be 16 bit */
# define R300_VAP_VF_CNTL__INDEX_SIZE_32bit (1<<11)
+# define R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS (1<<14)
/* number of vertices */
# define R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT 16
#define R500_VAP_INDEX_OFFSET 0x208c
+#define R500_VAP_ALT_NUM_VERTICES 0x2088
+
#define R300_VAP_OUTPUT_VTX_FMT_0 0x2090
# define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT (1<<0)
# define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT (1<<1)
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index cd4971ae136..9c001ae186d 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -42,6 +42,9 @@
/* r300_render: Vertex and index buffer primitive emission. */
#define R300_MAX_VBO_SIZE (1024 * 1024)
+/* XXX The DRM rejects VAP_ALT_NUM_VERTICES.. */
+//#define ENABLE_ALT_NUM_VERTS
+
uint32_t r300_translate_primitive(unsigned prim)
{
switch (prim) {
@@ -115,6 +118,18 @@ static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300,
return color_control;
}
+/* Check if the requested number of dwords is available in the CS and
+ * if not, flush. Return TRUE if the flush occured. */
+static boolean r300_reserve_cs_space(struct r300_context *r300,
+ unsigned dwords)
+{
+ if (!r300->winsys->check_cs(r300->winsys, dwords)) {
+ r300->context.flush(&r300->context, 0, NULL);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static boolean immd_is_good_idea(struct r300_context *r300,
unsigned count)
{
@@ -128,8 +143,8 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
{
struct pipe_vertex_element* velem;
struct pipe_vertex_buffer* vbuf;
- unsigned vertex_element_count = r300->vertex_element_count;
- unsigned i, v, vbi, dw, elem_offset;
+ unsigned vertex_element_count = r300->velems->count;
+ unsigned i, v, vbi, dw, elem_offset, dwords;
/* Size of the vertex, in dwords. */
unsigned vertex_size = 0;
@@ -151,7 +166,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
/* Calculate the vertex size, offsets, strides etc. and map the buffers. */
for (i = 0; i < vertex_element_count; i++) {
- velem = &r300->vertex_element[i];
+ velem = &r300->velems->velem[i];
offset[i] = velem->src_offset / 4;
size[i] = util_format_get_blocksize(velem->src_format) / 4;
vertex_size += size[i];
@@ -168,14 +183,19 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
}
}
+ dwords = 9 + count * vertex_size;
+
+ r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + dwords);
+ r300_emit_buffer_validate(r300, FALSE, NULL);
r300_emit_dirty_state(r300);
- BEGIN_CS(10 + count * vertex_size);
+ BEGIN_CS(dwords);
OUT_CS_REG(R300_GA_COLOR_CONTROL,
r300_provoking_vertex_fixes(r300, mode));
OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size);
- OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0);
- OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
+ OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2);
+ OUT_CS(count - 1);
+ OUT_CS(0);
OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, count * vertex_size);
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (count << 16) |
r300_translate_primitive(mode));
@@ -183,7 +203,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
/* Emit vertices. */
for (v = 0; v < count; v++) {
for (i = 0; i < vertex_element_count; i++) {
- velem = &r300->vertex_element[i];
+ velem = &r300->velems->velem[i];
vbi = velem->vertex_buffer_index;
elem_offset = offset[i] + stride[vbi] * (v + start);
@@ -196,7 +216,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300,
/* Unmap buffers. */
for (i = 0; i < vertex_element_count; i++) {
- vbi = r300->vertex_element[i].vertex_buffer_index;
+ vbi = r300->velems->velem[i].vertex_buffer_index;
if (map[vbi]) {
vbuf = &r300->vertex_buffer[vbi];
@@ -210,16 +230,29 @@ static void r300_emit_draw_arrays(struct r300_context *r300,
unsigned mode,
unsigned count)
{
+#if defined(ENABLE_ALT_NUM_VERTS)
+ boolean alt_num_verts = count > 65535;
+#else
+ boolean alt_num_verts = FALSE;
+#endif
CS_LOCALS(r300);
- BEGIN_CS(8);
+ if (alt_num_verts) {
+ assert(count < (1 << 24));
+ BEGIN_CS(9);
+ OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
+ } else {
+ BEGIN_CS(7);
+ }
OUT_CS_REG(R300_GA_COLOR_CONTROL,
r300_provoking_vertex_fixes(r300, mode));
- OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0);
- OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
+ OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2);
+ OUT_CS(count - 1);
+ OUT_CS(0);
OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
- r300_translate_primitive(mode));
+ r300_translate_primitive(mode) |
+ (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
END_CS;
}
@@ -234,72 +267,61 @@ static void r300_emit_draw_elements(struct r300_context *r300,
{
uint32_t count_dwords;
uint32_t offset_dwords = indexSize * start / sizeof(uint32_t);
+#if defined(ENABLE_ALT_NUM_VERTS)
+ boolean alt_num_verts = count > 65535;
+#else
+ boolean alt_num_verts = FALSE;
+#endif
CS_LOCALS(r300);
- /* XXX most of these are stupid */
- assert(indexSize == 4 || indexSize == 2);
assert((start * indexSize) % 4 == 0);
- assert(offset_dwords == 0);
+ assert(count < (1 << 24));
+
+ DBG(r300, DBG_DRAW, "r300: Indexbuf of %u indices, min %u max %u\n",
+ count, minIndex, maxIndex);
- BEGIN_CS(14);
+ maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index);
+
+ if (alt_num_verts) {
+ BEGIN_CS(15);
+ OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
+ } else {
+ BEGIN_CS(13);
+ }
OUT_CS_REG(R300_GA_COLOR_CONTROL,
r300_provoking_vertex_fixes(r300, mode));
- OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, minIndex);
- OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex);
+ OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX, 2);
+ OUT_CS(maxIndex);
+ OUT_CS(minIndex);
OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0);
if (indexSize == 4) {
- count_dwords = count + start;
+ count_dwords = count;
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
R300_VAP_VF_CNTL__INDEX_SIZE_32bit |
- r300_translate_primitive(mode));
+ r300_translate_primitive(mode) |
+ (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
} else {
- count_dwords = (count + start + 1) / 2;
+ count_dwords = (count + 1) / 2;
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
- r300_translate_primitive(mode));
+ r300_translate_primitive(mode) |
+ (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
}
/* INDX_BUFFER is a truly special packet3.
* Unlike most other packet3, where the offset is after the count,
* the order is reversed, so the relocation ends up carrying the
* size of the indexbuf instead of the offset.
- *
- * XXX Fix offset
*/
OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2);
OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) |
(0 << R300_INDX_BUFFER_SKIP_SHIFT));
- OUT_CS(offset_dwords);
+ OUT_CS(offset_dwords << 2);
OUT_CS_RELOC(indexBuffer, count_dwords,
RADEON_GEM_DOMAIN_GTT, 0, 0);
END_CS;
}
-static boolean r300_setup_vertex_buffers(struct r300_context *r300)
-{
- struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
- struct pipe_vertex_element *velem = r300->vertex_element;
- struct pipe_buffer *pbuf;
-
-validate:
- for (int i = 0; i < r300->vertex_element_count; i++) {
- pbuf = vbuf[velem[i].vertex_buffer_index].buffer;
-
- if (!r300->winsys->add_buffer(r300->winsys, pbuf,
- RADEON_GEM_DOMAIN_GTT, 0)) {
- r300->context.flush(&r300->context, 0, NULL);
- goto validate;
- }
- }
-
- if (!r300->winsys->validate(r300->winsys)) {
- r300->context.flush(&r300->context, 0, NULL);
- return r300->winsys->validate(r300->winsys);
- }
-
- return TRUE;
-}
-
static void r300_shorten_ubyte_elts(struct r300_context* r300,
struct pipe_buffer** elts,
unsigned count)
@@ -343,48 +365,52 @@ void r300_draw_range_elements(struct pipe_context* pipe,
{
struct r300_context* r300 = r300_context(pipe);
struct pipe_buffer* orgIndexBuffer = indexBuffer;
+#if defined(ENABLE_ALT_NUM_VERTS)
+ boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 &&
+ count > 65536;
+#else
+ boolean alt_num_verts = FALSE;
+#endif
+ unsigned short_count;
if (!u_trim_pipe_prim(mode, &count)) {
return;
}
- if (count > 65535) {
- /* XXX: use aux/indices functions to split this into smaller
- * primitives.
- */
- return;
- }
-
- r300_update_derived_state(r300);
-
- r300_emit_buffer_validate(r300);
-
- if (!r300_setup_vertex_buffers(r300)) {
- return;
- }
-
if (indexSize == 1) {
r300_shorten_ubyte_elts(r300, &indexBuffer, count);
indexSize = 2;
}
- if (!r300->winsys->add_buffer(r300->winsys, indexBuffer,
- RADEON_GEM_DOMAIN_GTT, 0)) {
- goto cleanup;
- }
-
- if (!r300->winsys->validate(r300->winsys)) {
- goto cleanup;
- }
+ r300_update_derived_state(r300);
+ /* 128 dwords for emit_aos and emit_draw_elements */
+ r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128);
+ r300_emit_buffer_validate(r300, TRUE, indexBuffer);
r300_emit_dirty_state(r300);
-
r300_emit_aos(r300, 0);
- r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex,
- mode, start, count);
+ if (alt_num_verts || count <= 65535) {
+ r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex,
+ maxIndex, mode, start, count);
+ } else {
+ do {
+ short_count = MIN2(count, 65534);
+ r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex,
+ maxIndex, mode, start, short_count);
+
+ start += short_count;
+ count -= short_count;
+
+ /* 16 spare dwords are enough for emit_draw_elements. */
+ if (count && r300_reserve_cs_space(r300, 16)) {
+ r300_emit_buffer_validate(r300, TRUE, indexBuffer);
+ r300_emit_dirty_state(r300);
+ r300_emit_aos(r300, 0);
+ }
+ } while (count);
+ }
-cleanup:
if (indexBuffer != orgIndexBuffer) {
pipe->screen->buffer_destroy(indexBuffer);
}
@@ -396,40 +422,60 @@ void r300_draw_elements(struct pipe_context* pipe,
unsigned indexSize, unsigned mode,
unsigned start, unsigned count)
{
- pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0,
- mode, start, count);
+ struct r300_context *r300 = r300_context(pipe);
+
+ pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0,
+ r300->vertex_buffer_max_index,
+ mode, start, count);
}
void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
unsigned start, unsigned count)
{
struct r300_context* r300 = r300_context(pipe);
+#if defined(ENABLE_ALT_NUM_VERTS)
+ boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 &&
+ count > 65536;
+#else
+ boolean alt_num_verts = FALSE;
+#endif
+ unsigned short_count;
if (!u_trim_pipe_prim(mode, &count)) {
return;
}
- if (count > 65535) {
- /* XXX: driver needs to handle this -- use the functions in
- * aux/indices to split this into several smaller primitives.
- */
- return;
- }
-
r300_update_derived_state(r300);
- r300_emit_buffer_validate(r300);
-
if (immd_is_good_idea(r300, count)) {
r300_emit_draw_arrays_immediate(r300, mode, start, count);
} else {
- if (!r300_setup_vertex_buffers(r300)) {
- return;
- }
-
+ /* Make sure there are at least 128 spare dwords in the command buffer.
+ * (most of it being consumed by emit_aos) */
+ r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128);
+ r300_emit_buffer_validate(r300, TRUE, NULL);
r300_emit_dirty_state(r300);
- r300_emit_aos(r300, start);
- r300_emit_draw_arrays(r300, mode, count);
+
+ if (alt_num_verts || count <= 65535) {
+ r300_emit_aos(r300, start);
+ r300_emit_draw_arrays(r300, mode, count);
+ } else {
+ do {
+ short_count = MIN2(count, 65535);
+ r300_emit_aos(r300, start);
+ r300_emit_draw_arrays(r300, mode, short_count);
+
+ start += short_count;
+ count -= short_count;
+
+ /* Again, we emit both AOS and draw_arrays so there should be
+ * at least 128 spare dwords. */
+ if (count && r300_reserve_cs_space(r300, 128)) {
+ r300_emit_buffer_validate(r300, TRUE, NULL);
+ r300_emit_dirty_state(r300);
+ }
+ } while (count);
+ }
}
}
@@ -559,7 +605,7 @@ r300_render_get_vertex_info(struct vbuf_render* render)
r300_update_derived_state(r300);
- return (struct vertex_info*)r300->vertex_format_state.state;
+ return &r300->vertex_info;
}
static boolean r300_render_allocate_vertices(struct vbuf_render* render,
@@ -644,6 +690,8 @@ static void r300_render_draw_arrays(struct vbuf_render* render,
CS_LOCALS(r300);
+ r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 2);
+ r300_emit_buffer_validate(r300, FALSE, NULL);
r300_emit_dirty_state(r300);
DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count);
@@ -662,12 +710,15 @@ static void r300_render_draw(struct vbuf_render* render,
struct r300_render* r300render = r300_render(render);
struct r300_context* r300 = r300render->r300;
int i;
+ unsigned dwords = 2 + (count+1)/2;
CS_LOCALS(r300);
+ r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + dwords);
+ r300_emit_buffer_validate(r300, FALSE, NULL);
r300_emit_dirty_state(r300);
- BEGIN_CS(2 + (count+1)/2);
+ BEGIN_CS(dwords);
OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2);
OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
r300render->hwprim);
diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index 5fa1ea0850e..5880eecd5fe 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -1,5 +1,6 @@
/*
* Copyright 2008 Corbin Simpson <[email protected]>
+ * Copyright 2010 Marek Olšák <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -20,14 +21,13 @@
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE. */
-#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_simple_screen.h"
#include "r300_context.h"
-#include "r300_screen.h"
#include "r300_texture.h"
+#include "r300_transfer.h"
#include "radeon_winsys.h"
#include "r300_winsys.h"
@@ -210,8 +210,9 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
{
uint32_t retval = 0;
boolean is_r500 = r300_screen(screen)->caps->is_r500;
- boolean is_z24 = format == PIPE_FORMAT_Z24X8_UNORM ||
- format == PIPE_FORMAT_Z24S8_UNORM;
+ boolean is_z24 = format == PIPE_FORMAT_X8Z24_UNORM ||
+ format == PIPE_FORMAT_S8Z24_UNORM;
+ boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM;
if (target >= PIPE_MAX_TEXTURE_TYPES) {
debug_printf("r300: Implementation error: Received bogus texture "
@@ -221,114 +222,34 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
/* Check sampler format support. */
if ((usage & PIPE_TEXTURE_USAGE_SAMPLER) &&
- (is_r500 || !is_z24) && /* Z24 cannot be sampled from on non-r5xx. */
- r300_translate_texformat(format) != ~0) {
+ /* Z24 cannot be sampled from on non-r5xx. */
+ (is_r500 || !is_z24) &&
+ r300_is_sampler_format_supported(format)) {
retval |= PIPE_TEXTURE_USAGE_SAMPLER;
}
- switch (format) {
- /* Supported formats. */
- /* Colorbuffer */
- case PIPE_FORMAT_A8_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- case PIPE_FORMAT_R5G6B5_UNORM:
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- case PIPE_FORMAT_A4R4G4B4_UNORM:
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- case PIPE_FORMAT_R8G8B8X8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- retval |= usage &
- (PIPE_TEXTURE_USAGE_RENDER_TARGET |
- PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
- PIPE_TEXTURE_USAGE_PRIMARY);
- break;
-
- /* ZS buffer */
- case PIPE_FORMAT_Z16_UNORM:
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z24S8_UNORM:
- retval = usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
- break;
-
- /* XXX Add all remaining gallium-supported formats,
- * see util/u_format.csv. */
-
- default:;
+ /* Check colorbuffer format support. */
+ if ((usage & (PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
+ PIPE_TEXTURE_USAGE_SCANOUT |
+ PIPE_TEXTURE_USAGE_SHARED)) &&
+ /* 2101010 cannot be rendered to on non-r5xx. */
+ (is_r500 || !is_color2101010) &&
+ r300_is_colorbuffer_format_supported(format)) {
+ retval |= usage &
+ (PIPE_TEXTURE_USAGE_RENDER_TARGET |
+ PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
+ PIPE_TEXTURE_USAGE_SCANOUT |
+ PIPE_TEXTURE_USAGE_SHARED);
}
- /* If usage was a mask that contained multiple bits, and not all of them
- * are supported, this will catch that and return FALSE.
- * e.g. usage = 2 | 4; retval = 4; (retval >= usage) == FALSE
- *
- * This also returns FALSE for any unknown formats.
- */
- return (retval >= usage);
-}
-
-static struct pipe_transfer*
-r300_get_tex_transfer(struct pipe_screen *screen,
- struct pipe_texture *texture,
- unsigned face, unsigned level, unsigned zslice,
- enum pipe_transfer_usage usage, unsigned x, unsigned y,
- unsigned w, unsigned h)
-{
- struct r300_texture *tex = (struct r300_texture *)texture;
- struct r300_transfer *trans;
- struct r300_screen *rscreen = r300_screen(screen);
- unsigned offset;
-
- offset = r300_texture_get_offset(tex, level, zslice, face); /* in bytes */
-
- trans = CALLOC_STRUCT(r300_transfer);
- if (trans) {
- pipe_texture_reference(&trans->transfer.texture, texture);
- trans->transfer.x = x;
- trans->transfer.y = y;
- trans->transfer.width = w;
- trans->transfer.height = h;
- trans->transfer.stride = r300_texture_get_stride(rscreen, tex, level);
- trans->transfer.usage = usage;
- trans->transfer.zslice = zslice;
- trans->transfer.face = face;
-
- trans->offset = offset;
+ /* Check depth-stencil format support. */
+ if (usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL &&
+ r300_is_zs_format_supported(format)) {
+ retval |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
}
- return &trans->transfer;
-}
-static void
-r300_tex_transfer_destroy(struct pipe_transfer *trans)
-{
- pipe_texture_reference(&trans->texture, NULL);
- FREE(trans);
-}
-
-static void* r300_transfer_map(struct pipe_screen* screen,
- struct pipe_transfer* transfer)
-{
- struct r300_texture* tex = (struct r300_texture*)transfer->texture;
- char* map;
- enum pipe_format format = tex->tex.format;
-
- map = pipe_buffer_map(screen, tex->buffer,
- pipe_transfer_buffer_flags(transfer));
-
- if (!map) {
- return NULL;
- }
-
- return map + r300_transfer(transfer)->offset +
- transfer->y / util_format_get_blockheight(format) * transfer->stride +
- transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-}
-
-static void r300_transfer_unmap(struct pipe_screen* screen,
- struct pipe_transfer* transfer)
-{
- struct r300_texture* tex = (struct r300_texture*)transfer->texture;
- pipe_buffer_unmap(screen, tex->buffer);
+ return retval == usage;
}
static void r300_destroy_screen(struct pipe_screen* pscreen)
@@ -367,13 +288,11 @@ struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys)
r300screen->screen.get_paramf = r300_get_paramf;
r300screen->screen.is_format_supported = r300_is_format_supported;
r300screen->screen.context_create = r300_create_context;
- r300screen->screen.get_tex_transfer = r300_get_tex_transfer;
- r300screen->screen.tex_transfer_destroy = r300_tex_transfer_destroy;
- r300screen->screen.transfer_map = r300_transfer_map;
- r300screen->screen.transfer_unmap = r300_transfer_unmap;
r300_init_screen_texture_functions(&r300screen->screen);
+ r300_init_screen_transfer_functions(&r300screen->screen);
u_simple_screen_init(&r300screen->screen);
return &r300screen->screen;
}
+
diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h
index 502fbfa5a24..484bde6a6be 100644
--- a/src/gallium/drivers/r300/r300_screen.h
+++ b/src/gallium/drivers/r300/r300_screen.h
@@ -1,5 +1,6 @@
/*
* Copyright 2008 Corbin Simpson <[email protected]>
+ * Copyright 2010 Marek Olšák <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -27,6 +28,8 @@
#include "r300_chipset.h"
+#define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM
+
struct radeon_winsys;
struct r300_screen {
@@ -35,6 +38,10 @@ struct r300_screen {
struct radeon_winsys* radeon_winsys;
+ /* XXX This hack will be removed once texture transfers become part of
+ * pipe_context. */
+ struct pipe_context* ctx;
+
/* Chipset capabilities */
struct r300_capabilities* caps;
@@ -42,25 +49,14 @@ struct r300_screen {
unsigned debug;
};
-struct r300_transfer {
- /* Parent class */
- struct pipe_transfer transfer;
-
- /* Offset from start of buffer. */
- unsigned offset;
-};
/* Convenience cast wrapper. */
static INLINE struct r300_screen* r300_screen(struct pipe_screen* screen) {
return (struct r300_screen*)screen;
}
-/* Convenience cast wrapper. */
-static INLINE struct r300_transfer*
-r300_transfer(struct pipe_transfer* transfer)
-{
- return (struct r300_transfer*)transfer;
-}
+/* Creates a new r300 screen. */
+struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys);
/* Debug functionality. */
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index e5ec2701c81..09bbf6c60e2 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -43,6 +43,12 @@
/* r300_state: Functions used to intialize state context by translating
* Gallium state objects into semi-native r300 state objects. */
+#define UPDATE_STATE(cso, atom) \
+ if (cso != atom.state) { \
+ atom.state = cso; \
+ atom.dirty = TRUE; \
+ }
+
static boolean blend_discard_if_src_alpha_0(unsigned srcRGB, unsigned srcA,
unsigned dstRGB, unsigned dstA)
{
@@ -328,8 +334,7 @@ static void r300_bind_blend_state(struct pipe_context* pipe,
{
struct r300_context* r300 = r300_context(pipe);
- r300->blend_state.state = state;
- r300->blend_state.dirty = TRUE;
+ UPDATE_STATE(state, r300->blend_state);
}
/* Free blend state. */
@@ -356,7 +361,7 @@ static void r300_set_blend_color(struct pipe_context* pipe,
(struct r300_blend_color_state*)r300->blend_color_state.state;
union util_color uc;
- util_pack_color(color->color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc);
+ util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
state->blend_color = uc.ui;
/* XXX if FP16 blending is enabled, we should use the FP16 format */
@@ -376,6 +381,8 @@ static void r300_set_clip_state(struct pipe_context* pipe,
{
struct r300_context* r300 = r300_context(pipe);
+ r300->clip = *state;
+
if (r300_screen(pipe->screen)->caps->has_tcl) {
memcpy(r300->clip_state.state, state, sizeof(struct pipe_clip_state));
r300->clip_state.size = 29;
@@ -476,11 +483,8 @@ static void r300_bind_dsa_state(struct pipe_context* pipe,
void* state)
{
struct r300_context* r300 = r300_context(pipe);
- struct r300_screen* r300screen = r300_screen(pipe->screen);
- r300->dsa_state.state = state;
- r300->dsa_state.size = r300screen->caps->is_r500 ? 8 : 6;
- r300->dsa_state.dirty = TRUE;
+ UPDATE_STATE(state, r300->dsa_state);
}
/* Free DSA state. */
@@ -567,6 +571,7 @@ static void
{
struct r300_context* r300 = r300_context(pipe);
struct r300_screen* r300screen = r300_screen(pipe->screen);
+ struct pipe_framebuffer_state *old_state = r300->fb_state.state;
unsigned max_width, max_height;
uint32_t zbuffer_bpp = 0;
@@ -591,22 +596,30 @@ static void
return;
}
-
if (r300->draw) {
draw_flush(r300->draw);
}
- memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state));
+ r300->fb_state.dirty = TRUE;
- r300->fb_state.size = (10 * state->nr_cbufs) + (state->zsbuf ? 10 : 0) + 6;
+ /* If nr_cbufs is changed from zero to non-zero or vice versa... */
+ if (!!old_state->nr_cbufs != !!state->nr_cbufs) {
+ r300->blend_state.dirty = TRUE;
+ }
+ /* If zsbuf is set from NULL to non-NULL or vice versa.. */
+ if (!!old_state->zsbuf != !!state->zsbuf) {
+ r300->dsa_state.dirty = TRUE;
+ }
+ if (!r300->scissor_enabled) {
+ r300->scissor_state.dirty = TRUE;
+ }
r300_fb_update_tiling_flags(r300, r300->fb_state.state, state);
- /* XXX wait what */
- r300->blend_state.dirty = TRUE;
- r300->dsa_state.dirty = TRUE;
- r300->fb_state.dirty = TRUE;
- r300->scissor_state.dirty = TRUE;
+ memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state));
+
+ r300->fb_state.size = (10 * state->nr_cbufs) + (2 * (4 - state->nr_cbufs)) +
+ (state->zsbuf ? 10 : 0) + 8;
/* Polygon offset depends on the zbuffer bit depth. */
if (state->zsbuf && r300->polygon_offset_enabled) {
@@ -658,8 +671,10 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
r300->fs = fs;
r300_pick_fragment_shader(r300);
- if (r300->vs && r300_vertex_shader_setup_wpos(r300)) {
- r300->vertex_format_state.dirty = TRUE;
+ r300->rs_block_state.dirty = TRUE; /* Will be updated before the emission. */
+
+ if (r300->vs_state.state && r300_vertex_shader_setup_wpos(r300)) {
+ r300->vap_output_state.dirty = TRUE;
}
r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS;
@@ -709,32 +724,14 @@ static void* r300_create_rs_state(struct pipe_context* pipe,
rs->vap_control_status = R300_VC_32BIT_SWAP;
#endif
- /* If bypassing TCL, or if no TCL engine is present, turn off the HW TCL.
- * Else, enable HW TCL and force Draw's TCL off. */
- if (state->bypass_vs_clip_and_viewport ||
- !r300screen->caps->has_tcl) {
+ /* If no TCL engine is present, turn off the HW TCL. */
+ if (!r300screen->caps->has_tcl) {
rs->vap_control_status |= R300_VAP_TCL_BYPASS;
}
rs->point_size = pack_float_16_6x(state->point_size) |
(pack_float_16_6x(state->point_size) << R300_POINTSIZE_X_SHIFT);
- /* Point minimum and maximum sizes. This register has to be emitted,
- * and it'd be a step backwards to put it in invariant state. */
- if (r300screen->caps->is_r500) {
- rs->point_minmax =
- ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
- ((int)(4096.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
- } else if (r300screen->caps->is_r400) {
- rs->point_minmax =
- ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
- ((int)(4021.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
- } else {
- rs->point_minmax =
- ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
- ((int)(2560.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
- }
-
rs->line_control = pack_float_16_6x(state->line_width) |
R300_GA_LINE_CNTL_END_TYPE_COMP;
@@ -817,6 +814,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
{
struct r300_context* r300 = r300_context(pipe);
struct r300_rs_state* rs = (struct r300_rs_state*)state;
+ boolean scissor_was_enabled = r300->scissor_enabled;
if (r300->draw) {
draw_flush(r300->draw);
@@ -824,22 +822,18 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
}
if (rs) {
- r300->tcl_bypass = rs->rs.bypass_vs_clip_and_viewport;
r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw;
+ r300->scissor_enabled = rs->rs.scissor;
} else {
- r300->tcl_bypass = FALSE;
r300->polygon_offset_enabled = FALSE;
+ r300->scissor_enabled = FALSE;
}
- r300->rs_state.state = rs;
- r300->rs_state.dirty = TRUE;
- /* XXX Why is this still needed, dammit!? */
- r300->scissor_state.dirty = TRUE;
- r300->viewport_state.dirty = TRUE;
+ UPDATE_STATE(state, r300->rs_state);
+ r300->rs_state.size = 17 + (r300->polygon_offset_enabled ? 5 : 0);
- /* XXX Clean these up when we move to atom emits */
- if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) {
- r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
+ if (scissor_was_enabled != r300->scissor_enabled) {
+ r300->scissor_state.dirty = TRUE;
}
}
@@ -871,7 +865,7 @@ static void*
state->max_anisotropy > 0);
/* Unfortunately, r300-r500 don't support floating-point mipmap lods. */
- /* We must pass these to the emit function to clamp them properly. */
+ /* We must pass these to the merge function to clamp them properly. */
sampler->min_lod = MAX2((unsigned)state->min_lod, 0);
sampler->max_lod = MAX2((unsigned)ceilf(state->max_lod), 0);
@@ -881,7 +875,7 @@ static void*
sampler->filter1 |= r300_anisotropy(state->max_anisotropy);
- util_pack_color(state->border_color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc);
+ util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
sampler->border_color = uc.ui;
/* R500-specific fixups and optimizations */
@@ -897,23 +891,20 @@ static void r300_bind_sampler_states(struct pipe_context* pipe,
void** states)
{
struct r300_context* r300 = r300_context(pipe);
- int i;
+ struct r300_textures_state* state =
+ (struct r300_textures_state*)r300->textures_state.state;
if (count > 8) {
return;
}
- for (i = 0; i < count; i++) {
- if (r300->sampler_states[i] != states[i]) {
- r300->sampler_states[i] = (struct r300_sampler_state*)states[i];
- r300->dirty_state |= (R300_NEW_SAMPLER << i);
- }
- }
+ memcpy(state->sampler_states, states, sizeof(void*) * count);
+ state->sampler_count = count;
- r300->sampler_count = count;
+ r300->textures_state.dirty = TRUE;
/* Pick a fragment shader based on the texture compare state. */
- if (r300->fs && (r300->dirty_state & R300_ANY_NEW_SAMPLERS)) {
+ if (r300->fs && count) {
if (r300_pick_fragment_shader(r300)) {
r300->dirty_state |= R300_NEW_FRAGMENT_SHADER |
R300_NEW_FRAGMENT_SHADER_CONSTANTS;
@@ -937,21 +928,22 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
struct pipe_sampler_view** views)
{
struct r300_context* r300 = r300_context(pipe);
+ unsigned i;
boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500;
- int i;
+ boolean dirty_tex = FALSE;
/* XXX magic num */
if (count > 8) {
return;
}
-
+
for (i = 0; i < count; i++) {
if (r300->fragment_sampler_views[i] != views[i]) {
struct r300_texture *texture;
pipe_sampler_view_reference(&r300->fragment_sampler_views[i],
views[i]);
- r300->dirty_state |= (R300_NEW_TEXTURE << i);
+ dirty_tex = TRUE;
texture = (struct r300_texture *)views[i]->texture;
@@ -968,11 +960,16 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe,
if (r300->fragment_sampler_views[i]) {
pipe_sampler_view_reference(&r300->fragment_sampler_views[i],
NULL);
- r300->dirty_state |= (R300_NEW_TEXTURE << i);
}
}
r300->fragment_sampler_view_count = count;
+
+ r300->textures_state.dirty = TRUE;
+
+ if (dirty_tex) {
+ r300->texture_cache_inval.dirty = TRUE;
+ }
}
static struct pipe_sampler_view *
@@ -1009,7 +1006,9 @@ static void r300_set_scissor_state(struct pipe_context* pipe,
memcpy(r300->scissor_state.state, state,
sizeof(struct pipe_scissor_state));
- r300->scissor_state.dirty = TRUE;
+ if (r300->scissor_enabled) {
+ r300->scissor_state.dirty = TRUE;
+ }
}
static void r300_set_viewport_state(struct pipe_context* pipe,
@@ -1019,6 +1018,8 @@ static void r300_set_viewport_state(struct pipe_context* pipe,
struct r300_viewport_state* viewport =
(struct r300_viewport_state*)r300->viewport_state.state;
+ r300->viewport = *state;
+
/* Do the transform in HW. */
viewport->vte_control = R300_VTX_W0_FMT;
@@ -1058,27 +1059,32 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
const struct pipe_vertex_buffer* buffers)
{
struct r300_context* r300 = r300_context(pipe);
+ unsigned i, max_index = ~0;
memcpy(r300->vertex_buffer, buffers,
sizeof(struct pipe_vertex_buffer) * count);
+
+ for (i = 0; i < count; i++) {
+ max_index = MIN2(buffers[i].max_index, max_index);
+ }
+
r300->vertex_buffer_count = count;
+ r300->vertex_buffer_max_index = max_index;
if (r300->draw) {
draw_flush(r300->draw);
draw_set_vertex_buffers(r300->draw, count, buffers);
}
-
- r300->vertex_format_state.dirty = TRUE;
}
static boolean r300_validate_aos(struct r300_context *r300)
{
struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
- struct pipe_vertex_element *velem = r300->vertex_element;
+ struct pipe_vertex_element *velem = r300->velems->velem;
int i;
/* Check if formats and strides are aligned to the size of DWORD. */
- for (i = 0; i < r300->vertex_element_count; i++) {
+ for (i = 0; i < r300->velems->count; i++) {
if (vbuf[velem[i].vertex_buffer_index].stride % 4 != 0 ||
util_format_get_blocksize(velem[i].src_format) % 4 != 0) {
return FALSE;
@@ -1087,20 +1093,209 @@ static boolean r300_validate_aos(struct r300_context *r300)
return TRUE;
}
-static void r300_set_vertex_elements(struct pipe_context* pipe,
- unsigned count,
- const struct pipe_vertex_element* elements)
+static void r300_draw_emit_attrib(struct r300_context* r300,
+ enum attrib_emit emit,
+ enum interp_mode interp,
+ int index)
{
- struct r300_context* r300 = r300_context(pipe);
+ struct r300_vertex_shader* vs = r300->vs_state.state;
+ struct tgsi_shader_info* info = &vs->info;
+ int output;
+
+ output = draw_find_shader_output(r300->draw,
+ info->output_semantic_name[index],
+ info->output_semantic_index[index]);
+ draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output);
+}
+
+static void r300_draw_emit_all_attribs(struct r300_context* r300)
+{
+ struct r300_vertex_shader* vs = r300->vs_state.state;
+ struct r300_shader_semantics* vs_outputs = &vs->outputs;
+ int i, gen_count;
+
+ /* Position. */
+ if (vs_outputs->pos != ATTR_UNUSED) {
+ r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
+ vs_outputs->pos);
+ } else {
+ assert(0);
+ }
- memcpy(r300->vertex_element,
- elements,
- sizeof(struct pipe_vertex_element) * count);
- r300->vertex_element_count = count;
+ /* Point size. */
+ if (vs_outputs->psize != ATTR_UNUSED) {
+ r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS,
+ vs_outputs->psize);
+ }
+
+ /* Colors. */
+ for (i = 0; i < ATTR_COLOR_COUNT; i++) {
+ if (vs_outputs->color[i] != ATTR_UNUSED) {
+ r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR,
+ vs_outputs->color[i]);
+ }
+ }
+
+ /* XXX Back-face colors. */
+
+ /* Texture coordinates. */
+ gen_count = 0;
+ for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
+ if (vs_outputs->generic[i] != ATTR_UNUSED) {
+ r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
+ vs_outputs->generic[i]);
+ gen_count++;
+ }
+ }
+
+ /* Fog coordinates. */
+ if (vs_outputs->fog != ATTR_UNUSED) {
+ r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
+ vs_outputs->fog);
+ gen_count++;
+ }
+
+ /* XXX magic */
+ assert(gen_count <= 8);
+}
+
+/* Update the PSC tables. */
+static void r300_vertex_psc(struct r300_vertex_element_state *velems)
+{
+ struct r300_vertex_stream_state *vstream = &velems->vertex_stream;
+ uint16_t type, swizzle;
+ enum pipe_format format;
+ unsigned i;
+
+ assert(velems->count <= 16);
+
+ /* Vertex shaders have no semantics on their inputs,
+ * so PSC should just route stuff based on the vertex elements,
+ * and not on attrib information. */
+ for (i = 0; i < velems->count; i++) {
+ format = velems->velem[i].src_format;
+
+ type = r300_translate_vertex_data_type(format) |
+ (i << R300_DST_VEC_LOC_SHIFT);
+ swizzle = r300_translate_vertex_data_swizzle(format);
+
+ if (i & 1) {
+ vstream->vap_prog_stream_cntl[i >> 1] |= type << 16;
+ vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
+ } else {
+ vstream->vap_prog_stream_cntl[i >> 1] |= type;
+ vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
+ }
+ }
+
+ /* Set the last vector in the PSC. */
+ if (i) {
+ i -= 1;
+ }
+ vstream->vap_prog_stream_cntl[i >> 1] |=
+ (R300_LAST_VEC << (i & 1 ? 16 : 0));
+
+ vstream->count = (i >> 1) + 1;
+}
+
+/* Update the PSC tables for SW TCL, using Draw. */
+static void r300_swtcl_vertex_psc(struct r300_context *r300,
+ struct r300_vertex_element_state *velems)
+{
+ struct r300_vertex_stream_state *vstream = &velems->vertex_stream;
+ struct r300_vertex_shader* vs = r300->vs_state.state;
+ struct vertex_info* vinfo = &r300->vertex_info;
+ uint16_t type, swizzle;
+ enum pipe_format format;
+ unsigned i, attrib_count;
+ int* vs_output_tab = vs->stream_loc_notcl;
+
+ /* For each Draw attribute, route it to the fragment shader according
+ * to the vs_output_tab. */
+ attrib_count = vinfo->num_attribs;
+ DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count);
+ for (i = 0; i < attrib_count; i++) {
+ DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d,"
+ " vs_output_tab %d\n", vinfo->attrib[i].src_index,
+ vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit,
+ vs_output_tab[i]);
+ }
+
+ for (i = 0; i < attrib_count; i++) {
+ /* Make sure we have a proper destination for our attribute. */
+ assert(vs_output_tab[i] != -1);
+
+ format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
+
+ /* Obtain the type of data in this attribute. */
+ type = r300_translate_vertex_data_type(format) |
+ vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
+
+ /* Obtain the swizzle for this attribute. Note that the default
+ * swizzle in the hardware is not XYZW! */
+ swizzle = r300_translate_vertex_data_swizzle(format);
+
+ /* Add the attribute to the PSC table. */
+ if (i & 1) {
+ vstream->vap_prog_stream_cntl[i >> 1] |= type << 16;
+ vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
+ } else {
+ vstream->vap_prog_stream_cntl[i >> 1] |= type;
+ vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
+ }
+ }
+
+ /* Set the last vector in the PSC. */
+ if (i) {
+ i -= 1;
+ }
+ vstream->vap_prog_stream_cntl[i >> 1] |=
+ (R300_LAST_VEC << (i & 1 ? 16 : 0));
+
+ vstream->count = (i >> 1) + 1;
+}
+
+static void* r300_create_vertex_elements_state(struct pipe_context* pipe,
+ unsigned count,
+ const struct pipe_vertex_element* attribs)
+{
+ struct r300_context *r300 = r300_context(pipe);
+ struct r300_screen* r300screen = r300_screen(pipe->screen);
+ struct r300_vertex_element_state *velems;
+
+ assert(count <= PIPE_MAX_ATTRIBS);
+ velems = CALLOC_STRUCT(r300_vertex_element_state);
+ if (velems != NULL) {
+ velems->count = count;
+ memcpy(velems->velem, attribs, sizeof(struct pipe_vertex_element) * count);
+
+ if (r300screen->caps->has_tcl) {
+ r300_vertex_psc(velems);
+ } else {
+ memset(&r300->vertex_info, 0, sizeof(struct vertex_info));
+ r300_draw_emit_all_attribs(r300);
+ draw_compute_vertex_size(&r300->vertex_info);
+ r300_swtcl_vertex_psc(r300, velems);
+ }
+ }
+ return velems;
+}
+
+static void r300_bind_vertex_elements_state(struct pipe_context *pipe,
+ void *state)
+{
+ struct r300_context *r300 = r300_context(pipe);
+ struct r300_vertex_element_state *velems = state;
+
+ if (velems == NULL) {
+ return;
+ }
+
+ r300->velems = velems;
if (r300->draw) {
draw_flush(r300->draw);
- draw_set_vertex_elements(r300->draw, count, elements);
+ draw_set_vertex_elements(r300->draw, velems->count, velems->velem);
}
if (!r300_validate_aos(r300)) {
@@ -1108,6 +1303,14 @@ static void r300_set_vertex_elements(struct pipe_context* pipe,
assert(0);
abort();
}
+
+ UPDATE_STATE(&velems->vertex_stream, r300->vertex_stream_state);
+ r300->vertex_stream_state.size = (1 + velems->vertex_stream.count) * 2;
+}
+
+static void r300_delete_vertex_elements_state(struct pipe_context *pipe, void *state)
+{
+ FREE(state);
}
static void* r300_create_vs_state(struct pipe_context* pipe,
@@ -1115,64 +1318,71 @@ static void* r300_create_vs_state(struct pipe_context* pipe,
{
struct r300_context* r300 = r300_context(pipe);
- if (r300_screen(pipe->screen)->caps->has_tcl) {
- struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader);
- /* Copy state directly into shader. */
- vs->state = *shader;
- vs->state.tokens = tgsi_dup_tokens(shader->tokens);
-
- tgsi_scan_shader(shader->tokens, &vs->info);
+ struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader);
+ r300_vertex_shader_common_init(vs, shader);
- return (void*)vs;
+ if (r300_screen(pipe->screen)->caps->has_tcl) {
+ r300_translate_vertex_shader(r300, vs);
} else {
- return draw_create_vertex_shader(r300->draw, shader);
+ vs->draw_vs = draw_create_vertex_shader(r300->draw, shader);
}
+
+ return vs;
}
static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
{
struct r300_context* r300 = r300_context(pipe);
+ struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
- if (r300_screen(pipe->screen)->caps->has_tcl) {
- struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
+ if (vs == NULL) {
+ r300->vs_state.state = NULL;
+ return;
+ }
+ if (vs == r300->vs_state.state) {
+ return;
+ }
+ r300->vs_state.state = vs;
- if (vs == NULL) {
- r300->vs = NULL;
- return;
- } else if (!vs->translated) {
- r300_translate_vertex_shader(r300, vs);
- }
+ // VS output mapping for HWTCL or stream mapping for SWTCL to the RS block
+ if (r300->fs) {
+ r300_vertex_shader_setup_wpos(r300);
+ }
+ memcpy(r300->vap_output_state.state, &vs->vap_out,
+ sizeof(struct r300_vap_output_state));
+ r300->vap_output_state.dirty = TRUE;
- r300->vs = vs;
- if (r300->fs) {
- r300_vertex_shader_setup_wpos(r300);
- }
+ /* The majority of the RS block bits is dependent on the vertex shader. */
+ r300->rs_block_state.dirty = TRUE; /* Will be updated before the emission. */
+
+ if (r300_screen(pipe->screen)->caps->has_tcl) {
+ r300->vs_state.dirty = TRUE;
+ r300->vs_state.size = vs->code.length + 9;
- r300->vertex_format_state.dirty = TRUE;
+ r300->pvs_flush.dirty = TRUE;
- r300->dirty_state |=
- R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS;
+ r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
} else {
draw_flush(r300->draw);
draw_bind_vertex_shader(r300->draw,
- (struct draw_vertex_shader*)shader);
+ (struct draw_vertex_shader*)vs->draw_vs);
}
}
static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
{
struct r300_context* r300 = r300_context(pipe);
+ struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
if (r300_screen(pipe->screen)->caps->has_tcl) {
- struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
-
rc_constants_destroy(&vs->code.constants);
- FREE((void*)vs->state.tokens);
- FREE(shader);
} else {
draw_delete_vertex_shader(r300->draw,
- (struct draw_vertex_shader*)shader);
+ (struct draw_vertex_shader*)vs->draw_vs);
}
+
+ FREE((void*)vs->state.tokens);
+ FREE(shader);
}
static void r300_set_constant_buffer(struct pipe_context *pipe,
@@ -1223,8 +1433,12 @@ static void r300_set_constant_buffer(struct pipe_context *pipe,
r300->shader_constants[shader].count = buf->size / (4 * sizeof(float));
pipe_buffer_unmap(pipe->screen, buf);
- if (shader == PIPE_SHADER_VERTEX)
- r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
+ if (shader == PIPE_SHADER_VERTEX) {
+ if (r300screen->caps->has_tcl) {
+ r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
+ r300->pvs_flush.dirty = TRUE;
+ }
+ }
else if (shader == PIPE_SHADER_FRAGMENT)
r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
}
@@ -1273,7 +1487,10 @@ void r300_init_state_functions(struct r300_context* r300)
r300->context.set_viewport_state = r300_set_viewport_state;
r300->context.set_vertex_buffers = r300_set_vertex_buffers;
- r300->context.set_vertex_elements = r300_set_vertex_elements;
+
+ r300->context.create_vertex_elements_state = r300_create_vertex_elements_state;
+ r300->context.bind_vertex_elements_state = r300_bind_vertex_elements_state;
+ r300->context.delete_vertex_elements_state = r300_delete_vertex_elements_state;
r300->context.create_vs_state = r300_create_vs_state;
r300->context.bind_vs_state = r300_bind_vs_state;
diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c
index 2cbce9210a7..6b9f61acd7b 100644
--- a/src/gallium/drivers/r300/r300_state_derived.c
+++ b/src/gallium/drivers/r300/r300_state_derived.c
@@ -37,179 +37,6 @@
/* r300_state_derived: Various bits of state which are dependent upon
* currently bound CSO data. */
-static void r300_draw_emit_attrib(struct r300_context* r300,
- enum attrib_emit emit,
- enum interp_mode interp,
- int index)
-{
- struct tgsi_shader_info* info = &r300->vs->info;
- int output;
-
- output = draw_find_shader_output(r300->draw,
- info->output_semantic_name[index],
- info->output_semantic_index[index]);
- draw_emit_vertex_attr(
- (struct vertex_info*)r300->vertex_format_state.state,
- emit, interp, output);
-}
-
-static void r300_draw_emit_all_attribs(struct r300_context* r300)
-{
- struct r300_shader_semantics* vs_outputs = &r300->vs->outputs;
- int i, gen_count;
-
- /* Position. */
- if (vs_outputs->pos != ATTR_UNUSED) {
- r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
- vs_outputs->pos);
- } else {
- assert(0);
- }
-
- /* Point size. */
- if (vs_outputs->psize != ATTR_UNUSED) {
- r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS,
- vs_outputs->psize);
- }
-
- /* Colors. */
- for (i = 0; i < ATTR_COLOR_COUNT; i++) {
- if (vs_outputs->color[i] != ATTR_UNUSED) {
- r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR,
- vs_outputs->color[i]);
- }
- }
-
- /* XXX Back-face colors. */
-
- /* Texture coordinates. */
- gen_count = 0;
- for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
- if (vs_outputs->generic[i] != ATTR_UNUSED) {
- r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
- vs_outputs->generic[i]);
- gen_count++;
- }
- }
-
- /* Fog coordinates. */
- if (vs_outputs->fog != ATTR_UNUSED) {
- r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE,
- vs_outputs->fog);
- gen_count++;
- }
-
- /* XXX magic */
- assert(gen_count <= 8);
-}
-
-/* Update the PSC tables. */
-static void r300_vertex_psc(struct r300_context* r300)
-{
- struct r300_vertex_info *vformat =
- (struct r300_vertex_info*)r300->vertex_format_state.state;
- uint16_t type, swizzle;
- enum pipe_format format;
- unsigned i;
- int identity[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- int* stream_tab;
-
- /* If TCL is bypassed, map vertex streams to equivalent VS output
- * locations. */
- if (r300->tcl_bypass) {
- stream_tab = r300->vs->stream_loc_notcl;
- } else {
- stream_tab = identity;
- }
-
- /* Vertex shaders have no semantics on their inputs,
- * so PSC should just route stuff based on the vertex elements,
- * and not on attrib information. */
- DBG(r300, DBG_DRAW, "r300: vs expects %d attribs, routing %d elements"
- " in psc\n",
- r300->vs->info.num_inputs,
- r300->vertex_element_count);
-
- for (i = 0; i < r300->vertex_element_count; i++) {
- format = r300->vertex_element[i].src_format;
-
- type = r300_translate_vertex_data_type(format) |
- (stream_tab[i] << R300_DST_VEC_LOC_SHIFT);
- swizzle = r300_translate_vertex_data_swizzle(format);
-
- if (i & 1) {
- vformat->vap_prog_stream_cntl[i >> 1] |= type << 16;
- vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
- } else {
- vformat->vap_prog_stream_cntl[i >> 1] |= type;
- vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
- }
- }
-
- assert(i <= 15);
-
- /* Set the last vector in the PSC. */
- if (i) {
- i -= 1;
- }
- vformat->vap_prog_stream_cntl[i >> 1] |=
- (R300_LAST_VEC << (i & 1 ? 16 : 0));
-}
-
-/* Update the PSC tables for SW TCL, using Draw. */
-static void r300_swtcl_vertex_psc(struct r300_context* r300)
-{
- struct r300_vertex_info *vformat =
- (struct r300_vertex_info*)r300->vertex_format_state.state;
- struct vertex_info* vinfo = &vformat->vinfo;
- uint16_t type, swizzle;
- enum pipe_format format;
- unsigned i, attrib_count;
- int* vs_output_tab = r300->vs->stream_loc_notcl;
-
- /* For each Draw attribute, route it to the fragment shader according
- * to the vs_output_tab. */
- attrib_count = vinfo->num_attribs;
- DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count);
- for (i = 0; i < attrib_count; i++) {
- DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d,"
- " vs_output_tab %d\n", vinfo->attrib[i].src_index,
- vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit,
- vs_output_tab[i]);
- }
-
- for (i = 0; i < attrib_count; i++) {
- /* Make sure we have a proper destination for our attribute. */
- assert(vs_output_tab[i] != -1);
-
- format = draw_translate_vinfo_format(vinfo->attrib[i].emit);
-
- /* Obtain the type of data in this attribute. */
- type = r300_translate_vertex_data_type(format) |
- vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT;
-
- /* Obtain the swizzle for this attribute. Note that the default
- * swizzle in the hardware is not XYZW! */
- swizzle = r300_translate_vertex_data_swizzle(format);
-
- /* Add the attribute to the PSC table. */
- if (i & 1) {
- vformat->vap_prog_stream_cntl[i >> 1] |= type << 16;
- vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16;
- } else {
- vformat->vap_prog_stream_cntl[i >> 1] |= type;
- vformat->vap_prog_stream_cntl_ext[i >> 1] |= swizzle;
- }
- }
-
- /* Set the last vector in the PSC. */
- if (i) {
- i -= 1;
- }
- vformat->vap_prog_stream_cntl[i >> 1] |=
- (R300_LAST_VEC << (i & 1 ? 16 : 0));
-}
-
static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr,
boolean swizzle_0001)
{
@@ -416,33 +243,16 @@ static void r300_update_rs_block(struct r300_context* r300,
/* Now, after all that, see if we actually need to update the state. */
if (memcmp(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block))) {
memcpy(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block));
- r300->rs_block_state.size = 5 + count;
- r300->rs_block_state.dirty = TRUE;
+ r300->rs_block_state.size = 5 + count*2;
}
}
/* Update the shader-dependant states. */
static void r300_update_derived_shader_state(struct r300_context* r300)
{
- struct r300_screen* r300screen = r300_screen(r300->context.screen);
- struct r300_vertex_info *vformat =
- (struct r300_vertex_info*)r300->vertex_format_state.state;
- struct vertex_info* vinfo = &vformat->vinfo;
+ struct r300_vertex_shader* vs = r300->vs_state.state;
- /* Mmm, delicious hax */
- memset(r300->vertex_format_state.state, 0, sizeof(struct r300_vertex_info));
- memcpy(vinfo->hwfmt, r300->vs->hwfmt, sizeof(uint)*4);
-
- r300_update_rs_block(r300, &r300->vs->outputs, &r300->fs->inputs);
-
- if (r300screen->caps->has_tcl) {
- r300_vertex_psc(r300);
- } else {
- r300_draw_emit_all_attribs(r300);
- draw_compute_vertex_size(
- (struct vertex_info*)r300->vertex_format_state.state);
- r300_swtcl_vertex_psc(r300);
- }
+ r300_update_rs_block(r300, &vs->outputs, &r300->fs->inputs);
}
static boolean r300_dsa_writes_depth_stencil(struct r300_dsa_state* dsa)
@@ -516,14 +326,72 @@ static void r300_update_ztop(struct r300_context* r300)
r300->ztop_state.dirty = TRUE;
}
+static void r300_merge_textures_and_samplers(struct r300_context* r300)
+{
+ struct r300_textures_state *state =
+ (struct r300_textures_state*)r300->textures_state.state;
+ struct r300_texture_sampler_state *texstate;
+ struct r300_sampler_state *sampler;
+ struct r300_texture *tex;
+ unsigned min_level, max_level, i, size;
+ unsigned count = MIN2(state->texture_count, state->sampler_count);
+
+ state->tx_enable = 0;
+ size = 2;
+
+ for (i = 0; i < count; i++) {
+ if (state->textures[i] && state->sampler_states[i]) {
+ state->tx_enable |= 1 << i;
+
+ tex = state->textures[i];
+ sampler = state->sampler_states[i];
+
+ texstate = &state->regs[i];
+ memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3);
+ texstate->filter[0] = sampler->filter0;
+ texstate->filter[1] = sampler->filter1;
+ texstate->border_color = sampler->border_color;
+ texstate->tile_config = R300_TXO_MACRO_TILE(tex->macrotile) |
+ R300_TXO_MICRO_TILE(tex->microtile);
+
+ /* to emulate 1D textures through 2D ones correctly */
+ if (tex->tex.target == PIPE_TEXTURE_1D) {
+ texstate->filter[0] &= ~R300_TX_WRAP_T_MASK;
+ texstate->filter[0] |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
+ }
+
+ if (tex->is_npot) {
+ /* NPOT textures don't support mip filter, unfortunately.
+ * This prevents incorrect rendering. */
+ texstate->filter[0] &= ~R300_TX_MIN_FILTER_MIP_MASK;
+ } else {
+ /* determine min/max levels */
+ /* the MAX_MIP level is the largest (finest) one */
+ max_level = MIN2(sampler->max_lod, tex->tex.last_level);
+ min_level = MIN2(sampler->min_lod, max_level);
+ texstate->format[0] |= R300_TX_NUM_LEVELS(max_level);
+ texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level);
+ }
+
+ texstate->filter[0] |= i << 28;
+
+ size += 16;
+ state->count = i+1;
+ }
+ }
+
+ r300->textures_state.size = size;
+}
+
void r300_update_derived_state(struct r300_context* r300)
{
- /* XXX */
- if (r300->dirty_state &
- (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER) ||
- r300->vertex_format_state.dirty || r300->rs_state.dirty) {
+ if (r300->rs_block_state.dirty) {
r300_update_derived_shader_state(r300);
}
+ if (r300->textures_state.dirty) {
+ r300_merge_textures_and_samplers(r300);
+ }
+
r300_update_ztop(r300);
}
diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h
index a6083925326..a32924ed0a3 100644
--- a/src/gallium/drivers/r300/r300_state_inlines.h
+++ b/src/gallium/drivers/r300/r300_state_inlines.h
@@ -327,117 +327,6 @@ static INLINE uint32_t r300_anisotropy(unsigned max_aniso)
}
}
-/* Buffer formats. */
-
-/* Colorbuffer formats. This is the unswizzled format of the RB3D block's
- * output. For the swizzling of the targets, check the shader's format. */
-static INLINE uint32_t r300_translate_colorformat(enum pipe_format format)
-{
- switch (format) {
- /* 8-bit buffers */
- case PIPE_FORMAT_A8_UNORM:
- case PIPE_FORMAT_I8_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- return R300_COLOR_FORMAT_I8;
- /* 16-bit buffers */
- case PIPE_FORMAT_R5G6B5_UNORM:
- return R300_COLOR_FORMAT_RGB565;
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- return R300_COLOR_FORMAT_ARGB1555;
- case PIPE_FORMAT_A4R4G4B4_UNORM:
- return R300_COLOR_FORMAT_ARGB4444;
- /* 32-bit buffers */
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- case PIPE_FORMAT_R8G8B8X8_UNORM:
- return R300_COLOR_FORMAT_ARGB8888;
- /* XXX Not in pipe_format
- case PIPE_FORMAT_A32R32G32B32:
- return R300_COLOR_FORMAT_ARGB32323232;
- case PIPE_FORMAT_A16R16G16B16:
- return R300_COLOR_FORMAT_ARGB16161616;
- case PIPE_FORMAT_A10R10G10B10_UNORM:
- return R500_COLOR_FORMAT_ARGB10101010;
- case PIPE_FORMAT_A2R10G10B10_UNORM:
- return R500_COLOR_FORMAT_ARGB2101010;
- case PIPE_FORMAT_I10_UNORM:
- return R500_COLOR_FORMAT_I10; */
- default:
- debug_printf("r300: Implementation error: "
- "Got unsupported color format %s in %s\n",
- util_format_name(format), __FUNCTION__);
- assert(0);
- break;
- }
- return 0;
-}
-
-/* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */
-static INLINE uint32_t r300_translate_zsformat(enum pipe_format format)
-{
- switch (format) {
- /* 16-bit depth, no stencil */
- case PIPE_FORMAT_Z16_UNORM:
- return R300_DEPTHFORMAT_16BIT_INT_Z;
- /* 24-bit depth, ignored stencil */
- case PIPE_FORMAT_Z24X8_UNORM:
- /* 24-bit depth, 8-bit stencil */
- case PIPE_FORMAT_Z24S8_UNORM:
- return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL;
- default:
- debug_printf("r300: Implementation error: "
- "Got unsupported ZS format %s in %s\n",
- util_format_name(format), __FUNCTION__);
- assert(0);
- break;
- }
- return 0;
-}
-
-/* Shader output formats. This is essentially the swizzle from the shader
- * to the RB3D block.
- *
- * Note that formats are stored from C3 to C0. */
-static INLINE uint32_t r300_translate_out_fmt(enum pipe_format format)
-{
- switch (format) {
- case PIPE_FORMAT_R5G6B5_UNORM:
- /* C_5_6_5 is missing in US_OUT_FMT, but C4_8 works just fine. */
- case PIPE_FORMAT_A1R5G5B5_UNORM:
- /* C_1_5_5_5 is missing in US_OUT_FMT, but C4_8 works just fine. */
- case PIPE_FORMAT_A4R4G4B4_UNORM:
- /* C4_4 is missing in US_OUT_FMT, but C4_8 works just fine. */
- case PIPE_FORMAT_A8R8G8B8_UNORM:
- case PIPE_FORMAT_X8R8G8B8_UNORM:
- return R300_US_OUT_FMT_C4_8 |
- R300_C0_SEL_B | R300_C1_SEL_G |
- R300_C2_SEL_R | R300_C3_SEL_A;
- case PIPE_FORMAT_R8G8B8A8_UNORM:
- case PIPE_FORMAT_R8G8B8X8_UNORM:
- return R300_US_OUT_FMT_C4_8 |
- R300_C0_SEL_A | R300_C1_SEL_B |
- R300_C2_SEL_G | R300_C3_SEL_R;
-
- /* 8-bit outputs */
- case PIPE_FORMAT_A8_UNORM:
- return R300_US_OUT_FMT_C4_8 |
- R300_C0_SEL_A;
- case PIPE_FORMAT_I8_UNORM:
- case PIPE_FORMAT_L8_UNORM:
- return R300_US_OUT_FMT_C4_8 |
- R300_C0_SEL_R;
- /* R300_OUT_SIGN(x) */
- default:
- debug_printf("r300: Implementation error: "
- "Got unsupported output format %s in %s\n",
- util_format_name(format), __FUNCTION__);
- assert(0);
- return R300_US_OUT_FMT_UNUSED;
- }
- return 0;
-}
-
/* Non-CSO state. (For now.) */
static INLINE uint32_t r300_translate_gb_pipes(int pipe_count)
@@ -459,44 +348,16 @@ static INLINE uint32_t r300_translate_gb_pipes(int pipe_count)
return 0;
}
-/* Utility function to count the number of components in RGBAZS formats.
- * XXX should go to util or p_format.h */
-static INLINE unsigned pf_component_count(enum pipe_format format) {
- unsigned count = 0;
-
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)) {
- count++;
- }
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 1)) {
- count++;
- }
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 2)) {
- count++;
- }
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3)) {
- count++;
- }
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 0)) {
- count++;
- }
- if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
- count++;
- }
-
- return count;
-}
-
/* Translate pipe_formats into PSC vertex types. */
static INLINE uint16_t
r300_translate_vertex_data_type(enum pipe_format format) {
uint32_t result = 0;
const struct util_format_description *desc;
- unsigned components = pf_component_count(format);
+ unsigned components = util_format_get_nr_components(format);
desc = util_format_description(format);
- if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
- desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) {
+ if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
debug_printf("r300: Bad format %s in %s:%d\n", util_format_name(format),
__FUNCTION__, __LINE__);
assert(0);
@@ -565,36 +426,19 @@ r300_translate_vertex_data_type(enum pipe_format format) {
static INLINE uint16_t
r300_translate_vertex_data_swizzle(enum pipe_format format) {
const struct util_format_description *desc = util_format_description(format);
- unsigned swizzle[4], i;
assert(format);
- if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
- desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) {
+ if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
debug_printf("r300: Bad format %s in %s:%d\n",
util_format_name(format), __FUNCTION__, __LINE__);
return 0;
}
- /* Swizzles for 8bits formats are in the reversed order, not sure why. */
- if (desc->channel[0].size == 8) {
- for (i = 0; i < 4; i++) {
- if (desc->swizzle[i] <= 3) {
- swizzle[i] = 3 - desc->swizzle[i];
- } else {
- swizzle[i] = desc->swizzle[i];
- }
- }
- } else {
- for (i = 0; i < 4; i++) {
- swizzle[i] = desc->swizzle[i];
- }
- }
-
- return ((swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) |
- (swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) |
- (swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) |
- (swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) |
+ return ((desc->swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) |
+ (desc->swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) |
+ (desc->swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) |
+ (desc->swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) |
(0xf << R300_WRITE_ENA_SHIFT));
}
diff --git a/src/gallium/drivers/r300/r300_state_invariant.c b/src/gallium/drivers/r300/r300_state_invariant.c
index 97927acf1b4..4a2c68269b1 100644
--- a/src/gallium/drivers/r300/r300_state_invariant.c
+++ b/src/gallium/drivers/r300/r300_state_invariant.c
@@ -38,7 +38,8 @@ struct pipe_viewport_state r300_viewport_identity = {
*
* Note that eventually this should be empty, but it's useful for development
* and general unduplication of code. */
-void r300_emit_invariant_state(struct r300_context* r300, void* state)
+void r300_emit_invariant_state(struct r300_context* r300,
+ unsigned size, void* state)
{
struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps;
CS_LOCALS(r300);
diff --git a/src/gallium/drivers/r300/r300_state_invariant.h b/src/gallium/drivers/r300/r300_state_invariant.h
index 5d1a9636545..83d031c7fe9 100644
--- a/src/gallium/drivers/r300/r300_state_invariant.h
+++ b/src/gallium/drivers/r300/r300_state_invariant.h
@@ -25,6 +25,7 @@
struct r300_context;
-void r300_emit_invariant_state(struct r300_context* r300, void* state);
+void r300_emit_invariant_state(struct r300_context* r300,
+ unsigned size, void* state);
#endif /* R300_STATE_INVARIANT_H */
diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
index 34a49bec34c..04124afd4dc 100644
--- a/src/gallium/drivers/r300/r300_texture.c
+++ b/src/gallium/drivers/r300/r300_texture.c
@@ -1,5 +1,6 @@
/*
* Copyright 2008 Corbin Simpson <[email protected]>
+ * Copyright 2010 Marek Olšák <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -29,6 +30,7 @@
#include "r300_context.h"
#include "r300_texture.h"
#include "r300_screen.h"
+#include "r300_state_inlines.h"
#include "radeon_winsys.h"
@@ -44,12 +46,465 @@ static const unsigned microblock_table[5][3][2] = {
{{ 2, 1}, {0, 0}, {0, 0}} /* 128 bits per pixel */
};
+/* Translate a pipe_format into a useful texture format for sampling.
+ *
+ * Some special formats are translated directly using R300_EASY_TX_FORMAT,
+ * but the majority of them is translated in a generic way, automatically
+ * supporting all the formats hw can support.
+ *
+ * R300_EASY_TX_FORMAT swizzles the texture.
+ * Note the signature of R300_EASY_TX_FORMAT:
+ * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT);
+ *
+ * The FORMAT specifies how the texture sampler will treat the texture, and
+ * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
+static uint32_t r300_translate_texformat(enum pipe_format format)
+{
+ uint32_t result = 0;
+ const struct util_format_description *desc;
+ unsigned components = 0, i;
+ boolean uniform = TRUE;
+ const uint32_t swizzle_shift[4] = {
+ R300_TX_FORMAT_R_SHIFT,
+ R300_TX_FORMAT_G_SHIFT,
+ R300_TX_FORMAT_B_SHIFT,
+ R300_TX_FORMAT_A_SHIFT
+ };
+ const uint32_t swizzle[4] = {
+ R300_TX_FORMAT_X,
+ R300_TX_FORMAT_Y,
+ R300_TX_FORMAT_Z,
+ R300_TX_FORMAT_W
+ };
+ const uint32_t sign_bit[4] = {
+ R300_TX_FORMAT_SIGNED_X,
+ R300_TX_FORMAT_SIGNED_Y,
+ R300_TX_FORMAT_SIGNED_Z,
+ R300_TX_FORMAT_SIGNED_W,
+ };
+
+ desc = util_format_description(format);
+
+ /* Colorspace (return non-RGB formats directly). */
+ switch (desc->colorspace) {
+ /* Depth stencil formats. */
+ case UTIL_FORMAT_COLORSPACE_ZS:
+ switch (format) {
+ case PIPE_FORMAT_Z16_UNORM:
+ return R300_EASY_TX_FORMAT(X, X, X, X, X16);
+ case PIPE_FORMAT_X8Z24_UNORM:
+ case PIPE_FORMAT_S8Z24_UNORM:
+ return R300_EASY_TX_FORMAT(X, X, X, X, W24_FP);
+ default:
+ return ~0; /* Unsupported. */
+ }
+
+ /* YUV formats. */
+ case UTIL_FORMAT_COLORSPACE_YUV:
+ result |= R300_TX_FORMAT_YUV_TO_RGB;
+
+ switch (format) {
+ case PIPE_FORMAT_UYVY:
+ return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | result;
+ case PIPE_FORMAT_YUYV:
+ return R300_EASY_TX_FORMAT(X, Y, Z, ONE, VYUY422) | result;
+ default:
+ return ~0; /* Unsupported/unknown. */
+ }
+
+ /* Add gamma correction. */
+ case UTIL_FORMAT_COLORSPACE_SRGB:
+ result |= R300_TX_FORMAT_GAMMA;
+ break;
+
+ default:;
+ }
+
+ /* Add swizzle. */
+ for (i = 0; i < 4; i++) {
+ switch (desc->swizzle[i]) {
+ case UTIL_FORMAT_SWIZZLE_X:
+ case UTIL_FORMAT_SWIZZLE_NONE:
+ result |= swizzle[0] << swizzle_shift[i];
+ break;
+ case UTIL_FORMAT_SWIZZLE_Y:
+ result |= swizzle[1] << swizzle_shift[i];
+ break;
+ case UTIL_FORMAT_SWIZZLE_Z:
+ result |= swizzle[2] << swizzle_shift[i];
+ break;
+ case UTIL_FORMAT_SWIZZLE_W:
+ result |= swizzle[3] << swizzle_shift[i];
+ break;
+ case UTIL_FORMAT_SWIZZLE_0:
+ result |= R300_TX_FORMAT_ZERO << swizzle_shift[i];
+ break;
+ case UTIL_FORMAT_SWIZZLE_1:
+ result |= R300_TX_FORMAT_ONE << swizzle_shift[i];
+ break;
+ default:
+ return ~0; /* Unsupported. */
+ }
+ }
+
+ /* Compressed formats. */
+ if (desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED) {
+ switch (format) {
+ case PIPE_FORMAT_DXT1_RGB:
+ case PIPE_FORMAT_DXT1_RGBA:
+ case PIPE_FORMAT_DXT1_SRGB:
+ case PIPE_FORMAT_DXT1_SRGBA:
+ return R300_TX_FORMAT_DXT1 | result;
+ case PIPE_FORMAT_DXT3_RGBA:
+ case PIPE_FORMAT_DXT3_SRGBA:
+ return R300_TX_FORMAT_DXT3 | result;
+ case PIPE_FORMAT_DXT5_RGBA:
+ case PIPE_FORMAT_DXT5_SRGBA:
+ return R300_TX_FORMAT_DXT5 | result;
+ default:
+ return ~0; /* Unsupported/unknown. */
+ }
+ }
+
+ /* Get the number of components. */
+ for (i = 0; i < 4; i++) {
+ if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
+ ++components;
+ }
+ }
+
+ /* Add sign. */
+ for (i = 0; i < components; i++) {
+ if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
+ result |= sign_bit[i];
+ }
+ }
+
+ /* See whether the components are of the same size. */
+ for (i = 1; i < components; i++) {
+ uniform = uniform && desc->channel[0].size == desc->channel[i].size;
+ }
+
+ /* Non-uniform formats. */
+ if (!uniform) {
+ switch (components) {
+ case 3:
+ if (desc->channel[0].size == 5 &&
+ desc->channel[1].size == 6 &&
+ desc->channel[2].size == 5) {
+ return R300_TX_FORMAT_Z5Y6X5 | result;
+ }
+ if (desc->channel[0].size == 5 &&
+ desc->channel[1].size == 5 &&
+ desc->channel[2].size == 6) {
+ return R300_TX_FORMAT_Z6Y5X5 | result;
+ }
+ return ~0; /* Unsupported/unknown. */
+
+ case 4:
+ if (desc->channel[0].size == 5 &&
+ desc->channel[1].size == 5 &&
+ desc->channel[2].size == 5 &&
+ desc->channel[3].size == 1) {
+ return R300_TX_FORMAT_W1Z5Y5X5 | result;
+ }
+ if (desc->channel[0].size == 10 &&
+ desc->channel[1].size == 10 &&
+ desc->channel[2].size == 10 &&
+ desc->channel[3].size == 2) {
+ return R300_TX_FORMAT_W2Z10Y10X10 | result;
+ }
+ }
+ return ~0; /* Unsupported/unknown. */
+ }
+
+ /* And finally, uniform formats. */
+ switch (desc->channel[0].type) {
+ case UTIL_FORMAT_TYPE_UNSIGNED:
+ case UTIL_FORMAT_TYPE_SIGNED:
+ if (!desc->channel[0].normalized &&
+ desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB) {
+ return ~0;
+ }
+
+ switch (desc->channel[0].size) {
+ case 4:
+ switch (components) {
+ case 2:
+ return R300_TX_FORMAT_Y4X4 | result;
+ case 4:
+ return R300_TX_FORMAT_W4Z4Y4X4 | result;
+ }
+ return ~0;
+
+ case 8:
+ switch (components) {
+ case 1:
+ return R300_TX_FORMAT_X8 | result;
+ case 2:
+ return R300_TX_FORMAT_Y8X8 | result;
+ case 4:
+ return R300_TX_FORMAT_W8Z8Y8X8 | result;
+ }
+ return ~0;
+
+ case 16:
+ switch (components) {
+ case 1:
+ return R300_TX_FORMAT_X16 | result;
+ case 2:
+ return R300_TX_FORMAT_Y16X16 | result;
+ case 4:
+ return R300_TX_FORMAT_W16Z16Y16X16 | result;
+ }
+ }
+ return ~0;
+
+/* XXX Enable float textures here. */
+#if 0
+ case UTIL_FORMAT_TYPE_FLOAT:
+ switch (desc->channel[0].size) {
+ case 16:
+ switch (components) {
+ case 1:
+ return R300_TX_FORMAT_16F | result;
+ case 2:
+ return R300_TX_FORMAT_16F_16F | result;
+ case 4:
+ return R300_TX_FORMAT_16F_16F_16F_16F | result;
+ }
+ return ~0;
+
+ case 32:
+ switch (components) {
+ case 1:
+ return R300_TX_FORMAT_32F | result;
+ case 2:
+ return R300_TX_FORMAT_32F_32F | result;
+ case 4:
+ return R300_TX_FORMAT_32F_32F_32F_32F | result;
+ }
+ }
+#endif
+ }
+
+ return ~0; /* Unsupported/unknown. */
+}
+
+/* Buffer formats. */
+
+/* Colorbuffer formats. This is the unswizzled format of the RB3D block's
+ * output. For the swizzling of the targets, check the shader's format. */
+static uint32_t r300_translate_colorformat(enum pipe_format format)
+{
+ switch (format) {
+ /* 8-bit buffers. */
+ case PIPE_FORMAT_A8_UNORM:
+ case PIPE_FORMAT_I8_UNORM:
+ case PIPE_FORMAT_L8_UNORM:
+ case PIPE_FORMAT_L8_SRGB:
+ case PIPE_FORMAT_R8_UNORM:
+ case PIPE_FORMAT_R8_SNORM:
+ return R300_COLOR_FORMAT_I8;
+
+ /* 16-bit buffers. */
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ return R300_COLOR_FORMAT_RGB565;
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ return R300_COLOR_FORMAT_ARGB1555;
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ return R300_COLOR_FORMAT_ARGB4444;
+
+ /* 32-bit buffers. */
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_B8G8R8A8_SRGB:
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_B8G8R8X8_SRGB:
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ case PIPE_FORMAT_A8R8G8B8_SRGB:
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ case PIPE_FORMAT_X8R8G8B8_SRGB:
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ case PIPE_FORMAT_R8G8B8A8_SNORM:
+ case PIPE_FORMAT_A8B8G8R8_SRGB:
+ case PIPE_FORMAT_X8B8G8R8_UNORM:
+ case PIPE_FORMAT_X8B8G8R8_SRGB:
+ case PIPE_FORMAT_R8SG8SB8UX8U_NORM:
+ return R300_COLOR_FORMAT_ARGB8888;
+ case PIPE_FORMAT_R10G10B10A2_UNORM:
+ return R500_COLOR_FORMAT_ARGB2101010; /* R5xx-only? */
+
+ /* 64-bit buffers. */
+ case PIPE_FORMAT_R16G16B16A16_UNORM:
+ case PIPE_FORMAT_R16G16B16A16_SNORM:
+ //case PIPE_FORMAT_R16G16B16A16_FLOAT: /* not in pipe_format */
+ return R300_COLOR_FORMAT_ARGB16161616;
+
+/* XXX Enable float textures here. */
+#if 0
+ /* 128-bit buffers. */
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ return R300_COLOR_FORMAT_ARGB32323232;
+#endif
+
+ /* YUV buffers. */
+ case PIPE_FORMAT_UYVY:
+ return R300_COLOR_FORMAT_YVYU;
+ case PIPE_FORMAT_YUYV:
+ return R300_COLOR_FORMAT_VYUY;
+ default:
+ return ~0; /* Unsupported. */
+ }
+}
+
+/* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */
+static uint32_t r300_translate_zsformat(enum pipe_format format)
+{
+ switch (format) {
+ /* 16-bit depth, no stencil */
+ case PIPE_FORMAT_Z16_UNORM:
+ return R300_DEPTHFORMAT_16BIT_INT_Z;
+ /* 24-bit depth, ignored stencil */
+ case PIPE_FORMAT_X8Z24_UNORM:
+ /* 24-bit depth, 8-bit stencil */
+ case PIPE_FORMAT_S8Z24_UNORM:
+ return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL;
+ default:
+ return ~0; /* Unsupported. */
+ }
+}
+
+/* Shader output formats. This is essentially the swizzle from the shader
+ * to the RB3D block.
+ *
+ * Note that formats are stored from C3 to C0. */
+static uint32_t r300_translate_out_fmt(enum pipe_format format)
+{
+ uint32_t modifier = 0;
+ unsigned i;
+ const struct util_format_description *desc;
+ static const uint32_t sign_bit[4] = {
+ R300_OUT_SIGN(0x1),
+ R300_OUT_SIGN(0x2),
+ R300_OUT_SIGN(0x4),
+ R300_OUT_SIGN(0x8),
+ };
+
+ desc = util_format_description(format);
+
+ /* Specifies how the shader output is written to the fog unit. */
+ if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
+ /* The gamma correction causes precision loss so we need
+ * higher precision to maintain reasonable quality.
+ * It has nothing to do with the colorbuffer format. */
+ modifier |= R300_US_OUT_FMT_C4_10_GAMMA;
+ } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) {
+ if (desc->channel[0].size == 32) {
+ modifier |= R300_US_OUT_FMT_C4_32_FP;
+ } else {
+ modifier |= R300_US_OUT_FMT_C4_16_FP;
+ }
+ } else {
+ if (desc->channel[0].size == 16) {
+ modifier |= R300_US_OUT_FMT_C4_16;
+ } else {
+ /* C4_8 seems to be used for the formats whose pixel size
+ * is <= 32 bits. */
+ modifier |= R300_US_OUT_FMT_C4_8;
+ }
+ }
+
+ /* Add sign. */
+ for (i = 0; i < 4; i++)
+ if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
+ modifier |= sign_bit[i];
+ }
+
+ /* Add swizzles and return. */
+ switch (format) {
+ /* 8-bit outputs.
+ * COLORFORMAT_I8 stores the C2 component. */
+ case PIPE_FORMAT_A8_UNORM:
+ return modifier | R300_C2_SEL_A;
+ case PIPE_FORMAT_I8_UNORM:
+ case PIPE_FORMAT_L8_UNORM:
+ case PIPE_FORMAT_L8_SRGB:
+ case PIPE_FORMAT_R8_UNORM:
+ case PIPE_FORMAT_R8_SNORM:
+ return modifier | R300_C2_SEL_R;
+
+ /* ARGB 32-bit outputs. */
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ case PIPE_FORMAT_B5G5R5A1_UNORM:
+ case PIPE_FORMAT_B4G4R4A4_UNORM:
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ case PIPE_FORMAT_B8G8R8A8_SRGB:
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ case PIPE_FORMAT_B8G8R8X8_SRGB:
+ return modifier |
+ R300_C0_SEL_B | R300_C1_SEL_G |
+ R300_C2_SEL_R | R300_C3_SEL_A;
+
+ /* BGRA 32-bit outputs. */
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ case PIPE_FORMAT_A8R8G8B8_SRGB:
+ case PIPE_FORMAT_X8R8G8B8_UNORM:
+ case PIPE_FORMAT_X8R8G8B8_SRGB:
+ return modifier |
+ R300_C0_SEL_A | R300_C1_SEL_R |
+ R300_C2_SEL_G | R300_C3_SEL_B;
+
+ /* RGBA 32-bit outputs. */
+ case PIPE_FORMAT_A8B8G8R8_UNORM:
+ case PIPE_FORMAT_R8G8B8A8_SNORM:
+ case PIPE_FORMAT_A8B8G8R8_SRGB:
+ case PIPE_FORMAT_X8B8G8R8_UNORM:
+ case PIPE_FORMAT_X8B8G8R8_SRGB:
+ return modifier |
+ R300_C0_SEL_A | R300_C1_SEL_B |
+ R300_C2_SEL_G | R300_C3_SEL_R;
+
+ /* ABGR 32-bit outputs. */
+ case PIPE_FORMAT_R8SG8SB8UX8U_NORM:
+ case PIPE_FORMAT_R10G10B10A2_UNORM:
+ /* RGBA high precision outputs (same swizzles as ABGR low precision) */
+ case PIPE_FORMAT_R16G16B16A16_UNORM:
+ case PIPE_FORMAT_R16G16B16A16_SNORM:
+ //case PIPE_FORMAT_R16G16B16A16_FLOAT: /* not in pipe_format */
+ case PIPE_FORMAT_R32G32B32A32_FLOAT:
+ return modifier |
+ R300_C0_SEL_R | R300_C1_SEL_G |
+ R300_C2_SEL_B | R300_C3_SEL_A;
+
+ default:
+ return ~0; /* Unsupported. */
+ }
+}
+
+boolean r300_is_colorbuffer_format_supported(enum pipe_format format)
+{
+ return r300_translate_colorformat(format) != ~0 &&
+ r300_translate_out_fmt(format) != ~0;
+}
+
+boolean r300_is_zs_format_supported(enum pipe_format format)
+{
+ return r300_translate_zsformat(format) != ~0;
+}
+
+boolean r300_is_sampler_format_supported(enum pipe_format format)
+{
+ return r300_translate_texformat(format) != ~0;
+}
+
static void r300_setup_texture_state(struct r300_screen* screen, struct r300_texture* tex)
{
- struct r300_texture_state* state = &tex->state;
+ struct r300_texture_format_state* state = &tex->state;
struct pipe_texture *pt = &tex->tex;
+ unsigned i;
boolean is_r500 = screen->caps->is_r500;
+ /* Set sampler state. */
state->format0 = R300_TX_WIDTH((pt->width0 - 1) & 0x7ff) |
R300_TX_HEIGHT((pt->height0 - 1) & 0x7ff);
@@ -83,6 +538,26 @@ static void r300_setup_texture_state(struct r300_screen* screen, struct r300_tex
SCREEN_DBG(screen, DBG_TEX, "r300: Set texture state (%dx%d, %d levels)\n",
pt->width0, pt->height0, pt->last_level);
+
+ /* Set framebuffer state. */
+ if (util_format_is_depth_or_stencil(tex->tex.format)) {
+ for (i = 0; i <= tex->tex.last_level; i++) {
+ tex->fb_state.depthpitch[i] =
+ tex->pitch[i] |
+ R300_DEPTHMACROTILE(tex->mip_macrotile[i]) |
+ R300_DEPTHMICROTILE(tex->microtile);
+ }
+ tex->fb_state.zb_format = r300_translate_zsformat(tex->tex.format);
+ } else {
+ for (i = 0; i <= tex->tex.last_level; i++) {
+ tex->fb_state.colorpitch[i] =
+ tex->pitch[i] |
+ r300_translate_colorformat(tex->tex.format) |
+ R300_COLOR_TILE(tex->mip_macrotile[i]) |
+ R300_COLOR_MICROTILE(tex->microtile);
+ }
+ tex->fb_state.us_out_fmt = r300_translate_out_fmt(tex->tex.format);
+ }
}
void r300_texture_reinterpret_format(struct pipe_screen *screen,
@@ -142,18 +617,23 @@ static unsigned r300_texture_get_tile_size(struct r300_texture* tex,
/* Return true if macrotiling should be enabled on the miplevel. */
static boolean r300_texture_macro_switch(struct r300_texture *tex,
unsigned level,
- boolean rv350_mode)
+ boolean rv350_mode,
+ int dim)
{
- unsigned tile_width, width;
+ unsigned tile, texdim;
- tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH, TRUE);
- width = u_minify(tex->tex.width0, level);
+ tile = r300_texture_get_tile_size(tex, dim, TRUE);
+ if (dim == TILE_WIDTH) {
+ texdim = u_minify(tex->tex.width0, level);
+ } else {
+ texdim = u_minify(tex->tex.height0, level);
+ }
/* See TX_FILTER1_n.MACRO_SWITCH. */
if (rv350_mode) {
- return width >= tile_width;
+ return texdim >= tile;
} else {
- return width > tile_width;
+ return texdim > tile;
}
}
@@ -217,9 +697,10 @@ static void r300_setup_miptree(struct r300_screen* screen,
for (i = 0; i <= base->last_level; i++) {
/* Let's see if this miplevel can be macrotiled. */
- tex->mip_macrotile[i] = (tex->macrotile == R300_BUFFER_TILED &&
- r300_texture_macro_switch(tex, i, rv350_mode)) ?
- R300_BUFFER_TILED : R300_BUFFER_LINEAR;
+ tex->mip_macrotile[i] =
+ (tex->macrotile == R300_BUFFER_TILED &&
+ r300_texture_macro_switch(tex, i, rv350_mode, TILE_WIDTH)) ?
+ R300_BUFFER_TILED : R300_BUFFER_LINEAR;
stride = r300_texture_get_stride(screen, tex, i);
nblocksy = r300_texture_get_nblocksy(tex, i);
@@ -249,10 +730,46 @@ static void r300_setup_flags(struct r300_texture* tex)
!util_is_power_of_two(tex->tex.height0);
}
+static void r300_setup_tiling(struct pipe_screen *screen,
+ struct r300_texture *tex)
+{
+ enum pipe_format format = tex->tex.format;
+ boolean rv350_mode = r300_screen(screen)->caps->family >= CHIP_FAMILY_RV350;
+
+ if (util_format_is_compressed(format)) {
+ return;
+ }
+
+ if (tex->tex.width0 == 1 ||
+ tex->tex.height0 == 1) {
+ return;
+ }
+
+ /* Set microtiling. */
+ switch (util_format_get_blocksize(format)) {
+ case 1:
+ case 4:
+ tex->microtile = R300_BUFFER_TILED;
+ break;
+
+ /* XXX Square-tiling doesn't work with kernel older than 2.6.34,
+ * XXX need to check the DRM version */
+ /*case 2:
+ case 8:
+ tex->microtile = R300_BUFFER_SQUARETILED;
+ break;*/
+ }
+
+ /* Set macrotiling. */
+ if (r300_texture_macro_switch(tex, 0, rv350_mode, TILE_WIDTH) &&
+ r300_texture_macro_switch(tex, 0, rv350_mode, TILE_HEIGHT)) {
+ tex->macrotile = R300_BUFFER_TILED;
+ }
+}
+
/* Create a new texture. */
-static struct pipe_texture*
- r300_texture_create(struct pipe_screen* screen,
- const struct pipe_texture* template)
+static struct pipe_texture* r300_texture_create(struct pipe_screen* screen,
+ const struct pipe_texture* template)
{
struct r300_texture* tex = CALLOC_STRUCT(r300_texture);
struct r300_screen* rscreen = r300_screen(screen);
@@ -267,6 +784,9 @@ static struct pipe_texture*
tex->tex.screen = screen;
r300_setup_flags(tex);
+ if (!(template->tex_usage & R300_TEXTURE_USAGE_TRANSFER)) {
+ r300_setup_tiling(screen, tex);
+ }
r300_setup_miptree(rscreen, tex);
r300_setup_texture_state(rscreen, tex);
@@ -331,14 +851,17 @@ static void r300_tex_surface_destroy(struct pipe_surface* s)
FREE(s);
}
+
static struct pipe_texture*
- r300_texture_blanket(struct pipe_screen* screen,
- const struct pipe_texture* base,
- const unsigned* stride,
- struct pipe_buffer* buffer)
+ r300_texture_from_handle(struct pipe_screen* screen,
+ const struct pipe_texture* base,
+ struct winsys_handle *whandle)
{
- struct r300_texture* tex;
+ struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
struct r300_screen* rscreen = r300_screen(screen);
+ struct pipe_buffer *buffer;
+ struct r300_texture* tex;
+ unsigned stride;
/* Support only 2D textures without mipmaps */
if (base->target != PIPE_TEXTURE_2D ||
@@ -347,6 +870,11 @@ static struct pipe_texture*
return NULL;
}
+ buffer = winsys->buffer_from_handle(winsys, screen, whandle, &stride);
+ if (!buffer) {
+ return NULL;
+ }
+
tex = CALLOC_STRUCT(r300_texture);
if (!tex) {
return NULL;
@@ -356,17 +884,38 @@ static struct pipe_texture*
pipe_reference_init(&tex->tex.reference, 1);
tex->tex.screen = screen;
- tex->stride_override = *stride;
- tex->pitch[0] = *stride / util_format_get_blocksize(base->format);
+ tex->stride_override = stride;
+ tex->pitch[0] = stride / util_format_get_blocksize(base->format);
r300_setup_flags(tex);
r300_setup_texture_state(rscreen, tex);
- pipe_buffer_reference(&tex->buffer, buffer);
+ /* one ref already taken */
+ tex->buffer = buffer;
return (struct pipe_texture*)tex;
}
+static boolean
+ r300_texture_get_handle(struct pipe_screen* screen,
+ struct pipe_texture *texture,
+ struct winsys_handle *whandle)
+{
+ struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
+ struct r300_texture* tex = (struct r300_texture*)texture;
+ unsigned stride;
+
+ if (!tex) {
+ return FALSE;
+ }
+
+ stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
+
+ winsys->buffer_get_handle(winsys, tex->buffer, stride, whandle);
+
+ return TRUE;
+}
+
static struct pipe_video_surface *
r300_video_surface_create(struct pipe_screen *screen,
enum pipe_video_chroma_format chroma_format,
@@ -390,7 +939,7 @@ r300_video_surface_create(struct pipe_screen *screen,
memset(&template, 0, sizeof(struct pipe_texture));
template.target = PIPE_TEXTURE_2D;
- template.format = PIPE_FORMAT_X8R8G8B8_UNORM;
+ template.format = PIPE_FORMAT_B8G8R8X8_UNORM;
template.last_level = 0;
template.width0 = util_next_power_of_two(width);
template.height0 = util_next_power_of_two(height);
@@ -418,30 +967,13 @@ static void r300_video_surface_destroy(struct pipe_video_surface *vsfc)
void r300_init_screen_texture_functions(struct pipe_screen* screen)
{
screen->texture_create = r300_texture_create;
+ screen->texture_from_handle = r300_texture_from_handle;
+ screen->texture_get_handle = r300_texture_get_handle;
screen->texture_destroy = r300_texture_destroy;
screen->get_tex_surface = r300_get_tex_surface;
screen->tex_surface_destroy = r300_tex_surface_destroy;
- screen->texture_blanket = r300_texture_blanket;
screen->video_surface_create = r300_video_surface_create;
screen->video_surface_destroy= r300_video_surface_destroy;
}
-boolean r300_get_texture_buffer(struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct pipe_buffer** buffer,
- unsigned* stride)
-{
- struct r300_texture* tex = (struct r300_texture*)texture;
- if (!tex) {
- return FALSE;
- }
-
- pipe_buffer_reference(buffer, tex->buffer);
-
- if (stride) {
- *stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
- }
-
- return TRUE;
-}
diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h
index 153f4eebdaf..138b62784e6 100644
--- a/src/gallium/drivers/r300/r300_texture.h
+++ b/src/gallium/drivers/r300/r300_texture.h
@@ -42,239 +42,11 @@ void r300_texture_reinterpret_format(struct pipe_screen *screen,
struct pipe_texture *tex,
enum pipe_format new_format);
-/* Translate a pipe_format into a useful texture format for sampling.
- *
- * R300_EASY_TX_FORMAT swizzles the texture.
- * Note the signature of R300_EASY_TX_FORMAT:
- * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT);
- *
- * The FORMAT specifies how the texture sampler will treat the texture, and
- * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */
-static INLINE uint32_t r300_translate_texformat(enum pipe_format format)
-{
- uint32_t result = 0;
- const struct util_format_description *desc;
- unsigned components = 0, i;
- boolean uniform = TRUE;
- const uint32_t swizzle_shift[4] = {
- R300_TX_FORMAT_R_SHIFT,
- R300_TX_FORMAT_G_SHIFT,
- R300_TX_FORMAT_B_SHIFT,
- R300_TX_FORMAT_A_SHIFT
- };
- const uint32_t sign_bit[4] = {
- R300_TX_FORMAT_SIGNED_X,
- R300_TX_FORMAT_SIGNED_Y,
- R300_TX_FORMAT_SIGNED_Z,
- R300_TX_FORMAT_SIGNED_W,
- };
-
- desc = util_format_description(format);
-
- /* Colorspace (return non-RGB formats directly). */
- switch (desc->colorspace) {
- /* Depth stencil formats. */
- case UTIL_FORMAT_COLORSPACE_ZS:
- switch (format) {
- case PIPE_FORMAT_Z16_UNORM:
- return R300_EASY_TX_FORMAT(X, X, X, X, X16);
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z24S8_UNORM:
- return R300_EASY_TX_FORMAT(X, X, X, X, W24_FP);
- default:
- return ~0; /* Unsupported. */
- }
-
- /* YUV formats. */
- case UTIL_FORMAT_COLORSPACE_YUV:
- result |= R300_TX_FORMAT_YUV_TO_RGB;
-
- switch (format) {
- case PIPE_FORMAT_YCBCR:
- return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | result;
- case PIPE_FORMAT_YCBCR_REV:
- return R300_EASY_TX_FORMAT(X, Y, Z, ONE, VYUY422) | result;
- default:
- return ~0; /* Unsupported/unknown. */
- }
-
- /* Add gamma correction. */
- case UTIL_FORMAT_COLORSPACE_SRGB:
- result |= R300_TX_FORMAT_GAMMA;
- break;
-
- default:;
- }
-
- /* Add swizzle. */
- for (i = 0; i < 4; i++) {
- switch (desc->swizzle[i]) {
- case UTIL_FORMAT_SWIZZLE_X:
- case UTIL_FORMAT_SWIZZLE_NONE:
- result |= R300_TX_FORMAT_X << swizzle_shift[i];
- break;
- case UTIL_FORMAT_SWIZZLE_Y:
- result |= R300_TX_FORMAT_Y << swizzle_shift[i];
- break;
- case UTIL_FORMAT_SWIZZLE_Z:
- result |= R300_TX_FORMAT_Z << swizzle_shift[i];
- break;
- case UTIL_FORMAT_SWIZZLE_W:
- result |= R300_TX_FORMAT_W << swizzle_shift[i];
- break;
- case UTIL_FORMAT_SWIZZLE_0:
- result |= R300_TX_FORMAT_ZERO << swizzle_shift[i];
- break;
- case UTIL_FORMAT_SWIZZLE_1:
- result |= R300_TX_FORMAT_ONE << swizzle_shift[i];
- break;
- default:
- return ~0; /* Unsupported. */
- }
- }
-
- /* Compressed formats. */
- if (desc->layout == UTIL_FORMAT_LAYOUT_DXT) {
- switch (format) {
- case PIPE_FORMAT_DXT1_RGB:
- case PIPE_FORMAT_DXT1_RGBA:
- case PIPE_FORMAT_DXT1_SRGB:
- case PIPE_FORMAT_DXT1_SRGBA:
- return R300_TX_FORMAT_DXT1 | result;
- case PIPE_FORMAT_DXT3_RGBA:
- case PIPE_FORMAT_DXT3_SRGBA:
- return R300_TX_FORMAT_DXT3 | result;
- case PIPE_FORMAT_DXT5_RGBA:
- case PIPE_FORMAT_DXT5_SRGBA:
- return R300_TX_FORMAT_DXT5 | result;
- default:
- return ~0; /* Unsupported/unknown. */
- }
- }
-
- /* Get the number of components. */
- for (i = 0; i < 4; i++) {
- if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
- ++components;
- }
- }
+boolean r300_is_colorbuffer_format_supported(enum pipe_format format);
- /* Add sign. */
- for (i = 0; i < components; i++) {
- if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) {
- result |= sign_bit[i];
- }
- }
+boolean r300_is_zs_format_supported(enum pipe_format format);
- /* See whether the components are of the same size. */
- for (i = 1; i < components; i++) {
- uniform = uniform && desc->channel[0].size == desc->channel[i].size;
- }
-
- /* Non-uniform formats. */
- if (!uniform) {
- switch (components) {
- case 3:
- if (desc->channel[0].size == 5 &&
- desc->channel[1].size == 6 &&
- desc->channel[2].size == 5) {
- return R300_TX_FORMAT_Z5Y6X5 | result;
- }
- if (desc->channel[0].size == 5 &&
- desc->channel[1].size == 5 &&
- desc->channel[2].size == 6) {
- return R300_TX_FORMAT_Z6Y5X5 | result;
- }
- return ~0; /* Unsupported/unknown. */
-
- case 4:
- if (desc->channel[0].size == 5 &&
- desc->channel[1].size == 5 &&
- desc->channel[2].size == 5 &&
- desc->channel[3].size == 1) {
- return R300_TX_FORMAT_W1Z5Y5X5 | result;
- }
- if (desc->channel[0].size == 10 &&
- desc->channel[1].size == 10 &&
- desc->channel[2].size == 10 &&
- desc->channel[3].size == 2) {
- return R300_TX_FORMAT_W2Z10Y10X10 | result;
- }
- }
- return ~0; /* Unsupported/unknown. */
- }
-
- /* And finally, uniform formats. */
- switch (desc->channel[0].type) {
- case UTIL_FORMAT_TYPE_UNSIGNED:
- case UTIL_FORMAT_TYPE_SIGNED:
- if (!desc->channel[0].normalized) {
- return ~0;
- }
-
- switch (desc->channel[0].size) {
- case 4:
- switch (components) {
- case 2:
- return R300_TX_FORMAT_Y4X4 | result;
- case 4:
- return R300_TX_FORMAT_W4Z4Y4X4 | result;
- }
- return ~0;
-
- case 8:
- switch (components) {
- case 1:
- return R300_TX_FORMAT_X8 | result;
- case 2:
- return R300_TX_FORMAT_Y8X8 | result;
- case 4:
- return R300_TX_FORMAT_W8Z8Y8X8 | result;
- }
- return ~0;
-
- case 16:
- switch (components) {
- case 1:
- return R300_TX_FORMAT_X16 | result;
- case 2:
- return R300_TX_FORMAT_Y16X16 | result;
- case 4:
- return R300_TX_FORMAT_W16Z16Y16X16 | result;
- }
- }
- return ~0;
-
-/* XXX Enable float textures here. */
-#if 0
- case UTIL_FORMAT_TYPE_FLOAT:
- switch (desc->channel[0].size) {
- case 16:
- switch (components) {
- case 1:
- return R300_TX_FORMAT_16F | result;
- case 2:
- return R300_TX_FORMAT_16F_16F | result;
- case 4:
- return R300_TX_FORMAT_16F_16F_16F_16F | result;
- }
- return ~0;
-
- case 32:
- switch (components) {
- case 1:
- return R300_TX_FORMAT_32F | result;
- case 2:
- return R300_TX_FORMAT_32F_32F | result;
- case 4:
- return R300_TX_FORMAT_32F_32F_32F_32F | result;
- }
- }
-#endif
- }
-
- return ~0; /* Unsupported/unknown. */
-}
+boolean r300_is_sampler_format_supported(enum pipe_format format);
struct r300_video_surface
{
@@ -288,13 +60,11 @@ r300_video_surface(struct pipe_video_surface *pvs)
return (struct r300_video_surface *)pvs;
}
-#ifndef R300_WINSYS_H
-
+/* Used internally for texture_is_referenced()
+ */
boolean r300_get_texture_buffer(struct pipe_screen* screen,
struct pipe_texture* texture,
struct pipe_buffer** buffer,
unsigned* stride);
-#endif /* R300_WINSYS_H */
-
#endif /* R300_TEXTURE_H */
diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c
new file mode 100644
index 00000000000..ec89681a3c0
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_transfer.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2008 Corbin Simpson <[email protected]>
+ * Copyright 2010 Marek Olšák <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#include "r300_context.h"
+#include "r300_transfer.h"
+#include "r300_texture.h"
+#include "r300_screen.h"
+
+#include "util/u_memory.h"
+#include "util/u_format.h"
+
+struct r300_transfer {
+ /* Parent class */
+ struct pipe_transfer transfer;
+
+ /* Pipe context. */
+ struct pipe_context *ctx;
+
+ /* Parameters of get_tex_transfer. */
+ unsigned x, y, level, zslice, face;
+
+ /* Offset from start of buffer. */
+ unsigned offset;
+
+ /* Detiled texture. */
+ struct r300_texture *detiled_texture;
+
+ /* Transfer and format flags. */
+ unsigned buffer_usage, render_target_usage;
+};
+
+/* Convenience cast wrapper. */
+static INLINE struct r300_transfer*
+r300_transfer(struct pipe_transfer* transfer)
+{
+ return (struct r300_transfer*)transfer;
+}
+
+/* Copy from a tiled texture to a detiled one. */
+static void r300_copy_from_tiled_texture(struct pipe_context *ctx,
+ struct r300_transfer *r300transfer)
+{
+ struct pipe_screen *screen = ctx->screen;
+ struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer;
+ struct pipe_texture *tex = transfer->texture;
+ struct pipe_surface *src, *dst;
+
+ src = screen->get_tex_surface(screen, tex, r300transfer->face,
+ r300transfer->level, r300transfer->zslice,
+ PIPE_BUFFER_USAGE_GPU_READ |
+ PIPE_BUFFER_USAGE_PIXEL);
+
+ dst = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex,
+ 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_WRITE |
+ PIPE_BUFFER_USAGE_PIXEL |
+ r300transfer->buffer_usage);
+
+ ctx->surface_copy(ctx, dst, 0, 0, src, r300transfer->x, r300transfer->y,
+ transfer->width, transfer->height);
+
+ pipe_surface_reference(&src, NULL);
+ pipe_surface_reference(&dst, NULL);
+}
+
+/* Copy a detiled texture to a tiled one. */
+static void r300_copy_into_tiled_texture(struct pipe_context *ctx,
+ struct r300_transfer *r300transfer)
+{
+ struct pipe_screen *screen = ctx->screen;
+ struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer;
+ struct pipe_texture *tex = transfer->texture;
+ struct pipe_surface *src, *dst;
+
+ src = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex,
+ 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_READ |
+ PIPE_BUFFER_USAGE_PIXEL);
+
+ dst = screen->get_tex_surface(screen, tex, r300transfer->face,
+ r300transfer->level, r300transfer->zslice,
+ PIPE_BUFFER_USAGE_GPU_WRITE |
+ PIPE_BUFFER_USAGE_PIXEL);
+
+ /* XXX this flush prevents the following DRM error from occuring:
+ * [drm:radeon_cs_ioctl] *ERROR* Failed to parse relocation !
+ * Reproducible with perf/copytex. */
+ ctx->flush(ctx, 0, NULL);
+
+ ctx->surface_copy(ctx, dst, r300transfer->x, r300transfer->y, src, 0, 0,
+ transfer->width, transfer->height);
+
+ /* XXX this flush fixes a few piglit tests (e.g. glean/pixelFormats). */
+ ctx->flush(ctx, 0, NULL);
+
+ pipe_surface_reference(&src, NULL);
+ pipe_surface_reference(&dst, NULL);
+}
+
+static struct pipe_transfer*
+r300_get_tex_transfer(struct pipe_screen *screen,
+ struct pipe_texture *texture,
+ unsigned face, unsigned level, unsigned zslice,
+ enum pipe_transfer_usage usage, unsigned x, unsigned y,
+ unsigned w, unsigned h)
+{
+ struct r300_texture *tex = (struct r300_texture *)texture;
+ struct r300_transfer *trans;
+ struct r300_screen *r300screen = r300_screen(screen);
+ struct pipe_texture template;
+
+ trans = CALLOC_STRUCT(r300_transfer);
+ if (trans) {
+ /* Initialize the transfer object. */
+ pipe_texture_reference(&trans->transfer.texture, texture);
+ trans->transfer.usage = usage;
+ trans->transfer.width = w;
+ trans->transfer.height = h;
+ trans->ctx = r300screen->ctx;
+ trans->x = x;
+ trans->y = y;
+ trans->level = level;
+ trans->zslice = zslice;
+ trans->face = face;
+
+ /* If the texture is tiled, we must create a temporary detiled texture
+ * for this transfer. */
+ if (tex->microtile || tex->macrotile) {
+ trans->buffer_usage = pipe_transfer_buffer_flags(&trans->transfer);
+ trans->render_target_usage =
+ util_format_is_depth_or_stencil(texture->format) ?
+ PIPE_TEXTURE_USAGE_DEPTH_STENCIL :
+ PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+ template.target = PIPE_TEXTURE_2D;
+ template.format = texture->format;
+ template.width0 = w;
+ template.height0 = h;
+ template.depth0 = 0;
+ template.last_level = 0;
+ template.nr_samples = 0;
+ template.tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC |
+ R300_TEXTURE_USAGE_TRANSFER;
+
+ /* For texture reading, the temporary (detiled) texture is used as
+ * a render target when blitting from a tiled texture. */
+ if (usage & PIPE_TRANSFER_READ) {
+ template.tex_usage |= trans->render_target_usage;
+ }
+ /* For texture writing, the temporary texture is used as a sampler
+ * when blitting into a tiled texture. */
+ if (usage & PIPE_TRANSFER_WRITE) {
+ template.tex_usage |= PIPE_TEXTURE_USAGE_SAMPLER;
+ }
+
+ /* Create the temporary texture. */
+ trans->detiled_texture =
+ (struct r300_texture*)screen->texture_create(screen, &template);
+ assert(!trans->detiled_texture->microtile &&
+ !trans->detiled_texture->macrotile);
+
+ /* Set the stride.
+ * Parameters x, y, level, zslice, and face remain zero. */
+ trans->transfer.stride =
+ r300_texture_get_stride(r300screen, trans->detiled_texture, 0);
+
+ if (usage & PIPE_TRANSFER_READ) {
+ /* We cannot map a tiled texture directly because the data is
+ * in a different order, therefore we do detiling using a blit. */
+ r300_copy_from_tiled_texture(r300screen->ctx, trans);
+ }
+ } else {
+ trans->transfer.x = x;
+ trans->transfer.y = y;
+ trans->transfer.stride =
+ r300_texture_get_stride(r300screen, tex, level);
+ trans->transfer.level = level;
+ trans->transfer.zslice = zslice;
+ trans->transfer.face = face;
+ trans->offset = r300_texture_get_offset(tex, level, zslice, face);
+ }
+ }
+ return &trans->transfer;
+}
+
+static void r300_tex_transfer_destroy(struct pipe_transfer *trans)
+{
+ struct r300_transfer *r300transfer = r300_transfer(trans);
+
+ if (r300transfer->detiled_texture) {
+ if (trans->usage & PIPE_TRANSFER_WRITE) {
+ r300_copy_into_tiled_texture(r300transfer->ctx, r300transfer);
+ }
+
+ pipe_texture_reference(
+ (struct pipe_texture**)&r300transfer->detiled_texture, NULL);
+ }
+ pipe_texture_reference(&trans->texture, NULL);
+ FREE(trans);
+}
+
+static void* r300_transfer_map(struct pipe_screen *screen,
+ struct pipe_transfer *transfer)
+{
+ struct r300_transfer *r300transfer = r300_transfer(transfer);
+ struct r300_texture *tex = (struct r300_texture*)transfer->texture;
+ char *map;
+ enum pipe_format format = tex->tex.format;
+
+ if (r300transfer->detiled_texture) {
+ /* The detiled texture is of the same size as the region being mapped
+ * (no offset needed). */
+ return pipe_buffer_map(screen,
+ r300transfer->detiled_texture->buffer,
+ pipe_transfer_buffer_flags(transfer));
+ } else {
+ /* Tiling is disabled. */
+ map = pipe_buffer_map(screen, tex->buffer,
+ pipe_transfer_buffer_flags(transfer));
+
+ if (!map) {
+ return NULL;
+ }
+
+ return map + r300_transfer(transfer)->offset +
+ transfer->y / util_format_get_blockheight(format) * transfer->stride +
+ transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+ }
+}
+
+static void r300_transfer_unmap(struct pipe_screen *screen,
+ struct pipe_transfer *transfer)
+{
+ struct r300_transfer *r300transfer = r300_transfer(transfer);
+ struct r300_texture *tex = (struct r300_texture*)transfer->texture;
+
+ if (r300transfer->detiled_texture) {
+ pipe_buffer_unmap(screen, r300transfer->detiled_texture->buffer);
+ } else {
+ pipe_buffer_unmap(screen, tex->buffer);
+ }
+}
+
+void r300_init_screen_transfer_functions(struct pipe_screen *screen)
+{
+ screen->get_tex_transfer = r300_get_tex_transfer;
+ screen->tex_transfer_destroy = r300_tex_transfer_destroy;
+ screen->transfer_map = r300_transfer_map;
+ screen->transfer_unmap = r300_transfer_unmap;
+}
diff --git a/src/gallium/drivers/r300/r300_transfer.h b/src/gallium/drivers/r300/r300_transfer.h
new file mode 100644
index 00000000000..60d1d3dc85c
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_transfer.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2008 Corbin Simpson <[email protected]>
+ * Copyright 2010 Marek Olšák <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#ifndef R300_TRANSFER
+#define R300_TRANSFER
+
+#include "pipe/p_screen.h"
+
+void r300_init_screen_transfer_functions(struct pipe_screen *screen);
+
+#endif
diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c
index a6786c321c6..379939ac750 100644
--- a/src/gallium/drivers/r300/r300_vs.c
+++ b/src/gallium/drivers/r300/r300_vs.c
@@ -89,95 +89,41 @@ static void r300_shader_read_vs_outputs(
assert(0);
}
}
+
+ /* WPOS is a straight copy of POSITION and it's always emitted. */
+ vs_outputs->wpos = i;
}
-static void r300_shader_vap_output_fmt(struct r300_vertex_shader* vs)
+/* This function sets up:
+ * - VAP mapping, which maps VS registers to output semantics and
+ * at the same time it indicates which attributes are enabled and should
+ * be rasterized.
+ * - Stream mapping to VS outputs if TCL is not present. */
+static void r300_init_vs_output_mapping(struct r300_vertex_shader* vs)
{
struct r300_shader_semantics* vs_outputs = &vs->outputs;
- uint32_t* hwfmt = vs->hwfmt;
- int i, gen_count;
+ struct r300_vap_output_state *vap_out = &vs->vap_out;
+ int *stream_loc = vs->stream_loc_notcl;
+ int i, gen_count, tabi = 0;
boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED ||
vs_outputs->bcolor[1] != ATTR_UNUSED;
- /* Do the actual vertex_info setup.
- *
- * vertex_info has four uints of hardware-specific data in it.
- * vinfo.hwfmt[0] is R300_VAP_VTX_STATE_CNTL
- * vinfo.hwfmt[1] is R300_VAP_VSM_VTX_ASSM
- * vinfo.hwfmt[2] is R300_VAP_OUTPUT_VTX_FMT_0
- * vinfo.hwfmt[3] is R300_VAP_OUTPUT_VTX_FMT_1 */
-
- hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */
+ vap_out->vap_vtx_state_cntl = 0x5555; /* XXX this is classic Mesa bonghits */
/* Position. */
if (vs_outputs->pos != ATTR_UNUSED) {
- hwfmt[1] |= R300_INPUT_CNTL_POS;
- hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT;
+ vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_POS;
+ vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT;
+
+ stream_loc[tabi++] = 0;
} else {
assert(0);
}
/* Point size. */
if (vs_outputs->psize != ATTR_UNUSED) {
- hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
- }
-
- /* Colors. */
- for (i = 0; i < ATTR_COLOR_COUNT; i++) {
- if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used ||
- vs_outputs->color[1] != ATTR_UNUSED) {
- hwfmt[1] |= R300_INPUT_CNTL_COLOR;
- hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i;
- }
- }
-
- /* Back-face colors. */
- if (any_bcolor_used) {
- for (i = 0; i < ATTR_COLOR_COUNT; i++) {
- hwfmt[1] |= R300_INPUT_CNTL_COLOR;
- hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << (2+i);
- }
- }
+ vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
- /* Texture coordinates. */
- gen_count = 0;
- for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
- if (vs_outputs->generic[i] != ATTR_UNUSED) {
- hwfmt[1] |= (R300_INPUT_CNTL_TC0 << gen_count);
- hwfmt[3] |= (4 << (3 * gen_count));
- gen_count++;
- }
- }
-
- /* Fog coordinates. */
- if (vs_outputs->fog != ATTR_UNUSED) {
- hwfmt[1] |= (R300_INPUT_CNTL_TC0 << gen_count);
- hwfmt[3] |= (4 << (3 * gen_count));
- gen_count++;
- }
-
- /* XXX magic */
- assert(gen_count <= 8);
-
- /* WPOS. */
- vs->wpos_tex_output = gen_count;
-}
-
-/* Sets up stream mapping to equivalent VS outputs if TCL is bypassed
- * or isn't present. */
-static void r300_stream_locations_notcl(
- struct r300_shader_semantics* vs_outputs,
- int* stream_loc)
-{
- int i, tabi = 0, gen_count;
- boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED ||
- vs_outputs->bcolor[1] != ATTR_UNUSED;
-
- /* Position. */
- stream_loc[tabi++] = 0;
-
- /* Point size. */
- if (vs_outputs->psize != ATTR_UNUSED) {
stream_loc[tabi++] = 1;
}
@@ -185,6 +131,9 @@ static void r300_stream_locations_notcl(
for (i = 0; i < ATTR_COLOR_COUNT; i++) {
if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used ||
vs_outputs->color[1] != ATTR_UNUSED) {
+ vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR;
+ vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i;
+
stream_loc[tabi++] = 2 + i;
}
}
@@ -192,6 +141,9 @@ static void r300_stream_locations_notcl(
/* Back-face colors. */
if (any_bcolor_used) {
for (i = 0; i < ATTR_COLOR_COUNT; i++) {
+ vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR;
+ vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << (2+i);
+
stream_loc[tabi++] = 4 + i;
}
}
@@ -200,6 +152,9 @@ static void r300_stream_locations_notcl(
gen_count = 0;
for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
if (vs_outputs->generic[i] != ATTR_UNUSED) {
+ vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count);
+ vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count));
+
assert(tabi < 16);
stream_loc[tabi++] = 6 + gen_count;
gen_count++;
@@ -208,17 +163,22 @@ static void r300_stream_locations_notcl(
/* Fog coordinates. */
if (vs_outputs->fog != ATTR_UNUSED) {
+ vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count);
+ vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count));
+
assert(tabi < 16);
stream_loc[tabi++] = 6 + gen_count;
gen_count++;
}
+ /* XXX magic */
+ assert(gen_count <= 8);
+
/* WPOS. */
- if (vs_outputs->wpos != ATTR_UNUSED) {
- assert(tabi < 16);
- stream_loc[tabi++] = 6 + gen_count;
- gen_count++;
- }
+ vs->wpos_tex_output = gen_count;
+
+ assert(tabi < 16);
+ stream_loc[tabi++] = 6 + gen_count;
for (; tabi < 16;) {
stream_loc[tabi++] = -1;
@@ -294,26 +254,16 @@ static void set_vertex_inputs_outputs(struct r300_vertex_program_compiler * c)
}
}
-static void r300_insert_wpos(struct r300_vertex_program_compiler* c,
- struct r300_shader_semantics* outputs)
+void r300_vertex_shader_common_init(struct r300_vertex_shader *vs,
+ const struct pipe_shader_state *shader)
{
- int i, lastOutput = 0;
-
- /* Find the max output index. */
- lastOutput = MAX2(lastOutput, outputs->psize);
- for (i = 0; i < ATTR_COLOR_COUNT; i++) {
- lastOutput = MAX2(lastOutput, outputs->color[i]);
- lastOutput = MAX2(lastOutput, outputs->bcolor[i]);
- }
- for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
- lastOutput = MAX2(lastOutput, outputs->generic[i]);
- }
- lastOutput = MAX2(lastOutput, outputs->fog);
+ /* Copy state directly into shader. */
+ vs->state = *shader;
+ vs->state.tokens = tgsi_dup_tokens(shader->tokens);
+ tgsi_scan_shader(shader->tokens, &vs->info);
- /* Set WPOS after the last output. */
- lastOutput++;
- rc_copy_output(&c->Base, 0, lastOutput); /* out[lastOutput] = out[0]; */
- outputs->wpos = lastOutput;
+ r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
+ r300_init_vs_output_mapping(vs);
}
void r300_translate_vertex_shader(struct r300_context* r300,
@@ -322,9 +272,6 @@ void r300_translate_vertex_shader(struct r300_context* r300,
struct r300_vertex_program_compiler compiler;
struct tgsi_to_rc ttr;
- /* Initialize. */
- r300_shader_read_vs_outputs(&vs->info, &vs->outputs);
-
/* Setup the compiler */
rc_init(&compiler.Base);
@@ -348,10 +295,7 @@ void r300_translate_vertex_shader(struct r300_context* r300,
compiler.SetHwInputOutput = &set_vertex_inputs_outputs;
/* Insert the WPOS output. */
- r300_insert_wpos(&compiler, &vs->outputs);
-
- r300_shader_vap_output_fmt(vs);
- r300_stream_locations_notcl(&vs->outputs, vs->stream_loc_notcl);
+ rc_copy_output(&compiler.Base, 0, vs->outputs.wpos);
/* Invoke the compiler */
r3xx_compile_vertex_program(&compiler);
@@ -363,30 +307,29 @@ void r300_translate_vertex_shader(struct r300_context* r300,
/* And, finally... */
rc_destroy(&compiler.Base);
- vs->translated = TRUE;
}
boolean r300_vertex_shader_setup_wpos(struct r300_context* r300)
{
- struct r300_vertex_shader* vs = r300->vs;
- int tex_output = r300->vs->wpos_tex_output;
+ struct r300_vertex_shader* vs = r300->vs_state.state;
+ struct r300_vap_output_state *vap_out = &vs->vap_out;
+ int tex_output = vs->wpos_tex_output;
uint32_t tex_fmt = R300_INPUT_CNTL_TC0 << tex_output;
- uint32_t* hwfmt = vs->hwfmt;
if (r300->fs->inputs.wpos != ATTR_UNUSED) {
/* Enable WPOS in VAP. */
- if (!(hwfmt[1] & tex_fmt)) {
- hwfmt[1] |= tex_fmt;
- hwfmt[3] |= (4 << (3 * tex_output));
+ if (!(vap_out->vap_vsm_vtx_assm & tex_fmt)) {
+ vap_out->vap_vsm_vtx_assm |= tex_fmt;
+ vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * tex_output));
assert(tex_output < 8);
return TRUE;
}
} else {
/* Disable WPOS in VAP. */
- if (hwfmt[1] & tex_fmt) {
- hwfmt[1] &= ~tex_fmt;
- hwfmt[3] &= ~(4 << (3 * tex_output));
+ if (vap_out->vap_vsm_vtx_assm & tex_fmt) {
+ vap_out->vap_vsm_vtx_assm &= ~tex_fmt;
+ vap_out->vap_out_vtx_fmt[1] &= ~(4 << (3 * tex_output));
return TRUE;
}
}
diff --git a/src/gallium/drivers/r300/r300_vs.h b/src/gallium/drivers/r300/r300_vs.h
index 18cfeee3cd4..f6f0b86b683 100644
--- a/src/gallium/drivers/r300/r300_vs.h
+++ b/src/gallium/drivers/r300/r300_vs.h
@@ -28,6 +28,7 @@
#include "tgsi/tgsi_scan.h"
#include "radeon_code.h"
+#include "r300_context.h"
#include "r300_shader_semantics.h"
struct r300_context;
@@ -38,7 +39,7 @@ struct r300_vertex_shader {
struct tgsi_shader_info info;
struct r300_shader_semantics outputs;
- uint hwfmt[4];
+ struct r300_vap_output_state vap_out;
/* Stream locations for SWTCL or if TCL is bypassed. */
int stream_loc_notcl[16];
@@ -46,13 +47,17 @@ struct r300_vertex_shader {
/* Output stream location for WPOS. */
int wpos_tex_output;
- /* Has this shader been translated yet? */
- boolean translated;
-
+ /* HWTCL-specific. */
/* Machine code (if translated) */
struct r300_vertex_program_code code;
+
+ /* SWTCL-specific. */
+ void *draw_vs;
};
+void r300_vertex_shader_common_init(struct r300_vertex_shader *vs,
+ const struct pipe_shader_state *shader);
+
void r300_translate_vertex_shader(struct r300_context* r300,
struct r300_vertex_shader* vs);
diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h
index 40fb8a95ca5..ddf2b790039 100644
--- a/src/gallium/drivers/r300/r300_winsys.h
+++ b/src/gallium/drivers/r300/r300_winsys.h
@@ -40,11 +40,6 @@ struct radeon_winsys;
struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys);
-boolean r300_get_texture_buffer(struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct pipe_buffer** buffer,
- unsigned* stride);
-
#ifdef __cplusplus
}
#endif