Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / drivers / dri / r600 / r700_oglprog.c
1 /*
2 * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
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.
20 */
21
22 /*
23 * Authors:
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
25 */
26
27 #include <string.h>
28
29 #include "main/glheader.h"
30 #include "main/imports.h"
31
32 #include "shader/program.h"
33 #include "tnl/tnl.h"
34
35 #include "r600_context.h"
36
37 #include "r700_oglprog.h"
38 #include "r700_fragprog.h"
39 #include "r700_vertprog.h"
40
41
42 static struct gl_program *r700NewProgram(GLcontext * ctx,
43 GLenum target,
44 GLuint id)
45 {
46 struct gl_program *pProgram = NULL;
47
48 struct r700_vertex_program *vp;
49 struct r700_fragment_program *fp;
50
51 switch (target)
52 {
53 case GL_VERTEX_STATE_PROGRAM_NV:
54 case GL_VERTEX_PROGRAM_ARB:
55 vp = CALLOC_STRUCT(r700_vertex_program);
56 pProgram = _mesa_init_vertex_program(ctx,
57 &vp->mesa_program,
58 target,
59 id);
60 vp->translated = GL_FALSE;
61 vp->loaded = GL_FALSE;
62
63 vp->shaderbo = NULL;
64
65 break;
66 case GL_FRAGMENT_PROGRAM_NV:
67 case GL_FRAGMENT_PROGRAM_ARB:
68 fp = CALLOC_STRUCT(r700_fragment_program);
69 pProgram = _mesa_init_fragment_program(ctx,
70 &fp->mesa_program,
71 target,
72 id);
73 fp->translated = GL_FALSE;
74 fp->loaded = GL_FALSE;
75
76 fp->shaderbo = NULL;
77
78 break;
79 default:
80 _mesa_problem(ctx, "Bad target in r700NewProgram");
81 }
82
83 return pProgram;
84 }
85
86 static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
87 {
88 struct r700_vertex_program * vp;
89 struct r700_fragment_program * fp;
90 context_t *context = R700_CONTEXT(ctx);
91
92 switch (prog->Target)
93 {
94 case GL_VERTEX_STATE_PROGRAM_NV:
95 case GL_VERTEX_PROGRAM_ARB:
96 vp = (struct r700_vertex_program*)prog;
97 /* Release DMA region */
98
99 r600DeleteShader(ctx, vp->shaderbo);
100
101 /* Clean up */
102 Clean_Up_Assembler(&(vp->r700AsmCode));
103 Clean_Up_Shader(&(vp->r700Shader));
104 break;
105 case GL_FRAGMENT_PROGRAM_NV:
106 case GL_FRAGMENT_PROGRAM_ARB:
107 fp = (struct r700_fragment_program*)prog;
108 /* Release DMA region */
109
110 r600DeleteShader(ctx, fp->shaderbo);
111
112 /* Clean up */
113 Clean_Up_Assembler(&(fp->r700AsmCode));
114 Clean_Up_Shader(&(fp->r700Shader));
115 break;
116 default:
117 _mesa_problem(ctx, "Bad target in r700NewProgram");
118 }
119
120 _mesa_delete_program(ctx, prog);
121 }
122
123 static void
124 r700ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
125 {
126
127 }
128
129 static GLboolean r700IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
130 {
131
132 return GL_TRUE;
133 }
134
135 void r700InitShaderFuncs(struct dd_function_table *functions)
136 {
137 functions->NewProgram = r700NewProgram;
138 functions->DeleteProgram = r700DeleteProgram;
139 functions->ProgramStringNotify = r700ProgramStringNotify;
140 functions->IsProgramNative = r700IsProgramNative;
141 }