Merge branch 'mesa_7_5_branch'
[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(context_t *rmesa)
51 {
52 BATCH_LOCALS(&rmesa->radeon);
53 }
54
55 GLboolean r600EmitShader(GLcontext * ctx,
56 void ** shaderbo,
57 GLvoid * data,
58 int sizeinDWORD,
59 char * szShaderUsage)
60 {
61 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
62
63 struct radeon_bo * pbo;
64 uint32_t *out;
65
66 shader_again_alloc:
67 #ifdef RADEON_DEBUG_BO
68 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
69 0,
70 sizeinDWORD * 4,
71 256,
72 RADEON_GEM_DOMAIN_GTT,
73 0,
74 szShaderUsage);
75 #else
76 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
77 0,
78 sizeinDWORD * 4,
79 256,
80 RADEON_GEM_DOMAIN_GTT,
81 0);
82 #endif /* RADEON_DEBUG_BO */
83
84 if (!pbo)
85 {
86 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
87 goto shader_again_alloc;
88 }
89
90 if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
91 pbo,
92 RADEON_GEM_DOMAIN_GTT, 0))
93 fprintf(stderr,"failure to revalidate BOs - badness\n");
94
95
96 radeon_bo_map(pbo, 1);
97
98 radeon_bo_ref(pbo);
99
100 out = (uint32_t*)(pbo->ptr);
101
102 memcpy(out, data, sizeinDWORD * 4);
103
104 radeon_bo_unmap(pbo);
105
106 *shaderbo = (void*)pbo;
107
108 return GL_TRUE;
109 }
110
111 GLboolean r600DeleteShader(GLcontext * ctx,
112 void * shaderbo)
113 {
114 struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;
115
116 if (pbo) {
117 radeon_bo_unmap(pbo);
118 radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
119 }
120
121 return GL_TRUE;
122 }