2 Copyright © 2012, The AROS Development Team. All rights reserved.
7 * Copyright © 2011 Intel Corporation
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 * Chris Wilson (intel-gpu-tools)
30 * 2012, The AROS Development Team.
33 #include <proto/exec.h>
34 #include <hidd/graphics.h>
35 #include <aros/debug.h>
37 #include "intelG45_intern.h"
38 #include "intelG45_regs.h"
40 //#include "i915/i915_reg.h" // crashes !?
46 extern struct g45staticdata sd
;
47 #define sd ((struct g45staticdata*)&(sd))
50 static inline uint32_t pack_float(float f
)
60 #define IS_915G(Id) ((Id) == 0x2582 || \
62 #define IS_915GM(Id) ((Id) == 0x2592)
64 #define IS_915(Id) (IS_915G(Id) || \
67 #define IS_945G(Id) ((Id) == 0x2772)
68 #define IS_945GM(Id) ((Id) == 0x27A2 || \
71 #define IS_945(Id) (IS_945G(Id) || \
76 #define IS_G33(Id) ((Id) == 0x29C2 || \
80 #define IS_PINEVIEW(Id) ((Id) == 0xa001 || \
83 #define IS_GEN3(Id) (IS_915(Id) || \
88 BOOL
copybox3d_supported()
91 if( IS_GEN3( sd
->ProductID
) )
98 BOOL
copybox3d( GMABitMap_t
*bm_dst
, GMABitMap_t
*bm_src
,
99 ULONG dst_x
,ULONG dst_y
,ULONG dst_width
, ULONG dst_height
,
100 ULONG src_x
,ULONG src_y
,ULONG src_width
, ULONG src_height
)
105 if( !copybox3d_supported() )
110 // buffers in gfx memory ?
111 if( ! (bm_src
->fbgfx
&& bm_src
->fbgfx
) )
116 // Max texture size, src and dst must be differend (at least if overlaps)
117 if( bm_src
->pitch
/4 > 2048 || bm_src
->height
> 2048 || bm_dst
== bm_src
)
122 // src pitch must be long aligmented.
123 if( bm_src
->pitch
& 0x3 )
125 bug("[GMA] copybox3d: ERROR bm_src->pitch=%d/n",bm_src
->pitch
);
131 src_format
= MAPSURF_32BIT
| MT_32BIT_ARGB8888
;
133 else if(bm_src
->bpp
== 2)
135 src_format
= MAPSURF_16BIT
| MT_16BIT_RGB565
;
139 bug("[GMA] copybox3d: ERROR src_bpp=%d/n",bm_src
->bpp
);
145 dst_format
= COLR_BUF_ARGB8888
;
147 else if(bm_dst
->bpp
== 2)
149 dst_format
= COLR_BUF_RGB565
;
153 bug("[GMA] copybox3d: ERROR dst_bpp=%d/n",bm_dst
->bpp
);
160 /* invariant state */
161 OUT_RING( _3DSTATE_AA_CMD
|
162 AA_LINE_ECAAR_WIDTH_ENABLE
|
163 AA_LINE_ECAAR_WIDTH_1_0
|
164 AA_LINE_REGION_WIDTH_ENABLE
| AA_LINE_REGION_WIDTH_1_0
);
165 OUT_RING( _3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD
|
167 IAB_MODIFY_FUNC
| (BLENDFUNC_ADD
<< IAB_FUNC_SHIFT
) |
168 IAB_MODIFY_SRC_FACTOR
| (BLENDFACT_ONE
<<
169 IAB_SRC_FACTOR_SHIFT
) |
170 IAB_MODIFY_DST_FACTOR
| (BLENDFACT_ZERO
<<
171 IAB_DST_FACTOR_SHIFT
) );
172 OUT_RING( _3DSTATE_DFLT_DIFFUSE_CMD
);
174 OUT_RING( _3DSTATE_DFLT_SPEC_CMD
);
176 OUT_RING( _3DSTATE_DFLT_Z_CMD
);
178 OUT_RING( _3DSTATE_COORD_SET_BINDINGS
|
184 CSB_TCB(5, 5) | CSB_TCB(6, 6) | CSB_TCB(7, 7) );
185 OUT_RING( _3DSTATE_RASTER_RULES_CMD
|
186 ENABLE_POINT_RASTER_RULE
|
187 OGL_POINT_RASTER_RULE
|
188 ENABLE_LINE_STRIP_PROVOKE_VRTX
|
189 ENABLE_TRI_FAN_PROVOKE_VRTX
|
190 LINE_STRIP_PROVOKE_VRTX(1) |
191 TRI_FAN_PROVOKE_VRTX(2) | ENABLE_TEXKILL_3D_4D
| TEXKILL_4D
);
192 OUT_RING( _3DSTATE_MODES_4_CMD
|
193 ENABLE_LOGIC_OP_FUNC
| LOGIC_OP_FUNC(LOGICOP_COPY
) |
194 ENABLE_STENCIL_WRITE_MASK
| STENCIL_WRITE_MASK(0xff) |
195 ENABLE_STENCIL_TEST_MASK
| STENCIL_TEST_MASK(0xff) );
196 OUT_RING( _3DSTATE_LOAD_STATE_IMMEDIATE_1
| I1_LOAD_S(3) | I1_LOAD_S(4) | I1_LOAD_S(5) | 2 );
197 OUT_RING( 0x00000000 ); /* Disable texture coordinate wrap-shortest */
198 OUT_RING( (1 << S4_POINT_WIDTH_SHIFT
) |
202 OUT_RING( 0x00000000 ); /* Stencil. */
203 OUT_RING( _3DSTATE_SCISSOR_ENABLE_CMD
| DISABLE_SCISSOR_RECT
);
204 OUT_RING( _3DSTATE_SCISSOR_RECT_0_CMD
);
207 OUT_RING( _3DSTATE_DEPTH_SUBRECT_DISABLE
);
208 OUT_RING( _3DSTATE_LOAD_INDIRECT
| 0 ); /* disable indirect state */
210 OUT_RING( _3DSTATE_STIPPLE
);
211 OUT_RING( 0x00000000 );
212 OUT_RING( _3DSTATE_BACKFACE_STENCIL_OPS
| BFO_ENABLE_STENCIL_TWO_SIDE
| 0 );
216 OUT_RING( _3DSTATE_MAP_STATE
| (3 * TEX_COUNT
) );
217 OUT_RING( (1 << TEX_COUNT
) - 1 );
220 OUT_RING( bm_src
->framebuffer
);
221 OUT_RING( src_format
|
222 (bm_src
->height
- 1) << MS3_HEIGHT_SHIFT
|
223 (bm_src
->pitch
/bm_src
->bpp
- 1) << MS3_WIDTH_SHIFT
);
224 OUT_RING( (bm_src
->pitch
/4 -1) << MS4_PITCH_SHIFT
);
226 OUT_RING( _3DSTATE_SAMPLER_STATE
| (3 * TEX_COUNT
) );
227 OUT_RING( (1 << TEX_COUNT
) - 1 );
228 OUT_RING( MIPFILTER_NONE
<< SS2_MIP_FILTER_SHIFT
|
229 FILTER_NEAREST
<< SS2_MAG_FILTER_SHIFT
|
230 FILTER_NEAREST
<< SS2_MIN_FILTER_SHIFT
);
231 OUT_RING( TEXCOORDMODE_WRAP
<< SS3_TCX_ADDR_MODE_SHIFT
|
232 TEXCOORDMODE_WRAP
<< SS3_TCY_ADDR_MODE_SHIFT
|
233 0 << SS3_TEXTUREMAP_INDEX_SHIFT
);
234 OUT_RING( 0x00000000 );
236 /* render target state */
238 // Destination buffer
239 OUT_RING( _3DSTATE_BUF_INFO_CMD
);
240 OUT_RING( BUF_3D_ID_COLOR_BACK
| bm_dst
->pitch
);
241 OUT_RING( bm_dst
->framebuffer
);
242 OUT_RING( _3DSTATE_DST_BUF_VARS_CMD
);
243 OUT_RING( dst_format
|
244 DSTORG_HORT_BIAS(0x8) |
245 DSTORG_VERT_BIAS(0x8) );
247 /* draw rect is unconditional */
248 OUT_RING( _3DSTATE_DRAW_RECT_CMD
);
250 OUT_RING( 0x00000000 );
251 OUT_RING( 0x00000000 ); // ymin, xmin
252 OUT_RING( DRAW_YMAX(dst_y
+ dst_height
- 1) |
253 DRAW_XMAX(dst_x
+ dst_width
- 1) );
255 /* yorig, xorig (relate to color buffer?) */
256 OUT_RING( 0x00000000 );
259 OUT_RING( _3DSTATE_LOAD_STATE_IMMEDIATE_1
| I1_LOAD_S(1) | I1_LOAD_S(2) | I1_LOAD_S(6) | 2 );
260 OUT_RING( (4 << S1_VERTEX_WIDTH_SHIFT
) | (4 << S1_VERTEX_PITCH_SHIFT
) );
261 OUT_RING( ~S2_TEXCOORD_FMT(0, TEXCOORDFMT_NOT_PRESENT
) |
262 S2_TEXCOORD_FMT(0, TEXCOORDFMT_2D
) );
263 OUT_RING( S6_CBUF_BLEND_ENABLE
| S6_COLOR_WRITE_ENABLE
|
264 BLENDFUNC_ADD
<< S6_CBUF_BLEND_FUNC_SHIFT
|
265 BLENDFACT_ONE
<< S6_CBUF_SRC_BLEND_FACT_SHIFT
|
266 BLENDFACT_ZERO
<< S6_CBUF_DST_BLEND_FACT_SHIFT
);
269 OUT_RING( _3DSTATE_PIXEL_SHADER_PROGRAM
| (1 + 3*3 - 2) );
272 REG_TYPE(FS_T0
) << D0_TYPE_SHIFT
|
273 REG_NR(FS_T0
) << D0_NR_SHIFT
|
274 ((REG_TYPE(FS_T0
) != REG_TYPE_S
) ? D0_CHANNEL_ALL
: 0) );
279 (REG_TYPE(FS_S0
) << D0_TYPE_SHIFT
) |
280 (REG_NR(FS_S0
) << D0_NR_SHIFT
) |
281 ((REG_TYPE(FS_S0
) != REG_TYPE_S
) ? D0_CHANNEL_ALL
: 0) );
284 /* texld(FS_OC, FS_S0, FS_T0 */
286 (REG_TYPE(FS_OC
) << T0_DEST_TYPE_SHIFT
) |
287 (REG_NR(FS_OC
) << T0_DEST_NR_SHIFT
) |
288 (REG_NR(FS_S0
) << T0_SAMPLER_NR_SHIFT
) );
289 OUT_RING( (REG_TYPE(FS_T0
) << T1_ADDRESS_REG_TYPE_SHIFT
) |
290 (REG_NR(FS_T0
) << T1_ADDRESS_REG_NR_SHIFT
) );
297 OUT_RING( PRIM3D_RECTLIST
| (3*4 - 1) );
298 OUT_RING( pack_float( dst_x
+ dst_width
) );
299 OUT_RING( pack_float( dst_y
+ dst_height
) );
300 OUT_RING( pack_float(src_x
+ src_width
) );
301 OUT_RING( pack_float(src_y
+ src_height
) );
303 OUT_RING( pack_float( dst_x
+ 0 ) );
304 OUT_RING( pack_float( dst_y
+dst_height
) );
305 OUT_RING( pack_float(src_x
+ 0) );
306 OUT_RING( pack_float(src_y
+ src_height
) );
308 OUT_RING( pack_float( dst_x
+ 0 ) );
309 OUT_RING( pack_float( dst_y
+ 0 ) );
310 OUT_RING( pack_float(src_x
+ 0) );
311 OUT_RING( pack_float(src_y
+ 0) );