summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/r600/r600_emit.c
blob: 53ece9a3505ac6a84c66de664cd320a2f1fa915c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**************************************************************************

Copyright 2008, 2009 Advanced Micro Devices Inc. (AMD)

Copyright (C) Advanced Micro Devices Inc. (AMD)  2009.  All Rights Reserved.

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.

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

/*
 * Authors:
 *   Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
 *   CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
 */

#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"

void r600EmitCacheFlush(context_t *rmesa)
{
}

GLboolean r600AllocShaderConsts(struct gl_context * 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(struct gl_context * 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;
}

GLboolean r600EmitShader(struct gl_context * ctx,
                         void ** shaderbo,
			 GLvoid * data,
                         int sizeinDWORD,
                         char * szShaderUsage)
{
	radeonContextPtr radeonctx = RADEON_CONTEXT(ctx);
	struct radeon_bo * pbo;
	uint32_t *out;
shader_again_alloc:
	pbo = radeon_bo_open(radeonctx->radeonScreen->bom,
			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);

	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;
	}

	radeon_bo_map(pbo, 1);

	out = (uint32_t*)(pbo->ptr);

	memcpy(out, data, sizeinDWORD * 4);

	radeon_bo_unmap(pbo);

	*shaderbo = (void*)pbo;

	return GL_TRUE;
}

GLboolean r600DeleteShader(struct gl_context * ctx,
                           void * shaderbo)
{
    struct radeon_bo * pbo = (struct radeon_bo *)shaderbo;

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

    if (pbo) {
	    if (pbo->ptr)
		radeon_bo_unmap(pbo);
	    radeon_bo_unref(pbo); /* when bo->cref <= 0, bo will be bo_free */
    }

    return GL_TRUE;
}