draw: corrections to allow for different cliptest cases
[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(GLcontext * 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(GLcontext * 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 uint8_t *out;
104
105 radeon_bo_map(pbo, 1);
106
107 out = (uint8_t*)(pbo->ptr);
108 out = (uint8_t*)ADD_POINTERS(pbo->ptr, bo_offset);
109
110 memcpy(out, data, sizeinBYTE);
111
112 radeon_bo_unmap(pbo);
113
114 return GL_TRUE;
115 }
116
117 GLboolean r600EmitShader(GLcontext * ctx,
118 void ** shaderbo,
119 GLvoid * data,
120 int sizeinDWORD,
121 char * szShaderUsage)
122 {
123 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
124 struct radeon_bo * pbo;
125 uint32_t *out;
126 shader_again_alloc:
127 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
128 0,
129 sizeinDWORD * 4,
130 256,
131 RADEON_GEM_DOMAIN_GTT,
132 0);
133
134 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinDWORD, szShaderUsage);
135
136 if (!pbo) {
137 radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
138 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
139 goto shader_again_alloc;
140 }
141
142 radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
143 pbo,
144 RADEON_GEM_DOMAIN_GTT, 0);
145
146 if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
147 pbo,
148 RADEON_GEM_DOMAIN_GTT, 0)) {
149 radeon_error("failure to revalidate BOs - badness\n");
150 return GL_FALSE;
151 }
152
153 radeon_bo_map(pbo, 1);
154
155 out = (uint32_t*)(pbo->ptr);
156
157 memcpy(out, data, sizeinDWORD * 4);
158
159 radeon_bo_unmap(pbo);
160
161 *shaderbo = (void*)pbo;
162
163 return GL_TRUE;
164 }
165
166 GLboolean r600DeleteShader(GLcontext * ctx,
167 void * shaderbo)
168 {
169 struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;
170
171 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s: %p\n", __func__, pbo);
172
173 if (pbo) {
174 if (pbo->ptr)
175 radeon_bo_unmap(pbo);
176 radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
177 }
178
179 return GL_TRUE;
180 }