Merge branch 'softpipe-opt'
[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 #include "r600_emit.h"
37
38 #include "r700_oglprog.h"
39 #include "r700_fragprog.h"
40 #include "r700_vertprog.h"
41
42
43 static struct gl_program *r700NewProgram(GLcontext * ctx,
44 GLenum target,
45 GLuint id)
46 {
47 struct gl_program *pProgram = NULL;
48
49 struct r700_vertex_program_cont *vpc;
50 struct r700_fragment_program *fp;
51
52 radeon_print(RADEON_SHADER, RADEON_VERBOSE,
53 "%s %u, %u\n", __func__, target, id);
54
55 switch (target)
56 {
57 case GL_VERTEX_STATE_PROGRAM_NV:
58 case GL_VERTEX_PROGRAM_ARB:
59 vpc = CALLOC_STRUCT(r700_vertex_program_cont);
60 pProgram = _mesa_init_vertex_program(ctx,
61 &vpc->mesa_program,
62 target,
63 id);
64 break;
65 case GL_FRAGMENT_PROGRAM_NV:
66 case GL_FRAGMENT_PROGRAM_ARB:
67 fp = CALLOC_STRUCT(r700_fragment_program);
68 pProgram = _mesa_init_fragment_program(ctx,
69 &fp->mesa_program,
70 target,
71 id);
72 fp->translated = GL_FALSE;
73 fp->loaded = GL_FALSE;
74
75 fp->shaderbo = NULL;
76
77 break;
78 default:
79 _mesa_problem(ctx, "Bad target in r700NewProgram");
80 }
81
82 return pProgram;
83 }
84
85 static void r700DeleteProgram(GLcontext * ctx, struct gl_program *prog)
86 {
87 struct r700_vertex_program_cont * vpc;
88 struct r700_vertex_program *vp, *tmp;
89 struct r700_fragment_program * fp;
90
91 radeon_print(RADEON_SHADER, RADEON_VERBOSE,
92 "%s %p\n", __func__, prog);
93
94 switch (prog->Target)
95 {
96 case GL_VERTEX_STATE_PROGRAM_NV:
97 case GL_VERTEX_PROGRAM_ARB:
98 vpc = (struct r700_vertex_program_cont*)prog;
99 vp = vpc->progs;
100 while (vp) {
101 tmp = vp->next;
102 /* Release DMA region */
103
104 r600DeleteShader(ctx, vp->shaderbo);
105
106 /* Clean up */
107 Clean_Up_Assembler(&(vp->r700AsmCode));
108 Clean_Up_Shader(&(vp->r700Shader));
109 _mesa_free(vp);
110 vp = tmp;
111 }
112 break;
113 case GL_FRAGMENT_PROGRAM_NV:
114 case GL_FRAGMENT_PROGRAM_ARB:
115 fp = (struct r700_fragment_program*)prog;
116 /* Release DMA region */
117
118 r600DeleteShader(ctx, fp->shaderbo);
119
120 /* Clean up */
121 Clean_Up_Assembler(&(fp->r700AsmCode));
122 Clean_Up_Shader(&(fp->r700Shader));
123 break;
124 default:
125 _mesa_problem(ctx, "Bad target in r700NewProgram");
126 }
127
128 _mesa_delete_program(ctx, prog);
129 }
130
131 static void
132 r700ProgramStringNotify(GLcontext * ctx, GLenum target, struct gl_program *prog)
133 {
134
135 }
136
137 static GLboolean r700IsProgramNative(GLcontext * ctx, GLenum target, struct gl_program *prog)
138 {
139
140 return GL_TRUE;
141 }
142
143 void r700InitShaderFuncs(struct dd_function_table *functions)
144 {
145 functions->NewProgram = r700NewProgram;
146 functions->DeleteProgram = r700DeleteProgram;
147 functions->ProgramStringNotify = r700ProgramStringNotify;
148 functions->IsProgramNative = r700IsProgramNative;
149 }