r6xx/r7xx: switch to common dma functions for vecs
[mesa.git] / src / mesa / drivers / dri / r600 / r600_emit.c
1 /**************************************************************************
2
3 Copyright 2008, 2009 Advanced Micro Devices Inc. (AMD)
4
5 Copyright (C) Advanced Micro Devices Inc. (AMD) 2009. All Rights Reserved.
6
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:
14
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.
18
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.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
32 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
33 */
34
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"
41
42 #include "swrast_setup/swrast_setup.h"
43 #include "math/m_translate.h"
44 #include "tnl/tnl.h"
45 #include "tnl/t_context.h"
46
47 #include "r600_context.h"
48 #include "r600_emit.h"
49
50 void r600EmitCacheFlush(r600ContextPtr rmesa)
51 {
52 BATCH_LOCALS(&rmesa->radeon);
53 /*
54 BEGIN_BATCH_NO_AUTOSTATE(4);
55 OUT_BATCH_REGVAL(R600_RB3D_DSTCACHE_CTLSTAT,
56 R600_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS |
57 R600_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
58 OUT_BATCH_REGVAL(R600_ZB_ZCACHE_CTLSTAT,
59 R600_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE |
60 R600_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
61 END_BATCH();
62 COMMIT_BATCH();
63 */
64 }
65
66 GLboolean r600EmitShader(GLcontext * ctx,
67 void ** shaderbo,
68 GLvoid * data,
69 int sizeinDWORD,
70 char * szShaderUsage)
71 {
72 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
73
74 struct radeon_bo * pbo;
75 uint32_t *out;
76
77 shader_again_alloc:
78 #ifdef RADEON_DEBUG_BO
79 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
80 0,
81 sizeinDWORD * 4,
82 256,
83 RADEON_GEM_DOMAIN_GTT,
84 0,
85 szShaderUsage);
86 #else
87 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
88 0,
89 sizeinDWORD * 4,
90 256,
91 RADEON_GEM_DOMAIN_GTT,
92 0);
93 #endif /* RADEON_DEBUG_BO */
94
95 if (!pbo)
96 {
97 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
98 goto shader_again_alloc;
99 }
100
101 radeon_validate_bo(radeonctx, pbo, RADEON_GEM_DOMAIN_GTT, 0);
102
103 if (radeon_revalidate_bos(radeonctx->glCtx) == GL_FALSE)
104 {
105 fprintf(stderr,"failure to revalidate BOs - badness\n");
106 }
107
108 radeon_bo_map(pbo, 1);
109
110 radeon_bo_ref(pbo);
111
112 out = (uint32_t*)(pbo->ptr);
113
114 memcpy(out, data, sizeinDWORD * 4);
115
116 radeon_bo_unmap(pbo);
117
118 *shaderbo = (void*)pbo;
119
120 return GL_TRUE;
121 }
122
123 GLboolean r600DeleteShader(GLcontext * ctx,
124 void * shaderbo)
125 {
126 struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;
127
128 if (pbo) {
129 radeon_bo_unmap(pbo);
130 radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
131 }
132
133 return GL_TRUE;
134 }