blob: 2a7ead2aa4175c40f6c39cfe8a0d2d5c223067a7 [file] [log] [blame]
Brandon Jonesc9610c52014-08-25 17:02:59 -07001//
2// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// ProgramD3D.cpp: Defines the rx::ProgramD3D class which implements rx::ProgramImpl.
8
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/renderer/d3d/ProgramD3D.h"
Jamie Madill437d2662014-12-05 14:23:35 -050010
11#include "common/utilities.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Framebuffer.h"
13#include "libANGLE/FramebufferAttachment.h"
14#include "libANGLE/Program.h"
Jamie Madill437d2662014-12-05 14:23:35 -050015#include "libANGLE/features.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050016#include "libANGLE/renderer/ShaderExecutable.h"
17#include "libANGLE/renderer/d3d/DynamicHLSL.h"
18#include "libANGLE/renderer/d3d/RendererD3D.h"
19#include "libANGLE/renderer/d3d/ShaderD3D.h"
Jamie Madill437d2662014-12-05 14:23:35 -050020#include "libANGLE/renderer/d3d/VertexDataManager.h"
Geoff Lang22072132014-11-20 15:15:01 -050021
Brandon Jonesc9610c52014-08-25 17:02:59 -070022namespace rx
23{
24
Brandon Joneseb994362014-09-24 10:27:28 -070025namespace
26{
27
Brandon Jones1a8a7e32014-10-01 12:49:30 -070028GLenum GetTextureType(GLenum samplerType)
29{
30 switch (samplerType)
31 {
32 case GL_SAMPLER_2D:
33 case GL_INT_SAMPLER_2D:
34 case GL_UNSIGNED_INT_SAMPLER_2D:
35 case GL_SAMPLER_2D_SHADOW:
36 return GL_TEXTURE_2D;
37 case GL_SAMPLER_3D:
38 case GL_INT_SAMPLER_3D:
39 case GL_UNSIGNED_INT_SAMPLER_3D:
40 return GL_TEXTURE_3D;
41 case GL_SAMPLER_CUBE:
42 case GL_SAMPLER_CUBE_SHADOW:
43 return GL_TEXTURE_CUBE_MAP;
44 case GL_INT_SAMPLER_CUBE:
45 case GL_UNSIGNED_INT_SAMPLER_CUBE:
46 return GL_TEXTURE_CUBE_MAP;
47 case GL_SAMPLER_2D_ARRAY:
48 case GL_INT_SAMPLER_2D_ARRAY:
49 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
50 case GL_SAMPLER_2D_ARRAY_SHADOW:
51 return GL_TEXTURE_2D_ARRAY;
52 default: UNREACHABLE();
53 }
54
55 return GL_TEXTURE_2D;
56}
57
Brandon Joneseb994362014-09-24 10:27:28 -070058void GetDefaultInputLayoutFromShader(const std::vector<sh::Attribute> &shaderAttributes, gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS])
59{
60 size_t layoutIndex = 0;
61 for (size_t attributeIndex = 0; attributeIndex < shaderAttributes.size(); attributeIndex++)
62 {
63 ASSERT(layoutIndex < gl::MAX_VERTEX_ATTRIBS);
64
65 const sh::Attribute &shaderAttr = shaderAttributes[attributeIndex];
66
67 if (shaderAttr.type != GL_NONE)
68 {
69 GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
70
71 for (size_t rowIndex = 0; static_cast<int>(rowIndex) < gl::VariableRowCount(transposedType); rowIndex++, layoutIndex++)
72 {
73 gl::VertexFormat *defaultFormat = &inputLayout[layoutIndex];
74
75 defaultFormat->mType = gl::VariableComponentType(transposedType);
76 defaultFormat->mNormalized = false;
77 defaultFormat->mPureInteger = (defaultFormat->mType != GL_FLOAT); // note: inputs can not be bool
78 defaultFormat->mComponents = gl::VariableColumnCount(transposedType);
79 }
80 }
81 }
82}
83
84std::vector<GLenum> GetDefaultOutputLayoutFromShader(const std::vector<PixelShaderOutputVariable> &shaderOutputVars)
85{
86 std::vector<GLenum> defaultPixelOutput(1);
87
88 ASSERT(!shaderOutputVars.empty());
89 defaultPixelOutput[0] = GL_COLOR_ATTACHMENT0 + shaderOutputVars[0].outputIndex;
90
91 return defaultPixelOutput;
92}
93
Brandon Jones1a8a7e32014-10-01 12:49:30 -070094bool IsRowMajorLayout(const sh::InterfaceBlockField &var)
95{
96 return var.isRowMajorLayout;
97}
98
99bool IsRowMajorLayout(const sh::ShaderVariable &var)
100{
101 return false;
102}
103
Jamie Madill437d2662014-12-05 14:23:35 -0500104struct AttributeSorter
105{
106 AttributeSorter(const ProgramImpl::SemanticIndexArray &semanticIndices)
107 : originalIndices(semanticIndices)
108 {
109 }
110
111 bool operator()(int a, int b)
112 {
113 if (originalIndices[a] == -1) return false;
114 if (originalIndices[b] == -1) return true;
115 return (originalIndices[a] < originalIndices[b]);
116 }
117
118 const ProgramImpl::SemanticIndexArray &originalIndices;
119};
120
Brandon Joneseb994362014-09-24 10:27:28 -0700121}
122
123ProgramD3D::VertexExecutable::VertexExecutable(const gl::VertexFormat inputLayout[],
124 const GLenum signature[],
125 ShaderExecutable *shaderExecutable)
126 : mShaderExecutable(shaderExecutable)
127{
128 for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
129 {
130 mInputs[attributeIndex] = inputLayout[attributeIndex];
131 mSignature[attributeIndex] = signature[attributeIndex];
132 }
133}
134
135ProgramD3D::VertexExecutable::~VertexExecutable()
136{
137 SafeDelete(mShaderExecutable);
138}
139
140bool ProgramD3D::VertexExecutable::matchesSignature(const GLenum signature[]) const
141{
142 for (size_t attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
143 {
144 if (mSignature[attributeIndex] != signature[attributeIndex])
145 {
146 return false;
147 }
148 }
149
150 return true;
151}
152
153ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature, ShaderExecutable *shaderExecutable)
154 : mOutputSignature(outputSignature),
155 mShaderExecutable(shaderExecutable)
156{
157}
158
159ProgramD3D::PixelExecutable::~PixelExecutable()
160{
161 SafeDelete(mShaderExecutable);
162}
163
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700164ProgramD3D::Sampler::Sampler() : active(false), logicalTextureUnit(0), textureType(GL_TEXTURE_2D)
165{
166}
167
Geoff Lang7dd2e102014-11-10 15:19:26 -0500168unsigned int ProgramD3D::mCurrentSerial = 1;
169
Jamie Madill93e13fb2014-11-06 15:27:25 -0500170ProgramD3D::ProgramD3D(RendererD3D *renderer)
Brandon Jonesc9610c52014-08-25 17:02:59 -0700171 : ProgramImpl(),
172 mRenderer(renderer),
173 mDynamicHLSL(NULL),
Brandon Joneseb994362014-09-24 10:27:28 -0700174 mGeometryExecutable(NULL),
175 mVertexWorkarounds(ANGLE_D3D_WORKAROUND_NONE),
176 mPixelWorkarounds(ANGLE_D3D_WORKAROUND_NONE),
Brandon Jones44151a92014-09-10 11:32:25 -0700177 mUsesPointSize(false),
Brandon Jonesc9610c52014-08-25 17:02:59 -0700178 mVertexUniformStorage(NULL),
Brandon Jones44151a92014-09-10 11:32:25 -0700179 mFragmentUniformStorage(NULL),
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700180 mUsedVertexSamplerRange(0),
181 mUsedPixelSamplerRange(0),
182 mDirtySamplerMapping(true),
Geoff Lang7dd2e102014-11-10 15:19:26 -0500183 mShaderVersion(100),
184 mSerial(issueSerial())
Brandon Jonesc9610c52014-08-25 17:02:59 -0700185{
Brandon Joneseb994362014-09-24 10:27:28 -0700186 mDynamicHLSL = new DynamicHLSL(renderer);
Brandon Jonesc9610c52014-08-25 17:02:59 -0700187}
188
189ProgramD3D::~ProgramD3D()
190{
191 reset();
192 SafeDelete(mDynamicHLSL);
193}
194
195ProgramD3D *ProgramD3D::makeProgramD3D(ProgramImpl *impl)
196{
197 ASSERT(HAS_DYNAMIC_TYPE(ProgramD3D*, impl));
198 return static_cast<ProgramD3D*>(impl);
199}
200
201const ProgramD3D *ProgramD3D::makeProgramD3D(const ProgramImpl *impl)
202{
203 ASSERT(HAS_DYNAMIC_TYPE(const ProgramD3D*, impl));
204 return static_cast<const ProgramD3D*>(impl);
205}
206
Brandon Jones44151a92014-09-10 11:32:25 -0700207bool ProgramD3D::usesPointSpriteEmulation() const
208{
209 return mUsesPointSize && mRenderer->getMajorShaderModel() >= 4;
210}
211
212bool ProgramD3D::usesGeometryShader() const
213{
214 return usesPointSpriteEmulation();
215}
216
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700217GLint ProgramD3D::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const
218{
219 GLint logicalTextureUnit = -1;
220
221 switch (type)
222 {
223 case gl::SAMPLER_PIXEL:
224 ASSERT(samplerIndex < caps.maxTextureImageUnits);
225 if (samplerIndex < mSamplersPS.size() && mSamplersPS[samplerIndex].active)
226 {
227 logicalTextureUnit = mSamplersPS[samplerIndex].logicalTextureUnit;
228 }
229 break;
230 case gl::SAMPLER_VERTEX:
231 ASSERT(samplerIndex < caps.maxVertexTextureImageUnits);
232 if (samplerIndex < mSamplersVS.size() && mSamplersVS[samplerIndex].active)
233 {
234 logicalTextureUnit = mSamplersVS[samplerIndex].logicalTextureUnit;
235 }
236 break;
237 default: UNREACHABLE();
238 }
239
240 if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
241 {
242 return logicalTextureUnit;
243 }
244
245 return -1;
246}
247
248// Returns the texture type for a given Direct3D 9 sampler type and
249// index (0-15 for the pixel shader and 0-3 for the vertex shader).
250GLenum ProgramD3D::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
251{
252 switch (type)
253 {
254 case gl::SAMPLER_PIXEL:
255 ASSERT(samplerIndex < mSamplersPS.size());
256 ASSERT(mSamplersPS[samplerIndex].active);
257 return mSamplersPS[samplerIndex].textureType;
258 case gl::SAMPLER_VERTEX:
259 ASSERT(samplerIndex < mSamplersVS.size());
260 ASSERT(mSamplersVS[samplerIndex].active);
261 return mSamplersVS[samplerIndex].textureType;
262 default: UNREACHABLE();
263 }
264
265 return GL_TEXTURE_2D;
266}
267
268GLint ProgramD3D::getUsedSamplerRange(gl::SamplerType type) const
269{
270 switch (type)
271 {
272 case gl::SAMPLER_PIXEL:
273 return mUsedPixelSamplerRange;
274 case gl::SAMPLER_VERTEX:
275 return mUsedVertexSamplerRange;
276 default:
277 UNREACHABLE();
278 return 0;
279 }
280}
281
282void ProgramD3D::updateSamplerMapping()
283{
284 if (!mDirtySamplerMapping)
285 {
286 return;
287 }
288
289 mDirtySamplerMapping = false;
290
291 // Retrieve sampler uniform values
292 for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
293 {
294 gl::LinkedUniform *targetUniform = mUniforms[uniformIndex];
295
296 if (targetUniform->dirty)
297 {
Geoff Lang2ec386b2014-12-03 14:44:38 -0500298 if (gl::IsSamplerType(targetUniform->type))
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700299 {
300 int count = targetUniform->elementCount();
301 GLint (*v)[4] = reinterpret_cast<GLint(*)[4]>(targetUniform->data);
302
303 if (targetUniform->isReferencedByFragmentShader())
304 {
305 unsigned int firstIndex = targetUniform->psRegisterIndex;
306
307 for (int i = 0; i < count; i++)
308 {
309 unsigned int samplerIndex = firstIndex + i;
310
311 if (samplerIndex < mSamplersPS.size())
312 {
313 ASSERT(mSamplersPS[samplerIndex].active);
314 mSamplersPS[samplerIndex].logicalTextureUnit = v[i][0];
315 }
316 }
317 }
318
319 if (targetUniform->isReferencedByVertexShader())
320 {
321 unsigned int firstIndex = targetUniform->vsRegisterIndex;
322
323 for (int i = 0; i < count; i++)
324 {
325 unsigned int samplerIndex = firstIndex + i;
326
327 if (samplerIndex < mSamplersVS.size())
328 {
329 ASSERT(mSamplersVS[samplerIndex].active);
330 mSamplersVS[samplerIndex].logicalTextureUnit = v[i][0];
331 }
332 }
333 }
334 }
335 }
336 }
337}
338
339bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
340{
341 // if any two active samplers in a program are of different types, but refer to the same
342 // texture image unit, and this is the current program, then ValidateProgram will fail, and
343 // DrawArrays and DrawElements will issue the INVALID_OPERATION error.
344 updateSamplerMapping();
345
346 std::vector<GLenum> textureUnitTypes(caps.maxCombinedTextureImageUnits, GL_NONE);
347
348 for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i)
349 {
350 if (mSamplersPS[i].active)
351 {
352 unsigned int unit = mSamplersPS[i].logicalTextureUnit;
353
354 if (unit >= textureUnitTypes.size())
355 {
356 if (infoLog)
357 {
358 infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size());
359 }
360
361 return false;
362 }
363
364 if (textureUnitTypes[unit] != GL_NONE)
365 {
366 if (mSamplersPS[i].textureType != textureUnitTypes[unit])
367 {
368 if (infoLog)
369 {
370 infoLog->append("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
371 }
372
373 return false;
374 }
375 }
376 else
377 {
378 textureUnitTypes[unit] = mSamplersPS[i].textureType;
379 }
380 }
381 }
382
383 for (unsigned int i = 0; i < mUsedVertexSamplerRange; ++i)
384 {
385 if (mSamplersVS[i].active)
386 {
387 unsigned int unit = mSamplersVS[i].logicalTextureUnit;
388
389 if (unit >= textureUnitTypes.size())
390 {
391 if (infoLog)
392 {
393 infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size());
394 }
395
396 return false;
397 }
398
399 if (textureUnitTypes[unit] != GL_NONE)
400 {
401 if (mSamplersVS[i].textureType != textureUnitTypes[unit])
402 {
403 if (infoLog)
404 {
405 infoLog->append("Samplers of conflicting types refer to the same texture image unit (%d).", unit);
406 }
407
408 return false;
409 }
410 }
411 else
412 {
413 textureUnitTypes[unit] = mSamplersVS[i].textureType;
414 }
415 }
416 }
417
418 return true;
419}
420
Geoff Lang7dd2e102014-11-10 15:19:26 -0500421LinkResult ProgramD3D::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -0700422{
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500423 int compileFlags = stream->readInt<int>();
424 if (compileFlags != ANGLE_COMPILE_OPTIMIZATION_LEVEL)
425 {
426 infoLog.append("Mismatched compilation flags.");
427 return LinkResult(false, gl::Error(GL_NO_ERROR));
428 }
429
Brandon Jones44151a92014-09-10 11:32:25 -0700430 stream->readInt(&mShaderVersion);
431
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700432 const unsigned int psSamplerCount = stream->readInt<unsigned int>();
433 for (unsigned int i = 0; i < psSamplerCount; ++i)
434 {
435 Sampler sampler;
436 stream->readBool(&sampler.active);
437 stream->readInt(&sampler.logicalTextureUnit);
438 stream->readInt(&sampler.textureType);
439 mSamplersPS.push_back(sampler);
440 }
441 const unsigned int vsSamplerCount = stream->readInt<unsigned int>();
442 for (unsigned int i = 0; i < vsSamplerCount; ++i)
443 {
444 Sampler sampler;
445 stream->readBool(&sampler.active);
446 stream->readInt(&sampler.logicalTextureUnit);
447 stream->readInt(&sampler.textureType);
448 mSamplersVS.push_back(sampler);
449 }
450
451 stream->readInt(&mUsedVertexSamplerRange);
452 stream->readInt(&mUsedPixelSamplerRange);
453
454 const unsigned int uniformCount = stream->readInt<unsigned int>();
455 if (stream->error())
456 {
457 infoLog.append("Invalid program binary.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500458 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700459 }
460
461 mUniforms.resize(uniformCount);
462 for (unsigned int uniformIndex = 0; uniformIndex < uniformCount; uniformIndex++)
463 {
464 GLenum type = stream->readInt<GLenum>();
465 GLenum precision = stream->readInt<GLenum>();
466 std::string name = stream->readString();
467 unsigned int arraySize = stream->readInt<unsigned int>();
468 int blockIndex = stream->readInt<int>();
469
470 int offset = stream->readInt<int>();
471 int arrayStride = stream->readInt<int>();
472 int matrixStride = stream->readInt<int>();
473 bool isRowMajorMatrix = stream->readBool();
474
475 const sh::BlockMemberInfo blockInfo(offset, arrayStride, matrixStride, isRowMajorMatrix);
476
477 gl::LinkedUniform *uniform = new gl::LinkedUniform(type, precision, name, arraySize, blockIndex, blockInfo);
478
479 stream->readInt(&uniform->psRegisterIndex);
480 stream->readInt(&uniform->vsRegisterIndex);
481 stream->readInt(&uniform->registerCount);
482 stream->readInt(&uniform->registerElement);
483
484 mUniforms[uniformIndex] = uniform;
485 }
486
487 const unsigned int uniformIndexCount = stream->readInt<unsigned int>();
488 if (stream->error())
489 {
490 infoLog.append("Invalid program binary.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500491 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700492 }
493
494 mUniformIndex.resize(uniformIndexCount);
495 for (unsigned int uniformIndexIndex = 0; uniformIndexIndex < uniformIndexCount; uniformIndexIndex++)
496 {
497 stream->readString(&mUniformIndex[uniformIndexIndex].name);
498 stream->readInt(&mUniformIndex[uniformIndexIndex].element);
499 stream->readInt(&mUniformIndex[uniformIndexIndex].index);
500 }
501
502 unsigned int uniformBlockCount = stream->readInt<unsigned int>();
503 if (stream->error())
504 {
505 infoLog.append("Invalid program binary.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500506 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700507 }
508
509 mUniformBlocks.resize(uniformBlockCount);
510 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < uniformBlockCount; ++uniformBlockIndex)
511 {
512 std::string name = stream->readString();
513 unsigned int elementIndex = stream->readInt<unsigned int>();
514 unsigned int dataSize = stream->readInt<unsigned int>();
515
516 gl::UniformBlock *uniformBlock = new gl::UniformBlock(name, elementIndex, dataSize);
517
518 stream->readInt(&uniformBlock->psRegisterIndex);
519 stream->readInt(&uniformBlock->vsRegisterIndex);
520
521 unsigned int numMembers = stream->readInt<unsigned int>();
522 uniformBlock->memberUniformIndexes.resize(numMembers);
523 for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
524 {
525 stream->readInt(&uniformBlock->memberUniformIndexes[blockMemberIndex]);
526 }
527
528 mUniformBlocks[uniformBlockIndex] = uniformBlock;
529 }
530
Brandon Joneseb994362014-09-24 10:27:28 -0700531 stream->readInt(&mTransformFeedbackBufferMode);
532 const unsigned int transformFeedbackVaryingCount = stream->readInt<unsigned int>();
533 mTransformFeedbackLinkedVaryings.resize(transformFeedbackVaryingCount);
534 for (unsigned int varyingIndex = 0; varyingIndex < transformFeedbackVaryingCount; varyingIndex++)
535 {
536 gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[varyingIndex];
537
538 stream->readString(&varying.name);
539 stream->readInt(&varying.type);
540 stream->readInt(&varying.size);
541 stream->readString(&varying.semanticName);
542 stream->readInt(&varying.semanticIndex);
543 stream->readInt(&varying.semanticIndexCount);
544 }
545
Brandon Jones22502d52014-08-29 16:58:36 -0700546 stream->readString(&mVertexHLSL);
547 stream->readInt(&mVertexWorkarounds);
548 stream->readString(&mPixelHLSL);
549 stream->readInt(&mPixelWorkarounds);
550 stream->readBool(&mUsesFragDepth);
Brandon Jones44151a92014-09-10 11:32:25 -0700551 stream->readBool(&mUsesPointSize);
Brandon Jones22502d52014-08-29 16:58:36 -0700552
553 const size_t pixelShaderKeySize = stream->readInt<unsigned int>();
554 mPixelShaderKey.resize(pixelShaderKeySize);
555 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKeySize; pixelShaderKeyIndex++)
556 {
557 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].type);
558 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].name);
559 stream->readString(&mPixelShaderKey[pixelShaderKeyIndex].source);
560 stream->readInt(&mPixelShaderKey[pixelShaderKeyIndex].outputIndex);
561 }
562
Brandon Joneseb994362014-09-24 10:27:28 -0700563 const unsigned char* binary = reinterpret_cast<const unsigned char*>(stream->data());
564
565 const unsigned int vertexShaderCount = stream->readInt<unsigned int>();
566 for (unsigned int vertexShaderIndex = 0; vertexShaderIndex < vertexShaderCount; vertexShaderIndex++)
567 {
568 gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS];
569
570 for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
571 {
572 gl::VertexFormat *vertexInput = &inputLayout[inputIndex];
573 stream->readInt(&vertexInput->mType);
574 stream->readInt(&vertexInput->mNormalized);
575 stream->readInt(&vertexInput->mComponents);
576 stream->readBool(&vertexInput->mPureInteger);
577 }
578
579 unsigned int vertexShaderSize = stream->readInt<unsigned int>();
580 const unsigned char *vertexShaderFunction = binary + stream->offset();
Geoff Langb543aff2014-09-30 14:52:54 -0400581
582 ShaderExecutable *shaderExecutable = NULL;
583 gl::Error error = mRenderer->loadExecutable(vertexShaderFunction, vertexShaderSize,
584 SHADER_VERTEX,
585 mTransformFeedbackLinkedVaryings,
586 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
587 &shaderExecutable);
588 if (error.isError())
589 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500590 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400591 }
592
Brandon Joneseb994362014-09-24 10:27:28 -0700593 if (!shaderExecutable)
594 {
595 infoLog.append("Could not create vertex shader.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500596 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Joneseb994362014-09-24 10:27:28 -0700597 }
598
599 // generated converted input layout
600 GLenum signature[gl::MAX_VERTEX_ATTRIBS];
601 getInputLayoutSignature(inputLayout, signature);
602
603 // add new binary
604 mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, shaderExecutable));
605
606 stream->skip(vertexShaderSize);
607 }
608
609 const size_t pixelShaderCount = stream->readInt<unsigned int>();
610 for (size_t pixelShaderIndex = 0; pixelShaderIndex < pixelShaderCount; pixelShaderIndex++)
611 {
612 const size_t outputCount = stream->readInt<unsigned int>();
613 std::vector<GLenum> outputs(outputCount);
614 for (size_t outputIndex = 0; outputIndex < outputCount; outputIndex++)
615 {
616 stream->readInt(&outputs[outputIndex]);
617 }
618
619 const size_t pixelShaderSize = stream->readInt<unsigned int>();
620 const unsigned char *pixelShaderFunction = binary + stream->offset();
Geoff Langb543aff2014-09-30 14:52:54 -0400621 ShaderExecutable *shaderExecutable = NULL;
622 gl::Error error = mRenderer->loadExecutable(pixelShaderFunction, pixelShaderSize, SHADER_PIXEL,
623 mTransformFeedbackLinkedVaryings,
624 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
625 &shaderExecutable);
626 if (error.isError())
627 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500628 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400629 }
Brandon Joneseb994362014-09-24 10:27:28 -0700630
631 if (!shaderExecutable)
632 {
633 infoLog.append("Could not create pixel shader.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500634 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Joneseb994362014-09-24 10:27:28 -0700635 }
636
637 // add new binary
638 mPixelExecutables.push_back(new PixelExecutable(outputs, shaderExecutable));
639
640 stream->skip(pixelShaderSize);
641 }
642
643 unsigned int geometryShaderSize = stream->readInt<unsigned int>();
644
645 if (geometryShaderSize > 0)
646 {
647 const unsigned char *geometryShaderFunction = binary + stream->offset();
Geoff Langb543aff2014-09-30 14:52:54 -0400648 gl::Error error = mRenderer->loadExecutable(geometryShaderFunction, geometryShaderSize, SHADER_GEOMETRY,
649 mTransformFeedbackLinkedVaryings,
650 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
651 &mGeometryExecutable);
652 if (error.isError())
653 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500654 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400655 }
Brandon Joneseb994362014-09-24 10:27:28 -0700656
657 if (!mGeometryExecutable)
658 {
659 infoLog.append("Could not create geometry shader.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500660 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Joneseb994362014-09-24 10:27:28 -0700661 }
662 stream->skip(geometryShaderSize);
663 }
664
Brandon Jones18bd4102014-09-22 14:21:44 -0700665 GUID binaryIdentifier = {0};
666 stream->readBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(GUID));
667
668 GUID identifier = mRenderer->getAdapterIdentifier();
669 if (memcmp(&identifier, &binaryIdentifier, sizeof(GUID)) != 0)
670 {
671 infoLog.append("Invalid program binary.");
Geoff Lang7dd2e102014-11-10 15:19:26 -0500672 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones18bd4102014-09-22 14:21:44 -0700673 }
674
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700675 initializeUniformStorage();
Jamie Madill437d2662014-12-05 14:23:35 -0500676 initAttributesByLayout();
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700677
Geoff Lang7dd2e102014-11-10 15:19:26 -0500678 return LinkResult(true, gl::Error(GL_NO_ERROR));
Brandon Jones22502d52014-08-29 16:58:36 -0700679}
680
Geoff Langb543aff2014-09-30 14:52:54 -0400681gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
Brandon Jones22502d52014-08-29 16:58:36 -0700682{
Jamie Madill2db1fbb2014-12-03 10:58:55 -0500683 stream->writeInt(ANGLE_COMPILE_OPTIMIZATION_LEVEL);
684
Brandon Jones44151a92014-09-10 11:32:25 -0700685 stream->writeInt(mShaderVersion);
686
Brandon Jones1a8a7e32014-10-01 12:49:30 -0700687 stream->writeInt(mSamplersPS.size());
688 for (unsigned int i = 0; i < mSamplersPS.size(); ++i)
689 {
690 stream->writeInt(mSamplersPS[i].active);
691 stream->writeInt(mSamplersPS[i].logicalTextureUnit);
692 stream->writeInt(mSamplersPS[i].textureType);
693 }
694
695 stream->writeInt(mSamplersVS.size());
696 for (unsigned int i = 0; i < mSamplersVS.size(); ++i)
697 {
698 stream->writeInt(mSamplersVS[i].active);
699 stream->writeInt(mSamplersVS[i].logicalTextureUnit);
700 stream->writeInt(mSamplersVS[i].textureType);
701 }
702
703 stream->writeInt(mUsedVertexSamplerRange);
704 stream->writeInt(mUsedPixelSamplerRange);
705
706 stream->writeInt(mUniforms.size());
707 for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); ++uniformIndex)
708 {
709 const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
710
711 stream->writeInt(uniform.type);
712 stream->writeInt(uniform.precision);
713 stream->writeString(uniform.name);
714 stream->writeInt(uniform.arraySize);
715 stream->writeInt(uniform.blockIndex);
716
717 stream->writeInt(uniform.blockInfo.offset);
718 stream->writeInt(uniform.blockInfo.arrayStride);
719 stream->writeInt(uniform.blockInfo.matrixStride);
720 stream->writeInt(uniform.blockInfo.isRowMajorMatrix);
721
722 stream->writeInt(uniform.psRegisterIndex);
723 stream->writeInt(uniform.vsRegisterIndex);
724 stream->writeInt(uniform.registerCount);
725 stream->writeInt(uniform.registerElement);
726 }
727
728 stream->writeInt(mUniformIndex.size());
729 for (size_t i = 0; i < mUniformIndex.size(); ++i)
730 {
731 stream->writeString(mUniformIndex[i].name);
732 stream->writeInt(mUniformIndex[i].element);
733 stream->writeInt(mUniformIndex[i].index);
734 }
735
736 stream->writeInt(mUniformBlocks.size());
737 for (size_t uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); ++uniformBlockIndex)
738 {
739 const gl::UniformBlock& uniformBlock = *mUniformBlocks[uniformBlockIndex];
740
741 stream->writeString(uniformBlock.name);
742 stream->writeInt(uniformBlock.elementIndex);
743 stream->writeInt(uniformBlock.dataSize);
744
745 stream->writeInt(uniformBlock.memberUniformIndexes.size());
746 for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++)
747 {
748 stream->writeInt(uniformBlock.memberUniformIndexes[blockMemberIndex]);
749 }
750
751 stream->writeInt(uniformBlock.psRegisterIndex);
752 stream->writeInt(uniformBlock.vsRegisterIndex);
753 }
754
Brandon Joneseb994362014-09-24 10:27:28 -0700755 stream->writeInt(mTransformFeedbackBufferMode);
756 stream->writeInt(mTransformFeedbackLinkedVaryings.size());
757 for (size_t i = 0; i < mTransformFeedbackLinkedVaryings.size(); i++)
758 {
759 const gl::LinkedVarying &varying = mTransformFeedbackLinkedVaryings[i];
760
761 stream->writeString(varying.name);
762 stream->writeInt(varying.type);
763 stream->writeInt(varying.size);
764 stream->writeString(varying.semanticName);
765 stream->writeInt(varying.semanticIndex);
766 stream->writeInt(varying.semanticIndexCount);
767 }
768
Brandon Jones22502d52014-08-29 16:58:36 -0700769 stream->writeString(mVertexHLSL);
770 stream->writeInt(mVertexWorkarounds);
771 stream->writeString(mPixelHLSL);
772 stream->writeInt(mPixelWorkarounds);
773 stream->writeInt(mUsesFragDepth);
Brandon Jones44151a92014-09-10 11:32:25 -0700774 stream->writeInt(mUsesPointSize);
Brandon Jones22502d52014-08-29 16:58:36 -0700775
Brandon Joneseb994362014-09-24 10:27:28 -0700776 const std::vector<PixelShaderOutputVariable> &pixelShaderKey = mPixelShaderKey;
Brandon Jones22502d52014-08-29 16:58:36 -0700777 stream->writeInt(pixelShaderKey.size());
778 for (size_t pixelShaderKeyIndex = 0; pixelShaderKeyIndex < pixelShaderKey.size(); pixelShaderKeyIndex++)
779 {
Brandon Joneseb994362014-09-24 10:27:28 -0700780 const PixelShaderOutputVariable &variable = pixelShaderKey[pixelShaderKeyIndex];
Brandon Jones22502d52014-08-29 16:58:36 -0700781 stream->writeInt(variable.type);
782 stream->writeString(variable.name);
783 stream->writeString(variable.source);
784 stream->writeInt(variable.outputIndex);
785 }
786
Brandon Joneseb994362014-09-24 10:27:28 -0700787 stream->writeInt(mVertexExecutables.size());
788 for (size_t vertexExecutableIndex = 0; vertexExecutableIndex < mVertexExecutables.size(); vertexExecutableIndex++)
789 {
790 VertexExecutable *vertexExecutable = mVertexExecutables[vertexExecutableIndex];
791
792 for (size_t inputIndex = 0; inputIndex < gl::MAX_VERTEX_ATTRIBS; inputIndex++)
793 {
794 const gl::VertexFormat &vertexInput = vertexExecutable->inputs()[inputIndex];
795 stream->writeInt(vertexInput.mType);
796 stream->writeInt(vertexInput.mNormalized);
797 stream->writeInt(vertexInput.mComponents);
798 stream->writeInt(vertexInput.mPureInteger);
799 }
800
801 size_t vertexShaderSize = vertexExecutable->shaderExecutable()->getLength();
802 stream->writeInt(vertexShaderSize);
803
804 const uint8_t *vertexBlob = vertexExecutable->shaderExecutable()->getFunction();
805 stream->writeBytes(vertexBlob, vertexShaderSize);
806 }
807
808 stream->writeInt(mPixelExecutables.size());
809 for (size_t pixelExecutableIndex = 0; pixelExecutableIndex < mPixelExecutables.size(); pixelExecutableIndex++)
810 {
811 PixelExecutable *pixelExecutable = mPixelExecutables[pixelExecutableIndex];
812
813 const std::vector<GLenum> outputs = pixelExecutable->outputSignature();
814 stream->writeInt(outputs.size());
815 for (size_t outputIndex = 0; outputIndex < outputs.size(); outputIndex++)
816 {
817 stream->writeInt(outputs[outputIndex]);
818 }
819
820 size_t pixelShaderSize = pixelExecutable->shaderExecutable()->getLength();
821 stream->writeInt(pixelShaderSize);
822
823 const uint8_t *pixelBlob = pixelExecutable->shaderExecutable()->getFunction();
824 stream->writeBytes(pixelBlob, pixelShaderSize);
825 }
826
827 size_t geometryShaderSize = (mGeometryExecutable != NULL) ? mGeometryExecutable->getLength() : 0;
828 stream->writeInt(geometryShaderSize);
829
830 if (mGeometryExecutable != NULL && geometryShaderSize > 0)
831 {
832 const uint8_t *geometryBlob = mGeometryExecutable->getFunction();
833 stream->writeBytes(geometryBlob, geometryShaderSize);
834 }
835
Brandon Jones18bd4102014-09-22 14:21:44 -0700836 GUID binaryIdentifier = mRenderer->getAdapterIdentifier();
Geoff Langb543aff2014-09-30 14:52:54 -0400837 stream->writeBytes(reinterpret_cast<unsigned char*>(&binaryIdentifier), sizeof(GUID));
Brandon Jones18bd4102014-09-22 14:21:44 -0700838
Geoff Langb543aff2014-09-30 14:52:54 -0400839 return gl::Error(GL_NO_ERROR);
Brandon Jones22502d52014-08-29 16:58:36 -0700840}
841
Geoff Langb543aff2014-09-30 14:52:54 -0400842gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutable **outExecutable)
Brandon Jones22502d52014-08-29 16:58:36 -0700843{
Brandon Joneseb994362014-09-24 10:27:28 -0700844 std::vector<GLenum> outputs;
845
Jamie Madill48faf802014-11-06 15:27:22 -0500846 const gl::ColorbufferInfo &colorbuffers = fbo->getColorbuffersForRender(mRenderer->getWorkarounds());
Brandon Joneseb994362014-09-24 10:27:28 -0700847
848 for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
849 {
850 const gl::FramebufferAttachment *colorbuffer = colorbuffers[colorAttachment];
851
852 if (colorbuffer)
853 {
854 outputs.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding());
855 }
856 else
857 {
858 outputs.push_back(GL_NONE);
859 }
860 }
861
Geoff Langb543aff2014-09-30 14:52:54 -0400862 return getPixelExecutableForOutputLayout(outputs, outExecutable);
Brandon Joneseb994362014-09-24 10:27:28 -0700863}
864
Geoff Langb543aff2014-09-30 14:52:54 -0400865gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature, ShaderExecutable **outExectuable)
Brandon Joneseb994362014-09-24 10:27:28 -0700866{
867 for (size_t executableIndex = 0; executableIndex < mPixelExecutables.size(); executableIndex++)
868 {
869 if (mPixelExecutables[executableIndex]->matchesSignature(outputSignature))
870 {
Geoff Langb543aff2014-09-30 14:52:54 -0400871 *outExectuable = mPixelExecutables[executableIndex]->shaderExecutable();
872 return gl::Error(GL_NO_ERROR);
Brandon Joneseb994362014-09-24 10:27:28 -0700873 }
874 }
875
Brandon Jones22502d52014-08-29 16:58:36 -0700876 std::string finalPixelHLSL = mDynamicHLSL->generatePixelShaderForOutputSignature(mPixelHLSL, mPixelShaderKey, mUsesFragDepth,
877 outputSignature);
878
879 // Generate new pixel executable
Brandon Joneseb994362014-09-24 10:27:28 -0700880 gl::InfoLog tempInfoLog;
Geoff Langb543aff2014-09-30 14:52:54 -0400881 ShaderExecutable *pixelExecutable = NULL;
882 gl::Error error = mRenderer->compileToExecutable(tempInfoLog, finalPixelHLSL, SHADER_PIXEL,
883 mTransformFeedbackLinkedVaryings,
884 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
885 mPixelWorkarounds, &pixelExecutable);
886 if (error.isError())
887 {
888 return error;
889 }
Brandon Joneseb994362014-09-24 10:27:28 -0700890
891 if (!pixelExecutable)
892 {
893 std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
894 tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]);
895 ERR("Error compiling dynamic pixel executable:\n%s\n", &tempCharBuffer[0]);
896 }
897 else
898 {
899 mPixelExecutables.push_back(new PixelExecutable(outputSignature, pixelExecutable));
900 }
Brandon Jones22502d52014-08-29 16:58:36 -0700901
Geoff Langb543aff2014-09-30 14:52:54 -0400902 *outExectuable = pixelExecutable;
903 return gl::Error(GL_NO_ERROR);
Brandon Jones22502d52014-08-29 16:58:36 -0700904}
905
Geoff Langb543aff2014-09-30 14:52:54 -0400906gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::VertexFormat inputLayout[gl::MAX_VERTEX_ATTRIBS], ShaderExecutable **outExectuable)
Brandon Jones22502d52014-08-29 16:58:36 -0700907{
Brandon Joneseb994362014-09-24 10:27:28 -0700908 GLenum signature[gl::MAX_VERTEX_ATTRIBS];
909 getInputLayoutSignature(inputLayout, signature);
910
911 for (size_t executableIndex = 0; executableIndex < mVertexExecutables.size(); executableIndex++)
912 {
913 if (mVertexExecutables[executableIndex]->matchesSignature(signature))
914 {
Geoff Langb543aff2014-09-30 14:52:54 -0400915 *outExectuable = mVertexExecutables[executableIndex]->shaderExecutable();
916 return gl::Error(GL_NO_ERROR);
Brandon Joneseb994362014-09-24 10:27:28 -0700917 }
918 }
919
Brandon Jones22502d52014-08-29 16:58:36 -0700920 // Generate new dynamic layout with attribute conversions
Brandon Joneseb994362014-09-24 10:27:28 -0700921 std::string finalVertexHLSL = mDynamicHLSL->generateVertexShaderForInputLayout(mVertexHLSL, inputLayout, mShaderAttributes);
Brandon Jones22502d52014-08-29 16:58:36 -0700922
923 // Generate new vertex executable
Brandon Joneseb994362014-09-24 10:27:28 -0700924 gl::InfoLog tempInfoLog;
Geoff Langb543aff2014-09-30 14:52:54 -0400925 ShaderExecutable *vertexExecutable = NULL;
926 gl::Error error = mRenderer->compileToExecutable(tempInfoLog, finalVertexHLSL, SHADER_VERTEX,
927 mTransformFeedbackLinkedVaryings,
928 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
929 mVertexWorkarounds, &vertexExecutable);
930 if (error.isError())
931 {
932 return error;
933 }
934
Brandon Joneseb994362014-09-24 10:27:28 -0700935 if (!vertexExecutable)
936 {
937 std::vector<char> tempCharBuffer(tempInfoLog.getLength()+3);
938 tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]);
939 ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]);
940 }
941 else
942 {
943 mVertexExecutables.push_back(new VertexExecutable(inputLayout, signature, vertexExecutable));
944 }
Brandon Jones22502d52014-08-29 16:58:36 -0700945
Geoff Langb543aff2014-09-30 14:52:54 -0400946 *outExectuable = vertexExecutable;
947 return gl::Error(GL_NO_ERROR);
Brandon Jones22502d52014-08-29 16:58:36 -0700948}
949
Geoff Lang7dd2e102014-11-10 15:19:26 -0500950LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
951 int registers)
Brandon Jones44151a92014-09-10 11:32:25 -0700952{
Brandon Jones18bd4102014-09-22 14:21:44 -0700953 ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
954 ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
Brandon Jones44151a92014-09-10 11:32:25 -0700955
Brandon Joneseb994362014-09-24 10:27:28 -0700956 gl::VertexFormat defaultInputLayout[gl::MAX_VERTEX_ATTRIBS];
957 GetDefaultInputLayoutFromShader(vertexShader->getActiveAttributes(), defaultInputLayout);
Geoff Langb543aff2014-09-30 14:52:54 -0400958 ShaderExecutable *defaultVertexExecutable = NULL;
959 gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable);
960 if (error.isError())
961 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500962 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400963 }
Brandon Jones44151a92014-09-10 11:32:25 -0700964
Brandon Joneseb994362014-09-24 10:27:28 -0700965 std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
Geoff Langb543aff2014-09-30 14:52:54 -0400966 ShaderExecutable *defaultPixelExecutable = NULL;
967 error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable);
968 if (error.isError())
969 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500970 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400971 }
Brandon Jones44151a92014-09-10 11:32:25 -0700972
Brandon Joneseb994362014-09-24 10:27:28 -0700973 if (usesGeometryShader())
974 {
975 std::string geometryHLSL = mDynamicHLSL->generateGeometryShaderHLSL(registers, fragmentShaderD3D, vertexShaderD3D);
Brandon Jones44151a92014-09-10 11:32:25 -0700976
Geoff Langb543aff2014-09-30 14:52:54 -0400977
978 error = mRenderer->compileToExecutable(infoLog, geometryHLSL, SHADER_GEOMETRY, mTransformFeedbackLinkedVaryings,
979 (mTransformFeedbackBufferMode == GL_SEPARATE_ATTRIBS),
980 ANGLE_D3D_WORKAROUND_NONE, &mGeometryExecutable);
981 if (error.isError())
982 {
Geoff Lang7dd2e102014-11-10 15:19:26 -0500983 return LinkResult(false, error);
Geoff Langb543aff2014-09-30 14:52:54 -0400984 }
Brandon Joneseb994362014-09-24 10:27:28 -0700985 }
986
Brandon Jones091540d2014-10-29 11:32:04 -0700987#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
Tibor den Ouden97049c62014-10-06 21:39:16 +0200988 if (usesGeometryShader() && mGeometryExecutable)
989 {
990 // Geometry shaders are currently only used internally, so there is no corresponding shader object at the interface level
991 // For now the geometry shader debug info is pre-pended to the vertex shader, this is a bit of a clutch
992 vertexShaderD3D->appendDebugInfo("// GEOMETRY SHADER BEGIN\n\n");
993 vertexShaderD3D->appendDebugInfo(mGeometryExecutable->getDebugInfo());
994 vertexShaderD3D->appendDebugInfo("\nGEOMETRY SHADER END\n\n\n");
995 }
996
997 if (defaultVertexExecutable)
998 {
999 vertexShaderD3D->appendDebugInfo(defaultVertexExecutable->getDebugInfo());
1000 }
1001
1002 if (defaultPixelExecutable)
1003 {
1004 fragmentShaderD3D->appendDebugInfo(defaultPixelExecutable->getDebugInfo());
1005 }
1006#endif
1007
Geoff Langb543aff2014-09-30 14:52:54 -04001008 bool linkSuccess = (defaultVertexExecutable && defaultPixelExecutable && (!usesGeometryShader() || mGeometryExecutable));
Geoff Lang7dd2e102014-11-10 15:19:26 -05001009 return LinkResult(linkSuccess, gl::Error(GL_NO_ERROR));
Brandon Jones18bd4102014-09-22 14:21:44 -07001010}
1011
Geoff Lang7dd2e102014-11-10 15:19:26 -05001012LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog,
1013 gl::Shader *fragmentShader, gl::Shader *vertexShader,
1014 const std::vector<std::string> &transformFeedbackVaryings,
1015 GLenum transformFeedbackBufferMode,
1016 int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
1017 std::map<int, gl::VariableLocation> *outputVariables)
Brandon Jones22502d52014-08-29 16:58:36 -07001018{
Brandon Joneseb994362014-09-24 10:27:28 -07001019 ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
1020 ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
1021
Jamie Madillde8892b2014-11-11 13:00:22 -05001022 mSamplersPS.resize(data.caps->maxTextureImageUnits);
1023 mSamplersVS.resize(data.caps->maxVertexTextureImageUnits);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001024
Brandon Joneseb994362014-09-24 10:27:28 -07001025 mTransformFeedbackBufferMode = transformFeedbackBufferMode;
Brandon Jones22502d52014-08-29 16:58:36 -07001026
1027 mPixelHLSL = fragmentShaderD3D->getTranslatedSource();
1028 mPixelWorkarounds = fragmentShaderD3D->getD3DWorkarounds();
1029
1030 mVertexHLSL = vertexShaderD3D->getTranslatedSource();
1031 mVertexWorkarounds = vertexShaderD3D->getD3DWorkarounds();
Brandon Jones44151a92014-09-10 11:32:25 -07001032 mShaderVersion = vertexShaderD3D->getShaderVersion();
Brandon Jones22502d52014-08-29 16:58:36 -07001033
1034 // Map the varyings to the register file
Brandon Joneseb994362014-09-24 10:27:28 -07001035 VaryingPacking packing = { NULL };
Brandon Jones22502d52014-08-29 16:58:36 -07001036 *registers = mDynamicHLSL->packVaryings(infoLog, packing, fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings);
1037
Geoff Langbdee2d52014-09-17 11:02:51 -04001038 if (*registers < 0)
Brandon Jones22502d52014-08-29 16:58:36 -07001039 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001040 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones22502d52014-08-29 16:58:36 -07001041 }
1042
Geoff Lang7dd2e102014-11-10 15:19:26 -05001043 if (!gl::Program::linkVaryings(infoLog, fragmentShader, vertexShader))
Brandon Jones22502d52014-08-29 16:58:36 -07001044 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001045 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones22502d52014-08-29 16:58:36 -07001046 }
1047
Jamie Madillde8892b2014-11-11 13:00:22 -05001048 if (!mDynamicHLSL->generateShaderLinkHLSL(data, infoLog, *registers, packing, mPixelHLSL, mVertexHLSL,
Brandon Jones22502d52014-08-29 16:58:36 -07001049 fragmentShaderD3D, vertexShaderD3D, transformFeedbackVaryings,
1050 linkedVaryings, outputVariables, &mPixelShaderKey, &mUsesFragDepth))
1051 {
Geoff Lang7dd2e102014-11-10 15:19:26 -05001052 return LinkResult(false, gl::Error(GL_NO_ERROR));
Brandon Jones22502d52014-08-29 16:58:36 -07001053 }
1054
Brandon Jones44151a92014-09-10 11:32:25 -07001055 mUsesPointSize = vertexShaderD3D->usesPointSize();
1056
Jamie Madill437d2662014-12-05 14:23:35 -05001057 initAttributesByLayout();
1058
Geoff Lang7dd2e102014-11-10 15:19:26 -05001059 return LinkResult(true, gl::Error(GL_NO_ERROR));
Brandon Jones22502d52014-08-29 16:58:36 -07001060}
1061
Brandon Jones44151a92014-09-10 11:32:25 -07001062void ProgramD3D::getInputLayoutSignature(const gl::VertexFormat inputLayout[], GLenum signature[]) const
1063{
1064 mDynamicHLSL->getInputLayoutSignature(inputLayout, signature);
1065}
1066
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001067void ProgramD3D::initializeUniformStorage()
Brandon Jonesc9610c52014-08-25 17:02:59 -07001068{
1069 // Compute total default block size
1070 unsigned int vertexRegisters = 0;
1071 unsigned int fragmentRegisters = 0;
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001072 for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
Brandon Jonesc9610c52014-08-25 17:02:59 -07001073 {
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001074 const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
Brandon Jonesc9610c52014-08-25 17:02:59 -07001075
Geoff Lang2ec386b2014-12-03 14:44:38 -05001076 if (!gl::IsSamplerType(uniform.type))
Brandon Jonesc9610c52014-08-25 17:02:59 -07001077 {
1078 if (uniform.isReferencedByVertexShader())
1079 {
1080 vertexRegisters = std::max(vertexRegisters, uniform.vsRegisterIndex + uniform.registerCount);
1081 }
1082 if (uniform.isReferencedByFragmentShader())
1083 {
1084 fragmentRegisters = std::max(fragmentRegisters, uniform.psRegisterIndex + uniform.registerCount);
1085 }
1086 }
1087 }
1088
1089 mVertexUniformStorage = mRenderer->createUniformStorage(vertexRegisters * 16u);
1090 mFragmentUniformStorage = mRenderer->createUniformStorage(fragmentRegisters * 16u);
1091}
1092
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001093gl::Error ProgramD3D::applyUniforms()
Brandon Jones18bd4102014-09-22 14:21:44 -07001094{
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001095 updateSamplerMapping();
1096
1097 gl::Error error = mRenderer->applyUniforms(*this, mUniforms);
1098 if (error.isError())
1099 {
1100 return error;
1101 }
1102
1103 for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
1104 {
1105 mUniforms[uniformIndex]->dirty = false;
1106 }
1107
1108 return gl::Error(GL_NO_ERROR);
Brandon Jones18bd4102014-09-22 14:21:44 -07001109}
1110
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001111gl::Error ProgramD3D::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const gl::Caps &caps)
Brandon Jones18bd4102014-09-22 14:21:44 -07001112{
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001113 ASSERT(boundBuffers.size() == mUniformBlocks.size());
1114
Brandon Jones18bd4102014-09-22 14:21:44 -07001115 const gl::Buffer *vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS] = {NULL};
1116 const gl::Buffer *fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS] = {NULL};
1117
1118 const unsigned int reservedBuffersInVS = mRenderer->getReservedVertexUniformBuffers();
1119 const unsigned int reservedBuffersInFS = mRenderer->getReservedFragmentUniformBuffers();
1120
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001121 for (unsigned int uniformBlockIndex = 0; uniformBlockIndex < mUniformBlocks.size(); uniformBlockIndex++)
Brandon Jones18bd4102014-09-22 14:21:44 -07001122 {
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001123 gl::UniformBlock *uniformBlock = mUniformBlocks[uniformBlockIndex];
Brandon Jones18bd4102014-09-22 14:21:44 -07001124 gl::Buffer *uniformBuffer = boundBuffers[uniformBlockIndex];
1125
1126 ASSERT(uniformBlock && uniformBuffer);
1127
1128 if (uniformBuffer->getSize() < uniformBlock->dataSize)
1129 {
1130 // undefined behaviour
1131 return gl::Error(GL_INVALID_OPERATION, "It is undefined behaviour to use a uniform buffer that is too small.");
1132 }
1133
1134 // Unnecessary to apply an unreferenced standard or shared UBO
1135 if (!uniformBlock->isReferencedByVertexShader() && !uniformBlock->isReferencedByFragmentShader())
1136 {
1137 continue;
1138 }
1139
1140 if (uniformBlock->isReferencedByVertexShader())
1141 {
1142 unsigned int registerIndex = uniformBlock->vsRegisterIndex - reservedBuffersInVS;
1143 ASSERT(vertexUniformBuffers[registerIndex] == NULL);
1144 ASSERT(registerIndex < caps.maxVertexUniformBlocks);
1145 vertexUniformBuffers[registerIndex] = uniformBuffer;
1146 }
1147
1148 if (uniformBlock->isReferencedByFragmentShader())
1149 {
1150 unsigned int registerIndex = uniformBlock->psRegisterIndex - reservedBuffersInFS;
1151 ASSERT(fragmentUniformBuffers[registerIndex] == NULL);
1152 ASSERT(registerIndex < caps.maxFragmentUniformBlocks);
1153 fragmentUniformBuffers[registerIndex] = uniformBuffer;
1154 }
1155 }
1156
1157 return mRenderer->setUniformBuffers(vertexUniformBuffers, fragmentUniformBuffers);
1158}
1159
1160bool ProgramD3D::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
1161 unsigned int registerIndex, const gl::Caps &caps)
1162{
1163 if (shader == GL_VERTEX_SHADER)
1164 {
1165 uniformBlock->vsRegisterIndex = registerIndex;
1166 if (registerIndex - mRenderer->getReservedVertexUniformBuffers() >= caps.maxVertexUniformBlocks)
1167 {
1168 infoLog.append("Vertex shader uniform block count exceed GL_MAX_VERTEX_UNIFORM_BLOCKS (%u)", caps.maxVertexUniformBlocks);
1169 return false;
1170 }
1171 }
1172 else if (shader == GL_FRAGMENT_SHADER)
1173 {
1174 uniformBlock->psRegisterIndex = registerIndex;
1175 if (registerIndex - mRenderer->getReservedFragmentUniformBuffers() >= caps.maxFragmentUniformBlocks)
1176 {
1177 infoLog.append("Fragment shader uniform block count exceed GL_MAX_FRAGMENT_UNIFORM_BLOCKS (%u)", caps.maxFragmentUniformBlocks);
1178 return false;
1179 }
1180 }
1181 else UNREACHABLE();
1182
1183 return true;
1184}
1185
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001186void ProgramD3D::dirtyAllUniforms()
Brandon Jones18bd4102014-09-22 14:21:44 -07001187{
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001188 unsigned int numUniforms = mUniforms.size();
1189 for (unsigned int index = 0; index < numUniforms; index++)
Brandon Jones18bd4102014-09-22 14:21:44 -07001190 {
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001191 mUniforms[index]->dirty = true;
Brandon Jones18bd4102014-09-22 14:21:44 -07001192 }
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001193}
1194
1195void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat* v)
1196{
1197 setUniform(location, count, v, GL_FLOAT);
1198}
1199
1200void ProgramD3D::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
1201{
1202 setUniform(location, count, v, GL_FLOAT_VEC2);
1203}
1204
1205void ProgramD3D::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
1206{
1207 setUniform(location, count, v, GL_FLOAT_VEC3);
1208}
1209
1210void ProgramD3D::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
1211{
1212 setUniform(location, count, v, GL_FLOAT_VEC4);
1213}
1214
1215void ProgramD3D::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1216{
1217 setUniformMatrixfv<2, 2>(location, count, transpose, value, GL_FLOAT_MAT2);
1218}
1219
1220void ProgramD3D::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1221{
1222 setUniformMatrixfv<3, 3>(location, count, transpose, value, GL_FLOAT_MAT3);
1223}
1224
1225void ProgramD3D::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1226{
1227 setUniformMatrixfv<4, 4>(location, count, transpose, value, GL_FLOAT_MAT4);
1228}
1229
1230void ProgramD3D::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1231{
1232 setUniformMatrixfv<2, 3>(location, count, transpose, value, GL_FLOAT_MAT2x3);
1233}
1234
1235void ProgramD3D::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1236{
1237 setUniformMatrixfv<3, 2>(location, count, transpose, value, GL_FLOAT_MAT3x2);
1238}
1239
1240void ProgramD3D::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1241{
1242 setUniformMatrixfv<2, 4>(location, count, transpose, value, GL_FLOAT_MAT2x4);
1243}
1244
1245void ProgramD3D::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1246{
1247 setUniformMatrixfv<4, 2>(location, count, transpose, value, GL_FLOAT_MAT4x2);
1248}
1249
1250void ProgramD3D::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1251{
1252 setUniformMatrixfv<3, 4>(location, count, transpose, value, GL_FLOAT_MAT3x4);
1253}
1254
1255void ProgramD3D::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
1256{
1257 setUniformMatrixfv<4, 3>(location, count, transpose, value, GL_FLOAT_MAT4x3);
1258}
1259
1260void ProgramD3D::setUniform1iv(GLint location, GLsizei count, const GLint *v)
1261{
1262 setUniform(location, count, v, GL_INT);
1263}
1264
1265void ProgramD3D::setUniform2iv(GLint location, GLsizei count, const GLint *v)
1266{
1267 setUniform(location, count, v, GL_INT_VEC2);
1268}
1269
1270void ProgramD3D::setUniform3iv(GLint location, GLsizei count, const GLint *v)
1271{
1272 setUniform(location, count, v, GL_INT_VEC3);
1273}
1274
1275void ProgramD3D::setUniform4iv(GLint location, GLsizei count, const GLint *v)
1276{
1277 setUniform(location, count, v, GL_INT_VEC4);
1278}
1279
1280void ProgramD3D::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
1281{
1282 setUniform(location, count, v, GL_UNSIGNED_INT);
1283}
1284
1285void ProgramD3D::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
1286{
1287 setUniform(location, count, v, GL_UNSIGNED_INT_VEC2);
1288}
1289
1290void ProgramD3D::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
1291{
1292 setUniform(location, count, v, GL_UNSIGNED_INT_VEC3);
1293}
1294
1295void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
1296{
1297 setUniform(location, count, v, GL_UNSIGNED_INT_VEC4);
1298}
1299
1300void ProgramD3D::getUniformfv(GLint location, GLfloat *params)
1301{
1302 getUniformv(location, params, GL_FLOAT);
1303}
1304
1305void ProgramD3D::getUniformiv(GLint location, GLint *params)
1306{
1307 getUniformv(location, params, GL_INT);
1308}
1309
1310void ProgramD3D::getUniformuiv(GLint location, GLuint *params)
1311{
1312 getUniformv(location, params, GL_UNSIGNED_INT);
1313}
1314
1315bool ProgramD3D::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
1316 const gl::Caps &caps)
1317{
Jamie Madill30d6c252014-11-13 10:03:33 -05001318 const ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader.getImplementation());
1319 const ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader.getImplementation());
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001320
1321 const std::vector<sh::Uniform> &vertexUniforms = vertexShader.getUniforms();
1322 const std::vector<sh::Uniform> &fragmentUniforms = fragmentShader.getUniforms();
1323
1324 // Check that uniforms defined in the vertex and fragment shaders are identical
1325 typedef std::map<std::string, const sh::Uniform*> UniformMap;
1326 UniformMap linkedUniforms;
1327
1328 for (unsigned int vertexUniformIndex = 0; vertexUniformIndex < vertexUniforms.size(); vertexUniformIndex++)
Brandon Jones18bd4102014-09-22 14:21:44 -07001329 {
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001330 const sh::Uniform &vertexUniform = vertexUniforms[vertexUniformIndex];
1331 linkedUniforms[vertexUniform.name] = &vertexUniform;
1332 }
1333
1334 for (unsigned int fragmentUniformIndex = 0; fragmentUniformIndex < fragmentUniforms.size(); fragmentUniformIndex++)
1335 {
1336 const sh::Uniform &fragmentUniform = fragmentUniforms[fragmentUniformIndex];
1337 UniformMap::const_iterator entry = linkedUniforms.find(fragmentUniform.name);
1338 if (entry != linkedUniforms.end())
1339 {
1340 const sh::Uniform &vertexUniform = *entry->second;
1341 const std::string &uniformName = "uniform '" + vertexUniform.name + "'";
Geoff Lang7dd2e102014-11-10 15:19:26 -05001342 if (!gl::Program::linkValidateUniforms(infoLog, uniformName, vertexUniform, fragmentUniform))
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001343 {
1344 return false;
1345 }
1346 }
1347 }
1348
1349 for (unsigned int uniformIndex = 0; uniformIndex < vertexUniforms.size(); uniformIndex++)
1350 {
1351 const sh::Uniform &uniform = vertexUniforms[uniformIndex];
1352
1353 if (uniform.staticUse)
1354 {
1355 defineUniformBase(GL_VERTEX_SHADER, uniform, vertexShaderD3D->getUniformRegister(uniform.name));
1356 }
1357 }
1358
1359 for (unsigned int uniformIndex = 0; uniformIndex < fragmentUniforms.size(); uniformIndex++)
1360 {
1361 const sh::Uniform &uniform = fragmentUniforms[uniformIndex];
1362
1363 if (uniform.staticUse)
1364 {
1365 defineUniformBase(GL_FRAGMENT_SHADER, uniform, fragmentShaderD3D->getUniformRegister(uniform.name));
1366 }
1367 }
1368
1369 if (!indexUniforms(infoLog, caps))
1370 {
1371 return false;
1372 }
1373
1374 initializeUniformStorage();
1375
1376 // special case for gl_DepthRange, the only built-in uniform (also a struct)
1377 if (vertexShaderD3D->usesDepthRange() || fragmentShaderD3D->usesDepthRange())
1378 {
1379 const sh::BlockMemberInfo &defaultInfo = sh::BlockMemberInfo::getDefaultBlockInfo();
1380
1381 mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.near", 0, -1, defaultInfo));
1382 mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.far", 0, -1, defaultInfo));
1383 mUniforms.push_back(new gl::LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, defaultInfo));
1384 }
1385
1386 return true;
1387}
1388
1389void ProgramD3D::defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister)
1390{
Jamie Madill30d6c252014-11-13 10:03:33 -05001391 ShShaderOutput outputType = ShaderD3D::getCompilerOutputType(shader);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001392 sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType));
1393 encoder.skipRegisters(uniformRegister);
1394
1395 defineUniform(shader, uniform, uniform.name, &encoder);
1396}
1397
1398void ProgramD3D::defineUniform(GLenum shader, const sh::ShaderVariable &uniform,
1399 const std::string &fullName, sh::HLSLBlockEncoder *encoder)
1400{
1401 if (uniform.isStruct())
1402 {
1403 for (unsigned int elementIndex = 0; elementIndex < uniform.elementCount(); elementIndex++)
1404 {
1405 const std::string &elementString = (uniform.isArray() ? ArrayString(elementIndex) : "");
1406
1407 encoder->enterAggregateType();
1408
1409 for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
1410 {
1411 const sh::ShaderVariable &field = uniform.fields[fieldIndex];
1412 const std::string &fieldFullName = (fullName + elementString + "." + field.name);
1413
1414 defineUniform(shader, field, fieldFullName, encoder);
1415 }
1416
1417 encoder->exitAggregateType();
1418 }
1419 }
1420 else // Not a struct
1421 {
1422 // Arrays are treated as aggregate types
1423 if (uniform.isArray())
1424 {
1425 encoder->enterAggregateType();
1426 }
1427
1428 gl::LinkedUniform *linkedUniform = getUniformByName(fullName);
1429
1430 if (!linkedUniform)
1431 {
1432 linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
1433 -1, sh::BlockMemberInfo::getDefaultBlockInfo());
1434 ASSERT(linkedUniform);
1435 linkedUniform->registerElement = encoder->getCurrentElement();
1436 mUniforms.push_back(linkedUniform);
1437 }
1438
1439 ASSERT(linkedUniform->registerElement == encoder->getCurrentElement());
1440
1441 if (shader == GL_FRAGMENT_SHADER)
1442 {
1443 linkedUniform->psRegisterIndex = encoder->getCurrentRegister();
1444 }
1445 else if (shader == GL_VERTEX_SHADER)
1446 {
1447 linkedUniform->vsRegisterIndex = encoder->getCurrentRegister();
1448 }
1449 else UNREACHABLE();
1450
1451 // Advance the uniform offset, to track registers allocation for structs
1452 encoder->encodeType(uniform.type, uniform.arraySize, false);
1453
1454 // Arrays are treated as aggregate types
1455 if (uniform.isArray())
1456 {
1457 encoder->exitAggregateType();
1458 }
1459 }
1460}
1461
1462template <typename T>
1463static inline void SetIfDirty(T *dest, const T& source, bool *dirtyFlag)
1464{
1465 ASSERT(dest != NULL);
1466 ASSERT(dirtyFlag != NULL);
1467
1468 *dirtyFlag = *dirtyFlag || (memcmp(dest, &source, sizeof(T)) != 0);
1469 *dest = source;
1470}
1471
1472template <typename T>
1473void ProgramD3D::setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType)
1474{
1475 const int components = gl::VariableComponentCount(targetUniformType);
1476 const GLenum targetBoolType = gl::VariableBoolVectorType(targetUniformType);
1477
1478 gl::LinkedUniform *targetUniform = getUniformByLocation(location);
1479
1480 int elementCount = targetUniform->elementCount();
1481
1482 count = std::min(elementCount - (int)mUniformIndex[location].element, count);
1483
1484 if (targetUniform->type == targetUniformType)
1485 {
1486 T *target = reinterpret_cast<T*>(targetUniform->data) + mUniformIndex[location].element * 4;
1487
1488 for (int i = 0; i < count; i++)
1489 {
1490 T *dest = target + (i * 4);
1491 const T *source = v + (i * components);
1492
1493 for (int c = 0; c < components; c++)
1494 {
1495 SetIfDirty(dest + c, source[c], &targetUniform->dirty);
1496 }
1497 for (int c = components; c < 4; c++)
1498 {
1499 SetIfDirty(dest + c, T(0), &targetUniform->dirty);
1500 }
1501 }
1502 }
1503 else if (targetUniform->type == targetBoolType)
1504 {
1505 GLint *boolParams = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4;
1506
1507 for (int i = 0; i < count; i++)
1508 {
1509 GLint *dest = boolParams + (i * 4);
1510 const T *source = v + (i * components);
1511
1512 for (int c = 0; c < components; c++)
1513 {
1514 SetIfDirty(dest + c, (source[c] == static_cast<T>(0)) ? GL_FALSE : GL_TRUE, &targetUniform->dirty);
1515 }
1516 for (int c = components; c < 4; c++)
1517 {
1518 SetIfDirty(dest + c, GL_FALSE, &targetUniform->dirty);
1519 }
1520 }
1521 }
Geoff Lang2ec386b2014-12-03 14:44:38 -05001522 else if (gl::IsSamplerType(targetUniform->type))
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001523 {
1524 ASSERT(targetUniformType == GL_INT);
1525
1526 GLint *target = reinterpret_cast<GLint*>(targetUniform->data) + mUniformIndex[location].element * 4;
1527
1528 bool wasDirty = targetUniform->dirty;
1529
1530 for (int i = 0; i < count; i++)
1531 {
1532 GLint *dest = target + (i * 4);
1533 const GLint *source = reinterpret_cast<const GLint*>(v) + (i * components);
1534
1535 SetIfDirty(dest + 0, source[0], &targetUniform->dirty);
1536 SetIfDirty(dest + 1, 0, &targetUniform->dirty);
1537 SetIfDirty(dest + 2, 0, &targetUniform->dirty);
1538 SetIfDirty(dest + 3, 0, &targetUniform->dirty);
1539 }
1540
1541 if (!wasDirty && targetUniform->dirty)
1542 {
1543 mDirtySamplerMapping = true;
1544 }
Brandon Jones18bd4102014-09-22 14:21:44 -07001545 }
1546 else UNREACHABLE();
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001547}
Brandon Jones18bd4102014-09-22 14:21:44 -07001548
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001549template<typename T>
1550bool transposeMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
1551{
1552 bool dirty = false;
1553 int copyWidth = std::min(targetHeight, srcWidth);
1554 int copyHeight = std::min(targetWidth, srcHeight);
1555
1556 for (int x = 0; x < copyWidth; x++)
1557 {
1558 for (int y = 0; y < copyHeight; y++)
1559 {
1560 SetIfDirty(target + (x * targetWidth + y), static_cast<T>(value[y * srcWidth + x]), &dirty);
1561 }
1562 }
1563 // clear unfilled right side
1564 for (int y = 0; y < copyWidth; y++)
1565 {
1566 for (int x = copyHeight; x < targetWidth; x++)
1567 {
1568 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
1569 }
1570 }
1571 // clear unfilled bottom.
1572 for (int y = copyWidth; y < targetHeight; y++)
1573 {
1574 for (int x = 0; x < targetWidth; x++)
1575 {
1576 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
1577 }
1578 }
1579
1580 return dirty;
1581}
1582
1583template<typename T>
1584bool expandMatrix(T *target, const GLfloat *value, int targetWidth, int targetHeight, int srcWidth, int srcHeight)
1585{
1586 bool dirty = false;
1587 int copyWidth = std::min(targetWidth, srcWidth);
1588 int copyHeight = std::min(targetHeight, srcHeight);
1589
1590 for (int y = 0; y < copyHeight; y++)
1591 {
1592 for (int x = 0; x < copyWidth; x++)
1593 {
1594 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(value[y * srcWidth + x]), &dirty);
1595 }
1596 }
1597 // clear unfilled right side
1598 for (int y = 0; y < copyHeight; y++)
1599 {
1600 for (int x = copyWidth; x < targetWidth; x++)
1601 {
1602 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
1603 }
1604 }
1605 // clear unfilled bottom.
1606 for (int y = copyHeight; y < targetHeight; y++)
1607 {
1608 for (int x = 0; x < targetWidth; x++)
1609 {
1610 SetIfDirty(target + (y * targetWidth + x), static_cast<T>(0), &dirty);
1611 }
1612 }
1613
1614 return dirty;
1615}
1616
1617template <int cols, int rows>
1618void ProgramD3D::setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType)
1619{
1620 gl::LinkedUniform *targetUniform = getUniformByLocation(location);
1621
1622 int elementCount = targetUniform->elementCount();
1623
1624 count = std::min(elementCount - (int)mUniformIndex[location].element, count);
1625 const unsigned int targetMatrixStride = (4 * rows);
1626 GLfloat *target = (GLfloat*)(targetUniform->data + mUniformIndex[location].element * sizeof(GLfloat) * targetMatrixStride);
1627
1628 for (int i = 0; i < count; i++)
1629 {
1630 // Internally store matrices as transposed versions to accomodate HLSL matrix indexing
1631 if (transpose == GL_FALSE)
1632 {
1633 targetUniform->dirty = transposeMatrix<GLfloat>(target, value, 4, rows, rows, cols) || targetUniform->dirty;
1634 }
1635 else
1636 {
1637 targetUniform->dirty = expandMatrix<GLfloat>(target, value, 4, rows, cols, rows) || targetUniform->dirty;
1638 }
1639 target += targetMatrixStride;
1640 value += cols * rows;
1641 }
1642}
1643
1644template <typename T>
1645void ProgramD3D::getUniformv(GLint location, T *params, GLenum uniformType)
1646{
1647 gl::LinkedUniform *targetUniform = mUniforms[mUniformIndex[location].index];
1648
1649 if (gl::IsMatrixType(targetUniform->type))
1650 {
1651 const int rows = gl::VariableRowCount(targetUniform->type);
1652 const int cols = gl::VariableColumnCount(targetUniform->type);
1653 transposeMatrix(params, (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4 * rows, rows, cols, 4, rows);
1654 }
1655 else if (uniformType == gl::VariableComponentType(targetUniform->type))
1656 {
1657 unsigned int size = gl::VariableComponentCount(targetUniform->type);
1658 memcpy(params, targetUniform->data + mUniformIndex[location].element * 4 * sizeof(T),
1659 size * sizeof(T));
1660 }
1661 else
1662 {
1663 unsigned int size = gl::VariableComponentCount(targetUniform->type);
1664 switch (gl::VariableComponentType(targetUniform->type))
1665 {
1666 case GL_BOOL:
1667 {
1668 GLint *boolParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
1669
1670 for (unsigned int i = 0; i < size; i++)
1671 {
1672 params[i] = (boolParams[i] == GL_FALSE) ? static_cast<T>(0) : static_cast<T>(1);
1673 }
1674 }
1675 break;
1676
1677 case GL_FLOAT:
1678 {
1679 GLfloat *floatParams = (GLfloat*)targetUniform->data + mUniformIndex[location].element * 4;
1680
1681 for (unsigned int i = 0; i < size; i++)
1682 {
1683 params[i] = static_cast<T>(floatParams[i]);
1684 }
1685 }
1686 break;
1687
1688 case GL_INT:
1689 {
1690 GLint *intParams = (GLint*)targetUniform->data + mUniformIndex[location].element * 4;
1691
1692 for (unsigned int i = 0; i < size; i++)
1693 {
1694 params[i] = static_cast<T>(intParams[i]);
1695 }
1696 }
1697 break;
1698
1699 case GL_UNSIGNED_INT:
1700 {
1701 GLuint *uintParams = (GLuint*)targetUniform->data + mUniformIndex[location].element * 4;
1702
1703 for (unsigned int i = 0; i < size; i++)
1704 {
1705 params[i] = static_cast<T>(uintParams[i]);
1706 }
1707 }
1708 break;
1709
1710 default: UNREACHABLE();
1711 }
1712 }
1713}
1714
1715template <typename VarT>
1716void ProgramD3D::defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
1717 sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes,
1718 bool inRowMajorLayout)
1719{
1720 for (unsigned int uniformIndex = 0; uniformIndex < fields.size(); uniformIndex++)
1721 {
1722 const VarT &field = fields[uniformIndex];
1723 const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
1724
1725 if (field.isStruct())
1726 {
1727 bool rowMajorLayout = (inRowMajorLayout || IsRowMajorLayout(field));
1728
1729 for (unsigned int arrayElement = 0; arrayElement < field.elementCount(); arrayElement++)
1730 {
1731 encoder->enterAggregateType();
1732
1733 const std::string uniformElementName = fieldName + (field.isArray() ? ArrayString(arrayElement) : "");
1734 defineUniformBlockMembers(field.fields, uniformElementName, blockIndex, encoder, blockUniformIndexes, rowMajorLayout);
1735
1736 encoder->exitAggregateType();
1737 }
1738 }
1739 else
1740 {
1741 bool isRowMajorMatrix = (gl::IsMatrixType(field.type) && inRowMajorLayout);
1742
1743 sh::BlockMemberInfo memberInfo = encoder->encodeType(field.type, field.arraySize, isRowMajorMatrix);
1744
1745 gl::LinkedUniform *newUniform = new gl::LinkedUniform(field.type, field.precision, fieldName, field.arraySize,
1746 blockIndex, memberInfo);
1747
1748 // add to uniform list, but not index, since uniform block uniforms have no location
1749 blockUniformIndexes->push_back(mUniforms.size());
1750 mUniforms.push_back(newUniform);
1751 }
1752 }
1753}
1754
1755bool ProgramD3D::defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock,
1756 const gl::Caps &caps)
1757{
Jamie Madill30d6c252014-11-13 10:03:33 -05001758 const ShaderD3D* shaderD3D = ShaderD3D::makeShaderD3D(shader.getImplementation());
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001759
1760 // create uniform block entries if they do not exist
1761 if (getUniformBlockIndex(interfaceBlock.name) == GL_INVALID_INDEX)
1762 {
1763 std::vector<unsigned int> blockUniformIndexes;
1764 const unsigned int blockIndex = mUniformBlocks.size();
1765
1766 // define member uniforms
1767 sh::BlockLayoutEncoder *encoder = NULL;
1768
1769 if (interfaceBlock.layout == sh::BLOCKLAYOUT_STANDARD)
1770 {
1771 encoder = new sh::Std140BlockEncoder;
1772 }
1773 else
1774 {
1775 encoder = new sh::HLSLBlockEncoder(sh::HLSLBlockEncoder::ENCODE_PACKED);
1776 }
1777 ASSERT(encoder);
1778
1779 defineUniformBlockMembers(interfaceBlock.fields, "", blockIndex, encoder, &blockUniformIndexes, interfaceBlock.isRowMajorLayout);
1780
1781 size_t dataSize = encoder->getBlockSize();
1782
1783 // create all the uniform blocks
1784 if (interfaceBlock.arraySize > 0)
1785 {
1786 for (unsigned int uniformBlockElement = 0; uniformBlockElement < interfaceBlock.arraySize; uniformBlockElement++)
1787 {
1788 gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, uniformBlockElement, dataSize);
1789 newUniformBlock->memberUniformIndexes = blockUniformIndexes;
1790 mUniformBlocks.push_back(newUniformBlock);
1791 }
1792 }
1793 else
1794 {
1795 gl::UniformBlock *newUniformBlock = new gl::UniformBlock(interfaceBlock.name, GL_INVALID_INDEX, dataSize);
1796 newUniformBlock->memberUniformIndexes = blockUniformIndexes;
1797 mUniformBlocks.push_back(newUniformBlock);
1798 }
1799 }
1800
1801 if (interfaceBlock.staticUse)
1802 {
1803 // Assign registers to the uniform blocks
1804 const GLuint blockIndex = getUniformBlockIndex(interfaceBlock.name);
1805 const unsigned int elementCount = std::max(1u, interfaceBlock.arraySize);
1806 ASSERT(blockIndex != GL_INVALID_INDEX);
1807 ASSERT(blockIndex + elementCount <= mUniformBlocks.size());
1808
1809 unsigned int interfaceBlockRegister = shaderD3D->getInterfaceBlockRegister(interfaceBlock.name);
1810
1811 for (unsigned int uniformBlockElement = 0; uniformBlockElement < elementCount; uniformBlockElement++)
1812 {
1813 gl::UniformBlock *uniformBlock = mUniformBlocks[blockIndex + uniformBlockElement];
1814 ASSERT(uniformBlock->name == interfaceBlock.name);
1815
1816 if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(),
1817 interfaceBlockRegister + uniformBlockElement, caps))
1818 {
1819 return false;
1820 }
1821 }
1822 }
1823
1824 return true;
1825}
1826
1827bool ProgramD3D::assignSamplers(unsigned int startSamplerIndex,
1828 GLenum samplerType,
1829 unsigned int samplerCount,
1830 std::vector<Sampler> &outSamplers,
1831 GLuint *outUsedRange)
1832{
1833 unsigned int samplerIndex = startSamplerIndex;
1834
1835 do
1836 {
1837 if (samplerIndex < outSamplers.size())
1838 {
1839 Sampler& sampler = outSamplers[samplerIndex];
1840 sampler.active = true;
1841 sampler.textureType = GetTextureType(samplerType);
1842 sampler.logicalTextureUnit = 0;
1843 *outUsedRange = std::max(samplerIndex + 1, *outUsedRange);
1844 }
1845 else
1846 {
1847 return false;
1848 }
1849
1850 samplerIndex++;
1851 } while (samplerIndex < startSamplerIndex + samplerCount);
1852
1853 return true;
1854}
1855
1856bool ProgramD3D::indexSamplerUniform(const gl::LinkedUniform &uniform, gl::InfoLog &infoLog, const gl::Caps &caps)
1857{
Geoff Lang2ec386b2014-12-03 14:44:38 -05001858 ASSERT(gl::IsSamplerType(uniform.type));
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001859 ASSERT(uniform.vsRegisterIndex != GL_INVALID_INDEX || uniform.psRegisterIndex != GL_INVALID_INDEX);
1860
1861 if (uniform.vsRegisterIndex != GL_INVALID_INDEX)
1862 {
1863 if (!assignSamplers(uniform.vsRegisterIndex, uniform.type, uniform.arraySize, mSamplersVS,
1864 &mUsedVertexSamplerRange))
1865 {
1866 infoLog.append("Vertex shader sampler count exceeds the maximum vertex texture units (%d).",
1867 mSamplersVS.size());
1868 return false;
1869 }
1870
1871 unsigned int maxVertexVectors = mRenderer->getReservedVertexUniformVectors() + caps.maxVertexUniformVectors;
1872 if (uniform.vsRegisterIndex + uniform.registerCount > maxVertexVectors)
1873 {
1874 infoLog.append("Vertex shader active uniforms exceed GL_MAX_VERTEX_UNIFORM_VECTORS (%u)",
1875 caps.maxVertexUniformVectors);
1876 return false;
1877 }
1878 }
1879
1880 if (uniform.psRegisterIndex != GL_INVALID_INDEX)
1881 {
1882 if (!assignSamplers(uniform.psRegisterIndex, uniform.type, uniform.arraySize, mSamplersPS,
1883 &mUsedPixelSamplerRange))
1884 {
1885 infoLog.append("Pixel shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (%d).",
1886 mSamplersPS.size());
1887 return false;
1888 }
1889
1890 unsigned int maxFragmentVectors = mRenderer->getReservedFragmentUniformVectors() + caps.maxFragmentUniformVectors;
1891 if (uniform.psRegisterIndex + uniform.registerCount > maxFragmentVectors)
1892 {
1893 infoLog.append("Fragment shader active uniforms exceed GL_MAX_FRAGMENT_UNIFORM_VECTORS (%u)",
1894 caps.maxFragmentUniformVectors);
1895 return false;
1896 }
1897 }
1898
1899 return true;
1900}
1901
1902bool ProgramD3D::indexUniforms(gl::InfoLog &infoLog, const gl::Caps &caps)
1903{
1904 for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
1905 {
1906 const gl::LinkedUniform &uniform = *mUniforms[uniformIndex];
1907
Geoff Lang2ec386b2014-12-03 14:44:38 -05001908 if (gl::IsSamplerType(uniform.type))
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001909 {
1910 if (!indexSamplerUniform(uniform, infoLog, caps))
1911 {
1912 return false;
1913 }
1914 }
1915
1916 for (unsigned int arrayElementIndex = 0; arrayElementIndex < uniform.elementCount(); arrayElementIndex++)
1917 {
1918 mUniformIndex.push_back(gl::VariableLocation(uniform.name, arrayElementIndex, uniformIndex));
1919 }
1920 }
1921
1922 return true;
Brandon Jones18bd4102014-09-22 14:21:44 -07001923}
1924
Brandon Jonesc9610c52014-08-25 17:02:59 -07001925void ProgramD3D::reset()
1926{
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001927 ProgramImpl::reset();
1928
Brandon Joneseb994362014-09-24 10:27:28 -07001929 SafeDeleteContainer(mVertexExecutables);
1930 SafeDeleteContainer(mPixelExecutables);
1931 SafeDelete(mGeometryExecutable);
1932
1933 mTransformFeedbackBufferMode = GL_NONE;
Brandon Joneseb994362014-09-24 10:27:28 -07001934
Brandon Jones22502d52014-08-29 16:58:36 -07001935 mVertexHLSL.clear();
Brandon Joneseb994362014-09-24 10:27:28 -07001936 mVertexWorkarounds = ANGLE_D3D_WORKAROUND_NONE;
Brandon Jones44151a92014-09-10 11:32:25 -07001937 mShaderVersion = 100;
Brandon Jones22502d52014-08-29 16:58:36 -07001938
1939 mPixelHLSL.clear();
Brandon Joneseb994362014-09-24 10:27:28 -07001940 mPixelWorkarounds = ANGLE_D3D_WORKAROUND_NONE;
Brandon Jones22502d52014-08-29 16:58:36 -07001941 mUsesFragDepth = false;
1942 mPixelShaderKey.clear();
Brandon Jones44151a92014-09-10 11:32:25 -07001943 mUsesPointSize = false;
Brandon Jones22502d52014-08-29 16:58:36 -07001944
Brandon Jonesc9610c52014-08-25 17:02:59 -07001945 SafeDelete(mVertexUniformStorage);
1946 SafeDelete(mFragmentUniformStorage);
Brandon Jones1a8a7e32014-10-01 12:49:30 -07001947
1948 mSamplersPS.clear();
1949 mSamplersVS.clear();
1950
1951 mUsedVertexSamplerRange = 0;
1952 mUsedPixelSamplerRange = 0;
1953 mDirtySamplerMapping = true;
Jamie Madill437d2662014-12-05 14:23:35 -05001954
1955 std::fill(mAttributesByLayout, mAttributesByLayout + ArraySize(mAttributesByLayout), -1);
Brandon Jonesc9610c52014-08-25 17:02:59 -07001956}
1957
Geoff Lang7dd2e102014-11-10 15:19:26 -05001958unsigned int ProgramD3D::getSerial() const
1959{
1960 return mSerial;
1961}
1962
1963unsigned int ProgramD3D::issueSerial()
1964{
1965 return mCurrentSerial++;
1966}
1967
Jamie Madill437d2662014-12-05 14:23:35 -05001968void ProgramD3D::initAttributesByLayout()
1969{
1970 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
1971 {
1972 mAttributesByLayout[i] = i;
1973 }
1974
1975 std::sort(&mAttributesByLayout[0], &mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS], AttributeSorter(mSemanticIndex));
1976}
1977
1978void ProgramD3D::sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
1979 int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS]) const
1980{
1981 rx::TranslatedAttribute oldTranslatedAttributes[gl::MAX_VERTEX_ATTRIBS];
1982
1983 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
1984 {
1985 oldTranslatedAttributes[i] = attributes[i];
1986 }
1987
1988 for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
1989 {
1990 int oldIndex = mAttributesByLayout[i];
1991 sortedSemanticIndices[i] = mSemanticIndex[oldIndex];
1992 attributes[i] = oldTranslatedAttributes[oldIndex];
1993 }
1994}
1995
Brandon Jonesc9610c52014-08-25 17:02:59 -07001996}