r300_emit.h cleanup.

Remove unused macro
Replace LOCAL_VAR, PREFIX*
Indent code
Remove radeon redundant CP type 3 packet
This commit is contained in:
Jerome Glisse 2006-07-27 22:51:14 +00:00
parent a7722cb794
commit 32d61d0616
5 changed files with 234 additions and 211 deletions

View file

@ -635,30 +635,35 @@ void r300EmitWait(r300ContextPtr rmesa, GLuint flags)
void r300EmitAOS(r300ContextPtr rmesa, GLuint nr, GLuint offset)
{
int sz = 1 + (nr >> 1) * 3 + (nr & 1) * 2;
int i;
LOCAL_VARS
int sz = 1 + (nr >> 1) * 3 + (nr & 1) * 2;
int i;
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
if (RADEON_DEBUG & DEBUG_VERTS)
fprintf(stderr, "%s: nr=%d, ofs=0x%08x\n", __func__, nr, offset);
if (RADEON_DEBUG & DEBUG_VERTS)
fprintf(stderr, "%s: nr=%d, ofs=0x%08x\n", __func__, nr, offset);
start_packet3(RADEON_CP_PACKET3_3D_LOAD_VBPNTR, sz-1);
e32(nr);
for(i=0;i+1<nr;i+=2){
e32( (rmesa->state.aos[i].aos_size << 0)
|(rmesa->state.aos[i].aos_stride << 8)
|(rmesa->state.aos[i+1].aos_size << 16)
|(rmesa->state.aos[i+1].aos_stride << 24)
);
e32(rmesa->state.aos[i].aos_offset+offset*4*rmesa->state.aos[i].aos_stride);
e32(rmesa->state.aos[i+1].aos_offset+offset*4*rmesa->state.aos[i+1].aos_stride);
}
if(nr & 1){
e32( (rmesa->state.aos[nr-1].aos_size << 0)
|(rmesa->state.aos[nr-1].aos_stride << 8)
);
e32(rmesa->state.aos[nr-1].aos_offset+offset*4*rmesa->state.aos[nr-1].aos_stride);
}
start_packet3(RADEON_CP_PACKET3_3D_LOAD_VBPNTR, sz-1);
e32(nr);
for(i=0;i+1<nr;i+=2){
e32( (rmesa->state.aos[i].aos_size << 0)
|(rmesa->state.aos[i].aos_stride << 8)
|(rmesa->state.aos[i+1].aos_size << 16)
|(rmesa->state.aos[i+1].aos_stride << 24)
);
e32(rmesa->state.aos[i].aos_offset +
offset*4*rmesa->state.aos[i].aos_stride);
e32(rmesa->state.aos[i+1].aos_offset +
offset*4*rmesa->state.aos[i+1].aos_stride);
}
if(nr & 1){
e32( (rmesa->state.aos[nr-1].aos_size << 0)
|(rmesa->state.aos[nr-1].aos_stride << 8)
);
e32(rmesa->state.aos[nr-1].aos_offset +
offset*4*rmesa->state.aos[nr-1].aos_stride);
}
}

View file

