gallium/draw: initial code to properly support llvm in the draw module
[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 r600EmitShader(GLcontext * ctx,
53 void ** shaderbo,
54 GLvoid * data,
55 int sizeinDWORD,
56 char * szShaderUsage)
57 {
58 radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
59 struct radeon_bo * pbo;
60 uint32_t *out;
61 shader_again_alloc:
62 pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
63 0,
64 sizeinDWORD * 4,
65 256,
66 RADEON_GEM_DOMAIN_GTT,
67 0);
68
69 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinDWORD, szShaderUsage);
70
71 if (!pbo) {
72 radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
73 rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
74 goto shader_again_alloc;
75 }
76
77 radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
78 pbo,
79 RADEON_GEM_DOMAIN_GTT, 0);
80
81 if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
82 pbo,
83 RADEON_GEM_DOMAIN_GTT, 0)) {
84 radeon_error("failure to revalidate BOs - badness\n");
85 return GL_FALSE;
86 }
87
88 radeon_bo_map(pbo, 1);
89
90 out = (uint32_t*)(pbo->ptr);
91
92 memcpy(out, data, sizeinDWORD * 4);
93
94 radeon_bo_unmap(pbo);
95
96 *shaderbo = (void*)pbo;
97
98 return GL_TRUE;
99 }
100
101 GLboolean r600DeleteShader(GLcontext * ctx,
102 void * shaderbo)
103 {
104 struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;
105
106 radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s: %p\n", __func__, pbo);
107
108 if (pbo) {
109 if (pbo->ptr)
110 radeon_bo_unmap(pbo);
111 radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
112 }
113
114 return GL_TRUE;
115 }