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(GLcontext
* 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(GLcontext
* ctx
,
102 struct radeon_bo
* pbo
= (struct radeon_bo
*)constbo
;
105 radeon_bo_map(pbo
, 1);
107 out
= (uint8_t*)(pbo
->ptr
);
108 out
= (uint8_t*)ADD_POINTERS(pbo
->ptr
, bo_offset
);
110 memcpy(out
, data
, sizeinBYTE
);
112 radeon_bo_unmap(pbo
);
117 GLboolean
r600EmitShader(GLcontext
* ctx
,
121 char * szShaderUsage
)
123 radeonContextPtr radeonctx
= RADEON_CONTEXT(ctx
);
124 struct radeon_bo
* pbo
;
127 pbo
= radeon_bo_open(radeonctx
->radeonScreen
->bom
,
131 RADEON_GEM_DOMAIN_GTT
,
134 radeon_print(RADEON_SHADER
, RADEON_NORMAL
, "%s %p size %d: %s\n", __func__
, pbo
, sizeinDWORD
, szShaderUsage
);
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
;
142 radeon_cs_space_add_persistent_bo(radeonctx
->cmdbuf
.cs
,
144 RADEON_GEM_DOMAIN_GTT
, 0);
146 if (radeon_cs_space_check_with_bo(radeonctx
->cmdbuf
.cs
,
148 RADEON_GEM_DOMAIN_GTT
, 0)) {
149 radeon_error("failure to revalidate BOs - badness\n");
153 radeon_bo_map(pbo
, 1);
155 out
= (uint32_t*)(pbo
->ptr
);
157 memcpy(out
, data
, sizeinDWORD
* 4);
159 radeon_bo_unmap(pbo
);
161 *shaderbo
= (void*)pbo
;
166 GLboolean
r600DeleteShader(GLcontext
* ctx
,
169 struct radeon_bo
* pbo
= (struct radeon_bo
*)shaderbo
;
171 radeon_print(RADEON_SHADER
, RADEON_NORMAL
, "%s: %p\n", __func__
, pbo
);
175 radeon_bo_unmap(pbo
);
176 radeon_bo_unref(pbo
); /* when bo->cref <= 0, bo will be bo_free */