@ -1,65 +1,64 @@
#ifndef __EMIT_H__
#define __EMIT_H__
/*
* Copyright (C) 2005 Vladimir Dergachev.
*
* All Rights Reserved.
*
* 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 the rights to use, copy, modify, merge, publish,
* distribute, sublicense, 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS 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.
*
*/
/*
* Authors:
* Vladimir Dergachev <volodya@mindspring.com>
* Nicolai Haehnle <prefect_@gmx.net>
* Aapo Tahkola <aet@rasterburn.org>
* Ben Skeggs <darktama@iinet.net.au>
* Jerome Glisse <j.glisse@gmail.com>
*/
/* This files defines functions for accessing R300 hardware.
*/
#ifndef __R300_EMIT_H__
#define __R300_EMIT_H__
#include "glheader.h"
#include "r300_context.h"
#include "r300_cmdbuf.h"
#include "radeon_reg.h"
/* convenience macros */
#define RADEON_CP_PACKET0 0x00000000
#define RADEON_CP_PACKET1 0x40000000
#define RADEON_CP_PACKET2 0x80000000
#define RADEON_CP_PACKET3 0xC0000000
#define RADEON_CP_PACKET3_NOP 0xC0001000
#define RADEON_CP_PACKET3_NEXT_CHAR 0xC0001900
/*
* CP type-3 packets
*/
#define RADEON_CP_PACKET3_UNK1B 0xC0001B00
#define RADEON_CP_PACKET3_PLY_NEXTSCAN 0xC0001D00
#define RADEON_CP_PACKET3_SET_SCISSORS 0xC0001E00
#define RADEON_CP_PACKET3_3D_RNDR_GEN_INDX_PRIM 0xC0002300
#define RADEON_CP_PACKET3_LOAD_MICROCODE 0xC0002400
#define RADEON_CP_PACKET3_WAIT_FOR_IDLE 0xC0002600
#define RADEON_CP_PACKET3_3D_DRAW_VBUF 0xC0002800
#define RADEON_CP_PACKET3_3D_DRAW_IMMD 0xC0002900
#define RADEON_CP_PACKET3_3D_DRAW_INDX 0xC0002A00
#define RADEON_CP_PACKET3_LOAD_PALETTE 0xC0002C00
#define RADEON_CP_PACKET3_INDX_BUFFER 0xC0003300
#define RADEON_CP_PACKET3_3D_DRAW_VBUF_2 0xC0003400
#define RADEON_CP_PACKET3_3D_DRAW_IMMD_2 0xC0003500
#define RADEON_CP_PACKET3_3D_DRAW_INDX_2 0xC0003600
#define RADEON_CP_PACKET3_3D_LOAD_VBPNTR 0xC0002F00
#define RADEON_CP_PACKET3_CNTL_PAINT 0xC0009100
#define RADEON_CP_PACKET3_CNTL_BITBLT 0xC0009200
#define RADEON_CP_PACKET3_CNTL_SMALLTEXT 0xC0009300
#define RADEON_CP_PACKET3_CNTL_HOSTDATA_BLT 0xC0009400
#define RADEON_CP_PACKET3_CNTL_POLYLINE 0xC0009500
#define RADEON_CP_PACKET3_CNTL_POLYSCANLINES 0xC0009800
#define RADEON_CP_PACKET3_CNTL_PAINT_MULTI 0xC0009A00
#define RADEON_CP_PACKET3_CNTL_BITBLT_MULTI 0xC0009B00
#define RADEON_CP_PACKET3_CNTL_TRANS_BITBLT 0xC0009C00
#define RADEON_CP_PACKET3_3D_CLEAR_ZMASK 0xC0003202
#define RADEON_CP_PACKET3_3D_CLEAR_CMASK 0xC0003802
#define RADEON_CP_PACKET3_3D_CLEAR_HIZ 0xC0003702
#define CP_PACKET0(reg, n) (RADEON_CP_PACKET0 | ((n)<<16) | ((reg)>>2))
/* Glue to R300 Mesa driver */
#define LOCAL_VARS int cmd_reserved=0;\
int cmd_written=0; \
drm_radeon_cmd_header_t *cmd=NULL;
#define PREFIX_VOID r300ContextPtr rmesa
#define PREFIX PREFIX_VOID ,
#define PASS_PREFIX_VOID rmesa
#define PASS_PREFIX rmesa ,
typedef GLuint CARD32;
/* This files defines functions for accessing R300 hardware.
It needs to be customized to whatever code r300_lib.c is used
in */
void static inline check_space(int dwords)
{
}
@ -127,156 +126,164 @@ static __inline__ uint32_t cmdpacify(void)
return cmd.u;
}
/* Prepare to write a register value to register at address reg.
If num_extra > 0 then the following extra values are written
to registers with address +4, +8 and so on.. */
#define reg_start(reg, num_extra) \
{ \
int _n; \
_n=(num_extra); \
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
(_n+2), \
__FUNCTION__); \
cmd_reserved=_n+2; \
cmd_written=1; \
cmd[0].i=cmdpacket0((reg), _n+1); \
}
/**
* Prepare to write a register value to register at address reg.
* If num_extra > 0 then the following extra values are written
* to registers with address +4, +8 and so on..
*/
#define reg_start(reg, num_extra) \
do { \
int _n; \
_n=(num_extra); \
cmd = r300AllocCmdBuf(rmesa, \
(_n+2), \
__FUNCTION__); \
cmd_reserved=_n+2; \
cmd_written=1; \
cmd[0].i=cmdpacket0((reg), _n+1); \
} while (0);
/* Prepare to write a register value to register at address reg.
If num_extra > 0 then the following extra values are written
into the same register. */
/* It is here to permit r300_lib to compile and link anyway, but
complain if actually called */
#define reg_start_pump(reg, num_extra) \
{ \
fprintf(stderr, "I am not defined.. Error ! in %s::%s at line %d\n", \
__FILE__, __FUNCTION__, __LINE__); \
exit(-1); \
}
/* Emit CARD32 freestyle*/
#define e32(dword) { \
if(cmd_written<cmd_reserved){\
cmd[cmd_written].i=(dword); \
cmd_written++; \
} else { \
fprintf(stderr, "e32 but no previous packet declaration.. Aborting! in %s::%s at line %d, cmd_written=%d cmd_reserved=%d\n", \
__FILE__, __FUNCTION__, __LINE__, cmd_written, cmd_reserved); \
exit(-1); \
} \
}
/**
* Emit GLuint freestyle
*/
#define e32(dword) \
do { \
if(cmd_written<cmd_reserved) { \
cmd[cmd_written].i=(dword); \
cmd_written++; \
} else { \
fprintf(stderr, \
"e32 but no previous packet " \
"declaration.\n" \
"Aborting! in %s::%s at line %d, " \
"cmd_written=%d cmd_reserved=%d\n", \
__FILE__, __FUNCTION__, __LINE__, \
cmd_written, cmd_reserved); \
exit(-1); \
} \
} while(0);
#define efloat(f) e32(r300PackFloat32(f))
#define vsf_start_fragment(dest, length) \
{ \
int _n; \
_n=(length); \
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
(_n+1), \
__FUNCTION__); \
cmd_reserved=_n+2; \
cmd_written=1; \
cmd[0].i=cmdvpu((dest), _n/4); \
#define vsf_start_fragment(dest, length) \
do { \
int _n; \
_n = (length); \
cmd = r300AllocCmdBuf(rmesa, \
(_n+1), \
__FUNCTION__); \
cmd_reserved = _n+2; \
cmd_written =1; \
cmd[0].i = cmdvpu((dest), _n/4); \
} while (0);
#define start_packet3(packet, count) \
{ \
int _n; \
GLuint _p; \
_n = (count); \
_p = (packet); \
cmd = r300AllocCmdBuf(rmesa, \
(_n+3), \
__FUNCTION__); \
cmd_reserved = _n+3; \
cmd_written = 2; \
if(_n > 0x3fff) { \
fprintf(stderr,"Too big packet3 %08x: cannot " \
"store %d dwords\n", \
_p, _n); \
exit(-1); \
} \
cmd[0].i = cmdpacket3(R300_CMD_PACKET3_RAW); \
cmd[1].i = _p | ((_n & 0x3fff)<<16); \
}
#define start_packet3(packet, count) \
{ \
int _n; \
CARD32 _p; \
_n=(count); \
_p=(packet); \
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
(_n+3), \
__FUNCTION__); \
cmd_reserved=_n+3; \
cmd_written=2; \
if(_n>0x3fff) {\
fprintf(stderr,"Too big packet3 %08x: cannot store %d dwords\n", \
_p, _n); \
exit(-1); \
} \
cmd[0].i=cmdpacket3(R300_CMD_PACKET3_RAW); \
cmd[1].i=_p | ((_n & 0x3fff)<<16); \
}
/* must be sent to switch to 2d commands */
void static inline end_3d(PREFIX_VOID)
/**
* Must be sent to switch to 2d commands
*/
void static inline end_3d(r300ContextPtr rmesa)
{
LOCAL_VARS
(void)cmd_reserved; (void)cmd_written;
drm_radeon_cmd_header_t *cmd = NULL;
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
1, \
__FUNCTION__); \
cmd[0].header.cmd_type=R300_CMD_END3D;
cmd = (drm_radeon_cmd_header_t*)r300AllocCmdBuf(rmesa,
1,
__FUNCTION__);
cmd[0].header.cmd_type=R300_CMD_END3D;
}
void static inline cp_delay(PREFIX unsigned short count)
void static inline cp_delay(r300ContextPtr rmesa, unsigned short count)
{
LOCAL_VARS
(void)cmd_reserved; (void)cmd_written;
drm_radeon_cmd_header_t *cmd = NULL;
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
1, \
__FUNCTION__); \
cmd[0].i=cmdcpdelay(count);
cmd = (drm_radeon_cmd_header_t*)r300AllocCmdBuf(rmesa,
1,
__FUNCTION__);
cmd[0].i=cmdcpdelay(count);
}
void static inline cp_wait(PREFIX unsigned char flags)
void static inline cp_wait(r300ContextPtr rmesa, unsigned char flags)
{
LOCAL_VARS
(void)cmd_reserved; (void)cmd_written;
drm_radeon_cmd_header_t *cmd = NULL;
cmd=(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa, \
1, \
__FUNCTION__); \
cmd[0].i=cmdwait(flags);
cmd = (drm_radeon_cmd_header_t*)r300AllocCmdBuf(rmesa,
1,
__FUNCTION__);
cmd[0].i = cmdwait(flags);
}
/* fire vertex buffer */
static void inline fire_AOS(PREFIX int vertex_count, int type)
/**
* fire vertex buffer
*/
static void inline fire_AOS(r300ContextPtr rmesa, int vertex_count, int type)
{
LOCAL_VARS
check_space(9);
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
check_space(9);
start_packet3(RADEON_CP_PACKET3_3D_DRAW_VBUF_2, 0);
/* e32(0x840c0024); */
e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (vertex_count<<16) | type);
start_packet3(RADEON_CP_PACKET3_3D_DRAW_VBUF_2, 0);
#ifdef NOTNEEDED_ANYMORE
e32(0x840c0024);
#endif
e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST |
(vertex_count<<16) | type);
}
/* these are followed by the corresponding data */
#define start_index32_packet(vertex_count, type) \
{\
int _vc;\
_vc=(vertex_count); \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, _vc); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (_vc<<16) | type \
| R300_VAP_VF_CNTL__INDEX_SIZE_32bit); \
}
/**
* These are followed by the corresponding data
*/
#define start_index32_packet(vertex_count, type) \
do { \
int _vc; \
_vc = (vertex_count); \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, _vc); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (_vc<<16) | \
type | R300_VAP_VF_CNTL__INDEX_SIZE_32bit); \
} while (0);
#define start_index16_packet(vertex_count, type) \
{\
int _vc, _n;\
_vc=(vertex_count); \
_n=(vertex_count+1)>>1; \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, _n); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (_vc<<16) | type); \
}
#define start_index16_packet(vertex_count, type) \
do { \
int _vc, _n; \
_vc = (vertex_count); \
_n = (vertex_count+1)>>1; \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_INDX_2, _n); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (_vc<<16) | \
type); \
} while (0);
/* Interestingly enough this ones needs the call to setup_AOS, even thought
some of the data so setup is not needed and some is not as arbitrary
as when used by DRAW_VBUF_2 or DRAW_INDX_2 */
#define start_immediate_packet(vertex_count, type, vertex_size) \
{\
int _vc; \
_vc=(vertex_count); \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_IMMD_2, _vc*(vertex_size)); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (_vc<<16) | type); \
}
/**
* Interestingly enough this ones needs the call to setup_AOS, even thought
* some of the data so setup is not needed and some is not as arbitrary
* as when used by DRAW_VBUF_2 or DRAW_INDX_2
*/
#define start_immediate_packet(vertex_count, type, vertex_size) \
do { \
int _vc; \
_vc = (vertex_count); \
start_packet3(RADEON_CP_PACKET3_3D_DRAW_IMMD_2, \
_vc*(vertex_size)); \
e32(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | \
(_vc<<16) | type); \
} while (0);
#endif

