-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprogram.hpp
More file actions
562 lines (508 loc) · 17.1 KB
/
program.hpp
File metadata and controls
562 lines (508 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#pragma once
#include "../shared.hpp"
#include "../base.hpp"
namespace commandbuffers
{
enum LinkProgramCommandBufferResponseSegmentType
{
SEGMENT_ACTIVE_ATTRIB,
SEGMENT_ACTIVE_UNIFORM,
SEGMENT_ATTRIB_LOCATION,
SEGMENT_UNIFORM_LOCATION,
SEGMENT_UNIFORM_BLOCK
};
class ActiveInfo
{
public:
ActiveInfo() = default;
ActiveInfo(const ActiveInfo &that) = default;
ActiveInfo(string name, int size, int type)
: name(name)
, size(size)
, type(type)
{
}
public:
string name;
int size = 0;
int type = 0;
};
class Location
{
public:
Location(string name, int location)
: name(name)
, location(location)
{
}
public:
string name;
int location;
};
using AttribLocation = Location;
using UniformLocation = Location;
class UniformBlock
{
public:
UniformBlock(string name, int index)
: name(name)
, index(index)
{
}
public:
string name;
int index;
};
class CreateProgramCommandBufferRequest final
: public TrCommandBufferSimpleRequest<CreateProgramCommandBufferRequest,
COMMAND_BUFFER_CREATE_PROGRAM_REQ>
{
public:
CreateProgramCommandBufferRequest() = delete;
CreateProgramCommandBufferRequest(int clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
CreateProgramCommandBufferRequest(const CreateProgramCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that)
, clientId(that.clientId)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << clientId << ")";
return ss.str();
}
/**
* Serialize the command buffer to a JSON object with program creation information.
* Program creation is critical for shader pipeline setup and GPU state management.
*
* @param allocator The JSON allocator to use for creating the JSON object
* @returns A JSON object containing base command info plus program creation parameters
*/
rapidjson::Value toJson(rapidjson::Document::AllocatorType &allocator) const override
{
// Get base command information with new structure
rapidjson::Value cmdInfo = TrCommandBufferBase::toJson(allocator);
// Add program creation parameters to the parameters array in OpenGL function order
rapidjson::Value ¶meters = cmdInfo["parameters"];
parameters.PushBack(rapidjson::Value().SetUint(clientId), allocator);
return cmdInfo;
}
public:
uint32_t clientId;
};
class DeleteProgramCommandBufferRequest final
: public TrCommandBufferSimpleRequest<DeleteProgramCommandBufferRequest,
COMMAND_BUFFER_DELETE_PROGRAM_REQ>
{
public:
DeleteProgramCommandBufferRequest() = delete;
DeleteProgramCommandBufferRequest(uint32_t clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
DeleteProgramCommandBufferRequest(const DeleteProgramCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that)
, clientId(that.clientId)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << clientId << ")";
return ss.str();
}
public:
uint32_t clientId;
};
class LinkProgramCommandBufferRequest final
: public TrCommandBufferSimpleRequest<LinkProgramCommandBufferRequest,
COMMAND_BUFFER_LINK_PROGRAM_REQ>
{
public:
LinkProgramCommandBufferRequest() = delete;
LinkProgramCommandBufferRequest(uint32_t clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
LinkProgramCommandBufferRequest(const LinkProgramCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that)
, clientId(that.clientId)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << clientId << ")";
return ss.str();
}
TrCommandBufferMessage *serialize() override
{
auto message = new TrCommandBufferMessage(type, size, this);
for (auto &attribLocation : attribLocations)
addLocationSegment(SEGMENT_ATTRIB_LOCATION, attribLocation, message);
for (auto &uniformLocation : uniformLocations)
addLocationSegment(SEGMENT_UNIFORM_LOCATION, uniformLocation, message);
for (auto &uniformBlock : uniformBlocks)
addUniformBlockSegment(uniformBlock, message);
return message;
}
void deserialize(TrCommandBufferMessage &message) override
{
for (size_t i = 0; i < message.getSegmentCount(); i++)
{
auto segment = message.getSegment(i);
if (segment == nullptr)
continue;
auto segmentChars = segment->toVec<char>();
char *pSourceData = segmentChars.data();
LinkProgramCommandBufferResponseSegmentType segmentType;
memcpy(&segmentType, pSourceData, sizeof(LinkProgramCommandBufferResponseSegmentType));
pSourceData += sizeof(LinkProgramCommandBufferResponseSegmentType);
size_t nameSize;
memcpy(&nameSize, pSourceData, sizeof(size_t));
pSourceData += sizeof(size_t);
string name(pSourceData, nameSize);
pSourceData += nameSize;
switch (segmentType)
{
case SEGMENT_ATTRIB_LOCATION:
{
int location;
memcpy(&location, pSourceData, sizeof(int));
pSourceData += sizeof(int);
attribLocations.push_back(AttribLocation(name, location));
break;
};
case SEGMENT_UNIFORM_LOCATION:
{
int location;
memcpy(&location, pSourceData, sizeof(int));
pSourceData += sizeof(int);
uniformLocations.push_back(UniformLocation(name, location));
break;
};
case SEGMENT_UNIFORM_BLOCK:
{
int index;
memcpy(&index, pSourceData, sizeof(int));
pSourceData += sizeof(int);
uniformBlocks.push_back(UniformBlock(name, index));
break;
};
default:
break;
}
}
}
private:
vector<char> getSegmentBase(LinkProgramCommandBufferResponseSegmentType type,
string &name)
{
vector<char> base;
base.insert(base.end(),
reinterpret_cast<char *>(&type),
reinterpret_cast<char *>(&type) + sizeof(LinkProgramCommandBufferResponseSegmentType));
size_t nameSize = name.size();
base.insert(base.end(),
reinterpret_cast<char *>(&nameSize),
reinterpret_cast<char *>(&nameSize) + sizeof(size_t));
base.insert(base.end(), name.begin(), name.end());
return base;
}
ActiveInfo getActiveInfoFromBuffer(string &name, char **pSrcData)
{
char *buf = *pSrcData;
int size;
{
memcpy(&size, buf, sizeof(int));
buf += sizeof(int);
}
int type;
{
memcpy(&type, buf, sizeof(int));
buf += sizeof(int);
}
return ActiveInfo(name, size, type);
}
void addActiveInfoSegment(ActiveInfo &activeInfo, LinkProgramCommandBufferResponseSegmentType segmentType, TrCommandBufferMessage *message)
{
auto base = getSegmentBase(segmentType, activeInfo.name);
base.insert(base.end(),
reinterpret_cast<char *>(&activeInfo.size),
reinterpret_cast<char *>(&activeInfo.size) + sizeof(activeInfo.size));
base.insert(base.end(),
reinterpret_cast<char *>(&activeInfo.type),
reinterpret_cast<char *>(&activeInfo.type) + sizeof(activeInfo.type));
message->addSegment(new ipc::TrIpcMessageSegment(base));
}
void addLocationSegment(LinkProgramCommandBufferResponseSegmentType type,
Location &loc,
TrCommandBufferMessage *message)
{
auto base = getSegmentBase(type, loc.name);
base.insert(base.end(),
reinterpret_cast<char *>(&loc.location),
reinterpret_cast<char *>(&loc.location) + sizeof(loc.location));
message->addSegment(new ipc::TrIpcMessageSegment(base));
}
void addUniformBlockSegment(UniformBlock &uniformBlock, TrCommandBufferMessage *message)
{
auto base = getSegmentBase(SEGMENT_UNIFORM_BLOCK, uniformBlock.name);
base.insert(base.end(),
reinterpret_cast<char *>(&uniformBlock.index),
reinterpret_cast<char *>(&uniformBlock.index) + sizeof(uniformBlock.index));
message->addSegment(new ipc::TrIpcMessageSegment(base));
}
public:
uint32_t clientId;
vector<AttribLocation> attribLocations;
vector<UniformLocation> uniformLocations;
vector<UniformBlock> uniformBlocks;
};
class ValidateProgramCommandBufferRequest final
: public TrCommandBufferSimpleRequest<ValidateProgramCommandBufferRequest,
COMMAND_BUFFER_VALIDATE_PROGRAM_REQ>
{
public:
ValidateProgramCommandBufferRequest() = delete;
ValidateProgramCommandBufferRequest(uint32_t clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
ValidateProgramCommandBufferRequest(const ValidateProgramCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that)
, clientId(that.clientId)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << clientId << ")";
return ss.str();
}
public:
uint32_t clientId;
};
class UseProgramCommandBufferRequest final
: public TrCommandBufferSimpleRequest<UseProgramCommandBufferRequest, COMMAND_BUFFER_USE_PROGRAM_REQ>
{
public:
UseProgramCommandBufferRequest() = delete;
UseProgramCommandBufferRequest(uint32_t clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
UseProgramCommandBufferRequest(const UseProgramCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that, clone)
, clientId(that.clientId)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << clientId << ")";
return ss.str();
}
public:
uint32_t clientId;
};
class BindAttribLocationCommandBufferRequest final
: public TrCommandBufferSimpleRequest<BindAttribLocationCommandBufferRequest,
COMMAND_BUFFER_BIND_ATTRIB_LOCATION_REQ>
{
public:
BindAttribLocationCommandBufferRequest() = delete;
BindAttribLocationCommandBufferRequest(uint32_t program, uint32_t index, const string &name)
: TrCommandBufferSimpleRequest()
, program(program)
, attribIndex(index)
, attribName(name)
{
}
BindAttribLocationCommandBufferRequest(const BindAttribLocationCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that, clone)
, program(that.program)
, attribIndex(that.attribIndex)
{
}
public:
TrCommandBufferMessage *serialize() override
{
auto message = new TrCommandBufferMessage(type, size, this);
message->addStringSegment(attribName);
return message;
}
void deserialize(TrCommandBufferMessage &message) override
{
attribName = message.getSegment(0)->toString();
}
public:
uint32_t program;
uint32_t attribIndex;
string attribName;
};
class GetProgramParamCommandBufferRequest final
: public TrCommandBufferSimpleRequest<GetProgramParamCommandBufferRequest,
COMMAND_BUFFER_GET_PROGRAM_PARAM_REQ>
{
public:
GetProgramParamCommandBufferRequest() = delete;
GetProgramParamCommandBufferRequest(uint32_t clientId, uint32_t pname)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
, pname(pname)
{
}
GetProgramParamCommandBufferRequest(const GetProgramParamCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that, clone)
, clientId(that.clientId)
, pname(that.pname)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "("
<< clientId << ", "
<< WebGLHelper::WebGLProgramParameterToString(pname) << ")";
return ss.str();
}
public:
uint32_t clientId;
uint32_t pname;
};
class GetProgramParamCommandBufferResponse final
: public TrCommandBufferSimpleResponse<GetProgramParamCommandBufferResponse>
{
public:
GetProgramParamCommandBufferResponse(GetProgramParamCommandBufferRequest *req, int value)
: TrCommandBufferSimpleResponse(COMMAND_BUFFER_GET_PROGRAM_PARAM_RES, req)
, value(value)
{
}
GetProgramParamCommandBufferResponse(const GetProgramParamCommandBufferResponse &that, bool clone = false)
: TrCommandBufferSimpleResponse(that, clone)
, value(that.value)
{
}
public:
int value;
};
class GetProgramInfoLogCommandBufferRequest final
: public TrCommandBufferSimpleRequest<GetProgramInfoLogCommandBufferRequest,
COMMAND_BUFFER_GET_PROGRAM_INFO_LOG_REQ>
{
public:
GetProgramInfoLogCommandBufferRequest() = delete;
GetProgramInfoLogCommandBufferRequest(uint32_t clientId)
: TrCommandBufferSimpleRequest()
, clientId(clientId)
{
}
GetProgramInfoLogCommandBufferRequest(const GetProgramInfoLogCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that, clone)
, clientId(that.clientId)
{
}
public:
uint32_t clientId;
};
class GetProgramInfoLogCommandBufferResponse final
: public TrCommandBufferSimpleResponse<GetProgramInfoLogCommandBufferResponse>
{
public:
GetProgramInfoLogCommandBufferResponse(GetProgramInfoLogCommandBufferRequest *req, const string infoLog)
: TrCommandBufferSimpleResponse(COMMAND_BUFFER_GET_PROGRAM_INFO_LOG_RES, req)
, infoLog(infoLog)
{
}
GetProgramInfoLogCommandBufferResponse(const GetProgramInfoLogCommandBufferResponse &that, bool clone = false)
: TrCommandBufferSimpleResponse(that, clone)
, infoLog()
{
if (clone)
infoLog = that.infoLog;
}
public:
TrCommandBufferMessage *serialize() override
{
auto message = new TrCommandBufferMessage(type, size, this);
message->addStringSegment(infoLog);
return message;
}
void deserialize(TrCommandBufferMessage &message) override
{
infoLog = message.getSegment(0)->toString();
}
public:
std::string infoLog;
};
class TransformFeedbackVaryingsCommandBufferRequest final
: public TrCommandBufferSimpleRequest<TransformFeedbackVaryingsCommandBufferRequest,
COMMAND_BUFFER_TRANSFORM_FEEDBACK_VARYINGS_REQ>
{
public:
TransformFeedbackVaryingsCommandBufferRequest() = delete;
TransformFeedbackVaryingsCommandBufferRequest(uint32_t program, const std::vector<std::string> &varyings, uint32_t bufferMode)
: TrCommandBufferSimpleRequest()
, program(program)
, varyings(varyings)
, bufferMode(bufferMode)
{
}
TransformFeedbackVaryingsCommandBufferRequest(const TransformFeedbackVaryingsCommandBufferRequest &that, bool clone = false)
: TrCommandBufferSimpleRequest(that, clone)
, program(that.program)
, varyings(that.varyings)
, bufferMode(that.bufferMode)
{
}
std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << TrCommandBufferSimpleRequest::toString(line_prefix) << "(" << program << ", [";
for (size_t i = 0; i < varyings.size(); i++)
{
if (i > 0)
ss << ", ";
ss << varyings[i];
}
ss << "], " << bufferMode << ")";
return ss.str();
}
TrCommandBufferMessage *serialize() override
{
auto message = new TrCommandBufferMessage(type, size, this);
// Serialize the varyings array
for (const auto &varying : varyings)
{
message->addStringSegment(const_cast<std::string &>(varying));
}
return message;
}
void deserialize(TrCommandBufferMessage &message) override
{
varyings.clear();
for (size_t i = 0; i < message.getSegmentCount(); i++)
{
auto segment = message.getSegment(i);
if (segment != nullptr)
{
varyings.push_back(segment->toString());
}
}
}
public:
uint32_t program;
std::vector<std::string> varyings;
uint32_t bufferMode;
};
}