Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  
  3. Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
  4.                      VA Linux Systems Inc., Fremont, California.
  5. Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
  6.  
  7. The Weather Channel (TM) funded Tungsten Graphics to develop the
  8. initial release of the Radeon 8500 driver under the XFree86 license.
  9. This notice must be preserved.
  10.  
  11. All Rights Reserved.
  12.  
  13. Permission is hereby granted, free of charge, to any person obtaining
  14. a copy of this software and associated documentation files (the
  15. "Software"), to deal in the Software without restriction, including
  16. without limitation the rights to use, copy, modify, merge, publish,
  17. distribute, sublicense, and/or sell copies of the Software, and to
  18. permit persons to whom the Software is furnished to do so, subject to
  19. the following conditions:
  20.  
  21. The above copyright notice and this permission notice (including the
  22. next paragraph) shall be included in all copies or substantial
  23. portions of the Software.
  24.  
  25. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  28. IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  29. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32.  
  33. **************************************************************************/
  34.  
  35. /*
  36.  * Authors:
  37.  *   Gareth Hughes <gareth@valinux.com>
  38.  *   Keith Whitwell <keith@tungstengraphics.com>
  39.  *   Kevin E. Martin <martin@valinux.com>
  40.  *   Nicolai Haehnle <prefect_@gmx.net>
  41.  */
  42.  
  43. #ifndef __RADEON_CONTEXT_H__
  44. #define __RADEON_CONTEXT_H__
  45.  
  46. #include "tnl/t_vertex.h"
  47. #include "dri_util.h"
  48. #include "drm.h"
  49. #include "radeon_drm.h"
  50. #include "main/macros.h"
  51. #include "main/mtypes.h"
  52. #include "main/colormac.h"
  53. #include "radeon_screen.h"
  54.  
  55. #include "radeon_common.h"
  56.  
  57.  
  58. struct r100_context;
  59. typedef struct r100_context r100ContextRec;
  60. typedef struct r100_context *r100ContextPtr;
  61.  
  62.  
  63.  
  64. #define R100_TEX_ALL 0x7
  65.  
  66. /* used for both tcl_vtx and vc_frmt tex bits (they are identical) */
  67. #define RADEON_ST_BIT(unit) \
  68. (unit == 0 ? RADEON_CP_VC_FRMT_ST0 : (RADEON_CP_VC_FRMT_ST1 >> 2) << (2 * unit))
  69.  
  70. #define RADEON_Q_BIT(unit) \
  71. (unit == 0 ? RADEON_CP_VC_FRMT_Q0 : (RADEON_CP_VC_FRMT_Q1 >> 2) << (2 * unit))
  72.  
  73. struct radeon_texture_env_state {
  74.         radeonTexObjPtr texobj;
  75.         GLenum format;
  76.         GLenum envMode;
  77. };
  78.  
  79. struct radeon_texture_state {
  80.         struct radeon_texture_env_state unit[RADEON_MAX_TEXTURE_UNITS];
  81. };
  82.  
  83. /* Trying to keep these relatively short as the variables are becoming
  84.  * extravagently long.  Drop the driver name prefix off the front of
  85.  * everything - I think we know which driver we're in by now, and keep the
  86.  * prefix to 3 letters unless absolutely impossible.  
  87.  */
  88.  
  89. #define CTX_CMD_0             0
  90. #define CTX_PP_MISC           1
  91. #define CTX_PP_FOG_COLOR      2
  92. #define CTX_RE_SOLID_COLOR    3
  93. #define CTX_RB3D_BLENDCNTL    4
  94. #define CTX_RB3D_DEPTHOFFSET  5
  95. #define CTX_RB3D_DEPTHPITCH   6
  96. #define CTX_RB3D_ZSTENCILCNTL 7
  97. #define CTX_CMD_1             8
  98. #define CTX_PP_CNTL           9
  99. #define CTX_RB3D_CNTL         10
  100. #define CTX_RB3D_COLOROFFSET  11
  101. #define CTX_CMD_2             12
  102. #define CTX_RB3D_COLORPITCH   13
  103. #define CTX_STATE_SIZE        14
  104.  
  105. #define SET_CMD_0               0
  106. #define SET_SE_CNTL             1
  107. #define SET_SE_COORDFMT         2
  108. #define SET_CMD_1               3
  109. #define SET_SE_CNTL_STATUS      4
  110. #define SET_STATE_SIZE          5
  111.  
  112. #define LIN_CMD_0               0
  113. #define LIN_RE_LINE_PATTERN     1
  114. #define LIN_RE_LINE_STATE       2
  115. #define LIN_CMD_1               3
  116. #define LIN_SE_LINE_WIDTH       4
  117. #define LIN_STATE_SIZE          5
  118.  
  119. #define MSK_CMD_0               0
  120. #define MSK_RB3D_STENCILREFMASK 1
  121. #define MSK_RB3D_ROPCNTL        2
  122. #define MSK_RB3D_PLANEMASK      3
  123. #define MSK_STATE_SIZE          4
  124.  
  125. #define VPT_CMD_0           0
  126. #define VPT_SE_VPORT_XSCALE          1
  127. #define VPT_SE_VPORT_XOFFSET         2
  128. #define VPT_SE_VPORT_YSCALE          3
  129. #define VPT_SE_VPORT_YOFFSET         4
  130. #define VPT_SE_VPORT_ZSCALE          5
  131. #define VPT_SE_VPORT_ZOFFSET         6
  132. #define VPT_STATE_SIZE      7
  133.  
  134. #define MSC_CMD_0               0
  135. #define MSC_RE_MISC             1
  136. #define MSC_STATE_SIZE          2
  137.  
  138. #define TEX_CMD_0                   0
  139. #define TEX_PP_TXFILTER             1
  140. #define TEX_PP_TXFORMAT             2
  141. #define TEX_PP_TXOFFSET             3
  142. #define TEX_PP_TXCBLEND             4
  143. #define TEX_PP_TXABLEND             5
  144. #define TEX_PP_TFACTOR              6
  145. #define TEX_CMD_1                   7
  146. #define TEX_PP_BORDER_COLOR         8
  147. #define TEX_STATE_SIZE              9
  148.  
  149. #define TXR_CMD_0                   0   /* rectangle textures */
  150. #define TXR_PP_TEX_SIZE             1   /* 0x1d04, 0x1d0c for NPOT! */
  151. #define TXR_PP_TEX_PITCH            2   /* 0x1d08, 0x1d10 for NPOT! */
  152. #define TXR_STATE_SIZE              3
  153.  
  154. #define CUBE_CMD_0                  0
  155. #define CUBE_PP_CUBIC_FACES         1
  156. #define CUBE_CMD_1                  2
  157. #define CUBE_PP_CUBIC_OFFSET_0      3
  158. #define CUBE_PP_CUBIC_OFFSET_1      4
  159. #define CUBE_PP_CUBIC_OFFSET_2      5
  160. #define CUBE_PP_CUBIC_OFFSET_3      6
  161. #define CUBE_PP_CUBIC_OFFSET_4      7
  162. #define CUBE_STATE_SIZE             8
  163.  
  164. #define ZBS_CMD_0              0
  165. #define ZBS_SE_ZBIAS_FACTOR             1
  166. #define ZBS_SE_ZBIAS_CONSTANT           2
  167. #define ZBS_STATE_SIZE         3
  168.  
  169. #define TCL_CMD_0                        0
  170. #define TCL_OUTPUT_VTXFMT         1
  171. #define TCL_OUTPUT_VTXSEL         2
  172. #define TCL_MATRIX_SELECT_0       3
  173. #define TCL_MATRIX_SELECT_1       4
  174. #define TCL_UCP_VERT_BLEND_CTL    5
  175. #define TCL_TEXTURE_PROC_CTL      6
  176. #define TCL_LIGHT_MODEL_CTL       7
  177. #define TCL_PER_LIGHT_CTL_0       8
  178. #define TCL_PER_LIGHT_CTL_1       9
  179. #define TCL_PER_LIGHT_CTL_2       10
  180. #define TCL_PER_LIGHT_CTL_3       11
  181. #define TCL_STATE_SIZE                   12
  182.  
  183. #define MTL_CMD_0            0
  184. #define MTL_EMMISSIVE_RED    1
  185. #define MTL_EMMISSIVE_GREEN  2
  186. #define MTL_EMMISSIVE_BLUE   3
  187. #define MTL_EMMISSIVE_ALPHA  4
  188. #define MTL_AMBIENT_RED      5
  189. #define MTL_AMBIENT_GREEN    6
  190. #define MTL_AMBIENT_BLUE     7
  191. #define MTL_AMBIENT_ALPHA    8
  192. #define MTL_DIFFUSE_RED      9
  193. #define MTL_DIFFUSE_GREEN    10
  194. #define MTL_DIFFUSE_BLUE     11
  195. #define MTL_DIFFUSE_ALPHA    12
  196. #define MTL_SPECULAR_RED     13
  197. #define MTL_SPECULAR_GREEN   14
  198. #define MTL_SPECULAR_BLUE    15
  199. #define MTL_SPECULAR_ALPHA   16
  200. #define MTL_SHININESS        17
  201. #define MTL_STATE_SIZE       18
  202.  
  203. #define VTX_CMD_0              0
  204. #define VTX_SE_COORD_FMT       1
  205. #define VTX_STATE_SIZE         2
  206.  
  207. #define MAT_CMD_0              0
  208. #define MAT_ELT_0              1
  209. #define MAT_STATE_SIZE         17
  210.  
  211. #define GRD_CMD_0                  0
  212. #define GRD_VERT_GUARD_CLIP_ADJ    1
  213. #define GRD_VERT_GUARD_DISCARD_ADJ 2
  214. #define GRD_HORZ_GUARD_CLIP_ADJ    3
  215. #define GRD_HORZ_GUARD_DISCARD_ADJ 4
  216. #define GRD_STATE_SIZE             5
  217.  
  218. /* position changes frequently when lighting in modelpos - separate
  219.  * out to new state item?  
  220.  */
  221. #define LIT_CMD_0                  0
  222. #define LIT_AMBIENT_RED            1
  223. #define LIT_AMBIENT_GREEN          2
  224. #define LIT_AMBIENT_BLUE           3
  225. #define LIT_AMBIENT_ALPHA          4
  226. #define LIT_DIFFUSE_RED            5
  227. #define LIT_DIFFUSE_GREEN          6
  228. #define LIT_DIFFUSE_BLUE           7
  229. #define LIT_DIFFUSE_ALPHA          8
  230. #define LIT_SPECULAR_RED           9
  231. #define LIT_SPECULAR_GREEN         10
  232. #define LIT_SPECULAR_BLUE          11
  233. #define LIT_SPECULAR_ALPHA         12
  234. #define LIT_POSITION_X             13
  235. #define LIT_POSITION_Y             14
  236. #define LIT_POSITION_Z             15
  237. #define LIT_POSITION_W             16
  238. #define LIT_DIRECTION_X            17
  239. #define LIT_DIRECTION_Y            18
  240. #define LIT_DIRECTION_Z            19
  241. #define LIT_DIRECTION_W            20
  242. #define LIT_ATTEN_QUADRATIC        21
  243. #define LIT_ATTEN_LINEAR           22
  244. #define LIT_ATTEN_CONST            23
  245. #define LIT_ATTEN_XXX              24
  246. #define LIT_CMD_1                  25
  247. #define LIT_SPOT_DCD               26
  248. #define LIT_SPOT_EXPONENT          27
  249. #define LIT_SPOT_CUTOFF            28
  250. #define LIT_SPECULAR_THRESH        29
  251. #define LIT_RANGE_CUTOFF           30   /* ? */
  252. #define LIT_ATTEN_CONST_INV        31
  253. #define LIT_STATE_SIZE             32
  254.  
  255. /* Fog
  256.  */
  257. #define FOG_CMD_0      0
  258. #define FOG_R          1
  259. #define FOG_C          2
  260. #define FOG_D          3
  261. #define FOG_PAD        4
  262. #define FOG_STATE_SIZE 5
  263.  
  264. /* UCP
  265.  */
  266. #define UCP_CMD_0      0
  267. #define UCP_X          1
  268. #define UCP_Y          2
  269. #define UCP_Z          3
  270. #define UCP_W          4
  271. #define UCP_STATE_SIZE 5
  272.  
  273. /* GLT - Global ambient
  274.  */
  275. #define GLT_CMD_0      0
  276. #define GLT_RED        1
  277. #define GLT_GREEN      2
  278. #define GLT_BLUE       3
  279. #define GLT_ALPHA      4
  280. #define GLT_STATE_SIZE 5
  281.  
  282. /* EYE
  283.  */
  284. #define EYE_CMD_0          0
  285. #define EYE_X              1
  286. #define EYE_Y              2
  287. #define EYE_Z              3
  288. #define EYE_RESCALE_FACTOR 4
  289. #define EYE_STATE_SIZE     5
  290.  
  291. #define SHN_CMD_0          0
  292. #define SHN_SHININESS      1
  293. #define SHN_STATE_SIZE     2
  294.  
  295. #define R100_QUERYOBJ_CMD_0  0
  296. #define R100_QUERYOBJ_DATA_0 1
  297. #define R100_QUERYOBJ_CMDSIZE  2
  298.  
  299. #define STP_CMD_0 0
  300. #define STP_DATA_0 1
  301. #define STP_CMD_1 2
  302. #define STP_STATE_SIZE 35
  303.  
  304. struct r100_hw_state {
  305.         /* Hardware state, stored as cmdbuf commands:  
  306.          *   -- Need to doublebuffer for
  307.          *           - eliding noop statechange loops? (except line stipple count)
  308.          */
  309.         struct radeon_state_atom ctx;
  310.         struct radeon_state_atom set;
  311.         struct radeon_state_atom lin;
  312.         struct radeon_state_atom msk;
  313.         struct radeon_state_atom vpt;
  314.         struct radeon_state_atom tcl;
  315.         struct radeon_state_atom msc;
  316.         struct radeon_state_atom tex[3];
  317.         struct radeon_state_atom cube[3];
  318.         struct radeon_state_atom zbs;
  319.         struct radeon_state_atom mtl;
  320.         struct radeon_state_atom mat[6];
  321.         struct radeon_state_atom lit[8];        /* includes vec, scl commands */
  322.         struct radeon_state_atom ucp[6];
  323.         struct radeon_state_atom eye;   /* eye pos */
  324.         struct radeon_state_atom grd;   /* guard band clipping */
  325.         struct radeon_state_atom fog;
  326.         struct radeon_state_atom glt;
  327.         struct radeon_state_atom txr[3];        /* for NPOT */
  328.         struct radeon_state_atom stp;
  329. };
  330.  
  331. struct radeon_stipple_state {
  332.         GLuint mask[32];
  333. };
  334.  
  335. struct r100_state {
  336.         struct radeon_stipple_state stipple;
  337.         struct radeon_texture_state texture;
  338. };
  339.  
  340. #define RADEON_CMD_BUF_SZ  (8*1024)
  341. #define R200_ELT_BUF_SZ  (8*1024)
  342. /* radeon_tcl.c
  343.  */
  344. struct r100_tcl_info {
  345.         GLuint vertex_format;
  346.         GLuint hw_primitive;
  347.  
  348.         /* Temporary for cases where incoming vertex data is incompatible
  349.          * with maos code.
  350.          */
  351.         GLvector4f ObjClean;
  352.  
  353.         GLuint *Elts;
  354.  
  355.         int elt_cmd_offset;
  356.         int elt_cmd_start;
  357.         int elt_used;
  358. };
  359.  
  360. /* radeon_swtcl.c
  361.  */
  362. struct r100_swtcl_info {
  363.         GLuint vertex_format;
  364.  
  365.         GLubyte *verts;
  366.  
  367.         /* Fallback rasterization functions
  368.          */
  369.         radeon_point_func draw_point;
  370.         radeon_line_func draw_line;
  371.         radeon_tri_func draw_tri;
  372.  
  373.    /**
  374.     * Offset of the 4UB color data within a hardware (swtcl) vertex.
  375.     */
  376.         GLuint coloroffset;
  377.  
  378.    /**
  379.     * Offset of the 3UB specular color data within a hardware (swtcl) vertex.
  380.     */
  381.         GLuint specoffset;
  382.  
  383.         GLboolean needproj;
  384. };
  385.  
  386.  
  387.  
  388. /* A maximum total of 20 elements per vertex:  3 floats for position, 3
  389.  * floats for normal, 4 floats for color, 4 bytes for secondary color,
  390.  * 3 floats for each texture unit (9 floats total).
  391.  *
  392.  * The position data is never actually stored here, so 3 elements could be
  393.  * trimmed out of the buffer. This number is only valid for vtxfmt!
  394.  */
  395. #define RADEON_MAX_VERTEX_SIZE 20
  396.  
  397. struct r100_context {
  398.         struct radeon_context radeon;
  399.  
  400.         /* Driver and hardware state management
  401.          */
  402.         struct r100_hw_state hw;
  403.         struct r100_state state;
  404.  
  405.         /* Vertex buffers
  406.          */
  407.         struct radeon_ioctl ioctl;
  408.         struct radeon_store store;
  409.  
  410.         /* TCL stuff
  411.          */
  412.         GLmatrix TexGenMatrix[RADEON_MAX_TEXTURE_UNITS];
  413.         GLboolean recheck_texgen[RADEON_MAX_TEXTURE_UNITS];
  414.         GLboolean TexGenNeedNormals[RADEON_MAX_TEXTURE_UNITS];
  415.         GLuint TexGenEnabled;
  416.         GLuint NeedTexMatrix;
  417.         GLuint TexMatColSwap;
  418.         GLmatrix tmpmat[RADEON_MAX_TEXTURE_UNITS];
  419.         GLuint last_ReallyEnabled;
  420.  
  421.         /* radeon_tcl.c
  422.          */
  423.         struct r100_tcl_info tcl;
  424.  
  425.         /* radeon_swtcl.c
  426.          */
  427.         struct r100_swtcl_info swtcl;
  428.  
  429.         GLboolean using_hyperz;
  430.         GLboolean texmicrotile;
  431.  
  432.         /* Performance counters
  433.          */
  434.         GLuint boxes;           /* Draw performance boxes */
  435.         GLuint hardwareWentIdle;
  436.         GLuint c_clears;
  437.         GLuint c_drawWaits;
  438.         GLuint c_textureSwaps;
  439.         GLuint c_textureBytes;
  440.         GLuint c_vertexBuffers;
  441.  
  442. };
  443.  
  444.  
  445. static inline r100ContextPtr
  446. R100_CONTEXT(struct gl_context *ctx)
  447. {
  448.    return (r100ContextPtr) ctx;
  449. }
  450.  
  451.  
  452.  
  453. #define RADEON_OLD_PACKETS 1
  454.  
  455. extern GLboolean r100CreateContext( gl_api api,
  456.                                     const struct gl_config *glVisual,
  457.                                     __DRIcontext *driContextPriv,
  458.                                     unsigned major_version,
  459.                                     unsigned minor_version,
  460.                                     uint32_t flags,
  461.                                     unsigned *error,
  462.                                     void *sharedContextPrivate);
  463.  
  464.  
  465. #endif                          /* __RADEON_CONTEXT_H__ */
  466.