View file

@ -65,12 +65,12 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
__DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable;
GLuint cboffset, cbpitch;
drm_r300_cmd_header_t* cmd2;
#ifdef CB_DPATH
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
r300ContextPtr rmesa=r300;
LOCAL_VARS;
#else
r300ContextPtr rmesa=r300;
LOCAL_VARS;
#ifndef CB_DPATH
int i;
#endif
@ -249,7 +249,7 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
#else
#if 1
cp_wait(r300, R300_WAIT_3D | R300_WAIT_3D_CLEAN);
end_3d(PASS_PREFIX_VOID);
end_3d(rmesa);
#endif
R300_STATECHANGE(r300, cb);
@ -345,7 +345,9 @@ static void r300EmitClearState(GLcontext * ctx)
r300ContextPtr rmesa=r300;
__DRIdrawablePrivate *dPriv = r300->radeon.dri.drawable;
int i;
LOCAL_VARS;
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
R300_STATECHANGE(r300, vir[0]);

View file

@ -196,9 +196,11 @@ static int r300_get_num_verts(r300ContextPtr rmesa,
/* vertex buffer implementation */
static void inline fire_EB(PREFIX unsigned long addr, int vertex_count, int type, int elt_size)
static void inline fire_EB(r300ContextPtr rmesa, unsigned long addr, int vertex_count, int type, int elt_size)
{
LOCAL_VARS
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
unsigned long addr_a;
unsigned long t_addr;
unsigned long magic_1, magic_2;
@ -241,7 +243,7 @@ static void inline fire_EB(PREFIX unsigned long addr, int vertex_count, int type
} else {
e32(magic_2); /* Total number of dwords needed? */
}
//cp_delay(PASS_PREFIX 1);
//cp_delay(rmesa, 1);
#if 0
fprintf(stderr, "magic_1 %d\n", magic_1);
fprintf(stderr, "t_addr %x\n", t_addr);
@ -271,7 +273,7 @@ static void inline fire_EB(PREFIX unsigned long addr, int vertex_count, int type
} else {
e32((vertex_count+1)/2 /*+ addr_a/4*/); /* Total number of dwords needed? */
}
//cp_delay(PASS_PREFIX 1);
//cp_delay(rmesa, 1);
#endif
}
@ -291,7 +293,9 @@ static void r300_render_vb_primitive(r300ContextPtr rmesa,
if(rmesa->state.VB.Elts){
r300EmitAOS(rmesa, rmesa->state.aos_count, /*0*/start);
#if 0
LOCAL_VARS
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
int i;
start_index32_packet(num_verts, type);
for(i=0; i < num_verts; i++)
@ -309,11 +313,11 @@ static void r300_render_vb_primitive(r300ContextPtr rmesa,
}
r300EmitElts(ctx, rmesa->state.VB.Elts, num_verts, rmesa->state.VB.elt_size);
fire_EB(PASS_PREFIX rmesa->state.elt_dma.aos_offset, num_verts, type, rmesa->state.VB.elt_size);
fire_EB(rmesa, rmesa->state.elt_dma.aos_offset, num_verts, type, rmesa->state.VB.elt_size);
#endif
}else{
r300EmitAOS(rmesa, rmesa->state.aos_count, start);
fire_AOS(PASS_PREFIX num_verts, type);
fire_AOS(rmesa, num_verts, type);
}
}
@ -370,7 +374,10 @@ GLboolean r300_run_vb_render(GLcontext *ctx,
r300ContextPtr rmesa = R300_CONTEXT(ctx);
struct radeon_vertex_buffer *VB = &rmesa->state.VB;
int i;
LOCAL_VARS
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
if (RADEON_DEBUG & DEBUG_PRIMS)
fprintf(stderr, "%s\n", __FUNCTION__);

View file

@ -239,7 +239,9 @@ int radeon_mm_alloc(r300ContextPtr rmesa, int alignment, int size)
#include "r300_emit.h"
static void emit_lin_cp(r300ContextPtr rmesa, unsigned long dst, unsigned long src, unsigned long size)
{
LOCAL_VARS
int cmd_reserved = 0;
int cmd_written = 0;
drm_radeon_cmd_header_t *cmd = NULL;
int cp_size;