2 * Copyright (C) 2005 Vladimir Dergachev.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 * Vladimir Dergachev <volodya@mindspring.com>
31 * Nicolai Haehnle <prefect_@gmx.net>
32 * Aapo Tahkola <aet@rasterburn.org>
33 * Ben Skeggs <darktama@iinet.net.au>
34 * Jerome Glisse <j.glisse@gmail.com>
37 /* This files defines functions for accessing R300 hardware.
39 #ifndef __R300_EMIT_H__
40 #define __R300_EMIT_H__
43 #include "r300_context.h"
44 #include "r300_cmdbuf.h"
45 #include "radeon_reg.h"
47 /* TODO: move these defines (and the ones from DRM) into r300_reg.h and sync up
49 #define CP_PACKET0(reg, n) (RADEON_CP_PACKET0 | ((n)<<16) | ((reg)>>2))
50 #define CP_PACKET3( pkt, n ) \
51 (RADEON_CP_PACKET3 | (pkt) | ((n) << 16))
53 static inline uint32_t cmdpacket0(int reg
, int count
)
55 drm_r300_cmd_header_t cmd
;
57 cmd
.packet0
.cmd_type
= R300_CMD_PACKET0
;
58 cmd
.packet0
.count
= count
;
59 cmd
.packet0
.reghi
= ((unsigned int)reg
& 0xFF00) >> 8;
60 cmd
.packet0
.reglo
= ((unsigned int)reg
& 0x00FF);
65 static inline uint32_t cmdvpu(int addr
, int count
)
67 drm_r300_cmd_header_t cmd
;
69 cmd
.vpu
.cmd_type
= R300_CMD_VPU
;
70 cmd
.vpu
.count
= count
;
71 cmd
.vpu
.adrhi
= ((unsigned int)addr
& 0xFF00) >> 8;
72 cmd
.vpu
.adrlo
= ((unsigned int)addr
& 0x00FF);
77 static inline uint32_t cmdpacket3(int packet
)
79 drm_r300_cmd_header_t cmd
;
81 cmd
.packet3
.cmd_type
= R300_CMD_PACKET3
;
82 cmd
.packet3
.packet
= packet
;
87 static inline uint32_t cmdcpdelay(unsigned short count
)
89 drm_r300_cmd_header_t cmd
;
91 cmd
.delay
.cmd_type
= R300_CMD_CP_DELAY
;
92 cmd
.delay
.count
= count
;
97 static inline uint32_t cmdwait(unsigned char flags
)
99 drm_r300_cmd_header_t cmd
;
101 cmd
.wait
.cmd_type
= R300_CMD_WAIT
;
102 cmd
.wait
.flags
= flags
;
107 static inline uint32_t cmdpacify(void)
109 drm_r300_cmd_header_t cmd
;
111 cmd
.header
.cmd_type
= R300_CMD_END3D
;
117 * Prepare to write a register value to register at address reg.
118 * If num_extra > 0 then the following extra values are written
119 * to registers with address +4, +8 and so on..
121 #define reg_start(reg, num_extra) \
125 cmd = (drm_radeon_cmd_header_t*) \
126 r300AllocCmdBuf(rmesa, \
131 cmd[0].i=cmdpacket0((reg), _n+1); \
135 * Emit GLuint freestyle
139 if(cmd_written<cmd_reserved) { \
140 cmd[cmd_written].i=(dword); \
144 "e32 but no previous packet " \
146 "Aborting! in %s::%s at line %d, " \
147 "cmd_written=%d cmd_reserved=%d\n", \
148 __FILE__, __FUNCTION__, __LINE__, \
149 cmd_written, cmd_reserved); \
154 #define efloat(f) e32(r300PackFloat32(f))
156 #define vsf_start_fragment(dest, length) \
160 cmd = (drm_radeon_cmd_header_t*) \
161 r300AllocCmdBuf(rmesa, \
164 cmd_reserved = _n+2; \
166 cmd[0].i = cmdvpu((dest), _n/4); \
169 #define start_packet3(packet, count) \
175 cmd = (drm_radeon_cmd_header_t*) \
176 r300AllocCmdBuf(rmesa, \
179 cmd_reserved = _n+3; \
182 fprintf(stderr,"Too big packet3 %08x: cannot " \
183 "store %d dwords\n", \
187 cmd[0].i = cmdpacket3(R300_CMD_PACKET3_RAW); \
188 cmd[1].i = _p | ((_n & 0x3fff)<<16); \
192 * Must be sent to switch to 2d commands
194 void static inline end_3d(r300ContextPtr rmesa
)
196 drm_radeon_cmd_header_t
*cmd
= NULL
;
199 (drm_radeon_cmd_header_t
*) r300AllocCmdBuf(rmesa
, 1, __FUNCTION__
);
200 cmd
[0].header
.cmd_type
= R300_CMD_END3D
;
203 void static inline cp_delay(r300ContextPtr rmesa
, unsigned short count
)
205 drm_radeon_cmd_header_t
*cmd
= NULL
;
208 (drm_radeon_cmd_header_t
*) r300AllocCmdBuf(rmesa
, 1, __FUNCTION__
);
209 cmd
[0].i
= cmdcpdelay(count
);
212 void static inline cp_wait(r300ContextPtr rmesa
, unsigned char flags
)
214 drm_radeon_cmd_header_t
*cmd
= NULL
;
217 (drm_radeon_cmd_header_t
*) r300AllocCmdBuf(rmesa
, 1, __FUNCTION__
);
218 cmd
[0].i
= cmdwait(flags
);
221 extern int r300EmitArrays(GLcontext
* ctx
);
224 void r300UseArrays(GLcontext
* ctx
);
227 extern void r300ReleaseArrays(GLcontext
* ctx
);
228 extern int r300PrimitiveType(r300ContextPtr rmesa
, int prim
);
229 extern int r300NumVerts(r300ContextPtr rmesa
, int num_verts
, int prim
);
231 extern void r300EmitCacheFlush(r300ContextPtr rmesa
);
233 extern GLuint
r300VAPInputRoute1(uint32_t * dst
, int swizzle
[][4], GLuint nr
);
234 extern GLuint
r300VAPInputCntl0(GLcontext
* ctx
, GLuint InputsRead
);
235 extern GLuint
r300VAPInputCntl1(GLcontext
* ctx
, GLuint InputsRead
);
236 extern GLuint
r300VAPOutputCntl0(GLcontext
* ctx
, GLuint OutputsWritten
);
237 extern GLuint
r300VAPOutputCntl1(GLcontext
* ctx
, GLuint OutputsWritten
);