2
* Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included
12
* in all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
* Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
29
#include "main/glheader.h"
30
#include "main/imports.h"
31
#include "program/program.h"
35
#include "r600_context.h"
36
#include "r600_emit.h"
38
#include "evergreen_oglprog.h"
39
#include "evergreen_fragprog.h"
40
#include "evergreen_vertprog.h"
43
static void evergreen_freeVertProgCache(GLcontext *ctx, struct r700_vertex_program_cont *cache)
45
struct evergreen_vertex_program *tmp, *vp = cache->progs;
49
/* Release DMA region */
50
r600DeleteShader(ctx, vp->shaderbo);
52
if(NULL != vp->constbo0)
54
r600DeleteShader(ctx, vp->constbo0);
58
Clean_Up_Assembler(&(vp->r700AsmCode));
59
Clean_Up_Shader(&(vp->r700Shader));
61
_mesa_reference_vertprog(ctx, &vp->mesa_program, NULL);
67
static struct gl_program *evergreenNewProgram(GLcontext * ctx,
71
struct gl_program *pProgram = NULL;
73
struct evergreen_vertex_program_cont *vpc;
74
struct evergreen_fragment_program *fp;
76
radeon_print(RADEON_SHADER, RADEON_VERBOSE,
77
"%s %u, %u\n", __func__, target, id);
81
case GL_VERTEX_STATE_PROGRAM_NV:
82
case GL_VERTEX_PROGRAM_ARB:
83
vpc = CALLOC_STRUCT(evergreen_vertex_program_cont);
84
pProgram = _mesa_init_vertex_program(ctx,
90
case GL_FRAGMENT_PROGRAM_NV:
91
case GL_FRAGMENT_PROGRAM_ARB:
92
fp = CALLOC_STRUCT(evergreen_fragment_program);
93
pProgram = _mesa_init_fragment_program(ctx,
97
fp->translated = GL_FALSE;
98
fp->loaded = GL_FALSE;
106
_mesa_problem(ctx, "Bad target in evergreenNewProgram");
112
static void evergreenDeleteProgram(GLcontext * ctx, struct gl_program *prog)
114
struct evergreen_vertex_program_cont *vpc = (struct evergreen_vertex_program_cont *)prog;
115
struct evergreen_fragment_program * fp;
117
radeon_print(RADEON_SHADER, RADEON_VERBOSE,
118
"%s %p\n", __func__, prog);
120
switch (prog->Target)
122
case GL_VERTEX_STATE_PROGRAM_NV:
123
case GL_VERTEX_PROGRAM_ARB:
124
evergreen_freeVertProgCache(ctx, vpc);
126
case GL_FRAGMENT_PROGRAM_NV:
127
case GL_FRAGMENT_PROGRAM_ARB:
128
fp = (struct evergreen_fragment_program*)prog;
129
/* Release DMA region */
131
r600DeleteShader(ctx, fp->shaderbo);
133
if(NULL != fp->constbo0)
135
r600DeleteShader(ctx, fp->constbo0);
139
Clean_Up_Assembler(&(fp->r700AsmCode));
140
Clean_Up_Shader(&(fp->r700Shader));
143
_mesa_problem(ctx, "Bad target in evergreenNewProgram");
146
_mesa_delete_program(ctx, prog);
150
evergreenProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
152
struct evergreen_vertex_program_cont *vpc = (struct evergreen_vertex_program_cont *)prog;
153
struct evergreen_fragment_program * fp = (struct evergreen_fragment_program*)prog;
156
case GL_VERTEX_PROGRAM_ARB:
157
evergreen_freeVertProgCache(ctx, vpc);
160
case GL_FRAGMENT_PROGRAM_ARB:
161
r600DeleteShader(ctx, fp->shaderbo);
163
if(NULL != fp->constbo0)
165
r600DeleteShader(ctx, fp->constbo0);
169
Clean_Up_Assembler(&(fp->r700AsmCode));
170
Clean_Up_Shader(&(fp->r700Shader));
171
fp->translated = GL_FALSE;
172
fp->loaded = GL_FALSE;
177
/* XXX check if program is legal, within limits */
181
static GLboolean evergreenIsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
187
void evergreenInitShaderFuncs(struct dd_function_table *functions)
189
functions->NewProgram = evergreenNewProgram;
190
functions->DeleteProgram = evergreenDeleteProgram;
191
functions->ProgramStringNotify = evergreenProgramStringNotify;
192
functions->IsProgramNative = evergreenIsProgramNative;