1 | /* $Id: packspu_glsl.c 63206 2016-08-09 14:13:22Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL GLSL related functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009-2016 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "packspu.h"
|
---|
20 | #include "cr_packfunctions.h"
|
---|
21 | #include "cr_net.h"
|
---|
22 | #include "packspu_proto.h"
|
---|
23 | #include "cr_mem.h"
|
---|
24 |
|
---|
25 |
|
---|
26 | GLuint PACKSPU_APIENTRY packspu_CreateProgram(void)
|
---|
27 | {
|
---|
28 | GET_THREAD(thread);
|
---|
29 | int writeback = 1;
|
---|
30 | GLuint return_val = (GLuint) 0;
|
---|
31 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
32 | {
|
---|
33 | crError("packspu_CreateProgram doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!");
|
---|
34 | }
|
---|
35 | if (pack_spu.swap)
|
---|
36 | {
|
---|
37 | crPackCreateProgramSWAP(&return_val, &writeback);
|
---|
38 | }
|
---|
39 | else
|
---|
40 | {
|
---|
41 | crPackCreateProgram(&return_val, &writeback);
|
---|
42 | }
|
---|
43 | packspuFlush((void *) thread);
|
---|
44 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
45 | if (pack_spu.swap)
|
---|
46 | {
|
---|
47 | return_val = (GLuint) SWAP32(return_val);
|
---|
48 | }
|
---|
49 |
|
---|
50 | crStateCreateProgram(return_val);
|
---|
51 |
|
---|
52 | return return_val;
|
---|
53 | }
|
---|
54 |
|
---|
55 | static GLint packspu_GetUniformLocationUncached(GLuint program, const char * name)
|
---|
56 | {
|
---|
57 | GET_THREAD(thread);
|
---|
58 | int writeback = 1;
|
---|
59 | GLint return_val = (GLint) 0;
|
---|
60 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
61 | {
|
---|
62 | crError("packspu_GetUniformLocation doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!");
|
---|
63 | }
|
---|
64 | if (pack_spu.swap)
|
---|
65 | {
|
---|
66 | crPackGetUniformLocationSWAP(program, name, &return_val, &writeback);
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | crPackGetUniformLocation(program, name, &return_val, &writeback);
|
---|
71 | }
|
---|
72 | packspuFlush((void *) thread);
|
---|
73 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
74 | if (pack_spu.swap)
|
---|
75 | {
|
---|
76 | return_val = (GLint) SWAP32(return_val);
|
---|
77 | }
|
---|
78 | return return_val;
|
---|
79 | }
|
---|
80 |
|
---|
81 | GLint PACKSPU_APIENTRY packspu_GetUniformLocation(GLuint program, const char * name)
|
---|
82 | {
|
---|
83 | if (!crStateIsProgramUniformsCached(program))
|
---|
84 | {
|
---|
85 | GET_THREAD(thread);
|
---|
86 | int writeback = 1;
|
---|
87 | GLsizei maxcbData;
|
---|
88 | GLsizei *pData;
|
---|
89 | GLint mu;
|
---|
90 |
|
---|
91 | packspu_GetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &mu);
|
---|
92 | maxcbData = 16*mu*sizeof(char);
|
---|
93 |
|
---|
94 | pData = (GLsizei *) crAlloc(maxcbData+sizeof(GLsizei));
|
---|
95 | if (!pData)
|
---|
96 | {
|
---|
97 | crWarning("packspu_GetUniformLocation: not enough memory, fallback to single query");
|
---|
98 | return packspu_GetUniformLocationUncached(program, name);
|
---|
99 | }
|
---|
100 |
|
---|
101 | crPackGetUniformsLocations(program, maxcbData, pData, NULL, &writeback);
|
---|
102 |
|
---|
103 | packspuFlush((void *) thread);
|
---|
104 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
105 |
|
---|
106 | crStateGLSLProgramCacheUniforms(program, pData[0], &pData[1]);
|
---|
107 |
|
---|
108 | CRASSERT(crStateIsProgramUniformsCached(program));
|
---|
109 |
|
---|
110 | crFree(pData);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*crDebug("packspu_GetUniformLocation(%d, %s)=%i", program, name, crStateGetUniformLocation(program, name));*/
|
---|
114 | return crStateGetUniformLocation(program, name);
|
---|
115 | }
|
---|
116 |
|
---|
117 | static GLint PACKSPU_APIENTRY packspu_GetAttribLocationUnchached( GLuint program, const char * name )
|
---|
118 | {
|
---|
119 | GET_THREAD(thread);
|
---|
120 | int writeback = 1;
|
---|
121 | GLint return_val = (GLint) 0;
|
---|
122 | if (!CRPACKSPU_IS_WDDM_CRHGSMI() && !(pack_spu.thread[pack_spu.idxThreadInUse].netServer.conn->actual_network))
|
---|
123 | {
|
---|
124 | crError( "packspu_GetAttribLocation doesn't work when there's no actual network involved!\nTry using the simplequery SPU in your chain!" );
|
---|
125 | }
|
---|
126 | if (pack_spu.swap)
|
---|
127 | {
|
---|
128 | crPackGetAttribLocationSWAP( program, name, &return_val, &writeback );
|
---|
129 | }
|
---|
130 | else
|
---|
131 | {
|
---|
132 | crPackGetAttribLocation( program, name, &return_val, &writeback );
|
---|
133 | }
|
---|
134 | packspuFlush( (void *) thread );
|
---|
135 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
136 | if (pack_spu.swap)
|
---|
137 | {
|
---|
138 | return_val = (GLint) SWAP32(return_val);
|
---|
139 | }
|
---|
140 | return return_val;
|
---|
141 | }
|
---|
142 |
|
---|
143 | GLint PACKSPU_APIENTRY packspu_GetAttribLocation(GLuint program, const char * name)
|
---|
144 | {
|
---|
145 | if (!(CR_VBOX_CAP_GETATTRIBSLOCATIONS & g_u32VBoxHostCaps))
|
---|
146 | return packspu_GetAttribLocationUnchached(program, name);
|
---|
147 |
|
---|
148 | if (!crStateIsProgramAttribsCached(program))
|
---|
149 | {
|
---|
150 | GET_THREAD(thread);
|
---|
151 | int writeback = 1;
|
---|
152 | GLsizei maxcbData;
|
---|
153 | GLsizei *pData;
|
---|
154 | GLint mu;
|
---|
155 |
|
---|
156 | packspu_GetIntegerv(GL_MAX_VERTEX_ATTRIBS, &mu);
|
---|
157 | maxcbData = 4*32*mu*sizeof(char);
|
---|
158 |
|
---|
159 | pData = (GLsizei *) crAlloc(maxcbData+sizeof(GLsizei));
|
---|
160 | if (!pData)
|
---|
161 | {
|
---|
162 | crWarning("packspu_GetAttribLocation: not enough memory, fallback to single query");
|
---|
163 | return packspu_GetAttribLocationUnchached(program, name);
|
---|
164 | }
|
---|
165 |
|
---|
166 | crPackGetAttribsLocations(program, maxcbData, pData, NULL, &writeback);
|
---|
167 |
|
---|
168 | packspuFlush((void *) thread);
|
---|
169 | CRPACKSPU_WRITEBACK_WAIT(thread, writeback);
|
---|
170 |
|
---|
171 | crStateGLSLProgramCacheAttribs(program, pData[0], &pData[1]);
|
---|
172 |
|
---|
173 | CRASSERT(crStateIsProgramAttribsCached(program));
|
---|
174 |
|
---|
175 | crFree(pData);
|
---|
176 | }
|
---|
177 |
|
---|
178 | /*crDebug("packspu_GetAttribLocation(%d, %s)=%i", program, name, crStateGetAttribLocation(program, name));*/
|
---|
179 | return crStateGetAttribLocation(program, name);
|
---|
180 | }
|
---|
181 |
|
---|
182 | void PACKSPU_APIENTRY packspu_GetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
|
---|
183 | {
|
---|
184 | (void) program;
|
---|
185 | (void) maxcbData;
|
---|
186 | (void) cbData;
|
---|
187 | (void) pData;
|
---|
188 | WARN(("packspu_GetUniformsLocations shouldn't be called directly"));
|
---|
189 | }
|
---|
190 |
|
---|
191 | void PACKSPU_APIENTRY packspu_GetAttribsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
|
---|
192 | {
|
---|
193 | (void) program;
|
---|
194 | (void) maxcbData;
|
---|
195 | (void) cbData;
|
---|
196 | (void) pData;
|
---|
197 | WARN(("packspu_GetAttribsLocations shouldn't be called directly"));
|
---|
198 | }
|
---|
199 |
|
---|
200 | void PACKSPU_APIENTRY packspu_DeleteProgram(GLuint program)
|
---|
201 | {
|
---|
202 | crStateDeleteProgram(program);
|
---|
203 | crPackDeleteProgram(program);
|
---|
204 | }
|
---|
205 |
|
---|
206 | void PACK_APIENTRY packspu_DeleteObjectARB(VBoxGLhandleARB obj)
|
---|
207 | {
|
---|
208 | GLuint hwid = crStateGetProgramHWID(obj);
|
---|
209 |
|
---|
210 | CRASSERT(obj);
|
---|
211 |
|
---|
212 | /* we do not track shader creation inside guest since it is not needed currently.
|
---|
213 | * this is why we only care about programs here */
|
---|
214 | if (hwid)
|
---|
215 | {
|
---|
216 | crStateDeleteProgram(obj);
|
---|
217 | }
|
---|
218 |
|
---|
219 | crPackDeleteObjectARB(obj);
|
---|
220 | }
|
---|
221 |
|
---|
222 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
223 | static void packspu_RecCheckInitRec()
|
---|
224 | {
|
---|
225 | if (pack_spu.Recorder.pDumper)
|
---|
226 | return;
|
---|
227 |
|
---|
228 | crDmpDbgPrintInit(&pack_spu.Dumper);
|
---|
229 |
|
---|
230 | crRecInit(&pack_spu.Recorder, NULL /*pBlitter: we do not support blitter operations here*/, &pack_spu.self, &pack_spu.Dumper.Base);
|
---|
231 | }
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | void PACKSPU_APIENTRY packspu_LinkProgram(GLuint program)
|
---|
235 | {
|
---|
236 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
237 | GLint linkStatus = 0;
|
---|
238 | #endif
|
---|
239 |
|
---|
240 | crStateLinkProgram(program);
|
---|
241 | crPackLinkProgram(program);
|
---|
242 |
|
---|
243 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
244 | pack_spu.self.GetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &linkStatus);
|
---|
245 | Assert(linkStatus);
|
---|
246 | if (!linkStatus)
|
---|
247 | {
|
---|
248 | CRContext *ctx = crStateGetCurrent();
|
---|
249 | packspu_RecCheckInitRec();
|
---|
250 | crRecDumpProgram(&pack_spu.Recorder, ctx, program, program);
|
---|
251 | }
|
---|
252 | #endif
|
---|
253 | }
|
---|
254 |
|
---|
255 | void PACKSPU_APIENTRY packspu_CompileShader(GLuint shader)
|
---|
256 | {
|
---|
257 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
258 | GLint compileStatus = 0;
|
---|
259 | #endif
|
---|
260 |
|
---|
261 | // crStateCompileShader(shader);
|
---|
262 | crPackCompileShader(shader);
|
---|
263 |
|
---|
264 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
265 | pack_spu.self.GetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &compileStatus);
|
---|
266 | Assert(compileStatus);
|
---|
267 | if (!compileStatus)
|
---|
268 | {
|
---|
269 | CRContext *ctx = crStateGetCurrent();
|
---|
270 | packspu_RecCheckInitRec();
|
---|
271 | crRecDumpShader(&pack_spu.Recorder, ctx, shader, shader);
|
---|
272 | }
|
---|
273 | #endif
|
---|
274 | }
|
---|
275 |
|
---|