r600c: add big endian support for r6xx/r7xx
[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
41 #include "swrast_setup/swrast_setup.h"
42 #include "tnl/tnl.h"
43 #include "tnl/t_context.h"
44
45 #include "r600_context.h"
46 #include "r600_emit.h"
47
48 void r600EmitCacheFlush(context_t *rmesa)
49 {
50 }
51
52 GLboolean r600AllocShaderConsts(struct gl_context * ctx,
53 void ** constbo,
54 int sizeinBYTE,
55 char * szShaderUsage)
56 {
57 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
58 struct radeon_bo * pbo;
59
60 if(sizeinBYTE < 64) /* SQ_ALU_CONST_BUFFER_SIZE need 64 bytes at least to be non 0 */
61 {
62 sizeinBYTE = 64;
63 }
64
65 shader_again_alloc:
66 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
67 0,
68 sizeinBYTE,
69 256,
70 RADEON_GEM_DOMAIN_GTT,
71 0);
72
73 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinBYTE, szShaderUsage);
74
75 if (!pbo) {
76 radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
77 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
78 goto shader_again_alloc;
79 }
80
81 radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
82 pbo,
83 RADEON_GEM_DOMAIN_GTT, 0);
84
85 if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
86 pbo,
87 RADEON_GEM_DOMAIN_GTT, 0)) {
88 radeon_error("failure to revalidate BOs - badness\n");
89 return GL_FALSE;
90 }
91
92 *constbo = (void*)pbo;
93
94 return GL_TRUE;
95 }
96 GLboolean r600EmitShaderConsts(struct gl_context * ctx,
97 void * constbo,
98 int bo_offset,
99 GLvoid * data,
100 int sizeinBYTE)
101 {
102 struct radeon_bo * pbo = (struct radeon_bo *)constbo;
103 uint32_t *out;
104 int i;
105
106 radeon_bo_map(pbo, 1);
107
108 out = (uint32_t*)(pbo->ptr);
109 out = (uint32_t*)ADD_POINTERS(pbo->ptr, bo_offset);
110
111 for(i = 0; i < sizeinBYTE / 4; i++) {
112 out[i] = CPU_TO_LE32(*((uint32_t *)data + i));
113 }
114
115 radeon_bo_unmap(pbo);
116
117 return GL_TRUE;
118 }
119
120 GLboolean r600EmitShader(struct gl_context * ctx,
121 void ** shaderbo,
122 GLvoid * data,
123 int sizeinDWORD,
124 char * szShaderUsage)
125 {
126 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
127 struct radeon_bo * pbo;
128 uint32_t *out;
129 int i;
130 shader_again_alloc:
131 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
132 0,
133 sizeinDWORD * 4,
134 256,
135 RADEON_GEM_DOMAIN_GTT,
136 0);
137
138 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinDWORD, szShaderUsage);
139
140 if (!pbo) {
141 radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
142 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
143 goto shader_again_alloc;
144 }
145
146 radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
147 pbo,
148 RADEON_GEM_DOMAIN_GTT, 0);
149
150 if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
151 pbo,
152 RADEON_GEM_DOMAIN_GTT, 0)) {
153 radeon_error("failure to revalidate BOs - badness\n");
154 return GL_FALSE;
155 }
156
157 radeon_bo_map(pbo, 1);
158
159 out = (uint32_t*)(pbo->ptr);
160
161 for(i = 0; i < sizeinDWORD; i++) {
162 out[i] = CPU_TO_LE32(*((uint32_t *)data + i));
163 }
164
165 radeon_bo_unmap(pbo);
166
167 *shaderbo = (void*)pbo;
168
169 return GL_TRUE;
170 }
171
172 GLboolean r600DeleteShader(struct gl_context * ctx,
173 void * shaderbo)
174 {
175 struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;
176
177 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s: %p\n", __func__, pbo);
178
179 if (pbo) {
180 if (pbo->ptr)
181 radeon_bo_unmap(pbo);
182 radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
183 }
184
185 return GL_TRUE;
186 }