1 | /* $Id: packspu_glsl.c 49264 2013-10-23 17:10:57Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox OpenGL GLSL related functions
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009-2012 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 | void PACKSPU_APIENTRY packspu_GetUniformsLocations(GLuint program, GLsizei maxcbData, GLsizei * cbData, GLvoid * pData)
|
---|
118 | {
|
---|
119 | (void) program;
|
---|
120 | (void) maxcbData;
|
---|
121 | (void) cbData;
|
---|
122 | (void) pData;
|
---|
123 | crWarning("packspu_GetUniformsLocations shouldn't be called directly");
|
---|
124 | }
|
---|
125 |
|
---|
126 | void PACKSPU_APIENTRY packspu_DeleteProgram(GLuint program)
|
---|
127 | {
|
---|
128 | crStateDeleteProgram(program);
|
---|
129 | crPackDeleteProgram(program);
|
---|
130 | }
|
---|
131 |
|
---|
132 | void PACK_APIENTRY packspu_DeleteObjectARB(GLhandleARB obj)
|
---|
133 | {
|
---|
134 | GLuint hwid = crStateGetProgramHWID(obj);
|
---|
135 |
|
---|
136 | CRASSERT(obj);
|
---|
137 |
|
---|
138 | /* we do not track shader creation inside guest since it is not needed currently.
|
---|
139 | * this is why we only care about programs here */
|
---|
140 | if (hwid)
|
---|
141 | {
|
---|
142 | crStateDeleteProgram(obj);
|
---|
143 | }
|
---|
144 |
|
---|
145 | crPackDeleteObjectARB(obj);
|
---|
146 | }
|
---|
147 |
|
---|
148 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
149 | static void packspu_RecCheckInitRec()
|
---|
150 | {
|
---|
151 | if (pack_spu.Recorder.pDumper)
|
---|
152 | return;
|
---|
153 |
|
---|
154 | crDmpDbgPrintInit(&pack_spu.Dumper);
|
---|
155 |
|
---|
156 | crRecInit(&pack_spu.Recorder, NULL /*pBlitter: we do not support blitter operations here*/, &pack_spu.self, &pack_spu.Dumper.Base);
|
---|
157 | }
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | void PACKSPU_APIENTRY packspu_LinkProgram(GLuint program)
|
---|
161 | {
|
---|
162 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
163 | GLint linkStatus = 0;
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | crStateLinkProgram(program);
|
---|
167 | crPackLinkProgram(program);
|
---|
168 |
|
---|
169 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
170 | pack_spu.self.GetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &linkStatus);
|
---|
171 | Assert(linkStatus);
|
---|
172 | if (!linkStatus)
|
---|
173 | {
|
---|
174 | CRContext *ctx = crStateGetCurrent();
|
---|
175 | packspu_RecCheckInitRec();
|
---|
176 | crRecDumpProgram(&pack_spu.Recorder, ctx, program, program);
|
---|
177 | }
|
---|
178 | #endif
|
---|
179 | }
|
---|
180 |
|
---|
181 | void PACKSPU_APIENTRY packspu_CompileShader(GLuint shader)
|
---|
182 | {
|
---|
183 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
184 | GLint compileStatus = 0;
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | // crStateCompileShader(shader);
|
---|
188 | crPackCompileShader(shader);
|
---|
189 |
|
---|
190 | #ifdef VBOX_WITH_CRPACKSPU_DUMPER
|
---|
191 | pack_spu.self.GetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &compileStatus);
|
---|
192 | Assert(compileStatus);
|
---|
193 | if (!compileStatus)
|
---|
194 | {
|
---|
195 | CRContext *ctx = crStateGetCurrent();
|
---|
196 | packspu_RecCheckInitRec();
|
---|
197 | crRecDumpShader(&pack_spu.Recorder, ctx, shader, shader);
|
---|
198 | }
|
---|
199 | #endif
|
---|
200 | }
|
---|
201 |
|
---|