r600_emit.c 4.96 KB
Newer Older
Richard Li's avatar
Richard Li committed
1
2
3
/**************************************************************************

Copyright 2008, 2009 Advanced Micro Devices Inc. (AMD)
Alex Deucher's avatar
Alex Deucher committed
4

Richard Li's avatar
Richard Li committed
5
Copyright (C) Advanced Micro Devices Inc. (AMD)  2009.  All Rights Reserved.
Alex Deucher's avatar
Alex Deucher committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

**************************************************************************/

Richard Li's avatar
Richard Li committed
29
30
31
32
/*
 * Authors:
 *   Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
 *   CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
Alex Deucher's avatar
Alex Deucher committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 */

#include "main/glheader.h"
#include "main/mtypes.h"
#include "main/colormac.h"
#include "main/imports.h"
#include "main/macros.h"

#include "swrast_setup/swrast_setup.h"
#include "tnl/tnl.h"
#include "tnl/t_context.h"

#include "r600_context.h"
#include "r600_emit.h"

Alex Deucher's avatar
Alex Deucher committed
48
void r600EmitCacheFlush(context_t *rmesa)
Alex Deucher's avatar
Alex Deucher committed
49
50
{
}
Richard Li's avatar
Richard Li committed
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
GLboolean r600AllocShaderConsts(GLcontext * ctx,
                                void ** constbo,			 
                                int sizeinBYTE,
                                char * szShaderUsage)
{
	radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
	struct radeon_bo * pbo;

    if(sizeinBYTE < 64) /* SQ_ALU_CONST_BUFFER_SIZE need 64 bytes at least to be non 0 */
    {
        sizeinBYTE = 64;
    }    

shader_again_alloc:
	pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
			0,
			sizeinBYTE,
			256,
			RADEON_GEM_DOMAIN_GTT,
			0);

	radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinBYTE, szShaderUsage);

	if (!pbo) {
		radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
		rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
		goto shader_again_alloc;
	}

	radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
			pbo,
			RADEON_GEM_DOMAIN_GTT, 0);

	if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
				pbo,
				RADEON_GEM_DOMAIN_GTT, 0)) {
		radeon_error("failure to revalidate BOs - badness\n");
		return GL_FALSE;
	}

	*constbo = (void*)pbo;

	return GL_TRUE;
}
GLboolean r600EmitShaderConsts(GLcontext * ctx,
                               void * constbo,
                               int    bo_offset,
                               GLvoid * data,
                               int sizeinBYTE)
{	
	struct radeon_bo * pbo = (struct radeon_bo *)constbo;
	uint8_t *out;

	radeon_bo_map(pbo, 1);

	out = (uint8_t*)(pbo->ptr);
    out = (uint8_t*)ADD_POINTERS(pbo->ptr, bo_offset);

	memcpy(out, data, sizeinBYTE);

	radeon_bo_unmap(pbo);

	return GL_TRUE;
}

117
GLboolean r600EmitShader(GLcontext * ctx,
Richard Li's avatar
Richard Li committed
118
                         void ** shaderbo,
119
			 GLvoid * data,
Richard Li's avatar
Richard Li committed
120
                         int sizeinDWORD,
121
                         char * szShaderUsage)
Richard Li's avatar
Richard Li committed
122
{
123
124
125
	radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
	struct radeon_bo * pbo;
	uint32_t *out;
126
shader_again_alloc:
127
	pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
128
129
130
131
132
133
134
			0,
			sizeinDWORD * 4,
			256,
			RADEON_GEM_DOMAIN_GTT,
			0);

	radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s %p size %d: %s\n", __func__, pbo, sizeinDWORD, szShaderUsage);
Richard Li's avatar
Richard Li committed
135

136
	if (!pbo) {
137
		radeon_print(RADEON_MEMORY | RADEON_CS, RADEON_IMPORTANT, "No memory for buffer object. Flushing command buffer.\n");
Richard Li's avatar
Richard Li committed
138
139
140
141
		rcommonFlushCmdBuf(radeonctx, __FUNCTION__);
		goto shader_again_alloc;
	}

142
	radeon_cs_space_add_persistent_bo(radeonctx->cmdbuf.cs,
143
144
			pbo,
			RADEON_GEM_DOMAIN_GTT, 0);
145

146
147
148
149
	if (radeon_cs_space_check_with_bo(radeonctx->cmdbuf.cs,
				pbo,
				RADEON_GEM_DOMAIN_GTT, 0)) {
		radeon_error("failure to revalidate BOs - badness\n");
150
151
		return GL_FALSE;
	}
Richard Li's avatar
Richard Li committed
152
153
154

	radeon_bo_map(pbo, 1);

155
	out = (uint32_t*)(pbo->ptr);
Richard Li's avatar
Richard Li committed
156

157
	memcpy(out, data, sizeinDWORD * 4);
Richard Li's avatar
Richard Li committed
158

159
	radeon_bo_unmap(pbo);
Richard Li's avatar
Richard Li committed
160

161
	*shaderbo = (void*)pbo;
Richard Li's avatar
Richard Li committed
162

163
	return GL_TRUE;
Richard Li's avatar
Richard Li committed
164
165
}

166
167
GLboolean r600DeleteShader(GLcontext * ctx,
                           void * shaderbo)
Richard Li's avatar
Richard Li committed
168
169
170
{
    struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;

171
172
    radeon_print(RADEON_SHADER, RADEON_NORMAL, "%s: %p\n", __func__, pbo);

173
    if (pbo) {
174
175
	    if (pbo->ptr)
		radeon_bo_unmap(pbo);
176
177
	    radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
    }
Richard Li's avatar
Richard Li committed
178
179
180

    return GL_TRUE;
}