1 /**************************************************************************
3 Copyright 2008, 2009 Advanced Micro Devices Inc. (AMD)
5 Copyright (C) Advanced Micro Devices Inc. (AMD) 2009. All Rights Reserved.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice (including the
16 next paragraph) shall be included in all copies or substantial
17 portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
23 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
32 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
35 #include "main/glheader.h"
36 #include "main/mtypes.h"
37 #include "main/colormac.h"
38 #include "main/imports.h"
39 #include "main/macros.h"
40 #include "main/image.h"
42 #include "swrast_setup/swrast_setup.h"
43 #include "math/m_translate.h"
45 #include "tnl/t_context.h"
47 #include "r600_context.h"
48 #include "r600_emit.h"
50 #if defined(USE_X86_ASM)
51 #define COPY_DWORDS( dst, src, nr ) \
54 __asm__ __volatile__( "rep ; movsl" \
55 : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
61 #define COPY_DWORDS( dst, src, nr ) \
64 for ( j = 0 ; j < nr ; j++ ) \
65 dst[j] = ((int *)src)[j]; \
70 static void r600EmitVec4(uint32_t *out
, GLvoid
* data
, int stride
, int count
)
74 if (RADEON_DEBUG
& DEBUG_VERTS
)
75 fprintf(stderr
, "%s count %d stride %d out %p data %p\n",
76 __FUNCTION__
, count
, stride
, (void *)out
, (void *)data
);
79 COPY_DWORDS(out
, data
, count
);
81 for (i
= 0; i
< count
; i
++) {
82 out
[0] = *(int *)data
;
88 static void r600EmitVec8(uint32_t *out
, GLvoid
* data
, int stride
, int count
)
92 if (RADEON_DEBUG
& DEBUG_VERTS
)
93 fprintf(stderr
, "%s count %d stride %d out %p data %p\n",
94 __FUNCTION__
, count
, stride
, (void *)out
, (void *)data
);
97 COPY_DWORDS(out
, data
, count
* 2);
99 for (i
= 0; i
< count
; i
++) {
100 out
[0] = *(int *)data
;
101 out
[1] = *(int *)(data
+ 4);
107 static void r600EmitVec12(uint32_t *out
, GLvoid
* data
, int stride
, int count
)
111 if (RADEON_DEBUG
& DEBUG_VERTS
)
112 fprintf(stderr
, "%s count %d stride %d out %p data %p\n",
113 __FUNCTION__
, count
, stride
, (void *)out
, (void *)data
);
116 COPY_DWORDS(out
, data
, count
* 3);
119 for (i
= 0; i
< count
; i
++) {
120 out
[0] = *(int *)data
;
121 out
[1] = *(int *)(data
+ 4);
122 out
[2] = *(int *)(data
+ 8);
128 static void r600EmitVec16(uint32_t *out
, GLvoid
* data
, int stride
, int count
)
132 if (RADEON_DEBUG
& DEBUG_VERTS
)
133 fprintf(stderr
, "%s count %d stride %d out %p data %p\n",
134 __FUNCTION__
, count
, stride
, (void *)out
, (void *)data
);
137 COPY_DWORDS(out
, data
, count
* 4);
139 for (i
= 0; i
< count
; i
++) {
140 out
[0] = *(int *)data
;
141 out
[1] = *(int *)(data
+ 4);
142 out
[2] = *(int *)(data
+ 8);
143 out
[3] = *(int *)(data
+ 12);
149 /* Emit vertex data to GART memory
150 * Route inputs to the vertex processor
151 * This function should never return R600_FALLBACK_TCL when using software tcl.
153 int r600EmitArrays(GLcontext
* ctx
)
156 return R600_FALLBACK_NONE
;
159 void r600EmitCacheFlush(r600ContextPtr rmesa
)
161 BATCH_LOCALS(&rmesa
->radeon
);
163 BEGIN_BATCH_NO_AUTOSTATE(4);
164 OUT_BATCH_REGVAL(R600_RB3D_DSTCACHE_CTLSTAT,
165 R600_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS |
166 R600_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
167 OUT_BATCH_REGVAL(R600_ZB_ZCACHE_CTLSTAT,
168 R600_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE |
169 R600_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
175 GLboolean
r600EmitShader(GLcontext
* ctx
,
180 radeonContextPtr radeonctx
= RADEON_CONTEXT(ctx
);
182 struct radeon_bo
* pbo
;
186 pbo
= radeon_bo_open(radeonctx
->radeonScreen
->bom
,
190 RADEON_GEM_DOMAIN_GTT
,
195 rcommonFlushCmdBuf(radeonctx
, __FUNCTION__
);
196 goto shader_again_alloc
;
199 radeon_validate_bo(radeonctx
, pbo
, RADEON_GEM_DOMAIN_GTT
, 0);
201 if (radeon_revalidate_bos(radeonctx
->glCtx
) == GL_FALSE
)
203 fprintf(stderr
,"failure to revalidate BOs - badness\n");
206 radeon_bo_map(pbo
, 1);
210 out
= (uint32_t*)(pbo
->ptr
);
212 memcpy(out
, data
, sizeinDWORD
* 4);
214 *shaderbo
= (void*)pbo
;
219 GLboolean
r600DeleteShader(GLcontext
* ctx
,
222 struct radeon_bo
* pbo
= (struct radeon_bo
*)shaderbo
;
224 radeon_bo_unmap(pbo
);
225 radeon_bo_unref(pbo
); /* when bo->cref <= 0, bo will be bo_free */
230 GLboolean
r600EmitVec(GLcontext
* ctx
,
231 struct radeon_aos
*aos
,
237 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
242 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, size
* count
* 4, 32);
247 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, size
* count
* 4, 32);
251 aos
->components
= size
;
254 out
= (uint32_t*)((char*)aos
->bo
->ptr
+ aos
->offset
);
256 case 1: r600EmitVec4(out
, data
, stride
, count
); break;
257 case 2: r600EmitVec8(out
, data
, stride
, count
); break;
258 case 3: r600EmitVec12(out
, data
, stride
, count
); break;
259 case 4: r600EmitVec16(out
, data
, stride
, count
); break;
268 void r600ReleaseVec(GLcontext
* ctx
)
270 radeonReleaseArrays(ctx
, ~0);
273 void r600FreeDmaRegion(context_t
*context
,
276 struct radeon_bo
*pbo
= (struct radeon_bo
*)shaderbo
;
279 radeon_bo_unref(pbo
);