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"
41 #include "swrast_setup/swrast_setup.h"
43 #include "tnl/t_context.h"
45 #include "r600_context.h"
46 #include "r600_emit.h"
48 void r600EmitCacheFlush(context_t
*rmesa
)
52 GLboolean
r600AllocShaderConsts(struct gl_context
* ctx
,
57 radeonContextPtr radeonctx
= RADEON_CONTEXT(ctx
);
58 struct radeon_bo
* pbo
;
60 if(sizeinBYTE
< 64) /* SQ_ALU_CONST_BUFFER_SIZE need 64 bytes at least to be non 0 */
66 pbo
= radeon_bo_open(radeonctx
->radeonScreen
->bom
,
70 RADEON_GEM_DOMAIN_GTT
,
73 radeon_print(RADEON_SHADER
, RADEON_NORMAL
, "%s %p size %d: %s\n", __func__
, pbo
, sizeinBYTE
, szShaderUsage
);
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
;
81 radeon_cs_space_add_persistent_bo(radeonctx
->cmdbuf
.cs
,
83 RADEON_GEM_DOMAIN_GTT
, 0);
85 if (radeon_cs_space_check_with_bo(radeonctx
->cmdbuf
.cs
,
87 RADEON_GEM_DOMAIN_GTT
, 0)) {
88 radeon_error("failure to revalidate BOs - badness\n");
92 *constbo
= (void*)pbo
;
96 GLboolean
r600EmitShaderConsts(struct gl_context
* ctx
,
102 struct radeon_bo
* pbo
= (struct radeon_bo
*)constbo
;
106 radeon_bo_map(pbo
, 1);
108 out
= (uint32_t*)(pbo
->ptr
);
109 out
= (uint32_t*)ADD_POINTERS(pbo
->ptr
, bo_offset
);
111 for(i
= 0; i
< sizeinBYTE
/ 4; i
++) {
112 out
[i
] = CPU_TO_LE32(*((uint32_t *)data
+ i
));
115 radeon_bo_unmap(pbo
);
120 GLboolean
r600EmitShader(struct gl_context
* ctx
,
124 char * szShaderUsage
)
126 radeonContextPtr radeonctx
= RADEON_CONTEXT(ctx
);
127 struct radeon_bo
* pbo
;
131 pbo
= radeon_bo_open(radeonctx
->radeonScreen
->bom
,
135 RADEON_GEM_DOMAIN_GTT
,
138 radeon_print(RADEON_SHADER
, RADEON_NORMAL
, "%s %p size %d: %s\n", __func__
, pbo
, sizeinDWORD
, szShaderUsage
);
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
;
146 radeon_cs_space_add_persistent_bo(radeonctx
->cmdbuf
.cs
,
148 RADEON_GEM_DOMAIN_GTT
, 0);
150 if (radeon_cs_space_check_with_bo(radeonctx
->cmdbuf
.cs
,
152 RADEON_GEM_DOMAIN_GTT
, 0)) {
153 radeon_error("failure to revalidate BOs - badness\n");
157 radeon_bo_map(pbo
, 1);
159 out
= (uint32_t*)(pbo
->ptr
);
161 for(i
= 0; i
< sizeinDWORD
; i
++) {
162 out
[i
] = CPU_TO_LE32(*((uint32_t *)data
+ i
));
165 radeon_bo_unmap(pbo
);
167 *shaderbo
= (void*)pbo
;
172 GLboolean
r600DeleteShader(struct gl_context
* ctx
,
175 struct radeon_bo
* pbo
= (struct radeon_bo
*)shaderbo
;
177 radeon_print(RADEON_SHADER
, RADEON_NORMAL
, "%s: %p\n", __func__
, pbo
);
181 radeon_bo_unmap(pbo
);
182 radeon_bo_unref(pbo
); /* when bo->cref <= 0, bo will be bo_free */